DXGL r483 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r482‎ | r483 | r484 >
Date:01:23, 11 August 2014
Author:admin
Status:new
Tags:
Comment:
Process Blt fragment shaders using integer values based on pixelformat, fixes color key on AMD GPU.
Use integer uniform for color fill Blt.
Modified paths:
  • /ddraw/ShaderGen2D.cpp (modified) (history)
  • /ddraw/TextureManager.c (modified) (history)
  • /ddraw/TextureManager.h (modified) (history)
  • /ddraw/glRenderer.cpp (modified) (history)

Diff [purge]

Index: ddraw/ShaderGen2D.cpp
@@ -165,22 +165,26 @@
166166 static const char unif_ckeysrc[] = "uniform ivec3 ckeysrc;\n";
167167 static const char unif_ckeydest[] = "uniform ivec3 ckeydest;\n";
168168 static const char unif_patternsize[] = "uniform ivec2 patternsize;\n";
 169+static const char unif_colorsizesrc[] = "uniform ivec4 colorsizesrc;\n";
 170+static const char unif_colorsizedest[] = "uniform ivec4 colorsizedest;\n";
 171+static const char unif_fillcolor[] = "uniform ivec4 fillcolor;\n";
169172
170 -
171173 // Variables
172174 static const char var_dest[] = "ivec4 dest;\n";
173175 static const char var_pattern[] = "ivec4 pattern;\n";
174176 static const char var_pixel[] = "ivec4 pixel;\n";
 177+static const char var_src[] = "ivec4 src;\n";
175178 static const char var_patternst[] = "vec2 patternst;\n";
176179
177180 // Operations
178 -static const char op_src[] = "pixel = ivec4(texture2D(srctex,gl_TexCoord[0].st)*255.5);\n";
179 -static const char op_color[] = "pixel = ivec4(gl_Color*255.5);\n";
180 -static const char op_dest[] = "dest = ivec4(texture2D(desttex,gl_TexCoord[1].st)*255.5);\n";
 181+static const char op_src[] = "src = ivec4(texture2D(srctex,gl_TexCoord[0].st)*vec4(colorsizesrc)+.5);\n";
 182+static const char op_pixel[] = "pixel = ivec4(texture2D(srctex,gl_TexCoord[0].st)*vec4(colorsizedest)+.5);\n";
 183+static const char op_color[] = "pixel = fillcolor;\n";
 184+static const char op_dest[] = "dest = ivec4(texture2D(desttex,gl_TexCoord[1].st)*vec4(colorsizedest)+.5);\n";
181185 static const char op_pattern[] = "patternst = vec2(mod(gl_FragCoord.x,float(patternsize.x))/float(patternsize.x),\n\
182186 mod(gl_FragCoord.y, float(patternsize.y)) / float(patternsize.y));\n\
183 -pattern = ivec4(texture2D(patterntex,patternst)*255.5);\n";
184 -static const char op_destout[] = "gl_FragColor = vec4(pixel)/255.0;\n";
 187+pattern = ivec4(texture2D(patterntex,patternst)*vec4(colorsizedest)+.5);\n";
 188+static const char op_destout[] = "gl_FragColor = vec4(pixel)/vec4(colorsizedest);\n";
185189 static const char op_vertex[] = "vec4 xyzw = vec4(xy[0],xy[1],0,1);\n\
186190 mat4 proj = mat4(\n\
187191 vec4(2.0 / (view[1] - view[0]), 0, 0, 0),\n\
@@ -216,9 +220,9 @@
217221 "",
218222 "",
219223 "",
220 -"pixel = pattern ^ ivec4(255);\n",//0F
 224+"pixel = pattern ^ colorsizedest;\n",//0F
221225 "",//10
222 -"pixel = (dest | pixel) ^ ivec4(255);\n",//11 NOTSRCERASE
 226+"pixel = (dest | pixel) ^ colorsizedest;\n",//11 NOTSRCERASE
223227 "",
224228 "",
225229 "",
@@ -252,7 +256,7 @@
253257 "",//30
254258 "",
255259 "",
256 -"pixel = pixel ^ ivec4(255);\n",//33 NOTSRCCOPY
 260+"pixel = pixel ^ colorsizedest;\n",//33 NOTSRCCOPY
257261 "",
258262 "",
259263 "",
@@ -269,7 +273,7 @@
270274 "",
271275 "",
272276 "",
273 -"pixel = pixel & (dest ^ ivec4(255));\n",//44 SRCERASE
 277+"pixel = pixel & (dest ^ colorsizedest);\n",//44 SRCERASE
274278 "",
275279 "",
276280 "",
@@ -286,7 +290,7 @@
287291 "",
288292 "",
289293 "",
290 -"pixel = dest ^ ivec4(255);\n",//55 DSTINVERT
 294+"pixel = dest ^ colorsizedest;\n",//55 DSTINVERT
291295 "",
292296 "",
293297 "",
@@ -388,7 +392,7 @@
389393 "",
390394 "",
391395 "",
392 -"pixel = dest | (pixel ^ ivec4(255));\n",//BB MERGEPAINT
 396+"pixel = dest | (pixel ^ colorsizedest);\n",//BB MERGEPAINT
