DXGL r142 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r141‎ | r142 | r143 >
Date:20:00, 28 April 2012
Author:admin
Status:new
Tags:
Comment:
Update D3D caps bits
Fix render failure if texcoords are used by vertex but not fragment shader
Modified paths:
  • /ddraw/glDirect3D.cpp (modified) (history)
  • /ddraw/glDirect3DDevice.cpp (modified) (history)
  • /ddraw/glRenderer.cpp (modified) (history)
  • /ddraw/glRenderer.h (modified) (history)
  • /ddraw/shadergen.cpp (modified) (history)

Diff [purge]

Index: ddraw/glDirect3D.cpp
@@ -25,18 +25,22 @@
2626 D3DDEVICEDESC7 d3ddesc =
2727 {
2828 D3DDEVCAPS_CANBLTSYSTONONLOCAL | D3DDEVCAPS_CANRENDERAFTERFLIP | D3DDEVCAPS_DRAWPRIMTLVERTEX |
29 - D3DDEVCAPS_FLOATTLVERTEX, // dwDevCaps
 29+ D3DDEVCAPS_FLOATTLVERTEX | D3DDEVCAPS_TEXTURENONLOCALVIDMEM | D3DDEVCAPS_TEXTURESYSTEMMEMORY |
 30+ D3DDEVCAPS_TEXTUREVIDEOMEMORY | D3DDEVCAPS_TLVERTEXSYSTEMMEMORY | D3DDEVCAPS_TLVERTEXVIDEOMEMORY, // dwDevCaps
3031 { //dpcLineCaps
3132 sizeof(D3DPRIMCAPS),
3233 0, // dwMiscCaps
3334 D3DPRASTERCAPS_SUBPIXEL | D3DPRASTERCAPS_ZTEST, //dwRasterCaps
3435 D3DPCMPCAPS_LESSEQUAL, //dwZCmpCaps
35 - DDBD_16|DDBD_24|DDBD_32, //dwSrcBlendCaps
36 - DDBD_16|DDBD_24|DDBD_32, //dwDestBlendCaps
 36+ 0, //dwSrcBlendCaps
 37+ 0, //dwDestBlendCaps
3738 0, //dwAlphaCmpCaps
38 - 0, //dwShadeCaps
39 - 0, //dwTextureCaps
40 - 0, //dwTextureFilterCaps
 39+ D3DPSHADECAPS_COLORGOURAUDRGB, //dwShadeCaps
 40+ D3DPTEXTURECAPS_PERSPECTIVE, //dwTextureCaps
 41+ D3DPTFILTERCAPS_NEAREST | D3DPTFILTERCAPS_LINEAR | D3DPTFILTERCAPS_MIPNEAREST |
 42+ D3DPTFILTERCAPS_MIPLINEAR | D3DPTFILTERCAPS_LINEARMIPNEAREST | D3DPTFILTERCAPS_LINEARMIPLINEAR |
 43+ D3DPTFILTERCAPS_MAGFLINEAR | D3DPTFILTERCAPS_MAGFPOINT | D3DPTFILTERCAPS_MINFLINEAR |
 44+ D3DPTFILTERCAPS_MINFPOINT, //dwTextureFilterCaps
4145 0, //dwTextureBlendCaps
4246 0, //dwTextureAddressCaps
4347 0, //dwStippleWidth
@@ -50,9 +54,12 @@
5155 0, //dwSrcBlendCaps
5256 0, //dwDestBlendCaps
5357 0, //dwAlphaCmpCaps
54 - 0, //dwShadeCaps
55 - 0, //dwTextureCaps
56 - 0, //dwTextureFilterCaps
 58+ D3DPSHADECAPS_COLORGOURAUDRGB, //dwShadeCaps
 59+ D3DPTEXTURECAPS_PERSPECTIVE, //dwTextureCaps
 60+ D3DPTFILTERCAPS_NEAREST | D3DPTFILTERCAPS_LINEAR | D3DPTFILTERCAPS_MIPNEAREST |
 61+ D3DPTFILTERCAPS_MIPLINEAR | D3DPTFILTERCAPS_LINEARMIPNEAREST | D3DPTFILTERCAPS_LINEARMIPLINEAR |
 62+ D3DPTFILTERCAPS_MAGFLINEAR | D3DPTFILTERCAPS_MAGFPOINT | D3DPTFILTERCAPS_MINFLINEAR |
 63+ D3DPTFILTERCAPS_MINFPOINT, //dwTextureFilterCaps
5764 0, //dwTextureBlendCaps
5865 0, //dwTextureAddressCaps
5966 0, //dwStippleWidth
@@ -60,8 +67,8 @@
6168 },
6269 DDBD_16|DDBD_24|DDBD_32, //dwDeviceRenderBitDepth
6370 DDBD_16|DDBD_24|DDBD_32, //dwDeviceZBufferBitDepth
64 - 0, //dwMinTextureWidth
65 - 0, //dwMinTextureHeight
 71+ 1, //dwMinTextureWidth
 72+ 1, //dwMinTextureHeight
6673 0, //dwMaxTextureWidth
6774 0, //dwMaxTextureHeight
6875 0, //dwMaxTextureRepeat
@@ -74,9 +81,10 @@
7582 0.0f, //dvExtentsAdjust
7683 0, //dwStencilCaps
7784 8, //dwFVFCaps
78 - 0, //dwTextureOpCaps
79 - 0, //wMaxTextureBlendStages
80 - 0, //wMaxSimultaneousTextures
 85+ D3DTEXOPCAPS_SELECTARG1 | D3DTEXOPCAPS_SELECTARG2 | D3DTOP_MODULATE |
 86+ D3DTOP_MODULATE2X | D3DTOP_MODULATE4X | D3DTOP_ADD, //dwTextureOpCaps
 87+ 8, //wMaxTextureBlendStages
 88+ 8, //wMaxSimultaneousTextures
8189 8, //dwMaxActiveLights
8290 0.0f, //dvMaxVertexW
8391 IID_IDirect3DHALDevice, //deviceGUID
Index: ddraw/glDirect3DDevice.cpp
@@ -28,6 +28,8 @@
2929 #include "glutil.h"
3030 #include "matrix.h"
3131
 32+extern D3DDEVICEDESC7 d3ddesc;
 33+
3234 const DWORD renderstate_default[153] = {0, // 0
3335 NULL, //texturehandle
3436 D3DANTIALIAS_NONE, //antialias
@@ -173,8 +175,10 @@
174176 0,
175177 D3DTTFF_DISABLE,
176178 NULL,
 179+ false,
177180 0,
178 - 0
 181+ GL_NEAREST,
 182+ GL_NEAREST
179183 };
180184
181185 int setdrawmode(D3DPRIMITIVETYPE d3dptPrimitiveType)
@@ -228,6 +232,8 @@
229233 ZeroMemory(lights,16*sizeof(glDirect3DLight*));
230234 memset(gllights,0xff,8*sizeof(int));
231235 memset(gltextures,0,8*sizeof(GLuint));
 236+ d3ddesc.dwMaxTextureWidth = d3ddesc.dwMaxTextureHeight =
 237+ d3ddesc.dwMaxTextureRepeat = d3ddesc.dwMaxTextureAspectRatio = glD3D7->glDD7->renderer->gl_caps.TextureMax;
232238 glD3D7->glDD7->renderer->InitD3D(zbuffer);
233239 }
234240 glDirect3DDevice7::~glDirect3DDevice7()
@@ -371,7 +377,7 @@
372378 shader |= ((renderstate[D3DRENDERSTATE_AMBIENTMATERIALSOURCE] & 3) << 27);
373379 shader |= ((renderstate[D3DRENDERSTATE_EMISSIVEMATERIALSOURCE] & 3) << 29);
374380 int numtextures = 0;
375 - for(int i = 0; i < 8; i++)
 381+ for(i = 0; i < 8; i++)
