changed: gcc8 base update
[opensg.git] / Source / System / State / Auxiliary / OSGTextureImageChunk.cpp
blob08c85db9d28750b3a7bd64802853b3f5526e8886
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 #define GL_GLEXT_PROTOTYPES
45 #include <cstdlib>
46 #include <cstdio>
48 #include <boost/bind.hpp>
50 #include "OSGConfig.h"
52 #include "OSGGL.h"
53 #include "OSGGLU.h"
54 #include "OSGGLEXT.h"
55 #include "OSGImage.h"
57 #include "OSGDrawEnv.h"
59 #include "OSGTextureImageChunk.h"
60 #include "OSGTextureBaseChunk.h"
62 #include "OSGGLFuncProtos.h"
64 //#define OSG_DUMP_TEX
67 OSG_USING_NAMESPACE
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 /***************************************************************************\
75 * Class variables *
76 \***************************************************************************/
78 StateChunkClass TextureImageChunk::_class("TextureImage", osgMaxTexImages, 30);
80 UInt32 TextureImageChunk::_arbShaderImageLS = Window::invalidExtensionID;
81 UInt32 TextureImageChunk::FuncIdBindImageTexture = Window::invalidFunctionID;
83 /***************************************************************************\
84 * Class methods *
85 \***************************************************************************/
87 /*-------------------------------------------------------------------------*\
88 - private -
89 \*-------------------------------------------------------------------------*/
91 void TextureImageChunk::initMethod(InitPhase ePhase)
93 Inherited::initMethod(ePhase);
95 if(ePhase == TypeObject::SystemPost)
97 _arbShaderImageLS =
98 Window::registerExtension("GL_ARB_shader_image_load_store");
100 FuncIdBindImageTexture =
101 Window::registerFunction
102 (OSG_DLSYM_UNDERSCORE"glBindImageTexture",
103 _arbShaderImageLS);
108 /***************************************************************************\
109 * Instance methods *
110 \***************************************************************************/
112 /*-------------------------------------------------------------------------*\
113 - private -
114 \*-------------------------------------------------------------------------*/
117 /*------------- constructors & destructors --------------------------------*/
119 TextureImageChunk::TextureImageChunk(void) :
120 Inherited()
124 TextureImageChunk::TextureImageChunk(const TextureImageChunk &source) :
125 Inherited(source)
129 TextureImageChunk::~TextureImageChunk(void)
133 /*------------------------- Chunk Class Access ---------------------------*/
135 const StateChunkClass *TextureImageChunk::getClass(void) const
137 return &_class;
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,
148 UInt32 origin,
149 BitVector details)
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
158 return false;
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)
190 return;
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"));
199 return;
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,
215 pWin);
217 osgGlBindImageTexture(idx,
218 iTexGLId,
219 this->getLevel (),
220 this->getLayer () != -1 ? GL_FALSE : GL_TRUE,
221 this->getLayer () != -1 ? this->getLayer() : 0,
222 this->getAccess(),
223 eFormat );
227 void TextureImageChunk::changeFrom(DrawEnv *pEnv,
228 StateChunk *old ,
229 UInt32 idx )
231 if(this->_sfTexture.getValue() == NULL)
232 return;
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"));
241 return;
244 // change from me to me?
245 // this assumes I haven't changed in the meantime.
246 // is that a valid assumption?
247 if(old == this)
248 return;
250 this->_sfTexture.getValue()->validate(pEnv);
252 GLint iTexGLId = 0;
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,
263 pWin);
265 osgGlBindImageTexture(idx,
266 iTexGLId,
267 this->getLevel (),
268 this->getLayer () != -1 ? GL_FALSE : GL_TRUE,
269 this->getLayer () != -1 ? this->getLayer() : 0,
270 this->getAccess(),
271 eFormat);
274 void TextureImageChunk::deactivate(DrawEnv *pEnv, UInt32 idx)
276 if(this->_sfTexture.getValue() == NULL)
277 return;
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"));
286 return;
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,
299 pWin);
301 osgGlBindImageTexture(idx,
303 this->getLevel (),
304 this->getLayer () != -1 ? GL_FALSE : GL_TRUE,
305 this->getLayer () != -1 ? this->getLayer() : 0,
306 this->getAccess(),
307 eFormat);
310 /*-------------------------- Comparison -----------------------------------*/
312 Real32 TextureImageChunk::switchCost(StateChunk *OSG_CHECK_ARG(chunk))
314 return 0;
317 bool TextureImageChunk::operator < (const StateChunk &other) const
319 return this < &other;
322 bool TextureImageChunk::operator == (const StateChunk &other) const
324 bool returnValue = false;
326 return returnValue;
329 bool TextureImageChunk::operator != (const StateChunk &other) const
331 return ! (*this == other);
334 #if 0
335 void TextureImageChunk::validate(DrawEnv *pEnv)
337 if(this->_sfTexture.getValue() == NULL)
338 return;
340 this->_sfTexture.getValue()->validate(pEnv);
342 #endif