DXGL r259 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r258‎ | r259 | r260 >
Date:10:07, 7 September 2012
Author:admin
Status:new
Tags:
Comment:
Update D3D caps.
Fix DDraw object releasing.
Add back face culling.
Modified paths:
  • /ddraw/glDirect3D.cpp (modified) (history)
  • /ddraw/glDirectDraw.cpp (modified) (history)
  • /ddraw/glRenderer.cpp (modified) (history)
  • /ddraw/glutil.cpp (modified) (history)
  • /ddraw/glutil.h (modified) (history)

Diff [purge]

Index: ddraw/glDirect3D.cpp
@@ -47,7 +47,7 @@
4848 D3DPBLENDCAPS_SRCALPHASAT | D3DPBLENDCAPS_BOTHSRCALPHA | D3DPBLENDCAPS_BOTHINVSRCALPHA, //dwDestBlendCaps
4949 0, //dwAlphaCmpCaps
5050 D3DPSHADECAPS_COLORGOURAUDRGB, //dwShadeCaps
51 - D3DPTEXTURECAPS_PERSPECTIVE, //dwTextureCaps
 51+ D3DPTEXTURECAPS_ALPHA | D3DPTEXTURECAPS_PERSPECTIVE, //dwTextureCaps
5252 D3DPTFILTERCAPS_NEAREST | D3DPTFILTERCAPS_LINEAR | D3DPTFILTERCAPS_MIPNEAREST |
5353 D3DPTFILTERCAPS_MIPLINEAR | D3DPTFILTERCAPS_LINEARMIPNEAREST | D3DPTFILTERCAPS_LINEARMIPLINEAR |
5454 D3DPTFILTERCAPS_MAGFLINEAR | D3DPTFILTERCAPS_MAGFPOINT | D3DPTFILTERCAPS_MINFLINEAR |
@@ -74,7 +74,7 @@
7575 D3DPBLENDCAPS_SRCALPHASAT | D3DPBLENDCAPS_BOTHSRCALPHA | D3DPBLENDCAPS_BOTHINVSRCALPHA, //dwDestBlendCaps
7676 0, //dwAlphaCmpCaps
7777 D3DPSHADECAPS_COLORGOURAUDRGB, //dwShadeCaps
78 - D3DPTEXTURECAPS_PERSPECTIVE, //dwTextureCaps
 78+ D3DPTEXTURECAPS_ALPHA | D3DPTEXTURECAPS_PERSPECTIVE, //dwTextureCaps
7979 D3DPTFILTERCAPS_NEAREST | D3DPTFILTERCAPS_LINEAR | D3DPTFILTERCAPS_MIPNEAREST |
8080 D3DPTFILTERCAPS_MIPLINEAR | D3DPTFILTERCAPS_LINEARMIPNEAREST | D3DPTFILTERCAPS_LINEARMIPLINEAR |
8181 D3DPTFILTERCAPS_MAGFLINEAR | D3DPTFILTERCAPS_MAGFPOINT | D3DPTFILTERCAPS_MINFLINEAR |
@@ -94,7 +94,7 @@
9595 0, //dwMaxTextureHeight
9696 0, //dwMaxTextureRepeat
9797 0, //dwMaxTextureAspectRatio
98 - 0, //dwMaxAnisotropy
 98+ 1, //dwMaxAnisotropy
9999 0.0f, //dvGuardBandLeft
100100 0.0f, //dvGuardBandTop
101101 0.0f, //dvGuardBandRight
Index: ddraw/glDirectDraw.cpp
@@ -1462,8 +1462,8 @@
14631463 }
14641464 glDirectDraw1::~glDirectDraw1()
14651465 {
 1466+ glDD7->glDD1 = NULL;
14661467 glDD7->Release();
1467 - glDD7->glDD1 = NULL;
14681468 }
14691469 HRESULT WINAPI glDirectDraw1::QueryInterface(REFIID riid, void** ppvObj)
14701470 {
@@ -1610,8 +1610,8 @@
16111611 }
16121612 glDirectDraw2::~glDirectDraw2()
16131613 {
 1614+ glDD7->glDD2 = NULL;
16141615 glDD7->Release();
1615 - glDD7->glDD2 = NULL;
16161616 }
16171617 HRESULT WINAPI glDirectDraw2::QueryInterface(REFIID riid, void** ppvObj)
16181618 {
@@ -1769,8 +1769,8 @@
17701770 }
17711771 glDirectDraw4::~glDirectDraw4()
17721772 {
 1773+ glDD7->glDD4 = NULL;
17731774 glDD7->Release();
1774 - glDD7->glDD4 = NULL;
17751775 }
17761776 HRESULT WINAPI glDirectDraw4::QueryInterface(REFIID riid, void** ppvObj)
17771777 {
Index: ddraw/glRenderer.cpp
@@ -784,6 +784,8 @@
785785 glFlush();
786786 SetScissor(false,0,0,0,0);
787787 glDisable(GL_SCISSOR_TEST);
 788+ SetCull(D3DCULL_CCW);
 789+ glEnable(GL_CULL_FACE);
788790 SwapBuffers(hDC);
789791 SetActiveTexture(0);
790792 if(hWnd)
@@ -946,6 +948,7 @@
947949 EnableArray(shaders[progtype].texcoord,true);
948950 glVertexAttribPointer(shaders[progtype].texcoord,2,GL_FLOAT,false,sizeof(BltVertex),&bltvertices[0].s);
949951 }
 952+ SetCull(D3DCULL_NONE);
