diff --git a/glsl_ext.c b/glsl_ext.c index 7fa193d..5a5d3b9 100644 --- a/glsl_ext.c +++ b/glsl_ext.c @@ -203,14 +203,18 @@ static struct schar directive(struct glsl_ext* ext, char** args, .cfd = ext->cfd, .dd = ext->dd, .handlers = ext->handlers, - .binds = ext->binds + .binds = ext->binds, + .ss_lookup = ext->ss_lookup, + .ss_len = ext->ss_len }; /* recursively process */ ext_process(&next, target); inherit(ext, &next); munmap(map, st.st_size); - + + ext->ss_lookup = next.ss_lookup; + struct schar ret = { .buf = next.processed, .sz = next.p_len @@ -302,6 +306,17 @@ void ext_process(struct glsl_ext* ext, const char* f) { ext->destruct = malloc(1); ext->destruct_sz = 0; + + if (!ext->ss_lookup) { + ext->ss_lookup = malloc(sizeof(ext->ss_lookup[0])); + ext->ss_len_s = 0; + ext->ss_len = &ext->ss_len_s; + ext->ss_own = true; + } else ext->ss_own = false; + + ext->ss_lookup = realloc(ext->ss_lookup, sizeof(ext->ss_lookup[0]) * ++(*ext->ss_len)); + int ss_cur = *ext->ss_len - 1; + ext->ss_lookup[ss_cur] = strdup(f); struct sbuf sbuf = { .buf = malloc(256), @@ -324,7 +339,9 @@ void ext_process(struct glsl_ext* ext, const char* f) { bool prev_slash = false, comment = false, comment_line = false, prev_asterix = false, prev_escape = false, string = false; - + + se_append(&sbuf, 32, "#line 1 %d\n", ss_cur); + for (t = 0; t <= source_len; ++t) { at = source_len == t ? '\0' : ext->source[t]; if (at == '\n') @@ -605,6 +622,7 @@ void ext_process(struct glsl_ext* ext, const char* f) { if (r.buf) { n_append(&sbuf, r.sz, r.buf); append(&sbuf, "\n"); + se_append(&sbuf, 48, "#line %d %d\n", line, ss_cur); } if (state == DEFINE) skip_macro(); else state = LINE_START; @@ -651,10 +669,14 @@ void ext_process(struct glsl_ext* ext, const char* f) { } void ext_free(struct glsl_ext* ext) { - free(ext->processed); size_t t; - for (t = 0; t < ext->destruct_sz; ++t) { - free(ext->destruct[t]); + free(ext->processed); + if (ext->ss_own) { + for (t = 0; t < ext->ss_len_s; ++t) + free(ext->ss_lookup[t]); + free(ext->ss_lookup); } + for (t = 0; t < ext->destruct_sz; ++t) + free(ext->destruct[t]); free(ext->destruct); } diff --git a/glsl_ext.h b/glsl_ext.h index 5b2e443..ae555eb 100644 --- a/glsl_ext.h +++ b/glsl_ext.h @@ -31,6 +31,10 @@ struct glsl_ext { struct rd_bind* binds; /* OPT IN: --pipe binds */ void** destruct; /* internal */ size_t destruct_sz; /* internal */ + char** ss_lookup; /* source-string lookup table */ + size_t* ss_len; + size_t ss_len_s; + bool ss_own; /* IN: NULL (where the last element's 'name' member is NULL) terminated array of request handlers */ diff --git a/render.c b/render.c index b3e9fa6..30961f5 100644 --- a/render.c +++ b/render.c @@ -212,7 +212,7 @@ static GLuint shaderload(const char* rpath, bind_header[0] = '\0'; size_t bh_idx = 0; - const char* fmt = "uniform %s __IN_%s;\n"; + const char* fmt = "uniform %s _IN_%s;\n"; for (struct rd_bind* bd = gl->binds; bd->name != NULL; ++bd) { size_t inc = snprintf(NULL, 0, fmt, bd->stype, bd->name); @@ -223,11 +223,11 @@ static GLuint shaderload(const char* rpath, static const GLchar* header_fmt = "#version %d\n" - "#define __UNIFORM_LIMIT %d\n" - "#define __PRE_SMOOTHED_AUDIO %d\n" - "#define __SMOOTH_FACTOR %.6f\n" - "#define __USE_ALPHA %d\n" - "#define __PREMULTIPLY_ALPHA %d\n" + "#define _UNIFORM_LIMIT %d\n" + "#define _PRE_SMOOTHED_AUDIO %d\n" + "#define _SMOOTH_FACTOR %.6f\n" + "#define _USE_ALPHA %d\n" + "#define _PREMULTIPLY_ALPHA %d\n" "#define USE_STDIN %d\n" "#if USE_STDIN == 1\n" "uniform %s STDIN;\n" @@ -297,7 +297,32 @@ static GLuint shaderload(const char* rpath, } fprintf(stderr, "Shader compilation failed for '%s':\n", path); - fwrite(ebuf, sizeof(GLchar), ilen - 1, stderr); + int ln_start = 0, col_start = 0; + for (int i = 0; i < ilen; ++i) { + switch (ebuf[i]) { + newline: + case '\n': { + int ret = -1, sz = (i - ln_start) + 1; + char fmt[] = { '%', '0' + (sz > 9 ? 9 : sz), 'd', '\0' }; + if (ext.ss_lookup && sscanf(ebuf + ln_start, fmt, &ret) > 0) { + fprintf(stderr, "\"%s\":", ext.ss_lookup[ret]); + } + sz -= col_start - ln_start; + if (sz > 0) + fwrite(ebuf + col_start, sizeof(GLchar), sz, stderr); + ln_start = i + 1; + col_start = ln_start; + break; + } + case ':': + if (col_start <= ln_start) + col_start = i + 1; + default: + if (i == ilen - 1) goto newline; + break; + + } + } #ifdef GLAVA_DEBUG if (gl->debug_verbose) { fprintf(stderr, "Processed shader source for '%s':\n", path); @@ -1388,8 +1413,9 @@ struct renderer* rd_new(const char** paths, const char* entry, bool skip; GLuint id = shaderbuild(gl, shaders, data, dd, handlers, shader_version, &skip, d->d_name); if (skip && verbose) printf("disabled: '%s'\n", d->d_name); + /* check for compilation failure */ if (!id && !skip) - abort(); + exit(EXIT_FAILURE); s->shader = id; @@ -1415,7 +1441,7 @@ struct renderer* rd_new(const char** paths, const char* entry, size_t u = 0; for (struct rd_bind* bd = gl->binds; bd->name != NULL; ++bd) { char buf[128]; - if (snprintf(buf, 128, "__IN_%s", bd->name) > 0) { + if (snprintf(buf, 128, "_IN_%s", bd->name) > 0) { s->pipe_uniforms[u] = glGetUniformLocation(id, buf); } else { fprintf(stderr, "failed to format binding: \"%s\"\n", bd->name); diff --git a/shaders/circle/2.frag b/shaders/circle/2.frag index e4794e8..e6cd45a 100644 --- a/shaders/circle/2.frag +++ b/shaders/circle/2.frag @@ -12,7 +12,7 @@ out vec4 fragment; /* output */ void main() { fragment = texelFetch(tex, ivec2(gl_FragCoord.x, gl_FragCoord.y), 0); #if C_SMOOTH > 0 - #if __USE_ALPHA + #if _USE_ALPHA vec4 a0 = texelFetch(tex, ivec2((gl_FragCoord.x + 1), (gl_FragCoord.y + 0)), 0), a1 = texelFetch(tex, ivec2((gl_FragCoord.x + 1), (gl_FragCoord.y + 1)), 0), diff --git a/shaders/radial/1.frag b/shaders/radial/1.frag index c98fdf5..641c3ec 100644 --- a/shaders/radial/1.frag +++ b/shaders/radial/1.frag @@ -31,7 +31,7 @@ out vec4 fragment; void main() { - #if __USE_ALPHA > 0 + #if _USE_ALPHA > 0 #define APPLY_FRAG(f, c) f = vec4(f.rgb * f.a + c.rgb * (1 - clamp(f.a, 0, 1)), max(c.a, f.a)) fragment = #00000000; #else @@ -48,7 +48,7 @@ void main() { float d = sqrt((dx * dx) + (dy * dy)); /* distance */ if (d > C_RADIUS - (float(C_LINE) / 2.0F) && d < C_RADIUS + (float(C_LINE) / 2.0F)) { APPLY_FRAG(fragment, OUTLINE); - #if __USE_ALPHA > 0 + #if _USE_ALPHA > 0 fragment.a *= clamp(((C_LINE / 2) - abs(C_RADIUS - d)) * C_ALIAS_FACTOR, 0, 1); #else return; /* return immediately if there is no alpha blending available */ @@ -74,7 +74,7 @@ void main() { v *= AMPLIFY; /* amplify */ #undef smooth_f /* offset to fragment distance from inner circle */ - #if __USE_ALPHA > 0 + #if _USE_ALPHA > 0 #define ALIAS_FACTOR (((BAR_WIDTH / 2) - abs(ym)) * BAR_ALIAS_FACTOR) d -= C_RADIUS; /* start bar overlapping the inner circle for blending */ #else @@ -91,7 +91,7 @@ void main() { #else r = COLOR; #endif - #if __USE_ALPHA > 0 + #if _USE_ALPHA > 0 r.a *= ALIAS_FACTOR; #endif APPLY_FRAG(fragment, r); @@ -99,7 +99,7 @@ void main() { } #if BAR_OUTLINE_WIDTH > 0 if (d <= v) { - #if __USE_ALPHA > 0 + #if _USE_ALPHA > 0 vec4 r = BAR_OUTLINE; r.a *= ALIAS_FACTOR; APPLY_FRAG(fragment, r); diff --git a/shaders/smooth_parameters.glsl b/shaders/smooth_parameters.glsl index bfea307..55460ec 100644 --- a/shaders/smooth_parameters.glsl +++ b/shaders/smooth_parameters.glsl @@ -39,7 +39,7 @@ /* The frequency range to sample. 1.0 would be the entire FFT output, and lower values reduce the displayed frequencies in a log-like scale. */ -#define SAMPLE_RANGE 0.9 +#define SAMPLE_RANGE 1.5 /* Factor for how to scale higher frequencies. Used in a linear equation which is multiplied by the result of the fft transformation. */ diff --git a/shaders/util/premultiply.frag b/shaders/util/premultiply.frag index 10595db..b25c059 100644 --- a/shaders/util/premultiply.frag +++ b/shaders/util/premultiply.frag @@ -1,5 +1,5 @@ -#if __PREMULTIPLY_ALPHA == 0 +#if _PREMULTIPLY_ALPHA == 0 #error __disablestage #endif diff --git a/shaders/util/smooth.glsl b/shaders/util/smooth.glsl index 61d6076..8029d59 100644 --- a/shaders/util/smooth.glsl +++ b/shaders/util/smooth.glsl @@ -34,14 +34,14 @@ float iscale_audio(float idx) { return -log((SAMPLE_RANGE) * idx) / (SAMPLE_SCALE); } -/* Note: the __SMOOTH_FACTOR macro is defined by GLava itself, from `#request setsmoothfactor`*/ +/* Note: the _SMOOTH_FACTOR macro is defined by GLava itself, from `#request setsmoothfactor`*/ float smooth_audio(in sampler1D tex, int tex_sz, highp float idx) { - #if __PRE_SMOOTHED_AUDIO < 1 + #if _PRE_SMOOTHED_AUDIO < 1 float - smin = scale_audio(clamp(idx - __SMOOTH_FACTOR, 0, 1)) * tex_sz, - smax = scale_audio(clamp(idx + __SMOOTH_FACTOR, 0, 1)) * tex_sz; + smin = scale_audio(clamp(idx - _SMOOTH_FACTOR, 0, 1)) * tex_sz, + smax = scale_audio(clamp(idx + _SMOOTH_FACTOR, 0, 1)) * tex_sz; float m = ((smax - smin) / 2.0F), s, w; float rm = smin + m; /* middle */ diff --git a/shaders/util/smooth_pass.frag b/shaders/util/smooth_pass.frag index 92a5396..eb3fe7a 100644 --- a/shaders/util/smooth_pass.frag +++ b/shaders/util/smooth_pass.frag @@ -6,8 +6,8 @@ uniform int w; out vec4 fragment; in vec4 gl_FragCoord; -#undef __PRE_SMOOTHED_AUDIO -#define __PRE_SMOOTHED_AUDIO 0 +#undef _PRE_SMOOTHED_AUDIO +#define _PRE_SMOOTHED_AUDIO 0 #include ":util/smooth.glsl"