Jump to content
  • Advertisement
Sign in to follow this  
fazekaim

problem porting pbuffer shadowing to fbo

This topic is 4826 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, i ported the lispm ( http://www.cg.tuwien.ac.at/research/vr/lispsm/ ) program to Java (jogl), and i qould like to use it with framebuffer object. The reference implementation create a depth texture like this:
glGenTextures(1,&depthTexture);
	glBindTexture(GL_TEXTURE_2D,depthTexture);
	glTexImage2D(GL_TEXTURE_2D,0,GL_DEPTH_COMPONENT,depthMapSize,depthMapSize,
		0,GL_DEPTH_COMPONENT,GL_UNSIGNED_BYTE,0);

	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP);

	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_COMPARE_FUNC_ARB,GL_LEQUAL);	
	glTexParameteri(GL_TEXTURE_2D,GL_DEPTH_TEXTURE_MODE_ARB,GL_LUMINANCE);
	//if available use a shadow ambient value
	glTexParameterfv(GL_TEXTURE_2D,GL_TEXTURE_COMPARE_FAIL_VALUE_ARB,globalAmbient);

I tried to create a fbo texture like this, but the fbo creation failed. I can create GL_RGB or GL_RGBA texture, but not a GL_DEPTH_COMPONENT texture. How can i resolve this? Thanks.

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
I could help you because im using FBO to do Multiple Render Targets and the depth buffer is one im rendering to texture. But i only can help you with code tomorrow, so here's my email: promag@di.uminho.pt feel free to write me.

Anyway, I think imho your texture creation is wrong, and probably your FBO schema is also wrong, but u dunno... you could post these code also?

Cheers
João Barbosa

Share this post


Link to post
Share on other sites
The code inserted into my post is a copy of the reference implementation of lispsm by it's author.
Using color texture as depth texture? How?

Share this post


Link to post
Share on other sites
Quote:
Original post by fazekaim
The code inserted into my post is a copy of the reference implementation of lispsm by it's author.
Using color texture as depth texture? How?


You need to post your FBO code, phantom is referring to the parameters you would send to the FBO functions to let GL know what kind of texture you are using and there are two kinds color and depth...

Share this post


Link to post
Share on other sites
ok. here it is:


