DXGL r893 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r892‎ | r893 | r894 >
Date:23:52, 18 February 2019
Author:admin
Status:new
Tags:
Comment:
Add 1, 2, and 4 bit surface formats. Update DrawPalette of surfacegen.cpp to support these formats.
Modified paths:
  • /ddraw/colorconv.c (modified) (history)
  • /ddraw/colorconv.h (modified) (history)
  • /ddraw/glDirect3DDevice.cpp (modified) (history)
  • /ddraw/glDirectDraw.cpp (modified) (history)
  • /ddraw/glTexture.cpp (modified) (history)
  • /dxglcfg/common.h (modified) (history)
  • /dxglcfg/palette.cpp (modified) (history)
  • /dxglcfg/palette.h (modified) (history)
  • /dxglcfg/surfacegen.cpp (modified) (history)
  • /dxglcfg/tests.cpp (modified) (history)
  • /dxglcfg/tests.h (modified) (history)

Diff [purge]

Index: ddraw/colorconv.c
@@ -1,5 +1,5 @@
22 // DXGL
3 -// Copyright (C) 2018 William Feely
 3+// Copyright (C) 2018-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
@@ -21,16 +21,23 @@
2222 typedef void(*COLORCONVPROC) (size_t count, void *dest, void *src);
2323 COLORCONVPROC colorconvproc[] =
2424 {
25 - rgba8332torgba8888,
26 - rgba8888torgba8332,
27 - rgb565torgba8888,
28 - rgb565torgbx8888,
29 - rgbx8888torgb565,
30 - rgba1555torgba8888,
31 - rgba8888torgba1555,
32 - rgba4444torgba8888,
33 - rgba8888torgba4444,
34 - uyvytorgbx8888
 25+ rgba8332torgba8888, // 0
 26+ rgba8888torgba8332, // 1
 27+ rgb565torgba8888, // 2
 28+ rgb565torgbx8888, // 3
 29+ rgbx8888torgb565, // 4
 30+ rgba1555torgba8888, // 5
 31+ rgba8888torgba1555, // 6
 32+ rgba4444torgba8888, // 7
 33+ rgba8888torgba4444, // 8
 34+ uyvytorgbx8888, // 9
 35+ rgbx8888touyvy, // 10
 36+ pal1topal8, // 11
 37+ pal2topal8, // 12
 38+ pal4topal8, // 13
 39+ pal8topal1, // 14
 40+ pal8topal2, // 15
 41+ pal8topal4, // 16
3542 };
3643
3744 __inline unsigned int _1to8(unsigned int input)
@@ -63,6 +70,85 @@
6471 return (input * 259 + 33) >> 6;
6572 }
6673
 74+_inline unsigned int _8to4(unsigned int input)
 75+{
 76+ return input >> 4;
 77+}
 78+
 79+_inline unsigned int _8to2(unsigned int input)
 80+{
 81+ return input >> 6;
 82+}
 83+
 84+_inline unsigned int _8to1(unsigned int input)
 85+{
 86+ return input >> 7;
 87+}
 88+
 89+void pal1topal8(size_t count, DWORD *dest, BYTE *src)
 90+{
 91+ size_t i;
 92+ for (i = 0; i < (count >> 2); i += 2)
 93+ {
 94+ dest[i] = (_1to8(src[i >> 1] >> 7) | (_1to8((src[i >> 1] >> 6) & 1) << 8)
 95+ | (_1to8((src[i >> 1] >> 5) & 1) << 16) | (_1to8((src[i >> 1] >> 4) & 1) << 24));
 96+ dest[i + 1] = (_1to8((src[i >> 1] >> 3) & 1) | (_1to8((src[i >> 1] >> 2) & 1) << 8)
 97+ | (_1to8((src[i >> 1] >> 1) & 1) << 16) | (_1to8((src[i >> 1]) & 1) << 24));
 98+ }
 99+ if (count & 4)
 100+ {
 101+ dest[count >> 2] = (_1to8(src[count >> 4] >> 7) | (_1to8((src[count >> 4] >> 6) & 1) << 8)
 102+ | (_1to8((src[count >> 4] >> 5) & 1) << 16) | (_1to8((src[count >> 4] >> 4) & 1) << 24));
 103+ }
 104+}
 105+
 106+void pal2topal8(size_t count, DWORD *dest, BYTE *src)
 107+{
 108+ size_t i;
 109+ for (i = 0; i < (count >> 2); i ++)
 110+ dest[i] = (_2to8(src[i] >> 6) | (_2to8((src[i] >> 4) & 3) << 8)
 111+ | (_2to8((src[i] >> 2) & 3) << 16) | (_2to8((src[i] & 3)) << 24));
 112+}
 113+
 114+void pal4topal8(size_t count, WORD *dest, BYTE *src)
 115+{
 116+ size_t i;
 117+ for (i = 0; i < (count >> 1); i++)
 118+ dest[i] = (_4to8(src[i] >> 4) | (_4to8(src[i] & 15) << 8));
 119+}
 120+
 121+void pal8topal4(size_t count, BYTE *dest, WORD *src)
 122+{
 123+ size_t i;
 124+ for (i = 0; i < count >> 1; i++)
 125+ dest[i] = ((_8to4(src[i] & 255) << 4) | _8to4(src[i] >> 8));
 126+}
 127+
 128+void pal8topal2(size_t count, BYTE *dest, DWORD *src)
 129+{
 130+ size_t i;
 131+ for (i = 0; i < count >> 2; i++)
 132+ dest[i] = ((_8to2(src[i] & 255) << 6) | (_8to2((src[i] >> 8) & 255) << 4)
 133+ | (_8to2((src[i] >> 16) & 255) << 2) | _8to2(src[i] >> 24));
 134+}
 135+
 136+void pal8topal1(size_t count, BYTE *dest, DWORD *src)
 137+{
 138+ size_t i;
 139+ for (i = 0; i < (count >> 2); i += 2)
 140+ {
 141+ dest[i >> 1] = ((_8to1(src[i] & 255) << 7) | (_8to1((src[i] >> 8) & 255) << 6)
 142+ | (_8to1((src[i] >> 16) & 255) << 5) | (_8to1(src[i] >> 24) << 4)
 143+ | (_8to1(src[i + 1] & 255) << 3) | (_8to1((src[i + 1] >> 8) & 255) << 2)
 144+ | (_8to1((src[i + 1]) >> 16) << 1) | _8to1(src[i + 1] >> 24));
 145+ }
 146+ if (count & 4)
 147+ {
 148+ dest[count >> 2] = ((_8to1(src[i] & 255) << 7) | (_8to1((src[i] >> 8) & 255) << 6)
 149+ | (_8to1((src[i] >> 16) & 255) << 5) | (_8to1(src[i] >> 24) << 4));
 150+ }
 151+}
 152+