950953 glDrawRangeElements(GL_TRIANGLE_STRIP,0,3,4,GL_UNSIGNED_SHORT,bltindices);
951954 SetFBO(0,0,false);
952955 if(((ddsd.ddsCaps.dwCaps & (DDSCAPS_FRONTBUFFER)) &&
@@ -1004,6 +1007,7 @@
10051008 glVertexAttribPointer(shaders[progtype].pos,2,GL_FLOAT,false,sizeof(BltVertex),&bltvertices[0].x);
10061009 EnableArray(shaders[progtype].texcoord,true);
10071010 glVertexAttribPointer(shaders[progtype].texcoord,2,GL_FLOAT,false,sizeof(BltVertex),&bltvertices[0].s);
 1011+ SetCull(D3DCULL_NONE);
10081012 glDrawRangeElements(GL_TRIANGLE_STRIP,0,3,4,GL_UNSIGNED_SHORT,bltindices);
10091013 SetFBO(0,0,false);
10101014 }
@@ -1119,6 +1123,7 @@
11201124 EnableArray(shaders[progtype].rgb,true);
11211125 glVertexAttribPointer(shaders[progtype].rgb,3,GL_UNSIGNED_BYTE,true,sizeof(BltVertex),&bltvertices[0].r);
11221126 }
 1127+ SetCull(D3DCULL_NONE);
11231128 glDrawRangeElements(GL_TRIANGLE_STRIP,0,3,4,GL_UNSIGNED_SHORT,bltindices);
11241129 glFlush();
11251130 if(hWnd) SwapBuffers(hDC);
@@ -1546,6 +1551,7 @@
15471552 if(device->renderstate[D3DRENDERSTATE_ALPHABLENDENABLE]) BlendEnable(true);
15481553 else BlendEnable(false);
15491554 SetBlend(device->renderstate[D3DRENDERSTATE_SRCBLEND],device->renderstate[D3DRENDERSTATE_DESTBLEND]);
 1555+ SetCull((D3DCULL)device->renderstate[D3DRENDERSTATE_CULLMODE]);
15501556 if(indices) glDrawElements(mode,indexcount,GL_UNSIGNED_SHORT,indices);
15511557 else glDrawArrays(mode,0,count);
15521558 if(device->glDDS7->zbuffer) device->glDDS7->zbuffer->dirty |= 2;
Index: ddraw/glutil.cpp
@@ -55,6 +55,8 @@
5656 GLenum blenddest = GL_ZERO;
5757 bool blendenabled = false;
5858 bool arrays[42];
 59+D3DCULL cullmode = D3DCULL_NONE;
 60+bool cullenabled = false;
5961
6062 void InitFBO()
6163 {
@@ -357,4 +359,35 @@
358360 if(enabled) glEnable(GL_BLEND);
359361 else glDisable(GL_BLEND);
360362 }
 363+}
 364+
 365+void EnableCull(bool enabled)
 366+{
 367+ if(cullenabled != enabled)
 368+ {
 369+ cullenabled = enabled;
 370+ if(enabled) glEnable(GL_CULL_FACE);
 371+ else glDisable(GL_CULL_FACE);
 372+ }
 373+}
 374+void SetCull(D3DCULL mode)
 375+{
 376+ if(cullmode != mode)
 377+ {
 378+ cullmode = mode;
 379+ switch(mode)
 380+ {
 381+ case D3DCULL_CCW:
 382+ EnableCull(true);
 383+ glFrontFace(GL_CCW);
 384+ break;
 385+ case D3DCULL_CW:
 386+ EnableCull(true);
 387+ glFrontFace(GL_CW);
 388+ break;
 389+ case D3DCULL_NONE:
 390+ EnableCull(false);
 391+ break;
 392+ }
 393+ }
361394 }
\ No newline at end of file
Index: ddraw/glutil.h
@@ -43,5 +43,7 @@
4444 void EnableArray(int index, bool enabled);
4545 void BlendFunc(GLenum src, GLenum dest);
4646 void BlendEnable(bool enabled);
 47+void EnableCull(bool enabled);
 48+void SetCull(D3DCULL mode);
4749
4850 #endif //_GLUTIL_H
\ No newline at end of file