Changeset View
Changeset View
Standalone View
Standalone View
source/renderer/Renderer.cpp
Show First 20 Lines • Show All 723 Lines • ▼ Show 20 Lines | #if !CONFIG2_GLES | ||||
} | } | ||||
else if (m_TerrainRenderMode == EDGED_FACES) | else if (m_TerrainRenderMode == EDGED_FACES) | ||||
{ | { | ||||
// edged faces: need to make a second pass over the data: | // edged faces: need to make a second pass over the data: | ||||
// first switch on wireframe | // first switch on wireframe | ||||
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); | glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); | ||||
// setup some renderstate .. | // setup some renderstate .. | ||||
pglActiveTextureARB(GL_TEXTURE0); | glActiveTextureARB(GL_TEXTURE0); | ||||
glLineWidth(2.0f); | glLineWidth(2.0f); | ||||
// render tiles edges | // render tiles edges | ||||
m->terrainRenderer.RenderPatches(cullGroup, CColor(0.5f, 0.5f, 1.0f, 1.0f)); | m->terrainRenderer.RenderPatches(cullGroup, CColor(0.5f, 0.5f, 1.0f, 1.0f)); | ||||
glLineWidth(4.0f); | glLineWidth(4.0f); | ||||
// render outline of each patch | // render outline of each patch | ||||
▲ Show 20 Lines • Show All 241 Lines • ▼ Show 20 Lines | void CRenderer::RenderReflections(const CShaderDefines& context, const CBoundingBoxAligned& scissor) | ||||
screenScissor.y1 = (GLint)floor((reflectionScissor[0].Y*0.5f+0.5f)*vpHeight); | screenScissor.y1 = (GLint)floor((reflectionScissor[0].Y*0.5f+0.5f)*vpHeight); | ||||
screenScissor.x2 = (GLint)ceil((reflectionScissor[1].X*0.5f+0.5f)*vpWidth); | screenScissor.x2 = (GLint)ceil((reflectionScissor[1].X*0.5f+0.5f)*vpWidth); | ||||
screenScissor.y2 = (GLint)ceil((reflectionScissor[1].Y*0.5f+0.5f)*vpHeight); | screenScissor.y2 = (GLint)ceil((reflectionScissor[1].Y*0.5f+0.5f)*vpHeight); | ||||
glEnable(GL_SCISSOR_TEST); | glEnable(GL_SCISSOR_TEST); | ||||
glScissor(screenScissor.x1, screenScissor.y1, screenScissor.x2 - screenScissor.x1, screenScissor.y2 - screenScissor.y1); | glScissor(screenScissor.x1, screenScissor.y1, screenScissor.x2 - screenScissor.x1, screenScissor.y2 - screenScissor.y1); | ||||
// try binding the framebuffer | // try binding the framebuffer | ||||
pglBindFramebufferEXT(GL_FRAMEBUFFER_EXT, wm.m_ReflectionFbo); | glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, wm.m_ReflectionFbo); | ||||
glClearColor(0.5f, 0.5f, 1.0f, 0.0f); | glClearColor(0.5f, 0.5f, 1.0f, 0.0f); | ||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); | ||||
glFrontFace(GL_CW); | glFrontFace(GL_CW); | ||||
if (!g_RenderingOptions.GetWaterReflection()) | if (!g_RenderingOptions.GetWaterReflection()) | ||||
{ | { | ||||
Show All 21 Lines | void CRenderer::RenderReflections(const CShaderDefines& context, const CBoundingBoxAligned& scissor) | ||||
} | } | ||||
glDisable(GL_SCISSOR_TEST); | glDisable(GL_SCISSOR_TEST); | ||||
// Reset old camera | // Reset old camera | ||||
m_ViewCamera = normalCamera; | m_ViewCamera = normalCamera; | ||||
SetViewport(m_ViewCamera.GetViewPort()); | SetViewport(m_ViewCamera.GetViewPort()); | ||||
pglBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); | glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); | ||||
} | } | ||||
/////////////////////////////////////////////////////////////////////////////////////////////////// | /////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
// RenderRefractions: render the water refractions to the refraction texture | // RenderRefractions: render the water refractions to the refraction texture | ||||
void CRenderer::RenderRefractions(const CShaderDefines& context, const CBoundingBoxAligned &scissor) | void CRenderer::RenderRefractions(const CShaderDefines& context, const CBoundingBoxAligned &scissor) | ||||
{ | { | ||||
PROFILE3_GPU("water refractions"); | PROFILE3_GPU("water refractions"); | ||||
Show All 25 Lines | void CRenderer::RenderRefractions(const CShaderDefines& context, const CBoundingBoxAligned &scissor) | ||||
screenScissor.y1 = (GLint)floor((refractionScissor[0].Y*0.5f+0.5f)*vpHeight); | screenScissor.y1 = (GLint)floor((refractionScissor[0].Y*0.5f+0.5f)*vpHeight); | ||||
screenScissor.x2 = (GLint)ceil((refractionScissor[1].X*0.5f+0.5f)*vpWidth); | screenScissor.x2 = (GLint)ceil((refractionScissor[1].X*0.5f+0.5f)*vpWidth); | ||||
screenScissor.y2 = (GLint)ceil((refractionScissor[1].Y*0.5f+0.5f)*vpHeight); | screenScissor.y2 = (GLint)ceil((refractionScissor[1].Y*0.5f+0.5f)*vpHeight); | ||||
glEnable(GL_SCISSOR_TEST); | glEnable(GL_SCISSOR_TEST); | ||||
glScissor(screenScissor.x1, screenScissor.y1, screenScissor.x2 - screenScissor.x1, screenScissor.y2 - screenScissor.y1); | glScissor(screenScissor.x1, screenScissor.y1, screenScissor.x2 - screenScissor.x1, screenScissor.y2 - screenScissor.y1); | ||||
// try binding the framebuffer | // try binding the framebuffer | ||||
pglBindFramebufferEXT(GL_FRAMEBUFFER_EXT, wm.m_RefractionFbo); | glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, wm.m_RefractionFbo); | ||||
glClearColor(1.0f, 0.0f, 0.0f, 0.0f); | glClearColor(1.0f, 0.0f, 0.0f, 0.0f); | ||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); | ||||
// Render terrain and models | // Render terrain and models | ||||
RenderPatches(context, CULL_REFRACTIONS); | RenderPatches(context, CULL_REFRACTIONS); | ||||
ogl_WarnIfError(); | ogl_WarnIfError(); | ||||
RenderModels(context, CULL_REFRACTIONS); | RenderModels(context, CULL_REFRACTIONS); | ||||
ogl_WarnIfError(); | ogl_WarnIfError(); | ||||
RenderTransparentModels(context, CULL_REFRACTIONS, TRANSPARENT_OPAQUE, false); | RenderTransparentModels(context, CULL_REFRACTIONS, TRANSPARENT_OPAQUE, false); | ||||
ogl_WarnIfError(); | ogl_WarnIfError(); | ||||
glDisable(GL_SCISSOR_TEST); | glDisable(GL_SCISSOR_TEST); | ||||
// Reset old camera | // Reset old camera | ||||
m_ViewCamera = normalCamera; | m_ViewCamera = normalCamera; | ||||
SetViewport(m_ViewCamera.GetViewPort()); | SetViewport(m_ViewCamera.GetViewPort()); | ||||
pglBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); | glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); | ||||
} | } | ||||
void CRenderer::RenderSilhouettes(const CShaderDefines& context) | void CRenderer::RenderSilhouettes(const CShaderDefines& context) | ||||
{ | { | ||||
PROFILE3_GPU("silhouettes"); | PROFILE3_GPU("silhouettes"); | ||||
CShaderDefines contextOccluder = context; | CShaderDefines contextOccluder = context; | ||||
contextOccluder.Add(str_MODE_SILHOUETTEOCCLUDER, str_1); | contextOccluder.Add(str_MODE_SILHOUETTEOCCLUDER, str_1); | ||||
Show All 38 Lines | void CRenderer::RenderSilhouettes(const CShaderDefines& context) | ||||
glDepthFunc(GL_GEQUAL); | glDepthFunc(GL_GEQUAL); | ||||
glColorMask(1, 1, 1, 1); | glColorMask(1, 1, 1, 1); | ||||
// Since we can't sort, we'll use the stencil buffer to ensure we only draw | // Since we can't sort, we'll use the stencil buffer to ensure we only draw | ||||
// a pixel once (using the color of whatever model happens to be drawn first). | // a pixel once (using the color of whatever model happens to be drawn first). | ||||
glEnable(GL_BLEND); | glEnable(GL_BLEND); | ||||
glBlendFunc(GL_CONSTANT_ALPHA, GL_ONE_MINUS_CONSTANT_ALPHA); | glBlendFunc(GL_CONSTANT_ALPHA, GL_ONE_MINUS_CONSTANT_ALPHA); | ||||
const float silhouetteAlpha = 0.75f; | const float silhouetteAlpha = 0.75f; | ||||
pglBlendColorEXT(0, 0, 0, silhouetteAlpha); | glBlendColorEXT(0, 0, 0, silhouetteAlpha); | ||||
glEnable(GL_STENCIL_TEST); | glEnable(GL_STENCIL_TEST); | ||||
glStencilFunc(GL_NOTEQUAL, 1, (GLuint)-1); | glStencilFunc(GL_NOTEQUAL, 1, (GLuint)-1); | ||||
glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE); | glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE); | ||||
{ | { | ||||
PROFILE("render model casters"); | PROFILE("render model casters"); | ||||
m->CallModelRenderers(contextDisplay, CULL_SILHOUETTE_CASTER, 0); | m->CallModelRenderers(contextDisplay, CULL_SILHOUETTE_CASTER, 0); | ||||
} | } | ||||
{ | { | ||||
PROFILE("render transparent casters"); | PROFILE("render transparent casters"); | ||||
m->CallTranspModelRenderers(contextDisplay, CULL_SILHOUETTE_CASTER, 0); | m->CallTranspModelRenderers(contextDisplay, CULL_SILHOUETTE_CASTER, 0); | ||||
} | } | ||||
// Restore state | // Restore state | ||||
glDepthFunc(GL_LEQUAL); | glDepthFunc(GL_LEQUAL); | ||||
glDisable(GL_BLEND); | glDisable(GL_BLEND); | ||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | ||||
pglBlendColorEXT(0, 0, 0, 0); | glBlendColorEXT(0, 0, 0, 0); | ||||
glDisable(GL_STENCIL_TEST); | glDisable(GL_STENCIL_TEST); | ||||
} | } | ||||
void CRenderer::RenderParticles(int cullGroup) | void CRenderer::RenderParticles(int cullGroup) | ||||
{ | { | ||||
PROFILE3_GPU("particles"); | PROFILE3_GPU("particles"); | ||||
m->particleRenderer.RenderParticles(cullGroup); | m->particleRenderer.RenderParticles(cullGroup); | ||||
▲ Show 20 Lines • Show All 471 Lines • ▼ Show 20 Lines | Scene& CRenderer::GetScene() | ||||
ENSURE(m_CurrentScene); | ENSURE(m_CurrentScene); | ||||
return *m_CurrentScene; | return *m_CurrentScene; | ||||
} | } | ||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
// BindTexture: bind a GL texture object to current active unit | // BindTexture: bind a GL texture object to current active unit | ||||
void CRenderer::BindTexture(int unit, GLuint tex) | void CRenderer::BindTexture(int unit, GLuint tex) | ||||
{ | { | ||||
pglActiveTextureARB(GL_TEXTURE0+unit); | glActiveTextureARB(GL_TEXTURE0+unit); | ||||
glBindTexture(GL_TEXTURE_2D, tex); | glBindTexture(GL_TEXTURE_2D, tex); | ||||
} | } | ||||
void CRenderer::MakeShadersDirty() | void CRenderer::MakeShadersDirty() | ||||
{ | { | ||||
m->ShadersDirty = true; | m->ShadersDirty = true; | ||||
m_WaterManager->m_NeedsReloading = true; | m_WaterManager->m_NeedsReloading = true; | ||||
▲ Show 20 Lines • Show All 57 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator