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 _OSGSHADERPROGRAMVARIABLECHUNK_H_
40 #define _OSGSHADERPROGRAMVARIABLECHUNK_H_
45 #include "OSGShaderProgramVariableChunkBase.h"
46 #include "OSGShaderProgramVariables.h"
47 #include "OSGLockPolicies.h"
48 #include "OSGSimpleReusePool.h"
52 /*! \brief ShaderProgramVariableChunk class. See \ref
53 PageStateShaderProgramVariableChunk for a description.
54 \ingroup GrpSystemShaderChunks
55 \ingroup GrpLibOSGSystem
59 class OSG_SYSTEM_DLLMAPPING ShaderProgramVariableChunk
:
60 public ShaderProgramVariableChunkBase
64 /*========================== PUBLIC =================================*/
68 typedef ShaderProgramVariableChunkBase Inherited
;
69 typedef ShaderProgramVariableChunk Self
;
71 struct VariableIdPoolTag
;
73 /*---------------------------------------------------------------------*/
74 /*! \name Chunk Class Access */
77 virtual const StateChunkClass
*getClass(void) const;
80 /*---------------------------------------------------------------------*/
81 /*! \name Static Chunk Class Access */
84 static UInt32
getStaticClassId(void);
85 static const StateChunkClass
*getStaticClass (void);
88 /*---------------------------------------------------------------------*/
92 virtual UInt16
getChunkId(void);
95 /*---------------------------------------------------------------------*/
99 virtual void changed(ConstFieldMaskArg whichField
,
104 /*---------------------------------------------------------------------*/
108 UInt16
getVariableId(void);
111 /*---------------------------------------------------------------------*/
114 template<class ValueT
>
115 bool addUniformVariable (const Char8
*name
, const ValueT
&value
);
117 template<class ValueT
>
118 bool updateUniformVariable (const Char8
*name
, const ValueT
&value
);
120 template<class ValueT
>
121 bool getUniformVariable (const Char8
*name
, ValueT
&value
);
123 bool subUniformVariable (const Char8
*name
);
124 void clearUniformVariables ( void );
127 /*---------------------------------------------------------------------*/
130 bool addUniformBlock (const Char8
*name
, UInt32 value
);
131 bool updateUniformBlock (const Char8
*name
, UInt32 value
);
132 bool getUniformBlock (const Char8
*name
, UInt32
&value
);
133 bool subUniformBlock (const Char8
*name
);
136 /*---------------------------------------------------------------------*/
139 bool addShaderStorageBlock (const Char8
*name
, UInt32 value
);
140 bool updateShaderStorageBlock(const Char8
*name
, UInt32 value
);
141 bool getShaderStorageBlock (const Char8
*name
, UInt32
&value
);
142 bool subShaderStorageBlock (const Char8
*name
);
145 /*---------------------------------------------------------------------*/
149 virtual void activate (DrawEnv
*, UInt32 index
= 0);
150 virtual void changeFrom(DrawEnv
*, StateChunk
*, UInt32 index
= 0);
151 virtual void deactivate(DrawEnv
*, UInt32 index
= 0);
154 /*---------------------------------------------------------------------*/
158 void addDestroyedFunctor (ChangedFunctor func
,
159 std::string createSymbol
);
161 template<class FunctorT
>
162 void subDestroyedFunctor (FunctorT func
);
164 template<class FunctorT
>
165 bool hasDestroyedFunctor (FunctorT func
);
167 void clearDestroyedFunctors(void );
170 /*---------------------------------------------------------------------*/
174 void addParent(FieldContainer
* const pParent
,
175 UInt16 uiParentFieldId
);
177 void subParent(FieldContainer
* const pParent
);
180 /*---------------------------------------------------------------------*/
184 virtual void dump( UInt32 uiIndent
= 0,
185 const BitVector bvFlags
= 0) const;
188 /*========================= PROTECTED ===============================*/
192 typedef SimpleReusePool
<Int32
,
194 SingleLockPolicy
> VarIdPool
;
197 static VarIdPool
*_pVarIdPool
;
201 /*---------------------------------------------------------------------*/
203 static volatile UInt16 _uiChunkCounter
;
207 // Variables should all be in ShaderProgramVariableChunkBase.
209 /*---------------------------------------------------------------------*/
213 void onCreate (const ShaderProgramVariableChunk
*source
= NULL
);
214 void onCreateAspect(const ShaderProgramVariableChunk
*createAspect
,
215 const ShaderProgramVariableChunk
*source
= NULL
);
218 /*---------------------------------------------------------------------*/
219 /*! \name Constructors */
222 virtual void onDestroy(UInt32 uiId
);
225 /*---------------------------------------------------------------------*/
226 /*! \name Constructors */
229 ShaderProgramVariableChunk(void);
230 ShaderProgramVariableChunk(const ShaderProgramVariableChunk
&source
);
233 /*---------------------------------------------------------------------*/
234 /*! \name Destructors */
237 virtual ~ShaderProgramVariableChunk(void);
240 /*---------------------------------------------------------------------*/
244 static void initMethod(InitPhase ePhase
);
247 /*---------------------------------------------------------------------*/
251 virtual void resolveLinks(void);
254 /*========================== PRIVATE ================================*/
258 // class. Used for indexing in State
259 static StateChunkClass _class
;
261 friend class FieldContainer
;
262 friend class ShaderProgramVariableChunkBase
;
264 // prohibit default functions (move to 'public' if you need one)
265 void operator =(const ShaderProgramVariableChunk
&source
);
268 typedef ShaderProgramVariableChunk
*ShaderProgramVariableChunkP
;
272 #include "OSGShaderProgramVariableChunkBase.inl"
273 #include "OSGShaderProgramVariableChunk.inl"
275 #endif /* _OSGSHADERPROGRAMVARIABLECHUNK_H_ */