Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fixed bug 3362 - OpenGL renderer doesn't check if framebuffers are su…
…pported when creating target textures

Simon Hug

The GL_CreateTexture function doesn't have any checks for the case where the driver doesn't support the framebuffer object extension. It will call into GL_GetFBO which will call the non-existent glGenFramebuffersEXT.

Also, for some reason GL_CreateContext always sets the SDL_RENDERER_TARGETTEXTURE info flag, even if it is not supported. Changeset cc226dce7536 [1] makes this change, but doesn't explain why. It seems to me like the code would already have taken care of this [2].

The attached patch adds some checks and stops SDL from reporting render target support if there is none. The application can then properly inform the user instead of just crashing.
  • Loading branch information
slouken committed Oct 1, 2016
1 parent fd1d692 commit 3f1b162
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/render/opengl/SDL_render_gl.c
Expand Up @@ -450,7 +450,7 @@ GL_CreateRenderer(SDL_Window * window, Uint32 flags)
renderer->GL_BindTexture = GL_BindTexture;
renderer->GL_UnbindTexture = GL_UnbindTexture;
renderer->info = GL_RenderDriver.info;
renderer->info.flags = (SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE);
renderer->info.flags = SDL_RENDERER_ACCELERATED;
renderer->driverdata = data;
renderer->window = window;

Expand Down Expand Up @@ -664,6 +664,11 @@ GL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)

GL_ActivateRenderer(renderer);

if (texture->access == SDL_TEXTUREACCESS_TARGET &&
!renderdata->GL_EXT_framebuffer_object_supported) {
return SDL_SetError("Render targets not supported by OpenGL");
}

if (!convert_format(renderdata, texture->format, &internalFormat,
&format, &type)) {
return SDL_SetError("Texture format %s not supported by OpenGL",
Expand Down Expand Up @@ -980,6 +985,10 @@ GL_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture)

GL_ActivateRenderer(renderer);

if (!data->GL_EXT_framebuffer_object_supported) {
return SDL_SetError("Render targets not supported by OpenGL");
}

if (texture == NULL) {
data->glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
return 0;
Expand Down

0 comments on commit 3f1b162

Please sign in to comment.