DXGL r468 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r467‎ | r468 | r469 >
Date:00:55, 24 July 2014
Author:admin
Status:new
Tags:
Comment:
Add support for pattern surfaces in Blt() command.
Add raster operations DSTINVERT, PATCOPY, and 0x0F.
Modified paths:
  • /ddraw/ShaderGen2D.cpp (modified) (history)
  • /ddraw/glDirectDrawSurface.cpp (modified) (history)
  • /ddraw/glRenderer.cpp (modified) (history)

Diff [purge]

Index: ddraw/ShaderGen2D.cpp
@@ -116,25 +116,25 @@
117117 };
118118
119119 const DWORD supported_rops[8] = {
120 - 0x00000001,
 120+ 0x00008001,
121121 0x00080000,
 122+ 0x00200000,
122123 0x00000000,
123124 0x00000000,
124 - 0x00000000,
125125 0x00000400,
126126 0x00001000,
127 - 0x80000000
 127+ 0x80010000
128128 };
129129
130130 const DWORD supported_rops_gl2[8] = {
131 - 0x00000001,
 131+ 0x00008001,
132132 0x00080000,
 133+ 0x00200000,
133134 0x00000000,
134135 0x00000000,
135 - 0x00000000,
136136 0x00000400,
137137 0x00001000,
138 - 0x80000000
 138+ 0x80010000
139139 };
140140
141141 static const char revheader[] =
@@ -164,6 +164,7 @@
165165 static const char unif_stenciltex[] = "uniform sampler2D stenciltex;\n";
166166 static const char unif_ckeysrc[] = "uniform ivec3 ckeysrc;\n";
167167 static const char unif_ckeydest[] = "uniform ivec3 ckeydest;\n";
 168+static const char unif_patternsize[] = "uniform ivec2 patternsize;\n";
168169
169170
170171 // Variables
@@ -170,12 +171,15 @@
171172 static const char var_dest[] = "ivec4 dest;\n";
172173 static const char var_pattern[] = "ivec4 pattern;\n";
173174 static const char var_pixel[] = "ivec4 pixel;\n";
 175+static const char var_patternst[] = "vec2 patternst;\n";
174176
175177 // Operations
176178 static const char op_src[] = "pixel = ivec4(texture2D(srctex,gl_TexCoord[0].st)*255.0);\n";
177179 static const char op_color[] = "pixel = ivec4(gl_Color*255.0);\n";
178180 static const char op_dest[] = "dest = ivec4(texture2D(desttex,gl_TexCoord[1].st)*255.0);\n";
179 -static const char op_pattern[] = "pattern = ivec4(texture2D(patterntex,gl_TexCoord[2].st)*255.0);\n";
 181+static const char op_pattern[] = "patternst = vec2(mod(gl_FragCoord.x,float(patternsize.x))/float(patternsize.x),\n\
 182+mod(gl_FragCoord.y, float(patternsize.y)) / float(patternsize.y));\n\
 183+pattern = ivec4(texture2D(patterntex,patternst)*255.0);\n";
180184 static const char op_destout[] = "gl_FragColor = vec4(pixel)/255.0;\n";
181185 static const char op_vertex[] = "vec4 xyzw = vec4(xy[0],xy[1],0,1);\n\
182186 mat4 proj = mat4(\n\
@@ -211,7 +215,7 @@
212216 "",
213217 "",
214218 "",
215 -"",//0F
 219+"pixel = pattern ^ ivec4(255);\n",//0F
216220 "",//10
217221 "",
218222 "",
@@ -281,6 +285,7 @@
282286 "",
283287 "",
284288 "",
 289+"pixel = dest ^ ivec4(255);\n",//55 DSTINVERT
285290 "",
286291 "",
287292 "",
@@ -290,7 +295,6 @@
291296 "",
292297 "",
293298 "",
294 -"",
295299 "",//5F
296300 "",//60
297301 "",
@@ -436,7 +440,7 @@
437441 "",
438442 "",
439443 "",//EF
440 -"",//F0
 444+"pixel = pattern;\n",//F0 PATCOPY
441445 "",
442446 "",
443447 "",
@@ -470,7 +474,7 @@
471475 "",
472476 "",
473477 "",
474 -"",//0F
 478+"pixel = ivec4(255) - pattern;\n",//0F
