DXGL r660 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r659‎ | r660 | r661 >
Date:01:24, 6 June 2016
Author:admin
Status:new
Tags:
Comment:
Bring back Blt surface isolation from r631 - currently breaks dest colorkey Blt and part of ROP test.
Fix a regression in D3D textures.
Fix EnumDisplayModes DDSURFACEDESC2 in DDraw 6 and 7.
Rewrite several parts of the code to support the Blt changes.
Modified paths:
  • /ddraw/common.h (modified) (history)
  • /ddraw/const.c (added) (history)
  • /ddraw/const.h (added) (history)
  • /ddraw/ddraw.vcxproj (modified) (history)
  • /ddraw/ddraw.vcxproj.filters (modified) (history)
  • /ddraw/glDirectDraw.cpp (modified) (history)
  • /ddraw/glDirectDrawClipper.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/glTexture.h (modified) (history)
  • /ddraw/glUtil.cpp (modified) (history)
  • /ddraw/glUtil.h (modified) (history)
  • /ddraw/struct.h (modified) (history)

Diff [purge]

Index: ddraw/common.h
@@ -1,5 +1,5 @@
22 // DXGL
3 -// Copyright (C) 2011-2015 William Feely
 3+// Copyright (C) 2011-2016 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
@@ -31,6 +31,7 @@
3232 #include "include/GL/glext.h"
3333 #include "include/GL/wglext.h"
3434 #include "struct.h"
 35+#include "const.h"
3536 #include "glExtensions.h"
3637 #ifdef __cplusplus
3738 #include "string.h"
Index: ddraw/const.c
@@ -0,0 +1,20 @@
 2+// DXGL
 3+// Copyright (C) 2016 William Feely
 4+
 5+// This library is free software; you can redistribute it and/or
 6+// modify it under the terms of the GNU Lesser General Public
 7+// License as published by the Free Software Foundation; either
 8+// version 2.1 of the License, or (at your option) any later version.
 9+
 10+// This library is distributed in the hope that it will be useful,
 11+// but WITHOUT ANY WARRANTY; without even the implied warranty of
 12+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 13+// Lesser General Public License for more details.
 14+
 15+// You should have received a copy of the GNU Lesser General Public
 16+// License along with this library; if not, write to the Free Software
 17+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 18+
 19+#include "common.h"
 20+
 21+const RECT nullrect = { -1,-1,-1,-1 };
\ No newline at end of file
Index: ddraw/const.h
@@ -0,0 +1,32 @@
 2+// DXGL
 3+// Copyright (C) 2016 William Feely
 4+
 5+// This library is free software; you can redistribute it and/or
 6+// modify it under the terms of the GNU Lesser General Public
 7+// License as published by the Free Software Foundation; either
 8+// version 2.1 of the License, or (at your option) any later version.
 9+
 10+// This library is distributed in the hope that it will be useful,
 11+// but WITHOUT ANY WARRANTY; without even the implied warranty of
 12+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 13+// Lesser General Public License for more details.
 14+
 15+// You should have received a copy of the GNU Lesser General Public
 16+// License along with this library; if not, write to the Free Software
 17+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 18+
 19+#pragma once
 20+#ifndef __CONST_H
 21+#define __CONST_H
 22+
 23+#ifdef __cplusplus
 24+extern "C" {
 25+#endif
 26+
 27+ extern const RECT nullrect;
 28+
 29+#ifdef __cplusplus
 30+}
 31+#endif
 32+
 33+#endif //__CONST_H
\ No newline at end of file
Index: ddraw/ddraw.vcxproj
@@ -278,6 +278,7 @@
279279 </ItemGroup>
280280 <ItemGroup>
281281 <ClInclude Include="common.h" />
 282+ <ClInclude Include="const.h" />
282283 <ClInclude Include="ddraw.h" />
283284 <ClInclude Include="glClassFactory.h" />
284285 <ClInclude Include="glDirect3D.h" />
@@ -320,6 +321,14 @@
321322 <ClInclude Include="util.h" />
322323 </ItemGroup>
323324 <ItemGroup>
 325+ <ClCompile Include="const.c">
 326+ <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">NotUsing</PrecompiledHeader>
 327+ <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release no DXGL|Win32'">NotUsing</PrecompiledHeader>
 328+ <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug No MSVCRT|Win32'">NotUsing</PrecompiledHeader>
 329+ <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug no DXGL|Win32'">NotUsing</PrecompiledHeader>
 330+ <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">NotUsing</PrecompiledHeader>
 331+ <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug Trace|Win32'">NotUsing</PrecompiledHeader>
 332+ </ClCompile>
324333 <ClCompile Include="ddraw.cpp" />
325334 <ClCompile Include="dllmain.cpp">
326335 <CompileAsManaged Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</CompileAsManaged>
Index: ddraw/ddraw.vcxproj.filters
@@ -152,6 +152,9 @@
153153 <ClInclude Include="struct.h">
154154 <Filter>Header Files</Filter>
155155 </ClInclude>
 156+ <ClInclude Include="const.h">
 157+ <Filter>Header Files</Filter>
 158+ </ClInclude>
156159 </ItemGroup>
157160 <ItemGroup>
158161 <ClCompile Include="ddraw.cpp">
@@ -256,6 +259,9 @@
257260 <ClCompile Include="glTexture.cpp">
258261 <Filter>Source Files</Filter>
259262 </ClCompile>
 263+ <ClCompile Include="const.c">
 264+ <Filter>Source Files</Filter>
 265+ </ClCompile>
260266 </ItemGroup>
261267 <ItemGroup>
262268 <ResourceCompile Include="ddraw.rc">
Index: ddraw/glDirectDraw.cpp
@@ -470,8 +470,8 @@
471471 DEVMODE *tmp;
472472 if(!modes) ERR(DDERR_OUTOFMEMORY);
473473 DDSURFACEDESC2 ddmode;
474 - ZeroMemory(&ddmode,sizeof(DDSURFACEDESC));
475 - ddmode.dwSize = sizeof(DDSURFACEDESC);
 474+ ZeroMemory(&ddmode,sizeof(DDSURFACEDESC2));
 475+ ddmode.dwSize = sizeof(DDSURFACEDESC2);
476476 ddmode.dwFlags = DDSD_HEIGHT | DDSD_WIDTH | DDSD_PITCH | DDSD_PIXELFORMAT | DDSD_REFRESHRATE;
477477 while(EnumDisplaySettings(NULL,modenum++,&mode))
478478 {
@@ -1442,7 +1442,7 @@
14431443 glDD7->internalx = glDD7->screenx = dwWidth;
14441444 glDD7->internaly = glDD7->screeny = dwHeight;
14451445 if (glDD7->renderer && glDD7->primary) glRenderer_DrawScreen(glDD7->renderer, glDD7->primary->texture,
1446 - glDD7->primary->texture->palette, glDD7->primary, glDD7->primary, 0);
 1446+ glDD7->primary->texture->palette, 0);
14471447 }
14481448
14491449
@@ -1952,7 +1952,7 @@
19531953 if(dwFlags & 0xFFFFFFFA) TRACE_RET(HRESULT,23,DDERR_INVALIDPARAMS);
19541954 if(dwFlags == 5) TRACE_RET(HRESULT,23,DDERR_INVALIDPARAMS);
19551955 if(!lastsync) lastsync = true;
1956 - else if(primary) primary->RenderScreen(primary->texture,primary,1);
 1956+ else if(primary) primary->RenderScreen(primary->texture,1);
19571957 TRACE_EXIT(23,DD_OK);
19581958 return DD_OK;
19591959 }
Index: ddraw/glDirectDrawClipper.cpp
@@ -517,5 +517,5 @@
518518 ddsd.dwWidth = texture->levels[0].ddsd.dwWidth;
519519 ddsd.lPitch = NextMultipleOf4(ddsd.dwWidth * 2);
520520 ddsd.dwHeight = texture->levels[0].ddsd.dwHeight;
521 - glTexture_Create(&ddsd, &This->texture, renderer, ddsd.dwWidth, ddsd.dwHeight, FALSE);
 521+ glTexture_Create(&ddsd, &This->texture, renderer, ddsd.dwWidth, ddsd.dwHeight, FALSE, FALSE);
522522 }
\ No newline at end of file
Index: ddraw/glDirectDrawPalette.c
@@ -309,7 +309,7 @@
310310 DDSURFACEDESC2 ddsd;
311311 ZeroMemory(&ddsd, sizeof(DDSURFACEDESC2));
312312 memcpy(&ddsd, &ddsd256pal, sizeof(DDSURFACEDESC2));
313 - glTexture_Create(&ddsd256pal, &This->texture, renderer, 256, 1, FALSE);
 313+ glTexture_Create(&ddsd256pal, &This->texture, renderer, 256, 1, FALSE, FALSE);
314314 glTexture_Lock(This->texture, 0, NULL, &ddsd, 0, FALSE);
315315 memcpy(ddsd.lpSurface, This->palette, 1024);
316316 glTexture_Unlock(This->texture, 0, NULL, FALSE);
Index: ddraw/glDirectDrawSurface.cpp
@@ -52,9 +52,6 @@
5353 pagelocked = 0;
5454 flipcount = 0;
5555 ZeroMemory(colorkey,4*sizeof(CKEY));
56 - ZeroMemory(&fbo,sizeof(FBO));
57 - ZeroMemory(&zfbo,sizeof(FBO));
58 - ZeroMemory(&stencilfbo,sizeof(FBO));
5956 palette = NULL;
6057 texture = NULL;
6158 clipper = NULL;
@@ -197,7 +194,7 @@
198195 texture = parenttex;
199196 glTexture_AddRef(texture);
200197 }
201 - else glTexture_Create(&ddsd, &texture, ddInterface->renderer, fakex, fakey, FALSE);
 198+ else glTexture_Create(&ddsd, &texture, ddInterface->renderer, fakex, fakey, hasstencil, FALSE);
