Initial WIP on OpenGL contexts being able to report themselves as lost

This commit is contained in:
UnknownShadow200 2019-07-21 17:15:30 +10:00
parent 4a5594f577
commit fc58658e58
5 changed files with 36 additions and 19 deletions

View File

@ -1302,7 +1302,7 @@ void Gfx_SetFpsLimit(bool vsync, float minFrameMs) {
void Gfx_BeginFrame(void) { frameStart = Stopwatch_Measure(); }
void Gfx_Clear(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); }
void Gfx_EndFrame(void) {
GLContext_SwapBuffers();
if (!GLContext_SwapBuffers()) Gfx_LoseContext("GLContext lost");
if (gfx_minFrameMs) Gfx_LimitFPS();
}
@ -1641,8 +1641,8 @@ static void Gfx_RestoreState(void) {
Gfx_InitDefaultResources();
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
gfx_batchFormat = -1;
Gfx_SwitchProgram();
Gfx_DirtyUniform(UNI_MASK_ALL);
GL_ClearCol(gfx_clearCol);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
@ -1776,6 +1776,7 @@ static void Gfx_RestoreState(void) {
Gfx_InitDefaultResources();
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
gfx_batchFormat = -1;
glHint(GL_FOG_HINT, GL_NICEST);
glAlphaFunc(GL_GREATER, 0.5f);

View File

@ -1691,6 +1691,7 @@ ReturnCode Process_StartShell(void) {
static const String path = String_FromConst("xterm");
static const String args = String_FromConst("-e ./update.sh");
return Process_Start(&path, &args);
}
#endif
/* Retrieving exe path is completely OS dependant */
#if defined CC_BUILD_OSX
@ -1998,7 +1999,6 @@ int Platform_ConvertUniString(void* data, const UniString* src) {
return len;
}
static void Platform_InitCommon(void) {
signal(SIGCHLD, SIG_IGN);
/* So writing to closed socket doesn't raise SIGPIPE */

View File

@ -258,7 +258,9 @@ void JavaCallVoid(JNIEnv* env, const char* name, const char* sig, jvalue* args);
jint JavaCallInt(JNIEnv* env, const char* name, const char* sig, jvalue* args);
/* Calls a method in the activity class that returns a jobject. */
jobject JavaCallObject(JNIEnv* env, const char* name, const char* sig, jvalue* args);
/* Calls a method in the activity class that takes a string and returns nothig. */
/* Calls a method in the activity class that takes a string and returns nothing. */
void JavaCall_String_Void(const char* name, const String* value);
/* Calls a method in the activity class that takes an int argument and returns a string. */
void JavaCall_Int_String(const char* name, int arg, String* dst);
#endif
#endif

View File

@ -3158,10 +3158,9 @@ void* GLContext_GetAddress(const char* function) {
return GLContext_IsInvalidAddress(address) ? NULL : address;
}
void GLContext_SwapBuffers(void) {
if (!SwapBuffers(ctx_DC)) {
Logger_Abort2(GetLastError(), "Failed to swap buffers");
}
bool GLContext_SwapBuffers(void) {
if (!SwapBuffers(ctx_DC)) Logger_Abort2(GetLastError(), "Failed to swap buffers");
return true;
}
void GLContext_SetFpsLimit(bool vsync, float minFrameMs) {
@ -3232,8 +3231,9 @@ void* GLContext_GetAddress(const char* function) {
return GLContext_IsInvalidAddress(address) ? NULL : address;
}
void GLContext_SwapBuffers(void) {
bool GLContext_SwapBuffers(void) {
glXSwapBuffers(win_display, win_handle);
return true;
}
void GLContext_SetFpsLimit(bool vsync, float minFrameMs) {
@ -3454,9 +3454,10 @@ void* GLContext_GetAddress(const char* function) {
return GLContext_IsInvalidAddress(address) ? NULL : address;
}
void GLContext_SwapBuffers(void) {
bool GLContext_SwapBuffers(void) {
aglSwapBuffers(ctx_handle);
GLContext_Check(0, "Swapping buffers");
return true;
}
void GLContext_SetFpsLimit(bool vsync, float minFrameMs) {
@ -3498,8 +3499,9 @@ void* GLContext_GetAddress(const char* function) {
return SDL_GL_GetProcAddress(function);
}
void GLContext_SwapBuffers(void) {
bool GLContext_SwapBuffers(void) {
SDL_GL_SwapWindow(win_handle);
return true;
}
void GLContext_SetFpsLimit(bool vsync, float minFrameMs) {
@ -3527,6 +3529,12 @@ static EGLint ctx_numConfig;
return info;
}*/
static void GLContext_InitSurface(void) {
if (!win_handle) return; /* window not created or lost */
ctx_surface = eglCreateWindowSurface(ctx_display, ctx_config, win_handle, NULL);
eglMakeCurrent(ctx_display, ctx_surface, ctx_surface, ctx_context);
}
void GLContext_Init(struct GraphicsMode* mode) {
static EGLint contextAttribs[3] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE };
static EGLint attribs[19] = {
@ -3549,16 +3557,20 @@ void GLContext_Init(struct GraphicsMode* mode) {
eglChooseConfig(ctx_display, attribs, &ctx_config, 1, &ctx_numConfig);
ctx_context = eglCreateContext(ctx_display, ctx_config, EGL_NO_CONTEXT, contextAttribs);
ctx_surface = eglCreateWindowSurface(ctx_display, ctx_config, win_handle, NULL);
eglMakeCurrent(ctx_display, ctx_surface, ctx_surface, ctx_context);\
GLContext_InitSurface();
}
void GLContext_Update(void) {
eglMakeCurrent(ctx_display, EGL_NO_SURFACE, EGL_NO_SURFACE, ctx_context);
eglDestroySurface(ctx_display, ctx_surface);
ctx_surface = eglCreateWindowSurface(ctx_display, ctx_config, win_handle, NULL);
eglMakeCurrent(ctx_display, ctx_surface, ctx_surface, ctx_context);
ctx_surface = NULL;
GLContext_InitSurface();
}
bool GLContext_TryRestore(void) {
GLContext_InitSurface();
return ctx_surface != NULL;
}
bool GLContext_TryRestore(void) { return true; }
void GLContext_Free(void) {
eglMakeCurrent(ctx_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
@ -3571,8 +3583,10 @@ void* GLContext_GetAddress(const char* function) {
return eglGetProcAddress(function);
}
void GLContext_SwapBuffers(void) {
bool GLContext_SwapBuffers(void) {
if (!ctx_surface) return false;
eglSwapBuffers(ctx_display, ctx_surface);
return true;
}
void GLContext_SetFpsLimit(bool vsync, float minFrameMs) {
@ -3621,7 +3635,7 @@ void GLContext_Free(void) {
}
void* GLContext_GetAddress(const char* function) { return NULL; }
void GLContext_SwapBuffers(void) { /* Browser implicitly does this */ }
bool GLContext_SwapBuffers(void) { return true; /* Browser implicitly does this */ }
void GLContext_SetFpsLimit(bool vsync, float minFrameMs) {
if (vsync) {

View File

@ -157,7 +157,7 @@ void GLContext_Free(void);
You must check the OpenGL version and/or GL_EXTENSIONS string for actual support! */
void* GLContext_GetAddress(const char* function);
/* Swaps the front and back buffer, displaying the back buffer on screen. */
void GLContext_SwapBuffers(void);
bool GLContext_SwapBuffers(void);
/* Sets whether synchronisation with the monitor is used. */
/* NOTE: The underlying platform may choose to still ignore this. */
void GLContext_SetFpsLimit(bool vsync, float minFrameMs);