393397 "",
394398 "",
395399 "",
@@ -452,11 +456,11 @@
453457 "",
454458 "",
455459 "",
456 -"pixel = dest | pattern | (pixel ^ 255);\n",//FB PATPAINT
 460+"pixel = dest | pattern | (pixel ^ colorsizedest);\n",//FB PATPAINT
457461 "",
458462 "",
459463 "",
460 -"pixel = ivec4(255);\n",//FF WHITENESS
 464+"pixel = colorsizedest;\n",//FF WHITENESS
461465 };
462466
463467 static const char *op_ROP_float[256] = {
@@ -813,8 +817,7 @@
814818
815819 // Attributes
816820 String_Append(vsrc, attr_xy);
817 - if (id & DDBLT_COLORFILL) String_Append(vsrc, attr_rgb);
818 - else String_Append(vsrc, attr_srcst);
 821+ if (!(id & DDBLT_COLORFILL)) String_Append(vsrc, attr_srcst);
819822 if (id & DDBLT_ROP)
820823 {
821824 if (rop_texture_usage[rop] & 2) usedest = TRUE;
@@ -829,8 +832,7 @@
830833 // Main
831834 String_Append(vsrc, mainstart);
832835 String_Append(vsrc, op_vertex);
833 - if (id & DDBLT_COLORFILL) String_Append(vsrc, op_vertcolorrgb);
834 - else String_Append(vsrc, op_texcoord0);
 836+ if (!(id & DDBLT_COLORFILL)) String_Append(vsrc, op_texcoord0);
835837 if(usedest) String_Append(vsrc, op_texcoord1);
836838 if (id & 0x10000000) String_Append(vsrc, op_texcoord3);
837839 String_Append(vsrc, mainend);
@@ -887,7 +889,8 @@
888890 String_Append(fsrc, idstring);
889891
890892 // Uniforms
891 - if (!(id & DDBLT_COLORFILL)) String_Append(fsrc, unif_srctex);
 893+ if (id & DDBLT_COLORFILL) String_Append(fsrc, unif_fillcolor);
 894+ else String_Append(fsrc, unif_srctex);
892895 if (id & DDBLT_KEYDEST) usedest = TRUE;
893896 if (id & DDBLT_ROP)
894897 {
@@ -900,11 +903,17 @@
901904 }
902905 if (usedest) String_Append(fsrc, unif_desttex);
903906 if (id & 0x10000000) String_Append(fsrc, unif_stenciltex);
904 - if (id & DDBLT_KEYSRC) String_Append(fsrc, unif_ckeysrc);
 907+ if (id & DDBLT_KEYSRC)
 908+ {
 909+ String_Append(fsrc, unif_ckeysrc);
 910+ String_Append(fsrc, unif_colorsizesrc);
 911+ }
 912+ String_Append(fsrc, unif_colorsizedest);
905913 if (id & DDBLT_KEYDEST) String_Append(fsrc, unif_ckeydest);
906914
907915 // Variables
908916 String_Append(fsrc, var_pixel);
 917+ if (id & DDBLT_KEYSRC) String_Append(fsrc, var_src);
909918 if (id & DDBLT_ROP)
910919 {
911920 if (rop_texture_usage[rop] & 4)
@@ -919,7 +928,8 @@
920929 String_Append(fsrc, mainstart);
921930 if (id & 0x10000000) String_Append(fsrc, op_clip);
922931 if (id & DDBLT_COLORFILL) String_Append(fsrc, op_color);
923 - else String_Append(fsrc, op_src);
 932+ else String_Append(fsrc, op_pixel);
 933+ if (id & DDBLT_KEYSRC) String_Append(fsrc, op_src);
924934 if (usedest) String_Append(fsrc, op_dest);
925935 if (id & DDBLT_KEYSRC) String_Append(fsrc, op_ckeysrc);
926936 if (id & DDBLT_KEYDEST) String_Append(fsrc, op_ckeydest);
@@ -992,4 +1002,8 @@
9931003 gen->genshaders2D[index].shader.uniforms[7] = gen->ext->glGetUniformLocation(gen->genshaders2D[index].shader.prog, "ckeysrchigh");
9941004 gen->genshaders2D[index].shader.uniforms[8] = gen->ext->glGetUniformLocation(gen->genshaders2D[index].shader.prog, "ckeydesthigh");
9951005 gen->genshaders2D[index].shader.uniforms[9] = gen->ext->glGetUniformLocation(gen->genshaders2D[index].shader.prog, "patternsize");
 1006+ gen->genshaders2D[index].shader.uniforms[10] = gen->ext->glGetUniformLocation(gen->genshaders2D[index].shader.prog, "colorsizesrc");
 1007+ gen->genshaders2D[index].shader.uniforms[11] = gen->ext->glGetUniformLocation(gen->genshaders2D[index].shader.prog, "colorsizedest");
 1008+ gen->genshaders2D[index].shader.uniforms[12] = gen->ext->glGetUniformLocation(gen->genshaders2D[index].shader.prog, "fillcolor");
 1009+
9961010 }
\ No newline at end of file
Index: ddraw/TextureManager.c
@@ -145,6 +145,15 @@
146146 texture->format = GL_LUMINANCE;
147147 }
148148 texture->type = GL_UNSIGNED_BYTE;
 149+ texture->colororder = 4;
 150+ texture->colorsizes[0] = 255;
 151+ texture->colorsizes[1] = 255;
 152+ texture->colorsizes[2] = 255;
 153+ texture->colorsizes[3] = 255;
 154+ texture->colorbits[0] = 8;
 155+ texture->colorbits[1] = 0;
 156+ texture->colorbits[2] = 0;
 157+ texture->colorbits[3] = 0;
149158 break;
150159 case 1: // 8-bit RGB332
151160 texture->internalformats[0] = GL_R3_G3_B2;
@@ -152,6 +161,15 @@
153162 texture->internalformats[2] = GL_RGBA8;
154163 texture->format = GL_RGB;
155164 texture->type = GL_UNSIGNED_BYTE_3_3_2;
 165+ texture->colororder = 1;
 166+ texture->colorsizes[0] = 7;
 167+ texture->colorsizes[1] = 7;
 168+ texture->colorsizes[2] = 3;
 169+ texture->colorsizes[3] = 1;
 170+ texture->colorbits[0] = 3;
 171+ texture->colorbits[1] = 3;
 172+ texture->colorbits[2] = 2;
 173+ texture->colorbits[3] = 0;
156174 break;
157175 case 2: // 16-bit RGB555
158176 texture->internalformats[0] = GL_RGB5_A1;
@@ -158,6 +176,15 @@
159177 texture->internalformats[1] = GL_RGBA8;
160178 texture->format = GL_BGRA;
161179 texture->type = GL_UNSIGNED_SHORT_1_5_5_5_REV;
 180+ texture->colororder = 1;
 181+ texture->colorsizes[0] = 31;
 182+ texture->colorsizes[1] = 31;
 183+ texture->colorsizes[2] = 31;
 184+ texture->colorsizes[3] = 1;
 185+ texture->colorbits[0] = 5;
 186+ texture->colorbits[1] = 5;
 187+ texture->colorbits[2] = 5;
 188+ texture->colorbits[3] = 1;
162189 break;
163190 case 3: // 16-bit RGB565
164191 texture->internalformats[0] = GL_RGB565;
@@ -165,6 +192,15 @@
166193 texture->internalformats[2] = GL_RGBA8;
167194 texture->format = GL_RGB;
168195 texture->type = GL_UNSIGNED_SHORT_5_6_5;
 196+ texture->colororder = 1;
 197+ texture->colorsizes[0] = 31;
 198+ texture->colorsizes[1] = 63;
 199+ texture->colorsizes[2] = 31;
 200+ texture->colorsizes[3] = 1;
 201+ texture->colorbits[0] = 5;
 202+ texture->colorbits[1] = 6;
 203+ texture->colorbits[2] = 5;
 204+ texture->colorbits[3] = 0;
169205 break;
170206 case 4: // 24-bit RGB888
171207 texture->internalformats[0] = GL_RGB8;
@@ -171,19 +207,55 @@
172208 texture->internalformats[1] = GL_RGBA8;
173209 texture->format = GL_BGR;
174210 texture->type = GL_UNSIGNED_BYTE;
 211+ texture->colororder = 1;
 212+ texture->colorsizes[0] = 255;
 213+ texture->colorsizes[1] = 255;
 214+ texture->colorsizes[2] = 255;
 215+ texture->colorsizes[3] = 1;
 216+ texture->colorbits[0] = 8;
 217+ texture->colorbits[1] = 8;
 218+ texture->colorbits[2] = 8;
 219+ texture->colorbits[3] = 0;
175220 break;
176221 case 5: // 32-bit RGB888
177222 texture->internalformats[0] = GL_RGBA8;
178223 texture->format = GL_BGRA;
179224 texture->type = GL_UNSIGNED_INT_8_8_8_8_REV;
 225+ texture->colororder = 1;
 226+ texture->colorsizes[0] = 255;
 227+ texture->colorsizes[1] = 255;
 228+ texture->colorsizes[2] = 255;
 229+ texture->colorsizes[3] = 1;
 230+ texture->colorbits[0] = 8;
 231+ texture->colorbits[1] = 8;
 232+ texture->colorbits[2] = 8;
 233+ texture->colorbits[3] = 0;
180234 break;
181235 case 6: // 32-bit BGR888
182236 texture->internalformats[0] = GL_RGBA8;
183237 texture->format = GL_RGBA;
184238 texture->type = GL_UNSIGNED_INT_8_8_8_8_REV;
 239+ texture->colororder = 0;
 240+ texture->colorsizes[0] = 255;
 241+ texture->colorsizes[1] = 255;
 242+ texture->colorsizes[2] = 255;
 243+ texture->colorsizes[3] = 1;
 244+ texture->colorbits[0] = 8;
 245+ texture->colorbits[1] = 8;
 246+ texture->colorbits[2] = 8;
 247+ texture->colorbits[3] = 0;
185248 break;
186249 case 7: // 16-bit RGBA8332
187250 FIXME("Unusual texture format RGBA8332 not supported");
 251+ texture->colororder = 1;
 252+ texture->colorsizes[0] = 7;
 253+ texture->colorsizes[1] = 7;
 254+ texture->colorsizes[2] = 3;
 255+ texture->colorsizes[3] = 255;
 256+ texture->colorbits[0] = 3;
 257+ texture->colorbits[1] = 3;
 258+ texture->colorbits[2] = 2;
 259+ texture->colorbits[3] = 8;
188260 break;
189261 case 8: // 16-bit RGBA4444
190262 texture->internalformats[0] = GL_RGBA4;
@@ -190,6 +262,15 @@
191263 texture->internalformats[1] = GL_RGBA8;
192264 texture->format = GL_BGRA;
193265 texture->type = GL_UNSIGNED_SHORT_4_4_4_4_REV;
 266+ texture->colororder = 1;
 267+ texture->colorsizes[0] = 15;
 268+ texture->colorsizes[1] = 15;
 269+ texture->colorsizes[2] = 15;
 270+ texture->colorsizes[3] = 15;
 271+ texture->colorbits[0] = 4;
 272+ texture->colorbits[1] = 4;
 273+ texture->colorbits[2] = 4;
 274+ texture->colorbits[3] = 4;
194275 break;
195276 case 9: // 16-bit RGBA1555
196277 texture->internalformats[0] = GL_RGB5_A1;
@@ -196,11 +277,24 @@
197278 texture->internalformats[1] = GL_RGBA8;
198279 texture->format = GL_BGRA;
199280 texture->type = GL_UNSIGNED_SHORT_1_5_5_5_REV;
 281+ texture->colorbits[0] = 5;
 282+ texture->colorbits[1] = 5;
 283+ texture->colorbits[2] = 5;
 284+ texture->colorbits[3] = 1;
200285 break;
201286 case 10: // 32-bit RGBA8888
202287 texture->internalformats[0] = GL_RGBA8;
203288 texture->format = GL_BGRA;
204289 texture->type = GL_UNSIGNED_INT_8_8_8_8_REV;
 290+ texture->colororder = 1;
 291+ texture->colorsizes[0] = 255;
 292+ texture->colorsizes[1] = 255;
 293+ texture->colorsizes[2] = 255;
 294+ texture->colorsizes[3] = 255;
 295+ texture->colorbits[0] = 8;
 296+ texture->colorbits[1] = 8;
 297+ texture->colorbits[2] = 8;
 298+ texture->colorbits[3] = 8;
205299 break;
206300 case 11: // 8-bit Luminance
207301 texture->internalformats[0] = GL_LUMINANCE8;
@@ -208,11 +302,29 @@
209303 texture->internalformats[2] = GL_RGBA8;
210304 texture->format = GL_LUMINANCE;
211305 texture->type = GL_UNSIGNED_BYTE;
 306+ texture->colororder = 5;
 307+ texture->colorsizes[0] = 255;
 308+ texture->colorsizes[1] = 255;
 309+ texture->colorsizes[2] = 255;
 310+ texture->colorsizes[3] = 255;
 311+ texture->colorbits[0] = 8;
 312+ texture->colorbits[1] = 0;
 313+ texture->colorbits[2] = 0;
 314+ texture->colorbits[3] = 0;
212315 break;
213316 case 12: // 8-bit Alpha
214317 texture->internalformats[0] = GL_ALPHA8;
215318 texture->format = GL_ALPHA;
216319 texture->type = GL_UNSIGNED_BYTE;
 320+ texture->colororder = 6;
 321+ texture->colorsizes[0] = 255;
 322+ texture->colorsizes[1] = 255;
 323+ texture->colorsizes[2] = 255;
 324+ texture->colorsizes[3] = 255;
 325+ texture->colorbits[0] = 0;
 326+ texture->colorbits[1] = 0;
 327+ texture->colorbits[2] = 0;
 328+ texture->colorbits[3] = 8;
217329 break;
218330 case 13: // 16-bit Luminance Alpha
219331 texture->internalformats[0] = GL_LUMINANCE8_ALPHA8;
@@ -219,36 +331,99 @@
220332 texture->internalformats[1] = GL_RGBA8;
221333 texture->format = GL_LUMINANCE_ALPHA;
222334 texture->type = GL_UNSIGNED_BYTE;
 335+ texture->colororder = 7;
 336+ texture->colorsizes[0] = 255;
 337+ texture->colorsizes[1] = 255;
 338+ texture->colorsizes[2] = 255;
 339+ texture->colorsizes[3] = 255;
 340+ texture->colorbits[0] = 8;
 341+ texture->colorbits[1] = 0;
 342+ texture->colorbits[2] = 0;
 343+ texture->colorbits[3] = 8;
223344 break;
224345 case 14: // 16-bit Z buffer
225346 texture->internalformats[0] = GL_DEPTH_COMPONENT16;
226347 texture->format = GL_DEPTH_COMPONENT;
227348 texture->type = GL_UNSIGNED_SHORT;
 349+ texture->colororder = 4;
 350+ texture->colorsizes[0] = 65535;
 351+ texture->colorsizes[1] = 65535;
 352+ texture->colorsizes[2] = 65535;
 353+ texture->colorsizes[3] = 65535;
 354+ texture->colorbits[0] = 16;
 355+ texture->colorbits[1] = 0;
 356+ texture->colorbits[2] = 0;
 357+ texture->colorbits[3] = 0;
228358 break;
229359 case 15: // 24-bit Z buffer
230360 texture->internalformats[0] = GL_DEPTH_COMPONENT24;
231361 texture->format = GL_DEPTH_COMPONENT;
232362 texture->type = GL_UNSIGNED_INT;
 363+ texture->colororder = 4;
 364+ texture->colorsizes[0] = 16777215;
 365+ texture->colorsizes[1] = 16777215;
 366+ texture->colorsizes[2] = 16777215;
 367+ texture->colorsizes[3] = 16777215;
 368+ texture->colorbits[0] = 24;
 369+ texture->colorbits[1] = 0;
 370+ texture->colorbits[2] = 0;
 371+ texture->colorbits[3] = 0;
233372 break;
234373 case 16: // 32/24 bit Z buffer
235374 texture->internalformats[0] = GL_DEPTH_COMPONENT24;
236375 texture->format = GL_DEPTH_COMPONENT;
237376 texture->type = GL_UNSIGNED_INT;
 377+ texture->colororder = 4;
 378+ texture->colorsizes[0] = 16777215;
 379+ texture->colorsizes[1] = 16777215;
 380+ texture->colorsizes[2] = 16777215;
 381+ texture->colorsizes[3] = 16777215;
 382+ texture->colorbits[0] = 24;
 383+ texture->colorbits[1] = 0;
 384+ texture->colorbits[2] = 0;
 385+ texture->colorbits[3] = 0;
238386 break;
239387 case 17: // 32-bit Z buffer
240388 texture->internalformats[0] = GL_DEPTH_COMPONENT32;
241389 texture->format = GL_DEPTH_COMPONENT;
242390 texture->type = GL_UNSIGNED_INT;
 391+ texture->colororder = 4;
 392+ texture->colorsizes[0] = 4294967295;
 393+ texture->colorsizes[1] = 4294967295;
 394+ texture->colorsizes[2] = 4294967295;
 395+ texture->colorsizes[3] = 4294967295;
 396+ texture->colorbits[0] = 32;
 397+ texture->colorbits[1] = 0;
 398+ texture->colorbits[2] = 0;
 399+ texture->colorbits[3] = 0;
243400 break;
244401 case 18: // 32-bit Z/Stencil buffer, depth LSB
245402 texture->internalformats[0] = GL_DEPTH24_STENCIL8;
246403 texture->format = GL_DEPTH_STENCIL;
247404 texture->type = GL_UNSIGNED_INT_24_8;
 405+ texture->colororder = 7;
 406+ texture->colorsizes[0] = 16777215;
 407+ texture->colorsizes[1] = 16777215;
 408+ texture->colorsizes[2] = 16777215;
 409+ texture->colorsizes[3] = 255;
 410+ texture->colorbits[0] = 24;
 411+ texture->colorbits[1] = 0;
 412+ texture->colorbits[2] = 0;
 413+ texture->colorbits[3] = 8;
248414 break;
249415 case 19: // 32-bit Z/Stencil buffer, depth MSB
250416 texture->internalformats[0] = GL_DEPTH24_STENCIL8;
251417 texture->format = GL_DEPTH_STENCIL;
252418 texture->type = GL_UNSIGNED_INT_24_8;
 419+ texture->colororder = 7;
 420+ texture->colorsizes[0] = 16777215;
 421+ texture->colorsizes[1] = 16777215;
 422+ texture->colorsizes[2] = 16777215;
 423+ texture->colorsizes[3] = 255;
 424+ texture->colorbits[0] = 24;
 425+ texture->colorbits[1] = 0;
 426+ texture->colorbits[2] = 0;
 427+ texture->colorbits[3] = 8;
253428 break;
254429 }
255430 texture->width = width;
Index: ddraw/TextureManager.h
@@ -7,7 +7,7 @@
88 // version 2.1 of the License, or (at your option) any later version.
99
1010 // This library is distributed in the hope that it will be useful,
11 -// but WITHOUT ANY WARRANTY; without even the implied warranty of
 11+// but WITHOUT ANY W ARRANTY; without even the implied warranty of
