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 _OSGSIMPLESHLCHUNK_H_
40 #define _OSGSIMPLESHLCHUNK_H_
45 #include "OSGSimpleSHLChunkBase.h"
46 #include "OSGShaderProgram.h"
47 #include "OSGShaderExecutableChunk.h"
53 /*! \brief SimpleSHLChunk class. See \ref
54 PageStateSimpleSHLChunk for a description.
55 \ingroup GrpSystemShaderSHLChunk
56 \ingroup GrpLibOSGSystem
60 class OSG_SYSTEM_DLLMAPPING SimpleSHLChunk
: public SimpleSHLChunkBase
64 /*========================== PUBLIC =================================*/
68 typedef SimpleSHLChunkBase Inherited
;
69 typedef SimpleSHLChunk Self
;
71 typedef ShaderVariableFunctor::GetUniformLocProc GetUniformLocProc
;
72 typedef ShaderVariableFunctor::ProcVarFunctor ProcVarFunctor
;
73 typedef ShaderVariableFunctor::ProcVarNodeFunctor ProcVarNodeFunctor
;
75 static const UInt32 KeepProgActive
= ShaderProgram::KeepProgActive
;
77 static const UInt32 ProgActive
= ShaderProgram::ProgActive
;
80 typedef ShaderVariableFunctor::ParamFunctor ParamFunctor
;
81 typedef ShaderVariableFunctor::OSGParamFunctor OSGParamFunctor
;
83 static const OSG::BitVector ParametersFieldMask
= VariablesFieldMask
;
86 /*---------------------------------------------------------------------*/
87 /*! \name Chunk Class Access */
90 virtual const StateChunkClass
*getClass(void) const;
93 /*---------------------------------------------------------------------*/
94 /*! \name Static Chunk Class Access */
97 static UInt32
getStaticClassId(void);
98 static const StateChunkClass
*getStaticClass (void);
101 /*---------------------------------------------------------------------*/
102 /*! \name Chunk Id */
105 virtual UInt16
getChunkId(void);
108 /*---------------------------------------------------------------------*/
112 virtual void changed(ConstFieldMaskArg whichField
,
117 /*---------------------------------------------------------------------*/
121 virtual void activate (DrawEnv
*pEnv
,
124 virtual void changeFrom (DrawEnv
*pEnv
,
128 virtual void deactivate (DrawEnv
*pEnv
,
131 virtual void updateObjectDependencies(DrawEnv
*pEnv
,
135 /*---------------------------------------------------------------------*/
139 bool readFragmentProgram (const Char8
*file
);
140 bool readGeometryProgram (const Char8
*file
);
141 bool readTessControlProgram (const Char8
* file
);
142 bool readTessEvaluationProgram(const Char8
* file
);
143 bool readVertexProgram (const Char8
*file
);
146 /*---------------------------------------------------------------------*/
147 /*! \name Program Parameter */
151 void addProgramParameter (GLenum name
, UInt32 value
);
152 void subProgramParameter (GLenum name
);
155 void setProgramParameter (GLenum name
, UInt32 value
);
157 UInt32
getProgramParameter (GLenum name
);
159 void clearProgramParameters(void );
162 /*---------------------------------------------------------------------*/
167 virtual void update (DrawEnv
*pEnv
);
171 /*---------------------------------------------------------------------*/
176 template<class ValueT
>
177 bool setUniformParameter (const Char8
*name
, const ValueT
&value
);
179 template<class ValueT
>
180 bool getUniformParameter (const Char8
*name
, ValueT
&value
);
182 bool subUniformParameter (const Char8
*name
);
183 void clearUniformParameters( void );
186 template<class ValueT
>
187 bool addUniformVariable (const Char8
*name
, const ValueT
&value
);
189 template<class ValueT
>
190 bool updateUniformVariable (const Char8
*name
, const ValueT
&value
);
192 template<class ValueT
>
193 bool getUniformVariable (const Char8
*name
, ValueT
&value
);
195 bool hasUniformVariable (const Char8
*name
);
197 bool subUniformVariable (const Char8
*name
);
198 void clearUniformVariables ( void );
200 bool addOSGVariable (const Char8
*name
);
203 /*---------------------------------------------------------------------*/
206 bool addUniformBlock (const Char8
*name
, UInt32 value
);
207 bool updateUniformBlock (const Char8
*name
, UInt32 value
);
208 bool getUniformBlock (const Char8
*name
, UInt32
& value
);
209 bool subUniformBlock (const Char8
*name
);
212 /*---------------------------------------------------------------------*/
215 bool addShaderStorageBlock (const Char8
*name
, UInt32 value
);
216 bool updateShaderStorageBlock(const Char8
*name
, UInt32 value
);
217 bool getShaderStorageBlock (const Char8
*name
, UInt32
& value
);
218 bool subShaderStorageBlock (const Char8
*name
);
221 /*---------------------------------------------------------------------*/
225 bool addProceduralVariable (const Char8
*name
,
226 ProcVarFunctor pFunc
,
227 UInt32 uiDependency
=
228 ShaderProcVariable::SHDObject
);
230 bool updateProceduralVariable (const Char8
*name
,
231 ProcVarFunctor pFunc
,
232 UInt32 uiDependency
=
233 ShaderProcVariable::SHDObject
);
235 bool addNodeProceduralVariable (const Char8
*name
,
236 ProcVarNodeFunctor pFunc
,
237 UInt32 uiDependency
=
238 ShaderProcVariable::SHDObject
);
240 bool updateNodeProceduralVariable(const Char8
*name
,
241 ProcVarNodeFunctor pFunc
,
242 UInt32 uiDependency
=
243 ShaderProcVariable::SHDObject
);
247 /*---------------------------------------------------------------------*/
252 void addParameterCallback(const Char8
*name
, ParamFunctor fp
);
253 void addParameterCallback(const Char8
*name
, OSGParamFunctor fp
);
255 static void setParameterCallback( ParamFunctor fp
);
259 /*---------------------------------------------------------------------*/
264 void updateParameters(
266 const UInt32
¶meters
,
267 bool useProgram
= true,
269 bool keepProgramActive
=false);
271 const UInt32
*getMFParameters(void) const;
275 /*---------------------------------------------------------------------*/
279 virtual void dump( UInt32 uiIndent
= 0,
280 const BitVector bvFlags
= 0) const;
283 /*---------------------------------------------------------------------*/
288 static UInt32
getFuncUniform1i (void);
289 static UInt32
getFuncUniform1iv (void);
290 static UInt32
getFuncUniform2iv (void);
291 static UInt32
getFuncUniform3iv (void);
292 static UInt32
getFuncUniform4iv (void);
294 static UInt32
getFuncUniform1f (void);
295 static UInt32
getFuncUniform1fv (void);
296 static UInt32
getFuncUniform2fv (void);
297 static UInt32
getFuncUniform3fv (void);
298 static UInt32
getFuncUniform4fv (void);
300 static UInt32
getFuncUniformMatrix4fv(void);
302 static UInt32
getFuncGetUniformiv (void);
303 static UInt32
getFuncGetUniformfv (void);
307 /*========================= PROTECTED ===============================*/
312 static ParamFunctor _fParameterCallback
;
315 /*---------------------------------------------------------------------*/
318 static volatile UInt16 _uiChunkCounter
;
323 // Variables should all be in SimpleSHLChunkBase.
325 typedef MFFragmentShaderType ::const_iterator FragmentShaderIt
;
326 typedef MFGeometryShaderType ::const_iterator GeometryShaderIt
;
327 typedef MFTessControlShaderType ::const_iterator TessControlShaderIt
;
328 typedef MFTessEvaluationShaderType::const_iterator TessEvalShaderIt
;
329 typedef MFVertexShaderType ::const_iterator VertexShaderIt
;
331 /*---------------------------------------------------------------------*/
332 /*! \name Constructors */
335 SimpleSHLChunk(void);
336 SimpleSHLChunk(const SimpleSHLChunk
&source
);
339 /*---------------------------------------------------------------------*/
340 /*! \name Destructors */
343 virtual ~SimpleSHLChunk(void);
346 /*---------------------------------------------------------------------*/
350 static void initMethod(InitPhase ePhase
);
353 /*---------------------------------------------------------------------*/
357 UInt32
handleGL (DrawEnv
*pEnv
,
359 Window::GLObjectStatusE mode
,
361 static void handleDestroyGL(DrawEnv
*pEnv
,
363 Window::GLObjectStatusE mode
);
366 /*---------------------------------------------------------------------*/
370 void onCreate (const SimpleSHLChunk
*source
= NULL
);
371 void onCreateAspect(const SimpleSHLChunk
*createAspect
,
372 const SimpleSHLChunk
*source
= NULL
);
373 void onDestroy( UInt32 uiId
);
376 /*---------------------------------------------------------------------*/
380 void updateVariableLocations (DrawEnv
*pEnv
,
382 void updateVariables (DrawEnv
*pEnv
,
384 void updateParameters (DrawEnv
*pEnv
,
386 void updateProceduralVariables(DrawEnv
*pEnv
,
387 UInt32 uiUpdateDependents
);
390 /*---------------------------------------------------------------------*/
394 bool readProgram( std::string
&szTarget
,
395 const Char8
*szFilename
);
397 bool readProgram( std::string
&szTarget
,
398 std::istream
&iStream
);
401 /*---------------------------------------------------------------------*/
406 /*========================== PRIVATE ================================*/
410 friend class FieldContainer
;
411 friend class SimpleSHLChunkBase
;
413 // prohibit default functions (move to 'public' if you need one)
414 void operator =(const SimpleSHLChunk
&source
);
417 typedef SimpleSHLChunk
*SimpleSHLChunkP
;
421 #include "OSGSimpleSHLChunkBase.inl"
422 #include "OSGSimpleSHLChunk.inl"
424 #endif /* _OSGSIMPLESHLCHUNK_H_ */