1 /*---------------------------------------------------------------------------*\
5 * Copyright (C) 2000-2002 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 //---------------------------------------------------------------------------
41 //---------------------------------------------------------------------------
46 void osgUniformShaderVariableLocation(DrawEnv *pEnv,
53 OSGGETGLFUNC_GL3_ES(glGetUniformLocation,
54 osgGlGetUniformLocation,
55 ShaderProgram::getFuncIdGetUniformLocation());
57 loc = osgGlGetUniformLocation(uiProgram, pVar->getName().c_str());
58 #ifdef OSG_MULTISHADER_VARCHUNK
66 void osgUniformShaderVariableBool(DrawEnv *pEnv,
72 ShaderVariableBool *p = dynamic_cast<ShaderVariableBool *>(pVar);
76 OSGGETGLFUNC_GL3_ES(glUniform1i,
78 ShaderProgram::getFuncIdUniform1i());
80 osgGlUniform1i(loc, GLint(p->getValue()));
82 else if(warnUnknown == true)
84 SWARNING << "Variable '" << p->getName() << "' type 'bool' "
85 << "not found in active uniform "
86 << "variables of shader program '" << uiProgram << "'"
92 void osgUniformShaderVariableInt(DrawEnv *pEnv,
98 ShaderVariableInt *p = dynamic_cast<ShaderVariableInt *>(pVar);
102 OSGGETGLFUNC_GL3_ES(glUniform1i,
104 ShaderProgram::getFuncIdUniform1i());
106 osgGlUniform1i(loc, p->getValue());
108 else if(warnUnknown == true)
110 SWARNING << "Variable '" << p->getName() << "' type 'int' "
111 << "not found in active uniform "
112 << "variables of shader program '" << uiProgram << "'"
118 void osgUniformShaderVariableUInt(DrawEnv *pEnv,
119 ShaderVariable *pVar,
124 if(!pEnv->getWindow()->hasExtOrVersion(
125 ShaderProgram::getExtIdGPUShader4(), 0x0303, 0x0200))
127 SWARNING << "Uniforms of type 'uint' are not supported, could not "
128 << "find extension 'EXT_gpu_shader4'!"
133 ShaderVariableUInt *p = dynamic_cast<ShaderVariableUInt *>(pVar);
137 OSGGETGLFUNC_GL3_ES(glUniform1ui,
139 ShaderProgram::getFuncIdUniform1ui());
141 osgGlUniform1ui(loc, p->getValue());
143 else if(warnUnknown == true)
145 SWARNING << "Variable '" << p->getName() << "' type 'uint' "
146 << "not found in active uniform "
147 << "variables of shader program '" << uiProgram << "'"
153 void osgUniformShaderVariableReal(DrawEnv *pEnv,
154 ShaderVariable *pVar,
159 ShaderVariableReal *p = dynamic_cast<ShaderVariableReal *>(pVar);
163 OSGGETGLFUNC_GL3_ES(glUniform1f,
165 ShaderProgram::getFuncIdUniform1f());
167 osgGlUniform1f(loc, p->getValue());
169 else if(warnUnknown == true)
171 SWARNING << "Variable '" << p->getName() << "' type 'float' "
172 << "not found in active uniform "
173 << "variables of shader program '" << uiProgram << "'"
179 void osgUniformShaderVariableVec2f(DrawEnv *pEnv,
180 ShaderVariable *pVar,
185 ShaderVariableVec2f *p = dynamic_cast<ShaderVariableVec2f *>(pVar);
189 OSGGETGLFUNC_GL3_ES(glUniform2fv,
191 ShaderProgram::getFuncIdUniform2fv());
193 osgGlUniform2fv(loc, 1, p->getValue().getValues());
195 else if(warnUnknown == true)
197 SWARNING << "Variable '" << p->getName() << "' type 'vec2f' "
198 << "not found in active uniform "
199 << "variables of shader program '" << uiProgram << "'"
205 void osgUniformShaderVariableVec3f(DrawEnv *pEnv,
206 ShaderVariable *pVar,
211 ShaderVariableVec3f *p = dynamic_cast<ShaderVariableVec3f *>(pVar);
215 OSGGETGLFUNC_GL3_ES(glUniform3fv,
217 ShaderProgram::getFuncIdUniform3fv());
219 osgGlUniform3fv(loc, 1, p->getValue().getValues());
221 else if(warnUnknown == true)
223 SWARNING << "Variable '" << p->getName() << "' type 'vec3f' "
224 << "not found in active uniform "
225 << "variables of shader program '" << uiProgram << "'"
231 void osgUniformShaderVariableVec4f(DrawEnv *pEnv,
232 ShaderVariable *pVar,
237 ShaderVariableVec4f *p = dynamic_cast<ShaderVariableVec4f *>(pVar);
241 OSGGETGLFUNC_GL3_ES(glUniform4fv,
243 ShaderProgram::getFuncIdUniform4fv());
245 osgGlUniform4fv(loc, 1, p->getValue().getValues());
247 else if(warnUnknown == true)
249 SWARNING << "Variable '" << p->getName() << "' type 'vec4f' "
250 << "not found in active uniform "
251 << "variables of shader program '" << uiProgram << "'"
257 void osgUniformShaderVariablePnt2f(DrawEnv *pEnv,
258 ShaderVariable *pVar,
263 ShaderVariablePnt2f *p = dynamic_cast<ShaderVariablePnt2f *>(pVar);
267 OSGGETGLFUNC_GL3_ES(glUniform2fv,
269 ShaderProgram::getFuncIdUniform2fv());
271 osgGlUniform2fv(loc, 1, p->getValue().getValues());
273 else if(warnUnknown == true)
275 SWARNING << "Variable '" << p->getName() << "' type 'pnt2f' "
276 << "not found in active uniform "
277 << "variables of shader program '" << uiProgram << "'"
283 void osgUniformShaderVariablePnt3f(DrawEnv *pEnv,
284 ShaderVariable *pVar,
289 ShaderVariablePnt3f *p = dynamic_cast<ShaderVariablePnt3f *>(pVar);
293 OSGGETGLFUNC_GL3_ES(glUniform3fv,
295 ShaderProgram::getFuncIdUniform3fv());
297 osgGlUniform3fv(loc, 1, p->getValue().getValues());
299 else if(warnUnknown == true)
301 SWARNING << "Variable '" << p->getName() << "' type 'pnt3f' "
302 << "not found in active uniform "
303 << "variables of shader program '" << uiProgram << "'"
309 void osgUniformShaderVariableMatrix(DrawEnv *pEnv,
310 ShaderVariable *pVar,
315 ShaderVariableMatrix *p = dynamic_cast<ShaderVariableMatrix *>(pVar);
319 OSGGETGLFUNC_GL3_ES(glUniformMatrix4fv,
320 osgGlUniformMatrix4fv,
321 ShaderProgram::getFuncIdUniformMatrix4fv());
323 osgGlUniformMatrix4fv(loc,
326 p->getValue().getValues());
328 else if(warnUnknown == true)
330 SWARNING << "Variable '" << p->getName() << "' type 'matrix' "
331 << "not found in active uniform "
332 << "variables of shader program '" << uiProgram << "'"
338 void osgUniformShaderVariableMInt(DrawEnv *pEnv,
339 ShaderVariable *pVar,
344 ShaderVariableMInt *p = dynamic_cast<ShaderVariableMInt *>(pVar);
346 if(loc > -1 && !p->getMFValue()->empty())
348 OSGGETGLFUNC_GL3_ES(glUniform1iv,
350 ShaderProgram::getFuncIdUniform1iv());
352 osgGlUniform1iv( loc,
353 p->getMFValue()->size32(),
354 &(p->getMFValue()->front ()));
356 else if(warnUnknown == true)
358 SWARNING << "Variable '" << p->getName() << "' type 'int []' "
359 << "not found in active uniform "
360 << "variables of shader program '" << uiProgram << "'"
366 void osgUniformShaderVariableMUInt(DrawEnv *pEnv,
367 ShaderVariable *pVar,
372 if(!pEnv->getWindow()->hasExtOrVersion(
373 ShaderProgram::getExtIdGPUShader4(), 0x0303, 0x0200))
375 SWARNING << "Uniforms of type 'uint' are not supported, could not "
376 << "find extension 'EXT_gpu_shader4'!"
381 ShaderVariableMUInt *p = dynamic_cast<ShaderVariableMUInt *>(pVar);
383 if(loc > -1 && !p->getMFValue()->empty())
385 OSGGETGLFUNC_GL3_ES(glUniform1uiv,
387 ShaderProgram::getFuncIdUniform1uiv());
389 osgGlUniform1uiv( loc,
390 p->getMFValue()->size32(),
391 &(p->getMFValue()->front ()));
393 else if(warnUnknown == true)
395 SWARNING << "Variable '" << p->getName() << "' type 'uint []' "
396 << "not found in active uniform "
397 << "variables of shader program '" << uiProgram << "'"
403 void osgUniformShaderVariableMReal(DrawEnv *pEnv,
404 ShaderVariable *pVar,
409 ShaderVariableMReal *p = dynamic_cast<ShaderVariableMReal *>(pVar);
411 if(loc > -1 && !p->getMFValue()->empty())
413 OSGGETGLFUNC_GL3_ES(glUniform1fv,
415 ShaderProgram::getFuncIdUniform1fv());
417 osgGlUniform1fv( loc,
418 p->getMFValue()->size32(),
419 &(p->getMFValue()->front ()));
421 else if(warnUnknown == true)
423 SWARNING << "Variable '" << p->getName() << "' type 'real []' "
424 << "not found in active uniform "
425 << "variables of shader program '" << uiProgram << "'"
431 void osgUniformShaderVariableMVec2f(DrawEnv *pEnv,
432 ShaderVariable *pVar,
437 ShaderVariableMVec2f *p = dynamic_cast<ShaderVariableMVec2f *>(pVar);
439 if(loc > -1 && !p->getMFValue()->empty())
441 OSGGETGLFUNC_GL3_ES(glUniform2fv,
443 ShaderProgram::getFuncIdUniform2fv());
446 p->getMFValue()->size32(),
447 p->getMFValue()->front ().getValues());
449 else if(warnUnknown == true)
451 SWARNING << "Variable '" << p->getName() << "' type 'vec2f []' "
452 << "not found in active uniform "
453 << "variables of shader program '" << uiProgram << "'"
459 void osgUniformShaderVariableMVec3f(DrawEnv *pEnv,
460 ShaderVariable *pVar,
465 ShaderVariableMVec3f *p = dynamic_cast<ShaderVariableMVec3f *>(pVar);
467 if(loc > -1 && !p->getMFValue()->empty())
469 OSGGETGLFUNC_GL3_ES(glUniform3fv,
471 ShaderProgram::getFuncIdUniform3fv());
474 p->getMFValue()->size32(),
475 p->getMFValue()->front ().getValues());
477 else if(warnUnknown == true)
479 SWARNING << "Variable '" << p->getName() << "' type 'vec3f []' "
480 << "not found in active uniform "
481 << "variables of shader program '" << uiProgram << "'"
487 void osgUniformShaderVariableMVec4f(DrawEnv *pEnv,
488 ShaderVariable *pVar,
493 ShaderVariableMVec4f *p = dynamic_cast<ShaderVariableMVec4f *>(pVar);
495 if(loc > -1 && !p->getMFValue()->empty())
497 OSGGETGLFUNC_GL3_ES(glUniform4fv,
499 ShaderProgram::getFuncIdUniform4fv());
502 p->getMFValue()->size32(),
503 p->getMFValue()->front ().getValues());
505 else if(warnUnknown == true)
507 SWARNING << "Variable '" << p->getName() << "' type 'vec4f []' "
508 << "not found in active uniform "
509 << "variables of shader program '" << uiProgram << "'"
515 void osgUniformShaderVariableMMatrix(DrawEnv *pEnv,
516 ShaderVariable *pVar,
521 ShaderVariableMMatrix *p = dynamic_cast<ShaderVariableMMatrix *>(pVar);
523 if(loc > -1 && !p->getMFValue()->empty())
525 OSGGETGLFUNC_GL3_ES(glUniformMatrix4fv,
526 osgGlUniformMatrix4fv,
527 ShaderProgram::getFuncIdUniformMatrix4fv());
529 osgGlUniformMatrix4fv(loc,
530 p->getMFValue()->size32(),
532 p->getMFValue()->front ().getValues());
534 else if(warnUnknown == true)
536 SWARNING << "Variable '" << p->getName() << "' type 'matrix []' "
537 << "not found in active uniform "
538 << "variables of shader program '" << uiProgram << "'"
544 void osgUniformShaderUniformBlockLocation(DrawEnv *pEnv,
545 ShaderVariable *pVar,
549 if(!pEnv->getWindow()->hasExtOrVersion(
550 ShaderProgram::getExtIdUniformBufferObject(), 0x0201, 0x0200))
552 SWARNING << "Uniform blocks are not supported, could not "
553 << "find extension 'GL_ARB_uniform_buffer_object'!"
560 OSGGETGLFUNC_GL3_ES(glGetUniformBlockIndex,
561 osgGlGetUniformBlockIndex,
562 ShaderProgram::getFuncIdGetUniformBlockIndex());
564 loc = osgGlGetUniformBlockIndex(uiProgram, pVar->getName().c_str());
565 #ifdef OSG_MULTISHADER_VARCHUNK
573 void osgUniformShaderUniformBlockBinding(DrawEnv *pEnv,
574 ShaderVariable *pVar,
579 if(!pEnv->getWindow()->hasExtOrVersion(
580 ShaderProgram::getExtIdUniformBufferObject(), 0x0201, 0x0200))
582 SWARNING << "Uniform blocks are not supported, could not "
583 << "find extension 'GL_ARB_uniform_buffer_object'!"
588 ShaderVariableUniformBlock *p = dynamic_cast<ShaderVariableUniformBlock *>(pVar);
592 OSGGETGLFUNC_GL3_ES(glUniformBlockBinding,
593 osgGlUniformBlockBinding,
594 ShaderProgram::getFuncIdUniformBlockBinding());
596 osgGlUniformBlockBinding(uiProgram, loc, p->getValue());
598 else if(warnUnknown == true)
600 SWARNING << "Block '" << p->getName() << "'"
601 << "not found in active shader program '" << uiProgram << "'"
607 void osgUniformShaderStorageBlockLocation(DrawEnv *pEnv,
608 ShaderVariable *pVar,
612 if(!pEnv->getWindow()->hasExtOrVersion(
613 ShaderProgram::getExtIdProgramInterfaceQuery(), 0x0402))
615 SWARNING << "Shader Storage are not supported, could not "
616 << "find extension 'GL_ARB_program_interface_query'!"
621 if(!pEnv->getWindow()->hasExtOrVersion(
622 ShaderProgram::getExtIdShaderStorageBufferObject(), 0x0403))
624 SWARNING << "Shader Storage are not supported, could not "
625 << "find extension 'GL_ARB_shader_storage_buffer_object'!"
632 OSGGETGLFUNC_GL3_ES(glGetProgramResourceIndex,
633 osgGlGetProgramResourceIndex,
634 ShaderProgram::getFuncIdGetProgramResourceIndex());
636 loc = osgGlGetProgramResourceIndex(uiProgram, GL_SHADER_STORAGE_BLOCK, pVar->getName().c_str());
637 #ifdef OSG_MULTISHADER_VARCHUNK
645 void osgUniformShaderStorageBlockBinding(DrawEnv *pEnv,
646 ShaderVariable *pVar,
651 if(!pEnv->getWindow()->hasExtOrVersion(
652 ShaderProgram::getExtIdShaderStorageBufferObject(), 0x0403))
654 SWARNING << "Shader Storage blocks are not supported, could not "
655 << "find extension 'GL_ARB_shader_storage_buffer_object'!"
660 ShaderVariableShaderStorageBlock *p = dynamic_cast<ShaderVariableShaderStorageBlock *>(pVar);
664 OSGGETGLFUNC_GL3_ES(glShaderStorageBlockBinding,
665 osgGlShaderStorageBlockBinding,
666 ShaderProgram::getFuncIdShaderStorageBlockBinding());
668 osgGlShaderStorageBlockBinding(uiProgram, loc, p->getValue());
670 else if(warnUnknown == true)
672 SWARNING << "Block '" << p->getName() << "'"
673 << "not found in active shader program '" << uiProgram << "'"