202199 if (!(ddsd.dwFlags & DDSD_PITCH))
203200 {
204201 ddsd.dwFlags |= DDSD_PITCH;
@@ -305,8 +302,6 @@
306303 if (d3dt2) delete d3dt2;
307304 if (gammacontrol) free(gammacontrol);
308305 if (texture) glTexture_Release(texture, FALSE);
309 - if(fbo.fbo) glRenderer_DeleteFBO(ddInterface->renderer, &fbo);
310 - if(stencilfbo.fbo) glRenderer_DeleteFBO(ddInterface->renderer, &stencilfbo);
311306 //if(bitmapinfo) free(bitmapinfo);
312307 if(palette) glDirectDrawPalette_Release(palette);
313308 if(backbuffer) backbuffer->Release();
@@ -628,11 +623,6 @@
629624 {
630625 if (zbuffer)
631626 {
632 - if (zbuffer->zfbo.fbo)
633 - {
634 - glRenderer_DeleteFBO(ddInterface->renderer, &zbuffer->zfbo);
635 - ZeroMemory(&zbuffer->zfbo, sizeof(FBO));
636 - }
637627 if (zbuffer->texture->dummycolor)
638628 {
639629 glTexture_DeleteDummyColor(zbuffer->texture, FALSE);
@@ -660,11 +650,25 @@
661651 HRESULT error;
662652 RECT tmprect;
663653 glDirectDrawSurface7 *pattern;
 654+ BltCommand cmd;
664655 TRACE_ENTER(6,14,this,26,lpDestRect,14,lpDDSrcSurface,26,lpSrcRect,9,dwFlags,14,lpDDBltFx);
665 - if(!this) TRACE_RET(HRESULT,23,DDERR_INVALIDOBJECT);
666 - if ((dwFlags & DDBLT_DEPTHFILL) && !lpDDBltFx) TRACE_RET(HRESULT,32,DDERR_INVALIDPARAMS);
667 - if((dwFlags & DDBLT_COLORFILL) && !lpDDBltFx) TRACE_RET(HRESULT,23,DDERR_INVALIDPARAMS);
668 - if((dwFlags & DDBLT_DDFX) && !lpDDBltFx) TRACE_RET(HRESULT,23,DDERR_INVALIDPARAMS);
 656+ if (!this) TRACE_RET(HRESULT, 23, DDERR_INVALIDOBJECT);
 657+ if ((dwFlags & DDBLT_DEPTHFILL) && !lpDDBltFx) TRACE_RET(HRESULT, 32, DDERR_INVALIDPARAMS);
 658+ if ((dwFlags & DDBLT_COLORFILL) && !lpDDBltFx) TRACE_RET(HRESULT, 23, DDERR_INVALIDPARAMS);
 659+ if ((dwFlags & DDBLT_DDFX) && !lpDDBltFx) TRACE_RET(HRESULT, 23, DDERR_INVALIDPARAMS);
 660+ ZeroMemory(&cmd, sizeof(BltCommand));
 661+ cmd.dest = this->texture;
 662+ cmd.destlevel = this->miplevel;
 663+ if (lpDestRect) cmd.destrect = *lpDestRect;
 664+ else cmd.destrect = nullrect;
 665+ if (lpSrcRect) cmd.srcrect = *lpSrcRect;
 666+ else cmd.srcrect = nullrect;
 667+ if (lpDDSrcSurface)
 668+ {
 669+ cmd.src = ((glDirectDrawSurface7*)lpDDSrcSurface)->texture;
 670+ cmd.srclevel = ((glDirectDrawSurface7*)lpDDSrcSurface)->miplevel;
 671+ }
 672+ cmd.flags = dwFlags;
669673 if (dwFlags & DDBLT_ROP)
670674 {
671675 if (!lpDDBltFx) TRACE_RET(HRESULT, 23, DDERR_INVALIDPARAMS);
@@ -672,16 +676,27 @@
673677 {
674678 if (!lpDDBltFx->lpDDSPattern) TRACE_RET(HRESULT, 23, DDERR_INVALIDPARAMS);
675679 pattern = (glDirectDrawSurface7*)lpDDBltFx->lpDDSPattern;
 680+ cmd.pattern = pattern->texture;
 681+ cmd.patternlevel = pattern->miplevel;
676682 }
677683 }
678684 if (dwFlags & DDBLT_KEYSRC)
679685 {
680686 if (!lpDDSrcSurface) TRACE_RET(HRESULT, 23, DDERR_INVALIDPARAMS);
681 - if (((glDirectDrawSurface7*)lpDDSrcSurface)->colorkey[0].colorspace) dwFlags |= 0x20000000;
 687+ if (!(((glDirectDrawSurface7*)lpDDSrcSurface)->ddsd.dwFlags & DDSD_CKSRCBLT))
 688+ TRACE_RET(HRESULT, 23, DDERR_INVALIDPARAMS);
 689+ if (((glDirectDrawSurface7*)lpDDSrcSurface)->ddsd.ddckCKSrcBlt.dwColorSpaceHighValue !=
 690+ ((glDirectDrawSurface7*)lpDDSrcSurface)->ddsd.ddckCKSrcBlt.dwColorSpaceLowValue)
 691+ cmd.flags |= 0x20000000;
682692 }
683 - if ((dwFlags & DDBLT_KEYDEST) && colorkey[1].colorspace) dwFlags |= 0x40000000;
 693+ if (dwFlags & DDBLT_KEYDEST)
 694+ {
 695+ if (!(this->ddsd.dwFlags & DDSD_CKDESTBLT)) TRACE_RET(HRESULT, 23, DDERR_INVALIDPARAMS);
 696+ if (this->ddsd.ddckCKDestBlt.dwColorSpaceHighValue != this->ddsd.ddckCKDestBlt.dwColorSpaceLowValue)
 697+ cmd.flags |= 0x40000000;
 698+ }
684699 glDirectDrawSurface7 *src = (glDirectDrawSurface7 *)lpDDSrcSurface;
685 - if (clipper)
 700+/* if (clipper)
686701 {
687702 if (!clipper->hWnd)
688703 {
@@ -693,24 +708,42 @@
694709 }
695710 dwFlags |= 0x10000000;
696711 }
697 - }
 712+ }*/
 713+ if (this->clipper && !(this->clipper->hWnd)) cmd.flags |= 0x10000000;
 714+ if (lpDDBltFx) cmd.bltfx = *lpDDBltFx;
698715 if (dwFlags & DDBLT_DEPTHFILL)
699716 {
700 - if (!(ddsd.ddpfPixelFormat.dwFlags & DDPF_ZBUFFER)) TRACE_RET(HRESULT, 23, DDERR_UNSUPPORTED);
701 - TRACE_RET(HRESULT, 23, glRenderer_DepthFill(ddInterface->renderer, lpDestRect, this, lpDDBltFx));
 717+ if (!(this->ddsd.ddpfPixelFormat.dwFlags & DDPF_ZBUFFER)) TRACE_RET(HRESULT, 23, DDERR_UNSUPPORTED);
 718+ if (this->attachparent)
 719+ {
 720+ TRACE_RET(HRESULT, 23, glRenderer_DepthFill(this->ddInterface->renderer, &cmd, this->attachparent->texture, this->attachparent->miplevel));
 721+ }
 722+ else
 723+ {
 724+ TRACE_RET(HRESULT, 23, glRenderer_DepthFill(this->ddInterface->renderer, &cmd, NULL, 0));
 725+ }
702726 }
703727 if (this == src)
704728 {
705729 tmprect.left = tmprect.top = 0;
706 - tmprect.right = lpSrcRect->right - lpSrcRect->left;
707 - tmprect.bottom = lpSrcRect->bottom - lpSrcRect->top;
708 - error = ddInterface->SetupTempSurface(tmprect.right, tmprect.bottom);
709 - if (error) TRACE_RET(HRESULT, 23, error);
710 - error = ddInterface->tmpsurface->Blt(&tmprect, lpDDSrcSurface, lpSrcRect, 0, NULL);
711 - if (error) TRACE_RET(HRESULT, 23, error);
712 - TRACE_RET(HRESULT,23,this->Blt(lpDestRect, ddInterface->tmpsurface, &tmprect, dwFlags, lpDDBltFx));
 730+ if (lpSrcRect)
 731+ {
 732+ tmprect.right = lpSrcRect->right - lpSrcRect->left;
 733+ tmprect.bottom = lpSrcRect->bottom - lpSrcRect->top;
 734+ }
 735+ else
 736+ {
 737+ tmprect.right = src->ddsd.dwWidth;
 738+ tmprect.bottom = src->ddsd.dwHeight;
 739+ }
 740+ error = this->ddInterface->SetupTempSurface(tmprect.right, tmprect.bottom);
 741+ if (FAILED(error)) TRACE_RET(HRESULT, 23, error);
 742+ error = this->ddInterface->tmpsurface->Blt(&tmprect, lpDDSrcSurface, lpSrcRect, 0, NULL);
 743+ if (FAILED(error)) TRACE_RET(HRESULT, 23, error);
 744+ TRACE_RET(HRESULT, 23, this->Blt(lpDestRect, (LPDIRECTDRAWSURFACE7)this->ddInterface->tmpsurface,
 745+ &tmprect, dwFlags, lpDDBltFx));
713746 }
714 - else TRACE_RET(HRESULT,23,glRenderer_Blt(ddInterface->renderer,lpDestRect,src,this,lpSrcRect,dwFlags,lpDDBltFx));
 747+ else TRACE_RET(HRESULT, 23, glRenderer_Blt(this->ddInterface->renderer, &cmd));
715748 }
716749 HRESULT WINAPI glDirectDrawSurface7::BltBatch(LPDDBLTBATCH lpDDBltBatch, DWORD dwCount, DWORD dwFlags)
717750 {
@@ -809,7 +842,7 @@
810843 swapinterval++;
811844 ddInterface->lastsync = false;
812845 }
813 - RenderScreen(texture,this,swapinterval);
 846+ RenderScreen(texture,swapinterval);
814847 }
815848 TRACE_EXIT(23,ret);
816849 return ret;
@@ -1045,7 +1078,7 @@
10461079 TRACE_ENTER(2,14,this,14,lphDC);
10471080 if(!this) TRACE_RET(HRESULT,23,DDERR_INVALIDOBJECT);
10481081 if(!lphDC) TRACE_RET(HRESULT,23,DDERR_INVALIDPARAMS);
1049 - glDirectDrawPalette *pal;
 1082+ glDirectDrawPalette *pal = NULL;
10501083 HRESULT error;
10511084 if (ddsd.ddpfPixelFormat.dwRGBBitCount == 8)
10521085 {
@@ -1155,10 +1188,10 @@
11561189 {
11571190 if (ddInterface->lastsync)
11581191 {
1159 - RenderScreen(texture, this, 1);
 1192+ RenderScreen(texture, 1);
11601193 ddInterface->lastsync = false;
11611194 }
1162 - else RenderScreen(texture, this, 0);
 1195+ else RenderScreen(texture, 0);
11631196 }
11641197 TRACE_EXIT(23,error);
11651198 return error;
@@ -1301,6 +1334,7 @@
13021335 ddsd.dwFlags |= DDSD_CKDESTOVERLAY;
13031336 colorkey[3] = key;
13041337 }
 1338+ glRenderer_SetTextureColorKey(this->ddInterface->renderer, this->texture, dwFlags, lpDDColorKey, this->miplevel);
13051339 TRACE_EXIT(23,DD_OK);
13061340 return DD_OK;
13071341 }
@@ -1357,10 +1391,10 @@
13581392 {
13591393 if(ddInterface->lastsync)
13601394 {
1361 - RenderScreen(texture,this,1);
 1395+ RenderScreen(texture,1);
13621396 ddInterface->lastsync = false;
13631397 }
1364 - else RenderScreen(texture,this,0);
 1398+ else RenderScreen(texture,0);
13651399 }
13661400 TRACE_EXIT(23, DD_OK);
13671401 return DD_OK;
@@ -1390,10 +1424,10 @@
13911425 ERR(DDERR_GENERIC);
13921426 }
13931427
1394 -void glDirectDrawSurface7::RenderScreen(glTexture *texture, glDirectDrawSurface7 *surface, int vsync)
 1428+void glDirectDrawSurface7::RenderScreen(glTexture *texture, int vsync)
13951429 {
1396 - TRACE_ENTER(3,14,this,14,texture,14,surface);
1397 - glRenderer_DrawScreen(ddInterface->renderer,texture, texture->palette, this, surface, vsync);
 1430+ TRACE_ENTER(3,14,this,14,texture,14,vsync);
 1431+ glRenderer_DrawScreen(ddInterface->renderer,texture, texture->palette, vsync);
13981432 TRACE_EXIT(0,0);
13991433 }
14001434 // ddraw 2+ api
Index: ddraw/glDirectDrawSurface.h
@@ -117,7 +117,7 @@
118118 void SetTexture(glTexture *newtexture){ texture = newtexture; };
119119 glDirectDrawSurface7 *GetBackbuffer(){return backbuffer;};
120120 glDirectDrawSurface7 *GetZBuffer(){return zbuffer;};
121 - void RenderScreen(glTexture *texture, glDirectDrawSurface7 *surface, int vsync);
 121+ void RenderScreen(glTexture *texture, int vsync);
