DXGL r178 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r177‎ | r178 | r179 >
Date:17:48, 24 June 2012
Author:admin
Status:new
Tags:
Comment:
Add depth testing
Modified paths:
  • /ddraw/glRenderer.cpp (modified) (history)
  • /ddraw/glutil.cpp (modified) (history)
  • /ddraw/glutil.h (modified) (history)

Diff [purge]

Index: ddraw/glRenderer.cpp
@@ -790,6 +790,8 @@
791791 SetSwap(1);
792792 SetSwap(0);
793793 glViewport(0,0,width,height);
 794+ DepthWrite(true);
 795+ DepthTest(false);
794796 glDisable(GL_DEPTH_TEST);
795797 SetDepthComp(GL_LESS);
796798 const GLubyte *glver = glGetString(GL_VERSION);
@@ -844,6 +846,7 @@
845847 DDSURFACEDESC2 ddsd;
846848 ddsd.dwSize = sizeof(DDSURFACEDESC2);
847849 dest->GetSurfaceDesc(&ddsd);
 850+ DepthTest(false);
848851 if(!lpDestRect)
849852 {
850853 destrect.left = 0;
@@ -1047,6 +1050,7 @@
10481051 if(memcmp(&r2,&r,sizeof(RECT)))
10491052 SetWindowPos(RenderWnd->GetHWnd(),NULL,0,0,r.right,r.bottom,SWP_SHOWWINDOW);
10501053 }
 1054+ DepthTest(false);
10511055 RECT *viewrect = &r2;
10521056 SetSwap(swapinterval);
10531057 LONG sizes[6];
@@ -1128,6 +1132,7 @@
11291133 glUniform1i(texloc,0);
11301134 }
11311135 glViewport(viewport[0],viewport[1],viewport[2],viewport[3]);
 1136+ glDepthRange(viewport[4],viewport[5]);
11321137 GLuint prog = GetProgram();
11331138 GLint viewloc = glGetUniformLocation(prog,"view");
11341139 glUniform4f(viewloc,view[0],view[1],view[2],view[3]);
@@ -1205,7 +1210,7 @@
12061211 SetEvent(busy);
12071212 glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST);
12081213 GLfloat ambient[] = {0.0,0.0,0.0,0.0};
1209 - if(zbuffer) glEnable(GL_DEPTH_TEST);
 1214+ if(zbuffer) DepthTest(true);
12101215 SetDepthComp(GL_LEQUAL);
12111216 glDisable(GL_DITHER);
12121217 }
@@ -1309,6 +1314,8 @@
13101315 __int64 shader = device->SelectShader(vertices);
13111316 SetShader(shader,device->texstages,texformats,0);
13121317 device->SetDepthComp();
 1318+ if(device->renderstate[D3DRENDERSTATE_ZENABLE]) DepthTest(true);
 1319+ else DepthTest(false);
13131320 _GENSHADER prog = genshaders[current_genshader].shader;
13141321 glEnableVertexAttribArray(prog.attribs[0]);
13151322 glVertexAttribPointer(prog.attribs[0],3,GL_FLOAT,false,vertices[0].stride,vertices[0].data);
Index: ddraw/glutil.cpp
@@ -18,6 +18,8 @@
1919 #include "common.h"
2020 #include "glutil.h"
2121
 22+bool depthwrite = true;
 23+bool depthtest = false;
2224 GLuint depthcomp = 0;
2325 GLuint alphacomp = 0;
2426 GLuint fbcolor = 0;
@@ -161,6 +163,24 @@
162164 }
163165 }
164166
 167+void DepthWrite(bool enabled)
 168+{
 169+ if(enabled != depthwrite)
 170+ {
 171+ depthwrite = enabled;
 172+ if(depthwrite) glDepthMask(GL_TRUE);
 173+ else glDepthMask(GL_FALSE);
 174+ }
 175+}
 176+void DepthTest(bool enabled)
 177+{
 178+ if(enabled != depthtest)
 179+ {
 180+ depthtest = enabled;
 181+ if(depthtest) glEnable(
 182+ else glDepthMask(GL_FALSE);
 183+ }
 184+}
165185 void SetDepthComp(GLenum comp)
166186 {
167187 if(comp != depthcomp)
Index: ddraw/glutil.h
@@ -29,5 +29,7 @@
3030 void SetActiveTexture(int level);
3131 GLenum SetFBO(GLint color, GLint z, bool stencil);
3232 void SetDepthComp(GLenum comp);
 33+void DepthWrite(bool enabled);
 34+void DepthTest(bool enabled);
3335
3436 #endif //_GLUTIL_H
\ No newline at end of file