mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-18 12:05:14 -04:00
Initial WIP on OpenGL contexts being able to report themselves as lost
This commit is contained in:
parent
4a5594f577
commit
fc58658e58
@ -1302,7 +1302,7 @@ void Gfx_SetFpsLimit(bool vsync, float minFrameMs) {
|
|||||||
void Gfx_BeginFrame(void) { frameStart = Stopwatch_Measure(); }
|
void Gfx_BeginFrame(void) { frameStart = Stopwatch_Measure(); }
|
||||||
void Gfx_Clear(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); }
|
void Gfx_Clear(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); }
|
||||||
void Gfx_EndFrame(void) {
|
void Gfx_EndFrame(void) {
|
||||||
GLContext_SwapBuffers();
|
if (!GLContext_SwapBuffers()) Gfx_LoseContext("GLContext lost");
|
||||||
if (gfx_minFrameMs) Gfx_LimitFPS();
|
if (gfx_minFrameMs) Gfx_LimitFPS();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1641,8 +1641,8 @@ static void Gfx_RestoreState(void) {
|
|||||||
Gfx_InitDefaultResources();
|
Gfx_InitDefaultResources();
|
||||||
glEnableVertexAttribArray(0);
|
glEnableVertexAttribArray(0);
|
||||||
glEnableVertexAttribArray(1);
|
glEnableVertexAttribArray(1);
|
||||||
|
gfx_batchFormat = -1;
|
||||||
|
|
||||||
Gfx_SwitchProgram();
|
|
||||||
Gfx_DirtyUniform(UNI_MASK_ALL);
|
Gfx_DirtyUniform(UNI_MASK_ALL);
|
||||||
GL_ClearCol(gfx_clearCol);
|
GL_ClearCol(gfx_clearCol);
|
||||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
@ -1776,6 +1776,7 @@ static void Gfx_RestoreState(void) {
|
|||||||
Gfx_InitDefaultResources();
|
Gfx_InitDefaultResources();
|
||||||
glEnableClientState(GL_VERTEX_ARRAY);
|
glEnableClientState(GL_VERTEX_ARRAY);
|
||||||
glEnableClientState(GL_COLOR_ARRAY);
|
glEnableClientState(GL_COLOR_ARRAY);
|
||||||
|
gfx_batchFormat = -1;
|
||||||
|
|
||||||
glHint(GL_FOG_HINT, GL_NICEST);
|
glHint(GL_FOG_HINT, GL_NICEST);
|
||||||
glAlphaFunc(GL_GREATER, 0.5f);
|
glAlphaFunc(GL_GREATER, 0.5f);
|
||||||
|
@ -1691,6 +1691,7 @@ ReturnCode Process_StartShell(void) {
|
|||||||
static const String path = String_FromConst("xterm");
|
static const String path = String_FromConst("xterm");
|
||||||
static const String args = String_FromConst("-e ./update.sh");
|
static const String args = String_FromConst("-e ./update.sh");
|
||||||
return Process_Start(&path, &args);
|
return Process_Start(&path, &args);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
/* Retrieving exe path is completely OS dependant */
|
/* Retrieving exe path is completely OS dependant */
|
||||||
#if defined CC_BUILD_OSX
|
#if defined CC_BUILD_OSX
|
||||||
@ -1998,7 +1999,6 @@ int Platform_ConvertUniString(void* data, const UniString* src) {
|
|||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void Platform_InitCommon(void) {
|
static void Platform_InitCommon(void) {
|
||||||
signal(SIGCHLD, SIG_IGN);
|
signal(SIGCHLD, SIG_IGN);
|
||||||
/* So writing to closed socket doesn't raise SIGPIPE */
|
/* So writing to closed socket doesn't raise SIGPIPE */
|
||||||
|
@ -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);
|
jint JavaCallInt(JNIEnv* env, const char* name, const char* sig, jvalue* args);
|
||||||
/* Calls a method in the activity class that returns a jobject. */
|
/* Calls a method in the activity class that returns a jobject. */
|
||||||
jobject JavaCallObject(JNIEnv* env, const char* name, const char* sig, jvalue* args);
|
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);
|
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
|
||||||
#endif
|
#endif
|
||||||
|
42
src/Window.c
42
src/Window.c
@ -3158,10 +3158,9 @@ void* GLContext_GetAddress(const char* function) {
|
|||||||
return GLContext_IsInvalidAddress(address) ? NULL : address;
|
return GLContext_IsInvalidAddress(address) ? NULL : address;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLContext_SwapBuffers(void) {
|
bool GLContext_SwapBuffers(void) {
|
||||||
if (!SwapBuffers(ctx_DC)) {
|
if (!SwapBuffers(ctx_DC)) Logger_Abort2(GetLastError(), "Failed to swap buffers");
|
||||||
Logger_Abort2(GetLastError(), "Failed to swap buffers");
|
return true;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLContext_SetFpsLimit(bool vsync, float minFrameMs) {
|
void GLContext_SetFpsLimit(bool vsync, float minFrameMs) {
|
||||||
@ -3232,8 +3231,9 @@ void* GLContext_GetAddress(const char* function) {
|
|||||||
return GLContext_IsInvalidAddress(address) ? NULL : address;
|
return GLContext_IsInvalidAddress(address) ? NULL : address;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLContext_SwapBuffers(void) {
|
bool GLContext_SwapBuffers(void) {
|
||||||
glXSwapBuffers(win_display, win_handle);
|
glXSwapBuffers(win_display, win_handle);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLContext_SetFpsLimit(bool vsync, float minFrameMs) {
|
void GLContext_SetFpsLimit(bool vsync, float minFrameMs) {
|
||||||
@ -3454,9 +3454,10 @@ void* GLContext_GetAddress(const char* function) {
|
|||||||
return GLContext_IsInvalidAddress(address) ? NULL : address;
|
return GLContext_IsInvalidAddress(address) ? NULL : address;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLContext_SwapBuffers(void) {
|
bool GLContext_SwapBuffers(void) {
|
||||||
aglSwapBuffers(ctx_handle);
|
aglSwapBuffers(ctx_handle);
|
||||||
GLContext_Check(0, "Swapping buffers");
|
GLContext_Check(0, "Swapping buffers");
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLContext_SetFpsLimit(bool vsync, float minFrameMs) {
|
void GLContext_SetFpsLimit(bool vsync, float minFrameMs) {
|
||||||
@ -3498,8 +3499,9 @@ void* GLContext_GetAddress(const char* function) {
|
|||||||
return SDL_GL_GetProcAddress(function);
|
return SDL_GL_GetProcAddress(function);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLContext_SwapBuffers(void) {
|
bool GLContext_SwapBuffers(void) {
|
||||||
SDL_GL_SwapWindow(win_handle);
|
SDL_GL_SwapWindow(win_handle);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLContext_SetFpsLimit(bool vsync, float minFrameMs) {
|
void GLContext_SetFpsLimit(bool vsync, float minFrameMs) {
|
||||||
@ -3527,6 +3529,12 @@ static EGLint ctx_numConfig;
|
|||||||
return info;
|
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) {
|
void GLContext_Init(struct GraphicsMode* mode) {
|
||||||
static EGLint contextAttribs[3] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE };
|
static EGLint contextAttribs[3] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE };
|
||||||
static EGLint attribs[19] = {
|
static EGLint attribs[19] = {
|
||||||
@ -3549,16 +3557,20 @@ void GLContext_Init(struct GraphicsMode* mode) {
|
|||||||
eglChooseConfig(ctx_display, attribs, &ctx_config, 1, &ctx_numConfig);
|
eglChooseConfig(ctx_display, attribs, &ctx_config, 1, &ctx_numConfig);
|
||||||
|
|
||||||
ctx_context = eglCreateContext(ctx_display, ctx_config, EGL_NO_CONTEXT, contextAttribs);
|
ctx_context = eglCreateContext(ctx_display, ctx_config, EGL_NO_CONTEXT, contextAttribs);
|
||||||
ctx_surface = eglCreateWindowSurface(ctx_display, ctx_config, win_handle, NULL);
|
GLContext_InitSurface();
|
||||||
eglMakeCurrent(ctx_display, ctx_surface, ctx_surface, ctx_context);\
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLContext_Update(void) {
|
void GLContext_Update(void) {
|
||||||
|
eglMakeCurrent(ctx_display, EGL_NO_SURFACE, EGL_NO_SURFACE, ctx_context);
|
||||||
eglDestroySurface(ctx_display, ctx_surface);
|
eglDestroySurface(ctx_display, ctx_surface);
|
||||||
ctx_surface = eglCreateWindowSurface(ctx_display, ctx_config, win_handle, NULL);
|
ctx_surface = NULL;
|
||||||
eglMakeCurrent(ctx_display, ctx_surface, ctx_surface, ctx_context);
|
GLContext_InitSurface();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool GLContext_TryRestore(void) {
|
||||||
|
GLContext_InitSurface();
|
||||||
|
return ctx_surface != NULL;
|
||||||
}
|
}
|
||||||
bool GLContext_TryRestore(void) { return true; }
|
|
||||||
|
|
||||||
void GLContext_Free(void) {
|
void GLContext_Free(void) {
|
||||||
eglMakeCurrent(ctx_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
|
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);
|
return eglGetProcAddress(function);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLContext_SwapBuffers(void) {
|
bool GLContext_SwapBuffers(void) {
|
||||||
|
if (!ctx_surface) return false;
|
||||||
eglSwapBuffers(ctx_display, ctx_surface);
|
eglSwapBuffers(ctx_display, ctx_surface);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLContext_SetFpsLimit(bool vsync, float minFrameMs) {
|
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_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) {
|
void GLContext_SetFpsLimit(bool vsync, float minFrameMs) {
|
||||||
if (vsync) {
|
if (vsync) {
|
||||||
|
@ -157,7 +157,7 @@ void GLContext_Free(void);
|
|||||||
You must check the OpenGL version and/or GL_EXTENSIONS string for actual support! */
|
You must check the OpenGL version and/or GL_EXTENSIONS string for actual support! */
|
||||||
void* GLContext_GetAddress(const char* function);
|
void* GLContext_GetAddress(const char* function);
|
||||||
/* Swaps the front and back buffer, displaying the back buffer on screen. */
|
/* 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. */
|
/* Sets whether synchronisation with the monitor is used. */
|
||||||
/* NOTE: The underlying platform may choose to still ignore this. */
|
/* NOTE: The underlying platform may choose to still ignore this. */
|
||||||
void GLContext_SetFpsLimit(bool vsync, float minFrameMs);
|
void GLContext_SetFpsLimit(bool vsync, float minFrameMs);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user