fixed: SimpleSHLChunk vars not updated in cluster (parent not transmitted correctly)
[opensg.git] / Source / System / State / Shader / Base / OSGShaderProgramVariables.h
blob2b71e5c052b6df30b34b918a599a8e19cfce80ee
1 /*---------------------------------------------------------------------------*\
2 * OpenSG *
3 * *
4 * *
5 * Copyright (C) 2000-2006 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 #ifndef _OSGSHADERPROGRAMVARIABLES_H_
40 #define _OSGSHADERPROGRAMVARIABLES_H_
41 #ifdef __sgi
42 #pragma once
43 #endif
45 #include "OSGShaderProgramVariablesBase.h"
46 #include "OSGVecMFields.h"
47 #include "OSGMathMFields.h"
48 #include "OSGShaderVariableFunctor.h"
50 OSG_BEGIN_NAMESPACE
52 class ShaderExecutableChunk;
53 class ShaderExecutableVarChunk;
55 /*! \brief ShaderProgramVariables class. See \ref
56 PageSystemShaderProgramVariables for a description.
57 \ingroup GrpSystemShaderBase
58 \ingroup GrpLibOSGSystem
59 \includebasedoc
62 class OSG_SYSTEM_DLLMAPPING ShaderProgramVariables :
63 public ShaderProgramVariablesBase
65 protected:
67 /*========================== PUBLIC =================================*/
69 public:
71 typedef ShaderProgramVariablesBase Inherited;
72 typedef ShaderProgramVariables Self;
74 typedef ShaderVariableFunctor::ProcVarFunctor ProcVarFunctor;
75 typedef ShaderVariableFunctor::ProcVarNodeFunctor ProcVarNodeFunctor;
77 #ifdef OSG_1_COMPAT
78 typedef ShaderVariableFunctor::ParamFunctor ParamFunctor;
79 typedef ShaderVariableFunctor::OSGParamFunctor OSGParamFunctor;
80 #endif
82 /*---------------------------------------------------------------------*/
83 /*! \name Sync */
84 /*! \{ */
86 virtual void changed(ConstFieldMaskArg whichField,
87 UInt32 origin,
88 BitVector details );
90 /*! \} */
91 /*---------------------------------------------------------------------*/
92 /*! \name Output */
93 /*! \{ */
95 const MFVariablesType *getMFVariables (void) const;
96 const MFProceduralVariablesType *getMFProceduralVariables(void) const;
98 /*! \} */
99 /*---------------------------------------------------------------------*/
100 /*! \name Output */
101 /*! \{ */
103 void addVariable (ShaderVariable * const value );
104 void subVariable (UInt32 uiIndex);
105 void clearVariables (void );
107 /*! \} */
108 /*---------------------------------------------------------------------*/
109 /*! \name Output */
110 /*! \{ */
112 const ShaderVariable *getVariable(const Char8 *name) const;
114 /*! \} */
115 /*---------------------------------------------------------------------*/
116 /*! \name Output */
117 /*! \{ */
119 void markAllChanged(void);
121 /*! \} */
122 /*---------------------------------------------------------------------*/
123 /*! \name Output */
124 /*! \{ */
126 void addProceduralVariable (ShaderVariable * const value );
127 void subProceduralVariable (UInt32 uiIndex);
128 void clearProceduralVariables(void );
130 /*! \} */
131 /*---------------------------------------------------------------------*/
132 /*! \name Output */
133 /*! \{ */
135 bool addUniformVariable (const Char8 *name,
136 bool value,
137 MFInt32 *pVarLoc,
138 MFInt32 *pProcVarLoc);
140 bool addUniformVariable (const Char8 *name,
141 Int32 value,
142 MFInt32 *pVarLoc,
143 MFInt32 *pProcVarLoc);
145 bool addUniformVariable (const Char8 *name,
146 UInt32 value,
147 MFInt32 *pVarLoc,
148 MFInt32 *pProcVarLoc);
150 bool addUniformVariable (const Char8 *name,
151 Real32 value,
152 MFInt32 *pVarLoc,
153 MFInt32 *pProcVarLoc);
155 bool addUniformVariable (const Char8 *name,
156 const Vec2f &value,
157 MFInt32 *pVarLoc,
158 MFInt32 *pProcVarLoc);
160 bool addUniformVariable (const Char8 *name,
161 const Vec3f &value,
162 MFInt32 *pVarLoc,
163 MFInt32 *pProcVarLoc);
165 bool addUniformVariable (const Char8 *name,
166 const Vec4f &value,
167 MFInt32 *pVarLoc,
168 MFInt32 *pProcVarLoc);
170 bool addUniformVariable (const Char8 *name,
171 const Matrix &value,
172 MFInt32 *pVarLoc,
173 MFInt32 *pProcVarLoc);
175 bool addUniformVariable (const Char8 *name,
176 const Pnt2f &value,
177 MFInt32 *pVarLoc,
178 MFInt32 *pProcVarLoc);
180 bool addUniformVariable (const Char8 *name,
181 const Pnt3f &value,
182 MFInt32 *pVarLoc,
183 MFInt32 *pProcVarLoc);
185 bool addUniformVariable (const Char8 *name,
186 const MFInt32 &value,
187 MFInt32 *pVarLoc,
188 MFInt32 *pProcVarLoc);
190 bool addUniformVariable (const Char8 *name,
191 const MFUInt32 &value,
192 MFInt32 *pVarLoc,
193 MFInt32 *pProcVarLoc);
195 bool addUniformVariable (const Char8 *name,
196 const MFReal32 &value,
197 MFInt32 *pVarLoc,
198 MFInt32 *pProcVarLoc);
200 bool addUniformVariable (const Char8 *name,
201 const MFVec2f &value,
202 MFInt32 *pVarLoc,
203 MFInt32 *pProcVarLoc);
205 bool addUniformVariable (const Char8 *name,
206 const MFVec3f &value,
207 MFInt32 *pVarLoc,
208 MFInt32 *pProcVarLoc);
210 bool addUniformVariable (const Char8 *name,
211 const MFVec4f &value,
212 MFInt32 *pVarLoc,
213 MFInt32 *pProcVarLoc);
215 bool addUniformVariable (const Char8 *name,
216 const MFMatrix &value,
217 MFInt32 *pVarLoc,
218 MFInt32 *pProcVarLoc);
220 #if 0
221 bool addUniformVariable (const Char8 *name,
222 const MFPnt2f &value,
223 MFInt32 *pVarLoc,
224 MFInt32 *pProcVarLoc);
226 bool addUniformVariable (const Char8 *name,
227 const MFPnt3f &value,
228 MFInt32 *pVarLoc,
229 MFInt32 *pProcVarLoc);
230 #endif
232 /*! \} */
233 /*---------------------------------------------------------------------*/
234 /*! \name Output */
235 /*! \{ */
237 bool updateUniformVariable(const Char8 *name, bool value);
238 bool updateUniformVariable(const Char8 *name, Int32 value);
239 bool updateUniformVariable(const Char8 *name, UInt32 value);
240 bool updateUniformVariable(const Char8 *name, Real32 value);
242 bool updateUniformVariable(const Char8 *name, const Vec2f &value);
243 bool updateUniformVariable(const Char8 *name, const Vec3f &value);
244 bool updateUniformVariable(const Char8 *name, const Vec4f &value);
245 bool updateUniformVariable(const Char8 *name, const Matrix &value);
246 bool updateUniformVariable(const Char8 *name, const Pnt2f &value);
247 bool updateUniformVariable(const Char8 *name, const Pnt3f &value);
248 bool updateUniformVariable(const Char8 *name, const MFInt32 &value);
249 bool updateUniformVariable(const Char8 *name, const MFUInt32 &value);
250 bool updateUniformVariable(const Char8 *name, const MFReal32 &value);
251 bool updateUniformVariable(const Char8 *name, const MFVec2f &value);
252 bool updateUniformVariable(const Char8 *name, const MFVec3f &value);
253 bool updateUniformVariable(const Char8 *name, const MFVec4f &value);
254 bool updateUniformVariable(const Char8 *name, const MFMatrix &value);
255 #if 0
256 bool updateUniformVariable(const Char8 *name, const MFPnt2f &value);
257 bool updateUniformVariable(const Char8 *name, const MFPnt3f &value);
258 #endif
260 /*! \} */
261 /*---------------------------------------------------------------------*/
262 /*! \name Output */
263 /*! \{ */
265 bool getUniformVariable (const Char8 *name, bool &value);
266 bool getUniformVariable (const Char8 *name, Int32 &value);
267 bool getUniformVariable (const Char8 *name, UInt32 &value);
268 bool getUniformVariable (const Char8 *name, Real32 &value);
269 bool getUniformVariable (const Char8 *name, Vec2f &value);
270 bool getUniformVariable (const Char8 *name, Vec3f &value);
271 bool getUniformVariable (const Char8 *name, Vec4f &value);
272 bool getUniformVariable (const Char8 *name, Matrix &value);
273 bool getUniformVariable (const Char8 *name, Pnt2f &value);
274 bool getUniformVariable (const Char8 *name, Pnt3f &value);
276 bool getUniformVariable (const Char8 *name, MFInt32 &value);
277 bool getUniformVariable (const Char8 *name, MFUInt32 &value);
278 bool getUniformVariable (const Char8 *name, MFReal32 &value);
279 bool getUniformVariable (const Char8 *name, MFVec2f &value);
280 bool getUniformVariable (const Char8 *name, MFVec3f &value);
281 bool getUniformVariable (const Char8 *name, MFVec4f &value);
282 bool getUniformVariable (const Char8 *name, MFMatrix &value);
283 #if 0
284 bool getUniformVariable (const Char8 *name, MFPnt2f &value);
285 bool getUniformVariable (const Char8 *name, MFPnt3f &value);
286 #endif
288 /*! \} */
289 /*---------------------------------------------------------------------*/
290 /*! \name Output */
291 /*! \{ */
293 bool addOSGVariable (const Char8 *name,
294 MFInt32 *pProcVarLoc );
296 bool addProceduralVariable (const Char8 *name,
297 ProcVarFunctor pFunc,
298 UInt32 uiDependency,
299 MFInt32 *pProcVarLoc );
301 bool addNodeProceduralVariable (const Char8 *name,
302 ProcVarNodeFunctor pFunc,
303 UInt32 uiDependency,
304 MFInt32 *pProcVarLoc );
306 bool updateProceduralVariable (const Char8 *name,
307 ProcVarFunctor pFunc,
308 UInt32 uiDependency);
310 bool updateNodeProceduralVariable(const Char8 *name,
311 ProcVarNodeFunctor pFunc,
312 UInt32 uiDependency);
314 #ifdef OSG_1_COMPAT
315 bool addProceduralVariable (const Char8 *name,
316 ParamFunctor pFunc,
317 MFInt32 *pProcVarLoc );
319 bool addProceduralVariable (const Char8 *name,
320 OSGParamFunctor pFunc,
321 MFInt32 *pProcVarLoc );
322 #endif
324 /*! \} */
325 /*---------------------------------------------------------------------*/
326 /*! \name Output */
327 /*! \{ */
329 bool subUniformVariable (const Char8 *name,
330 MFInt32 *pVarLoc,
331 MFInt32 *pProcVarLoc);
333 void clearUniformVariables(void );
335 /*! \} */
336 /*---------------------------------------------------------------------*/
337 /*! \name Output */
338 /*! \{ */
340 /*! \} */
341 /*---------------------------------------------------------------------*/
342 /*! \name Binary Access */
343 /*! \{ */
345 /*! \} */
346 /*---------------------------------------------------------------------*/
347 /*! \name Output */
348 /*! \{ */
350 virtual void dump( UInt32 uiIndent = 0,
351 const BitVector bvFlags = 0) const;
353 /*! \} */
354 /*========================= PROTECTED ===============================*/
356 protected:
358 // Variables should all be in ShaderProgramParametersBase.
360 typedef std::pair<Int32, Int32 > IntPair;
361 typedef std::map<std::string, IntPair> VariableMap;
363 typedef VariableMap:: iterator VariableIt;
364 typedef VariableMap::const_iterator VariableConstIt;
366 VariableMap _mVarMap;
367 UInt32 _uiMapsize;
369 /*---------------------------------------------------------------------*/
370 /*! \name Constructors */
371 /*! \{ */
373 ShaderProgramVariables(void);
374 ShaderProgramVariables(const ShaderProgramVariables &source);
376 /*! \} */
377 /*---------------------------------------------------------------------*/
378 /*! \name Destructors */
379 /*! \{ */
381 virtual ~ShaderProgramVariables(void);
383 /*! \} */
384 /*---------------------------------------------------------------------*/
385 /*! \name Init */
386 /*! \{ */
388 void merge(ShaderProgramVariables *pVars,
389 MFInt32 *pVarLoc,
390 MFInt32 *pProcVarLoc);
392 /*! \} */
393 /*---------------------------------------------------------------------*/
394 /*! \name Init */
395 /*! \{ */
397 static void initMethod(InitPhase ePhase);
399 /*! \} */
400 /*---------------------------------------------------------------------*/
401 /*! \name Var name handling */
402 /*! \{ */
404 void rebuildMap ( void );
406 void addMapVariable( ShaderVariable *pVar );
408 bool subMapVariable(const Char8 *name,
409 MFInt32 *pVarLoc,
410 MFInt32 *pProcVarLoc);
412 const ShaderVariable *getMapVariable(const Char8 *name) const;
414 /*! \} */
415 /*---------------------------------------------------------------------*/
416 /*! \name Var name handling */
417 /*! \{ */
419 template<class VariableType, class ValueType>
420 bool addMapSVariable (const Char8 *name,
421 const ValueType &value,
422 MFInt32 *pVarLoc,
423 MFInt32 *pProcVarLoc );
425 template<class VariableType, class ValueType>
426 bool updateMapSVariable (const Char8 *name,
427 const ValueType &value );
429 template<class VariableType, class ValueType>
430 bool getMapSVariable (const Char8 *name,
431 ValueType &value );
434 template<class VariableType, class ValueType>
435 bool addMapMVariable (const char *name,
436 const ValueType &value,
437 MFInt32 *pVarLoc,
438 MFInt32 *pProcVarLoc );
440 template<class VariableType, class ValueType>
441 bool updateMapMVariable (const char *name,
442 const ValueType &value );
444 template<class VariableType, class ValueType>
445 bool getMapMVariable (const Char8 *name,
446 ValueType &value );
449 bool addMapVariableOSG (const Char8 *name,
450 MFInt32 *pProcVarLoc );
452 template<class FunctorT>
453 bool addMapProceduralVariable (const Char8 *name,
454 FunctorT pFunctor,
455 UInt32 uiDependency,
456 MFInt32 *pProcVarLoc );
458 bool updateMapProceduralVariable(const Char8 *name,
459 ProcVarFunctor pFunctor,
460 UInt32 uiDependency);
462 bool updateMapProceduralVariable(const Char8 *name,
463 ProcVarNodeFunctor pFunctor,
464 UInt32 uiDependency);
466 /*! \} */
467 /*---------------------------------------------------------------------*/
468 /*! \name Init */
469 /*! \{ */
471 void onCreateAspect (const ShaderProgramVariables *createAspect,
472 const ShaderProgramVariables *source = NULL);
474 void onDestroyAspect( UInt32 uiContainerId,
475 UInt32 uiAspect );
477 /*! \} */
478 /*---------------------------------------------------------------------*/
479 /*! \name Init */
480 /*! \{ */
482 MFVariablesType *editMFVariables (void);
483 MFProceduralVariablesType *editMFProceduralVariables(void);
485 /*! \} */
486 /*========================== PRIVATE ================================*/
488 private:
490 friend class FieldContainer;
491 friend class ShaderProgramVariablesBase;
492 friend class ShaderExecutableChunk;
493 friend class ShaderExecutableVarChunk;
495 // prohibit default functions (move to 'public' if you need one)
496 void operator =(const ShaderProgramVariables &source);
499 typedef ShaderProgramVariables *ShaderProgramVariablesP;
501 OSG_END_NAMESPACE
503 #include "OSGShaderProgramVariablesBase.inl"
504 #include "OSGShaderProgramVariables.inl"
506 #endif /* _OSGSHADERVARIABLES_H_ */