DXGL r918 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r917‎ | r918 | r919 >
Date:01:11, 29 April 2019
Author:admin
Status:new
Tags:
Comment:
Implement several overlay related APIs. Overlays do not render yet.
Tweak a few APIs.
Adjust matching method for FOURCC pixel formats.
Modified paths:
  • /ddraw/ShaderGen2D.cpp (modified) (history)
  • /ddraw/glDirectDraw.cpp (modified) (history)
  • /ddraw/glDirectDrawPalette.c (modified) (history)
  • /ddraw/glDirectDrawSurface.cpp (modified) (history)
  • /ddraw/glDirectDrawSurface.h (modified) (history)
  • /ddraw/glRenderer.cpp (modified) (history)
  • /ddraw/glRenderer.h (modified) (history)
  • /ddraw/glTexture.cpp (modified) (history)
  • /ddraw/struct.h (modified) (history)
  • /dxglcfg/surfacegen.cpp (modified) (history)

Diff [purge]

Index: ddraw/ShaderGen2D.cpp
@@ -62,9 +62,10 @@
6363 Bit 28: (DXGL) Use Clipper
6464 Bit 29: (DXGL) Source color key range
6565 Bit 30: (DXGL) Dest. color key range
66 -Bit 31: reserved for DXGL usage
 66+Bit 31: (DXGL) Render to screen instead of dest
6767 Bits 32-39: Texture type input
6868 Bits 40-47: Texture type output
 69+Bit 48: if 1, use screen scale for filtering when applicable
6970 AND the dwFlags by 0xF2FAADFF before packing ROP index bits
7071
7172 Texture types:
Index: ddraw/glDirectDraw.cpp
@@ -1471,7 +1471,8 @@
14721472 if (ddCaps.dwSize < sizeof(DDCAPS_DX3)) TRACE_RET(HRESULT, 23, DDERR_INVALIDPARAMS);
14731473 ddCaps.dwCaps = DDCAPS_BLT | DDCAPS_BLTCOLORFILL | DDCAPS_BLTDEPTHFILL | DDCAPS_BLTFOURCC |
14741474 DDCAPS_BLTSTRETCH | DDCAPS_COLORKEY | DDCAPS_GDI | DDCAPS_PALETTE | DDCAPS_CANBLTSYSMEM |
1475 - DDCAPS_3D | DDCAPS_CANCLIP | DDCAPS_CANCLIPSTRETCHED | DDCAPS_READSCANLINE;
 1475+ DDCAPS_3D | DDCAPS_CANCLIP | DDCAPS_CANCLIPSTRETCHED | DDCAPS_READSCANLINE |
 1476+ DDCAPS_OVERLAY | DDCAPS_OVERLAYSTRETCH;
14761477 ddCaps.dwCaps2 = DDCAPS2_CANRENDERWINDOWED | DDCAPS2_WIDESURFACES | DDCAPS2_NOPAGELOCKREQUIRED |
14771478 DDCAPS2_FLIPINTERVAL | DDCAPS2_FLIPNOVSYNC | DDCAPS2_NONLOCALVIDMEM;
14781479 ddCaps.dwFXCaps = DDFXCAPS_BLTSHRINKX | DDFXCAPS_BLTSHRINKY |
@@ -1484,8 +1485,10 @@
14851486 DDSCAPS_FRONTBUFFER | DDSCAPS_OFFSCREENPLAIN | DDSCAPS_PALETTE |
14861487 DDSCAPS_SYSTEMMEMORY | DDSCAPS_VIDEOMEMORY | DDSCAPS_3DDEVICE |
14871488 DDSCAPS_NONLOCALVIDMEM | DDSCAPS_LOCALVIDMEM | DDSCAPS_TEXTURE |
1488 - DDSCAPS_MIPMAP;
 1489+ DDSCAPS_MIPMAP | DDSCAPS_OVERLAY;
14891490 ddCaps.ddsCaps.dwCaps2 = DDSCAPS2_MIPMAPSUBLEVEL;
 1491+ ddCaps.dwMinOverlayStretch = 1;
 1492+ ddCaps.dwMaxOverlayStretch = 2147483647;
14901493 ddCaps.dwCKeyCaps = DDCKEYCAPS_SRCBLT | DDCKEYCAPS_DESTBLT;
14911494 ddCaps.dwZBufferBitDepths = DDBD_16 | DDBD_24 | DDBD_32;
14921495 ddCaps.dwNumFourCCCodes = GetNumFOURCC();
@@ -1784,7 +1787,7 @@
17851788 if ((glDD7->primaryx == 640) && (glDD7->primaryy == 480) && dxglcfg.HackCrop640480to640400)
17861789 glDD7->internaly = (DWORD)((float)glDD7->internaly * 1.2f);
17871790 if (glDD7->renderer && glDD7->primary) glRenderer_DrawScreen(glDD7->renderer, glDD7->primary->texture,
1788 - glDD7->primary->texture->palette, 0, NULL, FALSE);
 1791+ glDD7->primary->texture->palette, 0, NULL, FALSE, NULL, 0);
17891792 }
17901793 extern "C" BOOL glDirectDraw7_GetFullscreen(glDirectDraw7 *glDD7)
17911794 {
@@ -2553,7 +2556,7 @@
25542557 if(dwFlags & 0xFFFFFFFA) TRACE_RET(HRESULT,23,DDERR_INVALIDPARAMS);
25552558 if(dwFlags == 5) TRACE_RET(HRESULT,23,DDERR_INVALIDPARAMS);
25562559 if(!lastsync) lastsync = true;
2557 - else if(primary) primary->RenderScreen(primary->texture,1,NULL,TRUE);
 2560+ else if(primary) primary->RenderScreen(primary->texture,1,NULL,TRUE,NULL,0);
25582561 TRACE_EXIT(23,DD_OK);
25592562 return DD_OK;
25602563 }
Index: ddraw/glDirectDrawPalette.c
@@ -24,7 +24,7 @@
2525 #include "timer.h"
2626
2727 extern DXGLCFG dxglcfg;
28 -void glDirectDrawSurface7_RenderScreen(LPDIRECTDRAWSURFACE7 surface, int vsync, BOOL settime);
 28+void glDirectDrawSurface7_RenderScreen(LPDIRECTDRAWSURFACE7 surface, int vsync, BOOL settime, OVERLAY *overlays, int overlaycount);
2929
3030 static const DDSURFACEDESC2 ddsd256pal =
3131 {
@@ -254,7 +254,7 @@
255255 if (This->timer)
256256 {
257257 if (DXGLTimer_CheckLastDraw(This->timer, dxglcfg.HackPaletteDelay))
258 - glDirectDrawSurface7_RenderScreen(This->surface, dxglcfg.HackPaletteVsync, FALSE);
 258+ glDirectDrawSurface7_RenderScreen(This->surface, dxglcfg.HackPaletteVsync, FALSE, NULL, 0);
259259 }
260260 }
261261 }
Index: ddraw/glDirectDrawSurface.cpp
@@ -44,7 +44,6 @@
4545 TRACE_ENTER(5,14,this,14,lpDD7,14,lpDDSurfaceDesc2,14,error,14,palettein);
4646 this->version = version;
4747 creator = NULL;
48 - overlay = false;
4948 hasstencil = false;
5049 handle = 0;
5150 device = NULL;
@@ -67,6 +66,12 @@
6867 zbuffer = NULL;
6968 attachcount = 0;
7069 attachparent = NULL;
 70+ overlayenabled = FALSE;
 71+ overlayset = FALSE;
 72+ overlaycount = 0;
 73+ maxoverlays = 0;
 74+ overlays = NULL;
 75+ overlaydest = NULL;
