Index: ddraw/ShaderGen2D.cpp |
— | — | @@ -121,7 +121,7 @@ |
122 | 122 | 0x00000000,
|
123 | 123 | 0x00000000,
|
124 | 124 | 0x00000000,
|
125 | | - 0x00000000,
|
| 125 | + 0x00000400,
|
126 | 126 | 0x00001000,
|
127 | 127 | 0x80000000
|
128 | 128 | };
|
— | — | @@ -132,7 +132,7 @@ |
133 | 133 | 0x00000000,
|
134 | 134 | 0x00000000,
|
135 | 135 | 0x00000000,
|
136 | | - 0x00000000,
|
| 136 | + 0x00000400,
|
137 | 137 | 0x00001000,
|
138 | 138 | 0x80000000
|
139 | 139 | };
|
— | — | @@ -154,7 +154,6 @@ |
155 | 155 | static const char attr_rgba[] = "attribute vec4 rgba;\n";
|
156 | 156 | static const char attr_srcst[] = "attribute vec2 srcst;\n";
|
157 | 157 | static const char attr_destst[] = "attribute vec2 destst;\n";
|
158 | | -static const char attr_patternst[] = "attribute vec2 patternst;\n";
|
159 | 158 | static const char attr_stencilst[] = "attribute vec2 stencilst;\n";
|
160 | 159 |
|
161 | 160 | // Uniforms
|
— | — | @@ -188,6 +187,7 @@ |
189 | 188 | gl_Position = proj * xyzw;\n";
|
190 | 189 | static const char op_vertcolorrgb[] = "gl_FrontColor = vec4(rgb,1.0);\n";
|
191 | 190 | static const char op_texcoord0[] = "gl_TexCoord[0] = vec4(srcst,0.0,1.0);\n";
|
| 191 | +static const char op_texcoord1[] = "gl_TexCoord[1] = vec4(destst,0.0,1.0);\n";
|
192 | 192 | static const char op_texcoord3[] = "gl_TexCoord[3] = vec4(stencilst,0.0,1.0);\n";
|
193 | 193 | static const char op_ckeysrc[] = "if(pixel.rgb == ckeysrc) discard;\n";
|
194 | 194 | static const char op_clip[] = "if(texture2D(stenciltex, gl_TexCoord[3].st).r < .5) discard;";
|
— | — | @@ -196,7 +196,7 @@ |
197 | 197 |
|
198 | 198 | // ROP Operations
|
199 | 199 | static const char *op_ROP[256] = {
|
200 | | -"pixel = ivec4(0);",//00 BLACKNESS
|
| 200 | +"pixel = ivec4(0);\n",//00 BLACKNESS
|
201 | 201 | "",
|
202 | 202 | "",
|
203 | 203 | "",
|
— | — | @@ -247,7 +247,7 @@ |
248 | 248 | "",//30
|
249 | 249 | "",
|
250 | 250 | "",
|
251 | | -"pixel = pixel ^ ivec4(255);",//33 NOTSRCCOPY
|
| 251 | +"pixel = pixel ^ ivec4(255);\n",//33 NOTSRCCOPY
|
252 | 252 | "",
|
253 | 253 | "",
|
254 | 254 | "",
|
— | — | @@ -366,11 +366,11 @@ |
367 | 367 | "",
|
368 | 368 | "",
|
369 | 369 | "",
|
| 370 | +"pixel = dest;\n",
|
370 | 371 | "",
|
371 | 372 | "",
|
372 | 373 | "",
|
373 | 374 | "",
|
374 | | -"",
|
375 | 375 | "",//AF
|
376 | 376 | "",//B0
|
377 | 377 | "",
|
— | — | @@ -455,7 +455,7 @@ |
456 | 456 | };
|
457 | 457 |
|
458 | 458 | static const char *op_ROP_float[256] = {
|
459 | | -"pixel = ivec4(0);",//00 BLACKNESS
|
| 459 | +"pixel = ivec4(0);\n",//00 BLACKNESS
|
460 | 460 | "",
|
461 | 461 | "",
|
462 | 462 | "",
|
— | — | @@ -506,7 +506,7 @@ |
507 | 507 | "",//30
|
508 | 508 | "",
|
509 | 509 | "",
|
510 | | -"pixel = ivec4(255) - pixel;",
|
| 510 | +"pixel = ivec4(255) - pixel;\n",// 33 NOTSRCCOPY
|
511 | 511 | "",
|
512 | 512 | "",
|
513 | 513 | "",
|
— | — | @@ -625,11 +625,11 @@ |
626 | 626 | "",
|
627 | 627 | "",
|
628 | 628 | "",
|
| 629 | +"pixel = dest;\n",
|
629 | 630 | "",
|
630 | 631 | "",
|
631 | 632 | "",
|
632 | 633 | "",
|
633 | | -"",
|
634 | 634 | "",//AF
|
635 | 635 | "",//B0
|
636 | 636 | "",
|
— | — | @@ -787,6 +787,7 @@ |
788 | 788 | String_Append(vsrc, revheader);
|
789 | 789 | if (id & DDBLT_ROP)
|
790 | 790 | {
|
| 791 | + rop = UnpackROPBits(id);
|
791 | 792 | if (gen->ext->glver_major >= 3)
|
792 | 793 | {
|
793 | 794 | String_Append(vsrc, version_130);
|
— | — | @@ -808,6 +809,10 @@ |
809 | 810 | String_Append(vsrc, attr_xy);
|
810 | 811 | if (id & DDBLT_COLORFILL) String_Append(vsrc, attr_rgb);
|
811 | 812 | else String_Append(vsrc, attr_srcst);
|
| 813 | + if (id & DDBLT_ROP)
|
| 814 | + {
|
| 815 | + if (rop_texture_usage[rop] & 2) String_Append(vsrc, attr_destst);
|
| 816 | + }
|
812 | 817 | if (id & 0x10000000) String_Append(vsrc, attr_stencilst);
|
813 | 818 |
|
814 | 819 | // Uniforms
|
— | — | @@ -818,6 +823,10 @@ |
819 | 824 | String_Append(vsrc, op_vertex);
|
820 | 825 | if (id & DDBLT_COLORFILL) String_Append(vsrc, op_vertcolorrgb);
|
821 | 826 | else String_Append(vsrc, op_texcoord0);
|
| 827 | + if (id & DDBLT_ROP)
|
| 828 | + {
|
| 829 | + if (rop_texture_usage[rop] & 2) String_Append(vsrc, op_texcoord1);
|
| 830 | + }
|
822 | 831 | if (id & 0x10000000) String_Append(vsrc, op_texcoord3);
|
823 | 832 | String_Append(vsrc, mainend);
|
824 | 833 | #ifdef _DEBUG
|
— | — | @@ -869,11 +878,19 @@ |
870 | 879 |
|
871 | 880 | // Uniforms
|
872 | 881 | if (!(id & DDBLT_COLORFILL)) String_Append(fsrc, unif_srctex);
|
| 882 | + if (id & DDBLT_ROP)
|
| 883 | + {
|
| 884 | + if (rop_texture_usage[rop] & 2) String_Append(fsrc, unif_desttex);
|
| 885 | + }
|
873 | 886 | if (id & 0x10000000) String_Append(fsrc, unif_stenciltex);
|
874 | 887 | if (id & DDBLT_KEYSRC) String_Append(fsrc, unif_ckeysrc);
|
875 | 888 |
|
876 | 889 | // Variables
|
877 | 890 | String_Append(fsrc, var_pixel);
|
| 891 | + if (id & DDBLT_ROP)
|
| 892 | + {
|
| 893 | + if (rop_texture_usage[rop] & 2) String_Append(fsrc, var_dest);
|
| 894 | + }
|
878 | 895 |
|
879 | 896 | // Main
|
880 | 897 | String_Append(fsrc, mainstart);
|
— | — | @@ -883,7 +900,7 @@ |
884 | 901 | if (id & DDBLT_KEYSRC) String_Append(fsrc, op_ckeysrc);
|
885 | 902 | if (id & DDBLT_ROP)
|
886 | 903 | {
|
887 | | - rop = UnpackROPBits(id);
|
| 904 | + if (rop_texture_usage[rop] & 2) String_Append(fsrc, op_dest);
|
888 | 905 | if (intproc) String_Append(fsrc, op_ROP[rop]);
|
889 | 906 | else String_Append(fsrc, op_ROP_float[rop]);
|
890 | 907 | }
|
— | — | @@ -932,8 +949,7 @@ |
933 | 950 | gen->genshaders2D[index].shader.attribs[2] = gen->ext->glGetAttribLocation(gen->genshaders2D[index].shader.prog, "rgba");
|
934 | 951 | gen->genshaders2D[index].shader.attribs[3] = gen->ext->glGetAttribLocation(gen->genshaders2D[index].shader.prog, "srcst");
|
935 | 952 | gen->genshaders2D[index].shader.attribs[4] = gen->ext->glGetAttribLocation(gen->genshaders2D[index].shader.prog, "destst");
|
936 | | - gen->genshaders2D[index].shader.attribs[5] = gen->ext->glGetAttribLocation(gen->genshaders2D[index].shader.prog, "patternst");
|
937 | | - gen->genshaders2D[index].shader.attribs[6] = gen->ext->glGetAttribLocation(gen->genshaders2D[index].shader.prog, "stencilst");
|
| 953 | + gen->genshaders2D[index].shader.attribs[5] = gen->ext->glGetAttribLocation(gen->genshaders2D[index].shader.prog, "stencilst");
|
938 | 954 | gen->genshaders2D[index].shader.uniforms[0] = gen->ext->glGetUniformLocation(gen->genshaders2D[index].shader.prog, "view");
|
939 | 955 | gen->genshaders2D[index].shader.uniforms[1] = gen->ext->glGetUniformLocation(gen->genshaders2D[index].shader.prog, "srctex");
|
940 | 956 | gen->genshaders2D[index].shader.uniforms[2] = gen->ext->glGetUniformLocation(gen->genshaders2D[index].shader.prog, "desttex");
|
Index: ddraw/ShaderGen2D.h |
— | — | @@ -28,7 +28,7 @@ |
29 | 29 | STRING vsrc;
|
30 | 30 | STRING fsrc;
|
31 | 31 | GLint prog;
|
32 | | - GLint attribs[8];
|
| 32 | + GLint attribs[6];
|
33 | 33 | GLint uniforms[16];
|
34 | 34 | } _GENSHADER2D;
|
35 | 35 |
|
Index: ddraw/glRenderer.cpp |
— | — | @@ -945,22 +945,16 @@ |
946 | 946 | void glRenderer__Blt(glRenderer *This, LPRECT lpDestRect, glDirectDrawSurface7 *src,
|
947 | 947 | glDirectDrawSurface7 *dest, LPRECT lpSrcRect, DWORD dwFlags, LPDDBLTFX lpDDBltFx)
|
948 | 948 | {
|
| 949 | + BOOL usedest = FALSE;
|
949 | 950 | LONG sizes[6];
|
| 951 | + RECT srcrect;
|
| 952 | + RECT destrect;
|
950 | 953 | This->ddInterface->GetSizes(sizes);
|
951 | 954 | DWORD shaderid;
|
952 | | - if ((lpDDBltFx) && (dwFlags & DDBLT_ROP)) shaderid = PackROPBits(lpDDBltFx->dwROP, dwFlags);
|
953 | | - else shaderid = dwFlags & 0xF2FAADFF;
|
954 | | - This->shaders->SetShader(shaderid, NULL, NULL, 1);
|
955 | | - GenShader2D *shader = &This->shaders->gen2d->genshaders2D[This->shaders->gen3d->current_genshader];
|
956 | | - This->util->BlendEnable(false);
|
957 | | - This->util->SetFBO(dest);
|
958 | | - This->util->SetViewport(0,0,dest->fakex,dest->fakey);
|
959 | | - RECT destrect;
|
960 | 955 | DDSURFACEDESC2 ddsd;
|
961 | 956 | ddsd.dwSize = sizeof(DDSURFACEDESC2);
|
962 | 957 | dest->GetSurfaceDesc(&ddsd);
|
963 | | - This->util->DepthTest(false);
|
964 | | - if(!lpDestRect)
|
| 958 | + if (!lpDestRect)
|
965 | 959 | {
|
966 | 960 | destrect.left = 0;
|
967 | 961 | destrect.top = 0;
|
— | — | @@ -968,7 +962,27 @@ |
969 | 963 | destrect.bottom = ddsd.dwHeight;
|
970 | 964 | }
|
971 | 965 | else destrect = *lpDestRect;
|
972 | | - RECT srcrect;
|
| 966 | + if ((lpDDBltFx) && (dwFlags & DDBLT_ROP))
|
| 967 | + {
|
| 968 | + shaderid = PackROPBits(lpDDBltFx->dwROP, dwFlags);
|
| 969 | + if (rop_texture_usage[(lpDDBltFx->dwROP >> 16) & 0xFF] & 2) usedest = TRUE;
|
| 970 | + }
|
| 971 | + else shaderid = dwFlags & 0xF2FAADFF;
|
| 972 | + if (usedest)
|
| 973 | + {
|
| 974 | + This->shaders->SetShader(PROG_TEXTURE, NULL, NULL, 0);
|
| 975 | + glRenderer__DrawBackbufferRect(This, dest->texture, destrect, PROG_TEXTURE);
|
| 976 | + This->bltvertices[1].dests = This->bltvertices[3].dests = 0.;
|
| 977 | + This->bltvertices[0].dests = This->bltvertices[2].dests = (GLfloat)(destrect.right - destrect.left) / (GLfloat)This->backx;
|
| 978 | + This->bltvertices[0].destt = This->bltvertices[1].destt = 1.;
|
| 979 | + This->bltvertices[2].destt = This->bltvertices[3].destt = 1.0-((GLfloat)(destrect.bottom - destrect.top) / (GLfloat)This->backy);
|
| 980 | + }
|
| 981 | + This->shaders->SetShader(shaderid, NULL, NULL, 1);
|
| 982 | + GenShader2D *shader = &This->shaders->gen2d->genshaders2D[This->shaders->gen3d->current_genshader];
|
| 983 | + This->util->BlendEnable(false);
|
| 984 | + This->util->SetFBO(dest);
|
| 985 | + This->util->SetViewport(0,0,dest->fakex,dest->fakey);
|
| 986 | + This->util->DepthTest(false);
|
973 | 987 | DDSURFACEDESC2 ddsdSrc;
|
974 | 988 | ddsdSrc.dwSize = sizeof(DDSURFACEDESC2);
|
975 | 989 | if(src) src->GetSurfaceDesc(&ddsdSrc);
|
— | — | @@ -1067,12 +1081,17 @@ |
1068 | 1082 | {
|
1069 | 1083 | This->ext->glUniform1i(shader->shader.uniforms[1],0);
|
1070 | 1084 | }
|
| 1085 | + if (usedest && (shader->shader.uniforms[2] != -1))
|
| 1086 | + {
|
| 1087 | + TextureManager_SetTexture(This->texman, 1, This->backbuffer);
|
| 1088 | + This->ext->glUniform1i(shader->shader.uniforms[2], 1);
|
| 1089 | + }
|
1071 | 1090 | if (dwFlags & 0x10000000) // Use clipper
|
1072 | 1091 | {
|
1073 | 1092 | TextureManager_SetTexture(This->texman, 3, dest->stencil);
|
1074 | 1093 | This->ext->glUniform1i(shader->shader.uniforms[4],3);
|
1075 | | - This->util->EnableArray(shader->shader.attribs[6],true);
|
1076 | | - This->ext->glVertexAttribPointer(shader->shader.attribs[6], 2, GL_FLOAT, false, sizeof(BltTexcoord), &This->blttexcoords[0].stencils);
|
| 1094 | + This->util->EnableArray(shader->shader.attribs[5],true);
|
| 1095 | + This->ext->glVertexAttribPointer(shader->shader.attribs[5], 2, GL_FLOAT, false, sizeof(BltTexcoord), &This->blttexcoords[0].stencils);
|
1077 | 1096 | }
|
1078 | 1097 | if(src)
|
1079 | 1098 | {
|
— | — | @@ -1099,6 +1118,11 @@ |
1100 | 1119 | This->util->EnableArray(shader->shader.attribs[3],true);
|
1101 | 1120 | This->ext->glVertexAttribPointer(shader->shader.attribs[3],2,GL_FLOAT,false,sizeof(BltVertex),&This->bltvertices[0].s);
|
1102 | 1121 | }
|
| 1122 | + if ((dwFlags & DDBLT_ROP) && usedest)
|
| 1123 | + {
|
| 1124 | + This->util->EnableArray(shader->shader.attribs[4], true);
|
| 1125 | + This->ext->glVertexAttribPointer(shader->shader.attribs[4],2,GL_FLOAT,false,sizeof(BltVertex),&This->bltvertices[0].dests);
|
| 1126 | + }
|
1103 | 1127 | This->util->SetCull(D3DCULL_NONE);
|
1104 | 1128 | This->util->SetPolyMode(D3DFILL_SOLID);
|
1105 | 1129 | This->ext->glDrawRangeElements(GL_TRIANGLE_STRIP,0,3,4,GL_UNSIGNED_SHORT,bltindices);
|
— | — | @@ -1167,6 +1191,63 @@ |
1168 | 1192 | This->util->SetFBO((FBO*)NULL);
|
1169 | 1193 | }
|
1170 | 1194 |
|
| 1195 | +void glRenderer__DrawBackbufferRect(glRenderer *This, TEXTURE *texture, RECT srcrect, int progtype)
|
| 1196 | +{
|
| 1197 | + GLfloat view[4];
|
| 1198 | + int x = srcrect.right - srcrect.left;
|
| 1199 | + int y = srcrect.bottom - srcrect.top;
|
| 1200 | + TextureManager_SetActiveTexture(This->texman, 0);
|
| 1201 | + if (!This->backbuffer)
|
| 1202 | + {
|
| 1203 | + This->backbuffer = (TEXTURE*)malloc(sizeof(TEXTURE));
|
| 1204 | + ZeroMemory(This->backbuffer, sizeof(TEXTURE));
|
| 1205 | + This->backbuffer->minfilter = This->backbuffer->magfilter = GL_LINEAR;
|
| 1206 | + This->backbuffer->wraps = This->backbuffer->wrapt = GL_CLAMP_TO_EDGE;
|
| 1207 | + This->backbuffer->pixelformat.dwFlags = DDPF_RGB;
|
| 1208 | + This->backbuffer->pixelformat.dwBBitMask = 0xFF;
|
| 1209 | + This->backbuffer->pixelformat.dwGBitMask = 0xFF00;
|
| 1210 | + This->backbuffer->pixelformat.dwRBitMask = 0xFF0000;
|
| 1211 | + This->backbuffer->pixelformat.dwRGBBitCount = 32;
|
| 1212 | + TextureManager__CreateTexture(This->texman, This->backbuffer, x, y);
|
| 1213 | + This->backx = x;
|
| 1214 | + This->backy = y;
|
| 1215 | + }
|
| 1216 | + if ((This->backx < x) || (This->backy < y))
|
| 1217 | + {
|
| 1218 | + if (This->backx > x) x = This->backx;
|
| 1219 | + if (This->backx > y) y = This->backx;
|
| 1220 | + TextureManager__UploadTexture(This->texman, This->backbuffer, 0, NULL, x, y);
|
| 1221 | + This->backx = x;
|
| 1222 | + This->backy = y;
|
| 1223 | + }
|
| 1224 | + This->util->SetFBO(&This->fbo, This->backbuffer, 0, false);
|
| 1225 | + view[0] = view[2] = 0;
|
| 1226 | + view[1] = (GLfloat)This->backx;
|
| 1227 | + view[3] = (GLfloat)This->backy;
|
| 1228 | + This->util->SetViewport(0, 0, This->backx, This->backy);
|
| 1229 | + This->util->SetScissor(true, 0, 0, This->backx, This->backy);
|
| 1230 | + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
| 1231 | + This->util->SetScissor(false, 0, 0, 0, 0);
|
| 1232 | + TextureManager_SetTexture(This->texman, 0, texture);
|
| 1233 | + This->ext->glUniform4f(This->shaders->shaders[progtype].view, view[0], view[1], view[2], view[3]);
|
| 1234 | + This->bltvertices[1].s = This->bltvertices[3].s = (GLfloat)srcrect.left / (GLfloat)texture->width;
|
| 1235 | + This->bltvertices[0].s = This->bltvertices[2].s = (GLfloat)srcrect.right / (GLfloat)texture->width;
|
| 1236 | + This->bltvertices[0].t = This->bltvertices[1].t = (GLfloat)srcrect.top / (GLfloat)texture->height;
|
| 1237 | + This->bltvertices[2].t = This->bltvertices[3].t = (GLfloat)srcrect.bottom / (GLfloat)texture->height;
|
| 1238 | + This->bltvertices[1].x = This->bltvertices[3].x = 0.;
|
| 1239 | + This->bltvertices[0].x = This->bltvertices[2].x = (float)x;
|
| 1240 | + This->bltvertices[0].y = This->bltvertices[1].y = 0.;
|
| 1241 | + This->bltvertices[2].y = This->bltvertices[3].y = (float)y;
|
| 1242 | + This->util->EnableArray(This->shaders->shaders[progtype].pos, true);
|
| 1243 | + This->ext->glVertexAttribPointer(This->shaders->shaders[progtype].pos, 2, GL_FLOAT, false, sizeof(BltVertex), &This->bltvertices[0].x);
|
| 1244 | + This->util->EnableArray(This->shaders->shaders[progtype].texcoord, true);
|
| 1245 | + This->ext->glVertexAttribPointer(This->shaders->shaders[progtype].texcoord, 2, GL_FLOAT, false, sizeof(BltVertex), &This->bltvertices[0].s);
|
| 1246 | + This->util->SetCull(D3DCULL_NONE);
|
| 1247 | + This->util->SetPolyMode(D3DFILL_SOLID);
|
| 1248 | + This->ext->glDrawRangeElements(GL_TRIANGLE_STRIP, 0, 3, 4, GL_UNSIGNED_SHORT, bltindices);
|
| 1249 | + This->util->SetFBO((FBO*)NULL);
|
| 1250 | +}
|
| 1251 | +
|
1171 | 1252 | void glRenderer__DrawScreen(glRenderer *This, TEXTURE *texture, TEXTURE *paltex, glDirectDrawSurface7 *dest, glDirectDrawSurface7 *src, GLint vsync, bool setsync)
|
1172 | 1253 | {
|
1173 | 1254 | int progtype;
|
Index: ddraw/glRenderer.h |
— | — | @@ -149,6 +149,7 @@ |
150 | 150 | void glRenderer__DrawScreen(glRenderer *This, TEXTURE *texture, TEXTURE *paltex, glDirectDrawSurface7 *dest, glDirectDrawSurface7 *src, GLint vsync, bool setsync);
|
151 | 151 | void glRenderer__DeleteTexture(glRenderer *This, TEXTURE *texture);
|
152 | 152 | void glRenderer__DrawBackbuffer(glRenderer *This, TEXTURE **texture, int x, int y, int progtype);
|
| 153 | +void glRenderer__DrawBackbufferRect(glRenderer *This, TEXTURE *texture, RECT srcrect, int progtype);
|
153 | 154 | void glRenderer__InitD3D(glRenderer *This, int zbuffer);
|
154 | 155 | void glRenderer__Clear(glRenderer *This, glDirectDrawSurface7 *target, DWORD dwCount, LPD3DRECT lpRects, DWORD dwFlags, DWORD dwColor, D3DVALUE dvZ, DWORD dwStencil);
|
155 | 156 | void glRenderer__DrawPrimitives(glRenderer *This, glDirect3DDevice7 *device, GLenum mode, GLVERTEX *vertices, int *texcormats, DWORD count, LPWORD indices,
|
Index: ddraw/glUtil.h |
— | — | @@ -39,7 +39,6 @@ |
40 | 40 |
|
41 | 41 | typedef struct
|
42 | 42 | {
|
43 | | - GLfloat patterns, patternt;
|
44 | 43 | GLfloat stencils, stencilt;
|
45 | 44 | } BltTexcoord;
|
46 | 45 |
|