Uniform structs with image buffers

It seems samplers, image buffers and bindless graphics pointers cannot be placed in GLSL structs. This would be quite useful in the following situation where multiple complex structures need to be accessed by the same function:

struct MyStruct
{
layout(rgba32f) imageBuffer someData; //or vec4* someData
layout(rgba32f) imageBuffer someOtherData;
ivec2 size;
};

uniform MyStruct data1;
uniform MyStruct data2;

void OperateOnStruct(MyStruct d)
{

}

void main()
{
OperateOnStruct(data1);
OperateOnStruct(data2);

}

One dirty workaround might be to write a preprocessor and/or do something fancy with macros. Is there a nice way to handle this or is the solution just to have lots of duplicated variables with prefixes such as data1_someData, data1_someOtherData, data2_someData etc?
Any suggestions appreciated!

Samplers and Images are not really uniforms, despite the fact that they unfortunately use the uniform API. They’re closer to uniform buffer locations than uniforms. They’re discrete locations in a shader that can have values stored in them, but they are not normal C/C++ data types.

For your particular case, the way to deal with it is very simple:


void OperateOnStruct(in sampler2D tex, in MyStruct d)
{
...
}

uniform sampler2D someTex;
uniform sampler2D otherTex;

void main()
{
OperateOnStruct(someTex, data1);
OperateOnStruct(otherTex, data2);
...
}

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.