Skip to content

Commit

Permalink
UPBGE: Avoid redundant state call to GL_CULL_FACE.
Browse files Browse the repository at this point in the history
The function SetCullFace now use a state from RAS_Rasterizer to skip
unecessary opengl calls. Also the rendering of plane to screen is now
using the function SetFrontFace instead disabling and renabling the
face culling.
  • Loading branch information
panzergame committed Aug 16, 2018
1 parent 2fdcf10 commit 9fb0a3b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
3 changes: 1 addition & 2 deletions source/gameengine/Ketsji/KX_WorldInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,14 +215,13 @@ void KX_WorldInfo::RenderBackground(RAS_Rasterizer *rasty)
GPU_material_bind(gpumat, m_scene->lay, 1.0f, false, rasty->GetViewMatrix().Data(),
rasty->GetViewInvMatrix().Data(), texcofac, false);

rasty->Disable(RAS_Rasterizer::RAS_CULL_FACE);
rasty->SetFrontFace(true);
rasty->Enable(RAS_Rasterizer::RAS_DEPTH_TEST);
rasty->SetDepthFunc(RAS_Rasterizer::RAS_ALWAYS);

rasty->DrawOverlayPlane();

rasty->SetDepthFunc(RAS_Rasterizer::RAS_LEQUAL);
rasty->Enable(RAS_Rasterizer::RAS_CULL_FACE);

GPU_material_unbind(gpumat);
}
Expand Down
2 changes: 0 additions & 2 deletions source/gameengine/Rasterizer/RAS_2DFilterManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ RAS_OffScreen *RAS_2DFilterManager::RenderFilters(RAS_Rasterizer *rasty, RAS_ICa
return inputofs;
}

rasty->Disable(RAS_Rasterizer::RAS_CULL_FACE);
rasty->Disable(RAS_Rasterizer::RAS_DEPTH_TEST);
rasty->SetDepthMask(RAS_Rasterizer::RAS_DEPTHMASK_DISABLED);
rasty->Disable(RAS_Rasterizer::RAS_BLEND);
Expand Down Expand Up @@ -147,7 +146,6 @@ RAS_OffScreen *RAS_2DFilterManager::RenderFilters(RAS_Rasterizer *rasty, RAS_ICa

rasty->Enable(RAS_Rasterizer::RAS_DEPTH_TEST);
rasty->SetDepthMask(RAS_Rasterizer::RAS_DEPTHMASK_ENABLED);
rasty->Enable(RAS_Rasterizer::RAS_CULL_FACE);

return targetofs;
}
Expand Down
20 changes: 12 additions & 8 deletions source/gameengine/Rasterizer/RAS_Rasterizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,8 @@ RAS_Rasterizer::RAS_Rasterizer()

InitOverrideShadersInterface();

m_state.frontFace = true;
m_state.frontFace = -1;
m_state.cullFace = -1;
m_state.polyOffset[0] = -1.0f;
m_state.polyOffset[1] = -1.0f;
}
Expand Down Expand Up @@ -283,7 +284,7 @@ void RAS_Rasterizer::Init()

void RAS_Rasterizer::Exit()
{
Enable(RAS_CULL_FACE);
SetCullFace(true);
Enable(RAS_DEPTH_TEST);

SetClearDepth(1.0f);
Expand Down Expand Up @@ -313,7 +314,7 @@ void RAS_Rasterizer::BeginFrame(double time)
m_state.polyOffset[0] = -1.0f;
m_state.polyOffset[1] = -1.0f;

Enable(RAS_CULL_FACE);
SetCullFace(true);
Enable(RAS_DEPTH_TEST);

Disable(RAS_BLEND);
Expand Down Expand Up @@ -444,14 +445,13 @@ void RAS_Rasterizer::DrawOffScreen(RAS_ICanvas *canvas, RAS_OffScreen *offScreen
SetViewport(viewport[0], viewport[1], viewport[2], viewport[3]);
SetScissor(viewport[0], viewport[1], viewport[2], viewport[3]);

Disable(RAS_CULL_FACE);
SetFrontFace(true);
SetDepthFunc(RAS_ALWAYS);

RAS_OffScreen::RestoreScreen();
DrawOffScreen(offScreen, nullptr);

SetDepthFunc(RAS_LEQUAL);
Enable(RAS_CULL_FACE);
}

void RAS_Rasterizer::DrawStereoOffScreen(RAS_ICanvas *canvas, RAS_OffScreen *leftOffScreen, RAS_OffScreen *rightOffScreen,
Expand All @@ -471,7 +471,7 @@ void RAS_Rasterizer::DrawStereoOffScreen(RAS_ICanvas *canvas, RAS_OffScreen *lef
SetViewport(viewport[0], viewport[1], viewport[2], viewport[3]);
SetScissor(viewport[0], viewport[1], viewport[2], viewport[3]);

Disable(RAS_CULL_FACE);
SetFrontFace(true);
SetDepthFunc(RAS_ALWAYS);

RAS_OffScreen::RestoreScreen();
Expand Down Expand Up @@ -517,7 +517,6 @@ void RAS_Rasterizer::DrawStereoOffScreen(RAS_ICanvas *canvas, RAS_OffScreen *lef
}

SetDepthFunc(RAS_LEQUAL);
Enable(RAS_CULL_FACE);
}

RAS_Rect RAS_Rasterizer::GetRenderArea(RAS_ICanvas *canvas, StereoMode stereoMode, StereoEye eye)
Expand Down Expand Up @@ -863,6 +862,11 @@ bool RAS_Rasterizer::GetCameraOrtho()

void RAS_Rasterizer::SetCullFace(bool enable)
{
if (enable == m_state.cullFace) {
return;
}
m_state.cullFace = enable;

if (enable) {
Enable(RAS_CULL_FACE);
}
Expand Down Expand Up @@ -1386,7 +1390,7 @@ void RAS_Rasterizer::DisableForText()
SetAlphaBlend(GPU_BLEND_ALPHA);
SetLines(false); /* needed for texture fonts otherwise they render as wireframe */

Enable(RAS_CULL_FACE);
SetCullFace(true);

DisableLights();

Expand Down
3 changes: 2 additions & 1 deletion source/gameengine/Rasterizer/RAS_Rasterizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,8 @@ class RAS_Rasterizer : public mt::SimdClassAllocator

/// States to reduce OpenGL calls.
struct {
bool frontFace;
char frontFace;
char cullFace;
float polyOffset[2];
} m_state;

Expand Down

0 comments on commit 9fb0a3b

Please sign in to comment.