7176 this->miplevel = miplevel;
7277 ddInterface = (glDirectDraw7 *)lpDD7;
7378 hRC = ddInterface->renderer->hRC;
@@ -393,6 +398,7 @@
394399 }
395400 glDirectDrawSurface7::~glDirectDrawSurface7()
396401 {
 402+ int i;
397403 TRACE_ENTER(1,14,this);
398404 AddRef();
399405 if (dds1) delete dds1;
@@ -402,6 +408,7 @@
403409 if (d3dt1) delete d3dt1;
404410 if (d3dt2) delete d3dt2;
405411 if (gammacontrol) free(gammacontrol);
 412+ if (overlaydest) overlaydest->DeleteOverlay(this);
406413 if (texture) glTexture_Release(texture, FALSE);
407414 //if(bitmapinfo) free(bitmapinfo);
408415 if (palette)
@@ -424,6 +431,12 @@
425432 if (!zbuffer->attachcount) zbuffer->attachparent = NULL;
426433 zbuffer_iface->Release();
427434 }
 435+ if (overlays)
 436+ {
 437+ for (i = 0; i < overlaycount; i++)
 438+ glTexture_Release(overlays[i].texture, FALSE);
 439+ free(overlays);
 440+ }
428441 if(miptexture) miptexture->Release();
429442 if (device) device->Release();
430443 if (device1) delete device1;
@@ -752,9 +765,8 @@
753766 {
754767 TRACE_ENTER(2,14,this,26,lpRect);
755768 if(!this) TRACE_RET(HRESULT,23,DDERR_INVALIDOBJECT);
756 - FIXME("glDirectDrawSurface7::AddOverlayDirtyRect: stub\n");
757 - TRACE_EXIT(23,DDERR_GENERIC);
758 - ERR(DDERR_GENERIC);
 769+ TRACE_EXIT(23,DDERR_UNSUPPORTED);
 770+ return DDERR_UNSUPPORTED;
759771 }
760772 HRESULT WINAPI glDirectDrawSurface7::Blt(LPRECT lpDestRect, LPDIRECTDRAWSURFACE7 lpDDSrcSurface, LPRECT lpSrcRect, DWORD dwFlags, LPDDBLTFX lpDDBltFx)
761773 {
@@ -934,6 +946,7 @@
935947 {
936948 TRACE_ENTER(3,14,this,9,dwFlags,14,lpDDSAttachedSurface);
937949 if(!this) TRACE_RET(HRESULT,23,DDERR_INVALIDOBJECT);
 950+ if (!lpDDSAttachedSurface) TRACE_RET(HRESULT, 23, DDERR_INVALIDPARAMS);
938951 if(lpDDSAttachedSurface == (LPDIRECTDRAWSURFACE7)zbuffer)
939952 {
940953 if (zbuffer && dxglcfg.primaryscale && (this->ddsd.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE))
@@ -975,11 +988,30 @@
976989 }
977990 HRESULT WINAPI glDirectDrawSurface7::EnumOverlayZOrders(DWORD dwFlags, LPVOID lpContext, LPDDENUMSURFACESCALLBACK7 lpfnCallback)
978991 {
 992+ int i;
979993 TRACE_ENTER(4,14,this,9,dwFlags,14,lpContext,14,lpfnCallback);
980994 if(!this) TRACE_RET(HRESULT,23,DDERR_INVALIDOBJECT);
981 - FIXME("glDirectDrawSurface7::EnumOverlayZOrders: stub\n");
982 - TRACE_EXIT(23,DDERR_GENERIC);
983 - ERR(DDERR_GENERIC);
 995+ if (!lpfnCallback) TRACE_RET(HRESULT, 23, DDERR_INVALIDPARAMS);
 996+ if (dwFlags > 1) TRACE_RET(HRESULT, 23, DDERR_INVALIDPARAMS);
 997+ if (this->overlaycount == 0) TRACE_RET(HRESULT, 23, DD_OK);
 998+ if (dwFlags == 1)
 999+ {
 1000+ for (i = this->overlaycount; i > 0; i--)
 1001+ {
 1002+ if (lpfnCallback((LPDIRECTDRAWSURFACE7)this->overlays[i].surface,
 1003+ &((glDirectDrawSurface7*)this->overlays[i].surface)->ddsd, lpContext) == DDENUMRET_CANCEL) break;
 1004+ }
 1005+ }
 1006+ else
 1007+ {
 1008+ for (i = this->overlaycount; i > 0; i--)
 1009+ {
 1010+ if (lpfnCallback((LPDIRECTDRAWSURFACE7)this->overlays[i].surface,
 1011+ &((glDirectDrawSurface7*)this->overlays[i].surface)->ddsd, lpContext) == DDENUMRET_CANCEL) break;
 1012+ }
 1013+ }
 1014+ TRACE_RET(HRESULT, 23, DD_OK);
 1015+ return DD_OK;
9841016 }
9851017 HRESULT WINAPI glDirectDrawSurface7::Flip(LPDIRECTDRAWSURFACE7 lpDDSurfaceTargetOverride, DWORD dwFlags)
9861018 {
@@ -995,8 +1027,12 @@
9961028 swapinterval++;
9971029 ddInterface->lastsync = false;
9981030 }
999 - RenderScreen(texture,swapinterval,previous,TRUE);
 1031+ RenderScreen(texture,swapinterval,previous,TRUE,FALSE,0);
10001032 }
 1033+ if (ddsd.ddsCaps.dwCaps & DDSCAPS_OVERLAY)
 1034+ {
 1035+ if (overlaydest) overlaydest->UpdateOverlayTexture(this, this->texture);
 1036+ }
10011037 TRACE_EXIT(23,ret);
10021038 return ret;
10031039 }
@@ -1006,7 +1042,7 @@
10071043 if(!this) TRACE_RET(HRESULT,23,DDERR_INVALIDOBJECT);
10081044 if(dwFlags & 0xF8FFFFC0) TRACE_RET(HRESULT,23,DDERR_INVALIDPARAMS);
10091045 if(locked) TRACE_RET(HRESULT,23,DDERR_SURFACEBUSY);
1010 - if(!overlay && ((dwFlags & DDFLIP_ODD) || (dwFlags & DDFLIP_EVEN))) TRACE_RET(HRESULT,23,DDERR_INVALIDPARAMS);
 1046+ if(!(this->ddsd.ddsCaps.dwCaps & DDSCAPS_OVERLAY) && ((dwFlags & DDFLIP_ODD) || (dwFlags & DDFLIP_EVEN))) TRACE_RET(HRESULT,23,DDERR_INVALIDPARAMS);
