framebuffers: cogl_offscreen_new_to_texture should take a ref on the texture

We weren't taking a reference on the texture to be used as the color buffer
for offscreen rendering, so it was possible to free the texture leaving the
framebuffer in an inconsistent state.
This commit is contained in:
Robert Bragg 2009-11-25 14:26:32 +00:00
parent 30b557c465
commit d9b91d61f5
2 changed files with 4 additions and 0 deletions

View File

@ -57,6 +57,7 @@ typedef struct _CoglOffscreen
CoglFramebuffer _parent;
GLuint fbo_handle;
GLuint gl_stencil_handle;
CoglHandle texture;
} CoglOffscreen;
#define COGL_OFFSCREEN(X) ((CoglOffscreen *)(X))

View File

@ -339,6 +339,7 @@ cogl_offscreen_new_to_texture (CoglHandle texhandle)
offscreen->fbo_handle = fbo_gl_handle;
offscreen->gl_stencil_handle = gl_stencil_handle;
offscreen->texture = cogl_handle_ref (texhandle);
/* XXX: Can we get a away with removing this? It wasn't documented, and most
* users of the API are hopefully setting up the modelview from scratch
@ -362,6 +363,8 @@ _cogl_offscreen_free (CoglOffscreen *offscreen)
if (offscreen->gl_stencil_handle)
GE (glDeleteRenderbuffers (1, &offscreen->gl_stencil_handle));
if (offscreen->texture != COGL_INVALID_HANDLE)
cogl_handle_unref (offscreen->texture);
GE (glDeleteFramebuffers (1, &offscreen->fbo_handle));
g_free (offscreen);
}