00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 #include <stdlib.h>
00044 #include <stdio.h>
00045
00046 #include <OSGConfig.h>
00047
00048 #include <OSGGL.h>
00049 #include <OSGGLU.h>
00050
00051 #include <OSGNodePtr.h>
00052 #include <OSGViewport.h>
00053 #include <OSGImage.h>
00054 #include <OSGTextureChunk.h>
00055
00056 #include "OSGTextureGrabForeground.h"
00057
00058 OSG_USING_NAMESPACE
00059
00060
00061
00062
00063
00072
00073
00074
00075
00076
00077
00078
00079
00080 void TextureGrabForeground::initMethod (void)
00081 {
00082 }
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095 TextureGrabForeground::TextureGrabForeground(void) :
00096 Inherited()
00097 {
00098 }
00099
00100 TextureGrabForeground::TextureGrabForeground(const TextureGrabForeground &source) :
00101 Inherited(source)
00102 {
00103 }
00104
00105 TextureGrabForeground::~TextureGrabForeground(void)
00106 {
00107 }
00108
00109
00110
00111 void TextureGrabForeground::changed(BitVector whichField, UInt32 origin)
00112 {
00113 Inherited::changed(whichField, origin);
00114 }
00115
00116 void TextureGrabForeground::dump( UInt32 ,
00117 const BitVector ) const
00118 {
00119 SLOG << "Dump TextureGrabForeground NI" << std::endl;
00120 }
00121
00122
00125 void TextureGrabForeground::draw(DrawActionBase *action, Viewport *port)
00126 {
00127 if(getActive() == false)
00128 return;
00129
00130 TextureChunkPtr t = getTexture();
00131
00132 if(t == NullFC)
00133 return;
00134
00135 Int32 pw = port->getPixelWidth(),
00136 ph = port->getPixelHeight();
00137
00138
00139 if(pw < 1 || ph < 1)
00140 return;
00141
00142 ImagePtr i = t->getImage();
00143
00144
00145
00146 if((i->getWidth() <= 1 && i->getHeight() <= 1) ||
00147 (getAutoResize() && (osgabs(i->getWidth() - pw) > 1 ||
00148 osgabs(i->getHeight() - ph) > 1 )
00149 )
00150 )
00151 {
00152 i->set(i->getPixelFormat(), pw, ph);
00153
00154 beginEditCP(t, TextureChunk::ImageFieldMask);
00155 endEditCP (t, TextureChunk::ImageFieldMask);
00156 }
00157
00158 UInt32 w = osgMin((Int32)i->getWidth(), pw);
00159 UInt32 h = osgMin((Int32)i->getHeight(), ph);
00160
00161 glErr("TextureGrabForeground::activate precheck");
00162
00163 action->getWindow()->validateGLObject(t->getGLId());
00164
00165 glErr("TextureGrabForeground::bind precheck");
00166
00167 GLenum bindTarget = getBindTarget(), copyTarget = getCopyTarget();
00168
00169 if(bindTarget == GL_NONE)
00170 {
00171 if(i->getDepth() > 1)
00172 {
00173 FWARNING(("TextureGrabBackground:: 3D textures not "
00174 "supported for this window!\n"));
00175 return;
00176 }
00177 else if(h > 1) bindTarget = GL_TEXTURE_2D;
00178 else bindTarget = GL_TEXTURE_1D;
00179 }
00180
00181 if(copyTarget == GL_NONE)
00182 copyTarget = bindTarget;
00183
00184 glBindTexture(bindTarget,
00185 action->getWindow()->getGLObjectId(t->getGLId()));
00186
00187 glErr("TextureGrabForeground::copy precheck");
00188
00189 if(copyTarget == GL_TEXTURE_3D)
00190 {
00191 FWARNING(("TextureGrabForeground:: grabbing to 3D textures not "
00192 "supported yet!\n"));
00193 }
00194 else if(copyTarget == GL_TEXTURE_1D)
00195 {
00196 glCopyTexSubImage1D(copyTarget, 0, 0,
00197 port->getPixelLeft(), port->getPixelBottom(),
00198 w);
00199 }
00200 else
00201 {
00202 glCopyTexSubImage2D(copyTarget, 0, 0, 0,
00203 port->getPixelLeft(), port->getPixelBottom(),
00204 w, h);
00205 }
00206
00207 glErr("TextureGrabForeground::copy postcheck");
00208
00209 glBindTexture(bindTarget, 0);
00210 }
00211
00212
00213
00214
00215
00216 #ifdef OSG_SGI_CC
00217 #pragma set woff 1174
00218 #endif
00219
00220 #ifdef OSG_LINUX_ICC
00221 #pragma warning( disable : 177 )
00222 #endif
00223
00224 namespace
00225 {
00226 static Char8 cvsid_cpp [] = "@(#)$Id: $";
00227 static Char8 cvsid_hpp [] = OSGTEXTUREGRABFOREGROUNDBASE_HEADER_CVSID;
00228 static Char8 cvsid_inl [] = OSGTEXTUREGRABFOREGROUNDBASE_INLINE_CVSID;
00229
00230 static Char8 cvsid_fields_hpp[] = OSGTEXTUREGRABFOREGROUNDFIELDS_HEADER_CVSID;
00231 }
00232
00233 #ifdef __sgi
00234 #pragma reset woff 1174
00235 #endif
00236