Hi Robert,

On Tue, Dec 8, 2009 at 2:25 PM, Robert Milharcic
<[email protected]> wrote:
> Anyway, I agree that at this point it is best not to include this feature 
> into core. Thanks for your suggestions and time spend...

For clarity, I don't think a readPixels callback is appropriate now,
or anytime in the future.  I believe it's in appropriate to utilize
callbacks for such low level operations - if we started doing this for
overriding basic methods where do you stop?  Every single method in
every single class to have it's own callback?  I try use the "minimal
and complete" approach classes API's, for me the readPixels falls well
short of this requirement as you can already override the required
function with higher level callbacks that are already more general
purpose and sufficient.

There is also one far less intrusive and verbose approach to enable
user customization in C++, and that's to make methods virtual.  This
would require one to subclass from osg::Image but this is no more
effort than subclassing from a Callback class.  One does need to
consider how often a method is called before one takes the step to
declare a function virtual, and in this case readPixels() is called
very rarely on each frame so the overhead would be negligible.  With
this in mind I've made a number of osg::Image methods virtual, to
allow for greater customization.  The following methods are now
virtual, and svn update will get these changes.

        /** Allocate a pixel block of specified size and type. */
        virtual void allocateImage(int s,int t,int r,
                           GLenum pixelFormat,GLenum type,
                           int packing=1);


        /** Set the image dimensions, format and data. */
        virtual void setImage(int s,int t,int r,
                      GLint internalTextureformat,
                      GLenum pixelFormat,GLenum type,
                      unsigned char* data,
                      AllocationMode mode,
                      int packing=1);

        /** Read pixels from current frame buffer at specified
position and size, using glReadPixels.
          * Create memory for storage if required, reuse existing
pixel coords if possible.
        */
        virtual void readPixels(int x,int y,int width,int height,
                        GLenum pixelFormat,GLenum type);


        /** Read the contents of the current bound texture, handling
compressed pixelFormats if present.
          * Create memory for storage if required, reuse existing
pixel coords if possible.
        */
        virtual void readImageFromCurrentTexture(unsigned int
contextID, bool copyMipMapsIfAvailable, GLenum type =
GL_UNSIGNED_BYTE);

        /** Scale image to specified size and with specified data type. */
        virtual void scaleImage(int s,int t,int r, GLenum newDataType);

        /** Copy a source Image into a subpart of this Image at
specified position.
          * Typically used to copy to an already allocated image, such
as creating
          * a 3D image from a stack 2D images.
          * If this Image is empty then image data is created to
          * accomodate the source image in its offset position.
          * If source is NULL then no operation happens, this Image is
left unchanged.
        */
        virtual void copySubImage(int s_offset, int t_offset, int
r_offset, const osg::Image* source);

Robert.
_______________________________________________
osg-submissions mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-submissions-openscenegraph.org

Reply via email to