DXGL r239 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r238‎ | r239 | r240 >
Date:21:16, 12 August 2012
Author:admin
Status:new
Tags:
Comment:
Add D3D Alpha Blending.
Add Alpha Blending to Texture Shader test.
Modified paths:
  • /ddraw/glRenderer.cpp (modified) (history)
  • /ddraw/glutil.cpp (modified) (history)
  • /ddraw/glutil.h (modified) (history)
  • /dxgltest/Resource.h (modified) (history)
  • /dxgltest/Tests3D.cpp (modified) (history)
  • /dxgltest/dxgltest.rc (modified) (history)

Diff [purge]

Index: ddraw/glRenderer.cpp
@@ -812,6 +812,8 @@
813813 ClearDepth(1.0);
814814 ClearStencil(0);
815815 EnableArray(-1,false);
 816+ BlendFunc(GL_ONE,GL_ZERO);
 817+ BlendEnable(false);
816818 glClear(GL_COLOR_BUFFER_BIT);
817819 glFlush();
818820 SetScissor(false,0,0,0,0);
@@ -848,6 +850,7 @@
849851 int progtype;
850852 LONG sizes[6];
851853 ddInterface->GetSizes(sizes);
 854+ BlendEnable(false);
852855 int error;
853856 error = SetFBO(dest->texture,0,false);
854857 SetViewport(0,0,dest->fakex,dest->fakey);
@@ -1043,6 +1046,7 @@
10441047 {
10451048 int progtype;
10461049 RECT r,r2;
 1050+ BlendEnable(false);
10471051 if((dest->ddsd.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE))
10481052 {
10491053 GetClientRect(hWnd,&r);
@@ -1293,6 +1297,108 @@
12941298 SetEvent(busy);
12951299 }
12961300
 1301+void SetBlend(DWORD src, DWORD dest)
 1302+{
 1303+ GLenum glsrc, gldest;
 1304+ bool bothalpha = false;
 1305+ switch(src)
 1306+ {
 1307+ case D3DBLEND_ZERO:
 1308+ glsrc = GL_ZERO;
 1309+ break;
 1310+ case D3DBLEND_ONE:
 1311+ default:
 1312+ glsrc = GL_ONE;
 1313+ break;
 1314+ case D3DBLEND_SRCCOLOR:
 1315+ glsrc = GL_SRC_COLOR;
 1316+ break;
 1317+ case D3DBLEND_INVSRCCOLOR:
 1318+ glsrc = GL_ONE_MINUS_SRC_COLOR;
 1319+ break;
 1320+ case D3DBLEND_SRCALPHA:
 1321+ glsrc = GL_SRC_ALPHA;
 1322+ break;
 1323+ case D3DBLEND_INVSRCALPHA:
 1324+ glsrc = GL_ONE_MINUS_SRC_ALPHA;
 1325+ break;
 1326+ case D3DBLEND_DESTALPHA:
 1327+ glsrc = GL_DST_ALPHA;
 1328+ break;
 1329+ case D3DBLEND_INVDESTALPHA:
 1330+ glsrc = GL_ONE_MINUS_DST_ALPHA;
 1331+ break;
 1332+ case D3DBLEND_DESTCOLOR:
 1333+ glsrc = GL_DST_COLOR;
 1334+ break;
 1335+ case D3DBLEND_INVDESTCOLOR:
 1336+ glsrc = GL_ONE_MINUS_DST_COLOR;
 1337+ break;
 1338+ case D3DBLEND_SRCALPHASAT:
 1339+ glsrc = GL_SRC_ALPHA_SATURATE;
 1340+ break;
 1341+ case D3DBLEND_BOTHSRCALPHA:
 1342+ bothalpha = true;
 1343+ glsrc = GL_SRC_ALPHA;
 1344+ gldest = GL_ONE_MINUS_SRC_ALPHA;
 1345+ break;
 1346+ case D3DBLEND_BOTHINVSRCALPHA:
 1347+ bothalpha = true;
 1348+ glsrc = GL_ONE_MINUS_SRC_ALPHA;
 1349+ gldest = GL_SRC_ALPHA;
 1350+ break;
 1351+ }
 1352+
 1353+ if(!bothalpha) switch(dest)
 1354+ {
 1355+ case D3DBLEND_ZERO:
 1356+ default:
 1357+ gldest = GL_ZERO;
 1358+ break;
 1359+ case D3DBLEND_ONE:
 1360+ gldest = GL_ONE;
 1361+ break;
 1362+ case D3DBLEND_SRCCOLOR:
 1363+ gldest = GL_SRC_COLOR;
 1364+ break;
 1365+ case D3DBLEND_INVSRCCOLOR:
 1366+ gldest = GL_ONE_MINUS_SRC_COLOR;
 1367+ break;
 1368+ case D3DBLEND_SRCALPHA:
 1369+ gldest = GL_SRC_ALPHA;
 1370+ break;
 1371+ case D3DBLEND_INVSRCALPHA:
 1372+ gldest = GL_ONE_MINUS_SRC_ALPHA;
 1373+ break;
 1374+ case D3DBLEND_DESTALPHA:
 1375+ gldest = GL_DST_ALPHA;
 1376+ break;
 1377+ case D3DBLEND_INVDESTALPHA:
 1378+ gldest = GL_ONE_MINUS_DST_ALPHA;
 1379+ break;
 1380+ case D3DBLEND_DESTCOLOR:
 1381+ gldest = GL_DST_COLOR;
 1382+ break;
 1383+ case D3DBLEND_INVDESTCOLOR:
 1384+ gldest = GL_ONE_MINUS_DST_COLOR;
 1385+ break;
 1386+ case D3DBLEND_SRCALPHASAT:
 1387+ gldest = GL_SRC_ALPHA_SATURATE;
 1388+ break;
 1389+ case D3DBLEND_BOTHSRCALPHA:
 1390+ bothalpha = true;
 1391+ glsrc = GL_SRC_ALPHA;
 1392+ gldest = GL_ONE_MINUS_SRC_ALPHA;
 1393+ break;
 1394+ case D3DBLEND_BOTHINVSRCALPHA:
 1395+ bothalpha = true;
 1396+ glsrc = GL_ONE_MINUS_SRC_ALPHA;
 1397+ gldest = GL_SRC_ALPHA;
 1398+ break;
 1399+ }
 1400+ BlendFunc(glsrc,gldest);
 1401+}
 1402+
12971403 void glRenderer::_DrawPrimitives(glDirect3DDevice7 *device, GLenum mode, GLVERTEX *vertices, int *texformats, DWORD count, LPWORD indices,
12981404 DWORD indexcount, DWORD flags)
12991405 {
@@ -1476,6 +1582,9 @@
14771583 else SetFBO(device->glDDS7->texture,0,false);
14781584 SetViewport(device->viewport.dwX,device->viewport.dwY,device->viewport.dwWidth,device->viewport.dwHeight);
14791585 SetDepthRange(device->viewport.dvMinZ,device->viewport.dvMaxZ);
 1586+ if(device->renderstate[D3DRENDERSTATE_ALPHABLENDENABLE]) BlendEnable(true);
 1587+ else BlendEnable(false);
 1588+ SetBlend(device->renderstate[D3DRENDERSTATE_SRCBLEND],device->renderstate[D3DRENDERSTATE_DESTBLEND]);
14801589 if(indices) glDrawElements(mode,indexcount,GL_UNSIGNED_SHORT,indices);
14811590 else glDrawArrays(mode,0,count);
14821591 if(device->glDDS7->zbuffer) device->glDDS7->zbuffer->dirty |= 2;
Index: ddraw/glutil.cpp
@@ -51,6 +51,9 @@
5252 GLclampf cleara = 0.0;
5353 GLclampd cleardepth = 1.0;
5454 GLint clearstencil = 0;
 55+GLenum blendsrc = GL_ONE;
 56+GLenum blenddest = GL_ZERO;
 57+bool blendenabled = false;
5558 bool arrays[42];
5659
5760 void InitFBO()
@@ -345,4 +348,24 @@
346349 if(enabled) glEnableVertexAttribArray(index);
347350 else glDisableVertexAttribArray(index);
348351 }
 352+}
 353+
 354+void BlendFunc(GLenum src, GLenum dest)
 355+{
 356+ if((blendsrc != src) || (blenddest != dest))
 357+ {
 358+ blendsrc = src;
 359+ blenddest = dest;
 360+ glBlendFunc(src,dest);
 361+ }
 362+}
 363+
 364+void BlendEnable(bool enabled)
 365+{
 366+ if(enabled != blendenabled)
 367+ {
 368+ blendenabled = enabled;
 369+ if(enabled) glEnable(GL_BLEND);
 370+ else glDisable(GL_BLEND);
 371+ }
349372 }
\ No newline at end of file
Index: ddraw/glutil.h
@@ -42,5 +42,7 @@
4343 void ClearDepth(GLclampd depth);
4444 void ClearStencil(GLint stencil);
4545 void EnableArray(int index, bool enabled);
 46+void BlendFunc(GLenum src, GLenum dest);
 47+void BlendEnable(bool enabled);
4648
4749 #endif //_GLUTIL_H
\ No newline at end of file
Index: dxgltest/Resource.h
@@ -39,6 +39,7 @@
4040 #define IDC_TEXTUREPREVIEW 1003
4141 #define IDC_DISPLAY 1004
4242 #define IDC_TESTLIST 1004
 43+#define IDC_ALPHABLEND 1006
4344 #define IDC_BGCOLOR 1007
4445 #define IDC_WINDOWED 1008
4546 #define IDC_FULLSCREEN 1009
@@ -98,7 +99,6 @@
99100 #define IDC_FACTORSELECT 1085
100101 #define IDC_FOGCOLOR 1086
101102 #define IDC_FOGCOLORSELECT 1087
102 -#define IDC_ALPHATEST 1088
103103 #define IDC_SRCBLEND 1089
104104 #define IDC_DESTBLEND 1090
105105 #define IDC_ALPHAREF 1091
@@ -113,3 +113,4 @@
114114 #define IDC_FOGDENSITY 1100
115115 #define IDC_RANGEBASEDFOG 1101
116116 #define IDC_BGCOLORSELECT 1102
 117+#define IDC_ALPHATEST 1103
Index: dxgltest/Tests3D.cpp
@@ -1286,6 +1286,28 @@
12871287 d3d7dev->SetRenderState(D3DRENDERSTATE_TEXTUREFACTOR,number);
12881288 }
12891289 break;
 1290+ case IDC_ALPHABLEND:
 1291+ if(HIWORD(wParam) == BN_CLICKED)
 1292+ {
 1293+ if(SendDlgItemMessage(hWnd,IDC_ALPHABLEND,BM_GETCHECK,0,0) == BST_CHECKED)
 1294+ d3d7dev->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE,TRUE);
 1295+ else d3d7dev->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE,FALSE);
 1296+ }
 1297+ break;
 1298+ case IDC_SRCBLEND:
 1299+ if(HIWORD(wParam) == CBN_SELCHANGE)
 1300+ {
 1301+ d3d7dev->SetRenderState(D3DRENDERSTATE_SRCBLEND,SendDlgItemMessage(hWnd,
 1302+ IDC_SRCBLEND,CB_GETCURSEL,0,0)+1);
 1303+ }
 1304+ case IDC_DESTBLEND:
 1305+ if(HIWORD(wParam) == CBN_SELCHANGE)
 1306+ {
 1307+ d3d7dev->SetRenderState(D3DRENDERSTATE_DESTBLEND,SendDlgItemMessage(hWnd,
 1308+ IDC_DESTBLEND,CB_GETCURSEL,0,0)+1);
 1309+ }
 1310+ break;
 1311+
12901312 }
12911313 break;
12921314 case WM_CLOSE:
Index: dxgltest/dxgltest.rc
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream