将自己的结构传递给opengl es 2.0着色器 [英] Passing own struct into opengl es 2.0 shader

查看:202
本文介绍了将自己的结构传递给opengl es 2.0着色器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想尝试一下OpenGL ES 2.0编程指南中的照明示例。在着色器中,他们制作了两个结构。

I want to try a lighting example from the book OpenGL ES 2.0 Programming 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?

问候
Niclas

Regards Niclas

推荐答案

你不能,OpenGL ES没有那个功能,要上传你必须得到每个嵌套变量的位置,并在每个嵌套变量上调用glUniform *。

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.

例如:

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

这篇关于将自己的结构传递给opengl es 2.0着色器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