PDA

View Full Version : Render to cubemap



Kiwaiii
04-16-2011, 06:56 AM
Hi everyone !

I've a trouble to render to a cubemap. It works well when I attach to a TEXTURE_2D_ARRAY (each layer is properly drawn) but when I attach a TEXTURE_CUBE_MAP only the first face (+X) is drawn.

Here, a simplified version of my program :


...

// Init
glGenTextures(1,&skyCubeTexture.id);
glBindTexture(skyCubeTexture.target,skyCubeTexture .id);

glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X,0,GL_R GBA32F,skyCubeTexture.size.x,skyCubeTexture.size.y ,0,GL_RGBA,GL_FLOAT,NULL);
glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X,0,GL_R GBA32F,skyCubeTexture.size.x,skyCubeTexture.size.y ,0,GL_RGBA,GL_FLOAT,NULL);
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y,0,GL_R GBA32F,skyCubeTexture.size.x,skyCubeTexture.size.y ,0,GL_RGBA,GL_FLOAT,NULL);
glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,0,GL_R GBA32F,skyCubeTexture.size.x,skyCubeTexture.size.y ,0,GL_RGBA,GL_FLOAT,NULL);
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z,0,GL_R GBA32F,skyCubeTexture.size.x,skyCubeTexture.size.y ,0,GL_RGBA,GL_FLOAT,NULL);
glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z,0,GL_R GBA32F,skyCubeTexture.size.x,skyCubeTexture.size.y ,0,GL_RGBA,GL_FLOAT,NULL);


glTexParameterf(skyCubeTexture.target, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(skyCubeTexture.target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(skyCubeTexture.target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(skyCubeTexture.target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameterf(skyCubeTexture.target, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
glBindTexture(skyCubeTexture.target,0);

glGenFramebuffers(1,&skyCubeFramebuffer);
glBindFramebuffer(GL_FRAMEBUFFER,skyCubeFramebuffe r);
glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, skyCubeTexture.id, 0);
glDrawBuffer(GL_COLOR_ATTACHMENT0);
glBindFramebuffer(GL_FRAMEBUFFER,0);

...

// Draw a cube around the view point with normal pointing inside
glDisable(GL_DEPTH_TEST);
glDepthMask(false);
glCullFace(GL_FRONT);

glViewport(0,0,skyCubeTexture.size.x,skyCubeTextur e.size.y);
glBindFramebuffer(GL_FRAMEBUFFER,skyCubeFramebuffe r);
glClear(GL_COLOR_BUFFER_BIT);
glUseProgram(program.id);
glBindBuffer(GL_ARRAY_BUFFER, vbuffer.id);
glVertexAttribPointer( vbufferVar,
3,
GL_FLOAT,
false,
sizeof(glm::vec3),
GLF_BUFFER_OFFSET(0));
glEnableVertexAttribArray(vbufferVar);
glDrawArrays(GL_TRIANGLES, 0, vbuffer.Size());
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindFramebuffer(GL_FRAMEBUFFER,0);
glViewport(0,0,ctx::window.Size.x,ctx::window.Size .y);

glCullFace(GL_BACK);
glDepthMask(true);
glEnable(GL_DEPTH_TEST);



VS :


#version 330 core
in vec3 Position;
void main()
{
gl_Position = vec4(Position,1.f);
}


GS :


#version 330 core

uniform mat4 Transformations[6];

layout(triangles) in;
layout(triangle_strip, max_vertices = 18) out;

out vec3 gPosition;

void main()
{
for(int layer=0;layer<6;++layer)
{
gl_Layer = layer;
for(int i=0; i<3;++i)
{
gl_Position = Transformations[layer] * gl_in[i].gl_Position;
gPosition = gl_in[i].gl_Position.xyz;
EmitVertex();
}
EndPrimitive();
}
}


FS :


#version 330 core
in vec3 gPosition;
out vec4 FragColor;

void main()
{
FragColor = vec4(gPosition,1);
return;
}




BTW, when I visualize the FBO in gDEBugger with an attached TEXTURE_CUBE_MAP, it says that something is attached but it doesn't say what. When I do the same with TEXTURE_2D_ARRAY, it says a TEXTURE_2D_ARRAY is attached. Weird.

My configuration :
- Win7 32
- OpenGL 3.3 Core
- nVidia 580GTX
- Driver 266.58

Bug driver ? Any idea ?

Thank you.