Commit 21205cf046922476737bb97feacd33bbabe01132
authorMichel Pollet <buserror@gmail.com>
Sun, 3 Jun 2012 16:25:41 +0000 (17:25 +0100)
committerMichel Pollet <buserror@gmail.com>
Sun, 3 Jun 2012 16:25:41 +0000 (17:25 +0100)
Minor update

Signed-off-by: Michel Pollet <buserror@gmail.com>
4 files changed:
examples/board_reprap/src/reprap_gl.c
examples/shared/libc3/src/c3camera.c
examples/shared/libc3/src/c3program.c
examples/shared/libc3/src/c3program.h

index 12a6cdcd22e36adb08606da5495fd5eb01593d17..08435d1141355a537e71c4de74167c29691bad4e 100644 (file)
 
 #include <cairo/cairo.h>
 
+#define FBO 1
+
 struct cairo_surface_t;
 
 int _w = 800, _h = 600;
-//c3cam cam;
-c3context_p c3;
-c3context_p hud;
-c3object_p head;
-c3texture_p fbo_c3;
-c3program_p fxaa = NULL;
+
+c3context_p c3 = NULL;
+c3context_p hud = NULL;
+
+c3object_p head = NULL;        // hotend
+c3texture_p fbo_c3;                    // frame buffer object texture
+c3program_p fxaa = NULL;       // full screen antialias shader
 
 int glsl_version = 110;
 
@@ -262,6 +265,7 @@ _c3_load_program(
     for (int pi = 0; pi < p->params.count; pi++) {
        c3program_param_p pa = &p->params.e[pi];
        pa->pid = glGetUniformLocation(p->pid, pa->name->str);
+       printf("%s %s load parameter '%s'\n", __func__, p->name->str, pa->name->str);
        if (pa->pid == -1) {
                fprintf(stderr, "%s %s: parameter '%s' not found\n",
                                __func__, p->name->str, pa->name->str);
@@ -418,8 +422,6 @@ const c3driver_context_t c3context_driver = {
                .geometry_draw = _c3_geometry_draw,
 };
 
-#define FBO 1
-
 static void
 _gl_display_cb(void)           /* function called whenever redisplay needed */
 {
index 29f98444591a94a27d7da232f258c6a8863e4786..64abd60be2157afaf792e50901e2d4e116ab626c 100644 (file)
@@ -20,7 +20,7 @@
        along with simavr.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-
+#include <string.h>
 #include "c3camera.h"
 
 
@@ -376,7 +376,7 @@ void
 c3cam_init(
                c3cam_p c)
 {
-       c3cam_reset(&c);
+       c3cam_reset(c);
 }
 
 void
index c91acf11088a0cd443d2d7856be738870be2fbc9..e7c7998932b12f87bd09eca80c23c7a931cbec9d 100644 (file)
@@ -24,6 +24,7 @@
 #include <unistd.h>
 #include <stdio.h>
 #include <errno.h>
+#include <ctype.h>
 #include <fcntl.h>
 
 #include "c3program.h"
@@ -40,16 +41,29 @@ c3program_new(
 
 void
 c3program_dispose(
-               const char * name)
+               c3program_p p)
 {
-       // TODO: implement c3program_dispose
+       c3program_purge(p);
+       for (int pi = 0; pi < p->params.count; pi++) {
+               c3program_param_p pa = &p->params.e[pi];
+               str_free(pa->name);
+       }
+       c3program_param_array_free(&p->params);
+       str_free(p->name);
+       str_free(p->log);
+       free(p);
 }
 
 void
 c3program_purge(
                c3program_p p)
 {
-       // TODO: implement c3program_purge
+       for (int si = 0; si < p->shaders.count; si++) {
+               c3shader_p s = &p->shaders.e[si];
+               str_free(s->name);
+               str_free(s->shader);
+       }
+       c3shader_array_free(&p->shaders);
 }
 
 int
@@ -108,6 +122,11 @@ c3program_load_shader(
                         * found a parameter, extract it's type & name
                         */
                        if (uniform && unitype && uniname) {
+                               // trim semicolons etc
+                               char *cl = uniname;
+                               while (isalpha(*cl) || *cl == '_')
+                                       cl++;
+                               *cl = 0;
                                str_p name = str_new(uniname);
                                for (int pi = 0; pi < p->params.count && uniform; pi++)
                                        if (!str_cmp(name, p->params.e[pi].name))
@@ -116,6 +135,7 @@ c3program_load_shader(
                                        c3program_param_t pa = {
                                                        .type = str_new(unitype),
                                                        .name = name,
+                                                       .program = p,
                                        };
                                        c3program_param_array_add(&p->params, pa);
                                        printf("%s %s: new parameter '%s' '%s'\n", __func__,
index c7095801d2127917ad2f783176445af2d126f17d..dfc6060cd8cc0a328b06fe04b35074fc9f763151 100644 (file)
@@ -30,12 +30,12 @@ typedef struct c3shader_t {
        uint32_t type;
        str_p   name;
        str_p   shader;
-       str_p   log;
 } c3shader_t, *c3shader_p;
 
 DECLARE_C_ARRAY(c3shader_t, c3shader_array, 4);
 
 typedef struct c3program_param_t {
+       struct c3program_t * program;
        int32_t pid;    // parameter id
        str_p   type;
        str_p   name;
@@ -53,14 +53,17 @@ typedef struct c3program_t {
 
 DECLARE_C_ARRAY(c3program_p, c3program_array, 4);
 
+//! Allocates a new, empty program
 c3program_p
 c3program_new(
                const char * name);
 
+//! disposes of a c3program memory
 void
 c3program_dispose(
-               const char * name);
+               c3program_p p);
 
+//! purge deletes the shader storage, but keep the program and parameters
 void
 c3program_purge(
                c3program_p p);