122122 // Special ddraw2->ddraw7 api
123123 HRESULT WINAPI Unlock2(LPVOID lpSurfaceData);
124124 HRESULT GetHandle(glDirect3DDevice7 *glD3DDev7, LPD3DTEXTUREHANDLE lpHandle);
@@ -142,9 +142,6 @@
143143 glDirectDrawPalette *palette;
144144 HGLRC hRC;
145145 D3DMATERIALHANDLE handle;
146 - FBO fbo;
147 - FBO zfbo;
148 - FBO stencilfbo;
149146 glDirectDrawClipper *clipper;
150147 IUnknown *creator;
151148 IUnknown *textureparent;
Index: ddraw/glRenderer.cpp
@@ -343,51 +343,29 @@
344344 }
345345
346346 /**
347 - * Copies the contents of one surface to another.
 347+ * Copies part or all of the contents of one texture to another.
348348 * @param This
349349 * Pointer to glRenderer object
350 - * @param lpDestRect
351 - * Pointer to the coordinates to blit to. If NULL, blits to the entire surface.
352 - * @param src
353 - * Surface to be used as the source.
354 - * @param dest
355 - * Surface to blit to.
356 - * @param lpSrcRect
357 - * Pointer of the coordinates to blit from on the source surface. If NULL, the
358 - * entire surface will be used.
359 - * @param dwFlags
360 - * Flags to determine the behavior of the blitter. Certain flags control the
361 - * synchronization of the operation: (not yet implemented)
362 - * - DDBLT_ASYNC: Adds the command to the queue. If the queue is full, returns
363 - * DDERR_WASSTILLDRAWING.
364 - * - DDBLT_DONOTWAIT: Fails and returns DDERR_WASSTILLDRAWING if the queue is full.
365 - * - DDBLT_WAIT: Waits until the Blt command is processed before returning.
366 - * @param lpDDBltFx
367 - * Effect parameters for the Blt operation.
 350+ * @param cmd
 351+ * Pointer to structure contaning all paramaters for a Blt operation.
368352 * @return
369 - * DD_OK if the call succeeds, or DDERR_WASSTILLDRAWING if busy.
 353+ * DD_OK if the call succeeds, or DDERR_WASSTILLDRAWING if queue is full and not waiting.
370354 */
371 -HRESULT glRenderer_Blt(glRenderer *This, LPRECT lpDestRect, glDirectDrawSurface7 *src,
372 - glDirectDrawSurface7 *dest, LPRECT lpSrcRect, DWORD dwFlags, LPDDBLTFX lpDDBltFx)
 355+HRESULT glRenderer_Blt(glRenderer *This, BltCommand *cmd)
