fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / System / State / Shader / Base / OSGShaderProgram.inl
blob92f2cfd57dd84e55b9f93a2db4e7455c1304231b
1 /*---------------------------------------------------------------------------*\
2  *                                OpenSG                                     *
3  *                                                                           *
4  *                                                                           *
5  *               Copyright (C) 2000-2006 by the OpenSG Forum                 *
6  *                                                                           *
7  *   contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de          *
8  *                                                                           *
9 \*---------------------------------------------------------------------------*/
10 /*---------------------------------------------------------------------------*\
11  *                                License                                    *
12  *                                                                           *
13  * This library is free software; you can redistribute it and/or modify it   *
14  * under the terms of the GNU Library General Public License as published    *
15  * by the Free Software Foundation, version 2.                               *
16  *                                                                           *
17  * This library is distributed in the hope that it will be useful, but       *
18  * WITHOUT ANY WARRANTY; without even the implied warranty of                *
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         *
20  * Library General Public License for more details.                          *
21  *                                                                           *
22  * You should have received a copy of the GNU Library General Public         *
23  * License along with this library; if not, write to the Free Software       *
24  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                 *
25  *                                                                           *
26 \*---------------------------------------------------------------------------*/
27 /*---------------------------------------------------------------------------*\
28  *                                Changes                                    *
29  *                                                                           *
30  *                                                                           *
31  *                                                                           *
32  *                                                                           *
33  *                                                                           *
34  *                                                                           *
35 \*---------------------------------------------------------------------------*/
37 //---------------------------------------------------------------------------
38 //  Includes
39 //---------------------------------------------------------------------------
41 OSG_BEGIN_NAMESPACE
43 inline
44 void ShaderProgram::validate(DrawEnv *pEnv)
46     pEnv->getWindow()->validateGLObject(getGLId(), pEnv);
49 inline
50 bool ShaderProgram::hasParameter(void)
52     return _mfParameter.size() != 0;
55 inline
56 bool ShaderProgram::hasAttributes(void)
58     return _mfAttributes.size() != 0;
61 template<class ValueT> inline
62 bool ShaderProgram::addUniformVariable(const Char8 *name, const ValueT &value)
64     if(_sfVariables.getValue() == NULL)
65     {
66         ShaderProgramVariablesUnrecPtr pParam = 
67             ShaderProgramVariables::createDependent(
68                 this->getFieldFlags()->_bNamespaceMask);
70         setVariables(pParam);
71     }
73 #if 0
74     return _sfVariables.getValue()->addUniformVariable(
75         name, 
76         value,
77         editMFVariableLocations          (),
78         editMFProceduralVariableLocations());
79 #else
80     return _sfVariables.getValue()->addUniformVariable(
81         name, 
82         value,
83         NULL,
84         NULL);
85 #endif
88 template<class ValueT> inline
89 bool ShaderProgram::updateUniformVariable(const Char8  *name, 
90                                           const ValueT &value)
92     if(_sfVariables.getValue() == NULL)
93     {
94         ShaderProgramVariablesUnrecPtr pParam = 
95             ShaderProgramVariables::createDependent(
96                 this->getFieldFlags()->_bNamespaceMask);
98         setVariables(pParam);
99     }
101     return _sfVariables.getValue()->updateUniformVariable(name, value);
104 template<class ValueT> inline
105 bool ShaderProgram::getUniformVariable(const Char8  *name,
106                                              ValueT &value)
108     if(_sfVariables.getValue() != NULL)
109     {
110         return _sfVariables.getValue()->getUniformVariable(name, value);
111     }
113     return false;
116 inline
117 bool ShaderProgram::addUniformBlock(const Char8 *name, UInt32 value)
119     if(_sfVariables.getValue() == NULL)
120     {
121         ShaderProgramVariablesUnrecPtr pParam = 
122             ShaderProgramVariables::createDependent(
123                 this->getFieldFlags()->_bNamespaceMask);
125         setVariables(pParam);
126     }
128 #if 0
129     return _sfVariables.getValue()->addUniformBlock(
130         name, 
131         value,
132         editMFVariableLocations          (),
133         editMFProceduralVariableLocations());
134 #else
135     return _sfVariables.getValue()->addUniformBlock(
136         name, 
137         value,
138         NULL,
139         NULL);
140 #endif
143 inline
144 bool ShaderProgram::updateUniformBlock(const Char8  *name, UInt32 value)
146     if(_sfVariables.getValue() == NULL)
147     {
148         ShaderProgramVariablesUnrecPtr pParam = 
149             ShaderProgramVariables::createDependent(
150                 this->getFieldFlags()->_bNamespaceMask);
152         setVariables(pParam);
153     }
155     return _sfVariables.getValue()->updateUniformBlock(name, value);
158 inline
159 bool ShaderProgram::getUniformBlock(const Char8  *name, UInt32 &value)
161     if(_sfVariables.getValue() != NULL)
162     {
163         return _sfVariables.getValue()->getUniformBlock(name, value);
164     }
166     return false;
169 inline
170 bool ShaderProgram::addShaderStorageBlock(const Char8 *name, UInt32 value)
172     if(_sfVariables.getValue() == NULL)
173     {
174         ShaderProgramVariablesUnrecPtr pParam = 
175             ShaderProgramVariables::createDependent(
176                 this->getFieldFlags()->_bNamespaceMask);
178         setVariables(pParam);
179     }
181 #if 0
182     return _sfVariables.getValue()->addShaderStorageBlock(
183         name, 
184         value,
185         editMFVariableLocations          (),
186         editMFProceduralVariableLocations());
187 #else
188     return _sfVariables.getValue()->addShaderStorageBlock(
189         name, 
190         value,
191         NULL,
192         NULL);
193 #endif
196 inline
197 bool ShaderProgram::updateShaderStorageBlock(const Char8  *name, UInt32 value)
199     if(_sfVariables.getValue() == NULL)
200     {
201         ShaderProgramVariablesUnrecPtr pParam = 
202             ShaderProgramVariables::createDependent(
203                 this->getFieldFlags()->_bNamespaceMask);
205         setVariables(pParam);
206     }
208     return _sfVariables.getValue()->updateShaderStorageBlock(name, value);
211 inline
212 bool ShaderProgram::getShaderStorageBlock(const Char8  *name, UInt32 &value)
214     if(_sfVariables.getValue() != NULL)
215     {
216         return _sfVariables.getValue()->getShaderStorageBlock(name, value);
217     }
219     return false;
222 inline
223 void ShaderProgram::addDestroyedFunctor(ChangedFunctor func,
224                                         std::string    createSymbol)
226     ChangedFunctorCallback oTmp;
228     oTmp._func         = func;
229     oTmp._createSymbol = createSymbol;
231     _mfDestroyedFunctors.push_back(oTmp);
234 template<class FunctorT> inline
235 void ShaderProgram::subDestroyedFunctor(FunctorT func)
237     MFChangedFunctorCallback::iterator       cfIt = 
238         _mfDestroyedFunctors.begin();
240     MFChangedFunctorCallback::const_iterator cfEnd= 
241         _mfDestroyedFunctors.end();
243     for(; cfIt != cfEnd; ++cfIt)
244     {
245         if(cfIt->_func == func)
246             break;
247     }
249     if(cfIt != cfEnd)
250         _mfDestroyedFunctors.erase(cfIt);
253 template<class FunctorT> inline
254 bool ShaderProgram::hasDestroyedFunctor(FunctorT func)
256     bool returnValue = false;
258     MFChangedFunctorCallback::iterator       cfIt = 
259         _mfDestroyedFunctors.begin();
261     MFChangedFunctorCallback::const_iterator cfEnd= 
262         _mfDestroyedFunctors.end();
265     for(; cfIt != cfEnd; ++cfIt)
266     {
267         if(cfIt->_func == func)
268         {
269             returnValue = true;
270             break;
271         }
272     }
273     
274     return returnValue;
277 inline
278 UInt32 ShaderProgram::getNumDestroyedFunctors(void) const
280     return _mfDestroyedFunctors.size32();
283 inline 
284 void ShaderProgram::clearDestroyedFunctors(void)
286     _mfDestroyedFunctors.clear();
289 inline
290 UInt32 ShaderProgram::getExtIdSHL(void)
292     return _extSHL;
295 inline
296 UInt32 ShaderProgram::getExtIdCgShader(void)
298     return _extCG;
301 inline
302 UInt32 ShaderProgram::getExtIdGeometryShader4(void)
304     return _extGeoShader4;
307 inline
308 UInt32 ShaderProgram::getExtIdGPUShader4(void)
310     return _extGPUShader4;
313 inline
314 UInt32 ShaderProgram::getExtIdTransformFeedback2(void)
316     return _extTransformFeedback2;
319 inline
320 UInt32 ShaderProgram::getExtIdUniformBufferObject(void)
322     return _extUniformBufferObject;
325 inline
326 UInt32 ShaderProgram::getExtIdProgramInterfaceQuery(void)
328     return _extProgramInterfaceQuery;
331 inline
332 UInt32 ShaderProgram::getExtIdShaderStorageBufferObject(void)
334     return _extShaderStorageBufferObject;
337 inline
338 UInt32 ShaderProgram::getFuncIdCreateShader(void)
340     return FuncIdCreateShader;
343 inline
344 UInt32 ShaderProgram::getFuncIdDeleteShader(void)
346     return FuncIdDeleteShader;
349 inline
350 UInt32 ShaderProgram::getFuncIdShaderSource(void)
352     return FuncIdShaderSource;
355 inline
356 UInt32 ShaderProgram::getFuncIdCompileShader(void)
358     return FuncIdCompileShader;
361 inline
362 UInt32 ShaderProgram::getFuncIdAttachShader(void)
364     return FuncIdAttachShader;
367 inline
368 UInt32 ShaderProgram::getFuncIdGetShaderiv(void)
370     return FuncIdGetShaderiv;
373 inline
374 UInt32 ShaderProgram::getFuncIdGetShaderInfoLog(void)
376     return FuncIdGetShaderInfoLog;
379 inline
380 UInt32 ShaderProgram::getFuncIdGetActiveAttrib(void)
382     return FuncIdGetActiveAttrib;
385 inline
386 UInt32 ShaderProgram::getFuncIdCreateProgram(void)
388     return FuncIdCreateProgram;
391 inline
392 UInt32 ShaderProgram::getFuncIdDeleteProgram(void)
394     return FuncIdDeleteProgram;
397 inline
398 UInt32 ShaderProgram::getFuncIdLinkProgram(void)
400     return FuncIdLinkProgram;
403 inline
404 UInt32 ShaderProgram::getFuncIdGetProgramiv(void)
406     return FuncIdGetProgramiv;
409 inline
410 UInt32 ShaderProgram::getFuncIdGetProgramInfoLog(void)
412     return FuncIdGetProgramInfoLog;
415 inline
416 UInt32 ShaderProgram::getFuncIdUseProgram(void)
418     return FuncIdUseProgram;
422 inline
423 UInt32 ShaderProgram::getFuncIdGetUniformLocation(void)
425     return FuncIdGetUniformLocation;
428 inline
429 UInt32 ShaderProgram::getFuncIdUniform1i(void)
431     return FuncIdUniform1i;
434 inline
435 UInt32 ShaderProgram::getFuncIdUniform2i(void)
437     return FuncIdUniform2i;
440 inline
441 UInt32 ShaderProgram::getFuncIdUniform3i(void)
443     return FuncIdUniform3i;
446 inline
447 UInt32 ShaderProgram::getFuncIdUniform4i(void)
449     return FuncIdUniform4i;
453 inline
454 UInt32 ShaderProgram::getFuncIdUniform1ui(void)
456     return FuncIdUniform1ui;
459 inline
460 UInt32 ShaderProgram::getFuncIdUniform2ui(void)
462     return FuncIdUniform2ui;
465 inline
466 UInt32 ShaderProgram::getFuncIdUniform3ui(void)
468     return FuncIdUniform3ui;
471 inline
472 UInt32 ShaderProgram::getFuncIdUniform4ui(void)
474     return FuncIdUniform4ui;
478 inline
479 UInt32 ShaderProgram::getFuncIdUniform1f(void)
481     return FuncIdUniform1f;
484 inline
485 UInt32 ShaderProgram::getFuncIdUniform2f(void)
487     return FuncIdUniform2f;
490 inline
491 UInt32 ShaderProgram::getFuncIdUniform3f(void)
493     return FuncIdUniform3f;
496 inline
497 UInt32 ShaderProgram::getFuncIdUniform4f(void)
499     return FuncIdUniform4f;
503 inline
504 UInt32 ShaderProgram::getFuncIdUniform1iv(void)
506     return FuncIdUniform1iv;
509 inline
510 UInt32 ShaderProgram::getFuncIdUniform2iv(void)
512     return FuncIdUniform2iv;
515 inline
516 UInt32 ShaderProgram::getFuncIdUniform3iv(void)
518     return FuncIdUniform3iv;
521 inline
522 UInt32 ShaderProgram::getFuncIdUniform4iv(void)
524     return FuncIdUniform4iv;
528 inline
529 UInt32 ShaderProgram::getFuncIdUniform1uiv(void)
531     return FuncIdUniform1uiv;
534 inline
535 UInt32 ShaderProgram::getFuncIdUniform2uiv(void)
537     return FuncIdUniform2uiv;
540 inline
541 UInt32 ShaderProgram::getFuncIdUniform3uiv(void)
543     return FuncIdUniform3uiv;
546 inline
547 UInt32 ShaderProgram::getFuncIdUniform4uiv(void)
549     return FuncIdUniform4uiv;
553 inline
554 UInt32 ShaderProgram::getFuncIdUniform1fv(void)
556     return FuncIdUniform1fv;
559 inline
560 UInt32 ShaderProgram::getFuncIdUniform2fv(void)
562     return FuncIdUniform2fv;
565 inline
566 UInt32 ShaderProgram::getFuncIdUniform3fv(void)
568     return FuncIdUniform3fv;
571 inline
572 UInt32 ShaderProgram::getFuncIdUniform4fv(void)
574     return FuncIdUniform4fv;
577 inline
578 UInt32 ShaderProgram::getFuncIdUniformMatrix2fv(void)
580     return FuncIdUniformMatrix2fv;
583 inline
584 UInt32 ShaderProgram::getFuncIdUniformMatrix3fv(void)
586     return FuncIdUniformMatrix3fv;
589 inline
590 UInt32 ShaderProgram::getFuncIdUniformMatrix4fv(void)
592     return FuncIdUniformMatrix4fv;
595 inline
596 UInt32 ShaderProgram::getFuncIdGetUniformiv(void)
598     return FuncIdGetUniformiv;
601 inline
602 UInt32 ShaderProgram::getFuncIdGetUniformfv(void)
604     return FuncIdGetUniformfv;
607 inline
608 UInt32 ShaderProgram::getFuncIdProgramParameteri(void)
610     return FuncIdProgramParameteri;
613 inline
614 UInt32 ShaderProgram::getFuncIdBindAttribLocation(void)
616     return FuncIdBindAttribLocation;
619 inline 
620 UInt32 ShaderProgram::getFuncIdBindBufferBase(void)
622     return FuncIdBindBufferBase;
625 inline
626 UInt32 ShaderProgram::getFuncIdTransformFeedbackVaryings(void)
628     return FuncIdTransformFeedbackVaryings;
631 inline
632 UInt32 ShaderProgram::getFuncIdBeginTransformFeedback(void)
634     return FuncIdBeginTransformFeedback;
637 inline
638 UInt32 ShaderProgram::getFuncIdEndTransformFeedback(void)
640     return FuncIdEndTransformFeedback;
643 inline
644 UInt32 ShaderProgram::getFuncIdPauseTransformFeedback(void)
646     return FuncIdPauseTransformFeedback;
649 inline
650 UInt32 ShaderProgram::getFuncIdResumeTransformFeedback(void)
652     return FuncIdResumeTransformFeedback;
655 inline
656 UInt32 ShaderProgram::getFuncIdGetUniformBlockIndex(void)
658     return FuncIdGetUniformBlockIndex;
661 inline
662 UInt32 ShaderProgram::getFuncIdUniformBlockBinding(void)
664     return FuncIdUniformBlockBinding;
667 inline
668 UInt16 ShaderProgram::getProgramId(void)
670     return _uiProgId;
673 inline
674 UInt32 ShaderProgram::getFuncIdGetProgramResourceIndex(void)
676     return FuncIdGetProgramResourceIndex;
679 inline
680 UInt32 ShaderProgram::getFuncIdGetProgramResourceiv(void)
682     return FuncIdGetProgramResourceiv;
685 inline
686 UInt32 ShaderProgram::getFuncIdShaderStorageBlockBinding(void)
688     return FuncIdShaderStorageBlockBinding;
691 OSG_END_NAMESPACE