glTexImage2DMultisample具有非规范化纹理格式

时间:2013-02-11 10:53:01

标签: opengl glsl opengl-3 multisampling

我很难使用非标准化的内部格式(例如GL_RGBA32UIGL_RGBA32I)渲染多重采样纹理。 这是我的代码:

width1=height1=32;
*target11=GL_TEXTURE_2D_MULTISAMPLE,*format=GL_RGBA16UI;
*samples=1;
glGenTextures(1, &id1);
glBindTexture(*target11, id1);
glGenFramebuffers(1, &Fboid);
GLint framebuffer;
glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING,&framebuffer);
glGenRenderbuffers(1, &depth);
glPixelStorei(GL_UNPACK_ALIGNMENT,1);
glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, *samples ,*format, width1, height1,true);    
glBindFramebuffer(GL_FRAMEBUFFER, Fboid);

glBindRenderbuffer(GL_RENDERBUFFER, depth);
glRenderbufferStorageMultisample(GL_RENDERBUFFER,*samples, GL_DEPTH_COMPONENT24, width1, height1);
glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depth);            glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,*target11,id1,0);
glEnable(GL_MULTISAMPLE);
draw_cube(0);

glDisable(GL_MULTISAMPLE);  
status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
switch(status)
    {
            case GL_FRAMEBUFFER_COMPLETE:                       tdkPrintf("GL_FRAMEBUFFER_COMPLETE\n");                        break;
            case 0x8CDB:                                        tdkPrintf("GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER\n");          break;
            case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT:          tdkPrintf("GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT\n");           break;
            case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:  tdkPrintf("GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT\n");   break;        
            case GL_FRAMEBUFFER_UNSUPPORTED:                    tdkPrintf("GL_FRAMEBUFFER_UNSUPPORTED\n");                     break;  
            default:                                            tdkPrintf("Unknown issue (%X).\n",status);                     break;
        }

glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);

render_cube();

手动规范片段着色器中的纹理数据: 对于GL_RGBA16UIfactor = 65535

uniform usampler2DMS tk_diffuseMap;
in vec3 ps_texCoord;
out vec4 fragColor;
uniform int samples;
uniform uint factor; 
void main(void)
{

    vec2 iTmp = textureSize(tk_diffuseMap);
    vec2 tmp =floor(iTmp * ps_texCoord.xy);
    uvec3 temp;  
    vec3 temp1;
    vec4 color;
    for(int i = 0; i < samples; ++i)
    {
         temp= texelFetch(tk_diffuseMap, ivec2(tmp), i).rgb;
         temp1=vec3(temp);
         temp1=temp1/factor;
        color = color + vec4(temp1,1.0);
    }

    fragColor = vec4(color/samples);
}

使用此代码,我将获得整个几何体的白色纹理。但是,它适用于规范化纹理格式。 在非规范化纹理的情况下,写入帧缓冲区的正确方法是什么?

0 个答案:

没有答案