将uint属性传递给GLSL

将uint属性传递给GLSL

本文介绍了将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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 02:51