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

OSGTextureGrabBackground.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 
00057 #include "OSGTextureGrabBackground.h"
00058 
00059 OSG_USING_NAMESPACE
00060 
00061 /***************************************************************************\
00062  *                            Description                                  *
00063 \***************************************************************************/
00064 
00076 /***************************************************************************\
00077  *                           Class variables                               *
00078 \***************************************************************************/
00079 
00080 /***************************************************************************\
00081  *                           Class methods                                 *
00082 \***************************************************************************/
00083 
00084 void TextureGrabBackground::initMethod (void)
00085 {
00086 }
00087 
00088 
00089 /***************************************************************************\
00090  *                           Instance methods                              *
00091 \***************************************************************************/
00092 
00093 /*-------------------------------------------------------------------------*\
00094  -  private                                                                 -
00095 \*-------------------------------------------------------------------------*/
00096 
00097 /*----------------------- constructors & destructors ----------------------*/
00098 
00099 TextureGrabBackground::TextureGrabBackground(void) :
00100     Inherited()
00101 {
00102 }
00103 
00104 TextureGrabBackground::TextureGrabBackground(const TextureGrabBackground &source) :
00105     Inherited(source)
00106 {
00107 }
00108 
00109 TextureGrabBackground::~TextureGrabBackground(void)
00110 {
00111 }
00112 
00113 /*----------------------------- class specific ----------------------------*/
00114 
00115 void TextureGrabBackground::changed(BitVector whichField, UInt32 origin)
00116 {
00117     Inherited::changed(whichField, origin);
00118 }
00119 
00120 /*-------------------------- your_category---------------------------------*/
00121 
00122 void TextureGrabBackground::clear(DrawActionBase *action, Viewport *port)
00123 {   
00124     // grab the texture
00125     TextureChunkPtr t = getTexture();
00126     
00127     if(t == NullFC)       // No texture, no grab.
00128     {
00129         Inherited::clear(action, port);
00130         return;
00131     }
00132     
00133     Int32  pw = port->getPixelWidth(),
00134            ph = port->getPixelHeight();
00135     
00136     // Ignore empty viewports
00137     if(pw < 1 || ph < 1)
00138         return;
00139  
00140     ImagePtr i = t->getImage();
00141              
00142     // If image is smaller than 2x2, resize it to vp size
00143     // the 2x2 is because you can't create 0x0 images
00144     if((i->getWidth() <= 1 && i->getHeight() <= 1) ||
00145        (getAutoResize() && (osgabs(i->getWidth()  - pw) > 1 ||
00146                             osgabs(i->getHeight() - ph) > 1 )
00147        )
00148       )
00149     {
00150         i->set(i->getPixelFormat(), pw, ph);
00151         // Tell the texture...
00152         beginEditCP(t, TextureChunk::ImageFieldMask);
00153         endEditCP  (t, TextureChunk::ImageFieldMask);
00154     }
00155     
00156     UInt32 w = osgMin((Int32)i->getWidth(),  pw);
00157     UInt32 h = osgMin((Int32)i->getHeight(), ph);
00158 
00159     glErr("TextureGrabBackground::activate precheck");
00160     
00161     action->getWindow()->validateGLObject(t->getGLId());
00162 
00163     glErr("TextureGrabBackground::bind precheck");
00164     
00165     GLenum bindTarget = getBindTarget(), copyTarget = getCopyTarget();
00166     
00167     if(bindTarget == GL_NONE)
00168     {
00169        if(i->getDepth() > 1)
00170        {
00171             FWARNING(("TextureGrabBackground:: 3D textures not "
00172                         "supported for this window!\n"));
00173             Inherited::clear(action, port);
00174             return;
00175        }
00176        else if(h > 1)        bindTarget = GL_TEXTURE_2D;
00177        else                  bindTarget = GL_TEXTURE_1D;        
00178     }
00179     
00180     if(copyTarget == GL_NONE)
00181         copyTarget = bindTarget;
00182     
00183     glBindTexture(bindTarget, t->getGLId());
00184 
00185     glErr("TextureGrabBackground::copy precheck");
00186 
00187     if(copyTarget == GL_TEXTURE_3D)
00188     {
00189         FWARNING(("TextureGrabBackground:: grabbing to 3D textures not "
00190                   "supported yet!\n"));      
00191     }
00192     else if(copyTarget == GL_TEXTURE_1D)
00193     {
00194         glCopyTexSubImage1D(copyTarget, 0, 0, 
00195                             port->getPixelLeft(), port->getPixelBottom(), 
00196                             w);
00197     }
00198     else
00199     {
00200         glCopyTexSubImage2D(copyTarget, 0, 0, 0, 
00201                             port->getPixelLeft(), port->getPixelBottom(), 
00202                             w, h);
00203     }
00204     
00205     glErr("TextureGrabBackground::copy postcheck");
00206    
00207     glBindTexture(bindTarget, 0);
00208    
00209     // now do the clearing
00210     Inherited::clear(action, port);
00211 }
00212 
00213 /*------------------------------- dump ----------------------------------*/
00214 
00215 void TextureGrabBackground::dump(      UInt32    , 
00216                          const BitVector ) const
00217 {
00218     SLOG << "Dump TextureGrabBackground NI" << std::endl;
00219 }
00220 
00221 
00222 /*------------------------------------------------------------------------*/
00223 /*                              cvs id's                                  */
00224 
00225 #ifdef OSG_SGI_CC
00226 #pragma set woff 1174
00227 #endif
00228 
00229 #ifdef OSG_LINUX_ICC
00230 #pragma warning( disable : 177 )
00231 #endif
00232 
00233 namespace
00234 {
00235     static Char8 cvsid_cpp       [] = "@(#)$Id: $";
00236     static Char8 cvsid_hpp       [] = OSGTEXTUREGRABBACKGROUNDBASE_HEADER_CVSID;
00237     static Char8 cvsid_inl       [] = OSGTEXTUREGRABBACKGROUNDBASE_INLINE_CVSID;
00238 
00239     static Char8 cvsid_fields_hpp[] = OSGTEXTUREGRABBACKGROUNDFIELDS_HEADER_CVSID;
00240 }
00241 
00242 #ifdef __sgi
00243 #pragma reset woff 1174
00244 #endif
00245 

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