DXGL r888 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r887‎ | r888 | r889 >
Date:12:49, 6 January 2019
Author:admin
Status:new
Tags:
Comment:
Partially add indexed formats to surface format test.
Validate pixel format when creating a surface.
Modified paths:
  • /ddraw/glDirectDraw.cpp (modified) (history)
  • /ddraw/glDirectDrawSurface.cpp (modified) (history)
  • /ddraw/glTexture.cpp (modified) (history)
  • /ddraw/glTexture.h (modified) (history)
  • /dxglcfg/surfacegen.cpp (modified) (history)

Diff [purge]

Index: ddraw/glDirectDraw.cpp
@@ -1,5 +1,5 @@
22 // DXGL
3 -// Copyright (C) 2011-2018 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
@@ -1311,6 +1311,11 @@
13121312 if (lpDDSurfaceDesc2->ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE) TRACE_RET(HRESULT, 23, DDERR_INVALIDPARAMS);
13131313 *lplpDDSurface = new glDirectDrawSurface7(this, lpDDSurfaceDesc2, &error, NULL, NULL, 0, version, NULL);
13141314 }
 1315+ if (error != DD_OK)
 1316+ {
 1317+ delete (glDirectDrawSurface7*)*lplpDDSurface;
 1318+ *lplpDDSurface = NULL;
 1319+ }
13151320 TRACE_VAR("*lplpDDSurface",14,*lplpDDSurface);
13161321 TRACE_EXIT(23,error);
13171322 return error;
Index: ddraw/glDirectDrawSurface.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
@@ -285,6 +285,13 @@
286286 ddsd.dwFlags |= DDSD_PIXELFORMAT;
287287 memcpy(&ddsd.ddpfPixelFormat, &texture->levels[this->miplevel].ddsd.ddpfPixelFormat, sizeof(DDPIXELFORMAT));
288288 }
 289+ if (!glTexture_ValidatePixelFormat(&ddsd.ddpfPixelFormat))
 290+ {
 291+ *error = DDERR_INVALIDPIXELFORMAT;
 292+ TRACE_VAR("*error", 23, DDERR_INVALIDPIXELFORMAT);
 293+ TRACE_EXIT(-1, 0);
 294+ return;
 295+ }
289296 if (ddsd.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)
290297 {
291298 if (ddInterface->GetBPP() == 8)
Index: ddraw/glTexture.cpp
@@ -1,5 +1,5 @@
22 // DXGL
3 -// Copyright (C) 2012-2016 William Feely
 3+// Copyright (C) 2012-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
@@ -400,6 +400,23 @@
401401 if(This->dummycolor) glTexture_Release(This->dummycolor, backend);
402402 This->dummycolor = NULL;
403403 }
 404+BOOL glTexture_ValidatePixelFormat(DDPIXELFORMAT *pixelformat)
 405+{
 406+ int i;
 407+ int texformat = -1;
 408+ numtexformats = END_TEXFORMATS - START_TEXFORMATS;
 409+ for (i = 0; i < numtexformats; i++)
 410+ {
 411+ if (!memcmp(&texformats[i], pixelformat, sizeof(DDPIXELFORMAT)))
 412+ {
 413+ texformat = i;
 414+ break;
 415+ }
 416+ }
 417+ if (texformat == -1) return FALSE;
 418+ else return TRUE;
 419+}
 420+
404421 HRESULT glTexture__SetSurfaceDesc(glTexture *This, LPDDSURFACEDESC2 ddsd)
405422 {
406423 // FIXME: Implement SetSurfaceDesc fully
Index: ddraw/glTexture.h
@@ -1,5 +1,5 @@
22 // DXGL
3 -// Copyright (C) 2012-2016 William Feely
 3+// Copyright (C) 2012-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
@@ -43,6 +43,7 @@
4444 void glTexture_SetStencil(glTexture *This, glTexture *stencil, BOOL backend);
4545 void glTexture_CreateDummyColor(glTexture *This, BOOL backend);
4646 void glTexture_DeleteDummyColor(glTexture *This, BOOL backend);
 47+BOOL glTexture_ValidatePixelFormat(DDPIXELFORMAT *pixelformat);
4748 void glTexture__SetFilter(glTexture *This, int level, GLint mag, GLint min, struct glRenderer *renderer);
4849 HRESULT glTexture__SetSurfaceDesc(glTexture *This, LPDDSURFACEDESC2 ddsd);
4950 void glTexture__Download(glTexture *This, GLint level);
Index: dxglcfg/surfacegen.cpp
@@ -1,5 +1,5 @@
22 // DXGL
3 -// Copyright (C) 2011-2018 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
@@ -1672,6 +1672,9 @@
16731673 {
16741674 _T("Primary surface"), // -1
16751675 _T("Same as primary"), // 0
 1676+ _T("1-bit Palette"),
 1677+ _T("2-bit Palette"),
 1678+ _T("4-bit Palette"),
16761679 _T("8-bit Palette"),
16771680 _T("8-bit 332"),
16781681 _T("15-bit 555"),
@@ -1700,6 +1703,9 @@
17011704 const DDPIXELFORMAT surfaceformats[] =
17021705 {
17031706 {0, 0, 0, 0, 0, 0, 0, 0}, // reserved
 1707+ {sizeof(DDPIXELFORMAT), DDPF_PALETTEINDEXED1, 0, 1, 0, 0, 0, 0}, // 8-bit paletted
 1708+ {sizeof(DDPIXELFORMAT), DDPF_PALETTEINDEXED2, 0, 2, 0, 0, 0, 0}, // 8-bit paletted
 1709+ {sizeof(DDPIXELFORMAT), DDPF_PALETTEINDEXED4, 0, 4, 0, 0, 0, 0}, // 8-bit paletted
17041710 {sizeof(DDPIXELFORMAT), DDPF_PALETTEINDEXED8, 0, 8, 0, 0, 0, 0}, // 8-bit paletted
17051711 {sizeof(DDPIXELFORMAT), DDPF_RGB, 0, 8, 0xE0, 0x1C, 0x3, 0}, // 8 bit 332
17061712 {sizeof(DDPIXELFORMAT), DDPF_RGB, 0, 16, 0x7C00, 0x3E0, 0x1F, 0}, // 15 bit 555