fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / System / Window / Background / OSGTextureGrabBackground.cpp
blobe47f4399375f61b8ddd25126488207df79e1db10
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 "OSGTextureGrabBackground.h"
58 OSG_USING_NAMESPACE
60 // Documentation for this class is emited in the
61 // OSGTextureGrabBackgroundBase.cpp file.
62 // To modify it, please change the .fcd file (OSGTextureGrabBackground.fcd) and
63 // regenerate the base file.
65 /***************************************************************************\
66 * Class variables *
67 \***************************************************************************/
69 /***************************************************************************\
70 * Class methods *
71 \***************************************************************************/
73 void TextureGrabBackground::initMethod(InitPhase ePhase)
75 Inherited::initMethod(ePhase);
79 /***************************************************************************\
80 * Instance methods *
81 \***************************************************************************/
83 /*-------------------------------------------------------------------------*\
84 - private -
85 \*-------------------------------------------------------------------------*/
87 /*----------------------- constructors & destructors ----------------------*/
89 TextureGrabBackground::TextureGrabBackground(void) :
90 Inherited()
94 TextureGrabBackground::TextureGrabBackground(
95 const TextureGrabBackground &source) :
97 Inherited(source)
101 TextureGrabBackground::~TextureGrabBackground(void)
105 /*----------------------------- class specific ----------------------------*/
107 void TextureGrabBackground::changed(ConstFieldMaskArg whichField,
108 UInt32 origin,
109 BitVector details)
111 Inherited::changed(whichField, origin, details);
114 /*-------------------------- your_category---------------------------------*/
116 void TextureGrabBackground::clear(DrawEnv *pEnv)
118 // grab the texture
119 TextureObjChunk *t = getTexture();
121 if(t == NULL) // No texture, no grab.
123 Inherited::clear(pEnv);
124 return;
127 Int32 pw = pEnv->getPixelWidth ();
128 Int32 ph = pEnv->getPixelHeight();
130 // Ignore empty viewports
131 if(pw < 1 || ph < 1)
132 return;
134 Image *i = t->getImage();
136 // If image is smaller than 2x2, resize it to vp size
137 // the 2x2 is because you can't create 0x0 images
138 if((i->getWidth() <= 1 && i->getHeight() <= 1) ||
139 (getAutoResize() && (osgAbs(i->getWidth() - pw) > 1 ||
140 osgAbs(i->getHeight() - ph) > 1 ) ) )
142 i->set(i->getPixelFormat(), pw, ph);
145 UInt32 w = osgMin(Int32(i->getWidth ()), pw);
146 UInt32 h = osgMin(Int32(i->getHeight()), ph);
148 glErr("TextureGrabBackground::activate precheck");
150 pEnv->getWindow()->validateGLObject(t->getGLId(), pEnv);
152 glErr("TextureGrabBackground::bind precheck");
154 GLenum bindTarget = getBindTarget(), copyTarget = getCopyTarget();
156 if(bindTarget == GL_NONE)
158 if(i->getDepth() > 1)
160 FWARNING(("TextureGrabBackground:: 3D textures not "
161 "supported for this window!\n"));
162 Inherited::clear(pEnv);
163 return;
165 else if(h > 1)
167 bindTarget = GL_TEXTURE_2D;
169 else
171 #ifndef OSG_OGL_ES2
172 bindTarget = GL_TEXTURE_1D;
173 #else
174 return;
175 #endif
179 if(copyTarget == GL_NONE)
180 copyTarget = bindTarget;
182 glBindTexture(bindTarget,
183 pEnv->getWindow()->getGLObjectId(t->getGLId()));
185 glErr("TextureGrabBackground::copy precheck");
187 if(copyTarget == GL_TEXTURE_3D)
189 FWARNING(("TextureGrabBackground:: grabbing to 3D textures not "
190 "supported yet!\n"));
192 #ifndef OSG_OGL_ES2
193 else if(copyTarget == GL_TEXTURE_1D)
195 glCopyTexSubImage1D(copyTarget, 0, 0,
196 pEnv->getPixelLeft(), pEnv->getPixelBottom(),
199 #endif
200 else
202 glCopyTexSubImage2D(copyTarget, 0, 0, 0,
203 pEnv->getPixelLeft(), pEnv->getPixelBottom(),
204 w, h);
207 glErr("TextureGrabBackground::copy postcheck");
209 glBindTexture(bindTarget, 0);
211 // now do the clearing
212 Inherited::clear(pEnv);
215 /*------------------------------- dump ----------------------------------*/
217 void TextureGrabBackground::dump( UInt32 ,
218 const BitVector ) const
220 SLOG << "Dump TextureGrabBackground NI" << std::endl;