Emit #line directives, refactor prefixes '__' -> '_', fix 'bars' outline
This commit is contained in:
34
glsl_ext.c
34
glsl_ext.c
@@ -203,14 +203,18 @@ static struct schar directive(struct glsl_ext* ext, char** args,
|
|||||||
.cfd = ext->cfd,
|
.cfd = ext->cfd,
|
||||||
.dd = ext->dd,
|
.dd = ext->dd,
|
||||||
.handlers = ext->handlers,
|
.handlers = ext->handlers,
|
||||||
.binds = ext->binds
|
.binds = ext->binds,
|
||||||
|
.ss_lookup = ext->ss_lookup,
|
||||||
|
.ss_len = ext->ss_len
|
||||||
};
|
};
|
||||||
|
|
||||||
/* recursively process */
|
/* recursively process */
|
||||||
ext_process(&next, target);
|
ext_process(&next, target);
|
||||||
inherit(ext, &next);
|
inherit(ext, &next);
|
||||||
munmap(map, st.st_size);
|
munmap(map, st.st_size);
|
||||||
|
|
||||||
|
ext->ss_lookup = next.ss_lookup;
|
||||||
|
|
||||||
struct schar ret = {
|
struct schar ret = {
|
||||||
.buf = next.processed,
|
.buf = next.processed,
|
||||||
.sz = next.p_len
|
.sz = next.p_len
|
||||||
@@ -302,6 +306,17 @@ void ext_process(struct glsl_ext* ext, const char* f) {
|
|||||||
|
|
||||||
ext->destruct = malloc(1);
|
ext->destruct = malloc(1);
|
||||||
ext->destruct_sz = 0;
|
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 = {
|
struct sbuf sbuf = {
|
||||||
.buf = malloc(256),
|
.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,
|
bool prev_slash = false, comment = false, comment_line = false, prev_asterix = false,
|
||||||
prev_escape = false, string = false;
|
prev_escape = false, string = false;
|
||||||
|
|
||||||
|
se_append(&sbuf, 32, "#line 1 %d\n", ss_cur);
|
||||||
|
|
||||||
for (t = 0; t <= source_len; ++t) {
|
for (t = 0; t <= source_len; ++t) {
|
||||||
at = source_len == t ? '\0' : ext->source[t];
|
at = source_len == t ? '\0' : ext->source[t];
|
||||||
if (at == '\n')
|
if (at == '\n')
|
||||||
@@ -605,6 +622,7 @@ void ext_process(struct glsl_ext* ext, const char* f) {
|
|||||||
if (r.buf) {
|
if (r.buf) {
|
||||||
n_append(&sbuf, r.sz, r.buf);
|
n_append(&sbuf, r.sz, r.buf);
|
||||||
append(&sbuf, "\n");
|
append(&sbuf, "\n");
|
||||||
|
se_append(&sbuf, 48, "#line %d %d\n", line, ss_cur);
|
||||||
}
|
}
|
||||||
if (state == DEFINE) skip_macro();
|
if (state == DEFINE) skip_macro();
|
||||||
else state = LINE_START;
|
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) {
|
void ext_free(struct glsl_ext* ext) {
|
||||||
free(ext->processed);
|
|
||||||
size_t t;
|
size_t t;
|
||||||
for (t = 0; t < ext->destruct_sz; ++t) {
|
free(ext->processed);
|
||||||
free(ext->destruct[t]);
|
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);
|
free(ext->destruct);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,6 +31,10 @@ struct glsl_ext {
|
|||||||
struct rd_bind* binds; /* OPT IN: --pipe binds */
|
struct rd_bind* binds; /* OPT IN: --pipe binds */
|
||||||
void** destruct; /* internal */
|
void** destruct; /* internal */
|
||||||
size_t destruct_sz; /* 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
|
/* IN: NULL (where the last element's 'name' member is NULL) terminated
|
||||||
array of request handlers */
|
array of request handlers */
|
||||||
|
|||||||
44
render.c
44
render.c
@@ -212,7 +212,7 @@ static GLuint shaderload(const char* rpath,
|
|||||||
bind_header[0] = '\0';
|
bind_header[0] = '\0';
|
||||||
size_t bh_idx = 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) {
|
for (struct rd_bind* bd = gl->binds; bd->name != NULL; ++bd) {
|
||||||
size_t inc = snprintf(NULL, 0, fmt, bd->stype, bd->name);
|
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 =
|
static const GLchar* header_fmt =
|
||||||
"#version %d\n"
|
"#version %d\n"
|
||||||
"#define __UNIFORM_LIMIT %d\n"
|
"#define _UNIFORM_LIMIT %d\n"
|
||||||
"#define __PRE_SMOOTHED_AUDIO %d\n"
|
"#define _PRE_SMOOTHED_AUDIO %d\n"
|
||||||
"#define __SMOOTH_FACTOR %.6f\n"
|
"#define _SMOOTH_FACTOR %.6f\n"
|
||||||
"#define __USE_ALPHA %d\n"
|
"#define _USE_ALPHA %d\n"
|
||||||
"#define __PREMULTIPLY_ALPHA %d\n"
|
"#define _PREMULTIPLY_ALPHA %d\n"
|
||||||
"#define USE_STDIN %d\n"
|
"#define USE_STDIN %d\n"
|
||||||
"#if USE_STDIN == 1\n"
|
"#if USE_STDIN == 1\n"
|
||||||
"uniform %s STDIN;\n"
|
"uniform %s STDIN;\n"
|
||||||
@@ -297,7 +297,32 @@ static GLuint shaderload(const char* rpath,
|
|||||||
}
|
}
|
||||||
|
|
||||||
fprintf(stderr, "Shader compilation failed for '%s':\n", path);
|
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
|
#ifdef GLAVA_DEBUG
|
||||||
if (gl->debug_verbose) {
|
if (gl->debug_verbose) {
|
||||||
fprintf(stderr, "Processed shader source for '%s':\n", path);
|
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;
|
bool skip;
|
||||||
GLuint id = shaderbuild(gl, shaders, data, dd, handlers, shader_version, &skip, d->d_name);
|
GLuint id = shaderbuild(gl, shaders, data, dd, handlers, shader_version, &skip, d->d_name);
|
||||||
if (skip && verbose) printf("disabled: '%s'\n", d->d_name);
|
if (skip && verbose) printf("disabled: '%s'\n", d->d_name);
|
||||||
|
/* check for compilation failure */
|
||||||
if (!id && !skip)
|
if (!id && !skip)
|
||||||
abort();
|
exit(EXIT_FAILURE);
|
||||||
|
|
||||||
s->shader = id;
|
s->shader = id;
|
||||||
|
|
||||||
@@ -1415,7 +1441,7 @@ struct renderer* rd_new(const char** paths, const char* entry,
|
|||||||
size_t u = 0;
|
size_t u = 0;
|
||||||
for (struct rd_bind* bd = gl->binds; bd->name != NULL; ++bd) {
|
for (struct rd_bind* bd = gl->binds; bd->name != NULL; ++bd) {
|
||||||
char buf[128];
|
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);
|
s->pipe_uniforms[u] = glGetUniformLocation(id, buf);
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "failed to format binding: \"%s\"\n", bd->name);
|
fprintf(stderr, "failed to format binding: \"%s\"\n", bd->name);
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ out vec4 fragment; /* output */
|
|||||||
void main() {
|
void main() {
|
||||||
fragment = texelFetch(tex, ivec2(gl_FragCoord.x, gl_FragCoord.y), 0);
|
fragment = texelFetch(tex, ivec2(gl_FragCoord.x, gl_FragCoord.y), 0);
|
||||||
#if C_SMOOTH > 0
|
#if C_SMOOTH > 0
|
||||||
#if __USE_ALPHA
|
#if _USE_ALPHA
|
||||||
vec4
|
vec4
|
||||||
a0 = texelFetch(tex, ivec2((gl_FragCoord.x + 1), (gl_FragCoord.y + 0)), 0),
|
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),
|
a1 = texelFetch(tex, ivec2((gl_FragCoord.x + 1), (gl_FragCoord.y + 1)), 0),
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ out vec4 fragment;
|
|||||||
|
|
||||||
void main() {
|
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))
|
#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;
|
fragment = #00000000;
|
||||||
#else
|
#else
|
||||||
@@ -48,7 +48,7 @@ void main() {
|
|||||||
float d = sqrt((dx * dx) + (dy * dy)); /* distance */
|
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)) {
|
if (d > C_RADIUS - (float(C_LINE) / 2.0F) && d < C_RADIUS + (float(C_LINE) / 2.0F)) {
|
||||||
APPLY_FRAG(fragment, OUTLINE);
|
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);
|
fragment.a *= clamp(((C_LINE / 2) - abs(C_RADIUS - d)) * C_ALIAS_FACTOR, 0, 1);
|
||||||
#else
|
#else
|
||||||
return; /* return immediately if there is no alpha blending available */
|
return; /* return immediately if there is no alpha blending available */
|
||||||
@@ -74,7 +74,7 @@ void main() {
|
|||||||
v *= AMPLIFY; /* amplify */
|
v *= AMPLIFY; /* amplify */
|
||||||
#undef smooth_f
|
#undef smooth_f
|
||||||
/* offset to fragment distance from inner circle */
|
/* 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)
|
#define ALIAS_FACTOR (((BAR_WIDTH / 2) - abs(ym)) * BAR_ALIAS_FACTOR)
|
||||||
d -= C_RADIUS; /* start bar overlapping the inner circle for blending */
|
d -= C_RADIUS; /* start bar overlapping the inner circle for blending */
|
||||||
#else
|
#else
|
||||||
@@ -91,7 +91,7 @@ void main() {
|
|||||||
#else
|
#else
|
||||||
r = COLOR;
|
r = COLOR;
|
||||||
#endif
|
#endif
|
||||||
#if __USE_ALPHA > 0
|
#if _USE_ALPHA > 0
|
||||||
r.a *= ALIAS_FACTOR;
|
r.a *= ALIAS_FACTOR;
|
||||||
#endif
|
#endif
|
||||||
APPLY_FRAG(fragment, r);
|
APPLY_FRAG(fragment, r);
|
||||||
@@ -99,7 +99,7 @@ void main() {
|
|||||||
}
|
}
|
||||||
#if BAR_OUTLINE_WIDTH > 0
|
#if BAR_OUTLINE_WIDTH > 0
|
||||||
if (d <= v) {
|
if (d <= v) {
|
||||||
#if __USE_ALPHA > 0
|
#if _USE_ALPHA > 0
|
||||||
vec4 r = BAR_OUTLINE;
|
vec4 r = BAR_OUTLINE;
|
||||||
r.a *= ALIAS_FACTOR;
|
r.a *= ALIAS_FACTOR;
|
||||||
APPLY_FRAG(fragment, r);
|
APPLY_FRAG(fragment, r);
|
||||||
|
|||||||
@@ -39,7 +39,7 @@
|
|||||||
/* The frequency range to sample. 1.0 would be the entire FFT output,
|
/* The frequency range to sample. 1.0 would be the entire FFT output,
|
||||||
and lower values reduce the displayed frequencies in a log-like
|
and lower values reduce the displayed frequencies in a log-like
|
||||||
scale. */
|
scale. */
|
||||||
#define SAMPLE_RANGE 0.9
|
#define SAMPLE_RANGE 1.5
|
||||||
|
|
||||||
/* Factor for how to scale higher frequencies. Used in a linear equation
|
/* Factor for how to scale higher frequencies. Used in a linear equation
|
||||||
which is multiplied by the result of the fft transformation. */
|
which is multiplied by the result of the fft transformation. */
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
|
|
||||||
#if __PREMULTIPLY_ALPHA == 0
|
#if _PREMULTIPLY_ALPHA == 0
|
||||||
#error __disablestage
|
#error __disablestage
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -34,14 +34,14 @@ float iscale_audio(float idx) {
|
|||||||
return -log((SAMPLE_RANGE) * idx) / (SAMPLE_SCALE);
|
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) {
|
float smooth_audio(in sampler1D tex, int tex_sz, highp float idx) {
|
||||||
|
|
||||||
#if __PRE_SMOOTHED_AUDIO < 1
|
#if _PRE_SMOOTHED_AUDIO < 1
|
||||||
float
|
float
|
||||||
smin = 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;
|
smax = scale_audio(clamp(idx + _SMOOTH_FACTOR, 0, 1)) * tex_sz;
|
||||||
float m = ((smax - smin) / 2.0F), s, w;
|
float m = ((smax - smin) / 2.0F), s, w;
|
||||||
float rm = smin + m; /* middle */
|
float rm = smin + m; /* middle */
|
||||||
|
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ uniform int w;
|
|||||||
out vec4 fragment;
|
out vec4 fragment;
|
||||||
in vec4 gl_FragCoord;
|
in vec4 gl_FragCoord;
|
||||||
|
|
||||||
#undef __PRE_SMOOTHED_AUDIO
|
#undef _PRE_SMOOTHED_AUDIO
|
||||||
#define __PRE_SMOOTHED_AUDIO 0
|
#define _PRE_SMOOTHED_AUDIO 0
|
||||||
|
|
||||||
#include ":util/smooth.glsl"
|
#include ":util/smooth.glsl"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user