Texture Buffers in GL3
A new addition in the GL3 engine is a feature called texture-buffers. Texture-buffers use the new jit.gl.buffer object in conjunction with jit.gl.mesh and allow you to access any of the buffers of a jit.gl.mesh (position, normal, vertex_attr, etc.) as a 1D texture in any of the mesh's shader programs, using the texelFetch command.
You can declare a mesh's buffer as a texture-buffer via the new jit.gl.buffer using the attribute texbuf 1 and must specify 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:
[ jit.gl.buffer @type vertex_attr0 @texbuf 1 ]
[ jit.gl.buffer @type vertex_attr1 @texbuf 1 ]
then in your shader params declaration you need something like:
<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" />
and in the program body:
uniform sampler2DRect tex1;
uniform sampler2DRect tex2;
uniform samplerBuffer texbuf1;
uniform samplerBuffer texbuf2;
This allows you access to the sampled texture for use in the rest of the shader. To sample, use texelFetch:
vec3 bufval = texelFetch(texbuf1, index).xyz;
where index is an integer between 0 and the buffer width minus one.
For an example, check out the tb.point.lights patch in the gl3 examples.
See Also
Name | Description |
---|---|
GL3 Package Topics | GL3 Package Topics |
jit.gl.buffer | |
jit.gl.mesh | Generate GL geometry from matrices |
jit.gl.tf |