added RGBA hex color parsing for GLSL, fixed alpha blending bug
This commit is contained in:
124
glsl_ext.c
124
glsl_ext.c
@@ -52,7 +52,7 @@ static void se_append(struct sbuf* sbuf, size_t elen, const char* fmt, ...) {
|
||||
int written;
|
||||
if ((written = vsnprintf(sbuf->buf + sbuf->at, space, fmt, args)) < 0)
|
||||
abort();
|
||||
sbuf->at += space;
|
||||
sbuf->at += written;
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
@@ -128,7 +128,8 @@ static struct schar directive(struct glsl_ext* ext, char** args,
|
||||
|
||||
int fd = open(path, O_RDONLY);
|
||||
if (fd == -1) {
|
||||
parse_error(line, f, "failed to load GLSL shader source specified by #include directive '%s': %s\n",
|
||||
parse_error(line, f, "failed to load GLSL shader source "
|
||||
"specified by #include directive '%s': %s\n",
|
||||
path, strerror(errno));
|
||||
}
|
||||
|
||||
@@ -137,7 +138,8 @@ static struct schar directive(struct glsl_ext* ext, char** args,
|
||||
|
||||
char* map = mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0);
|
||||
if (!map) {
|
||||
parse_error(line, f, "failed to map GLSL shader source specified by #include directive '%s': %s\n",
|
||||
parse_error(line, f, "failed to map GLSL shader source "
|
||||
"specified by #include directive '%s': %s\n",
|
||||
path, strerror(errno));
|
||||
}
|
||||
|
||||
@@ -210,10 +212,12 @@ static struct schar directive(struct glsl_ext* ext, char** args,
|
||||
case '1': { v = true; break; }
|
||||
case '0': { v = false; break; }
|
||||
default:
|
||||
parse_error_s(line, f, "tried to parse invalid raw string into a boolean");
|
||||
parse_error_s(line, f,
|
||||
"tried to parse invalid raw string into a boolean");
|
||||
}
|
||||
} else {
|
||||
parse_error_s(line, f, "tried to parse invalid raw string into a boolean");
|
||||
parse_error_s(line, f,
|
||||
"tried to parse invalid raw string into a boolean");
|
||||
}
|
||||
processed_args[i] = malloc(sizeof(bool));
|
||||
*(bool*) processed_args[i] = v;
|
||||
@@ -248,10 +252,11 @@ static struct schar directive(struct glsl_ext* ext, char** args,
|
||||
void ext_process(struct glsl_ext* ext, const char* f) {
|
||||
|
||||
#define LINE_START 0
|
||||
#define IGNORING 1
|
||||
#define GLSL 1
|
||||
#define MACRO 2
|
||||
#define REQUEST 3
|
||||
#define INCLUDE 4
|
||||
#define COLOR 5
|
||||
|
||||
struct sbuf sbuf = {
|
||||
.buf = malloc(256),
|
||||
@@ -263,12 +268,15 @@ void ext_process(struct glsl_ext* ext, const char* f) {
|
||||
size_t t;
|
||||
char at;
|
||||
int state = LINE_START;
|
||||
size_t macro_start_idx, arg_start_idx;
|
||||
size_t macro_start_idx, arg_start_idx, cbuf_idx;
|
||||
size_t line = 1;
|
||||
bool quoted = false, arg_start;
|
||||
char cbuf[9];
|
||||
char** args = NULL;
|
||||
size_t args_sz = 0;
|
||||
|
||||
|
||||
bool prev_slash = false, comment = false, comment_line = false, prev_asterix = false;
|
||||
|
||||
for (t = 0; t <= source_len; ++t) {
|
||||
at = source_len == t ? '\0' : ext->source[t];
|
||||
if (at == '\n')
|
||||
@@ -281,40 +289,114 @@ void ext_process(struct glsl_ext* ext, const char* f) {
|
||||
macro_start_idx = t;
|
||||
state = MACRO;
|
||||
continue; }
|
||||
case ' ':
|
||||
case '\t':
|
||||
case '\n':
|
||||
if (comment && comment_line) {
|
||||
comment = false;
|
||||
comment_line = false;
|
||||
}
|
||||
case '\t':
|
||||
case ' ':
|
||||
goto copy;
|
||||
default: {
|
||||
state = IGNORING;
|
||||
goto copy; }
|
||||
default: state = GLSL;
|
||||
/* let execution continue into next state */
|
||||
}
|
||||
}
|
||||
case IGNORING: /* copying GLSL source or unrelated preprocessor syntax */
|
||||
if (at == '\n') {
|
||||
state = LINE_START;
|
||||
case GLSL: /* copying GLSL source or unrelated preprocessor syntax */
|
||||
{
|
||||
switch (at) {
|
||||
case '/':
|
||||
if (!comment) {
|
||||
if (prev_slash) {
|
||||
comment = true;
|
||||
comment_line = true;
|
||||
prev_slash = false;
|
||||
} else prev_slash = true;
|
||||
} else if (!comment_line) {
|
||||
if (prev_asterix) {
|
||||
comment = false;
|
||||
prev_asterix = false;
|
||||
}
|
||||
}
|
||||
goto copy;
|
||||
case '*':
|
||||
if (!comment) {
|
||||
if (prev_slash) {
|
||||
comment = true;
|
||||
prev_slash = false;
|
||||
}
|
||||
} else prev_asterix = true;
|
||||
goto copy;
|
||||
case '#': {
|
||||
/* handle hex color syntax */
|
||||
if (!comment) {
|
||||
state = COLOR;
|
||||
cbuf_idx = 0;
|
||||
continue;
|
||||
} else goto normal_char;
|
||||
}
|
||||
case '\n':
|
||||
if (comment && comment_line) {
|
||||
comment = false;
|
||||
comment_line = false;
|
||||
}
|
||||
state = LINE_START;
|
||||
normal_char:
|
||||
default:
|
||||
prev_asterix = false;
|
||||
prev_slash = false;
|
||||
goto copy;
|
||||
}
|
||||
}
|
||||
case COLOR: /* parse hex color syntax (#ffffffff -> vec4(1.0, 1.0, 1.0, 1.0)) */
|
||||
{
|
||||
switch (at) {
|
||||
case 'a' ... 'z':
|
||||
case 'A' ... 'Z':
|
||||
case '0' ... '9': {
|
||||
cbuf[cbuf_idx] = at;
|
||||
++cbuf_idx;
|
||||
if (cbuf_idx >= 8)
|
||||
goto emit_color;
|
||||
else continue;
|
||||
}
|
||||
emit_color:
|
||||
default:
|
||||
cbuf[cbuf_idx] = '\0'; /* null terminate */
|
||||
float r = 0.0F, g = 0.0F, b = 0.0F, a = 1.0F;
|
||||
if (ext_parse_color(cbuf, 2, (float*[]) { &r, &g, &b, &a })) {
|
||||
se_append(&sbuf, 64, " vec4(%.6f, %.6f, %.6f, %.6f) ", r, g, b, a);
|
||||
} else {
|
||||
parse_error(line, f, "Invalid color format '#%s' while "
|
||||
"parsing GLSL color syntax extension", cbuf);
|
||||
}
|
||||
state = at == '\n' ? LINE_START : GLSL;
|
||||
if (cbuf_idx >= 8)
|
||||
continue;
|
||||
else goto copy; /* copy character if it ended the sequence */
|
||||
}
|
||||
}
|
||||
goto copy;
|
||||
case MACRO: /* processing start of macro */
|
||||
{
|
||||
switch (at) {
|
||||
case '\n':
|
||||
case ' ':
|
||||
case '\t':
|
||||
case '\0':
|
||||
case '\0':
|
||||
{
|
||||
/* end parsing directive */
|
||||
if (!strncmp("#request", &ext->source[macro_start_idx], t - macro_start_idx)
|
||||
|| !strncmp("#REQUEST", &ext->source[macro_start_idx], t - macro_start_idx)) {
|
||||
state = REQUEST;
|
||||
goto prepare_arg_parse;
|
||||
} else if (!strncmp("#include", &ext->source[macro_start_idx], t - macro_start_idx)
|
||||
|| !strncmp("#INCLUDE", &ext->source[macro_start_idx], t - macro_start_idx)) {
|
||||
} else if (!strncmp("#include", &ext->source[macro_start_idx],
|
||||
t - macro_start_idx)
|
||||
|| !strncmp("#INCLUDE", &ext->source[macro_start_idx],
|
||||
t - macro_start_idx)) {
|
||||
state = INCLUDE;
|
||||
goto prepare_arg_parse;
|
||||
} else {
|
||||
n_append(&sbuf, t - macro_start_idx, &ext->source[macro_start_idx]);
|
||||
state = IGNORING;
|
||||
state = at == '\n' ? LINE_START : GLSL;
|
||||
goto copy;
|
||||
}
|
||||
prepare_arg_parse:
|
||||
|
||||
4
render.c
4
render.c
@@ -753,10 +753,10 @@ struct renderer* rd_new(const char** paths, const char* entry, const char* force
|
||||
|
||||
#ifdef GLFW_TRANSPARENT_FRAMEBUFFER
|
||||
glfwWindowHint(GLFW_TRANSPARENT_FRAMEBUFFER, native_opacity ? GLFW_TRUE : GLFW_FALSE);
|
||||
gl->use_alpha = false;
|
||||
if (native_opacity) gl->use_alpha = false;
|
||||
#elif GLFW_TRANSPARENT
|
||||
glfwWindowHint(GLFW_TRANSPARENT, native_opacity ? GLFW_TRUE : GLFW_FALSE);
|
||||
gl->use_alpha = false;
|
||||
if (native_opacity) gl->use_alpha = false;
|
||||
#else
|
||||
if (native_opacity)
|
||||
printf("WARNING: the linked version of GLFW3 does not have transparency support"
|
||||
|
||||
@@ -7,13 +7,13 @@
|
||||
/* width (in pixels) of each bar gap */
|
||||
#define BAR_GAP 2
|
||||
/* outline color */
|
||||
#define BAR_OUTLINE vec4(0.15, 0.15, 0.15, 1)
|
||||
#define BAR_OUTLINE #262626
|
||||
/* outline width (in pixels, set to 0 to disable outline drawing) */
|
||||
#define BAR_OUTLINE_WIDTH 0
|
||||
/* Amplify magnitude of the results each bar displays */
|
||||
#define AMPLIFY 300
|
||||
/* Bar color */
|
||||
#define COLOR (vec4(0.2, 0.4, 0.7, 1) * ((d / 60) + 1))
|
||||
#define COLOR (#3366b2 * ((d / 60) + 1))
|
||||
/* Direction that the bars are facing, 0 for inward, 1 for outward */
|
||||
#define DIRECTION 0
|
||||
/* Whether to switch left/right audio buffers */
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
/* center line thickness (pixels) */
|
||||
#define C_LINE 2
|
||||
/* outline color */
|
||||
#define OUTLINE vec4(0.20, 0.20, 0.20, 1)
|
||||
#define OUTLINE #333333
|
||||
/* Amplify magnitude of the results each bar displays */
|
||||
#define AMPLIFY 150
|
||||
/* Angle (in radians) for how much to rotate the visualizer */
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
/* actual color definition */
|
||||
#define COLOR vec4((0.3 + RCOL_OFF) + LSTEP, 0.6 - LSTEP, (0.3 + LCOL_OFF) + LSTEP, 1)
|
||||
/* outline color */
|
||||
#define OUTLINE vec4(0.15, 0.15, 0.15, 1)
|
||||
#define OUTLINE #262626
|
||||
/* 1 to invert (vertically), 0 otherwise */
|
||||
#define INVERT 0
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
/* center line thickness (pixels) */
|
||||
#define C_LINE 2
|
||||
/* outline color */
|
||||
#define OUTLINE vec4(0.20, 0.20, 0.20, 1)
|
||||
#define OUTLINE #333333
|
||||
/* number of bars (use even values for best results) */
|
||||
#define NBARS 180
|
||||
/* width (in pixels) of each bar*/
|
||||
@@ -15,8 +15,8 @@
|
||||
#define BAR_OUTLINE_WIDTH 0
|
||||
/* Amplify magnitude of the results each bar displays */
|
||||
#define AMPLIFY 300
|
||||
/* Bar color */
|
||||
#define COLOR (vec4(0.8, 0.2, 0.2, 1) * ((d / 40) + 1))
|
||||
/* Bar color */
|
||||
#define COLOR (#cc3333 * ((d / 40) + 1))
|
||||
/* Angle (in radians) for how much to rotate the visualizer */
|
||||
#define ROTATE (PI / 2)
|
||||
/* Whether to switch left/right audio buffers */
|
||||
|
||||
Reference in New Issue
Block a user