feat(gx): add window creation to d3d backend

This commit is contained in:
fallenoak 2023-03-05 16:13:31 -06:00 committed by GitHub
parent 2010aa8e4e
commit 80388f0279
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 98 additions and 2 deletions

View File

@ -78,6 +78,10 @@ void CGxDevice::Log(const char* format, ...) {
// TODO
}
void CGxDevice::Log(const CGxFormat& format) {
// TODO
}
#if defined(WHOA_SYSTEM_WIN)
CGxDevice* CGxDevice::NewD3d() {
auto m = SMemAlloc(sizeof(CGxDeviceD3d), __FILE__, __LINE__, 0x0);

View File

@ -47,6 +47,7 @@ class CGxDevice {
// Static functions
static void Log(const char* format, ...);
static void Log(const CGxFormat& format);
#if defined(WHOA_SYSTEM_WIN)
static CGxDevice* NewD3d();
static CGxDevice* NewD3d9Ex();

View File

@ -27,6 +27,7 @@ class CGxFormat {
uint32_t sampleCount;
Format colorFormat;
uint32_t refreshRate;
C2iVector pos;
};
#endif

View File

@ -9,7 +9,7 @@ ATOM WindowClassCreate() {
wc.style = CS_OWNDC;
wc.lpfnWndProc = CGxDeviceD3d::WindowProcD3d;
wc.hInstance = instance;
wc.lpszClassName = "GxWindowClassD3d";
wc.lpszClassName = TEXT("GxWindowClassD3d");
wc.hIcon = static_cast<HICON>(LoadImage(instance, TEXT("BlizzardIcon.ico"), 1u, 0, 0, 0x40));
wc.hCursor = LoadCursor(instance, TEXT("BlizzardCursor.cur"));
@ -62,7 +62,8 @@ void CGxDeviceD3d::IUnloadD3dLib(HINSTANCE& d3dLib, LPDIRECT3D9& d3d) {
LRESULT CGxDeviceD3d::WindowProcD3d(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
// TODO
return 0;
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
void CGxDeviceD3d::CapsWindowSize(CRect& dst) {
@ -96,6 +97,41 @@ int32_t CGxDeviceD3d::DeviceCreate(long (*windowProc)(void*, uint32_t, uint32_t,
return 0;
}
int32_t CGxDeviceD3d::DeviceSetFormat(const CGxFormat& format) {
CGxDevice::Log("CGxDeviceD3d::DeviceSetFormat():");
CGxDevice::Log(format);
if (this->m_hwnd) {
ShowWindow(this->m_hwnd, 0);
}
// TODO
if (this->m_hwnd) {
DestroyWindow(this->m_hwnd);
}
this->m_hwnd = nullptr;
this->m_format = format;
CGxFormat createFormat = format;
if (this->ICreateWindow(createFormat) && this->ICreateD3dDevice(createFormat) && this->CGxDevice::DeviceSetFormat(format)) {
this->m_context = 1;
// TODO
if (this->m_format.window == 0) {
RECT windowRect;
GetWindowRect(this->m_hwnd, &windowRect);
ClipCursor(&windowRect);
}
return 1;
}
}
int32_t CGxDeviceD3d::ICreateD3d() {
if (CGxDeviceD3d::ILoadD3dLib(this->m_d3dLib, this->m_d3d) && this->m_d3d->GetDeviceCaps(0, D3DDEVTYPE_HAL, &this->m_d3dCaps) >= S_OK) {
if (this->m_desktopDisplayMode.Format != D3DFMT_UNKNOWN) {
@ -118,6 +154,56 @@ int32_t CGxDeviceD3d::ICreateD3d() {
return 0;
}
int32_t CGxDeviceD3d::ICreateD3dDevice(const CGxFormat& format) {
// TODO
return 0;
}
bool CGxDeviceD3d::ICreateWindow(CGxFormat& format) {
auto instance = GetModuleHandle(nullptr);
DWORD dwStyle;
if (format.window == 0) {
dwStyle = WS_POPUP | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_SYSMENU;
} else if (format.maximize == 1) {
dwStyle = WS_POPUP | WS_VISIBLE;
} else if (format.maximize == 2) {
dwStyle = WS_POPUP;
} else {
dwStyle = WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_CAPTION | WS_SYSMENU | WS_SIZEBOX | WS_MINIMIZEBOX | WS_MAXIMIZEBOX;
}
// TODO
int32_t width = format.size.x ? format.size.x : CW_USEDEFAULT;
int32_t height = format.size.y ? format.size.y : CW_USEDEFAULT;
if (format.window && format.maximize != 1 && format.size.x && format.size.y) {
// TODO adjust width and height
}
this->m_hwnd = CreateWindowEx(
WS_EX_APPWINDOW,
TEXT("GxWindowClassD3d"),
TEXT("World of Warcraft"),
dwStyle,
format.pos.x,
format.pos.y,
width,
height,
nullptr,
nullptr,
instance,
this
);
if (this->m_hwnd && format.maximize != 2) {
ShowWindow(this->m_hwnd, 1);
}
return this->m_hwnd != nullptr;
}
void CGxDeviceD3d::IDestroyD3d() {
this->IDestroyD3dDevice();
CGxDeviceD3d::IUnloadD3dLib(this->m_d3dLib, this->m_d3d);

View File

@ -14,6 +14,7 @@ class CGxDeviceD3d : public CGxDevice {
static LRESULT WindowProcD3d(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
// Member variables
HWND m_hwnd;
ATOM m_hwndClass;
int32_t m_ownhwnd;
HINSTANCE m_d3dLib;
@ -26,6 +27,7 @@ class CGxDeviceD3d : public CGxDevice {
virtual void ITexMarkAsUpdated(CGxTex* texId);
virtual void IRsSendToHw(EGxRenderState rs);
virtual int32_t DeviceCreate(long (*windowProc)(void*, uint32_t, uint32_t, long), const CGxFormat& format);
virtual int32_t DeviceSetFormat(const CGxFormat& format);
virtual void CapsWindowSize(CRect& dst);
virtual void CapsWindowSizeInScreenCoords(CRect& dst);
virtual void PoolSizeSet(CGxPool* pool, uint32_t size);
@ -34,6 +36,8 @@ class CGxDeviceD3d : public CGxDevice {
// Member functions
int32_t ICreateD3d();
int32_t ICreateD3dDevice(const CGxFormat& format);
bool ICreateWindow(CGxFormat& format);
void IDestroyD3d();
void IDestroyD3dDevice();
};