DXGL r590 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r589‎ | r590 | r591 >
Date:01:50, 6 February 2015
Author:admin
Status:new
Tags:
Comment:
Remove texcoords parameter from shader ID.
Modified paths:
  • /ddraw/ShaderGen3D.cpp (modified) (history)
  • /ddraw/ShaderGen3D.h (modified) (history)
  • /ddraw/ShaderManager.cpp (modified) (history)
  • /ddraw/ShaderManager.h (modified) (history)
  • /ddraw/glDirect3DDevice.cpp (modified) (history)
  • /ddraw/glRenderer.cpp (modified) (history)

Diff [purge]

Index: ddraw/ShaderGen3D.cpp
@@ -70,6 +70,7 @@
7171 Bits 27-28 - Ambient material source VS
7272 Bits 29-30 - Emissive material source VS
7373 Bits 31-33 - Number of textures VS/FS
 74+Bit 34 - More than 0 textures VS/FS
7475 Bit 35 - Use diffuse color VS
7576 Bit 36 - Use specular color VS
7677 Bit 37 - Enable normals VS
@@ -153,7 +154,7 @@
154155 * 1 for generated 2D
155156 * 2 for generated 3D
156157 */
157 -void ShaderGen3D_SetShader(ShaderGen3D *This, __int64 id, __int64 *texstate, int *texcoords, int type, ShaderGen2D *gen2d)
 158+void ShaderGen3D_SetShader(ShaderGen3D *This, __int64 id, __int64 *texstate, int type, ShaderGen2D *gen2d)
158159 {
159160 int shaderindex = -1;
160161 switch(type)
@@ -215,14 +216,7 @@
216217 bool texidmatch = true;
217218 for(int j = 0; j < 8; j++)
218219 if(This->genshaders[i].texids[j] != texstate[j]) texidmatch = false;
219 - if(texidmatch)
220 - {
221 - if(!memcmp(This->genshaders[i].texcoords,texcoords,8*sizeof(int)))
222 - {
223 - shaderindex = i;
224 - break;
225 - }
226 - }
 220+ if(texidmatch) shaderindex = i;
227221 }
228222 }
229223 if(shaderindex == -1)
@@ -239,7 +233,7 @@
240234 String_Free(&This->genshaders[This->genindex].shader.fsrc);
241235 ZeroMemory(&This->genshaders[This->genindex],sizeof(GenShader));
242236 }
243 - ShaderGen3D_CreateShader(This, This->genindex,id,texstate,texcoords);
 237+ ShaderGen3D_CreateShader(This, This->genindex,id,texstate);
244238 shaderindex = This->genindex;
245239 This->genindex++;
246240 if(This->genindex >= 256) This->genindex = 0;
@@ -247,7 +241,6 @@
248242 This->genshaders[shaderindex].id = id;
249243 for(int i = 0; i < 8; i++)
250244 This->genshaders[shaderindex].texids[i] = texstate[i];
251 - memcpy(This->genshaders[shaderindex].texcoords,texcoords,8*sizeof(int));
252245 This->ext->glUseProgram(This->genshaders[shaderindex].shader.prog);
253246 This->current_prog = This->genshaders[shaderindex].shader.prog;
254247 This->current_genshader = shaderindex;
@@ -484,7 +477,7 @@
485478 * @param texcoords
486479 * Pointer to number of texture coordinates in each texture stage
487480 */
488 -void ShaderGen3D_CreateShader(ShaderGen3D *This, int index, __int64 id, __int64 *texstate, int *texcoords)
 481+void ShaderGen3D_CreateShader(ShaderGen3D *This, int index, __int64 id, __int64 *texstate)
