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 //---------------------------------------------------------------------------
43 #define GL_GLEXT_PROTOTYPES
48 #include <boost/bind.hpp>
50 #include "OSGConfig.h"
57 #include "OSGDrawEnv.h"
59 #include "OSGTextureImageChunk.h"
60 #include "OSGTextureBaseChunk.h"
62 #include "OSGGLFuncProtos.h"
64 //#define OSG_DUMP_TEX
69 // Documentation for this class is emited in the
70 // OSGTextureImageChunkBase.cpp file.
71 // To modify it, please change the .fcd file (OSGTextureImageChunk.fcd) and
72 // regenerate the base file.
74 /***************************************************************************\
76 \***************************************************************************/
78 StateChunkClass
TextureImageChunk::_class("TextureImage", osgMaxTexImages
, 30);
80 UInt32
TextureImageChunk::_arbShaderImageLS
= Window::invalidExtensionID
;
81 UInt32
TextureImageChunk::FuncIdBindImageTexture
= Window::invalidFunctionID
;
83 /***************************************************************************\
85 \***************************************************************************/
87 /*-------------------------------------------------------------------------*\
89 \*-------------------------------------------------------------------------*/
91 void TextureImageChunk::initMethod(InitPhase ePhase
)
93 Inherited::initMethod(ePhase
);
95 if(ePhase
== TypeObject::SystemPost
)
98 Window::registerExtension("GL_ARB_shader_image_load_store");
100 FuncIdBindImageTexture
=
101 Window::registerFunction
102 (OSG_DLSYM_UNDERSCORE
"glBindImageTexture",
108 /***************************************************************************\
110 \***************************************************************************/
112 /*-------------------------------------------------------------------------*\
114 \*-------------------------------------------------------------------------*/
117 /*------------- constructors & destructors --------------------------------*/
119 TextureImageChunk::TextureImageChunk(void) :
124 TextureImageChunk::TextureImageChunk(const TextureImageChunk
&source
) :
129 TextureImageChunk::~TextureImageChunk(void)
133 /*------------------------- Chunk Class Access ---------------------------*/
135 const StateChunkClass
*TextureImageChunk::getClass(void) const
140 /*------------------------------- Sync -----------------------------------*/
142 /*! React to field changes.
143 Note: this function also handles CubeTexture changes, make sure to keep
144 it consistent with the cubeTexture specifics
147 void TextureImageChunk::changed(ConstFieldMaskArg whichField
,
151 Inherited::changed(whichField
, origin
, details
);
154 bool TextureImageChunk::isTransparent(void) const
156 // Even if the texture has alpha, the Blending is makes the sorting
157 // important, thus textures per se are not transparent
162 /*----------------------------- onCreate --------------------------------*/
164 void TextureImageChunk::onCreate(const TextureImageChunk
*source
)
166 Inherited::onCreate(source
);
169 void TextureImageChunk::onCreateAspect(const TextureImageChunk
*createAspect
,
170 const TextureImageChunk
*source
)
172 Inherited::onCreateAspect(createAspect
, source
);
175 /*------------------------------ Output ----------------------------------*/
177 void TextureImageChunk::dump( UInt32
OSG_CHECK_ARG(uiIndent
),
178 const BitVector
OSG_CHECK_ARG(bvFlags
)) const
180 SLOG
<< "Dump TextureImageChunk NI" << std::endl
;
184 /*------------------------------ State ------------------------------------*/
187 void TextureImageChunk::activate(DrawEnv
*pEnv
, UInt32 idx
)
189 if(this->_sfTexture
.getValue() == NULL
)
192 Window
*pWin
= pEnv
->getWindow();
194 if(!pWin
->hasExtOrVersion(_arbShaderImageLS
, 0x0402, 0xFFFF))
196 FWARNING(("OpenGL shader image load store is not supported, couldn't "
197 "find extension 'GL_ARB_shader_image_load_store'!\n"));
202 this->_sfTexture
.getValue()->validate(pEnv
);
204 GLint iTexGLId
= this->_sfTexture
.getValue()->getOpenGLId(pEnv
);
205 GLenum eFormat
= this->getFormat();
207 if(eFormat
== GL_NONE
)
209 eFormat
= this->_sfTexture
.getValue()->determineInternalFormat();
212 OSGGETGLFUNCBYID_GL4(glBindImageTexture
,
213 osgGlBindImageTexture
,
214 TextureImageChunk::FuncIdBindImageTexture
,
217 osgGlBindImageTexture(idx
,
220 this->getLayer () != -1 ? GL_FALSE
: GL_TRUE
,
221 this->getLayer () != -1 ? this->getLayer() : 0,
227 void TextureImageChunk::changeFrom(DrawEnv
*pEnv
,
231 if(this->_sfTexture
.getValue() == NULL
)
234 Window
*pWin
= pEnv
->getWindow();
236 if(!pWin
->hasExtOrVersion(_arbShaderImageLS
, 0x0402, 0xFFFF))
238 FWARNING(("OpenGL shader image load store is not supported, couldn't "
239 "find extension 'GL_ARB_shader_image_load_store'!\n"));
244 // change from me to me?
245 // this assumes I haven't changed in the meantime.
246 // is that a valid assumption?
250 this->_sfTexture
.getValue()->validate(pEnv
);
253 GLenum eFormat
= this->getFormat();
255 if(eFormat
== GL_NONE
)
257 eFormat
= this->_sfTexture
.getValue()->determineInternalFormat();
260 OSGGETGLFUNCBYID_GL4(glBindImageTexture
,
261 osgGlBindImageTexture
,
262 TextureImageChunk::FuncIdBindImageTexture
,
265 osgGlBindImageTexture(idx
,
268 this->getLayer () != -1 ? GL_FALSE
: GL_TRUE
,
269 this->getLayer () != -1 ? this->getLayer() : 0,
274 void TextureImageChunk::deactivate(DrawEnv
*pEnv
, UInt32 idx
)
276 if(this->_sfTexture
.getValue() == NULL
)
279 Window
*pWin
= pEnv
->getWindow();
281 if(!pWin
->hasExtOrVersion(_arbShaderImageLS
, 0x0402, 0xFFFF))
283 FWARNING(("OpenGL shader image load store is not supported, couldn't "
284 "find extension 'GL_ARB_shader_image_load_store'!\n"));
289 GLenum eFormat
= this->getFormat();
291 if(eFormat
== GL_NONE
)
293 eFormat
= this->_sfTexture
.getValue()->determineInternalFormat();
296 OSGGETGLFUNCBYID_GL4(glBindImageTexture
,
297 osgGlBindImageTexture
,
298 TextureImageChunk::FuncIdBindImageTexture
,
301 osgGlBindImageTexture(idx
,
304 this->getLayer () != -1 ? GL_FALSE
: GL_TRUE
,
305 this->getLayer () != -1 ? this->getLayer() : 0,
310 /*-------------------------- Comparison -----------------------------------*/
312 Real32
TextureImageChunk::switchCost(StateChunk
*OSG_CHECK_ARG(chunk
))
317 bool TextureImageChunk::operator < (const StateChunk
&other
) const
319 return this < &other
;
322 bool TextureImageChunk::operator == (const StateChunk
&other
) const
324 bool returnValue
= false;
329 bool TextureImageChunk::operator != (const StateChunk
&other
) const
331 return ! (*this == other
);
335 void TextureImageChunk::validate(DrawEnv
*pEnv
)
337 if(this->_sfTexture
.getValue() == NULL
)
340 this->_sfTexture
.getValue()->validate(pEnv
);