summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tests/CMakeLists.txt6
-rw-r--r--tests/OffscreenContext.cc56
-rw-r--r--tests/OffscreenContext.h9
-rw-r--r--tests/OffscreenContext.mm58
-rw-r--r--tests/fboutils.cc61
-rw-r--r--tests/fboutils.h10
6 files changed, 82 insertions, 118 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index e8e8fc6..feff2c2 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -186,7 +186,7 @@ target_link_libraries(cgaltest ${CGAL_LIBRARY} ${CGAL_3RD_PARTY_LIBRARIES} ${QT_
#
# cgalpngtest
#
-add_executable(cgalpngtest cgalpngtest.cc OffscreenView.cc ${OFFSCREEN_CTX_SOURCE} imageutils.cc
+add_executable(cgalpngtest cgalpngtest.cc OffscreenView.cc ${OFFSCREEN_CTX_SOURCE} imageutils.cc fboutils.cc
../src/CGALRenderer.cc ../src/CGAL_Nef_polyhedron.cc ../src/cgalutils.cc
../src/CSGTermEvaluator.cc ../src/CGALEvaluator.cc ../src/CGALCache.cc
../src/PolySetCGALEvaluator.cc ../src/qhash.cc
@@ -199,7 +199,7 @@ target_link_libraries(cgalpngtest ${CGAL_LIBRARY} ${CGAL_3RD_PARTY_LIBRARIES} ${
# opencsgtest
#
-add_executable(opencsgtest opencsgtest.cc csgtestcore.cc OffscreenView.cc ${OFFSCREEN_CTX_SOURCE} imageutils.cc
+add_executable(opencsgtest opencsgtest.cc csgtestcore.cc OffscreenView.cc ${OFFSCREEN_CTX_SOURCE} imageutils.cc fboutils.cc
../src/OpenCSGRenderer.cc ../src/ThrownTogetherRenderer.cc
../src/CSGTermEvaluator.cc ../src/CGAL_Nef_polyhedron.cc ../src/cgalutils.cc
../src/CGALEvaluator.cc ../src/CGALCache.cc ../src/PolySetCGALEvaluator.cc ../src/qhash.cc
@@ -212,7 +212,7 @@ target_link_libraries(opencsgtest ${CGAL_LIBRARY} ${CGAL_3RD_PARTY_LIBRARIES} ${
# throwntogethertest
#
-add_executable(throwntogethertest throwntogethertest.cc csgtestcore.cc OffscreenView.cc ${OFFSCREEN_CTX_SOURCE} imageutils.cc
+add_executable(throwntogethertest throwntogethertest.cc csgtestcore.cc OffscreenView.cc ${OFFSCREEN_CTX_SOURCE} imageutils.cc fboutils.cc
../src/OpenCSGRenderer.cc ../src/ThrownTogetherRenderer.cc
../src/CSGTermEvaluator.cc ../src/CGAL_Nef_polyhedron.cc ../src/cgalutils.cc
../src/CGALEvaluator.cc ../src/CGALCache.cc ../src/PolySetCGALEvaluator.cc ../src/qhash.cc
diff --git a/tests/OffscreenContext.cc b/tests/OffscreenContext.cc
index 36adc15..fa1afde 100644
--- a/tests/OffscreenContext.cc
+++ b/tests/OffscreenContext.cc
@@ -14,10 +14,6 @@
//#include <GL/glu.h> // for gluCheckExtension
#include <SDL.h>
-// Simple error reporting macros to help keep the sample code clean
-#define REPORT_ERROR_AND_EXIT(desc) { std::cout << desc << "\n"; return false; }
-#define NULL_ERROR_EXIT(test, desc) { if (!test) REPORT_ERROR_AND_EXIT(desc); }
-
struct OffscreenContext
{
int width;
@@ -59,51 +55,6 @@ OffscreenContext *create_offscreen_context(int w, int h)
//glewInit();
/*
- // Test if framebuffer objects are supported
- const GLubyte* strExt = glGetString(GL_EXTENSIONS);
- GLboolean fboSupported = gluCheckExtension((const GLubyte*)"GL_EXT_framebuffer_object", strExt);
- if (!fboSupported)
- REPORT_ERROR_AND_EXIT("Your system does not support framebuffer extension - unable to render scene");
-
- printf("%i\n", (int)glGenFramebuffersEXT);
- GLuint fbo;
- //ctx->fbo = 0;
- glGenFramebuffersEXT(1, &fbo);
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo);
- REPORTGLERROR("binding framebuffer");
-
-
- GLuint renderBuffer = 0;
- GLuint depthBuffer = 0;
- // Depth buffer to use for depth testing - optional if you're not using depth testing
- glGenRenderbuffersEXT(1, &depthBuffer);
- glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, depthBuffer);
- glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT24, w, h);
- REPORTGLERROR("creating depth render buffer");
-
- // Render buffer to use for imaging
- glGenRenderbuffersEXT(1, &renderBuffer);
- glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, renderBuffer);
- glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA8, w, h);
- REPORTGLERROR("creating color render buffer");
-
- glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
- GL_RENDERBUFFER_EXT, renderBuffer);
- REPORTGLERROR("specifying color render buffer");
-
- if (glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT) !=
- GL_FRAMEBUFFER_COMPLETE_EXT)
- REPORT_ERROR_AND_EXIT("Problem with OpenGL framebuffer after specifying color render buffer.");
-
- glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT,
- GL_RENDERBUFFER_EXT, depthBuffer);
- REPORTGLERROR("specifying depth render buffer");
-
- if (glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT) !=
- GL_FRAMEBUFFER_COMPLETE_EXT)
- REPORT_ERROR_AND_EXIT("Problem with OpenGL framebuffer after specifying depth render buffer.");
-*/
-/*
glClearColor(1, 1, 1, 1);
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_TRIANGLES);
@@ -128,12 +79,6 @@ OffscreenContext *create_offscreen_context(int w, int h)
bool teardown_offscreen_context(OffscreenContext *ctx)
{
- // "un"bind my FBO
-// glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
-
- /*
- * Cleanup
- */
return true;
}
@@ -166,5 +111,4 @@ bool save_framebuffer(OffscreenContext *ctx, const char *filename)
void bind_offscreen_context(OffscreenContext *ctx)
{
-// glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, ctx->fbo);
}
diff --git a/tests/OffscreenContext.h b/tests/OffscreenContext.h
index a024832..a079c3f 100644
--- a/tests/OffscreenContext.h
+++ b/tests/OffscreenContext.h
@@ -1,17 +1,8 @@
#ifndef OFFSCREENCONTEXT_H_
#define OFFSCREENCONTEXT_H_
-#ifdef __APPLE__
-#include <OpenGL/OpenGL.h>
-#else
-#include <GL/glew.h>
-#include <GL/gl.h>
-#endif
-
#include <iostream> // for error output
-#define REPORTGLERROR(task) { GLenum tGLErr = glGetError(); if (tGLErr != GL_NO_ERROR) { std::cout << "OpenGL error " << tGLErr << " while " << task << "\n"; } }
-
struct OffscreenContext *create_offscreen_context(int w, int h);
void bind_offscreen_context(OffscreenContext *ctx);
bool teardown_offscreen_context(OffscreenContext *ctx);
diff --git a/tests/OffscreenContext.mm b/tests/OffscreenContext.mm
index 8797e49..90af712 100644
--- a/tests/OffscreenContext.mm
+++ b/tests/OffscreenContext.mm
@@ -1,14 +1,9 @@
#include "OffscreenContext.h"
#include "imageutils.h"
+#include "fboutils.h"
-#import <OpenGL/OpenGL.h>
-#import <OpenGL/glu.h> // for gluCheckExtension
#import <AppKit/AppKit.h> // for NSOpenGL...
-// Simple error reporting macros to help keep the sample code clean
-#define REPORT_ERROR_AND_EXIT(desc) { std::cout << desc << "\n"; return false; }
-#define NULL_ERROR_EXIT(test, desc) { if (!test) REPORT_ERROR_AND_EXIT(desc); }
-
struct OffscreenContext
{
NSOpenGLContext *openGLContext;
@@ -41,58 +36,21 @@ OffscreenContext *create_offscreen_context(int w, int h)
// Create and make current the OpenGL context to render with (with color and depth buffers)
ctx->openGLContext = [[NSOpenGLContext alloc] initWithFormat:pixFormat shareContext:nil];
- NULL_ERROR_EXIT(ctx->openGLContext, "Unable to create NSOpenGLContext");
-
- [ctx->openGLContext makeCurrentContext];
-
- // Test if framebuffer objects are supported
- // FIXME: Use GLEW
- const GLubyte* strExt = glGetString(GL_EXTENSIONS);
- GLboolean fboSupported = gluCheckExtension((const GLubyte*)"GL_EXT_framebuffer_object", strExt);
- if (!fboSupported)
- REPORT_ERROR_AND_EXIT("Your system does not support framebuffer extension - unable to render scene");
-
- // Create an FBO
- GLuint renderBuffer = 0;
- GLuint depthBuffer = 0;
- // Depth buffer to use for depth testing - optional if you're not using depth testing
- glGenRenderbuffersEXT(1, &depthBuffer);
- glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, depthBuffer);
- glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT24, w, h);
- REPORTGLERROR("creating depth render buffer");
-
- // Render buffer to use for imaging
- glGenRenderbuffersEXT(1, &renderBuffer);
- glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, renderBuffer);
- glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA8, w, h);
- REPORTGLERROR("creating color render buffer");
- ctx->fbo = 0;
- glGenFramebuffersEXT(1, &ctx->fbo);
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, ctx->fbo);
- REPORTGLERROR("binding framebuffer");
-
- glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
- GL_RENDERBUFFER_EXT, renderBuffer);
- REPORTGLERROR("specifying color render buffer");
-
- if (glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT) != GL_FRAMEBUFFER_COMPLETE_EXT) {
- REPORT_ERROR_AND_EXIT("Problem with OpenGL framebuffer after specifying color render buffer.");
+ if (!ctx->openGLContext) {
+ std::cerr << "Unable to create NSOpenGLContext\n";
+ return NULL;
}
- glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, depthBuffer);
- REPORTGLERROR("specifying depth render buffer");
+ [ctx->openGLContext makeCurrentContext];
- if (glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT) != GL_FRAMEBUFFER_COMPLETE_EXT) {
- REPORT_ERROR_AND_EXIT("Problem with OpenGL framebuffer after specifying depth render buffer.");
- }
+ ctx->fbo = fbo_create(w, h);
return ctx;
}
bool teardown_offscreen_context(OffscreenContext *ctx)
{
- // "un"bind my FBO
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
+ fbo_unbind();
/*
* Cleanup
@@ -139,5 +97,5 @@ bool save_framebuffer(OffscreenContext *ctx, const char *filename)
void bind_offscreen_context(OffscreenContext *ctx)
{
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, ctx->fbo);
+ fbo_bind(ctx->fbo);
}
diff --git a/tests/fboutils.cc b/tests/fboutils.cc
new file mode 100644
index 0000000..d0430df
--- /dev/null
+++ b/tests/fboutils.cc
@@ -0,0 +1,61 @@
+#include "fboutils.h"
+#include <iostream>
+
+GLuint fbo_create(GLsizei width, GLsizei height)
+{
+ // Test if framebuffer objects are supported
+ // FIXME: Use GLEW
+ const GLubyte* strExt = glGetString(GL_EXTENSIONS);
+ GLboolean fboSupported = gluCheckExtension((const GLubyte*)"GL_EXT_framebuffer_object", strExt);
+ if (!fboSupported) {
+ std::cerr << "Your system does not support framebuffer extension - unable to render scene\n";
+ return 0;
+ }
+
+ // Create an FBO
+ GLuint fbo = 0;
+ GLuint renderBuffer = 0;
+ GLuint depthBuffer = 0;
+ // Depth buffer to use for depth testing - optional if you're not using depth testing
+ glGenRenderbuffersEXT(1, &depthBuffer);
+ glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, depthBuffer);
+ glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT24, width, height);
+ REPORTGLERROR("creating depth render buffer");
+
+ // Render buffer to use for imaging
+ glGenRenderbuffersEXT(1, &renderBuffer);
+ glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, renderBuffer);
+ glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA8, width, height);
+ REPORTGLERROR("creating color render buffer");
+ glGenFramebuffersEXT(1, &fbo);
+ glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo);
+ REPORTGLERROR("binding framebuffer");
+
+ glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
+ GL_RENDERBUFFER_EXT, renderBuffer);
+ REPORTGLERROR("specifying color render buffer");
+
+ if (glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT) != GL_FRAMEBUFFER_COMPLETE_EXT) {
+ std::cerr << "Problem with OpenGL framebuffer after specifying color render buffer.\n";
+ return 0;
+ }
+
+ glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, depthBuffer);
+ REPORTGLERROR("specifying depth render buffer");
+
+ if (glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT) != GL_FRAMEBUFFER_COMPLETE_EXT) {
+ std::cerr << "Problem with OpenGL framebuffer after specifying depth render buffer.\n";
+ return 0;
+ }
+ return fbo;
+}
+
+void fbo_bind(GLuint fbo)
+{
+ glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo);
+}
+
+void fbo_unbind()
+{
+ glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
+}
diff --git a/tests/fboutils.h b/tests/fboutils.h
new file mode 100644
index 0000000..0e5c32e
--- /dev/null
+++ b/tests/fboutils.h
@@ -0,0 +1,10 @@
+#ifndef FBOUTILS_H_
+#define FBOUTILS_H_
+
+#include "system-gl.h"
+
+GLuint fbo_create(GLsizei width, GLsizei height);
+void fbo_bind(GLuint fbo);
+void fbo_unbind();
+
+#endif
contact: Jan Huwald // Impressum