DXGL r915 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r914‎ | r915 | r916 >
Date:20:20, 13 April 2019
Author:admin
Status:new
Tags:
Comment:
Add RGBG and GRGB surface formats, Blt source only.
Modified paths:
  • /ddraw/ShaderGen2D.cpp (modified) (history)
  • /ddraw/fourcc.c (modified) (history)
  • /ddraw/glTexture.cpp (modified) (history)
  • /dxglcfg/surfacegen.cpp (modified) (history)

Diff [purge]

Index: ddraw/ShaderGen2D.cpp
@@ -156,6 +156,8 @@
157157 vec2 index = vec2(((myindex.x*(255.0/256.0))+(0.5/256.0)),0.5);\n\
158158 pixel = ivec4(texture2D(srcpal, index)*vec4(colorsizedest)+.5);\n";
159159 static const char op_pixelmul256[] = "pixel = ivec4(vec4(256.0)*texture2D(srctex,gl_TexCoord[0].st)*vec4(colorsizedest)+.5);\n";
 160+static const char op_pixelrgbg[] = "pixel = ivec4(readrgbg(srctex)*vec4(colorsizedest)+.5);\n";
 161+static const char op_pixelgrgb[] = "pixel = ivec4(readgrgb(srctex)*vec4(colorsizedest)+.5);\n";
160162 static const char op_pixeluyvy[] = "pixel = ivec4(readuyvy(srctex)*vec4(colorsizedest)+.5);\n";
161163 static const char op_pixelyuyv[] = "pixel = ivec4(readyuyv(srctex)*vec4(colorsizedest)+.5);\n";
162164 static const char op_pixelyvyu[] = "pixel = ivec4(readyvyu(srctex)*vec4(colorsizedest)+.5);\n";
@@ -200,7 +202,24 @@
201203 {\n\
202204 return vec4(vec3((bt601_coeff_inv * rgba.rgb) + yuv_offsets_inv),rgba.a);\n\
203205 }\n\n";
204 -static const char func_readuyvy_nearest[] =
 206+
 207+static const char func_readrgbg_nearest[] =
 208+"vec4 readrgbg(sampler2DRect texture)\n\
 209+{\n\
 210+ float x = floor(gl_TexCoord[0].s);\n\
 211+ float y = floor(gl_TexCoord[0].t);\n\
 212+ float x2 = floor(gl_TexCoord[0].s/2.0)*2.0;\n\
 213+ return vec4(texture2DRect(texture,vec2(x2,y)).r,texture2DRect(texture,vec2(x,y)).g,texture2DRect(texture,vec2(x2+1.0,y)).r,1.0);\n\
 214+}\n\n";
 215+static const char func_readgrgb_nearest[] =
 216+"vec4 readgrgb(sampler2DRect texture)\n\
 217+{\n\
 218+ float x = floor(gl_TexCoord[0].s);\n\
 219+ float y = floor(gl_TexCoord[0].t);\n\
 220+ float x2 = floor(gl_TexCoord[0].s/2.0)*2.0;\n\
 221+ return vec4(texture2DRect(texture,vec2(x2,y)).g,texture2DRect(texture,vec2(x,y)).r,texture2DRect(texture,vec2(x2+1.0,y)).g,1.0);\n\
 222+}\n\n";
 223+static const char func_readuyvy_nearest[] =
205224 "vec4 readuyvy(sampler2DRect texture)\n\
206225 {\n\
207226 float x = floor(gl_TexCoord[0].s);\n\
@@ -1029,8 +1048,10 @@
10301049 switch (srctype)
10311050 {
10321051 case 0x20:
 1052+ String_Append(fsrc, func_readrgbg_nearest);
10331053 break;
10341054 case 0x21:
 1055+ String_Append(fsrc, func_readgrgb_nearest);
10351056 break;
10361057 case 0x80:
10371058 String_Append(fsrc, func_readuyvy_nearest);
@@ -1104,8 +1125,10 @@
11051126 String_Append(fsrc, op_pixelmul256);
11061127 break;
11071128 case 0x20:
 1129+ String_Append(fsrc, op_pixelrgbg);
11081130 break;
11091131 case 0x21:
 1132+ String_Append(fsrc, op_pixelgrgb);
11101133 break;
11111134 case 0x80:
11121135 String_Append(fsrc, op_pixeluyvy);
Index: ddraw/fourcc.c
@@ -33,7 +33,9 @@
3434 MAKEFOURCC('Y','8',' ',' '),
3535 MAKEFOURCC('Y','8','0','0'),
3636 MAKEFOURCC('G','R','E','Y'),
37 - MAKEFOURCC('Y','1','6',' ')
 37+ MAKEFOURCC('Y','1','6',' '),
 38+ MAKEFOURCC('R','G','B','G'),
 39+ MAKEFOURCC('G','R','G','B')
3840 };
3941 static const int END_FOURCC = __LINE__ - 4;
4042
Index: ddraw/glTexture.cpp
@@ -1521,10 +1521,22 @@
15221522 This->packsize = 1;
15231523 break;
15241524 case DXGLPIXELFORMAT_FOURCC_RGBG:
1525 - This->blttype = 0x9E;
1526 - This->internalformats[0] = GL_RGBA8;
1527 - This->format = GL_BGRA;
1528 - This->type = GL_UNSIGNED_INT_8_8_8_8_REV;
 1525+ if (This->renderer->ext->glver_major >= 3)
 1526+ {
 1527+ This->internalformats[0] = GL_RG8;
 1528+ This->format = GL_RG;
 1529+ }
 1530+ else
 1531+ {
 1532+ This->useconv = TRUE;
 1533+ This->convfunctionupload = 9;
 1534+ This->convfunctiondownload = 10;
 1535+ This->internalsize = 4;
 1536+ This->internalformats[0] = GL_RGBA8;
 1537+ This->format = GL_RGBA;
 1538+ }
 1539+ This->blttype = 0x20;
 1540+ This->type = GL_UNSIGNED_BYTE;