1212 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1313 // Lesser General Public License for more details.
1414
@@ -35,6 +35,9 @@
3636 GLint miplevel;
3737 DWORD bordercolor;
3838 GLint internalformats[8];
 39+ DWORD colorsizes[4];
 40+ DWORD colorbits[4];
 41+ int colororder;
3942 GLenum format;
4043 GLenum type;
4144 GLuint pbo;
@@ -41,6 +44,16 @@
4245 DDPIXELFORMAT pixelformat;
4346 } TEXTURE;
4447
 48+// Color orders:
 49+// 0 - ABGR
 50+// 1 - ARGB
 51+// 2 - BGRA
 52+// 3 - RGBA
 53+// 4 - R or Indexed
 54+// 5 - Luminance
 55+// 6 - Alpha
 56+// 7 - Luminance Alpha
 57+
4558 typedef struct
4659 {
4760 GLuint id;
Index: ddraw/glRenderer.cpp
@@ -943,6 +943,134 @@
944944 return TRUE;
945945 }
946946
 947+void SetColorFillUniform(DWORD color, DWORD *colorsizes, int colororder, DWORD *colorbits, GLint uniform, glExtensions *ext)
 948+{
 949+ DWORD r, g, b, a;
 950+ switch (colororder)
 951+ {
 952+ case 0:
 953+ r = color & colorsizes[0];
 954+ color >>= colorbits[0];
 955+ g = color & colorsizes[1];
 956+ color >>= colorbits[1];
 957+ b = color & colorsizes[2];
 958+ color >>= colorbits[2];
 959+ a = color & colorsizes[3];
 960+ ext->glUniform4i(uniform, r, g, b, a);
 961+ break;
 962+ case 1:
 963+ b = color & colorsizes[2];
 964+ color >>= colorbits[2];
 965+ g = color & colorsizes[1];
 966+ color >>= colorbits[1];
 967+ r = color & colorsizes[0];
 968+ color >>= colorbits[0];
 969+ a = color & colorsizes[3];
 970+ ext->glUniform4i(uniform, r, g, b, a);
 971+ break;
 972+ case 2:
 973+ a = color & colorsizes[3];
 974+ color >>= colorbits[3];
 975+ r = color & colorsizes[0];
 976+ color >>= colorbits[0];
 977+ g = color & colorsizes[1];
 978+ color >>= colorbits[1];
 979+ b = color & colorsizes[2];
 980+ ext->glUniform4i(uniform, r, g, b, a);
 981+ break;
 982+ case 3:
 983+ a = color & colorsizes[3];
 984+ color >>= colorbits[3];
 985+ b = color & colorsizes[2];
 986+ color >>= colorbits[2];
 987+ g = color & colorsizes[1];
 988+ color >>= colorbits[1];
 989+ r = color & colorsizes[0];
 990+ ext->glUniform4i(uniform, r, g, b, a);
 991+ break;
 992+ case 4:
 993+ r = color & colorsizes[0];
 994+ ext->glUniform4i(uniform, r, r, r, r);
 995+ break;
 996+ case 5:
 997+ r = color & colorsizes[0];
 998+ ext->glUniform4i(uniform, r, r, r, r);
 999+ break;
 1000+ case 6:
 1001+ a = color & colorsizes[3];
 1002+ ext->glUniform4i(uniform, a, a, a, a);
 1003+ break;
 1004+ case 7:
 1005+ r = color & colorsizes[0];
 1006+ color >>= colorbits[0];
 1007+ a = color & colorsizes[3];
 1008+ ext->glUniform4i(uniform, r, r, r, a);
 1009+ break;
 1010+ }
 1011+}
 1012+
 1013+void SetColorKeyUniform(DWORD key, DWORD *colorsizes, int colororder, GLint uniform, DWORD *colorbits, glExtensions *ext)
 1014+{
 1015+ DWORD r, g, b, a;
 1016+ switch (colororder)
 1017+ {
 1018+ case 0:
 1019+ r = key & colorsizes[0];
 1020+ key >>= colorbits[0];
 1021+ g = key & colorsizes[1];
 1022+ key >>= colorbits[1];
 1023+ b = key & colorsizes[2];
 1024+ ext->glUniform3i(uniform, r, g, b);
 1025+ break;
 1026+ case 1:
 1027+ b = key & colorsizes[2];
 1028+ key >>= colorbits[2];
 1029+ g = key & colorsizes[1];
 1030+ key >>= colorbits[1];
 1031+ r = key & colorsizes[0];
 1032+ ext->glUniform3i(uniform, r, g, b);
 1033+ break;
 1034+ case 2:
 1035+ a = key & colorsizes[3];
 1036+ key >>= colorbits[3];
 1037+ r = key & colorsizes[0];
 1038+ key >>= colorbits[0];
 1039+ g = key & colorsizes[1];
 1040+ key >>= colorbits[1];
 1041+ b = key & colorsizes[2];
 1042+ ext->glUniform3i(uniform, r, g, b);
 1043+ break;
 1044+ case 3:
 1045+ a = key & colorsizes[3];
 1046+ key >>= colorbits[3];
 1047+ b = key & colorsizes[2];
 1048+ key >>= colorbits[2];
 1049+ g = key & colorsizes[1];
 1050+ key >>= colorbits[1];
 1051+ r = key & colorsizes[0];
 1052+ ext->glUniform3i(uniform, r, g, b);
 1053+ break;
 1054+ case 4:
 1055+ r = key & colorsizes[0];
 1056+ if (ext->glver_major >= 3) ext->glUniform3i(uniform, r, 0, 0);
 1057+ else ext->glUniform3i(uniform, r, r, r);
 1058+ break;
 1059+ case 5:
 1060+ r = key & colorsizes[0];
 1061+ ext->glUniform3i(uniform, r, r, r);
 1062+ break;
 1063+ case 6:
 1064+ a = key & colorsizes[3];
 1065+ ext->glUniform4i(uniform, 0, 0, 0, a);
 1066+ break;
 1067+ case 7:
 1068+ r = key & colorsizes[0];
 1069+ key >>= colorbits[0];
 1070+ a = key & colorsizes[3];
 1071+ ext->glUniform4i(uniform, r, r, r, a);
 1072+ break;
 1073+ }
 1074+}
