[client] allow renderers to pass back if they need an OpenGL context

This commit is contained in:
Geoffrey McRae 2021-01-27 19:38:34 +11:00
parent cc521eab90
commit 4dfe4b8e2b
5 changed files with 20 additions and 11 deletions

View File

@ -63,6 +63,9 @@ typedef struct LG_DSInitParams
bool borderless;
bool maximize;
bool minimizeOnFocusLoss;
// if true the renderer requires an OpenGL context
bool opengl;
}
LG_DSInitParams;

View File

@ -103,7 +103,7 @@ typedef const char * (* LG_RendererGetName)();
// called pre-creation to allow the renderer to register any options it might have
typedef void (* LG_RendererSetup)();
typedef bool (* LG_RendererCreate )(void ** opaque, const LG_RendererParams params);
typedef bool (* LG_RendererCreate )(void ** opaque, const LG_RendererParams params, bool * needsOpenGL);
typedef bool (* LG_RendererInitialize )(void * opaque);
typedef void (* LG_RendererDeInitialize )(void * opaque);
typedef bool (* LG_RendererSupports )(void * opaque, LG_RendererSupport support);

View File

@ -162,7 +162,7 @@ void egl_setup(void)
option_register(egl_options);
}
bool egl_create(void ** opaque, const LG_RendererParams params)
bool egl_create(void ** opaque, const LG_RendererParams params, bool * needsOpenGL)
{
// check if EGL is even available
if (!eglQueryString(EGL_NO_DISPLAY, EGL_VERSION))
@ -198,6 +198,7 @@ bool egl_create(void ** opaque, const LG_RendererParams params)
return false;
}
*needsOpenGL = false;
return true;
}

View File

@ -193,7 +193,8 @@ static void opengl_setup(void)
option_register(opengl_options);
}
bool opengl_create(void ** opaque, const LG_RendererParams params)
bool opengl_create(void ** opaque, const LG_RendererParams params,
bool * needsOpenGL)
{
// create our local storage
*opaque = malloc(sizeof(struct Inst));
@ -232,21 +233,21 @@ bool opengl_create(void ** opaque, const LG_RendererParams params)
this->alerts = ll_new();
*needsOpenGL = true;
return true;
}
bool opengl_initialize(void * opaque)
{
//FIXME
return false;
#if 0
struct Inst * this = (struct Inst *)opaque;
if (!this)
return false;
this->waiting = true;
this->waitDone = false;
return true;
#if 0
*sdlFlags = SDL_WINDOW_OPENGL;
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER , 1);
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);

View File

@ -590,7 +590,8 @@ void intHandler(int sig)
}
}
static bool tryRenderer(const int index, const LG_RendererParams lgrParams)
static bool tryRenderer(const int index, const LG_RendererParams lgrParams,
bool * needsOpenGL)
{
const LG_Renderer *r = LG_Renderers[index];
@ -602,7 +603,8 @@ static bool tryRenderer(const int index, const LG_RendererParams lgrParams)
// create the renderer
g_state.lgrData = NULL;
if (!r->create(&g_state.lgrData, lgrParams))
*needsOpenGL = false;
if (!r->create(&g_state.lgrData, lgrParams, needsOpenGL))
return false;
// initialize the renderer
@ -686,6 +688,7 @@ static int lg_run(void)
}
// select and init a renderer
bool needsOpenGL;
LG_RendererParams lgrParams;
lgrParams.showFPS = g_params.showFPS;
lgrParams.quickSplash = g_params.quickSplash;
@ -693,7 +696,7 @@ static int lg_run(void)
if (g_params.forceRenderer)
{
DEBUG_INFO("Trying forced renderer");
if (!tryRenderer(g_params.forceRendererIndex, lgrParams))
if (!tryRenderer(g_params.forceRendererIndex, lgrParams, &needsOpenGL))
{
DEBUG_ERROR("Forced renderer failed to iniailize");
return -1;
@ -705,7 +708,7 @@ static int lg_run(void)
// probe for a a suitable renderer
for(unsigned int i = 0; i < LG_RENDERER_COUNT; ++i)
{
if (tryRenderer(i, lgrParams))
if (tryRenderer(i, lgrParams, &needsOpenGL))
{
g_state.lgr = LG_Renderers[i];
break;
@ -731,7 +734,8 @@ static int lg_run(void)
.resizable = g_params.allowResize,
.borderless = g_params.borderless,
.maximize = g_params.maximize,
.minimizeOnFocusLoss = g_params.minimizeOnFocusLoss
.minimizeOnFocusLoss = g_params.minimizeOnFocusLoss,
.opengl = needsOpenGL
};
g_state.dsInitialized = g_state.ds->init(params);