489482 {
490483 STRING tmp;
491484 ZeroMemory(&tmp, sizeof(STRING));
@@ -496,8 +489,11 @@
497490 BOOL haskey = FALSE;
498491 int count;
499492 int numlights;
 493+ int numtex;
500494 int vertexfog,pixelfog;
501495 vertexfog = pixelfog = 0;
 496+ if ((id>>34)&1) numtex = ((id >> 31) & 7) + 1;
 497+ else numtex = 0;
502498 if((id>>61)&1)
503499 {
504500 vertexfog = (id>>8)&3;
@@ -542,25 +538,23 @@
543539 String_Append(vsrc, tmp.ptr);
544540 }
545541 }
546 - for(i = 0; i < 8; i++)
 542+ for(i = 0; i < numtex; i++)
547543 {
548 - switch(texcoords[i])
 544+ switch ((texstate[i] >> 51)&3)
549545 {
550 - case -1:
551 - continue;
552 - case 3:
 546+ case 0:
553547 String_Assign(&tmp,attr_s);
554548 tmp.ptr[16] = *(_itoa(i,idstring,10));
555549 break;
556 - case 0:
 550+ case 1:
557551 String_Assign(&tmp, attr_st);
558552 tmp.ptr[17] = *(_itoa(i,idstring,10));
559553 break;
560 - case 1:
 554+ case 2:
561555 String_Assign(&tmp, attr_str);
562556 tmp.ptr[18] = *(_itoa(i,idstring,10));
563557 break;
564 - case 2:
 558+ case 3:
565559 String_Assign(&tmp, attr_strq);
566560 tmp.ptr[19] = *(_itoa(i,idstring,10));
567561 break;
@@ -693,32 +687,28 @@
694688 tmp.ptr[12] = *(_itoa(i,idstring,10));
695689 String_Append(vsrc, tmp.ptr);
696690 texindex = (texstate[i]>>34)&3;
697 - switch(texcoords[texindex])
 691+ switch ((texstate[texindex] >> 51) & 3)
698692 {
699 - case -1: // No texcoords
700 - String_Append(vsrc, op_texpassthru2null);
 693+ case 0: // s
 694+ String_Assign(&tmp, op_texpassthru2s);
 695+ tmp.ptr[6] = *(_itoa(texindex, idstring, 10));
 696+ String_Append(vsrc, tmp.ptr);
701697 break;
702 - case 0: // st
 698+ case 1: // st
703699 String_Assign(&tmp, op_texpassthru2st);
704700 tmp.ptr[7] = *(_itoa(texindex,idstring,10));
705701 String_Append(vsrc, tmp.ptr);
706 - default:
707702 break;
708 - case 1: // str
 703+ case 2: // str
709704 String_Assign(&tmp, op_texpassthru2str);
710705 tmp.ptr[8] = *(_itoa(texindex,idstring,10));
711706 String_Append(vsrc, tmp.ptr);
712707 break;
713 - case 2: // strq
 708+ case 3: // strq
714709 String_Assign(&tmp, op_texpassthru2strq);
715710 tmp.ptr[4] = *(_itoa(texindex,idstring,10));
716711 String_Append(vsrc, tmp.ptr);
717712 break;
718 - case 3: // s
719 - String_Assign(&tmp, op_texpassthru2s);
720 - tmp.ptr[6] = *(_itoa(texindex,idstring,10));
721 - String_Append(vsrc, tmp.ptr);
722 - break;
723713 }
724714 }
725715 }
Index: ddraw/ShaderGen3D.h
@@ -38,7 +38,6 @@
3939 _GENSHADER shader;
4040 __int64 id;
4141 __int64 texids[8];
42 - int texcoords[8];
4342 } GenShader;
4443
4544 #define D3DTOP_DXGL_DECALMASK 0x101;
@@ -64,10 +63,10 @@
6564 void ShaderGen3D_Init(glExtensions *glext, ShaderManager *shaderman, ShaderGen3D *gen);
6665 void ShaderGen3D_Delete(ShaderGen3D *This);
6766 void ShaderGen3D_ClearShaders(ShaderGen3D *This);
68 -void ShaderGen3D_SetShader(ShaderGen3D *This, __int64 id, __int64 *texstate, int *texcoords, int type, ShaderGen2D *gen2d);
 67+void ShaderGen3D_SetShader(ShaderGen3D *This, __int64 id, __int64 *texstate, int type, ShaderGen2D *gen2d);
