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 "OSGTextureGrabForeground.h"
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 /***************************************************************************\
67 \***************************************************************************/
69 /***************************************************************************\
71 \***************************************************************************/
73 void TextureGrabForeground::initMethod(InitPhase ePhase
)
75 Inherited::initMethod(ePhase
);
79 /***************************************************************************\
81 \***************************************************************************/
83 /*-------------------------------------------------------------------------*\
85 \*-------------------------------------------------------------------------*/
87 /*----------------------- constructors & destructors ----------------------*/
89 TextureGrabForeground::TextureGrabForeground(void) :
94 TextureGrabForeground::TextureGrabForeground(
95 const TextureGrabForeground
&source
) :
101 TextureGrabForeground::~TextureGrabForeground(void)
105 /*----------------------------- class specific ----------------------------*/
107 void TextureGrabForeground::changed(ConstFieldMaskArg whichField
,
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)
128 TextureObjChunk
*t
= getTexture();
130 if(t
== NULL
) // No texture, no grab.
133 Int32 pw
= pEnv
->getPixelWidth (),
134 ph
= pEnv
->getPixelHeight();
136 // Ignore empty viewports
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"));
173 bindTarget
= GL_TEXTURE_2D
;
178 bindTarget
= GL_TEXTURE_1D
;
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"));
199 else if(copyTarget
== GL_TEXTURE_1D
)
201 glCopyTexSubImage1D(copyTarget
, 0, 0,
202 pEnv
->getPixelLeft(), pEnv
->getPixelBottom(),
208 glCopyTexSubImage2D(copyTarget
, 0, 0, 0,
209 pEnv
->getPixelLeft(), pEnv
->getPixelBottom(),
213 glErr("TextureGrabForeground::copy postcheck");
215 glBindTexture(bindTarget
, 0);