67153 void rgba8332torgba8888(size_t count, DWORD *dest, WORD *src)
68154 {
69155 size_t i;
@@ -199,4 +285,9 @@
200286 y = (src[i] >> 24) & 0xFF;
201287 dest[(i << 1)+1] = yuvtorgb(y, u, v);
202288 }
 289+}
 290+
 291+void rgbx8888touyvy(size_t count, DWORD *dest, DWORD *src)
 292+{
 293+
203294 }
\ No newline at end of file
Index: ddraw/colorconv.h
@@ -1,5 +1,5 @@
22 // DXGL
3 -// Copyright (C) 2018 William Feely
 3+// Copyright (C) 2018-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
@@ -26,6 +26,12 @@
2727 typedef void(*COLORCONVPROC) (size_t count, void *dest, void *src);
2828 extern COLORCONVPROC colorconvproc[];
2929
 30+void pal1topal8(size_t count, DWORD *dest, BYTE *src);
 31+void pal2topal8(size_t count, DWORD *dest, BYTE *src);
 32+void pal4topal8(size_t count, WORD *dest, BYTE *src);
 33+void pal8topal4(size_t count, BYTE *dest, WORD *src);
 34+void pal8topal2(size_t count, BYTE *dest, DWORD *src);
 35+void pal8topal1(size_t count, BYTE *dest, DWORD *src);
3036 void rgba8332torgba8888(size_t count, DWORD *dest, WORD *src);
3137 void rgba8888torgba8332(size_t count, WORD *dest, DWORD *src);
3238 void rgb565torgba8888(size_t count, DWORD *dest, WORD *src);
@@ -36,6 +42,7 @@
3743 void rgba4444torgba8888(size_t count, DWORD *dest, WORD *src);
3844 void rgba8888torgba4444(size_t count, WORD *dest, DWORD *src);
3945 void uyvytorgbx8888(size_t count, DWORD *dest, DWORD *src);
 46+void rgbx8888touyvy(size_t count, DWORD *dest, DWORD *src);
4047
4148 #ifdef __cplusplus
4249 }
Index: ddraw/glDirect3DDevice.cpp
@@ -1,5 +1,5 @@
22 // DXGL
3 -// Copyright (C) 2011-2016 William Feely
 3+// Copyright (C) 2011-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