10111047 DWORD i;
10121048 glDirectDrawSurface7 *tmp;
10131049 if(previous) *previous = this->texture;
@@ -1250,9 +1286,15 @@
12511287 {
12521288 TRACE_ENTER(3,14,this,14,lplX,14,lplY);
12531289 if(!this) TRACE_RET(HRESULT,23,DDERR_INVALIDOBJECT);
1254 - FIXME("glDirectDrawSurface7::GetOverlayPosition: stub\n");
1255 - TRACE_EXIT(23,DDERR_GENERIC);
1256 - ERR(DDERR_GENERIC);
 1290+ if (!(this->ddsd.ddsCaps.dwCaps & DDSCAPS_OVERLAY))
 1291+ TRACE_RET(HRESULT, 23, DDERR_NOTAOVERLAYSURFACE);
 1292+ if (!this->overlayenabled) TRACE_RET(HRESULT, 23, DDERR_OVERLAYNOTVISIBLE);
 1293+ if (!this->overlayset) TRACE_RET(HRESULT, 23, DDERR_NOOVERLAYDEST);
 1294+ if (!lplX && !lplY) TRACE_RET(HRESULT, 23, DDERR_INVALIDPARAMS);
 1295+ if (lplX) *lplX = this->overlaypos.x;
 1296+ if (lplY) *lplY = this->overlaypos.y;
 1297+ TRACE_EXIT(23, DD_OK);
 1298+ return DD_OK;
12571299 }
12581300 HRESULT WINAPI glDirectDrawSurface7::GetPalette(LPDIRECTDRAWPALETTE FAR *lplpDDPalette)
12591301 {
@@ -1334,10 +1376,10 @@
13351377 {
13361378 if (ddInterface->lastsync)
13371379 {
1338 - RenderScreen(texture, 1, NULL, TRUE);
 1380+ RenderScreen(texture, 1, NULL, TRUE, FALSE, 0);
13391381 ddInterface->lastsync = false;
13401382 }
1341 - else RenderScreen(texture, 0, NULL, TRUE);
 1383+ else RenderScreen(texture, 0, NULL, TRUE, FALSE, 0);
13421384 }
13431385 TRACE_EXIT(23,error);
13441386 return error;
@@ -1524,9 +1566,14 @@
15251567 {
15261568 TRACE_ENTER(3,14,this,7,lX,7,lY);
15271569 if(!this) TRACE_RET(HRESULT,23,DDERR_INVALIDOBJECT);
1528 - FIXME("glDirectDrawSurface7::SetOverlayPosition: stub\n");
1529 - TRACE_EXIT(23,DDERR_GENERIC);
1530 - ERR(DDERR_GENERIC);
 1570+ if (!(this->ddsd.ddsCaps.dwCaps & DDSCAPS_OVERLAY))
 1571+ TRACE_RET(HRESULT, 23, DDERR_NOTAOVERLAYSURFACE);
 1572+ if (!this->overlayenabled) TRACE_RET(HRESULT, 23, DDERR_OVERLAYNOTVISIBLE);
 1573+ if (!this->overlayset) TRACE_RET(HRESULT, 23, DDERR_NOOVERLAYDEST);
 1574+ this->overlaypos.x = lX;
 1575+ this->overlaypos.y = lY;
 1576+ TRACE_EXIT(23, DD_OK);
 1577+ return DD_OK;
15311578 }
15321579 HRESULT WINAPI glDirectDrawSurface7::SetPalette(LPDIRECTDRAWPALETTE lpDDPalette)
15331580 {
@@ -1574,7 +1621,7 @@
15751622 if (!dxglcfg.DebugNoPaletteRedraw)
15761623 {
15771624 if(DXGLTimer_CheckLastDraw(&ddInterface->renderer->timer,dxglcfg.HackPaletteDelay))
1578 - RenderScreen(texture, dxglcfg.HackPaletteVsync, NULL, FALSE);
 1625+ RenderScreen(texture, dxglcfg.HackPaletteVsync, NULL, FALSE, NULL, 0);
15791626 }
15801627 }
15811628 TRACE_EXIT(23,DD_OK);
@@ -1641,11 +1688,20 @@
16421689 {
16431690 if(ddInterface->lastsync)
16441691 {
1645 - RenderScreen(texture,1,NULL,TRUE);
 1692+ RenderScreen(texture,1,NULL,TRUE,NULL,0);
16461693 ddInterface->lastsync = false;
16471694 }
1648 - else RenderScreen(texture,0,NULL,TRUE);
 1695+ else RenderScreen(texture,0,NULL,TRUE,NULL,0);
16491696 }
 1697+ if ((ddsd.ddsCaps.dwCaps & DDSCAPS_OVERLAY) && overlayenabled)
 1698+ {
 1699+ if (ddInterface->lastsync)
 1700+ {
 1701+ RenderScreen(ddInterface->primary->texture, 1, NULL, TRUE, NULL, 0);
 1702+ ddInterface->lastsync = false;
 1703+ }
 1704+ else RenderScreen(ddInterface->primary->texture, 0, NULL, TRUE, NULL, 0);
 1705+ }
16501706 TRACE_EXIT(23, DD_OK);
16511707 return DD_OK;
16521708 }
@@ -1653,17 +1709,43 @@
16541710 {
16551711 TRACE_ENTER(6,14,this,26,lpSrcRect,14,lpDDDestSurface,26,lpDestRect,9,dwFlags,14,lpDDOverlayFx);
16561712 if(!this) TRACE_RET(HRESULT,23,DDERR_INVALIDOBJECT);
1657 - FIXME("glDirectDrawSurface7::UpdateOverlay: stub\n");
1658 - TRACE_EXIT(23,DDERR_GENERIC);
1659 - ERR(DDERR_GENERIC);
 1713+ if (!(this->ddsd.ddsCaps.dwCaps & DDSCAPS_OVERLAY))
 1714+ TRACE_RET(HRESULT,23,DDERR_NOTAOVERLAYSURFACE);
 1715+ if (!(((glDirectDrawSurface7 *)lpDDDestSurface)->ddsd.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE))
 1716+ TRACE_RET(HRESULT, 23, DDERR_INVALIDSURFACETYPE);
 1717+ if ((dwFlags & DDOVER_SHOW) && (dwFlags & DDOVER_HIDE))
 1718+ TRACE_RET(HRESULT, 23, DDERR_INVALIDPARAMS);
 1719+ OVERLAY newoverlay;
 1720+ ZeroMemory(&newoverlay, sizeof(OVERLAY));
 1721+ if (lpSrcRect) newoverlay.srcrect = *lpSrcRect;
 1722+ else newoverlay.srcrect = nullrect;
 1723+ if (lpDestRect) newoverlay.destrect = *lpDestRect;
 1724+ else newoverlay.destrect = nullrect;
 1725+ newoverlay.surface = this;
 1726+ newoverlay.texture = this->texture;
 1727+ if (lpDDOverlayFx) newoverlay.fx = *lpDDOverlayFx;
 1728+ newoverlay.flags = dwFlags;
 1729+ if (dwFlags & DDOVER_SHOW)
 1730+ {
 1731+ this->overlayenabled = TRUE;
 1732+ newoverlay.enabled = TRUE;
 1733+ }
 1734+ if (dwFlags & DDOVER_HIDE)
 1735+ {
 1736+ this->overlayenabled = FALSE;
 1737+ newoverlay.enabled = FALSE;
 1738+ }
 1739+ this->overlaydest = (glDirectDrawSurface7 *)lpDDDestSurface;
 1740+ ((glDirectDrawSurface7 *)lpDDDestSurface)->AddOverlay(&newoverlay);
 1741+ TRACE_EXIT(23, DD_OK);
 1742+ return DD_OK;
16601743 }
16611744 HRESULT WINAPI glDirectDrawSurface7::UpdateOverlayDisplay(DWORD dwFlags)
16621745 {
16631746 TRACE_ENTER(2,14,this,9,dwFlags);
16641747 if(!this) TRACE_RET(HRESULT,23,DDERR_INVALIDOBJECT);
1665 - FIXME("glDirectDrawSurface7::UpdateOverlayDisplay: stub\n");
1666 - TRACE_EXIT(23,DDERR_GENERIC);
1667 - ERR(DDERR_GENERIC);
 1748+ TRACE_EXIT(23,DDERR_UNSUPPORTED);
 1749+ return DDERR_UNSUPPORTED;
16681750 }
16691751 HRESULT WINAPI glDirectDrawSurface7::UpdateOverlayZOrder(DWORD dwFlags, LPDIRECTDRAWSURFACE7 lpDDSReference)
16701752 {
@@ -1674,15 +1756,15 @@
16751757 ERR(DDERR_GENERIC);
16761758 }
16771759
1678 -extern "C" void glDirectDrawSurface7_RenderScreen(LPDIRECTDRAWSURFACE7 surface, int vsync, BOOL settime)
 1760+extern "C" void glDirectDrawSurface7_RenderScreen(LPDIRECTDRAWSURFACE7 surface, int vsync, BOOL settime, OVERLAY *overlays, int overlaycount)
16791761 {
1680 - ((glDirectDrawSurface7*)surface)->RenderScreen(((glDirectDrawSurface7*)surface)->texture, vsync, NULL, settime);
 1762+ ((glDirectDrawSurface7*)surface)->RenderScreen(((glDirectDrawSurface7*)surface)->texture, vsync, NULL, settime, overlays, overlaycount);
16811763 }
16821764
1683 -void glDirectDrawSurface7::RenderScreen(glTexture *texture, int vsync, glTexture *previous, BOOL settime)
 1765+void glDirectDrawSurface7::RenderScreen(glTexture *texture, int vsync, glTexture *previous, BOOL settime, OVERLAY *overlays, int overlaycount)
16841766 {
16851767 TRACE_ENTER(3,14,this,14,texture,14,vsync);
1686 - glRenderer_DrawScreen(ddInterface->renderer,texture, texture->palette, vsync, previous, settime);
 1768+ glRenderer_DrawScreen(ddInterface->renderer,texture, texture->palette, vsync, previous, settime, overlays, overlaycount);
16871769 TRACE_EXIT(0,0);
16881770 }
16891771 // ddraw 2+ api
@@ -1718,6 +1800,7 @@
17191801 {
17201802 TRACE_ENTER(3,14,this,14,lpddsd2,9,dwFlags);
17211803 if(!this) TRACE_RET(HRESULT,23,DDERR_INVALIDOBJECT);
 1804+ if (this->overlayenabled) TRACE_RET(HRESULT, 23, DDERR_SURFACEBUSY);
17221805 FIXME("glDirectDrawSurface7::SetSurfaceDesc: stub\n");
17231806 TRACE_EXIT(23,DDERR_GENERIC);
17241807 ERR(DDERR_GENERIC);
@@ -1857,6 +1940,107 @@
18581941 ERR(DDERR_GENERIC);
18591942 }
18601943
 1944+HRESULT glDirectDrawSurface7::AddOverlay(OVERLAY *overlay)
 1945+{
 1946+ OVERLAY *tmpptr;
 1947+ int i;
 1948+ if (overlaycount + 1 > maxoverlays)
 1949+ {
 1950+ if (!overlays)
 1951+ {
 1952+ overlays = (OVERLAY*)malloc(16 * sizeof(OVERLAY));
 1953+ if (!overlays) return DDERR_OUTOFMEMORY;
 1954+ maxoverlays = 16;
 1955+ }
 1956+ else
 1957+ {
 1958+ if (maxoverlays == 256) return DDERR_OUTOFCAPS;
 1959+ maxoverlays += 16;
 1960+ tmpptr = (OVERLAY*)realloc(overlays, maxoverlays * sizeof(OVERLAY));
 1961+ if (!tmpptr) return DDERR_OUTOFMEMORY;
 1962+ overlays = tmpptr;
 1963+ }
 1964+ }
 1965+ for (i = 0; i < overlaycount; i++)
 1966+ {
 1967+ if (overlays[i].surface == overlay->surface)
 1968+ {
 1969+ glTexture_Release(overlays[i].texture, FALSE);
 1970+ overlays[i].destrect = overlay->destrect;
 1971+ overlays[i].srcrect = overlay->srcrect;
 1972+ overlays[i].flags = overlay->flags;
 1973+ overlays[i].fx = overlay->fx;
 1974+ overlays[i].surface = overlay->surface;
 1975+ overlays[i].texture = overlay->texture;
 1976+ if (overlay->flags & DDOVER_SHOW) overlays[i].enabled = TRUE;
 1977+ if (overlay->flags & DDOVER_HIDE) overlays[i].enabled = FALSE;
 1978+ memcpy(&overlays[i], overlay, sizeof(OVERLAY));
 1979+ glTexture_AddRef(overlays[i].texture);
 1980+ return DD_OK;
 1981+ }
 1982+ }
 1983+ overlays[overlaycount] = *overlay;
 1984+ glTexture_AddRef(overlays[overlaycount].texture);
 1985+ overlaycount++;
 1986+ if (ddInterface->lastsync)
 1987+ {
 1988+ RenderScreen(ddInterface->primary->texture, 1, NULL, TRUE, overlays, overlaycount);
 1989+ ddInterface->lastsync = false;
 1990+ }
 1991+ else RenderScreen(ddInterface->primary->texture, 0, NULL, TRUE, overlays, overlaycount);
 1992+ return DD_OK;
 1993+}
 1994+
 1995+HRESULT glDirectDrawSurface7::DeleteOverlay(glDirectDrawSurface7 *surface)
 1996+{
 1997+ int i;
 1998+ for (i = 0; i < overlaycount; i++)
 1999+ {
 2000+ if (overlays[i].surface == surface)
 2001+ {
 2002+ glTexture_Release(overlays[i].texture, FALSE);
 2003+ overlaycount--;
 2004+ memmove(&overlays[i], &overlays[i + 1], (overlaycount - i) * sizeof(OVERLAY));
 2005+ if (surface->overlayenabled)
 2006+ {
 2007+ if (ddInterface->lastsync)
 2008+ {
 2009+ RenderScreen(ddInterface->primary->texture, 1, NULL, TRUE, overlays, overlaycount);
 2010+ ddInterface->lastsync = false;
 2011+ }
 2012+ else RenderScreen(ddInterface->primary->texture, 0, NULL, TRUE, overlays, overlaycount);
 2013+ }
 2014+ return DD_OK;
 2015+ }
 2016+ }
 2017+ return DDERR_NOTFOUND;
 2018+}
 2019+
 2020+HRESULT glDirectDrawSurface7::UpdateOverlayTexture(glDirectDrawSurface7 *surface, glTexture *texture)
 2021+{
 2022+ int i;
 2023+ for (i = 0; i < overlaycount; i++)
 2024+ {
 2025+ if (overlays[i].surface == surface)
 2026+ {
 2027+ glTexture_Release(overlays[i].texture, FALSE);
 2028+ overlays[i].texture = texture;
 2029+ glTexture_AddRef(overlays[i].texture);
 2030+ if (surface->overlayenabled)
 2031+ {
 2032+ if (ddInterface->lastsync)
 2033+ {
 2034+ RenderScreen(ddInterface->primary->texture, 1, NULL, TRUE, overlays, overlaycount);
 2035+ ddInterface->lastsync = false;
 2036+ }
 2037+ else RenderScreen(ddInterface->primary->texture, 0, NULL, TRUE, overlays, overlaycount);
 2038+ }
 2039+ return DD_OK;
 2040+ }
 2041+ }
 2042+ return DDERR_NOTFOUND;
 2043+}
 2044+
