1 /*---------------------------------------------------------------------------*\
5 * Copyright (C) 2000-2006 by the OpenSG Forum *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
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 _OSGSHADERPROGRAMVARIABLES_H_
40 #define _OSGSHADERPROGRAMVARIABLES_H_
45 #include "OSGShaderProgramVariablesBase.h"
46 #include "OSGVecMFields.h"
47 #include "OSGMathMFields.h"
48 #include "OSGShaderVariableFunctor.h"
52 class ShaderExecutableChunk
;
53 class ShaderExecutableVarChunk
;
55 /*! \brief ShaderProgramVariables class. See \ref
56 PageSystemShaderProgramVariables for a description.
57 \ingroup GrpSystemShaderBase
58 \ingroup GrpLibOSGSystem
62 class OSG_SYSTEM_DLLMAPPING ShaderProgramVariables
:
63 public ShaderProgramVariablesBase
67 /*========================== PUBLIC =================================*/
71 typedef ShaderProgramVariablesBase Inherited
;
72 typedef ShaderProgramVariables Self
;
74 typedef ShaderVariableFunctor::ProcVarFunctor ProcVarFunctor
;
75 typedef ShaderVariableFunctor::ProcVarNodeFunctor ProcVarNodeFunctor
;
78 typedef ShaderVariableFunctor::ParamFunctor ParamFunctor
;
79 typedef ShaderVariableFunctor::OSGParamFunctor OSGParamFunctor
;
82 /*---------------------------------------------------------------------*/
86 virtual void changed(ConstFieldMaskArg whichField
,
91 /*---------------------------------------------------------------------*/
95 const MFVariablesType
*getMFVariables (void) const;
96 const MFProceduralVariablesType
*getMFProceduralVariables(void) const;
99 /*---------------------------------------------------------------------*/
103 void addVariable (ShaderVariable
* const value
);
104 void subVariable (UInt32 uiIndex
);
105 void clearVariables (void );
108 /*---------------------------------------------------------------------*/
112 const ShaderVariable
*getVariable(const Char8
*name
) const;
115 /*---------------------------------------------------------------------*/
119 void markAllChanged(void);
122 /*---------------------------------------------------------------------*/
126 void addProceduralVariable (ShaderVariable
* const value
);
127 void subProceduralVariable (UInt32 uiIndex
);
128 void clearProceduralVariables(void );
131 /*---------------------------------------------------------------------*/
135 bool addUniformVariable (const Char8
*name
,
138 MFInt32
*pProcVarLoc
);
140 bool addUniformVariable (const Char8
*name
,
143 MFInt32
*pProcVarLoc
);
145 bool addUniformVariable (const Char8
*name
,
148 MFInt32
*pProcVarLoc
);
150 bool addUniformVariable (const Char8
*name
,
153 MFInt32
*pProcVarLoc
);
155 bool addUniformVariable (const Char8
*name
,
158 MFInt32
*pProcVarLoc
);
160 bool addUniformVariable (const Char8
*name
,
163 MFInt32
*pProcVarLoc
);
165 bool addUniformVariable (const Char8
*name
,
168 MFInt32
*pProcVarLoc
);
170 bool addUniformVariable (const Char8
*name
,
173 MFInt32
*pProcVarLoc
);
175 bool addUniformVariable (const Char8
*name
,
178 MFInt32
*pProcVarLoc
);
180 bool addUniformVariable (const Char8
*name
,
183 MFInt32
*pProcVarLoc
);
185 bool addUniformVariable (const Char8
*name
,
186 const MFInt32
&value
,
188 MFInt32
*pProcVarLoc
);
190 bool addUniformVariable (const Char8
*name
,
191 const MFUInt32
&value
,
193 MFInt32
*pProcVarLoc
);
195 bool addUniformVariable (const Char8
*name
,
196 const MFReal32
&value
,
198 MFInt32
*pProcVarLoc
);
200 bool addUniformVariable (const Char8
*name
,
201 const MFVec2f
&value
,
203 MFInt32
*pProcVarLoc
);
205 bool addUniformVariable (const Char8
*name
,
206 const MFVec3f
&value
,
208 MFInt32
*pProcVarLoc
);
210 bool addUniformVariable (const Char8
*name
,
211 const MFVec4f
&value
,
213 MFInt32
*pProcVarLoc
);
215 bool addUniformVariable (const Char8
*name
,
216 const MFMatrix
&value
,
218 MFInt32
*pProcVarLoc
);
221 bool addUniformVariable (const Char8
*name
,
222 const MFPnt2f
&value
,
224 MFInt32
*pProcVarLoc
);
226 bool addUniformVariable (const Char8
*name
,
227 const MFPnt3f
&value
,
229 MFInt32
*pProcVarLoc
);
233 /*---------------------------------------------------------------------*/
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
);
256 bool updateUniformVariable(const Char8
*name
, const MFPnt2f
&value
);
257 bool updateUniformVariable(const Char8
*name
, const MFPnt3f
&value
);
261 /*---------------------------------------------------------------------*/
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
);
284 bool getUniformVariable (const Char8
*name
, MFPnt2f
&value
);
285 bool getUniformVariable (const Char8
*name
, MFPnt3f
&value
);
289 /*---------------------------------------------------------------------*/
293 bool addOSGVariable (const Char8
*name
,
294 MFInt32
*pProcVarLoc
);
296 bool addProceduralVariable (const Char8
*name
,
297 ProcVarFunctor pFunc
,
299 MFInt32
*pProcVarLoc
);
301 bool addNodeProceduralVariable (const Char8
*name
,
302 ProcVarNodeFunctor pFunc
,
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
);
315 bool addProceduralVariable (const Char8
*name
,
317 MFInt32
*pProcVarLoc
);
319 bool addProceduralVariable (const Char8
*name
,
320 OSGParamFunctor pFunc
,
321 MFInt32
*pProcVarLoc
);
325 /*---------------------------------------------------------------------*/
329 bool subUniformVariable (const Char8
*name
,
331 MFInt32
*pProcVarLoc
);
333 void clearUniformVariables(void );
336 /*---------------------------------------------------------------------*/
341 /*---------------------------------------------------------------------*/
342 /*! \name Binary Access */
346 /*---------------------------------------------------------------------*/
350 virtual void dump( UInt32 uiIndent
= 0,
351 const BitVector bvFlags
= 0) const;
354 /*========================= 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
;
369 /*---------------------------------------------------------------------*/
370 /*! \name Constructors */
373 ShaderProgramVariables(void);
374 ShaderProgramVariables(const ShaderProgramVariables
&source
);
377 /*---------------------------------------------------------------------*/
378 /*! \name Destructors */
381 virtual ~ShaderProgramVariables(void);
384 /*---------------------------------------------------------------------*/
388 void merge(ShaderProgramVariables
*pVars
,
390 MFInt32
*pProcVarLoc
);
393 /*---------------------------------------------------------------------*/
397 static void initMethod(InitPhase ePhase
);
400 /*---------------------------------------------------------------------*/
401 /*! \name Var name handling */
404 void rebuildMap ( void );
406 void addMapVariable( ShaderVariable
*pVar
);
408 bool subMapVariable(const Char8
*name
,
410 MFInt32
*pProcVarLoc
);
412 const ShaderVariable
*getMapVariable(const Char8
*name
) const;
415 /*---------------------------------------------------------------------*/
416 /*! \name Var name handling */
419 template<class VariableType
, class ValueType
>
420 bool addMapSVariable (const Char8
*name
,
421 const ValueType
&value
,
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
,
434 template<class VariableType
, class ValueType
>
435 bool addMapMVariable (const char *name
,
436 const ValueType
&value
,
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
,
449 bool addMapVariableOSG (const Char8
*name
,
450 MFInt32
*pProcVarLoc
);
452 template<class FunctorT
>
453 bool addMapProceduralVariable (const Char8
*name
,
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
);
467 /*---------------------------------------------------------------------*/
471 void onCreateAspect (const ShaderProgramVariables
*createAspect
,
472 const ShaderProgramVariables
*source
= NULL
);
474 void onDestroyAspect( UInt32 uiContainerId
,
478 /*---------------------------------------------------------------------*/
482 MFVariablesType
*editMFVariables (void);
483 MFProceduralVariablesType
*editMFProceduralVariables(void);
486 /*========================== 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
;
503 #include "OSGShaderProgramVariablesBase.inl"
504 #include "OSGShaderProgramVariables.inl"
506 #endif /* _OSGSHADERVARIABLES_H_ */