uniform array of structures

This topic contains 4 replies, has 4 voices, and was last updated by  Joe Davis 7 years, 3 months ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #30132

    3DGamer
    Member

    Hi all
    to implement lighting I have an uniform array of structures which is

    Code:
    uniform struct lightStruct{
        int enabled;
        vec2 attenuation;
        vec3 color;
        vec3 pos;
    }light[NUM_LIGHTS];

    (NUM_LIGHTS is eight)
    And to get the locations i use this code:

    Code:
    u_lightEnabled_loc[0]=glGetUniformLocation(programName,”light[0].enabled”);
    u_lightPos_loc[0]=glGetUniformLocation(programName,”light[0].pos”);
    u_lightColor_loc[0]=glGetUniformLocation(programName,”light[0].color”);
    u_lightAttenuation_loc[0]=glGetUniformLocation(programName,”light[0].attenuation”);
    u_lightEnabled_loc[1]=glGetUniformLocation(programName,”light[1].enabled”);
    u_lightPos_loc[1]=glGetUniformLocation(programName,”light[1].pos”);
    u_lightColor_loc[1]=glGetUniformLocation(programName,”light[1].color”
    u_lightAttenuation_loc[1]=glGetUniformLocation(programName,”light[1].attenuation”);
    ….

    The locations seem to be correct as they form a contiguous set of integers.
    However, when I set for example the value of u_lightEnabled_loc[5] using glUniform1i(u_lightEnabled_loc[5],x), the “enabled” field of all lights is set to x. What am I doing wrong?
    Thanks in advance.

    #33903

    Xmas
    Member

    This could be a driver bug. Which platform are you using?

    If it really is a driver bug, a simple workaround would be to drop the struct and use four plain arrays.

    #33904

    3DGamer
    Member

     I use a Sony Ericsson Satio (TI Omap 3430 with SGX530) , OS is Symbian. I’ll try out the simple array version, thanks Smile

    #33905

    kellogs
    Member
    3DGamer wrote:
    Hi all
    to implement lighting I have an uniform array of structures which is

    this bothers me. POwerVR seems not to follow the lights exported from a 3ds MAx design. Is this a known limitation ? What was 3DGamer talking about with his struct ?

    Thank you

    #33906

    Joe Davis
    Member

    The use of a struct in this case is purely to make the shader code a little cleaner and easier to read. It does not affect the functionality that is available in the shader.

    This appears to be a bug on this particular device, but other devices with SGX cores and different drivers may not have the same issue.

Viewing 5 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic.