Index: ddraw/glDirect3DDevice.cpp |
— | — | @@ -415,6 +415,8 @@ |
416 | 416 | }
|
417 | 417 | if(texstages[i].textransform & D3DTTFF_PROJECTED) texstages[i].shaderid |= 1i64 << 53;
|
418 | 418 | }
|
| 419 | + texstages[i].shaderid |= (__int64)(texstages[i].texcoordindex&7) << 54;
|
| 420 | + texstages[i].shaderid |= (__int64)((texstages[i].texcoordindex>>16)&3) << 57;
|
419 | 421 | return shader;
|
420 | 422 | }
|
421 | 423 |
|
— | — | @@ -468,10 +470,11 @@ |
469 | 471 | for(i = 0; i < 8; i++)
|
470 | 472 | vertdata[i+10].data = NULL;
|
471 | 473 | int numtex = (dwVertexTypeDesc&D3DFVF_TEXCOUNT_MASK)>>D3DFVF_TEXCOUNT_SHIFT;
|
472 | | - for(i = 0; i < numtex; i++)
|
| 474 | + for(i = 0; i < 8; i++)
|
473 | 475 | {
|
474 | | - vertdata[i+10].data = &vertptr[ptr];
|
475 | | - texformats[i] = (dwVertexTypeDesc>>(16+(2*i))&3);
|
| 476 | + vertdata[i+9].data = &vertptr[ptr];
|
| 477 | + if(i >= numtex) texformats[i] = -1;
|
| 478 | + else texformats[i] = (dwVertexTypeDesc>>(16+(2*i))&3);
|
476 | 479 | switch(texformats[i])
|
477 | 480 | {
|
478 | 481 | case 0: // st
|
Index: ddraw/glDirect3DDevice.h |
— | — | @@ -150,7 +150,7 @@ |
151 | 151 | GLubyte *specular;
|
152 | 152 | GLubyte *ambient;
|
153 | 153 | GLfloat *texcoords[8];
|
154 | | - GLVERTEX vertdata[17];
|
| 154 | + GLVERTEX vertdata[18];
|
155 | 155 | int texformats[8];
|
156 | 156 | };
|
157 | 157 |
|
Index: ddraw/glRenderer.cpp |
— | — | @@ -547,6 +547,7 @@ |
548 | 548 | glClear(GL_COLOR_BUFFER_BIT);
|
549 | 549 | glFlush();
|
550 | 550 | SwapBuffers(hDC);
|
| 551 | + SetActiveTexture(0);
|
551 | 552 | if(!hasHWnd)
|
552 | 553 | {
|
553 | 554 | dib.enabled = true;
|
— | — | @@ -700,7 +701,7 @@ |
701 | 702 | GLint texloc = glGetUniformLocation(shaders[PROG_TEXTURE].prog,"Texture");
|
702 | 703 | glUniform1i(texloc,0);
|
703 | 704 | }
|
704 | | - glActiveTexture(GL_TEXTURE0);
|
| 705 | + SetActiveTexture(0);
|
705 | 706 | if(src) glBindTexture(GL_TEXTURE_2D,src->GetTexture());
|
706 | 707 | GLuint prog = GetProgram()&0xffffffff;
|
707 | 708 | GLint viewloc = glGetUniformLocation(prog,"view");
|
— | — | @@ -746,7 +747,7 @@ |
747 | 748 | void glRenderer::_DrawBackbuffer(GLuint *texture, int x, int y)
|
748 | 749 | {
|
749 | 750 | GLfloat view[4];
|
750 | | - glActiveTexture(GL_TEXTURE0);
|
| 751 | + SetActiveTexture(0);
|
751 | 752 | if(!backbuffer)
|
752 | 753 | {
|
753 | 754 | backbuffer = _MakeTexture(GL_LINEAR,GL_LINEAR,GL_CLAMP_TO_EDGE,GL_CLAMP_TO_EDGE,x,y,GL_BGRA,GL_UNSIGNED_BYTE,GL_RGBA8);
|
— | — | @@ -854,11 +855,11 @@ |
855 | 856 | GLint texloc = glGetUniformLocation(shaders[PROG_PAL256].prog,"IndexTexture");
|
856 | 857 | glUniform1i(texloc,0);
|
857 | 858 | glUniform1i(palloc,1);
|
858 | | - glActiveTexture(GL_TEXTURE0);
|
| 859 | + SetActiveTexture(0);
|
859 | 860 | glBindTexture(GL_TEXTURE_2D,texture);
|
860 | | - glActiveTexture(GL_TEXTURE1);
|
| 861 | + SetActiveTexture(1);
|
861 | 862 | glBindTexture(GL_TEXTURE_2D,paltex);
|
862 | | - glActiveTexture(GL_TEXTURE0);
|
| 863 | + SetActiveTexture(0);
|
863 | 864 | if(dxglcfg.scalingfilter)
|
864 | 865 | {
|
865 | 866 | _DrawBackbuffer(&texture,dest->fakex,dest->fakey);
|
Index: ddraw/glutil.cpp |
— | — | @@ -22,8 +22,9 @@ |
23 | 23 | GLuint fbz = 0;
|
24 | 24 | GLuint fbo = 0;
|
25 | 25 | bool stencil = false;
|
| 26 | +GLint texlevel = 0;
|
| 27 | +GLint texwrap[16];
|
26 | 28 |
|
27 | | -
|
28 | 29 | void InitFBO()
|
29 | 30 | {
|
30 | 31 | if(GLEXT_ARB_framebuffer_object)
|
— | — | @@ -103,3 +104,51 @@ |
104 | 105 | ::stencil = stencil;
|
105 | 106 | return error;
|
106 | 107 | }
|
| 108 | +
|
| 109 | +void SetActiveTexture(int level)
|
| 110 | +{
|
| 111 | + if(level != texlevel)
|
| 112 | + {
|
| 113 | + texlevel = level;
|
| 114 | + glActiveTexture(GL_TEXTURE0+level);
|
| 115 | + }
|
| 116 | +}
|
| 117 | +
|
| 118 | +void SetWrap(int level, DWORD coord, DWORD address)
|
| 119 | +{
|
| 120 | + if(level == -1)
|
| 121 | + {
|
| 122 | + for(int i = 0; i < 16; i++)
|
| 123 | + texwrap[i] = GL_REPEAT;
|
| 124 | + }
|
| 125 | + if(coord > 1) return;
|
| 126 | + if(level > 8) return;
|
| 127 | + if(level < 0) return;
|
| 128 | + GLint wrapmode;
|
| 129 | + switch(address)
|
| 130 | + {
|
| 131 | + case D3DTADDRESS_WRAP:
|
| 132 | + wrapmode = GL_REPEAT;
|
| 133 | + break;
|
| 134 | + case D3DTADDRESS_MIRROR:
|
| 135 | + wrapmode = GL_MIRRORED_REPEAT;
|
| 136 | + break;
|
| 137 | + case D3DTADDRESS_CLAMP:
|
| 138 | + wrapmode = GL_CLAMP_TO_EDGE;
|
| 139 | + break;
|
| 140 | + case D3DTADDRESS_BORDER:
|
| 141 | + wrapmode = GL_CLAMP_TO_BORDER;
|
| 142 | + break;
|
| 143 | + default:
|
| 144 | + return;
|
| 145 | + }
|
| 146 | + if(texwrap[level*2+coord] == wrapmode) return;
|
| 147 | + else
|
| 148 | + {
|
| 149 | + int currtexture = texlevel;
|
| 150 | + SetActiveTexture(level);
|
| 151 | + if(coord) glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,wrapmode);
|
| 152 | + else glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,wrapmode);
|
| 153 | + SetActiveTexture(currtexture);
|
| 154 | + }
|
| 155 | +} |
\ No newline at end of file |
Index: ddraw/glutil.h |
— | — | @@ -25,6 +25,7 @@ |
26 | 26 |
|
27 | 27 | void InitFBO();
|
28 | 28 | void DeleteFBO();
|
| 29 | +void SetActiveTexture(int level);
|
29 | 30 | GLenum SetFBO(GLint color, GLint z, bool stencil);
|
30 | 31 |
|
31 | 32 | #endif //_GLUTIL_H |
\ No newline at end of file |
Index: ddraw/shadergen.cpp |
— | — | @@ -34,55 +34,60 @@ |
35 | 35 | int current_genshader;
|
36 | 36 |
|
37 | 37 | /* Bits in Shader ID:
|
38 | | -Bits 0-1 - Shading mode: 00=flat 01=gouraud 11=phong 10=flat per-pixel
|
39 | | -Bit 2 - Alpha test enable
|
40 | | -Bits 3-5 - Alpha test function:
|
| 38 | +Bits 0-1 - Shading mode: 00=flat 01=gouraud 11=phong 10=flat per-pixel VS/FS
|
| 39 | +Bit 2 - Alpha test enable FS
|
| 40 | +Bits 3-5 - Alpha test function: FS
|
41 | 41 | 000=never 001=less 010=equal 011=lessequal
|
42 | 42 | 100=greater 101=notequal 110=lessequal 111=always
|
43 | | -Bits 6-7 - Table fog:
|
| 43 | +Bits 6-7 - Table fog: FS
|
44 | 44 | 00 = none 01=exp 10=exp2 11=linear
|
45 | | -Bits 8-9 - Vertex fog: same as table
|
46 | | -Bit 10 - Range based fog
|
47 | | -Bit 11 - Specular highlights
|
48 | | -Bit 12 - Stippled alpha
|
49 | | -Bit 13 - Color key transparency
|
50 | | -Bit 14-17 - Z bias
|
51 | | -Bits 18-20 - Number of lights
|
52 | | -Bit 21 - Camera relative specular highlights
|
53 | | -Bit 22 - Alpha blended color key
|
54 | | -Bits 23-24 - Diffuse material source
|
55 | | -Bits 25-26 - Specular material source
|
56 | | -Bits 27-28 - Ambient material source
|
57 | | -Bits 29-30 - Emissive material source
|
58 | | -Bits 31-33 - Number of textures
|
59 | | -Bit 34 - Use transformed vertices
|
60 | | -Bit 35 - Use diffuse color
|
61 | | -Bit 36 - Use specular color
|
62 | | -Bit 37 - Enable normals
|
63 | | -Bits 38-45 - Light types
|
64 | | -Bits 46-48 - Number of blending weights
|
65 | | -Bit 49 - Normalize normals
|
| 45 | +Bits 8-9 - Vertex fog: same as table VS
|
| 46 | +Bit 10 - Range based fog VS/FS
|
| 47 | +Bit 11 - Specular highlights VS/FS
|
| 48 | +Bit 12 - Stippled alpha FS
|
| 49 | +Bit 13 - Color key transparency FS
|
| 50 | +Bit 14-17 - Z bias FS
|
| 51 | +Bits 18-20 - Number of lights VS/FS
|
| 52 | +Bit 21 - Camera relative specular highlights VS/FS
|
| 53 | +Bit 22 - Alpha blended color key FS
|
| 54 | +Bits 23-24 - Diffuse material source VS
|
| 55 | +Bits 25-26 - Specular material source VS
|
| 56 | +Bits 27-28 - Ambient material source VS
|
| 57 | +Bits 29-30 - Emissive material source VS
|
| 58 | +Bits 31-33 - Number of textures VS/FS
|
| 59 | +Bit 34 - Use transformed vertices VS
|
| 60 | +Bit 35 - Use diffuse color VS
|
| 61 | +Bit 36 - Use specular color VS
|
| 62 | +Bit 37 - Enable normals VS
|
| 63 | +Bits 38-45 - Light types VS/FS
|
| 64 | +Bits 46-48 - Number of blending weights VS
|
| 65 | +Bit 49 - Normalize normals VS
|
66 | 66 | */
|
67 | 67 |
|
68 | 68 | /* Bits in Texture Stage ID:
|
69 | | -Bits 0-4: Texture color operation
|
70 | | -Bits 5-10: Texture color argument 1
|
71 | | -Bits 11-16: Texture color argument 2
|
72 | | -Bits 17-21: Texture alpha operation
|
73 | | -Bits 22-27: Texture alpha argument 1
|
74 | | -Bits 28-33: Texture alpha argument 2
|
75 | | -Bits 34-36: Texture coordinate index
|
76 | | -Bits 37-38: Texture coordinate flags
|
77 | | -Bits 39-40: U Texture address
|
78 | | -Bits 41-42: V Texture address
|
79 | | -Bits 43-45: Texture magnification filter
|
80 | | -Bits 46-47: Texture minification filter
|
81 | | -Bits 48-49: Texture mip filter
|
82 | | -Bit 50: Enable texture coordinate transform
|
83 | | -Bits 51-52: Number of texcoord dimensions
|
84 | | -Bit 53: Projected texcoord
|
| 69 | +Bits 0-4: Texture color operation FS
|
| 70 | +Bits 5-10: Texture color argument 1 FS
|
| 71 | +Bits 11-16: Texture color argument 2 FS
|
| 72 | +Bits 17-21: Texture alpha operation FS
|
| 73 | +Bits 22-27: Texture alpha argument 1 FS
|
| 74 | +Bits 28-33: Texture alpha argument 2 FS
|
| 75 | +Bits 34-36: Texture coordinate index VS
|
| 76 | +Bits 37-38: Texture coordinate flags VS
|
| 77 | +Bits 39-40: U Texture address GL
|
| 78 | +Bits 41-42: V Texture address GL
|
| 79 | +Bits 43-45: Texture magnification filter GL/FS
|
| 80 | +Bits 46-47: Texture minification filter GL/FS
|
| 81 | +Bits 48-49: Texture mip filter GL/FS
|
| 82 | +Bit 50: Enable texture coordinate transform VS
|
| 83 | +Bits 51-52: Number of texcoord dimensions VS
|
| 84 | +Bit 53: Projected texcoord VS
|
85 | 85 | Bits in texcoord ID:
|
86 | 86 | 00=2dim 01=3dim 10=4dim 11=1dim
|
| 87 | +Bits 54-56: Texture coordinate index VS
|
| 88 | +Bits 57-58: Texture coordinate flags VS
|
| 89 | +Bits in flags:
|
| 90 | +00=passthru 01=cameraspacenormal
|
| 91 | +10=cameraspaceposition 11=cameraspacereflectionvector
|
87 | 92 | */
|
88 | 93 | void ZeroShaderArray()
|
89 | 94 | {
|
— | — | @@ -256,6 +261,12 @@ |
257 | 262 | gl_FrontColor = color;\n";
|
258 | 263 | static const char op_colorfragout[] = "gl_FragColor = color;\n";
|
259 | 264 | static const char op_colorfragin[] = "color = gl_Color;\n";
|
| 265 | +static const char op_texpassthru1[] = "gl_TexCoord[x] = ";
|
| 266 | +static const char op_texpassthru2s[] = "vec4(sX,0,0,1);\n";
|
| 267 | +static const char op_texpassthru2st[] = "vec4(stX,0,1);\n";
|
| 268 | +static const char op_texpassthru2str[] = "vec4(strX,1);\n";
|
| 269 | +static const char op_texpassthru2strq[] = "strqX;\n";
|
| 270 | +static const char op_texpassthru2null[] = "vec4(0,0,0,1);\n";
|
260 | 271 |
|
261 | 272 | // Functions
|
262 | 273 | static const char func_dirlight[] = "void DirLight(in Light light)\n\
|
— | — | @@ -330,6 +341,31 @@ |
331 | 342 | vsrc->append(tmp);
|
332 | 343 | }
|
333 | 344 | }
|
| 345 | + for(i = 0; i < 8; i++)
|
| 346 | + {
|
| 347 | + switch(texcoords[i])
|
| 348 | + {
|
| 349 | + case -1:
|
| 350 | + continue;
|
| 351 | + case 3:
|
| 352 | + tmp = attr_s;
|
| 353 | + tmp.replace(16,1,_itoa(i,idstring,10));
|
| 354 | + break;
|
| 355 | + case 0:
|
| 356 | + tmp = attr_st;
|
| 357 | + tmp.replace(17,1,_itoa(i,idstring,10));
|
| 358 | + break;
|
| 359 | + case 1:
|
| 360 | + tmp = attr_str;
|
| 361 | + tmp.replace(18,1,_itoa(i,idstring,10));
|
| 362 | + break;
|
| 363 | + case 2:
|
| 364 | + tmp = attr_strq;
|
| 365 | + tmp.replace(19,1,_itoa(i,idstring,10));
|
| 366 | + break;
|
| 367 | + }
|
| 368 | + vsrc->append(tmp);
|
| 369 | + }
|
334 | 370 |
|
335 | 371 | // Uniforms
|
336 | 372 | vsrc->append(unif_matrices); // Material
|
— | — | @@ -402,6 +438,48 @@ |
403 | 439 | }
|
404 | 440 | }
|
405 | 441 | vsrc->append(op_colorout);
|
| 442 | + int texindex;
|
| 443 | + for(i = 0; i < 8; i++)
|
| 444 | + {
|
| 445 | + if((texstate[i].shaderid>>50)&1)
|
| 446 | + {
|
| 447 | + FIXME("Support texture coordinate transform");
|
| 448 | + }
|
| 449 | + else
|
| 450 | + {
|
| 451 | + tmp = op_texpassthru1;
|
| 452 | + tmp.replace(12,1,_itoa(i,idstring,10));
|
| 453 | + vsrc->append(tmp);
|
| 454 | + texindex = (texstate[i].shaderid>>54)&3;
|
| 455 | + switch(texcoords[texindex])
|
| 456 | + {
|
| 457 | + case -1: // No texcoords
|
| 458 | + vsrc->append(op_texpassthru2null);
|
| 459 | + break;
|
| 460 | + case 0: // st
|
| 461 | + tmp = op_texpassthru2st;
|
| 462 | + tmp.replace(7,1,_itoa(texindex,idstring,10));
|
| 463 | + vsrc->append(tmp);
|
| 464 | + default:
|
| 465 | + break;
|
| 466 | + case 1: // str
|
| 467 | + tmp = op_texpassthru2str;
|
| 468 | + tmp.replace(8,1,_itoa(texindex,idstring,10));
|
| 469 | + vsrc->append(tmp);
|
| 470 | + break;
|
| 471 | + case 2: // strq
|
| 472 | + tmp = op_texpassthru2strq;
|
| 473 | + tmp.replace(4,1,_itoa(texindex,idstring,10));
|
| 474 | + vsrc->append(tmp);
|
| 475 | + break;
|
| 476 | + case 3: // s
|
| 477 | + tmp = op_texpassthru2s;
|
| 478 | + tmp.replace(6,1,_itoa(texindex,idstring,10));
|
| 479 | + vsrc->append(tmp);
|
| 480 | + break;
|
| 481 | + }
|
| 482 | + }
|
| 483 | + }
|
406 | 484 | vsrc->append(mainend);
|
407 | 485 | #ifdef _DEBUG
|
408 | 486 | OutputDebugStringA("Vertex shader:\n");
|