1 /*---------------------------------------------------------------------------*\
5 * Copyright (C) 2000-2002 by the OpenSG Forum *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
15 * This library is free software; you can redistribute it and/or modify it *
16 * under the terms of the GNU Library General Public License as published *
17 * by the Free Software Foundation, version 2. *
19 * This library is distributed in the hope that it will be useful, but *
20 * WITHOUT ANY WARRANTY; without even the implied warranty of *
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
22 * Library General Public License for more details. *
24 * You should have received a copy of the GNU Library General Public *
25 * License along with this library; if not, write to the Free Software *
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
37 \*---------------------------------------------------------------------------*/
39 //---------------------------------------------------------------------------
41 //---------------------------------------------------------------------------
46 #include "OSGConfig.h"
50 #include "OSGViewport.h"
53 #include "OSGGrabForeground.h"
55 #include "OSGCamera.h"
56 #include "OSGBackground.h"
57 #include "OSGDrawEnv.h"
61 // Documentation for this class is emited in the
62 // OSGGrabForegroundBase.cpp file.
63 // To modify it, please change the .fcd file (OSGGrabForeground.fcd) and
64 // regenerate the base file.
66 /*----------------------- constructors & destructors ----------------------*/
68 GrabForeground::GrabForeground(void) :
71 _sfActive
.setValue(false);
74 GrabForeground::GrabForeground(const GrabForeground
&source
) :
79 GrabForeground::~GrabForeground(void)
83 /*----------------------------- class specific ----------------------------*/
85 void GrabForeground::initMethod(InitPhase ePhase
)
87 Inherited::initMethod(ePhase
);
90 void GrabForeground::changed(ConstFieldMaskArg whichField
,
94 Inherited::changed(whichField
, origin
, details
);
97 void GrabForeground::dump( UInt32
,
98 const BitVector
) const
100 SLOG
<< "Dump GrabForeground NI" << std::endl
;
104 /*! Grab the image, if it is actually set.
107 void GrabForeground::draw(DrawEnv
* pEnv
)
109 if(getActive() == false)
112 Image
*i
= getImage();
114 if(i
== NULL
) // No image, no grab.
117 Int32 w
= osgMax(2, pEnv
->getPixelWidth ());
118 Int32 h
= osgMax(2, pEnv
->getPixelHeight());
120 // If image is smaller than 2x2, resize it to vp size
121 // the 2x2 is because you can't create 0x0 images
122 // If autoResize then update img size if vp changed
124 if( (i
->getWidth() <= 1 || i
->getHeight() <= 1) ||
125 (getAutoResize() && (w
!= i
->getWidth() || h
!= i
->getHeight())) )
127 i
->set(i
->getPixelFormat(),
133 bool storeChanged
= false;
135 if ( !getAutoResize() )
137 w
= osgMin(Int32(i
->getWidth ()), pEnv
->getPixelWidth ());
138 h
= osgMin(Int32(i
->getHeight()), pEnv
->getPixelHeight());
140 if(Int32(i
->getWidth()) != pEnv
->getPixelWidth())
142 glPixelStorei(GL_PACK_ROW_LENGTH
, i
->getWidth());
148 glReadPixels(pEnv
->getPixelLeft(),
149 pEnv
->getPixelBottom(),
158 glPixelStorei(GL_PACK_ROW_LENGTH
, 0);