fixed: compile issue
[opensg.git] / Source / System / Window / Foreground / OSGTextureGrabForeground.cpp
blob015f6932d5d226fce588e296c36c53e5e689b5b5
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"
49 #include "OSGGLU.h"
51 #include "OSGViewport.h"
52 #include "OSGImage.h"
53 #include "OSGTextureObjChunk.h"
54 #include "OSGDrawEnv.h"
56 #include "OSGTextureGrabForeground.h"
58 OSG_USING_NAMESPACE
60 // Documentation for this class is emited in the
61 // OSGTextureGrabForegroundBase.cpp file.
62 // To modify it, please change the .fcd file (OSGTextureGrabForeground.fcd) and
63 // regenerate the base file.
65 /***************************************************************************\
66 * Class variables *
67 \***************************************************************************/
69 /***************************************************************************\
70 * Class methods *
71 \***************************************************************************/
73 void TextureGrabForeground::initMethod(InitPhase ePhase)
75 Inherited::initMethod(ePhase);
79 /***************************************************************************\
80 * Instance methods *
81 \***************************************************************************/
83 /*-------------------------------------------------------------------------*\
84 - private -
85 \*-------------------------------------------------------------------------*/
87 /*----------------------- constructors & destructors ----------------------*/
89 TextureGrabForeground::TextureGrabForeground(void) :
90 Inherited()
94 TextureGrabForeground::TextureGrabForeground(
95 const TextureGrabForeground &source) :
97 Inherited(source)
101 TextureGrabForeground::~TextureGrabForeground(void)
105 /*----------------------------- class specific ----------------------------*/
107 void TextureGrabForeground::changed(ConstFieldMaskArg whichField,
108 UInt32 origin,
109 BitVector details)
111 Inherited::changed(whichField, origin, details);
114 void TextureGrabForeground::dump( UInt32 ,
115 const BitVector ) const
117 SLOG << "Dump TextureGrabForeground NI" << std::endl;
121 /*! Grab the image to the texture.
123 void TextureGrabForeground::draw(DrawEnv *pEnv)
125 if(getActive() == false)
126 return;
128 TextureObjChunk *t = getTexture();
130 if(t == NULL) // No texture, no grab.
131 return;
133 Int32 pw = pEnv->getPixelWidth (),
134 ph = pEnv->getPixelHeight();
136 // Ignore empty viewports
137 if(pw < 1 || ph < 1)
138 return;
140 Image *i = t->getImage();
142 // If image is smaller than 2x2, resize it to vp size
143 // the 2x2 is because you can't create 0x0 images
145 if((i->getWidth() <= 1 && i->getHeight() <= 1) ||
146 (getAutoResize() && (osgAbs(i->getWidth () - pw) > 1 ||
147 osgAbs(i->getHeight() - ph) > 1 ) ) )
149 i->set(i->getPixelFormat(), pw, ph);
152 UInt32 w = osgMin(Int32(i->getWidth ()), pw);
153 UInt32 h = osgMin(Int32(i->getHeight()), ph);
155 glErr("TextureGrabForeground::activate precheck");
157 pEnv->getWindow()->validateGLObject(t->getGLId(), pEnv);
159 glErr("TextureGrabForeground::bind precheck");
161 GLenum bindTarget = getBindTarget(), copyTarget = getCopyTarget();
163 if(bindTarget == GL_NONE)
165 if(i->getDepth() > 1)
167 FWARNING(("TextureGrabBackground:: 3D textures not "
168 "supported for this window!\n"));
169 return;
171 else if(h > 1)
173 bindTarget = GL_TEXTURE_2D;
175 else
177 #ifndef OSG_OGL_ES2
178 bindTarget = GL_TEXTURE_1D;
179 #else
180 return;
181 #endif
185 if(copyTarget == GL_NONE)
186 copyTarget = bindTarget;
188 glBindTexture(bindTarget,
189 pEnv->getWindow()->getGLObjectId(t->getGLId()));
191 glErr("TextureGrabForeground::copy precheck");
193 if(copyTarget == GL_TEXTURE_3D)
195 FWARNING(("TextureGrabForeground:: grabbing to 3D textures not "
196 "supported yet!\n"));
198 #ifndef OSG_OGL_ES2
199 else if(copyTarget == GL_TEXTURE_1D)
201 glCopyTexSubImage1D(copyTarget, 0, 0,
202 pEnv->getPixelLeft(), pEnv->getPixelBottom(),
205 #endif
206 else
208 glCopyTexSubImage2D(copyTarget, 0, 0, 0,
209 pEnv->getPixelLeft(), pEnv->getPixelBottom(),
210 w, h);
213 glErr("TextureGrabForeground::copy postcheck");
215 glBindTexture(bindTarget, 0);