mirror of
https://github.com/isledecomp/isle-portable.git
synced 2026-01-11 18:41:14 +00:00
Expose window during device probing (#462)
This commit is contained in:
parent
ab48ce60b0
commit
e2ff65cf91
@ -56,9 +56,17 @@ bool CConfigApp::InitInstance()
|
||||
return false;
|
||||
}
|
||||
m_device_enumerator = new LegoDeviceEnumerate;
|
||||
if (m_device_enumerator->DoEnumerate()) {
|
||||
SDL_Window* window = SDL_CreateWindow("Test window", 640, 480, SDL_WINDOW_HIDDEN | SDL_WINDOW_OPENGL);
|
||||
HWND hWnd;
|
||||
#ifdef MINIWIN
|
||||
hWnd = reinterpret_cast<HWND>(window);
|
||||
#else
|
||||
hWnd = (HWND) SDL_GetPointerProperty(SDL_GetWindowProperties(window), SDL_PROP_WINDOW_WIN32_HWND_POINTER, NULL);
|
||||
#endif
|
||||
if (m_device_enumerator->DoEnumerate(hWnd)) {
|
||||
return FALSE;
|
||||
}
|
||||
SDL_DestroyWindow(window);
|
||||
m_driver = NULL;
|
||||
m_device = NULL;
|
||||
m_full_screen = TRUE;
|
||||
|
||||
@ -108,7 +108,7 @@ MxResult LegoVideoManager::Create(MxVideoParam& p_videoParam, MxU32 p_frequencyM
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (deviceEnumerate.DoEnumerate() != SUCCESS) {
|
||||
if (deviceEnumerate.DoEnumerate(hwnd) != SUCCESS) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "LegoDeviceEnumerate::DoEnumerate failed");
|
||||
goto done;
|
||||
}
|
||||
|
||||
@ -215,6 +215,11 @@ BOOL MxDeviceEnumerate::EnumDirectDrawCallback(LPGUID p_guid, LPSTR p_driverDesc
|
||||
if (result != DD_OK) {
|
||||
BuildErrorString("DirectDraw Create failed: %s\n", EnumerateErrorToString(result));
|
||||
}
|
||||
else {
|
||||
result = lpDD->SetCooperativeLevel(m_hWnd, DDSCL_NORMAL);
|
||||
if (result != DD_OK) {
|
||||
BuildErrorString("SetCooperativeLevel failed: %s\n", EnumerateErrorToString(result));
|
||||
}
|
||||
else {
|
||||
newDevice.m_ddCaps.dwSize = sizeof(newDevice.m_ddCaps);
|
||||
result = lpDD->GetCaps(&newDevice.m_ddCaps, NULL);
|
||||
@ -242,6 +247,7 @@ BOOL MxDeviceEnumerate::EnumDirectDrawCallback(LPGUID p_guid, LPSTR p_driverDesc
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (lpDirect3d2) {
|
||||
lpDirect3d2->Release();
|
||||
@ -306,12 +312,14 @@ HRESULT MxDeviceEnumerate::EnumDevicesCallback(
|
||||
// FUNCTION: CONFIG 0x00401dc0
|
||||
// FUNCTION: LEGO1 0x1009c6c0
|
||||
// FUNCTION: BETA10 0x1011e3fa
|
||||
int MxDeviceEnumerate::DoEnumerate()
|
||||
int MxDeviceEnumerate::DoEnumerate(HWND hWnd)
|
||||
{
|
||||
if (IsInitialized()) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
m_hWnd = hWnd;
|
||||
|
||||
HRESULT ret = DirectDrawEnumerate(DirectDrawEnumerateCallback, this);
|
||||
if (ret != DD_OK) {
|
||||
BuildErrorString("DirectDrawEnumerate returned error %s\n", EnumerateErrorToString(ret));
|
||||
|
||||
@ -194,7 +194,7 @@ class MxDeviceEnumerate {
|
||||
MxDeviceEnumerate();
|
||||
~MxDeviceEnumerate();
|
||||
|
||||
virtual int DoEnumerate(); // vtable+0x00
|
||||
virtual int DoEnumerate(HWND hWnd); // vtable+0x00
|
||||
|
||||
BOOL EnumDirectDrawCallback(LPGUID p_guid, LPSTR p_driverDesc, LPSTR p_driverName);
|
||||
HRESULT EnumDevicesCallback(
|
||||
@ -242,6 +242,7 @@ class MxDeviceEnumerate {
|
||||
protected:
|
||||
list<MxDriver> m_list; // 0x04
|
||||
unsigned char m_initialized; // 0x10
|
||||
HWND m_hWnd;
|
||||
};
|
||||
|
||||
// TEMPLATE: BETA10 0x1011c1b0
|
||||
|
||||
@ -28,40 +28,25 @@ Direct3DRMRenderer* OpenGL1Renderer::Create(DWORD width, DWORD height)
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 1);
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
|
||||
|
||||
SDL_Window* window = DDWindow;
|
||||
bool testWindow = false;
|
||||
if (!window) {
|
||||
window = SDL_CreateWindow("OpenGL 1.1 test", width, height, SDL_WINDOW_HIDDEN | SDL_WINDOW_OPENGL);
|
||||
if (!window) {
|
||||
SDL_Log("SDL_CreateWindow: %s", SDL_GetError());
|
||||
if (!DDWindow) {
|
||||
SDL_Log("No window handler");
|
||||
return nullptr;
|
||||
}
|
||||
testWindow = true;
|
||||
}
|
||||
|
||||
SDL_GLContext context = SDL_GL_CreateContext(window);
|
||||
SDL_GLContext context = SDL_GL_CreateContext(DDWindow);
|
||||
if (!context) {
|
||||
SDL_Log("SDL_GL_CreateContext: %s", SDL_GetError());
|
||||
if (testWindow) {
|
||||
SDL_DestroyWindow(window);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!SDL_GL_MakeCurrent(window, context)) {
|
||||
if (!SDL_GL_MakeCurrent(DDWindow, context)) {
|
||||
SDL_GL_DestroyContext(context);
|
||||
SDL_Log("SDL_GL_MakeCurrent: %s", SDL_GetError());
|
||||
if (testWindow) {
|
||||
SDL_DestroyWindow(window);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
GL11_InitState();
|
||||
|
||||
if (testWindow) {
|
||||
SDL_DestroyWindow(window);
|
||||
}
|
||||
|
||||
return new OpenGL1Renderer(width, height, context);
|
||||
}
|
||||
|
||||
@ -78,6 +63,7 @@ OpenGL1Renderer::OpenGL1Renderer(DWORD width, DWORD height, SDL_GLContext contex
|
||||
OpenGL1Renderer::~OpenGL1Renderer()
|
||||
{
|
||||
SDL_DestroySurface(m_renderedImage);
|
||||
SDL_GL_DestroyContext(m_context);
|
||||
}
|
||||
|
||||
void OpenGL1Renderer::PushLights(const SceneLight* lightsArray, size_t count)
|
||||
|
||||
@ -40,25 +40,18 @@ Direct3DRMRenderer* OpenGLES2Renderer::Create(DWORD width, DWORD height)
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
|
||||
|
||||
SDL_Window* window = DDWindow;
|
||||
bool testWindow = false;
|
||||
if (!window) {
|
||||
window = SDL_CreateWindow("OpenGL ES 2.0 test", width, height, SDL_WINDOW_HIDDEN | SDL_WINDOW_OPENGL);
|
||||
testWindow = true;
|
||||
}
|
||||
|
||||
SDL_GLContext context = SDL_GL_CreateContext(window);
|
||||
if (!context) {
|
||||
if (testWindow) {
|
||||
SDL_DestroyWindow(window);
|
||||
}
|
||||
if (!DDWindow) {
|
||||
SDL_Log("No window handler");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!SDL_GL_MakeCurrent(window, context)) {
|
||||
if (testWindow) {
|
||||
SDL_DestroyWindow(window);
|
||||
SDL_GLContext context = SDL_GL_CreateContext(DDWindow);
|
||||
if (!context) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!SDL_GL_MakeCurrent(DDWindow, context)) {
|
||||
SDL_GL_DestroyContext(context);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -174,10 +167,6 @@ Direct3DRMRenderer* OpenGLES2Renderer::Create(DWORD width, DWORD height)
|
||||
glDeleteShader(vs);
|
||||
glDeleteShader(fs);
|
||||
|
||||
if (testWindow) {
|
||||
SDL_DestroyWindow(window);
|
||||
}
|
||||
|
||||
return new OpenGLES2Renderer(width, height, context, shaderProgram);
|
||||
}
|
||||
|
||||
@ -285,6 +274,7 @@ OpenGLES2Renderer::OpenGLES2Renderer(DWORD width, DWORD height, SDL_GLContext co
|
||||
OpenGLES2Renderer::~OpenGLES2Renderer()
|
||||
{
|
||||
SDL_DestroySurface(m_renderedImage);
|
||||
SDL_GL_DestroyContext(m_context);
|
||||
glDeleteProgram(m_shaderProgram);
|
||||
}
|
||||
|
||||
|
||||
@ -203,49 +203,31 @@ Direct3DRMRenderer* Direct3DRMSDL3GPURenderer::Create(DWORD width, DWORD height)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
SDL_Window* window = DDWindow;
|
||||
bool testWindow = false;
|
||||
if (!window) {
|
||||
window = SDL_CreateWindow("SDL_GPU test", width, height, SDL_WINDOW_HIDDEN);
|
||||
if (!window) {
|
||||
SDL_Log("SDL_CreateWindow: %s", SDL_GetError());
|
||||
if (!DDWindow) {
|
||||
SDL_Log("No window handler");
|
||||
return nullptr;
|
||||
}
|
||||
testWindow = true;
|
||||
}
|
||||
|
||||
if (!SDL_ClaimWindowForGPUDevice(device.ptr, window)) {
|
||||
if (!SDL_ClaimWindowForGPUDevice(device.ptr, DDWindow)) {
|
||||
SDL_LogError(LOG_CATEGORY_MINIWIN, "SDL_ClaimWindowForGPUDevice: %s", SDL_GetError());
|
||||
if (testWindow) {
|
||||
SDL_DestroyWindow(window);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ScopedPipeline opaquePipeline{device.ptr, InitializeGraphicsPipeline(device.ptr, window, true, true)};
|
||||
ScopedPipeline opaquePipeline{device.ptr, InitializeGraphicsPipeline(device.ptr, DDWindow, true, true)};
|
||||
if (!opaquePipeline.ptr) {
|
||||
SDL_LogError(LOG_CATEGORY_MINIWIN, "InitializeGraphicsPipeline for opaquePipeline");
|
||||
if (testWindow) {
|
||||
SDL_DestroyWindow(window);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ScopedPipeline transparentPipeline{device.ptr, InitializeGraphicsPipeline(device.ptr, window, true, false)};
|
||||
ScopedPipeline transparentPipeline{device.ptr, InitializeGraphicsPipeline(device.ptr, DDWindow, true, false)};
|
||||
if (!transparentPipeline.ptr) {
|
||||
SDL_LogError(LOG_CATEGORY_MINIWIN, "InitializeGraphicsPipeline for transparentPipeline");
|
||||
if (testWindow) {
|
||||
SDL_DestroyWindow(window);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ScopedPipeline uiPipeline{device.ptr, InitializeGraphicsPipeline(device.ptr, window, false, false)};
|
||||
ScopedPipeline uiPipeline{device.ptr, InitializeGraphicsPipeline(device.ptr, DDWindow, false, false)};
|
||||
if (!uiPipeline.ptr) {
|
||||
SDL_LogError(LOG_CATEGORY_MINIWIN, "InitializeGraphicsPipeline for uiPipeline");
|
||||
if (testWindow) {
|
||||
SDL_DestroyWindow(window);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -257,9 +239,6 @@ Direct3DRMRenderer* Direct3DRMSDL3GPURenderer::Create(DWORD width, DWORD height)
|
||||
ScopedTransferBuffer uploadBuffer{device.ptr, SDL_CreateGPUTransferBuffer(device.ptr, &uploadBufferInfo)};
|
||||
if (!uploadBuffer.ptr) {
|
||||
SDL_LogError(LOG_CATEGORY_MINIWIN, "SDL_CreateGPUTransferBuffer filed for upload buffer (%s)", SDL_GetError());
|
||||
if (testWindow) {
|
||||
SDL_DestroyWindow(window);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -273,9 +252,6 @@ Direct3DRMRenderer* Direct3DRMSDL3GPURenderer::Create(DWORD width, DWORD height)
|
||||
ScopedSampler sampler{device.ptr, SDL_CreateGPUSampler(device.ptr, &samplerInfo)};
|
||||
if (!sampler.ptr) {
|
||||
SDL_LogError(LOG_CATEGORY_MINIWIN, "Failed to create sampler: %s", SDL_GetError());
|
||||
if (testWindow) {
|
||||
SDL_DestroyWindow(window);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -289,17 +265,9 @@ Direct3DRMRenderer* Direct3DRMSDL3GPURenderer::Create(DWORD width, DWORD height)
|
||||
ScopedSampler uiSampler{device.ptr, SDL_CreateGPUSampler(device.ptr, &uiSamplerInfo)};
|
||||
if (!uiSampler.ptr) {
|
||||
SDL_LogError(LOG_CATEGORY_MINIWIN, "Failed to create sampler: %s", SDL_GetError());
|
||||
if (testWindow) {
|
||||
SDL_DestroyWindow(window);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (testWindow) {
|
||||
SDL_ReleaseWindowFromGPUDevice(device.ptr, window);
|
||||
SDL_DestroyWindow(window);
|
||||
}
|
||||
|
||||
auto renderer = new Direct3DRMSDL3GPURenderer(
|
||||
width,
|
||||
height,
|
||||
@ -383,9 +351,7 @@ Direct3DRMSDL3GPURenderer::~Direct3DRMSDL3GPURenderer()
|
||||
{
|
||||
SDL_ReleaseGPUBuffer(m_device, m_uiMeshCache.vertexBuffer);
|
||||
SDL_ReleaseGPUBuffer(m_device, m_uiMeshCache.indexBuffer);
|
||||
if (DDWindow) {
|
||||
SDL_ReleaseWindowFromGPUDevice(m_device, DDWindow);
|
||||
}
|
||||
if (m_downloadBuffer) {
|
||||
SDL_ReleaseGPUTransferBuffer(m_device, m_downloadBuffer);
|
||||
}
|
||||
@ -839,10 +805,6 @@ void Direct3DRMSDL3GPURenderer::Resize(int width, int height, const ViewportTran
|
||||
m_height = height;
|
||||
m_viewportTransform = viewportTransform;
|
||||
|
||||
if (!DDWindow) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_transferTexture) {
|
||||
SDL_ReleaseGPUTexture(m_device, m_transferTexture);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user