DXGL r603 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r602‎ | r603 | r604 >
Date:00:21, 11 March 2015
Author:admin
Status:new
Tags:
Comment:
Revert ddraw.dll to r590 (removing all recent async code)
Modified paths:
  • /ddraw/common.h (modified) (history)
  • /ddraw/ddraw.cpp (modified) (history)
  • /ddraw/ddraw.h (modified) (history)
  • /ddraw/ddraw.vcxproj (modified) (history)
  • /ddraw/ddraw.vcxproj.filters (modified) (history)
  • /ddraw/dllmain.c (deleted) (history)
  • /ddraw/dllmain.cpp (added) (history)
  • /ddraw/glDirect3DDevice.cpp (modified) (history)
  • /ddraw/glDirectDraw.cpp (modified) (history)
  • /ddraw/glDirectDraw.h (modified) (history)
  • /ddraw/glDirectDrawSurface.cpp (modified) (history)
  • /ddraw/glDirectDrawSurface.h (modified) (history)
  • /ddraw/glRenderWindow.cpp (modified) (history)
  • /ddraw/glRenderer.cpp (modified) (history)
  • /ddraw/glRenderer.h (modified) (history)
  • /ddraw/timer.c (modified) (history)

Diff [purge]

Index: ddraw/dllmain.c
@@ -1,53 +0,0 @@
2 -// DXGL
3 -// Copyright (C) 2011-2015 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 -#include "ddraw.h"
21 -#include "hooks.h"
22 -ATOM WindowClass = 0;
23 -BOOL smp = FALSE;
24 -CRITICAL_SECTION dll_cs = {NULL,0,0,NULL,NULL,0};
25 -SYSTEM_INFO sysinfo;
26 -BOOL APIENTRY DllMain(HMODULE hModule,
27 - DWORD ul_reason_for_call,
28 - LPVOID lpReserved
29 - )
30 -{
31 - switch (ul_reason_for_call)
32 - {
33 - case DLL_PROCESS_ATTACH:
34 - GetSystemInfo(&sysinfo);
35 - if (sysinfo.dwNumberOfProcessors > 1) smp = TRUE;
36 - if(!dll_cs.LockCount && !dll_cs.OwningThread) InitializeCriticalSection(&dll_cs);
37 - if (!hook_cs.LockCount && !hook_cs.OwningThread) InitializeCriticalSection(&hook_cs);
38 - InitHooks();
39 - GetCurrentConfig(&dxglcfg, TRUE);
40 - break;
41 - case DLL_THREAD_ATTACH:
42 - case DLL_THREAD_DETACH:
43 - break;
44 - case DLL_PROCESS_DETACH:
45 - ShutdownHooks();
46 - DeleteCriticalSection(&hook_cs);
47 - ZeroMemory(&hook_cs, sizeof(CRITICAL_SECTION));
48 - DeleteCriticalSection(&dll_cs);
49 - ZeroMemory(&dll_cs, sizeof(CRITICAL_SECTION));
50 - break;
51 - }
52 - return TRUE;
53 -}
54 -
Index: ddraw/common.h
@@ -1,5 +1,5 @@
22 // DXGL
3 -// Copyright (C) 2011-2012 William Feely
 3+// Copyright (C) 2011-2015 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
@@ -88,7 +88,6 @@
8989 #define ERR(error) return error;
9090 #endif
9191
92 -static INLINE int NextMultipleOf64K(int number){return ((number+65535) & (~65535));}
9392 static INLINE int NextMultipleOf8(int number){return ((number+7) & (~7));}
9493 static INLINE int NextMultipleOf4(int number){return ((number+3) & (~3));}
9594 static INLINE int NextMultipleOf2(int number){return ((number+1) & (~1));}
@@ -114,16 +113,7 @@
115114 #define NextMultipleOfWord NextMultipleOf4
116115 #endif
117116
118 -#ifdef __cplusplus
119 -extern "C"
120 -{
121 - extern CRITICAL_SECTION dll_cs;
122 - extern BOOL smp;
123 -}
124 -#else
125117 extern CRITICAL_SECTION dll_cs;
126 -extern BOOL smp;
127 -#endif
128118
129119 #include "trace.h"
130120 #include "../cfgmgr/cfgmgr.h"
Index: ddraw/ddraw.cpp
@@ -28,8 +28,6 @@
2929 #include "hooks.h"
3030 #include <intrin.h>
3131
32 -extern "C" {
33 -
3432 DXGLCFG dxglcfg;
3533 DWORD gllock = 0;
3634 HMODULE sysddraw = NULL;
@@ -570,5 +568,3 @@
571569 TRACE_EXIT(0,0);
572570 return TRUE;
573571 }
574 -
575 -}
\ No newline at end of file
Index: ddraw/ddraw.h
@@ -19,10 +19,6 @@
2020 #ifndef _DDRAW_PRIVATE_H
2121 #define _DDRAW_PRIVATE_H
2222
23 -#ifdef __cplusplus
24 -extern "C" {
25 -#endif
26 -
2723 #ifdef DDRAW_EXPORTS
2824 #define DDRAW_API __declspec(dllexport)
2925 #else
@@ -55,7 +51,7 @@
5652 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv);
5753 DDRAW_API void WINAPI GetDDSurfaceLocal();
5854 DDRAW_API HANDLE WINAPI GetOLEThunkData(int i1);
59 -DDRAW_API HRESULT WINAPI GlobalGetSurfaceFromDC(LPDIRECTDRAW7 lpDD, HDC hdc, LPDIRECTDRAWSURFACE7 *lpDDS);
 55+DDRAW_API HRESULT WINAPI GlobalGetSurfaceFromDC(LPDIRECTDRAW lpDD, HDC hdc, LPDIRECTDRAWSURFACE7 *lpDDS);
6056 DDRAW_API void WINAPI RegisterSpecialCase();
6157 DDRAW_API void WINAPI ReleaseDDThreadLock();
6258 DDRAW_API BOOL IsDXGLDDraw();
@@ -64,17 +60,7 @@
6561 extern DWORD gllock;
6662 extern const GUID device_template;
6763 struct glRenderer;
68 -#ifdef __cplusplus
6964 class glDirectDraw7;
70 -#else
71 -typedef void glDirectDraw7;
72 -typedef BOOL bool;
73 -#endif
7465 void InitGL(int width, int height, int bpp, bool fullscreen, unsigned int frequency, HWND hWnd, glDirectDraw7 *glDD7, bool devwnd);
7566
76 -
77 -#ifdef __cplusplus
78 -}
79 -#endif
80 -
8167 #endif //_DDRAW_PRIVATE_H
Index: ddraw/ddraw.vcxproj
@@ -66,7 +66,6 @@
6767 </PropertyGroup>
6868 <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
6969 <ImportGroup Label="ExtensionSettings">
70 - <Import Project="$(VCTargetsPath)\BuildCustomizations\masm.props" />
7170 </ImportGroup>
7271 <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
7372 <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
@@ -191,7 +190,7 @@
192191 <SubSystem>Windows</SubSystem>
193192 <GenerateDebugInformation>true</GenerateDebugInformation>
194193 <ModuleDefinitionFile>ddraw.def</ModuleDefinitionFile>
195 - <AdditionalDependencies>$(OutDir)..\Debug\libMinHook.x86.lib;$(OutDir)cfgmgr.lib;glu32.lib;opengl32.lib;winmm.lib;%(AdditionalDependencies)</AdditionalDependencies>
 194+ <AdditionalDependencies>$(OutDir)libMinHook.x86.lib;$(OutDir)cfgmgr.lib;glu32.lib;opengl32.lib;winmm.lib;%(AdditionalDependencies)</AdditionalDependencies>
196195 <ImportLibrary>$(OutDir)ddraw.lib</ImportLibrary>
197196 </Link>
198197 <PostBuildEvent />
@@ -308,7 +307,7 @@
309308 </ItemGroup>
310309 <ItemGroup>
311310 <ClCompile Include="ddraw.cpp" />
312 - <ClCompile Include="dllmain.c">
 311+ <ClCompile Include="dllmain.cpp">
313312 <CompileAsManaged Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</CompileAsManaged>
314313 <CompileAsManaged Condition="'$(Configuration)|$(Platform)'=='Debug Trace|Win32'">false</CompileAsManaged>
315314 <CompileAsManaged Condition="'$(Configuration)|$(Platform)'=='Debug No MSVCRT|Win32'">false</CompileAsManaged>
@@ -315,14 +314,18 @@
316315 <CompileAsManaged Condition="'$(Configuration)|$(Platform)'=='Debug no DXGL|Win32'">false</CompileAsManaged>
317316 <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
318317 </PrecompiledHeader>
319 - <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug Trace|Win32'">NotUsing</PrecompiledHeader>
320 - <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug No MSVCRT|Win32'">NotUsing</PrecompiledHeader>
321 - <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug no DXGL|Win32'">NotUsing</PrecompiledHeader>
 318+ <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug Trace|Win32'">
 319+ </PrecompiledHeader>
 320+ <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug No MSVCRT|Win32'">
 321+ </PrecompiledHeader>
 322+ <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug no DXGL|Win32'">
 323+ </PrecompiledHeader>
322324 <CompileAsManaged Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</CompileAsManaged>
323325 <CompileAsManaged Condition="'$(Configuration)|$(Platform)'=='Release no DXGL|Win32'">false</CompileAsManaged>
324326 <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
325327 </PrecompiledHeader>
326 - <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release no DXGL|Win32'">NotUsing</PrecompiledHeader>
 328+ <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release no DXGL|Win32'">
 329+ </PrecompiledHeader>
327330 </ClCompile>
328331 <ClCompile Include="glClassFactory.cpp" />
329332 <ClCompile Include="dxguid.c">
@@ -445,6 +448,5 @@
446449 </ItemGroup>
447450 <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
448451 <ImportGroup Label="ExtensionTargets">
449 - <Import Project="$(VCTargetsPath)\BuildCustomizations\masm.targets" />
450452 </ImportGroup>
451453 </Project>
\ No newline at end of file
Index: ddraw/ddraw.vcxproj.filters
@@ -151,6 +151,9 @@
152152 <ClCompile Include="ddraw.cpp">
153153 <Filter>Source Files</Filter>
154154 </ClCompile>
 155+ <ClCompile Include="dllmain.cpp">
 156+ <Filter>Source Files</Filter>
 157+ </ClCompile>
155158 <ClCompile Include="glDirectDraw.cpp">
156159 <Filter>Source Files</Filter>
157160 </ClCompile>
@@ -244,9 +247,6 @@
245248 <ClCompile Include="hooks.c">
246249 <Filter>Source Files</Filter>
247250 </ClCompile>
248 - <ClCompile Include="dllmain.c">
249 - <Filter>Source Files</Filter>
250 - </ClCompile>
251251 </ItemGroup>
252252 <ItemGroup>
253253 <ResourceCompile Include="ddraw.rc">
Index: ddraw/dllmain.cpp
@@ -0,0 +1,49 @@
 2+// DXGL
 3+// Copyright (C) 2011-2015 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+#include "ddraw.h"
 21+#include "hooks.h"
 22+ATOM WindowClass = NULL;
 23+CRITICAL_SECTION dll_cs = {NULL,0,0,NULL,NULL,0};
 24+BOOL APIENTRY DllMain( HMODULE hModule,
 25+ DWORD ul_reason_for_call,
 26+ LPVOID lpReserved
 27+ )
 28+{
 29+ switch (ul_reason_for_call)
 30+ {
 31+ case DLL_PROCESS_ATTACH:
 32+ if(!dll_cs.LockCount && !dll_cs.OwningThread) InitializeCriticalSection(&dll_cs);
 33+ if (!hook_cs.LockCount && !hook_cs.OwningThread) InitializeCriticalSection(&hook_cs);
 34+ InitHooks();
 35+ GetCurrentConfig(&dxglcfg, true);
 36+ break;
 37+ case DLL_THREAD_ATTACH:
 38+ case DLL_THREAD_DETACH:
 39+ break;
 40+ case DLL_PROCESS_DETACH:
 41+ ShutdownHooks();
 42+ DeleteCriticalSection(&hook_cs);
 43+ ZeroMemory(&hook_cs, sizeof(CRITICAL_SECTION));
 44+ DeleteCriticalSection(&dll_cs);
 45+ ZeroMemory(&dll_cs, sizeof(CRITICAL_SECTION));
 46+ break;
 47+ }
 48+ return TRUE;
 49+}
 50+
Index: ddraw/glDirect3DDevice.cpp
@@ -578,9 +578,7 @@
579579 TRACE_ENTER(7,14,this,8,dwCount,14,lpRects,9,dwFlags,9,dwColor,19,&dvZ,9,dwStencil);
580580 if(!this) TRACE_RET(HRESULT,23,DDERR_INVALIDOBJECT);
581581 if(dwCount && !lpRects) TRACE_RET(HRESULT,23,DDERR_INVALIDPARAMS);
582 - glRenderer_Clear(renderer,glDDS7,dwCount,lpRects,dwFlags,dwColor,dvZ,dwStencil);
583 - TRACE_EXIT(23, DD_OK);
584 - return DD_OK;
 582+ TRACE_RET(HRESULT,23,glRenderer_Clear(renderer,glDDS7,dwCount,lpRects,dwFlags,dwColor,dvZ,dwStencil));
585583 }
586584
587585 // ComputeSphereVisibility based on modified code from the Wine project, subject
@@ -812,49 +810,6 @@
813811 return shader;
814812 }*/
815813
816 -HRESULT GetFVFStride(DWORD dwVertexTypeDesc, LPDWORD stride)
817 -{
818 - TRACE_ENTER(2, 9, dwVertexTypeDesc, 14, stride);
819 - int i;
820 - int pos = (dwVertexTypeDesc & D3DFVF_POSITION_MASK) >> 1;
821 - int ptr = 0;
822 - DWORD texformats[8];
823 - if (pos == 1)
824 - {
825 - ptr += 3;
826 - if (dwVertexTypeDesc & D3DFVF_RESERVED1) ptr++;
827 - }
828 - else if (pos == 2) ptr += 4;
829 - else if (!pos) { TRACE_RET(HRESULT, 23, DDERR_INVALIDPARAMS); }
830 - else ptr += (3 + (pos - 2));
831 - if (dwVertexTypeDesc & D3DFVF_NORMAL) ptr += 3;
832 - if (dwVertexTypeDesc & D3DFVF_DIFFUSE) ptr++;
833 - if (dwVertexTypeDesc & D3DFVF_SPECULAR) ptr++;
834 - int numtex = (dwVertexTypeDesc&D3DFVF_TEXCOUNT_MASK) >> D3DFVF_TEXCOUNT_SHIFT;
835 - for (i = 0; i < 8; i++)
836 - {
837 - if (i >= numtex) texformats[i] = -1;
838 - else texformats[i] = (dwVertexTypeDesc >> (16 + (2 * i)) & 3);
839 - switch (texformats[i])
840 - {
841 - case 0: // st
842 - ptr += 2;
843 - break;
844 - case 1: // str
845 - ptr += 3;
846 - break;
847 - case 2: // strq
848 - ptr += 4;
849 - break;
850 - case 3: // s
851 - ptr++;
852 - break;
853 - }
854 - }
855 - *stride = ptr * 4;
856 - TRACE_EXIT(23, D3D_OK);
857 - return D3D_OK;
858 -}
859814 HRESULT glDirect3DDevice7::fvftoglvertex(DWORD dwVertexTypeDesc,LPDWORD vertptr)
860815 {
861816 TRACE_ENTER(3,14,this,9,dwVertexTypeDesc,14,vertptr);
@@ -907,7 +862,7 @@
908863 else vertdata[9].data = NULL;
909864 for(i = 0; i < 8; i++)
910865 vertdata[i+10].data = NULL;
911 - int numtex = (dwVertexTypeDesc & D3DFVF_TEXCOUNT_MASK) >> D3DFVF_TEXCOUNT_SHIFT;
 866+ int numtex = (dwVertexTypeDesc&D3DFVF_TEXCOUNT_MASK)>>D3DFVF_TEXCOUNT_SHIFT;
912867 for(i = 0; i < 8; i++)
913868 {
914869 vertdata[i+10].data = &vertptr[ptr];
@@ -949,15 +904,12 @@
950905 TRACE_ENTER(8,9,d3dptPrimitiveType,9,dwVertexTypeDesc,14,lpvVertices,8,dwVertexCount,14,lpwIndices,8,dwIndexCount,9,dwFlags);
951906 if(!this) TRACE_RET(HRESULT,23,DDERR_INVALIDOBJECT);
952907 if(!inscene) TRACE_RET(HRESULT,23,D3DERR_SCENE_NOT_IN_SCENE);
953 - DWORD stride;
954 - HRESULT err = GetFVFStride(dwVertexTypeDesc, &stride);
 908+ HRESULT err = fvftoglvertex(dwVertexTypeDesc,(LPDWORD)lpvVertices);
955909 if(lpwIndices) AddStats(d3dptPrimitiveType,dwIndexCount,&stats);
956910 else AddStats(d3dptPrimitiveType,dwVertexCount,&stats);
957911 if(err != D3D_OK) TRACE_RET(HRESULT,23,err);
958 - glRenderer_DrawPrimitives(renderer,this,setdrawmode(d3dptPrimitiveType),stride,(BYTE*)lpvVertices,
959 - dwVertexTypeDesc,dwVertexCount,lpwIndices,dwIndexCount,dwFlags);
960 - TRACE_EXIT(23, D3D_OK);
961 - return D3D_OK;
 912+ TRACE_RET(HRESULT,23,glRenderer_DrawPrimitives(renderer,this,setdrawmode(d3dptPrimitiveType),vertdata,texformats,
 913+ dwVertexCount,lpwIndices,dwIndexCount,dwFlags));
962914 }
963915 HRESULT WINAPI glDirect3DDevice7::DrawIndexedPrimitiveStrided(D3DPRIMITIVETYPE d3dptPrimitiveType, DWORD dwVertexTypeDesc,
964916 LPD3DDRAWPRIMITIVESTRIDEDDATA lpvVertexArray, DWORD dwVertexCount, LPWORD lpwIndices, DWORD dwIndexCount, DWORD dwFlags)
Index: ddraw/glDirectDraw.cpp
@@ -1164,7 +1164,6 @@
11651165 mode.dmSize = sizeof(DEVMODE);
11661166 EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &mode);
11671167 glRenderer_Init(tmprenderer, 16, 16, mode.dmBitsPerPel, false, mode.dmDisplayFrequency, hGLWnd, NULL, FALSE);
1168 - glRenderer_Sync(tmprenderer,0);
11691168 if (tmprenderer->ext->glver_major >= 3) fullrop = TRUE;
11701169 if (tmprenderer->ext->GLEXT_EXT_gpu_shader4) fullrop = TRUE;
11711170 glRenderer_Delete(tmprenderer);
@@ -1172,7 +1171,6 @@
11731172 }
11741173 else
11751174 {
1176 - glRenderer_Sync(renderer,0);
11771175 if (renderer->ext->glver_major >= 3) fullrop = TRUE;
11781176 if (renderer->ext->GLEXT_EXT_gpu_shader4) fullrop = TRUE;
11791177 }
@@ -1376,6 +1374,7 @@
13771375 threadsafe = false;
13781376 nowindowchanges = false;
13791377 cooplevel = 0;
 1378+ timer = timeGetTime();
