DXGL r229 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r228‎ | r229 | r230 >
Date:00:35, 6 August 2012
Author:admin
Status:new
Tags:
Comment:
Eliminate redundant clear state changes.
Modified paths:
  • /ddraw/glRenderer.cpp (modified) (history)
  • /ddraw/glutil.cpp (modified) (history)
  • /ddraw/glutil.h (modified) (history)

Diff [purge]

Index: ddraw/glRenderer.cpp
@@ -808,7 +808,9 @@
809809 glGetIntegerv(GL_MAX_TEXTURE_SIZE,&gl_caps.TextureMax);
810810 CompileShaders();
811811 InitFBO();
812 - glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
 812+ ClearColor(0.0f, 0.0f, 0.0f, 0.0f);
 813+ ClearDepth(1.0);
 814+ ClearStencil(0);
813815 glClear(GL_COLOR_BUFFER_BIT);
814816 glFlush();
815817 SetScissor(false,0,0,0,0);
@@ -1236,17 +1238,17 @@
12371239 if(D3DCLEAR_TARGET)
12381240 {
12391241 clearbits |= GL_COLOR_BUFFER_BIT;
1240 - glClearColor(color[0],color[1],color[2],color[3]);
 1242+ ClearColor(color[0],color[1],color[2],color[3]);
12411243 }
12421244 if(D3DCLEAR_ZBUFFER)
12431245 {
12441246 clearbits |= GL_DEPTH_BUFFER_BIT;
1245 - glClearDepth(dvZ);
 1247+ ClearDepth(dvZ);
12461248 }
12471249 if(D3DCLEAR_STENCIL)
12481250 {
12491251 clearbits |= GL_STENCIL_BUFFER_BIT;
1250 - glClearStencil(dwStencil);
 1252+ ClearStencil(dwStencil);
12511253 }
12521254 if(dwCount)
12531255 {
Index: ddraw/glutil.cpp
@@ -45,6 +45,12 @@
4646 bool stencil = false;
4747 GLint texlevel = 0;
4848 GLint texwrap[16];
 49+GLclampf clearr = 0.0;
 50+GLclampf clearg = 0.0;
 51+GLclampf clearb = 0.0;
 52+GLclampf cleara = 0.0;
 53+GLclampd cleardepth = 1.0;
 54+GLint clearstencil = 0;
4955
5056 void InitFBO()
5157 {
@@ -291,4 +297,34 @@
292298 depthfar = rangefar;
293299 glDepthRange(rangenear,rangefar);
294300 }
 301+}
 302+
 303+void ClearColor(GLclampf r, GLclampf g, GLclampf b, GLclampf a)
 304+{
 305+ if((clearr != r) || (clearg != g) || (clearb != b) || (cleara != a))
 306+ {
 307+ clearr = r;
 308+ clearg = g;
 309+ clearb = b;
 310+ cleara = a;
 311+ glClearColor(r,g,b,a);
 312+ }
 313+}
 314+
 315+void ClearDepth(GLclampd depth)
 316+{
 317+ if(cleardepth != depth)
 318+ {
 319+ cleardepth = depth;
 320+ glClearDepth(depth);
 321+ }
 322+}
 323+
 324+void ClearStencil(GLint stencil)
 325+{
 326+ if(clearstencil != stencil)
 327+ {
 328+ clearstencil = stencil;
 329+ glClearStencil(stencil);
 330+ }
295331 }
\ No newline at end of file
Index: ddraw/glutil.h
@@ -38,5 +38,8 @@
3939 void SetMaterial(GLfloat ambient[4],GLfloat diffuse[4],GLfloat specular[4],GLfloat emission[4],GLfloat shininess);
4040 void SetViewport(GLint x, GLint y, GLsizei width, GLsizei height);
4141 void SetDepthRange(GLclampd rangenear, GLclampd rangefar);
 42+void ClearColor(GLclampf r, GLclampf g, GLclampf b, GLclampf a);
 43+void ClearDepth(GLclampd depth);
 44+void ClearStencil(GLint stencil);
4245
4346 #endif //_GLUTIL_H
\ No newline at end of file