DXGL r216 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r215‎ | r216 | r217 >
Date:19:38, 15 July 2012
Author:admin
Status:new
Tags:
Comment:
Eliminate redundancies in glViewport, glDepthRange, and glMaterial calls.
Don't call glBindTexture if texture is 0.
Advertise Direct3D support in debug builds.
Modified paths:
  • /ddraw/glDirectDraw.cpp (modified) (history)
  • /ddraw/glRenderer.cpp (modified) (history)
  • /ddraw/glutil.cpp (modified) (history)
  • /ddraw/glutil.h (modified) (history)

Diff [purge]

Index: ddraw/glDirectDraw.cpp
@@ -799,6 +799,9 @@
800800 if(ddCaps.dwSize > sizeof(DDCAPS_DX7)) ddCaps.dwSize = sizeof(DDCAPS_DX7);
801801 ddCaps.dwCaps = DDCAPS_BLT | DDCAPS_BLTCOLORFILL | DDCAPS_BLTSTRETCH |
802802 DDCAPS_COLORKEY | DDCAPS_GDI | DDCAPS_PALETTE | DDCAPS_CANBLTSYSMEM;
 803+#ifdef _DEBUG
 804+ ddCaps.dwCaps |= DDCAPS_3D;
 805+#endif
803806 ddCaps.dwCaps2 = DDCAPS2_CANRENDERWINDOWED | DDCAPS2_WIDESURFACES | DDCAPS2_NOPAGELOCKREQUIRED |
804807 DDCAPS2_FLIPINTERVAL | DDCAPS2_FLIPNOVSYNC;
805808 ddCaps.dwFXCaps = DDFXCAPS_BLTSHRINKX | DDFXCAPS_BLTSHRINKY |
@@ -808,6 +811,10 @@
809812 DDSCAPS_BACKBUFFER | DDSCAPS_COMPLEX | DDSCAPS_FLIP |
810813 DDSCAPS_FRONTBUFFER | DDSCAPS_OFFSCREENPLAIN | DDSCAPS_PALETTE |
811814 DDSCAPS_SYSTEMMEMORY | DDSCAPS_VIDEOMEMORY;
 815+#ifdef _DEBUG
 816+ ddCaps.ddsOldCaps.dwCaps |= DDSCAPS_3DDEVICE;
 817+ ddCaps.ddsCaps.dwCaps |= DDSCAPS_3DDEVICE;
 818+#endif;
812819 ddCaps.dwCKeyCaps = DDCKEYCAPS_SRCBLT;
813820 if(lpDDDriverCaps)
814821 {
Index: ddraw/glRenderer.cpp
@@ -789,7 +789,9 @@
790790 InitGLExt();
791791 SetSwap(1);
792792 SetSwap(0);
 793+ SetViewport(0,0,width,height);
793794 glViewport(0,0,width,height);
 795+ SetDepthRange(0.0,1.0);
794796 DepthWrite(true);
795797 DepthTest(false);
796798 MatrixMode(GL_MODELVIEW);
@@ -844,7 +846,7 @@
845847 ddInterface->GetSizes(sizes);
846848 int error;
847849 error = SetFBO(dest->texture,0,false);
848 - glViewport(0,0,dest->fakex,dest->fakey);
 850+ SetViewport(0,0,dest->fakex,dest->fakey);
849851 RECT destrect;
850852 DDSURFACEDESC2 ddsd;
851853 ddsd.dwSize = sizeof(DDSURFACEDESC2);
@@ -1020,7 +1022,7 @@
10211023 view[0] = view[2] = 0;
10221024 view[1] = (GLfloat)x;
10231025 view[3] = (GLfloat)y;
1024 - glViewport(0,0,x,y);
 1026+ SetViewport(0,0,x,y);
10251027 glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
10261028 glBindTexture(GL_TEXTURE_2D,*texture);
10271029 *texture = backbuffer;
@@ -1134,7 +1136,7 @@
11351137 GLint texloc = glGetUniformLocation(prog,"Texture");
11361138 glUniform1i(texloc,0);
11371139 }
1138 - glViewport(viewport[0],viewport[1],viewport[2],viewport[3]);
 1140+ SetViewport(viewport[0],viewport[1],viewport[2],viewport[3]);
11391141 GLuint prog = GetProgram();
11401142 GLint viewloc = glGetUniformLocation(prog,"view");
11411143 glUniform4f(viewloc,view[0],view[1],view[2],view[3]);
@@ -1298,7 +1300,7 @@
12991301 gllock = false;
13001302 SetSwap(1);
13011303 SetSwap(0);
1302 - glViewport(0,0,width,height);
 1304+ SetViewport(0,0,width,height);
