简体   繁体   English

如何在GLSL中使用指针

[英]how to use pointers in GLSL

I need to send a set of data to shader like. 我需要向着色器发送一组数据。

//Application OpenGL

uniform vec3 *variable; 
variable = (uniform vec3 *)malloc(80 * sizeof(uniform vec3));  

//or    
uniform vec3 variable[80];

I need to send data such as indexes, and many other data. 我需要发送索引等数据以及许多其他数据。

The latter case is correct. 后一种情况是正确的。 GLSL is built on having as simple and straightforward execution as possible. GLSL建立在尽可能简单直接的执行之上。 You cannot allocate memory in the shader, iterating is expensive. 您无法在着色器中分配内存,迭代非常昂贵。 A well-written GLSL or HLSL shader takes in a fixed set of data, and outputs a fixed set of data. 精心编写的GLSL或HLSL着色器接收固定的数据集,并输出一组固定的数据。 This makes it very fast to execute in parallel. 这使得并行执行非常快。 This is my skeletal vertex shader. 这是我的骨架顶点着色器。

 #version 110

uniform mat4 transform[ 32 ];

in int boneID;

void main()
{

    gl_FrontColor = gl_Color;
    gl_Position = transform[ boneID ] * gl_Vertex;

}

On the C/++ side, when calling glUniformMatrix4fv, point it to an array of several matrices and tell it how many there are, and it'll bring them through into GLSL as separate values. 在C / ++方面,当调用glUniformMatrix4fv时,将其指向一个包含多个矩阵的数组并告诉它有多少,并将它们作为单独的值引入GLSL。

Please note that my code is built on an old version of GLSL, and uses many now-deprecated elements such as gl_Vertex. 请注意,我的代码是基于旧版本的GLSL构建的,并且使用了许多现已弃用的元素,例如gl_Vertex。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM