mirror of
https://github.com/FunkyFr3sh/cnc-ddraw.git
synced 2025-03-25 01:57:47 +01:00
add a header file for d3d9 renderer
This commit is contained in:
parent
28c9886dbe
commit
59f0f4d9b2
@ -26,6 +26,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="inc\clipper.h" />
|
<ClInclude Include="inc\clipper.h" />
|
||||||
|
<ClInclude Include="inc\d3d9renderer.h" />
|
||||||
<ClInclude Include="inc\ddraw.h" />
|
<ClInclude Include="inc\ddraw.h" />
|
||||||
<ClInclude Include="inc\debug.h" />
|
<ClInclude Include="inc\debug.h" />
|
||||||
<ClInclude Include="inc\glext.h" />
|
<ClInclude Include="inc\glext.h" />
|
||||||
|
@ -95,6 +95,9 @@
|
|||||||
<ClInclude Include="inc\d3d9shader.h">
|
<ClInclude Include="inc\d3d9shader.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="inc\d3d9renderer.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ResourceCompile Include="ddraw.rc">
|
<ResourceCompile Include="ddraw.rc">
|
||||||
|
11
inc/d3d9renderer.h
Normal file
11
inc/d3d9renderer.h
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
typedef struct CUSTOMVERTEX { float x, y, z, rhw, u, v; } CUSTOMVERTEX;
|
||||||
|
|
||||||
|
DWORD WINAPI render_d3d9_main(void);
|
||||||
|
BOOL Direct3D9_Create();
|
||||||
|
BOOL Direct3D9_Reset();
|
||||||
|
BOOL Direct3D9_Release();
|
||||||
|
BOOL Direct3D9_DeviceLost();
|
||||||
|
|
||||||
|
extern HMODULE Direct3D9_hModule;
|
@ -30,6 +30,9 @@
|
|||||||
|
|
||||||
extern BOOL ShowDriverWarning;
|
extern BOOL ShowDriverWarning;
|
||||||
|
|
||||||
|
BOOL detect_cutscene();
|
||||||
|
DWORD WINAPI render_soft_main(void);
|
||||||
|
|
||||||
struct IDirectDrawImpl;
|
struct IDirectDrawImpl;
|
||||||
struct IDirectDrawImplVtbl;
|
struct IDirectDrawImplVtbl;
|
||||||
struct IDirectDrawSurfaceImpl;
|
struct IDirectDrawSurfaceImpl;
|
||||||
|
27
src/main.c
27
src/main.c
@ -24,6 +24,7 @@
|
|||||||
#include "palette.h"
|
#include "palette.h"
|
||||||
#include "surface.h"
|
#include "surface.h"
|
||||||
#include "clipper.h"
|
#include "clipper.h"
|
||||||
|
#include "d3d9renderer.h"
|
||||||
|
|
||||||
#define IDR_MYMENU 93
|
#define IDR_MYMENU 93
|
||||||
|
|
||||||
@ -38,19 +39,11 @@ void mouse_unlock();
|
|||||||
BOOL screenshot(struct IDirectDrawSurfaceImpl *);
|
BOOL screenshot(struct IDirectDrawSurfaceImpl *);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern HMODULE D3D9_hModule;
|
|
||||||
|
|
||||||
BOOL CreateDirect3D9();
|
|
||||||
BOOL ResetDirect3D9();
|
|
||||||
BOOL ReleaseDirect3D9();
|
|
||||||
BOOL DeviceLostDirect3D9();
|
|
||||||
|
|
||||||
IDirectDrawImpl *ddraw = NULL;
|
IDirectDrawImpl *ddraw = NULL;
|
||||||
|
|
||||||
DWORD WINAPI render_main(void);
|
DWORD WINAPI render_main(void);
|
||||||
DWORD WINAPI render_soft_main(void);
|
DWORD WINAPI render_soft_main(void);
|
||||||
DWORD WINAPI render_dummy_main(void);
|
DWORD WINAPI render_dummy_main(void);
|
||||||
DWORD WINAPI render_d3d9_main(void);
|
|
||||||
|
|
||||||
int WindowPosX;
|
int WindowPosX;
|
||||||
int WindowPosY;
|
int WindowPosY;
|
||||||
@ -242,7 +235,7 @@ HRESULT __stdcall ddraw_RestoreDisplayMode(IDirectDrawImpl *This)
|
|||||||
This->render.thread = NULL;
|
This->render.thread = NULL;
|
||||||
|
|
||||||
if (This->renderer == render_d3d9_main)
|
if (This->renderer == render_d3d9_main)
|
||||||
ReleaseDirect3D9();
|
Direct3D9_Release();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!ddraw->windowed)
|
if(!ddraw->windowed)
|
||||||
@ -256,10 +249,10 @@ HRESULT __stdcall ddraw_RestoreDisplayMode(IDirectDrawImpl *This)
|
|||||||
|
|
||||||
void InitDirect3D9()
|
void InitDirect3D9()
|
||||||
{
|
{
|
||||||
Direct3D9Active = CreateDirect3D9();
|
Direct3D9Active = Direct3D9_Create();
|
||||||
if (!Direct3D9Active)
|
if (!Direct3D9Active)
|
||||||
{
|
{
|
||||||
ReleaseDirect3D9();
|
Direct3D9_Release();
|
||||||
ShowDriverWarning = TRUE;
|
ShowDriverWarning = TRUE;
|
||||||
ddraw->renderer = render_soft_main;
|
ddraw->renderer = render_soft_main;
|
||||||
}
|
}
|
||||||
@ -557,7 +550,7 @@ void ToggleFullscreen()
|
|||||||
LastSetWindowPosTick = timeGetTime();
|
LastSetWindowPosTick = timeGetTime();
|
||||||
|
|
||||||
if (Direct3D9Active)
|
if (Direct3D9Active)
|
||||||
ResetDirect3D9();
|
Direct3D9_Reset();
|
||||||
else
|
else
|
||||||
ChangeDisplaySettings(&ddraw->render.mode, CDS_FULLSCREEN);
|
ChangeDisplaySettings(&ddraw->render.mode, CDS_FULLSCREEN);
|
||||||
}
|
}
|
||||||
@ -589,7 +582,7 @@ void ToggleFullscreen()
|
|||||||
ddraw->windowed_init = TRUE;
|
ddraw->windowed_init = TRUE;
|
||||||
|
|
||||||
if (Direct3D9Active)
|
if (Direct3D9Active)
|
||||||
ResetDirect3D9();
|
Direct3D9_Reset();
|
||||||
}
|
}
|
||||||
mouse_lock();
|
mouse_lock();
|
||||||
}
|
}
|
||||||
@ -603,7 +596,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|||||||
{
|
{
|
||||||
case WM_D3D9DEVICELOST:
|
case WM_D3D9DEVICELOST:
|
||||||
{
|
{
|
||||||
if (Direct3D9Active && DeviceLostDirect3D9())
|
if (Direct3D9Active && Direct3D9_DeviceLost())
|
||||||
{
|
{
|
||||||
if (!ddraw->windowed)
|
if (!ddraw->windowed)
|
||||||
mouse_lock();
|
mouse_lock();
|
||||||
@ -975,7 +968,7 @@ ULONG __stdcall ddraw_Release(IDirectDrawImpl *This)
|
|||||||
This->render.thread = NULL;
|
This->render.thread = NULL;
|
||||||
|
|
||||||
if (This->renderer == render_d3d9_main)
|
if (This->renderer == render_d3d9_main)
|
||||||
ReleaseDirect3D9();
|
Direct3D9_Release();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(This->render.hDC)
|
if(This->render.hDC)
|
||||||
@ -1298,10 +1291,10 @@ HRESULT WINAPI DirectDrawCreate(GUID FAR* lpGUID, LPDIRECTDRAW FAR* lplpDD, IUnk
|
|||||||
LPDIRECT3D9 d3d = NULL;
|
LPDIRECT3D9 d3d = NULL;
|
||||||
|
|
||||||
// Windows = Direct3D 9, Wine = OpenGL
|
// Windows = Direct3D 9, Wine = OpenGL
|
||||||
if (!This->wine && (D3D9_hModule = LoadLibrary("d3d9.dll")))
|
if (!This->wine && (Direct3D9_hModule = LoadLibrary("d3d9.dll")))
|
||||||
{
|
{
|
||||||
IDirect3D9 *(WINAPI *D3DCreate9)(UINT) =
|
IDirect3D9 *(WINAPI *D3DCreate9)(UINT) =
|
||||||
(IDirect3D9 *(WINAPI *)(UINT))GetProcAddress(D3D9_hModule, "Direct3DCreate9");
|
(IDirect3D9 *(WINAPI *)(UINT))GetProcAddress(Direct3D9_hModule, "Direct3DCreate9");
|
||||||
|
|
||||||
if (D3DCreate9 && (d3d = D3DCreate9(D3D_SDK_VERSION)))
|
if (D3DCreate9 && (d3d = D3DCreate9(D3D_SDK_VERSION)))
|
||||||
d3d->lpVtbl->Release(d3d);
|
d3d->lpVtbl->Release(d3d);
|
||||||
|
@ -4,10 +4,10 @@
|
|||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "surface.h"
|
#include "surface.h"
|
||||||
#include "d3d9shader.h"
|
#include "d3d9shader.h"
|
||||||
|
#include "d3d9renderer.h"
|
||||||
|
|
||||||
typedef struct CUSTOMVERTEX { float x, y, z, rhw, u, v; } CUSTOMVERTEX;
|
|
||||||
|
|
||||||
HMODULE D3D9_hModule;
|
HMODULE Direct3D9_hModule;
|
||||||
|
|
||||||
static D3DPRESENT_PARAMETERS D3dpp;
|
static D3DPRESENT_PARAMETERS D3dpp;
|
||||||
static LPDIRECT3D9 D3d;
|
static LPDIRECT3D9 D3d;
|
||||||
@ -28,14 +28,6 @@ static BOOL UpdateVertices(BOOL inCutscene);
|
|||||||
static void SetMaxFPS();
|
static void SetMaxFPS();
|
||||||
static void Render();
|
static void Render();
|
||||||
|
|
||||||
BOOL CreateDirect3D9();
|
|
||||||
BOOL ResetDirect3D9();
|
|
||||||
BOOL ReleaseDirect3D9();
|
|
||||||
BOOL DeviceLostDirect3D9();
|
|
||||||
|
|
||||||
BOOL detect_cutscene();
|
|
||||||
DWORD WINAPI render_soft_main(void);
|
|
||||||
|
|
||||||
DWORD WINAPI render_d3d9_main(void)
|
DWORD WINAPI render_d3d9_main(void)
|
||||||
{
|
{
|
||||||
Sleep(500);
|
Sleep(500);
|
||||||
@ -46,18 +38,18 @@ DWORD WINAPI render_d3d9_main(void)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL CreateDirect3D9()
|
BOOL Direct3D9_Create()
|
||||||
{
|
{
|
||||||
if (!ReleaseDirect3D9())
|
if (!Direct3D9_Release())
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
if (!D3D9_hModule)
|
if (!Direct3D9_hModule)
|
||||||
D3D9_hModule = LoadLibrary("d3d9.dll");
|
Direct3D9_hModule = LoadLibrary("d3d9.dll");
|
||||||
|
|
||||||
if (D3D9_hModule)
|
if (Direct3D9_hModule)
|
||||||
{
|
{
|
||||||
IDirect3D9 *(WINAPI *D3DCreate9)(UINT) =
|
IDirect3D9 *(WINAPI *D3DCreate9)(UINT) =
|
||||||
(IDirect3D9 *(WINAPI *)(UINT))GetProcAddress(D3D9_hModule, "Direct3DCreate9");
|
(IDirect3D9 *(WINAPI *)(UINT))GetProcAddress(Direct3D9_hModule, "Direct3DCreate9");
|
||||||
|
|
||||||
if (D3DCreate9 && (D3d = D3DCreate9(D3D_SDK_VERSION)))
|
if (D3DCreate9 && (D3d = D3DCreate9(D3D_SDK_VERSION)))
|
||||||
{
|
{
|
||||||
@ -100,6 +92,72 @@ BOOL CreateDirect3D9()
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOL Direct3D9_DeviceLost()
|
||||||
|
{
|
||||||
|
if (D3dDev && D3dDev->lpVtbl->TestCooperativeLevel(D3dDev) == D3DERR_DEVICENOTRESET)
|
||||||
|
return Direct3D9_Reset();
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOL Direct3D9_Reset()
|
||||||
|
{
|
||||||
|
D3dpp.Windowed = ddraw->windowed;
|
||||||
|
D3dpp.BackBufferWidth = D3dpp.Windowed ? 0 : ddraw->render.width;
|
||||||
|
D3dpp.BackBufferHeight = D3dpp.Windowed ? 0 : ddraw->render.height;
|
||||||
|
D3dpp.BackBufferFormat = BitsPerPixel == 16 ? D3DFMT_R5G6B5 : D3DFMT_X8R8G8B8;
|
||||||
|
|
||||||
|
if (SUCCEEDED(D3dDev->lpVtbl->Reset(D3dDev, &D3dpp)))
|
||||||
|
return SetStates();
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOL Direct3D9_Release()
|
||||||
|
{
|
||||||
|
if (VertexBuf)
|
||||||
|
{
|
||||||
|
VertexBuf->lpVtbl->Release(VertexBuf);
|
||||||
|
VertexBuf = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (SurfaceTex)
|
||||||
|
{
|
||||||
|
SurfaceTex->lpVtbl->Release(SurfaceTex);
|
||||||
|
SurfaceTex = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (PaletteTex)
|
||||||
|
{
|
||||||
|
PaletteTex->lpVtbl->Release(PaletteTex);
|
||||||
|
PaletteTex = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (PixelShader)
|
||||||
|
{
|
||||||
|
PixelShader->lpVtbl->Release(PixelShader);
|
||||||
|
PixelShader = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (D3dDev)
|
||||||
|
{
|
||||||
|
if (FAILED(D3dDev->lpVtbl->Release(D3dDev)))
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
D3dDev = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (D3d)
|
||||||
|
{
|
||||||
|
if (FAILED(D3d->lpVtbl->Release(D3d)))
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
D3d = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
static BOOL CreateResources()
|
static BOOL CreateResources()
|
||||||
{
|
{
|
||||||
BOOL err = FALSE;
|
BOOL err = FALSE;
|
||||||
@ -190,27 +248,6 @@ static BOOL UpdateVertices(BOOL inCutscene)
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL DeviceLostDirect3D9()
|
|
||||||
{
|
|
||||||
if (D3dDev && D3dDev->lpVtbl->TestCooperativeLevel(D3dDev) == D3DERR_DEVICENOTRESET)
|
|
||||||
return ResetDirect3D9();
|
|
||||||
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
BOOL ResetDirect3D9()
|
|
||||||
{
|
|
||||||
D3dpp.Windowed = ddraw->windowed;
|
|
||||||
D3dpp.BackBufferWidth = D3dpp.Windowed ? 0 : ddraw->render.width;
|
|
||||||
D3dpp.BackBufferHeight = D3dpp.Windowed ? 0 : ddraw->render.height;
|
|
||||||
D3dpp.BackBufferFormat = BitsPerPixel == 16 ? D3DFMT_R5G6B5 : D3DFMT_X8R8G8B8;
|
|
||||||
|
|
||||||
if (SUCCEEDED(D3dDev->lpVtbl->Reset(D3dDev, &D3dpp)))
|
|
||||||
return SetStates();
|
|
||||||
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void SetMaxFPS()
|
static void SetMaxFPS()
|
||||||
{
|
{
|
||||||
MaxFPS = ddraw->render.maxfps;
|
MaxFPS = ddraw->render.maxfps;
|
||||||
@ -328,48 +365,3 @@ static void Render()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL ReleaseDirect3D9()
|
|
||||||
{
|
|
||||||
if (VertexBuf)
|
|
||||||
{
|
|
||||||
VertexBuf->lpVtbl->Release(VertexBuf);
|
|
||||||
VertexBuf = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (SurfaceTex)
|
|
||||||
{
|
|
||||||
SurfaceTex->lpVtbl->Release(SurfaceTex);
|
|
||||||
SurfaceTex = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (PaletteTex)
|
|
||||||
{
|
|
||||||
PaletteTex->lpVtbl->Release(PaletteTex);
|
|
||||||
PaletteTex = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (PixelShader)
|
|
||||||
{
|
|
||||||
PixelShader->lpVtbl->Release(PixelShader);
|
|
||||||
PixelShader = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (D3dDev)
|
|
||||||
{
|
|
||||||
if (FAILED(D3dDev->lpVtbl->Release(D3dDev)))
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
D3dDev = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (D3d)
|
|
||||||
{
|
|
||||||
if (FAILED(D3d->lpVtbl->Release(D3d)))
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
D3d = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user