summaryrefslogtreecommitdiff
path: root/src/OffscreenContextGLX.cc
diff options
context:
space:
mode:
authordon bright <hugh.m.bright@gmail.com>2013-01-26 05:52:06 (GMT)
committerdon bright <hugh.m.bright@gmail.com>2013-01-26 05:52:06 (GMT)
commit544a8e5b799f5dd0a35d650c00db10074104650a (patch)
tree0651f5efa1422aaf166a303c1210a92b23850681 /src/OffscreenContextGLX.cc
parent395628cb4ef7f8559c667af22fb273e21e4a5ad8 (diff)
refactor to reduce duplicate code
Diffstat (limited to 'src/OffscreenContextGLX.cc')
-rw-r--r--src/OffscreenContextGLX.cc25
1 files changed, 3 insertions, 22 deletions
diff --git a/src/OffscreenContextGLX.cc b/src/OffscreenContextGLX.cc
index dee47ed..574fbb5 100644
--- a/src/OffscreenContextGLX.cc
+++ b/src/OffscreenContextGLX.cc
@@ -62,6 +62,8 @@ struct OffscreenContext
fbo_t *fbo;
};
+#include "OffscreenContextAll.hpp"
+
void offscreen_context_init(OffscreenContext &ctx, int width, int height)
{
ctx.width = width;
@@ -296,30 +298,9 @@ bool teardown_offscreen_context(OffscreenContext *ctx)
return false;
}
-/*!
- Capture framebuffer from OpenGL and write it to the given ostream
-*/
bool save_framebuffer(OffscreenContext *ctx, std::ostream &output)
{
glXSwapBuffers(ctx->xdisplay, ctx->xwindow);
- if (!ctx) return false;
- int samplesPerPixel = 4; // R, G, B and A
- GLubyte pixels[ctx->width * ctx->height * samplesPerPixel];
- glReadPixels(0, 0, ctx->width, ctx->height, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
-
- // Flip it vertically - images read from OpenGL buffers are upside-down
- int rowBytes = samplesPerPixel * ctx->width;
- unsigned char *flippedBuffer = (unsigned char *)malloc(rowBytes * ctx->height);
- if (!flippedBuffer) {
- cerr << "Unable to allocate flipped buffer for corrected image.";
- return 1;
- }
- flip_image(pixels, flippedBuffer, samplesPerPixel, ctx->width, ctx->height);
-
- bool writeok = write_png(output, flippedBuffer, ctx->width, ctx->height);
-
- free(flippedBuffer);
-
- return writeok;
+ return save_framebuffer_common(ctx, output);
}
contact: Jan Huwald // Impressum