@@ -1018,6 +1018,10 @@
10191019 {
10201020 if (i == 7) continue;
10211021 if(::texformats[i].dwFlags & DDPF_ZBUFFER) continue;
 1022+ //FIXME: Remove these line after implementing palette textures
 1023+ if(::texformats[i].dwFlags & DDPF_PALETTEINDEXED1) continue;
 1024+ if(::texformats[i].dwFlags & DDPF_PALETTEINDEXED2) continue;
 1025+ if(::texformats[i].dwFlags & DDPF_PALETTEINDEXED4) continue;
10221026 if(::texformats[i].dwFlags & DDPF_PALETTEINDEXED8) continue;
10231027 memcpy(&fmt,&::texformats[i],sizeof(DDPIXELFORMAT));
10241028 result = lpd3dEnumPixelProc(&fmt,lpArg);
Index: ddraw/glDirectDraw.cpp
@@ -1580,7 +1580,7 @@
15811581 ddsdMode.dwHeight = primaryy;
15821582 ddsdMode.dwRefreshRate = primaryrefresh;
15831583 if(primarybpp == 15) ddsdMode.lPitch = NextMultipleOf4(primaryx * 2);
1584 - else if(primarybpp == 4) ddsdMode.lPitch = NextMultipleOf4(primaryx / 2);
 1584+ else if(primarybpp == 4) ddsdMode.lPitch = NextMultipleOf2(primaryx / 2);
15851585 else ddsdMode.lPitch = NextMultipleOf4(primaryx * (primarybpp / 8));
15861586 if(lpDDSurfaceDesc2->dwSize < sizeof(DDSURFACEDESC)) ERR(DDERR_INVALIDPARAMS);
15871587 if(lpDDSurfaceDesc2->dwSize > sizeof(DDSURFACEDESC2))
Index: ddraw/glTexture.cpp
@@ -69,6 +69,9 @@
7070 static const int START_TEXFORMATS = __LINE__;
7171 const DDPIXELFORMAT texformats[] =
7272 { // Size Flags FOURCC bits R/Ymask G/U/Zmask B/V/STmask A/Zmask
 73+ {sizeof(DDPIXELFORMAT), DDPF_RGB|DDPF_PALETTEINDEXED1, 0, 1, 0, 0, 0, 0}, // 8-bit paletted
 74+ {sizeof(DDPIXELFORMAT), DDPF_RGB|DDPF_PALETTEINDEXED2, 0, 2, 0, 0, 0, 0}, // 8-bit paletted
 75+ {sizeof(DDPIXELFORMAT), DDPF_RGB|DDPF_PALETTEINDEXED4, 0, 4, 0, 0, 0, 0}, // 8-bit paletted
7376 {sizeof(DDPIXELFORMAT), DDPF_RGB|DDPF_PALETTEINDEXED8, 0, 8, 0, 0, 0, 0}, // 8-bit paletted
7477 {sizeof(DDPIXELFORMAT), DDPF_RGB, 0, 8, 0xE0, 0x1C, 0x3, 0}, // 8 bit 332
7578 {sizeof(DDPIXELFORMAT), DDPF_RGB, 0, 16, 0x7C00, 0x3E0, 0x1F, 0}, // 15 bit 555
@@ -219,8 +222,17 @@
220223 break;
221224 }
222225 }
223 - else newtexture->levels[0].ddsd.lPitch = NextMultipleOf4(newtexture->levels[0].ddsd.dwWidth *
224 - (newtexture->levels[0].ddsd.ddpfPixelFormat.dwRGBBitCount / 8));
 226+ else
 227+ {
 228+ if (ddsd->ddpfPixelFormat.dwRGBBitCount == 1)
 229+ newtexture->levels[0].ddsd.lPitch = NextMultipleOf8(newtexture->levels[0].ddsd.dwWidth) / 8;
 230+ else if (ddsd->ddpfPixelFormat.dwRGBBitCount == 2)
 231+ newtexture->levels[0].ddsd.lPitch = NextMultipleOf4(newtexture->levels[0].ddsd.dwWidth) / 4;
 232+ else if (ddsd->ddpfPixelFormat.dwRGBBitCount == 4)
 233+ newtexture->levels[0].ddsd.lPitch = NextMultipleOf4(newtexture->levels[0].ddsd.dwWidth) / 2;
 234+ else newtexture->levels[0].ddsd.lPitch = NextMultipleOf4(newtexture->levels[0].ddsd.dwWidth *
 235+ (newtexture->levels[0].ddsd.ddpfPixelFormat.dwRGBBitCount / 8));
 236+ }
