1 /*---------------------------------------------------------------------------*\
5 * Copyright (C) 2000-2006 by the OpenSG Forum *
7 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
9 \*---------------------------------------------------------------------------*/
10 /*---------------------------------------------------------------------------*\
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. *
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. *
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. *
26 \*---------------------------------------------------------------------------*/
27 /*---------------------------------------------------------------------------*\
35 \*---------------------------------------------------------------------------*/
37 //---------------------------------------------------------------------------
39 //---------------------------------------------------------------------------
44 void ShaderProgram::validate(DrawEnv *pEnv)
46 pEnv->getWindow()->validateGLObject(getGLId(), pEnv);
50 bool ShaderProgram::hasParameter(void)
52 return _mfParameter.size() != 0;
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)
66 ShaderProgramVariablesUnrecPtr pParam =
67 ShaderProgramVariables::createDependent(
68 this->getFieldFlags()->_bNamespaceMask);
74 return _sfVariables.getValue()->addUniformVariable(
77 editMFVariableLocations (),
78 editMFProceduralVariableLocations());
80 return _sfVariables.getValue()->addUniformVariable(
88 template<class ValueT> inline
89 bool ShaderProgram::updateUniformVariable(const Char8 *name,
92 if(_sfVariables.getValue() == NULL)
94 ShaderProgramVariablesUnrecPtr pParam =
95 ShaderProgramVariables::createDependent(
96 this->getFieldFlags()->_bNamespaceMask);
101 return _sfVariables.getValue()->updateUniformVariable(name, value);
104 template<class ValueT> inline
105 bool ShaderProgram::getUniformVariable(const Char8 *name,
108 if(_sfVariables.getValue() != NULL)
110 return _sfVariables.getValue()->getUniformVariable(name, value);
117 bool ShaderProgram::addUniformBlock(const Char8 *name, UInt32 value)
119 if(_sfVariables.getValue() == NULL)
121 ShaderProgramVariablesUnrecPtr pParam =
122 ShaderProgramVariables::createDependent(
123 this->getFieldFlags()->_bNamespaceMask);
125 setVariables(pParam);
129 return _sfVariables.getValue()->addUniformBlock(
132 editMFVariableLocations (),
133 editMFProceduralVariableLocations());
135 return _sfVariables.getValue()->addUniformBlock(
144 bool ShaderProgram::updateUniformBlock(const Char8 *name, UInt32 value)
146 if(_sfVariables.getValue() == NULL)
148 ShaderProgramVariablesUnrecPtr pParam =
149 ShaderProgramVariables::createDependent(
150 this->getFieldFlags()->_bNamespaceMask);
152 setVariables(pParam);
155 return _sfVariables.getValue()->updateUniformBlock(name, value);
159 bool ShaderProgram::getUniformBlock(const Char8 *name, UInt32 &value)
161 if(_sfVariables.getValue() != NULL)
163 return _sfVariables.getValue()->getUniformBlock(name, value);
170 bool ShaderProgram::addShaderStorageBlock(const Char8 *name, UInt32 value)
172 if(_sfVariables.getValue() == NULL)
174 ShaderProgramVariablesUnrecPtr pParam =
175 ShaderProgramVariables::createDependent(
176 this->getFieldFlags()->_bNamespaceMask);
178 setVariables(pParam);
182 return _sfVariables.getValue()->addShaderStorageBlock(
185 editMFVariableLocations (),
186 editMFProceduralVariableLocations());
188 return _sfVariables.getValue()->addShaderStorageBlock(
197 bool ShaderProgram::updateShaderStorageBlock(const Char8 *name, UInt32 value)
199 if(_sfVariables.getValue() == NULL)
201 ShaderProgramVariablesUnrecPtr pParam =
202 ShaderProgramVariables::createDependent(
203 this->getFieldFlags()->_bNamespaceMask);
205 setVariables(pParam);
208 return _sfVariables.getValue()->updateShaderStorageBlock(name, value);
212 bool ShaderProgram::getShaderStorageBlock(const Char8 *name, UInt32 &value)
214 if(_sfVariables.getValue() != NULL)
216 return _sfVariables.getValue()->getShaderStorageBlock(name, value);
223 void ShaderProgram::addDestroyedFunctor(ChangedFunctor func,
224 std::string createSymbol)
226 ChangedFunctorCallback oTmp;
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)
245 if(cfIt->_func == func)
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)
267 if(cfIt->_func == func)
278 UInt32 ShaderProgram::getNumDestroyedFunctors(void) const
280 return _mfDestroyedFunctors.size32();
284 void ShaderProgram::clearDestroyedFunctors(void)
286 _mfDestroyedFunctors.clear();
290 UInt32 ShaderProgram::getExtIdSHL(void)
296 UInt32 ShaderProgram::getExtIdCgShader(void)
302 UInt32 ShaderProgram::getExtIdGeometryShader4(void)
304 return _extGeoShader4;
308 UInt32 ShaderProgram::getExtIdGPUShader4(void)
310 return _extGPUShader4;
314 UInt32 ShaderProgram::getExtIdTransformFeedback2(void)
316 return _extTransformFeedback2;
320 UInt32 ShaderProgram::getExtIdUniformBufferObject(void)
322 return _extUniformBufferObject;
326 UInt32 ShaderProgram::getExtIdProgramInterfaceQuery(void)
328 return _extProgramInterfaceQuery;
332 UInt32 ShaderProgram::getExtIdShaderStorageBufferObject(void)
334 return _extShaderStorageBufferObject;
338 UInt32 ShaderProgram::getFuncIdCreateShader(void)
340 return FuncIdCreateShader;
344 UInt32 ShaderProgram::getFuncIdDeleteShader(void)
346 return FuncIdDeleteShader;
350 UInt32 ShaderProgram::getFuncIdShaderSource(void)
352 return FuncIdShaderSource;
356 UInt32 ShaderProgram::getFuncIdCompileShader(void)
358 return FuncIdCompileShader;
362 UInt32 ShaderProgram::getFuncIdAttachShader(void)
364 return FuncIdAttachShader;
368 UInt32 ShaderProgram::getFuncIdGetShaderiv(void)
370 return FuncIdGetShaderiv;
374 UInt32 ShaderProgram::getFuncIdGetShaderInfoLog(void)
376 return FuncIdGetShaderInfoLog;
380 UInt32 ShaderProgram::getFuncIdGetActiveAttrib(void)
382 return FuncIdGetActiveAttrib;
386 UInt32 ShaderProgram::getFuncIdCreateProgram(void)
388 return FuncIdCreateProgram;
392 UInt32 ShaderProgram::getFuncIdDeleteProgram(void)
394 return FuncIdDeleteProgram;
398 UInt32 ShaderProgram::getFuncIdLinkProgram(void)
400 return FuncIdLinkProgram;
404 UInt32 ShaderProgram::getFuncIdGetProgramiv(void)
406 return FuncIdGetProgramiv;
410 UInt32 ShaderProgram::getFuncIdGetProgramInfoLog(void)
412 return FuncIdGetProgramInfoLog;
416 UInt32 ShaderProgram::getFuncIdUseProgram(void)
418 return FuncIdUseProgram;
423 UInt32 ShaderProgram::getFuncIdGetUniformLocation(void)
425 return FuncIdGetUniformLocation;
429 UInt32 ShaderProgram::getFuncIdUniform1i(void)
431 return FuncIdUniform1i;
435 UInt32 ShaderProgram::getFuncIdUniform2i(void)
437 return FuncIdUniform2i;
441 UInt32 ShaderProgram::getFuncIdUniform3i(void)
443 return FuncIdUniform3i;
447 UInt32 ShaderProgram::getFuncIdUniform4i(void)
449 return FuncIdUniform4i;
454 UInt32 ShaderProgram::getFuncIdUniform1ui(void)
456 return FuncIdUniform1ui;
460 UInt32 ShaderProgram::getFuncIdUniform2ui(void)
462 return FuncIdUniform2ui;
466 UInt32 ShaderProgram::getFuncIdUniform3ui(void)
468 return FuncIdUniform3ui;
472 UInt32 ShaderProgram::getFuncIdUniform4ui(void)
474 return FuncIdUniform4ui;
479 UInt32 ShaderProgram::getFuncIdUniform1f(void)
481 return FuncIdUniform1f;
485 UInt32 ShaderProgram::getFuncIdUniform2f(void)
487 return FuncIdUniform2f;
491 UInt32 ShaderProgram::getFuncIdUniform3f(void)
493 return FuncIdUniform3f;
497 UInt32 ShaderProgram::getFuncIdUniform4f(void)
499 return FuncIdUniform4f;
504 UInt32 ShaderProgram::getFuncIdUniform1iv(void)
506 return FuncIdUniform1iv;
510 UInt32 ShaderProgram::getFuncIdUniform2iv(void)
512 return FuncIdUniform2iv;
516 UInt32 ShaderProgram::getFuncIdUniform3iv(void)
518 return FuncIdUniform3iv;
522 UInt32 ShaderProgram::getFuncIdUniform4iv(void)
524 return FuncIdUniform4iv;
529 UInt32 ShaderProgram::getFuncIdUniform1uiv(void)
531 return FuncIdUniform1uiv;
535 UInt32 ShaderProgram::getFuncIdUniform2uiv(void)
537 return FuncIdUniform2uiv;
541 UInt32 ShaderProgram::getFuncIdUniform3uiv(void)
543 return FuncIdUniform3uiv;
547 UInt32 ShaderProgram::getFuncIdUniform4uiv(void)
549 return FuncIdUniform4uiv;
554 UInt32 ShaderProgram::getFuncIdUniform1fv(void)
556 return FuncIdUniform1fv;
560 UInt32 ShaderProgram::getFuncIdUniform2fv(void)
562 return FuncIdUniform2fv;
566 UInt32 ShaderProgram::getFuncIdUniform3fv(void)
568 return FuncIdUniform3fv;
572 UInt32 ShaderProgram::getFuncIdUniform4fv(void)
574 return FuncIdUniform4fv;
578 UInt32 ShaderProgram::getFuncIdUniformMatrix2fv(void)
580 return FuncIdUniformMatrix2fv;
584 UInt32 ShaderProgram::getFuncIdUniformMatrix3fv(void)
586 return FuncIdUniformMatrix3fv;
590 UInt32 ShaderProgram::getFuncIdUniformMatrix4fv(void)
592 return FuncIdUniformMatrix4fv;
596 UInt32 ShaderProgram::getFuncIdGetUniformiv(void)
598 return FuncIdGetUniformiv;
602 UInt32 ShaderProgram::getFuncIdGetUniformfv(void)
604 return FuncIdGetUniformfv;
608 UInt32 ShaderProgram::getFuncIdProgramParameteri(void)
610 return FuncIdProgramParameteri;
614 UInt32 ShaderProgram::getFuncIdBindAttribLocation(void)
616 return FuncIdBindAttribLocation;
620 UInt32 ShaderProgram::getFuncIdBindBufferBase(void)
622 return FuncIdBindBufferBase;
626 UInt32 ShaderProgram::getFuncIdTransformFeedbackVaryings(void)
628 return FuncIdTransformFeedbackVaryings;
632 UInt32 ShaderProgram::getFuncIdBeginTransformFeedback(void)
634 return FuncIdBeginTransformFeedback;
638 UInt32 ShaderProgram::getFuncIdEndTransformFeedback(void)
640 return FuncIdEndTransformFeedback;
644 UInt32 ShaderProgram::getFuncIdPauseTransformFeedback(void)
646 return FuncIdPauseTransformFeedback;
650 UInt32 ShaderProgram::getFuncIdResumeTransformFeedback(void)
652 return FuncIdResumeTransformFeedback;
656 UInt32 ShaderProgram::getFuncIdGetUniformBlockIndex(void)
658 return FuncIdGetUniformBlockIndex;
662 UInt32 ShaderProgram::getFuncIdUniformBlockBinding(void)
664 return FuncIdUniformBlockBinding;
668 UInt16 ShaderProgram::getProgramId(void)
674 UInt32 ShaderProgram::getFuncIdGetProgramResourceIndex(void)
676 return FuncIdGetProgramResourceIndex;
680 UInt32 ShaderProgram::getFuncIdGetProgramResourceiv(void)
682 return FuncIdGetProgramResourceiv;
686 UInt32 ShaderProgram::getFuncIdShaderStorageBlockBinding(void)
688 return FuncIdShaderStorageBlockBinding;