376382 if(VertexType[i+10].data) numtextures++;
377383 shader |= (__int64)numtextures << 31;
378384 if(VertexType[8].data) shader |= (1i64<<35);
@@ -416,10 +422,10 @@
417423 texstages[i].shaderid |= (__int64)(((texstages[i].textransform & 7) - 1)& 3) << 51;
418424 }
419425 if(texstages[i].textransform & D3DTTFF_PROJECTED) texstages[i].shaderid |= 1i64 << 53;
 426+ texstages[i].shaderid |= (__int64)(texstages[i].texcoordindex&7) << 54;
 427+ texstages[i].shaderid |= (__int64)((texstages[i].texcoordindex>>16)&3) << 57;
 428+ if(texstages[i].texture) texstages[i].shaderid |= 1i64 << 59;
420429 }
421 - texstages[i].shaderid |= (__int64)(texstages[i].texcoordindex&7) << 54;
422 - texstages[i].shaderid |= (__int64)((texstages[i].texcoordindex>>16)&3) << 57;
423 - if(texstages[i].texture) texstages[i].shaderid |= 1i64 << 59;
424430 return shader;
425431 }
426432
@@ -1154,8 +1160,24 @@
11551161 HRESULT WINAPI glDirect3DDevice7::ValidateDevice(LPDWORD lpdwPasses)
11561162 {
11571163 if(!this) return DDERR_INVALIDPARAMS;
1158 - FIXME("glDirect3DDevice7::ValidateDevice: stub");
1159 - ERR(DDERR_GENERIC);
 1164+ for(int i = 0; i < 8; i++)
 1165+ {
 1166+ switch(texstages[i].colorop)
 1167+ {
 1168+ case D3DTOP_DISABLE:
 1169+ case D3DTOP_SELECTARG1:
 1170+ case D3DTOP_SELECTARG2:
 1171+ case D3DTOP_MODULATE:
 1172+ case D3DTOP_MODULATE2X:
 1173+ case D3DTOP_MODULATE4X:
 1174+ case D3DTOP_ADD:
 1175+ break;
 1176+ default:
 1177+ return D3DERR_UNSUPPORTEDCOLOROPERATION;
 1178+ }
 1179+ }
 1180+ if(lpdwPasses) *lpdwPasses = 1;
 1181+ return D3D_OK;
11601182 }
11611183
11621184 void glDirect3DDevice7::UpdateNormalMatrix()
Index: ddraw/glRenderer.cpp
@@ -541,6 +541,7 @@
542542 gl_caps.ShaderVer = (GLfloat)atof((char*)glver);
543543 }
544544 else gl_caps.ShaderVer = 0;
 545+ glGetIntegerv(GL_MAX_TEXTURE_SIZE,&gl_caps.TextureMax);
