DXGL r904 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r903‎ | r904 | r905 >
Date:22:25, 30 March 2019
Author:admin
Status:new
Tags:
Comment:
Add texture storage for UYVY surface formats.
Modified paths:
  • /ddraw/ShaderGen2D.cpp (modified) (history)
  • /ddraw/glTexture.cpp (modified) (history)
  • /ddraw/struct.h (modified) (history)
  • /ddraw/util.c (modified) (history)
  • /ddraw/util.h (modified) (history)
  • /dxglcfg/surfacegen.cpp (modified) (history)

Diff [purge]

Index: ddraw/ShaderGen2D.cpp
@@ -72,7 +72,10 @@
7373 0x18: 24-bit Depth
7474 0x19: 24-bit Depth, 8-bit Stencil
7575 0x20: (first entry for specific RGB formats) (future)
76 -0x80: (first entry for specific YUV formats) (future)
 76+0x80: UYVY / UYNV
 77+0x81: YUY2 / YUNV
 78+0x82: RGBG
 79+0x83: GRGB
7780 0xC0: (first entry for compressed) (future)
7881 */
7982
Index: ddraw/glTexture.cpp
@@ -93,11 +93,51 @@
9494 {sizeof(DDPIXELFORMAT), DDPF_ZBUFFER, 0, 32, 0, 0xFFFFFF00, 0, 0}, // 24 bit Z buffer, 32-bit space, reversed
9595 {sizeof(DDPIXELFORMAT), DDPF_ZBUFFER, 0, 32, 0, 0xFFFFFFFF, 0, 0}, // 32 bit Z buffer
9696 {sizeof(DDPIXELFORMAT), DDPF_ZBUFFER, 0, 32, 8, 0xFFFFFF00, 0xFF, 0}, // 32 bit Z buffer with stencil
97 - {sizeof(DDPIXELFORMAT), DDPF_ZBUFFER, 0, 32, 8, 0xFF, 0xFFFFFF00, 0} // 32 bit Z buffer with stencil, reversed
 97+ {sizeof(DDPIXELFORMAT), DDPF_ZBUFFER, 0, 32, 8, 0xFF, 0xFFFFFF00, 0}, // 32 bit Z buffer with stencil, reversed
 98+ {sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('U','Y','V','Y'), 0, 0, 0, 0, 0}, // UYVY YUV surface
 99+ {sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('U','Y','N','V'), 0, 0, 0, 0, 0}, // UYVY YUV surface (NVIDIA alias)
 100+ {sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('Y','U','Y','2'), 0, 0, 0, 0, 0}, // YUY2 YUV surface
 101+ {sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('Y','U','N','V'), 0, 0, 0, 0, 0}, // YUY2 YUV surface (NVIDIA alias)
 102+ {sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('R','G','B','G'), 0, 0, 0, 0, 0}, // RGBG 16-bit pixelformat
 103+ {sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('G','R','G','B'), 0, 0, 0, 0, 0}, // GRGB 16-bit pixelformat
98104 };
99105 static const int END_TEXFORMATS = __LINE__ - 4;
100106 int numtexformats;
101107
 108+// Pixel format constants
 109+#define DXGLPIXELFORMAT_INVALID -1
 110+#define DXGLPIXELFORMAT_PAL1 0
 111+#define DXGLPIXELFORMAT_PAL2 1
 112+#define DXGLPIXELFORMAT_PAL4 2
 113+#define DXGLPIXELFORMAT_PAL8 3
 114+#define DXGLPIXELFORMAT_RGB332 4
 115+#define DXGLPIXELFORMAT_RGB555 5
 116+#define DXGLPIXELFORMAT_RGB565 6
 117+#define DXGLPIXELFORMAT_RGB888 7
 118+#define DXGLPIXELFORMAT_RGB888_REV 8
 119+#define DXGLPIXELFORMAT_RGBX8888 9
 120+#define DXGLPIXELFORMAT_RGBX8888_REV 10
 121+#define DXGLPIXELFORMAT_RGBA8332 11
 122+#define DXGLPIXELFORMAT_RGBA4444 12
 123+#define DXGLPIXELFORMAT_RGBA1555 13
 124+#define DXGLPIXELFORMAT_RGBA8888 14
 125+#define DXGLPIXELFORMAT_LUM8 15
 126+#define DXGLPIXELFORMAT_ALPHA8 16
 127+#define DXGLPIXELFORMAT_LUM_ALPHA88 17
 128+#define DXGLPIXELFORMAT_Z16 18
 129+#define DXGLPIXELFORMAT_Z24 19
 130+#define DXGLPIXELFORMAT_X8_Z24 20
 131+#define DXGLPIXELFORMAT_X8_Z24_REV 21
 132+#define DXGLPIXELFORMAT_Z32 22
 133+#define DXGLPIXELFORMAT_S8_Z32 23
 134+#define DXGLPIXELFORMAT_S8_Z32_REV 24
 135+#define DXGLPIXELFORMAT_FOURCC_UYVY 25
 136+#define DXGLPIXELFORMAT_FOURCC_UYNV 26
 137+#define DXGLPIXELFORMAT_FOURCC_YUY2 27
 138+#define DXGLPIXELFORMAT_FOURCC_YUNV 28
 139+#define DXGLPIXELFORMAT_FOURCC_RGBG 29
 140+#define DXGLPIXELFORMAT_FOURCC_GRGB 30
 141+
