Texture-buffers allow access to any jit.gl.mesh buffer (position, normal, vertex_attr, etc.) as a 1D texture in the mesh's shader programs, using the texelFetch command.
You can declare a mesh's buffer as a texture-buffer by connecting a jit.gl.buffer to the mesh, setting the attribute texbuf 1 and specifying the name of the buffer to bind as a texture (position, normal, vertex_attr, etc.) using the attribute type. It is important to note that any normal textures will be bound first, and then texture-buffers. Texture-buffers are declared in the shader as samplerBuffer uniforms.
So if you have two texture-buffers patched into a jit.gl.mesh that look like this:
then in your shader params declaration you need something like:
[ jit.gl.buffer @type vertex_attr0 @texbuf 1 ] [ jit.gl.buffer @type vertex_attr1 @texbuf 1 ]
and in the program body:
<param name="tex1" type="int" default="0" /> <param name="tex2" type="int" default="1" /> <param name="texbuf1" type="int" default="2" /> <param name="texbuf2" type="int" default="3" />
This allows you access to the sampled texture for use in the rest of the shader using texelFetch:
uniform sampler2DRect tex1; uniform sampler2DRect tex2; uniform samplerBuffer texbuf1; uniform samplerBuffer texbuf2;
where index is an integer between 0 and the buffer width minus one.
vec3 bufval = texelFetch(texbuf1, index).xyz;
For an example patch, check out tb.pl.disco.duck.
|Working with OpenGL||Working with OpenGL|
|jit.gl.mesh||Generate GL geometry from matrices|