diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/CMakeLists.txt | 11 | ||||
| -rw-r--r-- | tests/OffscreenContext.h | 1 | ||||
| -rw-r--r-- | tests/OffscreenContext.mm | 16 | ||||
| -rw-r--r-- | tests/OffscreenView.cc | 10 | ||||
| -rw-r--r-- | tests/OffscreenView.h | 2 | ||||
| -rw-r--r-- | tests/opencsgtest.cc | 14 | 
6 files changed, 30 insertions, 24 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 74d3df2..1d884c6 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -36,16 +36,19 @@ endif()  include_directories(${EIGEN2_INCLUDE_DIR})  # OpenCSG -if (NOT $ENV{MACOSX_DEPLOY_DIR} STREQUAL "") +if (NOT $ENV{OPENCSG_DIR} STREQUAL "") +  set(OPENCSG_DIR "$ENV{OPENCSG_DIR}") +elseif (NOT $ENV{MACOSX_DEPLOY_DIR} STREQUAL "")    set(OPENCSG_DIR "$ENV{MACOSX_DEPLOY_DIR}")  endif()  if (NOT OPENCSG_INCLUDE_DIR) +   message(STATUS ${OPENCSG_DIR})    find_path(OPENCSG_INCLUDE_DIR              opencsg.h -            PATHS $ENV{MACOSX_DEPLOY_DIR}/include) +            PATHS ${OPENCSG_DIR}/include)    find_library(OPENCSG_LIBRARY                 opencsg -               PATHS $ENV{MACOSX_DEPLOY_DIR}/lib) +               PATHS ${OPENCSG_DIR}/src)    if (NOT OPENCSG_INCLUDE_DIR OR NOT OPENCSG_LIBRARY)      message(FATAL_ERROR "OpenCSG not found")    else() @@ -146,7 +149,7 @@ target_link_libraries(cgaltest ${CGAL_LIBRARY} ${CGAL_3RD_PARTY_LIBRARIES} ${QT_  # opencsgtest  #  add_executable(opencsgtest opencsgtest.cc OffscreenView.cc OffscreenContext.mm -                           ../src/opencsgrenderer.cc ../src/CSGTermEvaluator.cc ../src/CGALEvaluator.cc +                           ../src/opencsgrenderer.cc ../src/throwntogetherrenderer.cc ../src/CSGTermEvaluator.cc ../src/CGALEvaluator.cc                             ../src/PolySetCGALEvaluator.cc ../src/qhash.cc ../src/nef2dxf.cc                             ../src/cgaladv_minkowski2.cc ../src/cgaladv_minkowski3.cc                             ${COMMON_SOURCES}) diff --git a/tests/OffscreenContext.h b/tests/OffscreenContext.h index 59b6e2d..0300bcb 100644 --- a/tests/OffscreenContext.h +++ b/tests/OffscreenContext.h @@ -7,6 +7,7 @@  #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);  bool save_framebuffer(OffscreenContext *ctx, const char *filename); diff --git a/tests/OffscreenContext.mm b/tests/OffscreenContext.mm index 7ff7772..c8d0df7 100644 --- a/tests/OffscreenContext.mm +++ b/tests/OffscreenContext.mm @@ -14,6 +14,7 @@ struct OffscreenContext    NSAutoreleasePool *pool;    int width;    int height; +  GLuint fbo;  }; @@ -56,8 +57,8 @@ OffscreenContext *create_offscreen_context(int w, int h)    /*     * Create an FBO     */ -  GLuint  renderBuffer = 0; -  GLuint  depthBuffer = 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); @@ -69,9 +70,9 @@ OffscreenContext *create_offscreen_context(int w, int h)    glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, renderBuffer);    glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA8, w, h);    REPORTGLERROR("creating color render buffer"); -  GLuint  fbo = 0; -  glGenFramebuffersEXT(1, &fbo); -  glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo); +  ctx->fbo = 0; +  glGenFramebuffersEXT(1, &ctx->fbo); +  glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, ctx->fbo);    REPORTGLERROR("binding framebuffer");    glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,  @@ -196,3 +197,8 @@ bool save_framebuffer(OffscreenContext *ctx, const char *filename)    CGImageRelease(imageRef);    return true;  } + +void bind_offscreen_context(OffscreenContext *ctx) +{ +  glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, ctx->fbo); +} diff --git a/tests/OffscreenView.cc b/tests/OffscreenView.cc index b7ee8c7..3740c69 100644 --- a/tests/OffscreenView.cc +++ b/tests/OffscreenView.cc @@ -1,14 +1,15 @@  #include <GL/glew.h>  #include "OffscreenView.h" +#include <opencsg.h>  #include "Renderer.h" -#include "OffscreenContext.h"  #include <math.h>  #define FAR_FAR_AWAY 100000.0  OffscreenView::OffscreenView(size_t width, size_t height) -	: orthomode(false), showaxes(false), showfaces(false), showedges(false), viewer_distance(500) +	: orthomode(false), showaxes(true), showfaces(true), showedges(false), viewer_distance(500)  { +	for (int i = 0; i < 10; i++) this->shaderinfo[i] = 0;    this->ctx = create_offscreen_context(width, height);  	initializeGL();  	resizeGL(width, height); @@ -218,9 +219,8 @@ void OffscreenView::paintGL()  	glColor3d(1.0, 0.0, 0.0);  	if (this->renderer) { -#if defined(ENABLE_MDI) && defined(ENABLE_OPENCSG) -		// FIXME: This belongs in the OpenCSG renderer, but it doesn't know about this ID yet -		OpenCSG::setContext(this->opencsg_id); +#ifdef ENABLE_OPENCSG +		OpenCSG::setContext(0);  #endif  		this->renderer->draw(showfaces, showedges);  	} diff --git a/tests/OffscreenView.h b/tests/OffscreenView.h index 6531bcf..52ee3af 100644 --- a/tests/OffscreenView.h +++ b/tests/OffscreenView.h @@ -19,9 +19,9 @@ public:  	bool save(const char *filename);  	GLint shaderinfo[11]; +	OffscreenContext *ctx;  private:  	Renderer *renderer; -	class OffscreenContext *ctx;  	double w_h_ratio;  	bool orthomode; diff --git a/tests/opencsgtest.cc b/tests/opencsgtest.cc index 4d69650..7da15e8 100644 --- a/tests/opencsgtest.cc +++ b/tests/opencsgtest.cc @@ -1,3 +1,4 @@ +#include <GL/glew.h>  #include "openscad.h"  #include "builtin.h"  #include "context.h" @@ -10,9 +11,9 @@  #include "PolySetCGALEvaluator.h"  #include "OpenCSGRenderer.h" +#include "ThrownTogetherRenderer.h"  #include "csgterm.h" -#include <GL/glew.h>  #include "OffscreenView.h"  #include <QApplication> @@ -207,7 +208,7 @@ int main(int argc, char *argv[])  	QDir::setCurrent(original_path.absolutePath()); -	csgInfo.glview = new OffscreenView(256, 256);	 +	csgInfo.glview = new OffscreenView(512,512);  	glewInit();  	cout << "GLEW version " << glewGetString(GLEW_VERSION) << "\n"; @@ -227,19 +228,14 @@ int main(int argc, char *argv[])  	}  	OpenCSGRenderer opencsgRenderer(csgInfo.root_chain, csgInfo.highlights_chain, csgInfo.background_chain, csgInfo.glview->shaderinfo); -//	csgInfo.glview->setRenderFunc(thrownTogetherRenderer); +	ThrownTogetherRenderer thrownTogetherRenderer(csgInfo.root_chain, csgInfo.highlights_chain, csgInfo.background_chain); +//	csgInfo.glview->setRenderer(&thrownTogetherRenderer);  	csgInfo.glview->setRenderer(&opencsgRenderer);  	csgInfo.glview->paintGL();  	csgInfo.glview->save("out.png"); -// FIXME: Render & Grab buffer - -	// QImage img = csgInfo.glview->grabFrameBuffer(); -	// cout << "Image: " << img.width() << "x" << img.height() << " " << img.format() << "\n"; -	// img.save("out.png"); -  	destroy_builtin_functions();  	destroy_builtin_modules();  | 
