Browse Source

Fixes nvgluCreateFramebuffer().

The framebuffer and renderbuffer did restore in `nvgluCreateFramebuffer()` on succeed. However, they are not restored if error occurs. This commit fixes it.
shared-context
Olli Wang 10 years ago
parent
commit
71a2bdf8af
1 changed files with 7 additions and 3 deletions
  1. +7
    -3
      src/nanovg_gl_utils.h

+ 7
- 3
src/nanovg_gl_utils.h View File

@@ -28,6 +28,7 @@ struct NVGLUframebuffer {
typedef struct NVGLUframebuffer NVGLUframebuffer; typedef struct NVGLUframebuffer NVGLUframebuffer;


// Helper function to create GL frame buffer to render to. // Helper function to create GL frame buffer to render to.
void nvgluBindFramebuffer(NVGLUframebuffer* fb);
NVGLUframebuffer* nvgluCreateFramebuffer(NVGcontext* ctx, int w, int h, int imageFlags); NVGLUframebuffer* nvgluCreateFramebuffer(NVGcontext* ctx, int w, int h, int imageFlags);
void nvgluDeleteFramebuffer(NVGcontext* ctx, NVGLUframebuffer* fb); void nvgluDeleteFramebuffer(NVGcontext* ctx, NVGLUframebuffer* fb);


@@ -54,13 +55,14 @@ NVGLUframebuffer* nvgluCreateFramebuffer(NVGcontext* ctx, int w, int h, int imag
GLint defaultFBO; GLint defaultFBO;
GLint defaultRBO; GLint defaultRBO;
NVGLUframebuffer* fb = NULL; NVGLUframebuffer* fb = NULL;
fb = (NVGLUframebuffer*)malloc(sizeof(NVGLUframebuffer));
if (fb == NULL) goto error;
memset(fb, 0, sizeof(NVGLUframebuffer));


glGetIntegerv(GL_FRAMEBUFFER_BINDING, &defaultFBO); glGetIntegerv(GL_FRAMEBUFFER_BINDING, &defaultFBO);
glGetIntegerv(GL_RENDERBUFFER_BINDING, &defaultRBO); glGetIntegerv(GL_RENDERBUFFER_BINDING, &defaultRBO);


fb = (NVGLUframebuffer*)malloc(sizeof(NVGLUframebuffer));
if (fb == NULL) goto error;
memset(fb, 0, sizeof(NVGLUframebuffer));

fb->image = nvgCreateImageRGBA(ctx, w, h, imageFlags | NVG_IMAGE_FLIPY | NVG_IMAGE_PREMULTIPLIED, NULL); fb->image = nvgCreateImageRGBA(ctx, w, h, imageFlags | NVG_IMAGE_FLIPY | NVG_IMAGE_PREMULTIPLIED, NULL);
fb->texture = nvglImageHandle(ctx, fb->image); fb->texture = nvglImageHandle(ctx, fb->image);


@@ -83,6 +85,8 @@ NVGLUframebuffer* nvgluCreateFramebuffer(NVGcontext* ctx, int w, int h, int imag
glBindRenderbuffer(GL_RENDERBUFFER, defaultRBO); glBindRenderbuffer(GL_RENDERBUFFER, defaultRBO);
return fb; return fb;
error: error:
glBindFramebuffer(GL_FRAMEBUFFER, defaultFBO);
glBindRenderbuffer(GL_RENDERBUFFER, defaultRBO);
nvgluDeleteFramebuffer(ctx, fb); nvgluDeleteFramebuffer(ctx, fb);
return NULL; return NULL;
#else #else


Loading…
Cancel
Save