public static void createNewReflectionFrameBuffer(int width, int height, int[] FBO, int[] FBORenderBuffer, int[] FBOTexture ){

if( FBORenderBuffer[0] > 0 ) gl.glDeleteRenderbuffersEXT( 1, FBOTexture );
if( FBOTexture[0] > 0 ) gl.glDeleteTextures( 1, FBOTexture );
if( FBO[0] > 0 ) gl.glDeleteFramebuffersEXT( 1, FBOTexture );

gl.glGenFramebuffersEXT( 1, FBO );
gl.glGenTextures( 1, FBOTexture );
gl.glGenRenderbuffersEXT( 1, FBORenderBuffer );

gl.glBindFramebufferEXT( GL.GL_FRAMEBUFFER_EXT, FBO[0] );

gl.glBindTexture( GL.GL_TEXTURE_2D, FBOTexture[0] );
gl.glTexImage2D( GL.GL_TEXTURE_2D, 0, GL.GL_DEPTH_COMPONENT, width, height, 0, GL.GL_DEPTH_COMPONENT, GL.GL_UNSIGNED_BYTE, BufferUtils.bufferOffset(0) );
//-------------------------
//gl.glTexParameteri( GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP);
//gl.glTexParameteri( GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP);
gl.glTexParameteri( GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR);
gl.glTexParameteri( GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR);
//l.glTexParameteri( GL.GL_TEXTURE_2D, GL.GL_TEXTURE_COMPARE_FUNC_ARB, GL.GL_LEQUAL);
//gl.glTexParameteri( GL.GL_TEXTURE_2D, GL.GL_DEPTH_TEXTURE_MODE_ARB, GL.GL_LUMINANCE);
//gl.glTexParameterfv( GL.GL_TEXTURE_2D, GL.GL_TEXTURE_COMPARE_FAIL_VALUE_ARB,globalAmbient);
//-------------------------
gl.glFramebufferTexture2DEXT( GL.GL_FRAMEBUFFER_EXT, GL.GL_COLOR_ATTACHMENT0_EXT, GL.GL_TEXTURE_2D, FBOTexture[0], 0 );

gl.glBindRenderbufferEXT( GL.GL_RENDERBUFFER_EXT, FBORenderBuffer[0] );
gl.glRenderbufferStorageEXT( GL.GL_RENDERBUFFER_EXT, GL.GL_DEPTH_COMPONENT24, width, height );
gl.glFramebufferRenderbufferEXT( GL.GL_FRAMEBUFFER_EXT, GL.GL_DEPTH_ATTACHMENT_EXT, GL.GL_RENDERBUFFER_EXT, FBORenderBuffer[0] );

if( !checkFrameBufferStatus( width, height ) ){
JOptionPane.showMessageDialog(null, "FBO jajjajj", "Unavailable extension", JOptionPane.ERROR_MESSAGE);
System.exit( -1 );
}

gl.glBindFramebufferEXT(GL.GL_FRAMEBUFFER_EXT, 0);
//System.out.println("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%");
}
public static boolean checkFrameBufferStatus(int width, int height) {
int status = gl.glCheckFramebufferStatusEXT( GL.GL_FRAMEBUFFER_EXT );
//System.out.println("<><><>"+GL.GL_FRAMEBUFFER_COMPLETE_EXT+" "+GL.GL_FRAMEBUFFER_UNSUPPORTED_EXT+" "+status);
switch(status) {
case GL.GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENTS_EXT:
EngineReckonings.log( "Framebuffer status = GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT" +status);
return false;
case GL.GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT:
EngineReckonings.log( "Framebuffer status = GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT" +status);
return false;
case GL.GL_FRAMEBUFFER_INCOMPLETE_DUPLICATE_ATTACHMENT_EXT:
EngineReckonings.log( "Framebuffer status = GL_FRAMEBUFFER_INCOMPLETE_DUPLICATE_ATTACHMENT_EXT" +status);
return false;
case GL.GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT:
EngineReckonings.log( "Framebuffer status = GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT" +status);
return false;
case GL.GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT:
EngineReckonings.log( "Framebuffer status = GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT"+status);
return false;
case GL.GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT:
EngineReckonings.log( "Framebuffer status = GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT"+status);
return false;
case GL.GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT:
EngineReckonings.log( "Framebuffer status = GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT" );
return false;
case GL.GL_FRAMEBUFFER_COMPLETE_EXT:
EngineReckonings.log( "Successfully created the frame buffer object < " +
width + ", " + height + ">" );
return true;
case GL.GL_FRAMEBUFFER_UNSUPPORTED_EXT:
EngineReckonings.log("Failed to create the frame buffer object, please verify your format");
return false;
default:
EngineReckonings.log("????? FBO ????????");
return false;
}
}




Share this post


Link to post
Share on other sites

gl.glFramebufferTexture2DEXT( GL.GL_FRAMEBUFFER_EXT, GL.GL_COLOR_ATTACHMENT0_EXT, GL.GL_TEXTURE_2D, FBOTexture[0], 0 );




That is what we are referring to. Change the GL_COLOR_ATTACHEMENT0_EXT to DEPTH_ATTACHMENT_EXT

Share this post


Link to post
Share on other sites
here is my code:


gl.glGenFramebuffersEXT( 1, FBO );
gl.glGenTextures( 1, FBORenderBuffer );

gl.glBindFramebufferEXT( GL.GL_FRAMEBUFFER_EXT, FBO[0] );

