aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authors-ol <s+removethis@s-ol.nu>2025-09-03 21:32:10 +0000
committers-ol <s+removethis@s-ol.nu>2025-09-14 15:39:20 +0000
commit76fcdb02fc595d4381e4f1d13f816c1fbee235e1 (patch)
treefd12e68968f351056b6966b308135df61b8ee5d8
parentrefactor Tag/Registry, reuse deleted tags (diff)
downloadalive-76fcdb02fc595d4381e4f1d13f816c1fbee235e1.tar.gz
alive-76fcdb02fc595d4381e4f1d13f816c1fbee235e1.zip
lib/glsl-view: use tag for texture, uniform names
-rw-r--r--alv-lib/glsl-view.moon49
-rw-r--r--examples/glsl-view/simple.alv6
-rw-r--r--examples/glsl-view/stream-controls.alv18
-rw-r--r--examples/glsl-view/stream.alv10
4 files changed, 44 insertions, 39 deletions
diff --git a/alv-lib/glsl-view.moon b/alv-lib/glsl-view.moon
index 74c53a2..d3c8e75 100644
--- a/alv-lib/glsl-view.moon
+++ b/alv-lib/glsl-view.moon
@@ -57,10 +57,9 @@ video_source = Constant.meta
meta:
name: 'video'
summary: "load a video texture source."
- examples: { '(video-source [socket] name type filename [format] [args])' }
+ examples: { '(video-source [socket] type filename [format] [args])' }
description: "Creates a texture source from a video or image file.
-- `name` is a unique name for this texture source.
- `type` can be one of:
- `2D`: `sampler2D` (loads first frame only)
- `3D` or `2D_ARRAY`: `sampler3D`/`sampler2DArray` (loads whole video)
@@ -70,29 +69,28 @@ video_source = Constant.meta
- `args` is a struct of optional arguments for the ffmpeg/avformat input format."
value: class extends Op
- pattern = -sig['osc/out'] + const.str + const.str + const.str + -const.str + -const!
+ pattern = -sig['osc/out'] + const.str + const.str + -const.str + -const!
setup: (inputs, scope) =>
- { socket, name, type, filename, format, args } = pattern\match inputs
+ { socket, type, filename, format, args } = pattern\match inputs
@prefix = COPILOT.active_module.file\match'(.*/)[^/]*$'
super
socket: Input.hot socket or scope\get '*oscout*'
- name: Input.cold name
type: Input.cold type
filename: Input.cold filename
format: format and Input.cold format
args: args and Input.cold args
samplertype = assert GLSL_SAMPLER_TYPES[@inputs.type!]
- @setup_out '=', Uniform, type: samplertype, val: @inputs.name!
+ @setup_out '=', Uniform, type: samplertype, val: "alv-#{@tag}"
tick: =>
- { :socket, :name, :type, :filename, :format, :args } = @unwrap_all!
+ { :socket, :type, :filename, :format, :args } = @unwrap_all!
with @inputs.socket!
filename = tryprefix @prefix, filename
- msg = Message.new{ address: "/source/#{name}/video", types: "ss", "TEXTURE_#{type}", filename }
+ msg = Message.new{ address: "/source/alv-#{@tag}/video", types: "ss", "TEXTURE_#{type}", filename }
msg\add 's', format if format
add_item msg, @inputs.args\type!, args if args
\send Message.pack msg.content
@@ -106,10 +104,9 @@ stream_source = Constant.meta
meta:
name: 'stream'
summary: "load a stream texture source."
- examples: { '(stream-source [socket] name type uri [format] [args])' }
+ examples: { '(stream-source [socket] type uri [format] [args])' }
description: "Creates a realtime stream from a capture source.
-- `name` is a unique name for this texture source.
- `type` must be `2D`.
- `uri` is the ffmpeg URI to load. If it starts with `./` it will be resolved relative to the current alv module.
- `format` optionally specifies the ffmpeg/avformat input format to use.
@@ -119,29 +116,28 @@ stream_source = Constant.meta
(stream-source 'testpt' '2D' 'testsrc=size=1280x720:rate=30' 'lavfi')"
value: class extends Op
- pattern = -sig['osc/out'] + const.str + const.str + const.str + -const.str + -const!
+ pattern = -sig['osc/out'] + const.str + const.str + -const.str + -const!
setup: (inputs, scope) =>
- { socket, name, type, filename, format, args } = pattern\match inputs
+ { socket, type, filename, format, args } = pattern\match inputs
@prefix = COPILOT.active_module.file\match'(.*/)[^/]*$'
super
socket: Input.hot socket or scope\get '*oscout*'
- name: Input.cold name
type: Input.cold type
filename: Input.cold filename
format: format and Input.cold format
args: args and Input.cold args
samplertype = assert GLSL_SAMPLER_TYPES[@inputs.type!]
- @setup_out '=', Uniform, type: samplertype, val: @inputs.name!
+ @setup_out '=', Uniform, type: samplertype, val: "alv-#{@tag}"
tick: =>
{ :socket, :name, :type, :filename, :format, :args } = @unwrap_all!
with @inputs.socket!
filename = tryprefix @prefix, filename
- msg = Message.new{ address: "/source/#{name}/stream", types: "ss", "TEXTURE_#{type}", filename }
+ msg = Message.new{ address: "/source/alv-#{@tag}/stream", types: "ss", "TEXTURE_#{type}", filename }
msg\add 's', format if format
add_item msg, @inputs.args\type!, args if args
\send Message.pack msg.content
@@ -153,7 +149,7 @@ tsv_source = Constant.meta
examples: { '(tsv-source [socket] name [type])' }
description: "Creates a texture source from a texture-share-vk texture.
-- `name` is a unique name for this texture source.
+- `name` is the tsv name of this texture source.
- `type` defaults to `2D`."
value: class extends Op
@@ -167,13 +163,13 @@ tsv_source = Constant.meta
type: Input.hot type or Constant.str "2D"
samplertype = assert GLSL_SAMPLER_TYPES[@inputs.type!]
- @setup_out '=', Uniform, type: samplertype, val: @inputs.name!
+ @setup_out '=', Uniform, type: samplertype, val: "alv-#{@tag}"
tick: =>
{ :socket, :name, :type } = @unwrap_all!
with @inputs.socket!
- \send Message.pack { address: "/source/#{name}/tsv", types: "ss", "TEXTURE_#{type}", name }
+ \send Message.pack { address: "/source/alv-#{@tag}/tsv", types: "ss", "TEXTURE_#{type}", name }
freeze = Constant.meta
meta:
@@ -239,7 +235,7 @@ shader_ = Constant.meta
value: class extends PureOp
pattern: const! + sig!^0
- name: (i) => "alv_u_#{i}"
+ name: (i) => "alv_u#{(tostring @tag)\gsub '%.', '_'}_#{i}"
type: (args) =>
uniforms = {}
@@ -247,9 +243,14 @@ shader_ = Constant.meta
type = val\type!
if type == T.str
continue
- elseif type.__class == Struct
- assert (type\get 'type') == T.str, "struct substituton needs type key"
- type = assert (type\get 'val'), "struct substituton needs val key"
+ else if type.__class == Struct and type.types['shader']
+ for name, typ in pairs type.types['uniforms'].types
+ uniforms[name] = typ
+ continue
+ else
+ if type.__class == Struct
+ assert type.types['type'] == T.str, "struct substituton needs type key"
+ type = type.types['val'], "struct substituton needs val key"
uniforms[@name i] = type
@@ -267,6 +268,10 @@ shader_ = Constant.meta
typestr = GLSL_TYPES[tostring type]
if type == T.str
val
+ elseif type.__class == Struct and type.types['shader']
+ for k, v in pairs val.uniforms
+ uniforms[k] = v
+ val.shader
else
if type.__class == Struct
typestr = val.type
diff --git a/examples/glsl-view/simple.alv b/examples/glsl-view/simple.alv
index 64e3335..02c8796 100644
--- a/examples/glsl-view/simple.alv
+++ b/examples/glsl-view/simple.alv
@@ -1,12 +1,12 @@
([1]import* glsl-view time math)
([2]import osc)
-([3]def *oscout* ([4]osc/connect 'localhost' 9000))
+([4]def *oscout* ([3]osc/connect 'localhost' 9000))
-([5]draw $[6]shader"
+([7]draw $[6]shader"
in vec2 uv;
out vec4 color;
void main() {
- color = vec4(uv, sin(uv.x + $([7]ramp 1 tau)), 1);
+ color = vec4(uv, sin(uv.x + $([5]ramp 1 tau)), 1);
}")
diff --git a/examples/glsl-view/stream-controls.alv b/examples/glsl-view/stream-controls.alv
index 5fd5a03..936dac9 100644
--- a/examples/glsl-view/stream-controls.alv
+++ b/examples/glsl-view/stream-controls.alv
@@ -1,17 +1,17 @@
([1]import* glsl-view link-time)
([2]import osc)
-([3]def
- *clock* ([4]clock false 120)
- *oscout* ([5]osc/connect 'localhost' 9000))
+([5]def
+ *clock* ([3]clock false 120)
+ *oscout* ([4]osc/connect 'localhost' 9000))
-([6]def
- paused? ([7]switch ([8]every 2) true false)
- cam ([9]doto ([10]stream-source 'webcam' '2D' '/dev/video0')
- ([11]freeze paused?)
- ([12]step! ([13]every 0.5))))
+([13]def
+ paused? ([7]switch ([6]every 2) true false)
+ cam ([12]doto ([8]stream-source '2D' '/dev/video0')
+ ([9]freeze paused?)
+ ([11]step! ([10]every 0.5))))
-([14]draw $[15]shader"
+([15]draw $[14]shader"
in vec2 uv;
out vec4 color;
diff --git a/examples/glsl-view/stream.alv b/examples/glsl-view/stream.alv
index 1ca2c63..4f40645 100644
--- a/examples/glsl-view/stream.alv
+++ b/examples/glsl-view/stream.alv
@@ -1,12 +1,12 @@
([1]import* glsl-view time)
([2]import osc)
-([3]def *oscout* ([5]osc/connect 'localhost' 9000))
+([4]def *oscout* ([3]osc/connect 'localhost' 9000))
-([6]def cam ([7]stream-source 'webcam' '2D' '/dev/video0')
- tst ([8]stream-source 'testpt' '2D' 'testsrc=size=1280x720:rate=30' 'lavfi'))
+([7]def cam ([5]stream-source '2D' '/dev/video0')
+ tst ([6]stream-source '2D' 'testsrc=size=1280x720:rate=30' 'lavfi'))
-([9]draw $[10]shader"
+([10]draw $[9]shader"
in vec2 uv;
out vec4 color;
@@ -14,7 +14,7 @@ void main() {
vec3 cam = texture($cam , uv).rgb;
vec3 tst = texture($tst , uv).rgb;
- color.rgb = mix(cam, tst, $([11]lfo 1));
+ color.rgb = mix(cam, tst, $([8]lfo 1));
color.a = 1.0;
}")