From: Michel Pollet Date: Sat, 2 Jun 2012 12:32:11 +0000 (+0100) Subject: reprap: Compatibility with OSX X-Git-Url: http://git.rot13.org/?a=commitdiff_plain;ds=sidebyside;h=47a131708adafd4eba74038fd981baab91c1ff40;p=simavr reprap: Compatibility with OSX The shader now works on both platform Removed the .bin file, made sure it never happends again Signed-off-by: Michel Pollet --- diff --git a/examples/board_reprap/.gitignore b/examples/board_reprap/.gitignore new file mode 100644 index 0000000..a8a0dce --- /dev/null +++ b/examples/board_reprap/.gitignore @@ -0,0 +1 @@ +*.bin diff --git a/examples/board_reprap/Makefile b/examples/board_reprap/Makefile index 50b4e3b..51fd468 100644 --- a/examples/board_reprap/Makefile +++ b/examples/board_reprap/Makefile @@ -72,4 +72,6 @@ ${target}: build-libc3 ${board} clean: clean-${OBJ} rm -rf *.a *.axf ${target} *.vcd + $(MAKE) -C $(LIBC3) CC="$(CC)" CFLAGS="$(CFLAGS)" clean + diff --git a/examples/board_reprap/gfx/postproc.fs b/examples/board_reprap/gfx/postproc.fs index 49de3fd..f74ab7c 100644 --- a/examples/board_reprap/gfx/postproc.fs +++ b/examples/board_reprap/gfx/postproc.fs @@ -1,11 +1,12 @@ -#version 120 + +#if (GLSL_VERSION == 120) +#extension GL_EXT_gpu_shader4 : enable +#endif // References: // http://www.geeks3d.com/20110405/fxaa-fast-approximate-anti-aliasing-demo-glsl-opengl-test-radeon-geforce/3/ // http://jmonkeyengine.googlecode.com/svn-history/r9095/trunk/engine/src/core-data/Common/MatDefs/Post/ -#extension GL_EXT_gpu_shader4 : enable - uniform sampler2D m_Texture; uniform vec2 g_Resolution = vec2(800,600); @@ -17,9 +18,13 @@ varying vec2 texCoord; varying vec4 posPos; #define FxaaTex(t, p) texture2D(t, p) - - #define OffsetVec(a, b) ivec2(a, b) +#define OffsetVec(a, b) ivec2(a, b) +#if (GLSL_VERSION == 120) #define FxaaTexOff(t, p, o, r) texture2DLodOffset(t, p, 0.0, o) +#endif +#if (GLSL_VERSION == 130) + #define FxaaTexOff(t, p, o, r) textureLodOffset(t, p, 0.0, o) +#endif vec3 FxaaPixelShader( vec4 posPos, // Output of FxaaVertexShader interpolated across screen. diff --git a/examples/board_reprap/gfx/postproc.vs b/examples/board_reprap/gfx/postproc.vs index 1031ee1..fb69cfd 100644 --- a/examples/board_reprap/gfx/postproc.vs +++ b/examples/board_reprap/gfx/postproc.vs @@ -1,4 +1,4 @@ -#version 120 + //uniform mat4 g_WorldViewProjectionMatrix; uniform vec2 g_Resolution = vec2(800,600); uniform float m_SubPixelShift = 1.0 / 4.0; diff --git a/examples/board_reprap/reprap_flash.bin b/examples/board_reprap/reprap_flash.bin deleted file mode 100644 index c97c12f..0000000 Binary files a/examples/board_reprap/reprap_flash.bin and /dev/null differ diff --git a/examples/board_reprap/src/reprap_gl.c b/examples/board_reprap/src/reprap_gl.c index 1d66cbd..48e43ca 100644 --- a/examples/board_reprap/src/reprap_gl.c +++ b/examples/board_reprap/src/reprap_gl.c @@ -52,9 +52,10 @@ int _w = 800, _h = 600; c3context_p c3; c3context_p hud; c3object_p head; - c3texture_p fbo_c3; +int glsl_version = 110; + extern reprap_t reprap; static int dumpError(const char * what) @@ -187,9 +188,17 @@ static GLuint create_shader(const char * fname, GLuint pid) fseek(f, 0, SEEK_END); long fs = ftell(f); fseek(f, 0, SEEK_SET); - buf = malloc(fs + 1); - fread((void*)buf, 1, fs, f); - ((char*)buf)[fs] = 0; + /* + * need to insert a header since there is nothing to detect the version number + * reliably without it, and __VERSION__ returns idiocy + */ + char head[128]; + sprintf(head, "#version %d\n#define GLSL_VERSION %d\n", glsl_version, glsl_version); + const int header = strlen(head); + buf = malloc(header + fs + 1); + memcpy((void*)buf, head, header); + fread((void*)buf + header, 1, fs, f); + ((char*)buf)[header + fs] = 0; fclose(f); GLuint vs = glCreateShader(pid); @@ -463,21 +472,20 @@ _c3_z_sorter( return d1 < d2 ? 1 : d1 > d2 ? -1 : 0; } -#define FBO 0 +#define FBO 1 static void _gl_display_cb(void) /* function called whenever redisplay needed */ { #if FBO - if (program_postproc) { - /* - * Draw in FBO object - */ - glBindFramebuffer(GL_FRAMEBUFFER, fbo); - // draw (without glutSwapBuffers) - dumpError("glBindFramebuffer fbo"); - glViewport(0, 0, _w, _h); - } + /* + * Draw in FBO object + */ + glBindFramebuffer(GL_FRAMEBUFFER, fbo); + // draw (without glutSwapBuffers) + dumpError("glBindFramebuffer fbo"); + glViewport(0, 0, _w, _h); + #else glBindFramebuffer(GL_FRAMEBUFFER, 0); #endif @@ -490,7 +498,7 @@ _gl_display_cb(void) /* function called whenever redisplay needed */ c3transform_set(head->transform.e[0], &headmove); if (c3->root->dirty) { - printf("reproject head %.2f,%.2f,%.2f\n", headp.x, headp.y,headp.z); + // printf("reproject head %.2f,%.2f,%.2f\n", headp.x, headp.y,headp.z); c3context_project(c3); z_min = 1000000000; @@ -548,31 +556,14 @@ _gl_display_cb(void) /* function called whenever redisplay needed */ glBindFramebuffer(GL_FRAMEBUFFER, 0); dumpError("glBindFramebuffer 0"); + glClearColor(1.0f, 1.0f, 1.0f, 1.0f); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); +#endif glDisable(GL_DEPTH_TEST); glDisable(GL_LIGHTING); glDisable(GL_ALPHA_TEST); - glMatrixMode(GL_PROJECTION); // Select projection matrix - glLoadIdentity(); // Start with an identity matrix - - glClearColor(1.0f, 1.0f, 1.0f, 0.0f); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - - glMatrixMode(GL_MODELVIEW); // Select modelview matrix - glLoadIdentity(); // Start with an identity matrix - -#if 0 - glEnable(GL_TEXTURE_2D); - glBindTexture(GL_TEXTURE_2D, fbo_texture); - dumpError("glBindTexture fbo"); -#if 0 - glUseProgram(program_postproc); - dumpError("glUseProgram program_postproc"); - glUniform1i(uniform_fbo_texture, /*GL_TEXTURE*/0); -#endif glUseProgram(0); -#endif -#endif glMatrixMode(GL_PROJECTION); // Select projection matrix glLoadIdentity(); // Start with an identity matrix @@ -636,10 +627,6 @@ _gl_motion_cb( switch (button) { case GLUT_LEFT_BUTTON: { - -// c3mat4 rotx = rotation3D(c3vec3f(1.0, 0, 0), delta.n[1] / 4); -// c3mat4 roty = rotation3D(c3vec3f(0.0, 0.0, 1.0), delta.n[0] / 4); - c3mat4 rotx = rotation3D(c3->cam.side, delta.n[1] / 4); c3mat4 roty = rotation3D(c3vec3f(0.0, 0.0, 1.0), delta.n[0] / 4); rotx = c3mat4_mul(&rotx, &roty); @@ -703,10 +690,8 @@ gl_init( // set material properties which will be assigned by glColor glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE); - + /* setup some lights */ glShadeModel(GL_SMOOTH); -#if 1 -// glEnable(GL_DEPTH_TEST); glEnable(GL_LIGHTING); GLfloat global_ambient[] = { 0.5f, 0.5f, 0.5f, 1.0f }; glLightModelfv(GL_LIGHT_MODEL_AMBIENT, global_ambient); @@ -725,7 +710,19 @@ gl_init( glLightfv(GL_LIGHT0, GL_POSITION, position); glEnable(GL_LIGHT0); } -#endif + + /* + * Extract the GLSL version as a nuneric value for later + */ + const char * glsl = (const char *)glGetString(GL_SHADING_LANGUAGE_VERSION); + { + int M = 0, m = 0; + if (sscanf(glsl, "%d.%d", &M, &m) == 2) + glsl_version = (M * 100) + m; + + } + printf("GL_SHADING_LANGUAGE_VERSION %s = %d\n", glsl, glsl_version); + gl_offscreenInit(_w, _h); gl_ppProgram(); @@ -865,7 +862,7 @@ gl_init( /* * This is the offscreen framebuffer where the 3D scene is drawn */ - if (program_postproc) { + if (FBO) { c3texture_p b = c3texture_new(hud->root); c3pixels_p dst = c3pixels_new(_w, _h, 4, _w * 4, NULL); diff --git a/examples/shared/libc3/Makefile b/examples/shared/libc3/Makefile index 25ab1db..7f4320f 100644 --- a/examples/shared/libc3/Makefile +++ b/examples/shared/libc3/Makefile @@ -14,9 +14,15 @@ C3OBJ = ${patsubst src/%,${OBJ}/%,${C3SRC:.c=.lo}} CC = clang PKGCONFIG = pkg-config -LIBTOOL = libtool INSTALL = install +ifeq (${shell uname}, Darwin) +# you need to install libtool via 'brew install libtool' on the mac +LIBTOOL = glibtool +else +LIBTOOL = libtool +endif + CFLAGS = -g -O2 CPPFLAGS += --std=gnu99 -fPIC CPPFLAGS += ${patsubst %,-I%,${subst :, ,${IPATH}}} diff --git a/examples/shared/libc3/src/c3cairo.c b/examples/shared/libc3/src/c3cairo.c index 390a5c3..a2b1655 100644 --- a/examples/shared/libc3/src/c3cairo.c +++ b/examples/shared/libc3/src/c3cairo.c @@ -52,8 +52,8 @@ const c3driver_geometry_t c3cairo_base_driver = { .dispose = _c3cairo_dispose, .project = _c3cairo_project, }; -const c3driver_geometry_t c3texture_driver; -const c3driver_geometry_t c3geometry_driver; +extern const c3driver_geometry_t c3texture_driver; +extern const c3driver_geometry_t c3geometry_driver; c3cairo_p c3cairo_new( diff --git a/examples/shared/libc3/src/c3texture.c b/examples/shared/libc3/src/c3texture.c index 9d9d427..78a8d20 100644 --- a/examples/shared/libc3/src/c3texture.c +++ b/examples/shared/libc3/src/c3texture.c @@ -75,7 +75,7 @@ const c3driver_geometry_t c3texture_driver = { .dispose = _c3texture_dispose, .project = _c3texture_project, }; -const c3driver_geometry_t c3geometry_driver; +extern const c3driver_geometry_t c3geometry_driver; c3texture_p c3texture_new(