changed: gcc8 base update
[opensg.git] / Source / System / State / Shader / SHL / OSGSimpleSHLChunk.h
blob78c158cafd2edd6805ba7fd5b1fee78b1c3ee53c
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 _OSGSIMPLESHLCHUNK_H_
40 #define _OSGSIMPLESHLCHUNK_H_
41 #ifdef __sgi
42 #pragma once
43 #endif
45 #include "OSGSimpleSHLChunkBase.h"
46 #include "OSGShaderProgram.h"
47 #include "OSGShaderExecutableChunk.h"
49 OSG_BEGIN_NAMESPACE
51 class Window;
53 /*! \brief SimpleSHLChunk class. See \ref
54 PageStateSimpleSHLChunk for a description.
55 \ingroup GrpSystemShaderSHLChunk
56 \ingroup GrpLibOSGSystem
57 \includebasedoc
60 class OSG_SYSTEM_DLLMAPPING SimpleSHLChunk : public SimpleSHLChunkBase
62 protected:
64 /*========================== PUBLIC =================================*/
66 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;
79 #ifdef OSG_1_COMPAT
80 typedef ShaderVariableFunctor::ParamFunctor ParamFunctor;
81 typedef ShaderVariableFunctor::OSGParamFunctor OSGParamFunctor;
83 static const OSG::BitVector ParametersFieldMask = VariablesFieldMask;
84 #endif
86 /*---------------------------------------------------------------------*/
87 /*! \name Chunk Class Access */
88 /*! \{ */
90 virtual const StateChunkClass *getClass(void) const;
92 /*! \} */
93 /*---------------------------------------------------------------------*/
94 /*! \name Static Chunk Class Access */
95 /*! \{ */
97 static UInt32 getStaticClassId(void);
98 static const StateChunkClass *getStaticClass (void);
100 /*! \} */
101 /*---------------------------------------------------------------------*/
102 /*! \name Chunk Id */
103 /*! \{ */
105 virtual UInt16 getChunkId(void);
107 /*! \} */
108 /*---------------------------------------------------------------------*/
109 /*! \name Sync */
110 /*! \{ */
112 virtual void changed(ConstFieldMaskArg whichField,
113 UInt32 origin,
114 BitVector details );
116 /*! \} */
117 /*---------------------------------------------------------------------*/
118 /*! \name Output */
119 /*! \{ */
121 virtual void activate (DrawEnv *pEnv,
122 UInt32 uiIdx = 0);
124 virtual void changeFrom (DrawEnv *pEnv,
125 StateChunk *pOld,
126 UInt32 uiIdx = 0);
128 virtual void deactivate (DrawEnv *pEnv,
129 UInt32 uiIdx = 0);
131 virtual void updateObjectDependencies(DrawEnv *pEnv,
132 UInt32 index = 0);
134 /*! \} */
135 /*---------------------------------------------------------------------*/
136 /*! \name Output */
137 /*! \{ */
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);
145 /*! \} */
146 /*---------------------------------------------------------------------*/
147 /*! \name Program Parameter */
148 /*! \{ */
150 #ifdef OSG_1_COMPAT
151 void addProgramParameter (GLenum name, UInt32 value);
152 void subProgramParameter (GLenum name );
153 #endif
155 void setProgramParameter (GLenum name, UInt32 value);
157 UInt32 getProgramParameter (GLenum name );
159 void clearProgramParameters(void );
161 /*! \} */
162 /*---------------------------------------------------------------------*/
163 /*! \name Init */
164 /*! \{ */
166 #if 0
167 virtual void update (DrawEnv *pEnv );
168 #endif
170 /*! \} */
171 /*---------------------------------------------------------------------*/
172 /*! \name Output */
173 /*! \{ */
175 #ifdef OSG_1_COMPAT
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 );
184 #endif
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 );
202 /*! \} */
203 /*---------------------------------------------------------------------*/
204 /*! \name Output */
205 /*! \{ */
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);
211 /*! \} */
212 /*---------------------------------------------------------------------*/
213 /*! \name Output */
214 /*! \{ */
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);
220 /*! \} */
221 /*---------------------------------------------------------------------*/
222 /*! \name Output */
223 /*! \{ */
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);
246 /*! \} */
247 /*---------------------------------------------------------------------*/
248 /*! \name Output */
249 /*! \{ */
251 #ifdef OSG_1_COMPAT
252 void addParameterCallback(const Char8 *name, ParamFunctor fp);
253 void addParameterCallback(const Char8 *name, OSGParamFunctor fp);
255 static void setParameterCallback( ParamFunctor fp);
256 #endif
258 /*! \} */
259 /*---------------------------------------------------------------------*/
260 /*! \name Output */
261 /*! \{ */
263 #if 1
264 void updateParameters(
265 Window *win,
266 const UInt32 &parameters,
267 bool useProgram = true,
268 bool force = false,
269 bool keepProgramActive=false);
271 const UInt32 *getMFParameters(void) const;
272 #endif
274 /*! \} */
275 /*---------------------------------------------------------------------*/
276 /*! \name Output */
277 /*! \{ */
279 virtual void dump( UInt32 uiIndent = 0,
280 const BitVector bvFlags = 0) const;
282 /*! \} */
283 /*---------------------------------------------------------------------*/
284 /*! \name Output */
285 /*! \{ */
287 #ifdef OSG_1_COMPAT
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);
304 #endif
306 /*! \} */
307 /*========================= PROTECTED ===============================*/
309 protected:
311 #ifdef OSG_1_COMPAT
312 static ParamFunctor _fParameterCallback;
313 #endif
315 /*---------------------------------------------------------------------*/
317 #if 0
318 static volatile UInt16 _uiChunkCounter;
319 #endif
321 UInt16 _uiChunkId;
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 */
333 /*! \{ */
335 SimpleSHLChunk(void);
336 SimpleSHLChunk(const SimpleSHLChunk &source);
338 /*! \} */
339 /*---------------------------------------------------------------------*/
340 /*! \name Destructors */
341 /*! \{ */
343 virtual ~SimpleSHLChunk(void);
345 /*! \} */
346 /*---------------------------------------------------------------------*/
347 /*! \name Init */
348 /*! \{ */
350 static void initMethod(InitPhase ePhase);
352 /*! \} */
353 /*---------------------------------------------------------------------*/
354 /*! \name Init */
355 /*! \{ */
357 UInt32 handleGL (DrawEnv *pEnv,
358 UInt32 id,
359 Window::GLObjectStatusE mode,
360 UInt64 uiOptions);
361 static void handleDestroyGL(DrawEnv *pEnv,
362 UInt32 id,
363 Window::GLObjectStatusE mode );
365 /*! \} */
366 /*---------------------------------------------------------------------*/
367 /*! \name Init */
368 /*! \{ */
370 void onCreate (const SimpleSHLChunk *source = NULL);
371 void onCreateAspect(const SimpleSHLChunk *createAspect,
372 const SimpleSHLChunk *source = NULL);
373 void onDestroy( UInt32 uiId );
375 /*! \} */
376 /*---------------------------------------------------------------------*/
377 /*! \name Init */
378 /*! \{ */
380 void updateVariableLocations (DrawEnv *pEnv,
381 UInt32 uiProgram);
382 void updateVariables (DrawEnv *pEnv,
383 UInt32 uiProgram);
384 void updateParameters (DrawEnv *pEnv,
385 UInt32 uiProgram);
386 void updateProceduralVariables(DrawEnv *pEnv,
387 UInt32 uiUpdateDependents);
389 /*! \} */
390 /*---------------------------------------------------------------------*/
391 /*! \name Init */
392 /*! \{ */
394 bool readProgram( std::string &szTarget,
395 const Char8 *szFilename);
397 bool readProgram( std::string &szTarget,
398 std::istream &iStream);
400 /*! \} */
401 /*---------------------------------------------------------------------*/
402 /*! \name Init */
403 /*! \{ */
405 /*! \} */
406 /*========================== PRIVATE ================================*/
408 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;
419 OSG_END_NAMESPACE
421 #include "OSGSimpleSHLChunkBase.inl"
422 #include "OSGSimpleSHLChunk.inl"
424 #endif /* _OSGSIMPLESHLCHUNK_H_ */