Hey guys. I'm trying to get my application to work on my Nvidia GTX 970 desktop. It currently works on my Intel HD 3000 laptop, but on the desktop, every bind textures specifically from framebuffers, I get half a second of lag. This is done 4 times as I have three RGBA textures and one depth 32F buffer. I tried to use debugging software for the first time - RenderDoc only shows SwapBuffers() and no OGL calls, while Nvidia Nsight crashes upon execution, so neither are helpful. Without binding it runs regularly. This does not happen with non-framebuffer binds.
GLFramebuffer::GLFramebuffer(FramebufferCreateInfo createInfo) {
glGenFramebuffers(1, &fbo);
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
textures = new GLuint[createInfo.numColorTargets];
glGenTextures(createInfo.numColorTargets, textures);
GLenum *DrawBuffers = new GLenum[createInfo.numColorTargets];
for (uint32_t i = 0; i < createInfo.numColorTargets; i++) {
glBindTexture(GL_TEXTURE_2D, textures[i]);
GLint internalFormat;
GLenum format;
TranslateFormats(createInfo.colorFormats[i], format, internalFormat); // returns GL_RGBA and GL_RGBA
glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, createInfo.width, createInfo.height, 0, format, GL_FLOAT, 0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
DrawBuffers[i] = GL_COLOR_ATTACHMENT0 + i;
glBindTexture(GL_TEXTURE_2D, 0);
glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, textures[i], 0);
}
if (createInfo.depthFormat != FORMAT_DEPTH_NONE) {
GLenum depthFormat;
switch (createInfo.depthFormat) {
case FORMAT_DEPTH_16:
depthFormat = GL_DEPTH_COMPONENT16;
break;
case FORMAT_DEPTH_24:
depthFormat = GL_DEPTH_COMPONENT24;
break;
case FORMAT_DEPTH_32:
depthFormat = GL_DEPTH_COMPONENT32;
break;
case FORMAT_DEPTH_24_STENCIL_8:
depthFormat = GL_DEPTH24_STENCIL8;
break;
case FORMAT_DEPTH_32_STENCIL_8:
depthFormat = GL_DEPTH32F_STENCIL8;
break;
}
glGenTextures(1, &depthrenderbuffer);
glBindTexture(GL_TEXTURE_2D, depthrenderbuffer);
glTexImage2D(GL_TEXTURE_2D, 0, depthFormat, createInfo.width, createInfo.height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, 0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glBindTexture(GL_TEXTURE_2D, 0);
glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, depthrenderbuffer, 0);
}
if (createInfo.numColorTargets > 0)
glDrawBuffers(createInfo.numColorTargets, DrawBuffers);
else
glDrawBuffer(GL_NONE);
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
std::cout << "Framebuffer Incomplete\n";
glBindFramebuffer(GL_FRAMEBUFFER, 0);
width = createInfo.width;
height = createInfo.height;
}
// ...
// FBO Creation
FramebufferCreateInfo gbufferCI;
gbufferCI.colorFormats = gbufferCFs.data();
gbufferCI.depthFormat = FORMAT_DEPTH_32;
gbufferCI.numColorTargets = gbufferCFs.size();
gbufferCI.width = engine.settings.resolutionX;
gbufferCI.height = engine.settings.resolutionY;
gbufferCI.renderPass = nullptr;
gbuffer = graphicsWrapper->CreateFramebuffer(gbufferCI);
// Bind
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo);
// Draw here...
// Bind to textures
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, textures[0]);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, textures[1]);
glActiveTexture(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, textures[2]);
glActiveTexture(GL_TEXTURE3);
glBindTexture(GL_TEXTURE_2D, depthrenderbuffer);
Here is an extract of my code. I can't think of anything else to include. I've really been butting my head into a wall trying to think of a reason but I can think of none and all my research yields nothing. Thanks in advance!
↧