373356 {
374357 EnterCriticalSection(&This->cs);
375358 RECT r,r2;
376 - if(((dest->ddsd.ddsCaps.dwCaps & (DDSCAPS_FRONTBUFFER)) &&
377 - (dest->ddsd.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)) ||
378 - ((dest->ddsd.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE) &&
379 - !(dest->ddsd.ddsCaps.dwCaps & DDSCAPS_FLIP)))
 359+ if(((cmd->dest->levels[0].ddsd.ddsCaps.dwCaps & (DDSCAPS_FRONTBUFFER)) &&
 360+ (cmd->dest->levels[0].ddsd.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)) ||
 361+ ((cmd->dest->levels[0].ddsd.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE) &&
 362+ !(cmd->dest->levels[0].ddsd.ddsCaps.dwCaps & DDSCAPS_FLIP)))
380363 {
381364 GetClientRect(This->hWnd,&r);
382365 GetClientRect(This->RenderWnd->GetHWnd(),&r2);
383366 if(memcmp(&r2,&r,sizeof(RECT)) != 0)
384 - SetWindowPos(This->RenderWnd->GetHWnd(),NULL,0,0,r.right,r.bottom,SWP_SHOWWINDOW);
 367+ SetWindowPos(This->RenderWnd->GetHWnd(),NULL,0,0,r.right,r.bottom,SWP_SHOWWINDOW);
385368 }
386 - This->inputs[0] = lpDestRect;
387 - This->inputs[1] = src;
388 - This->inputs[2] = dest;
389 - This->inputs[3] = lpSrcRect;
390 - This->inputs[4] = (void*)dwFlags;
391 - This->inputs[5] = lpDDBltFx;
 369+ This->inputs[0] = cmd;
392370 This->opcode = OP_BLT;
393371 SetEvent(This->start);
394372 WaitForSingleObject(This->busy,INFINITE);
@@ -410,14 +388,12 @@
411389 * @param vsync
412390 * Vertical sync count
413391 */
414 -void glRenderer_DrawScreen(glRenderer *This, glTexture *texture, glTexture *paltex, glDirectDrawSurface7 *dest, glDirectDrawSurface7 *src, GLint vsync)
 392+void glRenderer_DrawScreen(glRenderer *This, glTexture *texture, glTexture *paltex, GLint vsync)
415393 {
416394 EnterCriticalSection(&This->cs);
417395 This->inputs[0] = texture;
418396 This->inputs[1] = paltex;
419 - This->inputs[2] = dest;
420 - This->inputs[3] = src;
421 - This->inputs[4] = (void*)vsync;
 397+ This->inputs[2] = (void*)vsync;
422398 This->opcode = OP_DRAWSCREEN;
423399 SetEvent(This->start);
424400 WaitForSingleObject(This->busy,INFINITE);
@@ -671,22 +647,25 @@
672648 }
673649
674650 /**
675 - * Fills a depth surface with a specified value.
676 - * @param This
677 - * Pointer to glRenderer object
678 - * @param lpDestRect
679 - * Pointer to bounding rectangle for depth fill. If NULL, then fill entire surface
680 - * @param dest
681 - * Destination surface to depth fill
682 - * @param lpDDBltFx
683 - * Pointer to DDBLTFX structure with dwFillDepth defining the depth value.
684 - */
685 -HRESULT glRenderer_DepthFill(glRenderer *This, LPRECT lpDestRect, glDirectDrawSurface7 *dest, LPDDBLTFX lpDDBltFx)
 651+* Fills a depth surface with a specified value.
 652+* @param This
 653+* Pointer to glRenderer object
 654+* @param cmd
 655+* Pointer to structure contaning all paramaters for a Blt operation, with
 656+* appropriate depth fill parameters filled in.
 657+* @param parent
 658+* Texture representing parent surface
 659+* @param parentlevel
 660+* Mipmap level of parent surface
 661+* @return
 662+* DD_OK if the depth fill succeeded.
 663+*/
 664+HRESULT glRenderer_DepthFill(glRenderer *This, BltCommand *cmd, glTexture *parent, GLint parentlevel)
686665 {
687666 EnterCriticalSection(&This->cs);
688 - This->inputs[0] = lpDestRect;
689 - This->inputs[1] = dest;
690 - This->inputs[2] = lpDDBltFx;
 667+ This->inputs[0] = cmd;
 668+ This->inputs[1] = parent;
 669+ This->inputs[2] = (void*)parentlevel;
691670 This->opcode = OP_DEPTHFILL;
692671 SetEvent(This->start);
693672 WaitForSingleObject(This->busy, INFINITE);
@@ -836,6 +815,32 @@
837816 }
838817
839818 /**
 819+* Sets a color key for a texture object.
 820+* @param This
 821+* Pointer to glRenderer object
 822+* @param texture
 823+* Texture to set color key on
 824+* @param dwFlags
 825+* DDraw color key flags to select color key to add or update
 826+* @param lpDDColorKey
 827+* Pointer to a DDraw color key structure to set in the texture
 828+* @param level
 829+* Mip level of color key to set for DirectDraw; Direct3D colorkey operations use level 0
 830+*/
 831+void glRenderer_SetTextureColorKey(glRenderer *This, glTexture *texture, DWORD dwFlags, LPDDCOLORKEY lpDDColorKey, GLint level)
 832+{
 833+ EnterCriticalSection(&This->cs);
 834+ This->inputs[0] = texture;
 835+ This->inputs[1] = (void*)dwFlags;
 836+ This->inputs[2] = lpDDColorKey;
 837+ This->inputs[3] = (void*)level;
 838+ This->opcode = OP_SETTEXTURECOLORKEY;
 839+ SetEvent(This->start);
 840+ WaitForSingleObject(This->busy, INFINITE);
 841+ LeaveCriticalSection(&This->cs);
 842+}
 843+
 844+/**
840845 * Generates a glFrameTerminatorGREMEDY command in OpenGL if the
841846 * glFrameTerminatorGREMEDY command is available (i.e. running under gDebugger).
842847 * @param This
@@ -931,12 +936,11 @@
932937 glRenderer__DeleteTexture(This,(glTexture*)This->inputs[0]);
933938 break;
934939 case OP_BLT:
935 - glRenderer__Blt(This,(LPRECT)This->inputs[0],(glDirectDrawSurface7*)This->inputs[1],
936 - (glDirectDrawSurface7*)This->inputs[2],(LPRECT)This->inputs[3],(DWORD)This->inputs[4],(LPDDBLTFX)This->inputs[5]);
 940+ glRenderer__Blt(This, (BltCommand*)This->inputs[0]);
937941 break;
938942 case OP_DRAWSCREEN:
939943 glRenderer__DrawScreen(This,(glTexture*)This->inputs[0],(glTexture*)This->inputs[1],
940 - (glDirectDrawSurface7*)This->inputs[2],(glDirectDrawSurface7*)This->inputs[3],(GLint)This->inputs[4],true);
 944+ (GLint)This->inputs[2],true);
941945 break;
942946 case OP_INITD3D:
943947 glRenderer__InitD3D(This,(int)This->inputs[0],(int)This->inputs[1],(int)This->inputs[2]);
@@ -961,8 +965,7 @@
962966 glRenderer__UpdateClipper(This,(glDirectDrawSurface7*)This->inputs[0]);
963967 break;
964968 case OP_DEPTHFILL:
965 - glRenderer__DepthFill(This, (LPRECT)This->inputs[0], (glDirectDrawSurface7*)This->inputs[1],
966 - (LPDDBLTFX)This->inputs[2]);
 969+ glRenderer__DepthFill(This, (BltCommand*)This->inputs[0], (glTexture*)This->inputs[1], (GLint)This->inputs[2]);
967970 break;
968971 case OP_SETRENDERSTATE:
969972 glRenderer__SetRenderState(This, (D3DRENDERSTATETYPE)(DWORD)This->inputs[0], (DWORD)This->inputs[1]);
@@ -986,6 +989,10 @@
987990 case OP_SETVIEWPORT:
988991 glRenderer__SetViewport(This, (LPD3DVIEWPORT7)This->inputs[0]);
989992 break;
 993+ case OP_SETTEXTURECOLORKEY:
 994+ glRenderer__SetTextureColorKey(This, (glTexture*)This->inputs[0], (DWORD)This->inputs[1],
 995+ (LPDDCOLORKEY)This->inputs[2], (GLint)This->inputs[3]);
 996+ break;
990997 case OP_DXGLBREAK:
991998 glRenderer__DXGLBreak(This);
992999 break;
@@ -1339,8 +1346,7 @@
13401347 }
13411348 }
13421349
1343 -void glRenderer__Blt(glRenderer *This, LPRECT lpDestRect, glDirectDrawSurface7 *src,
1344 - glDirectDrawSurface7 *dest, LPRECT lpSrcRect, DWORD dwFlags, LPDDBLTFX lpDDBltFx)
 1350+void glRenderer__Blt(glRenderer *This, BltCommand *cmd)
13451351 {
13461352 int rotates = 0;
13471353 BOOL usedest = FALSE;
@@ -1351,9 +1357,8 @@
13521358 This->ddInterface->GetSizes(sizes);
13531359 DWORD shaderid;
13541360 DDSURFACEDESC2 ddsd;
1355 - ddsd.dwSize = sizeof(DDSURFACEDESC2);
1356 - dest->GetSurfaceDesc(&ddsd);
1357 - if (!lpDestRect)
 1361+ ddsd = cmd->dest->levels[cmd->destlevel].ddsd;
 1362+ if (!memcmp(&cmd->destrect, &nullrect, sizeof(RECT)))
13581363 {
13591364 destrect.left = 0;
13601365 destrect.top = 0;
@@ -1360,19 +1365,19 @@
13611366 destrect.right = ddsd.dwWidth;
13621367 destrect.bottom = ddsd.dwHeight;
13631368 }
1364 - else destrect = *lpDestRect;
1365 - if ((lpDDBltFx) && (dwFlags & DDBLT_ROP))
 1369+ else destrect = cmd->destrect;
 1370+ if ((cmd->bltfx.dwSize == sizeof(DDBLTFX)) && (cmd->flags & DDBLT_ROP))
13661371 {
1367 - shaderid = PackROPBits(lpDDBltFx->dwROP, dwFlags);
1368 - if (rop_texture_usage[(lpDDBltFx->dwROP >> 16) & 0xFF] & 2) usedest = TRUE;
1369 - if (rop_texture_usage[(lpDDBltFx->dwROP >> 16) & 0xFF] & 4) usepattern = TRUE;
 1372+ shaderid = PackROPBits(cmd->bltfx.dwROP, cmd->flags);
 1373+ if (rop_texture_usage[(cmd->bltfx.dwROP >> 16) & 0xFF] & 2) usedest = TRUE;
 1374+ if (rop_texture_usage[(cmd->bltfx.dwROP >> 16) & 0xFF] & 4) usepattern = TRUE;
13701375 }
1371 - else shaderid = dwFlags & 0xF2FAADFF;
1372 - if (dwFlags & DDBLT_KEYDEST) usedest = TRUE;
 1376+ else shaderid = cmd->flags & 0xF2FAADFF;
 1377+ if (cmd->flags & DDBLT_KEYDEST) usedest = TRUE;
13731378 if (usedest)
13741379 {
13751380 ShaderManager_SetShader(This->shaders, PROG_TEXTURE, NULL, 0);
1376 - glRenderer__DrawBackbufferRect(This, dest->texture, destrect, PROG_TEXTURE);
 1381+ glRenderer__DrawBackbufferRect(This, cmd->dest, destrect, PROG_TEXTURE);
13771382 This->bltvertices[1].dests = This->bltvertices[3].dests = 0.;
13781383 This->bltvertices[0].dests = This->bltvertices[2].dests = (GLfloat)(destrect.right - destrect.left) / (GLfloat)This->backx;
13791384 This->bltvertices[0].destt = This->bltvertices[1].destt = 1.;
@@ -1383,23 +1388,25 @@
13841389 glUtil_BlendEnable(This->util, FALSE);
13851390 do
13861391 {
1387 - if (glUtil_SetFBOSurface(This->util, dest) == GL_FRAMEBUFFER_COMPLETE) break;
1388 - if (!dest->texture->internalformats[1]) break;
1389 - glTexture__Repair(dest->texture, TRUE);
 1392+ if (glUtil_SetFBOSurface(This->util, cmd->dest, NULL, cmd->destlevel, 0, TRUE) == GL_FRAMEBUFFER_COMPLETE) break;
 1393+ if (!cmd->dest->internalformats[1]) break;
 1394+ glTexture__Repair(cmd->dest, TRUE);
13901395 glUtil_SetFBO(This->util, NULL);
1391 - dest->fbo.fbcolor = NULL;
1392 - dest->fbo.fbz = NULL;
 1396+ cmd->dest->levels[cmd->destlevel].fbo.fbcolor = NULL;
 1397+ cmd->dest->levels[cmd->destlevel].fbo.fbz = NULL;
13931398 } while (1);
1394 - glUtil_SetViewport(This->util,0,0,dest->fakex,dest->fakey);
 1399+ glUtil_SetViewport(This->util,0,0,cmd->dest->bigwidth,cmd->dest->bigheight);
13951400 glUtil_DepthTest(This->util, FALSE);
13961401 DDSURFACEDESC2 ddsdSrc;
13971402 ddsdSrc.dwSize = sizeof(DDSURFACEDESC2);
1398 - if (src)
 1403+ if (cmd->src)
13991404 {
1400 - src->GetSurfaceDesc(&ddsdSrc);
1401 - if (src->texture->levels[src->miplevel].dirty & 1) glTexture__Upload(src->texture, src->miplevel);
 1405+ ddsdSrc = cmd->src->levels[cmd->srclevel].ddsd;
 1406+ if (cmd->src->levels[cmd->srclevel].dirty & 1) glTexture__Upload(cmd->src, cmd->srclevel);
14021407 }
1403 - if(!lpSrcRect)
 1408+ if (cmd->dest->levels[cmd->destlevel].dirty & 1)
 1409+ glTexture__Upload(cmd->dest, cmd->destlevel);
 1410+ if (!memcmp(&cmd->srcrect, &nullrect, sizeof(RECT)))
14041411 {
14051412 srcrect.left = 0;
14061413 srcrect.top = 0;
@@ -1406,25 +1413,38 @@
14071414 srcrect.right = ddsdSrc.dwWidth;
14081415 srcrect.bottom = ddsdSrc.dwHeight;
14091416 }
1410 - else srcrect = *lpSrcRect;
1411 - if (dest->texture->levels[dest->miplevel].dirty & 1) glTexture__Upload(dest->texture, dest->miplevel);
1412 - This->bltvertices[1].x = This->bltvertices[3].x = (GLfloat)destrect.left * ((GLfloat)dest->fakex/(GLfloat)ddsd.dwWidth);
1413 - This->bltvertices[0].x = This->bltvertices[2].x = (GLfloat)destrect.right * ((GLfloat)dest->fakex/(GLfloat)ddsd.dwWidth);
1414 - This->bltvertices[0].y = This->bltvertices[1].y = (GLfloat)dest->fakey-((GLfloat)destrect.top * ((GLfloat)dest->fakey/(GLfloat)ddsd.dwHeight));
1415 - This->bltvertices[2].y = This->bltvertices[3].y = (GLfloat)dest->fakey-((GLfloat)destrect.bottom * ((GLfloat)dest->fakey/(GLfloat)ddsd.dwHeight));
 1417+ else srcrect = cmd->srcrect;
 1418+ if (cmd->destlevel == 0)
 1419+ {
 1420+ This->bltvertices[1].x = This->bltvertices[3].x =
 1421+ (GLfloat)destrect.left * ((GLfloat)cmd->dest->bigwidth / (GLfloat)ddsd.dwWidth);
 1422+ This->bltvertices[0].x = This->bltvertices[2].x =
 1423+ (GLfloat)destrect.right * ((GLfloat)cmd->dest->bigwidth / (GLfloat)ddsd.dwWidth);
 1424+ This->bltvertices[0].y = This->bltvertices[1].y =
 1425+ (GLfloat)cmd->dest->bigheight - ((GLfloat)destrect.top * ((GLfloat)cmd->dest->bigheight / (GLfloat)ddsd.dwHeight));
 1426+ This->bltvertices[2].y = This->bltvertices[3].y =
 1427+ (GLfloat)cmd->dest->bigheight - ((GLfloat)destrect.bottom * ((GLfloat)cmd->dest->bigheight / (GLfloat)ddsd.dwHeight));
 1428+ }
 1429+ else
 1430+ {
 1431+ This->bltvertices[1].x = This->bltvertices[3].x = (GLfloat)destrect.left;
 1432+ This->bltvertices[0].x = This->bltvertices[2].x = (GLfloat)destrect.right;
 1433+ This->bltvertices[0].y = This->bltvertices[1].y = (GLfloat)ddsd.dwHeight - (GLfloat)destrect.top;
 1434+ This->bltvertices[2].y = This->bltvertices[3].y = (GLfloat)ddsd.dwHeight - (GLfloat)destrect.bottom;
 1435+ }
14161436 This->bltvertices[1].s = This->bltvertices[3].s = (GLfloat)srcrect.left / (GLfloat)ddsdSrc.dwWidth;
14171437 This->bltvertices[0].s = This->bltvertices[2].s = (GLfloat)srcrect.right / (GLfloat)ddsdSrc.dwWidth;
14181438 This->bltvertices[0].t = This->bltvertices[1].t = (GLfloat)srcrect.top / (GLfloat)ddsdSrc.dwHeight;
14191439 This->bltvertices[2].t = This->bltvertices[3].t = (GLfloat)srcrect.bottom / (GLfloat)ddsdSrc.dwHeight;
1420 - if ((lpDDBltFx) && (dwFlags & DDBLT_DDFX))
 1440+ if ((cmd->bltfx.dwSize == sizeof(DDBLTFX)) && (cmd->flags & DDBLT_DDFX))
14211441 {
1422 - if (lpDDBltFx->dwDDFX & DDBLTFX_MIRRORLEFTRIGHT)
 1442+ if (cmd->bltfx.dwDDFX & DDBLTFX_MIRRORLEFTRIGHT)
14231443 BltFlipLR(This->bltvertices);
1424 - if (lpDDBltFx->dwDDFX & DDBLTFX_MIRRORUPDOWN)
 1444+ if (cmd->bltfx.dwDDFX & DDBLTFX_MIRRORUPDOWN)
14251445 BltFlipUD(This->bltvertices);
1426 - if (lpDDBltFx->dwDDFX & DDBLTFX_ROTATE90) rotates++;
1427 - if (lpDDBltFx->dwDDFX & DDBLTFX_ROTATE180) rotates += 2;
1428 - if (lpDDBltFx->dwDDFX & DDBLTFX_ROTATE270) rotates += 3;
 1446+ if (cmd->bltfx.dwDDFX & DDBLTFX_ROTATE90) rotates++;
 1447+ if (cmd->bltfx.dwDDFX & DDBLTFX_ROTATE180) rotates += 2;
 1448+ if (cmd->bltfx.dwDDFX & DDBLTFX_ROTATE270) rotates += 3;
14291449 rotates &= 3;
14301450 if (rotates)
14311451 {
@@ -1431,30 +1451,30 @@
14321452 RotateBlt90(This->bltvertices, rotates);
14331453 }
14341454 }
1435 - if (dwFlags & 0x10000000)
1436 - {
1437 - This->bltvertices[1].stencils = This->bltvertices[3].stencils = This->bltvertices[1].x / (GLfloat)dest->fakex;
1438 - This->bltvertices[0].stencils = This->bltvertices[2].stencils = This->bltvertices[0].x / (GLfloat)dest->fakex;
1439 - This->bltvertices[0].stencilt = This->bltvertices[1].stencilt = This->bltvertices[0].y / (GLfloat)dest->fakey;
1440 - This->bltvertices[2].stencilt = This->bltvertices[3].stencilt = This->bltvertices[2].y / (GLfloat)dest->fakey;
 1455+ if (cmd->flags & 0x10000000)
 1456+ {
 1457+ This->bltvertices[1].stencils = This->bltvertices[3].stencils = This->bltvertices[1].x / (GLfloat)cmd->dest->levels[cmd->destlevel].ddsd.dwWidth;
 1458+ This->bltvertices[0].stencils = This->bltvertices[2].stencils = This->bltvertices[0].x / (GLfloat)cmd->dest->levels[cmd->destlevel].ddsd.dwWidth;
 1459+ This->bltvertices[0].stencilt = This->bltvertices[1].stencilt = This->bltvertices[0].y / (GLfloat)cmd->dest->levels[cmd->destlevel].ddsd.dwHeight;
 1460+ This->bltvertices[2].stencilt = This->bltvertices[3].stencilt = This->bltvertices[2].y / (GLfloat)cmd->dest->levels[cmd->destlevel].ddsd.dwHeight;
14411461 }
1442 - if(dest->zbuffer) glClear(GL_DEPTH_BUFFER_BIT);
1443 - if (dwFlags & DDBLT_COLORFILL) SetColorFillUniform(lpDDBltFx->dwFillColor, dest->texture->colorsizes,
1444 - dest->texture->colororder, dest->texture->colorbits, shader->shader.uniforms[12], This->ext);
1445 - if ((dwFlags & DDBLT_KEYSRC) && (src && src->colorkey[0].enabled) && !(dwFlags & DDBLT_COLORFILL))
 1462+ if (cmd->dest->levels[cmd->destlevel].fbo.fbz) glClear(GL_DEPTH_BUFFER_BIT);
 1463+ if (cmd->flags & DDBLT_COLORFILL) SetColorFillUniform(cmd->bltfx.dwFillColor, cmd->dest->colorsizes,
 1464+ cmd->dest->colororder, cmd->dest->colorbits, shader->shader.uniforms[12], This->ext);
 1465+ if ((cmd->flags & DDBLT_KEYSRC) && (cmd->src && (cmd->src->levels[cmd->srclevel].ddsd.dwFlags & DDSD_CKSRCBLT)) && !(cmd->flags & DDBLT_COLORFILL))
14461466 {
1447 - SetColorKeyUniform(src->colorkey[0].key.dwColorSpaceLowValue, src->texture->colorsizes,
1448 - src->texture->colororder, shader->shader.uniforms[5], src->texture->colorbits, This->ext);
1449 - if (dwFlags & 0x20000000) SetColorKeyUniform(src->colorkey[0].key.dwColorSpaceHighValue, src->texture->colorsizes,
1450 - src->texture->colororder, shader->shader.uniforms[7], src->texture->colorbits, This->ext);
 1467+ SetColorKeyUniform(cmd->src->levels[cmd->srclevel].ddsd.ddckCKSrcBlt.dwColorSpaceLowValue, cmd->src->colorsizes,
 1468+ cmd->src->colororder, shader->shader.uniforms[5], cmd->src->colorbits, This->ext);
 1469+ if (cmd->flags & 0x20000000) SetColorKeyUniform(cmd->src->levels[cmd->srclevel].ddsd.ddckCKSrcBlt.dwColorSpaceHighValue, cmd->src->colorsizes,
 1470+ cmd->src->colororder, shader->shader.uniforms[7], cmd->src->colorbits, This->ext);
14511471 }
1452 - if (!(dwFlags & DDBLT_COLORFILL)) This->ext->glUniform1i(shader->shader.uniforms[1], 0);
1453 - if ((dwFlags & DDBLT_KEYDEST) && (This && dest->colorkey[1].enabled))
 1472+ if (!(cmd->flags & DDBLT_COLORFILL)) This->ext->glUniform1i(shader->shader.uniforms[1], 0);
 1473+ if ((cmd->flags & DDBLT_KEYDEST) && (This && (cmd->dest->levels[cmd->destlevel].ddsd.dwFlags & DDSD_CKDESTBLT)))
14541474 {
1455 - SetColorKeyUniform(dest->colorkey[1].key.dwColorSpaceLowValue, dest->texture->colorsizes,
1456 - dest->texture->colororder, shader->shader.uniforms[6], dest->texture->colorbits, This->ext);
1457 - if(dwFlags & 0x40000000) SetColorKeyUniform(dest->colorkey[1].key.dwColorSpaceHighValue, dest->texture->colorsizes,
1458 - dest->texture->colororder, shader->shader.uniforms[8], dest->texture->colorbits, This->ext);
 1475+ SetColorKeyUniform(cmd->dest->levels[cmd->destlevel].ddsd.ddckCKDestBlt.dwColorSpaceLowValue, cmd->dest->colorsizes,
 1476+ cmd->dest->colororder, shader->shader.uniforms[6], cmd->dest->colorbits, This->ext);
 1477+ if (cmd->flags & 0x40000000) SetColorKeyUniform(cmd->dest->levels[cmd->destlevel].ddsd.ddckCKDestBlt.dwColorSpaceHighValue, cmd->dest->colorsizes,
 1478+ cmd->dest->colororder, shader->shader.uniforms[8], cmd->dest->colorbits, This->ext);
14591479 }
14601480 if (usedest && (shader->shader.uniforms[2] != -1))
14611481 {
@@ -1463,40 +1483,40 @@
14641484 }
14651485 if (usepattern && (shader->shader.uniforms[3] != -1))
14661486 {
1467 - glDirectDrawSurface7 *pattern = (glDirectDrawSurface7*)lpDDBltFx->lpDDSPattern;
1468 - if (pattern->texture->levels[0].dirty & 1) glTexture__Upload(pattern->texture, 0);
1469 - glUtil_SetTexture(This->util, 2, pattern->texture);
 1487+ if (cmd->pattern->levels[cmd->patternlevel].dirty & 1) glTexture__Upload(cmd->pattern, cmd->patternlevel);
 1488+ glUtil_SetTexture(This->util, 2, cmd->pattern);
14701489 This->ext->glUniform1i(shader->shader.uniforms[3], 2);
14711490 This->ext->glUniform2i(shader->shader.uniforms[9],
1472 - pattern->texture->levels[0].ddsd.dwWidth, pattern->texture->levels[0].ddsd.dwHeight);
 1491+ cmd->pattern->levels[cmd->patternlevel].ddsd.dwWidth, cmd->pattern->levels[cmd->patternlevel].ddsd.dwHeight);
14731492 }
1474 - if (dwFlags & 0x10000000) // Use clipper
 1493+ if (cmd->flags & 0x10000000) // Use clipper
14751494 {
1476 - glUtil_SetTexture(This->util, 3, dest->texture->stencil);
 1495+ glUtil_SetTexture(This->util, 3, cmd->dest->stencil);
14771496 This->ext->glUniform1i(shader->shader.uniforms[4],3);
14781497 glUtil_EnableArray(This->util, shader->shader.attribs[5], TRUE);
14791498 This->ext->glVertexAttribPointer(shader->shader.attribs[5], 2, GL_FLOAT, GL_FALSE, sizeof(BltVertex), &This->bltvertices[0].stencils);
14801499 }
1481 - if(src)
 1500+ if (cmd->src)
14821501 {
1483 - glUtil_SetTexture(This->util,0,src->texture);
 1502+ glUtil_SetTexture(This->util, 0, cmd->src);
14841503 if(This->ext->GLEXT_ARB_sampler_objects)
14851504 {
1486 - if((dxglcfg.scalingfilter == 0) || (This->ddInterface->GetBPP() == 8))
1487 - glTexture__SetFilter(src->texture, 0, GL_NEAREST, GL_NEAREST, This);
1488 - else glTexture__SetFilter(src->texture, 0, GL_LINEAR, GL_LINEAR, This);
 1505+ if((dxglcfg.scalingfilter == 0) || (This->ddInterface->GetBPP() == 8))\
 1506+ glTexture__SetFilter(cmd->src, 0, GL_NEAREST, GL_NEAREST, This);
 1507+ else glTexture__SetFilter(cmd->src, 0, GL_LINEAR, GL_LINEAR, This);
14891508 }
14901509 }
14911510 else glUtil_SetTexture(This->util,0,NULL);
1492 - This->ext->glUniform4f(shader->shader.uniforms[0],0,(GLfloat)dest->fakex,0,(GLfloat)dest->fakey);
1493 - if(src) This->ext->glUniform4i(shader->shader.uniforms[10], src->texture->colorsizes[0], src->texture->colorsizes[1],
1494 - src->texture->colorsizes[2], src->texture->colorsizes[3]);
1495 - if(dest) This->ext->glUniform4i(shader->shader.uniforms[11], dest->texture->colorsizes[0], dest->texture->colorsizes[1],
1496 - dest->texture->colorsizes[2], dest->texture->colorsizes[3]);
1497 - dest->texture->levels[dest->miplevel].dirty |= 2;
 1511+ This->ext->glUniform4f(shader->shader.uniforms[0], 0,
 1512+ (GLfloat)cmd->dest->levels[cmd->destlevel].ddsd.dwWidth, 0, (GLfloat)cmd->dest->levels[cmd->destlevel].ddsd.dwHeight);
 1513+ if (cmd->src) This->ext->glUniform4i(shader->shader.uniforms[10], cmd->src->colorsizes[0], cmd->src->colorsizes[1],
 1514+ cmd->src->colorsizes[2], cmd->src->colorsizes[3]);
 1515+ if (cmd->dest) This->ext->glUniform4i(shader->shader.uniforms[11], cmd->dest->colorsizes[0], cmd->dest->colorsizes[1],
 1516+ cmd->dest->colorsizes[2], cmd->dest->colorsizes[3]);
 1517+ cmd->dest->levels[cmd->destlevel].dirty |= 2;
14981518 glUtil_EnableArray(This->util, shader->shader.attribs[0], TRUE);
14991519 This->ext->glVertexAttribPointer(shader->shader.attribs[0],2,GL_FLOAT,GL_FALSE,sizeof(BltVertex),&This->bltvertices[0].x);
1500 - if((!(dwFlags & DDBLT_COLORFILL)) && (shader->shader.attribs[3] != -1))
 1520+ if((!(cmd->flags & DDBLT_COLORFILL)) && (shader->shader.attribs[3] != -1))
15011521 {
15021522 glUtil_EnableArray(This->util, shader->shader.attribs[3], TRUE);
15031523 This->ext->glVertexAttribPointer(shader->shader.attribs[3],2,GL_FLOAT,GL_FALSE,sizeof(BltVertex),&This->bltvertices[0].s);
@@ -1514,7 +1534,7 @@
15151535 (ddsd.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)) ||
15161536 ((ddsd.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE) &&
15171537 !(ddsd.ddsCaps.dwCaps & DDSCAPS_FLIP)))
1518 - glRenderer__DrawScreen(This,dest->texture,dest->texture->palette,dest,dest,0,false);
 1538+ glRenderer__DrawScreen(This,cmd->dest,cmd->dest->palette,0,false);
15191539 This->outputs[0] = DD_OK;
15201540 SetEvent(This->busy);
15211541 }
@@ -1536,7 +1556,7 @@
15371557 ddsd.dwWidth = x;
15381558 ddsd.lPitch = x * 4;
15391559 ddsd.dwHeight = y;
1540 - glTexture_Create(&ddsd, &This->backbuffer, This, x, y, TRUE);
 1560+ glTexture_Create(&ddsd, &This->backbuffer, This, x, y, FALSE, TRUE);
15411561 This->backx = x;
15421562 This->backy = y;
15431563 }
@@ -1551,7 +1571,7 @@
15521572 This->backx = x;
15531573 This->backy = y;
15541574 }
1555 - glUtil_SetFBOTextures(This->util,&This->fbo,This->backbuffer,0,FALSE);
 1575+ glUtil_SetFBOTextures(This->util,&This->fbo,This->backbuffer,NULL,0,0,FALSE);
15561576 view[0] = view[2] = 0;
15571577 view[1] = (GLfloat)x;
15581578 view[3] = (GLfloat)y;
@@ -1590,7 +1610,7 @@
15911611 ddsd.dwWidth = x;
15921612 ddsd.lPitch = x * 4;
15931613 ddsd.dwHeight = y;
1594 - glTexture_Create(&ddsd, &This->backbuffer, This, x, y, TRUE);
 1614+ glTexture_Create(&ddsd, &This->backbuffer, This, x, y, FALSE, TRUE);
15951615 }
15961616 if ((This->backx < x) || (This->backy < y))
15971617 {
@@ -1605,7 +1625,7 @@
16061626 This->backx = x;
16071627 This->backy = y;
16081628 }
1609 - glUtil_SetFBOTextures(This->util, &This->fbo, This->backbuffer, 0, FALSE);
 1629+ glUtil_SetFBOTextures(This->util, &This->fbo, This->backbuffer, NULL, 0, 0, FALSE);
16101630 view[0] = view[2] = 0;
16111631 view[1] = (GLfloat)This->backx;
16121632 view[3] = (GLfloat)This->backy;
@@ -1633,12 +1653,12 @@
16341654 glUtil_SetFBO(This->util, NULL);
16351655 }
16361656
1637 -void glRenderer__DrawScreen(glRenderer *This, glTexture *texture, glTexture *paltex, glDirectDrawSurface7 *dest, glDirectDrawSurface7 *src, GLint vsync, BOOL setsync)
 1657+void glRenderer__DrawScreen(glRenderer *This, glTexture *texture, glTexture *paltex, GLint vsync, BOOL setsync)
16381658 {
16391659 int progtype;
16401660 RECT r,r2;
16411661 glUtil_BlendEnable(This->util, FALSE);
1642 - if((dest->ddsd.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE))
 1662+ if((texture->levels[0].ddsd.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE))
16431663 {
16441664 GetClientRect(This->hWnd,&r);
16451665 GetClientRect(This->RenderWnd->GetHWnd(),&r2);
@@ -1651,9 +1671,8 @@
16521672 LONG sizes[6];
16531673 GLfloat view[4];
16541674 GLint viewport[4];
1655 - if(src->texture->levels[src->miplevel].dirty & 1)
1656 - glTexture__Upload(src->texture, src->miplevel);
1657 - if(dest->ddsd.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)
 1675+ if(texture->levels[0].dirty & 1) glTexture__Upload(texture, 0);
 1676+ if(texture->levels[0].ddsd.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)
16581677 {
16591678 if(This->ddInterface->GetFullscreen())
16601679 {
@@ -1675,16 +1694,16 @@
16761695 ClientToScreen(This->RenderWnd->GetHWnd(),(LPPOINT)&viewrect->right);
16771696 view[0] = (GLfloat)viewrect->left;
16781697 view[1] = (GLfloat)viewrect->right;
1679 - view[2] = (GLfloat)dest->fakey-(GLfloat)viewrect->top;
1680 - view[3] = (GLfloat)dest->fakey-(GLfloat)viewrect->bottom;
 1698+ view[2] = (GLfloat)texture->bigheight-(GLfloat)viewrect->top;
 1699+ view[3] = (GLfloat)texture->bigheight-(GLfloat)viewrect->bottom;
16811700 }
16821701 }
16831702 else
16841703 {
16851704 view[0] = 0;
1686 - view[1] = (GLfloat)dest->fakex;
 1705+ view[1] = (GLfloat)texture->bigwidth;
16871706 view[2] = 0;
1688 - view[3] = (GLfloat)dest->fakey;
 1707+ view[3] = (GLfloat)texture->bigheight;
16891708 }
16901709 glUtil_SetFBO(This->util, NULL);
16911710 glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
@@ -1699,7 +1718,7 @@
17001719 glUtil_SetTexture(This->util,1,paltex);
17011720 if(dxglcfg.scalingfilter)
17021721 {
1703 - glRenderer__DrawBackbuffer(This,&texture,dest->fakex,dest->fakey,progtype);
 1722+ glRenderer__DrawBackbuffer(This,&texture,texture->bigwidth,texture->bigheight,progtype);
17041723 ShaderManager_SetShader(This->shaders,PROG_TEXTURE,NULL,0);
17051724 progtype = PROG_TEXTURE;
17061725 glUtil_SetTexture(This->util,0,texture);
@@ -1732,9 +1751,9 @@
17331752 }
17341753 else
17351754 {
1736 - This->bltvertices[0].x = This->bltvertices[2].x = (float)dest->fakex;
 1755+ This->bltvertices[0].x = This->bltvertices[2].x = (float)texture->bigwidth;
17371756 This->bltvertices[0].y = This->bltvertices[1].y = This->bltvertices[1].x = This->bltvertices[3].x = 0.;
1738 - This->bltvertices[2].y = This->bltvertices[3].y = (float)dest->fakey;
 1757+ This->bltvertices[2].y = This->bltvertices[3].y = (float)texture->bigheight;
17391758 }
17401759 This->bltvertices[0].s = This->bltvertices[0].t = This->bltvertices[1].t = This->bltvertices[2].s = 1.;
17411760 This->bltvertices[1].s = This->bltvertices[2].t = This->bltvertices[3].s = This->bltvertices[3].t = 0.;
@@ -1918,15 +1937,23 @@
19191938 {
19201939 This->outputs[0] = (void*)D3D_OK;
19211940 GLfloat color[4];
 1941+ glTexture *ztexture = NULL;
 1942+ GLint zlevel = 0;
 1943+ if (target->zbuffer)
 1944+ {
 1945+ ztexture = target->zbuffer->texture;
 1946+ zlevel = target->zbuffer->miplevel;
 1947+ }
19221948 dwordto4float(dwColor,color);
19231949 do
19241950 {
1925 - if (glUtil_SetFBOSurface(This->util, target) == GL_FRAMEBUFFER_COMPLETE) break;
 1951+ if (glUtil_SetFBOSurface(This->util, target->texture, ztexture,
 1952+ target->zbuffer->miplevel, zlevel, FALSE) == GL_FRAMEBUFFER_COMPLETE) break;
19261953 if (!target->texture->internalformats[1]) break;
19271954 glTexture__Repair(target->texture, TRUE);
19281955 glUtil_SetFBO(This->util, NULL);
1929 - target->fbo.fbcolor = NULL;
1930 - target->fbo.fbz = NULL;
 1956+ target->texture->levels[target->miplevel].fbo.fbcolor = NULL;
 1957+ target->texture->levels[target->miplevel].fbo.fbz = NULL;
19311958 } while (1);
19321959 int clearbits = 0;
19331960 if(dwFlags & D3DCLEAR_TARGET)
@@ -2119,6 +2146,13 @@
21202147 char strvar[] = "strX";
21212148 char strqvar[] = "strqX";
21222149 int i;
 2150+ glTexture *ztexture = NULL;
 2151+ GLint zlevel = 0;
 2152+ if (device->glDDS7->zbuffer)
 2153+ {
 2154+ ztexture = device->glDDS7->zbuffer->texture;
 2155+ zlevel = device->glDDS7->zbuffer->miplevel;
 2156+ }
21232157 if(vertices[1].data) transformed = true;
21242158 else transformed = false;
21252159 if(!vertices[0].data)
@@ -2321,12 +2355,13 @@
23222356 if(prog->uniforms[150]!= -1) This->ext->glUniform4iv(prog->uniforms[150],1,(GLint*)device->glDDS7->texture->colorbits);
23232357 do
23242358 {
2325 - if (glUtil_SetFBOSurface(This->util, device->glDDS7) == GL_FRAMEBUFFER_COMPLETE) break;
 2359+ if (glUtil_SetFBOSurface(This->util, device->glDDS7->texture, ztexture,
 2360+ device->glDDS7->miplevel, zlevel, FALSE) == GL_FRAMEBUFFER_COMPLETE) break;
23262361 if (!device->glDDS7->texture->internalformats[1]) break;
23272362 glTexture__Repair(device->glDDS7->texture, TRUE);
23282363 glUtil_SetFBO(This->util, NULL);
2329 - device->glDDS7->fbo.fbcolor = NULL;
2330 - device->glDDS7->fbo.fbz = NULL;
 2364+ device->glDDS7->texture->levels[device->glDDS7->miplevel].fbo.fbcolor = NULL;
 2365+ device->glDDS7->texture->levels[device->glDDS7->miplevel].fbo.fbz = NULL;
23312366 } while (1);
23322367 glUtil_SetViewport(This->util, (int)((float)This->viewport.dwX*device->glDDS7->mulx),
23332368 (int)((float)This->viewport.dwY*device->glDDS7->muly),
@@ -2373,7 +2408,7 @@
23742409 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT;
23752410 glTexture__SetSurfaceDesc(surface->texture->stencil, &ddsd);
23762411 }
2377 - glUtil_SetFBOTextures(This->util, &surface->stencilfbo, surface->texture->stencil, 0, FALSE);
 2412+ glUtil_SetFBOTextures(This->util, &surface->texture->stencil->levels[0].fbo, surface->texture->stencil, NULL, 0, 0, FALSE);
23782413 view[0] = view[2] = 0;
23792414 view[1] = (GLfloat)surface->ddsd.dwWidth;
23802415 view[3] = (GLfloat)surface->ddsd.dwHeight;
@@ -2392,14 +2427,14 @@
23932428 SetEvent(This->busy);
23942429 }
23952430
2396 -void glRenderer__DepthFill(glRenderer *This, LPRECT lpDestRect, glDirectDrawSurface7 *dest, LPDDBLTFX lpDDBltFx)
 2431+void glRenderer__DepthFill(glRenderer *This, BltCommand *cmd, glTexture *parent, GLint parentlevel)
23972432 {
23982433 RECT destrect;
23992434 DDSURFACEDESC2 ddsd;
2400 - DDSURFACEDESC2 ddsd2;
2401 - ddsd.dwSize = sizeof(DDSURFACEDESC2);
2402 - dest->GetSurfaceDesc(&ddsd);
2403 - if (!lpDestRect)
 2435+ DDSURFACEDESC2 tmpddsd;
 2436+ BOOL usedestrect = FALSE;
 2437+ ddsd = cmd->dest->levels[cmd->destlevel].ddsd;
 2438+ if (!memcmp(&cmd->destrect, &nullrect, sizeof(RECT)))
24042439 {
24052440 destrect.left = 0;
24062441 destrect.top = 0;
@@ -2406,44 +2441,50 @@
24072442 destrect.right = ddsd.dwWidth;
24082443 destrect.bottom = ddsd.dwHeight;
24092444 }
2410 - else destrect = *lpDestRect;
2411 - if (dest->attachparent)
 2445+ else
24122446 {
 2447+ destrect = cmd->destrect;
 2448+ usedestrect = TRUE;
 2449+ }
 2450+ if (parent)
 2451+ {
24132452 do
24142453 {
2415 - if (glUtil_SetFBOSurface(This->util, dest->attachparent) == GL_FRAMEBUFFER_COMPLETE) break;
2416 - if (!dest->attachparent->texture->internalformats[1]) break;
2417 - glTexture__Repair(dest->attachparent->texture, TRUE);
 2454+ if (glUtil_SetFBOSurface(This->util, parent, NULL, parentlevel, 0, TRUE) == GL_FRAMEBUFFER_COMPLETE) break;
 2455+ if (!parent->internalformats[1]) break;
 2456+ glTexture__Repair(parent, TRUE);
24182457 glUtil_SetFBO(This->util, NULL);
2419 - dest->attachparent->fbo.fbcolor = NULL;
2420 - dest->attachparent->fbo.fbz = NULL;
 2458+ parent->levels[parentlevel].fbo.fbcolor = NULL;
 2459+ parent->levels[parentlevel].fbo.fbz = NULL;
24212460 } while (1);
24222461 }
24232462 else
24242463 {
2425 - if (!dest->texture->dummycolor)
 2464+ if (!cmd->dest->dummycolor)
24262465 {
2427 - glTexture_CreateDummyColor(dest->texture, TRUE);
 2466+ glTexture_CreateDummyColor(cmd->dest, TRUE);
24282467 }
2429 - if ((dest->ddsd.dwWidth != dest->texture->dummycolor->levels[0].ddsd.dwWidth) ||
2430 - (dest->ddsd.dwHeight != dest->texture->dummycolor->levels[0].ddsd.dwHeight))
 2468+ if ((cmd->dest->levels[cmd->destlevel].ddsd.dwWidth != cmd->dest->dummycolor->levels[0].ddsd.dwWidth) ||
 2469+ (cmd->dest->levels[cmd->destlevel].ddsd.dwHeight != cmd->dest->dummycolor->levels[0].ddsd.dwHeight))
24312470 {
2432 - ZeroMemory(&ddsd2, sizeof(DDSURFACEDESC2));
2433 - ddsd2.dwSize = sizeof(DDSURFACEDESC2);
2434 - ddsd2.dwWidth = dest->ddsd.dwWidth;
2435 - ddsd2.dwHeight = dest->ddsd.dwHeight;
2436 - ddsd2.dwFlags = DDSD_WIDTH | DDSD_HEIGHT;
2437 - glTexture__SetSurfaceDesc(dest->texture->dummycolor, &ddsd2);
 2471+ ZeroMemory(&tmpddsd, sizeof(DDSURFACEDESC2));
 2472+ tmpddsd.dwSize = sizeof(DDSURFACEDESC2);
 2473+ tmpddsd.dwWidth = cmd->dest->levels[cmd->destlevel].ddsd.dwWidth;
 2474+ tmpddsd.dwHeight = cmd->dest->levels[cmd->destlevel].ddsd.dwHeight;
 2475+ tmpddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT;
 2476+ glTexture__SetSurfaceDesc(cmd->dest->dummycolor, &tmpddsd);
24382477 }
2439 - glUtil_SetFBOTextures(This->util, &dest->zfbo, dest->texture->dummycolor, dest->texture, FALSE);
 2478+ glUtil_SetFBOTextures(This->util, &cmd->dest->dummycolor->levels[0].fbo, cmd->dest->dummycolor,
 2479+ cmd->dest, cmd->destlevel, 0, FALSE);
24402480 }
2441 - glUtil_SetViewport(This->util, 0, 0, dest->ddsd.dwWidth, dest->ddsd.dwHeight);
2442 - if (lpDestRect) glUtil_SetScissor(This->util, TRUE, lpDestRect->left, lpDestRect->top,
2443 - lpDestRect->right, lpDestRect->bottom);
 2481+ glUtil_SetViewport(This->util, 0, 0, cmd->dest->levels[cmd->destlevel].ddsd.dwWidth,
 2482+ cmd->dest->levels[cmd->destlevel].ddsd.dwHeight);
 2483+ if (usedestrect) glUtil_SetScissor(This->util, TRUE, cmd->destrect.left, cmd->destrect.top,
 2484+ cmd->destrect.right, cmd->destrect.bottom);
24442485 glUtil_DepthWrite(This->util, TRUE);
2445 - glUtil_ClearDepth(This->util, lpDDBltFx->dwFillDepth / (double)0xFFFF); // FIXME: SOTE depth workaround
 2486+ glUtil_ClearDepth(This->util, cmd->bltfx.dwFillDepth / (double)0xFFFF); // FIXME: SOTE depth workaround
24462487 glClear(GL_DEPTH_BUFFER_BIT);
2447 - if (lpDestRect)glUtil_SetScissor(This->util, false, 0, 0, 0, 0);
 2488+ if (usedestrect)glUtil_SetScissor(This->util, false, 0, 0, 0, 0);
24482489 This->outputs[0] = DD_OK;
24492490 SetEvent(This->busy);
24502491 }
@@ -2878,6 +2919,39 @@
28792920 }
28802921 }
28812922
 2923+void glRenderer__SetTextureColorKey(glRenderer *This, glTexture *texture, DWORD dwFlags, LPDDCOLORKEY lpDDColorKey, GLint level)
 2924+{
 2925+ if (dwFlags & DDCKEY_SRCBLT)
 2926+ {
 2927+ texture->levels[level].ddsd.dwFlags |= DDSD_CKSRCBLT;
 2928+ texture->levels[level].ddsd.ddckCKSrcBlt.dwColorSpaceLowValue = lpDDColorKey->dwColorSpaceLowValue;
 2929+ if (DDCKEY_COLORSPACE) texture->levels[level].ddsd.ddckCKSrcBlt.dwColorSpaceHighValue = lpDDColorKey->dwColorSpaceLowValue;
 2930+ else texture->levels[level].ddsd.ddckCKSrcBlt.dwColorSpaceHighValue = lpDDColorKey->dwColorSpaceHighValue;
 2931+ }
 2932+ if (dwFlags & DDCKEY_DESTBLT)
 2933+ {
 2934+ texture->levels[level].ddsd.dwFlags |= DDSD_CKDESTBLT;
 2935+ texture->levels[level].ddsd.ddckCKDestBlt.dwColorSpaceLowValue = lpDDColorKey->dwColorSpaceLowValue;
 2936+ if (DDCKEY_COLORSPACE) texture->levels[level].ddsd.ddckCKDestBlt.dwColorSpaceHighValue = lpDDColorKey->dwColorSpaceLowValue;
 2937+ else texture->levels[level].ddsd.ddckCKDestBlt.dwColorSpaceHighValue = lpDDColorKey->dwColorSpaceHighValue;
 2938+ }
 2939+ if (dwFlags & DDCKEY_SRCOVERLAY)
 2940+ {
 2941+ texture->levels[level].ddsd.dwFlags |= DDSD_CKSRCOVERLAY;
 2942+ texture->levels[level].ddsd.ddckCKSrcOverlay.dwColorSpaceLowValue = lpDDColorKey->dwColorSpaceLowValue;
 2943+ if (DDCKEY_COLORSPACE) texture->levels[level].ddsd.ddckCKSrcOverlay.dwColorSpaceHighValue = lpDDColorKey->dwColorSpaceLowValue;
 2944+ else texture->levels[level].ddsd.ddckCKSrcOverlay.dwColorSpaceHighValue = lpDDColorKey->dwColorSpaceHighValue;
 2945+ }
 2946+ if (dwFlags & DDCKEY_DESTOVERLAY)
 2947+ {
 2948+ texture->levels[level].ddsd.dwFlags |= DDSD_CKDESTOVERLAY;
 2949+ texture->levels[level].ddsd.ddckCKDestOverlay.dwColorSpaceLowValue = lpDDColorKey->dwColorSpaceLowValue;
 2950+ if (DDCKEY_COLORSPACE) texture->levels[level].ddsd.ddckCKDestOverlay.dwColorSpaceHighValue = lpDDColorKey->dwColorSpaceLowValue;
 2951+ else texture->levels[level].ddsd.ddckCKDestOverlay.dwColorSpaceHighValue = lpDDColorKey->dwColorSpaceHighValue;
 2952+ }
 2953+ SetEvent(This->busy);
 2954+}
 2955+
28822956 void glRenderer__DXGLBreak(glRenderer *This)
28832957 {
28842958 if (This->ext->GLEXT_GREMEDY_frame_terminator) This->ext->glFrameTerminatorGREMEDY();
Index: ddraw/glRenderer.h
@@ -104,6 +104,7 @@
105105 #define OP_SETLIGHT 21
106106 #define OP_SETVIEWPORT 22
107107 #define OP_DXGLBREAK 23
 108+#define OP_SETTEXTURECOLORKEY 24
108109
109110 extern const DWORD renderstate_default[153];
110111 extern const TEXTURESTAGE texstagedefault0;
@@ -159,10 +160,9 @@
160161 static DWORD WINAPI glRenderer_ThreadEntry(void *entry);
161162 void glRenderer_UploadTexture(glRenderer *This, glTexture *texture, GLint level);
162163 void glRenderer_DownloadTexture(glRenderer *This, glTexture *texture, GLint level);
163 -HRESULT glRenderer_Blt(glRenderer *This, LPRECT lpDestRect, glDirectDrawSurface7 *src,
164 - glDirectDrawSurface7 *dest, LPRECT lpSrcRect, DWORD dwFlags, LPDDBLTFX lpDDBltFx);
 164+HRESULT glRenderer_Blt(glRenderer *This, BltCommand *cmd);
165165 void glRenderer_MakeTexture(glRenderer *This, glTexture *texture);
166 -void glRenderer_DrawScreen(glRenderer *This, glTexture *texture, glTexture *paltex, glDirectDrawSurface7 *dest, glDirectDrawSurface7 *src, GLint vsync);
 166+void glRenderer_DrawScreen(glRenderer *This, glTexture *texture, glTexture *paltex, GLint vsync);
167167 void glRenderer_DeleteTexture(glRenderer *This, glTexture *texture);
168168 void glRenderer_InitD3D(glRenderer *This, int zbuffer, int x, int y);
169169 void glRenderer_Flush(glRenderer *This);
@@ -173,7 +173,7 @@
174174 void glRenderer_DeleteFBO(glRenderer *This, FBO *fbo);
175175 void glRenderer_UpdateClipper(glRenderer *This, glDirectDrawSurface7 *surface);
176176 unsigned int glRenderer_GetScanLine(glRenderer *This);
177 -HRESULT glRenderer_DepthFill(glRenderer *This, LPRECT lpDestRect, glDirectDrawSurface7 *dest, LPDDBLTFX lpDDBltFx);
 177+HRESULT glRenderer_DepthFill(glRenderer *This, BltCommand *cmd, glTexture *parent, GLint parentlevel);
178178 void glRenderer_SetRenderState(glRenderer *This, D3DRENDERSTATETYPE dwRendStateType, DWORD dwRenderState);
179179 void glRenderer_SetTexture(glRenderer *This, DWORD dwStage, glDirectDrawSurface7 *Texture);
180180 void glRenderer_SetTextureStageState(glRenderer *This, DWORD dwStage, D3DTEXTURESTAGESTATETYPE dwState, DWORD dwValue);
@@ -181,6 +181,7 @@
182182 void glRenderer_SetMaterial(glRenderer *This, LPD3DMATERIAL7 lpMaterial);
183183 void glRenderer_SetLight(glRenderer *This, DWORD index, LPD3DLIGHT7 light, BOOL remove);
184184 void glRenderer_SetViewport(glRenderer *This, LPD3DVIEWPORT7 lpViewport);
 185+void glRenderer_SetTextureColorKey(glRenderer *This, glTexture *texture, DWORD dwFlags, LPDDCOLORKEY lpDDColorKey, GLint level);
185186 void glRenderer_DXGLBreak(glRenderer *This);
186187 // In-thread APIs
187188 DWORD glRenderer__Entry(glRenderer *This);
@@ -187,10 +188,9 @@
188189 BOOL glRenderer__InitGL(glRenderer *This, int width, int height, int bpp, int fullscreen, unsigned int frequency, HWND hWnd, glDirectDraw7 *glDD7);
189190 void glRenderer__UploadTexture(glRenderer *This, glTexture *texture, GLint level);
190191 void glRenderer__DownloadTexture(glRenderer *This, glTexture *texture, GLint level);
191 -void glRenderer__Blt(glRenderer *This, LPRECT lpDestRect, glDirectDrawSurface7 *src,
192 - glDirectDrawSurface7 *dest, LPRECT lpSrcRect, DWORD dwFlags, LPDDBLTFX lpDDBltFx);
 192+void glRenderer__Blt(glRenderer *This, BltCommand *cmd);
193193 void glRenderer__MakeTexture(glRenderer *This, glTexture *texture);
194 -void glRenderer__DrawScreen(glRenderer *This, glTexture *texture, glTexture *paltex, glDirectDrawSurface7 *dest, glDirectDrawSurface7 *src, GLint vsync, BOOL setsync);
 194+void glRenderer__DrawScreen(glRenderer *This, glTexture *texture, glTexture *paltex, GLint vsync, BOOL setsync);
195195 void glRenderer__DeleteTexture(glRenderer *This, glTexture *texture);
196196 void glRenderer__DrawBackbuffer(glRenderer *This, glTexture **texture, int x, int y, int progtype);
197197 void glRenderer__DrawBackbufferRect(glRenderer *This, glTexture *texture, RECT srcrect, int progtype);
@@ -202,7 +202,7 @@
203203 void glRenderer__SetWnd(glRenderer *This, int width, int height, int fullscreen, int bpp, unsigned int frequency, HWND newwnd, BOOL devwnd);
204204 void glRenderer__DeleteFBO(glRenderer *This, FBO *fbo);
205205 void glRenderer__UpdateClipper(glRenderer *This, glDirectDrawSurface7 *surface);
206 -void glRenderer__DepthFill(glRenderer *This, LPRECT lpDestRect, glDirectDrawSurface7 *dest, LPDDBLTFX lpDDBltFx);
 206+void glRenderer__DepthFill(glRenderer *This, BltCommand *cmd, glTexture *parent, GLint parentlevel);
207207 void glRenderer__SetFogColor(glRenderer *This, DWORD color);
208208 void glRenderer__SetFogStart(glRenderer *This, GLfloat start);
209209 void glRenderer__SetFogEnd(glRenderer *This, GLfloat end);
@@ -216,6 +216,7 @@
217217 void glRenderer__SetMaterial(glRenderer *This, LPD3DMATERIAL7 lpMaterial);
218218 void glRenderer__SetLight(glRenderer *This, DWORD index, LPD3DLIGHT7 light, BOOL remove);
219219 void glRenderer__SetViewport(glRenderer *This, LPD3DVIEWPORT7 lpViewport);
 220+void glRenderer__SetTextureColorKey(glRenderer *This, glTexture *texture, DWORD dwFlags, LPDDCOLORKEY lpDDColorKey, GLint level);
220221 void glRenderer__SetDepthComp(glRenderer *This);
221222 void glRenderer__DXGLBreak(glRenderer *This);
222223
Index: ddraw/glTexture.cpp
@@ -122,7 +122,7 @@
123123 *y = max(1, (DWORD)floorf((float)*y / 2.0f));
124124 }
125125
126 -HRESULT glTexture_Create(const DDSURFACEDESC2 *ddsd, glTexture **texture, struct glRenderer *renderer, GLint bigwidth, GLint bigheight, BOOL backend)
 126+HRESULT glTexture_Create(const DDSURFACEDESC2 *ddsd, glTexture **texture, struct glRenderer *renderer, GLint bigwidth, GLint bigheight, BOOL zhasstencil, BOOL backend)
127127 {
128128 glTexture *newtexture;
129129 if (!texture) return DDERR_INVALIDPARAMS;
@@ -164,6 +164,7 @@
165165 newtexture->levels[0].ddsd.ddpfPixelFormat.dwZBitMask = 0xFFFFFFFF;
166166 break;
167167 }
 168+ newtexture->zhasstencil = zhasstencil;
168169 }
169170
170171 if (!(newtexture->levels[0].ddsd.dwFlags & DDSD_PIXELFORMAT))
@@ -386,7 +387,7 @@
387388 ddsd.dwWidth = This->levels[0].ddsd.dwWidth;
388389 ddsd.lPitch = NextMultipleOf4(ddsd.dwWidth * 2);
389390 ddsd.dwHeight = This->levels[0].ddsd.dwHeight;
390 - glTexture_Create(&ddsd, &This->dummycolor, This->renderer, ddsd.dwWidth, ddsd.dwHeight, FALSE);
 391+ glTexture_Create(&ddsd, &This->dummycolor, This->renderer, ddsd.dwWidth, ddsd.dwHeight, FALSE, backend);
391392 }
392393 void glTexture_DeleteDummyColor(glTexture *This, BOOL backend)
393394 {
Index: ddraw/glTexture.h
@@ -32,7 +32,7 @@
3333
3434 DWORD CalculateMipLevels(DWORD width, DWORD height);
3535
36 -HRESULT glTexture_Create(const DDSURFACEDESC2 *ddsd, glTexture **texture, struct glRenderer *renderer, GLint bigwidth, GLint bigheight, BOOL backend);
 36+HRESULT glTexture_Create(const DDSURFACEDESC2 *ddsd, glTexture **texture, struct glRenderer *renderer, GLint bigwidth, GLint bigheight, BOOL zhasstencil, BOOL backend);
3737 ULONG glTexture_AddRef(glTexture *This);
3838 ULONG glTexture_Release(glTexture *This, BOOL backend);
3939 HRESULT glTexture_Lock(glTexture *This, GLint level, LPRECT r, LPDDSURFACEDESC2 ddsd, DWORD flags, BOOL backend);
Index: ddraw/glUtil.cpp
@@ -1,5 +1,5 @@
22 // DXGL
3 -// Copyright (C) 2012-2014 William Feely
 3+// Copyright (C) 2012-2016 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
@@ -142,7 +142,7 @@
143143 }
144144 }
145145
146 -void glUtil_SetFBOTexture(glUtil *This, FBO *fbo, glTexture *color, glTexture *z, BOOL stencil)
 146+void glUtil_SetFBOTexture(glUtil *This, FBO *fbo, glTexture *color, glTexture *z, GLint level, GLint zlevel, BOOL stencil)
147147 {
148148 if(!color) return;
149149 if(!fbo->fbo) return;
@@ -150,18 +150,18 @@
151151 {
152152 if(This->currentfbo != fbo) This->ext->glBindFramebuffer(GL_FRAMEBUFFER,fbo->fbo);
153153 This->currentfbo = fbo;
154 - This->ext->glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_TEXTURE_2D,color->id,0);
 154+ This->ext->glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_TEXTURE_2D,color->id,level);
155155 fbo->fbcolor = color;
156156 if(stencil)
157157 {
158158 if(!fbo->stencil) This->ext->glFramebufferTexture2D(GL_FRAMEBUFFER,GL_DEPTH_ATTACHMENT,GL_TEXTURE_2D,0,0);
159 - if(z)This->ext->glFramebufferTexture2D(GL_FRAMEBUFFER,GL_DEPTH_STENCIL_ATTACHMENT,GL_TEXTURE_2D,z->id,0);
 159+ if(z)This->ext->glFramebufferTexture2D(GL_FRAMEBUFFER,GL_DEPTH_STENCIL_ATTACHMENT,GL_TEXTURE_2D,z->id,zlevel);
160160 else This->ext->glFramebufferTexture2D(GL_FRAMEBUFFER,GL_DEPTH_STENCIL_ATTACHMENT,GL_TEXTURE_2D,0,0);
161161 }
162162 else
163163 {
164164 if(fbo->stencil) This->ext->glFramebufferTexture2D(GL_FRAMEBUFFER,GL_DEPTH_STENCIL_ATTACHMENT,GL_TEXTURE_2D,0,0);
165 - if(z) This->ext->glFramebufferTexture2D(GL_FRAMEBUFFER,GL_DEPTH_ATTACHMENT,GL_TEXTURE_2D,z->id,0);
 165+ if(z) This->ext->glFramebufferTexture2D(GL_FRAMEBUFFER,GL_DEPTH_ATTACHMENT,GL_TEXTURE_2D,z->id,zlevel);
166166 else This->ext->glFramebufferTexture2D(GL_FRAMEBUFFER,GL_DEPTH_ATTACHMENT,GL_TEXTURE_2D,0,0);
167167 }
168168 fbo->stencil = stencil;
@@ -172,14 +172,14 @@
173173 {
174174 if (This->currentfbo != fbo) This->ext->glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo->fbo);
175175 This->currentfbo = fbo;
176 - This->ext->glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, color->id, 0);
 176+ This->ext->glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, color->id, level);
177177 fbo->fbcolor = color;
178178 if(stencil)
179179 {
180180 if(z)
181181 {
182 - This->ext->glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, z->id, 0);
183 - This->ext->glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT, GL_TEXTURE_2D, z->id, 0);
 182+ This->ext->glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, z->id, zlevel);
 183+ This->ext->glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT, GL_TEXTURE_2D, z->id, zlevel);
184184 }
185185 else
186186 {
@@ -190,7 +190,7 @@
191191 else
192192 {
193193 This->ext->glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT, GL_TEXTURE_2D, 0, 0);
194 - if (z)This->ext->glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, z->id, 0);
 194+ if (z)This->ext->glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, z->id, zlevel);
195195 else This->ext->glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, 0, 0);
196196 }
197197 fbo->stencil = stencil;
@@ -199,11 +199,23 @@
200200 }
201201 }
202202
203 -GLenum glUtil_SetFBOSurface(glUtil *This, glDirectDrawSurface7 *surface)
 203+// Transitions away from using surface objects and adds miplevel
 204+GLenum glUtil_SetFBOSurface(glUtil *This, glTexture *surface, glTexture *zbuffer, GLint level, GLint zlevel, BOOL skipz)
204205 {
205206 if (!surface) return glUtil_SetFBO(This, (FBO*)NULL);
206 - if (surface->zbuffer) return glUtil_SetFBOTextures(This, &surface->fbo, surface->texture, surface->zbuffer->texture, surface->zbuffer->hasstencil);
207 - else return glUtil_SetFBOTextures(This, &surface->fbo, surface->texture, NULL, FALSE);
 207+ if (skipz)
 208+ {
 209+ if (surface->levels[level].fbo.fbz)
 210+ return glUtil_SetFBOTextures(This, &surface->levels[level].fbo, surface,
 211+ surface->levels[level].fbo.fbz, level, zlevel, surface->levels[level].fbo.fbz->zhasstencil);
 212+ else return glUtil_SetFBOTextures(This, &surface->levels[level].fbo, surface, NULL, level, zlevel, FALSE);
 213+ }
 214+ else
 215+ {
 216+ if (zbuffer) return glUtil_SetFBOTextures(This, &surface->levels[level].fbo, surface,
 217+ zbuffer, level, zlevel, zbuffer->zhasstencil);
 218+ else return glUtil_SetFBOTextures(This, &surface->levels[level].fbo, surface, NULL, 0, 0, FALSE);
 219+ }
208220 }
209221
210222 GLenum glUtil_SetFBO(glUtil *This, FBO *fbo)
@@ -241,7 +253,7 @@
242254 }
243255 }
244256
245 -GLenum glUtil_SetFBOTextures(glUtil *This, FBO *fbo, glTexture *color, glTexture *z, BOOL stencil)
 257+GLenum glUtil_SetFBOTextures(glUtil *This, FBO *fbo, glTexture *color, glTexture *z, GLint level, GLint zlevel, BOOL stencil)
246258 {
247259 if(!fbo)
248260 {
@@ -250,7 +262,7 @@
251263 if(!fbo->fbo) glUtil_InitFBO(This, fbo);
252264 if (!color) return GL_INVALID_ENUM;
253265 if((color != fbo->fbcolor) || (z != fbo->fbz) || (stencil != fbo->stencil))
254 - glUtil_SetFBOTexture(This, fbo,color,z,stencil);
 266+ glUtil_SetFBOTexture(This, fbo,color,z,level,zlevel,stencil);
255267 if(fbo != This->currentfbo) return glUtil_SetFBO(This, fbo);
256268 else return fbo->status;
257269 }
@@ -637,7 +649,7 @@
638650 {
639651 glUtil_SetActiveTexture(This, level);
640652 glBindTexture(GL_TEXTURE_2D, texname);
641 - This->textures[level] = texname;
 653+ //This->textures[level] = texname;
642654 }
643655 }
644656
Index: ddraw/glUtil.h
@@ -34,11 +34,11 @@
3535 void glUtil_Release(glUtil *This);
3636 void glUtil_InitFBO(glUtil *This, FBO *fbo);
3737 void glUtil_DeleteFBO(glUtil *This, FBO *fbo);
38 -void glUtil_SetFBOTexture(glUtil *This, FBO *fbo, glTexture *color, glTexture *z, BOOL stencil);
 38+void glUtil_SetFBOTexture(glUtil *This, FBO *fbo, glTexture *color, glTexture *z, GLint level, GLint zlevel, BOOL stencil);
3939 void glUtil_SetWrap(glUtil *This, int level, DWORD coord, DWORD address);
40 -GLenum glUtil_SetFBOSurface(glUtil *This, glDirectDrawSurface7 *surface);
 40+GLenum glUtil_SetFBOSurface(glUtil *This, glTexture *surface, glTexture *zbuffer, GLint level, GLint zlevel, BOOL skipz);
4141 GLenum glUtil_SetFBO(glUtil *This, FBO *fbo);
42 -GLenum glUtil_SetFBOTextures(glUtil *This, FBO *fbo, glTexture *color, glTexture *z, BOOL stencil);
 42+GLenum glUtil_SetFBOTextures(glUtil *This, FBO *fbo, glTexture *color, glTexture *z, GLint level, GLint zlevel, BOOL stencil);
4343 void glUtil_SetDepthComp(glUtil *This, GLenum comp);
4444 void glUtil_DepthWrite(glUtil *This, BOOL enabled);
4545 void glUtil_DepthTest(glUtil *This, BOOL enabled);
Index: ddraw/struct.h
@@ -284,6 +284,7 @@
285285 // 1 - Surface was locked
286286 // 2 - Texture was written to by GPU
287287 DWORD locked;
 288+ FBO fbo;
288289 } MIPLEVEL;
289290
290291 // Surface texture object
@@ -307,6 +308,7 @@
308309 int colororder;
309310 GLenum format;
310311 GLenum type;
 312+ BOOL zhasstencil;
311313 struct glTexture *palette;
312314 struct glTexture *stencil;
313315 struct glTexture *dummycolor;

Follow-up revisions

RevisionCommit summaryAuthorDate
r662Fix DXGLTest BltFast test to comply with parameter validation from r660 (whic...admin00:59, 8 June 2016

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r631Get rid of render window. Currently breaks windowed mode and NULL hWnd coope...admin00:22, 1 January 2016