9471075 void glRenderer__Blt(glRenderer *This, LPRECT lpDestRect, glDirectDrawSurface7 *src,
9481076 glDirectDrawSurface7 *dest, LPRECT lpSrcRect, DWORD dwFlags, LPDDBLTFX lpDDBltFx)
9491077 {
@@ -1022,105 +1150,15 @@
10231151 This->blttexcoords[2].stencilt = This->blttexcoords[3].stencilt = This->bltvertices[2].y / (GLfloat)dest->fakey;
10241152 }
10251153 if(dest->zbuffer) glClear(GL_DEPTH_BUFFER_BIT);
1026 - if(dwFlags & DDBLT_COLORFILL)
1027 - {
1028 - switch(This->ddInterface->GetBPP())
1029 - {
1030 - case 8:
1031 - This->bltvertices[0].r = This->bltvertices[0].g = This->bltvertices[0].b =
1032 - This->bltvertices[1].r = This->bltvertices[1].g = This->bltvertices[1].b =
1033 - This->bltvertices[2].r = This->bltvertices[2].g = This->bltvertices[2].b =
1034 - This->bltvertices[3].r = This->bltvertices[3].g = This->bltvertices[3].b = (GLubyte)lpDDBltFx->dwFillColor;
1035 - break;
1036 - case 15:
1037 - This->bltvertices[0].r = This->bltvertices[1].r = This->bltvertices[2].r = This->bltvertices[3].r =
1038 - _5to8bit((lpDDBltFx->dwFillColor>>10) & 31);
1039 - This->bltvertices[0].g = This->bltvertices[1].g = This->bltvertices[2].g = This->bltvertices[3].g =
1040 - _5to8bit((lpDDBltFx->dwFillColor>>5) & 31);
1041 - This->bltvertices[0].b = This->bltvertices[1].b = This->bltvertices[2].b = This->bltvertices[3].b =
1042 - _5to8bit(lpDDBltFx->dwFillColor & 31);
1043 - break;
1044 - case 16:
1045 - This->bltvertices[0].r = This->bltvertices[1].r = This->bltvertices[2].r = This->bltvertices[3].r =
1046 - _5to8bit((lpDDBltFx->dwFillColor>>11) & 31);
1047 - This->bltvertices[0].g = This->bltvertices[1].g = This->bltvertices[2].g = This->bltvertices[3].g =
1048 - _6to8bit((lpDDBltFx->dwFillColor>>5) & 63);
1049 - This->bltvertices[0].b = This->bltvertices[1].b = This->bltvertices[2].b = This->bltvertices[3].b =
1050 - _5to8bit(lpDDBltFx->dwFillColor & 31);
1051 - break;
1052 - case 24:
1053 - case 32:
1054 - This->bltvertices[0].r = This->bltvertices[1].r = This->bltvertices[2].r = This->bltvertices[3].r =
1055 - ((lpDDBltFx->dwFillColor>>16) & 255);
1056 - This->bltvertices[0].g = This->bltvertices[1].g = This->bltvertices[2].g = This->bltvertices[3].g =
1057 - ((lpDDBltFx->dwFillColor>>8) & 255);
1058 - This->bltvertices[0].b = This->bltvertices[1].b = This->bltvertices[2].b = This->bltvertices[3].b =
1059 - (lpDDBltFx->dwFillColor & 255);
1060 - default:
1061 - break;
1062 - }
1063 - }
1064 - if((dwFlags & DDBLT_KEYSRC) && (src && src->colorkey[0].enabled) && !(dwFlags & DDBLT_COLORFILL))
1065 - {
1066 - switch(This->ddInterface->GetBPP())
1067 - {
1068 - case 8:
1069 - if(This->ext->glver_major >= 3) This->ext->glUniform3i(shader->shader.uniforms[5],src->colorkey[0].key.dwColorSpaceHighValue,0,0);
1070 - else This->ext->glUniform3i(shader->shader.uniforms[5],src->colorkey[0].key.dwColorSpaceHighValue,src->colorkey[0].key.dwColorSpaceHighValue,
1071 - src->colorkey[0].key.dwColorSpaceHighValue);
1072 - break;
1073 - case 15:
1074 - This->ext->glUniform3i(shader->shader.uniforms[5],_5to8bit(src->colorkey[0].key.dwColorSpaceHighValue>>10 & 31),
1075 - _5to8bit(src->colorkey[0].key.dwColorSpaceHighValue>>5 & 31),
1076 - _5to8bit(src->colorkey[0].key.dwColorSpaceHighValue & 31));
1077 - break;
1078 - case 16:
1079 - This->ext->glUniform3i(shader->shader.uniforms[5],_5to8bit(src->colorkey[0].key.dwColorSpaceHighValue>>11 & 31),
1080 - _6to8bit(src->colorkey[0].key.dwColorSpaceHighValue>>5 & 63),
1081 - _5to8bit(src->colorkey[0].key.dwColorSpaceHighValue & 31));
1082 - break;
1083 - case 24:
1084 - case 32:
1085 - default:
1086 - This->ext->glUniform3i(shader->shader.uniforms[5],(src->colorkey[0].key.dwColorSpaceHighValue>>16 & 255),
1087 - (src->colorkey[0].key.dwColorSpaceHighValue>>8 & 255),
1088 - (src->colorkey[0].key.dwColorSpaceHighValue & 255));
1089 - break;
1090 - }
1091 - This->ext->glUniform1i(shader->shader.uniforms[1],0);
1092 - }
 1154+ if (dwFlags & DDBLT_COLORFILL) SetColorFillUniform(lpDDBltFx->dwFillColor, dest->texture->colorsizes,
 1155+ dest->texture->colororder, dest->texture->colorbits, shader->shader.uniforms[12], This->ext);
 1156+ if ((dwFlags & DDBLT_KEYSRC) && (src && src->colorkey[0].enabled) && !(dwFlags & DDBLT_COLORFILL))
 1157+ SetColorKeyUniform(src->colorkey[0].key.dwColorSpaceLowValue, src->texture->colorsizes,
 1158+ src->texture->colororder, shader->shader.uniforms[5], src->texture->colorbits, This->ext);
 1159+ if (!(dwFlags & DDBLT_COLORFILL)) This->ext->glUniform1i(shader->shader.uniforms[1], 0);
