Compare commits
9 Commits
97f768f65e
...
a7bc58e94e
| Author | SHA1 | Date | |
|---|---|---|---|
| a7bc58e94e | |||
| dfefe879c9 | |||
| 7d99c617ef | |||
| cdc7df3e56 | |||
| 8f0da378b0 | |||
| 7d03c9719e | |||
| dd20515e2b | |||
| 53c5639f92 | |||
| d85c5b47b6 |
@@ -0,0 +1,4 @@
|
||||
# yaml-language-server: $schema=https://json.schemastore.org/clang-format-21.x.json
|
||||
---
|
||||
BasedOnStyle: LLVM
|
||||
IndentWidth: 2
|
||||
@@ -0,0 +1,19 @@
|
||||
# EditorConfig is awesome: https://EditorConfig.org
|
||||
|
||||
# top-most EditorConfig file
|
||||
root = true
|
||||
|
||||
[*]
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
end_of_line = lf
|
||||
charset = utf-8
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
||||
|
||||
[{*.c,*.h}]
|
||||
indent_size = 2
|
||||
|
||||
[{Makefile.*,Makefile}]
|
||||
indent_style = tab
|
||||
indent_size = 2
|
||||
+4
-1
@@ -25,6 +25,10 @@ build:
|
||||
-o build/$(TARGET) \
|
||||
-g -Og
|
||||
|
||||
.PHONY: format
|
||||
format:
|
||||
clang-format -i src/*
|
||||
|
||||
.PHONY: run
|
||||
run: build
|
||||
./build/$(TARGET) $(TEST_ARGS) --monitor-only --internal-size=480 --video-size=240 --hot-reload
|
||||
@@ -101,4 +105,3 @@ release-arch: clean
|
||||
mkdir -p build
|
||||
cp PKGBUILD build
|
||||
cd build && makepkg
|
||||
|
||||
|
||||
@@ -175,14 +175,16 @@ These are configurable in the [`forge_project.cfg`](#forge_projectcfg).
|
||||
### CLI arguments
|
||||
|
||||
```txt
|
||||
usage: forge [-h] [-v] [-p=PROJECT_PATH] [-c=CFG_FILE] [-hr] [-s=SCREEN] [-m=SCREEN] [-mo] [-w] [-t=TEMPO] [-d] [-ar / -nar] [-arc=CYCLES] [-vi=FILE] [-vs=SIZE] [-is=SIZE] [-ls / -nls] [-ss / -nss] [-tm] [-tf]
|
||||
forge steel-dev
|
||||
|
||||
usage: forge [-h] [-v] [-p=PROJECT_PATH] [-c=CFG_FILE] [-hr] [-s=SCREEN] [-m=SCREEN] [-mo] [-w] [-t=TEMPO] [-d] [-ar / -nar] [-arc=CYCLES] [-vi=FILE] [-vs=SIZE] [-vr / -nvr] [-is=SIZE] [-ls / -nls] [-ss / -nss] [-tm] [-tf]
|
||||
|
||||
Fusion Of Real-time Generative Effects.
|
||||
|
||||
options:
|
||||
-h, --help show this help message and exit
|
||||
-v, --version print version
|
||||
-p, --project forge project directory (default: /usr/share/forge/default)
|
||||
-p, --project forge project directory (default: ./default)
|
||||
-c, --config config file name (default: forge_project.cfg)
|
||||
-hr, --hot-reload hot reload of shaders scripts
|
||||
-s, --screen output screen number (default: primary)
|
||||
@@ -196,6 +198,8 @@ options:
|
||||
-arc, --auto-random-cycle auto random cycle length (default: 4)
|
||||
-vi, --video-in path to video capture device (multiple allowed)
|
||||
-vs, --video-size video capture desired height (default: internal texture height)
|
||||
-vr, --video-reconnect auto-reconnect video (default)
|
||||
-nvr, --no-video-reconnect do not auto-reconnect video
|
||||
-is, --internal-size internal texture height (default: 720)
|
||||
-ls, --load-state load saved state (default)
|
||||
-nls, --no-load-state do not load saved state
|
||||
@@ -490,3 +494,7 @@ The code is available in the default project [default/inc_yuyv.glsl](./default/i
|
||||
The sentences are defined in [default/inc_sentences.glsl](./default/inc_sentences.glsl).
|
||||
|
||||
The script [scripts/sentences.py](./scripts/sentences.py) can help you update them.
|
||||
|
||||
### My video device keeps changing ID each time it's unplugged
|
||||
|
||||
You should [bind your device to a fixed interface](https://linuxvox.com/blog/linux-bind-camera-to-fixed-devvideo/).
|
||||
|
||||
+30
-30
@@ -22,7 +22,7 @@ uniform int iInputFPS2;
|
||||
|
||||
float s(vec2 uv, float x0, float y0) {
|
||||
return step(x0, uv.x) * step(-x0 - 1, -uv.x) * step(y0, uv.y) *
|
||||
step(-y0 - 1, -uv.y);
|
||||
step(-y0 - 1, -uv.y);
|
||||
}
|
||||
|
||||
const int texts[12][5] = {
|
||||
@@ -50,15 +50,15 @@ void main() {
|
||||
|
||||
vec4 c = vec4(0);
|
||||
|
||||
c += s(uv2,1,2) * texture(iTex7, uv2);
|
||||
c += s(uv2,2,2) * texture(iTex9, uv2);
|
||||
c += s(uv2, 1, 2) * texture(iTex7, uv2);
|
||||
c += s(uv2, 2, 2) * texture(iTex9, uv2);
|
||||
|
||||
c += s(uv2,1,0) * texture(iTex8, uv2);
|
||||
c += s(uv2,2,0) * texture(iTex10, uv2);
|
||||
c += s(uv2, 1, 0) * texture(iTex8, uv2);
|
||||
c += s(uv2, 2, 0) * texture(iTex10, uv2);
|
||||
|
||||
c += s(uv2,0,1) * debug(mod(uv2, 1));
|
||||
c += s(uv2,1,1) * texture(iTex11, uv2);
|
||||
c += s(uv2,2,1) * texture(iTex0, uv2);
|
||||
c += s(uv2, 0, 1) * debug(mod(uv2, 1));
|
||||
c += s(uv2, 1, 1) * texture(iTex11, uv2);
|
||||
c += s(uv2, 2, 1) * texture(iTex0, uv2);
|
||||
|
||||
float sel = 0;
|
||||
|
||||
@@ -74,65 +74,65 @@ void main() {
|
||||
float t = 0;
|
||||
|
||||
f += rect(uv3, vec2(-35, 28.5), vec2(2.1, 0.7));
|
||||
t += write_5(uv3, vec2(-37,28), texts[0]);
|
||||
t += write_5(uv3, vec2(-37, 28), texts[0]);
|
||||
|
||||
if (iInputResolution1.x > 0) {
|
||||
c += s(uv2,0,2) * texture(iTex5, uv2);
|
||||
if (iInputFormat1 == YUYV_FOURCC) {
|
||||
c += s(uv2, 0, 2) * texture(iTex5, uv2);
|
||||
f += rect(uv3, vec2(-35, 26.75), vec2(2.8, 0.7));
|
||||
t += write_int(uv3, vec2(-37.6,26.1), iInputFPS1, 2);
|
||||
t += write_5(uv3, vec2(-35.1,26.1), texts[8]);
|
||||
t += write_int(uv3, vec2(-37.6, 26.1), iInputFPS1, 2);
|
||||
t += write_5(uv3, vec2(-35.1, 26.1), texts[8]);
|
||||
} else {
|
||||
f += rect(uv3, vec2(-35, 26.75), vec2(1.6, 0.7));
|
||||
t += write_5(uv3, vec2(-36.5,26.1), texts[9]);
|
||||
t += write_5(uv3, vec2(-36.5, 26.1), texts[9]);
|
||||
}
|
||||
|
||||
f += rect(uv3, vec2(-35, -11.5), vec2(2.1, 0.7));
|
||||
t += write_5(uv3, vec2(-37,-12), texts[1]);
|
||||
t += write_5(uv3, vec2(-37, -12), texts[1]);
|
||||
|
||||
if (iInputResolution2.x > 0) {
|
||||
c += s(uv2,0,0) * texture(iTex6, uv2);
|
||||
if (iInputFormat2 == YUYV_FOURCC) {
|
||||
c += s(uv2, 0, 0) * texture(iTex6, uv2);
|
||||
f += rect(uv3, vec2(-35, -13.25), vec2(2.8, 0.7));
|
||||
t += write_int(uv3, vec2(-37.6,-13.9), iInputFPS2, 2);
|
||||
t += write_5(uv3, vec2(-35.1,-13.9), texts[8]);
|
||||
t += write_int(uv3, vec2(-37.6, -13.9), iInputFPS2, 2);
|
||||
t += write_5(uv3, vec2(-35.1, -13.9), texts[8]);
|
||||
} else {
|
||||
f += rect(uv3, vec2(-35, -13.25), vec2(1.6, 0.7));
|
||||
t += write_5(uv3, vec2(-36.5,-13.9), texts[9]);
|
||||
t += write_5(uv3, vec2(-36.5, -13.9), texts[9]);
|
||||
}
|
||||
|
||||
f += rect(uv3, vec2(-35, 8.5), vec2(2.1, 0.7));
|
||||
|
||||
if (iDemo > 0) {
|
||||
t += write_5(uv3, vec2(-37,8), texts[10]);
|
||||
t += write_5(uv3, vec2(-37, 8), texts[10]);
|
||||
} else {
|
||||
t += write_5(uv3, vec2(-37,8), texts[11]);
|
||||
t += write_5(uv3, vec2(-37, 8), texts[11]);
|
||||
}
|
||||
|
||||
f += rect(uv3, vec2(0, 28.5), vec2(2.6, 0.7));
|
||||
f += iActive1 == 1 ? h_rect(uv3, vec2(0, 28.5), vec2(3, 1), 0.2) : 0;
|
||||
t += write_5(uv3, vec2(-2.5,28), texts[2]);
|
||||
t += write_5(uv3, vec2(-2.5, 28), texts[2]);
|
||||
|
||||
f += rect(uv3, vec2(0, -11.5), vec2(2.6, 0.7));
|
||||
f += iActive1 == 2 ? h_rect(uv3, vec2(0, -11.5), vec2(3, 1), 0.2) : 0;
|
||||
t += write_5(uv3, vec2(-2.5,-12), texts[3]);
|
||||
t += write_5(uv3, vec2(-2.5, -12), texts[3]);
|
||||
|
||||
f += rect(uv3, vec2(35, 28.5), vec2(2.1, 0.7));
|
||||
f += iActive2 == 1 ? h_rect(uv3, vec2(35, 28.5), vec2(2.5, 1), 0.2) : 0;
|
||||
t += write_5(uv3, vec2(33,28), texts[4]);
|
||||
t += write_5(uv3, vec2(33, 28), texts[4]);
|
||||
|
||||
f += rect(uv3, vec2(35, -11.5), vec2(2.1, 0.7));
|
||||
f += iActive2 == 2 ? h_rect(uv3, vec2(35, -11.5), vec2(2.5, 1), 0.2) : 0;
|
||||
t += write_5(uv3, vec2(33,-12), texts[5]);
|
||||
t += write_5(uv3, vec2(33, -12), texts[5]);
|
||||
|
||||
f += rect(uv3, vec2(0, 8.5), vec2(1.6, 0.7));
|
||||
t += write_5(uv3, vec2(-1.5,8), texts[6]);
|
||||
t += write_5(uv3, vec2(-1.5, 8), texts[6]);
|
||||
|
||||
f += rect(uv3, vec2(35, 8.5), vec2(1.6, 0.7));
|
||||
f += iActive2 == 3 ? h_rect(uv3, vec2(35, 8.5), vec2(2, 1), 0.2) : 0;
|
||||
t += write_5(uv3, vec2(33.5,8), texts[7]);
|
||||
t += write_5(uv3, vec2(33.5, 8), texts[7]);
|
||||
|
||||
f += rect(uv3, vec2(35, 6.75), vec2(2.8, 0.7));
|
||||
t += write_int(uv3, vec2(32.4,6.1), iFPS, 2);
|
||||
t += write_5(uv3, vec2(34.9,6.1), texts[8]);
|
||||
t += write_int(uv3, vec2(32.4, 6.1), iFPS, 2);
|
||||
t += write_5(uv3, vec2(34.9, 6.1), texts[8]);
|
||||
|
||||
fragColor = mix(c, vec4(min(1, f) - t), min(1, f));
|
||||
}
|
||||
+43
-43
@@ -8,8 +8,8 @@
|
||||
uniform int iDemo;
|
||||
|
||||
uniform sampler2D iTex0;
|
||||
uniform sampler2D iTex3;
|
||||
uniform sampler2D iTex4;
|
||||
uniform sampler2D iTex5;
|
||||
uniform sampler2D iTex6;
|
||||
|
||||
subroutine vec4 src_stage_sub(vec2 vUV, int seed, vec3 b1, vec2 f1, vec3 b2, vec2 f2, vec3 b3, vec2 f3);
|
||||
|
||||
@@ -17,7 +17,7 @@ vec4 src_thru(vec2 vUV, sampler2D tex, int seed, vec3 b1, vec2 f1, vec3 b2, vec2
|
||||
{
|
||||
// start
|
||||
|
||||
vec2 uv0 = vUV.st;
|
||||
vec2 uv0 = vUV.st;
|
||||
|
||||
// controls
|
||||
|
||||
@@ -36,21 +36,21 @@ vec4 src_thru(vec2 vUV, sampler2D tex, int seed, vec3 b1, vec2 f1, vec3 b2, vec2
|
||||
|
||||
// output
|
||||
|
||||
return vec4(c, 1.);
|
||||
return vec4(c, 1.);
|
||||
}
|
||||
|
||||
// SRC 1: feedback + thru
|
||||
subroutine(src_stage_sub) vec4 src_1(vec2 vUV, int seed, vec3 b1, vec2 f1, vec3 b2, vec2 f2, vec3 b3, vec2 f3)
|
||||
subroutine ( src_stage_sub ) vec4 src_1(vec2 vUV, int seed, vec3 b1, vec2 f1, vec3 b2, vec2 f2, vec3 b3, vec2 f3)
|
||||
{
|
||||
return src_thru(vUV, iTex0, seed, b1, f1, b2, f2, b3, f3);
|
||||
}
|
||||
|
||||
// SRC 2 : lines
|
||||
subroutine(src_stage_sub) vec4 src_2(vec2 vUV, int seed, vec3 b1, vec2 f1, vec3 b2, vec2 f2, vec3 b3, vec2 f3)
|
||||
subroutine ( src_stage_sub ) vec4 src_2(vec2 vUV, int seed, vec3 b1, vec2 f1, vec3 b2, vec2 f2, vec3 b3, vec2 f3)
|
||||
{
|
||||
// start
|
||||
|
||||
vec2 uv0 = vUV.st;
|
||||
vec2 uv0 = vUV.st;
|
||||
float ratio = iResolution.x / iResolution.y;
|
||||
vec2 uv1 = (uv0 - .5) * vec2(ratio, 1);
|
||||
|
||||
@@ -73,11 +73,11 @@ subroutine(src_stage_sub) vec4 src_2(vec2 vUV, int seed, vec3 b1, vec2 f1, vec3
|
||||
}
|
||||
|
||||
// SRC 3 : dots
|
||||
subroutine(src_stage_sub) vec4 src_3(vec2 vUV, int seed, vec3 b1, vec2 f1, vec3 b2, vec2 f2, vec3 b3, vec2 f3)
|
||||
subroutine ( src_stage_sub ) vec4 src_3(vec2 vUV, int seed, vec3 b1, vec2 f1, vec3 b2, vec2 f2, vec3 b3, vec2 f3)
|
||||
{
|
||||
// start
|
||||
|
||||
vec2 uv0 = vUV.st;
|
||||
vec2 uv0 = vUV.st;
|
||||
float ratio = iResolution.x / iResolution.y;
|
||||
vec2 uv1 = (uv0 - .5) * vec2(ratio, 1);
|
||||
|
||||
@@ -102,11 +102,11 @@ subroutine(src_stage_sub) vec4 src_3(vec2 vUV, int seed, vec3 b1, vec2 f1, vec3
|
||||
}
|
||||
|
||||
// SRC 4 : circuit
|
||||
subroutine(src_stage_sub) vec4 src_4(vec2 vUV, int seed, vec3 b1, vec2 f1, vec3 b2, vec2 f2, vec3 b3, vec2 f3)
|
||||
subroutine ( src_stage_sub ) vec4 src_4(vec2 vUV, int seed, vec3 b1, vec2 f1, vec3 b2, vec2 f2, vec3 b3, vec2 f3)
|
||||
{
|
||||
// start
|
||||
|
||||
vec2 uv0 = vUV.st;
|
||||
vec2 uv0 = vUV.st;
|
||||
float ratio = iResolution.x / iResolution.y;
|
||||
vec2 uv1 = (uv0 - .5) * vec2(ratio, 1);
|
||||
|
||||
@@ -199,12 +199,12 @@ subroutine(src_stage_sub) vec4 src_4(vec2 vUV, int seed, vec3 b1, vec2 f1, vec3
|
||||
f += line(uv1, vec2(-t * 2), vec2(t * 2), t);
|
||||
f += line(uv1, vec2(-t * 2, t * 2), vec2(t * 2, -t * 2), t);
|
||||
} else if (k < 50) { // inductor
|
||||
f += istep(t * 2, length(uv1 - vec2(t * 2.5,0)));
|
||||
f += istep(t * 2, length(uv1 - vec2(0,0)));
|
||||
f += istep(t * 2, length(uv1 - vec2(-t * 2.5,0)));
|
||||
f -= 2 * istep(t, length(uv1 - vec2(t * 2.5,0)));
|
||||
f -= 2 * istep(t, length(uv1 - vec2(0,0)));
|
||||
f -= 2 * istep(t, length(uv1 - vec2(-t * 2.5,0)));
|
||||
f += istep(t * 2, length(uv1 - vec2(t * 2.5, 0)));
|
||||
f += istep(t * 2, length(uv1 - vec2(0, 0)));
|
||||
f += istep(t * 2, length(uv1 - vec2(-t * 2.5, 0)));
|
||||
f -= 2 * istep(t, length(uv1 - vec2(t * 2.5, 0)));
|
||||
f -= 2 * istep(t, length(uv1 - vec2(0, 0)));
|
||||
f -= 2 * istep(t, length(uv1 - vec2(-t * 2.5, 0)));
|
||||
f *= step(-t * 0.5, uv1.y);
|
||||
} else if (k < 60) { // switch
|
||||
f += istep(t, length(uv1 - vec2(t * 2.5, 0)));
|
||||
@@ -234,11 +234,11 @@ subroutine(src_stage_sub) vec4 src_4(vec2 vUV, int seed, vec3 b1, vec2 f1, vec3
|
||||
}
|
||||
|
||||
// SRC 5 : noise
|
||||
subroutine(src_stage_sub) vec4 src_5(vec2 vUV, int seed, vec3 b1, vec2 f1, vec3 b2, vec2 f2, vec3 b3, vec2 f3)
|
||||
subroutine ( src_stage_sub ) vec4 src_5(vec2 vUV, int seed, vec3 b1, vec2 f1, vec3 b2, vec2 f2, vec3 b3, vec2 f3)
|
||||
{
|
||||
// start
|
||||
|
||||
vec2 uv0 = vUV.st;
|
||||
vec2 uv0 = vUV.st;
|
||||
float ratio = iResolution.x / iResolution.y;
|
||||
vec2 uv1 = (uv0 - .5) * vec2(ratio, 1);
|
||||
|
||||
@@ -264,23 +264,23 @@ subroutine(src_stage_sub) vec4 src_5(vec2 vUV, int seed, vec3 b1, vec2 f1, vec3
|
||||
}
|
||||
|
||||
// SRC 6 : video in 1 + thru
|
||||
subroutine(src_stage_sub) vec4 src_6(vec2 vUV, int seed, vec3 b1, vec2 f1, vec3 b2, vec2 f2, vec3 b3, vec2 f3)
|
||||
subroutine ( src_stage_sub ) vec4 src_6(vec2 vUV, int seed, vec3 b1, vec2 f1, vec3 b2, vec2 f2, vec3 b3, vec2 f3)
|
||||
{
|
||||
if (iDemo > 0) {
|
||||
return src_2(vUV, seed, b1, f1, b2, f2, b3, f3);
|
||||
}
|
||||
|
||||
return src_thru(vUV, iTex3, seed, b1, f1, b2, f2, b3, f3);
|
||||
return src_thru(vUV, iTex5, seed, b1, f1, b2, f2, b3, f3);
|
||||
}
|
||||
|
||||
#include inc_cp437.glsl
|
||||
|
||||
// SRC 7 : cp437
|
||||
subroutine(src_stage_sub) vec4 src_7(vec2 vUV, int seed, vec3 b1, vec2 f1, vec3 b2, vec2 f2, vec3 b3, vec2 f3)
|
||||
subroutine ( src_stage_sub ) vec4 src_7(vec2 vUV, int seed, vec3 b1, vec2 f1, vec3 b2, vec2 f2, vec3 b3, vec2 f3)
|
||||
{
|
||||
// start
|
||||
|
||||
vec2 uv0 = vUV.st;
|
||||
vec2 uv0 = vUV.st;
|
||||
float ratio = iResolution.x / iResolution.y;
|
||||
vec2 uv1 = (uv0 - .5) * vec2(ratio, 1);
|
||||
|
||||
@@ -312,11 +312,11 @@ subroutine(src_stage_sub) vec4 src_7(vec2 vUV, int seed, vec3 b1, vec2 f1, vec3
|
||||
|
||||
#include inc_sentences.glsl
|
||||
|
||||
subroutine(src_stage_sub) vec4 src_8(vec2 vUV, int seed, vec3 b1, vec2 f1, vec3 b2, vec2 f2, vec3 b3, vec2 f3)
|
||||
subroutine ( src_stage_sub ) vec4 src_8(vec2 vUV, int seed, vec3 b1, vec2 f1, vec3 b2, vec2 f2, vec3 b3, vec2 f3)
|
||||
{
|
||||
// start
|
||||
|
||||
vec2 uv0 = vUV.st;
|
||||
vec2 uv0 = vUV.st;
|
||||
float ratio = iResolution.x / iResolution.y;
|
||||
vec2 uv1 = (uv0 - .5) * vec2(ratio, 1);
|
||||
|
||||
@@ -341,11 +341,11 @@ subroutine(src_stage_sub) vec4 src_8(vec2 vUV, int seed, vec3 b1, vec2 f1, vec3
|
||||
}
|
||||
|
||||
// SRC 9 : sentences repeat
|
||||
subroutine(src_stage_sub) vec4 src_9(vec2 vUV, int seed, vec3 b1, vec2 f1, vec3 b2, vec2 f2, vec3 b3, vec2 f3)
|
||||
subroutine ( src_stage_sub ) vec4 src_9(vec2 vUV, int seed, vec3 b1, vec2 f1, vec3 b2, vec2 f2, vec3 b3, vec2 f3)
|
||||
{
|
||||
// start
|
||||
// start
|
||||
|
||||
vec2 uv0 = vUV.st;
|
||||
vec2 uv0 = vUV.st;
|
||||
float ratio = iResolution.x / iResolution.y;
|
||||
vec2 uv1 = (uv0 - .5) * vec2(ratio, 1);
|
||||
|
||||
@@ -376,11 +376,11 @@ subroutine(src_stage_sub) vec4 src_9(vec2 vUV, int seed, vec3 b1, vec2 f1, vec3
|
||||
}
|
||||
|
||||
// SRC 10 : isometric grid
|
||||
subroutine(src_stage_sub) vec4 src_10(vec2 vUV, int seed, vec3 b1, vec2 f1, vec3 b2, vec2 f2, vec3 b3, vec2 f3)
|
||||
subroutine ( src_stage_sub ) vec4 src_10(vec2 vUV, int seed, vec3 b1, vec2 f1, vec3 b2, vec2 f2, vec3 b3, vec2 f3)
|
||||
{
|
||||
// start
|
||||
|
||||
vec2 uv0 = vUV.st;
|
||||
vec2 uv0 = vUV.st;
|
||||
float ratio = iResolution.x / iResolution.y;
|
||||
vec2 uv1 = (uv0 - .5) * vec2(ratio, 1);
|
||||
|
||||
@@ -420,29 +420,29 @@ subroutine(src_stage_sub) vec4 src_10(vec2 vUV, int seed, vec3 b1, vec2 f1, vec3
|
||||
float f = 0;
|
||||
|
||||
f = line(uv3, vec2(0, 0) - iso_z(e0), vec2(1, 0) - iso_z(e1), thick)
|
||||
+ line(uv3, vec2(0, 0) - iso_z(e0), vec2(0, 1) - iso_z(e2), thick)
|
||||
+ line(uv3, vec2(0, 0) - iso_z(e0), vec2(-1, 0) - iso_z(e3), thick)
|
||||
+ line(uv3, vec2(0, 0) - iso_z(e0), vec2(0, -1) - iso_z(e4), thick);
|
||||
+ line(uv3, vec2(0, 0) - iso_z(e0), vec2(0, 1) - iso_z(e2), thick)
|
||||
+ line(uv3, vec2(0, 0) - iso_z(e0), vec2(-1, 0) - iso_z(e3), thick)
|
||||
+ line(uv3, vec2(0, 0) - iso_z(e0), vec2(0, -1) - iso_z(e4), thick);
|
||||
|
||||
return vec4(f);
|
||||
}
|
||||
|
||||
// SRC 11 : video in 2 + thru
|
||||
subroutine(src_stage_sub) vec4 src_11(vec2 vUV, int seed, vec3 b1, vec2 f1, vec3 b2, vec2 f2, vec3 b3, vec2 f3)
|
||||
subroutine ( src_stage_sub ) vec4 src_11(vec2 vUV, int seed, vec3 b1, vec2 f1, vec3 b2, vec2 f2, vec3 b3, vec2 f3)
|
||||
{
|
||||
if (iDemo > 0) {
|
||||
return src_3(vUV, seed, b1, f1, b2, f2, b3, f3);
|
||||
}
|
||||
|
||||
return src_thru(vUV, iTex4, seed, b1, f1, b2, f2, b3, f3);
|
||||
return src_thru(vUV, iTex6, seed, b1, f1, b2, f2, b3, f3);
|
||||
}
|
||||
|
||||
// SRC 12 : Scales
|
||||
subroutine(src_stage_sub) vec4 src_12(vec2 vUV, int seed, vec3 b1, vec2 f1, vec3 b2, vec2 f2, vec3 b3, vec2 f3)
|
||||
subroutine ( src_stage_sub ) vec4 src_12(vec2 vUV, int seed, vec3 b1, vec2 f1, vec3 b2, vec2 f2, vec3 b3, vec2 f3)
|
||||
{
|
||||
// start
|
||||
|
||||
vec2 uv0 = vUV.st;
|
||||
vec2 uv0 = vUV.st;
|
||||
float ratio = iResolution.x / iResolution.y;
|
||||
vec2 uv1 = (uv0 - .5) * vec2(ratio, 1);
|
||||
|
||||
@@ -481,11 +481,11 @@ subroutine(src_stage_sub) vec4 src_12(vec2 vUV, int seed, vec3 b1, vec2 f1, vec3
|
||||
}
|
||||
|
||||
// SRC 13 : Credenza
|
||||
subroutine(src_stage_sub) vec4 src_13(vec2 vUV, int seed, vec3 b1, vec2 f1, vec3 b2, vec2 f2, vec3 b3, vec2 f3)
|
||||
subroutine ( src_stage_sub ) vec4 src_13(vec2 vUV, int seed, vec3 b1, vec2 f1, vec3 b2, vec2 f2, vec3 b3, vec2 f3)
|
||||
{
|
||||
// start
|
||||
|
||||
vec2 uv0 = vUV.st;
|
||||
vec2 uv0 = vUV.st;
|
||||
float ratio = iResolution.x / iResolution.y;
|
||||
vec2 uv1 = (uv0 - .5) * vec2(ratio, 1);
|
||||
|
||||
@@ -513,11 +513,11 @@ subroutine(src_stage_sub) vec4 src_13(vec2 vUV, int seed, vec3 b1, vec2 f1, vec3
|
||||
}
|
||||
|
||||
// SRC 14 : Cursor
|
||||
subroutine(src_stage_sub) vec4 src_14(vec2 vUV, int seed, vec3 b1, vec2 f1, vec3 b2, vec2 f2, vec3 b3, vec2 f3)
|
||||
subroutine ( src_stage_sub ) vec4 src_14(vec2 vUV, int seed, vec3 b1, vec2 f1, vec3 b2, vec2 f2, vec3 b3, vec2 f3)
|
||||
{
|
||||
// start
|
||||
|
||||
vec2 uv0 = vUV.st;
|
||||
vec2 uv0 = vUV.st;
|
||||
float ratio = iResolution.x / iResolution.y;
|
||||
vec2 uv1 = (uv0 - .5) * vec2(ratio, 1);
|
||||
|
||||
@@ -551,7 +551,7 @@ subroutine(src_stage_sub) vec4 src_14(vec2 vUV, int seed, vec3 b1, vec2 f1, vec3
|
||||
|
||||
uv2.y += 0.1;
|
||||
|
||||
f -= istep(0, (uv2.x + uv2.y * 3) * (uv2.x - uv2.y * 3)) * istep(0, uv2.y);
|
||||
f -= istep(0, (uv2.x + uv2.y * 3) * (uv2.x - uv2.y * 3)) * istep(0, uv2.y);
|
||||
|
||||
f += rect(uv2, vec2(0, -0.04), vec2(0.01, 0.04));
|
||||
|
||||
@@ -559,7 +559,7 @@ subroutine(src_stage_sub) vec4 src_14(vec2 vUV, int seed, vec3 b1, vec2 f1, vec3
|
||||
}
|
||||
|
||||
// SRC 15 : Random
|
||||
subroutine(src_stage_sub) vec4 src_15(vec2 vUV, int seed, vec3 b1, vec2 f1, vec3 b2, vec2 f2, vec3 b3, vec2 f3)
|
||||
subroutine ( src_stage_sub ) vec4 src_15(vec2 vUV, int seed, vec3 b1, vec2 f1, vec3 b2, vec2 f2, vec3 b3, vec2 f3)
|
||||
{
|
||||
int src = int(randTime(seed + 100) * 14);
|
||||
|
||||
|
||||
+16
-1
@@ -1,4 +1,3 @@
|
||||
#include <bsd/string.h>
|
||||
#include <limits.h>
|
||||
#include <log.h>
|
||||
#include <stdbool.h>
|
||||
@@ -33,6 +32,7 @@ static void print_help(int status_code) {
|
||||
#ifdef VIDEO_IN
|
||||
"[-vi=FILE] "
|
||||
"[-vs=SIZE] "
|
||||
"[-vr / -nvr] "
|
||||
#endif /* VIDEO_IN */
|
||||
"[-is=SIZE] "
|
||||
"[-ls / -nls] "
|
||||
@@ -64,6 +64,8 @@ static void print_help(int status_code) {
|
||||
"allowed)\n"
|
||||
" -vs, --video-size video capture desired height (default: "
|
||||
"internal texture height)\n"
|
||||
" -vr, --video-reconnect auto-reconnect video (default)\n"
|
||||
" -nvr, --no-video-reconnect do not auto-reconnect video\n"
|
||||
#endif /* VIDEO_IN */
|
||||
" -is, --internal-size internal texture height (default: 720)\n"
|
||||
" -ls, --load-state load saved state (default)\n"
|
||||
@@ -131,6 +133,7 @@ void args_parse(Parameters *params, int argc, char **argv) {
|
||||
params->auto_random_cycle = 4;
|
||||
params->video_in.length = 0;
|
||||
params->video_size = 0;
|
||||
params->video_reconnect = true;
|
||||
params->internal_size = 720;
|
||||
params->load_state = true;
|
||||
params->save_state = true;
|
||||
@@ -196,6 +199,18 @@ void args_parse(Parameters *params, int argc, char **argv) {
|
||||
}
|
||||
#else
|
||||
invalid_arg(arg);
|
||||
#endif /* VIDEO_IN */
|
||||
} else if (is_arg(arg, "-vr") || is_arg(arg, "--video-reconnect")) {
|
||||
#ifdef VIDEO_IN
|
||||
params->video_reconnect = true;
|
||||
#else
|
||||
invalid_arg(arg);
|
||||
#endif /* VIDEO_IN */
|
||||
} else if (is_arg(arg, "-nvr") || is_arg(arg, "--no-video-reconnect")) {
|
||||
#ifdef VIDEO_IN
|
||||
params->video_reconnect = false;
|
||||
#else
|
||||
invalid_arg(arg);
|
||||
#endif /* VIDEO_IN */
|
||||
} else if (is_arg(arg, "-is") || is_arg(arg, "--internal-size")) {
|
||||
params->internal_size = parse_uint(arg, value);
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#include <bsd/string.h>
|
||||
#include <hashmap.h>
|
||||
#include <log.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#include <bsd/string.h>
|
||||
#include <log.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
@@ -10,7 +9,6 @@
|
||||
#include "types.h"
|
||||
|
||||
#include "file.h"
|
||||
#include "string.h"
|
||||
|
||||
static time_t get_file_time(const File *file) {
|
||||
struct stat attr;
|
||||
|
||||
+101
-41
@@ -4,13 +4,12 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/wait.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "types.h"
|
||||
|
||||
#include "config.h"
|
||||
#include "config_file.h"
|
||||
#include "file.h"
|
||||
#include "forge.h"
|
||||
#include "midi.h"
|
||||
#include "project.h"
|
||||
@@ -22,24 +21,24 @@
|
||||
#include "video.h"
|
||||
#include "window.h"
|
||||
|
||||
static Parameters init_params;
|
||||
static SharedContext *context;
|
||||
static ShaderProgram program;
|
||||
static Window *window_output;
|
||||
static Window *window_monitor;
|
||||
static VideoCaptureArray inputs;
|
||||
static Timer timer;
|
||||
static MidiDevice midi;
|
||||
static bool trace_midi;
|
||||
static Project project;
|
||||
|
||||
static void compute_fps(bool trace_fps) {
|
||||
static void compute_fps() {
|
||||
double fps;
|
||||
char title[STR_LEN];
|
||||
|
||||
if (timer_inc(&timer)) {
|
||||
fps = timer_reset(&timer);
|
||||
|
||||
if (trace_fps) {
|
||||
if (init_params.trace_fps) {
|
||||
log_trace("(main) %.2ffps", fps);
|
||||
}
|
||||
|
||||
@@ -57,18 +56,16 @@ static void compute_fps(bool trace_fps) {
|
||||
}
|
||||
}
|
||||
|
||||
static void init_context(const Parameters *params) {
|
||||
static void init_context() {
|
||||
context = shared_init_context("/" PACKAGE "_context");
|
||||
|
||||
context->stop = false;
|
||||
|
||||
state_init(context, &project.state_config, params->demo, params->auto_random,
|
||||
params->auto_random_cycle, params->base_tempo, params->load_state);
|
||||
state_init(context, &project.state_config, init_params.demo,
|
||||
init_params.auto_random, init_params.auto_random_cycle,
|
||||
init_params.base_tempo, init_params.load_state);
|
||||
|
||||
memset(context->input_resolutions, 0, sizeof(context->input_resolutions));
|
||||
memset(context->input_formats, 0, sizeof(context->input_formats));
|
||||
memset(context->input_fps, 0, sizeof(context->input_fps));
|
||||
memset(context->input_swap, 0, sizeof(context->input_swap));
|
||||
}
|
||||
|
||||
static void free_context() { shared_close_context(context); }
|
||||
@@ -78,37 +75,83 @@ static void reload_shader(unsigned int i) {
|
||||
}
|
||||
|
||||
#ifdef VIDEO_IN
|
||||
static void init_inputs(const StringArray *video_in, unsigned int video_size) {
|
||||
inputs.length = video_in->length;
|
||||
static void init_inputs() {
|
||||
context->inputs.length = init_params.video_in.length;
|
||||
|
||||
for (unsigned int i = 0; i < video_in->length; i++) {
|
||||
video_init(&inputs.values[i], video_in->values[i], video_size);
|
||||
for (unsigned int i = 0; i < init_params.video_in.length; i++) {
|
||||
video_init(&context->inputs.values[i], init_params.video_in.values[i],
|
||||
init_params.video_size);
|
||||
|
||||
if (!inputs.values[i].error) {
|
||||
context->input_resolutions[i][0] = inputs.values[i].width;
|
||||
context->input_resolutions[i][1] = inputs.values[i].height;
|
||||
context->input_formats[i] = inputs.values[i].pixelformat;
|
||||
if (!context->inputs.values[i].error) {
|
||||
context->input_resolutions[i][0] = context->inputs.values[i].width;
|
||||
context->input_resolutions[i][1] = context->inputs.values[i].height;
|
||||
context->inputs.values[i].needs_reload = false;
|
||||
context->inputs.values[i].disconnected = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static bool start_video_captures(unsigned int video_count, bool trace_fps) {
|
||||
for (unsigned int i = 0; i < video_count; i++) {
|
||||
if (!inputs.values[i].error &&
|
||||
!video_background_read(&inputs.values[i], context, i, trace_fps)) {
|
||||
return false;
|
||||
static bool reconnect_video_captures() {
|
||||
for (unsigned int i = 0; i < init_params.video_in.length; i++) {
|
||||
if (context->inputs.values[i].disconnected) {
|
||||
video_init(&context->inputs.values[i], init_params.video_in.values[i],
|
||||
init_params.video_size);
|
||||
|
||||
if (!context->inputs.values[i].error) {
|
||||
context->input_resolutions[i][0] = context->inputs.values[i].width;
|
||||
context->input_resolutions[i][1] = context->inputs.values[i].height;
|
||||
|
||||
if (!video_background_read(&context->inputs.values[i], context, i,
|
||||
init_params.trace_fps)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
context->inputs.values[i].needs_reload = true;
|
||||
context->inputs.values[i].disconnected = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static void free_video_captures(unsigned int video_count) {
|
||||
for (unsigned int i = 0; i < video_count; i++) {
|
||||
shaders_free_input(&program, &inputs.values[i]);
|
||||
static bool start_video_captures() {
|
||||
pid_t pid;
|
||||
for (unsigned int i = 0; i < context->inputs.length; i++) {
|
||||
if (!context->inputs.values[i].error &&
|
||||
!video_background_read(&context->inputs.values[i], context, i,
|
||||
init_params.trace_fps)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (!init_params.video_reconnect) {
|
||||
return true;
|
||||
}
|
||||
pid = fork();
|
||||
if (pid < 0) {
|
||||
log_error("Could not create subprocess");
|
||||
return false;
|
||||
}
|
||||
if (pid == 0) {
|
||||
return true;
|
||||
}
|
||||
log_info("background reconnect acquisition started (pid: %d)", pid);
|
||||
while (!context->stop) {
|
||||
sleep(1);
|
||||
if (!reconnect_video_captures()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
video_free(&inputs.values[i]);
|
||||
static void free_video_captures() {
|
||||
for (unsigned int i = 0; i < context->inputs.length; i++) {
|
||||
shaders_free_input(&program, i);
|
||||
|
||||
video_free(&context->inputs.values[i]);
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* VIDEO_IN */
|
||||
|
||||
static void error_callback(int error, const char *description) {
|
||||
@@ -140,18 +183,20 @@ static void midi_callback(unsigned char code, unsigned char value) {
|
||||
}
|
||||
|
||||
static bool init(const Parameters *params) {
|
||||
init_params = *params;
|
||||
|
||||
project_init(&project, params->project_path, params->config_file);
|
||||
|
||||
if (project.error) {
|
||||
return false;
|
||||
}
|
||||
|
||||
init_context(params);
|
||||
init_context();
|
||||
|
||||
#ifdef VIDEO_IN
|
||||
init_inputs(¶ms->video_in, params->video_size);
|
||||
init_inputs();
|
||||
|
||||
if (!start_video_captures(params->video_in.length, params->trace_fps)) {
|
||||
if (!start_video_captures()) {
|
||||
return false;
|
||||
}
|
||||
#endif /* VIDEO_IN */
|
||||
@@ -200,7 +245,7 @@ static bool init(const Parameters *params) {
|
||||
}
|
||||
|
||||
#ifdef VIDEO_IN
|
||||
shaders_link_inputs(&program, &project, &inputs);
|
||||
shaders_link_inputs(&program, &project, &context->inputs);
|
||||
#endif /* VIDEO_IN */
|
||||
|
||||
if (program.error) {
|
||||
@@ -221,12 +266,23 @@ static bool should_close() {
|
||||
(window_monitor != NULL && window_should_close(window_monitor));
|
||||
}
|
||||
|
||||
static void loop(bool hr, bool trace_fps) {
|
||||
if (hr) {
|
||||
static bool loop() {
|
||||
if (init_params.hot_reload) {
|
||||
project_reload(&project, reload_shader);
|
||||
}
|
||||
|
||||
compute_fps(trace_fps);
|
||||
#ifdef VIDEO_IN
|
||||
if (init_params.video_reconnect) {
|
||||
for (unsigned int i = 0; i < context->inputs.length; i++) {
|
||||
if (context->inputs.values[i].needs_reload) {
|
||||
shaders_relink_input(&program, &project, &context->inputs, i);
|
||||
context->inputs.values[i].needs_reload = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif /* VIDEO_IN */
|
||||
|
||||
compute_fps();
|
||||
|
||||
context->time = window_get_time();
|
||||
context->tempo_total = (float)tempo_total(&context->tempo);
|
||||
@@ -248,12 +304,14 @@ static void loop(bool hr, bool trace_fps) {
|
||||
}
|
||||
|
||||
window_events();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void shutdown(const Parameters *params) {
|
||||
static void shutdown() {
|
||||
context->stop = true;
|
||||
|
||||
if (params->save_state) {
|
||||
if (init_params.save_state) {
|
||||
state_save(context, &project.state_config);
|
||||
}
|
||||
|
||||
@@ -268,11 +326,11 @@ static void shutdown(const Parameters *params) {
|
||||
if (window_monitor != NULL) {
|
||||
window_use(window_monitor, context);
|
||||
|
||||
shaders_free_window(&program, params->output);
|
||||
shaders_free_window(&program, init_params.output);
|
||||
}
|
||||
|
||||
#ifdef VIDEO_IN
|
||||
free_video_captures(params->video_in.length);
|
||||
free_video_captures();
|
||||
#endif /* VIDEO_IN */
|
||||
|
||||
free_context();
|
||||
@@ -288,8 +346,10 @@ void forge_run(const Parameters *params) {
|
||||
}
|
||||
|
||||
while (!should_close()) {
|
||||
loop(params->hot_reload, params->trace_fps);
|
||||
if (!loop()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
shutdown(params);
|
||||
shutdown();
|
||||
}
|
||||
+1
-1
@@ -17,7 +17,7 @@ int main(int argc, char **argv) {
|
||||
|
||||
puts(PACKAGE " " VERSION);
|
||||
|
||||
set_seed((unsigned long)time(NULL));
|
||||
rand_set_seed((unsigned long)time(NULL));
|
||||
|
||||
forge_run(¶ms);
|
||||
|
||||
|
||||
+3
-4
@@ -1,11 +1,10 @@
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <alsa/asoundlib.h>
|
||||
#include <bsd/string.h>
|
||||
#include <log.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "types.h"
|
||||
|
||||
#include "config.h"
|
||||
#include "log.h"
|
||||
|
||||
void midi_open(MidiDevice *device, const char *name) {
|
||||
strlcpy(device->name, name, STR_LEN);
|
||||
@@ -61,5 +60,5 @@ bool midi_background_listen(const MidiDevice *device,
|
||||
|
||||
log_info("(%s) background acquisition stopped by main thread (pid: %d)",
|
||||
device->name, pid);
|
||||
return false;
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
+1
-2
@@ -1,4 +1,4 @@
|
||||
#include <bsd/string.h>
|
||||
#include <log.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "types.h"
|
||||
@@ -6,7 +6,6 @@
|
||||
#include "config.h"
|
||||
#include "config_file.h"
|
||||
#include "file.h"
|
||||
#include "log.h"
|
||||
#include "project.h"
|
||||
#include "state.h"
|
||||
#include "string.h"
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ static unsigned long rand(void) {
|
||||
return (unsigned long)(x >> (22 + count));
|
||||
}
|
||||
|
||||
void set_seed(unsigned long long seed) {
|
||||
void rand_set_seed(unsigned long long seed) {
|
||||
mcg_state = 2 * seed + 1;
|
||||
(void)rand();
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
#ifndef RAND_H
|
||||
#define RAND_H
|
||||
|
||||
void set_seed(unsigned long long seed);
|
||||
void rand_set_seed(unsigned long long seed);
|
||||
unsigned int rand_uint(unsigned int max);
|
||||
|
||||
#endif
|
||||
+282
-100
@@ -26,20 +26,49 @@
|
||||
|
||||
static const GLuint unused_uniform = (GLuint)-1;
|
||||
|
||||
bool check_glerror(ShaderProgram *program) {
|
||||
bool check_glerror_ro(const char *context) {
|
||||
unsigned int code;
|
||||
|
||||
code = glGetError();
|
||||
|
||||
if (code > 0) {
|
||||
log_warn("GL Error: %04x", code);
|
||||
program->error = true;
|
||||
log_warn("GL Error: %04x (%s)", code, context);
|
||||
return true;
|
||||
}
|
||||
|
||||
return code > 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
static void init_gl(ShaderProgram *program) {
|
||||
bool check_glerror(ShaderProgram *program, const char *context) {
|
||||
if (check_glerror_ro(context)) {
|
||||
program->error = true;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool check_eglerror_ro(const char *context) {
|
||||
unsigned int code;
|
||||
|
||||
code = eglGetError();
|
||||
|
||||
if (code > 0 && code != EGL_SUCCESS) {
|
||||
log_warn("EGL Error: %04x (%s)", code, context);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool check_eglerror(ShaderProgram *program, const char *context) {
|
||||
if (check_eglerror_ro(context)) {
|
||||
program->error = true;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool init_gl(ShaderProgram *program) {
|
||||
gladLoadGL(glfwGetProcAddress);
|
||||
|
||||
#ifdef VIDEO_IN
|
||||
@@ -47,48 +76,88 @@ static void init_gl(ShaderProgram *program) {
|
||||
if (program->egl_display == EGL_NO_DISPLAY) {
|
||||
log_error("error: glfwGetEGLDisplay no EGLDisplay returned");
|
||||
program->error = true;
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
gladLoadEGL(program->egl_display, glfwGetProcAddress);
|
||||
#endif /* VIDEO_IN */
|
||||
|
||||
return !check_glerror(program, "init_gl") &&
|
||||
!check_eglerror(program, "init_gl");
|
||||
}
|
||||
|
||||
static void init_textures(ShaderProgram *program,
|
||||
static bool init_textures(ShaderProgram *program,
|
||||
const SharedContext *context) {
|
||||
glGenTextures(program->tex_count, program->textures);
|
||||
if (check_glerror(program, "init_textures/glGenTextures")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (unsigned int i = 0; i < program->tex_count; i++) {
|
||||
// selects which texture unit subsequent texture state calls will affect
|
||||
glActiveTexture(GL_TEXTURE0 + i);
|
||||
if (check_glerror(program, "init_textures/glActiveTexture")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, program->textures[i]);
|
||||
if (check_glerror(program, "init_textures/glBindTexture")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glDisable(GL_BLEND);
|
||||
if (check_glerror(program, "init_textures/glDisable")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// define texture image as empty
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, context->tex_resolution[0],
|
||||
context->tex_resolution[1], 0, GL_RGB, GL_UNSIGNED_BYTE, 0);
|
||||
if (check_glerror(program, "init_textures/glTexImage2D")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// setup mipmap context
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
if (check_glerror(program, "init_textures/glTexParameteri")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
log_info("Texture %d initialized", i);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void rebind_textures(const ShaderProgram *program) {
|
||||
for (unsigned int i = 0; i < program->tex_count; i++) {
|
||||
glActiveTexture(GL_TEXTURE0 + i);
|
||||
check_glerror_ro("rebind_textures/glActiveTexture");
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, program->textures[i]);
|
||||
check_glerror_ro("rebind_textures/glBindTexture");
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef VIDEO_IN
|
||||
static void link_input_to_texture(ShaderProgram *program, VideoCapture *input,
|
||||
unsigned int texture_index, bool swap) {
|
||||
static bool link_input_to_texture(ShaderProgram *program, VideoCapture *input,
|
||||
unsigned int input_index,
|
||||
unsigned int texture_index, bool swap,
|
||||
bool reload) {
|
||||
if (reload) {
|
||||
glDeleteTextures(1, program->textures + texture_index);
|
||||
if (check_glerror(program, "link_input_to_texture/glDeleteTextures")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
glGenTextures(1, program->textures + texture_index);
|
||||
if (check_glerror(program, "link_input_to_texture/glGenTextures")) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
EGLImageKHR dma_image;
|
||||
|
||||
dma_image = EGL_NO_IMAGE_KHR;
|
||||
@@ -110,59 +179,81 @@ static void link_input_to_texture(ShaderProgram *program, VideoCapture *input,
|
||||
|
||||
dma_image = eglCreateImageKHR(program->egl_display, EGL_NO_CONTEXT,
|
||||
EGL_LINUX_DMA_BUF_EXT, NULL, attrib_list);
|
||||
|
||||
if (swap) {
|
||||
input->dma_image_swap = dma_image;
|
||||
} else {
|
||||
input->dma_image = dma_image;
|
||||
if (check_eglerror(program, "link_input_to_texture/eglCreateImageKHR")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (dma_image == EGL_NO_IMAGE_KHR) {
|
||||
log_error("(%s) eglCreateImageKHR failed %04x", input->name, eglGetError());
|
||||
return;
|
||||
if (swap) {
|
||||
program->dma_images_swap[input_index] = dma_image;
|
||||
} else {
|
||||
program->dma_images[input_index] = dma_image;
|
||||
}
|
||||
|
||||
glActiveTexture(GL_TEXTURE0 + texture_index);
|
||||
if (check_glerror(program, "link_input_to_texture/glActiveTexture")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, program->textures[texture_index]);
|
||||
if (check_glerror(program, "link_input_to_texture/glBindTexture")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, input->width, input->height, 0, GL_RGB,
|
||||
GL_UNSIGNED_BYTE, 0);
|
||||
if (check_glerror(program, "link_input_to_texture/glTexImage2D")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// https://registry.khronos.org/OpenGL/extensions/EXT/EXT_EGL_image_storage.txt
|
||||
glEGLImageTargetTexStorageEXT(GL_TEXTURE_2D, input->dma_image, NULL);
|
||||
glEGLImageTargetTexStorageEXT(GL_TEXTURE_2D, dma_image, NULL);
|
||||
if (check_eglerror(program,
|
||||
"link_input_to_texture/glEGLImageTargetTexStorageEXT")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
log_info("Texture %d linked to %s", texture_index, input->name);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void init_input(ShaderProgram *program, const ConfigFile *config,
|
||||
VideoCaptureArray *inputs) {
|
||||
static bool init_input(ShaderProgram *program, const ConfigFile *config,
|
||||
VideoCaptureArray *inputs, unsigned int i, bool reload) {
|
||||
unsigned int tex_i;
|
||||
char name[STR_LEN];
|
||||
|
||||
for (unsigned int i = 0; i < program->in_count; i++) {
|
||||
if (i < inputs->length && !inputs->values[i].error) {
|
||||
snprintf(name, STR_LEN, "IN_%d_OUT", i + 1);
|
||||
tex_i = config_file_get_int(config, name, 0);
|
||||
link_input_to_texture(program, &inputs->values[i], tex_i, false);
|
||||
if (inputs->values[i].with_swap) {
|
||||
snprintf(name, STR_LEN, "IN_%d_SWAP_OUT", i + 1);
|
||||
tex_i = config_file_get_int(config, name, 0);
|
||||
link_input_to_texture(program, &inputs->values[i], tex_i, true);
|
||||
}
|
||||
} else {
|
||||
log_warn("Cannot link input %d", i + 1);
|
||||
if (i < inputs->length && !inputs->values[i].error) {
|
||||
snprintf(name, STR_LEN, "IN_%d_OUT", i + 1);
|
||||
tex_i = config_file_get_int(config, name, 0);
|
||||
if (!link_input_to_texture(program, &inputs->values[i], i, tex_i, false,
|
||||
reload)) {
|
||||
return false;
|
||||
}
|
||||
if (inputs->values[i].with_swap) {
|
||||
snprintf(name, STR_LEN, "IN_%d_SWAP_OUT", i + 1);
|
||||
tex_i = config_file_get_int(config, name, 0);
|
||||
if (!link_input_to_texture(program, &inputs->values[i], i, tex_i, true,
|
||||
reload)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
log_warn("Cannot link input %d", i + 1);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
#endif /* VIDEO_IN */
|
||||
|
||||
static void init_framebuffers(ShaderProgram *program,
|
||||
static bool init_framebuffers(ShaderProgram *program,
|
||||
const ConfigFile *config) {
|
||||
unsigned int tex_i;
|
||||
char name[STR_LEN];
|
||||
GLenum framebuffer_status;
|
||||
|
||||
glGenFramebuffers(program->frag_count, program->frame_buffers);
|
||||
if (check_glerror(program, "init_framebuffers/glGenFramebuffers")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (unsigned int i = 0; i < program->frag_count; i++) {
|
||||
if (i == program->frag_output_index || i == program->frag_monitor_index) {
|
||||
@@ -170,48 +261,87 @@ static void init_framebuffers(ShaderProgram *program,
|
||||
}
|
||||
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, program->frame_buffers[i]);
|
||||
if (check_glerror(program, "init_framebuffers/glBindFramebuffer")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
snprintf(name, STR_LEN, "FRAG_%d_OUT", i + 1);
|
||||
tex_i = config_file_get_int(config, name, 0);
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
|
||||
program->textures[tex_i], 0);
|
||||
if (check_glerror(program, "init_framebuffers/glFramebufferTexture2D")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// check framebuffer status
|
||||
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
|
||||
log_error("Framebuffer %d is KO: %x", i + 1,
|
||||
glCheckFramebufferStatus(GL_FRAMEBUFFER));
|
||||
|
||||
framebuffer_status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
|
||||
if (check_glerror(program, "init_framebuffers/glCheckFramebufferStatus")) {
|
||||
return false;
|
||||
}
|
||||
if (framebuffer_status != GL_FRAMEBUFFER_COMPLETE) {
|
||||
log_error("Framebuffer %d is KO: %x", i + 1, framebuffer_status);
|
||||
program->error = true;
|
||||
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
log_info("Framebuffer %d initialized", i);
|
||||
}
|
||||
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
|
||||
static void init_vertices(ShaderProgram *program) {
|
||||
static bool init_vertices(ShaderProgram *program) {
|
||||
glGenBuffers(1, &program->vertex_buffer);
|
||||
if (check_glerror(program, "init_vertices/glGenBuffers")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, program->vertex_buffer);
|
||||
if (check_glerror(program, "init_vertices/glBindBuffer")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
|
||||
if (check_glerror(program, "init_vertices/glBufferData")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void bind_vertices(ShaderProgram *program, unsigned int index) {
|
||||
static bool bind_vertices(ShaderProgram *program, unsigned int index) {
|
||||
glBindBuffer(GL_ARRAY_BUFFER, program->vertex_buffer);
|
||||
if (check_glerror(program, "bind_vertices/glBindBuffer")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
glGenVertexArrays(1, &program->vertex_array[index]);
|
||||
if (check_glerror(program, "bind_vertices/glGenVertexArrays")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
glBindVertexArray(program->vertex_array[index]);
|
||||
if (check_glerror(program, "bind_vertices/glBindVertexArray")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (unsigned int i = 0; i < program->frag_count; i++) {
|
||||
// enable attribute pointer
|
||||
glEnableVertexAttribArray(program->vpos_locations[i]);
|
||||
if (check_glerror(program, "bind_vertices/glEnableVertexAttribArray")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// specify the location and data format of the array of generic vertex
|
||||
// attributes to use when rendering
|
||||
glVertexAttribPointer(program->vpos_locations[i], 2, GL_FLOAT, GL_FALSE,
|
||||
sizeof(Vertex), (void *)offsetof(Vertex, pos));
|
||||
if (check_glerror(program, "bind_vertices/glVertexAttribPointer")) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool compile_shader(GLuint shader_id, const char *name,
|
||||
@@ -223,13 +353,18 @@ static bool compile_shader(GLuint shader_id, const char *name,
|
||||
|
||||
// update shader source code
|
||||
glShaderSource(shader_id, 1, &source_code, NULL);
|
||||
check_glerror_ro("compile_shader/glShaderSource");
|
||||
|
||||
// compile shader
|
||||
glCompileShader(shader_id);
|
||||
check_glerror_ro("compile_shader/glCompileShader");
|
||||
|
||||
// get compilation status
|
||||
glGetShaderiv(shader_id, GL_COMPILE_STATUS, &status_params);
|
||||
check_glerror_ro("compile_shader/glGetShaderiv");
|
||||
|
||||
glGetShaderInfoLog(shader_id, 1024, NULL, (GLchar *)&log);
|
||||
check_glerror_ro("compile_shader/glGetShaderInfoLog");
|
||||
|
||||
if (status_params == GL_FALSE) {
|
||||
log_error("Failed to compile\n%s", log);
|
||||
@@ -241,9 +376,13 @@ static bool compile_shader(GLuint shader_id, const char *name,
|
||||
return status_params == GL_TRUE;
|
||||
}
|
||||
|
||||
static void init_shaders(ShaderProgram *program, const Project *project) {
|
||||
static bool init_shaders(ShaderProgram *program, const Project *project) {
|
||||
// compile vertex shader
|
||||
program->vertex_shader = glCreateShader(GL_VERTEX_SHADER);
|
||||
if (check_glerror(program, "init_shaders/glCreateShader")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
program->error = program->error || !compile_shader(program->vertex_shader,
|
||||
"internal vertex shader",
|
||||
vertex_shader_text);
|
||||
@@ -251,18 +390,24 @@ static void init_shaders(ShaderProgram *program, const Project *project) {
|
||||
// compile fragment shaders
|
||||
for (unsigned int i = 0; i < program->frag_count; i++) {
|
||||
program->fragment_shaders[i] = glCreateShader(GL_FRAGMENT_SHADER);
|
||||
if (check_glerror(program, "init_shaders/glCreateShader")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
program->error = program->error ||
|
||||
!compile_shader(program->fragment_shaders[i],
|
||||
project->fragment_shaders[i][0].path,
|
||||
project->fragment_shaders[i][0].content);
|
||||
|
||||
if (program->error) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void init_single_program(ShaderProgram *program, unsigned int i,
|
||||
static bool init_single_program(ShaderProgram *program, unsigned int i,
|
||||
const ConfigFile *config,
|
||||
const StateConfig *state_config) {
|
||||
unsigned int index1;
|
||||
@@ -271,10 +416,20 @@ static void init_single_program(ShaderProgram *program, unsigned int i,
|
||||
const char *prefix;
|
||||
|
||||
program->programs[i] = glCreateProgram();
|
||||
if (check_glerror(program, "init_single_program/glCreateProgram")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
glAttachShader(program->programs[i], program->vertex_shader);
|
||||
glAttachShader(program->programs[i], program->fragment_shaders[i]);
|
||||
if (check_glerror(program, "init_single_program/glAttachShader")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
glLinkProgram(program->programs[i]);
|
||||
if (check_glerror(program, "init_single_program/glLinkProgram")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// create uniforms pointers
|
||||
program->itime_locations[i] = glGetUniformLocation(
|
||||
@@ -354,18 +509,6 @@ static void init_single_program(ShaderProgram *program, unsigned int i,
|
||||
glGetUniformLocation(program->programs[i], name);
|
||||
}
|
||||
|
||||
for (unsigned int j = 0; j < program->sub_type_count; j++) {
|
||||
snprintf(name, STR_LEN, "SUB_%d_PREFIX", j + 1);
|
||||
prefix = config_file_get_str(config, name, 0);
|
||||
for (unsigned int k = 0; k < program->sub_variant_count; k++) {
|
||||
snprintf(name, STR_LEN, "%s%d", prefix, k + 1);
|
||||
program->sub_locations[i * program->sub_variant_count *
|
||||
program->sub_type_count +
|
||||
j * program->sub_variant_count + k] =
|
||||
glGetSubroutineIndex(program->programs[i], GL_FRAGMENT_SHADER, name);
|
||||
}
|
||||
}
|
||||
|
||||
prefix = config_file_get_str(config, "UNIFORM_ACTIVE_PREFIX", "iActive");
|
||||
for (unsigned int j = 0; j < program->active_count; j++) {
|
||||
snprintf(name, STR_LEN, "%s%d", prefix, j + 1);
|
||||
@@ -404,18 +547,48 @@ static void init_single_program(ShaderProgram *program, unsigned int i,
|
||||
glGetUniformLocation(program->programs[i], name);
|
||||
}
|
||||
|
||||
if (check_glerror(program, "init_single_program/glGetUniformLocation")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (unsigned int j = 0; j < program->sub_type_count; j++) {
|
||||
snprintf(name, STR_LEN, "SUB_%d_PREFIX", j + 1);
|
||||
prefix = config_file_get_str(config, name, 0);
|
||||
for (unsigned int k = 0; k < program->sub_variant_count; k++) {
|
||||
snprintf(name, STR_LEN, "%s%d", prefix, k + 1);
|
||||
program->sub_locations[i * program->sub_variant_count *
|
||||
program->sub_type_count +
|
||||
j * program->sub_variant_count + k] =
|
||||
glGetSubroutineIndex(program->programs[i], GL_FRAGMENT_SHADER, name);
|
||||
}
|
||||
}
|
||||
|
||||
if (check_glerror(program, "init_single_program/glGetSubroutineIndex")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// create attribute pointer
|
||||
program->vpos_locations[i] =
|
||||
glGetAttribLocation(program->programs[i], "vPos");
|
||||
|
||||
if (check_glerror(program, "init_single_program/glGetAttribLocation")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
log_info("Program %d initialized", i + 1);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void init_programs(ShaderProgram *program, const ConfigFile *config,
|
||||
static bool init_programs(ShaderProgram *program, const ConfigFile *config,
|
||||
const StateConfig *state_config) {
|
||||
for (unsigned int i = 0; i < program->frag_count; i++) {
|
||||
init_single_program(program, i, config, state_config);
|
||||
if (!init_single_program(program, i, config, state_config)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void update_viewport(ShaderProgram *program,
|
||||
@@ -426,8 +599,12 @@ static void update_viewport(ShaderProgram *program,
|
||||
// clean and resize all textures
|
||||
for (unsigned int i = 0; i < program->tex_count; i++) {
|
||||
glActiveTexture(GL_TEXTURE0 + i);
|
||||
check_glerror_ro("update_viewport/glActiveTexture");
|
||||
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, context->tex_resolution[0],
|
||||
context->tex_resolution[1], 0, GL_RGB, GL_UNSIGNED_BYTE, 0);
|
||||
check_glerror_ro(
|
||||
"update_viewport/glTexImage2D"); // TODO dont remap input textures
|
||||
}
|
||||
program->last_resolution[0] = context->resolution[0];
|
||||
program->last_resolution[1] = context->resolution[1];
|
||||
@@ -507,11 +684,11 @@ static void use_program(const ShaderProgram *program, int i, bool output,
|
||||
write_uniform_2f(program->iinres_locations[i * program->in_count + j],
|
||||
&context->input_resolutions[j]);
|
||||
write_uniform_1i(program->iinfmt_locations[i * program->in_count + j],
|
||||
context->input_formats[j]);
|
||||
context->inputs.values[j].pixelformat);
|
||||
write_uniform_1i(program->iinfps_locations[i * program->in_count + j],
|
||||
context->input_fps[j]);
|
||||
context->inputs.values[j].fps);
|
||||
write_uniform_1i(program->iinswap_locations[i * program->in_count + j],
|
||||
context->input_swap[j] ? 1 : 0);
|
||||
context->inputs.values[j].swap ? 1 : 0);
|
||||
}
|
||||
|
||||
// set seeds uniforms
|
||||
@@ -581,71 +758,64 @@ void shaders_init(ShaderProgram *program, const Project *project,
|
||||
program->active_count = project->state_config.midi_active_counts.length;
|
||||
program->midi_lengths.length = 0;
|
||||
|
||||
init_gl(program);
|
||||
#ifdef VIDEO_IN
|
||||
memset(program->dma_images, 0, sizeof(program->dma_images));
|
||||
memset(program->dma_images_swap, 0, sizeof(program->dma_images_swap));
|
||||
#endif /* VIDEO_IN */
|
||||
|
||||
if (check_glerror(program)) {
|
||||
if (!init_gl(program)) {
|
||||
return;
|
||||
}
|
||||
|
||||
init_shaders(program, project);
|
||||
|
||||
if (program->error || check_glerror(program)) {
|
||||
if (!init_shaders(program, project)) {
|
||||
return;
|
||||
}
|
||||
|
||||
init_textures(program, context);
|
||||
|
||||
if (check_glerror(program)) {
|
||||
if (!init_textures(program, context)) {
|
||||
return;
|
||||
}
|
||||
|
||||
init_framebuffers(program, &project->config);
|
||||
|
||||
if (check_glerror(program)) {
|
||||
if (!init_framebuffers(program, &project->config)) {
|
||||
return;
|
||||
}
|
||||
|
||||
init_programs(program, &project->config, &project->state_config);
|
||||
|
||||
if (check_glerror(program)) {
|
||||
if (!init_programs(program, &project->config, &project->state_config)) {
|
||||
return;
|
||||
}
|
||||
|
||||
init_vertices(program);
|
||||
|
||||
if (check_glerror(program)) {
|
||||
if (!init_vertices(program)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
bind_vertices(program, rebind ? 1 : 0);
|
||||
|
||||
if (check_glerror(program)) {
|
||||
if (!bind_vertices(program, rebind ? 1 : 0)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void shaders_relink_input(ShaderProgram *program, const Project *project,
|
||||
VideoCaptureArray *inputs, unsigned int i) {
|
||||
#ifdef VIDEO_IN
|
||||
// shaders_free_input(program, i);
|
||||
init_input(program, &project->config, inputs, i, true);
|
||||
#endif /* VIDEO_IN */
|
||||
}
|
||||
|
||||
void shaders_link_inputs(ShaderProgram *program, const Project *project,
|
||||
VideoCaptureArray *inputs) {
|
||||
#ifdef VIDEO_IN
|
||||
init_input(program, &project->config, inputs);
|
||||
|
||||
if (check_glerror(program)) {
|
||||
return;
|
||||
for (unsigned int i = 0; i < program->in_count; i++) {
|
||||
init_input(program, &project->config, inputs, i, false);
|
||||
}
|
||||
#endif /* VIDEO_IN */
|
||||
}
|
||||
|
||||
void shaders_update(ShaderProgram *program, const File *fragment_shader,
|
||||
unsigned int i, const Project *project) {
|
||||
bool result;
|
||||
|
||||
result = compile_shader(program->fragment_shaders[i], fragment_shader->path,
|
||||
fragment_shader->content);
|
||||
|
||||
if (result) {
|
||||
init_single_program(program, i, &project->config, &project->state_config);
|
||||
|
||||
if (compile_shader(program->fragment_shaders[i], fragment_shader->path,
|
||||
fragment_shader->content) &&
|
||||
init_single_program(program, i, &project->config,
|
||||
&project->state_config)) {
|
||||
log_info("Program %d updated", i + 1);
|
||||
}
|
||||
}
|
||||
@@ -672,30 +842,42 @@ void shaders_compute(ShaderProgram *program, const SharedContext *context,
|
||||
monitor ? program->frag_monitor_index
|
||||
: program->frag_output_index,
|
||||
true, context);
|
||||
|
||||
check_glerror(program, "shaders_compute");
|
||||
}
|
||||
|
||||
void shaders_free(const ShaderProgram *program) {
|
||||
for (unsigned int i = 0; i < program->frag_count; i++) {
|
||||
glDeleteProgram(program->programs[i]);
|
||||
}
|
||||
check_glerror_ro("shaders_free/glDeleteProgram");
|
||||
|
||||
glDeleteFramebuffers(program->frag_count, program->frame_buffers);
|
||||
check_glerror_ro("shaders_free/glDeleteFramebuffers");
|
||||
|
||||
glDeleteTextures(program->tex_count, program->textures);
|
||||
check_glerror_ro("shaders_free/glDeleteTextures");
|
||||
|
||||
glDeleteBuffers(1, &program->vertex_buffer);
|
||||
check_glerror_ro("shaders_free/glDeleteBuffers");
|
||||
}
|
||||
|
||||
void shaders_free_window(const ShaderProgram *program, bool secondary) {
|
||||
glDeleteVertexArrays(1, &program->vertex_array[secondary ? 1 : 0]);
|
||||
check_glerror_ro("shaders_free_window/glDeleteVertexArrays");
|
||||
}
|
||||
|
||||
void shaders_free_input(const ShaderProgram *program,
|
||||
const VideoCapture *input) {
|
||||
void shaders_free_input(ShaderProgram *program, unsigned int input_index) {
|
||||
#ifdef VIDEO_IN
|
||||
if (!input->error && input->dma_image != EGL_NO_IMAGE_KHR) {
|
||||
eglDestroyImageKHR(program->egl_display, input->dma_image);
|
||||
if (program->dma_images[input_index] != EGL_NO_IMAGE_KHR) {
|
||||
eglDestroyImageKHR(program->egl_display, program->dma_images[input_index]);
|
||||
program->dma_images[input_index] = EGL_NO_IMAGE_KHR;
|
||||
}
|
||||
if (!input->error && input->dma_image_swap != EGL_NO_IMAGE_KHR) {
|
||||
eglDestroyImageKHR(program->egl_display, input->dma_image_swap);
|
||||
if (program->dma_images_swap[input_index] != EGL_NO_IMAGE_KHR) {
|
||||
eglDestroyImageKHR(program->egl_display,
|
||||
program->dma_images_swap[input_index]);
|
||||
program->dma_images_swap[input_index] = EGL_NO_IMAGE_KHR;
|
||||
}
|
||||
check_eglerror_ro("shaders_free_input/eglDestroyImageKHR");
|
||||
#endif /* VIDEO_IN */
|
||||
}
|
||||
+4
-2
@@ -6,6 +6,9 @@
|
||||
void shaders_init(ShaderProgram *program, const Project *project,
|
||||
const SharedContext *context, bool rebind);
|
||||
|
||||
void shaders_relink_input(ShaderProgram *program, const Project *project,
|
||||
VideoCaptureArray *inputs, unsigned int i);
|
||||
|
||||
void shaders_link_inputs(ShaderProgram *program, const Project *project,
|
||||
VideoCaptureArray *inputs);
|
||||
|
||||
@@ -19,7 +22,6 @@ void shaders_free(const ShaderProgram *program);
|
||||
|
||||
void shaders_free_window(const ShaderProgram *program, bool secondary);
|
||||
|
||||
void shaders_free_input(const ShaderProgram *program,
|
||||
const VideoCapture *input);
|
||||
void shaders_free_input(ShaderProgram *program, unsigned int input_index);
|
||||
|
||||
#endif /* SHADERS_H */
|
||||
+2
-1
@@ -1,5 +1,6 @@
|
||||
#include <log.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "types.h"
|
||||
|
||||
@@ -619,7 +620,7 @@ bool state_background_write(SharedContext *context,
|
||||
}
|
||||
|
||||
log_info("(state) background writing stopped by main thread (pid: %d)", pid);
|
||||
return false;
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
void state_init(SharedContext *context, const StateConfig *state_config,
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#include <bsd/string.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
+12
-7
@@ -8,7 +8,6 @@
|
||||
#include <hashmap.h>
|
||||
#include <linmath.h>
|
||||
#include <stdbool.h>
|
||||
#include <sys/time.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "config.h"
|
||||
@@ -49,6 +48,7 @@ typedef struct Parameters {
|
||||
StringArray video_in;
|
||||
unsigned int video_size;
|
||||
unsigned int internal_size;
|
||||
bool video_reconnect;
|
||||
bool load_state;
|
||||
bool save_state;
|
||||
bool trace_midi;
|
||||
@@ -130,6 +130,8 @@ typedef struct ShaderProgram {
|
||||
unsigned int in_count;
|
||||
#ifdef VIDEO_IN
|
||||
EGLDisplay egl_display;
|
||||
EGLImageKHR dma_images[MAX_VIDEO];
|
||||
EGLImageKHR dma_images_swap[MAX_VIDEO];
|
||||
#endif /* VIDEO_IN */
|
||||
} ShaderProgram;
|
||||
|
||||
@@ -138,7 +140,11 @@ typedef struct ShaderProgram {
|
||||
typedef struct VideoCapture {
|
||||
char name[STR_LEN];
|
||||
bool error;
|
||||
bool disconnected;
|
||||
bool needs_reload;
|
||||
bool with_swap;
|
||||
bool swap;
|
||||
unsigned int fps;
|
||||
int fd;
|
||||
int exp_fd;
|
||||
int exp_fd_swap;
|
||||
@@ -149,12 +155,13 @@ typedef struct VideoCapture {
|
||||
#ifdef VIDEO_IN
|
||||
struct v4l2_buffer buf;
|
||||
struct v4l2_buffer buf_swap;
|
||||
EGLImageKHR dma_image;
|
||||
EGLImageKHR dma_image_swap;
|
||||
#endif /* VIDEO_IN */
|
||||
} VideoCapture;
|
||||
|
||||
typedef ARRAY(VideoCaptureArray, VideoCapture);
|
||||
typedef struct VideoCaptureArray {
|
||||
VideoCapture values[MAX_VIDEO];
|
||||
unsigned int length;
|
||||
} VideoCaptureArray;
|
||||
|
||||
// window.c
|
||||
|
||||
@@ -193,9 +200,7 @@ typedef struct SharedContext {
|
||||
unsigned int auto_random_cycle;
|
||||
unsigned int seeds[MAX_FRAG];
|
||||
unsigned int fps;
|
||||
unsigned int input_formats[MAX_VIDEO];
|
||||
unsigned int input_fps[MAX_VIDEO];
|
||||
bool input_swap[MAX_VIDEO];
|
||||
VideoCaptureArray inputs;
|
||||
bool stop;
|
||||
} SharedContext;
|
||||
|
||||
|
||||
+15
-13
@@ -1,6 +1,5 @@
|
||||
#ifdef VIDEO_IN
|
||||
|
||||
#include <bsd/string.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <linux/videodev2.h>
|
||||
@@ -286,22 +285,25 @@ static void close_stream(const VideoCapture *video_capture) {
|
||||
ioctl(video_capture->fd, VIDIOC_STREAMOFF, &buf_type);
|
||||
}
|
||||
|
||||
static unsigned int read_video(const VideoCapture *video_capture, bool swap) {
|
||||
int result;
|
||||
static unsigned int read_video(VideoCapture *video_capture) {
|
||||
unsigned int result;
|
||||
struct v4l2_capability cap;
|
||||
|
||||
result = 0;
|
||||
|
||||
if ((swap || !video_capture->with_swap) &&
|
||||
if ((video_capture->swap || !video_capture->with_swap) &&
|
||||
ioctl(video_capture->fd, VIDIOC_DQBUF, &video_capture->buf) != -1) {
|
||||
ioctl(video_capture->fd, VIDIOC_QBUF, &video_capture->buf);
|
||||
|
||||
result = 1;
|
||||
} else if (!swap && video_capture->with_swap &&
|
||||
} else if (!video_capture->swap && video_capture->with_swap &&
|
||||
ioctl(video_capture->fd, VIDIOC_DQBUF, &video_capture->buf_swap) !=
|
||||
-1) {
|
||||
ioctl(video_capture->fd, VIDIOC_QBUF, &video_capture->buf_swap);
|
||||
|
||||
result = 2;
|
||||
} else if (ioctl(video_capture->fd, VIDIOC_QUERYCAP, &cap) == -1) {
|
||||
video_capture->error = true;
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -361,18 +363,18 @@ bool video_background_read(VideoCapture *video_capture, SharedContext *context,
|
||||
pid);
|
||||
timer_init(&timer, 30);
|
||||
|
||||
while (!context->stop) {
|
||||
video_result = read_video(video_capture, context->input_swap[input_index]);
|
||||
while (!context->stop && !video_capture->error) {
|
||||
video_result = read_video(video_capture);
|
||||
if (video_result > 0 && timer_inc(&timer)) {
|
||||
fps = timer_reset(&timer);
|
||||
|
||||
context->input_fps[input_index] = (unsigned int)round(fps);
|
||||
context->inputs.values[input_index].fps = (unsigned int)round(fps);
|
||||
if (trace_fps) {
|
||||
log_trace("(%s) %.2ffps", video_capture->name, fps);
|
||||
}
|
||||
}
|
||||
if (video_result > 0) {
|
||||
context->input_swap[input_index] = video_result == 2;
|
||||
video_capture->swap = video_result == 2;
|
||||
}
|
||||
}
|
||||
if (context->stop) {
|
||||
@@ -381,15 +383,15 @@ bool video_background_read(VideoCapture *video_capture, SharedContext *context,
|
||||
} else {
|
||||
log_info("(%s) background acquisition stopped after error (pid: %d)",
|
||||
video_capture->name, pid);
|
||||
video_capture->disconnected = true;
|
||||
video_capture->pixelformat = 0;
|
||||
video_free(video_capture);
|
||||
}
|
||||
exit(context->stop ? EXIT_SUCCESS : EXIT_FAILURE);
|
||||
return false;
|
||||
}
|
||||
|
||||
void video_free(const VideoCapture *video_capture) {
|
||||
if (!video_capture->error) {
|
||||
close_stream(video_capture);
|
||||
}
|
||||
close_stream(video_capture);
|
||||
if (video_capture->exp_fd != -1) {
|
||||
close(video_capture->exp_fd);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user