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 #ifndef _OSGSHADERSTORAGEBUFFEROBJCHUNK_H_
40 #define _OSGSHADERSTORAGEBUFFEROBJCHUNK_H_
45 #include "OSGShaderStorageBufferObjChunkBase.h"
46 #include "OSGWindow.h"
50 /*! \brief ShaderStorageBufferObjChunk class. See \ref
51 PageSystemShaderStorageBufferObjChunk for a description.
54 class OSG_SYSTEM_DLLMAPPING ShaderStorageBufferObjChunk
: public ShaderStorageBufferObjChunkBase
57 enum FundamentalTypes
{
58 FLOAT_T
, DOUBLE_T
, INT_T
, UINT_T
, BOOL_T
62 SIMPLE_T
, VEC2_T
, VEC3_T
, VEC4_T
, MAT2_T
, MAT3_T
, MAT4_T
,
63 MAT2X3_T
, MAT2X4_T
, MAT3X4_T
, MAT3X2_T
, MAT4X2_T
, MAT4X3_T
66 /*========================== PUBLIC =================================*/
70 typedef ShaderStorageBufferObjChunkBase Inherited
;
71 typedef ShaderStorageBufferObjChunk Self
;
73 /*---------------------------------------------------------------------*/
74 /*! \name Interface */
76 UInt32
addFloat (const std::string
& name
, UInt32 cardinality
= 1);
77 UInt32
addDouble (const std::string
& name
, UInt32 cardinality
= 1);
78 UInt32
addInt (const std::string
& name
, UInt32 cardinality
= 1);
79 UInt32
addUInt (const std::string
& name
, UInt32 cardinality
= 1);
80 UInt32
addBool (const std::string
& name
, UInt32 cardinality
= 1);
81 UInt32
addVec2 (const std::string
& name
, UInt32 cardinality
= 1);
82 UInt32
addVec3 (const std::string
& name
, UInt32 cardinality
= 1);
83 UInt32
addVec4 (const std::string
& name
, UInt32 cardinality
= 1);
84 UInt32
addDVec2 (const std::string
& name
, UInt32 cardinality
= 1);
85 UInt32
addDVec3 (const std::string
& name
, UInt32 cardinality
= 1);
86 UInt32
addDVec4 (const std::string
& name
, UInt32 cardinality
= 1);
87 UInt32
addIVec2 (const std::string
& name
, UInt32 cardinality
= 1);
88 UInt32
addIVec3 (const std::string
& name
, UInt32 cardinality
= 1);
89 UInt32
addIVec4 (const std::string
& name
, UInt32 cardinality
= 1);
90 UInt32
addUVec2 (const std::string
& name
, UInt32 cardinality
= 1);
91 UInt32
addUVec3 (const std::string
& name
, UInt32 cardinality
= 1);
92 UInt32
addUVec4 (const std::string
& name
, UInt32 cardinality
= 1);
93 UInt32
addBVec2 (const std::string
& name
, UInt32 cardinality
= 1);
94 UInt32
addBVec3 (const std::string
& name
, UInt32 cardinality
= 1);
95 UInt32
addBVec4 (const std::string
& name
, UInt32 cardinality
= 1);
96 UInt32
addMat2 (const std::string
& name
, UInt32 cardinality
= 1);
97 UInt32
addMat3 (const std::string
& name
, UInt32 cardinality
= 1);
98 UInt32
addMat4 (const std::string
& name
, UInt32 cardinality
= 1);
99 UInt32
addDMat2 (const std::string
& name
, UInt32 cardinality
= 1);
100 UInt32
addDMat3 (const std::string
& name
, UInt32 cardinality
= 1);
101 UInt32
addDMat4 (const std::string
& name
, UInt32 cardinality
= 1);
102 UInt32
addMat2x3 (const std::string
& name
, UInt32 cardinality
= 1);
103 UInt32
addMat3x2 (const std::string
& name
, UInt32 cardinality
= 1);
104 UInt32
addMat2x4 (const std::string
& name
, UInt32 cardinality
= 1);
105 UInt32
addMat4x2 (const std::string
& name
, UInt32 cardinality
= 1);
106 UInt32
addMat3x4 (const std::string
& name
, UInt32 cardinality
= 1);
107 UInt32
addMat4x3 (const std::string
& name
, UInt32 cardinality
= 1);
108 UInt32
addDMat2x3 (const std::string
& name
, UInt32 cardinality
= 1);
109 UInt32
addDMat3x2 (const std::string
& name
, UInt32 cardinality
= 1);
110 UInt32
addDMat2x4 (const std::string
& name
, UInt32 cardinality
= 1);
111 UInt32
addDMat4x2 (const std::string
& name
, UInt32 cardinality
= 1);
112 UInt32
addDMat3x4 (const std::string
& name
, UInt32 cardinality
= 1);
113 UInt32
addDMat4x3 (const std::string
& name
, UInt32 cardinality
= 1);
115 void setFloat (UInt32 handle
, Real32 value
, UInt32 array_idx
= 0);
116 void setDouble (UInt32 handle
, Real64 value
, UInt32 array_idx
= 0);
117 void setInt (UInt32 handle
, Int32 value
, UInt32 array_idx
= 0);
118 void setUInt (UInt32 handle
, UInt32 value
, UInt32 array_idx
= 0);
119 void setBool (UInt32 handle
, bool value
, UInt32 array_idx
= 0);
120 void setVec2 (UInt32 handle
, const Vec2f
& value
, UInt32 array_idx
= 0);
121 void setVec2 (UInt32 handle
, const Pnt2f
& value
, UInt32 array_idx
= 0);
122 void setVec3 (UInt32 handle
, const Vec3f
& value
, UInt32 array_idx
= 0);
123 void setVec3 (UInt32 handle
, const Pnt3f
& value
, UInt32 array_idx
= 0);
124 void setVec3 (UInt32 handle
, const Color3f
& value
, UInt32 array_idx
= 0);
125 void setVec4 (UInt32 handle
, const Vec4f
& value
, UInt32 array_idx
= 0);
126 void setVec4 (UInt32 handle
, const Pnt4f
& value
, UInt32 array_idx
= 0);
127 void setVec4 (UInt32 handle
, const Color4f
& value
, UInt32 array_idx
= 0);
128 void setDVec2 (UInt32 handle
, const Vec2d
& value
, UInt32 array_idx
= 0);
129 void setDVec2 (UInt32 handle
, const Pnt2d
& value
, UInt32 array_idx
= 0);
130 void setDVec3 (UInt32 handle
, const Vec3d
& value
, UInt32 array_idx
= 0);
131 void setDVec3 (UInt32 handle
, const Pnt3d
& value
, UInt32 array_idx
= 0);
132 void setDVec4 (UInt32 handle
, const Vec4d
& value
, UInt32 array_idx
= 0);
133 void setDVec4 (UInt32 handle
, const Pnt4d
& value
, UInt32 array_idx
= 0);
134 void setIVec2 (UInt32 handle
, const Vec2i
& value
, UInt32 array_idx
= 0);
135 void setIVec2 (UInt32 handle
, const Pnt2i
& value
, UInt32 array_idx
= 0);
136 void setIVec3 (UInt32 handle
, const Vec3i
& value
, UInt32 array_idx
= 0);
137 //void setIVec3 (UInt32 handle, const Pnt3i& value, UInt32 array_idx = 0);
138 void setIVec4 (UInt32 handle
, const Vec4i
& value
, UInt32 array_idx
= 0);
139 //void setIVec4 (UInt32 handle, const Pnt4i& value, UInt32 array_idx = 0);
140 void setUVec2 (UInt32 handle
, const Vec2u
& value
, UInt32 array_idx
= 0);
141 //void setUVec2 (UInt32 handle, const Pnt2u& value, UInt32 array_idx = 0);
142 void setUVec3 (UInt32 handle
, const Vec3u
& value
, UInt32 array_idx
= 0);
143 //void setUVec3 (UInt32 handle, const Pnt3u& value, UInt32 array_idx = 0);
144 void setUVec4 (UInt32 handle
, const Vec4u
& value
, UInt32 array_idx
= 0);
145 //void setUVec4 (UInt32 handle, const Pnt4u& value, UInt32 array_idx = 0);
146 void setBVec2 (UInt32 handle
, const Vec2b
& value
, UInt32 array_idx
= 0);
147 void setBVec2 (UInt32 handle
, const Pnt2b
& value
, UInt32 array_idx
= 0);
148 void setBVec3 (UInt32 handle
, const Vec3b
& value
, UInt32 array_idx
= 0);
149 void setBVec3 (UInt32 handle
, const Pnt3b
& value
, UInt32 array_idx
= 0);
150 void setBVec4 (UInt32 handle
, const Vec4b
& value
, UInt32 array_idx
= 0);
151 void setBVec4 (UInt32 handle
, const Pnt4b
& value
, UInt32 array_idx
= 0);
152 void setMat2 (UInt32 handle
, const Matrix4f
& value
, UInt32 array_idx
= 0);
153 void setMat3 (UInt32 handle
, const Matrix4f
& value
, UInt32 array_idx
= 0);
154 void setMat4 (UInt32 handle
, const Matrix4f
& value
, UInt32 array_idx
= 0);
155 void setDMat2 (UInt32 handle
, const Matrix4d
& value
, UInt32 array_idx
= 0);
156 void setDMat3 (UInt32 handle
, const Matrix4d
& value
, UInt32 array_idx
= 0);
157 void setDMat4 (UInt32 handle
, const Matrix4d
& value
, UInt32 array_idx
= 0);
158 void setMat2x3 (UInt32 handle
, const Matrix4f
& value
, UInt32 array_idx
= 0);
159 void setMat3x2 (UInt32 handle
, const Matrix4f
& value
, UInt32 array_idx
= 0);
160 void setMat2x4 (UInt32 handle
, const Matrix4f
& value
, UInt32 array_idx
= 0);
161 void setMat4x2 (UInt32 handle
, const Matrix4f
& value
, UInt32 array_idx
= 0);
162 void setMat3x4 (UInt32 handle
, const Matrix4f
& value
, UInt32 array_idx
= 0);
163 void setMat4x3 (UInt32 handle
, const Matrix4f
& value
, UInt32 array_idx
= 0);
164 void setDMat2x3 (UInt32 handle
, const Matrix4d
& value
, UInt32 array_idx
= 0);
165 void setDMat3x2 (UInt32 handle
, const Matrix4d
& value
, UInt32 array_idx
= 0);
166 void setDMat2x4 (UInt32 handle
, const Matrix4d
& value
, UInt32 array_idx
= 0);
167 void setDMat4x2 (UInt32 handle
, const Matrix4d
& value
, UInt32 array_idx
= 0);
168 void setDMat3x4 (UInt32 handle
, const Matrix4d
& value
, UInt32 array_idx
= 0);
169 void setDMat4x3 (UInt32 handle
, const Matrix4d
& value
, UInt32 array_idx
= 0);
171 void setFloat (const std::string
& name
, Real32 value
, UInt32 array_idx
= 0);
172 void setDouble (const std::string
& name
, Real64 value
, UInt32 array_idx
= 0);
173 void setInt (const std::string
& name
, Int32 value
, UInt32 array_idx
= 0);
174 void setUInt (const std::string
& name
, UInt32 value
, UInt32 array_idx
= 0);
175 void setBool (const std::string
& name
, bool value
, UInt32 array_idx
= 0);
176 void setVec2 (const std::string
& name
, const Vec2f
& value
, UInt32 array_idx
= 0);
177 void setVec2 (const std::string
& name
, const Pnt2f
& value
, UInt32 array_idx
= 0);
178 void setVec3 (const std::string
& name
, const Vec3f
& value
, UInt32 array_idx
= 0);
179 void setVec3 (const std::string
& name
, const Pnt3f
& value
, UInt32 array_idx
= 0);
180 void setVec3 (const std::string
& name
, const Color3f
& value
, UInt32 array_idx
= 0);
181 void setVec4 (const std::string
& name
, const Vec4f
& value
, UInt32 array_idx
= 0);
182 void setVec4 (const std::string
& name
, const Pnt4f
& value
, UInt32 array_idx
= 0);
183 void setVec4 (const std::string
& name
, const Color4f
& value
, UInt32 array_idx
= 0);
184 void setDVec2 (const std::string
& name
, const Vec2d
& value
, UInt32 array_idx
= 0);
185 void setDVec2 (const std::string
& name
, const Pnt2d
& value
, UInt32 array_idx
= 0);
186 void setDVec3 (const std::string
& name
, const Vec3d
& value
, UInt32 array_idx
= 0);
187 void setDVec3 (const std::string
& name
, const Pnt3d
& value
, UInt32 array_idx
= 0);
188 void setDVec4 (const std::string
& name
, const Vec4d
& value
, UInt32 array_idx
= 0);
189 void setDVec4 (const std::string
& name
, const Pnt4d
& value
, UInt32 array_idx
= 0);
190 void setIVec2 (const std::string
& name
, const Vec2i
& value
, UInt32 array_idx
= 0);
191 void setIVec2 (const std::string
& name
, const Pnt2i
& value
, UInt32 array_idx
= 0);
192 void setIVec3 (const std::string
& name
, const Vec3i
& value
, UInt32 array_idx
= 0);
193 //void setIVec3 (const std::string& name, const Pnt3i& value, UInt32 array_idx = 0);
194 void setIVec4 (const std::string
& name
, const Vec4i
& value
, UInt32 array_idx
= 0);
195 //void setIVec4 (const std::string& name, const Pnt4i& value, UInt32 array_idx = 0);
196 void setUVec2 (const std::string
& name
, const Vec2u
& value
, UInt32 array_idx
= 0);
197 //void setUVec2 (const std::string& name, const Pnt2u& value, UInt32 array_idx = 0);
198 void setUVec3 (const std::string
& name
, const Vec3u
& value
, UInt32 array_idx
= 0);
199 //void setUVec3 (const std::string& name, const Pnt3u& value, UInt32 array_idx = 0);
200 void setUVec4 (const std::string
& name
, const Vec4u
& value
, UInt32 array_idx
= 0);
201 //void setUVec4 (const std::string& name, const Pnt4u& value, UInt32 array_idx = 0);
202 void setBVec2 (const std::string
& name
, const Vec2b
& value
, UInt32 array_idx
= 0);
203 void setBVec2 (const std::string
& name
, const Pnt2b
& value
, UInt32 array_idx
= 0);
204 void setBVec3 (const std::string
& name
, const Vec3b
& value
, UInt32 array_idx
= 0);
205 void setBVec3 (const std::string
& name
, const Pnt3b
& value
, UInt32 array_idx
= 0);
206 void setBVec4 (const std::string
& name
, const Vec4b
& value
, UInt32 array_idx
= 0);
207 void setBVec4 (const std::string
& name
, const Pnt4b
& value
, UInt32 array_idx
= 0);
208 void setMat2 (const std::string
& name
, const Matrix4f
& value
, UInt32 array_idx
= 0);
209 void setMat3 (const std::string
& name
, const Matrix4f
& value
, UInt32 array_idx
= 0);
210 void setMat4 (const std::string
& name
, const Matrix4f
& value
, UInt32 array_idx
= 0);
211 void setDMat2 (const std::string
& name
, const Matrix4d
& value
, UInt32 array_idx
= 0);
212 void setDMat3 (const std::string
& name
, const Matrix4d
& value
, UInt32 array_idx
= 0);
213 void setDMat4 (const std::string
& name
, const Matrix4d
& value
, UInt32 array_idx
= 0);
214 void setMat2x3 (const std::string
& name
, const Matrix4f
& value
, UInt32 array_idx
= 0);
215 void setMat3x2 (const std::string
& name
, const Matrix4f
& value
, UInt32 array_idx
= 0);
216 void setMat2x4 (const std::string
& name
, const Matrix4f
& value
, UInt32 array_idx
= 0);
217 void setMat4x2 (const std::string
& name
, const Matrix4f
& value
, UInt32 array_idx
= 0);
218 void setMat3x4 (const std::string
& name
, const Matrix4f
& value
, UInt32 array_idx
= 0);
219 void setMat4x3 (const std::string
& name
, const Matrix4f
& value
, UInt32 array_idx
= 0);
220 void setDMat2x3 (const std::string
& name
, const Matrix4d
& value
, UInt32 array_idx
= 0);
221 void setDMat3x2 (const std::string
& name
, const Matrix4d
& value
, UInt32 array_idx
= 0);
222 void setDMat2x4 (const std::string
& name
, const Matrix4d
& value
, UInt32 array_idx
= 0);
223 void setDMat4x2 (const std::string
& name
, const Matrix4d
& value
, UInt32 array_idx
= 0);
224 void setDMat3x4 (const std::string
& name
, const Matrix4d
& value
, UInt32 array_idx
= 0);
225 void setDMat4x3 (const std::string
& name
, const Matrix4d
& value
, UInt32 array_idx
= 0);
229 /*---------------------------------------------------------------------*/
233 virtual void changed(ConstFieldMaskArg whichField
,
238 /*---------------------------------------------------------------------*/
242 virtual void dump( UInt32 uiIndent
= 0,
243 const BitVector bvFlags
= 0) const;
246 /*---------------------------------------------------------------------*/
250 virtual void activate (DrawEnv
*pEnv
,
253 virtual void changeFrom (DrawEnv
*pEnv
,
257 virtual void deactivate (DrawEnv
*pEnv
,
261 /*---------------------------------------------------------------------*/
262 /*! \name OpenGL handling */
265 virtual void validate (DrawEnv
*pEnv
);
266 virtual Int32
getOpenGLId (DrawEnv
*pEnv
);
269 /*========================= PROTECTED ===============================*/
272 // Variables should all be in ShaderStorageBufferObjChunkBase.
274 void onCreate (const ShaderStorageBufferObjChunk
*source
= NULL
);
275 void onCreateAspect(const ShaderStorageBufferObjChunk
*createAspect
,
276 const ShaderStorageBufferObjChunk
*source
= NULL
);
277 void onDestroy ( UInt32 uiContainerId
);
279 /*---------------------------------------------------------------------*/
280 /*! \name Constructors */
283 ShaderStorageBufferObjChunk(void);
284 ShaderStorageBufferObjChunk(const ShaderStorageBufferObjChunk
&source
);
287 /*---------------------------------------------------------------------*/
288 /*! \name Destructors */
291 virtual ~ShaderStorageBufferObjChunk(void);
294 /*---------------------------------------------------------------------*/
298 static void initMethod(InitPhase ePhase
);
302 // extension indices for used extensions;
303 static UInt32 _extVertexBufferObject
;
304 static UInt32 _funcBindBuffer
;
305 static UInt32 _funcMapBuffer
;
306 static UInt32 _funcUnmapBuffer
;
307 static UInt32 _funcBufferData
;
308 static UInt32 _funcBufferSubData
;
309 static UInt32 _funcGenBuffers
;
310 static UInt32 _funcDeleteBuffers
;
311 static UInt32 _funcGetBufferParameteriv
;
313 static UInt32 _extUniformBufferObject
;
314 static UInt32 _funcBindBufferBase
;
316 static UInt32 _extProgramInterfaceQuery
;
317 static UInt32 _funcGetProgramResourceIndex
;
318 static UInt32 _funcGetProgramResourceiv
;
319 static UInt32 _funcGetProgramResourceName
;
321 static UInt32 _extShaderStorageBufferObject
;
323 /*========================== PRIVATE ================================*/
327 friend class FieldContainer
;
328 friend class ShaderStorageBufferObjChunkBase
;
330 /*---------------------------------------------------------------------*/
334 UInt32
handleGL (DrawEnv
*pEnv
,
336 Window::GLObjectStatusE mode
,
339 static void handleDestroyGL(DrawEnv
*pEnv
,
341 Window::GLObjectStatusE mode
);
344 /*---------------------------------------------------------------------*/
347 std::vector
<GLubyte
> createBuffer (DrawEnv
*pEnv
);
350 /*---------------------------------------------------------------------*/
351 /*! \name Invariants */
353 bool invariantOnStorageSize ();
356 /*---------------------------------------------------------------------*/
358 // prohibit default functions (move to 'public' if you need one)
359 void operator =(const ShaderStorageBufferObjChunk
&source
);
362 typedef ShaderStorageBufferObjChunk
*ShaderStorageBufferObjChunkP
;
366 #include "OSGShaderStorageBufferObjChunkBase.inl"
367 #include "OSGShaderStorageBufferObjChunk.inl"
369 #endif /* _OSGSHADERSTORAGEBUFFEROBJCHUNK_H_ */