changed: gcc8 base update
[opensg.git] / Source / System / State / Base / OSGShaderStorageBufferObjRefChunk.cpp
blob0340088651538327ff7e7568c3d40996aec02ac4
1 /*---------------------------------------------------------------------------*\
2 * OpenSG *
3 * *
4 * *
5 * Copyright (C) 2000-2013 by the OpenSG Forum *
6 * *
7 * www.opensg.org *
8 * *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, carsten_neumann@gmx.net *
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 #include <cstdlib>
44 #include <cstdio>
46 #include <boost/bind.hpp>
48 #include "OSGConfig.h"
50 #include "OSGGL.h"
51 #include "OSGGLU.h"
52 #include "OSGGLEXT.h"
53 #include "OSGWindow.h"
55 #include "OSGGLFuncProtos.h"
57 #include "OSGDrawEnv.h"
59 #include "OSGShaderStorageBufferObjRefChunk.h"
61 OSG_BEGIN_NAMESPACE
63 // Documentation for this class is emitted in the
64 // OSGShaderStorageBufferObjRefChunkBase.cpp file.
65 // To modify it, please change the .fcd file (OSGShaderStorageBufferObjRefChunk.fcd) and
66 // regenerate the base file.
68 /***************************************************************************\
69 * Class variables *
70 \***************************************************************************/
72 typedef OSG::Window Win;
74 UInt32 ShaderStorageBufferObjRefChunk::_extUniformBufferObject = Win::invalidExtensionID;
75 UInt32 ShaderStorageBufferObjRefChunk::_extVertexBufferObject = Win::invalidExtensionID;
76 UInt32 ShaderStorageBufferObjRefChunk::_extShaderStorageBufferObject = Win::invalidExtensionID;
78 UInt32 ShaderStorageBufferObjRefChunk::_funcBindBuffer = Win::invalidFunctionID;
79 UInt32 ShaderStorageBufferObjRefChunk::_funcBindBufferBase = Win::invalidFunctionID;
81 /***************************************************************************\
82 * Class methods *
83 \***************************************************************************/
85 void ShaderStorageBufferObjRefChunk::initMethod(InitPhase ePhase)
87 Inherited::initMethod(ePhase);
89 if(ePhase == TypeObject::SystemPost)
91 _extVertexBufferObject=
92 Window::registerExtension("GL_ARB_vertex_buffer_object");
94 _extUniformBufferObject =
95 Window::registerExtension("GL_ARB_uniform_buffer_object" );
97 _extShaderStorageBufferObject =
98 Window::registerExtension("GL_ARB_shader_storage_buffer_object");
100 _funcBindBuffer =
101 Window::registerFunction(
102 OSG_DLSYM_UNDERSCORE"glBindBufferARB",
103 _extVertexBufferObject);
105 _funcBindBufferBase =
106 Window::registerFunction(
107 OSG_DLSYM_UNDERSCORE"glBindBufferBase",
108 _extUniformBufferObject);
112 /***************************************************************************\
113 * Instance methods *
114 \***************************************************************************/
116 /*-------------------------------------------------------------------------*\
117 - private -
118 \*-------------------------------------------------------------------------*/
120 /*----------------------- constructors & destructors ----------------------*/
122 ShaderStorageBufferObjRefChunk::ShaderStorageBufferObjRefChunk(void) :
123 Inherited()
127 ShaderStorageBufferObjRefChunk::ShaderStorageBufferObjRefChunk(
128 const ShaderStorageBufferObjRefChunk &source) :
129 Inherited(source)
133 ShaderStorageBufferObjRefChunk::~ShaderStorageBufferObjRefChunk(void)
137 /*----------------------------- class specific ----------------------------*/
139 void ShaderStorageBufferObjRefChunk::changed(ConstFieldMaskArg whichField,
140 UInt32 origin,
141 BitVector details)
143 Inherited::changed(whichField, origin, details);
146 /*----------------------------- onCreate --------------------------------*/
148 void ShaderStorageBufferObjRefChunk::onCreate(const ShaderStorageBufferObjRefChunk *source)
150 Inherited::onCreate(source);
152 if(GlobalSystemState == Startup)
153 return;
156 void ShaderStorageBufferObjRefChunk::onCreateAspect(
157 const ShaderStorageBufferObjRefChunk *createAspect,
158 const ShaderStorageBufferObjRefChunk *source )
160 Inherited::onCreateAspect(createAspect, source);
163 void ShaderStorageBufferObjRefChunk::onDestroy(UInt32 uiContainerId)
165 Inherited::onDestroy(uiContainerId);
168 /*------------------------------ Output ----------------------------------*/
170 void ShaderStorageBufferObjRefChunk::dump(UInt32 uiIndent,
171 const BitVector bvFlags) const
173 SLOG << "Dump ShaderStorageBufferObjRefChunk NI" << std::endl;
175 Inherited::dump(uiIndent, bvFlags);
178 /*------------------------------ tools --------------------------------------*/
180 void ShaderStorageBufferObjRefChunk::validate(DrawEnv *pEnv)
182 if(this->getOsgGLId() != 0)
184 pEnv->getWindow()->validateGLObject(this->getOsgGLId(),
185 pEnv );
189 Int32 ShaderStorageBufferObjRefChunk::getOpenGLId(DrawEnv *pEnv)
191 if(this->getOsgGLId() != 0)
193 return pEnv->getWindow()->getGLObjectId(this->getOsgGLId());
195 else
197 return this->getOglGLId();
201 /*------------------------------ activate -----------------------------------*/
203 void ShaderStorageBufferObjRefChunk::activate(DrawEnv *pEnv, UInt32 idx)
205 Window *pWin = pEnv->getWindow();
207 validate(pEnv);
208 GLuint id = this->getOpenGLId(pEnv);
210 OSGGETGLFUNCBYID_GL3_ES( glBindBuffer,
211 osgGlBindBuffer,
212 _funcBindBuffer,
213 pWin);
215 OSGGETGLFUNCBYID_GL3_ES( glBindBufferBase,
216 osgGlBindBufferBase,
217 _funcBindBufferBase,
218 pWin);
220 osgGlBindBuffer (GL_SHADER_STORAGE_BUFFER, id);
221 osgGlBindBufferBase(GL_SHADER_STORAGE_BUFFER, idx, id);
223 glErr("ShaderStorageBufferObjRefChunk::activate");
226 /*------------------------------ deactivate ---------------------------------*/
228 void ShaderStorageBufferObjRefChunk::deactivate(DrawEnv *pEnv, UInt32 idx)
230 Window *pWin = pEnv->getWindow();
232 OSGGETGLFUNCBYID_GL3_ES( glBindBuffer,
233 osgGlBindBuffer,
234 _funcBindBuffer,
235 pWin);
237 OSGGETGLFUNCBYID_GL3_ES( glBindBufferBase,
238 osgGlBindBufferBase,
239 _funcBindBufferBase,
240 pWin);
242 osgGlBindBufferBase(GL_SHADER_STORAGE_BUFFER, idx, 0);
243 osgGlBindBuffer (GL_SHADER_STORAGE_BUFFER, 0);
245 glErr("ShaderStorageBufferObjRefChunk::deactivate");
248 /*------------------------------ changeFrom ---------------------------------*/
250 void ShaderStorageBufferObjRefChunk::changeFrom(DrawEnv *pEnv,
251 StateChunk *old,
252 UInt32 idx )
254 // change from me to me?
255 // this assumes I haven't changed in the meantime.
256 // is that a valid assumption?
257 if (old == this)
258 return;
260 old->deactivate(pEnv, idx);
261 this->activate(pEnv, idx);
264 OSG_END_NAMESPACE