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 _OSGCOMPUTESHADERCHUNK_H_
40 #define _OSGCOMPUTESHADERCHUNK_H_
45 #include "OSGComputeShaderChunkBase.h"
46 #include "OSGShaderProgram.h"
47 #include "OSGShaderExecutableChunk.h"
53 /*! \brief ComputeShaderChunk class. See \ref
54 PageStateComputeShaderChunk for a description.
55 \ingroup GrpSystemShaderSHLChunk
56 \ingroup GrpLibOSGSystem
60 class OSG_CONTRIBCOMPUTEBASE_DLLMAPPING ComputeShaderChunk
:
61 public ComputeShaderChunkBase
65 /*========================== PUBLIC =================================*/
69 typedef ComputeShaderChunkBase Inherited
;
70 typedef ComputeShaderChunk Self
;
72 typedef ShaderVariableFunctor::GetUniformLocProc GetUniformLocProc
;
73 typedef ShaderVariableFunctor::ProcVarFunctor ProcVarFunctor
;
74 typedef ShaderVariableFunctor::ProcVarNodeFunctor ProcVarNodeFunctor
;
76 static const UInt32 KeepProgActive
= ShaderProgram::KeepProgActive
;
78 static const UInt32 ProgActive
= ShaderProgram::ProgActive
;
80 /*---------------------------------------------------------------------*/
81 /*! \name Chunk Class Access */
84 virtual const StateChunkClass
*getClass(void) const;
87 /*---------------------------------------------------------------------*/
88 /*! \name Static Chunk Class Access */
91 static UInt32
getStaticClassId(void);
92 static const StateChunkClass
*getStaticClass (void);
95 /*---------------------------------------------------------------------*/
99 virtual UInt16
getChunkId(void);
102 /*---------------------------------------------------------------------*/
106 virtual void changed(ConstFieldMaskArg whichField
,
111 /*---------------------------------------------------------------------*/
115 virtual void activate (DrawEnv
*pEnv
,
117 virtual void changeFrom(DrawEnv
*pEnv
,
120 virtual void deactivate(DrawEnv
*pEnv
,
123 /*---------------------------------------------------------------------*/
127 bool readComputeProgram (const Char8
*file
);
130 /*---------------------------------------------------------------------*/
131 /*! \name Program Parameter */
135 /*---------------------------------------------------------------------*/
140 virtual void update (DrawEnv
*pEnv
);
144 /*---------------------------------------------------------------------*/
148 template<class ValueT
>
149 bool addUniformVariable (const Char8
*name
, const ValueT
&value
);
151 template<class ValueT
>
152 bool updateUniformVariable (const Char8
*name
, const ValueT
&value
);
154 template<class ValueT
>
155 bool getUniformVariable (const Char8
*name
, ValueT
&value
);
157 bool subUniformVariable (const Char8
*name
);
158 void clearUniformVariables ( void );
160 bool addOSGVariable (const Char8
*name
);
163 /*---------------------------------------------------------------------*/
167 bool addProceduralVariable (const Char8
*name
,
168 ProcVarFunctor pFunc
,
169 UInt32 uiDependency
=
170 ShaderProcVariable::SHDObject
);
172 bool updateProceduralVariable (const Char8
*name
,
173 ProcVarFunctor pFunc
,
174 UInt32 uiDependency
=
175 ShaderProcVariable::SHDObject
);
177 bool addNodeProceduralVariable (const Char8
*name
,
178 ProcVarNodeFunctor pFunc
,
179 UInt32 uiDependency
=
180 ShaderProcVariable::SHDObject
);
182 bool updateNodeProceduralVariable(const Char8
*name
,
183 ProcVarNodeFunctor pFunc
,
184 UInt32 uiDependency
=
185 ShaderProcVariable::SHDObject
);
189 /*---------------------------------------------------------------------*/
194 /*---------------------------------------------------------------------*/
199 void updateParameters(
201 const UInt32
¶meters
,
202 bool useProgram
= true,
204 bool keepProgramActive
=false);
206 const UInt32
*getMFParameters(void) const;
210 /*---------------------------------------------------------------------*/
214 virtual void dump( UInt32 uiIndent
= 0,
215 const BitVector bvFlags
= 0) const;
218 /*---------------------------------------------------------------------*/
223 /*========================= PROTECTED ===============================*/
227 static UInt32 _arbComputeShader
;
229 /*---------------------------------------------------------------------*/
231 static volatile UInt16 _uiChunkCounter
;
235 // Variables should all be in ComputeShaderChunkBase.
237 typedef MFComputeShaderType::const_iterator ComputeShaderIt
;
239 /*---------------------------------------------------------------------*/
240 /*! \name Constructors */
243 ComputeShaderChunk(void);
244 ComputeShaderChunk(const ComputeShaderChunk
&source
);
247 /*---------------------------------------------------------------------*/
248 /*! \name Destructors */
251 virtual ~ComputeShaderChunk(void);
254 /*---------------------------------------------------------------------*/
258 static void initMethod(InitPhase ePhase
);
261 /*---------------------------------------------------------------------*/
265 UInt32
handleGL (DrawEnv
*pEnv
,
267 Window::GLObjectStatusE mode
,
269 static void handleDestroyGL(DrawEnv
*pEnv
,
271 Window::GLObjectStatusE mode
);
274 /*---------------------------------------------------------------------*/
278 void onCreate (const ComputeShaderChunk
*source
= NULL
);
279 void onCreateAspect(const ComputeShaderChunk
*createAspect
,
280 const ComputeShaderChunk
*source
= NULL
);
281 void onDestroy( UInt32 uiId
);
284 /*---------------------------------------------------------------------*/
288 void updateVariableLocations (DrawEnv
*pEnv
,
290 void updateVariables (DrawEnv
*pEnv
,
292 void updateProceduralVariables(DrawEnv
*pEnv
,
293 UInt32 uiUpdateDependents
);
296 /*---------------------------------------------------------------------*/
300 bool readProgram( std::string
&szTarget
,
301 const Char8
*szFilename
);
303 bool readProgram( std::string
&szTarget
,
304 std::istream
&iStream
);
307 /*---------------------------------------------------------------------*/
312 /*========================== PRIVATE ================================*/
316 // class. Used for indexing in State
317 static StateChunkClass _class
;
319 friend class FieldContainer
;
320 friend class ComputeShaderChunkBase
;
322 // prohibit default functions (move to 'public' if you need one)
323 void operator =(const ComputeShaderChunk
&source
);
326 typedef ComputeShaderChunk
*ComputeShaderChunkP
;
330 #include "OSGComputeShaderChunkBase.inl"
331 #include "OSGComputeShaderChunk.inl"
333 #endif /* _OSGCOMPUTESHADERCHUNK_H_ */