DXGL r467 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r466‎ | r467 | r468 >
Date:18:16, 20 July 2014
Author:admin
Status:new
Tags:
Comment:
Note: Last ROP added was actually called "NOTSRCCOPY"
Add destination ROP support.
Add ROP code 0xAA.
Modified paths:
  • /ddraw/ShaderGen2D.cpp (modified) (history)
  • /ddraw/ShaderGen2D.h (modified) (history)
  • /ddraw/glRenderer.cpp (modified) (history)
  • /ddraw/glRenderer.h (modified) (history)
  • /ddraw/glUtil.h (modified) (history)

Diff [purge]

Index: ddraw/ShaderGen2D.cpp
@@ -121,7 +121,7 @@
122122 0x00000000,
123123 0x00000000,
124124 0x00000000,
125 - 0x00000000,
 125+ 0x00000400,
126126 0x00001000,
127127 0x80000000
128128 };
@@ -132,7 +132,7 @@
133133 0x00000000,
134134 0x00000000,
135135 0x00000000,
136 - 0x00000000,
 136+ 0x00000400,
137137 0x00001000,
138138 0x80000000
139139 };
@@ -154,7 +154,6 @@
155155 static const char attr_rgba[] = "attribute vec4 rgba;\n";
156156 static const char attr_srcst[] = "attribute vec2 srcst;\n";
157157 static const char attr_destst[] = "attribute vec2 destst;\n";
158 -static const char attr_patternst[] = "attribute vec2 patternst;\n";
159158 static const char attr_stencilst[] = "attribute vec2 stencilst;\n";
160159
161160 // Uniforms
@@ -188,6 +187,7 @@
189188 gl_Position = proj * xyzw;\n";
190189 static const char op_vertcolorrgb[] = "gl_FrontColor = vec4(rgb,1.0);\n";
191190 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";
192192 static const char op_texcoord3[] = "gl_TexCoord[3] = vec4(stencilst,0.0,1.0);\n";
193193 static const char op_ckeysrc[] = "if(pixel.rgb == ckeysrc) discard;\n";
194194 static const char op_clip[] = "if(texture2D(stenciltex, gl_TexCoord[3].st).r < .5) discard;";
@@ -196,7 +196,7 @@
197197
198198 // ROP Operations
199199 static const char *op_ROP[256] = {
200 -"pixel = ivec4(0);",//00 BLACKNESS
 200+"pixel = ivec4(0);\n",//00 BLACKNESS
201201 "",
202202 "",
203203 "",
@@ -247,7 +247,7 @@
248248 "",//30
249249 "",
250250 "",
251 -"pixel = pixel ^ ivec4(255);",//33 NOTSRCCOPY
 251+"pixel = pixel ^ ivec4(255);\n",//33 NOTSRCCOPY
252252 "",
253253 "",
254254 "",
@@ -366,11 +366,11 @@
367367 "",
368368 "",
369369 "",
 370+"pixel = dest;\n",
370371 "",
371372 "",
372373 "",
373374 "",
374 -"",
375375 "",//AF
376376 "",//B0
377377 "",
@@ -455,7 +455,7 @@
456456 };
457457
458458 static const char *op_ROP_float[256] = {
459 -"pixel = ivec4(0);",//00 BLACKNESS
 459+"pixel = ivec4(0);\n",//00 BLACKNESS
460460 "",
461461 "",
462462 "",
@@ -506,7 +506,7 @@
507507 "",//30
508508 "",
509509 "",
510 -"pixel = ivec4(255) - pixel;",
 510+"pixel = ivec4(255) - pixel;\n",// 33 NOTSRCCOPY
511511 "",
512512 "",
513513 "",
@@ -625,11 +625,11 @@
626626 "",
627627 "",
628628 "",
 629+"pixel = dest;\n",
629630 "",
630631 "",
631632 "",
632633 "",
633 -"",
634634 "",//AF
635635 "",//B0
636636 "",
@@ -787,6 +787,7 @@
788788 String_Append(vsrc, revheader);
789789 if (id & DDBLT_ROP)
790790 {
 791+ rop = UnpackROPBits(id);
791792 if (gen->ext->glver_major >= 3)
792793 {
793794 String_Append(vsrc, version_130);
@@ -808,6 +809,10 @@
809810 String_Append(vsrc, attr_xy);
810811 if (id & DDBLT_COLORFILL) String_Append(vsrc, attr_rgb);
811812 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+ }
812817 if (id & 0x10000000) String_Append(vsrc, attr_stencilst);
813818
814819 // Uniforms
@@ -818,6 +823,10 @@
819824 String_Append(vsrc, op_vertex);
820825 if (id & DDBLT_COLORFILL) String_Append(vsrc, op_vertcolorrgb);
821826 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+ }
822831 if (id & 0x10000000) String_Append(vsrc, op_texcoord3);
823832 String_Append(vsrc, mainend);
824833 #ifdef _DEBUG
@@ -869,11 +878,19 @@
870879
871880 // Uniforms
872881 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+ }
873886 if (id & 0x10000000) String_Append(fsrc, unif_stenciltex);
874887 if (id & DDBLT_KEYSRC) String_Append(fsrc, unif_ckeysrc);
875888
876889 // Variables
877890 String_Append(fsrc, var_pixel);
 891+ if (id & DDBLT_ROP)
 892+ {
 893+ if (rop_texture_usage[rop] & 2) String_Append(fsrc, var_dest);
 894+ }
