1 /* 2 * OpenSCAD (www.openscad.org) 3 * Copyright (C) 2009-2011 Clifford Wolf <clifford@clifford.at> and 4 * Marius Kintel <marius@kintel.net> 5 * 6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation; either version 2 of the License, or 9 * (at your option) any later version. 10 * 11 * As a special exception, you have permission to link this program 12 * with the CGAL library and distribute executables, as long as you 13 * follow the requirements of the GNU GPL in regard to all of the 14 * software in the executable aside from CGAL. 15 * 16 * This program is distributed in the hope that it will be useful, 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 * GNU General Public License for more details. 20 * 21 * You should have received a copy of the GNU General Public License 22 * along with this program; if not, write to the Free Software 23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 24 * 25 */ 26 27 #pragma once 28 29 #ifndef NULLGL 30 31 #include "colormap.h" 32 #include "rendersettings.h" 33 #include "CGAL_OGL_Polyhedron.h" 34 #include "CGAL_OGL_VBO_helper.h" 35 #include "printutils.h" 36 37 class CGAL_OGL_VBOPolyhedron : public VBOPolyhedron, public CGAL_OGL_Polyhedron 38 { 39 public: 40 CGAL_OGL_VBOPolyhedron(const ColorScheme & cs)41 CGAL_OGL_VBOPolyhedron(const ColorScheme &cs) 42 : VBOPolyhedron(), CGAL_OGL_Polyhedron(cs) { 43 PRINTD("CGAL_OGL_VBOPolyhedron()"); 44 PRINTD("CGAL_OGL_VBOPolyhedron() end"); 45 } 46 draw(bool showedges)47 void draw(bool showedges) const override { 48 PRINTDB("VBO draw(showedges = %d)", showedges); 49 // grab current state to restore after 50 GLfloat current_point_size, current_line_width; 51 GLboolean origVertexArrayState = glIsEnabled(GL_VERTEX_ARRAY); 52 GLboolean origNormalArrayState = glIsEnabled(GL_NORMAL_ARRAY); 53 GLboolean origColorArrayState = glIsEnabled(GL_COLOR_ARRAY); 54 55 glGetFloatv(GL_POINT_SIZE, ¤t_point_size); GL_ERROR_CHECK(); 56 glGetFloatv(GL_LINE_WIDTH, ¤t_line_width); GL_ERROR_CHECK(); 57 58 if(this->style == SNC_BOUNDARY) { 59 for (const auto &halffacet : this->halffacets_states) { 60 if (halffacet) halffacet->draw(); 61 } 62 } 63 64 if (this->style != SNC_BOUNDARY || showedges) { 65 for (const auto &point_edge : this->points_edges_states) { 66 if (point_edge) point_edge->draw(); 67 } 68 } 69 70 // restore states 71 GL_TRACE("glPointSize(%d)", current_point_size); 72 glPointSize(current_point_size); GL_ERROR_CHECK(); 73 GL_TRACE("glLineWidth(%d)", current_line_width); 74 glLineWidth(current_line_width); GL_ERROR_CHECK(); 75 76 if (!origVertexArrayState) glDisableClientState(GL_VERTEX_ARRAY); 77 if (!origNormalArrayState) glDisableClientState(GL_NORMAL_ARRAY); 78 if (!origColorArrayState) glDisableClientState(GL_COLOR_ARRAY); 79 80 PRINTD("VBO draw() end"); 81 } 82 }; // CGAL_OGL_Polyhedron 83 84 85 86 87 #else // NULLGL 88 89 #pragma push_macro("NDEBUG") 90 #undef NDEBUG 91 #include <CGAL/Bbox_3.h> 92 #pragma pop_macro("NDEBUG") 93 94 class CGAL_OGL_VBOPolyhedron : public CGAL::OGL::VBOPolyhedron, public CGAL_OGL_Polyhedron 95 { 96 public: CGAL_OGL_VBOPolyhedron()97 CGAL_OGL_VBOPolyhedron() {} draw(bool showedges)98 void draw(bool showedges) const {} bbox()99 CGAL::Bbox_3 bbox() const { return CGAL::Bbox_3(-1,-1,-1,1,1,1); } 100 }; 101 102 #endif // NULLGL 103