summaryrefslogtreecommitdiff
path: root/tests/OffscreenContext.mm
diff options
context:
space:
mode:
authorMarius Kintel <marius@kintel.net>2011-09-29 02:05:47 (GMT)
committerMarius Kintel <marius@kintel.net>2011-09-29 02:05:47 (GMT)
commit846970462afbe91e3c06f57c45e095a625aec0d3 (patch)
treebcd49faa6ced22e7046bf79c6024f26bb0d4b7e5 /tests/OffscreenContext.mm
parentc6e5e84eec401096451f14e9e853e33c3aa88853 (diff)
More refactoring of offscreen rendering
Diffstat (limited to 'tests/OffscreenContext.mm')
-rw-r--r--tests/OffscreenContext.mm58
1 files changed, 8 insertions, 50 deletions
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);
}
contact: Jan Huwald // Impressum