pass in input resolution

This commit is contained in:
2025-09-22 23:38:35 +02:00
parent 1659ae94c7
commit bf9f0845b7
9 changed files with 76 additions and 21 deletions
+21 -6
View File
@@ -61,12 +61,8 @@ static void init_context(Parameters params) {
context.demo = params.demo;
context.monitor = params.monitor;
context.sub_state = malloc(program.frag_count * program.sub_type_count *
sizeof(unsigned int));
for (i = 0; i < program.frag_count * program.sub_type_count; i++) {
context.sub_state[i] = 0;
}
context.sub_state = (unsigned int *)calloc(
program.frag_count * program.sub_type_count, sizeof(unsigned int));
if (params.demo) {
randomize_context_state();
@@ -76,11 +72,30 @@ static void init_context(Parameters params) {
for (i = 0; i < program.frag_count; i++) {
context.seeds[i] = rand_uint(1000);
}
context.input_widths =
(unsigned int *)calloc(program.in_count, sizeof(unsigned int));
context.input_heights =
(unsigned int *)calloc(program.in_count, sizeof(unsigned int));
context.input_formats =
(unsigned int *)calloc(program.in_count, sizeof(unsigned int));
for (i = 0; i < program.in_count; i++) {
if (!inputs[i].error) {
context.input_widths[i] = inputs[i].width;
context.input_heights[i] = inputs[i].height;
context.input_formats[i] = inputs[i].pixelformat;
log_debug("%d %x", inputs[i].pixelformat, inputs[i].pixelformat);
}
}
}
static void free_context() {
free(context.sub_state);
free(context.seeds);
free(context.input_widths);
free(context.input_heights);
free(context.input_formats);
}
static void hot_reload() {
+9 -1
View File
@@ -435,6 +435,7 @@ static void use_program(ShaderProgram program, int i, bool output,
unsigned int j, k;
GLuint *subroutines;
vec2 resolution, tex_resolution;
vec3 in_resolution;
resolution[0] = (float)context.width;
resolution[1] = (float)context.height;
@@ -469,7 +470,14 @@ static void use_program(ShaderProgram program, int i, bool output,
glUniform2fv(program.itexres_locations[i], 1,
(const GLfloat *)&tex_resolution);
// TODO video resolution
for (j = 0; j < program.in_count; j++) {
in_resolution[0] = context.input_widths[j];
in_resolution[1] = context.input_heights[j];
in_resolution[2] = context.input_formats[j];
glUniform3fv(program.iinres_locations[i * program.in_count + j], 1,
(const GLfloat *)&in_resolution);
}
// set seeds uniforms
for (j = 0; j < program.frag_count; j++) {
+1
View File
@@ -115,6 +115,7 @@ typedef struct Context {
bool monitor;
unsigned int *input_widths;
unsigned int *input_heights;
unsigned int *input_formats;
} Context;
typedef struct Timer {
+12 -3
View File
@@ -107,6 +107,7 @@ static bool get_available_sizes(VideoCapture *video_capture,
unsigned int preferred_height) {
struct v4l2_frmsizeenum fmt_enum;
unsigned int index;
bool found = false;
memset(&fmt_enum, 0, sizeof(fmt_enum));
@@ -114,6 +115,7 @@ static bool get_available_sizes(VideoCapture *video_capture,
fmt_enum.index = index;
fmt_enum.pixel_format = V4L2_PIX_FMT_YUYV;
found = false;
video_capture->width = 0;
video_capture->height = 0;
@@ -124,12 +126,18 @@ static bool get_available_sizes(VideoCapture *video_capture,
if (fmt_enum.discrete.height == preferred_height) {
video_capture->height = preferred_height;
found = true;
if (video_capture->width == 0 ||
video_capture->width < fmt_enum.discrete.width) {
video_capture->width = fmt_enum.discrete.width;
}
} else if (fmt_enum.discrete.height < preferred_height &&
fmt_enum.discrete.height > video_capture->height) {
} else if (fmt_enum.discrete.height < preferred_height) {
if (!found || fmt_enum.discrete.height > video_capture->height) {
video_capture->height = fmt_enum.discrete.height;
video_capture->width = fmt_enum.discrete.width;
found = true;
}
} else if (video_capture->height == 0) {
video_capture->height = fmt_enum.discrete.height;
video_capture->width = fmt_enum.discrete.width;
}
@@ -141,6 +149,7 @@ static bool get_available_sizes(VideoCapture *video_capture,
}
if (video_capture->height == 0) {
log_warn("(%s) No format found");
video_capture->error = true;
return false;
}
@@ -159,7 +168,7 @@ static bool set_format(VideoCapture *video_capture) {
fmt.fmt.pix.width = video_capture->width;
fmt.fmt.pix.height = video_capture->height;
fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV;
fmt.fmt.pix.field = V4L2_FIELD_INTERLACED;
fmt.fmt.pix.field = V4L2_FIELD_ANY;
if (ioctl(video_capture->fd, VIDIOC_S_FMT, &fmt) == -1) {
fmt.type = V4L2_BUF_TYPE_VIDEO_OUTPUT;