102142 void ClearError()
103143 {
104144 do
@@ -226,14 +266,34 @@
227267 }
228268 else
229269 {
230 - if (ddsd->ddpfPixelFormat.dwRGBBitCount == 1)
231 - newtexture->levels[0].ddsd.lPitch = NextMultipleOf8(newtexture->levels[0].ddsd.dwWidth) / 8;
232 - else if (ddsd->ddpfPixelFormat.dwRGBBitCount == 2)
233 - newtexture->levels[0].ddsd.lPitch = NextMultipleOf4(newtexture->levels[0].ddsd.dwWidth) / 4;
234 - else if (ddsd->ddpfPixelFormat.dwRGBBitCount == 4)
235 - newtexture->levels[0].ddsd.lPitch = NextMultipleOf4(newtexture->levels[0].ddsd.dwWidth) / 2;
236 - else newtexture->levels[0].ddsd.lPitch = NextMultipleOf4(newtexture->levels[0].ddsd.dwWidth *
237 - (newtexture->levels[0].ddsd.ddpfPixelFormat.dwRGBBitCount / 8));
 270+ if (ddsd->ddpfPixelFormat.dwFlags & DDPF_FOURCC)
 271+ {
 272+ switch (ddsd->ddpfPixelFormat.dwFourCC)
 273+ {
 274+ case MAKEFOURCC('U', 'Y', 'V', 'Y'):
 275+ case MAKEFOURCC('U', 'Y', 'N', 'V'):
 276+ case MAKEFOURCC('Y', 'U', 'Y', '2'):
 277+ case MAKEFOURCC('Y', 'U', 'N', 'V'):
 278+ case MAKEFOURCC('R', 'G', 'B', 'G'):
 279+ case MAKEFOURCC('G', 'R', 'G', 'B'):
 280+ newtexture->levels[0].ddsd.lPitch = NextMultipleOf4(newtexture->levels[0].ddsd.dwWidth * 2);
 281+ break;
 282+ default:
 283+ newtexture->levels[0].ddsd.lPitch = NextMultipleOf4(newtexture->levels[0].ddsd.dwWidth * 4);
 284+ break;
 285+ }
 286+ }
 287+ else
 288+ {
 289+ if (ddsd->ddpfPixelFormat.dwRGBBitCount == 1)
 290+ newtexture->levels[0].ddsd.lPitch = NextMultipleOf8(newtexture->levels[0].ddsd.dwWidth) / 8;
 291+ else if (ddsd->ddpfPixelFormat.dwRGBBitCount == 2)
 292+ newtexture->levels[0].ddsd.lPitch = NextMultipleOf4(newtexture->levels[0].ddsd.dwWidth) / 4;
 293+ else if (ddsd->ddpfPixelFormat.dwRGBBitCount == 4)
 294+ newtexture->levels[0].ddsd.lPitch = NextMultipleOf4(newtexture->levels[0].ddsd.dwWidth) / 2;
 295+ else newtexture->levels[0].ddsd.lPitch = NextMultipleOf4(newtexture->levels[0].ddsd.dwWidth *
 296+ (newtexture->levels[0].ddsd.ddpfPixelFormat.dwRGBBitCount / 8));
 297+ }
238298 }
239299 /*if (!(newtexture->levels[0].ddsd.ddsCaps.dwCaps2 & DDSCAPS2_MIPMAPSUBLEVEL))
240300 {
@@ -564,6 +624,7 @@
565625 int inpitch, outpitch;
566626 int i;
567627 char *writebuffer;
 628+ width = DivCeiling(width, This->packsize);
568629 if (dorealloc)
569630 {
570631 This->levels[level].ddsd.dwWidth = width;
@@ -744,9 +805,9 @@
745806 This->internalformats[7] = 0;
746807 ClearError();
747808 if ((This->levels[0].ddsd.dwWidth != This->bigwidth) || (This->levels[0].ddsd.dwHeight != This->bigheight))
748 - glTexImage2D(This->target, i, This->internalformats[0], This->bigwidth,
 809+ glTexImage2D(This->target, i, This->internalformats[0], DivCeiling(This->bigwidth, This->packsize),
749810 This->bigheight, 0, This->format, This->type, This->levels[i].bigbuffer);
750 - else glTexImage2D(This->target, i, This->internalformats[0], This->levels[i].ddsd.dwWidth,
 811+ else glTexImage2D(This->target, i, This->internalformats[0], DivCeiling(This->levels[i].ddsd.dwWidth, This->packsize),
751812 This->levels[i].ddsd.dwHeight, 0, This->format, This->type, This->levels[i].buffer);
752813 error = glGetError();
753814 if (error != GL_NO_ERROR)
@@ -797,6 +858,7 @@
798859 {
799860 int texformat = -1;
800861 int i;
 862+ int bytes;
801863 DWORD x, y;
802864 GLenum error;
803865 numtexformats = END_TEXFORMATS - START_TEXFORMATS;
@@ -811,7 +873,7 @@
812874 ZeroMemory(This->internalformats, 8 * sizeof(GLint));
813875 switch (texformat)
814876 {
815 - case 0: // 1-bit palette
 877+ case DXGLPIXELFORMAT_PAL1: // 1-bit palette
816878 This->useconv = TRUE;
817879 This->convfunctionupload = 11;
818880 This->convfunctiondownload = 14;
@@ -838,8 +900,9 @@
839901 This->colorbits[1] = 0;
840902 This->colorbits[2] = 0;
841903 This->colorbits[3] = 0;
 904+ This->packsize = 1;
842905 break;
843 - case 1: // 2-bit palette
 906+ case DXGLPIXELFORMAT_PAL2: // 2-bit palette
844907 This->useconv = TRUE;
845908 This->convfunctionupload = 12;
846909 This->convfunctiondownload = 15;
@@ -866,8 +929,9 @@
867930 This->colorbits[1] = 0;
868931 This->colorbits[2] = 0;
869932 This->colorbits[3] = 0;
 933+ This->packsize = 1;
870934 break;
871 - case 2: // 4-bit palette
 935+ case DXGLPIXELFORMAT_PAL4: // 4-bit palette
872936 This->useconv = TRUE;
873937 This->convfunctionupload = 13;
874938 This->convfunctiondownload = 16;
@@ -894,8 +958,9 @@
895959 This->colorbits[1] = 0;
896960 This->colorbits[2] = 0;
897961 This->colorbits[3] = 0;
 962+ This->packsize = 1;
898963 break;
899 - case 3: // 8-bit palette
 964+ case DXGLPIXELFORMAT_PAL8: // 8-bit palette
900965 This->blttype = 0x10;
901966 if (This->renderer->ext->glver_major >= 3)
902967 {
@@ -918,8 +983,9 @@
919984 This->colorbits[1] = 0;
920985 This->colorbits[2] = 0;
921986 This->colorbits[3] = 0;
 987+ This->packsize = 1;
922988 break;
923 - case 4: // 8-bit RGB332
 989+ case DXGLPIXELFORMAT_RGB332: // 8-bit RGB332
924990 This->internalformats[0] = GL_R3_G3_B2;
925991 This->internalformats[1] = GL_RGB8;
926992 This->internalformats[2] = GL_RGBA8;
@@ -935,8 +1001,9 @@
9361002 This->colorbits[1] = 3;
9371003 This->colorbits[2] = 2;
9381004 This->colorbits[3] = 0;
 1005+ This->packsize = 1;
9391006 break;
940 - case 5: // 16-bit RGB555
 1007+ case DXGLPIXELFORMAT_RGB555: // 16-bit RGB555
9411008 This->internalformats[0] = GL_RGB5_A1;
9421009 This->internalformats[1] = GL_RGBA8;
9431010 This->format = GL_BGRA;
@@ -951,8 +1018,9 @@
9521019 This->colorbits[1] = 5;
9531020 This->colorbits[2] = 5;
9541021 This->colorbits[3] = 1;
 1022+ This->packsize = 1;
9551023 break;
956 - case 6: // 16-bit RGB565
 1024+ case DXGLPIXELFORMAT_RGB565: // 16-bit RGB565
9571025 This->internalformats[0] = GL_RGB565;
9581026 This->internalformats[1] = GL_RGB8;
9591027 This->internalformats[2] = GL_RGBA8;
@@ -968,8 +1036,9 @@
9691037 This->colorbits[1] = 6;
9701038 This->colorbits[2] = 5;
9711039 This->colorbits[3] = 0;
 1040+ This->packsize = 1;
9721041 break;
973 - case 7: // 24-bit RGB888
 1042+ case DXGLPIXELFORMAT_RGB888: // 24-bit RGB888
9741043 This->internalformats[0] = GL_RGB8;
9751044 This->internalformats[1] = GL_RGBA8;
9761045 This->format = GL_BGR;
@@ -984,14 +1053,15 @@
9851054 This->colorbits[1] = 8;
9861055 This->colorbits[2] = 8;
9871056 This->colorbits[3] = 0;
 1057+ This->packsize = 1;
9881058 break;
989 - case 8: // 24-bit BGR888
 1059+ case DXGLPIXELFORMAT_RGB888_REV: // 24-bit BGR888
9901060 This->internalformats[0] = GL_RGB8;
9911061 This->internalformats[1] = GL_RGBA8;
9921062 This->format = GL_RGB;
9931063 This->type = GL_UNSIGNED_BYTE;
9941064 if (!This->target) This->target = GL_TEXTURE_2D;
995 - This->colororder = 1;
 1065+ This->colororder = 0;
9961066 This->colorsizes[0] = 255;
9971067 This->colorsizes[1] = 255;
9981068 This->colorsizes[2] = 255;
@@ -1000,8 +1070,9 @@
10011071 This->colorbits[1] = 8;
10021072 This->colorbits[2] = 8;
10031073 This->colorbits[3] = 0;
 1074+ This->packsize = 1;
10041075 break;
1005 - case 9: // 32-bit RGB888
 1076+ case DXGLPIXELFORMAT_RGBX8888: // 32-bit RGB888
10061077 This->internalformats[0] = GL_RGBA8;
10071078 This->format = GL_BGRA;
10081079 This->type = GL_UNSIGNED_INT_8_8_8_8_REV;
@@ -1015,8 +1086,9 @@
10161087 This->colorbits[1] = 8;
10171088 This->colorbits[2] = 8;
10181089 This->colorbits[3] = 0;
 1090+ This->packsize = 1;
10191091 break;
1020 - case 10: // 32-bit BGR888
 1092+ case DXGLPIXELFORMAT_RGBX8888_REV: // 32-bit BGR888
10211093 This->internalformats[0] = GL_RGBA8;
10221094 This->format = GL_RGBA;
10231095 This->type = GL_UNSIGNED_INT_8_8_8_8_REV;
@@ -1030,8 +1102,9 @@
10311103 This->colorbits[1] = 8;
10321104 This->colorbits[2] = 8;
10331105 This->colorbits[3] = 0;
 1106+ This->packsize = 1;
10341107 break;
1035 - case 11: // 16-bit RGBA8332
 1108+ case DXGLPIXELFORMAT_RGBA8332: // 16-bit RGBA8332
10361109 This->useconv = TRUE;
10371110 This->convfunctionupload = 0;
10381111 This->convfunctiondownload = 1;
@@ -1049,8 +1122,9 @@
10501123 This->colorbits[1] = 3;
10511124 This->colorbits[2] = 2;
10521125 This->colorbits[3] = 8;
 1126+ This->packsize = 1;
10531127 break;
1054 - case 12: // 16-bit RGBA4444
 1128+ case DXGLPIXELFORMAT_RGBA4444: // 16-bit RGBA4444
10551129 This->internalformats[0] = GL_RGBA4;
10561130 This->internalformats[1] = GL_RGBA8;
10571131 This->format = GL_BGRA;
@@ -1065,8 +1139,9 @@
10661140 This->colorbits[1] = 4;
10671141 This->colorbits[2] = 4;
10681142 This->colorbits[3] = 4;
 1143+ This->packsize = 1;
10691144 break;
1070 - case 13: // 16-bit RGBA1555
 1145+ case DXGLPIXELFORMAT_RGBA1555: // 16-bit RGBA1555
10711146 This->internalformats[0] = GL_RGB5_A1;
10721147 This->internalformats[1] = GL_RGBA8;
10731148 This->format = GL_BGRA;
@@ -1076,9 +1151,10 @@
10771152 This->colorbits[1] = 5;
10781153 This->colorbits[2] = 5;
10791154 This->colorbits[3] = 1;
 1155+ This->packsize = 1;
10801156 break;
1081 - case -1:
1082 - case 14: // 32-bit RGBA8888
 1157+ case DXGLPIXELFORMAT_INVALID:
 1158+ case DXGLPIXELFORMAT_RGBA8888: // 32-bit RGBA8888
10831159 This->internalformats[0] = GL_RGBA8;
10841160 This->format = GL_BGRA;
10851161 This->type = GL_UNSIGNED_INT_8_8_8_8_REV;
@@ -1092,8 +1168,9 @@
10931169 This->colorbits[1] = 8;
10941170 This->colorbits[2] = 8;
10951171 This->colorbits[3] = 8;
 1172+ This->packsize = 1;
10961173 break;
1097 - case 15: // 8-bit Luminance
 1174+ case DXGLPIXELFORMAT_LUM8: // 8-bit Luminance
10981175 This->internalformats[0] = GL_LUMINANCE8;
10991176 This->internalformats[1] = GL_RGB8;
11001177 This->internalformats[2] = GL_RGBA8;
@@ -1109,8 +1186,9 @@
11101187 This->colorbits[1] = 0;
11111188 This->colorbits[2] = 0;
11121189 This->colorbits[3] = 0;
 1190+ This->packsize = 1;
11131191 break;
1114 - case 16: // 8-bit Alpha
 1192+ case DXGLPIXELFORMAT_ALPHA8: // 8-bit Alpha
11151193 This->internalformats[0] = GL_ALPHA8;
11161194 This->format = GL_ALPHA;
11171195 This->type = GL_UNSIGNED_BYTE;
@@ -1124,8 +1202,9 @@
11251203 This->colorbits[1] = 0;
11261204 This->colorbits[2] = 0;
11271205 This->colorbits[3] = 8;
 1206+ This->packsize = 1;
11281207 break;
1129 - case 17: // 16-bit Luminance Alpha
 1208+ case DXGLPIXELFORMAT_LUM_ALPHA88: // 16-bit Luminance Alpha
11301209 This->internalformats[0] = GL_LUMINANCE8_ALPHA8;
11311210 This->internalformats[1] = GL_RGBA8;
11321211 This->format = GL_LUMINANCE_ALPHA;
@@ -1140,8 +1219,9 @@
11411220 This->colorbits[1] = 0;
11421221 This->colorbits[2] = 0;
11431222 This->colorbits[3] = 8;
 1223+ This->packsize = 1;
11441224 break;
1145 - case 18: // 16-bit Z buffer
 1225+ case DXGLPIXELFORMAT_Z16: // 16-bit Z buffer
11461226 This->internalformats[0] = GL_DEPTH_COMPONENT16;
11471227 This->format = GL_DEPTH_COMPONENT;
11481228 This->type = GL_UNSIGNED_SHORT;
@@ -1155,8 +1235,9 @@
11561236 This->colorbits[1] = 0;
11571237 This->colorbits[2] = 0;
11581238 This->colorbits[3] = 0;
 1239+ This->packsize = 1;
11591240 break;
1160 - case 19: // 24-bit Z buffer
 1241+ case DXGLPIXELFORMAT_Z24: // 24-bit Z buffer
11611242 This->useconv = TRUE;
11621243 This->convfunctionupload = 17;
11631244 This->convfunctiondownload = 18;
@@ -1175,8 +1256,9 @@
11761257 This->colorbits[1] = 0;
11771258 This->colorbits[2] = 0;
11781259 This->colorbits[3] = 0;
 1260+ This->packsize = 1;
11791261 break;
1180 - case 20: // 32/24 bit Z buffer
 1262+ case DXGLPIXELFORMAT_X8_Z24: // 32/24 bit Z buffer
11811263 This->blttype = 0x18;
11821264 This->internalformats[0] = GL_DEPTH_COMPONENT24;
11831265 This->format = GL_DEPTH_COMPONENT;
@@ -1191,8 +1273,9 @@
11921274 This->colorbits[1] = 0;
11931275 This->colorbits[2] = 0;
11941276 This->colorbits[3] = 0;
 1277+ This->packsize = 1;
11951278 break;
1196 - case 21: // 32/24 bit Z buffer reversed
 1279+ case DXGLPIXELFORMAT_X8_Z24_REV: // 32/24 bit Z buffer reversed
11971280 This->internalformats[0] = GL_DEPTH_COMPONENT24;
11981281 This->format = GL_DEPTH_COMPONENT;
11991282 This->type = GL_UNSIGNED_INT;
@@ -1206,8 +1289,9 @@
12071290 This->colorbits[1] = 0;
12081291 This->colorbits[2] = 0;
12091292 This->colorbits[3] = 0;
 1293+ This->packsize = 1;
12101294 break;
1211 - case 22: // 32-bit Z buffer
 1295+ case DXGLPIXELFORMAT_Z32: // 32-bit Z buffer
12121296 This->internalformats[0] = GL_DEPTH_COMPONENT32;
12131297 This->format = GL_DEPTH_COMPONENT;
12141298 This->type = GL_UNSIGNED_INT;
@@ -1221,8 +1305,9 @@
12221306 This->colorbits[1] = 0;
12231307 This->colorbits[2] = 0;
12241308 This->colorbits[3] = 0;
 1309+ This->packsize = 1;
12251310 break;
1226 - case 23: // 32-bit Z/Stencil buffer, depth LSB
 1311+ case DXGLPIXELFORMAT_S8_Z32: // 32-bit Z/Stencil buffer, depth LSB
12271312 This->internalformats[0] = GL_DEPTH24_STENCIL8;
12281313 This->format = GL_DEPTH_STENCIL;
12291314 This->type = GL_UNSIGNED_INT_24_8;
@@ -1236,8 +1321,9 @@
12371322 This->colorbits[1] = 0;
12381323 This->colorbits[2] = 0;
12391324 This->colorbits[3] = 8;
 1325+ This->packsize = 1;
12401326 break;
1241 - case 24: // 32-bit Z/Stencil buffer, depth MSB
 1327+ case DXGLPIXELFORMAT_S8_Z32_REV: // 32-bit Z/Stencil buffer, depth MSB
12421328 This->blttype = 0x18;
12431329 This->internalformats[0] = GL_DEPTH24_STENCIL8;
12441330 This->format = GL_DEPTH_STENCIL;
@@ -1252,7 +1338,39 @@
12531339 This->colorbits[1] = 0;
12541340 This->colorbits[2] = 0;
12551341 This->colorbits[3] = 8;
 1342+ This->packsize = 1;
12561343 break;
 1344+ case DXGLPIXELFORMAT_FOURCC_UYVY:
 1345+ case DXGLPIXELFORMAT_FOURCC_UYNV:
 1346+ This->blttype = 0x80;
 1347+ This->internalformats[0] = GL_RGBA8;
 1348+ This->format = GL_BGRA;
 1349+ This->type = GL_UNSIGNED_INT_8_8_8_8_REV;
 1350+ if (!This->target) This->target = GL_TEXTURE_RECTANGLE;
 1351+ This->colororder = 1;
 1352+ This->colorsizes[0] = 255;
 1353+ This->colorsizes[1] = 255;
 1354+ This->colorsizes[2] = 255;
 1355+ This->colorsizes[3] = 255;
 1356+ This->colorbits[0] = 8;
 1357+ This->colorbits[0] = 8;
 1358+ This->colorbits[0] = 8;
 1359+ This->colorbits[0] = 8;
 1360+ This->packsize = 2;
 1361+ break;
 1362+ case DXGLPIXELFORMAT_FOURCC_YUY2:
 1363+ case DXGLPIXELFORMAT_FOURCC_YUNV:
 1364+ FIXME("Add YUY2/YUNV mode");
 1365+ This->packsize = 2;
 1366+ break;
 1367+ case DXGLPIXELFORMAT_FOURCC_RGBG:
 1368+ FIXME("Add RGBG mode");
 1369+ This->packsize = 2;
 1370+ break;
 1371+ case DXGLPIXELFORMAT_FOURCC_GRGB:
 1372+ FIXME("Add GRGB mode");
 1373+ This->packsize = 2;
 1374+ break;
12571375 }
12581376 glGenTextures(1, &This->id);
12591377 glUtil_SetTexture(This->renderer->util, 0, This);
@@ -1294,7 +1412,7 @@
12951413 do
12961414 {
12971415 ClearError();
1298 - glTexImage2D(This->target, i, This->internalformats[0], x, y, 0, This->format, This->type, NULL);
 1416+ glTexImage2D(This->target, i, This->internalformats[0], DivCeiling(x, This->packsize), y, 0, This->format, This->type, NULL);
12991417 This->levels[i].dirty |= 2;
13001418 ShrinkMip(&x, &y);
13011419 error = glGetError();
@@ -1310,11 +1428,28 @@
13111429 }
13121430 else break;
13131431 } while (1);
1314 - This->levels[i].buffer = (char*)malloc(NextMultipleOf4((This->levels[i].ddsd.ddpfPixelFormat.dwRGBBitCount *
1315 - This->levels[i].ddsd.dwWidth) / 8) * This->levels[i].ddsd.dwHeight);
 1432+ if (This->levels[i].ddsd.ddpfPixelFormat.dwFlags & DDPF_FOURCC)
 1433+ {
 1434+ switch (This->levels[i].ddsd.ddpfPixelFormat.dwFourCC)
 1435+ {
 1436+ case MAKEFOURCC('U', 'Y', 'V', 'Y'):
 1437+ case MAKEFOURCC('U', 'Y', 'N', 'V'):
 1438+ case MAKEFOURCC('Y', 'U', 'Y', '2'):
 1439+ case MAKEFOURCC('Y', 'U', 'N', 'V'):
 1440+ case MAKEFOURCC('R', 'G', 'B', 'G'):
 1441+ case MAKEFOURCC('G', 'R', 'G', 'B'):
 1442+ bytes = 2 * This->levels[i].ddsd.dwWidth;
 1443+ break;
 1444+ default:
 1445+ bytes = 4 * This->levels[i].ddsd.dwWidth;
 1446+ break;
 1447+ }
 1448+ }
 1449+ else bytes = NextMultipleOf4((This->levels[i].ddsd.ddpfPixelFormat.dwRGBBitCount *
 1450+ This->levels[i].ddsd.dwWidth) / 8);
 1451+ This->levels[i].buffer = (char*)malloc(bytes * This->levels[i].ddsd.dwHeight);
13161452 if ((i == 0) && ((This->levels[i].ddsd.dwWidth != This->bigwidth) || (This->levels[i].ddsd.dwHeight != This->bigheight)))
1317 - This->levels[i].bigbuffer = (char *)malloc(NextMultipleOf4((This->levels[i].ddsd.ddpfPixelFormat.dwRGBBitCount *
1318 - This->bigwidth) / 8) * This->bigheight);
 1453+ This->levels[i].bigbuffer = (char *)malloc(bytes * This->bigheight);
13191454 }
13201455 }
13211456 void glTexture__Destroy(glTexture *This)
Index: ddraw/struct.h
@@ -317,6 +317,7 @@
318318 int convfunctionupload;
319319 int convfunctiondownload;
320320 int internalsize;
 321+ int packsize;
321322 unsigned char blttype;
322323 struct glTexture *palette;
323324 struct glTexture *stencil;
Index: ddraw/util.c
@@ -1,5 +1,5 @@
22 // DXGL
3 -// Copyright (C) 2013-2017 William Feely
 3+// Copyright (C) 2013-2019 William Feely
44
55 // This library is free software; you can redistribute it and/or
66 // modify it under the terms of the GNU Lesser General Public
@@ -199,3 +199,9 @@
200200 wndclassdxgltempatom = 0;
201201 }
202202 }
 203+
 204+int DivCeiling(int dividend, int divisor)
 205+{
 206+ return (dividend / divisor) + (dividend % divisor != 0);
 207+}
 208+
Index: ddraw/util.h
@@ -1,5 +1,5 @@
22 // DXGL
3 -// Copyright (C) 2013-2017 William Feely
 3+// Copyright (C) 2013-2019 William Feely
44
55 // This library is free software; you can redistribute it and/or
66 // modify it under the terms of the GNU Lesser General Public
@@ -35,6 +35,8 @@
3636 void RegisterDXGLTempWindowClass();
3737 void UnregisterDXGLTempWindowClass();
3838
 39+int DivCeiling(int dividend, int divisor);
 40+
3941 #ifdef __cplusplus
4042 }
4143 #endif
Index: dxglcfg/surfacegen.cpp
@@ -1753,7 +1753,13 @@
17541754 _T("24-bit Z,32b.rev"),
17551755 _T("32-bit Zbuffer"),
17561756 _T("32-bit Z/stencil"),
1757 - _T("32-bit Z/st.rev")
 1757+ _T("32-bit Z/st.rev"),
 1758+ _T("16-bit UYVY"),
 1759+ _T("16-bit UYNV"),
 1760+ _T("16-bit YUY2"),
 1761+ _T("16-bit YUNV"),
 1762+ _T("16-bit RGBG"),
 1763+ _T("16-bit GRGB"),
17581764 };
17591765 static const int END_SURFACEFORMATS = __LINE__ - 4;
17601766 const int numsurfaceformats = END_SURFACEFORMATS - START_SURFACEFORMATS;
@@ -1785,7 +1791,13 @@
17861792 {sizeof(DDPIXELFORMAT), DDPF_ZBUFFER, 0, 32, 0, 0xFFFFFF00, 0, 0}, // 24 bit Z buffer, 32-bit space, reversed
17871793 {sizeof(DDPIXELFORMAT), DDPF_ZBUFFER, 0, 32, 0, 0xFFFFFFFF, 0, 0}, // 32 bit Z buffer
17881794 {sizeof(DDPIXELFORMAT), DDPF_ZBUFFER, 0, 32, 8, 0xFFFFFF00, 0xFF, 0}, // 32 bit Z buffer with stencil
1789 - {sizeof(DDPIXELFORMAT), DDPF_ZBUFFER, 0, 32, 8, 0xFF, 0xFFFFFF00, 0} // 32 bit Z buffer with stencil, reversed
 1795+ {sizeof(DDPIXELFORMAT), DDPF_ZBUFFER, 0, 32, 8, 0xFF, 0xFFFFFF00, 0}, // 32 bit Z buffer with stencil, reversed
 1796+ {sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('U','Y','V','Y'), 0, 0, 0, 0, 0}, // UYVY YUV surface
 1797+ {sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('U','Y','N','V'), 0, 0, 0, 0, 0}, // UYVY YUV surface (NVIDIA alias)
 1798+ {sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('Y','U','Y','2'), 0, 0, 0, 0, 0}, // YUY2 YUV surface
 1799+ {sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('Y','U','N','V'), 0, 0, 0, 0, 0}, // YUY2 YUV surface (NVIDIA alias)
 1800+ {sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('R','G','B','G'), 0, 0, 0, 0, 0}, // RGBG 16-bit pixelformat
 1801+ {sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('G','R','G','B'), 0, 0, 0, 0, 0}, // GRGB 16-bit pixelformat
17901802 };
17911803
17921804 static const LPTSTR strErrorMessages[] =