0

i have a struct

struct distance
{
    int dist[5];
};

and its used as an array

distance dist[100];

How can i pass this to my tessellation control shader?

shader:

 #version 410 core

struct distance
{
    int dist[5];
};

uniform distance myDistances[100];

layout (vertices = 16) out;

void main(void)
{
    uint id = gl_InvocationID;

    if (id == 0)
    {
        gl_TessLevelInner[0] = myDistances[gl_PrimitiveID].dist[4];
        gl_TessLevelInner[1] = myDistances[gl_PrimitiveID].dist[4];
        gl_TessLevelOuter[0] = myDistances[gl_PrimitiveID].dist[0];
        gl_TessLevelOuter[1] = myDistances[gl_PrimitiveID].dist[1];
        gl_TessLevelOuter[2] = myDistances[gl_PrimitiveID].dist[2];
        gl_TessLevelOuter[3] = myDistances[gl_PrimitiveID].dist[3];
    }

    gl_out[gl_InvocationID].gl_Position = gl_in[id].gl_Position;
}

application uniform definition:

struct
    {
        struct
        {
            int     mv_matrix;
            int     proj_matrix;
            int     mvp;
            int     dist;
        } patch;
        struct
        {
            int     draw_color;
            int     mvp;
        } control_point;
    } uniforms;

in my main

glUniformMatrix4fv(uniforms.patch.mv_matrix, 1, GL_FALSE, mv_matrix);
    glUniformMatrix4fv(uniforms.patch.proj_matrix, 1, GL_FALSE, proj_matrix);
    glUniformMatrix4fv(uniforms.patch.mvp, 1, GL_FALSE, proj_matrix * mv_matrix);
    for(int i=0; i<100; i++)
    {
        for(int j=0; j<5; j++)
        {
            glGetUniformLocation(program, "myDistances[i].dist[j]");
            glUniform1i(uniforms.patch.dist, ocean.detail[i].dist[j]);
        }
    }

1 Answer 1

1

Under the assumption that you want to pass the data as a uniforms: You can use a similar struct than in C++. The following code could be your shader:

struct distance
{
    int dist[5];
};

uniform distance myDistances[100];

void main()
{
     ....
}

In you application you can access the struct by

glUniform1i(..., "myDistances[i].dist[j]")

where i =[0-99] and j = [1-5] (or by glUniform1iv with the same uniform name).

Sign up to request clarification or add additional context in comments.

3 Comments

Yes i'd like to pass it in as a uniform. The problem is i'm not sure how to set up the uniform in my applications main.
glUniform1iv(uniforms.patch.dist, 100, ocean.detail); is complaining that ist not an GLint
Basically yes, but your result of glGetUniform isn't stored anywhere and you have to replace i and j in "myDistances[i].dist[j]" with the value of your variable. Something like "myDistances[" + i + "].dist[" + j + "]".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.