summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordon bright <hugh.m.bright@gmail.com>2013-02-24 02:54:13 (GMT)
committerdon bright <hugh.m.bright@gmail.com>2013-02-24 02:54:13 (GMT)
commitce2a9a8cb5e1a820a3ade385ca0bcfc56040d3c2 (patch)
tree838dd4885406c2b3cf3a8dee3a7e957a5841f947
parent386df69c0f6a893d3f888ae0dd9150fae197514c (diff)
move enable_opencsg_shaders from csgtestcore to OffscreenView.cc
-rw-r--r--src/OffscreenView.cc97
-rw-r--r--src/OffscreenView.h2
-rw-r--r--src/qglview.cc53
-rw-r--r--tests/CMakeLists.txt4
-rw-r--r--tests/csgtestcore.cc99
5 files changed, 133 insertions, 122 deletions
diff --git a/src/OffscreenView.cc b/src/OffscreenView.cc
index 80fa35d..e499bb0 100644
--- a/src/OffscreenView.cc
+++ b/src/OffscreenView.cc
@@ -32,6 +32,103 @@ OffscreenView::~OffscreenView()
teardown_offscreen_context(this->ctx);
}
+void OffscreenView::enable_opencsg_shaders()
+{
+#ifdef ENABLE_OPENCSG
+ const char *openscad_disable_gl20_env = getenv("OPENSCAD_DISABLE_GL20");
+ if (openscad_disable_gl20_env && !strcmp(openscad_disable_gl20_env, "0")) {
+ openscad_disable_gl20_env = NULL;
+ }
+
+ if (glewIsSupported("GL_VERSION_2_0") && openscad_disable_gl20_env == NULL )
+ {
+ const char *vs_source =
+ "uniform float xscale, yscale;\n"
+ "attribute vec3 pos_b, pos_c;\n"
+ "attribute vec3 trig, mask;\n"
+ "varying vec3 tp, tr;\n"
+ "varying float shading;\n"
+ "void main() {\n"
+ " vec4 p0 = gl_ModelViewProjectionMatrix * gl_Vertex;\n"
+ " vec4 p1 = gl_ModelViewProjectionMatrix * vec4(pos_b, 1.0);\n"
+ " vec4 p2 = gl_ModelViewProjectionMatrix * vec4(pos_c, 1.0);\n"
+ " float a = distance(vec2(xscale*p1.x/p1.w, yscale*p1.y/p1.w), vec2(xscale*p2.x/p2.w, yscale*p2.y/p2.w));\n"
+ " float b = distance(vec2(xscale*p0.x/p0.w, yscale*p0.y/p0.w), vec2(xscale*p1.x/p1.w, yscale*p1.y/p1.w));\n"
+ " float c = distance(vec2(xscale*p0.x/p0.w, yscale*p0.y/p0.w), vec2(xscale*p2.x/p2.w, yscale*p2.y/p2.w));\n"
+ " float s = (a + b + c) / 2.0;\n"
+ " float A = sqrt(s*(s-a)*(s-b)*(s-c));\n"
+ " float ha = 2.0*A/a;\n"
+ " gl_Position = p0;\n"
+ " tp = mask * ha;\n"
+ " tr = trig;\n"
+ " vec3 normal, lightDir;\n"
+ " normal = normalize(gl_NormalMatrix * gl_Normal);\n"
+ " lightDir = normalize(vec3(gl_LightSource[0].position));\n"
+ " shading = abs(dot(normal, lightDir));\n"
+ "}\n";
+
+ const char *fs_source =
+ "uniform vec4 color1, color2;\n"
+ "varying vec3 tp, tr, tmp;\n"
+ "varying float shading;\n"
+ "void main() {\n"
+ " gl_FragColor = vec4(color1.r * shading, color1.g * shading, color1.b * shading, color1.a);\n"
+ " if (tp.x < tr.x || tp.y < tr.y || tp.z < tr.z)\n"
+ " gl_FragColor = color2;\n"
+ "}\n";
+
+ GLuint vs = glCreateShader(GL_VERTEX_SHADER);
+ glShaderSource(vs, 1, (const GLchar**)&vs_source, NULL);
+ glCompileShader(vs);
+
+ GLuint fs = glCreateShader(GL_FRAGMENT_SHADER);
+ glShaderSource(fs, 1, (const GLchar**)&fs_source, NULL);
+ glCompileShader(fs);
+
+ GLuint edgeshader_prog = glCreateProgram();
+ glAttachShader(edgeshader_prog, vs);
+ glAttachShader(edgeshader_prog, fs);
+ glLinkProgram(edgeshader_prog);
+
+ shaderinfo[0] = edgeshader_prog;
+ shaderinfo[1] = glGetUniformLocation(edgeshader_prog, "color1");
+ shaderinfo[2] = glGetUniformLocation(edgeshader_prog, "color2");
+ shaderinfo[3] = glGetAttribLocation(edgeshader_prog, "trig");
+ shaderinfo[4] = glGetAttribLocation(edgeshader_prog, "pos_b");
+ shaderinfo[5] = glGetAttribLocation(edgeshader_prog, "pos_c");
+ shaderinfo[6] = glGetAttribLocation(edgeshader_prog, "mask");
+ shaderinfo[7] = glGetUniformLocation(edgeshader_prog, "xscale");
+ shaderinfo[8] = glGetUniformLocation(edgeshader_prog, "yscale");
+
+ GLenum err = glGetError();
+ if (err != GL_NO_ERROR) {
+ fprintf(stderr, "OpenGL Error: %s\n", gluErrorString(err));
+ }
+
+ GLint status;
+ glGetProgramiv(edgeshader_prog, GL_LINK_STATUS, &status);
+ if (status == GL_FALSE) {
+ int loglen;
+ char logbuffer[1000];
+ glGetProgramInfoLog(edgeshader_prog, sizeof(logbuffer), &loglen, logbuffer);
+ fprintf(stderr, "OpenGL Program Linker Error:\n%.*s", loglen, logbuffer);
+ } else {
+ int loglen;
+ char logbuffer[1000];
+ glGetProgramInfoLog(edgeshader_prog, sizeof(logbuffer), &loglen, logbuffer);
+ if (loglen > 0) {
+ fprintf(stderr, "OpenGL Program Link OK:\n%.*s", loglen, logbuffer);
+ }
+ glValidateProgram(edgeshader_prog);
+ glGetProgramInfoLog(edgeshader_prog, sizeof(logbuffer), &loglen, logbuffer);
+ if (loglen > 0) {
+ fprintf(stderr, "OpenGL Program Validation results:\n%.*s", loglen, logbuffer);
+ }
+ }
+ }
+#endif
+}
+
void OffscreenView::initializeGL()
{
glEnable(GL_DEPTH_TEST);
diff --git a/src/OffscreenView.h b/src/OffscreenView.h
index 091470c..3e03175 100644
--- a/src/OffscreenView.h
+++ b/src/OffscreenView.h
@@ -24,7 +24,7 @@ public:
bool save(const char *filename);
bool save(std::ostream &output);
std::string getRendererInfo() const;
-
+ void enable_opencsg_shaders();
OffscreenContext *ctx; // not
};
diff --git a/src/qglview.cc b/src/qglview.cc
index d689a96..0e07b52 100644
--- a/src/qglview.cc
+++ b/src/qglview.cc
@@ -107,30 +107,8 @@ void QGLView::init()
#endif
}
-void QGLView::initializeGL()
+void QGLView::enable_opencsg_shaders()
{
- glEnable(GL_DEPTH_TEST);
- glDepthRange(-FAR_FAR_AWAY, +FAR_FAR_AWAY);
-
- glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-
- GLfloat light_diffuse[] = {1.0, 1.0, 1.0, 1.0};
- GLfloat light_position0[] = {-1.0, -1.0, +1.0, 0.0};
- GLfloat light_position1[] = {+1.0, +1.0, -1.0, 0.0};
-
- glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
- glLightfv(GL_LIGHT0, GL_POSITION, light_position0);
- glEnable(GL_LIGHT0);
- glLightfv(GL_LIGHT1, GL_DIFFUSE, light_diffuse);
- glLightfv(GL_LIGHT1, GL_POSITION, light_position1);
- glEnable(GL_LIGHT1);
- glEnable(GL_LIGHTING);
- glEnable(GL_NORMALIZE);
-
- glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
- glEnable(GL_COLOR_MATERIAL);
-
#ifdef ENABLE_OPENCSG
GLenum err = glewInit();
if (GLEW_OK != err) {
@@ -279,7 +257,34 @@ void QGLView::initializeGL()
}
}
}
-#endif /* ENABLE_OPENCSG */
+#endif
+}
+
+void QGLView::initializeGL()
+{
+ glEnable(GL_DEPTH_TEST);
+ glDepthRange(-FAR_FAR_AWAY, +FAR_FAR_AWAY);
+
+ glEnable(GL_BLEND);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+
+ GLfloat light_diffuse[] = {1.0, 1.0, 1.0, 1.0};
+ GLfloat light_position0[] = {-1.0, -1.0, +1.0, 0.0};
+ GLfloat light_position1[] = {+1.0, +1.0, -1.0, 0.0};
+
+ glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
+ glLightfv(GL_LIGHT0, GL_POSITION, light_position0);
+ glEnable(GL_LIGHT0);
+ glLightfv(GL_LIGHT1, GL_DIFFUSE, light_diffuse);
+ glLightfv(GL_LIGHT1, GL_POSITION, light_position1);
+ glEnable(GL_LIGHT1);
+ glEnable(GL_LIGHTING);
+ glEnable(GL_NORMALIZE);
+
+ glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
+ glEnable(GL_COLOR_MATERIAL);
+
+ enable_opencsg_shaders();
}
std::string QGLView::getRendererInfo() const
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index d9f6c3b..e62fbfd 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -101,6 +101,7 @@ if(CMAKE_CXX_COMPILER MATCHES ".*clang.*")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-function")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-c++11-extensions")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-sign-compare")
+ string(REPLACE -frounding-math "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
endif()
#
@@ -849,8 +850,9 @@ endif()
#
add_executable(test_pretty_print test_pretty_print.cc)
+file(TO_NATIVE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/test_pretty_print.py PYSRC)
set_target_properties(test_pretty_print PROPERTIES COMPILE_FLAGS
- "-DPYBIN=${PYTHON_EXECUTABLE} -DPYSRC=test_pretty_print.py -DBUILDDIR=--builddir=${CMAKE_CURRENT_BINARY_DIR}"
+ "-DPYBIN=${PYTHON_EXECUTABLE} -DPYSRC=${PYSRC} -DBUILDDIR=--builddir=${CMAKE_CURRENT_BINARY_DIR}"
)
if (MINGW_CROSS_ENV_DIR)
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/test_pretty_print "wine test_pretty_print.exe")
diff --git a/tests/csgtestcore.cc b/tests/csgtestcore.cc
index 6d00f09..1a414d5 100644
--- a/tests/csgtestcore.cc
+++ b/tests/csgtestcore.cc
@@ -123,101 +123,8 @@ po::variables_map parse_options(int argc, char *argv[])
return vm;
}
-void enable_opencsg_shaders( OffscreenView *glview )
-{
- bool ignore_gl_version = true;
- const char *openscad_disable_gl20_env = getenv("OPENSCAD_DISABLE_GL20");
- if (openscad_disable_gl20_env && !strcmp(openscad_disable_gl20_env, "0"))
- openscad_disable_gl20_env = NULL;
- if (glewIsSupported("GL_VERSION_2_0") && openscad_disable_gl20_env == NULL )
- {
- const char *vs_source =
- "uniform float xscale, yscale;\n"
- "attribute vec3 pos_b, pos_c;\n"
- "attribute vec3 trig, mask;\n"
- "varying vec3 tp, tr;\n"
- "varying float shading;\n"
- "void main() {\n"
- " vec4 p0 = gl_ModelViewProjectionMatrix * gl_Vertex;\n"
- " vec4 p1 = gl_ModelViewProjectionMatrix * vec4(pos_b, 1.0);\n"
- " vec4 p2 = gl_ModelViewProjectionMatrix * vec4(pos_c, 1.0);\n"
- " float a = distance(vec2(xscale*p1.x/p1.w, yscale*p1.y/p1.w), vec2(xscale*p2.x/p2.w, yscale*p2.y/p2.w));\n"
- " float b = distance(vec2(xscale*p0.x/p0.w, yscale*p0.y/p0.w), vec2(xscale*p1.x/p1.w, yscale*p1.y/p1.w));\n"
- " float c = distance(vec2(xscale*p0.x/p0.w, yscale*p0.y/p0.w), vec2(xscale*p2.x/p2.w, yscale*p2.y/p2.w));\n"
- " float s = (a + b + c) / 2.0;\n"
- " float A = sqrt(s*(s-a)*(s-b)*(s-c));\n"
- " float ha = 2.0*A/a;\n"
- " gl_Position = p0;\n"
- " tp = mask * ha;\n"
- " tr = trig;\n"
- " vec3 normal, lightDir;\n"
- " normal = normalize(gl_NormalMatrix * gl_Normal);\n"
- " lightDir = normalize(vec3(gl_LightSource[0].position));\n"
- " shading = abs(dot(normal, lightDir));\n"
- "}\n";
-
- const char *fs_source =
- "uniform vec4 color1, color2;\n"
- "varying vec3 tp, tr, tmp;\n"
- "varying float shading;\n"
- "void main() {\n"
- " gl_FragColor = vec4(color1.r * shading, color1.g * shading, color1.b * shading, color1.a);\n"
- " if (tp.x < tr.x || tp.y < tr.y || tp.z < tr.z)\n"
- " gl_FragColor = color2;\n"
- "}\n";
-
- GLuint vs = glCreateShader(GL_VERTEX_SHADER);
- glShaderSource(vs, 1, (const GLchar**)&vs_source, NULL);
- glCompileShader(vs);
-
- GLuint fs = glCreateShader(GL_FRAGMENT_SHADER);
- glShaderSource(fs, 1, (const GLchar**)&fs_source, NULL);
- glCompileShader(fs);
-
- GLuint edgeshader_prog = glCreateProgram();
- glAttachShader(edgeshader_prog, vs);
- glAttachShader(edgeshader_prog, fs);
- glLinkProgram(edgeshader_prog);
-
- glview->shaderinfo[0] = edgeshader_prog;
- glview->shaderinfo[1] = glGetUniformLocation(edgeshader_prog, "color1");
- glview->shaderinfo[2] = glGetUniformLocation(edgeshader_prog, "color2");
- glview->shaderinfo[3] = glGetAttribLocation(edgeshader_prog, "trig");
- glview->shaderinfo[4] = glGetAttribLocation(edgeshader_prog, "pos_b");
- glview->shaderinfo[5] = glGetAttribLocation(edgeshader_prog, "pos_c");
- glview->shaderinfo[6] = glGetAttribLocation(edgeshader_prog, "mask");
- glview->shaderinfo[7] = glGetUniformLocation(edgeshader_prog, "xscale");
- glview->shaderinfo[8] = glGetUniformLocation(edgeshader_prog, "yscale");
-
- GLenum err = glGetError();
- if (err != GL_NO_ERROR) {
- fprintf(stderr, "OpenGL Error: %s\n", gluErrorString(err));
- }
-
- GLint status;
- glGetProgramiv(edgeshader_prog, GL_LINK_STATUS, &status);
- if (status == GL_FALSE) {
- int loglen;
- char logbuffer[1000];
- glGetProgramInfoLog(edgeshader_prog, sizeof(logbuffer), &loglen, logbuffer);
- fprintf(stderr, "OpenGL Program Linker Error:\n%.*s", loglen, logbuffer);
- } else {
- int loglen;
- char logbuffer[1000];
- glGetProgramInfoLog(edgeshader_prog, sizeof(logbuffer), &loglen, logbuffer);
- if (loglen > 0) {
- fprintf(stderr, "OpenGL Program Link OK:\n%.*s", loglen, logbuffer);
- }
- glValidateProgram(edgeshader_prog);
- glGetProgramInfoLog(edgeshader_prog, sizeof(logbuffer), &loglen, logbuffer);
- if (loglen > 0) {
- fprintf(stderr, "OpenGL Program Validation results:\n%.*s", loglen, logbuffer);
- }
- }
- }
- glview->shaderinfo[9] = glview->width;
- glview->shaderinfo[10] = glview->height;
-}
+// glview->shaderinfo[9] = glview->width;
+// glview->shaderinfo[10] = glview->height;
int csgtestcore(int argc, char *argv[], test_type_e test_type)
{
@@ -333,7 +240,7 @@ int csgtestcore(int argc, char *argv[], test_type_e test_type)
fprintf(stderr,"Can't create OpenGL OffscreenView. Code: %i. Exiting.\n", error);
exit(1);
}
- enable_opencsg_shaders(csgInfo.glview);
+ csgInfo.glview->enable_opencsg_shaders();
if (sysinfo_dump) cout << info_dump(csgInfo.glview);
Vector3d center(0,0,0);
contact: Jan Huwald // Impressum