13801379 ZeroMemory(&oldmode,sizeof(DEVMODE));
13811380 surfaces = (glDirectDrawSurface7 **)malloc(1024*sizeof(glDirectDrawSurface7 *));
13821381 if(!surfaces) TRACE_RET(HRESULT,23,DDERR_OUTOFMEMORY);
@@ -1909,7 +1908,7 @@
19101909 if(dwFlags & 0xFFFFFFFA) TRACE_RET(HRESULT,23,DDERR_INVALIDPARAMS);
19111910 if(dwFlags == 5) TRACE_RET(HRESULT,23,DDERR_INVALIDPARAMS);
19121911 if(!lastsync) lastsync = true;
1913 - else if(primary) primary->RenderScreen(primary->texture,primary,1);
 1912+ else primary->RenderScreen(primary->texture,primary,1);
19141913 TRACE_EXIT(23,DD_OK);
19151914 return DD_OK;
19161915 }
Index: ddraw/glDirectDraw.h
@@ -136,6 +136,7 @@
137137 glDirect3D3 *glD3D3;
138138 glDirect3D2 *glD3D2;
139139 glDirect3D1 *glD3D1;
 140+ DWORD timer;
140141 bool devwnd;
141142 DWORD cooplevel;
142143 };
Index: ddraw/glDirectDrawSurface.cpp
@@ -30,6 +30,7 @@
3131 #include "glDirectDrawPalette.h"
3232 #include "glDirectDrawClipper.h"
3333 #include "glDirectDrawGammaControl.h"
 34+#include "glRenderer.h"
