| Index: ddraw/colorconv.c |
| — | — | @@ -1,5 +1,5 @@ |
| 2 | 2 | // DXGL
|
| 3 | | -// Copyright (C) 2018 William Feely
|
| | 3 | +// Copyright (C) 2018-2019 William Feely
|
| 4 | 4 |
|
| 5 | 5 | // This library is free software; you can redistribute it and/or
|
| 6 | 6 | // modify it under the terms of the GNU Lesser General Public
|
| — | — | @@ -21,16 +21,23 @@ |
| 22 | 22 | typedef void(*COLORCONVPROC) (size_t count, void *dest, void *src);
|
| 23 | 23 | COLORCONVPROC colorconvproc[] =
|
| 24 | 24 | {
|
| 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
|
| 35 | 42 | };
|
| 36 | 43 |
|
| 37 | 44 | __inline unsigned int _1to8(unsigned int input)
|
| — | — | @@ -63,6 +70,85 @@ |
| 64 | 71 | return (input * 259 + 33) >> 6;
|
| 65 | 72 | }
|
| 66 | 73 |
|
| | 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 | +
|
| 67 | 153 | void rgba8332torgba8888(size_t count, DWORD *dest, WORD *src)
|
| 68 | 154 | {
|
| 69 | 155 | size_t i;
|
| — | — | @@ -199,4 +285,9 @@ |
| 200 | 286 | y = (src[i] >> 24) & 0xFF;
|
| 201 | 287 | dest[(i << 1)+1] = yuvtorgb(y, u, v);
|
| 202 | 288 | }
|
| | 289 | +}
|
| | 290 | +
|
| | 291 | +void rgbx8888touyvy(size_t count, DWORD *dest, DWORD *src)
|
| | 292 | +{
|
| | 293 | +
|
| 203 | 294 | } |
| \ No newline at end of file |
| Index: ddraw/colorconv.h |
| — | — | @@ -1,5 +1,5 @@ |
| 2 | 2 | // DXGL
|
| 3 | | -// Copyright (C) 2018 William Feely
|
| | 3 | +// Copyright (C) 2018-2019 William Feely
|
| 4 | 4 |
|
| 5 | 5 | // This library is free software; you can redistribute it and/or
|
| 6 | 6 | // modify it under the terms of the GNU Lesser General Public
|
| — | — | @@ -26,6 +26,12 @@ |
| 27 | 27 | typedef void(*COLORCONVPROC) (size_t count, void *dest, void *src);
|
| 28 | 28 | extern COLORCONVPROC colorconvproc[];
|
| 29 | 29 |
|
| | 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);
|
| 30 | 36 | void rgba8332torgba8888(size_t count, DWORD *dest, WORD *src);
|
| 31 | 37 | void rgba8888torgba8332(size_t count, WORD *dest, DWORD *src);
|
| 32 | 38 | void rgb565torgba8888(size_t count, DWORD *dest, WORD *src);
|
| — | — | @@ -36,6 +42,7 @@ |
| 37 | 43 | void rgba4444torgba8888(size_t count, DWORD *dest, WORD *src);
|
| 38 | 44 | void rgba8888torgba4444(size_t count, WORD *dest, DWORD *src);
|
| 39 | 45 | void uyvytorgbx8888(size_t count, DWORD *dest, DWORD *src);
|
| | 46 | +void rgbx8888touyvy(size_t count, DWORD *dest, DWORD *src);
|
| 40 | 47 |
|
| 41 | 48 | #ifdef __cplusplus
|
| 42 | 49 | }
|
| Index: ddraw/glDirect3DDevice.cpp |
| — | — | @@ -1,5 +1,5 @@ |
| 2 | 2 | // DXGL
|
| 3 | | -// Copyright (C) 2011-2016 William Feely
|
| | 3 | +// Copyright (C) 2011-2019 William Feely
|
| 4 | 4 |
|
| 5 | 5 | // This library is free software; you can redistribute it and/or
|
| 6 | 6 | // modify it under the terms of the GNU Lesser General Public
|
| — | — | @@ -1018,6 +1018,10 @@ |
| 1019 | 1019 | {
|
| 1020 | 1020 | if (i == 7) continue;
|
| 1021 | 1021 | 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;
|
| 1022 | 1026 | if(::texformats[i].dwFlags & DDPF_PALETTEINDEXED8) continue;
|
| 1023 | 1027 | memcpy(&fmt,&::texformats[i],sizeof(DDPIXELFORMAT));
|
| 1024 | 1028 | result = lpd3dEnumPixelProc(&fmt,lpArg);
|
| Index: ddraw/glDirectDraw.cpp |
| — | — | @@ -1580,7 +1580,7 @@ |
| 1581 | 1581 | ddsdMode.dwHeight = primaryy;
|
| 1582 | 1582 | ddsdMode.dwRefreshRate = primaryrefresh;
|
| 1583 | 1583 | 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);
|
| 1585 | 1585 | else ddsdMode.lPitch = NextMultipleOf4(primaryx * (primarybpp / 8));
|
| 1586 | 1586 | if(lpDDSurfaceDesc2->dwSize < sizeof(DDSURFACEDESC)) ERR(DDERR_INVALIDPARAMS);
|
| 1587 | 1587 | if(lpDDSurfaceDesc2->dwSize > sizeof(DDSURFACEDESC2))
|
| Index: ddraw/glTexture.cpp |
| — | — | @@ -69,6 +69,9 @@ |
| 70 | 70 | static const int START_TEXFORMATS = __LINE__;
|
| 71 | 71 | const DDPIXELFORMAT texformats[] =
|
| 72 | 72 | { // 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
|
| 73 | 76 | {sizeof(DDPIXELFORMAT), DDPF_RGB|DDPF_PALETTEINDEXED8, 0, 8, 0, 0, 0, 0}, // 8-bit paletted
|
| 74 | 77 | {sizeof(DDPIXELFORMAT), DDPF_RGB, 0, 8, 0xE0, 0x1C, 0x3, 0}, // 8 bit 332
|
| 75 | 78 | {sizeof(DDPIXELFORMAT), DDPF_RGB, 0, 16, 0x7C00, 0x3E0, 0x1F, 0}, // 15 bit 555
|
| — | — | @@ -219,8 +222,17 @@ |
| 220 | 223 | break;
|
| 221 | 224 | }
|
| 222 | 225 | }
|
| 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 | + }
|
| 225 | 237 | /*if (!(newtexture->levels[0].ddsd.ddsCaps.dwCaps2 & DDSCAPS2_MIPMAPSUBLEVEL))
|
| 226 | 238 | {
|
| 227 | 239 | newtexture->pixelformat = newtexture->levels[0].ddsd.ddpfPixelFormat;
|
| — | — | @@ -797,8 +809,11 @@ |
| 798 | 810 | ZeroMemory(This->internalformats, 8 * sizeof(GLint));
|
| 799 | 811 | switch (texformat)
|
| 800 | 812 | {
|
| 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
|
| 803 | 818 | if (This->renderer->ext->glver_major >= 3)
|
| 804 | 819 | {
|
| 805 | 820 | This->internalformats[0] = GL_R8;
|
| — | — | @@ -811,6 +826,80 @@ |
| 812 | 827 | }
|
| 813 | 828 | This->type = GL_UNSIGNED_BYTE;
|
| 814 | 829 | 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;
|
| 815 | 904 | This->colorsizes[0] = 255;
|
| 816 | 905 | This->colorsizes[1] = 255;
|
| 817 | 906 | This->colorsizes[2] = 255;
|
| — | — | @@ -820,7 +909,7 @@ |
| 821 | 910 | This->colorbits[2] = 0;
|
| 822 | 911 | This->colorbits[3] = 0;
|
| 823 | 912 | break;
|
| 824 | | - case 1: // 8-bit RGB332
|
| | 913 | + case 4: // 8-bit RGB332
|
| 825 | 914 | This->internalformats[0] = GL_R3_G3_B2;
|
| 826 | 915 | This->internalformats[1] = GL_RGB8;
|
| 827 | 916 | This->internalformats[2] = GL_RGBA8;
|
| — | — | @@ -836,7 +925,7 @@ |
| 837 | 926 | This->colorbits[2] = 2;
|
| 838 | 927 | This->colorbits[3] = 0;
|
| 839 | 928 | break;
|
| 840 | | - case 2: // 16-bit RGB555
|
| | 929 | + case 5: // 16-bit RGB555
|
| 841 | 930 | This->internalformats[0] = GL_RGB5_A1;
|
| 842 | 931 | This->internalformats[1] = GL_RGBA8;
|
| 843 | 932 | This->format = GL_BGRA;
|
| — | — | @@ -851,7 +940,7 @@ |
| 852 | 941 | This->colorbits[2] = 5;
|
| 853 | 942 | This->colorbits[3] = 1;
|
| 854 | 943 | break;
|
| 855 | | - case 3: // 16-bit RGB565
|
| | 944 | + case 6: // 16-bit RGB565
|
| 856 | 945 | This->internalformats[0] = GL_RGB565;
|
| 857 | 946 | This->internalformats[1] = GL_RGB8;
|
| 858 | 947 | This->internalformats[2] = GL_RGBA8;
|
| — | — | @@ -867,7 +956,7 @@ |
| 868 | 957 | This->colorbits[2] = 5;
|
| 869 | 958 | This->colorbits[3] = 0;
|
| 870 | 959 | break;
|
| 871 | | - case 4: // 24-bit RGB888
|
| | 960 | + case 7: // 24-bit RGB888
|
| 872 | 961 | This->internalformats[0] = GL_RGB8;
|
| 873 | 962 | This->internalformats[1] = GL_RGBA8;
|
| 874 | 963 | This->format = GL_BGR;
|
| — | — | @@ -882,7 +971,7 @@ |
| 883 | 972 | This->colorbits[2] = 8;
|
| 884 | 973 | This->colorbits[3] = 0;
|
| 885 | 974 | break;
|
| 886 | | - case 5: // 24-bit BGR888
|
| | 975 | + case 8: // 24-bit BGR888
|
| 887 | 976 | This->internalformats[0] = GL_RGB8;
|
| 888 | 977 | This->internalformats[1] = GL_RGBA8;
|
| 889 | 978 | This->format = GL_RGB;
|
| — | — | @@ -897,7 +986,7 @@ |
| 898 | 987 | This->colorbits[2] = 8;
|
| 899 | 988 | This->colorbits[3] = 0;
|
| 900 | 989 | break;
|
| 901 | | - case 6: // 32-bit RGB888
|
| | 990 | + case 9: // 32-bit RGB888
|
| 902 | 991 | This->internalformats[0] = GL_RGBA8;
|
| 903 | 992 | This->format = GL_BGRA;
|
| 904 | 993 | This->type = GL_UNSIGNED_INT_8_8_8_8_REV;
|
| — | — | @@ -911,7 +1000,7 @@ |
| 912 | 1001 | This->colorbits[2] = 8;
|
| 913 | 1002 | This->colorbits[3] = 0;
|
| 914 | 1003 | break;
|
| 915 | | - case 7: // 32-bit BGR888
|
| | 1004 | + case 10: // 32-bit BGR888
|
| 916 | 1005 | This->internalformats[0] = GL_RGBA8;
|
| 917 | 1006 | This->format = GL_RGBA;
|
| 918 | 1007 | This->type = GL_UNSIGNED_INT_8_8_8_8_REV;
|
| — | — | @@ -925,7 +1014,7 @@ |
| 926 | 1015 | This->colorbits[2] = 8;
|
| 927 | 1016 | This->colorbits[3] = 0;
|
| 928 | 1017 | break;
|
| 929 | | - case 8: // 16-bit RGBA8332
|
| | 1018 | + case 11: // 16-bit RGBA8332
|
| 930 | 1019 | This->useconv = TRUE;
|
| 931 | 1020 | This->convfunctionupload = 0;
|
| 932 | 1021 | This->convfunctiondownload = 1;
|
| — | — | @@ -943,7 +1032,7 @@ |
| 944 | 1033 | This->colorbits[2] = 2;
|
| 945 | 1034 | This->colorbits[3] = 8;
|
| 946 | 1035 | break;
|
| 947 | | - case 9: // 16-bit RGBA4444
|
| | 1036 | + case 12: // 16-bit RGBA4444
|
| 948 | 1037 | This->internalformats[0] = GL_RGBA4;
|
| 949 | 1038 | This->internalformats[1] = GL_RGBA8;
|
| 950 | 1039 | This->format = GL_BGRA;
|
| — | — | @@ -958,7 +1047,7 @@ |
| 959 | 1048 | This->colorbits[2] = 4;
|
| 960 | 1049 | This->colorbits[3] = 4;
|
| 961 | 1050 | break;
|
| 962 | | - case 10: // 16-bit RGBA1555
|
| | 1051 | + case 13: // 16-bit RGBA1555
|
| 963 | 1052 | This->internalformats[0] = GL_RGB5_A1;
|
| 964 | 1053 | This->internalformats[1] = GL_RGBA8;
|
| 965 | 1054 | This->format = GL_BGRA;
|
| — | — | @@ -968,7 +1057,8 @@ |
| 969 | 1058 | This->colorbits[2] = 5;
|
| 970 | 1059 | This->colorbits[3] = 1;
|
| 971 | 1060 | break;
|
| 972 | | - case 11: // 32-bit RGBA8888
|
| | 1061 | + case -1:
|
| | 1062 | + case 14: // 32-bit RGBA8888
|
| 973 | 1063 | This->internalformats[0] = GL_RGBA8;
|
| 974 | 1064 | This->format = GL_BGRA;
|
| 975 | 1065 | This->type = GL_UNSIGNED_INT_8_8_8_8_REV;
|
| — | — | @@ -982,7 +1072,7 @@ |
| 983 | 1073 | This->colorbits[2] = 8;
|
| 984 | 1074 | This->colorbits[3] = 8;
|
| 985 | 1075 | break;
|
| 986 | | - case 12: // 8-bit Luminance
|
| | 1076 | + case 15: // 8-bit Luminance
|
| 987 | 1077 | This->internalformats[0] = GL_LUMINANCE8;
|
| 988 | 1078 | This->internalformats[1] = GL_RGB8;
|
| 989 | 1079 | This->internalformats[2] = GL_RGBA8;
|
| — | — | @@ -998,7 +1088,7 @@ |
| 999 | 1089 | This->colorbits[2] = 0;
|
| 1000 | 1090 | This->colorbits[3] = 0;
|
| 1001 | 1091 | break;
|
| 1002 | | - case 13: // 8-bit Alpha
|
| | 1092 | + case 16: // 8-bit Alpha
|
| 1003 | 1093 | This->internalformats[0] = GL_ALPHA8;
|
| 1004 | 1094 | This->format = GL_ALPHA;
|
| 1005 | 1095 | This->type = GL_UNSIGNED_BYTE;
|
| — | — | @@ -1012,7 +1102,7 @@ |
| 1013 | 1103 | This->colorbits[2] = 0;
|
| 1014 | 1104 | This->colorbits[3] = 8;
|
| 1015 | 1105 | break;
|
| 1016 | | - case 14: // 16-bit Luminance Alpha
|
| | 1106 | + case 17: // 16-bit Luminance Alpha
|
| 1017 | 1107 | This->internalformats[0] = GL_LUMINANCE8_ALPHA8;
|
| 1018 | 1108 | This->internalformats[1] = GL_RGBA8;
|
| 1019 | 1109 | This->format = GL_LUMINANCE_ALPHA;
|
| — | — | @@ -1027,7 +1117,7 @@ |
| 1028 | 1118 | This->colorbits[2] = 0;
|
| 1029 | 1119 | This->colorbits[3] = 8;
|
| 1030 | 1120 | break;
|
| 1031 | | - case 15: // 16-bit Z buffer
|
| | 1121 | + case 18: // 16-bit Z buffer
|
| 1032 | 1122 | This->internalformats[0] = GL_DEPTH_COMPONENT16;
|
| 1033 | 1123 | This->format = GL_DEPTH_COMPONENT;
|
| 1034 | 1124 | This->type = GL_UNSIGNED_SHORT;
|
| — | — | @@ -1041,7 +1131,7 @@ |
| 1042 | 1132 | This->colorbits[2] = 0;
|
| 1043 | 1133 | This->colorbits[3] = 0;
|
| 1044 | 1134 | break;
|
| 1045 | | - case 16: // 24-bit Z buffer
|
| | 1135 | + case 19: // 24-bit Z buffer
|
| 1046 | 1136 | This->internalformats[0] = GL_DEPTH_COMPONENT24;
|
| 1047 | 1137 | This->format = GL_DEPTH_COMPONENT;
|
| 1048 | 1138 | This->type = GL_UNSIGNED_SHORT;
|
| — | — | @@ -1055,7 +1145,7 @@ |
| 1056 | 1146 | This->colorbits[2] = 0;
|
| 1057 | 1147 | This->colorbits[3] = 0;
|
| 1058 | 1148 | break;
|
| 1059 | | - case 17: // 32/24 bit Z buffer
|
| | 1149 | + case 20: // 32/24 bit Z buffer
|
| 1060 | 1150 | This->internalformats[0] = GL_DEPTH_COMPONENT24;
|
| 1061 | 1151 | This->format = GL_DEPTH_COMPONENT;
|
| 1062 | 1152 | This->type = GL_UNSIGNED_INT;
|
| — | — | @@ -1069,7 +1159,7 @@ |
| 1070 | 1160 | This->colorbits[2] = 0;
|
| 1071 | 1161 | This->colorbits[3] = 0;
|
| 1072 | 1162 | break;
|
| 1073 | | - case 18: // 32-bit Z buffer
|
| | 1163 | + case 21: // 32-bit Z buffer
|
| 1074 | 1164 | This->internalformats[0] = GL_DEPTH_COMPONENT32;
|
| 1075 | 1165 | This->format = GL_DEPTH_COMPONENT;
|
| 1076 | 1166 | This->type = GL_UNSIGNED_INT;
|
| — | — | @@ -1083,7 +1173,7 @@ |
| 1084 | 1174 | This->colorbits[2] = 0;
|
| 1085 | 1175 | This->colorbits[3] = 0;
|
| 1086 | 1176 | break;
|
| 1087 | | - case 19: // 32-bit Z/Stencil buffer, depth LSB
|
| | 1177 | + case 22: // 32-bit Z/Stencil buffer, depth LSB
|
| 1088 | 1178 | This->internalformats[0] = GL_DEPTH24_STENCIL8;
|
| 1089 | 1179 | This->format = GL_DEPTH_STENCIL;
|
| 1090 | 1180 | This->type = GL_UNSIGNED_INT_24_8;
|
| — | — | @@ -1097,7 +1187,7 @@ |
| 1098 | 1188 | This->colorbits[2] = 0;
|
| 1099 | 1189 | This->colorbits[3] = 8;
|
| 1100 | 1190 | break;
|
| 1101 | | - case 20: // 32-bit Z/Stencil buffer, depth MSB
|
| | 1191 | + case 23: // 32-bit Z/Stencil buffer, depth MSB
|
| 1102 | 1192 | This->internalformats[0] = GL_DEPTH24_STENCIL8;
|
| 1103 | 1193 | This->format = GL_DEPTH_STENCIL;
|
| 1104 | 1194 | This->type = GL_UNSIGNED_INT_24_8;
|
| Index: dxglcfg/common.h |
| — | — | @@ -1,5 +1,5 @@ |
| 2 | 2 | // DXGL
|
| 3 | | -// Copyright (C) 2011-2012 William Feely
|
| | 3 | +// Copyright (C) 2011-2019 William Feely
|
| 4 | 4 |
|
| 5 | 5 | // This library is free software; you can redistribute it and/or
|
| 6 | 6 | // modify it under the terms of the GNU Lesser General Public
|
| — | — | @@ -74,7 +74,10 @@ |
| 75 | 75 | #include "Resource.h"
|
| 76 | 76 | // DirectX/DXGL headers
|
| 77 | 77 | #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];
|
| 79 | 82 |
|
| 80 | 83 | #ifdef _UNICODE
|
| 81 | 84 | #define _ttof _wtof
|
| Index: dxglcfg/palette.cpp |
| — | — | @@ -1,5 +1,5 @@ |
| 2 | 2 | // DXGL
|
| 3 | | -// Copyright (C) 2011 William Feely
|
| | 3 | +// Copyright (C) 2011-2019 William Feely
|
| 4 | 4 |
|
| 5 | 5 | // This library is free software; you can redistribute it and/or
|
| 6 | 6 | // modify it under the terms of the GNU Lesser General Public
|
| — | — | @@ -18,7 +18,27 @@ |
| 19 | 19 | #include "common.h"
|
| 20 | 20 | #include "palette.h"
|
| 21 | 21 |
|
| 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] = {
|
| 23 | 43 | 0x00,0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x80,0x00,0x00,0x80,0x80,0x00,0x00,
|
| 24 | 44 | 0x00,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x00,0x80,0x80,0x00,0xc0,0xc0,0xc0,0x00,
|
| 25 | 45 | 0xa0,0xa0,0xa0,0x00,0xf0,0xf0,0xf0,0x00,0x40,0x20,0x00,0x00,0x60,0x20,0x00,0x00,
|
| Index: dxglcfg/palette.h |
| — | — | @@ -1,5 +1,5 @@ |
| 2 | 2 | // DXGL
|
| 3 | | -// Copyright (C) 2011 William Feely
|
| | 3 | +// Copyright (C) 2011-2019 William Feely
|
| 4 | 4 |
|
| 5 | 5 | // This library is free software; you can redistribute it and/or
|
| 6 | 6 | // modify it under the terms of the GNU Lesser General Public
|
| — | — | @@ -15,4 +15,7 @@ |
| 16 | 16 | // License along with this library; if not, write to the Free Software
|
| 17 | 17 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
| 18 | 18 |
|
| 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 @@ |
| 209 | 209 | {
|
| 210 | 210 | DWORD x,y;
|
| 211 | 211 | DWORD color;
|
| | 212 | + unsigned char value;
|
| 212 | 213 | unsigned short *buffer16 = (unsigned short*) buffer;
|
| 213 | 214 | unsigned long *buffer32 = (unsigned long*) buffer;
|
| 214 | 215 | switch(ddsd.ddpfPixelFormat.dwRGBBitCount)
|
| 215 | 216 | {
|
| | 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;
|
| 216 | 250 | case 8:
|
| 217 | 251 | for(y = 0; y < ddsd.dwHeight; y++)
|
| 218 | 252 | {
|
| Index: dxglcfg/tests.cpp |
| — | — | @@ -215,12 +215,19 @@ |
| 216 | 216 | break;
|
| 217 | 217 | case WM_DESTROY:
|
| 218 | 218 | StopTimer();
|
| 219 | | - for(int i = 0; i < 16; i++)
|
| | 219 | + for (int i = 0; i < 16; i++)
|
| | 220 | + {
|
| 220 | 221 | if (sprites[i].surface)
|
| 221 | 222 | {
|
| 222 | 223 | sprites[i].surface->Release();
|
| 223 | 224 | sprites[i].surface = NULL;
|
| 224 | 225 | }
|
| | 226 | + if (sprites[i].palette)
|
| | 227 | + {
|
| | 228 | + sprites[i].palette->Release();
|
| | 229 | + sprites[i].palette = NULL;
|
| | 230 | + }
|
| | 231 | + }
|
| 225 | 232 | for (int i = 0; i < 8; i++)
|
| 226 | 233 | {
|
| 227 | 234 | if (textures[i])
|
| — | — | @@ -549,9 +556,14 @@ |
| 550 | 557 | }
|
| 551 | 558 | if(bpp == 8)
|
| 552 | 559 | {
|
| 553 | | - ddinterface->CreatePalette(DDPCAPS_8BIT|DDPCAPS_ALLOW256,(LPPALETTEENTRY)&DefaultPalette,&pal,NULL);
|
| | 560 | + ddinterface->CreatePalette(DDPCAPS_8BIT|DDPCAPS_ALLOW256,(LPPALETTEENTRY)&DefaultPalette8,&pal,NULL);
|
| 554 | 561 | ddsrender->SetPalette(pal);
|
| 555 | 562 | }
|
| | 563 | + else if (bpp == 4)
|
| | 564 | + {
|
| | 565 | + ddinterface->CreatePalette(DDPCAPS_4BIT, (LPPALETTEENTRY)&DefaultPalette4, &pal, NULL);
|
| | 566 | + ddsrender->SetPalette(pal);
|
| | 567 | + }
|
| 556 | 568 | else pal = NULL;
|
| 557 | 569 | if (is3d)
|
| 558 | 570 | {
|
| — | — | @@ -2326,6 +2338,15 @@ |
| 2327 | 2339 | }
|
| 2328 | 2340 | }
|
| 2329 | 2341 |
|
| | 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 | +
|
| 2330 | 2351 | void RunSurfaceFormatTest()
|
| 2331 | 2352 | {
|
| 2332 | 2353 | HRESULT error;
|
| — | — | @@ -2356,11 +2377,21 @@ |
| 2357 | 2378 | sprites[0].surface->Release();
|
| 2358 | 2379 | sprites[0].surface = NULL;
|
| 2359 | 2380 | }
|
| | 2381 | + if (sprites[0].palette)
|
| | 2382 | + {
|
| | 2383 | + sprites[0].palette->Release();
|
| | 2384 | + sprites[0].palette = NULL;
|
| | 2385 | + }
|
| 2360 | 2386 | if (sprites[1].surface)
|
| 2361 | 2387 | {
|
| 2362 | 2388 | sprites[1].surface->Release();
|
| 2363 | 2389 | sprites[1].surface = NULL;
|
| 2364 | 2390 | }
|
| | 2391 | + if (sprites[1].palette)
|
| | 2392 | + {
|
| | 2393 | + sprites[1].palette->Release();
|
| | 2394 | + sprites[1].palette = NULL;
|
| | 2395 | + }
|
| 2365 | 2396 | ddsrender->GetSurfaceDesc(&ddsd);
|
| 2366 | 2397 | switch (testmethod)
|
| 2367 | 2398 | {
|
| — | — | @@ -2386,6 +2417,27 @@ |
| 2387 | 2418 | }
|
| 2388 | 2419 | else
|
| 2389 | 2420 | {
|
| | 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 | + }
|
| 2390 | 2442 | // FIXME: Select pattern
|
| 2391 | 2443 | error = sprites[0].surface->Lock(NULL, &ddsd, DDLOCK_WAIT, NULL);
|
| 2392 | 2444 | if (error)
|
| Index: dxglcfg/tests.h |
| — | — | @@ -1,5 +1,5 @@ |
| 2 | 2 | // DXGL
|
| 3 | | -// Copyright (C) 2011 William Feely
|
| | 3 | +// Copyright (C) 2011-2019 William Feely
|
| 4 | 4 |
|
| 5 | 5 | // This library is free software; you can redistribute it and/or
|
| 6 | 6 | // modify it under the terms of the GNU Lesser General Public
|
| — | — | @@ -22,6 +22,7 @@ |
| 23 | 23 | typedef struct
|
| 24 | 24 | {
|
| 25 | 25 | MultiDirectDrawSurface *surface;
|
| | 26 | + IDirectDrawPalette *palette;
|
| 26 | 27 | DDSURFACEDESC2 ddsd;
|
| 27 | 28 | float width;
|
| 28 | 29 | float height;
|