Hi,

here's a new patch that fixes another missing feature when rendering
is set to setFboOn(flase). The getReadBuffer attribute was ignored.
So now in "emulation mode" it's also possible to read back the pixel
data into main memory. Please review the code. I'm not sure if
glReadBuffer( GL_BACK ) is correct for all possible cases.

Regards,

  Toni

P.S.: This patch contains the previous patch!

--
Ing. Antonio Bleile
Seac02 S.r.l.
via Avogadro 4
10121 Torino Italia
Tel. +39.011.197.006.52
Fax +39.011.197.006.53
E-mail [EMAIL PROTECTED]
Sito www.seac02.it
Index: OSGFBOViewport.cpp
===================================================================
RCS file: /cvsroot/opensg/OpenSG/Source/System/Window/OSGFBOViewport.cpp,v
retrieving revision 1.11
diff -u -r1.11 OSGFBOViewport.cpp
--- OSGFBOViewport.cpp  30 Aug 2007 16:03:43 -0000      1.11
+++ OSGFBOViewport.cpp  3 Sep 2007 09:44:46 -0000
@@ -884,22 +884,61 @@
                         // deactivate viewport settings
                         deactivate();
 
-                        win->validateGLObject(getTextures(0)->getGLId());
+                       GLenum target;
+                       // copy ALL attached textures.
+                       // Most likely there's just one texture attached, the 
color
+                       // buffer or the depth buffer. But in case both are 
attached, copy both!
+                       for(UInt16 nt = 0; nt < getTextures().getSize(); nt++)
+                       {
+                               
win->validateGLObject(getTextures(nt)->getGLId());
                         
-                        GLenum target = getTextures(0)->getTarget();
+                               target = getTextures(nt)->getTarget();
                         
-                        // TODO; check if target is valid and allow usage of 
3d texture slices
-                        if (target == GL_NONE)
-                            target = GL_TEXTURE_2D;
+                               // TODO; check if target is valid and allow 
usage of 3d texture slices
+                               if (target == GL_NONE)
+                                       target = GL_TEXTURE_2D;
                         
-                        glBindTexture(target, 
-                            win->getGLObjectId(getTextures(0)->getGLId()));
+                               glBindTexture(target, 
+                                       
win->getGLObjectId(getTextures(nt)->getGLId()));
                         
-                        glCopyTexSubImage2D(target, 0, x1, y1, 0, 0, tw, th);
-                        
-                        if (glGetError() != GL_NO_ERROR)
-                            SWARNING << "Error in Texture-Creation! " << 
endLog;    
+                               glCopyTexSubImage2D(target, 0, x1, y1, 0, 0, 
tw, th);
                         
+                               if (glGetError() != GL_NO_ERROR)
+                                       SWARNING << "Error in Texture-Creation! 
" << endLog;    
+
+                                if(getReadBuffer())
+                                {
+                                        Int32 format = 
getTextures(nt)->getInternalFormat();
+                                        if ( format == GL_DEPTH_COMPONENT || 
+                                            (format >= 
GL_DEPTH_COMPONENT16_ARB &&
+                                             format <= 
GL_DEPTH_COMPONENT32_ARB) ||
+                                             format == GL_STENCIL_INDEX ||
+                                             format == GL_DEPTH_STENCIL_EXT )
+                                                continue; // ignore non-color 
buffers
+
+                                        ImagePtr texImg = 
getTextures(nt)->getImage();
+
+                                        if((texImg->getWidth () != 
getStorageWidth ()) ||
+                                           (texImg->getHeight() != 
getStorageHeight()) ||
+                                           (texImg->getData  () == NULL        
      )   )
+                                       {
+                                                SINFO << "FBOViewport::render: 
(Re)Allocating image "
+                                                      << "for read-back."
+                                                      << endLog;
+                    
+                                                
texImg->set(texImg->getPixelFormat(),
+                                                            getStorageWidth(),
+                                                            getStorageHeight() 
      );
+                                        }
+                    
+                                        // select GL_COLORATTACHMENTn and read 
data into image
+                                        glReadBuffer(GL_BACK); // readback 
from back buffer!
+                                        glReadPixels(0, 0, getStorageWidth(), 
getStorageHeight(),
+                                                     texImg->getPixelFormat(), 
texImg->getDataType(),
+                                                     texImg->getData() );
+                                        glReadBuffer(GL_NONE);
+                                }
+                       }
                         glBindTexture(target, 0);
                     }
                 }
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
Opensg-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensg-users

Reply via email to