| Index: ddraw/glDirect3DDevice.cpp |
| — | — | @@ -417,6 +417,7 @@ |
| 418 | 418 | }
|
| 419 | 419 | texstages[i].shaderid |= (__int64)(texstages[i].texcoordindex&7) << 54;
|
| 420 | 420 | texstages[i].shaderid |= (__int64)((texstages[i].texcoordindex>>16)&3) << 57;
|
| | 421 | + if(texstages[i].texture) texstages[i].shaderid |= 1i64 << 59;
|
| 421 | 422 | return shader;
|
| 422 | 423 | }
|
| 423 | 424 |
|
| — | — | @@ -904,6 +905,7 @@ |
| 905 | 906 | if(dwStage > 7) return DDERR_INVALIDPARAMS;
|
| 906 | 907 | if(texstages[dwStage].texture) texstages[dwStage].texture->Release();
|
| 907 | 908 | texstages[dwStage].texture = (glDirectDrawSurface7*)lpTexture;
|
| | 909 | + texstages[dwStage].dirty = true;
|
| 908 | 910 | if(lpTexture) lpTexture->AddRef();
|
| 909 | 911 | return D3D_OK;
|
| 910 | 912 | }
|
| Index: ddraw/glDirect3DDevice.h |
| — | — | @@ -133,10 +133,10 @@ |
| 134 | 134 | glDirectDrawSurface7 *glDDS7;
|
| 135 | 135 | DWORD renderstate[153];
|
| 136 | 136 | TEXTURESTAGE texstages[8];
|
| | 137 | + glDirect3D7 *glD3D7;
|
| 137 | 138 |
|
| 138 | 139 | private:
|
| 139 | 140 | HRESULT fvftoglvertex(DWORD dwVertexTypeDesc,LPDWORD vertptr);
|
| 140 | | - glDirect3D7 *glD3D7;
|
| 141 | 141 | ULONG refcount;
|
| 142 | 142 | GLuint gltextures[8];
|
| 143 | 143 | DWORD lightsmax;
|
| Index: ddraw/glRenderer.cpp |
| — | — | @@ -1142,6 +1142,28 @@ |
| 1143 | 1143 | glUniform4f(prog.uniforms[136],RGBA_GETRED(ambient),RGBA_GETGREEN(ambient),
|
| 1144 | 1144 | RGBA_GETBLUE(ambient),RGBA_GETALPHA(ambient));
|
| 1145 | 1145 |
|
| | 1146 | + for(i = 0; i < 8; i++)
|
| | 1147 | + {
|
| | 1148 | + if(device->texstages[i].colorop == D3DTOP_DISABLE) break;
|
| | 1149 | + if(device->texstages[i].texture)
|
| | 1150 | + {
|
| | 1151 | + if(device->texstages[i].texture->dirty & 1)
|
| | 1152 | + {
|
| | 1153 | + _UploadTexture(device->texstages[i].texture->buffer,device->texstages[i].texture->bigbuffer,
|
| | 1154 | + device->texstages[i].texture->texture,device->texstages[i].texture->ddsd.dwWidth,
|
| | 1155 | + device->texstages[i].texture->ddsd.dwHeight,device->texstages[i].texture->fakex,
|
| | 1156 | + device->texstages[i].texture->fakey,device->texstages[i].texture->ddsd.lPitch,
|
| | 1157 | + (device->texstages[i].texture->ddsd.ddpfPixelFormat.dwRGBBitCount/8*device->texstages[i].texture->fakex),
|
| | 1158 | + device->texstages[i].texture->ddsd.ddpfPixelFormat.dwRGBBitCount,device->texstages[i].texture->texformat,
|
| | 1159 | + device->texstages[i].texture->texformat2,device->texstages[i].texture->texformat3);
|
| | 1160 | + device->texstages[i].texture->dirty &= ~1;
|
| | 1161 | + }
|
| | 1162 | + SetTexture(i,device->texstages[i].texture->texture);
|
| | 1163 | + }
|
| | 1164 | + else SetTexture(i,0);
|
| | 1165 | + glUniform1i(prog.uniforms[128+i],i);
|
| | 1166 | + }
|
| | 1167 | +
|
| 1146 | 1168 | if(device->glDDS7->zbuffer) SetFBO(device->glDDS7->texture,device->glDDS7->zbuffer->texture,device->glDDS7->zbuffer->hasstencil);
|
| 1147 | 1169 | else SetFBO(device->glDDS7->texture,0,false);
|
| 1148 | 1170 | glViewport(device->viewport.dwX,device->viewport.dwY,device->viewport.dwWidth,device->viewport.dwHeight);
|
| Index: ddraw/glutil.cpp |
| — | — | @@ -114,6 +114,12 @@ |
| 115 | 115 | }
|
| 116 | 116 | }
|
| 117 | 117 |
|
| | 118 | +void SetTexture(int level,GLuint texture)
|
| | 119 | +{
|
| | 120 | + SetActiveTexture(level);
|
| | 121 | + glBindTexture(GL_TEXTURE_2D,texture);
|
| | 122 | +}
|
| | 123 | +
|
| 118 | 124 | void SetWrap(int level, DWORD coord, DWORD address)
|
| 119 | 125 | {
|
| 120 | 126 | if(level == -1)
|
| Index: ddraw/glutil.h |
| — | — | @@ -25,6 +25,7 @@ |
| 26 | 26 |
|
| 27 | 27 | void InitFBO();
|
| 28 | 28 | void DeleteFBO();
|
| | 29 | +void SetTexture(int level,GLuint texture);
|
| 29 | 30 | void SetActiveTexture(int level);
|
| 30 | 31 | GLenum SetFBO(GLint color, GLint z, bool stencil);
|
| 31 | 32 |
|
| Index: ddraw/shadergen.cpp |
| — | — | @@ -88,6 +88,7 @@ |
| 89 | 89 | Bits in flags:
|
| 90 | 90 | 00=passthru 01=cameraspacenormal
|
| 91 | 91 | 10=cameraspaceposition 11=cameraspacereflectionvector
|
| | 92 | +Bit 59: Texture image enabled
|
| 92 | 93 | */
|
| 93 | 94 | void ZeroShaderArray()
|
| 94 | 95 | {
|
| — | — | @@ -236,13 +237,14 @@ |
| 237 | 238 | };\n";
|
| 238 | 239 | static const char unif_light[] = "uniform Light lightX;\n";
|
| 239 | 240 | static const char unif_ambient[] = "uniform vec4 ambientcolor;\n";
|
| 240 | | -static const char unif_tex[] = "uniform sampler2d texX;\n";
|
| | 241 | +static const char unif_tex[] = "uniform sampler2D texX;\n";
|
| 241 | 242 | // Variables
|
| 242 | 243 | static const char var_common[] = "vec4 diffuse;\n\
|
| 243 | 244 | vec4 specular;\n\
|
| 244 | 245 | vec4 ambient;\n\
|
| 245 | 246 | vec3 N;";
|
| 246 | | -static const char var_color[] = "vec4 color;\n";
|
| | 247 | +static const char var_color[] = "vec3 color;\n\
|
| | 248 | +float alpha;\n";
|
| 247 | 249 | static const char var_xyzw[] = "vec4 xyzw;\n";
|
| 248 | 250 | // Operations
|
| 249 | 251 | static const char op_transform[] = "xyzw = vec4(xyz,1);\n\
|
| — | — | @@ -256,11 +258,11 @@ |
| 257 | 259 | static const char op_dirlight[] = "DirLight(lightX);\n";
|
| 258 | 260 | static const char op_dirlightnospecular[] = "DirLightNoSpecular(lightX);\n";
|
| 259 | 261 | static const char op_spotlight[] = "SpotLight(lightX);\n";
|
| 260 | | -static const char op_colorout[] = "vec4 color = (material.diffuse * diffuse) + (material.ambient * ambient) + \n\
|
| 261 | | -(material.specular * specular) + material.emissive;\n\
|
| 262 | | -gl_FrontColor = color;\n";
|
| 263 | | -static const char op_colorfragout[] = "gl_FragColor = color;\n";
|
| 264 | | -static const char op_colorfragin[] = "color = gl_Color;\n";
|
| | 262 | +static const char op_colorout[] = "gl_FrontColor = (material.diffuse * diffuse) + (material.ambient * ambient) + material.emissive;\n\
|
| | 263 | +gl_FrontSecondaryColor = (material.specular * specular);\n";
|
| | 264 | +static const char op_colorfragout[] = "gl_FragColor = vec4(color,alpha);\n";
|
| | 265 | +static const char op_colorfragin[] = "color = gl_Color.rgb;\n\
|
| | 266 | +alpha = gl_Color.a;\n";
|
| 265 | 267 | static const char op_texpassthru1[] = "gl_TexCoord[x] = ";
|
| 266 | 268 | static const char op_texpassthru2s[] = "vec4(sX,0,0,1);\n";
|
| 267 | 269 | static const char op_texpassthru2st[] = "vec4(stX,0,1);\n";
|
| — | — | @@ -514,6 +516,13 @@ |
| 515 | 517 | fsrc->append(idheader);
|
| 516 | 518 | fsrc->append(idstring);
|
| 517 | 519 | // Uniforms
|
| | 520 | + for(i = 0; i < 8; i++)
|
| | 521 | + {
|
| | 522 | + if((texstate[i].shaderid & 31) == D3DTOP_DISABLE)break;
|
| | 523 | + tmp = unif_tex;
|
| | 524 | + tmp.replace(21,1,_itoa(i,idstring,10));
|
| | 525 | + fsrc->append(tmp);
|
| | 526 | + }
|
| 518 | 527 | // Variables
|
| 519 | 528 | fsrc->append(var_color);
|
| 520 | 529 | // Functions
|
| — | — | @@ -520,9 +529,84 @@ |
| 521 | 530 | // Main
|
| 522 | 531 | fsrc->append(mainstart);
|
| 523 | 532 | fsrc->append(op_colorfragin);
|
| 524 | | - for(int i = 0; i < 8; i++)
|
| | 533 | + string arg1,arg2;
|
| | 534 | + int args[4];
|
| | 535 | + const string blendargs[] = {"color","gl_Color","texture2DProj(texX,gl_TexCoord[Y]).rgb",
|
| | 536 | + "texture2DProj(texX,gl_TexCoord[Y]).a","texfactor","gl_SecondaryColor","vec3(1,1,1)","1"};
|
| | 537 | + for(i = 0; i < 8; i++)
|
| 525 | 538 | {
|
| 526 | | -
|
| | 539 | + if((texstate[i].shaderid & 31) == D3DTOP_DISABLE)break;
|
| | 540 | + // Color stage
|
| | 541 | + args[0] = (texstate[i].shaderid>>5)&63;
|
| | 542 | + switch(args[0]&7) //arg1
|
| | 543 | + {
|
| | 544 | + case D3DTA_CURRENT:
|
| | 545 | + default:
|
| | 546 | + arg1 = blendargs[0];
|
| | 547 | + break;
|
| | 548 | + case D3DTA_DIFFUSE:
|
| | 549 | + arg1 = blendargs[1];
|
| | 550 | + break;
|
| | 551 | + 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));
|
| | 555 | + break;
|
| | 556 | + case D3DTA_TFACTOR:
|
| | 557 | + FIXME("Support texture factor value");
|
| | 558 | + arg1 = blendargs[4];
|
| | 559 | + break;
|
| | 560 | + case D3DTA_SPECULAR:
|
| | 561 | + arg1 = blendargs[5];
|
| | 562 | + break;
|
| | 563 | + }
|
| | 564 | + args[1] = (texstate[i].shaderid>>11)&63;
|
| | 565 | + switch(args[1]&7) //arg2
|
| | 566 | + {
|
| | 567 | + case D3DTA_CURRENT:
|
| | 568 | + default:
|
| | 569 | + arg2 = blendargs[0];
|
| | 570 | + break;
|
| | 571 | + case D3DTA_DIFFUSE:
|
| | 572 | + arg2 = blendargs[1];
|
| | 573 | + break;
|
| | 574 | + 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));
|
| | 578 | + break;
|
| | 579 | + case D3DTA_TFACTOR:
|
| | 580 | + FIXME("Support texture factor value");
|
| | 581 | + arg2 = blendargs[4];
|
| | 582 | + break;
|
| | 583 | + case D3DTA_SPECULAR:
|
| | 584 | + arg2 = blendargs[5];
|
| | 585 | + break;
|
| | 586 | + }
|
| | 587 | + switch(texstate[i].shaderid & 31)
|
| | 588 | + {
|
| | 589 | + case D3DTOP_DISABLE:
|
| | 590 | + default:
|
| | 591 | + break;
|
| | 592 | + case D3DTOP_SELECTARG1:
|
| | 593 | + fsrc->append("color = " + arg1 + ";\n");
|
| | 594 | + break;
|
| | 595 | + case D3DTOP_SELECTARG2:
|
| | 596 | + fsrc->append("color = " + arg2 + ";\n");
|
| | 597 | + break;
|
| | 598 | + case D3DTOP_MODULATE:
|
| | 599 | + fsrc->append("color = " + arg1 + " * " + arg2 + ";\n");
|
| | 600 | + break;
|
| | 601 | + case D3DTOP_MODULATE2X:
|
| | 602 | + fsrc->append("color = (" + arg1 + " * " + arg2 + ") * 2;\n");
|
| | 603 | + break;
|
| | 604 | + case D3DTOP_MODULATE4X:
|
| | 605 | + fsrc->append("color = (" + arg1 + " * " + arg2 + ") * 4;\n");
|
| | 606 | + break;
|
| | 607 | + case D3DTOP_ADD:
|
| | 608 | + fsrc->append("color = " + arg1 + " + " + arg2 + ";\n");
|
| | 609 | + break;
|
| | 610 | + }
|
| 527 | 611 | }
|
| 528 | 612 | fsrc->append(op_colorfragout);
|
| 529 | 613 | fsrc->append(mainend);
|
| Index: dxgltest/Tests3D.cpp |
| — | — | @@ -68,6 +68,7 @@ |
| 69 | 69 | break;
|
| 70 | 70 | case WM_DESTROY:
|
| 71 | 71 | StopTimer();
|
| | 72 | + Sleep(100);
|
| 72 | 73 | for(int i = 0; i < 8; i++)
|
| 73 | 74 | {
|
| 74 | 75 | if(textures[i])
|