mirror of
https://github.com/FunkyFr3sh/cnc-ddraw.git
synced 2025-03-14 22:03:27 +01:00
add a header file for d3d9 renderer
This commit is contained in:
parent
28c9886dbe
commit
59f0f4d9b2
@ -26,6 +26,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="inc\clipper.h" />
|
||||
<ClInclude Include="inc\d3d9renderer.h" />
|
||||
<ClInclude Include="inc\ddraw.h" />
|
||||
<ClInclude Include="inc\debug.h" />
|
||||
<ClInclude Include="inc\glext.h" />
|
||||
|
@ -95,6 +95,9 @@
|
||||
<ClInclude Include="inc\d3d9shader.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="inc\d3d9renderer.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<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;
|
||||
|
||||
BOOL detect_cutscene();
|
||||
DWORD WINAPI render_soft_main(void);
|
||||
|
||||
struct IDirectDrawImpl;
|
||||
struct IDirectDrawImplVtbl;
|
||||
struct IDirectDrawSurfaceImpl;
|
||||
|
27
src/main.c
27
src/main.c
@ -24,6 +24,7 @@
|
||||
#include "palette.h"
|
||||
#include "surface.h"
|
||||
#include "clipper.h"
|
||||
#include "d3d9renderer.h"
|
||||
|
||||
#define IDR_MYMENU 93
|
||||
|
||||
@ -38,19 +39,11 @@ void mouse_unlock();
|
||||
BOOL screenshot(struct IDirectDrawSurfaceImpl *);
|
||||
#endif
|
||||
|
||||
extern HMODULE D3D9_hModule;
|
||||
|
||||
BOOL CreateDirect3D9();
|
||||
BOOL ResetDirect3D9();
|
||||
BOOL ReleaseDirect3D9();
|
||||
BOOL DeviceLostDirect3D9();
|
||||
|
||||
IDirectDrawImpl *ddraw = NULL;
|
||||
|
||||
DWORD WINAPI render_main(void);
|
||||
DWORD WINAPI render_soft_main(void);
|
||||
DWORD WINAPI render_dummy_main(void);
|
||||
DWORD WINAPI render_d3d9_main(void);
|
||||
|
||||
int WindowPosX;
|
||||
int WindowPosY;
|
||||
@ -242,7 +235,7 @@ HRESULT __stdcall ddraw_RestoreDisplayMode(IDirectDrawImpl *This)
|
||||
This->render.thread = NULL;
|
||||
|
||||
if (This->renderer == render_d3d9_main)
|
||||
ReleaseDirect3D9();
|
||||
Direct3D9_Release();
|
||||
}
|
||||
|
||||
if(!ddraw->windowed)
|
||||
@ -256,10 +249,10 @@ HRESULT __stdcall ddraw_RestoreDisplayMode(IDirectDrawImpl *This)
|
||||
|
||||
void InitDirect3D9()
|
||||
{
|
||||
Direct3D9Active = CreateDirect3D9();
|
||||
Direct3D9Active = Direct3D9_Create();
|
||||
if (!Direct3D9Active)
|
||||
{
|
||||
ReleaseDirect3D9();
|
||||
Direct3D9_Release();
|
||||
ShowDriverWarning = TRUE;
|
||||
ddraw->renderer = render_soft_main;
|
||||
}
|
||||
@ -557,7 +550,7 @@ void ToggleFullscreen()
|
||||
LastSetWindowPosTick = timeGetTime();
|
||||
|
||||
if (Direct3D9Active)
|
||||
ResetDirect3D9();
|
||||
Direct3D9_Reset();
|
||||
else
|
||||
ChangeDisplaySettings(&ddraw->render.mode, CDS_FULLSCREEN);
|
||||
}
|
||||
@ -589,7 +582,7 @@ void ToggleFullscreen()
|
||||
ddraw->windowed_init = TRUE;
|
||||
|
||||
if (Direct3D9Active)
|
||||
ResetDirect3D9();
|
||||
Direct3D9_Reset();
|
||||
}
|
||||
mouse_lock();
|
||||
}
|
||||
@ -603,7 +596,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
case WM_D3D9DEVICELOST:
|
||||
{
|
||||
if (Direct3D9Active && DeviceLostDirect3D9())
|
||||
if (Direct3D9Active && Direct3D9_DeviceLost())
|
||||
{
|
||||
if (!ddraw->windowed)
|
||||
mouse_lock();
|
||||
@ -975,7 +968,7 @@ ULONG __stdcall ddraw_Release(IDirectDrawImpl *This)
|
||||
This->render.thread = NULL;
|
||||
|
||||
if (This->renderer == render_d3d9_main)
|
||||
ReleaseDirect3D9();
|
||||
Direct3D9_Release();
|
||||
}
|
||||
|
||||
if(This->render.hDC)
|
||||
@ -1298,10 +1291,10 @@ HRESULT WINAPI DirectDrawCreate(GUID FAR* lpGUID, LPDIRECTDRAW FAR* lplpDD, IUnk
|
||||
LPDIRECT3D9 d3d = NULL;
|
||||
|
||||
// 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 *)(UINT))GetProcAddress(D3D9_hModule, "Direct3DCreate9");
|
||||
(IDirect3D9 *(WINAPI *)(UINT))GetProcAddress(Direct3D9_hModule, "Direct3DCreate9");
|
||||
|
||||
if (D3DCreate9 && (d3d = D3DCreate9(D3D_SDK_VERSION)))
|
||||
d3d->lpVtbl->Release(d3d);
|
||||
|
@ -4,10 +4,10 @@
|
||||
#include "main.h"
|
||||
#include "surface.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 LPDIRECT3D9 D3d;
|
||||
@ -28,14 +28,6 @@ static BOOL UpdateVertices(BOOL inCutscene);
|
||||
static void SetMaxFPS();
|
||||
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)
|
||||
{
|
||||
Sleep(500);
|
||||
@ -46,18 +38,18 @@ DWORD WINAPI render_d3d9_main(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
BOOL CreateDirect3D9()
|
||||
BOOL Direct3D9_Create()
|
||||
{
|
||||
if (!ReleaseDirect3D9())
|
||||
if (!Direct3D9_Release())
|
||||
return FALSE;
|
||||
|
||||
if (!D3D9_hModule)
|
||||
D3D9_hModule = LoadLibrary("d3d9.dll");
|
||||
if (!Direct3D9_hModule)
|
||||
Direct3D9_hModule = LoadLibrary("d3d9.dll");
|
||||
|
||||
if (D3D9_hModule)
|
||||
if (Direct3D9_hModule)
|
||||
{
|
||||
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)))
|
||||
{
|
||||
@ -100,6 +92,72 @@ BOOL CreateDirect3D9()
|
||||
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()
|
||||
{
|
||||
BOOL err = FALSE;
|
||||
@ -190,27 +248,6 @@ static BOOL UpdateVertices(BOOL inCutscene)
|
||||
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()
|
||||
{
|
||||
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