diff options
author | kintel <kintel@b57f626f-c46c-0410-a088-ec61d464b74c> | 2010-02-10 16:43:43 (GMT) |
---|---|---|
committer | kintel <kintel@b57f626f-c46c-0410-a088-ec61d464b74c> | 2010-02-10 16:43:43 (GMT) |
commit | 12ad2eda30fb35fbb287e2cd94da5289b115c0be (patch) | |
tree | 252d66a39a74723b897f8d1eacd695a7fa8407be | |
parent | 63c1154f8e434da1988dccac4101a51271083fe2 (diff) |
Extracted OpenCSG code to separate files
git-svn-id: http://svn.clifford.at/openscad/trunk@434 b57f626f-c46c-0410-a088-ec61d464b74c
-rw-r--r-- | doc/TODO.txt | 7 | ||||
-rw-r--r-- | opencsg.pri | 3 | ||||
-rw-r--r-- | openscad.pro | 2 | ||||
-rw-r--r-- | src/mainwin.cc | 84 | ||||
-rw-r--r-- | src/render-opencsg.cc | 84 | ||||
-rw-r--r-- | src/render-opencsg.h | 8 |
6 files changed, 103 insertions, 85 deletions
diff --git a/doc/TODO.txt b/doc/TODO.txt index 3f62c80..a301d6e 100644 --- a/doc/TODO.txt +++ b/doc/TODO.txt @@ -3,12 +3,12 @@ BUGS ---- o Some invalid DXF data gets pass the import checks and breaks the tessing code o Tesselation via GLU sometimes produces strange results -o Non-manifold objects make CGAL crash (e.g. two cubes which touch at one edge) +o Export STL: Exports existing CGAL model even though the current model is changed, but not CGAL rendered CRASH BUGS ---------- o Broken polyhedron() entities are not correctly detected and cause CGAL segfaults -o Export STL: Exports existing CGAL model even though the current model is changed, but not CGAL rendered +o Non-manifold objects make CGAL crash (e.g. two cubes which touch at one edge) USER INTERFACE @@ -40,7 +40,8 @@ o 3D View - Quick highlighting of object under the cursor in the editor - View All - overlay indicator displaying current view mode - - CSG rendering: prefer holes when coincident surfaces to avoid zbuffer fighting? + - OpenCSG rendering: Coincident surfaces causes z-buffer fighting. Is this somehow + avoidable tuning the depth tests in OpenCSG? o Editor - line numbers - tear-off/maximize options? diff --git a/opencsg.pri b/opencsg.pri index 0ae05d2..3f3695d 100644 --- a/opencsg.pri +++ b/opencsg.pri @@ -1,4 +1,7 @@ opencsg { + HEADERS += src/render-opencsg.h + SOURCES += src/render-opencsg.cc + DEFINES += ENABLE_OPENCSG LIBS += -lopencsg unix:LIBS += -lGLEW diff --git a/openscad.pro b/openscad.pro index 8e2ac2c..610bbeb 100644 --- a/openscad.pro +++ b/openscad.pro @@ -34,7 +34,7 @@ QT += opengl macx:CONFIG += mdi CONFIG += cgal CONFIG += opencsg -#CONFIG += progresswidget +macx:CONFIG += progresswidget mdi { # MDI needs an OpenCSG library that is compiled with OpenCSG-Reset-Hack.patch applied diff --git a/src/mainwin.cc b/src/mainwin.cc index 6b8fe13..d1a84d2 100644 --- a/src/mainwin.cc +++ b/src/mainwin.cc @@ -38,6 +38,9 @@ #include "builtin.h" #include "dxftess.h" #include "progress.h" +#ifdef ENABLE_OPENCSG +#include "render-opencsg.h" +#endif #ifdef USE_PROGRESSWIDGET #include "ProgressWidget.h" #endif @@ -1313,87 +1316,6 @@ void MainWindow::viewModeActionsUncheck() #ifdef ENABLE_OPENCSG -class OpenCSGPrim : public OpenCSG::Primitive -{ -public: - OpenCSGPrim(OpenCSG::Operation operation, unsigned int convexity) : - OpenCSG::Primitive(operation, convexity) { } - PolySet *p; - double *m; - int csgmode; - virtual void render() { - glPushMatrix(); - glMultMatrixd(m); - p->render_surface(PolySet::COLORMODE_NONE, PolySet::csgmode_e(csgmode), m); - glPopMatrix(); - } -}; - -static void renderCSGChainviaOpenCSG(CSGChain *chain, GLint *shaderinfo, bool highlight, bool background) -{ - std::vector<OpenCSG::Primitive*> primitives; - int j = 0; - for (int i = 0;; i++) - { - bool last = i == chain->polysets.size(); - - if (last || chain->types[i] == CSGTerm::TYPE_UNION) - { - if (j+1 != i) { - OpenCSG::render(primitives); - glDepthFunc(GL_EQUAL); - } - if (shaderinfo) - glUseProgram(shaderinfo[0]); - for (; j < i; j++) { - double *m = chain->matrices[j]; - glPushMatrix(); - glMultMatrixd(m); - int csgmode = chain->types[j] == CSGTerm::TYPE_DIFFERENCE ? PolySet::CSGMODE_DIFFERENCE : PolySet::CSGMODE_NORMAL; - if (highlight) { - chain->polysets[j]->render_surface(PolySet::COLORMODE_HIGHLIGHT, PolySet::csgmode_e(csgmode + 20), m, shaderinfo); - } else if (background) { - chain->polysets[j]->render_surface(PolySet::COLORMODE_BACKGROUND, PolySet::csgmode_e(csgmode + 10), m, shaderinfo); - } else if (m[16] >= 0 || m[17] >= 0 || m[18] >= 0 || m[19] >= 0) { - // User-defined color from source - glColor4d(m[16], m[17], m[18], m[19]); - if (shaderinfo) { - glUniform4f(shaderinfo[1], m[16], m[17], m[18], m[19]); - glUniform4f(shaderinfo[2], (m[16]+1)/2, (m[17]+1)/2, (m[18]+1)/2, 1.0); - } - chain->polysets[j]->render_surface(PolySet::COLORMODE_NONE, PolySet::csgmode_e(csgmode), m, shaderinfo); - } else if (chain->types[j] == CSGTerm::TYPE_DIFFERENCE) { - chain->polysets[j]->render_surface(PolySet::COLORMODE_CUTOUT, PolySet::csgmode_e(csgmode), m, shaderinfo); - } else { - chain->polysets[j]->render_surface(PolySet::COLORMODE_MATERIAL, PolySet::csgmode_e(csgmode), m, shaderinfo); - } - glPopMatrix(); - } - if (shaderinfo) - glUseProgram(0); - for (unsigned int k = 0; k < primitives.size(); k++) { - delete primitives[k]; - } - glDepthFunc(GL_LEQUAL); - primitives.clear(); - } - - if (last) - break; - - OpenCSGPrim *prim = new OpenCSGPrim(chain->types[i] == CSGTerm::TYPE_DIFFERENCE ? - OpenCSG::Subtraction : OpenCSG::Intersection, chain->polysets[i]->convexity); - prim->p = chain->polysets[i]; - prim->m = chain->matrices[i]; - prim->csgmode = chain->types[i] == CSGTerm::TYPE_DIFFERENCE ? PolySet::CSGMODE_DIFFERENCE : PolySet::CSGMODE_NORMAL; - if (highlight) - prim->csgmode += 20; - else if (background) - prim->csgmode += 10; - primitives.push_back(prim); - } -} - static void renderGLThrownTogether(void *vp); static void renderGLviaOpenCSG(void *vp) diff --git a/src/render-opencsg.cc b/src/render-opencsg.cc new file mode 100644 index 0000000..f6d26ac --- /dev/null +++ b/src/render-opencsg.cc @@ -0,0 +1,84 @@ +#include "render-opencsg.h" +#include "polyset.h" +#include "csgterm.h" + +class OpenCSGPrim : public OpenCSG::Primitive +{ +public: + OpenCSGPrim(OpenCSG::Operation operation, unsigned int convexity) : + OpenCSG::Primitive(operation, convexity) { } + PolySet *p; + double *m; + int csgmode; + virtual void render() { + glPushMatrix(); + glMultMatrixd(m); + p->render_surface(PolySet::COLORMODE_NONE, PolySet::csgmode_e(csgmode), m); + glPopMatrix(); + } +}; + +void renderCSGChainviaOpenCSG(CSGChain *chain, GLint *shaderinfo, bool highlight, bool background) +{ + std::vector<OpenCSG::Primitive*> primitives; + int j = 0; + for (int i = 0;; i++) + { + bool last = i == chain->polysets.size(); + + if (last || chain->types[i] == CSGTerm::TYPE_UNION) + { + if (j+1 != i) { + OpenCSG::render(primitives); + glDepthFunc(GL_EQUAL); + } + if (shaderinfo) + glUseProgram(shaderinfo[0]); + for (; j < i; j++) { + double *m = chain->matrices[j]; + glPushMatrix(); + glMultMatrixd(m); + int csgmode = chain->types[j] == CSGTerm::TYPE_DIFFERENCE ? PolySet::CSGMODE_DIFFERENCE : PolySet::CSGMODE_NORMAL; + if (highlight) { + chain->polysets[j]->render_surface(PolySet::COLORMODE_HIGHLIGHT, PolySet::csgmode_e(csgmode + 20), m, shaderinfo); + } else if (background) { + chain->polysets[j]->render_surface(PolySet::COLORMODE_BACKGROUND, PolySet::csgmode_e(csgmode + 10), m, shaderinfo); + } else if (m[16] >= 0 || m[17] >= 0 || m[18] >= 0 || m[19] >= 0) { + // User-defined color from source + glColor4d(m[16], m[17], m[18], m[19]); + if (shaderinfo) { + glUniform4f(shaderinfo[1], m[16], m[17], m[18], m[19]); + glUniform4f(shaderinfo[2], (m[16]+1)/2, (m[17]+1)/2, (m[18]+1)/2, 1.0); + } + chain->polysets[j]->render_surface(PolySet::COLORMODE_NONE, PolySet::csgmode_e(csgmode), m, shaderinfo); + } else if (chain->types[j] == CSGTerm::TYPE_DIFFERENCE) { + chain->polysets[j]->render_surface(PolySet::COLORMODE_CUTOUT, PolySet::csgmode_e(csgmode), m, shaderinfo); + } else { + chain->polysets[j]->render_surface(PolySet::COLORMODE_MATERIAL, PolySet::csgmode_e(csgmode), m, shaderinfo); + } + glPopMatrix(); + } + if (shaderinfo) + glUseProgram(0); + for (unsigned int k = 0; k < primitives.size(); k++) { + delete primitives[k]; + } + glDepthFunc(GL_LEQUAL); + primitives.clear(); + } + + if (last) + break; + + OpenCSGPrim *prim = new OpenCSGPrim(chain->types[i] == CSGTerm::TYPE_DIFFERENCE ? + OpenCSG::Subtraction : OpenCSG::Intersection, chain->polysets[i]->convexity); + prim->p = chain->polysets[i]; + prim->m = chain->matrices[i]; + prim->csgmode = chain->types[i] == CSGTerm::TYPE_DIFFERENCE ? PolySet::CSGMODE_DIFFERENCE : PolySet::CSGMODE_NORMAL; + if (highlight) + prim->csgmode += 20; + else if (background) + prim->csgmode += 10; + primitives.push_back(prim); + } +} diff --git a/src/render-opencsg.h b/src/render-opencsg.h new file mode 100644 index 0000000..9433cbe --- /dev/null +++ b/src/render-opencsg.h @@ -0,0 +1,8 @@ +#ifndef RENDER_OPENCSG_H_ +#define RENDER_OPENCSG_H_ + +#include <GL/glew.h> + +void renderCSGChainviaOpenCSG(class CSGChain *chain, GLint *shaderinfo, bool highlight, bool background); + +#endif |