13031305 }
13041306
13051307 SetEvent(busy);
@@ -1485,8 +1487,8 @@
14861488 if(prog.uniforms[138]!= -1) glUniform1f(prog.uniforms[138],device->glDDS7->fakey);
14871489 if(device->glDDS7->zbuffer) SetFBO(device->glDDS7->texture,device->glDDS7->zbuffer->texture,device->glDDS7->zbuffer->hasstencil);
14881490 else SetFBO(device->glDDS7->texture,0,false);
1489 - glViewport(device->viewport.dwX,device->viewport.dwY,device->viewport.dwWidth,device->viewport.dwHeight);
1490 - glDepthRange(device->viewport.dvMinZ,device->viewport.dvMaxZ);
 1491+ SetViewport(device->viewport.dwX,device->viewport.dwY,device->viewport.dwWidth,device->viewport.dwHeight);
 1492+ SetDepthRange(device->viewport.dvMinZ,device->viewport.dvMaxZ);
14911493 if(indices) glDrawElements(mode,indexcount,GL_UNSIGNED_SHORT,indices);
14921494 else glDrawArrays(mode,0,count);
14931495 if(device->glDDS7->zbuffer) device->glDDS7->zbuffer->dirty |= 2;
Index: ddraw/glutil.cpp
@@ -29,6 +29,12 @@
3030 GLint scissory = 0;
3131 GLsizei scissorwidth = 0;
3232 GLsizei scissorheight = 0;
 33+GLint viewportx = 0;
 34+GLint viewporty = 0;
 35+GLsizei viewportwidth = 0;
 36+GLsizei viewportheight = 0;
 37+GLclampd depthnear = 0.0;
 38+GLclampd depthfar = 1.0;
3339 GLenum matrixmode = GL_MODELVIEW;
3440 GLfloat materialambient[4] = {0,0,0,0};
3541 GLfloat materialdiffuse[4] = {0,0,0,0};
@@ -132,7 +138,7 @@
133139 void SetTexture(int level,GLuint texture)
134140 {
135141 SetActiveTexture(level);
136 - glBindTexture(GL_TEXTURE_2D,texture);
 142+ if(texture) glBindTexture(GL_TEXTURE_2D,texture);
137143 }
138144
139145 void SetWrap(int level, DWORD coord, DWORD address)
@@ -238,22 +244,22 @@
239245
240246 void SetMaterial(GLfloat ambient[4],GLfloat diffuse[4],GLfloat specular[4],GLfloat emission[4],GLfloat shininess)
241247 {
242 - if(ambient != materialambient)
 248+ if(memcmp(ambient,materialambient,4*sizeof(GLfloat)))
243249 {
244250 memcpy(materialambient,ambient,4*sizeof(GLfloat));
245251 glMaterialfv(GL_FRONT,GL_AMBIENT,ambient);
246252 }
247 - if(diffuse != materialdiffuse)
 253+ if(memcmp(diffuse,materialdiffuse,4*sizeof(GLfloat)))
248254 {
249255 memcpy(materialdiffuse,diffuse,4*sizeof(GLfloat));
250256 glMaterialfv(GL_FRONT,GL_DIFFUSE,diffuse);
251257 }
252 - if(specular != materialspecular)
 258+ if(memcmp(specular,materialspecular,4*sizeof(GLfloat)))
253259 {
254260 memcpy(materialspecular,specular,4*sizeof(GLfloat));
255261 glMaterialfv(GL_FRONT,GL_SPECULAR,specular);
256262 }
257 - if(emission != materialemission)
 263+ if(memcmp(emission,materialemission,4*sizeof(GLfloat)))
258264 {
259265 memcpy(materialemission,emission,4*sizeof(GLfloat));
260266 glMaterialfv(GL_FRONT,GL_EMISSION,emission);
@@ -263,4 +269,26 @@
264270 materialshininess = shininess;
265271 glMaterialf(GL_FRONT,GL_SHININESS,shininess);
266272 }
 273+}
 274+
 275+void SetViewport(GLint x, GLint y, GLsizei width, GLsizei height)
 276+{
 277+ if((x != viewportx) || (y != viewporty) || (width != viewportwidth) || (height != viewportheight))
 278+ {
 279+ viewportx = x;
 280+ viewporty = y;
 281+ viewportwidth = width;
 282+ viewportheight = height;
 283+ glViewport(x,y,width,height);
 284+ }
 285+}
 286+
 287+void SetDepthRange(GLclampd rangenear, GLclampd rangefar)
 288+{
 289+ if((rangenear != depthnear) || (rangefar != depthfar))
 290+ {
 291+ depthnear = rangenear;
 292+ depthfar = rangefar;
 293+ glDepthRange(rangenear,rangefar);
 294+ }
267295 }
\ No newline at end of file
Index: ddraw/glutil.h
@@ -36,5 +36,7 @@
3737 void SetMatrix(GLenum mode, GLfloat *mat1, GLfloat *mat2, bool *dirty);
3838 void MatrixMode(GLenum mode);
3939 void SetMaterial(GLfloat ambient[4],GLfloat diffuse[4],GLfloat specular[4],GLfloat emission[4],GLfloat shininess);
 40+void SetViewport(GLint x, GLint y, GLsizei width, GLsizei height);
 41+void SetDepthRange(GLclampd rangenear, GLclampd rangefar);
4042
4143 #endif //_GLUTIL_H
\ No newline at end of file