What is faster glUniform4f / glUniform4fv, taking into account any optimization?

Here are the captions.

glUniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
glUniform4fv(GLint location, GLsizei count, const GLfloat *v);

In my humble opinion, the previous one should be faster, because values ​​can be transferred directly from registers without being retrieved from memory. However, I want to hear a lot of opinions.

+5
source share
2 answers

While the variant *vmainly exists for installing uniforms that have an array type, the OpenGL specification explicitly allows the use of array variants to also set scalar values ​​using the number of units.

Let me quote from the OpenGL Spec (adds itself):

glUniform {1 | 2 | 3 | 4} {f | i} v . , . 1. , 1 .

OpenGL 2.1 Spec, OpenGL 4.2 Spec.

. , vec3 v[2], glGetUniformLocation(), 6. , 6 v[0].


: ?

. , , . , , .

. :

void glUniform1f(GLint  location,  GLfloat  v0)
{
    glUniform1fv(location, 1, &v0);
}

. :

void glUniform1fv(GLint  location, GLsizei count, GLfloat * value)
{
    int i;

    for (i = 0; i < count; i++) {
        glUniform1f(location, *value);
        value++;
        location++;
    }
}

.

( ), OpenGL, , , , - OpenGL. , , , , , , , , , , .

. :

struct v3 {
     GLfloat x;
     GLfloat y;
     GLfloat z;
};

void setUniform (GLint location, struct v3 * vPtr) {
    glUniform3f(location, vPtr->x, vPtr->y, vPtr->z);
}

vPtr , :

void setUniform (GLint location, struct v3 * vPtr) {
    glUniform3fv(location, 1, (const GLfloat *)vPtr);
}

, . , , , . , , . , , , , , , , .

+20

. , ( 4-), , ( 4-).

, 1 , , . , , .

, , (.. ), , , , , , , , , .

+2

All Articles