-1

My Problem:

When trying to perform frame buffer operations in a separate class outside of the main one handling my rendering loop, the code executes and some functions register, but ultimately the result of the operations doesn't render.

To be absolutely clear, if I copy my intended rendering operations out of a separate class (GBuffer) and merge it into my main rendering class, everything works.

If that happens to be the wrong question, an alternative question would be "how do I perform rendering operations outside of the QOpenGLWidget class?"

Details:

In my rendering loop, I can perform the following and render a scene to my screen:

glBindFramebuffer(GL_DRAW_FRAMEBUFFER, TARGET_FBO);
glDrawBuffer(GL_COLOR_ATTACHMENT4);
glClear(GL_COLOR_BUFFER_BIT);

RenderPass();

glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
glBindFramebuffer(GL_READ_FRAMEBUFFER, TARGET_FBO);
glReadBuffer(GL_COLOR_ATTACHMENT4);
glBlitFramebuffer(0, 0, width, height, 0, 0, width, height, GL_COLOR_BUFFER_BIT, GL_LINEAR);

However, if I move the lines before and after the render pass into a separate class, such as a GBuffer, the code will run, but nothing will render:

GBuffer.StartFrame();

RenderPass();

GBuffer.FinalPass();
glBlitFramebuffer(0, 0, width, height, 0, 0, width, height, GL_COLOR_BUFFER_BIT, GL_LINEAR);

My rendering class extends a class of mine Called DFuncShader, which holds a shader program and extends QOpenGLFunctions_4_3_Core. I've been doing this for several other classes and haven't noticed any problems, however none of them did anything with frame buffers before, they all mainly just handled shader operations.

The only differences is that my Rendering class inherits from the QOpenGLWidget as well.

The only solution I can think of is to add a pointer in my GBuffer class towards my main rendering class, and append all OpenGL calls with that pointer, pretty much making the class moot...

Yattabyte
  • 1,280
  • 14
  • 28

2 Answers2

3

The refactoring that you described should not affect the result as the OpenGL is just a C API and doesn't care about any C++ wrapping that you do on top of it, as long as the function order is the same and parameters are the same. Are you sure that TARGET_FBO is the same in both versions? You can capture a trace using Apitrace with both versions and compare. I suspect some difference will come up that can explain the failure.

Etay Meiri
  • 336
  • 1
  • 2
  • 4
  • Yes I am certain, I directly copied the entire class over. This morning, or rather just now, I checked which lines I was able to keep and what I could move back, and I found out that the only call that wasn't working was the one binding the default frame buffer, when done outside of my main rendering class. – Yattabyte Sep 08 '15 at 15:47
0

I narrowed down which functions weren't working when used from outside the provided "QOpenGLWidget" class, and it seems as long as I bind the default frame buffer within my main QOpenGLWidget class, then everything is fine.

That one line

glBindFramebuffer(GL_FRAMEBUFFER, defaultFramebufferObject());

or any variation like using "0" apparently can't happen in any other of my classes except for the one dealing with my rendering loop.

This is easy enough to deal with.

Yattabyte
  • 1,280
  • 14
  • 28