summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordon bright <hugh.m.bright@gmail.com>2013-01-26 06:10:36 (GMT)
committerdon bright <hugh.m.bright@gmail.com>2013-01-26 06:10:36 (GMT)
commit7d147032543f51c93123c484d0c2b2c7e191df26 (patch)
tree451ff6e100de7671bb5df4167e47446abc5d4007 /src
parentaf4333a669eacc2cafc8274e23f58415e634477b (diff)
commit files created during refactor
Diffstat (limited to 'src')
-rw-r--r--src/CsgInfo.h42
-rw-r--r--src/OffscreenContextAll.hpp70
2 files changed, 112 insertions, 0 deletions
diff --git a/src/CsgInfo.h b/src/CsgInfo.h
new file mode 100644
index 0000000..fa3e100
--- /dev/null
+++ b/src/CsgInfo.h
@@ -0,0 +1,42 @@
+#ifndef __CSGINFO_H__
+#define __CSGINFO_H__
+
+#include "OffscreenView.h"
+
+class CsgInfo
+{
+public:
+ CsgInfo() { glview = NULL; }
+ OffscreenView *glview;
+};
+
+
+#ifdef ENABLE_OPENCSG
+
+#include <opencsg.h>
+#include "OpenCSGRenderer.h"
+#include "csgterm.h"
+#include "csgtermnormalizer.h"
+
+class CsgInfo_OpenCSG : public CsgInfo
+{
+public:
+ CsgInfo_OpenCSG()
+ {
+ root_chain = NULL;
+ highlights_chain = NULL;
+ background_chain = NULL;
+ glview = NULL;
+ }
+ shared_ptr<CSGTerm> root_norm_term; // Normalized CSG products
+ class CSGChain *root_chain;
+ std::vector<shared_ptr<CSGTerm> > highlight_terms;
+ CSGChain *highlights_chain;
+ std::vector<shared_ptr<CSGTerm> > background_terms;
+ CSGChain *background_chain;
+};
+
+#endif // ENABLE_OPENCSG
+
+#endif
+
diff --git a/src/OffscreenContextAll.hpp b/src/OffscreenContextAll.hpp
new file mode 100644
index 0000000..8ee7ebe
--- /dev/null
+++ b/src/OffscreenContextAll.hpp
@@ -0,0 +1,70 @@
+// Functions shared by OffscreenContext[platform].cc
+
+void bind_offscreen_context(OffscreenContext *ctx)
+{
+ if (ctx) fbo_bind(ctx->fbo);
+}
+
+/*
+ Capture framebuffer from OpenGL and write it to the given filename as PNG.
+*/
+bool save_framebuffer(OffscreenContext *ctx, const char *filename)
+{
+ std::ofstream fstream(filename);
+ if (!fstream.is_open()) {
+ std::cerr << "Can't open file " << filename << " for writing";
+ return false;
+ } else {
+ save_framebuffer(ctx, fstream);
+ fstream.close();
+ }
+ return true;
+}
+
+/*!
+ Capture framebuffer from OpenGL and write it to the given ostream.
+ Called by save_framebuffer() from platform-specific code.
+*/
+bool save_framebuffer_common(OffscreenContext *ctx, std::ostream &output)
+{
+ if (!ctx) return false;
+ int samplesPerPixel = 4; // R, G, B and A
+ vector<GLubyte> pixels(ctx->width * ctx->height * samplesPerPixel);
+ glReadPixels(0, 0, ctx->width, ctx->height, GL_RGBA, GL_UNSIGNED_BYTE, &pixels[0]);
+
+ // 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) {
+ std::cerr << "Unable to allocate flipped buffer for corrected image.";
+ return 1;
+ }
+ flip_image(&pixels[0], flippedBuffer, samplesPerPixel, ctx->width, ctx->height);
+
+ bool writeok = write_png(output, flippedBuffer, ctx->width, ctx->height);
+
+ free(flippedBuffer);
+
+ return writeok;
+}
+
+// Called by create_offscreen_context() from platform-specific code.
+OffscreenContext *create_offscreen_context_common(OffscreenContext *ctx)
+{
+ if (!ctx) return NULL;
+ GLenum err = glewInit(); // must come after Context creation and before FBO c$
+ if (GLEW_OK != err) {
+ cerr << "Unable to init GLEW: " << glewGetErrorString(err) << "\n";
+ return NULL;
+ }
+ //cerr << glew_dump(0);
+
+ ctx->fbo = fbo_new();
+ if (!fbo_init(ctx->fbo, ctx->width, ctx->height)) {
+ return NULL;
+ }
+
+ return ctx;
+}
+
contact: Jan Huwald // Impressum