将 uint 属性传递给 GLSL [英] Passing uint attribute to GLSL

查看:45
本文介绍了将 uint 属性传递给 GLSL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将一堆连续的无符号整数作为属性传递给我的 GLSL 着色器.

I'm trying to pass a bunch of consecutive unsigned ints as attribute to my GLSL shader.

到目前为止我想出了

s_number = glGetAttribLocation(shader, "number");

numberData = new GLuint[dotAmount];
for (GLuint i = 0; i < dotAmount; i++) {
    numberData[i] = i;
}

glGenBuffers(1, &vertBuf);
glBindBuffer(GL_ARRAY_BUFFER, vertBuf);

glBufferData(
        GL_ARRAY_BUFFER,
        sizeof(dotAmount),
        numberData,
        GL_STATIC_DRAW
);

渲染函数是

glUseProgram(shader);

[..]

glEnableVertexAttribArray(s_number);
glBindBuffer(GL_ARRAY_BUFFER, vertBuf);

glVertexAttribPointer(
        s_number,
        1,
        GL_UNSIGNED_INT,
        GL_FALSE,
        0,
        BUFFER_OFFSET(0)
);

glDrawArrays(GL_POINTS, 0, dotAmount);

我尝试像这样使用顶点着色器中的数字:

I try to use the number in the vertex shader like this:

attribute uint number;

(名称 'vertBuf' 实际上有点误导,因为它不是我想传递的顶点数据)我使用的是 OpenGL 3 和着色器版本 1.3.

(The name 'vertBuf' is actually a bit misleading since it's not vertex data I want to pass) I'm using OpenGL 3 and shader versions 1.3.

我想要实现的是,我希望着色器被执行 dotAmount 次.定位是在着色器中以数学方式完成的.但我得到的只是一个空白屏幕......

What I am trying to achieve is, I want the shaders to be executed dotAmount times. The positioning is done mathematically within the shader. But all I get is a blank screen...

我很确定问题不在于着色器.我想画点,如果我把 gl_Position = vec4(0.0, 0.0, 0.0, 0.0); 放在顶点着色器中,我认为它应该画一些东西.

I am quite sure that the problem does not lie in the shaders. I want to draw points, and if I put gl_Position = vec4(0.0, 0.0, 0.0, 0.0); in the vertex shader, I assume it should draw something.

推荐答案

尝试将片段着色器更改为 gl_FragColor = vec4(1,0,0,1); 这将确保输出颜色使片段可见.

Try changing the fragment shader to gl_FragColor = vec4(1,0,0,1); This will make sure that the output color makes the fragment visible.

另外,你应该有 gl_Position = vec4(0, 0, 0, 1); (原因是 gl_Position 必须在齐次坐标中,这意味着前三个分量将被除以第四个.)

Also, You should have gl_Position = vec4(0, 0, 0, 1); (The reason is that gl_Position must be in homogenous coordinates, meaning that the first three components will be divided by the fourth.)

这篇关于将 uint 属性传递给 GLSL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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