draupnie
draupnie

Reputation: 1130

Why samplers cannot be part of uniform blocks in OpenGL, and any ways to get around it?

I want to render a scene to texture, and share the texture sampler in several programs. Similar to share the project view matrix in multiple programs. Unlike project view matrix, which can be put into uniform blocks, "Samplers cannot be part of uniform blocks". https://www.opengl.org/wiki/Uniform_(GLSL)

Some discussion here describes why:

multiple issues:
GLSL samplers embody two things: source of texture data and how to filter from it (nearest, linear, mipmapping, anisotropic, etc)
Samples are opaque things, and to place them into a uniform buffer object requires they have a well defined (and cross-platform) size.
Those issues together make it dicey.

I want to see some explanation of why this cannot be handled and any other ways to achieve sharing texture samplers.

Upvotes: 4

Views: 3918

Answers (1)

datenwolf
datenwolf

Reputation: 162164

The explanation is right here:

Samples are opaque things, and to place them into a uniform buffer object requires they have a well defined (and cross-platform) size.

The purpose of uniform blocks is, that you can set then with a single OpenGL call from a single structure in your (client) program. But for this to work the memory layout of this structure must be known, so that the memory layout produced by the compiler matches that of the shader uniform block.

But since the memory layout of samplers is not defined a memory layout can not be determined. Without a definitive memory layout no structure, without a structure no block.

Upvotes: 7

Related Questions