Compare commits

...

2 commits

Author SHA1 Message Date
84595eff00
Auto-set pipe size according to frame size, add iSampleRate uniform
The pipe size is now set automatically to avoid unnescessary buffering of frames
which aren't supposes to be there yet as well as preventing partial reads and
writes when larger resolutuions are used.

The iSampleRate uniform was added according to shadertoy spec.

Signed-off-by: Tyrolyean <tyrolyean@tyrolyean.net>
2022-07-18 00:59:36 +02:00
f0ffbc7c33
Set to newer c-standard and add source code fortification
The fortify source code was added to prevent builds from passing but then
failing in our build system and the c-standard was set to c11 to avoid the
compiler yelling at me whenever i want to print a size_t.

Signed-off-by: Tyrolyean <tyrolyean@tyrolyean.net>
2022-07-18 00:58:11 +02:00
2 changed files with 51 additions and 4 deletions

View file

@ -1,4 +1,4 @@
CFLAGS = -ansi -pedantic -Wall -Wextra -O2 -Ofast -D_DEFAULT_SOURCE
CFLAGS = -std=c11 -pedantic -Wall -Wextra -O2 -Ofast -D_DEFAULT_SOURCE -D_FORTIFY_SOURCE=2
LDFLAGS = -lX11 -lGL -lGLEW -lm -lrt
shadermeh: shadermeh.o window.o shader.o

View file

@ -1,4 +1,5 @@
/* SPDX-License-Identifier: ISC */
/*
* shadermeh.c
*
@ -6,6 +7,9 @@
*/
#include "shadermeh.h"
#include <fcntl.h>
#include <errno.h>
#define HAVE_ARCH_STRUCT_FLOCK
#include <linux/fcntl.h>
static GLfloat vertex_buffer[] = {
-1.0f, -1.0f, 0.0f, /* lower left corner */
@ -90,7 +94,7 @@ static const struct option long_opts[] = {
{ NULL, 0, NULL, 0 },
};
static const char *short_opts = "w:h:s:S:r";
static const char *short_opts = "r:w:h:s:S";
static const char *usage_str =
"shadermeh OPTIONS...\n"
@ -99,6 +103,7 @@ static const char *usage_str =
"\n"
" --width, -w <pixels>\n"
" --height, -h <pixels>\n"
" --sampling-rate, -r <sampling rate[Hz]>\n"
"\n"
" --to-stdout, -S\n"
"\n"
@ -110,6 +115,7 @@ static const char *usage_str =
int main(int argc, char **argv)
{
GLuint u_iResolution, u_iTime, u_iTimeDelta, u_iFrame;
GLfloat u_iSampleRate;
struct timespec start, frame_start, frame_end;
unsigned int width, height, iFrame = 0;
void *fb32 = NULL, *fb24 = NULL;
@ -120,7 +126,9 @@ int main(int argc, char **argv)
bool to_stdout = false;
window *wnd;
int i;
unsigned int sampling_rate = 0;
unsigned int sampling_rate = 0; /* Leaving this at 0 disables audio
* input
*/
float in_samples[SND_BUFFER_SIZE]; /* Raw input floats from -1...1 */
float norm_samples[SND_BUFFER_SIZE]; /* Normalized samples from 0...1 */
@ -174,6 +182,43 @@ int main(int argc, char **argv)
free(fb32);
return EXIT_FAILURE;
}
if(!isatty(STDOUT_FILENO)){
long old_pipe_size = fcntl(STDOUT_FILENO, F_GETPIPE_SZ);
if(old_pipe_size < 0){
perror("Failed to get stdout pipe size");
}else{
int psz = getpagesize();
size_t frame_size = (width * height * 3);
size_t frame_cnt = psz / frame_size;
if((psz % frame_size) != 0){
frame_cnt++;
}
size_t new_pipe_size = frame_size * frame_cnt;
int fin_psz = fcntl(STDOUT_FILENO, F_SETPIPE_SZ,
new_pipe_size);
if(fin_psz < 0){
fprintf(stderr, "Failed to set STDOUT "
"pipe size to %zu: %s\n",
new_pipe_size, strerror(errno));
}else{
fprintf(stderr, "stdout pipe size "
"change from %li to %zu "
"resulted in %i\n",
old_pipe_size,
new_pipe_size,
fin_psz);
}
/* A failure to change pipe size is not
* catastrophic, beacause the application will
* still perform as needed, just with a bigger
* or smaller buffer. */
}
}
}
if (sampling_rate != 0 && !isatty(STDIN_FILENO)){
fputs("Sampling rate specified and STDIN not a tty! "
"You habe been warnded!\n", stderr);
}
/********** create window and make context current **********/
@ -202,7 +247,7 @@ int main(int argc, char **argv)
glGetIntegerv(GL_MAJOR_VERSION, &major);
glGetIntegerv(GL_MINOR_VERSION, &minor);
printf("OpenGL version %d.%d\n", major, minor);
fprintf(stderr,"OpenGL version %d.%d\n", major, minor);
/******************** initialization ********************/
glViewport(0, 0, width, height);
@ -239,8 +284,10 @@ int main(int argc, char **argv)
u_iTime = glGetUniformLocation(prog, "iTime");
u_iTimeDelta = glGetUniformLocation(prog, "iTimeDelta");
u_iFrame = glGetUniformLocation(prog, "iFrame;");
u_iSampleRate = glGetUniformLocation(prog, "iSampleRate");
glUniform3f(u_iResolution, width, height, 0.0f);
glUniform1f(u_iSampleRate, sampling_rate);
clock_gettime(CLOCK_MONOTONIC_RAW, &start);