build on system without OpenGL. do cmake .. -DNULLGL=1

svg-export
Don Bright 2014-01-30 18:21:32 -06:00
parent 79f6baf264
commit 0308a2c896
10 changed files with 222 additions and 141 deletions

View File

@ -3,8 +3,10 @@ Running regression tests:
Prerequisites: cmake, python, ImageMagick 6.5.9.3 or newer
First, get a working qmake GUI build of the main openscad binary and install MCAD.
See the main README.
First, install MCAD.
$ cd openscad
$ git submodule update --init
A) Building test environment
@ -13,7 +15,10 @@ $ cd tests
$ cmake .
$ make
Windows + MSVC:
Windows + MSVC:
The MSVC build hasn't been tested in years. See the README for pointers.
First, gett the main GUI to build. Then, to build the tests:
From the QT command prompt:
@ -23,9 +28,10 @@ From the QT command prompt:
> cmake .
> nmake -f Makefile
Cross compiling Linux->Win32:
Cross compiling Linux->Win32 and testing under Wine:
Please see openscad/tests/CMingw-cross-env.cmake for instructions.
Experimental. Please see openscad/tests/CMingw-cross-env.cmake for instructions
on attempting to get it to work.
B) Running tests
@ -65,23 +71,6 @@ This is almost the same as adding a new regression test:
4) run the test normally and verify that it passes:
$ ctest -C Examples -R exampleNNN
Migration away from dedicated regression tests:
-----------------------------------------------
This test still needs an intermediate script that mangles away timestamps and
near-zero floating point numbers:
* cgalstlsanitytest
Some tests are yet to be converted:
* csgtexttest -- verify whether this is not redundant with dumptest
These look like tests, but are not actually in use:
* modulecachetest
* cgalcachetest
Troubleshooting:
------------------------------
@ -147,10 +136,42 @@ Is a boost/libstdc++ bug. Fix like so:
$ export LC_MESSAGES=
6. Other issues
6. I want to build without OpenGL
There is an unsupported way to do this, by defining NULLGL to Cmake:
mkdir nullglbin
cd nullglbin && cmake .. -DNULLGL=1 && make
The resulting openscad_nogui binary will fail most tests, but may be
useful for debugging and outputting 3d-formats like STL on systems without GL.
This option may break in the future and require tweaking to get working again.
7. Other issues
The OpenSCAD User Manual has a section on buildling. Please check there
for updates:
http://en.wikibooks.org/wiki/OpenSCAD_User_Manual
Migration away from dedicated regression tests:
-----------------------------------------------
In 2013 the test programs underwent a major change. These notes are leftover.
This test still needs an intermediate script that mangles away timestamps and
near-zero floating point numbers:
* cgalstlsanitytest
Some tests are yet to be converted:
* csgtexttest -- verify whether this is not redundant with dumptest
These look like tests, but are not actually in use:
* modulecachetest
* cgalcachetest

View File

@ -27,6 +27,8 @@
#ifndef CGAL_RENDERER_H
#define CGAL_RENDERER_H
#ifndef NULLGL
#include "OGL_helper.h"
#undef CGAL_NEF3_MARKED_VERTEX_COLOR
#undef CGAL_NEF3_MARKED_EDGE_COLOR
@ -101,4 +103,24 @@ private:
}; // Polyhedron
#else // NULLGL
#include <CGAL/Bbox_3.h>
class Polyhedron
{
public:
Polyhedron() {}
void draw(bool showedges) const {}
CGAL::Bbox_3 bbox() const { return CGAL::Bbox_3(-1,-1,-1,1,1,1); }
};
#endif // NULLGL
#endif // CGAL_RENDERER_H

View File

@ -7,6 +7,7 @@ This class is inherited by:
*QGLview - for Qt GUI
*OffscreenView - for offscreen rendering, in tests and from command-line
(This class is also overridden by NULLGL.cc for special experiments)
The view assumes either a Gimbal Camera (rotation,translation,distance)
or Vector Camera (eye,center/target) is being used. See Camera.h. The

View File

@ -1,4 +1,3 @@
#include <GL/glew.h>
#include "OffscreenView.h"
#include "system-gl.h"
#include <math.h>

View File