10931160 if ((dwFlags & DDBLT_KEYDEST) && (This && dest->colorkey[1].enabled))
1094 - {
1095 - switch (This->ddInterface->GetBPP())
1096 - {
1097 - case 8:
1098 - if (This->ext->glver_major >= 3) This->ext->glUniform3i(shader->shader.uniforms[6], dest->colorkey[1].key.dwColorSpaceHighValue, 0, 0);
1099 - else This->ext->glUniform3i(shader->shader.uniforms[6], dest->colorkey[1].key.dwColorSpaceHighValue, dest->colorkey[1].key.dwColorSpaceHighValue,
1100 - dest->colorkey[1].key.dwColorSpaceHighValue);
1101 - break;
1102 - case 15:
1103 - This->ext->glUniform3i(shader->shader.uniforms[6], _5to8bit(dest->colorkey[1].key.dwColorSpaceHighValue >> 10 & 31),
1104 - _5to8bit(dest->colorkey[1].key.dwColorSpaceHighValue >> 5 & 31),
1105 - _5to8bit(dest->colorkey[1].key.dwColorSpaceHighValue & 31));
1106 - break;
1107 - case 16:
1108 - This->ext->glUniform3i(shader->shader.uniforms[6], _5to8bit(dest->colorkey[1].key.dwColorSpaceHighValue >> 11 & 31),
1109 - _6to8bit(dest->colorkey[1].key.dwColorSpaceHighValue >> 5 & 63),
1110 - _5to8bit(dest->colorkey[1].key.dwColorSpaceHighValue & 31));
1111 - break;
1112 - case 24:
1113 - case 32:
1114 - default:
1115 - This->ext->glUniform3i(shader->shader.uniforms[5], (dest->colorkey[1].key.dwColorSpaceHighValue >> 16 & 255),
1116 - (dest->colorkey[1].key.dwColorSpaceHighValue >> 8 & 255),
1117 - (dest->colorkey[1].key.dwColorSpaceHighValue & 255));
1118 - break;
1119 - }
1120 - }
1121 - else if (!(dwFlags & DDBLT_COLORFILL))
1122 - {
1123 - This->ext->glUniform1i(shader->shader.uniforms[1],0);
1124 - }
 1161+ SetColorKeyUniform(dest->colorkey[1].key.dwColorSpaceLowValue, dest->texture->colorsizes,
 1162+ dest->texture->colororder, shader->shader.uniforms[6], dest->texture->colorbits, This->ext);
11251163 if (usedest && (shader->shader.uniforms[2] != -1))
11261164 {
11271165 TextureManager_SetTexture(This->texman, 1, This->backbuffer);
@@ -1152,6 +1190,10 @@
11531191 }
11541192 else TextureManager_SetTexture(This->texman,0,NULL);
11551193 This->ext->glUniform4f(shader->shader.uniforms[0],0,(GLfloat)dest->fakex,0,(GLfloat)dest->fakey);
 1194+ if(src) This->ext->glUniform4i(shader->shader.uniforms[10], src->texture->colorsizes[0], src->texture->colorsizes[1],
 1195+ src->texture->colorsizes[2], src->texture->colorsizes[3]);
 1196+ if(dest) This->ext->glUniform4i(shader->shader.uniforms[11], dest->texture->colorsizes[0], dest->texture->colorsizes[1],
 1197+ dest->texture->colorsizes[2], dest->texture->colorsizes[3]);
11561198 dest->dirty |= 2;
11571199 This->util->EnableArray(shader->shader.attribs[0],true);
11581200 This->ext->glVertexAttribPointer(shader->shader.attribs[0],2,GL_FLOAT,false,sizeof(BltVertex),&This->bltvertices[0].x);