1 /*---------------------------------------------------------------------------*\
5 * Copyright (C) 2000-2013 by the OpenSG Forum *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, carsten_neumann@gmx.net *
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 <boost/bind.hpp>
48 #include "OSGConfig.h"
53 #include "OSGWindow.h"
55 #include "OSGGLFuncProtos.h"
57 #include "OSGDrawEnv.h"
59 #include "OSGShaderStorageBufferObjRefChunk.h"
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 /***************************************************************************\
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 /***************************************************************************\
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");
101 Window::registerFunction(
102 OSG_DLSYM_UNDERSCORE
"glBindBufferARB",
103 _extVertexBufferObject
);
105 _funcBindBufferBase
=
106 Window::registerFunction(
107 OSG_DLSYM_UNDERSCORE
"glBindBufferBase",
108 _extUniformBufferObject
);
112 /***************************************************************************\
114 \***************************************************************************/
116 /*-------------------------------------------------------------------------*\
118 \*-------------------------------------------------------------------------*/
120 /*----------------------- constructors & destructors ----------------------*/
122 ShaderStorageBufferObjRefChunk::ShaderStorageBufferObjRefChunk(void) :
127 ShaderStorageBufferObjRefChunk::ShaderStorageBufferObjRefChunk(
128 const ShaderStorageBufferObjRefChunk
&source
) :
133 ShaderStorageBufferObjRefChunk::~ShaderStorageBufferObjRefChunk(void)
137 /*----------------------------- class specific ----------------------------*/
139 void ShaderStorageBufferObjRefChunk::changed(ConstFieldMaskArg whichField
,
143 Inherited::changed(whichField
, origin
, details
);
146 /*----------------------------- onCreate --------------------------------*/
148 void ShaderStorageBufferObjRefChunk::onCreate(const ShaderStorageBufferObjRefChunk
*source
)
150 Inherited::onCreate(source
);
152 if(GlobalSystemState
== Startup
)
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(),
189 Int32
ShaderStorageBufferObjRefChunk::getOpenGLId(DrawEnv
*pEnv
)
191 if(this->getOsgGLId() != 0)
193 return pEnv
->getWindow()->getGLObjectId(this->getOsgGLId());
197 return this->getOglGLId();
201 /*------------------------------ activate -----------------------------------*/
203 void ShaderStorageBufferObjRefChunk::activate(DrawEnv
*pEnv
, UInt32 idx
)
205 Window
*pWin
= pEnv
->getWindow();
208 GLuint id
= this->getOpenGLId(pEnv
);
210 OSGGETGLFUNCBYID_GL3_ES( glBindBuffer
,
215 OSGGETGLFUNCBYID_GL3_ES( glBindBufferBase
,
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
,
237 OSGGETGLFUNCBYID_GL3_ES( glBindBufferBase
,
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
,
254 // change from me to me?
255 // this assumes I haven't changed in the meantime.
256 // is that a valid assumption?
260 old
->deactivate(pEnv
, idx
);
261 this->activate(pEnv
, idx
);