3435 #include <string>
3536 using namespace std;
3637 #include "ShaderGen3D.h"
@@ -224,9 +225,9 @@
225226 switch(surfacetype)
226227 {
227228 case 0:
228 - buffer = (BYTE *)malloc(NextMultipleOf4((ddsd.ddpfPixelFormat.dwRGBBitCount * ddsd.dwWidth)/8) * ddsd.dwHeight);
 229+ buffer = (char *)malloc(NextMultipleOf4((ddsd.ddpfPixelFormat.dwRGBBitCount * ddsd.dwWidth)/8) * ddsd.dwHeight);
229230 if((ddsd.dwWidth != fakex) || (ddsd.dwHeight != fakey))
230 - bigbuffer = (BYTE *)malloc(NextMultipleOf4((ddsd.ddpfPixelFormat.dwRGBBitCount * fakex)/8) * fakey);
 231+ bigbuffer = (char *)malloc(NextMultipleOf4((ddsd.ddpfPixelFormat.dwRGBBitCount * fakex)/8) * fakey);
231232 if(!buffer) *error = DDERR_OUTOFMEMORY;
232233 goto maketex;
233234 break;
@@ -401,7 +402,6 @@
402403 glDirectDrawSurface7::~glDirectDrawSurface7()
403404 {
404405 TRACE_ENTER(1,14,this);
405 - glRenderer_Sync(ddInterface->renderer, 0);
406406 AddRef();
407407 if (dds1) delete dds1;
408408 if (dds2) delete dds2;
@@ -852,9 +852,7 @@
853853 if (dwFlags & DDBLT_DEPTHFILL)
854854 {
855855 if (!(ddsd.ddpfPixelFormat.dwFlags & DDPF_ZBUFFER)) TRACE_RET(HRESULT, 23, DDERR_UNSUPPORTED);
856 - glRenderer_DepthFill(ddInterface->renderer, lpDestRect, this, lpDDBltFx);
857 - TRACE_EXIT(23, DD_OK);
858 - return DD_OK;
 856+ TRACE_RET(HRESULT, 23, glRenderer_DepthFill(ddInterface->renderer, lpDestRect, this, lpDDBltFx));
859857 }
860858 if (this == src)
861859 {
@@ -865,12 +863,9 @@
866864 if (error) TRACE_RET(HRESULT, 23, error);
867865 error = ddInterface->tmpsurface->Blt(&tmprect, lpDDSrcSurface, lpSrcRect, 0, NULL);
868866 if (error) TRACE_RET(HRESULT, 23, error);
869 - this->Blt(lpDestRect, ddInterface->tmpsurface, &tmprect, dwFlags, lpDDBltFx);
 867+ TRACE_RET(HRESULT,23,this->Blt(lpDestRect, ddInterface->tmpsurface, &tmprect, dwFlags, lpDDBltFx));
870868 }
871 - else glRenderer_Blt(ddInterface->renderer,lpDestRect,src,this,lpSrcRect,dwFlags,lpDDBltFx);
872 - if (this == ddInterface->primary) glRenderer_Sync(ddInterface->renderer,0);
873 - TRACE_EXIT(23, DD_OK);
874 - return DD_OK;
 869+ else TRACE_RET(HRESULT,23,glRenderer_Blt(ddInterface->renderer,lpDestRect,src,this,lpSrcRect,dwFlags,lpDDBltFx));
875870 }
876871 HRESULT WINAPI glDirectDrawSurface7::BltBatch(LPDDBLTBATCH lpDDBltBatch, DWORD dwCount, DWORD dwFlags)
877872 {
@@ -991,7 +986,6 @@
992987 else if(dwFlags & DDFLIP_INTERVAL4) swapinterval=4;
993988 else swapinterval=1;
994989 }
995 - glRenderer_Sync(ddInterface->renderer,0);
996990 int flips = 1;
997991 if(lpDDSurfaceTargetOverride)
998992 {
@@ -1332,9 +1326,9 @@
13331327 ERR(DDERR_UNSUPPORTED);
13341328 break;
13351329 case 2:
1336 - buffer = (BYTE *)malloc(ddsd.lPitch * ddsd.dwHeight);
 1330+ buffer = (char *)malloc(ddsd.lPitch * ddsd.dwHeight);
13371331 if((ddsd.dwWidth != fakex) || (ddsd.dwHeight != fakey))
1338 - bigbuffer = (BYTE *)malloc((ddsd.ddpfPixelFormat.dwRGBBitCount * NextMultipleOf4(fakex) * fakey)/8);
 1332+ bigbuffer = (char *)malloc((ddsd.ddpfPixelFormat.dwRGBBitCount * NextMultipleOf4(fakex) * fakey)/8);
13391333 else bigbuffer = NULL;
13401334 glRenderer_DownloadTexture(ddInterface->renderer,buffer,bigbuffer,texture,ddsd.dwWidth,ddsd.dwHeight,fakex,fakey,ddsd.lPitch,
13411335 (ddInterface->GetBPPMultipleOf8()/8)*fakex,ddsd.ddpfPixelFormat.dwRGBBitCount,miplevel);
Index: ddraw/glDirectDrawSurface.h
@@ -148,9 +148,9 @@
149149 TEXTURE *dummycolor;
150150 bool hasstencil;
151151 DWORD miplevel;
152 - BYTE *buffer;
153 - BYTE *bigbuffer;
154 - BYTE *gdibuffer;
 152+ char *buffer;
 153+ char *bigbuffer;
 154+ char *gdibuffer;
155155 DDSURFACEDESC2 ddsd;
156156 glDirectDrawPalette *palette;
157157 HGLRC hRC;
Index: ddraw/glRenderWindow.cpp
@@ -129,7 +129,7 @@
130130 #ifdef _DEBUG
131131 if(hotkeyregistered) UnregisterHotKey(hWnd,1);
132132 #endif
133 - PostMessage(hWnd,WM_CLOSE,0,0);
 133+ SendMessage(hWnd,WM_CLOSE,0,0);
134134 WaitForSingleObject(hThread,INFINITE);
135135 CloseHandle(hThread);
136136 }
Index: ddraw/glRenderer.cpp
@@ -35,7 +35,6 @@
3636 extern "C" {
3737
3838 const GLushort bltindices[4] = {0,1,2,3};
39 -const RECT nullrect = { -1, -1, -1, -1 };
4039
4140 /**
4241 * Expands a 5-bit value to 8 bits.
@@ -79,236 +78,111 @@
8079 }
8180
8281 /**
83 -* Adds a command to the renderer queue.\n
84 -* If the command requires more space than the queue buffer, the buffer will be
85 -* expanded. If there is no free space for the command, execution will pause
86 -* until the queue has been sufficiently emptied.
87 -* @param This
88 -* Pointer to glRenderer object
89 -* @param opcode
90 -* Code that describes the command to be added to the queue.
91 -* @param mode
92 -* Method to use for synchronization:
93 -* - 0: Do not fail the call
94 -* - 1: Fail if queue is full
95 -* - 2: Fail if queue is not empty
96 -* @param size
97 -* Size of the command in DWORDs
98 -* @param paramcount
99 -* Number of parameters to add to the queue command.
100 -* @param ...
101 -* Parameters for the command, when required. This is given in pairs of two
102 -* arguments:
103 -* - size: The size of the parameter, in bytes. Note that parameters are DWORD
104 -* aligned. The size cannot exceed the size of the command, minus data already
105 -* written to the queue.
106 -* - pointer: A pointer to the data to be added to the command.\n
107 -* If no parameters are used for the opcode, then supply 0 and NULL for the ...
108 -* parameter.
109 -* @return
110 -* Zero if the call succeeds, nonzero otherwise.
111 -*/
112 -int glRenderer_AddQueue(glRenderer *This, DWORD opcode, int mode, DWORD size, int paramcount, ...)
113 -{
114 - EnterCriticalSection(&This->queuecs);
115 - if ((mode == 2) && This->queuelength)
116 - {
117 - LeaveCriticalSection(&This->queuecs);
118 - return 1;
119 - }
120 - va_list params;
121 - // Check queue size
122 - va_start(params, paramcount);
123 - int argsize;
124 - void *argptr;
125 - if (size > This->queuesize)
126 - {
127 - This->queue = (LPDWORD)realloc(This->queue, (This->queuesize + size)*sizeof(DWORD));
128 - This->queuesize += size;
129 - }
130 - if (This->queuesize - This->queue_write < size)
131 - {
132 -/* if (This->queue_read < size)
133 - {
134 - if (mode == 1)
135 - {
136 - LeaveCriticalSection(&This->queuecs);
137 - return 1;
138 - }
139 - if (This->queue_write < This->queuesize)
140 - {
141 - This->queue[This->queue_write] = OP_RESETQUEUE;
142 - This->queuelength++;
143 - }
144 - LeaveCriticalSection(&This->queuecs);
145 - glRenderer_Sync(This, size);
146 - EnterCriticalSection(&This->queuecs);
147 - }*/
148 - LeaveCriticalSection(&This->queuecs);
149 - glRenderer_Sync(This, 0);
150 - EnterCriticalSection(&This->queuecs);
151 - }
152 - if (This->queue_write < This->queue_read)
153 - {
154 - if (This->queue_read - This->queue_write < size)
155 - {
156 - LeaveCriticalSection(&This->queuecs);
157 - glRenderer_Sync(This, size);
158 - EnterCriticalSection(&This->queuecs);
159 - }
160 - }
161 - This->queue[This->queue_write++] = opcode;
162 - This->queue[This->queue_write++] = size;
163 - size -= 2;
164 - for (int i = 0; i < paramcount; i++)
165 - {
166 - argsize = va_arg(params, int);
167 - argptr = va_arg(params, void*);
168 - if (!argsize)
169 - {
170 - This->queue[This->queue_write++] = argsize;
171 - size -= 1;
172 - continue;
173 - }
174 - if ((NextMultipleOf4(argsize) / 4) > size) break;
175 - This->queue[This->queue_write++] = argsize;
176 - if (argptr) memcpy(This->queue + This->queue_write, argptr, argsize);
177 - This->queue_write += (NextMultipleOf4(argsize) / 4);
178 - size -= 1 + (NextMultipleOf4(argsize) / 4);
179 - }
180 - va_end(params);
181 - if (size != 0)
182 - {
183 - FIXME("Opcode size mismatch!\n")
184 - }
185 - This->queuelength++;
186 - if (!This->running) SetEvent(This->start);
187 - LeaveCriticalSection(&This->queuecs);
188 - return 0;
189 -}
190 -
191 -/**
192 -* Waits until the specified amount of queue space is free
193 -* @param This
194 -* Pointer to glRenderer object
195 -* @param size
196 -* If nonzero, the number of DWORDs that must be available within the queue.
197 -* If zero, waits until the queue is empty.
198 -*/
199 -void glRenderer_Sync(glRenderer *This, int size)
200 -{
201 - EnterCriticalSection(&This->queuecs);
202 - if (!This->queuelength && !This->running)
203 - {
204 - LeaveCriticalSection(&This->queuecs);
205 - return;
206 - }
207 - ResetEvent(This->sync);
208 - This->syncsize = size;
209 - if (!This->running) SetEvent(This->start);
210 - LeaveCriticalSection(&This->queuecs);
211 - WaitForSingleObject(This->sync, INFINITE);
212 -}
213 -
214 -/**
21582 * Internal function for uploading surface content to an OpenGL texture
21683 * @param This
21784 * Pointer to glRenderer object
21885 * @param buffer
21986 * Contains the contents of the surface
 87+ * @param bigbuffer
 88+ * Optional buffer to receive the rescaled surface contents, for when primary
 89+ * scaling is enabled.
22090 * @param texture
22191 * Texture object to upload to
22292 * @param x,y
22393 * Width and height of the surface
 94+ * @param bigx,bigy
 95+ * Width and height of the scaled surface buffer
22496 * @param pitch
22597 * Bytes from one line of graphics to the next in the surface
 98+ * @param bigpitch
 99+ * Pitch of the scaled surface buffer
 100+ * @param bpp
 101+ * Number of bits per surface pixel
226102 * @param miplevel
227103 * Mipmap level of texture to write
228104 */
229 -void glRenderer__UploadTexture(glRenderer *This, BYTE *buffer, TEXTURE *texture,
230 - DWORD x, DWORD y, DWORD pitch, DWORD miplevel)
 105+void glRenderer__UploadTexture(glRenderer *This, char *buffer, char *bigbuffer, TEXTURE *texture, int x, int y,
 106+ int bigx, int bigy, int pitch, int bigpitch, int bpp, int miplevel)
231107 {
232 - TextureManager__UploadTexture(This->texman, texture, miplevel, buffer, x, y, FALSE, FALSE);
233 -}
234 -
235 -/**
236 -* Uploads the content of a surface to an OpenGL texture, called from the backend.
237 -* @param This
238 -* Pointer to glRenderer object
239 -* @param buffer
240 -* Contains the contents of the surface
241 -* @param bigbuffer
242 -* Optional buffer to receive the rescaled surface contents, for when primary
243 -* scaling is enabled. Scaling will be performed before the surface is uploaded.
244 -* @param texture
245 -* Texture object to upload to
246 -* @param x,y
247 -* Width and height of the surface
248 -* @param bigx,bigy
249 -* Width and height of the scaled surface buffer
250 -* @param pitch
251 -* Bytes from one line of graphics to the next in the surface
252 -* @param bigpitch
253 -* Pitch of the scaled surface buffer
254 -* @param bpp
255 -* Number of bits per surface pixel
256 -* @param miplevel
257 -* Mipmap level of texture to write
258 -*/
259 -void glRenderer__UploadTextureSurface(glRenderer *This, BYTE *buffer, BYTE *bigbuffer, TEXTURE *texture, DWORD x, DWORD y, DWORD bigx, DWORD bigy, DWORD pitch, DWORD bigpitch, DWORD bpp, DWORD miplevel)
260 -{
261 - BYTE *outbuffer;
262 - DWORD outx, outy, outpitch, outbpp;
263 - if (bpp == 15) outbpp = 16;
264 - else outbpp = bpp;
265 - if ((x == bigx && y == bigy) || !bigbuffer)
 108+ if(bpp == 15) bpp = 16;
 109+ if((x == bigx && y == bigy) || !bigbuffer)
266110 {
267 - outbuffer = buffer;
268 - outx = x;
269 - outy = y;
270 - outpitch = pitch;
 111+ TextureManager__UploadTexture(This->texman, texture, miplevel, buffer, x, y, FALSE, FALSE);
271112 }
272113 else
273114 {
274 - switch (outbpp)
 115+ switch(bpp)
275116 {
276117 case 8:
277 - ScaleNearest8(bigbuffer, buffer, bigx, bigy, x, y, pitch, bigpitch);
 118+ ScaleNearest8(bigbuffer,buffer,bigx,bigy,x,y,pitch,bigpitch);
278119 break;
279120 case 16:
280 - ScaleNearest16(bigbuffer, buffer, bigx, bigy, x, y, pitch / 2, bigpitch / 2);
 121+ ScaleNearest16(bigbuffer,buffer,bigx,bigy,x,y,pitch/2,bigpitch/2);
281122 break;
282123 case 24:
283 - ScaleNearest24(bigbuffer, buffer, bigx, bigy, x, y, pitch, bigpitch);
 124+ ScaleNearest24(bigbuffer,buffer,bigx,bigy,x,y,pitch,bigpitch);
284125 break;
285126 case 32:
286 - ScaleNearest32(bigbuffer, buffer, bigx, bigy, x, y, pitch / 4, bigpitch / 4);
 127+ ScaleNearest32(bigbuffer,buffer,bigx,bigy,x,y,pitch/4,bigpitch/4);
287128 break;
288 - break;
 129+ break;
289130 }
290 - outbuffer = bigbuffer;
291 - outx = bigx;
292 - outy = bigy;
293 - outpitch = bigpitch;
 131+ TextureManager__UploadTexture(This->texman, texture, miplevel, bigbuffer, bigx, bigy, FALSE, FALSE);
294132 }
295 - glRenderer__UploadTexture(This, outbuffer, texture, outx, outy, outpitch, miplevel);
296133 }
297134
298135 /**
299 - * Internal function for downloading surface content from an OpenGL texture.
300 - * Forwards the request to the Texture Manager.
 136+ * Internal function for downloading surface content from an OpenGL texture
301137 * @param This
302138 * Pointer to glRenderer object
303139 * @param buffer
304140 * Buffer to receive the surface contents
 141+ * @param bigbuffer
 142+ * Optional buffer to receive the rescaled surface contents, for when primary
 143+ * scaling is enabled.
305144 * @param texture
306145 * Texture object to download from
 146+ * @param x,y
 147+ * Width and height of the surface
 148+ * @param bigx,bigy
 149+ * Width and height of the scaled surface buffer
 150+ * @param pitch
 151+ * Bytes from one line of graphics to the next in the surface
 152+ * @param bigpitch
 153+ * Pitch of the scaled surface buffer
 154+ * @param bpp
 155+ * Number of bits per surface pixel
307156 * @param miplevel
308157 * Mipmap level of texture to read
309158 */
310 -void glRenderer__DownloadTexture(glRenderer *This, BYTE *buffer, TEXTURE *texture, DWORD miplevel)
 159+void glRenderer__DownloadTexture(glRenderer *This, char *buffer, char *bigbuffer, TEXTURE *texture, int x, int y,
 160+ int bigx, int bigy, int pitch, int bigpitch, int bpp, int miplevel)
311161 {
312 - TextureManager__DownloadTexture(This->texman,texture,miplevel,buffer);
 162+ if((bigx == x && bigy == y) || !bigbuffer)
 163+ {
 164+ TextureManager__DownloadTexture(This->texman,texture,miplevel,buffer);
 165+ }
 166+ else
 167+ {
 168+ TextureManager__DownloadTexture(This->texman,texture,miplevel,bigbuffer);
 169+ switch(bpp)
 170+ {
 171+ case 8:
 172+ ScaleNearest8(buffer,bigbuffer,x,y,bigx,bigy,bigpitch,pitch);
 173+ break;
 174+ case 15:
 175+ case 16:
 176+ ScaleNearest16(buffer,bigbuffer,x,y,bigx,bigy,bigpitch/2,pitch/2);
 177+ break;
 178+ case 24:
 179+ ScaleNearest24(buffer,bigbuffer,x,y,bigx,bigy,bigpitch,pitch);
 180+ break;
 181+ case 32:
 182+ ScaleNearest32(buffer,bigbuffer,x,y,bigx,bigy,bigpitch/4,pitch/4);
 183+ break;
 184+ break;
 185+ }
 186+ }
313187 }
314188
315189 /**
@@ -327,7 +201,7 @@
328202 * @param devwnd
329203 * True if creating window with name "DirectDrawDeviceWnd"
330204 */
331 -void glRenderer_Init(glRenderer *This, DWORD width, DWORD height, DWORD bpp, BOOL fullscreen, DWORD frequency, HWND hwnd, glDirectDraw7 *glDD7, BOOL devwnd)
 205+void glRenderer_Init(glRenderer *This, int width, int height, int bpp, bool fullscreen, unsigned int frequency, HWND hwnd, glDirectDraw7 *glDD7, BOOL devwnd)
332206 {
333207 LONG_PTR winstyle, winstyleex;
334208 This->oldswap = 0;
@@ -340,12 +214,11 @@
341215 This->hRC = NULL;
342216 This->PBO = 0;
343217 This->dib.enabled = false;
344 - This->running = FALSE;
345218 This->hWnd = hwnd;
346 - This->busy = CreateEvent(NULL, FALSE, FALSE, NULL);
347 - InitializeCriticalSection(&This->commandcs);
348 - InitializeCriticalSection(&This->queuecs);
349 - if (fullscreen)
 219+ InitializeCriticalSection(&This->cs);
 220+ This->busy = CreateEvent(NULL,FALSE,FALSE,NULL);
 221+ This->start = CreateEvent(NULL,FALSE,FALSE,NULL);
 222+ if(fullscreen)
350223 {
351224 winstyle = GetWindowLongPtrA(This->hWnd, GWL_STYLE);
352225 winstyleex = GetWindowLongPtrA(This->hWnd, GWL_EXSTYLE);
@@ -357,7 +230,6 @@
358231 {
359232 // TODO: Adjust window rect
360233 }
361 - EnterCriticalSection(&This->commandcs);
362234 SetWindowPos(This->hWnd,HWND_TOP,0,0,0,0,SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED);
363235 This->RenderWnd = new glRenderWindow(width,height,fullscreen,This->hWnd,glDD7,devwnd);
364236 This->inputs[0] = (void*)width;
@@ -367,9 +239,10 @@
368240 This->inputs[4] = (void*)frequency;
369241 This->inputs[5] = (void*)This->hWnd;
370242 This->inputs[6] = glDD7;
371 - This->hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)glRenderer__Entry, This, 0, NULL);
372 - WaitForSingleObject(This->busy, INFINITE);
373 - LeaveCriticalSection(&This->commandcs);
 243+ This->inputs[7] = This;
 244+ This->inputs[8] = (void*)devwnd;
 245+ This->hThread = CreateThread(NULL, 0, glRenderer_ThreadEntry, This->inputs, 0, NULL);
 246+ WaitForSingleObject(This->busy,INFINITE);
374247 }
375248
376249 /**
@@ -379,19 +252,30 @@
380253 */
381254 void glRenderer_Delete(glRenderer *This)
382255 {
383 - MSG Msg;
384 - EnterCriticalSection(&This->commandcs);
385 - glRenderer_AddQueue(This, OP_DELETE, 0, 2, 0);
386 - LeaveCriticalSection(&This->commandcs);
387 - WaitForObjectAndMessages(This->hThread);
388 - DeleteCriticalSection(&This->commandcs);
 256+ EnterCriticalSection(&This->cs);
 257+ This->opcode = OP_DELETE;
 258+ SetEvent(This->start);
 259+ WaitForObjectAndMessages(This->busy);
 260+ CloseHandle(This->start);
389261 CloseHandle(This->busy);
390 - CloseHandle(This->sync);
391 - CloseHandle(This->start);
 262+ LeaveCriticalSection(&This->cs);
 263+ DeleteCriticalSection(&This->cs);
392264 CloseHandle(This->hThread);
393265 }
394266
395267 /**
 268+ * Entry point for the renderer thread
 269+ * @param entry
 270+ * Pointer to the inputs passed by the CreateThread function
 271+ */
 272+DWORD WINAPI glRenderer_ThreadEntry(void *entry)
 273+{
 274+ void **inputsin = (void**)entry;
 275+ glRenderer *This = (glRenderer*)inputsin[7];
 276+ return glRenderer__Entry(This);
 277+}
 278+
 279+/**
396280 * Creates an OpenGL texture.
397281 * @param This
398282 * Pointer to glRenderer object
@@ -412,10 +296,14 @@
413297 */
414298 void glRenderer_MakeTexture(glRenderer *This, TEXTURE *texture, DWORD width, DWORD height)
415299 {
416 - EnterCriticalSection(&This->commandcs);
417 - glRenderer_AddQueue(This, OP_CREATE, 0, 8, 3, 4, &texture, 4, &width, 4, &height);
418 - glRenderer_Sync(This, 0);
419 - LeaveCriticalSection(&This->commandcs);
 300+ EnterCriticalSection(&This->cs);
 301+ This->inputs[0] = texture;
 302+ This->inputs[1] = (void*)width;
 303+ This->inputs[2] = (void*)height;
 304+ This->opcode = OP_CREATE;
 305+ SetEvent(This->start);
 306+ WaitForSingleObject(This->busy,INFINITE);
 307+ LeaveCriticalSection(&This->cs);
420308 }
421309
422310 /**
@@ -426,7 +314,7 @@
427315 * Contains the contents of the surface
428316 * @param bigbuffer
429317 * Optional buffer to receive the rescaled surface contents, for when primary
430 - * scaling is enabled. Scaling will be performed before the surface is uploaded.
 318+ * scaling is enabled.
431319 * @param texture
432320 * Texture object to upload to
433321 * @param x,y
@@ -442,50 +330,25 @@
443331 * @param miplevel
444332 * Mipmap level of texture to write
445333 */
446 -void glRenderer_UploadTexture(glRenderer *This, BYTE *buffer, BYTE *bigbuffer, TEXTURE *texture, DWORD x, DWORD y,
447 - DWORD bigx, DWORD bigy, DWORD pitch, DWORD bigpitch, DWORD bpp, DWORD miplevel)
 334+void glRenderer_UploadTexture(glRenderer *This, char *buffer, char *bigbuffer, TEXTURE *texture, int x, int y,
 335+ int bigx, int bigy, int pitch, int bigpitch, int bpp, int miplevel)
448336 {
449 - BYTE *outbuffer;
450 - DWORD outx, outy, outpitch, outbpp;
451 - DWORD *opbuffer;
452 - DWORD uploadopsize;
453 - if (bpp == 15) outbpp = 16;
454 - else outbpp = bpp;
455 - if ((x == bigx && y == bigy) || !bigbuffer)
456 - {
457 - outbuffer = buffer;
458 - outx = x;
459 - outy = y;
460 - outpitch = pitch;
461 - }
462 - else
463 - {
464 - switch (outbpp)
465 - {
466 - case 8:
467 - ScaleNearest8(bigbuffer, buffer, bigx, bigy, x, y, pitch, bigpitch);
468 - break;
469 - case 16:
470 - ScaleNearest16(bigbuffer, buffer, bigx, bigy, x, y, pitch / 2, bigpitch / 2);
471 - break;
472 - case 24:
473 - ScaleNearest24(bigbuffer, buffer, bigx, bigy, x, y, pitch, bigpitch);
474 - break;
475 - case 32:
476 - ScaleNearest32(bigbuffer, buffer, bigx, bigy, x, y, pitch / 4, bigpitch / 4);
477 - break;
478 - break;
479 - }
480 - outbuffer = bigbuffer;
481 - outx = bigx;
482 - outy = bigy;
483 - outpitch = bigpitch;
484 - }
485 - EnterCriticalSection(&This->commandcs);
486 - glRenderer_AddQueue(This, OP_UPLOAD, 0, 14, 6, 4, &outbuffer, 4, &texture, 4, &outx, 4, &outy,
487 - 4, &outpitch, 4, &miplevel);
488 - glRenderer_Sync(This, 0);
489 - LeaveCriticalSection(&This->commandcs);
 337+ EnterCriticalSection(&This->cs);
 338+ This->inputs[0] = buffer;
 339+ This->inputs[1] = bigbuffer;
 340+ This->inputs[2] = texture;
 341+ This->inputs[3] = (void*)x;
 342+ This->inputs[4] = (void*)y;
 343+ This->inputs[5] = (void*)bigx;
 344+ This->inputs[6] = (void*)bigy;
 345+ This->inputs[7] = (void*)pitch;
 346+ This->inputs[8] = (void*)bigpitch;
 347+ This->inputs[9] = (void*)bpp;
 348+ This->inputs[10] = (void*)miplevel;
 349+ This->opcode = OP_UPLOAD;
 350+ SetEvent(This->start);
 351+ WaitForSingleObject(This->busy,INFINITE);
 352+ LeaveCriticalSection(&This->cs);
490353 }
491354
492355 /**
@@ -496,7 +359,7 @@
497360 * Buffer to receive the surface contents
498361 * @param bigbuffer
499362 * Optional buffer to receive the rescaled surface contents, for when primary
500 - * scaling is enabled. Scaling will be performed after the download is complete.
 363+ * scaling is enabled.
501364 * @param texture
502365 * Texture object to download from
503366 * @param x,y
@@ -512,52 +375,25 @@
513376 * @param miplevel
514377 * Mipmap level of texture to read
515378 */
516 -void glRenderer_DownloadTexture(glRenderer *This, BYTE *buffer, BYTE *bigbuffer, TEXTURE *texture, DWORD x, DWORD y,
517 - DWORD bigx, DWORD bigy, DWORD pitch, DWORD bigpitch, DWORD bpp, DWORD miplevel)
 379+void glRenderer_DownloadTexture(glRenderer *This, char *buffer, char *bigbuffer, TEXTURE *texture, int x, int y,
 380+ int bigx, int bigy, int pitch, int bigpitch, int bpp, int miplevel)
518381 {
519 - BOOL doscale;
520 - BYTE *inbuffer;
521 - DWORD inx, iny, inpitch;
522 - if ((x == bigx && y == bigy) || !bigbuffer)
523 - {
524 - doscale = FALSE;
525 - inbuffer = buffer;
526 - inx = x;
527 - iny = y;
528 - inpitch = pitch;
529 - }
530 - else
531 - {
532 - doscale = TRUE;
533 - inbuffer = bigbuffer;
534 - inx = bigx;
535 - iny = bigy;
536 - inpitch = bigpitch;
537 - }
538 - EnterCriticalSection(&This->commandcs);
539 - glRenderer_AddQueue(This, OP_DOWNLOAD, 0, 8, 3, 4, &inbuffer, 4, &texture, 4, &miplevel);
540 - glRenderer_Sync(This, 0);
541 - LeaveCriticalSection(&This->commandcs);
542 - if (doscale)
543 - {
544 - switch (bpp)
545 - {
546 - case 8:
547 - ScaleNearest8(buffer, bigbuffer, x, y, bigx, bigy, bigpitch, pitch);
548 - break;
549 - case 15:
550 - case 16:
551 - ScaleNearest16(buffer, bigbuffer, x, y, bigx, bigy, bigpitch / 2, pitch / 2);
552 - break;
553 - case 24:
554 - ScaleNearest24(buffer, bigbuffer, x, y, bigx, bigy, bigpitch, pitch);
555 - break;
556 - case 32:
557 - ScaleNearest32(buffer, bigbuffer, x, y, bigx, bigy, bigpitch / 4, pitch / 4);
558 - break;
559 - break;
560 - }
561 - }
 382+ EnterCriticalSection(&This->cs);
 383+ This->inputs[0] = buffer;
 384+ This->inputs[1] = bigbuffer;
 385+ This->inputs[2] = texture;
 386+ This->inputs[3] = (void*)x;
 387+ This->inputs[4] = (void*)y;
 388+ This->inputs[5] = (void*)bigx;
 389+ This->inputs[6] = (void*)bigy;
 390+ This->inputs[7] = (void*)pitch;
 391+ This->inputs[8] = (void*)bigpitch;
 392+ This->inputs[9] = (void*)bpp;
 393+ This->inputs[10] = (void*)miplevel;
 394+ This->opcode = OP_DOWNLOAD;
 395+ SetEvent(This->start);
 396+ WaitForSingleObject(This->busy,INFINITE);
 397+ LeaveCriticalSection(&This->cs);
562398 }
563399
564400 /**
@@ -569,9 +405,12 @@
570406 */
571407 void glRenderer_DeleteTexture(glRenderer *This, TEXTURE * texture)
572408 {
573 - EnterCriticalSection(&This->commandcs);
574 - glRenderer_AddQueue(This, OP_DELETETEX, 0, 4, 1, 4, &texture);
575 - LeaveCriticalSection(&This->commandcs);
 409+ EnterCriticalSection(&This->cs);
 410+ This->inputs[0] = texture;
 411+ This->opcode = OP_DELETETEX;
 412+ SetEvent(This->start);
 413+ WaitForSingleObject(This->busy,INFINITE);
 414+ LeaveCriticalSection(&This->cs);
576415 }
577416
578417 /**
@@ -589,36 +428,42 @@
590429 * entire surface will be used.
591430 * @param dwFlags
592431 * Flags to determine the behavior of the blitter. Certain flags control the
593 - * synchronization of the operation: (not yet fully implemented)
 432+ * synchronization of the operation: (not yet implemented)
594433 * - DDBLT_ASYNC: Adds the command to the queue. If the queue is full, returns
595434 * DDERR_WASSTILLDRAWING.
596435 * - DDBLT_DONOTWAIT: Fails and returns DDERR_WASSTILLDRAWING if the queue is full.
597 - * - DDBLT_WAIT: Waits until the Blt command is added to the queue before returning.
 436+ * - DDBLT_WAIT: Waits until the Blt command is processed before returning.
598437 * @param lpDDBltFx
599438 * Effect parameters for the Blt operation.
 439+ * @return
 440+ * DD_OK if the call succeeds, or DDERR_WASSTILLDRAWING if busy.
600441 */
601442 HRESULT glRenderer_Blt(glRenderer *This, LPRECT lpDestRect, glDirectDrawSurface7 *src,
602443 glDirectDrawSurface7 *dest, LPRECT lpSrcRect, DWORD dwFlags, LPDDBLTFX lpDDBltFx)
603444 {
604 - DWORD nullfx = 0xFFFFFFFF;
605 - RECT emptyrect = nullrect;
606 - EnterCriticalSection(&This->commandcs);
607 - int syncmode = 0;
608 - if (dwFlags & DDBLT_ASYNC) syncmode = 1;
609 - if (dwFlags & DDBLT_DONOTWAIT) syncmode = 2;
610 - if (!lpSrcRect) lpSrcRect = &emptyrect;
611 - if (!lpDestRect) lpDestRect = &emptyrect;
612 - int fxsize = 4;
613 - if (lpDDBltFx) fxsize = sizeof(DDBLTFX);
614 - else lpDDBltFx = (LPDDBLTFX)&nullfx;
615 - if (glRenderer_AddQueue(This, OP_BLT, syncmode, 11 + (sizeof(RECT) / 2) + (fxsize / 4), 6, sizeof(RECT), lpDestRect, 4, &src,
616 - 4, &dest, sizeof(RECT), lpSrcRect, 4, &dwFlags, fxsize, lpDDBltFx))
 445+ EnterCriticalSection(&This->cs);
 446+ RECT r,r2;
 447+ if(((dest->ddsd.ddsCaps.dwCaps & (DDSCAPS_FRONTBUFFER)) &&
 448+ (dest->ddsd.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)) ||
 449+ ((dest->ddsd.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE) &&
 450+ !(dest->ddsd.ddsCaps.dwCaps & DDSCAPS_FLIP)))
617451 {
618 - LeaveCriticalSection(&This->commandcs);
619 - return DDERR_WASSTILLDRAWING;
 452+ GetClientRect(This->hWnd,&r);
 453+ GetClientRect(This->RenderWnd->GetHWnd(),&r2);
 454+ if(memcmp(&r2,&r,sizeof(RECT)))
 455+ SetWindowPos(This->RenderWnd->GetHWnd(),NULL,0,0,r.right,r.bottom,SWP_SHOWWINDOW);
620456 }
621 - LeaveCriticalSection(&This->commandcs);
622 - return DD_OK;
 457+ This->inputs[0] = lpDestRect;
 458+ This->inputs[1] = src;
 459+ This->inputs[2] = dest;
 460+ This->inputs[3] = lpSrcRect;
 461+ This->inputs[4] = (void*)dwFlags;
 462+ This->inputs[5] = lpDDBltFx;
 463+ This->opcode = OP_BLT;
 464+ SetEvent(This->start);
 465+ WaitForSingleObject(This->busy,INFINITE);
 466+ LeaveCriticalSection(&This->cs);
 467+ return (HRESULT)This->outputs[0];
623468 }
624469
625470 /**
@@ -638,10 +483,16 @@
639484 */
640485 void glRenderer_DrawScreen(glRenderer *This, TEXTURE *texture, TEXTURE *paltex, glDirectDrawSurface7 *dest, glDirectDrawSurface7 *src, GLint vsync)
641486 {
642 - EnterCriticalSection(&This->commandcs);
643 - glRenderer_AddQueue(This, OP_DRAWSCREEN, 0, 12, 5, 4, &texture, 4, &paltex, 4, &dest, 4, &src, 4, &vsync);
644 - glRenderer_Sync(This, 0);
645 - LeaveCriticalSection(&This->commandcs);
 487+ EnterCriticalSection(&This->cs);
 488+ This->inputs[0] = texture;
 489+ This->inputs[1] = paltex;
 490+ This->inputs[2] = dest;
 491+ This->inputs[3] = src;
 492+ This->inputs[4] = (void*)vsync;
 493+ This->opcode = OP_DRAWSCREEN;
 494+ SetEvent(This->start);
 495+ WaitForSingleObject(This->busy,INFINITE);
 496+ LeaveCriticalSection(&This->cs);
646497 }
647498
648499 /**
@@ -653,9 +504,14 @@
654505 */
655506 void glRenderer_InitD3D(glRenderer *This, int zbuffer, int x, int y)
656507 {
657 - EnterCriticalSection(&This->commandcs);
658 - glRenderer_AddQueue(This, OP_INITD3D, 0, 8, 3, 4, &zbuffer, 4, &x, 4, &y);
659 - LeaveCriticalSection(&This->commandcs);
 508+ EnterCriticalSection(&This->cs);
 509+ This->inputs[0] = (void*)zbuffer;
 510+ This->inputs[1] = (void*)x;
 511+ This->inputs[2] = (void*)y;
 512+ This->opcode = OP_INITD3D;
 513+ SetEvent(This->start);
 514+ WaitForSingleObject(This->busy,INFINITE);
 515+ LeaveCriticalSection(&This->cs);
660516 }
661517
662518 /**
@@ -676,27 +532,38 @@
677533 * Value to fill the Z buffer with.
678534 * @param dwStencil
679535 * Value to fill the stencil buffer with.
 536+ * @return
 537+ * Returns D3D_OK
680538 */
681 -void glRenderer_Clear(glRenderer *This, glDirectDrawSurface7 *target, DWORD dwCount, LPD3DRECT lpRects, DWORD dwFlags, DWORD dwColor, D3DVALUE dvZ, DWORD dwStencil)
 539+HRESULT glRenderer_Clear(glRenderer *This, glDirectDrawSurface7 *target, DWORD dwCount, LPD3DRECT lpRects, DWORD dwFlags, DWORD dwColor, D3DVALUE dvZ, DWORD dwStencil)
682540 {
683 - EnterCriticalSection(&This->commandcs);
684 - int rectsize = dwCount * sizeof(D3DRECT);
685 - glRenderer_AddQueue(This, OP_CLEAR, 0, 15 + (rectsize / 4), 7, 4, &target, 4, &dwCount,
686 - 4, &dwFlags, 4, &dwColor, 4, &dvZ, 4, &dwStencil, rectsize, lpRects);
687 - LeaveCriticalSection(&This->commandcs);
 541+ EnterCriticalSection(&This->cs);
 542+ This->inputs[0] = target;
 543+ This->inputs[1] = (void*)dwCount;
 544+ This->inputs[2] = lpRects;
 545+ This->inputs[3] = (void*)dwFlags;
 546+ This->inputs[4] = (void*)dwColor;
 547+ memcpy(&This->inputs[5],&dvZ,4);
 548+ This->inputs[6] = (void*)dwStencil;
 549+ This->opcode = OP_CLEAR;
 550+ SetEvent(This->start);
 551+ WaitForSingleObject(This->busy,INFINITE);
 552+ LeaveCriticalSection(&This->cs);
 553+ return (HRESULT)This->outputs[0];
688554 }
689555
690556 /**
691 - * Instructs the OpenGL driver to send all queued commands to the GPU, and empties the queue.
 557+ * Instructs the OpenGL driver to send all queued commands to the GPU.
692558 * @param This
693559 * Pointer to glRenderer object
694560 */
695561 void glRenderer_Flush(glRenderer *This)
696562 {
697 - EnterCriticalSection(&This->commandcs);
698 - glRenderer_AddQueue(This, OP_CLEAR, 0, 2, 0, 0, NULL);
699 - glRenderer_Sync(This, 0);
700 - LeaveCriticalSection(&This->commandcs);
 563+ EnterCriticalSection(&This->cs);
 564+ This->opcode = OP_FLUSH;
 565+ SetEvent(This->start);
 566+ WaitForSingleObject(This->busy,INFINITE);
 567+ LeaveCriticalSection(&This->cs);
701568 }
702569
703570 /**
@@ -712,13 +579,26 @@
713580 * @param devwnd
714581 * True if creating window with name "DirectDrawDeviceWnd"
715582 */
716 -void glRenderer_SetWnd(glRenderer *This, DWORD width, DWORD height, DWORD bpp, DWORD fullscreen, DWORD frequency, HWND newwnd, BOOL devwnd)
 583+void glRenderer_SetWnd(glRenderer *This, int width, int height, int bpp, int fullscreen, unsigned int frequency, HWND newwnd, BOOL devwnd)
717584 {
718 - EnterCriticalSection(&This->commandcs);
719 - glRenderer_AddQueue(This, OP_SETWND, 0, 16, 7, 4, &width, 4, &height, 4, &bpp, 4, &fullscreen,
720 - 4, &frequency, 4, &newwnd, 4, &devwnd);
721 - glRenderer_Sync(This, 0);
722 - LeaveCriticalSection(&This->commandcs);
 585+ EnterCriticalSection(&This->cs);
 586+ if(fullscreen && newwnd)
 587+ {
 588+ SetWindowLongPtrA(newwnd,GWL_EXSTYLE,WS_EX_APPWINDOW);
 589+ SetWindowLongPtrA(newwnd,GWL_STYLE,WS_OVERLAPPED);
 590+ ShowWindow(newwnd,SW_MAXIMIZE);
 591+ }
 592+ This->inputs[0] = (void*)width;
 593+ This->inputs[1] = (void*)height;
 594+ This->inputs[2] = (void*)bpp;
 595+ This->inputs[3] = (void*)fullscreen;
 596+ This->inputs[4] = (void*)frequency;
 597+ This->inputs[5] = (void*)newwnd;
 598+ This->inputs[6] = (void*)devwnd;
 599+ This->opcode = OP_SETWND;
 600+ SetEvent(This->start);
 601+ WaitForObjectAndMessages(This->busy);
 602+ LeaveCriticalSection(&This->cs);
723603 }
724604 /**
725605 * Draws one or more primitives to the currently selected render target.
@@ -728,12 +608,12 @@
729609 * glDirect3DDevice7 interface to use for drawing
730610 * @param mode
731611 * OpenGL primitive drawing mode to use
732 - * @param stride
733 - * Distance between vertex sets in bytes
734612 * @param vertices
735613 * Pointer to vertex data
736 - * @param dwVertexTypeDesc
737 - * FVF flags for vertex type.
 614+ * @param packed
 615+ * True if vertex data is packed (e.g. xyz,normal,texcoord,xyz,normal,etc.)
 616+ * @param texformats
 617+ * Pointer to texture coordinate formats used in the call
738618 * @param count
739619 * Number of vertices to copy to the draw command
740620 * @param indices
@@ -742,25 +622,29 @@
743623 * @param indexcount
744624 * Number of vertex indices. May be 0 for non-indexed mode.
745625 * @param flags
746 - * Set to D3DDP_WAIT to wait until the queue has processed the call.
 626+ * Set to D3DDP_WAIT to wait until the queue has processed the call. (not yet
 627+ * implemented)
747628 * @return
748629 * D3D_OK if the call succeeds, or D3DERR_INVALIDVERTEXTYPE if the vertex format
749630 * has no position coordinates.
750631 */
751 -void glRenderer_DrawPrimitives(glRenderer *This, glDirect3DDevice7 *device, GLenum mode, DWORD stride, BYTE *vertices, DWORD dwVertexTypeDesc, DWORD count, LPWORD indices,
 632+HRESULT glRenderer_DrawPrimitives(glRenderer *This, glDirect3DDevice7 *device, GLenum mode, GLVERTEX *vertices, int *texformats, DWORD count, LPWORD indices,
752633 DWORD indexcount, DWORD flags)
753634 {
754 - EnterCriticalSection(&This->commandcs);
755 - DWORD vertsize = 0;
756 - DWORD indexsize = 0;
757 - if (!indices) indexcount = 0;
758 - vertsize = stride * count;
759 - indexsize = NextMultipleOf4(indexcount * 2);
760 - glRenderer_AddQueue(This, OP_DRAWPRIMITIVES, 0, 16 + ((vertsize + indexsize)/4), 8, 4, &device,
761 - 4, &mode, 4, &stride, 4, &dwVertexTypeDesc, 4, &count, 4, &indexcount,
762 - vertsize, vertices, indexsize, indices);
763 - if (flags & D3DDP_WAIT) glRenderer_Sync(This, 0);
764 - LeaveCriticalSection(&This->commandcs);
 635+ EnterCriticalSection(&This->cs);
 636+ This->inputs[0] = device;
 637+ This->inputs[1] = (void*)mode;
 638+ This->inputs[2] = vertices;
 639+ This->inputs[3] = texformats;
 640+ This->inputs[4] = (void*)count;
 641+ This->inputs[5] = indices;
 642+ This->inputs[6] = (void*)indexcount;
 643+ This->inputs[7] = (void*)flags;
 644+ This->opcode = OP_DRAWPRIMITIVES;
 645+ SetEvent(This->start);
 646+ WaitForSingleObject(This->busy,INFINITE);
 647+ LeaveCriticalSection(&This->cs);
 648+ return (HRESULT)This->outputs[0];
765649 }
766650
767651 /**
@@ -772,10 +656,12 @@
773657 */
774658 void glRenderer_DeleteFBO(glRenderer *This, FBO *fbo)
775659 {
776 - EnterCriticalSection(&This->commandcs);
777 - glRenderer_AddQueue(This, OP_DELETEFBO, 0, 4, 1, 4, &fbo);
778 - glRenderer_Sync(This, 0);
779 - LeaveCriticalSection(&This->commandcs);
 660+ EnterCriticalSection(&This->cs);
 661+ This->inputs[0] = fbo;
 662+ This->opcode = OP_DELETEFBO;
 663+ SetEvent(This->start);
 664+ WaitForSingleObject(This->busy,INFINITE);
 665+ LeaveCriticalSection(&This->cs);
780666 }
781667
782668 /**
@@ -787,9 +673,12 @@
788674 */
789675 void glRenderer_UpdateClipper(glRenderer *This, glDirectDrawSurface7 *surface)
790676 {
791 - EnterCriticalSection(&This->commandcs);
792 - glRenderer_AddQueue(This, OP_UPDATECLIPPER, 0, 4, 1, 4, &surface);
793 - LeaveCriticalSection(&This->commandcs);
 677+ EnterCriticalSection(&This->cs);
 678+ This->inputs[0] = surface;
 679+ This->opcode = OP_UPDATECLIPPER;
 680+ SetEvent(This->start);
 681+ WaitForSingleObject(This->busy,INFINITE);
 682+ LeaveCriticalSection(&This->cs);
794683 }
795684
796685
@@ -814,14 +703,17 @@
815704 * @param lpDDBltFx
816705 * Pointer to DDBLTFX structure with dwFillDepth defining the depth value.
817706 */
818 -void glRenderer_DepthFill(glRenderer *This, LPRECT lpDestRect, glDirectDrawSurface7 *dest, LPDDBLTFX lpDDBltFx)
 707+HRESULT glRenderer_DepthFill(glRenderer *This, LPRECT lpDestRect, glDirectDrawSurface7 *dest, LPDDBLTFX lpDDBltFx)
819708 {
820 - EnterCriticalSection(&This->commandcs);
821 - RECT emptyrect = nullrect;
822 - if (!lpDestRect) lpDestRect = &emptyrect;
823 - glRenderer_AddQueue(This, OP_DEPTHFILL, 0, 6 + (sizeof(RECT) / 4) + (sizeof(DDBLTFX) / 4),
824 - 3, 4, &dest, sizeof(RECT), lpDestRect, sizeof(DDBLTFX), lpDDBltFx);
825 - LeaveCriticalSection(&This->commandcs);
 709+ EnterCriticalSection(&This->cs);
 710+ This->inputs[0] = lpDestRect;
 711+ This->inputs[1] = dest;
 712+ This->inputs[2] = lpDDBltFx;
 713+ This->opcode = OP_DEPTHFILL;
 714+ SetEvent(This->start);
 715+ WaitForSingleObject(This->busy, INFINITE);
 716+ LeaveCriticalSection(&This->cs);
 717+ return (HRESULT)This->outputs[0];
826718 }
827719
828720 /**
@@ -835,10 +727,13 @@
836728 */
837729 void glRenderer_SetRenderState(glRenderer *This, D3DRENDERSTATETYPE dwRendStateType, DWORD dwRenderState)
838730 {
839 - EnterCriticalSection(&This->commandcs);
840 - if (!This->running) This->renderstate[dwRendStateType] = dwRenderState;
841 - else glRenderer_AddQueue(This, OP_SETRENDERSTATE, 0, 6, 2, 4, &dwRendStateType, 4, &dwRenderState);
842 - LeaveCriticalSection(&This->commandcs);
 731+ EnterCriticalSection(&This->cs);
 732+ This->inputs[0] = (void*)dwRendStateType;
 733+ This->inputs[1] = (void*)dwRenderState;
 734+ This->opcode = OP_SETRENDERSTATE;
 735+ SetEvent(This->start);
 736+ WaitForSingleObject(This->busy, INFINITE);
 737+ LeaveCriticalSection(&This->cs);
843738 }
844739
845740 /**
@@ -852,9 +747,13 @@
853748 */
854749 void glRenderer_SetTexture(glRenderer *This, DWORD dwStage, glDirectDrawSurface7 *Texture)
855750 {
856 - EnterCriticalSection(&This->commandcs);
857 - glRenderer_AddQueue(This, OP_SETTEXTURE, 0, 6, 2, 4, &dwStage, 4, &Texture);
858 - LeaveCriticalSection(&This->commandcs);
 751+ EnterCriticalSection(&This->cs);
 752+ This->inputs[0] = (void*)dwStage;
 753+ This->inputs[1] = Texture;
 754+ This->opcode = OP_SETTEXTURE;
 755+ SetEvent(This->start);
 756+ WaitForSingleObject(This->busy, INFINITE);
 757+ LeaveCriticalSection(&This->cs);
859758 }
860759
861760 /**
@@ -870,9 +769,14 @@
871770 */
872771 void glRenderer_SetTextureStageState(glRenderer *This, DWORD dwStage, D3DTEXTURESTAGESTATETYPE dwState, DWORD dwValue)
873772 {
874 - EnterCriticalSection(&This->commandcs);
875 - glRenderer_AddQueue(This, OP_SETTEXTURESTAGESTATE, 0, 8, 3, 4, &dwStage, 4, &dwState, 4, &dwValue);
876 - LeaveCriticalSection(&This->commandcs);
 773+ EnterCriticalSection(&This->cs);
 774+ This->inputs[0] = (void*)dwStage;
 775+ This->inputs[1] = (void*)dwState;
 776+ This->inputs[2] = (void*)dwValue;
 777+ This->opcode = OP_SETTEXTURESTAGESTATE;
 778+ SetEvent(This->start);
 779+ WaitForSingleObject(This->busy, INFINITE);
 780+ LeaveCriticalSection(&This->cs);
877781 }
878782
879783 /**
@@ -886,11 +790,13 @@
887791 */
888792 void glRenderer_SetTransform(glRenderer *This, D3DTRANSFORMSTATETYPE dtstTransformStateType, LPD3DMATRIX lpD3DMatrix)
889793 {
890 - EnterCriticalSection(&This->commandcs);
891 - if (!This->running) memcpy(&This->transform[dtstTransformStateType], lpD3DMatrix, sizeof(D3DMATRIX));
892 - else glRenderer_AddQueue(This, OP_SETTRANSFORM, 0, 5 + (sizeof(D3DMATRIX) / 4), 2,
893 - 4, &dtstTransformStateType, sizeof(D3DMATRIX), lpD3DMatrix);
894 - LeaveCriticalSection(&This->commandcs);
 794+ EnterCriticalSection(&This->cs);
 795+ This->inputs[0] = (void*)dtstTransformStateType;
 796+ This->inputs[1] = lpD3DMatrix;
 797+ This->opcode = OP_SETTRANSFORM;
 798+ SetEvent(This->start);
 799+ WaitForSingleObject(This->busy, INFINITE);
 800+ LeaveCriticalSection(&This->cs);
895801 }
896802
897803 /**
@@ -902,11 +808,12 @@
903809 */
904810 void glRenderer_SetMaterial(glRenderer *This, LPD3DMATERIAL7 lpMaterial)
905811 {
906 - EnterCriticalSection(&This->commandcs);
907 - if (!This->running) memcpy(&This->material, lpMaterial, sizeof(D3DMATERIAL7));
908 - glRenderer_AddQueue(This, OP_SETMATERIAL, 0, 3 + (sizeof(D3DMATERIAL7) / 4), 1,
909 - sizeof(D3DMATERIAL7), lpMaterial);
910 - LeaveCriticalSection(&This->commandcs);
 812+ EnterCriticalSection(&This->cs);
 813+ This->inputs[0] = lpMaterial;
 814+ This->opcode = OP_SETMATERIAL;
 815+ SetEvent(This->start);
 816+ WaitForSingleObject(This->busy, INFINITE);
 817+ LeaveCriticalSection(&This->cs);
911818 }
912819
913820 /**
@@ -923,15 +830,14 @@
924831
925832 void glRenderer_SetLight(glRenderer *This, DWORD index, LPD3DLIGHT7 light, BOOL remove)
926833 {
927 - EnterCriticalSection(&This->commandcs);
928 - D3DLIGHT7 null_light;
929 - D3DLIGHT7 *light7;
930 - DWORD _remove = remove;
931 - if (light) light7 = light;
932 - else light7 = &null_light;
933 - glRenderer_AddQueue(This, OP_SETLIGHT, 0, 7 + (sizeof(D3DLIGHT7) / 4), 3, 4, &index,
934 - 4, &_remove, sizeof(D3DLIGHT7), light7);
935 - LeaveCriticalSection(&This->commandcs);
 834+ EnterCriticalSection(&This->cs);
 835+ This->inputs[0] = (void*)index;
 836+ This->inputs[1] = light;
 837+ This->inputs[2] = (void*)remove;
 838+ This->opcode = OP_SETLIGHT;
 839+ SetEvent(This->start);
 840+ WaitForSingleObject(This->busy, INFINITE);
 841+ LeaveCriticalSection(&This->cs);
936842 }
937843
938844 /**
@@ -943,10 +849,12 @@
944850 */
945851 void glRenderer_SetViewport(glRenderer *This, LPD3DVIEWPORT7 lpViewport)
946852 {
947 - EnterCriticalSection(&This->commandcs);
948 - glRenderer_AddQueue(This, OP_SETVIEWPORT, 0, 3 + (sizeof(D3DVIEWPORT7) / 4), 1,
949 - sizeof(D3DVIEWPORT7), lpViewport);
950 - LeaveCriticalSection(&This->commandcs);
 853+ EnterCriticalSection(&This->cs);
 854+ This->inputs[0] = lpViewport;
 855+ This->opcode = OP_SETVIEWPORT;
 856+ SetEvent(This->start);
 857+ WaitForSingleObject(This->busy, INFINITE);
 858+ LeaveCriticalSection(&This->cs);
951859 }
952860
953861 /**
@@ -956,31 +864,19 @@
957865 * @return
958866 * Returns 0 to signal successful thread termination
959867 */
960 -DWORD WINAPI glRenderer__Entry(glRenderer *This)
 868+DWORD glRenderer__Entry(glRenderer *This)
961869 {
962870 float tmpfloats[16];
963 - RECT *r1;
964 - RECT *r2;
965 - WORD *indexptr;
966 - DDBLTFX *fxptr;
967 - glRenderer__InitGL(This, (DWORD)This->inputs[0], (DWORD)This->inputs[1], (DWORD)This->inputs[2],
968 - (BOOL)This->inputs[3],(DWORD)This->inputs[4], (HWND)This->inputs[5], (glDirectDraw7*)This->inputs[6]);
969 - This->dead = false;
970 - This->queue = (LPDWORD)malloc(1048576);
971 - This->queuesize = 1048576 / sizeof(DWORD);
972 - This->queuelength = This->queue_read = This->queue_write = This->syncsize = 0;
 871+ EnterCriticalSection(&This->cs);
 872+ glRenderer__InitGL(This,(int)This->inputs[0],(int)This->inputs[1],(int)This->inputs[2],
 873+ (int)This->inputs[3],(unsigned int)This->inputs[4],(HWND)This->inputs[5],
 874+ (glDirectDraw7*)This->inputs[6]);
 875+ LeaveCriticalSection(&This->cs);
973876 SetEvent(This->busy);
974 - This->start = CreateEvent(NULL, TRUE, FALSE, NULL);
975 - ResetEvent(This->start);
976 - This->sync = CreateEvent(NULL, TRUE, FALSE, NULL);
977 -queueloop:
978 - WaitForSingleObject(&This->start, INFINITE);
979 - if (This->queuelength)
 877+ while(1)
980878 {
981 - EnterCriticalSection(&This->queuecs);
982 - This->running = TRUE;
983 - LeaveCriticalSection(&This->queuecs);
984 - switch (This->queue[This->queue_read])
 879+ WaitForSingleObject(This->start,INFINITE);
 880+ switch(This->opcode)
985881 {
986882 case OP_DELETE:
987883 if(This->hRC)
@@ -1021,151 +917,90 @@
1022918 This->hDC = NULL;
1023919 delete This->RenderWnd;
1024920 This->RenderWnd = NULL;
1025 - This->dead = true;
 921+ SetEvent(This->busy);
 922+ return 0;
1026923 break;
1027 - case OP_NULL:
1028 - break;
1029924 case OP_SETWND:
1030 - if (This->queue[This->queue_read + 1] != 16) break;
1031 - glRenderer__SetWnd(This, (DWORD)This->queue[This->queue_read + 3], (DWORD)This->queue[This->queue_read + 5],
1032 - (DWORD)This->queue[This->queue_read + 7], (DWORD)This->queue[This->queue_read + 9], (DWORD)This->queue[This->queue_read + 11],
1033 - (HWND)This->queue[This->queue_read + 13], (BOOL)This->queue[This->queue_read + 15]);
 925+ glRenderer__SetWnd(This,(int)This->inputs[0],(int)This->inputs[1],(int)This->inputs[2],
 926+ (int)This->inputs[3],(unsigned int)This->inputs[4],(HWND)This->inputs[5],(BOOL)This->inputs[6]);
1034927 break;
1035928 case OP_CREATE:
1036 - if (This->queue[This->queue_read + 1] != 8) break;
1037 - glRenderer__MakeTexture(This, (TEXTURE*)This->queue[This->queue_read + 3],
1038 - (DWORD)This->queue[This->queue_read + 5], (DWORD)This->queue[This->queue_read + 7]);
 929+ glRenderer__MakeTexture(This,(TEXTURE*)This->inputs[0],(DWORD)This->inputs[1],(DWORD)This->inputs[2]);
 930+ SetEvent(This->busy);
1039931 break;
1040932 case OP_UPLOAD:
1041 - if (This->queue[This->queue_read + 1] != 14) break;
1042 - glRenderer__UploadTexture(This, (BYTE*)This->queue[This->queue_read + 3], (TEXTURE*)This->queue[This->queue_read + 5],
1043 - (DWORD)This->queue[This->queue_read + 7], (DWORD)This->queue[This->queue_read + 9],
1044 - (DWORD)This->queue[This->queue_read + 11], (DWORD)This->queue[This->queue_read + 13]);
 933+ glRenderer__UploadTexture(This,(char*)This->inputs[0],(char*)This->inputs[1],(TEXTURE*)This->inputs[2],
 934+ (int)This->inputs[3],(int)This->inputs[4],(int)This->inputs[5],(int)This->inputs[6],
 935+ (int)This->inputs[7],(int)This->inputs[8],(int)This->inputs[9],(int)This->inputs[10]);
 936+ SetEvent(This->busy);
1045937 break;
1046938 case OP_DOWNLOAD:
1047 - if (This->queue[This->queue_read + 1] != 8) break;
1048 - glRenderer__DownloadTexture(This, (BYTE*)This->queue[This->queue_read + 3],
1049 - (TEXTURE*)This->queue[This->queue_read + 5], (DWORD)This->queue[This->queue_read + 7]);
 939+ glRenderer__DownloadTexture(This,(char*)This->inputs[0],(char*)This->inputs[1],(TEXTURE*)This->inputs[2],
 940+ (int)This->inputs[3],(int)This->inputs[4],(int)This->inputs[5],(int)This->inputs[6],
 941+ (int)This->inputs[7],(int)This->inputs[8],(int)This->inputs[9],(int)This->inputs[10]);
 942+ SetEvent(This->busy);
1050943 break;
1051944 case OP_DELETETEX:
1052 - if (This->queue[This->queue_read + 1] != 4) break;
1053 - glRenderer__DeleteTexture(This, (TEXTURE*)This->queue[This->queue_read + 3]);
 945+ glRenderer__DeleteTexture(This,(TEXTURE*)This->inputs[0]);
1054946 break;
1055947 case OP_BLT:
1056 - if (This->queue[This->queue_read + 1] < (10 + (sizeof(RECT) / 2))) break;
1057 - r1 = (RECT*)&This->queue[This->queue_read + 3];
1058 - r2 = (RECT*)&This->queue[This->queue_read + 8 + (sizeof(RECT) / 4)];
1059 - if (!memcmp(r1, &nullrect, sizeof(RECT))) r1 = NULL;
1060 - if (!memcmp(r2, &nullrect, sizeof(RECT))) r2 = NULL;
1061 - if ((This->queue[This->queue_read + 10 + (sizeof(RECT) / 2)]) == 4) fxptr = NULL;
1062 - else fxptr = (DDBLTFX*)&This->queue[This->queue_read + 11 + (sizeof(RECT) / 2)];
1063 - glRenderer__Blt(This, r1, (glDirectDrawSurface7*)This->queue[This->queue_read + 4 + (sizeof(RECT) / 4)],
1064 - (glDirectDrawSurface7*)This->queue[This->queue_read + 6 + (sizeof(RECT) / 4)], r2,
1065 - (DWORD)This->queue[This->queue_read + 9 + (sizeof(RECT) / 2)], fxptr);
 948+ glRenderer__Blt(This,(LPRECT)This->inputs[0],(glDirectDrawSurface7*)This->inputs[1],
 949+ (glDirectDrawSurface7*)This->inputs[2],(LPRECT)This->inputs[3],(DWORD)This->inputs[4],(LPDDBLTFX)This->inputs[5]);
1066950 break;
1067951 case OP_DRAWSCREEN:
1068 - if (This->queue[This->queue_read + 1] != 12) break;
1069 - glRenderer__DrawScreen(This, (TEXTURE*)This->queue[This->queue_read + 3], (TEXTURE*)This->queue[This->queue_read + 5],
1070 - (glDirectDrawSurface7*)This->queue[This->queue_read + 7], (glDirectDrawSurface7*)This->queue[This->queue_read + 9],
1071 - (GLint)This->queue[This->queue_read + 11]);
 952+ glRenderer__DrawScreen(This,(TEXTURE*)This->inputs[0],(TEXTURE*)This->inputs[1],
 953+ (glDirectDrawSurface7*)This->inputs[2],(glDirectDrawSurface7*)This->inputs[3],(GLint)This->inputs[4],true);
1072954 break;
1073955 case OP_INITD3D:
1074 - if (This->queue[This->queue_read + 1] != 8) break;
1075 - glRenderer__InitD3D(This,(int)This->queue[This->queue_read+3],(int)This->queue[This->queue_read+5],
1076 - (int)This->queue[This->queue_read + 7]);
 956+ glRenderer__InitD3D(This,(int)This->inputs[0],(int)This->inputs[1],(int)This->inputs[2]);
1077957 break;
1078958 case OP_CLEAR:
1079 - if (This->queue[This->queue_read + 1] < 15) break;
1080 - if (This->queue[This->queue_read + 14] != 0) r1 = (RECT*)&This->queue[This->queue_read + 15];
1081 - else r1 = NULL;
1082 - glRenderer__Clear(This, (glDirectDrawSurface7*)This->queue[This->queue_read + 3], (DWORD)This->queue[This->queue_read + 5],
1083 - (LPD3DRECT)r1, (DWORD)This->queue[This->queue_read + 7], (DWORD)This->queue[This->queue_read + 9],
1084 - (D3DVALUE)This->queue[This->queue_read + 11], (DWORD)This->queue[This->queue_read + 13]);
 959+ memcpy(&tmpfloats[0],&This->inputs[5],4);
 960+ glRenderer__Clear(This,(glDirectDrawSurface7*)This->inputs[0],(DWORD)This->inputs[1],
 961+ (LPD3DRECT)This->inputs[2],(DWORD)This->inputs[3],(DWORD)This->inputs[4],tmpfloats[0],(DWORD)This->inputs[6]);
1085962 break;
1086963 case OP_FLUSH:
1087 - if (This->queue[This->queue_read + 1] != 2) break;
1088964 glRenderer__Flush(This);
1089965 break;
1090966 case OP_DRAWPRIMITIVES:
1091 - if (This->queue[This->queue_read + 1] < 16) break;
1092 - if (!This->queue[This->queue_read + 15 + (This->queue[This->queue_read + 14] / 4)]) indexptr = NULL;
1093 - else indexptr = (WORD*)&This->queue[This->queue_read + 16 + (This->queue[This->queue_read + 14] / 4)];
1094 - glRenderer__DrawPrimitives(This, (glDirect3DDevice7*)This->queue[This->queue_read + 3], (GLenum)This->queue[This->queue_read+5],
1095 - (DWORD)This->queue[This->queue_read + 7], (BYTE*)&This->queue[This->queue_read+15], (DWORD)This->queue[This->queue_read + 9],
1096 - (DWORD)This->queue[This->queue_read + 11], indexptr, (DWORD)This->queue[This->queue_read + 13], 0);
 967+ glRenderer__DrawPrimitives(This,(glDirect3DDevice7*)This->inputs[0],(GLenum)This->inputs[1],
 968+ (GLVERTEX*)This->inputs[2],(int*)This->inputs[3],(DWORD)This->inputs[4],(LPWORD)This->inputs[5],
 969+ (DWORD)This->inputs[6],(DWORD)This->inputs[7]);
1097970 break;
1098971 case OP_DELETEFBO:
1099 - if (This->queue[This->queue_read + 1] != 4) break;
1100 - glRenderer__DeleteFBO(This, (FBO*)This->queue[This->queue_read + 3]);
 972+ glRenderer__DeleteFBO(This,(FBO*)This->inputs[0]);
1101973 break;
1102974 case OP_UPDATECLIPPER:
1103 - if (This->queue[This->queue_read + 1] != 4) break;
1104 - glRenderer__UpdateClipper(This, (glDirectDrawSurface7*)This->queue[This->queue_read + 3]);
 975+ glRenderer__UpdateClipper(This,(glDirectDrawSurface7*)This->inputs[0]);
1105976 break;
1106977 case OP_DEPTHFILL:
1107 - if (This->queue[This->queue_read + 1] != (6 + (sizeof(RECT) / 4) + (sizeof(DDBLTFX) / 4))) break;
1108 - r1 = (RECT*)&This->queue[This->queue_read + 5];
1109 - if (!memcmp(r1, &nullrect, sizeof(RECT))) r1 = NULL;
1110 - glRenderer__DepthFill(This, r1, (glDirectDrawSurface7*)This->queue[This->queue_read + 3],
1111 - (LPDDBLTFX)&This->queue[This->queue_read + 6 + (sizeof(RECT) / 4)]);
 978+ glRenderer__DepthFill(This, (LPRECT)This->inputs[0], (glDirectDrawSurface7*)This->inputs[1],
 979+ (LPDDBLTFX)This->inputs[2]);
1112980 break;
1113981 case OP_SETRENDERSTATE:
1114 - if (This->queue[This->queue_read + 1] != 6) break;
1115 - glRenderer__SetRenderState(This, (D3DRENDERSTATETYPE)This->queue[This->queue_read + 3],
1116 - (DWORD)This->queue[This->queue_read + 5]);
 982+ glRenderer__SetRenderState(This, (D3DRENDERSTATETYPE)(DWORD)This->inputs[0], (DWORD)This->inputs[1]);
1117983 break;
1118984 case OP_SETTEXTURE:
1119 - if (This->queue[This->queue_read + 1] != 6) break;
1120 - glRenderer__SetTexture(This, (DWORD)This->queue[This->queue_read + 3],
1121 - (glDirectDrawSurface7*)This->queue[This->queue_read + 5]);
 985+ glRenderer__SetTexture(This, (DWORD)This->inputs[0], (glDirectDrawSurface7*)This->inputs[1]);
1122986 break;
1123987 case OP_SETTEXTURESTAGESTATE:
1124 - if (This->queue[This->queue_read + 1] != 8) break;
1125 - glRenderer__SetTextureStageState(This, (DWORD)This->queue[This->queue_read + 3],
1126 - (D3DTEXTURESTAGESTATETYPE)This->queue[This->queue_read + 5], (DWORD)This->queue[This->queue_read + 7]);
 988+ glRenderer__SetTextureStageState(This, (DWORD)This->inputs[0], (D3DTEXTURESTAGESTATETYPE)(DWORD)This->inputs[1],
 989+ (DWORD)This->inputs[2]);
1127990 break;
1128991 case OP_SETTRANSFORM:
1129 - if (This->queue[This->queue_read + 1] != (5 + (sizeof(D3DMATRIX) / 4))) break;
1130 - glRenderer__SetTransform(This, (D3DTRANSFORMSTATETYPE)This->queue[This->queue_read + 3],
1131 - (LPD3DMATRIX)&This->queue[This->queue_read + 5]);
 992+ glRenderer__SetTransform(This, (D3DTRANSFORMSTATETYPE)(DWORD)This->inputs[0], (LPD3DMATRIX)This->inputs[1]);
1132993 break;
1133994 case OP_SETMATERIAL:
1134 - if (This->queue[This->queue_read + 1] != (3 + (sizeof(D3DMATERIAL7) / 4))) break;
1135 - glRenderer__SetMaterial(This, (LPD3DMATERIAL7)&This->queue[This->queue_read + 3]);
 995+ glRenderer__SetMaterial(This, (LPD3DMATERIAL7)This->inputs[0]);
1136996 break;
1137997 case OP_SETLIGHT:
1138 - if (This->queue[This->queue_read + 1] != (7 + (sizeof(D3DLIGHT7) / 4))) break;
1139 - glRenderer__SetLight(This, (DWORD)This->queue[This->queue_read + 3], (LPD3DLIGHT7)&This->queue[This->queue_read + 7],
1140 - (BOOL)This->queue[This->queue_read + 5]);
 998+ glRenderer__SetLight(This, (DWORD)This->inputs[0], (LPD3DLIGHT7)This->inputs[1], (BOOL)This->inputs[2]);
1141999 break;
11421000 case OP_SETVIEWPORT:
1143 - if (This->queue[This->queue_read + 1] != (3 + (sizeof(D3DVIEWPORT7) / 4))) break;
1144 - glRenderer__SetViewport(This, (LPD3DVIEWPORT7)&This->queue[This->queue_read + 3]);
 1001+ glRenderer__SetViewport(This, (LPD3DVIEWPORT7)This->inputs[0]);
11451002 break;
1146 - case OP_RESETQUEUE:
1147 - break;
1148 - default:
1149 - FIXME("Invalid opcode detected");
1150 - break;
11511003 }
1152 - EnterCriticalSection(&This->queuecs);
1153 - This->queuelength--;
1154 - This->queue_read += This->queue[This->queue_read + 1];
1155 - if ((This->queue_read >= This->syncsize) && This->syncsize != 0) SetEvent(This->sync);
11561004 }
1157 - else EnterCriticalSection(&This->queuecs);
1158 - if (!This->queuelength)
1159 - {
1160 - ResetEvent(This->start);
1161 - This->queue_read = 0;
1162 - This->queue_write = 0;
1163 - This->running = false;
1164 - SetEvent(This->sync);
1165 - }
1166 - LeaveCriticalSection(&This->queuecs);
1167 - if (!This->dead) goto queueloop;
1168 - free(This->queue);
1169 - This->queue = NULL;
11701005 return 0;
11711006 }
11721007
@@ -1187,7 +1022,7 @@
11881023 * @return
11891024 * TRUE if OpenGL has been initialized, FALSE otherwise.
11901025 */
1191 -BOOL glRenderer__InitGL(glRenderer *This, DWORD width, DWORD height, DWORD bpp, BOOL fullscreen, DWORD frequency, HWND hWnd, glDirectDraw7 *glDD7)
 1026+BOOL glRenderer__InitGL(glRenderer *This, int width, int height, int bpp, int fullscreen, unsigned int frequency, HWND hWnd, glDirectDraw7 *glDD7)
11921027 {
11931028 EnterCriticalSection(&dll_cs);
11941029 This->ddInterface = glDD7;
@@ -1684,7 +1519,9 @@
16851520 (ddsd.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)) ||
16861521 ((ddsd.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE) &&
16871522 !(ddsd.ddsCaps.dwCaps & DDSCAPS_FLIP)))
1688 - glRenderer__DrawScreen(This,dest->texture,dest->paltex,dest,dest,0);
 1523+ glRenderer__DrawScreen(This,dest->texture,dest->paltex,dest,dest,0,false);
 1524+ This->outputs[0] = DD_OK;
 1525+ SetEvent(This->busy);
16891526 }
16901527
16911528 void glRenderer__MakeTexture(glRenderer *This, TEXTURE *texture, DWORD width, DWORD height)
@@ -1799,7 +1636,7 @@
18001637 This->util->SetFBO((FBO*)NULL);
18011638 }
18021639
1803 -void glRenderer__DrawScreen(glRenderer *This, TEXTURE *texture, TEXTURE *paltex, glDirectDrawSurface7 *dest, glDirectDrawSurface7 *src, GLint vsync)
 1640+void glRenderer__DrawScreen(glRenderer *This, TEXTURE *texture, TEXTURE *paltex, glDirectDrawSurface7 *dest, glDirectDrawSurface7 *src, GLint vsync, bool setsync)
18041641 {
18051642 int progtype;
18061643 RECT r,r2;
@@ -1819,7 +1656,7 @@
18201657 GLint viewport[4];
18211658 if(src->dirty & 1)
18221659 {
1823 - glRenderer__UploadTextureSurface(This,src->buffer,src->bigbuffer,texture,src->ddsd.dwWidth,src->ddsd.dwHeight,
 1660+ glRenderer__UploadTexture(This,src->buffer,src->bigbuffer,texture,src->ddsd.dwWidth,src->ddsd.dwHeight,
18241661 src->fakex,src->fakey,src->ddsd.lPitch,
18251662 (NextMultipleOf4((This->ddInterface->GetBPPMultipleOf8()/8)*src->fakex)),
18261663 src->ddsd.ddpfPixelFormat.dwRGBBitCount,src->miplevel);
@@ -1950,11 +1787,14 @@
19511788 SelectObject(This->dib.hdc,hPrevObj);
19521789 ReleaseDC(This->RenderWnd->GetHWnd(),hRenderDC);
19531790 }
 1791+ if(setsync) SetEvent(This->busy);
 1792+
19541793 }
19551794
19561795 void glRenderer__DeleteTexture(glRenderer *This, TEXTURE *texture)
19571796 {
19581797 TextureManager__DeleteTexture(This->texman,texture);
 1798+ SetEvent(This->busy);
19591799 }
19601800
19611801 __int64 InitShaderState(glRenderer *renderer, DWORD *renderstate, TEXTURESTAGE *texstages, D3DLIGHT7 *lights)
@@ -2053,6 +1893,7 @@
20541894
20551895 void glRenderer__InitD3D(glRenderer *This, int zbuffer, int x, int y)
20561896 {
 1897+ SetEvent(This->busy);
20571898 glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST);
20581899 GLfloat ambient[] = {0.0,0.0,0.0,0.0};
20591900 if(zbuffer) This->util->DepthTest(true);
@@ -2083,6 +1924,7 @@
20841925
20851926 void glRenderer__Clear(glRenderer *This, glDirectDrawSurface7 *target, DWORD dwCount, LPD3DRECT lpRects, DWORD dwFlags, DWORD dwColor, D3DVALUE dvZ, DWORD dwStencil)
20861927 {
 1928+ This->outputs[0] = (void*)D3D_OK;
20871929 GLfloat color[4];
20881930 dwordto4float(dwColor,color);
20891931 do
@@ -2123,14 +1965,16 @@
21241966 else glClear(clearbits);
21251967 if(target->zbuffer) target->zbuffer->dirty |= 2;
21261968 target->dirty |= 2;
 1969+ SetEvent(This->busy);
21271970 }
21281971
21291972 void glRenderer__Flush(glRenderer *This)
21301973 {
21311974 glFlush();
 1975+ SetEvent(This->busy);
21321976 }
21331977
2134 -void glRenderer__SetWnd(glRenderer *This, DWORD width, DWORD height, DWORD fullscreen, DWORD bpp, DWORD frequency, HWND newwnd, BOOL devwnd)
 1978+void glRenderer__SetWnd(glRenderer *This, int width, int height, int bpp, int fullscreen, unsigned int frequency, HWND newwnd, BOOL devwnd)
21351979 {
21361980 if(newwnd != This->hWnd)
21371981 {
@@ -2168,6 +2012,8 @@
21692013 glRenderer__SetSwap(This,0);
21702014 This->util->SetViewport(0,0,width,height);
21712015 }
 2016+
 2017+ SetEvent(This->busy);
21722018 }
21732019
21742020 void glRenderer__SetBlend(glRenderer *This, DWORD src, DWORD dest)
@@ -2272,7 +2118,7 @@
22732119 This->util->BlendFunc(glsrc,gldest);
22742120 }
22752121
2276 -void glRenderer__DrawPrimitives(glRenderer *This, glDirect3DDevice7 *device, GLenum mode, DWORD stride, BYTE *vertices, DWORD dwVertexTypeDesc, DWORD count, LPWORD indices,
 2122+void glRenderer__DrawPrimitives(glRenderer *This, glDirect3DDevice7 *device, GLenum mode, GLVERTEX *vertices, int *texformats, DWORD count, LPWORD indices,
22772123 DWORD indexcount, DWORD flags)
22782124 {
22792125 bool transformed;
@@ -2281,140 +2127,113 @@
22822128 char strvar[] = "strX";
22832129 char strqvar[] = "strqX";
22842130 int i;
2285 - int ptr = 0;
2286 - int numtex;
2287 - int texcoords[8];
2288 - if ((dwVertexTypeDesc & D3DFVF_POSITION_MASK) == D3DFVF_XYZRHW) transformed = true;
 2131+ if(vertices[1].data) transformed = true;
22892132 else transformed = false;
2290 - This->shaderstate3d.stateid &= 0xFFFA3FFC7FFFFFFFi64;
 2133+ if(!vertices[0].data)
 2134+ {
 2135+ This->outputs[0] = (void*)DDERR_INVALIDPARAMS;
 2136+ SetEvent(This->busy);
 2137+ return;
 2138+ }
22912139 This->shaderstate3d.stateid &= 0xFFFA3FF87FFFFFFFi64;
2292 - int numtextures = (dwVertexTypeDesc & D3DFVF_TEXCOUNT_MASK) >> D3DFVF_TEXCOUNT_SHIFT;
 2140+ int numtextures = 0;
 2141+ for (i = 0; i < 8; i++)
 2142+ {
 2143+ This->shaderstate3d.texstageid[i] &= 0xFFE7FFFFFFFFFFFFi64;
 2144+ This->shaderstate3d.texstageid[i] |= (__int64)(texformats[i] - 1) << 51;
 2145+ if (vertices[i + 10].data) numtextures++;
 2146+ }
22932147 This->shaderstate3d.stateid |= (__int64)((numtextures-1)&7) << 31;
22942148 if (numtextures) This->shaderstate3d.stateid |= (1i64 << 34);
22952149 int blendweights = 0;
2296 - if (((dwVertexTypeDesc & D3DFVF_POSITION_MASK) >> 1) > 2)
2297 - blendweights = ((dwVertexTypeDesc & D3DFVF_POSITION_MASK) >> 1) - 2;
 2150+ for (i = 0; i < 5; i++)
 2151+ if (vertices[i + 2].data) blendweights++;
22982152 This->shaderstate3d.stateid |= (__int64)blendweights << 46;
2299 - if (transformed) This->shaderstate3d.stateid |= (1i64 << 50);
2300 - if (dwVertexTypeDesc & D3DFVF_DIFFUSE) This->shaderstate3d.stateid |= (1i64 << 35);
2301 - if (dwVertexTypeDesc & D3DFVF_SPECULAR) This->shaderstate3d.stateid |= (1i64 << 36);
2302 - if (dwVertexTypeDesc & D3DFVF_NORMAL) This->shaderstate3d.stateid |= (1i64 << 37);
2303 - numtex = (dwVertexTypeDesc & D3DFVF_TEXCOUNT_MASK) >> D3DFVF_TEXCOUNT_SHIFT;
2304 - for(i = 0; i < numtex; i++)
2305 - {
2306 - This->shaderstate3d.texstageid[i] &= 0xFFE7FFFFFFFFFFFFi64;
2307 - switch (dwVertexTypeDesc >> (16 + (2 * i)) & 3)
2308 - {
2309 - case 0: // st
2310 - texcoords[i] = 2;
2311 - break;
2312 - case 1: // str
2313 - texcoords[i] = 3;
2314 - break;
2315 - case 2: // strq
2316 - texcoords[i] = 4;
2317 - break;
2318 - case 3: // s
2319 - texcoords[i] = 1;
2320 - break;
2321 - }
2322 - This->shaderstate3d.texstageid[i] |= (__int64)(texcoords[i] - 1) << 51;
2323 - }
2324 - ShaderManager_SetShader(This->shaders, This->shaderstate3d.stateid, This->shaderstate3d.texstageid, 2);
2325 - _GENSHADER *prog = &This->shaders->gen3d->genshaders[This->shaders->gen3d->current_genshader].shader;
2326 - This->util->EnableArray(prog->attribs[0], true);
2327 - This->ext->glVertexAttribPointer(prog->attribs[0], 3, GL_FLOAT, false, stride, &vertices[ptr]);
2328 - ptr += 12;
2329 - if (transformed)
2330 - {
2331 - if (prog->attribs[1] != -1)
2332 - {
2333 - This->util->EnableArray(prog->attribs[1], true);
2334 - This->ext->glVertexAttribPointer(prog->attribs[1], 4, GL_FLOAT, false, stride, &vertices[ptr]);
2335 - }
2336 - ptr += 4;
2337 - }
2338 - else if (dwVertexTypeDesc & D3DFVF_RESERVED1) ptr += 4;
 2153+ if (vertices[1].data) This->shaderstate3d.stateid |= (1i64 << 50);
 2154+ if (vertices[8].data) This->shaderstate3d.stateid |= (1i64 << 35);
 2155+ if (vertices[9].data) This->shaderstate3d.stateid |= (1i64 << 36);
 2156+ if (vertices[7].data) This->shaderstate3d.stateid |= (1i64 << 37);
 2157+ ShaderManager_SetShader(This->shaders,This->shaderstate3d.stateid,This->shaderstate3d.texstageid,2);
23392158 glRenderer__SetDepthComp(This);
23402159 if(This->renderstate[D3DRENDERSTATE_ZENABLE]) This->util->DepthTest(true);
23412160 else This->util->DepthTest(false);
23422161 if(This->renderstate[D3DRENDERSTATE_ZWRITEENABLE]) This->util->DepthWrite(true);
23432162 else This->util->DepthWrite(false);
2344 - for(i = 0; i < blendweights; i++)
 2163+ _GENSHADER *prog = &This->shaders->gen3d->genshaders[This->shaders->gen3d->current_genshader].shader;
 2164+ This->util->EnableArray(prog->attribs[0],true);
 2165+ This->ext->glVertexAttribPointer(prog->attribs[0],3,GL_FLOAT,false,vertices[0].stride,vertices[0].data);
 2166+ if(transformed)
23452167 {
2346 - if(prog->attribs[i+2] != -1)
 2168+ if(prog->attribs[1] != -1)
23472169 {
2348 - This->util->EnableArray(prog->attribs[i+2],true);
2349 - This->ext->glVertexAttribPointer(prog->attribs[i + 2], 1, GL_FLOAT, false, stride, &vertices[ptr]);
 2170+ This->util->EnableArray(prog->attribs[1],true);
 2171+ This->ext->glVertexAttribPointer(prog->attribs[1],4,GL_FLOAT,false,vertices[1].stride,vertices[1].data);
23502172 }
2351 - ptr += 4;
23522173 }
2353 - if (dwVertexTypeDesc & D3DFVF_NORMAL)
 2174+ for(i = 0; i < 5; i++)
23542175 {
2355 - if(prog->attribs[7] != -1)
 2176+ if(vertices[i+2].data)
23562177 {
2357 - This->util->EnableArray(prog->attribs[7],true);
2358 - This->ext->glVertexAttribPointer(prog->attribs[7], 3, GL_FLOAT, false, stride, &vertices[ptr]);
 2178+ if(prog->attribs[i+2] != -1)
 2179+ {
 2180+ This->util->EnableArray(prog->attribs[i+2],true);
 2181+ This->ext->glVertexAttribPointer(prog->attribs[i+2],1,GL_FLOAT,false,vertices[i+2].stride,vertices[i+2].data);
 2182+ }
23592183 }
2360 - ptr += 12;
23612184 }
2362 - if (dwVertexTypeDesc & D3DFVF_DIFFUSE)
 2185+ if(vertices[7].data)
23632186 {
2364 - if (prog->attribs[8] != -1)
 2187+ if(prog->attribs[7] != -1)
23652188 {
2366 - This->util->EnableArray(prog->attribs[8], true);
2367 - This->ext->glVertexAttribPointer(prog->attribs[8], 4, GL_UNSIGNED_BYTE, true, stride, &vertices[ptr]);
 2189+ This->util->EnableArray(prog->attribs[7],true);
 2190+ This->ext->glVertexAttribPointer(prog->attribs[7],3,GL_FLOAT,false,vertices[7].stride,vertices[7].data);
23682191 }
2369 - ptr += 4;
23702192 }
2371 - if (dwVertexTypeDesc & D3DFVF_SPECULAR)
 2193+ for(i = 0; i < 2; i++)
23722194 {
2373 - if (prog->attribs[9] != -1)
 2195+ if(vertices[i+8].data)
23742196 {
2375 - This->util->EnableArray(prog->attribs[9], true);
2376 - This->ext->glVertexAttribPointer(prog->attribs[9], 4, GL_UNSIGNED_BYTE, true, stride, &vertices[ptr]);
 2197+ if(prog->attribs[8+i] != -1)
 2198+ {
 2199+ This->util->EnableArray(prog->attribs[8+i],true);
 2200+ This->ext->glVertexAttribPointer(prog->attribs[8+i],4,GL_UNSIGNED_BYTE,true,vertices[i+8].stride,vertices[i+8].data);
 2201+ }
23772202 }
2378 - ptr += 4;
23792203 }
2380 - for(i = 0; i < numtex; i++)
 2204+ for(i = 0; i < 8; i++)
23812205 {
23822206 {
2383 - switch(texcoords[i])
 2207+ switch(texformats[i])
23842208 {
23852209 case -1: // Null
2386 - default:
23872210 break;
23882211 case 1: // s
23892212 if (prog->attribs[i + 10] != -1)
23902213 {
23912214 This->util->EnableArray(prog->attribs[i + 10], true);
2392 - This->ext->glVertexAttribPointer(prog->attribs[i + 10], 1, GL_FLOAT, false, stride, &vertices[ptr]);
 2215+ This->ext->glVertexAttribPointer(prog->attribs[i + 10], 1, GL_FLOAT, false, vertices[i + 10].stride, vertices[i + 10].data);
23932216 }
2394 - ptr += 4;
23952217 break;
23962218 case 2: // st
23972219 if(prog->attribs[i+18] != -1)
23982220 {
23992221 This->util->EnableArray(prog->attribs[i+18],true);
2400 - This->ext->glVertexAttribPointer(prog->attribs[i + 18], 2, GL_FLOAT, false, stride, &vertices[ptr]);
 2222+ This->ext->glVertexAttribPointer(prog->attribs[i+18],2,GL_FLOAT,false,vertices[i+10].stride,vertices[i+10].data);
24012223 }
2402 - ptr += 8;
24032224 break;
24042225 case 3: // str
24052226 if(prog->attribs[i+26] != -1)
24062227 {
24072228 This->util->EnableArray(prog->attribs[i+26],true);
2408 - This->ext->glVertexAttribPointer(prog->attribs[i + 26], 3, GL_FLOAT, false, stride, &vertices[ptr]);
 2229+ This->ext->glVertexAttribPointer(prog->attribs[i+26],3,GL_FLOAT,false,vertices[i+10].stride,vertices[i+10].data);
24092230 }
2410 - ptr += 12;
24112231 break;
24122232 case 4: // strq
24132233 if(prog->attribs[i+34] != -1)
24142234 {
24152235 This->util->EnableArray(prog->attribs[i+34],true);
2416 - This->ext->glVertexAttribPointer(prog->attribs[i + 34], 4, GL_FLOAT, false, stride, &vertices[ptr]);
 2236+ This->ext->glVertexAttribPointer(prog->attribs[i+34],4,GL_FLOAT,false,vertices[i+10].stride,vertices[i+10].data);
24172237 }
2418 - ptr += 16;
24192238 break;
24202239 }
24212240
@@ -2478,7 +2297,7 @@
24792298 {
24802299 if(This->texstages[i].texture->dirty & 1)
24812300 {
2482 - glRenderer__UploadTextureSurface(This,This->texstages[i].texture->buffer,This->texstages[i].texture->bigbuffer,
 2301+ glRenderer__UploadTexture(This,This->texstages[i].texture->buffer,This->texstages[i].texture->bigbuffer,
24832302 This->texstages[i].texture->texture,This->texstages[i].texture->ddsd.dwWidth,
24842303 This->texstages[i].texture->ddsd.dwHeight,This->texstages[i].texture->fakex,
24852304 This->texstages[i].texture->fakey,This->texstages[i].texture->ddsd.lPitch,
@@ -2544,6 +2363,8 @@
25452364 if(device->glDDS7->zbuffer) device->glDDS7->zbuffer->dirty |= 2;
25462365 device->glDDS7->dirty |= 2;
25472366 if(flags & D3DDP_WAIT) glFlush();
 2367+ This->outputs[0] = (void*)D3D_OK;
 2368+ SetEvent(This->busy);
25482369 return;
25492370 }
25502371
@@ -2550,6 +2371,7 @@
25512372 void glRenderer__DeleteFBO(glRenderer *This, FBO *fbo)
25522373 {
25532374 This->util->DeleteFBO(fbo);
 2375+ SetEvent(This->busy);
25542376 }
25552377
25562378 void glRenderer__UpdateClipper(glRenderer *This, glDirectDrawSurface7 *surface)
@@ -2589,6 +2411,7 @@
25902412 This->ext->glDrawRangeElements(GL_TRIANGLES, 0, (6 * surface->clipper->clipsize) - 1,
25912413 6 * surface->clipper->clipsize, GL_UNSIGNED_SHORT, surface->clipper->indices);
25922414 This->util->SetFBO((FBO*)NULL);
 2415+ SetEvent(This->busy);
25932416 }
25942417
25952418 void glRenderer__DepthFill(glRenderer *This, LPRECT lpDestRect, glDirectDrawSurface7 *dest, LPDDBLTFX lpDDBltFx)
@@ -2648,11 +2471,13 @@
26492472 This->util->ClearDepth(lpDDBltFx->dwFillDepth / (double)0xFFFF);
26502473 glClear(GL_DEPTH_BUFFER_BIT);
26512474 if (lpDestRect)This->util->SetScissor(false, 0, 0, 0, 0);
 2475+ This->outputs[0] = DD_OK;
 2476+ SetEvent(This->busy);
26522477 }
26532478
26542479 void glRenderer__SetRenderState(glRenderer *This, D3DRENDERSTATETYPE dwRendStateType, DWORD dwRenderState)
26552480 {
2656 - if (dwRendStateType > 152) return;
 2481+ SetEvent(This->busy);
26572482 if (This->renderstate[dwRendStateType] == dwRenderState) return;
26582483 This->renderstate[dwRendStateType] = dwRenderState;
26592484 switch (dwRendStateType)
@@ -2755,7 +2580,11 @@
27562581
27572582 void glRenderer__SetTexture(glRenderer *This, DWORD dwStage, glDirectDrawSurface7 *Texture)
27582583 {
2759 - if (This->texstages[dwStage].texture == Texture) return;
 2584+ if (This->texstages[dwStage].texture == Texture)
 2585+ {
 2586+ SetEvent(This->busy);
 2587+ return;
 2588+ }
27602589 This->texstages[dwStage].texture = Texture;
27612590 if (Texture)
27622591 {
@@ -2764,10 +2593,12 @@
27652594 else This->shaderstate3d.texstageid[dwStage] &= 0xEFFFFFFFFFFFFFFFi64;
27662595 }
27672596 else This->shaderstate3d.texstageid[dwStage] &= 0xE7FFFFFFFFFFFFFFi64;
 2597+ SetEvent(This->busy);
27682598 }
27692599
27702600 void glRenderer__SetTextureStageState(glRenderer *This, DWORD dwStage, D3DTEXTURESTAGESTATETYPE dwState, DWORD dwValue)
27712601 {
 2602+ SetEvent(This->busy);
27722603 switch (dwState)
27732604 {
27742605 case D3DTSS_COLOROP:
@@ -2963,13 +2794,19 @@
29642795
29652796 void glRenderer__SetTransform(glRenderer *This, D3DTRANSFORMSTATETYPE dtstTransformStateType, LPD3DMATRIX lpD3DMatrix)
29662797 {
2967 - if (dtstTransformStateType > 23) return;
 2798+ if (dtstTransformStateType > 23)
 2799+ {
 2800+ SetEvent(This->busy);
 2801+ return;
 2802+ }
29682803 memcpy(&This->transform[dtstTransformStateType], lpD3DMatrix, sizeof(D3DMATRIX));
 2804+ SetEvent(This->busy);
29692805 }
29702806
29712807 void glRenderer__SetMaterial(glRenderer *This, LPD3DMATERIAL7 lpMaterial)
29722808 {
29732809 memcpy(&This->material, lpMaterial, sizeof(D3DMATERIAL));
 2810+ SetEvent(This->busy);
29742811 }
29752812
29762813 void glRenderer__SetLight(glRenderer *This, DWORD index, LPD3DLIGHT7 light, BOOL remove)
@@ -2978,6 +2815,7 @@
29792816 int lightindex = 0;
29802817 if(!remove)memcpy(&This->lights[index], light, sizeof(D3DLIGHT7));
29812818 else ZeroMemory(&This->lights[index], sizeof(D3DLIGHT7));
 2819+ SetEvent(This->busy);
29822820 for (int i = 0; i < 8; i++)
29832821 if (This->lights[i].dltType) numlights++;
29842822 This->shaderstate3d.stateid &= 0xF807C03FFFE3FFFFi64;
@@ -2999,6 +2837,7 @@
30002838 void glRenderer__SetViewport(glRenderer *This, LPD3DVIEWPORT7 lpViewport)
30012839 {
30022840 memcpy(&This->viewport, lpViewport, sizeof(D3DVIEWPORT7));
 2841+ SetEvent(This->busy);
30032842 }
30042843
30052844 void glRenderer__SetFogColor(glRenderer *This, DWORD color)
Index: ddraw/glRenderer.h
@@ -88,31 +88,32 @@
8989 };
9090
9191 #define OP_NULL 0
92 -#define OP_INIT 1
93 -#define OP_SETWND 2
94 -#define OP_DELETE 3
95 -#define OP_CREATE 4
96 -#define OP_UPLOAD 5
97 -#define OP_DOWNLOAD 6
98 -#define OP_DELETETEX 7
99 -#define OP_BLT 8
100 -#define OP_DRAWSCREEN 9
101 -#define OP_INITD3D 10
102 -#define OP_CLEAR 11
103 -#define OP_FLUSH 12
104 -#define OP_DRAWPRIMITIVES 13
105 -#define OP_DELETEFBO 14
106 -#define OP_UPDATECLIPPER 15
107 -#define OP_DEPTHFILL 16
108 -#define OP_SETRENDERSTATE 17
109 -#define OP_SETTEXTURE 18
110 -#define OP_SETTEXTURESTAGESTATE 19
111 -#define OP_SETTRANSFORM 20
112 -#define OP_SETMATERIAL 21
113 -#define OP_SETLIGHT 22
114 -#define OP_SETVIEWPORT 23
 92+#define OP_SETWND 1
 93+#define OP_DELETE 2
 94+#define OP_CREATE 3
 95+#define OP_UPLOAD 4
 96+#define OP_DOWNLOAD 5
 97+#define OP_DELETETEX 6
 98+#define OP_BLT 7
 99+#define OP_DRAWSCREEN 8
 100+#define OP_INITD3D 9
 101+#define OP_CLEAR 10
 102+#define OP_FLUSH 11
 103+#define OP_DRAWPRIMITIVES 12
 104+#define OP_DELETEFBO 13
 105+#define OP_UPDATECLIPPER 14
 106+#define OP_DEPTHFILL 15
 107+#define OP_SETRENDERSTATE 16
 108+#define OP_SETTEXTURE 17
 109+#define OP_SETTEXTURESTAGESTATE 18
 110+#define OP_SETTRANSFORM 19
 111+#define OP_SETMATERIAL 20
 112+#define OP_SETLIGHT 21
 113+#define OP_SETVIEWPORT 22
115114
116 -#define OP_RESETQUEUE 0xFFFFFFFF
 115+extern const DWORD renderstate_default[153];
 116+extern const TEXTURESTAGE texstagedefault0;
 117+extern const TEXTURESTAGE texstagedefault1;
117118
118119 #ifdef __cplusplus
119120 class glDirectDraw7;
@@ -119,6 +120,7 @@
120121 class glDirect3DDevice7;
121122 class glDirectDrawSurface7;
122123 class glRenderWindow;
 124+extern "C" {
123125 #else
124126 typedef int glDirectDraw7;
125127 typedef int glDirect3DDevice7;
@@ -126,14 +128,6 @@
127129 typedef int glRenderWindow;
128130 #endif
129131
130 -extern const DWORD renderstate_default[153];
131 -extern const TEXTURESTAGE texstagedefault0;
132 -extern const TEXTURESTAGE texstagedefault1;
133 -
134 -#ifdef __cplusplus
135 -extern "C" {
136 -#endif
137 -
138132 /** @brief glRenderer struct
139133 * OpenGL renderer structure for DXGL.
140134 */
@@ -143,8 +137,9 @@
144138 GLCAPS gl_caps;
145139 glExtensions *ext;
146140 glDirectDraw7 *ddInterface;
147 - void* inputs[7];
148 - void *output;
 141+ int opcode;
 142+ void* inputs[32];
 143+ void* outputs[32];
149144 HANDLE hThread;
150145 HDC hDC;
151146 HWND hWnd;
@@ -152,6 +147,9 @@
153148 DIB dib;
154149 FBO fbo;
155150 GLuint PBO;
 151+ CRITICAL_SECTION cs;
 152+ HANDLE busy;
 153+ HANDLE start;
156154 unsigned int frequency;
157155 DXGLTimer timer;
158156 TEXTURE *backbuffer;
@@ -173,27 +171,13 @@
174172 D3DLIGHT7 lights[8];
175173 D3DMATRIX transform[24];
176174 D3DVIEWPORT7 viewport;
177 - HANDLE busy;
178 - HANDLE start;
179 - HANDLE sync;
180 - BOOL running;
181 - CRITICAL_SECTION commandcs;
182 - CRITICAL_SECTION queuecs;
183 - LPDWORD queue;
184 - DWORD queuesize;
185 - DWORD queuelength;
186 - DWORD queue_read;
187 - DWORD queue_write;
188 - DWORD syncsize;
189 - BOOL dead;
190175 } glRenderer;
191176
192 -void glRenderer_Init(glRenderer *This, DWORD width, DWORD height, DWORD bpp, BOOL fullscreen, DWORD frequency, HWND hwnd, glDirectDraw7 *glDD7, BOOL devwnd);
 177+void glRenderer_Init(glRenderer *This, int width, int height, int bpp, bool fullscreen, unsigned int frequency, HWND hwnd, glDirectDraw7 *glDD7, BOOL devwnd);
193178 void glRenderer_Delete(glRenderer *This);
194 -int glRenderer_AddQueue(glRenderer *This, DWORD opcode, int mode, DWORD size, int paramcount, ...);
195 -void glRenderer_Sync(glRenderer *This, int size);
196 -void glRenderer_UploadTexture(glRenderer *This, BYTE *buffer, BYTE *bigbuffer, TEXTURE *texture, DWORD x, DWORD y, DWORD bigx, DWORD bigy, DWORD pitch, DWORD bigpitch, DWORD bpp, DWORD miplevel);
197 -void glRenderer_DownloadTexture(glRenderer *This, BYTE *buffer, BYTE *bigbuffer, TEXTURE *texture, DWORD x, DWORD y, DWORD bigx, DWORD bigy, DWORD pitch, DWORD bigpitch, DWORD bpp, DWORD miplevel);
 179+static DWORD WINAPI glRenderer_ThreadEntry(void *entry);
 180+void glRenderer_UploadTexture(glRenderer *This, char *buffer, char *bigbuffer, TEXTURE *texture, int x, int y, int bigx, int bigy, int pitch, int bigpitch, int bpp, int miplevel);
 181+void glRenderer_DownloadTexture(glRenderer *This, char *buffer, char *bigbuffer, TEXTURE *texture, int x, int y, int bigx, int bigy, int pitch, int bigpitch, int bpp, int miplevel);
198182 HRESULT glRenderer_Blt(glRenderer *This, LPRECT lpDestRect, glDirectDrawSurface7 *src,
199183 glDirectDrawSurface7 *dest, LPRECT lpSrcRect, DWORD dwFlags, LPDDBLTFX lpDDBltFx);
200184 void glRenderer_MakeTexture(glRenderer *This, TEXTURE *texture, DWORD width, DWORD height);
@@ -201,14 +185,14 @@
202186 void glRenderer_DeleteTexture(glRenderer *This, TEXTURE *texture);
203187 void glRenderer_InitD3D(glRenderer *This, int zbuffer, int x, int y);
204188 void glRenderer_Flush(glRenderer *This);
205 -void glRenderer_SetWnd(glRenderer *This, DWORD width, DWORD height, DWORD bpp, DWORD fullscreen, DWORD frequency, HWND newwnd, BOOL devwnd);
206 -void glRenderer_Clear(glRenderer *This, glDirectDrawSurface7 *target, DWORD dwCount, LPD3DRECT lpRects, DWORD dwFlags, DWORD dwColor, D3DVALUE dvZ, DWORD dwStencil);
207 -void glRenderer_DrawPrimitives(glRenderer *This, glDirect3DDevice7 *device, GLenum mode, DWORD stride, BYTE *vertices, DWORD dwVertexTypeDesc, DWORD count, LPWORD indices,
 189+void glRenderer_SetWnd(glRenderer *This, int width, int height, int bpp, int fullscreen, unsigned int frequency, HWND newwnd, BOOL devwnd);
 190+HRESULT glRenderer_Clear(glRenderer *This, glDirectDrawSurface7 *target, DWORD dwCount, LPD3DRECT lpRects, DWORD dwFlags, DWORD dwColor, D3DVALUE dvZ, DWORD dwStencil);
 191+HRESULT glRenderer_DrawPrimitives(glRenderer *This, glDirect3DDevice7 *device, GLenum mode, GLVERTEX *vertices, int *texformats, DWORD count, LPWORD indices,
208192 DWORD indexcount, DWORD flags);
209193 void glRenderer_DeleteFBO(glRenderer *This, FBO *fbo);
210194 void glRenderer_UpdateClipper(glRenderer *This, glDirectDrawSurface7 *surface);
211195 unsigned int glRenderer_GetScanLine(glRenderer *This);
212 -void glRenderer_DepthFill(glRenderer *This, LPRECT lpDestRect, glDirectDrawSurface7 *dest, LPDDBLTFX lpDDBltFx);
 196+HRESULT glRenderer_DepthFill(glRenderer *This, LPRECT lpDestRect, glDirectDrawSurface7 *dest, LPDDBLTFX lpDDBltFx);
213197 void glRenderer_SetRenderState(glRenderer *This, D3DRENDERSTATETYPE dwRendStateType, DWORD dwRenderState);
214198 void glRenderer_SetTexture(glRenderer *This, DWORD dwStage, glDirectDrawSurface7 *Texture);
215199 void glRenderer_SetTextureStageState(glRenderer *This, DWORD dwStage, D3DTEXTURESTAGESTATETYPE dwState, DWORD dwValue);
@@ -217,24 +201,23 @@
218202 void glRenderer_SetLight(glRenderer *This, DWORD index, LPD3DLIGHT7 light, BOOL remove);
219203 void glRenderer_SetViewport(glRenderer *This, LPD3DVIEWPORT7 lpViewport);
220204 // In-thread APIs
221 -DWORD WINAPI glRenderer__Entry(glRenderer *This);
222 -BOOL glRenderer__InitGL(glRenderer *This, DWORD width, DWORD height, DWORD bpp, BOOL fullscreen, DWORD frequency, HWND hWnd, glDirectDraw7 *glDD7);
223 -void glRenderer__UploadTexture(glRenderer *This, BYTE *buffer, TEXTURE *texture, DWORD x, DWORD y, DWORD pitch, DWORD miplevel);
224 -void glRenderer__UploadTextureSurface(glRenderer *This, BYTE *buffer, BYTE *bigbuffer, TEXTURE *texture, DWORD x, DWORD y, DWORD bigx, DWORD bigy, DWORD pitch, DWORD bigpitch, DWORD bpp, DWORD miplevel);
225 -void glRenderer__DownloadTexture(glRenderer *This, BYTE *buffer, TEXTURE *texture, DWORD miplevel);
 205+DWORD glRenderer__Entry(glRenderer *This);
 206+BOOL glRenderer__InitGL(glRenderer *This, int width, int height, int bpp, int fullscreen, unsigned int frequency, HWND hWnd, glDirectDraw7 *glDD7);
 207+void glRenderer__UploadTexture(glRenderer *This, char *buffer, char *bigbuffer, TEXTURE *texture, int x, int y, int bigx, int bigy, int pitch, int bigpitch, int bpp, int miplevel);
 208+void glRenderer__DownloadTexture(glRenderer *This, char *buffer, char *bigbuffer, TEXTURE *texture, int x, int y, int bigx, int bigy, int pitch, int bigpitch, int bpp, int miplevel);
226209 void glRenderer__Blt(glRenderer *This, LPRECT lpDestRect, glDirectDrawSurface7 *src,
227210 glDirectDrawSurface7 *dest, LPRECT lpSrcRect, DWORD dwFlags, LPDDBLTFX lpDDBltFx);
228211 void glRenderer__MakeTexture(glRenderer *This, TEXTURE *texture, DWORD width, DWORD height);
229 -void glRenderer__DrawScreen(glRenderer *This, TEXTURE *texture, TEXTURE *paltex, glDirectDrawSurface7 *dest, glDirectDrawSurface7 *src, GLint vsync);
 212+void glRenderer__DrawScreen(glRenderer *This, TEXTURE *texture, TEXTURE *paltex, glDirectDrawSurface7 *dest, glDirectDrawSurface7 *src, GLint vsync, bool setsync);
230213 void glRenderer__DeleteTexture(glRenderer *This, TEXTURE *texture);
231214 void glRenderer__DrawBackbuffer(glRenderer *This, TEXTURE **texture, int x, int y, int progtype);
232215 void glRenderer__DrawBackbufferRect(glRenderer *This, TEXTURE *texture, RECT srcrect, int progtype);
233216 void glRenderer__InitD3D(glRenderer *This, int zbuffer, int x, int y);
234217 void glRenderer__Clear(glRenderer *This, glDirectDrawSurface7 *target, DWORD dwCount, LPD3DRECT lpRects, DWORD dwFlags, DWORD dwColor, D3DVALUE dvZ, DWORD dwStencil);
235 -void glRenderer__DrawPrimitives(glRenderer *This, glDirect3DDevice7 *device, GLenum mode, DWORD stride, BYTE *vertices, DWORD dwVertexTypeDesc, DWORD count, LPWORD indices,
 218+void glRenderer__DrawPrimitives(glRenderer *This, glDirect3DDevice7 *device, GLenum mode, GLVERTEX *vertices, int *texcormats, DWORD count, LPWORD indices,
236219 DWORD indexcount, DWORD flags);
237220 void glRenderer__Flush(glRenderer *This);
238 -void glRenderer__SetWnd(glRenderer *This, DWORD width, DWORD height, DWORD fullscreen, DWORD bpp, DWORD frequency, HWND newwnd, BOOL devwnd);
 221+void glRenderer__SetWnd(glRenderer *This, int width, int height, int fullscreen, int bpp, unsigned int frequency, HWND newwnd, BOOL devwnd);
239222 void glRenderer__DeleteFBO(glRenderer *This, FBO *fbo);
240223 void glRenderer__UpdateClipper(glRenderer *This, glDirectDrawSurface7 *surface);
241224 void glRenderer__DepthFill(glRenderer *This, LPRECT lpDestRect, glDirectDrawSurface7 *dest, LPDDBLTFX lpDDBltFx);
Index: ddraw/timer.c
@@ -28,10 +28,10 @@
2929 QueryPerformanceFrequency(&freq);
3030 if (!freq.QuadPart)
3131 {
32 - /*timeGetDevCaps(&mmcaps, sizeof(TIMECAPS));
 32+ timeGetDevCaps(&mmcaps, sizeof(TIMECAPS));
3333 timeBeginPeriod(mmcaps.wPeriodMin);
3434 timer->timer_frequency = ((double) mmcaps.wPeriodMin / 1.0) * 1000.0;
35 - timer->timertype = 2;*/
 35+ timer->timertype = 2;
3636 }
3737 else
3838 {
@@ -52,7 +52,7 @@
5353 }
5454 else
5555 {
56 - //timer->timer_base.QuadPart = timeGetTime();
 56+ timer->timer_base.QuadPart = timeGetTime();
5757 linesperms = (double) lines / ((1.0 / (double) frequency) * 1000.0);
5858 timer->vsync_lines = (unsigned int)(linesperms * (frequency / 1000.0));
5959 timer->lines = lines + timer->vsync_lines;
@@ -65,7 +65,7 @@
6666 double sync_pos;
6767 double milliseconds;
6868 if (timer->timertype == 1) QueryPerformanceCounter(&timerpos);
69 - //else timerpos.QuadPart = timeGetTime();
 69+ else timerpos.QuadPart = timeGetTime();
7070 timerpos.QuadPart -= timer->timer_base.QuadPart;
7171 if (timer->timertype == 1) milliseconds = ((double) timerpos.QuadPart / (double)timer->timer_frequency) * 1000.0;
7272 else milliseconds = (double) timerpos.QuadPart;

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r590Remove texcoords parameter from shader ID.admin01:50, 6 February 2015