15291541 if (!This->target) This->target = GL_TEXTURE_RECTANGLE;
15301542 This->colororder = 1;
15311543 This->colorsizes[0] = 255;
@@ -1535,13 +1547,25 @@
15361548 This->colorbits[1] = 8;
15371549 This->colorbits[2] = 8;
15381550 This->colorbits[3] = 8;
1539 - This->packsize = 2;
 1551+ This->packsize = 1;
15401552 break;
15411553 case DXGLPIXELFORMAT_FOURCC_GRGB:
1542 - This->blttype = 0x9F;
1543 - This->internalformats[0] = GL_RGBA8;
1544 - This->format = GL_BGRA;
1545 - This->type = GL_UNSIGNED_INT_8_8_8_8_REV;
 1554+ if (This->renderer->ext->glver_major >= 3)
 1555+ {
 1556+ This->internalformats[0] = GL_RG8;
 1557+ This->format = GL_RG;
 1558+ }
 1559+ else
 1560+ {
 1561+ This->useconv = TRUE;
 1562+ This->convfunctionupload = 9;
 1563+ This->convfunctiondownload = 10;
 1564+ This->internalsize = 4;
 1565+ This->internalformats[0] = GL_RGBA8;
 1566+ This->format = GL_RGBA;
 1567+ }
 1568+ This->blttype = 0x21;
 1569+ This->type = GL_UNSIGNED_BYTE;
15461570 if (!This->target) This->target = GL_TEXTURE_RECTANGLE;
15471571 This->colororder = 1;
15481572 This->colorsizes[0] = 255;
@@ -1552,7 +1576,7 @@
15531577 This->colorbits[1] = 8;
15541578 This->colorbits[2] = 8;
15551579 This->colorbits[3] = 8;
1556 - This->packsize = 2;
 1580+ This->packsize = 1;
15571581 break;
15581582 case DXGLPIXELFORMAT_FOURCC_AYUV: // 32-bit AYUV
15591583 This->blttype = 0x83;
Index: dxglcfg/surfacegen.cpp
@@ -240,6 +240,18 @@
241241 else return (y | (v << 8));
242242 }
243243
 244+unsigned short EncodeRGBG(unsigned long value, DWORD x)
 245+{
 246+ if (x % 2) return ((value & 0xff) | ((value >> 8) & 0xff) << 8);
 247+ else return (((value >> 16) & 0xff) | ((value >> 8) & 0xff) << 8);
 248+}
 249+
 250+unsigned short EncodeGRGB(unsigned long value, DWORD x)
 251+{
 252+ if (x % 2) return (((value >> 8) & 0xff) | (value & 0xff) << 8);
 253+ else return (((value >> 8) & 0xff) | ((value >> 16) & 0xff) << 8);
 254+}
 255+
244256 unsigned long EncodeAYUV(unsigned long value)
245257 {
246258 short r = (value >> 16) & 0xff;
@@ -371,6 +383,24 @@
372384 }
373385 }
374386 break;
 387+ case MAKEFOURCC('R', 'G', 'B', 'G'):
 388+ for (y = 0; y < ddsd.dwHeight; y++)
 389+ {
 390+ for (x = 0; x < ddsd.dwWidth; x++)
 391+ {
 392+ buffer16[x + ((ddsd.lPitch / 2) * y)] = EncodeRGBG((unsigned long)((x / (ddsd.dwWidth / 4096.)) + 4096 * floor((y / (ddsd.dwHeight / 4096.)))), x);
 393+ }
 394+ }
 395+ break;
 396+ case MAKEFOURCC('G', 'R', 'G', 'B'):
 397+ for (y = 0; y < ddsd.dwHeight; y++)
 398+ {
 399+ for (x = 0; x < ddsd.dwWidth; x++)
 400+ {
 401+ buffer16[x + ((ddsd.lPitch / 2) * y)] = EncodeGRGB((unsigned long)((x / (ddsd.dwWidth / 4096.)) + 4096 * floor((y / (ddsd.dwHeight / 4096.)))), x);
 402+ }
 403+ }
 404+ break;
375405 default:
376406 for (y = 0; y < ddsd.dwHeight; y++)
377407 {