mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-13 17:47:12 -04:00
Carbon: Simplify GLContext related code a bit
This commit is contained in:
parent
c3d98109a9
commit
f218c49970
@ -157,10 +157,6 @@ void Clipboard_SetText(const cc_string* value) {
|
|||||||
/*########################################################################################################################*
|
/*########################################################################################################################*
|
||||||
*----------------------------------------------------------Wwindow--------------------------------------------------------*
|
*----------------------------------------------------------Wwindow--------------------------------------------------------*
|
||||||
*#########################################################################################################################*/
|
*#########################################################################################################################*/
|
||||||
/* fullscreen is tied to OpenGL context unfortunately */
|
|
||||||
static cc_result GLContext_UnsetFullscreen(void);
|
|
||||||
static cc_result GLContext_SetFullscreen(void);
|
|
||||||
|
|
||||||
static void RefreshWindowBounds(void) {
|
static void RefreshWindowBounds(void) {
|
||||||
Rect r;
|
Rect r;
|
||||||
if (win_fullscreen) return;
|
if (win_fullscreen) return;
|
||||||
@ -526,23 +522,6 @@ int Window_GetWindowState(void) {
|
|||||||
return WINDOW_STATE_NORMAL;
|
return WINDOW_STATE_NORMAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void UpdateWindowState(void) {
|
|
||||||
Event_RaiseVoid(&WindowEvents.StateChanged);
|
|
||||||
RefreshWindowBounds();
|
|
||||||
Event_RaiseVoid(&WindowEvents.Resized);
|
|
||||||
}
|
|
||||||
|
|
||||||
cc_result Window_EnterFullscreen(void) {
|
|
||||||
cc_result res = GLContext_SetFullscreen();
|
|
||||||
UpdateWindowState();
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
cc_result Window_ExitFullscreen(void) {
|
|
||||||
cc_result res = GLContext_UnsetFullscreen();
|
|
||||||
UpdateWindowState();
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
int Window_IsObscured(void) {
|
int Window_IsObscured(void) {
|
||||||
/* TODO: This isn't a complete fix because it doesn't check for occlusion - */
|
/* TODO: This isn't a complete fix because it doesn't check for occlusion - */
|
||||||
/* so you'll still get 100% CPU usage when window is hidden in background */
|
/* so you'll still get 100% CPU usage when window is hidden in background */
|
||||||
@ -710,37 +689,17 @@ static void GLContext_GetAttribs(struct GraphicsMode* mode, GLint* attribs, cc_b
|
|||||||
attribs[i++] = 0;
|
attribs[i++] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static cc_result GLContext_UnsetFullscreen(void) {
|
cc_result Window_EnterFullscreen(void) {
|
||||||
int code;
|
|
||||||
Platform_LogConst("Unsetting fullscreen.");
|
|
||||||
|
|
||||||
code = aglSetDrawable(ctx_handle, NULL);
|
|
||||||
if (!code) return aglGetError();
|
|
||||||
/* TODO: I don't think this is necessary */
|
|
||||||
code = aglUpdateContext(ctx_handle);
|
|
||||||
if (!code) return aglGetError();
|
|
||||||
|
|
||||||
CGDisplayRelease(CGMainDisplayID());
|
|
||||||
GLContext_SetDrawable();
|
|
||||||
|
|
||||||
win_fullscreen = false;
|
|
||||||
/* TODO: Eliminate this if possible */
|
|
||||||
Window_SetSize(ctx_windowWidth, ctx_windowHeight);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static cc_result GLContext_SetFullscreen(void) {
|
|
||||||
int width = DisplayInfo.Width;
|
int width = DisplayInfo.Width;
|
||||||
int height = DisplayInfo.Height;
|
int height = DisplayInfo.Height;
|
||||||
int code;
|
int code;
|
||||||
|
|
||||||
Platform_LogConst("Switching to fullscreen");
|
|
||||||
/* TODO: Does aglSetFullScreen capture the screen anyways? */
|
/* TODO: Does aglSetFullScreen capture the screen anyways? */
|
||||||
CGDisplayCapture(CGMainDisplayID());
|
CGDisplayCapture(CGMainDisplayID());
|
||||||
|
|
||||||
if (!aglSetFullScreen(ctx_handle, width, height, 0, 0)) {
|
if (!aglSetFullScreen(ctx_handle, width, height, 0, 0)) {
|
||||||
code = aglGetError();
|
code = aglGetError();
|
||||||
GLContext_UnsetFullscreen();
|
Window_ExitFullscreen();
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -750,6 +709,26 @@ static cc_result GLContext_SetFullscreen(void) {
|
|||||||
|
|
||||||
windowX = DisplayInfo.X; WindowInfo.Width = DisplayInfo.Width;
|
windowX = DisplayInfo.X; WindowInfo.Width = DisplayInfo.Width;
|
||||||
windowY = DisplayInfo.Y; WindowInfo.Height = DisplayInfo.Height;
|
windowY = DisplayInfo.Y; WindowInfo.Height = DisplayInfo.Height;
|
||||||
|
|
||||||
|
Event_RaiseVoid(&WindowEvents.Resized);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
cc_result Window_ExitFullscreen(void) {
|
||||||
|
int code;
|
||||||
|
|
||||||
|
code = aglSetDrawable(ctx_handle, NULL);
|
||||||
|
if (!code) return aglGetError();
|
||||||
|
|
||||||
|
CGDisplayRelease(CGMainDisplayID());
|
||||||
|
GLContext_SetDrawable();
|
||||||
|
|
||||||
|
win_fullscreen = false;
|
||||||
|
/* TODO: Eliminate this if possible */
|
||||||
|
Window_SetSize(ctx_windowWidth, ctx_windowHeight);
|
||||||
|
|
||||||
|
RefreshWindowBounds();
|
||||||
|
Event_RaiseVoid(&WindowEvents.Resized);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -782,18 +761,14 @@ void GLContext_Create(void) {
|
|||||||
|
|
||||||
ctx_handle = aglCreateContext(fmt, NULL);
|
ctx_handle = aglCreateContext(fmt, NULL);
|
||||||
GLContext_Check(0, "Creating GL context");
|
GLContext_Check(0, "Creating GL context");
|
||||||
|
|
||||||
aglDestroyPixelFormat(fmt);
|
aglDestroyPixelFormat(fmt);
|
||||||
GLContext_Check(0, "Destroying pixel format");
|
|
||||||
|
|
||||||
GLContext_SetDrawable();
|
GLContext_SetDrawable();
|
||||||
GLContext_Update();
|
|
||||||
GLContext_MakeCurrent();
|
GLContext_MakeCurrent();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLContext_Update(void) {
|
void GLContext_Update(void) {
|
||||||
if (win_fullscreen) return;
|
if (win_fullscreen) return;
|
||||||
GLContext_SetDrawable();
|
|
||||||
aglUpdateContext(ctx_handle);
|
aglUpdateContext(ctx_handle);
|
||||||
}
|
}
|
||||||
cc_bool GLContext_TryRestore(void) { return true; }
|
cc_bool GLContext_TryRestore(void) { return true; }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user