gl.glBindTexture( GL.GL_TEXTURE_2D, FBORenderBuffer[0] );
gl.glTexImage2D( GL.GL_TEXTURE_2D, 0, GL.GL_RGBA, width, height, 0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, BufferUtils.bufferOffset(0) );
gl.glTexParameteri( GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_NEAREST );
gl.glTexParameteri( GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST );
gl.glFramebufferTexture2DEXT( GL.GL_FRAMEBUFFER_EXT, GL.GL_DEPTH_ATTACHMENT_EXT, GL.GL_TEXTURE_2D, FBORenderBuffer[0], 0 );

if( !EngineReckonings.checkFrameBufferStatus( width, height ) ){
JOptionPane.showMessageDialog(null, "FBO jajjajj", "Unavailable extension", JOptionPane.ERROR_MESSAGE);
System.exit( -1 );
}

gl.glBindFramebufferEXT(GL.GL_FRAMEBUFFER_EXT, 0);



and i got an error: GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT36054

replacing GL_COLOR_ATTACHMENT0_EXT to GL_DEPTH_ATTACHMENT_EXT doesn't seem to be working.
I tried to use 2 texture:

gl.glGenFramebuffersEXT( 1, FBO );
gl.glGenTextures( 1, FBOTexture );
gl.glGenTextures( 1, FBORenderBuffer );

gl.glBindFramebufferEXT( GL.GL_FRAMEBUFFER_EXT, FBO[0] );

gl.glBindTexture( GL.GL_TEXTURE_2D, FBOTexture[0] );
gl.glTexImage2D( GL.GL_TEXTURE_2D, 0, GL.GL_RGB, width, height, 0, GL.GL_RGB, GL.GL_UNSIGNED_BYTE, BufferUtils.bufferOffset(0) );
gl.glTexParameteri( GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_NEAREST );
gl.glTexParameteri( GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST );
//gl.glBindTexture( GL.GL_TEXTURE_2D, FBOTexture[0] );
gl.glFramebufferTexture2DEXT( GL.GL_FRAMEBUFFER_EXT, GL.GL_COLOR_ATTACHMENT0_EXT, GL.GL_TEXTURE_2D, FBOTexture[0], 0 );

gl.glBindTexture( GL.GL_TEXTURE_2D, FBORenderBuffer[0] );
gl.glTexImage2D( GL.GL_TEXTURE_2D, 0, GL.GL_RGBA, width, height, 0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, BufferUtils.bufferOffset(0) );
gl.glTexParameteri( GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_NEAREST );
gl.glTexParameteri( GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST );
gl.glFramebufferTexture2DEXT( GL.GL_FRAMEBUFFER_EXT, GL.GL_DEPTH_ATTACHMENT_EXT, GL.GL_TEXTURE_2D, FBORenderBuffer[0], 0 );

if( !EngineReckonings.checkFrameBufferStatus( width, height ) ){
JOptionPane.showMessageDialog(null, "FBO jajjajj", "Unavailable extension", JOptionPane.ERROR_MESSAGE);
System.exit( -1 );
}

gl.glBindFramebufferEXT(GL.GL_FRAMEBUFFER_EXT, 0);



the result is the same.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
glGenFramebuffersEXT(1, &framebuffer);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, framebuffer);

// need to define the color buffer
glGenRenderbuffersEXT(1, &colorbuffer);
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, colorbuffer);
glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA, width, height);
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, colorbuffer);

// depth buffer rendered to texture
glGenTextures(1, &depthtexture);
glBindTexture(GL_TEXTURE_2D, depthtexture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, width, height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL); // not unsigned byte but float
glTexParameteri(...); // texture parameters go here...
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, depthtexture, 0);

if(glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT)!=GL_FRAMEBUFFER_COMPLETE_EXT) error();

I striped out this code from mine and did some changes to meet your requirements, so I belive it will work.. but if not then post some results or errors.

Cheers
João Barbosa

Share this post


Link to post
Share on other sites

The error occurs because the texture you use for DEPTH_ATTACHMENT is an RGBA texture. This needs to be a DEPTH_COMPONENT texture.

Apart from that, your second example should work just fine.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!