18612045 // DDRAW1 wrapper
18622046 glDirectDrawSurface1::glDirectDrawSurface1(glDirectDrawSurface7 *gl_DDS7)
18632047 {
@@ -2148,7 +2332,7 @@
21492333 {
21502334 TRACE_ENTER(6,14,this,26,lpSrcRect,14,lpDDDestSurface,26,lpDestRect,9,dwFlags,14,lpDDOverlayFx);
21512335 if(!this) TRACE_RET(HRESULT,23,DDERR_INVALIDOBJECT);
2152 - TRACE_RET(HRESULT,23,glDDS7->UpdateOverlay(lpSrcRect,(LPDIRECTDRAWSURFACE7)lpDDDestSurface,lpDestRect,dwFlags,lpDDOverlayFx));
 2336+ TRACE_RET(HRESULT,23,glDDS7->UpdateOverlay(lpSrcRect,((glDirectDrawSurface1*)lpDDDestSurface)->glDDS7,lpDestRect,dwFlags,lpDDOverlayFx));
21532337 }
21542338 HRESULT WINAPI glDirectDrawSurface1::UpdateOverlayDisplay(DWORD dwFlags)
21552339 {
@@ -2452,7 +2636,7 @@
24532637 {
24542638 TRACE_ENTER(6,14,this,26,lpSrcRect,14,lpDDDestSurface,26,lpDestRect,9,dwFlags,14,lpDDOverlayFx);
24552639 if(!this) TRACE_RET(HRESULT,23,DDERR_INVALIDOBJECT);
2456 - TRACE_RET(HRESULT,23,glDDS7->UpdateOverlay(lpSrcRect,(LPDIRECTDRAWSURFACE7)lpDDDestSurface,lpDestRect,dwFlags,lpDDOverlayFx));
 2640+ TRACE_RET(HRESULT,23,glDDS7->UpdateOverlay(lpSrcRect, ((glDirectDrawSurface2*)lpDDDestSurface)->glDDS7,lpDestRect,dwFlags,lpDDOverlayFx));
24572641 }
24582642 HRESULT WINAPI glDirectDrawSurface2::UpdateOverlayDisplay(DWORD dwFlags)
24592643 {
@@ -2781,7 +2965,7 @@
27822966 {
27832967 TRACE_ENTER(6,14,this,26,lpSrcRect,14,lpDDDestSurface,26,lpDestRect,9,dwFlags,14,lpDDOverlayFx);
27842968 if(!this) TRACE_RET(HRESULT,23,DDERR_INVALIDOBJECT);
2785 - TRACE_RET(HRESULT,23,glDDS7->UpdateOverlay(lpSrcRect,(LPDIRECTDRAWSURFACE7)lpDDDestSurface,lpDestRect,dwFlags,lpDDOverlayFx));
 2969+ TRACE_RET(HRESULT,23,glDDS7->UpdateOverlay(lpSrcRect,((glDirectDrawSurface3*)lpDDDestSurface)->glDDS7,lpDestRect,dwFlags,lpDDOverlayFx));
27862970 }
27872971 HRESULT WINAPI glDirectDrawSurface3::UpdateOverlayDisplay(DWORD dwFlags)
27882972 {
@@ -3090,7 +3274,7 @@
30913275 {
30923276 TRACE_ENTER(6,14,this,26,lpSrcRect,14,lpDDDestSurface,26,lpDestRect,9,dwFlags,14,lpDDOverlayFx);
30933277 if(!this) TRACE_RET(HRESULT,23,DDERR_INVALIDOBJECT);
3094 - TRACE_RET(HRESULT,23,glDDS7->UpdateOverlay(lpSrcRect,(LPDIRECTDRAWSURFACE7)lpDDDestSurface,lpDestRect,dwFlags,lpDDOverlayFx));
 3278+ TRACE_RET(HRESULT,23,glDDS7->UpdateOverlay(lpSrcRect,((glDirectDrawSurface4*)lpDDDestSurface)->glDDS7,lpDestRect,dwFlags,lpDDOverlayFx));
30953279 }
30963280 HRESULT WINAPI glDirectDrawSurface4::UpdateOverlayDisplay(DWORD dwFlags)
30973281 {
Index: ddraw/glDirectDrawSurface.h
@@ -1,5 +1,5 @@
22 // DXGL
3 -// Copyright (C) 2011-2015 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
@@ -118,7 +118,7 @@
119119 void SetTexture(glTexture *newtexture){ texture = newtexture; };
120120 glDirectDrawSurface7 *GetBackbuffer(){return backbuffer;};
121121 glDirectDrawSurface7 *GetZBuffer(){return zbuffer;};
122 - void RenderScreen(glTexture *texture, int vsync, glTexture *previous, BOOL settime);
 122+ void RenderScreen(glTexture *texture, int vsync, glTexture *previous, BOOL settime, OVERLAY *overlays, int overlaycount);
123123 // Special ddraw2->ddraw7 api
124124 HRESULT WINAPI Unlock2(LPVOID lpSurfaceData);
125125 HRESULT GetHandle(glDirect3DDevice7 *glD3DDev7, LPD3DTEXTUREHANDLE lpHandle);
@@ -125,6 +125,9 @@
126126 HRESULT Load(glDirectDrawSurface7 *src);
127127 HRESULT GetGammaRamp(DWORD dwFlags, LPDDGAMMARAMP lpRampData);
128128 HRESULT SetGammaRamp(DWORD dwFlags, LPDDGAMMARAMP lpRampData);
 129+ HRESULT AddOverlay(OVERLAY *overlay);
 130+ HRESULT DeleteOverlay(glDirectDrawSurface7 *surface);
 131+ HRESULT UpdateOverlayTexture(glDirectDrawSurface7 *surface, glTexture *texture);
129132 glDirectDrawSurface1 *dds1;
130133 glDirectDrawSurface2 *dds2;
131134 glDirectDrawSurface3 *dds3;
@@ -152,6 +155,13 @@
153156 glDirectDrawSurface7 *backbufferwraparound;
154157 DWORD attachcount;
155158 glDirectDrawSurface7 *attachparent;
 159+ BOOL overlayenabled;
 160+ BOOL overlayset;
 161+ int overlaycount;
 162+ int maxoverlays;
 163+ OVERLAY *overlays;
 164+ glDirectDrawSurface7 *overlaydest;
 165+ POINT overlaypos;
156166 private:
157167 int swapinterval;
158168 ULONG refcount7, refcount4, refcount3, refcount2, refcount1;
@@ -162,7 +172,6 @@
163173 int pagelocked;
164174 glDirect3DDevice7 *device1;
165175 glDirect3DDevice7 *device;
166 - bool overlay;
167176 IUnknown *zbuffer_iface;
168177 int version;
169178 unsigned char *clientbuffer;
Index: ddraw/glRenderer.cpp
@@ -1679,6 +1679,8 @@
16801680 This->hDC = NULL;
16811681 This->hRC = NULL;
16821682 This->pbo = NULL;
 1683+ This->overlays = NULL;
 1684+ This->overlaycount = 0;
16831685 This->last_fvf = 0xFFFFFFFF; // Bogus value to force initial FVF change
16841686 This->mode_3d = FALSE;
16851687 ZeroMemory(&This->dib, sizeof(DIB));
@@ -2122,7 +2124,7 @@
21232125 * @param previous
21242126 * Texture previously used as primary before a flip
21252127 */
2126 -void glRenderer_DrawScreen(glRenderer *This, glTexture *texture, glTexture *paltex, GLint vsync, glTexture *previous, BOOL settime)
 2128+void glRenderer_DrawScreen(glRenderer *This, glTexture *texture, glTexture *paltex, GLint vsync, glTexture *previous, BOOL settime, OVERLAY *overlays, int overlaycount)
21272129 {
21282130 /*DrawScreenCmd cmd;
21292131 cmd.opcode = OP_DRAWSCREEN;
@@ -2138,6 +2140,8 @@
21392141 This->inputs[2] = (void*)vsync;
21402142 This->inputs[3] = previous;
21412143 This->inputs[4] = (void*)settime;
 2144+ This->inputs[5] = overlays;
 2145+ This->inputs[6] = (void*)overlaycount;
21422146 This->opcode = OP_DRAWSCREEN;
21432147 SetEvent(This->start);
21442148 WaitForSingleObject(This->busy,INFINITE);
@@ -2850,6 +2854,7 @@
28512855 glUtil_Release(This->util);
28522856 free(This->shaders);
28532857 free(This->ext);
 2858+ if (This->overlays) free(This->overlays);
28542859 This->ext = NULL;
28552860 wglMakeCurrent(NULL,NULL);
28562861 wglDeleteContext(This->hRC);
@@ -2888,7 +2893,8 @@
28892894 break;
28902895 case OP_DRAWSCREEN:
28912896 glRenderer__DrawScreen(This,(glTexture*)This->inputs[0],(glTexture*)This->inputs[1],
2892 - (GLint)This->inputs[2],(glTexture*)This->inputs[3],true,(BOOL)This->inputs[4]);
 2897+ (GLint)This->inputs[2],(glTexture*)This->inputs[3],TRUE,(BOOL)This->inputs[4],
 2898+ (OVERLAY*)This->inputs[5],(int)This->inputs[6]);
28932899 break;
28942900 case OP_INITD3D:
28952901 glRenderer__InitD3D(This,(int)This->inputs[0],(int)This->inputs[1],(int)This->inputs[2]);
@@ -3581,7 +3587,7 @@
35823588 (ddsd.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)) ||
35833589 ((ddsd.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE) &&
35843590 !(ddsd.ddsCaps.dwCaps & DDSCAPS_FLIP)))
3585 - glRenderer__DrawScreen(This,cmd->dest,cmd->dest->palette,0,NULL,FALSE,TRUE);
 3591+ glRenderer__DrawScreen(This,cmd->dest,cmd->dest->palette,0,NULL,FALSE,TRUE,NULL,0);
35863592 This->outputs[0] = DD_OK;
35873593 SetEvent(This->busy);
35883594 }
@@ -3955,11 +3961,32 @@
39563962 return __UpdateLayeredWindow(hWnd, hdcDst, pptDst, psize, hdcSrc, pptSrc, crKey, pblend, dwFlags);
39573963 }
39583964
3959 -void glRenderer__DrawScreen(glRenderer *This, glTexture *texture, glTexture *paltex, GLint vsync, glTexture *previous, BOOL setsync, BOOL settime)
 3965+void glRenderer__DrawScreen(glRenderer *This, glTexture *texture, glTexture *paltex, GLint vsync, glTexture *previous, BOOL setsync, BOOL settime, OVERLAY *overlays, int overlaycount)
39603966 {
39613967 int progtype;
39623968 RECT r, r2;
 3969+ int i;
 3970+ unsigned __int64 shaderid;
 3971+ BltCommand bltcmd;
 3972+ glTexture *primary = texture;
39633973 BOOL scale512448 = Is512448Scale(This, texture, paltex);
 3974+ if (overlays && overlaycount)
 3975+ {
 3976+ if (!This->overlays)
 3977+ {
 3978+ This->overlays = (OVERLAY *)malloc(overlaycount * sizeof(OVERLAY));
 3979+ This->overlaycount = overlaycount;
 3980+ }
 3981+ else
 3982+ {
 3983+ if (overlaycount != This->overlaycount)
 3984+ {
 3985+ This->overlays = (OVERLAY*)realloc(This->overlays, overlaycount * sizeof(OVERLAY));
 3986+ This->overlaycount = overlaycount;
 3987+ }
 3988+ }
 3989+ memcpy(This->overlays, overlays, overlaycount * sizeof(OVERLAY));
 3990+ }
39643991 glUtil_BlendEnable(This->util, FALSE);
39653992 if (previous) previous->levels[0].ddsd.ddsCaps.dwCaps &= ~DDSCAPS_FRONTBUFFER;
39663993 texture->levels[0].ddsd.ddsCaps.dwCaps |= DDSCAPS_FRONTBUFFER;
@@ -4104,6 +4131,38 @@
41054132 glUtil_SetCull(This->util, D3DCULL_NONE);
41064133 glUtil_SetPolyMode(This->util, D3DFILL_SOLID);
41074134 This->ext->glDrawRangeElements(GL_TRIANGLE_STRIP,0,3,4,GL_UNSIGNED_SHORT,bltindices);
 4135+ if (This->overlays)
 4136+ {
 4137+ for (i = 0; i < overlaycount; i++)
 4138+ {
 4139+ if (This->overlays[i].enabled)
 4140+ {
 4141+ bltcmd.flags = 0x80000000;
 4142+ if (overlays[i].flags & DDOVER_DDFX)
 4143+ {
 4144+ if (overlays[i].flags & DDOVER_KEYDEST) bltcmd.flags |= DDBLT_KEYDEST;
 4145+ if (overlays[i].flags & DDOVER_KEYDESTOVERRIDE)
 4146+ {
 4147+ bltcmd.flags |= DDBLT_KEYDESTOVERRIDE;
 4148+ bltcmd.destkey = overlays[i].fx.dckDestColorkey;
 4149+ }
 4150+ if (overlays[i].flags & DDOVER_KEYSRC) bltcmd.flags |= DDBLT_KEYSRC;
 4151+ if (overlays[i].flags & DDOVER_KEYSRCOVERRIDE)
 4152+ {
 4153+ bltcmd.flags |= DDBLT_KEYSRCOVERRIDE;
 4154+ bltcmd.srckey = overlays[i].fx.dckSrcColorkey;
 4155+ }
 4156+ }
 4157+ bltcmd.src = This->overlays[i].texture;
 4158+ bltcmd.srclevel = 0;
 4159+ bltcmd.srcrect = This->overlays[i].srcrect;
 4160+ bltcmd.dest = primary;
 4161+ bltcmd.destlevel = 0;
 4162+ bltcmd.destrect = This->overlays[i].destrect;
 4163+ //FIXME: Finish Blt
 4164+ }
 4165+ }
 4166+ }
41084167 glFlush();
41094168 if(This->hWnd) SwapBuffers(This->hDC);
41104169 else
Index: ddraw/glRenderer.h
@@ -161,6 +161,8 @@
162162 BOOL mode_3d;
163163 float postsizex, postsizey;
164164 int xoffset, yoffset;
 165+ OVERLAY *overlays;
 166+ int overlaycount;
165167 } glRenderer;
166168
167169 HRESULT glRenderer_AddCommand(glRenderer *This, QueueCmd *cmd, BOOL inner, BOOL wait);
@@ -172,7 +174,7 @@
173175 void glRenderer_DownloadTexture(glRenderer *This, glTexture *texture, GLint level);
174176 HRESULT glRenderer_Blt(glRenderer *This, BltCommand *cmd);
175177 void glRenderer_MakeTexture(glRenderer *This, glTexture *texture);
176 -void glRenderer_DrawScreen(glRenderer *This, glTexture *texture, glTexture *paltex, GLint vsync, glTexture *previous, BOOL settime);
 178+void glRenderer_DrawScreen(glRenderer *This, glTexture *texture, glTexture *paltex, GLint vsync, glTexture *previous, BOOL settime, OVERLAY *overlays, int overlaycount);
177179 void glRenderer_DeleteTexture(glRenderer *This, glTexture *texture);
178180 void glRenderer_InitD3D(glRenderer *This, int zbuffer, int x, int y);
179181 void glRenderer_Flush(glRenderer *This);
@@ -206,7 +208,7 @@
207209 void glRenderer__DownloadTexture(glRenderer *This, glTexture *texture, GLint level);
208210 void glRenderer__Blt(glRenderer *This, BltCommand *cmd);
209211 void glRenderer__MakeTexture(glRenderer *This, glTexture *texture);
210 -void glRenderer__DrawScreen(glRenderer *This, glTexture *texture, glTexture *paltex, GLint vsync, glTexture *previous, BOOL setsync, BOOL settime);
 212+void glRenderer__DrawScreen(glRenderer *This, glTexture *texture, glTexture *paltex, GLint vsync, glTexture *previous, BOOL setsync, BOOL settime, OVERLAY *overlays, int overlaycount);
211213 void glRenderer__DeleteTexture(glRenderer *This, glTexture *texture);
212214 void glRenderer__DrawBackbuffer(glRenderer *This, glTexture **texture, int x, int y, int progtype, BOOL paletted, BOOL firstpass);
213215 void glRenderer__DrawBackbufferRect(glRenderer *This, glTexture *texture, RECT srcrect, RECT destrect, int progtype);
Index: ddraw/glTexture.cpp
@@ -94,20 +94,20 @@
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
9797 {sizeof(DDPIXELFORMAT), DDPF_ZBUFFER, 0, 32, 8, 0xFF, 0xFFFFFF00, 0}, // 32 bit Z buffer with stencil, reversed
98 - {sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('Y','8',' ',' '), 8, 0, 0, 0, 0}, // 8-bit grayscale
99 - {sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('Y','8','0','0'), 8, 0, 0, 0, 0}, // 8-bit grayscale
100 - {sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('G','R','E','Y'), 8, 0, 0, 0, 0}, // 8-bit grayscale
101 - {sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('Y','1','6',' '), 16, 0, 0, 0, 0}, // 16-bit grayscale
102 - {sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('U','Y','V','Y'), 16, 0, 0, 0, 0}, // UYVY packed YUV surface
103 - {sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('U','Y','N','V'), 16, 0, 0, 0, 0}, // UYVY packed YUV surface (NVIDIA alias)
104 - {sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('Y','4','2','2'), 16, 0, 0, 0, 0}, // UYVY packed YUV surface (ADS Tech. alias)
105 - {sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('Y','U','Y','2'), 16, 0, 0, 0, 0}, // YUY2 packed YUV surface
106 - {sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('Y','U','Y','V'), 16, 0, 0, 0, 0}, // YUY2 packed YUV surface (dup. of YUY2)
107 - {sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('Y','U','N','V'), 16, 0, 0, 0, 0}, // YUY2 packed YUV surface (NVIDIA alias)
108 - {sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('Y','V','Y','U'), 16, 0, 0, 0, 0}, // YUY2 packed YUV surface
109 - {sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('R','G','B','G'), 16, 0, 0, 0, 0}, // RGBG packed 16-bit pixelformat
110 - {sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('G','R','G','B'), 16, 0, 0, 0, 0}, // GRGB packed 16-bit pixelformat
111 - {sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('A','Y','U','V'), 32, 0, 0, 0, 0}, // AYUV packed YUV surface
 98+ {sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('Y','8',' ',' '), 0, 0, 0, 0, 0}, // 8-bit grayscale
 99+ {sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('Y','8','0','0'), 0, 0, 0, 0, 0}, // 8-bit grayscale
 100+ {sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('G','R','E','Y'), 0, 0, 0, 0, 0}, // 8-bit grayscale
 101+ {sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('Y','1','6',' '), 0, 0, 0, 0, 0}, // 16-bit grayscale
 102+ {sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('U','Y','V','Y'), 0, 0, 0, 0, 0}, // UYVY packed YUV surface
 103+ {sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('U','Y','N','V'), 0, 0, 0, 0, 0}, // UYVY packed YUV surface (NVIDIA alias)
 104+ {sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('Y','4','2','2'), 0, 0, 0, 0, 0}, // UYVY packed YUV surface (ADS Tech. alias)
 105+ {sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('Y','U','Y','2'), 0, 0, 0, 0, 0}, // YUY2 packed YUV surface
 106+ {sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('Y','U','Y','V'), 0, 0, 0, 0, 0}, // YUY2 packed YUV surface (dup. of YUY2)
 107+ {sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('Y','U','N','V'), 0, 0, 0, 0, 0}, // YUY2 packed YUV surface (NVIDIA alias)
 108+ {sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('Y','V','Y','U'), 0, 0, 0, 0, 0}, // YUY2 packed YUV surface
 109+ {sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('R','G','B','G'), 0, 0, 0, 0, 0}, // RGBG packed 16-bit pixelformat
 110+ {sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('G','R','G','B'), 0, 0, 0, 0, 0}, // GRGB packed 16-bit pixelformat
 111+ {sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('A','Y','U','V'), 0, 0, 0, 0, 0}, // AYUV packed YUV surface
112112 };
113113 static const int END_TEXFORMATS = __LINE__ - 4;
114114 int numtexformats;
@@ -505,6 +505,15 @@
506506 int i;
507507 int texformat = -1;
508508 numtexformats = END_TEXFORMATS - START_TEXFORMATS;
 509+ DDPIXELFORMAT compformat;
 510+ if (pixelformat->dwFlags & DDPF_FOURCC)
 511+ {
 512+ ZeroMemory(&compformat, sizeof(DDPIXELFORMAT));
 513+ compformat.dwSize = sizeof(DDPIXELFORMAT);
 514+ compformat.dwFlags = pixelformat->dwFlags;
 515+ compformat.dwFourCC = pixelformat->dwFourCC;
 516+ }
 517+ else compformat = *pixelformat;
509518 for (i = 0; i < numtexformats; i++)
510519 {
511520 if (!memcmp(&texformats[i], pixelformat, sizeof(DDPIXELFORMAT)))
@@ -888,9 +897,18 @@
889898 DWORD x, y;
890899 GLenum error;
891900 numtexformats = END_TEXFORMATS - START_TEXFORMATS;
 901+ DDPIXELFORMAT compformat;
 902+ if (This->levels[0].ddsd.ddpfPixelFormat.dwFlags & DDPF_FOURCC)
 903+ {
 904+ ZeroMemory(&compformat, sizeof(DDPIXELFORMAT));
 905+ compformat.dwSize = sizeof(DDPIXELFORMAT);
 906+ compformat.dwFlags = This->levels[0].ddsd.ddpfPixelFormat.dwFlags;
 907+ compformat.dwFourCC = This->levels[0].ddsd.ddpfPixelFormat.dwFourCC;
 908+ }
 909+ else compformat = This->levels[0].ddsd.ddpfPixelFormat;
892910 for (i = 0; i < numtexformats; i++)
893911 {
894 - if (!memcmp(&texformats[i], &This->levels[0].ddsd.ddpfPixelFormat, sizeof(DDPIXELFORMAT)))
 912+ if (!memcmp(&texformats[i], &compformat, sizeof(DDPIXELFORMAT)))
895913 {
896914 texformat = i;
897915 break;
Index: ddraw/struct.h
@@ -326,7 +326,6 @@
327327 BufferObject *pboPack;
328328 BufferObject *pboUnpack;
329329 } glTexture;
330 -
331330 // Color orders:
332331 // 0 - ABGR
333332 // 1 - ARGB
@@ -337,6 +336,17 @@
338337 // 6 - Alpha
339338 // 7 - Luminance Alpha
340339
 340+typedef struct OVERLAY
 341+{
 342+ DDOVERLAYFX fx;
 343+ RECT srcrect;
 344+ RECT destrect;
 345+ void *surface;
 346+ glTexture *texture;
 347+ DWORD flags;
 348+ BOOL enabled;
 349+} OVERLAY;
 350+
341351 typedef struct SHADER
342352 {
343353 GLint vs;
Index: dxglcfg/surfacegen.cpp
@@ -1949,20 +1949,20 @@
19501950 {sizeof(DDPIXELFORMAT), DDPF_ZBUFFER, 0, 32, 0, 0xFFFFFFFF, 0, 0}, // 32 bit Z buffer
19511951 {sizeof(DDPIXELFORMAT), DDPF_ZBUFFER, 0, 32, 8, 0xFFFFFF00, 0xFF, 0}, // 32 bit Z buffer with stencil
19521952 {sizeof(DDPIXELFORMAT), DDPF_ZBUFFER, 0, 32, 8, 0xFF, 0xFFFFFF00, 0}, // 32 bit Z buffer with stencil, reversed
1953 - {sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('Y','8',' ',' '), 8, 0, 0, 0, 0}, // 8-bit grayscale
1954 - {sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('Y','8','0','0'), 8, 0, 0, 0, 0}, // 8-bit grayscale
1955 - {sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('G','R','E','Y'), 8, 0, 0, 0, 0}, // 8-bit grayscale
1956 - {sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('Y','1','6',' '), 16, 0, 0, 0, 0}, // 16-bit grayscale
1957 - {sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('U','Y','V','Y'), 16, 0, 0, 0, 0}, // UYVY packed YUV surface
1958 - {sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('U','Y','N','V'), 16, 0, 0, 0, 0}, // UYVY packed YUV surface (NVIDIA alias)
1959 - {sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('Y','4','2','2'), 16, 0, 0, 0, 0}, // UYVY packed YUV surface (ADS Tech. alias)
1960 - {sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('Y','U','Y','2'), 16, 0, 0, 0, 0}, // YUY2 packed YUV surface
1961 - {sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('Y','U','Y','V'), 16, 0, 0, 0, 0}, // YUY2 packed YUV surface (dup. of YUY2)
1962 - {sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('Y','U','N','V'), 16, 0, 0, 0, 0}, // YUY2 packed YUV surface (NVIDIA alias)
1963 - {sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('Y','V','Y','U'), 16, 0, 0, 0, 0}, // YUY2 packed YUV surface
1964 - {sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('R','G','B','G'), 16, 0, 0, 0, 0}, // RGBG packed 16-bit pixelformat
1965 - {sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('G','R','G','B'), 16, 0, 0, 0, 0}, // GRGB packed 16-bit pixelformat
1966 - {sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('A','Y','U','V'), 32, 0, 0, 0, 0}, // AYUV packed YUV surface
 1953+ {sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('Y','8',' ',' '), 0, 0, 0, 0, 0}, // 8-bit grayscale
 1954+ {sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('Y','8','0','0'), 0, 0, 0, 0, 0}, // 8-bit grayscale
 1955+ {sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('G','R','E','Y'), 0, 0, 0, 0, 0}, // 8-bit grayscale
 1956+ {sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('Y','1','6',' '), 0, 0, 0, 0, 0}, // 16-bit grayscale
 1957+ {sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('U','Y','V','Y'), 0, 0, 0, 0, 0}, // UYVY packed YUV surface
 1958+ {sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('U','Y','N','V'), 0, 0, 0, 0, 0}, // UYVY packed YUV surface (NVIDIA alias)
 1959+ {sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('Y','4','2','2'), 0, 0, 0, 0, 0}, // UYVY packed YUV surface (ADS Tech. alias)
 1960+ {sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('Y','U','Y','2'), 0, 0, 0, 0, 0}, // YUY2 packed YUV surface
 1961+ {sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('Y','U','Y','V'), 0, 0, 0, 0, 0}, // YUY2 packed YUV surface (dup. of YUY2)
 1962+ {sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('Y','U','N','V'), 0, 0, 0, 0, 0}, // YUY2 packed YUV surface (NVIDIA alias)
 1963+ {sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('Y','V','Y','U'), 0, 0, 0, 0, 0}, // YUY2 packed YUV surface
 1964+ {sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('R','G','B','G'), 0, 0, 0, 0, 0}, // RGBG packed 16-bit pixelformat
 1965+ {sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('G','R','G','B'), 0, 0, 0, 0, 0}, // GRGB packed 16-bit pixelformat
 1966+ {sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('A','Y','U','V'), 0, 0, 0, 0, 0}, // AYUV packed YUV surface
19671967 };
19681968
19691969 static const LPTSTR strErrorMessages[] =