FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Depth buffer issues with GL3 and deferred shading

 
Post new topic   Reply to topic     Forum Index -> Derelict
View previous topic :: View next topic  
Author Message
ste3e



Joined: 08 Apr 2012
Posts: 17
Location: New Zealand

PostPosted: Sat May 05, 2012 4:38 am    Post subject: Depth buffer issues with GL3 and deferred shading Reply with quote

Sorted! When I was figuring out that glEnable calls must follow the setting up of the gl context I must have removed glDepthFunc. Now that I have replaced it the code is working proper.


I have noticed that calls to set the clear color and enable depth testing are ignored if they are made prior to setting up the SDL_GL context and reloading Derelict3. I had to make them in the following order:

Code:
win=SDL_CreateWindow("3Doodle", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, w, h, flags);
if(!win){
       writefln("Error creating SDL window");
      SDL_Quit();
}

context=SDL_GL_CreateContext(win);
SDL_GL_SetSwapInterval(1);
      
glVersion=DerelictGL3.reload();

glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);

glClearColor(0.0, 0.0, 0.0, 1.0);
glClearDepth(1.0);

glCullFace(GL_BACK);
glFrontFace(GL_CCW);


While this sorted out depth culling while writing to the standard double buffer, when I implement a framebuffer object with a renderBuffer as the new depth buffer I get a freeze... the program compiles and runs without warnings, but the rendered image to the screen aligned quad remains fixed. If I comment out glEnable(GL_DEPTH_TEST); the camera moves freely but the the rendered image pays no mind to depth testing and simply draws objects in order.

The framebuffer initialization code is:

Code:
//fbo
glEnable (GL_FRAMEBUFFER_SRGB);
glGenFramebuffers(1, &fbo);
assert(fbo > 0);
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
      
glGenRenderbuffers(1, &rbo);
assert(rbo > 0);
glBindRenderbuffer(GL_RENDERBUFFER, rbo);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, projMat.w, projMat.h);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rbo);
glBindRenderbuffer(GL_RENDERBUFFER, 0);
      
glGenTextures(1, &fbon);
assert(fbon > 0);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, fbon);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, projMat.w, projMat.h, 0, GL_RGBA, GL_UNSIGNED_BYTE, null);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);   
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, fbon, 0);
glBindTexture(GL_TEXTURE_2D, 0);
      
glGenTextures(1, &fboc);
assert(fboc > 0);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, fboc);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, projMat.w, projMat.h, 0, GL_RGBA, GL_UNSIGNED_BYTE, null);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);   
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, fboc, 0);
glBindTexture(GL_TEXTURE_2D, 0);
      
glGenTextures(1, &fbop);
assert(fbop > 0);
glActiveTexture(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, fbop);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, projMat.w, projMat.h, 0, GL_RGBA, GL_UNSIGNED_BYTE, null);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);   
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT2, GL_TEXTURE_2D, fbop, 0);
glBindTexture(GL_TEXTURE_2D, 0);
      
int status=glCheckFramebufferStatus(GL_FRAMEBUFFER);
assert(status == GL_FRAMEBUFFER_COMPLETE);
      
buffs=[GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2];
glDrawBuffers(3, buffs.ptr);
glBindFramebuffer(GL_FRAMEBUFFER, 0);


The code calling the fbo in draw() is:

Code:
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
      
glUseProgram(shad);
glUniformMatrix4fv(viewLoc, 1, GL_TRUE, player.mat.ptr);
      
current.draw();
      
glUseProgram(0);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
      
rend.draw();


I am at a loss as the same codes is working in c# as it ought.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> Derelict All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group