From 3f1b1629c4efe99b07ac4745012aecff9058d38e Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sat, 1 Oct 2016 10:52:24 -0700 Subject: [PATCH] Fixed bug 3362 - OpenGL renderer doesn't check if framebuffers are supported 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. --- src/render/opengl/SDL_render_gl.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/render/opengl/SDL_render_gl.c b/src/render/opengl/SDL_render_gl.c index 6a4fa3ecf..ab831e7b3 100644 --- a/src/render/opengl/SDL_render_gl.c +++ b/src/render/opengl/SDL_render_gl.c @@ -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; @@ -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", @@ -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;