diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/CMakeLists.txt | 4 | ||||
-rw-r--r-- | tests/OffscreenContext.cc | 41 | ||||
-rw-r--r-- | tests/fbo.cc | 35 | ||||
-rw-r--r-- | tests/system-gl.cc | 48 | ||||
-rw-r--r-- | tests/system-gl.h | 3 |
5 files changed, 81 insertions, 50 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index d3abff2..1a73254 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -276,11 +276,11 @@ 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 fbo.cc +add_executable(throwntogethertest throwntogethertest.cc csgtestcore.cc OffscreenView.cc ${OFFSCREEN_CTX_SOURCE} imageutils.cc fbo.cc system-gl.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 - ../src/CGAL_Nef_polyhedron_DxfData.cc ../src/cgaladv_minkowski2.cc ../src/cgaladv_convexhull2.cc + ../src/CGAL_Nef_polyhedron_DxfData.cc ../src/cgaladv_minkowski2.cc ../src/cgaladv_convexhull2.cc ${COMMON_SOURCES}) set_target_properties(throwntogethertest PROPERTIES COMPILE_FLAGS "-DENABLE_OPENCSG -DENABLE_CGAL ${CGAL_CXX_FLAGS_INIT}") target_link_libraries(throwntogethertest ${CGAL_LIBRARY} ${CGAL_3RD_PARTY_LIBRARIES} ${QT_LIBRARIES} ${OPENCSG_LIBRARY} ${GLEW_LIBRARY} ${COCOA_LIBRARY} ${OPENGL_LIBRARY}) diff --git a/tests/OffscreenContext.cc b/tests/OffscreenContext.cc index 0679962..727e771 100644 --- a/tests/OffscreenContext.cc +++ b/tests/OffscreenContext.cc @@ -16,6 +16,7 @@ See Also #include "OffscreenContext.h" #include "printutils.h" #include "imageutils.h" +#include "system-gl.h" #include "fbo.h" #include <GL/gl.h> @@ -98,15 +99,16 @@ bool create_glx_dummy_window(OffscreenContext &ctx) // can't depend on xWin==NULL at failure. use a custom Xlib error handler instead. original_xlib_handler = XSetErrorHandler( XCreateWindow_error ); Window xWin = XCreateSimpleWindow( dpy, DefaultRootWindow(dpy), 0,0,10,10, 0,0,0 ); - XSync( dpy, false ); - if ( XCreateWindow_failed ) { + XSync( dpy, false ); + if ( XCreateWindow_failed ) { XFree( visinfo ); XFree( fbconfigs ); - return false; + return false; } XSetErrorHandler( original_xlib_handler ); // Most programs would call XMapWindow here. But we don't, to keep the window hidden + XMapWindow( dpy, xWin ); GLXContext context = glXCreateNewContext( dpy, fbconfigs[0], GLX_RGBA_TYPE, NULL, True ); if ( context == NULL ) { @@ -115,9 +117,12 @@ bool create_glx_dummy_window(OffscreenContext &ctx) XFree( visinfo ); XFree( fbconfigs ); return false; - } + } + + GLXWindow glxWin = glXCreateWindow( dpy, fbconfigs[0], xWin, NULL ); - if (!glXMakeContextCurrent( dpy, xWin, xWin, context )) { + //if (!glXMakeContextCurrent( dpy, xWin, xWin, context )) { + if (!glXMakeContextCurrent( dpy, glxWin, glxWin, context )) { cerr << "glXMakeContextCurrent failed\n"; glXDestroyContext( dpy, context ); XDestroyWindow( dpy, xWin ); @@ -165,25 +170,6 @@ Bool create_glx_dummy_context(OffscreenContext &ctx) return result; } -void glewCheck() { -#ifdef DEBUG - cerr << "GLEW version " << glewGetString(GLEW_VERSION) << "\n"; - cerr << (const char *)glGetString(GL_RENDERER) << "(" << (const char *)glGetString(GL_VENDOR) << ")\n" - << "OpenGL version " << (const char *)glGetString(GL_VERSION) << "\n"; - cerr << "Extensions: " << (const char *)glGetString(GL_EXTENSIONS) << "\n"; - - if (GLEW_ARB_framebuffer_object) { - cerr << "ARB_FBO supported\n"; - } - if (GLEW_EXT_framebuffer_object) { - cerr << "EXT_FBO supported\n"; - } - if (GLEW_EXT_packed_depth_stencil) { - cerr << "EXT_packed_depth_stencil\n"; - } -#endif -} - OffscreenContext *create_offscreen_context(int w, int h) { OffscreenContext *ctx = new OffscreenContext; @@ -199,13 +185,14 @@ OffscreenContext *create_offscreen_context(int w, int h) // glewInit must come after Context creation and before FBO calls. GLenum err = glewInit(); if (GLEW_OK != err) { - fprintf(stderr, "Unable to init GLEW: %s\n", glewGetErrorString(err)); - exit(1); + cerr << "Unable to init GLEW: " << glewGetErrorString(err) << endl; + return NULL; } - glewCheck(); ctx->fbo = fbo_new(); if (!fbo_init(ctx->fbo, w, h)) { + cerr << "Framebuffer init failed; dumping GLEW info" << endl; + glew_dump(); return NULL; } diff --git a/tests/fbo.cc b/tests/fbo.cc index f3d9223..42dacaa 100644 --- a/tests/fbo.cc +++ b/tests/fbo.cc @@ -1,4 +1,5 @@ #include "fbo.h" +#include "system-gl.h" #include <stdio.h> #include <iostream> using namespace std; @@ -14,16 +15,6 @@ fbo_t *fbo_new() return fbo; } -bool REPORTGLERROR(const char * task) -{ - GLenum tGLErr = glGetError(); - if (tGLErr != GL_NO_ERROR) { - std::cerr << "OpenGL error " << tGLErr << " while " << task << "\n"; - return true; - } else - return false; -} - bool use_ext() { // do we need to use the EXT or ARB version? @@ -47,7 +38,7 @@ bool check_fbo_status() else status = glCheckFramebufferStatus(GL_FRAMEBUFFER); - if (REPORTGLERROR("checking framebuffer status")) return false; + if (report_glerror("checking framebuffer status")) return false; if (status == GL_FRAMEBUFFER_COMPLETE) result = true; @@ -76,8 +67,9 @@ bool fbo_ext_init(fbo_t *fbo, size_t width, size_t height) { // Generate and bind FBO glGenFramebuffersEXT(1, &fbo->fbo_id); + if (report_glerror("glGenFramebuffersEXT")) return false; glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo->fbo_id); - if (REPORTGLERROR("binding framebuffer")) return false; + if (report_glerror("glBindFramebufferEXT")) return false; // Generate depth and render buffers glGenRenderbuffersEXT(1, &fbo->depthbuf_id); @@ -89,7 +81,7 @@ bool fbo_ext_init(fbo_t *fbo, size_t width, size_t height) // Attach render and depth buffers glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, fbo->renderbuf_id); - if (REPORTGLERROR("specifying color render buffer")) return false; + if (report_glerror("specifying color render buffer")) return false; if (!check_fbo_status()) { @@ -99,7 +91,7 @@ bool fbo_ext_init(fbo_t *fbo, size_t width, size_t height) glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, fbo->depthbuf_id); - if (REPORTGLERROR("specifying depth render buffer")) return false; + if (report_glerror("specifying depth render buffer")) return false; if (!check_fbo_status()) { cerr << "Problem with OpenGL framebuffer after specifying depth render buffer.\n"; @@ -113,8 +105,9 @@ bool fbo_arb_init(fbo_t *fbo, size_t width, size_t height) { // Generate and bind FBO glGenFramebuffers(1, &fbo->fbo_id); + if (report_glerror("glGenFramebuffers")) return false; glBindFramebuffer(GL_FRAMEBUFFER, fbo->fbo_id); - if (REPORTGLERROR("binding framebuffer")) return false; + if (report_glerror("glBindFramebuffer")) return false; // Generate depth and render buffers glGenRenderbuffers(1, &fbo->depthbuf_id); @@ -126,7 +119,7 @@ bool fbo_arb_init(fbo_t *fbo, size_t width, size_t height) // Attach render and depth buffers glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, fbo->renderbuf_id); - if (REPORTGLERROR("specifying color render buffer")) return false; + if (report_glerror("specifying color render buffer")) return false; if (!check_fbo_status()) { cerr << "Problem with OpenGL framebuffer after specifying color render buffer.\n"; @@ -135,7 +128,7 @@ bool fbo_arb_init(fbo_t *fbo, size_t width, size_t height) glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, fbo->depthbuf_id); - if (REPORTGLERROR("specifying depth render buffer")) return false; + if (report_glerror("specifying depth render buffer")) return false; if (!check_fbo_status()) { cerr << "Problem with OpenGL framebuffer after specifying depth render buffer.\n"; @@ -173,19 +166,19 @@ bool fbo_resize(fbo_t *fbo, size_t width, size_t height) if (use_ext()) { glBindRenderbufferEXT(GL_RENDERBUFFER, fbo->depthbuf_id); glRenderbufferStorageEXT(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, width, height); - if (REPORTGLERROR("creating depth render buffer")) return false; + if (report_glerror("creating depth render buffer")) return false; glBindRenderbufferEXT(GL_RENDERBUFFER, fbo->renderbuf_id); glRenderbufferStorageEXT(GL_RENDERBUFFER, GL_RGBA8, width, height); - if (REPORTGLERROR("creating color render buffer")) return false; + if (report_glerror("creating color render buffer")) return false; } else { glBindRenderbuffer(GL_RENDERBUFFER, fbo->depthbuf_id); glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, width, height); - if (REPORTGLERROR("creating depth render buffer")) return false; + if (report_glerror("creating depth render buffer")) return false; glBindRenderbuffer(GL_RENDERBUFFER, fbo->renderbuf_id); glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, width, height); - if (REPORTGLERROR("creating color render buffer")) return false; + if (report_glerror("creating color render buffer")) return false; } return true; diff --git a/tests/system-gl.cc b/tests/system-gl.cc new file mode 100644 index 0000000..b7c7dd6 --- /dev/null +++ b/tests/system-gl.cc @@ -0,0 +1,48 @@ + +/* OpenGL helper functions */ + +#include <iostream> +#include "system-gl.h" +#include <boost/algorithm/string.hpp> + +using namespace std; +using namespace boost; + +void glew_dump() { + cerr << "GLEW version: " << glewGetString(GLEW_VERSION) << endl + << "Renderer: " << (const char *)glGetString(GL_RENDERER) << endl + << "Vendor: " << (const char *)glGetString(GL_VENDOR) << endl + << "OpenGL version: " << (const char *)glGetString(GL_VERSION) << endl; + + string extensions((const char *)glGetString(GL_EXTENSIONS)); + replace_all( extensions, " ", "\n " ); + cerr << "Extensions: " << endl << " " << extensions << endl + << "Framebuffer and Stencil support:" << endl + << " GLEW_ARB_framebuffer_object: " << (bool)GLEW_ARB_framebuffer_object << endl + << " GLEW_EXT_framebuffer_object: " << (bool)GLEW_EXT_framebuffer_object << endl + << " GLEW_EXT_packed_depth_stencil: " << (bool)GLEW_EXT_packed_depth_stencil << endl + << " glewIsSupported(\"GL_ARB_framebuffer_object\"): " << (bool)glewIsSupported("GL_ARB_framebuffer_object") << endl + << " glewIsSupported(\"GL_EXT_framebuffer_object\"): " << (bool)glewIsSupported("GL_EXT_framebuffer_object") << endl + << " glewIsSupported(\"GL_EXT_packed_depth_stencil\"): " << (bool)glewIsSupported("GL_EXT_packed_depth_stencil") << endl; +}; + +const char * gl_errors[] = { + "GL_INVALID_ENUM", // 0x0500 + "GL_INVALID_VALUE", // 0x0501 + "GL_INVALID_OPERATION", // 0x0502 + "GL_OUT_OF_MEMORY" // 0x0503 +}; + +bool report_glerror(const char * task) +{ + GLenum tGLErr = glGetError(); + if (tGLErr != GL_NO_ERROR) { + if ( (tGLErr-0x500)<=3 && (tGLErr-0x500)>=0 ) + cerr << "OpenGL error " << gl_errors[tGLErr-0x500] << " while " << task << endl; + else + cerr << "OpenGL error " << hex << tGLErr << " while " << task << endl; + return true; + } + return false; +} + diff --git a/tests/system-gl.h b/tests/system-gl.h index 0f983cf..bb41be5 100644 --- a/tests/system-gl.h +++ b/tests/system-gl.h @@ -3,4 +3,7 @@ #include <GL/glew.h> +void glew_dump(); +bool report_glerror(const char *task); + #endif |