Changeset View
Changeset View
Standalone View
Standalone View
source/renderer/Renderer.cpp
Show First 20 Lines • Show All 950 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); | ||||
glDisable(GL_TEXTURE_2D); | glDisable(GL_TEXTURE_2D); | ||||
glColor3f(0.5f, 0.5f, 1.0f); | glColor3f(0.5f, 0.5f, 1.0f); | ||||
glLineWidth(2.0f); | glLineWidth(2.0f); | ||||
// render tiles edges | // render tiles edges | ||||
m->terrainRenderer.RenderPatches(cullGroup); | m->terrainRenderer.RenderPatches(cullGroup); | ||||
// set color for outline | // set color for outline | ||||
▲ Show 20 Lines • Show All 238 Lines • ▼ Show 20 Lines | void CRenderer::RenderReflections(const CShaderDefines& context, const CBoundingBoxAligned& scissor) | ||||
screenScissor.y1 = (GLint)floor((scissor[0].Y*0.5f+0.5f)*vpHeight); | screenScissor.y1 = (GLint)floor((scissor[0].Y*0.5f+0.5f)*vpHeight); | ||||
screenScissor.x2 = (GLint)ceil((scissor[1].X*0.5f+0.5f)*vpWidth); | screenScissor.x2 = (GLint)ceil((scissor[1].X*0.5f+0.5f)*vpWidth); | ||||
screenScissor.y2 = (GLint)ceil((scissor[1].Y*0.5f+0.5f)*vpHeight); | screenScissor.y2 = (GLint)ceil((scissor[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 (!m_Options.m_WaterReflection) | if (!m_Options.m_WaterReflection) | ||||
{ | { | ||||
Show All 22 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; | ||||
m->SetOpenGLCamera(m_ViewCamera); | m->SetOpenGLCamera(m_ViewCamera); | ||||
// rebind post-processing frambuffer. | // rebind post-processing frambuffer. | ||||
pglBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo); | glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo); | ||||
return; | return; | ||||
} | } | ||||
/////////////////////////////////////////////////////////////////////////////////////////////////// | /////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
// 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) | ||||
Show All 27 Lines | void CRenderer::RenderRefractions(const CShaderDefines& context, const CBoundingBoxAligned &scissor) | ||||
screenScissor.y1 = (GLint)floor((scissor[0].Y*0.5f+0.5f)*vpHeight); | screenScissor.y1 = (GLint)floor((scissor[0].Y*0.5f+0.5f)*vpHeight); | ||||
screenScissor.x2 = (GLint)ceil((scissor[1].X*0.5f+0.5f)*vpWidth); | screenScissor.x2 = (GLint)ceil((scissor[1].X*0.5f+0.5f)*vpWidth); | ||||
screenScissor.y2 = (GLint)ceil((scissor[1].Y*0.5f+0.5f)*vpHeight); | screenScissor.y2 = (GLint)ceil((scissor[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; | ||||
m->SetOpenGLCamera(m_ViewCamera); | m->SetOpenGLCamera(m_ViewCamera); | ||||
// rebind post-processing frambuffer. | // rebind post-processing frambuffer. | ||||
pglBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo); | glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo); | ||||
return; | return; | ||||
} | } | ||||
void CRenderer::RenderSilhouettes(const CShaderDefines& context) | void CRenderer::RenderSilhouettes(const CShaderDefines& context) | ||||
{ | { | ||||
PROFILE3_GPU("silhouettes"); | PROFILE3_GPU("silhouettes"); | ||||
▲ Show 20 Lines • Show All 57 Lines • ▼ Show 20 Lines | if (silhouetteAlpha == 1.f) | ||||
glDepthMask(0); | glDepthMask(0); | ||||
} | } | ||||
else | else | ||||
{ | { | ||||
// 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); | ||||
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 casters"); | PROFILE("render casters"); | ||||
m->CallModelRenderers(contextDisplay, CULL_SILHOUETTE_CASTER, 0); | m->CallModelRenderers(contextDisplay, CULL_SILHOUETTE_CASTER, 0); | ||||
// (This won't render transparent objects with SILHOUETTE_CASTER - will | // (This won't render transparent objects with SILHOUETTE_CASTER - will | ||||
// we have any units that need that?) | // we have any units that need that?) | ||||
} | } | ||||
// Restore state | // Restore state | ||||
glDepthFunc(GL_LEQUAL); | glDepthFunc(GL_LEQUAL); | ||||
if (silhouetteAlpha == 1.f) | if (silhouetteAlpha == 1.f) | ||||
{ | { | ||||
glDepthMask(1); | glDepthMask(1); | ||||
} | } | ||||
else | else | ||||
{ | { | ||||
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) | ||||
{ | { | ||||
// Only supported in shader modes | // Only supported in shader modes | ||||
if (GetRenderPath() != RP_SHADER) | if (GetRenderPath() != RP_SHADER) | ||||
▲ Show 20 Lines • Show All 465 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); | ||||
#if !CONFIG2_GLES | #if !CONFIG2_GLES | ||||
if (tex) { | if (tex) { | ||||
glEnable(GL_TEXTURE_2D); | glEnable(GL_TEXTURE_2D); | ||||
} else { | } else { | ||||
glDisable(GL_TEXTURE_2D); | glDisable(GL_TEXTURE_2D); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 228 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator