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"
51 #include "OSGViewport.h"
53 #include "OSGTextureObjChunk.h"
54 #include "OSGDrawEnv.h"
56 #include "OSGTextureGrabBackground.h"
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 /***************************************************************************\
67 \***************************************************************************/
69 /***************************************************************************\
71 \***************************************************************************/
73 void TextureGrabBackground::initMethod(InitPhase ePhase
)
75 Inherited::initMethod(ePhase
);
79 /***************************************************************************\
81 \***************************************************************************/
83 /*-------------------------------------------------------------------------*\
85 \*-------------------------------------------------------------------------*/
87 /*----------------------- constructors & destructors ----------------------*/
89 TextureGrabBackground::TextureGrabBackground(void) :
94 TextureGrabBackground::TextureGrabBackground(
95 const TextureGrabBackground
&source
) :
101 TextureGrabBackground::~TextureGrabBackground(void)
105 /*----------------------------- class specific ----------------------------*/
107 void TextureGrabBackground::changed(ConstFieldMaskArg whichField
,
111 Inherited::changed(whichField
, origin
, details
);
114 /*-------------------------- your_category---------------------------------*/
116 void TextureGrabBackground::clear(DrawEnv
*pEnv
)
119 TextureObjChunk
*t
= getTexture();
121 if(t
== NULL
) // No texture, no grab.
123 Inherited::clear(pEnv
);
127 Int32 pw
= pEnv
->getPixelWidth ();
128 Int32 ph
= pEnv
->getPixelHeight();
130 // Ignore empty viewports
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
);
167 bindTarget
= GL_TEXTURE_2D
;
172 bindTarget
= GL_TEXTURE_1D
;
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"));
193 else if(copyTarget
== GL_TEXTURE_1D
)
195 glCopyTexSubImage1D(copyTarget
, 0, 0,
196 pEnv
->getPixelLeft(), pEnv
->getPixelBottom(),
202 glCopyTexSubImage2D(copyTarget
, 0, 0, 0,
203 pEnv
->getPixelLeft(), pEnv
->getPixelBottom(),
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
;