-
Notifications
You must be signed in to change notification settings - Fork 494
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't Set Float Uniform Variable #991
Comments
Do you use the code-generated struct or your own (in the #pragma pack(push,1)
SOKOL_SHDC_ALIGN(16) typedef struct fsParams_t {
float time;
uint8_t _pad_4[12];
} fsParams_t;
#pragma pack(pop Note how this is padded to a multiple of 16 bytes. This is a side effect of 'flattening' uniform blocks into a vec4 array via SPIRVCross, which allows to update uniforms with a single glUniform4fv() call per uniform-block in the GL backend (instead of one individual glUniform call per uniform block member which is otherwise used). PS: the PPS: in general, and if possible, you should use the code-generated structs for passing uniforms into sokol-gfx, since the alignment and padding rules for uniform blocks are non-trivial, and very different from vanilla C structs. PPPS: code example const fsParams_t fs_params = { .time = (float)glfwGetTime() };
sg_apply_uniforms(SG_SHADERSTAGE_FS, SLOT_fsParams, &SG_RANGE(fs_params)); |
I know the By the way, using the '&' before 'SG_RANGE' gives me an error. I've seen it being used every example though. The error is 'Taking address of rvalue [-fpermissive]', the program runs fine regardless of this error. I have all warnings and errors enabled so that must be the case. |
Ah right, that's a C vs C++ thing. In C++ you can do this instead (just drop the '&'): sg_apply_uniforms(SG_SHADERSTAGE_FS, SLOT_fsParams, SG_RANGE(fs_params)); ...or use the SG_RANGE_REF() macro which does the right thing both in C and C++: sg_apply_uniforms(SG_SHADERSTAGE_FS, SLOT_fsParams, SG_RANGE_REF(fs_params)); |
This is a .glsl shader file that I'm compiling using sokol-shdc I grabbed from the sokol-tools-bin repo. You can see in the fragment shader that I have a uniform block with a float variable called time which I set to '(float)glfwGetTime()'. I am using this variable to just play with the colors. This shader works perfectly fine when embedding this code in the shader desc, but compiling it with sokol-shdc into a header file just does not work. Setting the uniform variable says that the block size does not match and after going through the generated header file, the float variable in the fragment shader is getting converted into a vec4 for whatever reason. And sure enough, it works perfectly when I set a vec4, no block size errors.
This is the first time I've ever reported an issue on GitHub so excuse me if it's not formatted nicely. I'm really loving sokol by the way, it's great. Also I think it would be kinda cool if there was a discord server or something no?
The text was updated successfully, but these errors were encountered: