diff options
Diffstat (limited to 'config.c')
-rw-r--r-- | config.c | 63 |
1 files changed, 62 insertions, 1 deletions
@@ -43,6 +43,12 @@ static bool context_is_parent(const SettingsContext *parent, const SettingsConte static void settings_copy(Settings *dest, const Settings *src) { *dest = *src; + + // we only use this function before generating these + assert(!src->bg_shader); + assert(!src->bg_buffer); + assert(!src->bg_array); + context_copy(&dest->context, &src->context); for (u32 i = 0; i < LANG_COUNT; ++i) { if (src->language_extensions[i]) @@ -59,7 +65,13 @@ static void settings_free(Settings *settings) { context_free(&settings->context); for (u32 i = 0; i < LANG_COUNT; ++i) free(settings->language_extensions[i]); - memset(settings, 0, sizeof *settings); + if (settings->bg_shader) + glDeleteProgram(settings->bg_shader); + if (settings->bg_buffer) + glDeleteBuffers(1, &settings->bg_buffer); + if (settings->bg_array) + glDeleteVertexArrays(1, &settings->bg_array); + memset(settings, 0, sizeof *settings); } static void config_part_free(ConfigPart *part) { @@ -272,6 +284,7 @@ static OptionFloat const options_float[] = { }; static OptionString const options_string[] = { {"build-default-command", options_zero.build_default_command, sizeof options_zero.build_default_command, true}, + {"bg-shader", options_zero.bg_shader_text, sizeof options_zero.bg_shader_text, true}, }; static void option_bool_set(Settings *settings, const OptionBool *opt, bool value) { @@ -861,6 +874,54 @@ void config_parse(Ted *ted, ConfigPart **pparts) { } } + arr_foreach_ptr(ted->all_settings, Settings, s) { + if (*s->bg_shader_text) { + // load bg shader + char vshader[] = "#version 110\n\ + attribute vec2 v_pos;\n\ + varying vec2 t_pos;\n\ + void main() { \n\ + gl_Position = vec4(v_pos * 2.0 - 1.0, 0.0, 1.0);\n\ + t_pos = v_pos;\n\ + }"; + char fshader[8192]; + strbuf_printf(fshader, "#version 110\n\ + varying vec2 t_pos;\n\ + uniform float t_time;\n\ + uniform float t_save_time;\n\ + uniform vec2 t_aspect;\n\ + #line 1\n\ + %s", settings->bg_shader_text); + s->bg_shader = gl_compile_and_link_shaders(ted->error, vshader, fshader); + if (s->bg_shader) { + GLuint bg_buffer = 0, bg_array = 0; + glGenBuffers(1, &bg_buffer); + if (gl_version_major >= 3) { + glGenVertexArrays(1, &bg_array); + glBindVertexArray(bg_array); + } + + s->bg_buffer = bg_buffer; + s->bg_array = bg_array; + + float bg_buffer_data[][2] = { + {0,0}, + {1,0}, + {1,1}, + {0,0}, + {1,1}, + {0,1} + }; + + GLuint v_pos = (GLuint)glGetAttribLocation(s->bg_shader, "v_pos"); + glBindBuffer(GL_ARRAY_BUFFER, bg_buffer); + glBufferData(GL_ARRAY_BUFFER, sizeof bg_buffer_data, bg_buffer_data, GL_STATIC_DRAW); + glVertexAttribPointer(v_pos, 2, GL_FLOAT, 0, 2 * sizeof(float), 0); + glEnableVertexAttribArray(v_pos); + } + } + } + arr_foreach_ptr(parts, ConfigPart, part) { config_part_free(part); } |