@ -25,7 +25,7 @@ void export_png(const CGAL_Nef_polyhedron *root_N, Camera &c, std::ostream &outp
void export_png_with_opencsg(Tree &tree, Camera &c, std::ostream &output);
void export_png_with_throwntogether(Tree &tree, Camera &c, std::ostream &output);
#endif
#endif // ENABLE_CGAL
#ifdef DEBUG
void export_stl(const class PolySet &ps, std::ostream &output);

View File

@ -91,9 +91,11 @@ void export_png_preview_common( Tree &tree, Camera &cam, std::ostream &output, P
}
csgInfo.glview->setCamera( cam );
#ifdef ENABLE_OPENCSG
if ( previewer == OPENCSG )
csgInfo.glview->setRenderer( &openCSGRenderer );
else
#endif
csgInfo.glview->setRenderer( &thrownTogetherRenderer );
#ifdef ENABLE_OPENCSG
OpenCSG::setContext( 0 );

View File

@ -104,6 +104,71 @@ void PolySet::insert_vertex(Vector3d v)
polygons.back().insert(polygons.back().begin(), v);
}
BoundingBox PolySet::getBoundingBox() const
{
BoundingBox bbox;
for (size_t i = 0; i < polygons.size(); i++) {
const Polygon &poly = polygons[i];
for (size_t j = 0; j < poly.size(); j++) {
const Vector3d &p = poly[j];
bbox.extend(p);
}
}
return bbox;
}
size_t PolySet::memsize() const
{
size_t mem = 0;
BOOST_FOREACH(const Polygon &p, this->polygons) mem += p.size() * sizeof(Vector3d);
mem += this->polygon.memsize() - sizeof(this->polygon);
mem += sizeof(PolySet);
return mem;
}
void PolySet::append(const PolySet &ps)
{
this->polygons.insert(this->polygons.end(), ps.polygons.begin(), ps.polygons.end());
}
void PolySet::transform(const Transform3d &mat)
{
BOOST_FOREACH(Polygon &p, this->polygons) {
BOOST_FOREACH(Vector3d &v, p) {
v = mat * v;
}
}
}
void PolySet::resize(Vector3d newsize, const Eigen::Matrix<bool,3,1> &autosize)
{
BoundingBox bbox = this->getBoundingBox();
// Find largest dimension
int maxdim = 0;
for (int i=1;i<3;i++) if (newsize[i] > newsize[maxdim]) maxdim = i;
// Default scale (scale with 1 if the new size is 0)
Vector3d scale(1,1,1);
for (int i=0;i<3;i++) if (newsize[i] > 0) scale[i] = newsize[i] / bbox.sizes()[i];
// Autoscale where applicable
double autoscale = scale[maxdim];
Vector3d newscale;
for (int i=0;i<3;i++) newscale[i] = !autosize[i] || (newsize[i] > 0) ? scale[i] : autoscale;
Transform3d t;
t.matrix() <<
newscale[0], 0, 0, 0,
0, newscale[1], 0, 0,
0, 0, newscale[2], 0,
0, 0, 0, 1;
this->transform(t);
}
// all GL functions grouped together here
#ifndef NULLGL
static void gl_draw_triangle(GLint *shaderinfo, const Vector3d &p0, const Vector3d &p1, const Vector3d &p2, bool e0, bool e1, bool e2, double z, bool mirrored)
{
double ax = p1[0] - p0[0], bx = p1[0] - p2[0];
@ -333,66 +398,8 @@ void PolySet::render_edges(Renderer::csgmode_e csgmode) const
glEnable(GL_LIGHTING);
}
BoundingBox PolySet::getBoundingBox() const
{
BoundingBox bbox;
for (size_t i = 0; i < polygons.size(); i++) {
const Polygon &poly = polygons[i];
for (size_t j = 0; j < poly.size(); j++) {
const Vector3d &p = poly[j];
bbox.extend(p);
}
}
return bbox;
}
size_t PolySet::memsize() const
{
size_t mem = 0;
BOOST_FOREACH(const Polygon &p, this->polygons) mem += p.size() * sizeof(Vector3d);
mem += this->polygon.memsize() - sizeof(this->polygon);
mem += sizeof(PolySet);
return mem;
}
void PolySet::append(const PolySet &ps)
{
this->polygons.insert(this->polygons.end(), ps.polygons.begin(), ps.polygons.end());
}
void PolySet::transform(const Transform3d &mat)
{
BOOST_FOREACH(Polygon &p, this->polygons) {
BOOST_FOREACH(Vector3d &v, p) {
v = mat * v;
}
}
}
void PolySet::resize(Vector3d newsize, const Eigen::Matrix<bool,3,1> &autosize)
{
BoundingBox bbox = this->getBoundingBox();
// Find largest dimension
int maxdim = 0;
for (int i=1;i<3;i++) if (newsize[i] > newsize[maxdim]) maxdim = i;
// Default scale (scale with 1 if the new size is 0)
Vector3d scale(1,1,1);
for (int i=0;i<3;i++) if (newsize[i] > 0) scale[i] = newsize[i] / bbox.sizes()[i];
// Autoscale where applicable
double autoscale = scale[maxdim];
Vector3d newscale;
for (int i=0;i<3;i++) newscale[i] = !autosize[i] || (newsize[i] > 0) ? scale[i] : autoscale;
Transform3d t;
t.matrix() <<
newscale[0], 0, 0, 0,
0, newscale[1], 0, 0,
0, 0, newscale[2], 0,
0, 0, 0, 1;
this->transform(t);
}
#else //NULLGL
static void gl_draw_triangle(GLint *shaderinfo, const Vector3d &p0, const Vector3d &p1, const Vector3d &p2, bool e0, bool e1, bool e2, double z, bool mirrored) {}
void PolySet::render_surface(Renderer::csgmode_e csgmode, const Transform3d &m, GLint *shaderinfo) const {}
void PolySet::render_edges(Renderer::csgmode_e csgmode) const {}
#endif //NULLGL

