Index: ddraw/ShaderGen3D.cpp |
— | — | @@ -70,6 +70,7 @@ |
71 | 71 | Bits 27-28 - Ambient material source VS
|
72 | 72 | Bits 29-30 - Emissive material source VS
|
73 | 73 | Bits 31-33 - Number of textures VS/FS
|
| 74 | +Bit 34 - More than 0 textures VS/FS
|
74 | 75 | Bit 35 - Use diffuse color VS
|
75 | 76 | Bit 36 - Use specular color VS
|
76 | 77 | Bit 37 - Enable normals VS
|
— | — | @@ -153,7 +154,7 @@ |
154 | 155 | * 1 for generated 2D
|
155 | 156 | * 2 for generated 3D
|
156 | 157 | */
|
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)
|
158 | 159 | {
|
159 | 160 | int shaderindex = -1;
|
160 | 161 | switch(type)
|
— | — | @@ -215,14 +216,7 @@ |
216 | 217 | bool texidmatch = true;
|
217 | 218 | for(int j = 0; j < 8; j++)
|
218 | 219 | 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;
|
227 | 221 | }
|
228 | 222 | }
|
229 | 223 | if(shaderindex == -1)
|
— | — | @@ -239,7 +233,7 @@ |
240 | 234 | String_Free(&This->genshaders[This->genindex].shader.fsrc);
|
241 | 235 | ZeroMemory(&This->genshaders[This->genindex],sizeof(GenShader));
|
242 | 236 | }
|
243 | | - ShaderGen3D_CreateShader(This, This->genindex,id,texstate,texcoords);
|
| 237 | + ShaderGen3D_CreateShader(This, This->genindex,id,texstate);
|
244 | 238 | shaderindex = This->genindex;
|
245 | 239 | This->genindex++;
|
246 | 240 | if(This->genindex >= 256) This->genindex = 0;
|
— | — | @@ -247,7 +241,6 @@ |
248 | 242 | This->genshaders[shaderindex].id = id;
|
249 | 243 | for(int i = 0; i < 8; i++)
|
250 | 244 | This->genshaders[shaderindex].texids[i] = texstate[i];
|
251 | | - memcpy(This->genshaders[shaderindex].texcoords,texcoords,8*sizeof(int));
|
252 | 245 | This->ext->glUseProgram(This->genshaders[shaderindex].shader.prog);
|
253 | 246 | This->current_prog = This->genshaders[shaderindex].shader.prog;
|
254 | 247 | This->current_genshader = shaderindex;
|
— | — | @@ -484,7 +477,7 @@ |
485 | 478 | * @param texcoords
|
486 | 479 | * Pointer to number of texture coordinates in each texture stage
|
487 | 480 | */
|
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)
|
489 | 482 | {
|
490 | 483 | STRING tmp;
|
491 | 484 | ZeroMemory(&tmp, sizeof(STRING));
|
— | — | @@ -496,8 +489,11 @@ |
497 | 490 | BOOL haskey = FALSE;
|
498 | 491 | int count;
|
499 | 492 | int numlights;
|
| 493 | + int numtex;
|
500 | 494 | int vertexfog,pixelfog;
|
501 | 495 | vertexfog = pixelfog = 0;
|
| 496 | + if ((id>>34)&1) numtex = ((id >> 31) & 7) + 1;
|
| 497 | + else numtex = 0;
|
502 | 498 | if((id>>61)&1)
|
503 | 499 | {
|
504 | 500 | vertexfog = (id>>8)&3;
|
— | — | @@ -542,25 +538,23 @@ |
543 | 539 | String_Append(vsrc, tmp.ptr);
|
544 | 540 | }
|
545 | 541 | }
|
546 | | - for(i = 0; i < 8; i++)
|
| 542 | + for(i = 0; i < numtex; i++)
|
547 | 543 | {
|
548 | | - switch(texcoords[i])
|
| 544 | + switch ((texstate[i] >> 51)&3)
|
549 | 545 | {
|
550 | | - case -1:
|
551 | | - continue;
|
552 | | - case 3:
|
| 546 | + case 0:
|
553 | 547 | String_Assign(&tmp,attr_s);
|
554 | 548 | tmp.ptr[16] = *(_itoa(i,idstring,10));
|
555 | 549 | break;
|
556 | | - case 0:
|
| 550 | + case 1:
|
557 | 551 | String_Assign(&tmp, attr_st);
|
558 | 552 | tmp.ptr[17] = *(_itoa(i,idstring,10));
|
559 | 553 | break;
|
560 | | - case 1:
|
| 554 | + case 2:
|
561 | 555 | String_Assign(&tmp, attr_str);
|
562 | 556 | tmp.ptr[18] = *(_itoa(i,idstring,10));
|
563 | 557 | break;
|
564 | | - case 2:
|
| 558 | + case 3:
|
565 | 559 | String_Assign(&tmp, attr_strq);
|
566 | 560 | tmp.ptr[19] = *(_itoa(i,idstring,10));
|
567 | 561 | break;
|
— | — | @@ -693,32 +687,28 @@ |
694 | 688 | tmp.ptr[12] = *(_itoa(i,idstring,10));
|
695 | 689 | String_Append(vsrc, tmp.ptr);
|
696 | 690 | texindex = (texstate[i]>>34)&3;
|
697 | | - switch(texcoords[texindex])
|
| 691 | + switch ((texstate[texindex] >> 51) & 3)
|
698 | 692 | {
|
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);
|
701 | 697 | break;
|
702 | | - case 0: // st
|
| 698 | + case 1: // st
|
703 | 699 | String_Assign(&tmp, op_texpassthru2st);
|
704 | 700 | tmp.ptr[7] = *(_itoa(texindex,idstring,10));
|
705 | 701 | String_Append(vsrc, tmp.ptr);
|
706 | | - default:
|
707 | 702 | break;
|
708 | | - case 1: // str
|
| 703 | + case 2: // str
|
709 | 704 | String_Assign(&tmp, op_texpassthru2str);
|
710 | 705 | tmp.ptr[8] = *(_itoa(texindex,idstring,10));
|
711 | 706 | String_Append(vsrc, tmp.ptr);
|
712 | 707 | break;
|
713 | | - case 2: // strq
|
| 708 | + case 3: // strq
|
714 | 709 | String_Assign(&tmp, op_texpassthru2strq);
|
715 | 710 | tmp.ptr[4] = *(_itoa(texindex,idstring,10));
|
716 | 711 | String_Append(vsrc, tmp.ptr);
|
717 | 712 | 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;
|
723 | 713 | }
|
724 | 714 | }
|
725 | 715 | }
|
Index: ddraw/ShaderGen3D.h |
— | — | @@ -38,7 +38,6 @@ |
39 | 39 | _GENSHADER shader;
|
40 | 40 | __int64 id;
|
41 | 41 | __int64 texids[8];
|
42 | | - int texcoords[8];
|
43 | 42 | } GenShader;
|
44 | 43 |
|
45 | 44 | #define D3DTOP_DXGL_DECALMASK 0x101;
|
— | — | @@ -64,10 +63,10 @@ |
65 | 64 | void ShaderGen3D_Init(glExtensions *glext, ShaderManager *shaderman, ShaderGen3D *gen);
|
66 | 65 | void ShaderGen3D_Delete(ShaderGen3D *This);
|
67 | 66 | 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);
|
69 | 68 | GLuint ShaderGen3D_GetProgram(ShaderGen3D *This);
|
70 | 69 | 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);
|
72 | 71 |
|
73 | 72 | #ifdef __cplusplus
|
74 | 73 | }
|
Index: ddraw/ShaderManager.cpp |
— | — | @@ -204,9 +204,9 @@ |
205 | 205 | free(This->gen3d);
|
206 | 206 | }
|
207 | 207 |
|
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)
|
209 | 209 | {
|
210 | | - ShaderGen3D_SetShader(This->gen3d, id, texstate, texcoords, type, This->gen2d);
|
| 210 | + ShaderGen3D_SetShader(This->gen3d, id, texstate, type, This->gen2d);
|
211 | 211 | }
|
212 | 212 |
|
213 | 213 | } |
\ No newline at end of file |
Index: ddraw/ShaderManager.h |
— | — | @@ -61,7 +61,7 @@ |
62 | 62 |
|
63 | 63 | void ShaderManager_Init(glExtensions *glext, ShaderManager *shaderman);
|
64 | 64 | 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);
|
66 | 66 |
|
67 | 67 | #ifdef __cplusplus
|
68 | 68 | }
|
Index: ddraw/glDirect3DDevice.cpp |
— | — | @@ -814,6 +814,7 @@ |
815 | 815 | {
|
816 | 816 | TRACE_ENTER(3,14,this,9,dwVertexTypeDesc,14,vertptr);
|
817 | 817 | int i;
|
| 818 | + int texformats1[8];
|
818 | 819 | int ptr = 0;
|
819 | 820 | if((dwVertexTypeDesc & D3DFVF_XYZ) && (dwVertexTypeDesc & D3DFVF_XYZRHW))
|
820 | 821 | TRACE_RET(HRESULT,23,DDERR_INVALIDPARAMS);
|
— | — | @@ -865,22 +866,29 @@ |
866 | 867 | for(i = 0; i < 8; i++)
|
867 | 868 | {
|
868 | 869 | 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])
|
872 | 873 | {
|
873 | 874 | case 0: // st
|
874 | 875 | ptr += 2;
|
| 876 | + texformats[i] = 2;
|
875 | 877 | break;
|
876 | 878 | case 1: // str
|
877 | 879 | ptr += 3;
|
| 880 | + texformats[i] = 3;
|
878 | 881 | break;
|
879 | 882 | case 2: // strq
|
880 | 883 | ptr += 4;
|
| 884 | + texformats[i] = 4;
|
881 | 885 | break;
|
882 | 886 | case 3: // s
|
883 | 887 | ptr++;
|
| 888 | + texformats[i] = 1;
|
884 | 889 | break;
|
| 890 | + default:
|
| 891 | + texformats[i] = 2;
|
| 892 | + break;
|
885 | 893 | }
|
886 | 894 | }
|
887 | 895 | int stride = ptr*4;
|
Index: ddraw/glRenderer.cpp |
— | — | @@ -1383,7 +1383,7 @@ |
1384 | 1384 | if (dwFlags & DDBLT_KEYDEST) usedest = TRUE;
|
1385 | 1385 | if (usedest)
|
1386 | 1386 | {
|
1387 | | - ShaderManager_SetShader(This->shaders, PROG_TEXTURE, NULL, NULL, 0);
|
| 1387 | + ShaderManager_SetShader(This->shaders, PROG_TEXTURE, NULL, 0);
|
1388 | 1388 | glRenderer__DrawBackbufferRect(This, dest->texture, destrect, PROG_TEXTURE);
|
1389 | 1389 | This->bltvertices[1].dests = This->bltvertices[3].dests = 0.;
|
1390 | 1390 | This->bltvertices[0].dests = This->bltvertices[2].dests = (GLfloat)(destrect.right - destrect.left) / (GLfloat)This->backx;
|
— | — | @@ -1390,7 +1390,7 @@ |
1391 | 1391 | This->bltvertices[0].destt = This->bltvertices[1].destt = 1.;
|
1392 | 1392 | This->bltvertices[2].destt = This->bltvertices[3].destt = 1.0-((GLfloat)(destrect.bottom - destrect.top) / (GLfloat)This->backy);
|
1393 | 1393 | }
|
1394 | | - ShaderManager_SetShader(This->shaders, shaderid, NULL, NULL, 1);
|
| 1394 | + ShaderManager_SetShader(This->shaders, shaderid, NULL, 1);
|
1395 | 1395 | GenShader2D *shader = &This->shaders->gen2d->genshaders2D[This->shaders->gen3d->current_genshader];
|
1396 | 1396 | This->util->BlendEnable(false);
|
1397 | 1397 | do
|
— | — | @@ -1699,7 +1699,7 @@ |
1700 | 1700 | glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
|
1701 | 1701 | if(This->ddInterface->GetBPP() == 8)
|
1702 | 1702 | {
|
1703 | | - ShaderManager_SetShader(This->shaders,PROG_PAL256,NULL,NULL,0);
|
| 1703 | + ShaderManager_SetShader(This->shaders,PROG_PAL256,NULL,0);
|
1704 | 1704 | progtype = PROG_PAL256;
|
1705 | 1705 | TextureManager__UploadTexture(This->texman,paltex,0,glDirectDrawPalette_GetPalette(dest->palette,NULL),256,1,FALSE,FALSE);
|
1706 | 1706 | This->ext->glUniform1i(This->shaders->shaders[progtype].tex0,0);
|
— | — | @@ -1709,7 +1709,7 @@ |
1710 | 1710 | if(dxglcfg.scalingfilter)
|
1711 | 1711 | {
|
1712 | 1712 | 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);
|
1714 | 1714 | progtype = PROG_TEXTURE;
|
1715 | 1715 | TextureManager_SetTexture(This->texman,0,texture);
|
1716 | 1716 | This->ext->glUniform1i(This->shaders->shaders[progtype].tex0,0);
|
— | — | @@ -1722,7 +1722,7 @@ |
1723 | 1723 | }
|
1724 | 1724 | else
|
1725 | 1725 | {
|
1726 | | - ShaderManager_SetShader(This->shaders,PROG_TEXTURE,NULL,NULL,0);
|
| 1726 | + ShaderManager_SetShader(This->shaders,PROG_TEXTURE,NULL,0);
|
1727 | 1727 | progtype = PROG_TEXTURE;
|
1728 | 1728 | TextureManager_SetTexture(This->texman,0,texture);
|
1729 | 1729 | This->ext->glUniform1i(This->shaders->shaders[progtype].tex0,0);
|
— | — | @@ -2135,11 +2135,16 @@ |
2136 | 2136 | SetEvent(This->busy);
|
2137 | 2137 | return;
|
2138 | 2138 | }
|
2139 | | - This->shaderstate3d.stateid &= 0xFFFA3FFC7FFFFFFFi64;
|
| 2139 | + This->shaderstate3d.stateid &= 0xFFFA3FF87FFFFFFFi64;
|
2140 | 2140 | int numtextures = 0;
|
2141 | 2141 | for (i = 0; i < 8; i++)
|
| 2142 | + {
|
| 2143 | + This->shaderstate3d.texstageid[i] &= 0xFFE7FFFFFFFFFFFFi64;
|
| 2144 | + This->shaderstate3d.texstageid[i] |= (__int64)(texformats[i] - 1) << 51;
|
2142 | 2145 | 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);
|
2144 | 2149 | int blendweights = 0;
|
2145 | 2150 | for (i = 0; i < 5; i++)
|
2146 | 2151 | if (vertices[i + 2].data) blendweights++;
|
— | — | @@ -2148,7 +2153,7 @@ |
2149 | 2154 | if (vertices[8].data) This->shaderstate3d.stateid |= (1i64 << 35);
|
2150 | 2155 | if (vertices[9].data) This->shaderstate3d.stateid |= (1i64 << 36);
|
2151 | 2156 | 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);
|
2153 | 2158 | glRenderer__SetDepthComp(This);
|
2154 | 2159 | if(This->renderstate[D3DRENDERSTATE_ZENABLE]) This->util->DepthTest(true);
|
2155 | 2160 | else This->util->DepthTest(false);
|
— | — | @@ -2202,7 +2207,14 @@ |
2203 | 2208 | {
|
2204 | 2209 | case -1: // Null
|
2205 | 2210 | 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
|
2207 | 2219 | if(prog->attribs[i+18] != -1)
|
2208 | 2220 | {
|
2209 | 2221 | This->util->EnableArray(prog->attribs[i+18],true);
|
— | — | @@ -2209,7 +2221,7 @@ |
2210 | 2222 | This->ext->glVertexAttribPointer(prog->attribs[i+18],2,GL_FLOAT,false,vertices[i+10].stride,vertices[i+10].data);
|
2211 | 2223 | }
|
2212 | 2224 | break;
|
2213 | | - case 1: // str
|
| 2225 | + case 3: // str
|
2214 | 2226 | if(prog->attribs[i+26] != -1)
|
2215 | 2227 | {
|
2216 | 2228 | This->util->EnableArray(prog->attribs[i+26],true);
|
— | — | @@ -2216,7 +2228,7 @@ |
2217 | 2229 | This->ext->glVertexAttribPointer(prog->attribs[i+26],3,GL_FLOAT,false,vertices[i+10].stride,vertices[i+10].data);
|
2218 | 2230 | }
|
2219 | 2231 | break;
|
2220 | | - case 2: // strq
|
| 2232 | + case 4: // strq
|
2221 | 2233 | if(prog->attribs[i+34] != -1)
|
2222 | 2234 | {
|
2223 | 2235 | This->util->EnableArray(prog->attribs[i+34],true);
|
— | — | @@ -2223,13 +2235,6 @@ |
2224 | 2236 | This->ext->glVertexAttribPointer(prog->attribs[i+34],4,GL_FLOAT,false,vertices[i+10].stride,vertices[i+10].data);
|
2225 | 2237 | }
|
2226 | 2238 | 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;
|
2234 | 2239 | }
|
2235 | 2240 |
|
2236 | 2241 | }
|
— | — | @@ -2396,7 +2401,7 @@ |
2397 | 2402 | view[3] = (GLfloat)surface->ddsd.dwHeight;
|
2398 | 2403 | This->util->SetViewport(0,0,surface->ddsd.dwWidth,surface->ddsd.dwHeight);
|
2399 | 2404 | glClear(GL_COLOR_BUFFER_BIT);
|
2400 | | - ShaderManager_SetShader(This->shaders,PROG_CLIPSTENCIL,NULL,NULL,0);
|
| 2405 | + ShaderManager_SetShader(This->shaders,PROG_CLIPSTENCIL,NULL,0);
|
2401 | 2406 | This->ext->glUniform4f(This->shaders->shaders[PROG_CLIPSTENCIL].view,view[0],view[1],view[2],view[3]);
|
2402 | 2407 | This->util->EnableArray(This->shaders->shaders[PROG_CLIPSTENCIL].pos,true);
|
2403 | 2408 | This->ext->glVertexAttribPointer(This->shaders->shaders[PROG_CLIPSTENCIL].pos,
|