Hmmm... okay.. some additional info on this topic:
- I tried with a new StateAttribute "osg::DrawBuffer", but this doen'st work :-( the situation is:
I have the top pre_render camera, I attach both texture2dArrays on slot 1 and slot 2 (slot 0 is already used by a needed sampler, also, those too textures are attached on COLOR_BUFFER0 and COLOR_BUFFER1); then I add child quads with the osg::DrawBuffer state attribute properly configured, and an uniform properly configured to access the "source texture" (as opposed to the texture being rendered on that quad, which is supposed to be determined by the DrawBuffer state attribute...)
=> If I perform a "single pass" (rendering texture B from texture A) then both texture A and B are properly rendered.
=> As soon as I try to render two passes (rendering texture B from texture A then rendering texture A from Texture B) then texture B is still OK but texture A is completely black :-(
- So I assumed the osg::DrawBuffer" stateAttribute was not working as expected (but here I really don't understand why...) and started creating a special PingPongDrawable.
The idea with this ping pong drawable is to place is just under the camera previously defined (so I assume the FBO is applied, the textures are applied, the shader program is applied and the color buffers are attached: I attached the source of that "PingPongDrawable if someone wants to have a look... it's main part is to render all the passes in one cycle just as in the pure OpenGL code snipped I'm using as template:
So the main part of the code is:
// just call the OpenGL code.
for (int i = 0; i < _numPasses; ++i) { //
extensions->glUniform1f(passLoc, float(i + 0.5) / _numPasses);
if (i%2 == 0) {
extensions->glUniform1i(imgLoc, 1); // use the first texture.
glDrawBuffer(GL_COLOR_ATTACHMENT1_EXT);
} else {
extensions->glUniform1i(imgLoc, 2); // Use the second texture.
glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);
}
drawQuad();
}
... but here again... everything is fine with a single pass but the texture A becomes completely black as soon as I try with 2 passes...
I'm really starting to feel desperated so if somebody as a clue why my first texture2D array gets cleared /destroyed/ sent into another dimension ? that would be very helpful.
Buy the way, here is how the FBO camera is setup if you want to know that (this is some lua code, but I guess everyone can understand the osg calls):
local PASSES = options.PASSES or 8; local FFT_SIZE = options.FFT_SIZE or 256
-- Create a single camera holding the attachments:
local cam = osg.Camera(); cam:setRenderOrder(osg.Camera.RenderOrder.PRE_RENDER,11);
cam:setClearColor(osg.Vec4(1.0,0.0,0.0,1.0)); --cam:setClearMask(GL.Mode.GL_COLOR_BUFFER_BIT + GL.Mode.GL_DEPTH_BUFFER_BIT)
cam:setClearMask(0) cam:setViewport(osg.Viewport(0,0,FFT_SIZE,FFT_SIZE))
--cam:setReferenceFrame(osg.Transform.ReferenceFrame.ABSOLUTE_RF); --cam:setGraphicsContext(context);
cam:setRenderTargetImplementation(osg.Camera.RenderTargetImplementation.FRAME_BUFFER_OBJECT)
-- attach the buffers to the init camera: --cam:setReadBuffer(GLValues.GL_COLOR_ATTACHMENT0_EXT);
local ss = cam:getOrCreateStateSet() ss:setMode(GL.Mode.GL_BLEND,osg.StateAttribute.Values.OFF+osg.StateAttribute.Values.OVERRIDE+osg.StateAttribute.Values.PROTECTED)
ss:setMode(GL.Mode.GL_DEPTH_TEST,osg.StateAttribute.Values.OFF+osg.StateAttribute.Values.OVERRIDE+osg.StateAttribute.Values.PROTECTED)
cam:attach(osg.Camera.BufferComponent.COLOR_BUFFER0,result.ffta,0) --,0,true); -- last true here means: generate mipmaps (is it needed ??)
cam:attach(osg.Camera.BufferComponent.COLOR_BUFFER1,result.fftb,0) --,0,true); -- last true here means: generate mipmaps (is it needed ??)
ss:setTextureAttribute(1,result.ffta,osg.StateAttribute.Values.ON);
ss:setTextureAttribute(2,result.fftb,osg.StateAttribute.Values.ON);
local ss = cam:getOrCreateStateSet(); cam:setReadBuffer(GLValues.GL_COLOR_ATTACHMENT0_EXT)
cam:setDrawBuffer(GLValues.GL_COLOR_ATTACHMENT0_EXT)
local proj = giProject.ProjectManager.getProject("ocean2"); assignTexture{ss=ss,name="butterfly",project=proj,slot=0}
release(proj) --- Save uniform here:
giScene.SceneTools.setIntUniform(ss:getOrCreateUniform("nLayers",osg.Uniform.Type.INT), options.choppy and 5 or 3)
local fftx_passes = osg.Group() cam:addChild(fftx_passes)
local ss = fftx_passes:getOrCreateStateSet()
-- Add the program: local proj = giProject.ProjectManager.getProject("ocean2");
local prog = createProgram(proj,"fftx") ss:setAttributeAndModes(prog)
release(proj) -- Add passes:
local pass = setupFFTPass(options,result,prog,8) -- this is where the "pingPongDrawable" is created and added (taking the program and numPasses as arguments)
fftx_passes:addChild(pass)Thanks for your help guys!
cheers,
Manu.