View File

@ -1,6 +1,8 @@
#ifndef SYSTEMGL_H_
#define SYSTEMGL_H_
#ifndef NULLGL
#include <GL/glew.h>
#ifdef __APPLE__
@ -13,10 +15,16 @@
#endif
#endif
#else // NULLGL
#define GLint int
#define GLuint unsigned int
inline void glColor4fv( float *c ) {}
#endif // NULLGL
#include <string>
std::string glew_dump();
std::string glew_extensions_dump();
bool report_glerror(const char * function);
#endif
#endif // SYSTEMGL_H_

View File

@ -73,6 +73,17 @@ if(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/../libraries/MCAD/__init__.py)
message(FATAL_ERROR "MCAD not found. You can install from the OpenSCAD root as follows: \n git submodule update --init")
endif()
# NULLGL - Allow us to buidl without OpenGL(TM). run 'cmake .. -DNULLGL=1'
# Most tests will fail, but it can be used for testing/experiments
if(NULLGL)
set(ENABLE_OPENCSG_FLAG "") # OpenCSG is entirely an OpenGL software
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DNULLGL")
set(SKIP_IMAGEMAGICK "1") # we dont generate png, so nothing to compare
else()
set(ENABLE_OPENCSG_FLAG "-DENABLE_OPENCSG")
endif()
#
# Windows
#
@ -255,6 +266,10 @@ else()
inclusion(EIGEN_DIR EIGEN_INCLUDE_DIR)
endif()
###### NULLGL wraps all OpenGL(TM) items (GL, Glew, OpenCSG)
###### Several pages of code fall under this 'if( NOT NULLGL )'
if (NOT NULLGL)
# OpenGL
find_package(OpenGL REQUIRED)
if (NOT OPENGL_GLU_FOUND)
@ -327,6 +342,8 @@ message(STATUS "GLEW library: " ${GLEW_LIBRARY})
inclusion(GLEW_DIR GLEW_INCLUDE_DIR)
endif() ########## NULLGL ENDIF
# Flex/Bison
find_package(BISON REQUIRED)
@ -431,19 +448,19 @@ else()
else()
message(FATAL_ERROR "Couldn't find imagemagick 'convert' program")
endif()
endif()
if ( "${ImageMagick_VERSION_STRING}" VERSION_LESS "6.5.9.4" )
message(STATUS "ImageMagick version less than 6.5.9.4, cannot use -morphology comparison")
message(STATUS "ImageMagick Using older image comparison method")
set(COMPARATOR "old")
endif()
if ( "${ImageMagick_VERSION_STRING}" VERSION_LESS "6.5.9.4" )
message(STATUS "ImageMagick version less than 6.5.9.4, cannot use -morphology comparison")
message(STATUS "ImageMagick Using older image comparison method")
set(COMPARATOR "old")
endif()
execute_process(COMMAND ${ImageMagick_convert_EXECUTABLE} --version OUTPUT_VARIABLE IM_OUT )
if ( ${IM_OUT} MATCHES "OpenMP" )
# http://www.daniloaz.com/en/617/systems/high-cpu-load-when-converting-images-with-imagemagick
message(STATUS "ImageMagick: OpenMP bug workaround - setting MAGICK_THREAD_LIMIT=1")
set(CTEST_ENVIRONMENT "${CTEST_ENVIRONMENT};MAGICK_THREAD_LIMIT=1")
execute_process(COMMAND ${ImageMagick_convert_EXECUTABLE} --version OUTPUT_VARIABLE IM_OUT )
if ( ${IM_OUT} MATCHES "OpenMP" )
# http://www.daniloaz.com/en/617/systems/high-cpu-load-when-converting-images-with-imagemagick
message(STATUS "ImageMagick: OpenMP bug workaround - setting MAGICK_THREAD_LIMIT=1")
set(CTEST_ENVIRONMENT "${CTEST_ENVIRONMENT};MAGICK_THREAD_LIMIT=1")
endif()
endif()
# Internal includes
@ -592,6 +609,21 @@ set(OFFSCREEN_SOURCES
../src/${PLATFORMUTILS_SOURCE}
../src/OpenCSGRenderer.cc)
if(NULLGL)
message(STATUS "NULLGL is set. Overriding previous OpenGL(TM) settings")
set(OFFSCREEN_SOURCES
../src/NULLGL.cc # contains several 'nullified' versions of above .cc files
../src/OffscreenView.cc
../src/OffscreenContextNULL.cc
../src/export_png.cc
../src/${OFFSCREEN_IMGUTILS_SOURCE}
../src/imageutils.cc
../src/renderer.cc
../src/render.cc
../src/PlatformUtils.cc
../src/${PLATFORMUTILS_SOURCE} )
endif()
add_library(tests-core STATIC ${CORE_SOURCES})
target_link_libraries(tests-core ${OPENGL_LIBRARIES} ${GLIB2_LIBRARIES} )
set(TESTS-CORE-LIBRARIES ${OPENGL_LIBRARIES} ${GLIB2_LIBRARIES} ${Boost_LIBRARIES} )
@ -604,11 +636,24 @@ set_target_properties(tests-cgal PROPERTIES COMPILE_FLAGS "-DENABLE_CGAL ${CGAL_
target_link_libraries(tests-cgal tests-common)
set(TESTS-CGAL-LIBRARIES ${CGAL_LIBRARY} ${CGAL_3RD_PARTY_LIBRARIES} ${GMP_LIBRARIES} ${MPFR_LIBRARIES} ${TESTS-CORE-LIBRARIES})
add_library(tests-nocgal STATIC ${NOCGAL_SOURCES})
target_link_libraries(tests-nocgal tests-common)
#
# Create non-CGAL tests
#
if (NOT NULLGL)
add_library(tests-nocgal STATIC ${NOCGAL_SOURCES})
target_link_libraries(tests-nocgal tests-common)
set(TESTS-NOCGAL-LIBRARIES ${TESTS-CORE-LIBRARIES})
else()
message(STATUS "NULLGL: cannot use GL/GLU tessellator. see dxftess.cc")
message(STATUS "NULLGL: non-CGAL tests will use CGAL's tessellator")
add_library(tests-nocgal STATIC ${CGAL_SOURCES})
set_target_properties(tests-nocgal PROPERTIES COMPILE_FLAGS "-DENABLE_CGAL ${CGAL_CXX_FLAGS_INIT}")
target_link_libraries(tests-nocgal tests-common)
set(TESTS-NOCGAL-LIBRARIES ${TESTS-CGAL-LIBRARIES})
endif()
add_library(tests-offscreen STATIC ${OFFSCREEN_SOURCES})
set_target_properties(tests-offscreen PROPERTIES COMPILE_FLAGS "-DENABLE_OPENCSG -DENABLE_CGAL ${CGAL_CXX_FLAGS_INIT}")
set(TESTS-NOCGAL-LIBRARIES ${TESTS-CORE-LIBRARIES})
set_target_properties(tests-offscreen PROPERTIES COMPILE_FLAGS "${ENABLE_OPENCSG_FLAG} -DENABLE_CGAL ${CGAL_CXX_FLAGS_INIT}")
#
# modulecachetest
@ -633,33 +678,9 @@ target_link_libraries(cgalcachetest tests-cgal ${TESTS-CGAL-LIBRARIES} ${CLIPPER
# openscad no-qt
#
add_executable(openscad_nogui ../src/openscad.cc)
set_target_properties(openscad_nogui PROPERTIES COMPILE_FLAGS "-fno-strict-aliasing -DEIGEN_DONT_ALIGN -DENABLE_CGAL -DENABLE_OPENCSG ${CGAL_CXX_FLAGS_INIT}")
set_target_properties(openscad_nogui PROPERTIES COMPILE_FLAGS "-fno-strict-aliasing -DEIGEN_DONT_ALIGN -DENABLE_CGAL ${ENABLE_OPENCSG_FLAG} ${CGAL_CXX_FLAGS_INIT}")
target_link_libraries(openscad_nogui tests-offscreen tests-cgal tests-nocgal ${TESTS-CORE-LIBRARIES} ${TESTS-CGAL-LIBRARIES} ${GLEW_LIBRARY} ${Boost_LIBRARIES} ${OPENCSG_LIBRARY} ${COCOA_LIBRARY} ${APP_SERVICES_LIBRARY})
#
# GUI binary tests
#
#if(APPLE)
# set(OPENSCAD_BINPATH "${CMAKE_CURRENT_SOURCE_DIR}/../OpenSCAD.app/Contents/MacOS/OpenSCAD")
#elseif (MINGW_CROSS_ENV_DIR)
# set(OPENSCAD_BINPATH "${CMAKE_CURRENT_SOURCE_DIR}/../mingw32/release/openscad.exe")
#elseif(WIN32)
# set(OPENSCAD_BINPATH "${CMAKE_CURRENT_SOURCE_DIR}/../Release/openscad.exe")
#else()
# set(OPENSCAD_BINPATH "${CMAKE_CURRENT_SOURCE_DIR}/../openscad")
#endif()
#if(EXISTS "${CMAKE_CURRENT_BINARY_DIR}/openscad")
# set(OPENSCAD_BINPATH "${CMAKE_CURRENT_BINARY_DIR}/openscad")
#endif()
#if(EXISTS "${OPENSCAD_BINPATH}")
# message(STATUS "Found OpenSCAD binary: ${OPENSCAD_BINPATH}")
#else()
# message(STATUS "Couldn't find the OpenSCAD binary: ${OPENSCAD_BINPATH}")
# message(FATAL_ERROR "Please build the OpenSCAD binary and place it here: ${OPENSCAD_BINPATH}" )
#endif()
if(WIN32)
set(OPENSCAD_BINPATH "${CMAKE_CURRENT_BINARY_DIR}/openscad_nogui.exe")
else()

View File

@ -1,28 +1,28 @@
find_package(PkgConfig REQUIRED)
pkg_search_module(GLIB2 REQUIRED glib-2.0)
#message("GLIB2_LIBRARIES ${GLIB2_LIBRARIES}")
message("GLIB2_LIBRARY_DIRS ${GLIB2_LIBRARY_DIRS}")
#message("GLIB2_LDFLAGS ${GLIB2_LDFLAGS}")
#message("GLIB2_LDFLAGS_OTHER ${GLIB2_LDFLAGS_OTHER}")
message("GLIB2_INCLUDE_DIRS ${GLIB2_INCLUDE_DIRS}")
#message("GLIB2_CFLAGS ${GLIB2_CFLAGS}")
#message("GLIB2_CFLAGS_OTHER ${GLIB2_CFLAGS_OTHER}")
message("GLIB2_LIBDIR ${GLIB2_LIBDIR}")
#message(STATUS "GLIB2_LIBRARIES ${GLIB2_LIBRARIES}")
message(STATUS "GLIB2_LIBRARY_DIRS ${GLIB2_LIBRARY_DIRS}")
#message(STATUS "GLIB2_LDFLAGS ${GLIB2_LDFLAGS}")
#message(STATUS "GLIB2_LDFLAGS_OTHER ${GLIB2_LDFLAGS_OTHER}")
message(STATUS "GLIB2_INCLUDE_DIRS ${GLIB2_INCLUDE_DIRS}")
#message(STATUS "GLIB2_CFLAGS ${GLIB2_CFLAGS}")
#message(STATUS "GLIB2_CFLAGS_OTHER ${GLIB2_CFLAGS_OTHER}")
message(STATUS "GLIB2_LIBDIR ${GLIB2_LIBDIR}")
set(GLIB2_DEFINITIONS ${GLIB2_CFLAGS_OTHER})
#message("GLIB2_DEFINITIONS ${GLIB2_DEFINITIONS}")
#message(STATUS "GLIB2_DEFINITIONS ${GLIB2_DEFINITIONS}")
set(GLIB2_LIBRARY_NAMES ${GLIB2_LIBRARIES})
set(GLIB2_LIBRARIES "")
foreach(GLIB2_LIB ${GLIB2_LIBRARY_NAMES})
# message("lib: ${GLIB2_LIB}")
# message(STATUS "lib: ${GLIB2_LIB}")
set(TMP TMP-NOTFOUND)
find_library(TMP NAMES ${GLIB2_LIB}
PATHS ${GLIB2_LIBRARY_DIRS}
PATHS ${GLIB2_LIBDIR}
NO_DEFAULT_PATH)
# message("TMP: ${TMP}")
# message(STATUS "TMP: ${TMP}")
list(APPEND GLIB2_LIBRARIES "${TMP}")
endforeach()
message("GLIB2_LIBRARIES: ${GLIB2_LIBRARIES}")
message(STATUS "GLIB2_LIBRARIES: ${GLIB2_LIBRARIES}")