PDA

View Full Version : Using OpenGL framebuffer object in custom rendering in Viewport 2.0


Muhe
07-03-2012, 03:36 PM
Hi,

I'm trying to code a draw override for a shape in the viewport 2.0.
Everything works fine until i try to draw into an offscreen framebuffer.
If I bind an offscreen framebuffer (glBindFramebuffer()), it looks like Maya's screen buffer is erased (all black).
I do it in MPxDrawOverride's 'prepareforDraw()' method.
When I tried to use framebuffer in stand-alone program it did not erase screen buffer.
Does anybody know how framebuffers work in Maya? Or more importantly how to draw to a texture in Maya without corrupting what was already drawn on the screen?

I tried to overcome this problem by saving the screen buffer by M3dView::readColorBuffer() and then upload it back after offscreen drawing but it is a bit slow and fails when multisampling is enabled.

Thanks for any advise.

Maitreya
07-06-2012, 01:52 AM
once i tried also to use OPENGL in my own maya plugin. seems since maya itself use OPENGL, the framebuffer would always got influenced with each other between user's framebuffer and maya's....
create a complete new thread will solve this problem(once asked similar question here, got this :cool: ) but maybe better not use your own OPENGL in maya?
i myself don't know much about this, hope there are better solution ^_^

Muhe
07-06-2012, 09:42 AM
once i tried also to use OPENGL in my own maya plugin. seems since maya itself use OPENGL, the framebuffer would always got influenced with each other between user's framebuffer and maya's....
create a complete new thread will solve this problem(once asked similar question here, got this :cool: ) but maybe better not use your own OPENGL in maya?
i myself don't know much about this, hope there are better solution ^_^
Thanks for reply. I think that using OpenGL in Maya is completely valid. For some reason framebuffer object is corrupting Maya's Viewport 2.0. I just found out that it works fine in default viewport so the problem lies in the Viewport 2.0.

djx
07-06-2012, 10:59 AM
Since I'm a frustrated viewport2 user I'll be interested to hear if you eventually work around your problem. Sorry I cant help with the coding though.

I did want to point out that the behaviour you describe with the buffer erasing to black sounds similar to what I get when I use script extra modelPanel/modelEditor setups with viewport2. Closing one panel sometimes causes the other to go black. There are plenty of other issues so it may be for different reasons, but there it is.

I'd love it if you'd drop back every little while and let us know how its going.

cheers
David

Keilun
07-06-2012, 07:35 PM
So long as you're in 2012+, you might want to have a look at the blastCmd.cpp file. It illustrates usage of some Maya FBO API to render to an offscreen texture and write it out to disk. The purpose of that plug-in is to create your own playblast.

I believe that plug-in might only be shipped on Linux, or perhaps it was just the binary is only precompiled on Linux. I can't recall. I customized it on Linux and it worked mostly, although there was a bug if you wanted to render a size other than the current viewport size. I believe thats fixed in the latest 2013 SP though.

In any case, hope this helps.

Edit: In case this is also an alternative for your needs, another approach is to use MRenderOverrides. This is mostly your typical post-effect script chain. You can set up buffers to render into and reuse them as shader inputs down the line. But of course this has rather limited value depending on what you need your offscreen texture for.

zoharl
07-07-2012, 02:09 PM
When I need some manual stuff, I personally prefer not to rely on maya, and to work instead with my own opengl environment. When performance is needed I also setup a fbo (glGenFramebuffersEXT). Also see if you can find something useful in the following discussion:

http://forums.cgsociety.org/showthread.php?f=89&t=1001043&page=1&pp=15

Muhe
07-07-2012, 07:03 PM
Thanks for replies.

I work in Maya 2012.
Unfortunatly I wasn't able to find the blastCmd.cpp file.

Rendering to own opengl context seem interesting, but I don't have much time to test it now.

Anyway, I found out that if I enable shadow mapping in Viewport 2.0, my code works well. But the Maya's shadow map don't work. Maya is probably internally using fbo for shadow mapping so there is something fishy.
I'll probably try to port the code to Maya 2013 if there would be a difference ...

Muhe
07-10-2012, 01:04 PM
I finally found out where the problem was (the idea came during washing dishes :)).

Viewport 2.0 draws not directly to screen buffer, but to some custom framebuffer object (which I did not realize). What I did was that I bound my custom framebuffer, renderer what I needed, and then bound the default screen framebuffer, not the framebuffer Maya was using. That lead to the wierd behaviour I described earlier.

Anyway, thanks for the support. Hopefuly, this thread will help somebody and he would not have to waste many long hours on this problem like I did.

mlager8
07-10-2012, 07:23 PM
Not to be completely off topic here, but Dave, is your icon the chick from die antwoord..?

suyati
07-11-2012, 08:33 AM
If it's any help than have a look at the gpuCache plugin in the devkit of 2013. i just had a quick look at it and it uses vbo's. there also a viewport 2.0 implementation (gpuCacheGeometryOverride files)

CGTalk Moderation
07-11-2012, 08:33 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.