dx9: update device size on window size change
This commit is contained in:
@@ -261,27 +261,27 @@ void GfxDirectX9::UploadPools() {
|
|||||||
if (!impl->VBO || impl->VertexBufferSize != GetVertexPoolSize()) {
|
if (!impl->VBO || impl->VertexBufferSize != GetVertexPoolSize()) {
|
||||||
if (impl->VBO) impl->VBO->Release();
|
if (impl->VBO) impl->VBO->Release();
|
||||||
impl->Device->CreateVertexBuffer(GetVertexPoolSize() * sizeof(Li::Vertex),
|
impl->Device->CreateVertexBuffer(GetVertexPoolSize() * sizeof(Li::Vertex),
|
||||||
D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY, 0,
|
D3DUSAGE_WRITEONLY, 0, D3DPOOL_MANAGED,
|
||||||
D3DPOOL_DEFAULT, &impl->VBO, nullptr);
|
&impl->VBO, nullptr);
|
||||||
impl->VertexBufferSize = GetVertexPoolSize();
|
impl->VertexBufferSize = GetVertexPoolSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!impl->IBO || impl->IndexBufferSize != GetIndexPoolSize()) {
|
if (!impl->IBO || impl->IndexBufferSize != GetIndexPoolSize()) {
|
||||||
if (impl->IBO) impl->IBO->Release();
|
if (impl->IBO) impl->IBO->Release();
|
||||||
impl->Device->CreateIndexBuffer(
|
impl->Device->CreateIndexBuffer(GetIndexPoolSize() * sizeof(u16),
|
||||||
GetIndexPoolSize() * sizeof(u16), D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY,
|
D3DUSAGE_WRITEONLY, D3DFMT_INDEX16,
|
||||||
D3DFMT_INDEX16, D3DPOOL_DEFAULT, &impl->IBO, nullptr);
|
D3DPOOL_MANAGED, &impl->IBO, nullptr);
|
||||||
impl->IndexBufferSize = GetIndexPoolSize();
|
impl->IndexBufferSize = GetIndexPoolSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
void* vptr;
|
void* vptr;
|
||||||
impl->VBO->Lock(0, 0, &vptr, D3DLOCK_DISCARD);
|
impl->VBO->Lock(0, 0, &vptr, 0);
|
||||||
memcpy(vptr, GetVertexBufPtr(0),
|
memcpy(vptr, GetVertexBufPtr(0),
|
||||||
GetVertexPoolSize() * sizeof(PD::Li::Vertex));
|
GetVertexPoolSize() * sizeof(PD::Li::Vertex));
|
||||||
impl->VBO->Unlock();
|
impl->VBO->Unlock();
|
||||||
|
|
||||||
void* iptr;
|
void* iptr;
|
||||||
impl->IBO->Lock(0, 0, &iptr, D3DLOCK_DISCARD);
|
impl->IBO->Lock(0, 0, &iptr, 0);
|
||||||
memcpy(iptr, GetIndexBufPtr(0), GetIndexPoolSize() * sizeof(u16));
|
memcpy(iptr, GetIndexBufPtr(0), GetIndexPoolSize() * sizeof(u16));
|
||||||
impl->IBO->Unlock();
|
impl->IBO->Unlock();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ struct DesktopOS::Impl {
|
|||||||
#if WIN32
|
#if WIN32
|
||||||
IDirect3D9* d3d = nullptr;
|
IDirect3D9* d3d = nullptr;
|
||||||
IDirect3DDevice9* dx9_device = nullptr;
|
IDirect3DDevice9* dx9_device = nullptr;
|
||||||
|
D3DPRESENT_PARAMETERS d3dpp = {};
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -56,17 +57,18 @@ void DesktopOS::Init() {
|
|||||||
if (pDriver == Driver::DirectX9) {
|
if (pDriver == Driver::DirectX9) {
|
||||||
impl->d3d = Direct3DCreate9(D3D_SDK_VERSION);
|
impl->d3d = Direct3DCreate9(D3D_SDK_VERSION);
|
||||||
auto hwnd = glfwGetWin32Window(impl->win);
|
auto hwnd = glfwGetWin32Window(impl->win);
|
||||||
D3DPRESENT_PARAMETERS d3dpp = {};
|
|
||||||
d3dpp.Windowed = TRUE;
|
impl->d3dpp = D3DPRESENT_PARAMETERS{};
|
||||||
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
|
impl->d3dpp.Windowed = TRUE;
|
||||||
d3dpp.hDeviceWindow = hwnd;
|
impl->d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
|
||||||
d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
|
impl->d3dpp.hDeviceWindow = hwnd;
|
||||||
d3dpp.EnableAutoDepthStencil = TRUE;
|
impl->d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
|
||||||
d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
|
impl->d3dpp.EnableAutoDepthStencil = TRUE;
|
||||||
|
impl->d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
|
||||||
|
|
||||||
HRESULT hr = impl->d3d->CreateDevice(
|
HRESULT hr = impl->d3d->CreateDevice(
|
||||||
D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd,
|
D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd,
|
||||||
D3DCREATE_HARDWARE_VERTEXPROCESSING, &d3dpp, &impl->dx9_device);
|
D3DCREATE_HARDWARE_VERTEXPROCESSING, &impl->d3dpp, &impl->dx9_device);
|
||||||
if (FAILED(hr)) {
|
if (FAILED(hr)) {
|
||||||
MessageBoxW(nullptr, L"Failed to create D3D9 device", L"Error", MB_OK);
|
MessageBoxW(nullptr, L"Failed to create D3D9 device", L"Error", MB_OK);
|
||||||
std::abort();
|
std::abort();
|
||||||
@@ -100,7 +102,15 @@ void DesktopOS::ClearViewPort() {
|
|||||||
glViewport(0, 0, pViewPort.x, pViewPort.y);
|
glViewport(0, 0, pViewPort.x, pViewPort.y);
|
||||||
} else if (pDriver == Driver::DirectX9) {
|
} else if (pDriver == Driver::DirectX9) {
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
if (impl->dx9_device) {
|
// Resize the swapchain to match the window size
|
||||||
|
if (impl->dx9_device && pViewPort.x > 0 && pViewPort.y > 0) {
|
||||||
|
if (impl->d3dpp.BackBufferWidth != (UINT)pViewPort.x ||
|
||||||
|
impl->d3dpp.BackBufferHeight != (UINT)pViewPort.y) {
|
||||||
|
impl->d3dpp.BackBufferWidth = pViewPort.x;
|
||||||
|
impl->d3dpp.BackBufferHeight = pViewPort.y;
|
||||||
|
impl->dx9_device->Reset(&impl->d3dpp);
|
||||||
|
}
|
||||||
|
|
||||||
impl->dx9_device->Clear(0, nullptr, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER,
|
impl->dx9_device->Clear(0, nullptr, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER,
|
||||||
D3DCOLOR_XRGB(25, 25, 25), 1.0f, 0);
|
D3DCOLOR_XRGB(25, 25, 25), 1.0f, 0);
|
||||||
impl->dx9_device->BeginScene();
|
impl->dx9_device->BeginScene();
|
||||||
@@ -112,7 +122,8 @@ void DesktopOS::ClearViewPort() {
|
|||||||
void DesktopOS::SwapBuffers() {
|
void DesktopOS::SwapBuffers() {
|
||||||
if (pDriver == Driver::DirectX9) {
|
if (pDriver == Driver::DirectX9) {
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
if (impl->dx9_device) {
|
// yes we schould use some safetey checks
|
||||||
|
if (impl->dx9_device && pViewPort.x > 0 && pViewPort.y > 0) {
|
||||||
impl->dx9_device->EndScene();
|
impl->dx9_device->EndScene();
|
||||||
impl->dx9_device->Present(nullptr, nullptr, nullptr, nullptr);
|
impl->dx9_device->Present(nullptr, nullptr, nullptr, nullptr);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user