6968 GLuint ShaderGen3D_GetProgram(ShaderGen3D *This);
7069 void ShaderGen3D_ZeroShaderArray(ShaderGen3D *This);
71 -void ShaderGen3D_CreateShader(ShaderGen3D *This, int index, __int64 id, __int64 *texstate, int *texcoords);
 70+void ShaderGen3D_CreateShader(ShaderGen3D *This, int index, __int64 id, __int64 *texstate);
7271
7372 #ifdef __cplusplus
7473 }
Index: ddraw/ShaderManager.cpp
@@ -204,9 +204,9 @@
205205 free(This->gen3d);
206206 }
207207
208 -void ShaderManager_SetShader(ShaderManager *This, __int64 id, __int64 *texstate, int *texcoords, int type)
 208+void ShaderManager_SetShader(ShaderManager *This, __int64 id, __int64 *texstate, int type)
209209 {
210 - ShaderGen3D_SetShader(This->gen3d, id, texstate, texcoords, type, This->gen2d);
 210+ ShaderGen3D_SetShader(This->gen3d, id, texstate, type, This->gen2d);
211211 }
212212
213213 }
\ No newline at end of file
Index: ddraw/ShaderManager.h
@@ -61,7 +61,7 @@
6262
6363 void ShaderManager_Init(glExtensions *glext, ShaderManager *shaderman);
6464 void ShaderManager_Delete(ShaderManager *This);
65 -void ShaderManager_SetShader(ShaderManager *This, __int64 id, __int64 *texstate, int *texcoords, int type);
 65+void ShaderManager_SetShader(ShaderManager *This, __int64 id, __int64 *texstate, int type);
6666
6767 #ifdef __cplusplus
6868 }
Index: ddraw/glDirect3DDevice.cpp
@@ -814,6 +814,7 @@
815815 {
816816 TRACE_ENTER(3,14,this,9,dwVertexTypeDesc,14,vertptr);
817817 int i;
 818+ int texformats1[8];
818819 int ptr = 0;
819820 if((dwVertexTypeDesc & D3DFVF_XYZ) && (dwVertexTypeDesc & D3DFVF_XYZRHW))
820821 TRACE_RET(HRESULT,23,DDERR_INVALIDPARAMS);
@@ -865,22 +866,29 @@
866867 for(i = 0; i < 8; i++)
867868 {
868869 vertdata[i+10].data = &vertptr[ptr];
869 - if(i >= numtex) texformats[i] = -1;
870 - else texformats[i] = (dwVertexTypeDesc>>(16+(2*i))&3);
871 - switch(texformats[i])
 870+ if(i >= numtex) texformats1[i] = -1;
 871+ else texformats1[i] = (dwVertexTypeDesc>>(16+(2*i))&3);
 872+ switch(texformats1[i])
872873 {
873874 case 0: // st
874875 ptr += 2;
 876+ texformats[i] = 2;
875877 break;
876878 case 1: // str
877879 ptr += 3;
 880+ texformats[i] = 3;
878881 break;
879882 case 2: // strq
880883 ptr += 4;
 884+ texformats[i] = 4;
881885 break;
882886 case 3: // s
883887 ptr++;
 888+ texformats[i] = 1;
884889 break;
 890+ default:
 891+ texformats[i] = 2;
 892+ break;
885893 }
886894 }
887895 int stride = ptr*4;
Index: ddraw/glRenderer.cpp
@@ -1383,7 +1383,7 @@
13841384 if (dwFlags & DDBLT_KEYDEST) usedest = TRUE;
13851385 if (usedest)
13861386 {
1387 - ShaderManager_SetShader(This->shaders, PROG_TEXTURE, NULL, NULL, 0);
 1387+ ShaderManager_SetShader(This->shaders, PROG_TEXTURE, NULL, 0);
13881388 glRenderer__DrawBackbufferRect(This, dest->texture, destrect, PROG_TEXTURE);
13891389 This->bltvertices[1].dests = This->bltvertices[3].dests = 0.;
13901390 This->bltvertices[0].dests = This->bltvertices[2].dests = (GLfloat)(destrect.right - destrect.left) / (GLfloat)This->backx;
@@ -1390,7 +1390,7 @@
13911391 This->bltvertices[0].destt = This->bltvertices[1].destt = 1.;
13921392 This->bltvertices[2].destt = This->bltvertices[3].destt = 1.0-((GLfloat)(destrect.bottom - destrect.top) / (GLfloat)This->backy);
13931393 }
1394 - ShaderManager_SetShader(This->shaders, shaderid, NULL, NULL, 1);
 1394+ ShaderManager_SetShader(This->shaders, shaderid, NULL, 1);
13951395 GenShader2D *shader = &This->shaders->gen2d->genshaders2D[This->shaders->gen3d->current_genshader];
13961396 This->util->BlendEnable(false);
13971397 do
@@ -1699,7 +1699,7 @@
17001700 glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
17011701 if(This->ddInterface->GetBPP() == 8)
17021702 {
1703 - ShaderManager_SetShader(This->shaders,PROG_PAL256,NULL,NULL,0);
 1703+ ShaderManager_SetShader(This->shaders,PROG_PAL256,NULL,0);
17041704 progtype = PROG_PAL256;
17051705 TextureManager__UploadTexture(This->texman,paltex,0,glDirectDrawPalette_GetPalette(dest->palette,NULL),256,1,FALSE,FALSE);
17061706 This->ext->glUniform1i(This->shaders->shaders[progtype].tex0,0);
@@ -1709,7 +1709,7 @@
17101710 if(dxglcfg.scalingfilter)
17111711 {
17121712 glRenderer__DrawBackbuffer(This,&texture,dest->fakex,dest->fakey,progtype);
1713 - ShaderManager_SetShader(This->shaders,PROG_TEXTURE,NULL,NULL,0);
 1713+ ShaderManager_SetShader(This->shaders,PROG_TEXTURE,NULL,0);
17141714 progtype = PROG_TEXTURE;
17151715 TextureManager_SetTexture(This->texman,0,texture);
17161716 This->ext->glUniform1i(This->shaders->shaders[progtype].tex0,0);
@@ -1722,7 +1722,7 @@
17231723 }
17241724 else
17251725 {
1726 - ShaderManager_SetShader(This->shaders,PROG_TEXTURE,NULL,NULL,0);
 1726+ ShaderManager_SetShader(This->shaders,PROG_TEXTURE,NULL,0);
17271727 progtype = PROG_TEXTURE;
17281728 TextureManager_SetTexture(This->texman,0,texture);
17291729 This->ext->glUniform1i(This->shaders->shaders[progtype].tex0,0);
@@ -2135,11 +2135,16 @@
21362136 SetEvent(This->busy);
21372137 return;
21382138 }
2139 - This->shaderstate3d.stateid &= 0xFFFA3FFC7FFFFFFFi64;
 2139+ This->shaderstate3d.stateid &= 0xFFFA3FF87FFFFFFFi64;
21402140 int numtextures = 0;
21412141 for (i = 0; i < 8; i++)
 2142+ {
 2143+ This->shaderstate3d.texstageid[i] &= 0xFFE7FFFFFFFFFFFFi64;
 2144+ This->shaderstate3d.texstageid[i] |= (__int64)(texformats[i] - 1) << 51;
21422145 if (vertices[i + 10].data) numtextures++;
2143 - This->shaderstate3d.stateid |= (__int64)numtextures << 31;
 2146+ }
 2147+ This->shaderstate3d.stateid |= (__int64)((numtextures-1)&7) << 31;
 2148+ if (numtextures) This->shaderstate3d.stateid |= (1i64 << 34);
21442149 int blendweights = 0;
21452150 for (i = 0; i < 5; i++)
21462151 if (vertices[i + 2].data) blendweights++;
@@ -2148,7 +2153,7 @@
21492154 if (vertices[8].data) This->shaderstate3d.stateid |= (1i64 << 35);
21502155 if (vertices[9].data) This->shaderstate3d.stateid |= (1i64 << 36);
21512156 if (vertices[7].data) This->shaderstate3d.stateid |= (1i64 << 37);
2152 - ShaderManager_SetShader(This->shaders,This->shaderstate3d.stateid,This->shaderstate3d.texstageid,texformats,2);
 2157+ ShaderManager_SetShader(This->shaders,This->shaderstate3d.stateid,This->shaderstate3d.texstageid,2);
21532158 glRenderer__SetDepthComp(This);
21542159 if(This->renderstate[D3DRENDERSTATE_ZENABLE]) This->util->DepthTest(true);
21552160 else This->util->DepthTest(false);
@@ -2202,7 +2207,14 @@
22032208 {
22042209 case -1: // Null
22052210 break;
2206 - case 0: // st
 2211+ case 1: // s
 2212+ if (prog->attribs[i + 10] != -1)
 2213+ {
 2214+ This->util->EnableArray(prog->attribs[i + 10], true);
 2215+ This->ext->glVertexAttribPointer(prog->attribs[i + 10], 1, GL_FLOAT, false, vertices[i + 10].stride, vertices[i + 10].data);
 2216+ }
 2217+ break;
 2218+ case 2: // st
22072219 if(prog->attribs[i+18] != -1)
22082220 {
22092221 This->util->EnableArray(prog->attribs[i+18],true);
@@ -2209,7 +2221,7 @@
22102222 This->ext->glVertexAttribPointer(prog->attribs[i+18],2,GL_FLOAT,false,vertices[i+10].stride,vertices[i+10].data);
22112223 }
22122224 break;
2213 - case 1: // str
 2225+ case 3: // str
22142226 if(prog->attribs[i+26] != -1)
22152227 {
22162228 This->util->EnableArray(prog->attribs[i+26],true);
@@ -2216,7 +2228,7 @@
22172229 This->ext->glVertexAttribPointer(prog->attribs[i+26],3,GL_FLOAT,false,vertices[i+10].stride,vertices[i+10].data);
22182230 }
22192231 break;
2220 - case 2: // strq
 2232+ case 4: // strq
22212233 if(prog->attribs[i+34] != -1)
22222234 {
22232235 This->util->EnableArray(prog->attribs[i+34],true);
@@ -2223,13 +2235,6 @@
22242236 This->ext->glVertexAttribPointer(prog->attribs[i+34],4,GL_FLOAT,false,vertices[i+10].stride,vertices[i+10].data);
22252237 }
22262238 break;
2227 - case 3: // s
2228 - if(prog->attribs[i+10] != -1)
2229 - {
2230 - This->util->EnableArray(prog->attribs[i+10],true);
2231 - This->ext->glVertexAttribPointer(prog->attribs[i+10],1,GL_FLOAT,false,vertices[i+10].stride,vertices[i+10].data);
2232 - }
2233 - break;
22342239 }
22352240
22362241 }
@@ -2396,7 +2401,7 @@
23972402 view[3] = (GLfloat)surface->ddsd.dwHeight;
23982403 This->util->SetViewport(0,0,surface->ddsd.dwWidth,surface->ddsd.dwHeight);
23992404 glClear(GL_COLOR_BUFFER_BIT);
2400 - ShaderManager_SetShader(This->shaders,PROG_CLIPSTENCIL,NULL,NULL,0);
 2405+ ShaderManager_SetShader(This->shaders,PROG_CLIPSTENCIL,NULL,0);
24012406 This->ext->glUniform4f(This->shaders->shaders[PROG_CLIPSTENCIL].view,view[0],view[1],view[2],view[3]);
24022407 This->util->EnableArray(This->shaders->shaders[PROG_CLIPSTENCIL].pos,true);
24032408 This->ext->glVertexAttribPointer(This->shaders->shaders[PROG_CLIPSTENCIL].pos,

Follow-up revisions

RevisionCommit summaryAuthorDate
r603Revert ddraw.dll to r590 (removing all recent async code)admin00:21, 11 March 2015