Skip to content

Commit

Permalink
pcsx2: reset OpenGl context for Mesa drivers
Browse files Browse the repository at this point in the history
  • Loading branch information
beaumanvienna committed Sep 1, 2020
1 parent 55b1d26 commit 66bcd66
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 9 deletions.
21 changes: 13 additions & 8 deletions src/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,14 +326,9 @@ SDL_Texture* loadTextureFromFile(string str)
return texture;
}

bool initGUI(void)
{
bool ok = true;
Uint32 windowFlags;
int imgFlags;

SDL_ShowCursor(SDL_DISABLE);


void initOpenGL(void)
{
SDL_GL_ResetAttributes();

SDL_GL_SetAttribute( SDL_GL_CONTEXT_MAJOR_VERSION, 3 );
Expand All @@ -346,6 +341,16 @@ bool initGUI(void)
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 0);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetAttribute(SDL_GL_STEREO, 0);
}

bool initGUI(void)
{
bool ok = true;
Uint32 windowFlags;
int imgFlags;

SDL_ShowCursor(SDL_DISABLE);
initOpenGL();

SDL_DisplayMode current;
SDL_GetCurrentDisplayMode(0, &current);
Expand Down
39 changes: 38 additions & 1 deletion src/statemachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <algorithm>
#include <X11/Xlib.h>
#include <SDL_syswm.h>
#include <GL/gl.h>

int gState = 0;
int gCurrentGame;
Expand Down Expand Up @@ -65,6 +66,8 @@ extern Window Xwindow;

bool checkAxis(int cmd);
bool checkTrigger(int cmd);
void initOpenGL(void);
void setAppIcon(void);

void resetStatemachine(void)
{
Expand Down Expand Up @@ -493,7 +496,41 @@ void statemachine(int cmd)
argv[8] = arg9;

argc = 9;

const char* vendor_str = (const char*)glGetString(GL_VENDOR);
const char* version_str = (const char*)glGetString(GL_VERSION);
const char* renderer_str = (const char*)glGetString(GL_RENDERER);

printf("OpenGL Version: %s, Vendor: %s, Renderer: %s\n", version_str, vendor_str, renderer_str);
string renderer = renderer_str;
std::transform(renderer.begin(), renderer.end(), renderer.begin(),
[](unsigned char c){ return std::tolower(c); });
std::size_t found = renderer.find("mesa");
if (found!=std::string::npos)
{
printf("Mesa driver found, resetting OpenGL context\n");
// reset OpenGL context for Mesa driver
// destroy old
freeTextures();
SDL_DestroyRenderer( gRenderer );
SDL_DestroyWindow(gWindow);
// create new
initOpenGL();
Uint32 windowFlags = SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL;
if (gFullscreen)
{
windowFlags = windowFlags | SDL_WINDOW_FULLSCREEN_DESKTOP;
}

string str = "marley ";
str += PACKAGE_VERSION;
gWindow = SDL_CreateWindow( str.c_str(),
SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED,
WINDOW_WIDTH,
WINDOW_HEIGHT,
windowFlags );
setAppIcon();
}
SDL_SysWMinfo sdlWindowInfo;
SDL_VERSION(&sdlWindowInfo.version);
if(SDL_GetWindowWMInfo(gWindow, &sdlWindowInfo))
Expand Down

0 comments on commit 66bcd66

Please sign in to comment.