878895
879896 // Main
880897 String_Append(fsrc, mainstart);
@@ -883,7 +900,7 @@
884901 if (id & DDBLT_KEYSRC) String_Append(fsrc, op_ckeysrc);
885902 if (id & DDBLT_ROP)
886903 {
887 - rop = UnpackROPBits(id);
 904+ if (rop_texture_usage[rop] & 2) String_Append(fsrc, op_dest);
888905 if (intproc) String_Append(fsrc, op_ROP[rop]);
889906 else String_Append(fsrc, op_ROP_float[rop]);
890907 }
@@ -932,8 +949,7 @@
933950 gen->genshaders2D[index].shader.attribs[2] = gen->ext->glGetAttribLocation(gen->genshaders2D[index].shader.prog, "rgba");
934951 gen->genshaders2D[index].shader.attribs[3] = gen->ext->glGetAttribLocation(gen->genshaders2D[index].shader.prog, "srcst");
935952 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");
938954 gen->genshaders2D[index].shader.uniforms[0] = gen->ext->glGetUniformLocation(gen->genshaders2D[index].shader.prog, "view");
939955 gen->genshaders2D[index].shader.uniforms[1] = gen->ext->glGetUniformLocation(gen->genshaders2D[index].shader.prog, "srctex");
940956 gen->genshaders2D[index].shader.uniforms[2] = gen->ext->glGetUniformLocation(gen->genshaders2D[index].shader.prog, "desttex");
Index: ddraw/ShaderGen2D.h
@@ -28,7 +28,7 @@
2929 STRING vsrc;
3030 STRING fsrc;
3131 GLint prog;
32 - GLint attribs[8];
 32+ GLint attribs[6];
3333 GLint uniforms[16];
3434 } _GENSHADER2D;
3535
Index: ddraw/glRenderer.cpp
@@ -945,22 +945,16 @@
946946 void glRenderer__Blt(glRenderer *This, LPRECT lpDestRect, glDirectDrawSurface7 *src,
947947 glDirectDrawSurface7 *dest, LPRECT lpSrcRect, DWORD dwFlags, LPDDBLTFX lpDDBltFx)
948948 {
 949+ BOOL usedest = FALSE;
949950 LONG sizes[6];
 951+ RECT srcrect;
 952+ RECT destrect;
950953 This->ddInterface->GetSizes(sizes);
951954 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;
960955 DDSURFACEDESC2 ddsd;
961956 ddsd.dwSize = sizeof(DDSURFACEDESC2);
962957 dest->GetSurfaceDesc(&ddsd);
963 - This->util->DepthTest(false);
964 - if(!lpDestRect)
 958+ if (!lpDestRect)
965959 {
966960 destrect.left = 0;
967961 destrect.top = 0;
@@ -968,7 +962,27 @@
969963 destrect.bottom = ddsd.dwHeight;
970964 }
971965 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);
973987 DDSURFACEDESC2 ddsdSrc;
974988 ddsdSrc.dwSize = sizeof(DDSURFACEDESC2);
975989 if(src) src->GetSurfaceDesc(&ddsdSrc);
@@ -1067,12 +1081,17 @@
10681082 {
10691083 This->ext->glUniform1i(shader->shader.uniforms[1],0);
10701084 }
 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+ }
10711090 if (dwFlags & 0x10000000) // Use clipper
10721091 {
10731092 TextureManager_SetTexture(This->texman, 3, dest->stencil);
10741093 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);
10771096 }
10781097 if(src)
10791098 {
@@ -1099,6 +1118,11 @@
11001119 This->util->EnableArray(shader->shader.attribs[3],true);
11011120 This->ext->glVertexAttribPointer(shader->shader.attribs[3],2,GL_FLOAT,false,sizeof(BltVertex),&This->bltvertices[0].s);
11021121 }
 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+ }
11031127 This->util->SetCull(D3DCULL_NONE);
11041128 This->util->SetPolyMode(D3DFILL_SOLID);
11051129 This->ext->glDrawRangeElements(GL_TRIANGLE_STRIP,0,3,4,GL_UNSIGNED_SHORT,bltindices);
@@ -1167,6 +1191,63 @@
11681192 This->util->SetFBO((FBO*)NULL);
11691193 }
11701194
 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+
11711252 void glRenderer__DrawScreen(glRenderer *This, TEXTURE *texture, TEXTURE *paltex, glDirectDrawSurface7 *dest, glDirectDrawSurface7 *src, GLint vsync, bool setsync)
11721253 {
11731254 int progtype;
Index: ddraw/glRenderer.h
@@ -149,6 +149,7 @@
150150 void glRenderer__DrawScreen(glRenderer *This, TEXTURE *texture, TEXTURE *paltex, glDirectDrawSurface7 *dest, glDirectDrawSurface7 *src, GLint vsync, bool setsync);
151151 void glRenderer__DeleteTexture(glRenderer *This, TEXTURE *texture);
152152 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);
153154 void glRenderer__InitD3D(glRenderer *This, int zbuffer);
154155 void glRenderer__Clear(glRenderer *This, glDirectDrawSurface7 *target, DWORD dwCount, LPD3DRECT lpRects, DWORD dwFlags, DWORD dwColor, D3DVALUE dvZ, DWORD dwStencil);
155156 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 @@
4040
4141 typedef struct
4242 {
43 - GLfloat patterns, patternt;
4443 GLfloat stencils, stencilt;
4544 } BltTexcoord;
4645