changed: gcc8 base update
[opensg.git] / Source / System / Window / Foreground / OSGGrabForeground.cpp
blob0ce8ac27c15247b8291df8bb3027ae1244b87dba
1 /*---------------------------------------------------------------------------*\
2 * OpenSG *
3 * *
4 * *
5 * Copyright (C) 2000-2002 by the OpenSG Forum *
6 * *
7 * www.opensg.org *
8 * *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
10 * *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
13 * License *
14 * *
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. *
18 * *
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. *
23 * *
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. *
27 * *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
30 * Changes *
31 * *
32 * *
33 * *
34 * *
35 * *
36 * *
37 \*---------------------------------------------------------------------------*/
39 //---------------------------------------------------------------------------
40 // Includes
41 //---------------------------------------------------------------------------
43 #include <cstdlib>
44 #include <cstdio>
46 #include "OSGConfig.h"
48 #include "OSGGL.h"
50 #include "OSGViewport.h"
51 #include "OSGImage.h"
53 #include "OSGGrabForeground.h"
54 #include "OSGNode.h"
55 #include "OSGCamera.h"
56 #include "OSGBackground.h"
57 #include "OSGDrawEnv.h"
59 OSG_USING_NAMESPACE
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) :
69 Inherited()
71 _sfActive.setValue(false);
74 GrabForeground::GrabForeground(const GrabForeground &source) :
75 Inherited(source)
79 GrabForeground::~GrabForeground(void)
83 /*----------------------------- class specific ----------------------------*/
85 void GrabForeground::initMethod(InitPhase ePhase)
87 Inherited::initMethod(ePhase);
90 void GrabForeground::changed(ConstFieldMaskArg whichField,
91 UInt32 origin,
92 BitVector details)
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)
110 return;
112 Image *i = getImage();
114 if(i == NULL) // No image, no grab.
115 return;
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(),
132 #ifndef OSG_OGL_ES2
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());
143 storeChanged = true;
146 #endif
148 glReadPixels(pEnv->getPixelLeft(),
149 pEnv->getPixelBottom(),
152 i->getPixelFormat(),
153 i->getDataType(),
154 i->editData());
156 #ifndef OSG_OGL_ES2
157 if(storeChanged)
158 glPixelStorei(GL_PACK_ROW_LENGTH, 0);
159 #endif