Moved #version definition to c code and added config option for enabling/disabling vsync

dev
Shariq Shah 6 years ago
parent 6a2bb7e3c4
commit 3b5a8aecd3
  1. 2
      assets/shaders/blinn_phong.frag
  2. 2
      assets/shaders/blinn_phong.vert
  3. 2
      assets/shaders/debug.frag
  4. 2
      assets/shaders/debug.vert
  5. 2
      assets/shaders/deferred_light.frag
  6. 2
      assets/shaders/deferred_light.vert
  7. 2
      assets/shaders/fbo.frag
  8. 2
      assets/shaders/fbo.vert
  9. 2
      assets/shaders/gui.frag
  10. 2
      assets/shaders/gui.vert
  11. 2
      assets/shaders/im_geom.frag
  12. 2
      assets/shaders/im_geom.vert
  13. 2
      assets/shaders/phong.frag
  14. 2
      assets/shaders/phong.vert
  15. 2
      assets/shaders/phongTextured.frag
  16. 2
      assets/shaders/quad.frag
  17. 2
      assets/shaders/quad.vert
  18. 2
      assets/shaders/simple.frag
  19. 2
      assets/shaders/simple.vert
  20. 2
      assets/shaders/sprite.frag
  21. 2
      assets/shaders/sprite.vert
  22. 2
      assets/shaders/unshaded.frag
  23. 2
      assets/shaders/unshaded.vert
  24. 2
      assets/shaders/unshaded_textured.frag
  25. 2
      assets/shaders/unshaded_textured.vert
  26. 1
      assets/shaders/version.glsl
  27. 19
      src/game/shader.c
  28. 1
      src/system/config_vars.c
  29. 11
      src/system/main.c
  30. 5
      src/system/platform.c
  31. 2
      src/system/platform.h
  32. 6
      todo.txt

@ -1,4 +1,4 @@
//include fog.glsl common.glsl commonFrag.glsl version.glsl //include fog.glsl common.glsl commonFrag.glsl
struct Light struct Light
{ {

@ -1,4 +1,4 @@
//include commonVert.glsl version.glsl //include commonVert.glsl
void main() void main()
{ {

@ -1,5 +1,3 @@
//include version.glsl
uniform vec4 debug_color; uniform vec4 debug_color;
out vec4 frag_color; out vec4 frag_color;

@ -1,5 +1,3 @@
//include version.glsl
uniform mat4 mvp; uniform mat4 mvp;
in vec3 vPosition; in vec3 vPosition;

@ -1,5 +1,3 @@
//include version.glsl
in vec2 uv; in vec2 uv;
out vec4 frag_color; out vec4 frag_color;

@ -1,5 +1,3 @@
//include version.glsl
in vec2 vPosition; in vec2 vPosition;
in vec2 vUV; in vec2 vUV;

@ -1,5 +1,3 @@
//include version.glsl
in vec2 uv; in vec2 uv;
out vec4 frag_color; out vec4 frag_color;

@ -1,5 +1,3 @@
//include version.glsl
in vec2 vPosition; in vec2 vPosition;
in vec2 vUV; in vec2 vUV;

@ -1,5 +1,3 @@
//include version.glsl
in vec2 uv; in vec2 uv;
in vec4 color; in vec4 color;

@ -1,5 +1,3 @@
//include version.glsl
uniform mat4 proj_mat; uniform mat4 proj_mat;
in vec2 vPosition; in vec2 vPosition;

@ -1,5 +1,3 @@
//include version.glsl
uniform vec4 geom_color; uniform vec4 geom_color;
out vec4 frag_color; out vec4 frag_color;

@ -1,5 +1,3 @@
//include version.glsl
uniform mat4 mvp; uniform mat4 mvp;
in vec3 vPosition; in vec3 vPosition;

@ -1,4 +1,4 @@
//include fog.glsl phongCommon.glsl common.glsl commonFrag.glsl version.glsl //include fog.glsl phongCommon.glsl common.glsl commonFrag.glsl
void main() void main()
{ {

@ -1,4 +1,4 @@
//include commonVert.glsl version.glsl //include commonVert.glsl
void main() void main()
{ {

@ -1,4 +1,4 @@
//include fog.glsl phongCommon.glsl common.glsl commonFrag.glsl version.glsl //include fog.glsl phongCommon.glsl common.glsl commonFrag.glsl
uniform sampler2D sampler; uniform sampler2D sampler;

@ -1,5 +1,3 @@
#version 130
in vec2 uv; in vec2 uv;
out vec4 fragColor; out vec4 fragColor;

@ -1,5 +1,3 @@
#version 130
in vec2 vPosition; in vec2 vPosition;
in vec2 vUV; in vec2 vUV;

@ -1,5 +1,3 @@
#version 130
uniform sampler2D sampler; uniform sampler2D sampler;
in vec2 uv; in vec2 uv;

@ -1,5 +1,3 @@
#version 130
in vec3 vPosition; in vec3 vPosition;
in vec2 vUV; in vec2 vUV;

@ -1,5 +1,3 @@
//include version.glsl
in vec2 uv; in vec2 uv;
in vec4 color; in vec4 color;

@ -1,5 +1,3 @@
//include version.glsl
uniform mat4 mvp; uniform mat4 mvp;
in vec2 vPosition; in vec2 vPosition;

@ -1,4 +1,4 @@
//include fog.glsl common.glsl commonFrag.glsl version.glsl //include fog.glsl common.glsl commonFrag.glsl
uniform sampler2D diffuse_texture; uniform sampler2D diffuse_texture;

@ -1,4 +1,4 @@
//include commonVert.glsl version.glsl //include commonVert.glsl
void main() void main()
{ {

@ -1,4 +1,4 @@
//include fog.glsl commonFrag.glsl common.glsl version.glsl //include fog.glsl commonFrag.glsl common.glsl
uniform sampler2D sampler; uniform sampler2D sampler;

@ -1,4 +1,4 @@
//include commonVert.glsl version.glsl //include commonVert.glsl
void main() void main()
{ {

@ -13,10 +13,11 @@
#include <string.h> #include <string.h>
#include <assert.h> #include <assert.h>
#define MAX_INCLUDE_LINE_LEN 256
static uint* shader_list; static uint* shader_list;
static int* empty_indices; static int* empty_indices;
static const char* GLSL_VERSION_STR = "#version 330\n";
#define MAX_INCLUDE_LINE_LEN 256
void debug_print_shader(const char* shaderText) void debug_print_shader(const char* shaderText)
{ {
@ -93,17 +94,11 @@ int shader_create(const char* vert_shader_name, const char* frag_shader_name)
vert_source = run_preprocessor(vert_source); vert_source = run_preprocessor(vert_source);
frag_source = run_preprocessor(frag_source); frag_source = run_preprocessor(frag_source);
GLint v_size = (GLint)strlen(vert_source); const char* vert_sourcePtr[2] = { GLSL_VERSION_STR, vert_source };
GLint f_size = (GLint)strlen(frag_source); const char* frag_sourcePtr[2] = { GLSL_VERSION_STR, frag_source };
const char* vert_sourcePtr = vert_source;
const char* frag_sourcePtr = frag_source;
const GLint* vert_size = &v_size;
const GLint* frag_size = &f_size;
GL_CHECK(glShaderSource(vert_shader, 1, &vert_sourcePtr, vert_size)); GL_CHECK(glShaderSource(vert_shader, 2, &vert_sourcePtr, NULL));
GL_CHECK(glShaderSource(frag_shader, 1, &frag_sourcePtr, frag_size)); GL_CHECK(glShaderSource(frag_shader, 2, &frag_sourcePtr, NULL));
GL_CHECK(glCompileShader(vert_shader)); GL_CHECK(glCompileShader(vert_shader));
GL_CHECK(glCompileShader(frag_shader)); GL_CHECK(glCompileShader(frag_shader));

@ -15,6 +15,7 @@ void config_vars_init(struct Hashmap* cvars)
/* Initialize with default values incase there is no config file */ /* Initialize with default values incase there is no config file */
hashmap_int_set(cvars, "render_width", 1280); hashmap_int_set(cvars, "render_width", 1280);
hashmap_int_set(cvars, "render_height", 720); hashmap_int_set(cvars, "render_height", 720);
hashmap_bool_set(cvars, "vsync_enabled", true);
hashmap_int_set(cvars, "fog_mode", 0); hashmap_int_set(cvars, "fog_mode", 0);
hashmap_vec3_setf(cvars, "fog_color", 0.9f, 0.2f, 0.2f); hashmap_vec3_setf(cvars, "fog_color", 0.9f, 0.2f, 0.2f);
hashmap_float_set(cvars, "fog_density", 0.1f); hashmap_float_set(cvars, "fog_density", 0.1f);

@ -76,11 +76,12 @@ bool init(void)
return false; return false;
} }
int width = hashmap_int_get(cvars, "render_width"); int width = hashmap_int_get(cvars, "render_width");
int height = hashmap_int_get(cvars, "render_height"); int height = hashmap_int_get(cvars, "render_height");
int msaa = hashmap_bool_get(cvars, "msaa_enabled"); int msaa = hashmap_bool_get(cvars, "msaa_enabled");
int msaa_levels = hashmap_int_get(cvars, "msaa_levels"); int msaa_levels = hashmap_int_get(cvars, "msaa_levels");
window = window_create("Symmetry", width, height, msaa, msaa_levels); bool vsync = hashmap_bool_get(cvars, "vsync_enabled");
window = window_create("Symmetry", width, height, msaa, msaa_levels, vsync);
if(!window) if(!window)
{ {
log_error("main:init", "Window creation failed"); log_error("main:init", "Window creation failed");

@ -18,7 +18,7 @@ struct Window
bool is_fullscreen; bool is_fullscreen;
}; };
struct Window* window_create(const char* title, int width, int height, int msaa, int msaa_levels) struct Window* window_create(const char* title, int width, int height, int msaa, int msaa_levels, bool vsync)
{ {
struct Window* new_window = NULL; struct Window* new_window = NULL;
if(!new_window) if(!new_window)
@ -83,7 +83,8 @@ struct Window* window_create(const char* title, int width, int height, int msaa,
SDL_Window* current_window = SDL_GL_GetCurrentWindow(); SDL_Window* current_window = SDL_GL_GetCurrentWindow();
SDL_GLContext current_context = SDL_GL_GetCurrentContext(); SDL_GLContext current_context = SDL_GL_GetCurrentContext();
SDL_GL_MakeCurrent((SDL_Window*)new_window->sdl_window, new_window->gl_context); SDL_GL_MakeCurrent((SDL_Window*)new_window->sdl_window, new_window->gl_context);
SDL_GL_SetSwapInterval(0); /* 0: Vsync disabled, 1: Vsync enabled*/
SDL_GL_SetSwapInterval(vsync ? 1 : 0); /* 0: Vsync disabled, 1: Vsync enabled*/
if(current_window && current_context) SDL_GL_MakeCurrent(current_window, current_context); if(current_window && current_context) SDL_GL_MakeCurrent(current_window, current_context);
int major = 0, minor = 0; int major = 0, minor = 0;

@ -14,7 +14,7 @@ enum Video_Drivers_Linux
// Window Related functions // Window Related functions
struct Window; struct Window;
struct Window* window_create(const char* title, int width, int height, int msaa, int msaa_levels); struct Window* window_create(const char* title, int width, int height, int msaa, int msaa_levels, bool vsync);
void window_destroy(struct Window* window); void window_destroy(struct Window* window);
void window_show(struct Window* window); void window_show(struct Window* window);
void window_hide(struct Window* window); void window_hide(struct Window* window);

@ -1,4 +1,7 @@
Todo: Todo:
- Move MAX_LIGHTS shader definition from inside the shader to be dynamically defined and added to the shader code when it is compiled
to reduce inconsistencies
- Fix bug with blinn shader reaching maximum uniform number on mac
- Fix Deployment target issue in xcode build on macos - Fix Deployment target issue in xcode build on macos
- Implement/Fix copying libraries to executable folder after build completes on mac os - Implement/Fix copying libraries to executable folder after build completes on mac os
- Fix symlink issue in genie for macos which interferes with fopen operations - Fix symlink issue in genie for macos which interferes with fopen operations
@ -116,6 +119,7 @@ Bugs:
- Fix hang on fullscreen toggle - Fix hang on fullscreen toggle
- Fix axis lines not aligning with grid lines - Fix axis lines not aligning with grid lines
- Fix arc angles resetting when rotating - Fix arc angles resetting when rotating
- Fix shader preprocessor failing when the file in //include directive is empty
Done: Done:
* Input * Input
@ -310,4 +314,4 @@ Done:
* Added editor shortcut key to delete selected entity * Added editor shortcut key to delete selected entity
* Console command to read/write entity to file and add it to scene * Console command to read/write entity to file and add it to scene
* Fix editor camera right-click behaviour * Fix editor camera right-click behaviour
* Moved #version definition from shaders to c code for easier control

Loading…
Cancel
Save