Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

OSGTextureGrabForeground.cpp

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002  *                                OpenSG                                     *
00003  *                                                                           *
00004  *                                                                           *
00005  *               Copyright (C) 2000-2002 by the OpenSG Forum                 *
00006  *                                                                           *
00007  *                            www.opensg.org                                 *
00008  *                                                                           *
00009  *   contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de          *
00010  *                                                                           *
00011 \*---------------------------------------------------------------------------*/
00012 /*---------------------------------------------------------------------------*\
00013  *                                License                                    *
00014  *                                                                           *
00015  * This library is free software; you can redistribute it and/or modify it   *
00016  * under the terms of the GNU Library General Public License as published    *
00017  * by the Free Software Foundation, version 2.                               *
00018  *                                                                           *
00019  * This library is distributed in the hope that it will be useful, but       *
00020  * WITHOUT ANY WARRANTY; without even the implied warranty of                *
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         *
00022  * Library General Public License for more details.                          *
00023  *                                                                           *
00024  * You should have received a copy of the GNU Library General Public         *
00025  * License along with this library; if not, write to the Free Software       *
00026  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                 *
00027  *                                                                           *
00028 \*---------------------------------------------------------------------------*/
00029 /*---------------------------------------------------------------------------*\
00030  *                                Changes                                    *
00031  *                                                                           *
00032  *                                                                           *
00033  *                                                                           *
00034  *                                                                           *
00035  *                                                                           *
00036  *                                                                           *
00037 \*---------------------------------------------------------------------------*/
00038 
00039 //---------------------------------------------------------------------------
00040 //  Includes
00041 //---------------------------------------------------------------------------
00042 
00043 #include <stdlib.h>
00044 #include <stdio.h>
00045 
00046 #include <OSGConfig.h>
00047 
00048 #include <OSGGL.h>
00049 #include <OSGGLU.h>
00050 
00051 #include <OSGNodePtr.h>
00052 #include <OSGViewport.h>
00053 #include <OSGImage.h>
00054 #include <OSGTextureChunk.h>
00055 
00056 #include "OSGTextureGrabForeground.h"
00057 
00058 OSG_USING_NAMESPACE
00059 
00060 /***************************************************************************\
00061  *                            Description                                  *
00062 \***************************************************************************/
00063 
00072 /***************************************************************************\
00073  *                           Class variables                               *
00074 \***************************************************************************/
00075 
00076 /***************************************************************************\
00077  *                           Class methods                                 *
00078 \***************************************************************************/
00079 
00080 void TextureGrabForeground::initMethod (void)
00081 {
00082 }
00083 
00084 
00085 /***************************************************************************\
00086  *                           Instance methods                              *
00087 \***************************************************************************/
00088 
00089 /*-------------------------------------------------------------------------*\
00090  -  private                                                                 -
00091 \*-------------------------------------------------------------------------*/
00092 
00093 /*----------------------- constructors & destructors ----------------------*/
00094 
00095 TextureGrabForeground::TextureGrabForeground(void) :
00096     Inherited()
00097 {
00098 }
00099 
00100 TextureGrabForeground::TextureGrabForeground(const TextureGrabForeground &source) :
00101     Inherited(source)
00102 {
00103 }
00104 
00105 TextureGrabForeground::~TextureGrabForeground(void)
00106 {
00107 }
00108 
00109 /*----------------------------- class specific ----------------------------*/
00110 
00111 void TextureGrabForeground::changed(BitVector whichField, UInt32 origin)
00112 {
00113     Inherited::changed(whichField, origin);
00114 }
00115 
00116 void TextureGrabForeground::dump(      UInt32    , 
00117                          const BitVector ) const
00118 {
00119     SLOG << "Dump TextureGrabForeground NI" << std::endl;
00120 }
00121 
00122 
00125 void TextureGrabForeground::draw(DrawActionBase *action, Viewport *port)
00126 {
00127     TextureChunkPtr t = getTexture();
00128     
00129     if(t == NullFC)       // No texture, no grab.
00130         return;
00131     
00132     Int32  pw = port->getPixelWidth(),
00133            ph = port->getPixelHeight();
00134     
00135     // Ignore empty viewports
00136     if(pw < 1 || ph < 1)
00137         return;
00138  
00139     ImagePtr i = t->getImage();
00140              
00141     // If image is smaller than 2x2, resize it to vp size
00142     // the 2x2 is because you can't create 0x0 images
00143     if((i->getWidth() <= 1 && i->getHeight() <= 1) ||
00144        (getAutoResize() && (osgabs(i->getWidth()  - pw) > 1 ||
00145                             osgabs(i->getHeight() - ph) > 1 )
00146        )
00147       )
00148     {
00149         i->set(i->getPixelFormat(), pw, ph);
00150         // Tell the texture...
00151         beginEditCP(t, TextureChunk::ImageFieldMask);
00152         endEditCP  (t, TextureChunk::ImageFieldMask);
00153     }
00154     
00155     UInt32 w = osgMin((Int32)i->getWidth(),  pw);
00156     UInt32 h = osgMin((Int32)i->getHeight(), ph);
00157 
00158     glErr("TextureGrabForeground::activate precheck");
00159     
00160     action->getWindow()->validateGLObject(t->getGLId());
00161 
00162     glErr("TextureGrabForeground::bind precheck");
00163     
00164     GLenum bindTarget = getBindTarget(), copyTarget = getCopyTarget();
00165     
00166     if(bindTarget == GL_NONE)
00167     {
00168        if(i->getDepth() > 1)
00169        {
00170             FWARNING(("TextureGrabBackground:: 3D textures not "
00171                         "supported for this window!\n"));
00172             return;
00173        }
00174        else if(h > 1)        bindTarget = GL_TEXTURE_2D;
00175        else                  bindTarget = GL_TEXTURE_1D;        
00176     }
00177     
00178     if(copyTarget == GL_NONE)
00179         copyTarget = bindTarget;
00180     
00181     glBindTexture(bindTarget, t->getGLId());
00182 
00183     glErr("TextureGrabForeground::copy precheck");
00184 
00185     if(copyTarget == GL_TEXTURE_3D)
00186     {
00187         FWARNING(("TextureGrabForeground:: grabbing to 3D textures not "
00188                   "supported yet!\n"));      
00189     }
00190     else if(copyTarget == GL_TEXTURE_1D)
00191     {
00192         glCopyTexSubImage1D(copyTarget, 0, 0, 
00193                             port->getPixelLeft(), port->getPixelBottom(), 
00194                             w);
00195     }
00196     else
00197     {
00198         glCopyTexSubImage2D(copyTarget, 0, 0, 0, 
00199                             port->getPixelLeft(), port->getPixelBottom(), 
00200                             w, h);
00201     }
00202     
00203     glErr("TextureGrabForeground::copy postcheck");
00204    
00205     glBindTexture(bindTarget, 0);
00206 }
00207 
00208 
00209 /*------------------------------------------------------------------------*/
00210 /*                              cvs id's                                  */
00211 
00212 #ifdef OSG_SGI_CC
00213 #pragma set woff 1174
00214 #endif
00215 
00216 #ifdef OSG_LINUX_ICC
00217 #pragma warning( disable : 177 )
00218 #endif
00219 
00220 namespace
00221 {
00222     static Char8 cvsid_cpp       [] = "@(#)$Id: $";
00223     static Char8 cvsid_hpp       [] = OSGTEXTUREGRABFOREGROUNDBASE_HEADER_CVSID;
00224     static Char8 cvsid_inl       [] = OSGTEXTUREGRABFOREGROUNDBASE_INLINE_CVSID;
00225 
00226     static Char8 cvsid_fields_hpp[] = OSGTEXTUREGRABFOREGROUNDFIELDS_HEADER_CVSID;
00227 }
00228 
00229 #ifdef __sgi
00230 #pragma reset woff 1174
00231 #endif
00232 

Generated on Thu Aug 25 04:11:31 2005 for OpenSG by  doxygen 1.4.3