545546 CompileShaders();
546547 InitFBO();
547548 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
@@ -1070,20 +1071,32 @@
10711072 case -1: // Null
10721073 break;
10731074 case 0: // st
1074 - glEnableVertexAttribArray(prog.attribs[i+18]);
1075 - glVertexAttribPointer(prog.attribs[i+18],2,GL_FLOAT,false,vertices[i+10].stride,vertices[i+10].data);
 1075+ if(prog.attribs[i+18] != -1)
 1076+ {
 1077+ glEnableVertexAttribArray(prog.attribs[i+18]);
 1078+ glVertexAttribPointer(prog.attribs[i+18],2,GL_FLOAT,false,vertices[i+10].stride,vertices[i+10].data);
 1079+ }
10761080 break;
10771081 case 1: // str
1078 - glEnableVertexAttribArray(prog.attribs[i+26]);
1079 - glVertexAttribPointer(prog.attribs[i+26],3,GL_FLOAT,false,vertices[i+10].stride,vertices[i+10].data);
 1082+ if(prog.attribs[i+26] != -1)
 1083+ {
 1084+ glEnableVertexAttribArray(prog.attribs[i+26]);
 1085+ glVertexAttribPointer(prog.attribs[i+26],3,GL_FLOAT,false,vertices[i+10].stride,vertices[i+10].data);
 1086+ }
10801087 break;
10811088 case 2: // strq
1082 - glEnableVertexAttribArray(prog.attribs[i+34]);
1083 - glVertexAttribPointer(prog.attribs[i+34],4,GL_FLOAT,false,vertices[i+10].stride,vertices[i+10].data);
 1089+ if(prog.attribs[i+34] != -1)
 1090+ {
 1091+ glEnableVertexAttribArray(prog.attribs[i+34]);
 1092+ glVertexAttribPointer(prog.attribs[i+34],4,GL_FLOAT,false,vertices[i+10].stride,vertices[i+10].data);
 1093+ }
10841094 break;
10851095 case 3: // s
1086 - glEnableVertexAttribArray(prog.attribs[i+10]);
1087 - glVertexAttribPointer(prog.attribs[i+10],1,GL_FLOAT,false,vertices[i+10].stride,vertices[i+10].data);
 1096+ if(prog.attribs[i+10] != -1)
 1097+ {
 1098+ glEnableVertexAttribArray(prog.attribs[i+10]);
 1099+ glVertexAttribPointer(prog.attribs[i+10],1,GL_FLOAT,false,vertices[i+10].stride,vertices[i+10].data);
 1100+ }
