1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2  * Copyright (C) 2003-2005 3Dlabs Inc. Ltd.
3  * Copyright (C) 2008 Zebra Imaging
4  * Copyright (C) 2012 David Callu
5  *
6  * This application is open source and may be redistributed and/or modified
7  * freely and without restriction, both in commercial and non commercial
8  * applications, as long as this copyright notice is maintained.
9  *
10  * This application is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 */
14 
15 /* file:   src/osg/Uniform.cpp
16  * author: Mike Weiblen 2008-01-02
17 */
18 #include <string.h>
19 
20 #include <osg/Notify>
21 #include <osg/Uniform>
22 #include <osg/Program>
23 #include <osg/StateSet>
24 
25 #include <limits.h>
26 #include <algorithm>
27 
28 using namespace osg;
29 
30 ///////////////////////////////////////////////////////////////////////////
31 // osg::Uniform
32 ///////////////////////////////////////////////////////////////////////////
33 
Uniform()34 Uniform::Uniform() :
35     _type(UNDEFINED), _numElements(0), _nameID(UINT_MAX), _modifiedCount(0)
36 {
37 }
38 
39 
Uniform(Type type,const std::string & name,int numElements)40 Uniform::Uniform( Type type, const std::string& name, int numElements ) :
41     _type(type), _numElements(0), _nameID(UINT_MAX), _modifiedCount(0)
42 {
43     setName(name);
44     setNumElements(numElements);
45     allocateDataArray();
46 }
47 
Uniform(const Uniform & uniform,const CopyOp & copyop)48 Uniform::Uniform(const Uniform& uniform, const CopyOp& copyop) :
49     Object(uniform, copyop),
50     _type(uniform._type),
51     _updateCallback(copyop(uniform._updateCallback.get())),
52     _eventCallback(copyop(uniform._eventCallback.get()))
53 {
54     copyData(uniform);
55 }
56 
~Uniform()57 Uniform::~Uniform()
58 {
59 }
60 
addParent(osg::StateSet * object)61 void Uniform::addParent(osg::StateSet* object)
62 {
63     OSG_DEBUG_FP<<"Uniform Adding parent"<<std::endl;
64 
65     OpenThreads::ScopedPointerLock<OpenThreads::Mutex> lock(getRefMutex());
66 
67     _parents.push_back(object);
68 }
69 
removeParent(osg::StateSet * object)70 void Uniform::removeParent(osg::StateSet* object)
71 {
72     OpenThreads::ScopedPointerLock<OpenThreads::Mutex> lock(getRefMutex());
73 
74     ParentList::iterator pitr = std::find(_parents.begin(),_parents.end(),object);
75     if (pitr!=_parents.end()) _parents.erase(pitr);
76 }
77 
setType(Type t)78 bool Uniform::setType( Type t )
79 {
80     if (_type==t) return true;
81 
82     if( _type != UNDEFINED )
83     {
84         OSG_WARN << "cannot change Uniform type" << std::endl;
85         return false;
86     }
87     _type = t;
88     allocateDataArray();
89     return true;
90 }
91 
setName(const std::string & name)92 void Uniform::setName( const std::string& name )
93 {
94     if( _name != "" )
95     {
96         OSG_WARN << "cannot change Uniform name" << std::endl;
97         return;
98     }
99     Object::setName(name);
100     _nameID = getNameID(_name);
101 }
102 
setNumElements(unsigned int numElements)103 void Uniform::setNumElements( unsigned int numElements )
104 {
105     if( numElements < 1 )
106     {
107         OSG_WARN << "Uniform numElements < 1 is invalid" << std::endl;
108         return;
109     }
110 
111     if (numElements == _numElements) return;
112 
113     if( _numElements>0 )
114     {
115         OSG_WARN << "Warning: Uniform::setNumElements() cannot change Uniform numElements, size already fixed." << std::endl;
116         return;
117     }
118 
119     _numElements = numElements;
120     allocateDataArray();
121 }
122 
allocateDataArray()123 void Uniform::allocateDataArray()
124 {
125     // if one array is already allocated, the job is done.
126     if( _floatArray.valid() || _doubleArray.valid() || _intArray.valid() || _uintArray.valid() || _int64Array.valid() || _uint64Array.valid()) return;
127 
128     // array cannot be created until _type and _numElements are specified
129     int arrayNumElements = getInternalArrayNumElements();
130     if( arrayNumElements )
131     {
132         switch( getInternalArrayType(getType()) )
133         {
134             case GL_FLOAT:
135                 _floatArray = new FloatArray(arrayNumElements);
136                 return;
137 
138             case GL_DOUBLE:
139                 _doubleArray = new DoubleArray(arrayNumElements);
140                 return;
141 
142             case GL_INT:
143                 _intArray = new IntArray(arrayNumElements);
144                 return;
145 
146             case GL_UNSIGNED_INT:
147                 _uintArray = new UIntArray(arrayNumElements);
148                 return;
149 
150             case GL_INT64_ARB:
151                 _int64Array = new Int64Array(arrayNumElements);
152                 return;
153 
154             case GL_UNSIGNED_INT64_ARB:
155                 _uint64Array = new UInt64Array(arrayNumElements);
156                 return;
157 
158             default:
159                 break;
160         }
161     }
162 }
163 
setArray(FloatArray * array)164 bool Uniform::setArray( FloatArray* array )
165 {
166     if( !array ) return false;
167 
168     // incoming array must match configuration of the Uniform
169     if( getInternalArrayType(getType())!=GL_FLOAT || getInternalArrayNumElements()!=array->getNumElements() )
170     {
171         OSG_WARN << "Uniform::setArray : incompatible array" << std::endl;
172         return false;
173     }
174 
175     _floatArray = array;
176     _doubleArray = 0;
177     _intArray = 0;
178     _uintArray = 0;
179     _int64Array = 0;
180     _uint64Array = 0;
181     dirty();
182     return true;
183 }
184 
setArray(DoubleArray * array)185 bool Uniform::setArray( DoubleArray* array )
186 {
187     if( !array ) return false;
188 
189     // incoming array must match configuration of the Uniform
190     if( getInternalArrayType(getType())!=GL_DOUBLE || getInternalArrayNumElements()!=array->getNumElements() )
191     {
192         OSG_WARN << "Uniform::setArray : incompatible array" << std::endl;
193         return false;
194     }
195 
196     _doubleArray = array;
197     _floatArray = 0;
198     _intArray = 0;
199     _uintArray = 0;
200     _int64Array = 0;
201     _uint64Array = 0;
202     dirty();
203     return true;
204 }
205 
setArray(IntArray * array)206 bool Uniform::setArray( IntArray* array )
207 {
208     if( !array ) return false;
209 
210     // incoming array must match configuration of the Uniform
211     if( getInternalArrayType(getType())!=GL_INT || getInternalArrayNumElements()!=array->getNumElements() )
212     {
213         OSG_WARN << "Uniform::setArray : incompatible array" << std::endl;
214         return false;
215     }
216 
217     _intArray = array;
218     _floatArray = 0;
219     _doubleArray = 0;
220     _uintArray = 0;
221     _int64Array = 0;
222     _uint64Array = 0;
223     dirty();
224     return true;
225 }
226 
setArray(UIntArray * array)227 bool Uniform::setArray( UIntArray* array )
228 {
229     if( !array ) return false;
230 
231     // incoming array must match configuration of the Uniform
232     if( getInternalArrayType(getType())!=GL_UNSIGNED_INT || getInternalArrayNumElements()!=array->getNumElements() )
233     {
234         OSG_WARN << "Uniform::setArray : incompatible array" << std::endl;
235         return false;
236     }
237 
238     _uintArray = array;
239     _floatArray = 0;
240     _doubleArray = 0;
241     _intArray = 0;
242     _int64Array = 0;
243     _uint64Array = 0;
244     dirty();
245     return true;
246 }
setArray(UInt64Array * array)247 bool Uniform::setArray( UInt64Array* array )
248 {
249     if( !array ) return false;
250 
251     // incoming array must match configuration of the Uniform
252     if( getInternalArrayType(getType())!=GL_UNSIGNED_INT64_ARB || getInternalArrayNumElements()!=array->getNumElements() )
253     {
254         OSG_WARN << "Uniform::setArray : incompatible array" << std::endl;
255         return false;
256     }
257 
258     _uint64Array = array;
259     _floatArray = 0;
260     _doubleArray = 0;
261     _intArray = 0;
262     _uintArray = 0;
263     _int64Array =0;
264     dirty();
265     return true;
266 }
267 
setArray(Int64Array * array)268 bool Uniform::setArray( Int64Array* array )
269 {
270     if( !array ) return false;
271 
272     // incoming array must match configuration of the Uniform
273     if( getInternalArrayType(getType())!=GL_UNSIGNED_INT64_ARB || getInternalArrayNumElements()!=array->getNumElements() )
274     {
275         OSG_WARN << "Uniform::setArray : incompatible array" << std::endl;
276         return false;
277     }
278 
279     _int64Array = array;
280     _floatArray = 0;
281     _doubleArray = 0;
282     _intArray = 0;
283     _uintArray = 0;
284     _uint64Array =0;
285     dirty();
286     return true;
287 }
288 
289 ///////////////////////////////////////////////////////////////////////////
290 
compare(const Uniform & rhs) const291 int Uniform::compare(const Uniform& rhs) const
292 {
293     if( this == &rhs ) return 0;
294 
295     if( _type < rhs._type ) return -1;
296     if( rhs._type < _type ) return 1;
297 
298     if( _numElements < rhs._numElements ) return -1;
299     if( rhs._numElements < _numElements ) return 1;
300 
301     if( _name < rhs._name ) return -1;
302     if( rhs._name < _name ) return 1;
303 
304     return compareData( rhs );
305 }
306 
compareData(const Uniform & rhs) const307 int Uniform::compareData(const Uniform& rhs) const
308 {
309     // caller must ensure that _type==rhs._type
310 
311     if( _floatArray.valid() )
312     {
313         if( ! rhs._floatArray ) return 1;
314         if( _floatArray == rhs._floatArray ) return 0;
315         return memcmp( _floatArray->getDataPointer(), rhs._floatArray->getDataPointer(),
316             _floatArray->getTotalDataSize() );
317     }
318 
319     else if( _doubleArray.valid() )
320     {
321         if( ! rhs._doubleArray ) return 1;
322         if( _doubleArray == rhs._doubleArray ) return 0;
323         return memcmp( _doubleArray->getDataPointer(), rhs._doubleArray->getDataPointer(),
324             _doubleArray->getTotalDataSize() );
325     }
326 
327     else if( _intArray.valid() )
328     {
329         if( ! rhs._intArray ) return 1;
330         if( _intArray == rhs._intArray ) return 0;
331         return memcmp( _intArray->getDataPointer(), rhs._intArray->getDataPointer(),
332             _intArray->getTotalDataSize() );
333     }
334 
335     else if( _uintArray.valid() )
336     {
337         if( ! rhs._uintArray ) return 1;
338         if( _uintArray == rhs._uintArray ) return 0;
339         return memcmp( _uintArray->getDataPointer(), rhs._uintArray->getDataPointer(),
340             _uintArray->getTotalDataSize() );
341     }
342 
343     else if( _uint64Array.valid() )
344     {
345         if( ! rhs._uint64Array ) return 1;
346         if( _uint64Array == rhs._uint64Array ) return 0;
347         return memcmp( _uint64Array->getDataPointer(), rhs._uint64Array->getDataPointer(),
348             _uint64Array->getTotalDataSize() );
349     }
350 
351     else if( _int64Array.valid() )
352     {
353         if( ! rhs._int64Array ) return 1;
354         if( _int64Array == rhs._int64Array ) return 0;
355         return memcmp( _int64Array->getDataPointer(), rhs._int64Array->getDataPointer(),
356             _int64Array->getTotalDataSize() );
357     }
358 
359     return -1;  // how got here?
360 }
361 
copyData(const Uniform & rhs)362 void Uniform::copyData(const Uniform& rhs)
363 {
364     // caller must ensure that _type==rhs._type
365     _numElements = rhs._numElements;
366     _nameID = rhs._nameID;
367     if (rhs._floatArray.valid() || rhs._doubleArray.valid() || rhs._intArray.valid() || rhs._uintArray.valid()) allocateDataArray();
368     if( _floatArray.valid()  && rhs._floatArray.valid() )   *_floatArray  = *rhs._floatArray;
369     if( _doubleArray.valid() && rhs._doubleArray.valid() )  *_doubleArray = *rhs._doubleArray;
370     if( _intArray.valid()    && rhs._intArray.valid() )     *_intArray    = *rhs._intArray;
371     if( _uintArray.valid()   && rhs._uintArray.valid() )    *_uintArray   = *rhs._uintArray;
372     if( _int64Array.valid()    && rhs._int64Array.valid() )     *_int64Array    = *rhs._int64Array;
373     if( _uint64Array.valid()   && rhs._uint64Array.valid() )    *_uint64Array   = *rhs._uint64Array;
374     dirty();
375 }
376 
isCompatibleType(Type t) const377 bool Uniform::isCompatibleType( Type t ) const
378 {
379     if( (t==UNDEFINED) || (getType()==UNDEFINED) ) return false;
380     if( t == getType() ) return true;
381     if( getGlApiType(t) == getGlApiType(getType()) ) return true;
382 
383     OSG_WARN << "Cannot assign between Uniform types " << getTypename(t)
384              << " and " << getTypename(getType()) << std::endl;
385     return false;
386 }
387 
isCompatibleType(Type t1,Type t2) const388 bool Uniform::isCompatibleType( Type t1, Type t2 ) const
389 {
390     if( (t1==UNDEFINED) || (t2==UNDEFINED) || (getType()==UNDEFINED) ) return false;
391     if( (t1 == getType()) || (t2 == getType()) ) return true;
392     if( getGlApiType(t1) == getGlApiType(getType()) ) return true;
393     if( getGlApiType(t2) == getGlApiType(getType()) ) return true;
394 
395     OSG_WARN << "Cannot assign between Uniform types " << getTypename(t1) << " or " << getTypename(t2)
396              << " and " << getTypename(getType()) << std::endl;
397     return false;
398 }
399 
getInternalArrayNumElements() const400 unsigned int Uniform::getInternalArrayNumElements() const
401 {
402     if( getNumElements()<1 || getType()==UNDEFINED ) return 0;
403     return getNumElements() * getTypeNumComponents(getType());
404 }
405 
406 
407 ///////////////////////////////////////////////////////////////////////////
408 // static methods
409 
getTypename(Type t)410 const char* Uniform::getTypename( Type t )
411 {
412     switch( t )
413     {
414     case FLOAT:      return "float";
415     case FLOAT_VEC2: return "vec2";
416     case FLOAT_VEC3: return "vec3";
417     case FLOAT_VEC4: return "vec4";
418 
419     case DOUBLE:      return "double";
420     case DOUBLE_VEC2: return "dvec2";
421     case DOUBLE_VEC3: return "dvec3";
422     case DOUBLE_VEC4: return "dvec4";
423 
424     case INT:      return "int";
425     case INT_VEC2: return "ivec2";
426     case INT_VEC3: return "ivec3";
427     case INT_VEC4: return "ivec4";
428 
429     case UNSIGNED_INT:      return "uint";
430     case UNSIGNED_INT_VEC2: return "uivec2";
431     case UNSIGNED_INT_VEC3: return "uivec3";
432     case UNSIGNED_INT_VEC4: return "uivec4";
433 
434     case BOOL:      return "bool";
435     case BOOL_VEC2: return "bvec2";
436     case BOOL_VEC3: return "bvec3";
437     case BOOL_VEC4: return "bvec4";
438 
439     case INT64:      return "int64_t";
440     case UNSIGNED_INT64: return "uint64_t";
441 
442     case FLOAT_MAT2:   return "mat2";
443     case FLOAT_MAT3:   return "mat3";
444     case FLOAT_MAT4:   return "mat4";
445     case FLOAT_MAT2x3: return "mat2x3";
446     case FLOAT_MAT2x4: return "mat2x4";
447     case FLOAT_MAT3x2: return "mat3x2";
448     case FLOAT_MAT3x4: return "mat3x4";
449     case FLOAT_MAT4x2: return "mat4x2";
450     case FLOAT_MAT4x3: return "mat4x3";
451 
452     case DOUBLE_MAT2:   return "dmat2";
453     case DOUBLE_MAT3:   return "dmat3";
454     case DOUBLE_MAT4:   return "dmat4";
455     case DOUBLE_MAT2x3: return "dmat2x3";
456     case DOUBLE_MAT2x4: return "dmat2x4";
457     case DOUBLE_MAT3x2: return "dmat3x2";
458     case DOUBLE_MAT3x4: return "dmat3x4";
459     case DOUBLE_MAT4x2: return "dmat4x2";
460     case DOUBLE_MAT4x3: return "dmat4x3";
461 
462     case SAMPLER_1D:                    return "sampler1D";
463     case SAMPLER_2D:                    return "sampler2D";
464     case SAMPLER_3D:                    return "sampler3D";
465     case SAMPLER_CUBE:                  return "samplerCube";
466     case SAMPLER_1D_SHADOW:             return "sampler1DShadow";
467     case SAMPLER_2D_SHADOW:             return "sampler2DShadow";
468     case SAMPLER_1D_ARRAY:              return "sampler1DArray";
469     case SAMPLER_2D_ARRAY:              return "sampler2DArray";
470     case SAMPLER_CUBE_MAP_ARRAY:        return "samplerCubeMapArray";
471     case SAMPLER_1D_ARRAY_SHADOW:       return "sampler1DArrayShadow";
472     case SAMPLER_2D_ARRAY_SHADOW:       return "sampler2DArrayShadow";
473     case SAMPLER_2D_MULTISAMPLE:        return "sampler2DMS";
474     case SAMPLER_2D_MULTISAMPLE_ARRAY:  return "sampler2DMSArray";
475     case SAMPLER_CUBE_SHADOW:           return "samplerCubeShadow";
476     case SAMPLER_CUBE_MAP_ARRAY_SHADOW: return "samplerCubeMapArrayShadow";
477     case SAMPLER_BUFFER:                return "samplerBuffer";
478     case SAMPLER_2D_RECT:               return "sampler2DRect";
479     case SAMPLER_2D_RECT_SHADOW:        return "sampler2DRectShadow";
480 
481     case INT_SAMPLER_1D:                   return "isampler1D";
482     case INT_SAMPLER_2D:                   return "isampler2D";
483     case INT_SAMPLER_3D:                   return "isampler3D";
484     case INT_SAMPLER_CUBE:                 return "isamplerCube";
485     case INT_SAMPLER_1D_ARRAY:             return "isampler1DArray";
486     case INT_SAMPLER_2D_ARRAY:             return "isampler2DArray";
487     case INT_SAMPLER_CUBE_MAP_ARRAY:       return "isamplerCubeMapArray";
488     case INT_SAMPLER_2D_MULTISAMPLE:       return "isampler2DMS";
489     case INT_SAMPLER_2D_MULTISAMPLE_ARRAY: return "isampler2DMSArray";
490     case INT_SAMPLER_BUFFER:               return "isamplerBuffer";
491     case INT_SAMPLER_2D_RECT:              return "isampler2DRect";
492 
493     case UNSIGNED_INT_SAMPLER_1D:                   return "usampler1D";
494     case UNSIGNED_INT_SAMPLER_2D:                   return "usampler2D";
495     case UNSIGNED_INT_SAMPLER_3D:                   return "usampler3D";
496     case UNSIGNED_INT_SAMPLER_CUBE:                 return "usamplerCube";
497     case UNSIGNED_INT_SAMPLER_1D_ARRAY:             return "usampler1DArray";
498     case UNSIGNED_INT_SAMPLER_2D_ARRAY:             return "usampler2DArray";
499     case UNSIGNED_INT_SAMPLER_CUBE_MAP_ARRAY:       return "usamplerCubeMapArray";
500     case UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE:       return "usampler2DMS";
501     case UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE_ARRAY: return "usampler2DMSArray";
502     case UNSIGNED_INT_SAMPLER_BUFFER:               return "usamplerBuffer";
503     case UNSIGNED_INT_SAMPLER_2D_RECT:              return "usampler2DRect";
504 
505     case IMAGE_1D:                   return "image1D";
506     case IMAGE_2D:                   return "image2D";
507     case IMAGE_3D:                   return "image3D";
508     case IMAGE_2D_RECT:              return "image2DRect";
509     case IMAGE_CUBE:                 return "imageCube";
510     case IMAGE_BUFFER:               return "imageBuffer";
511     case IMAGE_1D_ARRAY:             return "image1DArray";
512     case IMAGE_2D_ARRAY:             return "image2DArray";
513     case IMAGE_CUBE_MAP_ARRAY:       return "imageCubeArray";
514     case IMAGE_2D_MULTISAMPLE:       return "image2DMS";
515     case IMAGE_2D_MULTISAMPLE_ARRAY: return "image2DMSArray";
516 
517     case INT_IMAGE_1D:                   return "iimage1D";
518     case INT_IMAGE_2D:                   return "iimage2D";
519     case INT_IMAGE_3D:                   return "iimage3D";
520     case INT_IMAGE_2D_RECT:              return "iimage2DRect";
521     case INT_IMAGE_CUBE:                 return "iimageCube";
522     case INT_IMAGE_BUFFER:               return "iimageBuffer";
523     case INT_IMAGE_1D_ARRAY:             return "iimage1DArray";
524     case INT_IMAGE_2D_ARRAY:             return "iimage2DArray";
525     case INT_IMAGE_CUBE_MAP_ARRAY:       return "iimageCubeArray";
526     case INT_IMAGE_2D_MULTISAMPLE:       return "iimage2DMS";
527     case INT_IMAGE_2D_MULTISAMPLE_ARRAY: return "iimage2DMSArray";
528 
529     case UNSIGNED_INT_IMAGE_1D:                   return "uimage1D";
530     case UNSIGNED_INT_IMAGE_2D:                   return "uimage2D";
531     case UNSIGNED_INT_IMAGE_3D:                   return "uimage3D";
532     case UNSIGNED_INT_IMAGE_2D_RECT:              return "uimage2DRect";
533     case UNSIGNED_INT_IMAGE_CUBE:                 return "uimageCube";
534     case UNSIGNED_INT_IMAGE_BUFFER:               return "uimageBuffer";
535     case UNSIGNED_INT_IMAGE_1D_ARRAY:             return "uimage1DArray";
536     case UNSIGNED_INT_IMAGE_2D_ARRAY:             return "uimage2DArray";
537     case UNSIGNED_INT_IMAGE_CUBE_MAP_ARRAY:       return "uimageCubeArray";
538     case UNSIGNED_INT_IMAGE_2D_MULTISAMPLE:       return "uimage2DMS";
539     case UNSIGNED_INT_IMAGE_2D_MULTISAMPLE_ARRAY: return "uimage2DMSArray";
540 
541     default: return "UNDEFINED";
542     }
543 }
544 
getTypeNumComponents(Type t)545 int Uniform::getTypeNumComponents( Type t )
546 {
547     switch( t )
548     {
549     case FLOAT:
550     case DOUBLE:
551     case INT:
552     case UNSIGNED_INT:
553     case BOOL:
554     case UNSIGNED_INT64:
555     case INT64:
556 
557     case SAMPLER_1D:
558     case SAMPLER_2D:
559     case SAMPLER_3D:
560     case SAMPLER_CUBE:
561     case SAMPLER_1D_SHADOW:
562     case SAMPLER_2D_SHADOW:
563     case SAMPLER_1D_ARRAY:
564     case SAMPLER_2D_ARRAY:
565     case SAMPLER_CUBE_MAP_ARRAY:
566     case SAMPLER_1D_ARRAY_SHADOW:
567     case SAMPLER_2D_ARRAY_SHADOW:
568     case SAMPLER_2D_MULTISAMPLE:
569     case SAMPLER_2D_MULTISAMPLE_ARRAY:
570     case SAMPLER_CUBE_SHADOW:
571     case SAMPLER_CUBE_MAP_ARRAY_SHADOW:
572     case SAMPLER_BUFFER:
573     case SAMPLER_2D_RECT:
574     case SAMPLER_2D_RECT_SHADOW:
575 
576     case INT_SAMPLER_1D:
577     case INT_SAMPLER_2D:
578     case INT_SAMPLER_3D:
579     case INT_SAMPLER_CUBE:
580     case INT_SAMPLER_1D_ARRAY:
581     case INT_SAMPLER_2D_ARRAY:
582     case INT_SAMPLER_CUBE_MAP_ARRAY:
583     case INT_SAMPLER_2D_MULTISAMPLE:
584     case INT_SAMPLER_2D_MULTISAMPLE_ARRAY:
585     case INT_SAMPLER_BUFFER:
586     case INT_SAMPLER_2D_RECT:
587 
588     case UNSIGNED_INT_SAMPLER_1D:
589     case UNSIGNED_INT_SAMPLER_2D:
590     case UNSIGNED_INT_SAMPLER_3D:
591     case UNSIGNED_INT_SAMPLER_CUBE:
592     case UNSIGNED_INT_SAMPLER_1D_ARRAY:
593     case UNSIGNED_INT_SAMPLER_2D_ARRAY:
594     case UNSIGNED_INT_SAMPLER_CUBE_MAP_ARRAY:
595     case UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE:
596     case UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE_ARRAY:
597     case UNSIGNED_INT_SAMPLER_BUFFER:
598     case UNSIGNED_INT_SAMPLER_2D_RECT:
599 
600     case IMAGE_1D:
601     case IMAGE_2D:
602     case IMAGE_3D:
603     case IMAGE_2D_RECT:
604     case IMAGE_CUBE:
605     case IMAGE_BUFFER:
606     case IMAGE_1D_ARRAY:
607     case IMAGE_2D_ARRAY:
608     case IMAGE_CUBE_MAP_ARRAY:
609     case IMAGE_2D_MULTISAMPLE:
610     case IMAGE_2D_MULTISAMPLE_ARRAY:
611 
612     case INT_IMAGE_1D:
613     case INT_IMAGE_2D:
614     case INT_IMAGE_3D:
615     case INT_IMAGE_2D_RECT:
616     case INT_IMAGE_CUBE:
617     case INT_IMAGE_BUFFER:
618     case INT_IMAGE_1D_ARRAY:
619     case INT_IMAGE_2D_ARRAY:
620     case INT_IMAGE_CUBE_MAP_ARRAY:
621     case INT_IMAGE_2D_MULTISAMPLE:
622     case INT_IMAGE_2D_MULTISAMPLE_ARRAY:
623 
624     case UNSIGNED_INT_IMAGE_1D:
625     case UNSIGNED_INT_IMAGE_2D:
626     case UNSIGNED_INT_IMAGE_3D:
627     case UNSIGNED_INT_IMAGE_2D_RECT:
628     case UNSIGNED_INT_IMAGE_CUBE:
629     case UNSIGNED_INT_IMAGE_BUFFER:
630     case UNSIGNED_INT_IMAGE_1D_ARRAY:
631     case UNSIGNED_INT_IMAGE_2D_ARRAY:
632     case UNSIGNED_INT_IMAGE_CUBE_MAP_ARRAY:
633     case UNSIGNED_INT_IMAGE_2D_MULTISAMPLE:
634     case UNSIGNED_INT_IMAGE_2D_MULTISAMPLE_ARRAY:
635         return 1;
636 
637     case FLOAT_VEC2:
638     case DOUBLE_VEC2:
639     case INT_VEC2:
640     case UNSIGNED_INT_VEC2:
641     case BOOL_VEC2:
642         return 2;
643 
644     case FLOAT_VEC3:
645     case DOUBLE_VEC3:
646     case INT_VEC3:
647     case UNSIGNED_INT_VEC3:
648     case BOOL_VEC3:
649         return 3;
650 
651     case FLOAT_VEC4:
652     case DOUBLE_VEC4:
653     case FLOAT_MAT2:
654     case DOUBLE_MAT2:
655     case INT_VEC4:
656     case UNSIGNED_INT_VEC4:
657     case BOOL_VEC4:
658         return 4;
659 
660     case FLOAT_MAT2x3:
661     case FLOAT_MAT3x2:
662     case DOUBLE_MAT2x3:
663     case DOUBLE_MAT3x2:
664         return 6;
665 
666     case FLOAT_MAT2x4:
667     case FLOAT_MAT4x2:
668     case DOUBLE_MAT2x4:
669     case DOUBLE_MAT4x2:
670         return 8;
671 
672     case FLOAT_MAT3:
673     case DOUBLE_MAT3:
674         return 9;
675 
676     case FLOAT_MAT3x4:
677     case FLOAT_MAT4x3:
678     case DOUBLE_MAT3x4:
679     case DOUBLE_MAT4x3:
680         return 12;
681 
682     case FLOAT_MAT4:
683     case DOUBLE_MAT4:
684         return 16;
685 
686     default:
687         return 0;
688     }
689 }
690 
getTypeId(const std::string & tname)691 Uniform::Type Uniform::getTypeId( const std::string& tname )
692 {
693     if( tname == "float" )           return FLOAT;
694     if( tname == "vec2" )            return FLOAT_VEC2;
695     if( tname == "vec3" )            return FLOAT_VEC3;
696     if( tname == "vec4" )            return FLOAT_VEC4;
697 
698     if( tname == "double" )          return DOUBLE;
699     if( tname == "dvec2" )           return DOUBLE_VEC2;
700     if( tname == "dvec3" )           return DOUBLE_VEC3;
701     if( tname == "dvec4" )           return DOUBLE_VEC4;
702 
703     if( tname == "int" )             return INT;
704     if( tname == "ivec2" )           return INT_VEC2;
705     if( tname == "ivec3" )           return INT_VEC3;
706     if( tname == "ivec4" )           return INT_VEC4;
707 
708     if( tname == "unsigned int" || tname == "uint" ) return UNSIGNED_INT;
709     if( tname == "uvec2" )                           return UNSIGNED_INT_VEC2;
710     if( tname == "uvec3" )                           return UNSIGNED_INT_VEC3;
711     if( tname == "uvec4" )                           return UNSIGNED_INT_VEC4;
712 
713     if( tname == "bool" )            return BOOL;
714     if( tname == "bvec2" )           return BOOL_VEC2;
715     if( tname == "bvec3" )           return BOOL_VEC3;
716     if( tname == "bvec4" )           return BOOL_VEC4;
717 
718     if( tname == "uint64_t" )        return UNSIGNED_INT64;
719     if( tname == "int64_t" )         return INT64;
720 
721     if( tname == "mat2" || tname == "mat2x2" ) return FLOAT_MAT2;
722     if( tname == "mat3" || tname == "mat3x3" ) return FLOAT_MAT3;
723     if( tname == "mat4" || tname == "mat4x4" ) return FLOAT_MAT4;
724     if( tname == "mat2x3" ) return FLOAT_MAT2x3;
725     if( tname == "mat2x4" ) return FLOAT_MAT2x4;
726     if( tname == "mat3x2" ) return FLOAT_MAT3x2;
727     if( tname == "mat3x4" ) return FLOAT_MAT3x4;
728     if( tname == "mat4x2" ) return FLOAT_MAT4x2;
729     if( tname == "mat4x3" ) return FLOAT_MAT4x3;
730 
731     if( tname == "mat2d" || tname == "mat2x2d" ) return DOUBLE_MAT2;
732     if( tname == "mat3d" || tname == "mat3x3d" ) return DOUBLE_MAT3;
733     if( tname == "mat4d" || tname == "mat4x4d" ) return DOUBLE_MAT4;
734     if( tname == "mat2x3d" ) return DOUBLE_MAT2x3;
735     if( tname == "mat2x4d" ) return DOUBLE_MAT2x4;
736     if( tname == "mat3x2d" ) return DOUBLE_MAT3x2;
737     if( tname == "mat3x4d" ) return DOUBLE_MAT3x4;
738     if( tname == "mat4x2d" ) return DOUBLE_MAT4x2;
739     if( tname == "mat4x3d" ) return DOUBLE_MAT4x3;
740 
741     if( tname == "sampler1D" )                 return SAMPLER_1D;
742     if( tname == "sampler2D" )                 return SAMPLER_2D;
743     if( tname == "sampler3D" )                 return SAMPLER_3D;
744     if( tname == "samplerCube" )               return SAMPLER_CUBE;
745     if( tname == "sampler1DShadow" )           return SAMPLER_1D_SHADOW;
746     if( tname == "sampler2DShadow" )           return SAMPLER_2D_SHADOW;
747     if( tname == "sampler1DArray" )            return SAMPLER_1D_ARRAY;
748     if( tname == "sampler2DArray" )            return SAMPLER_2D_ARRAY;
749     if( tname == "samplerCubeMapArray" )       return SAMPLER_CUBE_MAP_ARRAY;
750     if( tname == "sampler1DArrayShadow" )      return SAMPLER_1D_ARRAY_SHADOW;
751     if( tname == "sampler2DArrayShadow" )      return SAMPLER_2D_ARRAY_SHADOW;
752     if( tname == "sampler2DMS" )               return SAMPLER_2D_MULTISAMPLE;
753     if( tname == "sampler2DMSArray" )          return SAMPLER_2D_MULTISAMPLE_ARRAY;
754     if( tname == "samplerCubeShadow" )         return SAMPLER_CUBE_SHADOW;
755     if( tname == "samplerCubeMapArrayShadow" ) return SAMPLER_CUBE_MAP_ARRAY_SHADOW;
756     if( tname == "samplerBuffer" )             return SAMPLER_BUFFER;
757     if( tname == "sampler2DRect" )             return SAMPLER_2D_RECT;
758     if( tname == "sampler2DRectShadow" )       return SAMPLER_2D_RECT_SHADOW;
759 
760     if( tname == "isampler1D" )           return INT_SAMPLER_1D;
761     if( tname == "isampler2D" )           return INT_SAMPLER_2D;
762     if( tname == "isampler3D" )           return INT_SAMPLER_3D;
763     if( tname == "isamplerCube" )         return INT_SAMPLER_CUBE;
764     if( tname == "isampler1DArray" )      return INT_SAMPLER_1D_ARRAY;
765     if( tname == "isampler2DArray" )      return INT_SAMPLER_2D_ARRAY;
766     if( tname == "isamplerCubeMapArray" ) return INT_SAMPLER_CUBE_MAP_ARRAY;
767     if( tname == "isampler2DMS" )         return INT_SAMPLER_2D_MULTISAMPLE;
768     if( tname == "isampler2DMSArray" )    return INT_SAMPLER_2D_MULTISAMPLE_ARRAY;
769     if( tname == "isamplerBuffer" )       return INT_SAMPLER_BUFFER;
770     if( tname == "isampler2DRect" )       return INT_SAMPLER_2D_RECT;
771 
772     if( tname == "usampler1D" )           return UNSIGNED_INT_SAMPLER_1D;
773     if( tname == "usampler2D" )           return UNSIGNED_INT_SAMPLER_2D;
774     if( tname == "usampler3D" )           return UNSIGNED_INT_SAMPLER_3D;
775     if( tname == "usamplerCube" )         return UNSIGNED_INT_SAMPLER_CUBE;
776     if( tname == "usampler1DArray" )      return UNSIGNED_INT_SAMPLER_1D_ARRAY;
777     if( tname == "usampler2DArray" )      return UNSIGNED_INT_SAMPLER_2D_ARRAY;
778     if( tname == "usamplerCubeMapArray" ) return UNSIGNED_INT_SAMPLER_CUBE_MAP_ARRAY;
779     if( tname == "usampler2DMS" )         return UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE;
780     if( tname == "usampler2DMSArray" )    return UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE_ARRAY;
781     if( tname == "usamplerBuffer" )       return UNSIGNED_INT_SAMPLER_BUFFER;
782     if( tname == "usampler2DRect" )       return UNSIGNED_INT_SAMPLER_2D_RECT;
783 
784     if( tname == "image1D" )        return IMAGE_1D;
785     if( tname == "image2D" )        return IMAGE_2D;
786     if( tname == "image3D" )        return IMAGE_3D;
787     if( tname == "image2DRect" )    return IMAGE_2D_RECT;
788     if( tname == "imageCube" )      return IMAGE_CUBE;
789     if( tname == "imageBuffer" )    return IMAGE_BUFFER;
790     if( tname == "image1DArray" )   return IMAGE_1D_ARRAY;
791     if( tname == "image2DArray" )   return IMAGE_2D_ARRAY;
792     if( tname == "imageCubeArray" ) return IMAGE_CUBE_MAP_ARRAY;
793     if( tname == "image2DMS" )      return IMAGE_2D_MULTISAMPLE;
794     if( tname == "image2DMSArray" ) return IMAGE_2D_MULTISAMPLE_ARRAY;
795 
796     if( tname == "iimage1D" )        return INT_IMAGE_1D;
797     if( tname == "iimage2D" )        return INT_IMAGE_2D;
798     if( tname == "iimage3D" )        return INT_IMAGE_3D;
799     if( tname == "iimage2DRect" )    return INT_IMAGE_2D_RECT;
800     if( tname == "iimageCube" )      return INT_IMAGE_CUBE;
801     if( tname == "iimageBuffer" )    return INT_IMAGE_BUFFER;
802     if( tname == "iimage1DArray" )   return INT_IMAGE_1D_ARRAY;
803     if( tname == "iimage2DArray" )   return INT_IMAGE_2D_ARRAY;
804     if( tname == "iimageCubeArray" ) return INT_IMAGE_CUBE_MAP_ARRAY;
805     if( tname == "iimage2DMS" )      return INT_IMAGE_2D_MULTISAMPLE;
806     if( tname == "iimage2DMSArray" ) return INT_IMAGE_2D_MULTISAMPLE_ARRAY;
807 
808     if( tname == "uimage1D" )        return UNSIGNED_INT_IMAGE_1D;
809     if( tname == "uimage2D" )        return UNSIGNED_INT_IMAGE_2D;
810     if( tname == "uimage3D" )        return UNSIGNED_INT_IMAGE_3D;
811     if( tname == "uimage2DRect" )    return UNSIGNED_INT_IMAGE_2D_RECT;
812     if( tname == "uimageCube" )      return UNSIGNED_INT_IMAGE_CUBE;
813     if( tname == "uimageBuffer" )    return UNSIGNED_INT_IMAGE_BUFFER;
814     if( tname == "uimage1DArray" )   return UNSIGNED_INT_IMAGE_1D_ARRAY;
815     if( tname == "uimage2DArray" )   return UNSIGNED_INT_IMAGE_2D_ARRAY;
816     if( tname == "uimageCubeArray" ) return UNSIGNED_INT_IMAGE_CUBE_MAP_ARRAY;
817     if( tname == "uimage2DMS" )      return UNSIGNED_INT_IMAGE_2D_MULTISAMPLE;
818     if( tname == "uimage2DMSArray" ) return UNSIGNED_INT_IMAGE_2D_MULTISAMPLE_ARRAY;
819 
820     return UNDEFINED;
821 }
822 
getGlApiType(Type t)823 Uniform::Type Uniform::getGlApiType( Type t )
824 {
825     switch( t )
826     {
827     case BOOL:
828 
829     case SAMPLER_1D:
830     case SAMPLER_2D:
831     case SAMPLER_3D:
832     case SAMPLER_CUBE:
833     case SAMPLER_1D_SHADOW:
834     case SAMPLER_2D_SHADOW:
835     case SAMPLER_1D_ARRAY:
836     case SAMPLER_2D_ARRAY:
837     case SAMPLER_CUBE_MAP_ARRAY:
838     case SAMPLER_1D_ARRAY_SHADOW:
839     case SAMPLER_2D_ARRAY_SHADOW:
840     case SAMPLER_2D_MULTISAMPLE:
841     case SAMPLER_2D_MULTISAMPLE_ARRAY:
842     case SAMPLER_CUBE_SHADOW:
843     case SAMPLER_CUBE_MAP_ARRAY_SHADOW:
844     case SAMPLER_BUFFER:
845     case SAMPLER_2D_RECT:
846     case SAMPLER_2D_RECT_SHADOW:
847 
848     case INT_SAMPLER_1D:
849     case INT_SAMPLER_2D:
850     case INT_SAMPLER_3D:
851     case INT_SAMPLER_CUBE:
852     case INT_SAMPLER_1D_ARRAY:
853     case INT_SAMPLER_2D_ARRAY:
854     case INT_SAMPLER_CUBE_MAP_ARRAY:
855     case INT_SAMPLER_2D_MULTISAMPLE:
856     case INT_SAMPLER_2D_MULTISAMPLE_ARRAY:
857     case INT_SAMPLER_BUFFER:
858     case INT_SAMPLER_2D_RECT:
859 
860     case UNSIGNED_INT_SAMPLER_1D:
861     case UNSIGNED_INT_SAMPLER_2D:
862     case UNSIGNED_INT_SAMPLER_3D:
863     case UNSIGNED_INT_SAMPLER_CUBE:
864     case UNSIGNED_INT_SAMPLER_1D_ARRAY:
865     case UNSIGNED_INT_SAMPLER_2D_ARRAY:
866     case UNSIGNED_INT_SAMPLER_CUBE_MAP_ARRAY:
867     case UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE:
868     case UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE_ARRAY:
869     case UNSIGNED_INT_SAMPLER_BUFFER:
870     case UNSIGNED_INT_SAMPLER_2D_RECT:
871 
872     case IMAGE_1D:
873     case IMAGE_2D:
874     case IMAGE_3D:
875     case IMAGE_2D_RECT:
876     case IMAGE_CUBE:
877     case IMAGE_BUFFER:
878     case IMAGE_1D_ARRAY:
879     case IMAGE_2D_ARRAY:
880     case IMAGE_CUBE_MAP_ARRAY:
881     case IMAGE_2D_MULTISAMPLE:
882     case IMAGE_2D_MULTISAMPLE_ARRAY:
883 
884     case INT_IMAGE_1D:
885     case INT_IMAGE_2D:
886     case INT_IMAGE_3D:
887     case INT_IMAGE_2D_RECT:
888     case INT_IMAGE_CUBE:
889     case INT_IMAGE_BUFFER:
890     case INT_IMAGE_1D_ARRAY:
891     case INT_IMAGE_2D_ARRAY:
892     case INT_IMAGE_CUBE_MAP_ARRAY:
893     case INT_IMAGE_2D_MULTISAMPLE:
894     case INT_IMAGE_2D_MULTISAMPLE_ARRAY:
895 
896     case UNSIGNED_INT_IMAGE_1D:
897     case UNSIGNED_INT_IMAGE_2D:
898     case UNSIGNED_INT_IMAGE_3D:
899     case UNSIGNED_INT_IMAGE_2D_RECT:
900     case UNSIGNED_INT_IMAGE_CUBE:
901     case UNSIGNED_INT_IMAGE_BUFFER:
902     case UNSIGNED_INT_IMAGE_1D_ARRAY:
903     case UNSIGNED_INT_IMAGE_2D_ARRAY:
904     case UNSIGNED_INT_IMAGE_CUBE_MAP_ARRAY:
905     case UNSIGNED_INT_IMAGE_2D_MULTISAMPLE:
906     case UNSIGNED_INT_IMAGE_2D_MULTISAMPLE_ARRAY:
907         return INT;
908 
909     case BOOL_VEC2:
910         return INT_VEC2;
911 
912     case BOOL_VEC3:
913         return INT_VEC3;
914 
915     case BOOL_VEC4:
916         return INT_VEC4;
917 
918     case UNSIGNED_INT64:
919         return UNSIGNED_INT64;
920 
921     case INT64:
922         return INT64;
923 
924     default:
925         return t;
926     }
927 }
928 
getInternalArrayType(Type t)929 GLenum Uniform::getInternalArrayType( Type t )
930 {
931     switch( t )
932     {
933     case FLOAT:
934     case FLOAT_VEC2:
935     case FLOAT_VEC3:
936     case FLOAT_VEC4:
937     case FLOAT_MAT2:
938     case FLOAT_MAT3:
939     case FLOAT_MAT4:
940     case FLOAT_MAT2x3:
941     case FLOAT_MAT2x4:
942     case FLOAT_MAT3x2:
943     case FLOAT_MAT3x4:
944     case FLOAT_MAT4x2:
945     case FLOAT_MAT4x3:
946         return GL_FLOAT;
947 
948     case DOUBLE:
949     case DOUBLE_VEC2:
950     case DOUBLE_VEC3:
951     case DOUBLE_VEC4:
952     case DOUBLE_MAT2:
953     case DOUBLE_MAT3:
954     case DOUBLE_MAT4:
955     case DOUBLE_MAT2x3:
956     case DOUBLE_MAT2x4:
957     case DOUBLE_MAT3x2:
958     case DOUBLE_MAT3x4:
959     case DOUBLE_MAT4x2:
960     case DOUBLE_MAT4x3:
961         return GL_DOUBLE;
962 
963     case INT:
964     case INT_VEC2:
965     case INT_VEC3:
966     case INT_VEC4:
967     case BOOL:
968     case BOOL_VEC2:
969     case BOOL_VEC3:
970     case BOOL_VEC4:
971     case SAMPLER_1D:
972     case SAMPLER_2D:
973     case SAMPLER_3D:
974     case SAMPLER_CUBE:
975     case SAMPLER_1D_SHADOW:
976     case SAMPLER_2D_SHADOW:
977     case SAMPLER_1D_ARRAY:
978     case SAMPLER_2D_ARRAY:
979     case SAMPLER_CUBE_MAP_ARRAY:
980     case SAMPLER_1D_ARRAY_SHADOW:
981     case SAMPLER_2D_ARRAY_SHADOW:
982     case SAMPLER_2D_MULTISAMPLE:
983     case SAMPLER_2D_MULTISAMPLE_ARRAY:
984     case SAMPLER_CUBE_SHADOW:
985     case SAMPLER_CUBE_MAP_ARRAY_SHADOW:
986     case SAMPLER_BUFFER:
987     case SAMPLER_2D_RECT:
988     case SAMPLER_2D_RECT_SHADOW:
989 
990     case INT_SAMPLER_1D:
991     case INT_SAMPLER_2D:
992     case INT_SAMPLER_3D:
993     case INT_SAMPLER_CUBE:
994     case INT_SAMPLER_1D_ARRAY:
995     case INT_SAMPLER_2D_ARRAY:
996     case INT_SAMPLER_CUBE_MAP_ARRAY:
997     case INT_SAMPLER_2D_MULTISAMPLE:
998     case INT_SAMPLER_2D_MULTISAMPLE_ARRAY:
999     case INT_SAMPLER_BUFFER:
1000     case INT_SAMPLER_2D_RECT:
1001 
1002     case UNSIGNED_INT_SAMPLER_1D:
1003     case UNSIGNED_INT_SAMPLER_2D:
1004     case UNSIGNED_INT_SAMPLER_3D:
1005     case UNSIGNED_INT_SAMPLER_CUBE:
1006     case UNSIGNED_INT_SAMPLER_1D_ARRAY:
1007     case UNSIGNED_INT_SAMPLER_2D_ARRAY:
1008     case UNSIGNED_INT_SAMPLER_CUBE_MAP_ARRAY:
1009     case UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE:
1010     case UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE_ARRAY:
1011     case UNSIGNED_INT_SAMPLER_BUFFER:
1012     case UNSIGNED_INT_SAMPLER_2D_RECT:
1013 
1014     case IMAGE_1D:
1015     case IMAGE_2D:
1016     case IMAGE_3D:
1017     case IMAGE_2D_RECT:
1018     case IMAGE_CUBE:
1019     case IMAGE_BUFFER:
1020     case IMAGE_1D_ARRAY:
1021     case IMAGE_2D_ARRAY:
1022     case IMAGE_CUBE_MAP_ARRAY:
1023     case IMAGE_2D_MULTISAMPLE:
1024     case IMAGE_2D_MULTISAMPLE_ARRAY:
1025 
1026     case INT_IMAGE_1D:
1027     case INT_IMAGE_2D:
1028     case INT_IMAGE_3D:
1029     case INT_IMAGE_2D_RECT:
1030     case INT_IMAGE_CUBE:
1031     case INT_IMAGE_BUFFER:
1032     case INT_IMAGE_1D_ARRAY:
1033     case INT_IMAGE_2D_ARRAY:
1034     case INT_IMAGE_CUBE_MAP_ARRAY:
1035     case INT_IMAGE_2D_MULTISAMPLE:
1036     case INT_IMAGE_2D_MULTISAMPLE_ARRAY:
1037 
1038     case UNSIGNED_INT_IMAGE_1D:
1039     case UNSIGNED_INT_IMAGE_2D:
1040     case UNSIGNED_INT_IMAGE_3D:
1041     case UNSIGNED_INT_IMAGE_2D_RECT:
1042     case UNSIGNED_INT_IMAGE_CUBE:
1043     case UNSIGNED_INT_IMAGE_BUFFER:
1044     case UNSIGNED_INT_IMAGE_1D_ARRAY:
1045     case UNSIGNED_INT_IMAGE_2D_ARRAY:
1046     case UNSIGNED_INT_IMAGE_CUBE_MAP_ARRAY:
1047     case UNSIGNED_INT_IMAGE_2D_MULTISAMPLE:
1048     case UNSIGNED_INT_IMAGE_2D_MULTISAMPLE_ARRAY:
1049         return GL_INT;
1050 
1051     case UNSIGNED_INT:
1052     case UNSIGNED_INT_VEC2:
1053     case UNSIGNED_INT_VEC3:
1054     case UNSIGNED_INT_VEC4:
1055         return GL_UNSIGNED_INT;
1056 
1057     case UNSIGNED_INT64:
1058         return GL_UNSIGNED_INT64_ARB;
1059 
1060     case INT64:
1061         return GL_INT64_ARB;
1062 
1063     default:
1064         return 0;
1065     }
1066 }
1067 
1068 
getNameID(const std::string & name)1069 unsigned int Uniform::getNameID(const std::string& name)
1070 {
1071     typedef std::map<std::string, unsigned int> UniformNameIDMap;
1072     static OpenThreads::Mutex s_mutex_uniformNameIDMap;
1073     static UniformNameIDMap s_uniformNameIDMap;
1074 
1075     OpenThreads::ScopedLock<OpenThreads::Mutex> lock(s_mutex_uniformNameIDMap);
1076     UniformNameIDMap::iterator it = s_uniformNameIDMap.find(name);
1077     if (it != s_uniformNameIDMap.end())
1078     {
1079         return it->second;
1080     }
1081     unsigned int id = s_uniformNameIDMap.size();
1082     s_uniformNameIDMap.insert(UniformNameIDMap::value_type(name, id));
1083     return id;
1084 }
1085 
1086 // Use a proxy to force the initialization of the static variables in the Uniform::getNameID() method during static initialization
OSG_INIT_SINGLETON_PROXY(UniformNameIDStaticInitializationProxy,Uniform::getNameID (std::string ()))1087 OSG_INIT_SINGLETON_PROXY(UniformNameIDStaticInitializationProxy, Uniform::getNameID(std::string()))
1088 
1089 
1090 ///////////////////////////////////////////////////////////////////////////
1091 // value constructors for single-element (ie: non-array) uniforms
1092 
1093 Uniform::Uniform( const char* name, float f ) :
1094     _type(FLOAT), _numElements(1), _modifiedCount(0)
1095 {
1096     setName(name);
1097     allocateDataArray();
1098     set( f );
1099 }
1100 
Uniform(const char * name,const osg::Vec2 & v2)1101 Uniform::Uniform( const char* name, const osg::Vec2& v2 ) :
1102     _type(FLOAT_VEC2), _numElements(1), _modifiedCount(0)
1103 {
1104     setName(name);
1105     allocateDataArray();
1106     set( v2 );
1107 }
1108 
Uniform(const char * name,const osg::Vec3 & v3)1109 Uniform::Uniform( const char* name, const osg::Vec3& v3 ) :
1110      _type(FLOAT_VEC3), _numElements(1), _modifiedCount(0)
1111 {
1112     setName(name);
1113     allocateDataArray();
1114     set( v3 );
1115 }
1116 
Uniform(const char * name,const osg::Vec4 & v4)1117 Uniform::Uniform( const char* name, const osg::Vec4& v4 ) :
1118     _type(FLOAT_VEC4), _numElements(1), _modifiedCount(0)
1119 {
1120     setName(name);
1121     allocateDataArray();
1122     set( v4 );
1123 }
1124 
Uniform(const char * name,const osg::Matrix2 & m2)1125 Uniform::Uniform( const char* name, const osg::Matrix2& m2 ) :
1126     _type(FLOAT_MAT2), _numElements(1), _modifiedCount(0)
1127 {
1128     setName(name);
1129     allocateDataArray();
1130     set( m2 );
1131 }
1132 
Uniform(const char * name,const osg::Matrix3 & m3)1133 Uniform::Uniform( const char* name, const osg::Matrix3& m3 ) :
1134     _type(FLOAT_MAT3), _numElements(1), _modifiedCount(0)
1135 {
1136     setName(name);
1137     allocateDataArray();
1138     set( m3 );
1139 }
1140 
Uniform(const char * name,const osg::Matrixf & m4)1141 Uniform::Uniform( const char* name, const osg::Matrixf& m4 ) :
1142     _type(FLOAT_MAT4), _numElements(1), _modifiedCount(0)
1143 {
1144     setName(name);
1145     allocateDataArray();
1146     set( m4 );
1147 }
1148 
Uniform(const char * name,const osg::Matrix2x3 & m2x3)1149 Uniform::Uniform( const char* name, const osg::Matrix2x3& m2x3 ) :
1150     _type(FLOAT_MAT2x3), _numElements(1), _modifiedCount(0)
1151 {
1152     setName(name);
1153     allocateDataArray();
1154     set( m2x3 );
1155 }
1156 
Uniform(const char * name,const osg::Matrix2x4 & m2x4)1157 Uniform::Uniform( const char* name, const osg::Matrix2x4& m2x4 ) :
1158     _type(FLOAT_MAT2x4), _numElements(1), _modifiedCount(0)
1159 {
1160     setName(name);
1161     allocateDataArray();
1162     set( m2x4 );
1163 }
1164 
Uniform(const char * name,const osg::Matrix3x2 & m3x2)1165 Uniform::Uniform( const char* name, const osg::Matrix3x2& m3x2 ) :
1166     _type(FLOAT_MAT3x2), _numElements(1), _modifiedCount(0)
1167 {
1168     setName(name);
1169     allocateDataArray();
1170     set( m3x2 );
1171 }
1172 
Uniform(const char * name,const osg::Matrix3x4 & m3x4)1173 Uniform::Uniform( const char* name, const osg::Matrix3x4& m3x4 ) :
1174     _type(FLOAT_MAT3x4), _numElements(1), _modifiedCount(0)
1175 {
1176     setName(name);
1177     allocateDataArray();
1178     set( m3x4 );
1179 }
1180 
Uniform(const char * name,const osg::Matrix4x2 & m4x2)1181 Uniform::Uniform( const char* name, const osg::Matrix4x2& m4x2 ) :
1182     _type(FLOAT_MAT4x2), _numElements(1), _modifiedCount(0)
1183 {
1184     setName(name);
1185     allocateDataArray();
1186     set( m4x2 );
1187 }
1188 
Uniform(const char * name,const osg::Matrix4x3 & m4x3)1189 Uniform::Uniform( const char* name, const osg::Matrix4x3& m4x3 ) :
1190     _type(FLOAT_MAT4x3), _numElements(1), _modifiedCount(0)
1191 {
1192     setName(name);
1193     allocateDataArray();
1194     set( m4x3 );
1195 }
1196 
Uniform(const char * name,double d)1197 Uniform::Uniform( const char* name, double d ) :
1198     _type(DOUBLE), _numElements(1), _modifiedCount(0)
1199 {
1200     setName(name);
1201     allocateDataArray();
1202     set( d );
1203 }
1204 
Uniform(const char * name,const osg::Vec2d & v2)1205 Uniform::Uniform( const char* name, const osg::Vec2d& v2 ) :
1206     _type(DOUBLE_VEC2), _numElements(1), _modifiedCount(0)
1207 {
1208     setName(name);
1209     allocateDataArray();
1210     set( v2 );
1211 }
1212 
Uniform(const char * name,const osg::Vec3d & v3)1213 Uniform::Uniform( const char* name, const osg::Vec3d& v3 ) :
1214      _type(DOUBLE_VEC3), _numElements(1), _modifiedCount(0)
1215 {
1216     setName(name);
1217     allocateDataArray();
1218     set( v3 );
1219 }
1220 
Uniform(const char * name,const osg::Vec4d & v4)1221 Uniform::Uniform( const char* name, const osg::Vec4d& v4 ) :
1222     _type(DOUBLE_VEC4), _numElements(1), _modifiedCount(0)
1223 {
1224     setName(name);
1225     allocateDataArray();
1226     set( v4 );
1227 }
1228 
Uniform(const char * name,const osg::Matrix2d & m2)1229 Uniform::Uniform( const char* name, const osg::Matrix2d& m2 ) :
1230     _type(DOUBLE_MAT2), _numElements(1), _modifiedCount(0)
1231 {
1232     setName(name);
1233     allocateDataArray();
1234     set( m2 );
1235 }
1236 
Uniform(const char * name,const osg::Matrix3d & m3)1237 Uniform::Uniform( const char* name, const osg::Matrix3d& m3 ) :
1238     _type(DOUBLE_MAT3), _numElements(1), _modifiedCount(0)
1239 {
1240     setName(name);
1241     allocateDataArray();
1242     set( m3 );
1243 }
1244 
Uniform(const char * name,const osg::Matrixd & m4)1245 Uniform::Uniform( const char* name, const osg::Matrixd& m4 ) :
1246     _type(DOUBLE_MAT4), _numElements(1), _modifiedCount(0)
1247 {
1248     setName(name);
1249     allocateDataArray();
1250     set( m4 );
1251 }
1252 
Uniform(const char * name,const osg::Matrix2x3d & m2x3)1253 Uniform::Uniform( const char* name, const osg::Matrix2x3d& m2x3 ) :
1254     _type(DOUBLE_MAT2x3), _numElements(1), _modifiedCount(0)
1255 {
1256     setName(name);
1257     allocateDataArray();
1258     set( m2x3 );
1259 }
1260 
Uniform(const char * name,const osg::Matrix2x4d & m2x4)1261 Uniform::Uniform( const char* name, const osg::Matrix2x4d& m2x4 ) :
1262     _type(DOUBLE_MAT2x4), _numElements(1), _modifiedCount(0)
1263 {
1264     setName(name);
1265     allocateDataArray();
1266     set( m2x4 );
1267 }
1268 
Uniform(const char * name,const osg::Matrix3x2d & m3x2)1269 Uniform::Uniform( const char* name, const osg::Matrix3x2d& m3x2 ) :
1270     _type(DOUBLE_MAT3x2), _numElements(1), _modifiedCount(0)
1271 {
1272     setName(name);
1273     allocateDataArray();
1274     set( m3x2 );
1275 }
1276 
Uniform(const char * name,const osg::Matrix3x4d & m3x4)1277 Uniform::Uniform( const char* name, const osg::Matrix3x4d& m3x4 ) :
1278     _type(DOUBLE_MAT3x4), _numElements(1), _modifiedCount(0)
1279 {
1280     setName(name);
1281     allocateDataArray();
1282     set( m3x4 );
1283 }
1284 
Uniform(const char * name,const osg::Matrix4x2d & m4x2)1285 Uniform::Uniform( const char* name, const osg::Matrix4x2d& m4x2 ) :
1286     _type(DOUBLE_MAT4x2), _numElements(1), _modifiedCount(0)
1287 {
1288     setName(name);
1289     allocateDataArray();
1290     set( m4x2 );
1291 }
1292 
Uniform(const char * name,const osg::Matrix4x3d & m4x3)1293 Uniform::Uniform( const char* name, const osg::Matrix4x3d& m4x3 ) :
1294     _type(DOUBLE_MAT4x3), _numElements(1), _modifiedCount(0)
1295 {
1296     setName(name);
1297     allocateDataArray();
1298     set( m4x3 );
1299 }
1300 
Uniform(const char * name,int i)1301 Uniform::Uniform( const char* name, int i ) :
1302     _type(INT), _numElements(1), _modifiedCount(0)
1303 {
1304     setName(name);
1305     allocateDataArray();
1306     set( i );
1307 }
1308 
Uniform(const char * name,int i0,int i1)1309 Uniform::Uniform( const char* name, int i0, int i1 ) :
1310     _type(INT_VEC2), _numElements(1), _modifiedCount(0)
1311 {
1312     setName(name);
1313     allocateDataArray();
1314     set( i0, i1 );
1315 }
1316 
Uniform(const char * name,int i0,int i1,int i2)1317 Uniform::Uniform( const char* name, int i0, int i1, int i2 ) :
1318     _type(INT_VEC3), _numElements(1), _modifiedCount(0)
1319 {
1320     setName(name);
1321     allocateDataArray();
1322     set( i0, i1, i2 );
1323 }
1324 
Uniform(const char * name,int i0,int i1,int i2,int i3)1325 Uniform::Uniform( const char* name, int i0, int i1, int i2, int i3 ) :
1326     _type(INT_VEC4), _numElements(1), _modifiedCount(0)
1327 {
1328     setName(name);
1329     allocateDataArray();
1330     set( i0, i1, i2, i3 );
1331 }
1332 
Uniform(const char * name,unsigned int ui)1333 Uniform::Uniform( const char* name, unsigned int ui ) :
1334     _type(UNSIGNED_INT), _numElements(1), _modifiedCount(0)
1335 {
1336     setName(name);
1337     allocateDataArray();
1338     set( ui );
1339 }
1340 
Uniform(const char * name,unsigned int ui0,unsigned int ui1)1341 Uniform::Uniform( const char* name, unsigned int ui0, unsigned int ui1 ) :
1342     _type(UNSIGNED_INT_VEC2), _numElements(1), _modifiedCount(0)
1343 {
1344     setName(name);
1345     allocateDataArray();
1346     set( ui0, ui1 );
1347 }
1348 
Uniform(const char * name,unsigned int ui0,unsigned int ui1,unsigned int ui2)1349 Uniform::Uniform( const char* name, unsigned int ui0, unsigned int ui1, unsigned int ui2 ) :
1350     _type(UNSIGNED_INT_VEC3), _numElements(1), _modifiedCount(0)
1351 {
1352     setName(name);
1353     allocateDataArray();
1354     set( ui0, ui1, ui2 );
1355 }
1356 
Uniform(const char * name,unsigned int ui0,unsigned int ui1,unsigned int ui2,unsigned int ui3)1357 Uniform::Uniform( const char* name, unsigned int ui0, unsigned int ui1, unsigned int ui2, unsigned int ui3 ) :
1358     _type(UNSIGNED_INT_VEC4), _numElements(1), _modifiedCount(0)
1359 {
1360     setName(name);
1361     allocateDataArray();
1362     set( ui0, ui1, ui2, ui3 );
1363 }
1364 
Uniform(const char * name,bool b)1365 Uniform::Uniform( const char* name, bool b ) :
1366     _type(BOOL), _numElements(1), _modifiedCount(0)
1367 {
1368     setName(name);
1369     allocateDataArray();
1370     set( b );
1371 }
1372 
Uniform(const char * name,bool b0,bool b1)1373 Uniform::Uniform( const char* name, bool b0, bool b1 ) :
1374      _type(BOOL_VEC2), _numElements(1), _modifiedCount(0)
1375 {
1376     setName(name);
1377     allocateDataArray();
1378     set( b0, b1 );
1379 }
1380 
Uniform(const char * name,bool b0,bool b1,bool b2)1381 Uniform::Uniform( const char* name, bool b0, bool b1, bool b2 ) :
1382     _type(BOOL_VEC3), _numElements(1), _modifiedCount(0)
1383 {
1384     setName(name);
1385     allocateDataArray();
1386     set( b0, b1, b2 );
1387 }
1388 
Uniform(const char * name,bool b0,bool b1,bool b2,bool b3)1389 Uniform::Uniform( const char* name, bool b0, bool b1, bool b2, bool b3 ) :
1390     _type(BOOL_VEC4), _numElements(1), _modifiedCount(0)
1391 {
1392     setName(name);
1393     allocateDataArray();
1394     set( b0, b1, b2, b3 );
1395 }
Uniform(const char * name,unsigned long long ull)1396 Uniform::Uniform( const char* name, unsigned long long  ull) :
1397     _type(UNSIGNED_INT64), _numElements(1), _modifiedCount(0)
1398 {
1399     setName(name);
1400     allocateDataArray();
1401     set( ull );
1402 }
Uniform(const char * name,long long ll)1403 Uniform::Uniform( const char* name, long long ll) :
1404     _type(INT64), _numElements(1), _modifiedCount(0)
1405 {
1406     setName(name);
1407     allocateDataArray();
1408     set( ll );
1409 }
1410 ////////////////////////////////////////////////////////////////////////
1411 // Value assignment for single-element (ie: non-array) uniforms.
1412 // (For backwards compatibility, if not already configured, set the
1413 // Uniform's _numElements=1)
1414 
set(float f)1415 bool Uniform::set( float f )
1416 {
1417     if( getNumElements() == 0 ) setNumElements(1);
1418     return isScalar() ? setElement(0,f) : false;
1419 }
1420 
set(const osg::Vec2 & v2)1421 bool Uniform::set( const osg::Vec2& v2 )
1422 {
1423     if( getNumElements() == 0 ) setNumElements(1);
1424     return isScalar() ? setElement(0,v2) : false;
1425 }
1426 
set(const osg::Vec3 & v3)1427 bool Uniform::set( const osg::Vec3& v3 )
1428 {
1429     if( getNumElements() == 0 ) setNumElements(1);
1430     return isScalar() ? setElement(0,v3) : false;
1431 }
1432 
set(const osg::Vec4 & v4)1433 bool Uniform::set( const osg::Vec4& v4 )
1434 {
1435     if( getNumElements() == 0 ) setNumElements(1);
1436     return isScalar() ? setElement(0,v4) : false;
1437 }
1438 
set(const osg::Matrix2 & m2)1439 bool Uniform::set( const osg::Matrix2& m2 )
1440 {
1441     if( getNumElements() == 0 ) setNumElements(1);
1442     return isScalar() ? setElement(0,m2) : false;
1443 }
1444 
set(const osg::Matrix3 & m3)1445 bool Uniform::set( const osg::Matrix3& m3 )
1446 {
1447     if( getNumElements() == 0 ) setNumElements(1);
1448     return isScalar() ? setElement(0,m3) : false;
1449 }
1450 
set(const osg::Matrixf & m4)1451 bool Uniform::set( const osg::Matrixf& m4 )
1452 {
1453     if( getNumElements() == 0 ) setNumElements(1);
1454     return isScalar() ? setElement(0,m4) : false;
1455 }
1456 
set(const osg::Matrix2x3 & m2x3)1457 bool Uniform::set( const osg::Matrix2x3& m2x3 )
1458 {
1459     if( getNumElements() == 0 ) setNumElements(1);
1460     return isScalar() ? setElement(0,m2x3) : false;
1461 }
1462 
set(const osg::Matrix2x4 & m2x4)1463 bool Uniform::set( const osg::Matrix2x4& m2x4 )
1464 {
1465     if( getNumElements() == 0 ) setNumElements(1);
1466     return isScalar() ? setElement(0,m2x4) : false;
1467 }
1468 
set(const osg::Matrix3x2 & m3x2)1469 bool Uniform::set( const osg::Matrix3x2& m3x2 )
1470 {
1471     if( getNumElements() == 0 ) setNumElements(1);
1472     return isScalar() ? setElement(0,m3x2) : false;
1473 }
1474 
set(const osg::Matrix3x4 & m3x4)1475 bool Uniform::set( const osg::Matrix3x4& m3x4 )
1476 {
1477     if( getNumElements() == 0 ) setNumElements(1);
1478     return isScalar() ? setElement(0,m3x4) : false;
1479 }
1480 
set(const osg::Matrix4x2 & m4x2)1481 bool Uniform::set( const osg::Matrix4x2& m4x2 )
1482 {
1483     if( getNumElements() == 0 ) setNumElements(1);
1484     return isScalar() ? setElement(0,m4x2) : false;
1485 }
1486 
set(const osg::Matrix4x3 & m4x3)1487 bool Uniform::set( const osg::Matrix4x3& m4x3 )
1488 {
1489     if( getNumElements() == 0 ) setNumElements(1);
1490     return isScalar() ? setElement(0,m4x3) : false;
1491 }
1492 
set(double d)1493 bool Uniform::set( double d )
1494 {
1495     if( getNumElements() == 0 ) setNumElements(1);
1496     return isScalar() ? setElement(0,d) : false;
1497 }
1498 
set(const osg::Vec2d & v2)1499 bool Uniform::set( const osg::Vec2d& v2 )
1500 {
1501     if( getNumElements() == 0 ) setNumElements(1);
1502     return isScalar() ? setElement(0,v2) : false;
1503 }
1504 
set(const osg::Vec3d & v3)1505 bool Uniform::set( const osg::Vec3d& v3 )
1506 {
1507     if( getNumElements() == 0 ) setNumElements(1);
1508     return isScalar() ? setElement(0,v3) : false;
1509 }
1510 
set(const osg::Vec4d & v4)1511 bool Uniform::set( const osg::Vec4d& v4 )
1512 {
1513     if( getNumElements() == 0 ) setNumElements(1);
1514     return isScalar() ? setElement(0,v4) : false;
1515 }
1516 
set(const osg::Matrix2d & m2)1517 bool Uniform::set( const osg::Matrix2d& m2 )
1518 {
1519     if( getNumElements() == 0 ) setNumElements(1);
1520     return isScalar() ? setElement(0,m2) : false;
1521 }
1522 
set(const osg::Matrix3d & m3)1523 bool Uniform::set( const osg::Matrix3d& m3 )
1524 {
1525     if( getNumElements() == 0 ) setNumElements(1);
1526     return isScalar() ? setElement(0,m3) : false;
1527 }
1528 
set(const osg::Matrixd & m4)1529 bool Uniform::set( const osg::Matrixd& m4 )
1530 {
1531     if( getNumElements() == 0 ) setNumElements(1);
1532     return isScalar() ? setElement(0,m4) : false;
1533 }
1534 
set(const osg::Matrix2x3d & m2x3)1535 bool Uniform::set( const osg::Matrix2x3d& m2x3 )
1536 {
1537     if( getNumElements() == 0 ) setNumElements(1);
1538     return isScalar() ? setElement(0,m2x3) : false;
1539 }
1540 
set(const osg::Matrix2x4d & m2x4)1541 bool Uniform::set( const osg::Matrix2x4d& m2x4 )
1542 {
1543     if( getNumElements() == 0 ) setNumElements(1);
1544     return isScalar() ? setElement(0,m2x4) : false;
1545 }
1546 
set(const osg::Matrix3x2d & m3x2)1547 bool Uniform::set( const osg::Matrix3x2d& m3x2 )
1548 {
1549     if( getNumElements() == 0 ) setNumElements(1);
1550     return isScalar() ? setElement(0,m3x2) : false;
1551 }
1552 
set(const osg::Matrix3x4d & m3x4)1553 bool Uniform::set( const osg::Matrix3x4d& m3x4 )
1554 {
1555     if( getNumElements() == 0 ) setNumElements(1);
1556     return isScalar() ? setElement(0,m3x4) : false;
1557 }
1558 
set(const osg::Matrix4x2d & m4x2)1559 bool Uniform::set( const osg::Matrix4x2d& m4x2 )
1560 {
1561     if( getNumElements() == 0 ) setNumElements(1);
1562     return isScalar() ? setElement(0,m4x2) : false;
1563 }
1564 
set(const osg::Matrix4x3d & m4x3)1565 bool Uniform::set( const osg::Matrix4x3d& m4x3 )
1566 {
1567     if( getNumElements() == 0 ) setNumElements(1);
1568     return isScalar() ? setElement(0,m4x3) : false;
1569 }
1570 
set(int i)1571 bool Uniform::set( int i )
1572 {
1573     if( getNumElements() == 0 ) setNumElements(1);
1574     return isScalar() ? setElement(0,i) : false;
1575 }
1576 
set(int i0,int i1)1577 bool Uniform::set( int i0, int i1 )
1578 {
1579     if( getNumElements() == 0 ) setNumElements(1);
1580     return isScalar() ? setElement(0,i0,i1) : false;
1581 }
1582 
set(int i0,int i1,int i2)1583 bool Uniform::set( int i0, int i1, int i2 )
1584 {
1585     if( getNumElements() == 0 ) setNumElements(1);
1586     return isScalar() ? setElement(0,i0,i1,i2) : false;
1587 }
1588 
set(int i0,int i1,int i2,int i3)1589 bool Uniform::set( int i0, int i1, int i2, int i3 )
1590 {
1591     if( getNumElements() == 0 ) setNumElements(1);
1592     return isScalar() ? setElement(0,i0,i1,i2,i3) : false;
1593 }
1594 
set(unsigned int ui)1595 bool Uniform::set( unsigned int ui )
1596 {
1597     if( getNumElements() == 0 ) setNumElements(1);
1598     return isScalar() ? setElement(0,ui) : false;
1599 }
1600 
set(unsigned int ui0,unsigned int ui1)1601 bool Uniform::set( unsigned int ui0, unsigned int ui1 )
1602 {
1603     if( getNumElements() == 0 ) setNumElements(1);
1604     return isScalar() ? setElement(0,ui0,ui1) : false;
1605 }
1606 
set(unsigned int ui0,unsigned int ui1,unsigned int ui2)1607 bool Uniform::set( unsigned int ui0, unsigned int ui1, unsigned int ui2 )
1608 {
1609     if( getNumElements() == 0 ) setNumElements(1);
1610     return isScalar() ? setElement(0,ui0,ui1,ui2) : false;
1611 }
1612 
set(unsigned int ui0,unsigned int ui1,unsigned int ui2,unsigned int ui3)1613 bool Uniform::set( unsigned int ui0, unsigned int ui1, unsigned int ui2, unsigned int ui3 )
1614 {
1615     if( getNumElements() == 0 ) setNumElements(1);
1616     return isScalar() ? setElement(0,ui0,ui1,ui2,ui3) : false;
1617 }
1618 
set(bool b)1619 bool Uniform::set( bool b )
1620 {
1621     if( getNumElements() == 0 ) setNumElements(1);
1622     return isScalar() ? setElement(0,b) : false;
1623 }
1624 
set(bool b0,bool b1)1625 bool Uniform::set( bool b0, bool b1 )
1626 {
1627     if( getNumElements() == 0 ) setNumElements(1);
1628     return isScalar() ? setElement(0,b0,b1) : false;
1629 }
1630 
set(bool b0,bool b1,bool b2)1631 bool Uniform::set( bool b0, bool b1, bool b2 )
1632 {
1633     if( getNumElements() == 0 ) setNumElements(1);
1634     return isScalar() ? setElement(0,b0,b1,b2) : false;
1635 }
1636 
set(bool b0,bool b1,bool b2,bool b3)1637 bool Uniform::set( bool b0, bool b1, bool b2, bool b3 )
1638 {
1639     if( getNumElements() == 0 ) setNumElements(1);
1640     return isScalar() ? setElement(0,b0,b1,b2,b3) : false;
1641 }
1642 
1643 
set(unsigned long long ull)1644 bool Uniform::set( unsigned long long  ull )
1645 {
1646     if( getNumElements() == 0 ) setNumElements(1);
1647     return isScalar() ? setElement(0,ull) : false;
1648 }
set(long long ll)1649 bool Uniform::set( long long ll )
1650 {
1651     if( getNumElements() == 0 ) setNumElements(1);
1652     return isScalar() ? setElement(0,ll) : false;
1653 }
1654 ///////////////////////////////////////////////////////////////////////////
1655 // Value query for single-element (ie: non-array) uniforms.
1656 
get(float & f) const1657 bool Uniform::get( float& f ) const
1658 {
1659     return isScalar() ? getElement(0,f) : false;
1660 }
1661 
get(osg::Vec2 & v2) const1662 bool Uniform::get( osg::Vec2& v2 ) const
1663 {
1664     return isScalar() ? getElement(0,v2) : false;
1665 }
1666 
get(osg::Vec3 & v3) const1667 bool Uniform::get( osg::Vec3& v3 ) const
1668 {
1669     return isScalar() ? getElement(0,v3) : false;
1670 }
1671 
get(osg::Vec4 & v4) const1672 bool Uniform::get( osg::Vec4& v4 ) const
1673 {
1674     return isScalar() ? getElement(0,v4) : false;
1675 }
1676 
get(osg::Matrix2 & m2) const1677 bool Uniform::get( osg::Matrix2& m2 ) const
1678 {
1679     return isScalar() ? getElement(0,m2) : false;
1680 }
1681 
get(osg::Matrix3 & m3) const1682 bool Uniform::get( osg::Matrix3& m3 ) const
1683 {
1684     return isScalar() ? getElement(0,m3) : false;
1685 }
1686 
get(osg::Matrixf & m4) const1687 bool Uniform::get( osg::Matrixf& m4 ) const
1688 {
1689     return isScalar() ? getElement(0,m4) : false;
1690 }
1691 
get(osg::Matrix2x3 & m2x3) const1692 bool Uniform::get( osg::Matrix2x3& m2x3 ) const
1693 {
1694     return isScalar() ? getElement(0,m2x3) : false;
1695 }
1696 
get(osg::Matrix2x4 & m2x4) const1697 bool Uniform::get( osg::Matrix2x4& m2x4 ) const
1698 {
1699     return isScalar() ? getElement(0,m2x4) : false;
1700 }
1701 
get(osg::Matrix3x2 & m3x2) const1702 bool Uniform::get( osg::Matrix3x2& m3x2 ) const
1703 {
1704     return isScalar() ? getElement(0,m3x2) : false;
1705 }
1706 
get(osg::Matrix3x4 & m3x4) const1707 bool Uniform::get( osg::Matrix3x4& m3x4 ) const
1708 {
1709     return isScalar() ? getElement(0,m3x4) : false;
1710 }
1711 
get(osg::Matrix4x2 & m4x2) const1712 bool Uniform::get( osg::Matrix4x2& m4x2 ) const
1713 {
1714     return isScalar() ? getElement(0,m4x2) : false;
1715 }
1716 
get(osg::Matrix4x3 & m4x3) const1717 bool Uniform::get( osg::Matrix4x3& m4x3 ) const
1718 {
1719     return isScalar() ? getElement(0,m4x3) : false;
1720 }
1721 
get(double & d) const1722 bool Uniform::get( double& d ) const
1723 {
1724     return isScalar() ? getElement(0,d) : false;
1725 }
1726 
get(osg::Vec2d & v2) const1727 bool Uniform::get( osg::Vec2d& v2 ) const
1728 {
1729     return isScalar() ? getElement(0,v2) : false;
1730 }
1731 
get(osg::Vec3d & v3) const1732 bool Uniform::get( osg::Vec3d& v3 ) const
1733 {
1734     return isScalar() ? getElement(0,v3) : false;
1735 }
1736 
get(osg::Vec4d & v4) const1737 bool Uniform::get( osg::Vec4d& v4 ) const
1738 {
1739     return isScalar() ? getElement(0,v4) : false;
1740 }
1741 
get(osg::Matrix2d & m2) const1742 bool Uniform::get( osg::Matrix2d& m2 ) const
1743 {
1744     return isScalar() ? getElement(0,m2) : false;
1745 }
1746 
get(osg::Matrix3d & m3) const1747 bool Uniform::get( osg::Matrix3d& m3 ) const
1748 {
1749     return isScalar() ? getElement(0,m3) : false;
1750 }
1751 
get(osg::Matrixd & m4) const1752 bool Uniform::get( osg::Matrixd& m4 ) const
1753 {
1754     return isScalar() ? getElement(0,m4) : false;
1755 }
1756 
get(osg::Matrix2x3d & m2x3) const1757 bool Uniform::get( osg::Matrix2x3d& m2x3 ) const
1758 {
1759     return isScalar() ? getElement(0,m2x3) : false;
1760 }
1761 
get(osg::Matrix2x4d & m2x4) const1762 bool Uniform::get( osg::Matrix2x4d& m2x4 ) const
1763 {
1764     return isScalar() ? getElement(0,m2x4) : false;
1765 }
1766 
get(osg::Matrix3x2d & m3x2) const1767 bool Uniform::get( osg::Matrix3x2d& m3x2 ) const
1768 {
1769     return isScalar() ? getElement(0,m3x2) : false;
1770 }
1771 
get(osg::Matrix3x4d & m3x4) const1772 bool Uniform::get( osg::Matrix3x4d& m3x4 ) const
1773 {
1774     return isScalar() ? getElement(0,m3x4) : false;
1775 }
1776 
get(osg::Matrix4x2d & m4x2) const1777 bool Uniform::get( osg::Matrix4x2d& m4x2 ) const
1778 {
1779     return isScalar() ? getElement(0,m4x2) : false;
1780 }
1781 
get(osg::Matrix4x3d & m4x3) const1782 bool Uniform::get( osg::Matrix4x3d& m4x3 ) const
1783 {
1784     return isScalar() ? getElement(0,m4x3) : false;
1785 }
1786 
get(int & i) const1787 bool Uniform::get( int& i ) const
1788 {
1789     return isScalar() ? getElement(0,i) : false;
1790 }
1791 
get(int & i0,int & i1) const1792 bool Uniform::get( int& i0, int& i1 ) const
1793 {
1794     return isScalar() ? getElement(0,i0,i1) : false;
1795 }
1796 
get(int & i0,int & i1,int & i2) const1797 bool Uniform::get( int& i0, int& i1, int& i2 ) const
1798 {
1799     return isScalar() ? getElement(0,i0,i1,i2) : false;
1800 }
1801 
get(int & i0,int & i1,int & i2,int & i3) const1802 bool Uniform::get( int& i0, int& i1, int& i2, int& i3 ) const
1803 {
1804     return isScalar() ? getElement(0,i0,i1,i2,i3) : false;
1805 }
1806 
get(unsigned int & ui) const1807 bool Uniform::get( unsigned int& ui ) const
1808 {
1809     return isScalar() ? getElement(0,ui) : false;
1810 }
1811 
get(unsigned int & ui0,unsigned int & ui1) const1812 bool Uniform::get( unsigned int& ui0, unsigned int& ui1 ) const
1813 {
1814     return isScalar() ? getElement(0,ui0,ui1) : false;
1815 }
1816 
get(unsigned int & ui0,unsigned int & ui1,unsigned int & ui2) const1817 bool Uniform::get( unsigned int& ui0, unsigned int& ui1, unsigned int& ui2 ) const
1818 {
1819     return isScalar() ? getElement(0,ui0,ui1,ui2) : false;
1820 }
1821 
get(unsigned int & ui0,unsigned int & ui1,unsigned int & ui2,unsigned int & ui3) const1822 bool Uniform::get( unsigned int& ui0, unsigned int& ui1, unsigned int& ui2, unsigned int& ui3 ) const
1823 {
1824     return isScalar() ? getElement(0,ui0,ui1,ui2,ui3) : false;
1825 }
1826 
get(bool & b) const1827 bool Uniform::get( bool& b ) const
1828 {
1829     return isScalar() ? getElement(0,b) : false;
1830 }
1831 
get(bool & b0,bool & b1) const1832 bool Uniform::get( bool& b0, bool& b1 ) const
1833 {
1834     return isScalar() ? getElement(0,b0,b1) : false;
1835 }
1836 
get(bool & b0,bool & b1,bool & b2) const1837 bool Uniform::get( bool& b0, bool& b1, bool& b2 ) const
1838 {
1839     return isScalar() ? getElement(0,b0,b1,b2) : false;
1840 }
1841 
get(bool & b0,bool & b1,bool & b2,bool & b3) const1842 bool Uniform::get( bool& b0, bool& b1, bool& b2, bool& b3 ) const
1843 {
1844     return isScalar() ? getElement(0,b0,b1,b2,b3) : false;
1845 }
1846 
get(unsigned long long & ull) const1847 bool Uniform::get( unsigned long long& ull ) const
1848 {
1849     return isScalar() ? getElement(0,ull) : false;
1850 }
get(long long & ll) const1851 bool Uniform::get( long long& ll ) const
1852 {
1853     return isScalar() ? getElement(0,ll) : false;
1854 }
1855 ///////////////////////////////////////////////////////////////////////////
1856 // Value assignment for array uniforms.
1857 
setElement(unsigned int index,float f)1858 bool Uniform::setElement( unsigned int index, float f )
1859 {
1860     if( index>=getNumElements() || !isCompatibleType(FLOAT) ) return false;
1861     unsigned int j = index * getTypeNumComponents(getType());
1862     (*_floatArray)[j] = f;
1863     dirty();
1864     return true;
1865 }
1866 
setElement(unsigned int index,const osg::Vec2 & v2)1867 bool Uniform::setElement( unsigned int index, const osg::Vec2& v2 )
1868 {
1869     if( index>=getNumElements() || !isCompatibleType(FLOAT_VEC2) ) return false;
1870     unsigned int j = index * getTypeNumComponents(getType());
1871     (*_floatArray)[j] = v2.x();
1872     (*_floatArray)[j+1] = v2.y();
1873     dirty();
1874     return true;
1875 }
1876 
setElement(unsigned int index,const osg::Vec3 & v3)1877 bool Uniform::setElement( unsigned int index, const osg::Vec3& v3 )
1878 {
1879     if( index>=getNumElements() || !isCompatibleType(FLOAT_VEC3) ) return false;
1880     unsigned int j = index * getTypeNumComponents(getType());
1881     (*_floatArray)[j] = v3.x();
1882     (*_floatArray)[j+1] = v3.y();
1883     (*_floatArray)[j+2] = v3.z();
1884     dirty();
1885     return true;
1886 }
1887 
setElement(unsigned int index,const osg::Vec4 & v4)1888 bool Uniform::setElement( unsigned int index, const osg::Vec4& v4 )
1889 {
1890     if( index>=getNumElements() || !isCompatibleType(FLOAT_VEC4) ) return false;
1891     unsigned int j = index * getTypeNumComponents(getType());
1892     (*_floatArray)[j] = v4.x();
1893     (*_floatArray)[j+1] = v4.y();
1894     (*_floatArray)[j+2] = v4.z();
1895     (*_floatArray)[j+3] = v4.w();
1896     dirty();
1897     return true;
1898 }
1899 
setElement(unsigned int index,const osg::Matrix2 & m2)1900 bool Uniform::setElement( unsigned int index, const osg::Matrix2& m2 )
1901 {
1902     if( index>=getNumElements() || !isCompatibleType(FLOAT_MAT2) ) return false;
1903     unsigned int j = index * getTypeNumComponents(getType());
1904     for( int i = 0; i < 4; ++i ) (*_floatArray)[j+i] = m2[i];
1905     dirty();
1906     return true;
1907 }
1908 
setElement(unsigned int index,const osg::Matrix3 & m3)1909 bool Uniform::setElement( unsigned int index, const osg::Matrix3& m3 )
1910 {
1911     if( index>=getNumElements() || !isCompatibleType(FLOAT_MAT3) ) return false;
1912     unsigned int j = index * getTypeNumComponents(getType());
1913     for( int i = 0; i < 9; ++i ) (*_floatArray)[j+i] = m3[i];
1914     dirty();
1915     return true;
1916 }
1917 
setElement(unsigned int index,const osg::Matrixf & m4)1918 bool Uniform::setElement( unsigned int index, const osg::Matrixf& m4 )
1919 {
1920     if( index>=getNumElements() || !isCompatibleType(FLOAT_MAT4) ) return false;
1921     unsigned int j = index * getTypeNumComponents(getType());
1922     const Matrixf::value_type* p = m4.ptr();
1923     for( int i = 0; i < 16; ++i ) (*_floatArray)[j+i] = p[i];
1924     dirty();
1925     return true;
1926 }
1927 
setElement(unsigned int index,const osg::Matrix2x3 & m2x3)1928 bool Uniform::setElement( unsigned int index, const osg::Matrix2x3& m2x3 )
1929 {
1930     if( index>=getNumElements() || !isCompatibleType(FLOAT_MAT2x3) ) return false;
1931     unsigned int j = index * getTypeNumComponents(getType());
1932     for( int i = 0; i < 6; ++i ) (*_floatArray)[j+i] = m2x3[i];
1933     dirty();
1934     return true;
1935 }
1936 
setElement(unsigned int index,const osg::Matrix2x4 & m2x4)1937 bool Uniform::setElement( unsigned int index, const osg::Matrix2x4& m2x4 )
1938 {
1939     if( index>=getNumElements() || !isCompatibleType(FLOAT_MAT2x4) ) return false;
1940     unsigned int j = index * getTypeNumComponents(getType());
1941     for( int i = 0; i < 8; ++i ) (*_floatArray)[j+i] = m2x4[i];
1942     dirty();
1943     return true;
1944 }
1945 
setElement(unsigned int index,const osg::Matrix3x2 & m3x2)1946 bool Uniform::setElement( unsigned int index, const osg::Matrix3x2& m3x2 )
1947 {
1948     if( index>=getNumElements() || !isCompatibleType(FLOAT_MAT3x2) ) return false;
1949     unsigned int j = index * getTypeNumComponents(getType());
1950     for( int i = 0; i < 6; ++i ) (*_floatArray)[j+i] = m3x2[i];
1951     dirty();
1952     return true;
1953 }
1954 
setElement(unsigned int index,const osg::Matrix3x4 & m3x4)1955 bool Uniform::setElement( unsigned int index, const osg::Matrix3x4& m3x4 )
1956 {
1957     if( index>=getNumElements() || !isCompatibleType(FLOAT_MAT3x4) ) return false;
1958     unsigned int j = index * getTypeNumComponents(getType());
1959     for( int i = 0; i < 12; ++i ) (*_floatArray)[j+i] = m3x4[i];
1960     dirty();
1961     return true;
1962 }
1963 
setElement(unsigned int index,const osg::Matrix4x2 & m4x2)1964 bool Uniform::setElement( unsigned int index, const osg::Matrix4x2& m4x2 )
1965 {
1966     if( index>=getNumElements() || !isCompatibleType(FLOAT_MAT4x2) ) return false;
1967     unsigned int j = index * getTypeNumComponents(getType());
1968     for( int i = 0; i < 8; ++i ) (*_floatArray)[j+i] = m4x2[i];
1969     dirty();
1970     return true;
1971 }
1972 
setElement(unsigned int index,const osg::Matrix4x3 & m4x3)1973 bool Uniform::setElement( unsigned int index, const osg::Matrix4x3& m4x3 )
1974 {
1975     if( index>=getNumElements() || !isCompatibleType(FLOAT_MAT4x3) ) return false;
1976     unsigned int j = index * getTypeNumComponents(getType());
1977     for( int i = 0; i < 12; ++i ) (*_floatArray)[j+i] = m4x3[i];
1978     dirty();
1979     return true;
1980 }
1981 
setElement(unsigned int index,double d)1982 bool Uniform::setElement( unsigned int index, double d )
1983 {
1984     if( index>=getNumElements() || !isCompatibleType(DOUBLE) ) return false;
1985     unsigned int j = index * getTypeNumComponents(getType());
1986     (*_doubleArray)[j] = d;
1987     dirty();
1988     return true;
1989 }
1990 
setElement(unsigned int index,const osg::Vec2d & v2)1991 bool Uniform::setElement( unsigned int index, const osg::Vec2d& v2 )
1992 {
1993     if( index>=getNumElements() || !isCompatibleType(DOUBLE_VEC2) ) return false;
1994     unsigned int j = index * getTypeNumComponents(getType());
1995     (*_doubleArray)[j] = v2.x();
1996     (*_doubleArray)[j+1] = v2.y();
1997     dirty();
1998     return true;
1999 }
2000 
setElement(unsigned int index,const osg::Vec3d & v3)2001 bool Uniform::setElement( unsigned int index, const osg::Vec3d& v3 )
2002 {
2003     if( index>=getNumElements() || !isCompatibleType(DOUBLE_VEC3) ) return false;
2004     unsigned int j = index * getTypeNumComponents(getType());
2005     (*_doubleArray)[j] = v3.x();
2006     (*_doubleArray)[j+1] = v3.y();
2007     (*_doubleArray)[j+2] = v3.z();
2008     dirty();
2009     return true;
2010 }
2011 
setElement(unsigned int index,const osg::Vec4d & v4)2012 bool Uniform::setElement( unsigned int index, const osg::Vec4d& v4 )
2013 {
2014     if( index>=getNumElements() || !isCompatibleType(DOUBLE_VEC4) ) return false;
2015     unsigned int j = index * getTypeNumComponents(getType());
2016     (*_doubleArray)[j] = v4.x();
2017     (*_doubleArray)[j+1] = v4.y();
2018     (*_doubleArray)[j+2] = v4.z();
2019     (*_doubleArray)[j+3] = v4.w();
2020     dirty();
2021     return true;
2022 }
2023 
setElement(unsigned int index,const osg::Matrix2d & m2)2024 bool Uniform::setElement( unsigned int index, const osg::Matrix2d& m2 )
2025 {
2026     if( index>=getNumElements() || !isCompatibleType(DOUBLE_MAT2) ) return false;
2027     unsigned int j = index * getTypeNumComponents(getType());
2028     for( int i = 0; i < 4; ++i ) (*_doubleArray)[j+i] = m2[i];
2029     dirty();
2030     return true;
2031 }
2032 
setElement(unsigned int index,const osg::Matrix3d & m3)2033 bool Uniform::setElement( unsigned int index, const osg::Matrix3d& m3 )
2034 {
2035     if( index>=getNumElements() || !isCompatibleType(DOUBLE_MAT3) ) return false;
2036     unsigned int j = index * getTypeNumComponents(getType());
2037     for( int i = 0; i < 9; ++i ) (*_doubleArray)[j+i] = m3[i];
2038     dirty();
2039     return true;
2040 }
2041 
setElement(unsigned int index,const osg::Matrixd & m4)2042 bool Uniform::setElement( unsigned int index, const osg::Matrixd& m4 )
2043 {
2044     if( index>=getNumElements() || !isCompatibleType(DOUBLE_MAT4, FLOAT_MAT4) ) return false;
2045     unsigned int j = index * getTypeNumComponents(getType());
2046 
2047     if (_type == DOUBLE_MAT4)
2048     {
2049         const Matrixd::value_type* p = m4.ptr();
2050         for( int i = 0; i < 16; ++i ) (*_doubleArray)[j+i] = p[i];
2051     }
2052     else //if (_type == FLOAT_MAT4) for backward compatibility only
2053     {
2054         const Matrixd::value_type* p = m4.ptr();
2055         for( int i = 0; i < 16; ++i ) (*_floatArray)[j+i] = static_cast<float>(p[i]);
2056     }
2057     dirty();
2058     return true;
2059 }
2060 
setElement(unsigned int index,const osg::Matrix2x3d & m2x3)2061 bool Uniform::setElement( unsigned int index, const osg::Matrix2x3d& m2x3 )
2062 {
2063     if( index>=getNumElements() || !isCompatibleType(DOUBLE_MAT2x3) ) return false;
2064     unsigned int j = index * getTypeNumComponents(getType());
2065     for( int i = 0; i < 6; ++i ) (*_doubleArray)[j+i] = m2x3[i];
2066     dirty();
2067     return true;
2068 }
2069 
setElement(unsigned int index,const osg::Matrix2x4d & m2x4)2070 bool Uniform::setElement( unsigned int index, const osg::Matrix2x4d& m2x4 )
2071 {
2072     if( index>=getNumElements() || !isCompatibleType(DOUBLE_MAT2x4) ) return false;
2073     unsigned int j = index * getTypeNumComponents(getType());
2074     for( int i = 0; i < 8; ++i ) (*_doubleArray)[j+i] = m2x4[i];
2075     dirty();
2076     return true;
2077 }
2078 
setElement(unsigned int index,const osg::Matrix3x2d & m3x2)2079 bool Uniform::setElement( unsigned int index, const osg::Matrix3x2d& m3x2 )
2080 {
2081     if( index>=getNumElements() || !isCompatibleType(DOUBLE_MAT3x2) ) return false;
2082     unsigned int j = index * getTypeNumComponents(getType());
2083     for( int i = 0; i < 6; ++i ) (*_doubleArray)[j+i] = m3x2[i];
2084     dirty();
2085     return true;
2086 }
2087 
setElement(unsigned int index,const osg::Matrix3x4d & m3x4)2088 bool Uniform::setElement( unsigned int index, const osg::Matrix3x4d& m3x4 )
2089 {
2090     if( index>=getNumElements() || !isCompatibleType(DOUBLE_MAT3x4) ) return false;
2091     unsigned int j = index * getTypeNumComponents(getType());
2092     for( int i = 0; i < 12; ++i ) (*_doubleArray)[j+i] = m3x4[i];
2093     dirty();
2094     return true;
2095 }
2096 
setElement(unsigned int index,const osg::Matrix4x2d & m4x2)2097 bool Uniform::setElement( unsigned int index, const osg::Matrix4x2d& m4x2 )
2098 {
2099     if( index>=getNumElements() || !isCompatibleType(DOUBLE_MAT4x2) ) return false;
2100     unsigned int j = index * getTypeNumComponents(getType());
2101     for( int i = 0; i < 8; ++i ) (*_doubleArray)[j+i] = m4x2[i];
2102     dirty();
2103     return true;
2104 }
2105 
setElement(unsigned int index,const osg::Matrix4x3d & m4x3)2106 bool Uniform::setElement( unsigned int index, const osg::Matrix4x3d& m4x3 )
2107 {
2108     if( index>=getNumElements() || !isCompatibleType(DOUBLE_MAT4x3) ) return false;
2109     unsigned int j = index * getTypeNumComponents(getType());
2110     for( int i = 0; i < 12; ++i ) (*_doubleArray)[j+i] = m4x3[i];
2111     dirty();
2112     return true;
2113 }
2114 
setElement(unsigned int index,int i)2115 bool Uniform::setElement( unsigned int index, int i )
2116 {
2117     if( index>=getNumElements() || !isCompatibleType(INT) ) return false;
2118     unsigned int j = index * getTypeNumComponents(getType());
2119     (*_intArray)[j] = i;
2120     dirty();
2121     return true;
2122 }
2123 
setElement(unsigned int index,int i0,int i1)2124 bool Uniform::setElement( unsigned int index, int i0, int i1 )
2125 {
2126     if( index>=getNumElements() || !isCompatibleType(INT_VEC2) ) return false;
2127     unsigned int j = index * getTypeNumComponents(getType());
2128     (*_intArray)[j] = i0;
2129     (*_intArray)[j+1] = i1;
2130     dirty();
2131     return true;
2132 }
2133 
setElement(unsigned int index,int i0,int i1,int i2)2134 bool Uniform::setElement( unsigned int index, int i0, int i1, int i2 )
2135 {
2136     if( index>=getNumElements() || !isCompatibleType(INT_VEC3) ) return false;
2137     unsigned int j = index * getTypeNumComponents(getType());
2138     (*_intArray)[j] = i0;
2139     (*_intArray)[j+1] = i1;
2140     (*_intArray)[j+2] = i2;
2141     dirty();
2142     return true;
2143 }
2144 
setElement(unsigned int index,int i0,int i1,int i2,int i3)2145 bool Uniform::setElement( unsigned int index, int i0, int i1, int i2, int i3 )
2146 {
2147     if( index>=getNumElements() || !isCompatibleType(INT_VEC4) ) return false;
2148     unsigned int j = index * getTypeNumComponents(getType());
2149     (*_intArray)[j] = i0;
2150     (*_intArray)[j+1] = i1;
2151     (*_intArray)[j+2] = i2;
2152     (*_intArray)[j+3] = i3;
2153     dirty();
2154     return true;
2155 }
2156 
setElement(unsigned int index,unsigned int ui)2157 bool Uniform::setElement( unsigned int index, unsigned int ui )
2158 {
2159     if( index>=getNumElements() || !isCompatibleType(UNSIGNED_INT) ) return false;
2160     unsigned int j = index * getTypeNumComponents(getType());
2161     (*_uintArray)[j] = ui;
2162     dirty();
2163     return true;
2164 }
2165 
setElement(unsigned int index,unsigned int ui0,unsigned int ui1)2166 bool Uniform::setElement( unsigned int index, unsigned int ui0, unsigned int ui1 )
2167 {
2168     if( index>=getNumElements() || !isCompatibleType(UNSIGNED_INT_VEC2) ) return false;
2169     unsigned int j = index * getTypeNumComponents(getType());
2170     (*_uintArray)[j] = ui0;
2171     (*_uintArray)[j+1] = ui1;
2172     dirty();
2173     return true;
2174 }
2175 
setElement(unsigned int index,unsigned int ui0,unsigned int ui1,unsigned int ui2)2176 bool Uniform::setElement( unsigned int index, unsigned int ui0, unsigned int ui1, unsigned int ui2 )
2177 {
2178     if( index>=getNumElements() || !isCompatibleType(UNSIGNED_INT_VEC3) ) return false;
2179     unsigned int j = index * getTypeNumComponents(getType());
2180     (*_uintArray)[j] = ui0;
2181     (*_uintArray)[j+1] = ui1;
2182     (*_uintArray)[j+2] = ui2;
2183     dirty();
2184     return true;
2185 }
2186 
setElement(unsigned int index,unsigned int ui0,unsigned int ui1,unsigned int ui2,unsigned int ui3)2187 bool Uniform::setElement( unsigned int index, unsigned int ui0, unsigned int ui1, unsigned int ui2, unsigned int ui3 )
2188 {
2189     if( index>=getNumElements() || !isCompatibleType(UNSIGNED_INT_VEC4) ) return false;
2190     unsigned int j = index * getTypeNumComponents(getType());
2191     (*_uintArray)[j] = ui0;
2192     (*_uintArray)[j+1] = ui1;
2193     (*_uintArray)[j+2] = ui2;
2194     (*_uintArray)[j+3] = ui3;
2195     dirty();
2196     return true;
2197 }
2198 
setElement(unsigned int index,bool b)2199 bool Uniform::setElement( unsigned int index, bool b )
2200 {
2201     if( index>=getNumElements() || !isCompatibleType(BOOL) ) return false;
2202     unsigned int j = index * getTypeNumComponents(getType());
2203     (*_intArray)[j] = b;
2204     dirty();
2205     return true;
2206 }
2207 
setElement(unsigned int index,bool b0,bool b1)2208 bool Uniform::setElement( unsigned int index, bool b0, bool b1 )
2209 {
2210     if( index>=getNumElements() || !isCompatibleType(BOOL_VEC2) ) return false;
2211     unsigned int j = index * getTypeNumComponents(getType());
2212     (*_intArray)[j] = b0;
2213     (*_intArray)[j+1] = b1;
2214     dirty();
2215     return true;
2216 }
2217 
setElement(unsigned int index,bool b0,bool b1,bool b2)2218 bool Uniform::setElement( unsigned int index, bool b0, bool b1, bool b2 )
2219 {
2220     if( index>=getNumElements() || !isCompatibleType(BOOL_VEC3) ) return false;
2221     unsigned int j = index * getTypeNumComponents(getType());
2222     (*_intArray)[j] = b0;
2223     (*_intArray)[j+1] = b1;
2224     (*_intArray)[j+2] = b2;
2225     dirty();
2226     return true;
2227 }
2228 
setElement(unsigned int index,bool b0,bool b1,bool b2,bool b3)2229 bool Uniform::setElement( unsigned int index, bool b0, bool b1, bool b2, bool b3 )
2230 {
2231     if( index>=getNumElements() || !isCompatibleType(BOOL_VEC4) ) return false;
2232     unsigned int j = index * getTypeNumComponents(getType());
2233     (*_intArray)[j] = b0;
2234     (*_intArray)[j+1] = b1;
2235     (*_intArray)[j+2] = b2;
2236     (*_intArray)[j+3] = b3;
2237     dirty();
2238     return true;
2239 }
setElement(unsigned int index,unsigned long long ull)2240 bool Uniform::setElement( unsigned int index, unsigned long long ull )
2241 {
2242     if( index>=getNumElements() || !isCompatibleType(UNSIGNED_INT64) ) return false;
2243     unsigned int j = index * getTypeNumComponents(getType());
2244     (*_uint64Array)[j] = ull;
2245     dirty();
2246     return true;
2247 }
setElement(unsigned int index,long long ll)2248 bool Uniform::setElement( unsigned int index, long long ll )
2249 {
2250     if( index>=getNumElements() || !isCompatibleType(INT64) ) return false;
2251     unsigned int j = index * getTypeNumComponents(getType());
2252     (*_int64Array)[j] = ll;
2253     dirty();
2254     return true;
2255 }
2256 ///////////////////////////////////////////////////////////////////////////
2257 // Value query for array uniforms.
2258 
getElement(unsigned int index,float & f) const2259 bool Uniform::getElement( unsigned int index, float& f ) const
2260 {
2261     if( index>=getNumElements() || !isCompatibleType(FLOAT) ) return false;
2262     unsigned int j = index * getTypeNumComponents(getType());
2263     f = (*_floatArray)[j];
2264     return true;
2265 }
2266 
getElement(unsigned int index,osg::Vec2 & v2) const2267 bool Uniform::getElement( unsigned int index, osg::Vec2& v2 ) const
2268 {
2269     if( index>=getNumElements() || !isCompatibleType(FLOAT_VEC2) ) return false;
2270     unsigned int j = index * getTypeNumComponents(getType());
2271     v2.x() = (*_floatArray)[j];
2272     v2.y() = (*_floatArray)[j+1];
2273     return true;
2274 }
2275 
getElement(unsigned int index,osg::Vec3 & v3) const2276 bool Uniform::getElement( unsigned int index, osg::Vec3& v3 ) const
2277 {
2278     if( index>=getNumElements() || !isCompatibleType(FLOAT_VEC3) ) return false;
2279     unsigned int j = index * getTypeNumComponents(getType());
2280     v3.x() = (*_floatArray)[j];
2281     v3.y() = (*_floatArray)[j+1];
2282     v3.z() = (*_floatArray)[j+2];
2283     return true;
2284 }
2285 
getElement(unsigned int index,osg::Vec4 & v4) const2286 bool Uniform::getElement( unsigned int index, osg::Vec4& v4 ) const
2287 {
2288     if( index>=getNumElements() || !isCompatibleType(FLOAT_VEC4) ) return false;
2289     unsigned int j = index * getTypeNumComponents(getType());
2290     v4.x() = (*_floatArray)[j];
2291     v4.y() = (*_floatArray)[j+1];
2292     v4.z() = (*_floatArray)[j+2];
2293     v4.w() = (*_floatArray)[j+3];
2294     return true;
2295 }
2296 
getElement(unsigned int index,osg::Matrix2 & m2) const2297 bool Uniform::getElement( unsigned int index, osg::Matrix2& m2 ) const
2298 {
2299     if( index>=getNumElements() || !isCompatibleType(FLOAT_MAT2) ) return false;
2300     unsigned int j = index * getTypeNumComponents(getType());
2301     m2.Matrix2::base_class::set( &((*_floatArray)[j]) );
2302     return true;
2303 }
2304 
getElement(unsigned int index,osg::Matrix3 & m3) const2305 bool Uniform::getElement( unsigned int index, osg::Matrix3& m3 ) const
2306 {
2307     if( index>=getNumElements() || !isCompatibleType(FLOAT_MAT3) ) return false;
2308     unsigned int j = index * getTypeNumComponents(getType());
2309     m3.Matrix3::base_class::set( &((*_floatArray)[j]) );
2310     return true;
2311 }
2312 
getElement(unsigned int index,osg::Matrixf & m4) const2313 bool Uniform::getElement( unsigned int index, osg::Matrixf& m4 ) const
2314 {
2315     if( index>=getNumElements() || !isCompatibleType(FLOAT_MAT4) ) return false;
2316     unsigned int j = index * getTypeNumComponents(getType());
2317     m4.set( &((*_floatArray)[j]) );
2318     return true;
2319 }
2320 
getElement(unsigned int index,osg::Matrix2x3 & m2x3) const2321 bool Uniform::getElement( unsigned int index, osg::Matrix2x3& m2x3 ) const
2322 {
2323     if( index>=getNumElements() || !isCompatibleType(FLOAT_MAT2x3) ) return false;
2324     unsigned int j = index * getTypeNumComponents(getType());
2325     m2x3.Matrix2x3::base_class::set( &((*_floatArray)[j]) );
2326     return true;
2327 }
2328 
getElement(unsigned int index,osg::Matrix2x4 & m2x4) const2329 bool Uniform::getElement( unsigned int index, osg::Matrix2x4& m2x4 ) const
2330 {
2331     if( index>=getNumElements() || !isCompatibleType(FLOAT_MAT2x4) ) return false;
2332     unsigned int j = index * getTypeNumComponents(getType());
2333     m2x4.Matrix2x4::base_class::set( &((*_floatArray)[j]) );
2334     return true;
2335 }
2336 
getElement(unsigned int index,osg::Matrix3x2 & m3x2) const2337 bool Uniform::getElement( unsigned int index, osg::Matrix3x2& m3x2 ) const
2338 {
2339     if( index>=getNumElements() || !isCompatibleType(FLOAT_MAT3x2) ) return false;
2340     unsigned int j = index * getTypeNumComponents(getType());
2341     m3x2.Matrix3x2::base_class::set( &((*_floatArray)[j]) );
2342     return true;
2343 }
2344 
getElement(unsigned int index,osg::Matrix3x4 & m3x4) const2345 bool Uniform::getElement( unsigned int index, osg::Matrix3x4& m3x4 ) const
2346 {
2347     if( index>=getNumElements() || !isCompatibleType(FLOAT_MAT3x4) ) return false;
2348     unsigned int j = index * getTypeNumComponents(getType());
2349     m3x4.Matrix3x4::base_class::set( &((*_floatArray)[j]) );
2350     return true;
2351 }
2352 
getElement(unsigned int index,osg::Matrix4x2 & m4x2) const2353 bool Uniform::getElement( unsigned int index, osg::Matrix4x2& m4x2 ) const
2354 {
2355     if( index>=getNumElements() || !isCompatibleType(FLOAT_MAT4x2) ) return false;
2356     unsigned int j = index * getTypeNumComponents(getType());
2357     m4x2.Matrix4x2::base_class::set( &((*_floatArray)[j]) );
2358     return true;
2359 }
2360 
getElement(unsigned int index,osg::Matrix4x3 & m4x3) const2361 bool Uniform::getElement( unsigned int index, osg::Matrix4x3& m4x3 ) const
2362 {
2363     if( index>=getNumElements() || !isCompatibleType(FLOAT_MAT4x3) ) return false;
2364     unsigned int j = index * getTypeNumComponents(getType());
2365     m4x3.Matrix4x3::base_class::set( &((*_floatArray)[j]) );
2366     return true;
2367 }
2368 
getElement(unsigned int index,double & d) const2369 bool Uniform::getElement( unsigned int index, double& d ) const
2370 {
2371     if( index>=getNumElements() || !isCompatibleType(DOUBLE) ) return false;
2372     unsigned int j = index * getTypeNumComponents(getType());
2373     d = (*_doubleArray)[j];
2374     return true;
2375 }
2376 
getElement(unsigned int index,osg::Vec2d & v2) const2377 bool Uniform::getElement( unsigned int index, osg::Vec2d& v2 ) const
2378 {
2379     if( index>=getNumElements() || !isCompatibleType(DOUBLE_VEC2) ) return false;
2380     unsigned int j = index * getTypeNumComponents(getType());
2381     v2.x() = (*_doubleArray)[j];
2382     v2.y() = (*_doubleArray)[j+1];
2383     return true;
2384 }
2385 
getElement(unsigned int index,osg::Vec3d & v3) const2386 bool Uniform::getElement( unsigned int index, osg::Vec3d& v3 ) const
2387 {
2388     if( index>=getNumElements() || !isCompatibleType(DOUBLE_VEC3) ) return false;
2389     unsigned int j = index * getTypeNumComponents(getType());
2390     v3.x() = (*_doubleArray)[j];
2391     v3.y() = (*_doubleArray)[j+1];
2392     v3.z() = (*_doubleArray)[j+2];
2393     return true;
2394 }
2395 
getElement(unsigned int index,osg::Vec4d & v4) const2396 bool Uniform::getElement( unsigned int index, osg::Vec4d& v4 ) const
2397 {
2398     if( index>=getNumElements() || !isCompatibleType(DOUBLE_VEC4) ) return false;
2399     unsigned int j = index * getTypeNumComponents(getType());
2400     v4.x() = (*_doubleArray)[j];
2401     v4.y() = (*_doubleArray)[j+1];
2402     v4.z() = (*_doubleArray)[j+2];
2403     v4.w() = (*_doubleArray)[j+3];
2404     return true;
2405 }
2406 
getElement(unsigned int index,osg::Matrix2d & m2) const2407 bool Uniform::getElement( unsigned int index, osg::Matrix2d& m2 ) const
2408 {
2409     if( index>=getNumElements() || !isCompatibleType(DOUBLE_MAT2) ) return false;
2410     unsigned int j = index * getTypeNumComponents(getType());
2411     m2.Matrix2d::base_class::set( &((*_doubleArray)[j]) );
2412     return true;
2413 }
2414 
getElement(unsigned int index,osg::Matrix3d & m3) const2415 bool Uniform::getElement( unsigned int index, osg::Matrix3d& m3 ) const
2416 {
2417     if( index>=getNumElements() || !isCompatibleType(DOUBLE_MAT3) ) return false;
2418     unsigned int j = index * getTypeNumComponents(getType());
2419     m3.Matrix3d::base_class::set( &((*_doubleArray)[j]) );
2420     return true;
2421 }
2422 
getElement(unsigned int index,osg::Matrixd & m4) const2423 bool Uniform::getElement( unsigned int index, osg::Matrixd& m4 ) const
2424 {
2425     if( index>=getNumElements() || !isCompatibleType(DOUBLE_MAT4, FLOAT_MAT4) ) return false;
2426     unsigned int j = index * getTypeNumComponents(getType());
2427 
2428     if (_type == DOUBLE_MAT4)
2429       m4.set( &((*_doubleArray)[j]) );
2430     else // if (_type == FLOAT_MAT4) for backward compatibility only
2431       m4.set( &((*_floatArray)[j]) );
2432     return true;
2433 }
2434 
getElement(unsigned int index,osg::Matrix2x3d & m2x3) const2435 bool Uniform::getElement( unsigned int index, osg::Matrix2x3d& m2x3 ) const
2436 {
2437     if( index>=getNumElements() || !isCompatibleType(DOUBLE_MAT2x3) ) return false;
2438     unsigned int j = index * getTypeNumComponents(getType());
2439     m2x3.Matrix2x3d::base_class::set( &((*_doubleArray)[j]) );
2440     return true;
2441 }
2442 
getElement(unsigned int index,osg::Matrix2x4d & m2x4) const2443 bool Uniform::getElement( unsigned int index, osg::Matrix2x4d& m2x4 ) const
2444 {
2445     if( index>=getNumElements() || !isCompatibleType(DOUBLE_MAT2x4) ) return false;
2446     unsigned int j = index * getTypeNumComponents(getType());
2447     m2x4.Matrix2x4d::base_class::set( &((*_doubleArray)[j]) );
2448     return true;
2449 }
2450 
getElement(unsigned int index,osg::Matrix3x2d & m3x2) const2451 bool Uniform::getElement( unsigned int index, osg::Matrix3x2d& m3x2 ) const
2452 {
2453     if( index>=getNumElements() || !isCompatibleType(DOUBLE_MAT3x2) ) return false;
2454     unsigned int j = index * getTypeNumComponents(getType());
2455     m3x2.Matrix3x2d::base_class::set( &((*_doubleArray)[j]) );
2456     return true;
2457 }
2458 
getElement(unsigned int index,osg::Matrix3x4d & m3x4) const2459 bool Uniform::getElement( unsigned int index, osg::Matrix3x4d& m3x4 ) const
2460 {
2461     if( index>=getNumElements() || !isCompatibleType(DOUBLE_MAT3x4) ) return false;
2462     unsigned int j = index * getTypeNumComponents(getType());
2463     m3x4.Matrix3x4d::base_class::set( &((*_doubleArray)[j]) );
2464     return true;
2465 }
2466 
getElement(unsigned int index,osg::Matrix4x2d & m4x2) const2467 bool Uniform::getElement( unsigned int index, osg::Matrix4x2d& m4x2 ) const
2468 {
2469     if( index>=getNumElements() || !isCompatibleType(DOUBLE_MAT4x2) ) return false;
2470     unsigned int j = index * getTypeNumComponents(getType());
2471     m4x2.Matrix4x2d::base_class::set( &((*_doubleArray)[j]) );
2472     return true;
2473 }
2474 
getElement(unsigned int index,osg::Matrix4x3d & m4x3) const2475 bool Uniform::getElement( unsigned int index, osg::Matrix4x3d& m4x3 ) const
2476 {
2477     if( index>=getNumElements() || !isCompatibleType(DOUBLE_MAT4x3) ) return false;
2478     unsigned int j = index * getTypeNumComponents(getType());
2479     m4x3.Matrix4x3d::base_class::set( &((*_doubleArray)[j]) );
2480     return true;
2481 }
2482 
getElement(unsigned int index,int & i) const2483 bool Uniform::getElement( unsigned int index, int& i ) const
2484 {
2485     if( index>=getNumElements() || !isCompatibleType(INT) ) return false;
2486     unsigned int j = index * getTypeNumComponents(getType());
2487     i = (*_intArray)[j];
2488     return true;
2489 }
2490 
getElement(unsigned int index,int & i0,int & i1) const2491 bool Uniform::getElement( unsigned int index, int& i0, int& i1 ) const
2492 {
2493     if( index>=getNumElements() || !isCompatibleType(INT_VEC2) ) return false;
2494     unsigned int j = index * getTypeNumComponents(getType());
2495     i0 = (*_intArray)[j];
2496     i1 = (*_intArray)[j+1];
2497     return true;
2498 }
2499 
getElement(unsigned int index,int & i0,int & i1,int & i2) const2500 bool Uniform::getElement( unsigned int index, int& i0, int& i1, int& i2 ) const
2501 {
2502     if( index>=getNumElements() || !isCompatibleType(INT_VEC3) ) return false;
2503     unsigned int j = index * getTypeNumComponents(getType());
2504     i0 = (*_intArray)[j];
2505     i1 = (*_intArray)[j+1];
2506     i2 = (*_intArray)[j+2];
2507     return true;
2508 }
2509 
getElement(unsigned int index,int & i0,int & i1,int & i2,int & i3) const2510 bool Uniform::getElement( unsigned int index, int& i0, int& i1, int& i2, int& i3 ) const
2511 {
2512     if( index>=getNumElements() || !isCompatibleType(INT_VEC4) ) return false;
2513     unsigned int j = index * getTypeNumComponents(getType());
2514     i0 = (*_intArray)[j];
2515     i1 = (*_intArray)[j+1];
2516     i2 = (*_intArray)[j+2];
2517     i3 = (*_intArray)[j+3];
2518     return true;
2519 }
2520 
getElement(unsigned int index,unsigned int & ui) const2521 bool Uniform::getElement( unsigned int index, unsigned int& ui ) const
2522 {
2523     if( index>=getNumElements() || !isCompatibleType(UNSIGNED_INT) ) return false;
2524     unsigned int j = index * getTypeNumComponents(getType());
2525     ui = (*_uintArray)[j];
2526     return true;
2527 }
2528 
getElement(unsigned int index,unsigned int & ui0,unsigned int & ui1) const2529 bool Uniform::getElement( unsigned int index, unsigned int& ui0, unsigned int& ui1 ) const
2530 {
2531     if( index>=getNumElements() || !isCompatibleType(UNSIGNED_INT_VEC2) ) return false;
2532     unsigned int j = index * getTypeNumComponents(getType());
2533     ui0 = (*_uintArray)[j];
2534     ui1 = (*_uintArray)[j+1];
2535     return true;
2536 }
2537 
getElement(unsigned int index,unsigned int & ui0,unsigned int & ui1,unsigned int & ui2) const2538 bool Uniform::getElement( unsigned int index, unsigned int& ui0, unsigned int& ui1, unsigned int& ui2 ) const
2539 {
2540     if( index>=getNumElements() || !isCompatibleType(UNSIGNED_INT_VEC3) ) return false;
2541     unsigned int j = index * getTypeNumComponents(getType());
2542     ui0 = (*_uintArray)[j];
2543     ui1 = (*_uintArray)[j+1];
2544     ui2 = (*_uintArray)[j+2];
2545     return true;
2546 }
2547 
getElement(unsigned int index,unsigned int & ui0,unsigned int & ui1,unsigned int & ui2,unsigned int & ui3) const2548 bool Uniform::getElement( unsigned int index, unsigned int& ui0, unsigned int& ui1, unsigned int& ui2, unsigned int& ui3 ) const
2549 {
2550     if( index>=getNumElements() || !isCompatibleType(UNSIGNED_INT_VEC4) ) return false;
2551     unsigned int j = index * getTypeNumComponents(getType());
2552     ui0 = (*_uintArray)[j];
2553     ui1 = (*_uintArray)[j+1];
2554     ui2 = (*_uintArray)[j+2];
2555     ui3 = (*_uintArray)[j+3];
2556     return true;
2557 }
2558 
getElement(unsigned int index,bool & b) const2559 bool Uniform::getElement( unsigned int index, bool& b ) const
2560 {
2561     if( index>=getNumElements() || !isCompatibleType(BOOL) ) return false;
2562     unsigned int j = index * getTypeNumComponents(getType());
2563     b = ((*_intArray)[j] != 0);
2564     return true;
2565 }
2566 
getElement(unsigned int index,unsigned long long & ull) const2567 bool Uniform::getElement( unsigned int index, unsigned long long& ull ) const
2568 {
2569     if( index>=getNumElements() || !isCompatibleType(UNSIGNED_INT64) ) return false;
2570     unsigned int j = index * getTypeNumComponents(getType());
2571     ull = ((*_uint64Array)[j] != 0);
2572     return true;
2573 }
2574 
getElement(unsigned int index,long long & ll) const2575 bool Uniform::getElement( unsigned int index, long long& ll ) const
2576 {
2577     if( index>=getNumElements() || !isCompatibleType(INT64) ) return false;
2578     unsigned int j = index * getTypeNumComponents(getType());
2579     ll = ((*_int64Array)[j] != 0);
2580     return true;
2581 }
2582 
getElement(unsigned int index,bool & b0,bool & b1) const2583 bool Uniform::getElement( unsigned int index, bool& b0, bool& b1 ) const
2584 {
2585     if( index>=getNumElements() || !isCompatibleType(BOOL_VEC2) ) return false;
2586     unsigned int j = index * getTypeNumComponents(getType());
2587     b0 = ((*_intArray)[j] != 0);
2588     b1 = ((*_intArray)[j+1] != 0);
2589     return true;
2590 }
2591 
getElement(unsigned int index,bool & b0,bool & b1,bool & b2) const2592 bool Uniform::getElement( unsigned int index, bool& b0, bool& b1, bool& b2 ) const
2593 {
2594     if( index>=getNumElements() || !isCompatibleType(BOOL_VEC3) ) return false;
2595     unsigned int j = index * getTypeNumComponents(getType());
2596     b0 = ((*_intArray)[j] != 0);
2597     b1 = ((*_intArray)[j+1] != 0);
2598     b2 = ((*_intArray)[j+2] != 0);
2599     return true;
2600 }
2601 
getElement(unsigned int index,bool & b0,bool & b1,bool & b2,bool & b3) const2602 bool Uniform::getElement( unsigned int index, bool& b0, bool& b1, bool& b2, bool& b3 ) const
2603 {
2604     if( index>=getNumElements() || !isCompatibleType(BOOL_VEC4) ) return false;
2605     unsigned int j = index * getTypeNumComponents(getType());
2606     b0 = ((*_intArray)[j] != 0);
2607     b1 = ((*_intArray)[j+1] != 0);
2608     b2 = ((*_intArray)[j+2] != 0);
2609     b3 = ((*_intArray)[j+3] != 0);
2610     return true;
2611 }
2612 
getNameID() const2613 unsigned int Uniform::getNameID() const
2614 {
2615     return _nameID;
2616 }
2617 
2618 ///////////////////////////////////////////////////////////////////////////
2619 
apply(const GLExtensions * ext,GLint location) const2620 void Uniform::apply(const GLExtensions* ext, GLint location) const
2621 {
2622     // OSG_NOTICE << "uniform at "<<location<<" "<<_name<< std::endl;
2623 
2624     GLsizei num = getNumElements();
2625     if( num < 1 ) return;
2626 
2627     switch( getGlApiType(getType()) )
2628     {
2629     case FLOAT:
2630         if( _floatArray.valid() ) ext->glUniform1fv( location, num, &_floatArray->front() );
2631         break;
2632 
2633     case FLOAT_VEC2:
2634         if( _floatArray.valid() ) ext->glUniform2fv( location, num, &_floatArray->front() );
2635         break;
2636 
2637     case FLOAT_VEC3:
2638         if( _floatArray.valid() ) ext->glUniform3fv( location, num, &_floatArray->front() );
2639         break;
2640 
2641     case FLOAT_VEC4:
2642         if( _floatArray.valid() ) ext->glUniform4fv( location, num, &_floatArray->front() );
2643         break;
2644 
2645     case FLOAT_MAT2:
2646         if( _floatArray.valid() ) ext->glUniformMatrix2fv( location, num, GL_FALSE, &_floatArray->front() );
2647         break;
2648 
2649     case FLOAT_MAT3:
2650         if( _floatArray.valid() ) ext->glUniformMatrix3fv( location, num, GL_FALSE, &_floatArray->front() );
2651         break;
2652 
2653     case FLOAT_MAT4:
2654         if( _floatArray.valid() ) ext->glUniformMatrix4fv( location, num, GL_FALSE, &_floatArray->front() );
2655         break;
2656 
2657     case FLOAT_MAT2x3:
2658         if( _floatArray.valid() ) ext->glUniformMatrix2x3fv( location, num, GL_FALSE, &_floatArray->front() );
2659         break;
2660 
2661     case FLOAT_MAT2x4:
2662         if( _floatArray.valid() ) ext->glUniformMatrix2x4fv( location, num, GL_FALSE, &_floatArray->front() );
2663         break;
2664 
2665     case FLOAT_MAT3x2:
2666         if( _floatArray.valid() ) ext->glUniformMatrix3x2fv( location, num, GL_FALSE, &_floatArray->front() );
2667         break;
2668 
2669     case FLOAT_MAT3x4:
2670         if( _floatArray.valid() ) ext->glUniformMatrix3x4fv( location, num, GL_FALSE, &_floatArray->front() );
2671         break;
2672 
2673     case FLOAT_MAT4x2:
2674         if( _floatArray.valid() ) ext->glUniformMatrix4x2fv( location, num, GL_FALSE, &_floatArray->front() );
2675         break;
2676 
2677     case FLOAT_MAT4x3:
2678         if( _floatArray.valid() ) ext->glUniformMatrix4x3fv( location, num, GL_FALSE, &_floatArray->front() );
2679         break;
2680 
2681     case DOUBLE:
2682         if( _doubleArray.valid() ) ext->glUniform1dv( location, num, &_doubleArray->front() );
2683         break;
2684 
2685     case DOUBLE_VEC2:
2686         if( _doubleArray.valid() ) ext->glUniform2dv( location, num, &_doubleArray->front() );
2687         break;
2688 
2689     case DOUBLE_VEC3:
2690         if( _doubleArray.valid() ) ext->glUniform3dv( location, num, &_doubleArray->front() );
2691         break;
2692 
2693     case DOUBLE_VEC4:
2694         if( _doubleArray.valid() ) ext->glUniform4dv( location, num, &_doubleArray->front() );
2695         break;
2696 
2697     case DOUBLE_MAT2:
2698         if( _doubleArray.valid() ) ext->glUniformMatrix2dv( location, num, GL_FALSE, &_doubleArray->front() );
2699         break;
2700 
2701     case DOUBLE_MAT3:
2702         if( _doubleArray.valid() ) ext->glUniformMatrix3dv( location, num, GL_FALSE, &_doubleArray->front() );
2703         break;
2704 
2705     case DOUBLE_MAT4:
2706         if( _doubleArray.valid() ) ext->glUniformMatrix4dv( location, num, GL_FALSE, &_doubleArray->front() );
2707         break;
2708 
2709     case DOUBLE_MAT2x3:
2710         if( _doubleArray.valid() ) ext->glUniformMatrix2x3dv( location, num, GL_FALSE, &_doubleArray->front() );
2711         break;
2712 
2713     case DOUBLE_MAT2x4:
2714         if( _doubleArray.valid() ) ext->glUniformMatrix2x4dv( location, num, GL_FALSE, &_doubleArray->front() );
2715         break;
2716 
2717     case DOUBLE_MAT3x2:
2718         if( _doubleArray.valid() ) ext->glUniformMatrix3x2dv( location, num, GL_FALSE, &_doubleArray->front() );
2719         break;
2720 
2721     case DOUBLE_MAT3x4:
2722         if( _doubleArray.valid() ) ext->glUniformMatrix3x4dv( location, num, GL_FALSE, &_doubleArray->front() );
2723         break;
2724 
2725     case DOUBLE_MAT4x2:
2726         if( _doubleArray.valid() ) ext->glUniformMatrix4x2dv( location, num, GL_FALSE, &_doubleArray->front() );
2727         break;
2728 
2729     case DOUBLE_MAT4x3:
2730         if( _doubleArray.valid() ) ext->glUniformMatrix4x3dv( location, num, GL_FALSE, &_doubleArray->front() );
2731         break;
2732 
2733     case INT:
2734         if( _intArray.valid() ) ext->glUniform1iv( location, num, &_intArray->front() );
2735         break;
2736 
2737     case INT_VEC2:
2738         if( _intArray.valid() ) ext->glUniform2iv( location, num, &_intArray->front() );
2739         break;
2740 
2741     case INT_VEC3:
2742         if( _intArray.valid() ) ext->glUniform3iv( location, num, &_intArray->front() );
2743         break;
2744 
2745     case INT_VEC4:
2746         if( _intArray.valid() ) ext->glUniform4iv( location, num, &_intArray->front() );
2747         break;
2748 
2749     case UNSIGNED_INT:
2750         if( _uintArray.valid() ) ext->glUniform1uiv( location, num, &_uintArray->front() );
2751         break;
2752 
2753     case UNSIGNED_INT_VEC2:
2754         if( _uintArray.valid() ) ext->glUniform2uiv( location, num, &_uintArray->front() );
2755         break;
2756 
2757     case UNSIGNED_INT_VEC3:
2758         if( _uintArray.valid() ) ext->glUniform3uiv( location, num, &_uintArray->front() );
2759         break;
2760 
2761     case UNSIGNED_INT_VEC4:
2762         if( _uintArray.valid() ) ext->glUniform4uiv( location, num, &_uintArray->front() );
2763         break;
2764 
2765     case UNSIGNED_INT64:
2766         if( _uint64Array.valid() ){
2767             if (ext->glUniform1ui64v)
2768                 ext->glUniform1ui64v( location, num, &_uint64Array->front() );
2769             else
2770                 OSG_WARN << "how got here? " __FILE__ ":" << __LINE__ << std::endl;
2771         }
2772         break;
2773 
2774     case INT64:
2775         if( _int64Array.valid() ) ext->glUniform1i64v( location, num, &_int64Array->front() );
2776         break;
2777 
2778     default:
2779         OSG_FATAL << "how got here? " __FILE__ ":" << __LINE__ << std::endl;
2780         break;
2781     }
2782 }
2783 
setUpdateCallback(UniformCallback * uc)2784 void Uniform::setUpdateCallback(UniformCallback* uc)
2785 {
2786     OSG_INFO<<"Uniform::Setting Update callbacks"<<std::endl;
2787 
2788     if (_updateCallback==uc) return;
2789 
2790     int delta = 0;
2791     if (_updateCallback.valid()) --delta;
2792     if (uc) ++delta;
2793 
2794     _updateCallback = uc;
2795 
2796     if (delta!=0)
2797     {
2798         OSG_INFO<<"Going to set Uniform parents"<<std::endl;
2799 
2800         for(ParentList::iterator itr=_parents.begin();
2801             itr!=_parents.end();
2802             ++itr)
2803         {
2804             OSG_INFO<<"   setting Uniform parent"<<std::endl;
2805             (*itr)->setNumChildrenRequiringUpdateTraversal((*itr)->getNumChildrenRequiringUpdateTraversal()+delta);
2806         }
2807     }
2808 }
2809 
setEventCallback(UniformCallback * ec)2810 void Uniform::setEventCallback(UniformCallback* ec)
2811 {
2812     OSG_INFO<<"Uniform::Setting Event callbacks"<<std::endl;
2813 
2814     if (_eventCallback==ec) return;
2815 
2816     int delta = 0;
2817     if (_eventCallback.valid()) --delta;
2818     if (ec) ++delta;
2819 
2820     _eventCallback = ec;
2821 
2822     if (delta!=0)
2823     {
2824         for(ParentList::iterator itr=_parents.begin();
2825             itr!=_parents.end();
2826             ++itr)
2827         {
2828             (*itr)->setNumChildrenRequiringEventTraversal((*itr)->getNumChildrenRequiringEventTraversal()+delta);
2829         }
2830     }
2831 }
2832 
2833