OpenGL - 渲染到3D纹理对纹理没有影响

时间:2014-10-25 16:58:41

标签: c++ opengl shader

我正在尝试将顶点信息展开为3D纹理。

对应的C ++代码:

GLuint color_tex;
GLuint fb;
glGenTextures(1, &color_tex);
glBindTexture(GL_TEXTURE_3D, color_tex);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_REPEAT);
glTexImage3D(GL_TEXTURE_3D, 0, GL_R32UI, 32, 32, 32, 0, GL_RED_INTEGER, GL_UNSIGNED_INT, NULL);
  //-------------------------
glGenFramebuffers(1, &fb);
glBindFramebuffer(GL_FRAMEBUFFER, fb);
 //Attach one of the faces of the Cubemap texture to this FBO
glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, color_tex, 0);
//-------------------------
//Does the GPU support current FBO configuration?
GLenum status;
status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
switch(status)
{
    case GL_FRAMEBUFFER_COMPLETE:
        std::cout << "good" << std::endl;
    default:
        break;
}
//-------------------------
glClearColor(0,0,0,0);
glClear(GL_COLOR_BUFFER_BIT);

glUseProgram(splat_vertex_ids);
glBindVertexArray( mVAO );
glDrawArrays(mPrimitiveType, 0, mDrawSize);
glBindFramebuffer(GL_FRAMEBUFFER, 0);

GLuint content[32*32*32];
glBindTexture(GL_TEXTURE_3D, color_tex);
glGetTexImage(GL_TEXTURE_3D, 0, GL_RED_INTEGER, GL_UNSIGNED_INT, &content);

for(int i = 0; i< 32*32*32; ++i)
    if(content[i] != 0)
        std::cout << content[i] << std::endl;

我回读内容以检查是否有任何内容呈现,但纹理只包含0。

我的第一个想法是,我的着色器无法正常工作,因此我将其替换为:

几何着色器:

#version 330
layout(points) in;
layout(points, max_vertices = 1) out;

in vec3[] vPosition;

out vec2 oTexCoord;

void main(void)
{
    oTexCoord = vec2(0.2);

    gl_Position = vec4(0.2,0.2, 0.2,1);
    gl_Layer = 0;
    EmitVertex();
    EndPrimitive();
}

顶点着色器:

#version 330

layout(location = 0)in vec3 aPosition;

uniform vec3 uChunkStart;
uniform float uRes;

out vec3 vPosition;

void main(void)
{
    vPosition = aPosition;
}

Fragment Shader:

#version 330

in vec2 oTexCoord;

out uint color;

void main(void)
{
    color = 1337u;
}

不知道这有什么不对。它不应该创建一个单点吗?我第一次做这样的事情。

编辑:渲染到2D纹理也失败

0 个答案:

没有答案