Perform cleanup when OpenGL's Backend_Init fails
This commit is contained in:
parent
0c9c0115cf
commit
a40c3d7b1b
1 changed files with 83 additions and 54 deletions
|
@ -288,21 +288,17 @@ Backend_Surface* Backend_Init(SDL_Window *p_window)
|
|||
|
||||
context = SDL_GL_CreateContext(window);
|
||||
|
||||
if (context == NULL)
|
||||
return NULL;
|
||||
|
||||
if (SDL_GL_MakeCurrent(window, context) < 0)
|
||||
return NULL;
|
||||
|
||||
if (!gladLoadGLLoader((GLADloadproc)SDL_GL_GetProcAddress))
|
||||
return NULL;
|
||||
|
||||
if (context != NULL)
|
||||
{
|
||||
if (SDL_GL_MakeCurrent(window, context) == 0)
|
||||
{
|
||||
if (gladLoadGLLoader((GLADloadproc)SDL_GL_GetProcAddress))
|
||||
{
|
||||
// Check if the platform supports OpenGL 3.2
|
||||
if (!GLAD_GL_VERSION_3_2)
|
||||
return NULL;
|
||||
|
||||
// glEnable(GL_DEBUG_OUTPUT);
|
||||
// glDebugMessageCallback(MessageCallback, 0);
|
||||
if (GLAD_GL_VERSION_3_2)
|
||||
{
|
||||
//glEnable(GL_DEBUG_OUTPUT);
|
||||
//glDebugMessageCallback(MessageCallback, 0);
|
||||
|
||||
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
@ -330,8 +326,11 @@ Backend_Surface* Backend_Init(SDL_Window *p_window)
|
|||
program_glyph_subpixel_part2 = CompileShader(vertex_shader_texture, fragment_shader_glyph_subpixel_part2);
|
||||
|
||||
if (program_texture == 0 || program_texture_colour_key == 0 || program_colour_fill == 0 || program_glyph_normal == 0 || program_glyph_subpixel_part1 == 0 || program_glyph_subpixel_part2 == 0)
|
||||
{
|
||||
printf("Failed to compile shaders\n");
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
// Get shader uniforms
|
||||
program_colour_fill_uniform_colour = glGetUniformLocation(program_colour_fill, "colour");
|
||||
program_glyph_normal_uniform_colour = glGetUniformLocation(program_glyph_normal, "colour");
|
||||
|
@ -358,6 +357,36 @@ Backend_Surface* Backend_Init(SDL_Window *p_window)
|
|||
glViewport(0, 0, framebuffer.width, framebuffer.height);
|
||||
|
||||
return &framebuffer;
|
||||
}
|
||||
|
||||
if (program_glyph_subpixel_part2 != 0)
|
||||
glDeleteProgram(program_glyph_subpixel_part2);
|
||||
|
||||
if (program_glyph_subpixel_part1 != 0)
|
||||
glDeleteProgram(program_glyph_subpixel_part1);
|
||||
|
||||
if (program_glyph_normal != 0)
|
||||
glDeleteProgram(program_glyph_normal);
|
||||
|
||||
if (program_texture_colour_key != 0)
|
||||
glDeleteProgram(program_texture_colour_key);
|
||||
|
||||
if (program_texture_colour_key != 0)
|
||||
glDeleteProgram(program_texture_colour_key);
|
||||
|
||||
if (program_texture != 0)
|
||||
glDeleteProgram(program_texture);
|
||||
|
||||
glDeleteBuffers(1, &vertex_buffer_id);
|
||||
glDeleteVertexArrays(1, &vertex_array_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SDL_GL_DeleteContext(context);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void Backend_Deinit(void)
|
||||
|
|
Loading…
Add table
Reference in a new issue