Explorar el Código

Merge uniforms translation unit into simple_renderer

rexim hace 2 años
padre
commit
7a3fd90e09
Se han modificado 5 ficheros con 42 adiciones y 81 borrados
  1. 1 1
      build.sh
  2. 32 0
      src/simple_renderer.c
  3. 9 2
      src/simple_renderer.h
  4. 0 48
      src/uniforms.c
  5. 0 30
      src/uniforms.h

+ 1 - 1
build.sh

@@ -6,7 +6,7 @@ CC="${CXX:-cc}"
 PKGS="sdl2 glew freetype2"
 CFLAGS="-Wall -Wextra -std=c11 -pedantic -ggdb"
 LIBS=-lm
-SRC="src/main.c src/la.c src/editor.c src/sdl_extra.c src/file.c src/gl_extra.c src/free_glyph.c src/uniforms.c src/simple_renderer.c"
+SRC="src/main.c src/la.c src/editor.c src/sdl_extra.c src/file.c src/gl_extra.c src/free_glyph.c src/simple_renderer.c"
 
 if [ `uname` = "Darwin" ]; then
     CFLAGS+=" -framework OpenGL"

+ 32 - 0
src/simple_renderer.c

@@ -4,6 +4,31 @@
 #include "./simple_renderer.h"
 #include "./gl_extra.h"
 
+typedef struct {
+    Uniform_Slot slot;
+    const char *name;
+} Uniform_Def;
+
+static_assert(COUNT_UNIFORM_SLOTS == 4, "The amount of the shader uniforms have change. Please update the definition table accordingly");
+static const Uniform_Def uniform_defs[COUNT_UNIFORM_SLOTS] = {
+    [UNIFORM_SLOT_TIME] = {
+        .slot = UNIFORM_SLOT_TIME,
+        .name = "time",
+    },
+    [UNIFORM_SLOT_RESOLUTION] = {
+        .slot = UNIFORM_SLOT_RESOLUTION,
+        .name = "resolution",
+    },
+    [UNIFORM_SLOT_CAMERA_POS] = {
+        .slot = UNIFORM_SLOT_CAMERA_POS,
+        .name = "camera_pos",
+    },
+    [UNIFORM_SLOT_CAMERA_SCALE] = {
+        .slot = UNIFORM_SLOT_CAMERA_SCALE,
+        .name = "camera_scale",
+    },
+};
+
 #define UNIMPLEMENTED(...)               \
     do {                                 \
         printf("%s:%d: UNIMPLEMENTED: %s \n", __FILE__, __LINE__, __VA_ARGS__); \
@@ -11,6 +36,13 @@
     } while(0)
 #define UNUSED(x) (void)(x)
 
+static void get_uniform_location(GLuint program, GLint locations[COUNT_UNIFORM_SLOTS])
+{
+    for (Uniform_Slot slot = 0; slot < COUNT_UNIFORM_SLOTS; ++slot) {
+        locations[slot] = glGetUniformLocation(program, uniform_defs[slot].name);
+    }
+}
+
 void simple_renderer_init(Simple_Renderer *sr,
                           const char *vert_file_path,
                           const char *color_frag_file_path,

+ 9 - 2
src/simple_renderer.h

@@ -8,7 +8,14 @@
 #include <SDL2/SDL_opengl.h>
 
 #include "./la.h"
-#include "./uniforms.h"
+
+typedef enum {
+    UNIFORM_SLOT_TIME = 0,
+    UNIFORM_SLOT_RESOLUTION,
+    UNIFORM_SLOT_CAMERA_POS,
+    UNIFORM_SLOT_CAMERA_SCALE,
+    COUNT_UNIFORM_SLOTS,
+} Uniform_Slot;
 
 typedef enum {
     SIMPLE_VERTEX_ATTR_POSITION = 0,
@@ -27,7 +34,7 @@ typedef struct {
 typedef enum {
     SHADER_FOR_COLOR = 0,
     SHADER_FOR_IMAGE,
-    SHADER_FOR_EPICNESS,
+    SHADER_FOR_EPICNESS, // This is the one that does that cool rainbowish animation
     COUNT_SIMPLE_SHADERS,
 } Simple_Shader;
 

+ 0 - 48
src/uniforms.c

@@ -1,48 +0,0 @@
-#include <assert.h>
-#include "./uniforms.h"
-
-static_assert(COUNT_UNIFORM_SLOTS == 7, "The amount of the shader uniforms have change. Please update the definition table accordingly");
-static const Uniform_Def uniform_defs[COUNT_UNIFORM_SLOTS] = {
-    [UNIFORM_SLOT_TIME] = {
-        .slot = UNIFORM_SLOT_TIME,
-        .name = "time",
-    },
-    [UNIFORM_SLOT_RESOLUTION] = {
-        .slot = UNIFORM_SLOT_RESOLUTION,
-        .name = "resolution",
-    },
-    [UNIFORM_SLOT_CAMERA_POS] = {
-        .slot = UNIFORM_SLOT_CAMERA_POS,
-        .name = "camera_pos",
-    },
-    [UNIFORM_SLOT_CAMERA_SCALE] = {
-        .slot = UNIFORM_SLOT_CAMERA_SCALE,
-        .name = "camera_scale",
-    },
-    [UNIFORM_SLOT_CURSOR_POS] = {
-        .slot = UNIFORM_SLOT_CURSOR_POS,
-        .name = "cursor_pos",
-    },
-    [UNIFORM_SLOT_CURSOR_HEIGHT] = {
-        .slot = UNIFORM_SLOT_CURSOR_HEIGHT,
-        .name = "cursor_height",
-    },
-    [UNIFORM_SLOT_LAST_STROKE] = {
-        .slot = UNIFORM_SLOT_LAST_STROKE,
-        .name = "last_stroke",
-    },
-};
-
-const Uniform_Def *get_uniform_def(Uniform_Slot slot)
-{
-    assert(0 <= slot);
-    assert(slot < COUNT_UNIFORM_SLOTS);
-    return &uniform_defs[slot];
-}
-
-void get_uniform_location(GLuint program, GLint locations[COUNT_UNIFORM_SLOTS])
-{
-    for (Uniform_Slot slot = 0; slot < COUNT_UNIFORM_SLOTS; ++slot) {
-        locations[slot] = glGetUniformLocation(program, uniform_defs[slot].name);
-    }
-}

+ 0 - 30
src/uniforms.h

@@ -1,30 +0,0 @@
-#ifndef UNIFORMS_H_
-#define UNIFORMS_H_
-
-#define GLEW_STATIC
-#include <GL/glew.h>
-
-#define GL_GLEXT_PROTOTYPES
-#include <SDL2/SDL_opengl.h>
-
-typedef enum {
-    UNIFORM_SLOT_TIME = 0,
-    UNIFORM_SLOT_RESOLUTION,
-    UNIFORM_SLOT_CAMERA_POS,
-    UNIFORM_SLOT_CAMERA_SCALE,
-
-    UNIFORM_SLOT_CURSOR_POS,
-    UNIFORM_SLOT_CURSOR_HEIGHT,
-    UNIFORM_SLOT_LAST_STROKE,
-    COUNT_UNIFORM_SLOTS,
-} Uniform_Slot;
-
-typedef struct {
-    Uniform_Slot slot;
-    const char *name;
-} Uniform_Def;
-
-const Uniform_Def *get_uniform_def(Uniform_Slot slot);
-void get_uniform_location(GLuint program, GLint locations[COUNT_UNIFORM_SLOTS]);
-
-#endif // UNIFORMS_H_