UniformsGL 2.0

glUniform3fv

Sets a vec3 uniform (or an array of them) from a pointer.

Part of the family glUniform*

Signature

void glUniform3fv(GLint location, GLsizei count, const GLfloat *value);

How it works

The v suffix means "vector": values come from a pointer instead of separate arguments. With GLM you pass glm::value_ptr(v) or &v[0]. count lets you upload a whole vec3 array in one call.

Parameters

locationGLint

Uniform location from glGetUniformLocation. -1 is silently ignored.

countGLsizei

How many vec3 to set: 1 for a single vec3, N for an array.

valueconst GLfloat *

Pointer to 3 × count floats.

Tips & pitfalls

  • Uniforms are written to the program currently selected with glUseProgram.

Errors

When the call is invalid it does nothing and sets an error, which glGetError returns:

GL_INVALID_OPERATION
No program in use, or the function's type/size does not match the uniform declared in GLSL.

Example

example.cpp
1glm::vec3 lightPos(1.2f, 1.0f, 2.0f);
2glUniform3fv(uLightPos, 1, glm::value_ptr(lightPos));
Official Khronos documentation