225237 /*if (!(newtexture->levels[0].ddsd.ddsCaps.dwCaps2 & DDSCAPS2_MIPMAPSUBLEVEL))
226238 {
227239 newtexture->pixelformat = newtexture->levels[0].ddsd.ddpfPixelFormat;
@@ -797,8 +809,11 @@
798810 ZeroMemory(This->internalformats, 8 * sizeof(GLint));
799811 switch (texformat)
800812 {
801 - case -1:
802 - case 0: // 8-bit palette
 813+ case 0: // 1-bit palette
 814+ This->useconv = TRUE;
 815+ This->convfunctionupload = 11;
 816+ This->convfunctiondownload = 14;
 817+ This->internalsize = 1; // Store in R8/LUMINANCE8 texture
803818 if (This->renderer->ext->glver_major >= 3)
804819 {
805820 This->internalformats[0] = GL_R8;
@@ -811,6 +826,80 @@
812827 }
813828 This->type = GL_UNSIGNED_BYTE;
814829 This->colororder = 4;
 830+ This->colorsizes[0] = 1;
 831+ This->colorsizes[1] = 1;
 832+ This->colorsizes[2] = 1;
 833+ This->colorsizes[3] = 1;
 834+ This->colorbits[0] = 1;
 835+ This->colorbits[1] = 0;
 836+ This->colorbits[2] = 0;
 837+ This->colorbits[3] = 0;
 838+ break;
 839+ case 1: // 2-bit palette
 840+ This->useconv = TRUE;
 841+ This->convfunctionupload = 12;
 842+ This->convfunctiondownload = 15;
 843+ This->internalsize = 1; // Store in R8/LUMINANCE8 texture
 844+ if (This->renderer->ext->glver_major >= 3)
 845+ {
 846+ This->internalformats[0] = GL_R8;
 847+ This->format = GL_RED;
 848+ }
 849+ else
 850+ {
 851+ This->internalformats[0] = GL_RGBA8;
 852+ This->format = GL_LUMINANCE;
 853+ }
 854+ This->type = GL_UNSIGNED_BYTE;
 855+ This->colororder = 4;
 856+ This->colorsizes[0] = 3;
 857+ This->colorsizes[1] = 3;
 858+ This->colorsizes[2] = 3;
 859+ This->colorsizes[3] = 3;
 860+ This->colorbits[0] = 2;
 861+ This->colorbits[1] = 0;
 862+ This->colorbits[2] = 0;
 863+ This->colorbits[3] = 0;
 864+ break;
 865+ case 2: // 4-bit palette
 866+ This->useconv = TRUE;
 867+ This->convfunctionupload = 13;
 868+ This->convfunctiondownload = 16;
 869+ This->internalsize = 1; // Store in R8/LUMINANCE8 texture
 870+ if (This->renderer->ext->glver_major >= 3)
 871+ {
 872+ This->internalformats[0] = GL_R8;
 873+ This->format = GL_RED;
 874+ }
 875+ else
 876+ {
 877+ This->internalformats[0] = GL_RGBA8;
 878+ This->format = GL_LUMINANCE;
 879+ }
 880+ This->type = GL_UNSIGNED_BYTE;
 881+ This->colororder = 4;
 882+ This->colorsizes[0] = 15;
 883+ This->colorsizes[1] = 15;
 884+ This->colorsizes[2] = 15;
 885+ This->colorsizes[3] = 15;
 886+ This->colorbits[0] = 4;
 887+ This->colorbits[1] = 0;
 888+ This->colorbits[2] = 0;
 889+ This->colorbits[3] = 0;
 890+ break;
 891+ case 3: // 8-bit palette
 892+ if (This->renderer->ext->glver_major >= 3)
 893+ {
 894+ This->internalformats[0] = GL_R8;
 895+ This->format = GL_RED;
 896+ }
 897+ else
 898+ {
 899+ This->internalformats[0] = GL_RGBA8;
 900+ This->format = GL_LUMINANCE;
 901+ }
 902+ This->type = GL_UNSIGNED_BYTE;
 903+ This->colororder = 4;
815904 This->colorsizes[0] = 255;
816905 This->colorsizes[1] = 255;
817906 This->colorsizes[2] = 255;
@@ -820,7 +909,7 @@
821910 This->colorbits[2] = 0;
822911 This->colorbits[3] = 0;
823912 break;
824 - case 1: // 8-bit RGB332
 913+ case 4: // 8-bit RGB332
825914 This->internalformats[0] = GL_R3_G3_B2;
826915 This->internalformats[1] = GL_RGB8;
827916 This->internalformats[2] = GL_RGBA8;
@@ -836,7 +925,7 @@
837926 This->colorbits[2] = 2;
838927 This->colorbits[3] = 0;
839928 break;
840 - case 2: // 16-bit RGB555
 929+ case 5: // 16-bit RGB555
841930 This->internalformats[0] = GL_RGB5_A1;
842931 This->internalformats[1] = GL_RGBA8;
843932 This->format = GL_BGRA;
@@ -851,7 +940,7 @@
852941 This->colorbits[2] = 5;
853942 This->colorbits[3] = 1;
854943 break;
855 - case 3: // 16-bit RGB565
 944+ case 6: // 16-bit RGB565
856945 This->internalformats[0] = GL_RGB565;
857946 This->internalformats[1] = GL_RGB8;
858947 This->internalformats[2] = GL_RGBA8;
@@ -867,7 +956,7 @@
868957 This->colorbits[2] = 5;
869958 This->colorbits[3] = 0;
870959 break;
871 - case 4: // 24-bit RGB888
 960+ case 7: // 24-bit RGB888
872961 This->internalformats[0] = GL_RGB8;
873962 This->internalformats[1] = GL_RGBA8;
874963 This->format = GL_BGR;
@@ -882,7 +971,7 @@
883972 This->colorbits[2] = 8;
884973 This->colorbits[3] = 0;
885974 break;
886 - case 5: // 24-bit BGR888
 975+ case 8: // 24-bit BGR888
887976 This->internalformats[0] = GL_RGB8;
888977 This->internalformats[1] = GL_RGBA8;
889978 This->format = GL_RGB;
@@ -897,7 +986,7 @@
898987 This->colorbits[2] = 8;
899988 This->colorbits[3] = 0;
900989 break;
901 - case 6: // 32-bit RGB888
 990+ case 9: // 32-bit RGB888
902991 This->internalformats[0] = GL_RGBA8;
903992 This->format = GL_BGRA;
904993 This->type = GL_UNSIGNED_INT_8_8_8_8_REV;
@@ -911,7 +1000,7 @@
9121001 This->colorbits[2] = 8;
9131002 This->colorbits[3] = 0;
9141003 break;
915 - case 7: // 32-bit BGR888
 1004+ case 10: // 32-bit BGR888
9161005 This->internalformats[0] = GL_RGBA8;
9171006 This->format = GL_RGBA;
9181007 This->type = GL_UNSIGNED_INT_8_8_8_8_REV;
@@ -925,7 +1014,7 @@
9261015 This->colorbits[2] = 8;
9271016 This->colorbits[3] = 0;
9281017 break;
929 - case 8: // 16-bit RGBA8332
 1018+ case 11: // 16-bit RGBA8332
9301019 This->useconv = TRUE;
9311020 This->convfunctionupload = 0;
9321021 This->convfunctiondownload = 1;
@@ -943,7 +1032,7 @@
9441033 This->colorbits[2] = 2;
9451034 This->colorbits[3] = 8;
9461035 break;
947 - case 9: // 16-bit RGBA4444
 1036+ case 12: // 16-bit RGBA4444
9481037 This->internalformats[0] = GL_RGBA4;
9491038 This->internalformats[1] = GL_RGBA8;
9501039 This->format = GL_BGRA;
@@ -958,7 +1047,7 @@
9591048 This->colorbits[2] = 4;
9601049 This->colorbits[3] = 4;
9611050 break;
962 - case 10: // 16-bit RGBA1555
 1051+ case 13: // 16-bit RGBA1555
9631052 This->internalformats[0] = GL_RGB5_A1;
9641053 This->internalformats[1] = GL_RGBA8;
9651054 This->format = GL_BGRA;
@@ -968,7 +1057,8 @@
9691058 This->colorbits[2] = 5;
9701059 This->colorbits[3] = 1;
9711060 break;
972 - case 11: // 32-bit RGBA8888
 1061+ case -1:
 1062+ case 14: // 32-bit RGBA8888
9731063 This->internalformats[0] = GL_RGBA8;
9741064 This->format = GL_BGRA;
9751065 This->type = GL_UNSIGNED_INT_8_8_8_8_REV;
@@ -982,7 +1072,7 @@
9831073 This->colorbits[2] = 8;
9841074 This->colorbits[3] = 8;
9851075 break;
986 - case 12: // 8-bit Luminance
 1076+ case 15: // 8-bit Luminance
9871077 This->internalformats[0] = GL_LUMINANCE8;
9881078 This->internalformats[1] = GL_RGB8;
9891079 This->internalformats[2] = GL_RGBA8;
@@ -998,7 +1088,7 @@
9991089 This->colorbits[2] = 0;
10001090 This->colorbits[3] = 0;
10011091 break;
1002 - case 13: // 8-bit Alpha
 1092+ case 16: // 8-bit Alpha
10031093 This->internalformats[0] = GL_ALPHA8;
10041094 This->format = GL_ALPHA;
10051095 This->type = GL_UNSIGNED_BYTE;
@@ -1012,7 +1102,7 @@
10131103 This->colorbits[2] = 0;
10141104 This->colorbits[3] = 8;
10151105 break;
1016 - case 14: // 16-bit Luminance Alpha
 1106+ case 17: // 16-bit Luminance Alpha
10171107 This->internalformats[0] = GL_LUMINANCE8_ALPHA8;
10181108 This->internalformats[1] = GL_RGBA8;
10191109 This->format = GL_LUMINANCE_ALPHA;
@@ -1027,7 +1117,7 @@
10281118 This->colorbits[2] = 0;
10291119 This->colorbits[3] = 8;
10301120 break;
1031 - case 15: // 16-bit Z buffer
 1121+ case 18: // 16-bit Z buffer
10321122 This->internalformats[0] = GL_DEPTH_COMPONENT16;
10331123 This->format = GL_DEPTH_COMPONENT;
10341124 This->type = GL_UNSIGNED_SHORT;
@@ -1041,7 +1131,7 @@
10421132 This->colorbits[2] = 0;
10431133 This->colorbits[3] = 0;
10441134 break;
1045 - case 16: // 24-bit Z buffer
 1135+ case 19: // 24-bit Z buffer
10461136 This->internalformats[0] = GL_DEPTH_COMPONENT24;
10471137 This->format = GL_DEPTH_COMPONENT;
10481138 This->type = GL_UNSIGNED_SHORT;
@@ -1055,7 +1145,7 @@
10561146 This->colorbits[2] = 0;
10571147 This->colorbits[3] = 0;
10581148 break;
1059 - case 17: // 32/24 bit Z buffer
 1149+ case 20: // 32/24 bit Z buffer
10601150 This->internalformats[0] = GL_DEPTH_COMPONENT24;
10611151 This->format = GL_DEPTH_COMPONENT;
10621152 This->type = GL_UNSIGNED_INT;
@@ -1069,7 +1159,7 @@
10701160 This->colorbits[2] = 0;
10711161 This->colorbits[3] = 0;
10721162 break;
1073 - case 18: // 32-bit Z buffer
 1163+ case 21: // 32-bit Z buffer
10741164 This->internalformats[0] = GL_DEPTH_COMPONENT32;
10751165 This->format = GL_DEPTH_COMPONENT;
10761166 This->type = GL_UNSIGNED_INT;
@@ -1083,7 +1173,7 @@
10841174 This->colorbits[2] = 0;
10851175 This->colorbits[3] = 0;
10861176 break;
1087 - case 19: // 32-bit Z/Stencil buffer, depth LSB
 1177+ case 22: // 32-bit Z/Stencil buffer, depth LSB
10881178 This->internalformats[0] = GL_DEPTH24_STENCIL8;
10891179 This->format = GL_DEPTH_STENCIL;
10901180 This->type = GL_UNSIGNED_INT_24_8;
@@ -1097,7 +1187,7 @@
10981188 This->colorbits[2] = 0;
10991189 This->colorbits[3] = 8;
11001190 break;
1101 - case 20: // 32-bit Z/Stencil buffer, depth MSB
 1191+ case 23: // 32-bit Z/Stencil buffer, depth MSB
11021192 This->internalformats[0] = GL_DEPTH24_STENCIL8;
11031193 This->format = GL_DEPTH_STENCIL;
11041194 This->type = GL_UNSIGNED_INT_24_8;
Index: dxglcfg/common.h
@@ -1,5 +1,5 @@
22 // DXGL
3 -// Copyright (C) 2011-2012 William Feely
 3+// Copyright (C) 2011-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
@@ -74,7 +74,10 @@
7575 #include "Resource.h"
7676 // DirectX/DXGL headers
7777 #include "../ddraw/include/ddraw.h"
78 -extern const unsigned char DefaultPalette[1024];
 78+extern const unsigned char DefaultPalette1[8];
 79+extern const unsigned char DefaultPalette2[16];
 80+extern const unsigned char DefaultPalette4[64];
 81+extern const unsigned char DefaultPalette8[1024];
7982
8083 #ifdef _UNICODE
8184 #define _ttof _wtof
Index: dxglcfg/palette.cpp
@@ -1,5 +1,5 @@
22 // DXGL
3 -// Copyright (C) 2011 William Feely
 3+// Copyright (C) 2011-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
@@ -18,7 +18,27 @@
1919 #include "common.h"
2020 #include "palette.h"
2121
22 -const unsigned char DefaultPalette[1024] = {
 22+const unsigned char DefaultPalette1[8] = {
 23+ 0x00,0x00,0x00,0x00,0xff,0xff,0xff,0x00
 24+}; // Just black and white
 25+
 26+const unsigned char DefaultPalette2[16] = {
 27+ 0x00,0x00,0x00,0x00,0xff,0xff,0x55,0x00,
 28+ 0xff,0x55,0xff,0x00,0xff,0xff,0xff,0x00
 29+}; // Based on IBM PC CGA Palette 1 with intensity bit set
 30+
 31+const unsigned char DefaultPalette4[64] = {
 32+ 0x00,0x00,0x00,0x00,0xaa,0x00,0x00,0x00,
 33+ 0x00,0xaa,0x00,0x00,0xaa,0xaa,0x00,0x00,
 34+ 0x00,0x00,0xaa,0x00,0xaa,0x00,0xaa,0x00,
 35+ 0x00,0x55,0xaa,0x00,0xaa,0xaa,0xaa,0x00,
 36+ 0x55,0x55,0x55,0x00,0xff,0x55,0x55,0x00,
 37+ 0x55,0xff,0x55,0x00,0xff,0xff,0x55,0x00,
 38+ 0x55,0x55,0xff,0x00,0x55,0xff,0x55,0x00,
 39+ 0x55,0xff,0xff,0x00,0xff,0xff,0xff,0x00
 40+}; // Based on IBM PC CGA/EGA/VGA default 16 color palette
 41+
 42+const unsigned char DefaultPalette8[1024] = {
2343 0x00,0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x80,0x00,0x00,0x80,0x80,0x00,0x00,
2444 0x00,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x00,0x80,0x80,0x00,0xc0,0xc0,0xc0,0x00,
2545 0xa0,0xa0,0xa0,0x00,0xf0,0xf0,0xf0,0x00,0x40,0x20,0x00,0x00,0x60,0x20,0x00,0x00,
Index: dxglcfg/palette.h
@@ -1,5 +1,5 @@
22 // DXGL
3 -// Copyright (C) 2011 William Feely
 3+// Copyright (C) 2011-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
@@ -15,4 +15,7 @@
1616 // License along with this library; if not, write to the Free Software
1717 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1818
19 -extern const unsigned char DefaultPalette[1024];
 19+extern const unsigned char DefaultPalette1[8];
 20+extern const unsigned char DefaultPalette2[16];
 21+extern const unsigned char DefaultPalette4[64];
 22+extern const unsigned char DefaultPalette8[1024];
Index: dxglcfg/surfacegen.cpp
@@ -208,10 +208,44 @@
209209 {
210210 DWORD x,y;
211211 DWORD color;
 212+ unsigned char value;
212213 unsigned short *buffer16 = (unsigned short*) buffer;
213214 unsigned long *buffer32 = (unsigned long*) buffer;
214215 switch(ddsd.ddpfPixelFormat.dwRGBBitCount)
215216 {
 217+ case 1:
 218+ for(y = 0; y < ddsd.dwHeight; y++)
 219+ {
 220+ for(x = 0; x < (ddsd.dwWidth/8); x++)
 221+ {
 222+ value = (unsigned char)((x / (ddsd.dwWidth / 8.)) + 2 * floor((y / (ddsd.dwHeight / 2.))));
 223+ if (value) value = 0xFF;
 224+ buffer[x + (ddsd.lPitch*y)] = value;
 225+ }
 226+ }
 227+ break;
 228+ case 2:
 229+ for(y = 0; y < ddsd.dwHeight; y++)
 230+ {
 231+ for(x = 0; x < (ddsd.dwWidth/4); x++)
 232+ {
 233+ value = (unsigned char)((x / (ddsd.dwWidth / 8.)) + 2 * floor((y / (ddsd.dwHeight / 2.))));
 234+ value |= ((value << 2) | (value << 4) | (value << 6));
 235+ buffer[x + (ddsd.lPitch*y)] = value;
 236+ }
 237+ }
 238+ break;
 239+ case 4:
 240+ for(y = 0; y < ddsd.dwHeight; y++)
 241+ {
 242+ for(x = 0; x < (ddsd.dwWidth/2); x++)
 243+ {
 244+ value = (unsigned char)((x / (ddsd.dwWidth / 8.)) + 4 * floor((y / (ddsd.dwHeight / 4.))));
 245+ value |= (value << 4);
 246+ buffer[x + (ddsd.lPitch*y)] = value;
 247+ }
 248+ }
 249+ break;
216250 case 8:
217251 for(y = 0; y < ddsd.dwHeight; y++)
218252 {
Index: dxglcfg/tests.cpp
@@ -215,12 +215,19 @@
216216 break;
217217 case WM_DESTROY:
218218 StopTimer();
219 - for(int i = 0; i < 16; i++)
 219+ for (int i = 0; i < 16; i++)
 220+ {
220221 if (sprites[i].surface)
221222 {
222223 sprites[i].surface->Release();
223224 sprites[i].surface = NULL;
224225 }
 226+ if (sprites[i].palette)
 227+ {
 228+ sprites[i].palette->Release();
 229+ sprites[i].palette = NULL;
 230+ }
 231+ }
225232 for (int i = 0; i < 8; i++)
226233 {
227234 if (textures[i])
@@ -549,9 +556,14 @@
550557 }
551558 if(bpp == 8)
552559 {
553 - ddinterface->CreatePalette(DDPCAPS_8BIT|DDPCAPS_ALLOW256,(LPPALETTEENTRY)&DefaultPalette,&pal,NULL);
 560+ ddinterface->CreatePalette(DDPCAPS_8BIT|DDPCAPS_ALLOW256,(LPPALETTEENTRY)&DefaultPalette8,&pal,NULL);
554561 ddsrender->SetPalette(pal);
555562 }
 563+ else if (bpp == 4)
 564+ {
 565+ ddinterface->CreatePalette(DDPCAPS_4BIT, (LPPALETTEENTRY)&DefaultPalette4, &pal, NULL);
 566+ ddsrender->SetPalette(pal);
 567+ }
556568 else pal = NULL;
557569 if (is3d)
558570 {
@@ -2326,6 +2338,15 @@
23272339 }
23282340 }
23292341
 2342+DWORD PaletteType(DWORD flags)
 2343+{
 2344+ if (flags & DDPF_PALETTEINDEXED1) return 1;
 2345+ else if (flags & DDPF_PALETTEINDEXED2) return 2;
 2346+ else if (flags & DDPF_PALETTEINDEXED4) return 4;
 2347+ else if (flags & DDPF_PALETTEINDEXED8) return 8;
 2348+ else return 0;
 2349+}
 2350+
23302351 void RunSurfaceFormatTest()
23312352 {
23322353 HRESULT error;
@@ -2356,11 +2377,21 @@
23572378 sprites[0].surface->Release();
23582379 sprites[0].surface = NULL;
23592380 }
 2381+ if (sprites[0].palette)
 2382+ {
 2383+ sprites[0].palette->Release();
 2384+ sprites[0].palette = NULL;
 2385+ }
23602386 if (sprites[1].surface)
23612387 {
23622388 sprites[1].surface->Release();
23632389 sprites[1].surface = NULL;
23642390 }
 2391+ if (sprites[1].palette)
 2392+ {
 2393+ sprites[1].palette->Release();
 2394+ sprites[1].palette = NULL;
 2395+ }
23652396 ddsrender->GetSurfaceDesc(&ddsd);
23662397 switch (testmethod)
23672398 {
@@ -2386,6 +2417,27 @@
23872418 }
23882419 else
23892420 {
 2421+ switch (PaletteType(ddsd.ddpfPixelFormat.dwFlags))
 2422+ {
 2423+ case 0:
 2424+ break;
 2425+ case 1:
 2426+ ddinterface->CreatePalette(DDPCAPS_1BIT, (LPPALETTEENTRY)&DefaultPalette1, &sprites[0].palette, NULL);
 2427+ sprites[0].surface->SetPalette(sprites[0].palette);
 2428+ break;
 2429+ case 2:
 2430+ ddinterface->CreatePalette(DDPCAPS_2BIT, (LPPALETTEENTRY)&DefaultPalette2, &sprites[0].palette, NULL);
 2431+ sprites[0].surface->SetPalette(sprites[0].palette);
 2432+ break;
 2433+ case 4:
 2434+ ddinterface->CreatePalette(DDPCAPS_4BIT, (LPPALETTEENTRY)&DefaultPalette4, &sprites[0].palette, NULL);
 2435+ sprites[0].surface->SetPalette(sprites[0].palette);
 2436+ break;
 2437+ case 8:
 2438+ ddinterface->CreatePalette(DDPCAPS_8BIT, (LPPALETTEENTRY)&DefaultPalette8, &sprites[0].palette, NULL);
 2439+ sprites[0].surface->SetPalette(sprites[0].palette);
 2440+ break;
 2441+ }
23902442 // FIXME: Select pattern
23912443 error = sprites[0].surface->Lock(NULL, &ddsd, DDLOCK_WAIT, NULL);
23922444 if (error)
Index: dxglcfg/tests.h
@@ -1,5 +1,5 @@
22 // DXGL
3 -// Copyright (C) 2011 William Feely
 3+// Copyright (C) 2011-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
@@ -22,6 +22,7 @@
2323 typedef struct
2424 {
2525 MultiDirectDrawSurface *surface;
 26+ IDirectDrawPalette *palette;
2627 DDSURFACEDESC2 ddsd;
2728 float width;
2829 float height;