475479 "",//10
476480 "",
477481 "",
@@ -540,6 +544,7 @@
541545 "",
542546 "",
543547 "",
 548+"pixel = ivec4(255) - dest;\n",//55 DSTINVERT
544549 "",
545550 "",
546551 "",
@@ -549,7 +554,6 @@
550555 "",
551556 "",
552557 "",
553 -"",
554558 "",//5F
555559 "",//60
556560 "",
@@ -695,7 +699,7 @@
696700 "",
697701 "",
698702 "",//EF
699 -"",//F0
 703+"pixel = pattern;\n",//F0 PATCOPY
700704 "",
701705 "",
702706 "",
@@ -881,6 +885,11 @@
882886 if (id & DDBLT_ROP)
883887 {
884888 if (rop_texture_usage[rop] & 2) String_Append(fsrc, unif_desttex);
 889+ if (rop_texture_usage[rop] & 4)
 890+ {
 891+ String_Append(fsrc, unif_patterntex);
 892+ String_Append(fsrc, unif_patternsize);
 893+ }
885894 }
886895 if (id & 0x10000000) String_Append(fsrc, unif_stenciltex);
887896 if (id & DDBLT_KEYSRC) String_Append(fsrc, unif_ckeysrc);
@@ -890,6 +899,11 @@
891900 if (id & DDBLT_ROP)
892901 {
893902 if (rop_texture_usage[rop] & 2) String_Append(fsrc, var_dest);
 903+ if (rop_texture_usage[rop] & 4)
 904+ {
 905+ String_Append(fsrc, var_pattern);
 906+ String_Append(fsrc, var_patternst);
 907+ }
894908 }
895909
896910 // Main
@@ -901,6 +915,7 @@
902916 if (id & DDBLT_ROP)
903917 {
904918 if (rop_texture_usage[rop] & 2) String_Append(fsrc, op_dest);
 919+ if (rop_texture_usage[rop] & 4) String_Append(fsrc, op_pattern);
905920 if (intproc) String_Append(fsrc, op_ROP[rop]);
906921 else String_Append(fsrc, op_ROP_float[rop]);
907922 }
@@ -957,4 +972,5 @@
958973 gen->genshaders2D[index].shader.uniforms[4] = gen->ext->glGetUniformLocation(gen->genshaders2D[index].shader.prog, "stenciltex");
959974 gen->genshaders2D[index].shader.uniforms[5] = gen->ext->glGetUniformLocation(gen->genshaders2D[index].shader.prog, "ckeysrc");
960975 gen->genshaders2D[index].shader.uniforms[6] = gen->ext->glGetUniformLocation(gen->genshaders2D[index].shader.prog, "ckeydest");
 976+ gen->genshaders2D[index].shader.uniforms[7] = gen->ext->glGetUniformLocation(gen->genshaders2D[index].shader.prog, "patternsize");
961977 }
\ No newline at end of file
Index: ddraw/glDirectDrawSurface.cpp
@@ -609,10 +609,24 @@
610610 {
611611 HRESULT error;
612612 RECT tmprect;
 613+ glDirectDrawSurface7 *pattern;
613614 TRACE_ENTER(6,14,this,26,lpDestRect,14,lpDDSrcSurface,26,lpSrcRect,9,dwFlags,14,lpDDBltFx);
614615 if(!this) TRACE_RET(HRESULT,23,DDERR_INVALIDOBJECT);
615616 if((dwFlags & DDBLT_COLORFILL) && !lpDDBltFx) TRACE_RET(HRESULT,23,DDERR_INVALIDPARAMS);
616 - if((dwFlags & DDBLT_ROP) && !lpDDBltFx) TRACE_RET(HRESULT,23,DDERR_INVALIDPARAMS);
 617+ if (dwFlags & DDBLT_ROP)
 618+ {
 619+ if (!lpDDBltFx) TRACE_RET(HRESULT, 23, DDERR_INVALIDPARAMS);
 620+ if ((rop_texture_usage[(lpDDBltFx->dwROP >> 16) & 0xFF] & 4))
 621+ {
 622+ if (!lpDDBltFx->lpDDSPattern) TRACE_RET(HRESULT, 23, DDERR_INVALIDPARAMS);
 623+ pattern = (glDirectDrawSurface7*)lpDDBltFx->lpDDSPattern;
 624+ if (pattern->dirty & 1)
 625+ glRenderer_UploadTexture(ddInterface->renderer, pattern->buffer, pattern->bigbuffer, pattern->texture,
 626+ pattern->ddsd.dwWidth, pattern->ddsd.dwHeight, pattern->fakex, pattern->fakey, pattern->ddsd.lPitch,
 627+ (NextMultipleOf4((ddInterface->GetBPPMultipleOf8() / 8)*pattern->fakex)),
 628+ pattern->ddsd.ddpfPixelFormat.dwRGBBitCount);
 629+ }
 630+ }
617631 glDirectDrawSurface7 *src = (glDirectDrawSurface7 *)lpDDSrcSurface;
618632 if(dirty & 1)
619633 {
@@ -1598,6 +1612,20 @@
15991613 {
16001614 TRACE_ENTER(6,14,this,26,lpDestRect,14,lpDDSrcSurface,14,lpSrcRect,9,dwFlags,14,lpDDBltFx);
16011615 if(!this) TRACE_RET(HRESULT,23,DDERR_INVALIDOBJECT);
 1616+ DDBLTFX bltfx;
 1617+ if (dwFlags & DDBLT_ROP)
 1618+ {
 1619+ if (!lpDDBltFx) TRACE_RET(HRESULT, 23, DDERR_INVALIDPARAMS);
 1620+ bltfx = *lpDDBltFx;
 1621+ if ((rop_texture_usage[(lpDDBltFx->dwROP >> 16) & 0xFF] & 4))
 1622+ {
 1623+ if (!lpDDBltFx->lpDDSPattern) TRACE_RET(HRESULT, 23, DDERR_INVALIDPARAMS);
 1624+ glDirectDrawSurface1 *pattern = (glDirectDrawSurface1*)lpDDBltFx->lpDDSPattern;
 1625+ bltfx.lpDDSPattern = (LPDIRECTDRAWSURFACE)pattern->GetDDS7();
 1626+ if (lpDDSrcSurface) { TRACE_RET(HRESULT, 23, glDDS7->Blt(lpDestRect, ((glDirectDrawSurface1*)lpDDSrcSurface)->GetDDS7(), lpSrcRect, dwFlags, &bltfx)) }
 1627+ else TRACE_RET(HRESULT, 23, glDDS7->Blt(lpDestRect, NULL, lpSrcRect, dwFlags, &bltfx));
 1628+ }
 1629+ }
16021630 if(lpDDSrcSurface) {TRACE_RET(HRESULT,23,glDDS7->Blt(lpDestRect,((glDirectDrawSurface1*)lpDDSrcSurface)->GetDDS7(),lpSrcRect,dwFlags,lpDDBltFx))}
16031631 else TRACE_RET(HRESULT,23,glDDS7->Blt(lpDestRect,NULL,lpSrcRect,dwFlags,lpDDBltFx));
16041632 }
@@ -1872,7 +1900,21 @@
18731901 {
18741902 TRACE_ENTER(6,14,this,26,lpDestRect,14,lpDDSrcSurface,26,lpSrcRect,9,dwFlags,14,lpDDBltFx);
18751903 if(!this) TRACE_RET(HRESULT,23,DDERR_INVALIDOBJECT);
1876 - if(lpDDSrcSurface) {TRACE_RET(HRESULT,23,glDDS7->Blt(lpDestRect,((glDirectDrawSurface2*)lpDDSrcSurface)->GetDDS7(),lpSrcRect,dwFlags,lpDDBltFx));}
 1904+ DDBLTFX bltfx;
 1905+ if (dwFlags & DDBLT_ROP)
 1906+ {
 1907+ if (!lpDDBltFx) TRACE_RET(HRESULT, 23, DDERR_INVALIDPARAMS);
 1908+ bltfx = *lpDDBltFx;
 1909+ if ((rop_texture_usage[(lpDDBltFx->dwROP >> 16) & 0xFF] & 4))
 1910+ {
 1911+ if (!lpDDBltFx->lpDDSPattern) TRACE_RET(HRESULT, 23, DDERR_INVALIDPARAMS);
 1912+ glDirectDrawSurface2 *pattern = (glDirectDrawSurface2*)lpDDBltFx->lpDDSPattern;
 1913+ bltfx.lpDDSPattern = (LPDIRECTDRAWSURFACE)pattern->GetDDS7();
 1914+ if (lpDDSrcSurface) { TRACE_RET(HRESULT, 23, glDDS7->Blt(lpDestRect, ((glDirectDrawSurface2*)lpDDSrcSurface)->GetDDS7(), lpSrcRect, dwFlags, &bltfx)) }
 1915+ else TRACE_RET(HRESULT, 23, glDDS7->Blt(lpDestRect, NULL, lpSrcRect, dwFlags, &bltfx));
 1916+ }
 1917+ }
 1918+ if (lpDDSrcSurface) { TRACE_RET(HRESULT, 23, glDDS7->Blt(lpDestRect, ((glDirectDrawSurface2*)lpDDSrcSurface)->GetDDS7(), lpSrcRect, dwFlags, lpDDBltFx)); }
18771919 else TRACE_RET(HRESULT,23,glDDS7->Blt(lpDestRect,NULL,lpSrcRect,dwFlags,lpDDBltFx));
18781920 }
18791921 HRESULT WINAPI glDirectDrawSurface2::BltBatch(LPDDBLTBATCH lpDDBltBatch, DWORD dwCount, DWORD dwFlags)
@@ -2170,7 +2212,21 @@
21712213 {
21722214 TRACE_ENTER(6,14,this,26,lpDestRect,14,lpDDSrcSurface,26,lpSrcRect,9,dwFlags,14,lpDDBltFx);
21732215 if(!this) TRACE_RET(HRESULT,23,DDERR_INVALIDOBJECT);
2174 - if(lpDDSrcSurface) {TRACE_RET(HRESULT,23,glDDS7->Blt(lpDestRect,((glDirectDrawSurface3*)lpDDSrcSurface)->GetDDS7(),lpSrcRect,dwFlags,lpDDBltFx));}
 2216+ DDBLTFX bltfx;
 2217+ if (dwFlags & DDBLT_ROP)
 2218+ {
 2219+ if (!lpDDBltFx) TRACE_RET(HRESULT, 23, DDERR_INVALIDPARAMS);
 2220+ bltfx = *lpDDBltFx;
 2221+ if ((rop_texture_usage[(lpDDBltFx->dwROP >> 16) & 0xFF] & 4))
 2222+ {
 2223+ if (!lpDDBltFx->lpDDSPattern) TRACE_RET(HRESULT, 23, DDERR_INVALIDPARAMS);
 2224+ glDirectDrawSurface3 *pattern = (glDirectDrawSurface3*)lpDDBltFx->lpDDSPattern;
 2225+ bltfx.lpDDSPattern = (LPDIRECTDRAWSURFACE)pattern->GetDDS7();
 2226+ if (lpDDSrcSurface) { TRACE_RET(HRESULT, 23, glDDS7->Blt(lpDestRect, ((glDirectDrawSurface3*)lpDDSrcSurface)->GetDDS7(), lpSrcRect, dwFlags, &bltfx)) }
 2227+ else TRACE_RET(HRESULT, 23, glDDS7->Blt(lpDestRect, NULL, lpSrcRect, dwFlags, &bltfx));
 2228+ }
 2229+ }
 2230+ if (lpDDSrcSurface) { TRACE_RET(HRESULT, 23, glDDS7->Blt(lpDestRect, ((glDirectDrawSurface3*)lpDDSrcSurface)->GetDDS7(), lpSrcRect, dwFlags, lpDDBltFx)); }
21752231 else TRACE_RET(HRESULT,23,glDDS7->Blt(lpDestRect,NULL,lpSrcRect,dwFlags,lpDDBltFx));
21762232 }
21772233 HRESULT WINAPI glDirectDrawSurface3::BltBatch(LPDDBLTBATCH lpDDBltBatch, DWORD dwCount, DWORD dwFlags)
@@ -2474,7 +2530,21 @@
24752531 {
24762532 TRACE_ENTER(6,14,this,26,lpDestRect,14,lpDDSrcSurface,26,lpSrcRect,9,dwFlags,14,lpDDBltFx);
24772533 if(!this) TRACE_RET(HRESULT,23,DDERR_INVALIDOBJECT);
2478 - if(lpDDSrcSurface) {TRACE_RET(HRESULT,23,glDDS7->Blt(lpDestRect,((glDirectDrawSurface4*)lpDDSrcSurface)->GetDDS7(),lpSrcRect,dwFlags,lpDDBltFx));}
 2534+ DDBLTFX bltfx;
 2535+ if (dwFlags & DDBLT_ROP)
 2536+ {
 2537+ if (!lpDDBltFx) TRACE_RET(HRESULT, 23, DDERR_INVALIDPARAMS);
 2538+ bltfx = *lpDDBltFx;
 2539+ if ((rop_texture_usage[(lpDDBltFx->dwROP >> 16) & 0xFF] & 4))
 2540+ {
 2541+ if (!lpDDBltFx->lpDDSPattern) TRACE_RET(HRESULT, 23, DDERR_INVALIDPARAMS);
 2542+ glDirectDrawSurface4 *pattern = (glDirectDrawSurface4*)lpDDBltFx->lpDDSPattern;
 2543+ bltfx.lpDDSPattern = (LPDIRECTDRAWSURFACE)pattern->GetDDS7();
 2544+ if (lpDDSrcSurface) { TRACE_RET(HRESULT, 23, glDDS7->Blt(lpDestRect, ((glDirectDrawSurface4*)lpDDSrcSurface)->GetDDS7(), lpSrcRect, dwFlags, &bltfx)) }
 2545+ else TRACE_RET(HRESULT, 23, glDDS7->Blt(lpDestRect, NULL, lpSrcRect, dwFlags, &bltfx));
 2546+ }
 2547+ }
 2548+ if (lpDDSrcSurface) { TRACE_RET(HRESULT, 23, glDDS7->Blt(lpDestRect, ((glDirectDrawSurface4*)lpDDSrcSurface)->GetDDS7(), lpSrcRect, dwFlags, lpDDBltFx)); }
24792549 else TRACE_RET(HRESULT,23,glDDS7->Blt(lpDestRect,NULL,lpSrcRect,dwFlags,lpDDBltFx));
24802550 }
24812551 HRESULT WINAPI glDirectDrawSurface4::BltBatch(LPDDBLTBATCH lpDDBltBatch, DWORD dwCount, DWORD dwFlags)
Index: ddraw/glRenderer.cpp
@@ -946,6 +946,7 @@
947947 glDirectDrawSurface7 *dest, LPRECT lpSrcRect, DWORD dwFlags, LPDDBLTFX lpDDBltFx)
948948 {
949949 BOOL usedest = FALSE;
 950+ BOOL usepattern = FALSE;
950951 LONG sizes[6];
951952 RECT srcrect;
952953 RECT destrect;
@@ -966,6 +967,7 @@
967968 {
968969 shaderid = PackROPBits(lpDDBltFx->dwROP, dwFlags);
969970 if (rop_texture_usage[(lpDDBltFx->dwROP >> 16) & 0xFF] & 2) usedest = TRUE;
 971+ if (rop_texture_usage[(lpDDBltFx->dwROP >> 16) & 0xFF] & 4) usepattern = TRUE;
970972 }
971973 else shaderid = dwFlags & 0xF2FAADFF;
972974 if (usedest)
@@ -1086,6 +1088,13 @@
10871089 TextureManager_SetTexture(This->texman, 1, This->backbuffer);
10881090 This->ext->glUniform1i(shader->shader.uniforms[2], 1);
10891091 }
 1092+ if (usepattern && (shader->shader.uniforms[3] != -1))
 1093+ {
 1094+ glDirectDrawSurface7 *pattern = (glDirectDrawSurface7*)lpDDBltFx->lpDDSPattern;
 1095+ TextureManager_SetTexture(This->texman, 2, pattern->texture);
 1096+ This->ext->glUniform1i(shader->shader.uniforms[3], 2);
 1097+ This->ext->glUniform2i(shader->shader.uniforms[7], pattern->texture->width, pattern->texture->height);
 1098+ }
10901099 if (dwFlags & 0x10000000) // Use clipper
10911100 {
10921101 TextureManager_SetTexture(This->texman, 3, dest->stencil);