Minorly simplify OpenGL context creation

This commit is contained in:
UnknownShadow200 2022-10-09 18:54:09 +11:00
parent 7e35327d7e
commit e7650e1646
4 changed files with 19 additions and 21 deletions

View File

@ -679,21 +679,6 @@ static void GLContext_SetDrawable(void) {
GLContext_Check(code, "Attaching GL context");
}
static void GLContext_GetAttribs(struct GraphicsMode* mode, GLint* attribs, cc_bool fullscreen) {
int i = 0;
if (!mode->IsIndexed) { attribs[i++] = AGL_RGBA; }
attribs[i++] = AGL_RED_SIZE; attribs[i++] = mode->R;
attribs[i++] = AGL_GREEN_SIZE; attribs[i++] = mode->G;
attribs[i++] = AGL_BLUE_SIZE; attribs[i++] = mode->B;
attribs[i++] = AGL_ALPHA_SIZE; attribs[i++] = mode->A;
attribs[i++] = AGL_DEPTH_SIZE; attribs[i++] = GLCONTEXT_DEFAULT_DEPTH;
attribs[i++] = AGL_DOUBLEBUFFER;
if (fullscreen) { attribs[i++] = AGL_FULLSCREEN; }
attribs[i++] = 0;
}
cc_result Window_EnterFullscreen(void) {
int width = DisplayInfo.Width;
int height = DisplayInfo.Height;
@ -737,6 +722,21 @@ cc_result Window_ExitFullscreen(void) {
return 0;
}
static void GLContext_GetAttribs(struct GraphicsMode* mode, GLint* attribs, cc_bool fullscreen) {
int i = 0;
attribs[i++] = AGL_RGBA;
attribs[i++] = AGL_RED_SIZE; attribs[i++] = mode->R;
attribs[i++] = AGL_GREEN_SIZE; attribs[i++] = mode->G;
attribs[i++] = AGL_BLUE_SIZE; attribs[i++] = mode->B;
attribs[i++] = AGL_ALPHA_SIZE; attribs[i++] = mode->A;
attribs[i++] = AGL_DEPTH_SIZE; attribs[i++] = GLCONTEXT_DEFAULT_DEPTH;
attribs[i++] = AGL_DOUBLEBUFFER;
if (fullscreen) { attribs[i++] = AGL_FULLSCREEN; }
attribs[i++] = 0;
}
void GLContext_Create(void) {
GLint attribs[20];
AGLPixelFormat fmt;

View File

@ -712,8 +712,6 @@ void GLContext_Create(void) {
GLContext_SelectGraphicsMode(&mode);
ctx_handle = wglCreateContext(win_DC);
if (!ctx_handle) ctx_handle = wglCreateContext(win_DC);
if (!ctx_handle) {
Logger_Abort2(GetLastError(), "Failed to create OpenGL context");
}

View File

@ -1293,7 +1293,8 @@ static void GetAttribs(struct GraphicsMode* mode, int* attribs, int depth) {
/* See http://www-01.ibm.com/support/knowledgecenter/ssw_aix_71/com.ibm.aix.opengl/doc/openglrf/glXChooseVisual.htm%23b5c84be452rree */
/* for the attribute declarations. Note that the attributes are different than those used in glxChooseVisual */
if (!mode->IsIndexed) { attribs[i++] = GLX_RGBA; }
/* TODO always use RGBA? need to test 8bpp displays */
if (DisplayInfo.Depth >= 15) { attribs[i++] = GLX_RGBA; }
attribs[i++] = GLX_RED_SIZE; attribs[i++] = mode->R;
attribs[i++] = GLX_GREEN_SIZE; attribs[i++] = mode->G;
attribs[i++] = GLX_BLUE_SIZE; attribs[i++] = mode->B;

View File

@ -78,13 +78,12 @@ void OpenKeyboardArgs_Init(struct OpenKeyboardArgs* args, STRING_REF const cc_st
}
struct GraphicsMode { int R, G, B, A, IsIndexed; };
struct GraphicsMode { int R, G, B, A; };
/* Creates a GraphicsMode compatible with the default display device */
static void InitGraphicsMode(struct GraphicsMode* m) {
int bpp = DisplayInfo.Depth;
m->IsIndexed = bpp < 15;
m->A = 0;
switch (bpp) {
case 32:
m->R = 8; m->G = 8; m->B = 8; m->A = 8; break;