10881101 break;
10891102 }
10901103
Index: ddraw/glRenderer.h
@@ -22,12 +22,7 @@
2323 {
2424 float Version;
2525 float ShaderVer;
26 - int TextureMaxX;
27 - int TextureMaxY;
28 - bool NonPowerOfTwo;
29 - int RenderToTexture; // 0 - no support, 1 -
30 - int MultiTextureExt;
31 - int PalettedTextures;
 26+ GLint TextureMax;
3227 } GLCAPS;
3328 typedef struct
3429 {
@@ -98,6 +93,7 @@
9994 DWORD indexcount, DWORD flags);
10095 HGLRC hRC;
10196 LRESULT WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
 97+ GLCAPS gl_caps;
10298 private:
10399 // In-thread APIs
104100 DWORD _Entry();
@@ -124,7 +120,6 @@
125121 HWND hWnd;
126122 HWND hRenderWnd;
127123 bool hasHWnd;
128 - GLCAPS gl_caps;
129124 DIB dib;
130125 GLuint PBO;
131126 CRITICAL_SECTION cs;
Index: ddraw/shadergen.cpp
@@ -197,6 +197,7 @@
198198 static const char attr_xyz[] = "attribute vec3 xyz;\n";
199199 static const char attr_rhw[] = "attribute float rhw;\n";
200200 static const char attr_nxyz[] = "attribute vec3 nxyz;\n";
 201+static const char const_nxyz[] = "const vec3 nxyz = vec3(0,0,0);\n";
201202 static const char attr_blend[] = "attribute float blendX;\n";
202203 static const char attr_rgba[] = "attribute vec4 rgbaX;\n";
203204 static const char attr_s[] = "attribute float sX;\n";
@@ -333,6 +334,7 @@
334335 vsrc->append(tmp);
335336 }
336337 if((id>>37)&1) vsrc->append(attr_nxyz);
 338+ else vsrc->append(const_nxyz);
337339 count = (id>>46)&7;
338340 if(count)
339341 {
@@ -531,6 +533,7 @@
532534 fsrc->append(op_colorfragin);
533535 string arg1,arg2;
534536 int args[4];
 537+ bool texfail;
535538 const string blendargs[] = {"color","gl_Color","texture2DProj(texX,gl_TexCoord[Y]).rgb",
536539 "texture2DProj(texX,gl_TexCoord[Y]).a","texfactor","gl_SecondaryColor","vec3(1,1,1)","1"};
537540 for(i = 0; i < 8; i++)
@@ -537,6 +540,7 @@
538541 {
539542 if((texstate[i].shaderid & 31) == D3DTOP_DISABLE)break;
540543 // Color stage
 544+ texfail = false;
541545 args[0] = (texstate[i].shaderid>>5)&63;
542546 switch(args[0]&7) //arg1
543547 {
@@ -548,9 +552,13 @@
549553 arg1 = blendargs[1];
550554 break;
551555 case D3DTA_TEXTURE:
552 - arg1 = blendargs[2];
553 - arg1.replace(17,1,_itoa(i,idstring,10));
554 - arg1.replace(31,1,_itoa((texstate[i].shaderid>>54)&7,idstring,10));
 556+ if((texstate[i].shaderid >> 59)&1)
 557+ {
 558+ arg1 = blendargs[2];
 559+ arg1.replace(17,1,_itoa(i,idstring,10));
 560+ arg1.replace(31,1,_itoa((texstate[i].shaderid>>54)&7,idstring,10));
 561+ }
 562+ else texfail = true;
555563 break;
556564 case D3DTA_TFACTOR:
557565 FIXME("Support texture factor value");
@@ -571,9 +579,13 @@
572580 arg2 = blendargs[1];
573581 break;
574582 case D3DTA_TEXTURE:
575 - arg2 = blendargs[3];
576 - arg2.replace(17,1,_itoa(i,idstring,10));
577 - arg2.replace(31,1,_itoa((texstate[i].shaderid>>54)&7,idstring,10));
 583+ if((texstate[i].shaderid >> 59)&1)
 584+ {
 585+ arg2 = blendargs[3];
 586+ arg2.replace(17,1,_itoa(i,idstring,10));
 587+ arg2.replace(31,1,_itoa((texstate[i].shaderid>>54)&7,idstring,10));
 588+ }
 589+ else texfail = true;
578590 break;
579591 case D3DTA_TFACTOR:
580592 FIXME("Support texture factor value");
@@ -583,7 +595,7 @@
584596 arg2 = blendargs[5];
585597 break;
586598 }
587 - switch(texstate[i].shaderid & 31)
 599+ if(!texfail) switch(texstate[i].shaderid & 31)
588600 {
589601 case D3DTOP_DISABLE:
590602 default: