summaryrefslogtreecommitdiffstats
path: root/libdimension/gl.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2009-07-08 17:12:02 +0000
committerTavian Barnes <tavianator@gmail.com>2009-07-08 17:12:02 +0000
commitbff7f2b3b440c30d0d6eb692576af57ef42edd1b (patch)
tree0ba45051db1ee7b7808339cfb587f8f76d8c7c5c /libdimension/gl.c
parent14c9cd86e1b7c6ff27c5000d72721c54a718daac (diff)
downloaddimension-bff7f2b3b440c30d0d6eb692576af57ef42edd1b.tar.xz
Comments and style adjustments, and a couple fixes.
Diffstat (limited to 'libdimension/gl.c')
-rw-r--r--libdimension/gl.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/libdimension/gl.c b/libdimension/gl.c
index 20c9af3..006db4b 100644
--- a/libdimension/gl.c
+++ b/libdimension/gl.c
@@ -46,12 +46,15 @@ dmnsn_gl_optimize_canvas(dmnsn_canvas *canvas)
optimizer.optimizer_fn = &dmnsn_gl_optimizer_fn;
optimizer.free_fn = &free;
+ /* Allocate a buffer to hold RGB values */
optimizer.ptr = malloc(4*canvas->x*canvas->y*sizeof(GLushort));
if (!optimizer.ptr) {
return 1;
}
+ /* Set a new optimizer */
if (dmnsn_optimize_canvas(canvas, optimizer) != 0) {
+ /* Set failed; dmnsn_set_pixel() has probably been called already */
free(optimizer.ptr);
return 1;
}
@@ -78,11 +81,11 @@ dmnsn_gl_write_canvas(const dmnsn_canvas *canvas)
dmnsn_array_get(canvas->optimizers, i, &optimizer);
if (optimizer.optimizer_fn == &dmnsn_gl_optimizer_fn) {
glDrawPixels(width, height, GL_RGBA, GL_UNSIGNED_SHORT, optimizer.ptr);
- return 0;
+ return glGetError() == GL_NO_ERROR ? 0 : 1;
}
}
- /* We couldn't, so to this non-optimally */
+ /* We couldn't, so transform the canvas to RGB now */
pixels = malloc(4*width*height*sizeof(GLushort));
if (!pixels) {
return 1;
@@ -129,7 +132,7 @@ dmnsn_gl_write_canvas(const dmnsn_canvas *canvas)
glDrawPixels(width, height, GL_RGBA, GL_UNSIGNED_SHORT, pixels);
free(pixels);
- return 0;
+ return glGetError() == GL_NO_ERROR ? 0 : 1;
}
/* Read a canvas from a GL framebuffer. Returns NULL on failure. */
@@ -157,6 +160,12 @@ dmnsn_gl_read_canvas(unsigned int x0, unsigned int y0,
glReadPixels(x0, y0, width, height, GL_RGBA, GL_UNSIGNED_SHORT, pixels);
+ if (glGetError() != GL_NO_ERROR) {
+ free(pixels);
+ dmnsn_delete_canvas(canvas);
+ return NULL;
+ }
+
for (y = 0; y < height; ++y) {
for (x = 0; x < width; ++x) {
pixel = pixels + 4*(y*width + x);