Jiro
Jiro

Reputation: 95

Can I upload a vec3 value to vec4 uniforms?

I've just read through this answer and its comments and have some related questions:

Upvotes: 2

Views: 456

Answers (2)

BDL
BDL

Reputation: 22168

No, these rules do not apply to uniforms. Consequently, you are not allowed to call glUniform3fv on a vec4.

The Spec states in Section 7.6.1:

For all [...] uniform types loadable with Uniform* commands, the command used must match the size and type of the uniform, as declared in the shader, and no type conversions are done.

Upvotes: 3

t.niese
t.niese

Reputation: 40842

The specs in (7.6. UNIFORMVARIABLES) say that the Uniform* would result in INVALID_OPERATION error if:

the size indicated in the name of the Uniform* command used does not match the size of the uniform declared in the shader,

or

the component type and count indicated in the name of the Uniform* command used does not match the type of the uniform declared in the shader, where a boolean uniform component type is considered to match any of the Uniform*i{v}, Uniform*ui{v}, or Uniform*f{v} commands.

And testing to call glUniform3f for a vec4 uniform will indeed result in a INVALID_OPERATION error.

Upvotes: 4

Related Questions