开发者

Passing own struct into opengl es 2.0 shader

开发者 https://www.devze.com 2023-01-23 23:06 出处:网络
I want to try a lighting example from the book OpenGL ES 2.0 Programming开发者_JAVA百科 Guide. In the shader they have made two structures.

I want to try a lighting example from the book OpenGL ES 2.0 Programming开发者_JAVA百科 Guide. In the shader they have made two structures.

struct directional_light   
{  

    vec3 direction; // normalized light direction in eye space  
    vec3 halfplane; // normalized half-plane vector  

    vec4 ambient_color;
    vec4 diffuse_color;
    vec4 specular_color;
};

struct material_properties 
{ 
    vec4 ambient_color; 
    vec4 diffuse_color; 
    vec4 specular_color; 
    float specular_exponent;
};

They have also made two uniforms, based on these structures.

uniform  material_properties u_material_properties;   
uniform directional_light u_directional_light;

The problem is, I do not know how to pass own structures into the actual shader.

I want to create the same structures in my main code and pass the objects into the shader. How is this possible?

Regards Niclas


You can't, OpenGL ES doesn't have that functionality, to upload you have to get the location of each of your nested variables and call glUniform* on each of them.

For example:

GLuint loc = glGetUniformLocation(program, "u_material_properties.ambient_color");
glUniform4f(loc, 1.0, 1.0, 1.0, 0.0);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号