mirror of
https://github.com/scratchfoundation/bgfx.git
synced 2024-11-28 10:35:43 -05:00
Cleanup.
This commit is contained in:
parent
2772c5d209
commit
a1e226cb5b
6 changed files with 93 additions and 58 deletions
|
@ -67,6 +67,7 @@ namespace bgfx
|
|||
#include <bx/uint32_t.h>
|
||||
#include <bx/readerwriter.h>
|
||||
#include <bx/string.h>
|
||||
#include <bx/os.h>
|
||||
|
||||
#include "dds.h"
|
||||
|
||||
|
|
|
@ -72,19 +72,19 @@ namespace bgfx
|
|||
|
||||
void GlContext::create(uint32_t /*_width*/, uint32_t /*_height*/)
|
||||
{
|
||||
m_opengl32dll = LoadLibrary("opengl32.dll");
|
||||
m_opengl32dll = bx::dlopen("opengl32.dll");
|
||||
BGFX_FATAL(NULL != m_opengl32dll, Fatal::UnableToInitialize, "Failed to load opengl32.dll.");
|
||||
|
||||
wglGetProcAddress = (PFNWGLGETPROCADDRESSPROC)GetProcAddress(m_opengl32dll, "wglGetProcAddress");
|
||||
wglGetProcAddress = (PFNWGLGETPROCADDRESSPROC)bx::dlsym(m_opengl32dll, "wglGetProcAddress");
|
||||
BGFX_FATAL(NULL != wglGetProcAddress, Fatal::UnableToInitialize, "Failed get wglGetProcAddress.");
|
||||
|
||||
wglMakeCurrent = (PFNWGLMAKECURRENTPROC)GetProcAddress(m_opengl32dll, "wglMakeCurrent");
|
||||
wglMakeCurrent = (PFNWGLMAKECURRENTPROC)bx::dlsym(m_opengl32dll, "wglMakeCurrent");
|
||||
BGFX_FATAL(NULL != wglMakeCurrent, Fatal::UnableToInitialize, "Failed get wglMakeCurrent.");
|
||||
|
||||
wglCreateContext = (PFNWGLCREATECONTEXTPROC)GetProcAddress(m_opengl32dll, "wglCreateContext");
|
||||
wglCreateContext = (PFNWGLCREATECONTEXTPROC)bx::dlsym(m_opengl32dll, "wglCreateContext");
|
||||
BGFX_FATAL(NULL != wglCreateContext, Fatal::UnableToInitialize, "Failed get wglCreateContext.");
|
||||
|
||||
wglDeleteContext = (PFNWGLDELETECONTEXTPROC)GetProcAddress(m_opengl32dll, "wglDeleteContext");
|
||||
wglDeleteContext = (PFNWGLDELETECONTEXTPROC)bx::dlsym(m_opengl32dll, "wglDeleteContext");
|
||||
BGFX_FATAL(NULL != wglDeleteContext, Fatal::UnableToInitialize, "Failed get wglDeleteContext.");
|
||||
|
||||
m_hdc = GetDC(g_bgfxHwnd);
|
||||
|
@ -234,7 +234,7 @@ namespace bgfx
|
|||
ReleaseDC(g_bgfxHwnd, m_hdc);
|
||||
m_hdc = NULL;
|
||||
|
||||
FreeLibrary(m_opengl32dll);
|
||||
bx::dlclose(m_opengl32dll);
|
||||
m_opengl32dll = NULL;
|
||||
}
|
||||
|
||||
|
@ -259,7 +259,7 @@ namespace bgfx
|
|||
_func = (_proto)wglGetProcAddress(#_func); \
|
||||
if (_func == NULL) \
|
||||
{ \
|
||||
_func = (_proto)GetProcAddress(m_opengl32dll, #_func); \
|
||||
_func = (_proto)bx::dlsym(m_opengl32dll, #_func); \
|
||||
} \
|
||||
BGFX_FATAL(_optional || NULL != _func, Fatal::UnableToInitialize, "Failed to create OpenGL context. wglGetProcAddress(\"%s\")", #_func); \
|
||||
}
|
||||
|
|
|
@ -75,7 +75,7 @@ namespace bgfx
|
|||
return NULL != m_context;
|
||||
}
|
||||
|
||||
HMODULE m_opengl32dll;
|
||||
void* m_opengl32dll;
|
||||
HGLRC m_context;
|
||||
HDC m_hdc;
|
||||
};
|
||||
|
|
|
@ -327,18 +327,18 @@ namespace bgfx
|
|||
|
||||
void init()
|
||||
{
|
||||
m_d3d11dll = LoadLibrary("d3d11.dll");
|
||||
m_d3d11dll = bx::dlopen("d3d11.dll");
|
||||
BGFX_FATAL(NULL != m_d3d11dll, Fatal::UnableToInitialize, "Failed to load d3d11.dll.");
|
||||
|
||||
#if BGFX_CONFIG_DEBUG_PIX
|
||||
// D3D11_1.h has ID3DUserDefinedAnnotation
|
||||
// http://msdn.microsoft.com/en-us/library/windows/desktop/hh446881%28v=vs.85%29.aspx
|
||||
m_d3d9dll = LoadLibrary("d3d9.dll");
|
||||
m_d3d9dll = bx::dlopen("d3d9.dll");
|
||||
BGFX_FATAL(NULL != m_d3d9dll, Fatal::UnableToInitialize, "Failed to load d3d9.dll.");
|
||||
|
||||
m_D3DPERF_SetMarker = (D3DPERF_SetMarkerFunc)GetProcAddress(m_d3d9dll, "D3DPERF_SetMarker");
|
||||
m_D3DPERF_BeginEvent = (D3DPERF_BeginEventFunc)GetProcAddress(m_d3d9dll, "D3DPERF_BeginEvent");
|
||||
m_D3DPERF_EndEvent = (D3DPERF_EndEventFunc)GetProcAddress(m_d3d9dll, "D3DPERF_EndEvent");
|
||||
m_D3DPERF_SetMarker = (D3DPERF_SetMarkerFunc)bx::dlsym(m_d3d9dll, "D3DPERF_SetMarker");
|
||||
m_D3DPERF_BeginEvent = (D3DPERF_BeginEventFunc)bx::dlsym(m_d3d9dll, "D3DPERF_BeginEvent");
|
||||
m_D3DPERF_EndEvent = (D3DPERF_EndEventFunc)bx::dlsym(m_d3d9dll, "D3DPERF_EndEvent");
|
||||
BX_CHECK(NULL != m_D3DPERF_SetMarker
|
||||
&& NULL != m_D3DPERF_BeginEvent
|
||||
&& NULL != m_D3DPERF_EndEvent
|
||||
|
@ -346,13 +346,13 @@ namespace bgfx
|
|||
);
|
||||
#endif // BGFX_CONFIG_DEBUG_PIX
|
||||
|
||||
PFN_D3D11_CREATE_DEVICE d3D11CreateDevice = (PFN_D3D11_CREATE_DEVICE)GetProcAddress(m_d3d11dll, "D3D11CreateDevice");
|
||||
PFN_D3D11_CREATE_DEVICE d3D11CreateDevice = (PFN_D3D11_CREATE_DEVICE)bx::dlsym(m_d3d11dll, "D3D11CreateDevice");
|
||||
BGFX_FATAL(NULL != d3D11CreateDevice, Fatal::UnableToInitialize, "Function D3D11CreateDevice not found.");
|
||||
|
||||
m_dxgidll = LoadLibrary("dxgi.dll");
|
||||
m_dxgidll = bx::dlopen("dxgi.dll");
|
||||
BGFX_FATAL(NULL != m_dxgidll, Fatal::UnableToInitialize, "Failed to load dxgi.dll.");
|
||||
|
||||
PFN_CREATEDXGIFACTORY dxgiCreateDXGIFactory = (PFN_CREATEDXGIFACTORY)GetProcAddress(m_dxgidll, "CreateDXGIFactory");
|
||||
PFN_CREATEDXGIFACTORY dxgiCreateDXGIFactory = (PFN_CREATEDXGIFACTORY)bx::dlsym(m_dxgidll, "CreateDXGIFactory");
|
||||
BGFX_FATAL(NULL != dxgiCreateDXGIFactory, Fatal::UnableToInitialize, "Function CreateDXGIFactory not found.");
|
||||
|
||||
HRESULT hr;
|
||||
|
@ -523,8 +523,8 @@ namespace bgfx
|
|||
DX_RELEASE(m_device, 0);
|
||||
DX_RELEASE(m_factory, 0);
|
||||
|
||||
FreeLibrary(m_dxgidll);
|
||||
FreeLibrary(m_d3d11dll);
|
||||
bx::dlclose(m_dxgidll);
|
||||
bx::dlclose(m_d3d11dll);
|
||||
}
|
||||
|
||||
void preReset()
|
||||
|
@ -1113,14 +1113,14 @@ namespace bgfx
|
|||
}
|
||||
|
||||
#if BGFX_CONFIG_DEBUG_PIX
|
||||
HMODULE m_d3d9dll;
|
||||
void* m_d3d9dll;
|
||||
D3DPERF_SetMarkerFunc m_D3DPERF_SetMarker;
|
||||
D3DPERF_BeginEventFunc m_D3DPERF_BeginEvent;
|
||||
D3DPERF_EndEventFunc m_D3DPERF_EndEvent;
|
||||
#endif // BGFX_CONFIG_DEBUG_PIX
|
||||
|
||||
HMODULE m_d3d11dll;
|
||||
HMODULE m_dxgidll;
|
||||
void* m_d3d11dll;
|
||||
void* m_dxgidll;
|
||||
D3D_DRIVER_TYPE m_driverType;
|
||||
IDXGIAdapter* m_adapter;
|
||||
DXGI_ADAPTER_DESC m_adapterDesc;
|
||||
|
|
|
@ -218,6 +218,9 @@ namespace bgfx
|
|||
{ D3DFMT_RAWZ, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, false },
|
||||
};
|
||||
|
||||
static const GUID IID_IDirect3D9 = { 0x81bdcbca, 0x64d4, 0x426d, { 0xae, 0x8d, 0xad, 0x1, 0x47, 0xf4, 0x27, 0x5c } };
|
||||
static const GUID IID_IDirect3DDevice9Ex = { 0xb18b10ce, 0x2649, 0x405a, { 0x87, 0xf, 0x95, 0xf7, 0x77, 0xd4, 0x31, 0x3a } };
|
||||
|
||||
struct RendererContext
|
||||
{
|
||||
RendererContext()
|
||||
|
@ -258,13 +261,13 @@ namespace bgfx
|
|||
m_params.BackBufferWidth = rect.right-rect.left;
|
||||
m_params.BackBufferHeight = rect.bottom-rect.top;
|
||||
|
||||
m_d3d9dll = LoadLibrary("d3d9.dll");
|
||||
m_d3d9dll = bx::dlopen("d3d9.dll");
|
||||
BGFX_FATAL(NULL != m_d3d9dll, Fatal::UnableToInitialize, "Failed to load d3d9.dll.");
|
||||
|
||||
#if BGFX_CONFIG_DEBUG_PIX
|
||||
m_D3DPERF_SetMarker = (D3DPERF_SetMarkerFunc)GetProcAddress(m_d3d9dll, "D3DPERF_SetMarker");
|
||||
m_D3DPERF_BeginEvent = (D3DPERF_BeginEventFunc)GetProcAddress(m_d3d9dll, "D3DPERF_BeginEvent");
|
||||
m_D3DPERF_EndEvent = (D3DPERF_EndEventFunc)GetProcAddress(m_d3d9dll, "D3DPERF_EndEvent");
|
||||
m_D3DPERF_SetMarker = (D3DPERF_SetMarkerFunc)bx::dlsym(m_d3d9dll, "D3DPERF_SetMarker");
|
||||
m_D3DPERF_BeginEvent = (D3DPERF_BeginEventFunc)bx::dlsym(m_d3d9dll, "D3DPERF_BeginEvent");
|
||||
m_D3DPERF_EndEvent = (D3DPERF_EndEventFunc)bx::dlsym(m_d3d9dll, "D3DPERF_EndEvent");
|
||||
|
||||
BX_CHECK(NULL != m_D3DPERF_SetMarker
|
||||
&& NULL != m_D3DPERF_BeginEvent
|
||||
|
@ -274,14 +277,23 @@ namespace bgfx
|
|||
#endif // BGFX_CONFIG_DEBUG_PIX
|
||||
|
||||
#if BGFX_CONFIG_RENDERER_DIRECT3D9EX
|
||||
Direct3DCreate9ExFn direct3DCreate9Ex = (Direct3DCreate9ExFn)GetProcAddress(m_d3d9dll, "Direct3DCreate9Ex");
|
||||
BGFX_FATAL(NULL != direct3DCreate9Ex, Fatal::UnableToInitialize, "Function Direct3DCreate9Ex not found.");
|
||||
direct3DCreate9Ex(D3D_SDK_VERSION, &m_d3d9);
|
||||
#else
|
||||
Direct3DCreate9Fn direct3DCreate9 = (Direct3DCreate9Fn)GetProcAddress(m_d3d9dll, "Direct3DCreate9");
|
||||
BGFX_FATAL(NULL != direct3DCreate9, Fatal::UnableToInitialize, "Function Direct3DCreate9 not found.");
|
||||
m_d3d9 = direct3DCreate9(D3D_SDK_VERSION);
|
||||
#endif // defined(D3D_DISABLE_9EX)
|
||||
m_d3d9ex = NULL;
|
||||
|
||||
Direct3DCreate9ExFn direct3DCreate9Ex = (Direct3DCreate9ExFn)bx::dlsym(m_d3d9dll, "Direct3DCreate9Ex");
|
||||
if (NULL != direct3DCreate9Ex)
|
||||
{
|
||||
direct3DCreate9Ex(D3D_SDK_VERSION, &m_d3d9ex);
|
||||
DX_CHECK(m_d3d9ex->QueryInterface(IID_IDirect3D9, (void**)&m_d3d9) );
|
||||
m_pool = D3DPOOL_DEFAULT;
|
||||
}
|
||||
else
|
||||
#endif // BGFX_CONFIG_RENDERER_DIRECT3D9EX
|
||||
{
|
||||
Direct3DCreate9Fn direct3DCreate9 = (Direct3DCreate9Fn)bx::dlsym(m_d3d9dll, "Direct3DCreate9");
|
||||
BGFX_FATAL(NULL != direct3DCreate9, Fatal::UnableToInitialize, "Function Direct3DCreate9 not found.");
|
||||
m_d3d9 = direct3DCreate9(D3D_SDK_VERSION);
|
||||
m_pool = D3DPOOL_MANAGED;
|
||||
}
|
||||
|
||||
BGFX_FATAL(m_d3d9, Fatal::UnableToInitialize, "Unable to create Direct3D.");
|
||||
|
||||
|
@ -329,7 +341,7 @@ namespace bgfx
|
|||
|
||||
for (uint32_t ii = 0; ii < countof(behaviorFlags) && NULL == m_device; ++ii)
|
||||
{
|
||||
#if BGFX_CONFIG_RENDERER_DIRECT3D9EX
|
||||
#if 0 // BGFX_CONFIG_RENDERER_DIRECT3D9EX
|
||||
DX_CHECK(m_d3d9->CreateDeviceEx(m_adapter
|
||||
, m_deviceType
|
||||
, g_bgfxHwnd
|
||||
|
@ -351,6 +363,13 @@ namespace bgfx
|
|||
|
||||
BGFX_FATAL(m_device, Fatal::UnableToInitialize, "Unable to create Direct3D9 device.");
|
||||
|
||||
#if BGFX_CONFIG_RENDERER_DIRECT3D9EX
|
||||
if (NULL != m_d3d9ex)
|
||||
{
|
||||
DX_CHECK(m_device->QueryInterface(IID_IDirect3DDevice9Ex, (void**)&m_deviceEx) );
|
||||
}
|
||||
#endif // BGFX_CONFIG_RENDERER_DIRECT3D9EX
|
||||
|
||||
DX_CHECK(m_device->GetDeviceCaps(&m_caps) );
|
||||
|
||||
// For shit GPUs that can create DX9 device but can't do simple stuff. GTFO!
|
||||
|
@ -489,11 +508,23 @@ namespace bgfx
|
|||
m_renderTargets[ii].destroy();
|
||||
}
|
||||
|
||||
DX_RELEASE(m_device, 0);
|
||||
DX_RELEASE(m_d3d9, 0);
|
||||
#if BGFX_CONFIG_RENDERER_DIRECT3D9EX
|
||||
if (NULL != m_d3d9ex)
|
||||
{
|
||||
DX_RELEASE(m_deviceEx, 1);
|
||||
DX_RELEASE(m_device, 0);
|
||||
DX_RELEASE(m_d3d9, 1);
|
||||
DX_RELEASE(m_d3d9ex, 0);
|
||||
}
|
||||
else
|
||||
#endif // BGFX_CONFIG_RENDERER_DIRECT3D9EX
|
||||
{
|
||||
DX_RELEASE(m_device, 0);
|
||||
DX_RELEASE(m_d3d9, 0);
|
||||
}
|
||||
|
||||
#if BX_PLATFORM_WINDOWS
|
||||
FreeLibrary(m_d3d9dll);
|
||||
bx::dlclose(m_d3d9dll);
|
||||
#endif // BX_PLATFORM_WINDOWS
|
||||
|
||||
m_initialized = false;
|
||||
|
@ -645,7 +676,10 @@ namespace bgfx
|
|||
if (NULL != m_device)
|
||||
{
|
||||
#if BGFX_CONFIG_RENDERER_DIRECT3D9EX
|
||||
DX_CHECK(m_device->WaitForVBlank(0) );
|
||||
if (NULL != m_deviceEx)
|
||||
{
|
||||
DX_CHECK(m_deviceEx->WaitForVBlank(0) );
|
||||
}
|
||||
#endif // BGFX_CONFIG_RENDERER_DIRECT3D9EX
|
||||
|
||||
HRESULT hr;
|
||||
|
@ -908,12 +942,13 @@ namespace bgfx
|
|||
#endif // BX_PLATFORM_WINDOWS
|
||||
|
||||
#if BGFX_CONFIG_RENDERER_DIRECT3D9EX
|
||||
IDirect3D9Ex* m_d3d9;
|
||||
IDirect3DDevice9Ex* m_device;
|
||||
#else
|
||||
IDirect3D9Ex* m_d3d9ex;
|
||||
IDirect3DDevice9Ex* m_deviceEx;
|
||||
#endif // BGFX_CONFIG_RENDERER_DIRECT3D9EX
|
||||
|
||||
IDirect3D9* m_d3d9;
|
||||
IDirect3DDevice9* m_device;
|
||||
#endif // BGFX_CONFIG_RENDERER_DIRECT3D9EX
|
||||
D3DPOOL m_pool;
|
||||
|
||||
IDirect3DSurface9* m_backBufferColor;
|
||||
IDirect3DSurface9* m_backBufferDepthStencil;
|
||||
|
@ -924,7 +959,7 @@ namespace bgfx
|
|||
|
||||
IDirect3DVertexDeclaration9* m_instanceDataDecls[BGFX_CONFIG_MAX_INSTANCE_DATA_COUNT];
|
||||
|
||||
HMODULE m_d3d9dll;
|
||||
void* m_d3d9dll;
|
||||
uint32_t m_adapter;
|
||||
D3DDEVTYPE m_deviceType;
|
||||
D3DPRESENT_PARAMETERS m_params;
|
||||
|
@ -970,7 +1005,7 @@ namespace bgfx
|
|||
m_dynamic = NULL == _data;
|
||||
|
||||
uint32_t usage = D3DUSAGE_WRITEONLY;
|
||||
D3DPOOL pool = D3DPOOL_MANAGED;
|
||||
D3DPOOL pool = s_renderCtx.m_pool;
|
||||
|
||||
if (m_dynamic)
|
||||
{
|
||||
|
@ -1021,7 +1056,7 @@ namespace bgfx
|
|||
m_dynamic = NULL == _data;
|
||||
|
||||
uint32_t usage = D3DUSAGE_WRITEONLY;
|
||||
D3DPOOL pool = D3DPOOL_MANAGED;
|
||||
D3DPOOL pool = s_renderCtx.m_pool;
|
||||
|
||||
if (m_dynamic)
|
||||
{
|
||||
|
@ -1275,7 +1310,7 @@ namespace bgfx
|
|||
, _numMips
|
||||
, 0
|
||||
, _fmt
|
||||
, D3DPOOL_MANAGED
|
||||
, s_renderCtx.m_pool
|
||||
, &m_texture2d
|
||||
, NULL
|
||||
) );
|
||||
|
@ -1298,7 +1333,7 @@ namespace bgfx
|
|||
, _numMips
|
||||
, 0
|
||||
, _fmt
|
||||
, D3DPOOL_MANAGED
|
||||
, s_renderCtx.m_pool
|
||||
, &m_texture3d
|
||||
, NULL
|
||||
) );
|
||||
|
@ -1320,7 +1355,7 @@ namespace bgfx
|
|||
, _numMips
|
||||
, 0
|
||||
, _fmt
|
||||
, D3DPOOL_MANAGED
|
||||
, s_renderCtx.m_pool
|
||||
, &m_textureCube
|
||||
, NULL
|
||||
) );
|
||||
|
|
|
@ -8,14 +8,6 @@
|
|||
|
||||
#define BGFX_CONFIG_RENDERER_DIRECT3D9EX (BX_PLATFORM_WINDOWS && 0)
|
||||
|
||||
#ifndef D3DSTREAMSOURCE_INDEXEDDATA
|
||||
# define D3DSTREAMSOURCE_INDEXEDDATA (1<<30)
|
||||
#endif// D3DSTREAMSOURCE_INDEXEDDATA
|
||||
|
||||
#ifndef D3DSTREAMSOURCE_INSTANCEDATA
|
||||
# define D3DSTREAMSOURCE_INSTANCEDATA (2<<30)
|
||||
#endif // D3DSTREAMSOURCE_INSTANCEDATA
|
||||
|
||||
#if BX_PLATFORM_WINDOWS
|
||||
# if !BGFX_CONFIG_RENDERER_DIRECT3D9EX
|
||||
# define D3D_DISABLE_9EX
|
||||
|
@ -24,9 +16,8 @@
|
|||
|
||||
# if BGFX_CONFIG_RENDERER_DIRECT3D9EX
|
||||
typedef HRESULT (WINAPI *Direct3DCreate9ExFn)(UINT SDKVersion, IDirect3D9Ex**);
|
||||
# else
|
||||
typedef IDirect3D9* (WINAPI *Direct3DCreate9Fn)(UINT SDKVersion);
|
||||
# endif // BGFX_CONFIG_RENDERER_DIRECT3D9EX
|
||||
typedef IDirect3D9* (WINAPI *Direct3DCreate9Fn)(UINT SDKVersion);
|
||||
|
||||
#elif BX_PLATFORM_XBOX360
|
||||
# include <xgraphics.h>
|
||||
|
@ -44,6 +35,14 @@ typedef IDirect3D9* (WINAPI *Direct3DCreate9Fn)(UINT SDKVersion);
|
|||
# define _PIX_ENDEVENT() do {} while(0)
|
||||
#endif // BX_PLATFORM_
|
||||
|
||||
#ifndef D3DSTREAMSOURCE_INDEXEDDATA
|
||||
# define D3DSTREAMSOURCE_INDEXEDDATA (1<<30)
|
||||
#endif// D3DSTREAMSOURCE_INDEXEDDATA
|
||||
|
||||
#ifndef D3DSTREAMSOURCE_INSTANCEDATA
|
||||
# define D3DSTREAMSOURCE_INSTANCEDATA (2<<30)
|
||||
#endif // D3DSTREAMSOURCE_INSTANCEDATA
|
||||
|
||||
#include "renderer_d3d.h"
|
||||
|
||||
namespace bgfx
|
||||
|
|
Loading…
Reference in a new issue