mirror of https://github.com/PCSX2/pcsx2.git
gsdx ogl: improve error message on windows
* Common function * Print an error id * Don't exit on bad setpixelformat (it is illegal to call it twice)
This commit is contained in:
parent
f3adf4bf57
commit
726f9d5312
|
@ -23,6 +23,22 @@
|
||||||
#include "GSWndWGL.h"
|
#include "GSWndWGL.h"
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
|
||||||
|
static void win_error(const char* msg, bool fatal = true)
|
||||||
|
{
|
||||||
|
DWORD errorID = ::GetLastError();
|
||||||
|
if (errorID)
|
||||||
|
fprintf(stderr, "WIN API ERROR:%ld\t", errorID);
|
||||||
|
|
||||||
|
if (fatal) {
|
||||||
|
MessageBox(NULL, msg, "ERROR", MB_OK | MB_ICONEXCLAMATION);
|
||||||
|
throw GSDXRecoverableError();
|
||||||
|
} else {
|
||||||
|
fprintf(stderr, "ERROR:%s\n", msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
GSWndWGL::GSWndWGL()
|
GSWndWGL::GSWndWGL()
|
||||||
: m_NativeWindow(NULL), m_NativeDisplay(NULL), m_context(NULL)
|
: m_NativeWindow(NULL), m_NativeDisplay(NULL), m_context(NULL)
|
||||||
{
|
{
|
||||||
|
@ -49,7 +65,7 @@ void GSWndWGL::CreateContext(int major, int minor)
|
||||||
{
|
{
|
||||||
if (!m_NativeDisplay || !m_NativeWindow)
|
if (!m_NativeDisplay || !m_NativeWindow)
|
||||||
{
|
{
|
||||||
fprintf( stderr, "Wrong display/window\n" );
|
win_error("Wrong display/window", false);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,10 +73,8 @@ void GSWndWGL::CreateContext(int major, int minor)
|
||||||
|
|
||||||
// GL2 context are quite easy but we need GL3 which is another painful story...
|
// GL2 context are quite easy but we need GL3 which is another painful story...
|
||||||
m_context = wglCreateContext(m_NativeDisplay);
|
m_context = wglCreateContext(m_NativeDisplay);
|
||||||
if (!m_context) {
|
if (!m_context)
|
||||||
fprintf(stderr, "Failed to create a 2.0 context\n");
|
win_error("Failed to create a 2.0 context");
|
||||||
throw GSDXRecoverableError();
|
|
||||||
}
|
|
||||||
|
|
||||||
// FIXME test it
|
// FIXME test it
|
||||||
// Note: albeit every tutorial said that we need an opengl context to use the GL function wglCreateContextAttribsARB
|
// Note: albeit every tutorial said that we need an opengl context to use the GL function wglCreateContextAttribsARB
|
||||||
|
@ -87,14 +101,12 @@ void GSWndWGL::CreateContext(int major, int minor)
|
||||||
};
|
};
|
||||||
|
|
||||||
PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC)wglGetProcAddress("wglCreateContextAttribsARB");
|
PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC)wglGetProcAddress("wglCreateContextAttribsARB");
|
||||||
if (!wglCreateContextAttribsARB) {
|
if (!wglCreateContextAttribsARB)
|
||||||
fprintf(stderr, "Failed to init wglCreateContextAttribsARB function pointer\n");
|
win_error("Failed to init wglCreateContextAttribsARB function pointer");
|
||||||
throw GSDXRecoverableError();
|
|
||||||
}
|
|
||||||
|
|
||||||
HGLRC context30 = wglCreateContextAttribsARB(m_NativeDisplay, NULL, context_attribs);
|
HGLRC context30 = wglCreateContextAttribsARB(m_NativeDisplay, NULL, context_attribs);
|
||||||
if (!context30) {
|
if (!context30) {
|
||||||
fprintf(stderr, "Failed to create a 3.x context with standard flags\n");
|
win_error("Failed to create a 3.x context with standard flags", false);
|
||||||
// retry with more compatible option for (Mesa on Windows, OpenGL on WINE)
|
// retry with more compatible option for (Mesa on Windows, OpenGL on WINE)
|
||||||
context_attribs[2*2+1] = 0;
|
context_attribs[2*2+1] = 0;
|
||||||
|
|
||||||
|
@ -104,10 +116,8 @@ void GSWndWGL::CreateContext(int major, int minor)
|
||||||
DetachContext();
|
DetachContext();
|
||||||
wglDeleteContext(m_context);
|
wglDeleteContext(m_context);
|
||||||
|
|
||||||
if (!context30) {
|
if (!context30)
|
||||||
fprintf(stderr, "Failed to create a 3.x context with compatible flags\n");
|
win_error("Failed to create a 3.x context with compatible flags");
|
||||||
throw GSDXRecoverableError();
|
|
||||||
}
|
|
||||||
|
|
||||||
m_context = context30;
|
m_context = context30;
|
||||||
fprintf(stderr, "3.x GL context successfully created\n");
|
fprintf(stderr, "3.x GL context successfully created\n");
|
||||||
|
@ -129,19 +139,6 @@ void GSWndWGL::DetachContext()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: DROP ???
|
|
||||||
void GSWndWGL::CheckContext()
|
|
||||||
{
|
|
||||||
#if 0
|
|
||||||
int glxMajorVersion, glxMinorVersion;
|
|
||||||
glXQueryVersion(m_NativeDisplay, &glxMajorVersion, &glxMinorVersion);
|
|
||||||
if (glXIsDirect(m_NativeDisplay, m_context))
|
|
||||||
fprintf(stderr, "glX-Version %d.%d with Direct Rendering\n", glxMajorVersion, glxMinorVersion);
|
|
||||||
else
|
|
||||||
fprintf(stderr, "glX-Version %d.%d with Indirect Rendering !!! It won't support properly opengl\n", glxMajorVersion, glxMinorVersion);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
bool GSWndWGL::Attach(void* handle, bool managed)
|
bool GSWndWGL::Attach(void* handle, bool managed)
|
||||||
{
|
{
|
||||||
m_NativeWindow = (HWND)handle;
|
m_NativeWindow = (HWND)handle;
|
||||||
|
@ -153,8 +150,6 @@ bool GSWndWGL::Attach(void* handle, bool managed)
|
||||||
|
|
||||||
AttachContext();
|
AttachContext();
|
||||||
|
|
||||||
CheckContext();
|
|
||||||
|
|
||||||
m_swapinterval = (PFNWGLSWAPINTERVALEXTPROC)wglGetProcAddress("wglSwapIntervalEXT");
|
m_swapinterval = (PFNWGLSWAPINTERVALEXTPROC)wglGetProcAddress("wglSwapIntervalEXT");
|
||||||
|
|
||||||
PopulateGlFunction();
|
PopulateGlFunction();
|
||||||
|
@ -212,31 +207,22 @@ void GSWndWGL::OpenWGLDisplay()
|
||||||
|
|
||||||
m_NativeDisplay = GetDC(m_NativeWindow);
|
m_NativeDisplay = GetDC(m_NativeWindow);
|
||||||
if (!m_NativeDisplay)
|
if (!m_NativeDisplay)
|
||||||
{
|
win_error("(1) Can't Create A GL Device Context.");
|
||||||
MessageBox(NULL, "(1) Can't Create A GL Device Context.", "ERROR", MB_OK | MB_ICONEXCLAMATION);
|
|
||||||
throw GSDXRecoverableError();
|
|
||||||
}
|
|
||||||
PixelFormat = ChoosePixelFormat(m_NativeDisplay, &pfd);
|
PixelFormat = ChoosePixelFormat(m_NativeDisplay, &pfd);
|
||||||
if (!PixelFormat)
|
if (!PixelFormat)
|
||||||
{
|
win_error("(2) Can't Find A Suitable PixelFormat.");
|
||||||
MessageBox(NULL, "(2) Can't Find A Suitable PixelFormat.", "ERROR", MB_OK | MB_ICONEXCLAMATION);
|
|
||||||
throw GSDXRecoverableError();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!SetPixelFormat(m_NativeDisplay, PixelFormat, &pfd))
|
if (!SetPixelFormat(m_NativeDisplay, PixelFormat, &pfd))
|
||||||
{
|
win_error("(3) Can't Set The PixelFormat.", false);
|
||||||
MessageBox(NULL, "(3) Can't Set The PixelFormat.", "ERROR", MB_OK | MB_ICONEXCLAMATION);
|
|
||||||
throw GSDXRecoverableError();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GSWndWGL::CloseWGLDisplay()
|
void GSWndWGL::CloseWGLDisplay()
|
||||||
{
|
{
|
||||||
if (m_NativeDisplay && !ReleaseDC(m_NativeWindow, m_NativeDisplay)) // Are We Able To Release The DC
|
if (m_NativeDisplay && !ReleaseDC(m_NativeWindow, m_NativeDisplay))
|
||||||
{
|
win_error("Release Device Context Failed.");
|
||||||
MessageBox(NULL, "Release Device Context Failed.", "SHUTDOWN ERROR", MB_OK | MB_ICONINFORMATION);
|
|
||||||
}
|
m_NativeDisplay = NULL;
|
||||||
m_NativeDisplay = NULL; // Set DC To NULL
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: GSopen 1 => Drop?
|
//TODO: GSopen 1 => Drop?
|
||||||
|
|
|
@ -32,7 +32,6 @@ class GSWndWGL : public GSWndGL
|
||||||
PFNWGLSWAPINTERVALEXTPROC m_swapinterval;
|
PFNWGLSWAPINTERVALEXTPROC m_swapinterval;
|
||||||
|
|
||||||
void CreateContext(int major, int minor);
|
void CreateContext(int major, int minor);
|
||||||
void CheckContext();
|
|
||||||
|
|
||||||
void CloseWGLDisplay();
|
void CloseWGLDisplay();
|
||||||
void OpenWGLDisplay();
|
void OpenWGLDisplay();
|
||||||
|
|
Loading…
Reference in New Issue