Uniform 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958
  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. /* file: include/osg/Uniform
  15. * author: Mike Weiblen 2008-01-02
  16. */
  17. #ifndef OSG_UNIFORM
  18. #define OSG_UNIFORM 1
  19. #include <osg/ref_ptr>
  20. #include <osg/Array>
  21. #include <osg/Callback>
  22. #include <osg/Vec2>
  23. #include <osg/Vec3>
  24. #include <osg/Vec4>
  25. #include <osg/Vec2d>
  26. #include <osg/Vec3d>
  27. #include <osg/Vec4d>
  28. #include <osg/Matrix>
  29. #include <osg/GLExtensions>
  30. #include <string.h> // for memset
  31. #include <string>
  32. #include <vector>
  33. namespace osg {
  34. // forward declare
  35. class NodeVisitor;
  36. ///////////////////////////////////////////////////////////////////////////
  37. // C++ classes to represent the GLSL-specific types.
  38. //
  39. // Warning :
  40. // OSG is Row major
  41. // GLSL is Column Major
  42. //
  43. // If you define an Uniform with type Uniform::FLOAT_MAT4X2 and so use a Matrix4x2 to setup your Uniform,
  44. // like this :
  45. // 1 2
  46. // 3 4
  47. // 5 6
  48. // 7 8
  49. //
  50. // you will get in your shader a Column Major Matrix like this :
  51. // 1 3 5 7
  52. // 2 4 6 8
  53. //
  54. // In simple term, you matrix in OSG will be a transposed matrix in GLSL
  55. //
  56. //
  57. // You can avoid this behaviours starting GLSL version 1.40 with uniform layout :
  58. //
  59. // <GLSL code>
  60. // layout(row_major) uniform matrix4x2 myVariable;
  61. // <GLSL code>
  62. //
  63. //
  64. template <typename T, unsigned int RowN, unsigned int ColN>
  65. class MatrixTemplate
  66. {
  67. public:
  68. enum { col_count = ColN };
  69. enum { row_count = RowN };
  70. enum { value_count = ColN * RowN };
  71. typedef T value_type;
  72. public:
  73. MatrixTemplate() {}
  74. ~MatrixTemplate() {}
  75. value_type& operator()(int row, int col) { return _mat[row][col]; }
  76. value_type operator()(int row, int col) const { return _mat[row][col]; }
  77. MatrixTemplate& operator = (const MatrixTemplate& rhs)
  78. {
  79. if( &rhs == this ) return *this;
  80. set(rhs.ptr());
  81. return *this;
  82. }
  83. void set(const MatrixTemplate& rhs) { set(rhs.ptr()); }
  84. void set(value_type const * const ptr)
  85. {
  86. value_type* local_ptr = (value_type*)_mat;
  87. for(int i=0;i<value_count;++i) local_ptr[i]=ptr[i];
  88. }
  89. value_type* ptr() { return (value_type*)_mat; }
  90. const value_type* ptr() const { return (const value_type*)_mat; }
  91. value_type& operator [] (int i) {return ptr()[i];}
  92. value_type operator [] (int i) const {return ptr()[i];}
  93. void reset() { memset(_mat, 0, sizeof( value_type ) * value_count); }
  94. protected:
  95. value_type _mat[row_count][col_count];
  96. };
  97. template <typename T>
  98. class Matrix2Template : public MatrixTemplate<T, 2, 2>
  99. {
  100. public:
  101. typedef MatrixTemplate<T, 2, 2> base_class;
  102. typedef typename base_class::value_type value_type;
  103. public:
  104. Matrix2Template() { makeIdentity(); }
  105. Matrix2Template( const Matrix2Template& mat ) { set(mat.ptr()); }
  106. Matrix2Template( value_type a00, value_type a01,
  107. value_type a10, value_type a11 )
  108. {
  109. set( a00, a01,
  110. a10, a11 );
  111. }
  112. ~Matrix2Template() {}
  113. using base_class::set;
  114. void set(value_type a00, value_type a01,
  115. value_type a10, value_type a11 )
  116. {
  117. base_class::_mat[0][0]=a00; base_class::_mat[0][1]=a01;
  118. base_class::_mat[1][0]=a10; base_class::_mat[1][1]=a11;
  119. }
  120. void makeIdentity()
  121. {
  122. set( 1, 0,
  123. 0, 1 );
  124. }
  125. };
  126. template <typename T>
  127. class Matrix2x3Template : public MatrixTemplate<T, 2, 3>
  128. {
  129. public:
  130. typedef MatrixTemplate<T, 2, 3> base_class;
  131. typedef typename base_class::value_type value_type;
  132. public:
  133. Matrix2x3Template() { base_class::reset(); }
  134. Matrix2x3Template( const Matrix2x3Template& mat ) { set(mat.ptr()); }
  135. Matrix2x3Template( value_type a00, value_type a01, value_type a02,
  136. value_type a10, value_type a11, value_type a12 )
  137. {
  138. set( a00, a01, a02,
  139. a10, a11, a12 );
  140. }
  141. ~Matrix2x3Template() {}
  142. using base_class::set;
  143. void set( value_type a00, value_type a01, value_type a02,
  144. value_type a10, value_type a11, value_type a12 )
  145. {
  146. base_class::_mat[0][0]=a00; base_class::_mat[0][1]=a01; base_class::_mat[0][2]=a02;
  147. base_class::_mat[1][0]=a10; base_class::_mat[1][1]=a11; base_class::_mat[1][2]=a12;
  148. }
  149. };
  150. template <typename T>
  151. class Matrix2x4Template : public MatrixTemplate<T, 2, 4>
  152. {
  153. public:
  154. typedef MatrixTemplate<T, 2, 4> base_class;
  155. typedef typename base_class::value_type value_type;
  156. public:
  157. Matrix2x4Template() { base_class::reset(); }
  158. Matrix2x4Template( const Matrix2x4Template& mat ) { set(mat.ptr()); }
  159. Matrix2x4Template( value_type a00, value_type a01, value_type a02, value_type a03,
  160. value_type a10, value_type a11, value_type a12, value_type a13 )
  161. {
  162. set( a00, a01, a02, a03,
  163. a10, a11, a12, a13 );
  164. }
  165. ~Matrix2x4Template() {}
  166. using base_class::set;
  167. void set( value_type a00, value_type a01, value_type a02, value_type a03,
  168. value_type a10, value_type a11, value_type a12, value_type a13 )
  169. {
  170. base_class::_mat[0][0]=a00; base_class::_mat[0][1]=a01; base_class::_mat[0][2]=a02; base_class::_mat[0][3]=a03;
  171. base_class::_mat[1][0]=a10; base_class::_mat[1][1]=a11; base_class::_mat[1][2]=a12; base_class::_mat[1][3]=a13;
  172. }
  173. };
  174. template <typename T>
  175. class Matrix3x2Template : public MatrixTemplate<T, 3, 2>
  176. {
  177. public:
  178. typedef MatrixTemplate<T, 3, 2> base_class;
  179. typedef typename base_class::value_type value_type;
  180. public:
  181. Matrix3x2Template() { base_class::reset(); }
  182. Matrix3x2Template( const Matrix3x2Template& mat ) { set(mat.ptr()); }
  183. Matrix3x2Template( value_type a00, value_type a01,
  184. value_type a10, value_type a11,
  185. value_type a20, value_type a21 )
  186. {
  187. set( a00, a01,
  188. a10, a11,
  189. a20, a21 );
  190. }
  191. ~Matrix3x2Template() {}
  192. using base_class::set;
  193. void set( value_type a00, value_type a01,
  194. value_type a10, value_type a11,
  195. value_type a20, value_type a21 )
  196. {
  197. base_class::_mat[0][0]=a00; base_class::_mat[0][1]=a01;
  198. base_class::_mat[1][0]=a10; base_class::_mat[1][1]=a11;
  199. base_class::_mat[2][0]=a20; base_class::_mat[2][1]=a21;
  200. }
  201. };
  202. template <typename T>
  203. class Matrix3Template : public MatrixTemplate<T, 3, 3>
  204. {
  205. public:
  206. typedef MatrixTemplate<T, 3, 3> base_class;
  207. typedef typename base_class::value_type value_type;
  208. public:
  209. Matrix3Template() { base_class::reset(); }
  210. Matrix3Template( const Matrix3Template& mat ) { set(mat.ptr()); }
  211. Matrix3Template( value_type a00, value_type a01, value_type a02,
  212. value_type a10, value_type a11, value_type a12,
  213. value_type a20, value_type a21, value_type a22 )
  214. {
  215. set( a00, a01, a02,
  216. a10, a11, a12,
  217. a20, a21, a22 );
  218. }
  219. ~Matrix3Template() {}
  220. using base_class::set;
  221. void set( value_type a00, value_type a01, value_type a02,
  222. value_type a10, value_type a11, value_type a12,
  223. value_type a20, value_type a21, value_type a22 )
  224. {
  225. base_class::_mat[0][0]=a00; base_class::_mat[0][1]=a01; base_class::_mat[0][2]=a02;
  226. base_class::_mat[1][0]=a10; base_class::_mat[1][1]=a11; base_class::_mat[1][2]=a12;
  227. base_class::_mat[2][0]=a20; base_class::_mat[2][1]=a21; base_class::_mat[2][2]=a22;
  228. }
  229. void makeIdentity()
  230. {
  231. set( 1, 0, 0,
  232. 0, 1, 0,
  233. 0, 0, 1 );
  234. }
  235. };
  236. template <typename T>
  237. class Matrix3x4Template : public MatrixTemplate<T, 3, 4>
  238. {
  239. public:
  240. typedef MatrixTemplate<T, 3, 4> base_class;
  241. typedef typename base_class::value_type value_type;
  242. public:
  243. Matrix3x4Template() { base_class::reset(); }
  244. Matrix3x4Template( const Matrix3x4Template& mat ) { set(mat.ptr()); }
  245. Matrix3x4Template( value_type a00, value_type a01, value_type a02, value_type a03,
  246. value_type a10, value_type a11, value_type a12, value_type a13,
  247. value_type a20, value_type a21, value_type a22, value_type a23 )
  248. {
  249. set( a00, a01, a02, a03,
  250. a10, a11, a12, a13,
  251. a20, a21, a22, a23 );
  252. }
  253. ~Matrix3x4Template() {}
  254. using base_class::set;
  255. void set( value_type a00, value_type a01, value_type a02, value_type a03,
  256. value_type a10, value_type a11, value_type a12, value_type a13,
  257. value_type a20, value_type a21, value_type a22, value_type a23 )
  258. {
  259. base_class::_mat[0][0]=a00; base_class::_mat[0][1]=a01; base_class::_mat[0][2]=a02; base_class::_mat[0][3]=a03;
  260. base_class::_mat[1][0]=a10; base_class::_mat[1][1]=a11; base_class::_mat[1][2]=a12; base_class::_mat[1][3]=a13;
  261. base_class::_mat[2][0]=a20; base_class::_mat[2][1]=a21; base_class::_mat[2][2]=a22; base_class::_mat[2][3]=a23;
  262. }
  263. };
  264. template <typename T>
  265. class Matrix4x2Template : public MatrixTemplate<T, 4, 2>
  266. {
  267. public:
  268. typedef MatrixTemplate<T, 4, 2> base_class;
  269. typedef typename base_class::value_type value_type;
  270. public:
  271. Matrix4x2Template() { base_class::reset(); }
  272. Matrix4x2Template( const Matrix4x2Template& mat ) { set(mat.ptr()); }
  273. Matrix4x2Template( value_type a00, value_type a01,
  274. value_type a10, value_type a11,
  275. value_type a20, value_type a21,
  276. value_type a30, value_type a31 )
  277. {
  278. set( a00, a01,
  279. a10, a11,
  280. a20, a21,
  281. a30, a31 );
  282. }
  283. ~Matrix4x2Template() {}
  284. using base_class::set;
  285. void set( value_type a00, value_type a01,
  286. value_type a10, value_type a11,
  287. value_type a20, value_type a21,
  288. value_type a30, value_type a31 )
  289. {
  290. base_class::_mat[0][0]=a00; base_class::_mat[0][1]=a01;
  291. base_class::_mat[1][0]=a10; base_class::_mat[1][1]=a11;
  292. base_class::_mat[2][0]=a20; base_class::_mat[2][1]=a21;
  293. base_class::_mat[3][0]=a30; base_class::_mat[3][1]=a31;
  294. }
  295. };
  296. template <typename T>
  297. class Matrix4x3Template : public MatrixTemplate<T, 4, 3>
  298. {
  299. public:
  300. typedef MatrixTemplate<T, 4, 3> base_class;
  301. typedef typename base_class::value_type value_type;
  302. public:
  303. Matrix4x3Template() { base_class::reset(); }
  304. Matrix4x3Template( const Matrix4x3Template& mat ) { set(mat.ptr()); }
  305. Matrix4x3Template( value_type a00, value_type a01, value_type a02,
  306. value_type a10, value_type a11, value_type a12,
  307. value_type a20, value_type a21, value_type a22,
  308. value_type a30, value_type a31, value_type a32 )
  309. {
  310. set( a00, a01, a02,
  311. a10, a11, a12,
  312. a20, a21, a22,
  313. a30, a31, a32 );
  314. }
  315. ~Matrix4x3Template() {}
  316. using base_class::set;
  317. void set( value_type a00, value_type a01, value_type a02,
  318. value_type a10, value_type a11, value_type a12,
  319. value_type a20, value_type a21, value_type a22,
  320. value_type a30, value_type a31, value_type a32 )
  321. {
  322. base_class::_mat[0][0]=a00; base_class::_mat[0][1]=a01; base_class::_mat[0][2]=a02;
  323. base_class::_mat[1][0]=a10; base_class::_mat[1][1]=a11; base_class::_mat[1][2]=a12;
  324. base_class::_mat[2][0]=a20; base_class::_mat[2][1]=a21; base_class::_mat[2][2]=a22;
  325. base_class::_mat[3][0]=a30; base_class::_mat[3][1]=a31; base_class::_mat[3][2]=a32;
  326. }
  327. };
  328. typedef Matrix2Template<float> Matrix2;
  329. typedef Matrix2x3Template<float> Matrix2x3;
  330. typedef Matrix2x4Template<float> Matrix2x4;
  331. typedef Matrix3x2Template<float> Matrix3x2;
  332. typedef Matrix3Template<float> Matrix3;
  333. typedef Matrix3x4Template<float> Matrix3x4;
  334. typedef Matrix4x2Template<float> Matrix4x2;
  335. typedef Matrix4x3Template<float> Matrix4x3;
  336. typedef Matrix2Template<double> Matrix2d;
  337. typedef Matrix2x3Template<double> Matrix2x3d;
  338. typedef Matrix2x4Template<double> Matrix2x4d;
  339. typedef Matrix3x2Template<double> Matrix3x2d;
  340. typedef Matrix3Template<double> Matrix3d;
  341. typedef Matrix3x4Template<double> Matrix3x4d;
  342. typedef Matrix4x2Template<double> Matrix4x2d;
  343. typedef Matrix4x3Template<double> Matrix4x3d;
  344. ///////////////////////////////////////////////////////////////////////////
  345. /** Uniform encapsulates glUniform values */
  346. class OSG_EXPORT Uniform : public Object
  347. {
  348. public:
  349. enum Type {
  350. FLOAT = GL_FLOAT,
  351. FLOAT_VEC2 = GL_FLOAT_VEC2,
  352. FLOAT_VEC3 = GL_FLOAT_VEC3,
  353. FLOAT_VEC4 = GL_FLOAT_VEC4,
  354. DOUBLE = GL_DOUBLE,
  355. DOUBLE_VEC2 = GL_DOUBLE_VEC2,
  356. DOUBLE_VEC3 = GL_DOUBLE_VEC3,
  357. DOUBLE_VEC4 = GL_DOUBLE_VEC4,
  358. INT = GL_INT,
  359. INT_VEC2 = GL_INT_VEC2,
  360. INT_VEC3 = GL_INT_VEC3,
  361. INT_VEC4 = GL_INT_VEC4,
  362. UNSIGNED_INT = GL_UNSIGNED_INT,
  363. UNSIGNED_INT_VEC2 = GL_UNSIGNED_INT_VEC2_EXT,
  364. UNSIGNED_INT_VEC3 = GL_UNSIGNED_INT_VEC3_EXT,
  365. UNSIGNED_INT_VEC4 = GL_UNSIGNED_INT_VEC4_EXT,
  366. BOOL = GL_BOOL,
  367. BOOL_VEC2 = GL_BOOL_VEC2,
  368. BOOL_VEC3 = GL_BOOL_VEC3,
  369. BOOL_VEC4 = GL_BOOL_VEC4,
  370. INT64 = GL_INT64_ARB,
  371. UNSIGNED_INT64 = GL_UNSIGNED_INT64_ARB,
  372. FLOAT_MAT2 = GL_FLOAT_MAT2,
  373. FLOAT_MAT3 = GL_FLOAT_MAT3,
  374. FLOAT_MAT4 = GL_FLOAT_MAT4,
  375. FLOAT_MAT2x3 = GL_FLOAT_MAT2x3,
  376. FLOAT_MAT2x4 = GL_FLOAT_MAT2x4,
  377. FLOAT_MAT3x2 = GL_FLOAT_MAT3x2,
  378. FLOAT_MAT3x4 = GL_FLOAT_MAT3x4,
  379. FLOAT_MAT4x2 = GL_FLOAT_MAT4x2,
  380. FLOAT_MAT4x3 = GL_FLOAT_MAT4x3,
  381. DOUBLE_MAT2 = GL_DOUBLE_MAT2,
  382. DOUBLE_MAT3 = GL_DOUBLE_MAT3,
  383. DOUBLE_MAT4 = GL_DOUBLE_MAT4,
  384. DOUBLE_MAT2x3 = GL_DOUBLE_MAT2x3,
  385. DOUBLE_MAT2x4 = GL_DOUBLE_MAT2x4,
  386. DOUBLE_MAT3x2 = GL_DOUBLE_MAT3x2,
  387. DOUBLE_MAT3x4 = GL_DOUBLE_MAT3x4,
  388. DOUBLE_MAT4x2 = GL_DOUBLE_MAT4x2,
  389. DOUBLE_MAT4x3 = GL_DOUBLE_MAT4x3,
  390. SAMPLER_1D = GL_SAMPLER_1D,
  391. SAMPLER_2D = GL_SAMPLER_2D,
  392. SAMPLER_3D = GL_SAMPLER_3D,
  393. SAMPLER_CUBE = GL_SAMPLER_CUBE,
  394. SAMPLER_1D_SHADOW = GL_SAMPLER_1D_SHADOW,
  395. SAMPLER_2D_SHADOW = GL_SAMPLER_2D_SHADOW,
  396. SAMPLER_1D_ARRAY = GL_SAMPLER_1D_ARRAY_EXT,
  397. SAMPLER_2D_ARRAY = GL_SAMPLER_2D_ARRAY_EXT,
  398. SAMPLER_CUBE_MAP_ARRAY = GL_SAMPLER_CUBE_MAP_ARRAY,
  399. SAMPLER_1D_ARRAY_SHADOW = GL_SAMPLER_1D_ARRAY_SHADOW_EXT,
  400. SAMPLER_2D_ARRAY_SHADOW = GL_SAMPLER_2D_ARRAY_SHADOW_EXT,
  401. SAMPLER_2D_MULTISAMPLE = GL_SAMPLER_2D_MULTISAMPLE,
  402. SAMPLER_2D_MULTISAMPLE_ARRAY = GL_SAMPLER_2D_MULTISAMPLE_ARRAY,
  403. SAMPLER_CUBE_SHADOW = GL_SAMPLER_CUBE_SHADOW_EXT,
  404. SAMPLER_CUBE_MAP_ARRAY_SHADOW = GL_SAMPLER_CUBE_MAP_ARRAY_SHADOW,
  405. SAMPLER_BUFFER = GL_SAMPLER_BUFFER_EXT,
  406. SAMPLER_2D_RECT = GL_SAMPLER_2D_RECT,
  407. SAMPLER_2D_RECT_SHADOW = GL_SAMPLER_2D_RECT_SHADOW,
  408. INT_SAMPLER_1D = GL_INT_SAMPLER_1D_EXT,
  409. INT_SAMPLER_2D = GL_INT_SAMPLER_2D_EXT,
  410. INT_SAMPLER_3D = GL_INT_SAMPLER_3D_EXT,
  411. INT_SAMPLER_CUBE = GL_INT_SAMPLER_CUBE_EXT,
  412. INT_SAMPLER_1D_ARRAY = GL_INT_SAMPLER_1D_ARRAY_EXT,
  413. INT_SAMPLER_2D_ARRAY = GL_INT_SAMPLER_2D_ARRAY_EXT,
  414. INT_SAMPLER_CUBE_MAP_ARRAY = GL_INT_SAMPLER_CUBE_MAP_ARRAY,
  415. INT_SAMPLER_2D_MULTISAMPLE = GL_INT_SAMPLER_2D_MULTISAMPLE,
  416. INT_SAMPLER_2D_MULTISAMPLE_ARRAY = GL_INT_SAMPLER_2D_MULTISAMPLE_ARRAY,
  417. INT_SAMPLER_BUFFER = GL_INT_SAMPLER_BUFFER_EXT,
  418. INT_SAMPLER_2D_RECT = GL_INT_SAMPLER_2D_RECT_EXT,
  419. UNSIGNED_INT_SAMPLER_1D = GL_UNSIGNED_INT_SAMPLER_1D_EXT,
  420. UNSIGNED_INT_SAMPLER_2D = GL_UNSIGNED_INT_SAMPLER_2D_EXT,
  421. UNSIGNED_INT_SAMPLER_3D = GL_UNSIGNED_INT_SAMPLER_3D_EXT,
  422. UNSIGNED_INT_SAMPLER_CUBE = GL_UNSIGNED_INT_SAMPLER_CUBE_EXT,
  423. UNSIGNED_INT_SAMPLER_1D_ARRAY = GL_UNSIGNED_INT_SAMPLER_1D_ARRAY_EXT,
  424. UNSIGNED_INT_SAMPLER_2D_ARRAY = GL_UNSIGNED_INT_SAMPLER_2D_ARRAY_EXT,
  425. UNSIGNED_INT_SAMPLER_CUBE_MAP_ARRAY = GL_UNSIGNED_INT_SAMPLER_CUBE_MAP_ARRAY,
  426. UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE = GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE,
  427. UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE_ARRAY = GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE_ARRAY,
  428. UNSIGNED_INT_SAMPLER_BUFFER = GL_UNSIGNED_INT_SAMPLER_BUFFER_EXT,
  429. UNSIGNED_INT_SAMPLER_2D_RECT = GL_UNSIGNED_INT_SAMPLER_2D_RECT_EXT,
  430. IMAGE_1D = GL_IMAGE_1D,
  431. IMAGE_2D = GL_IMAGE_2D,
  432. IMAGE_3D = GL_IMAGE_3D,
  433. IMAGE_2D_RECT = GL_IMAGE_2D_RECT,
  434. IMAGE_CUBE = GL_IMAGE_CUBE,
  435. IMAGE_BUFFER = GL_IMAGE_BUFFER,
  436. IMAGE_1D_ARRAY = GL_IMAGE_1D_ARRAY,
  437. IMAGE_2D_ARRAY = GL_IMAGE_2D_ARRAY,
  438. IMAGE_CUBE_MAP_ARRAY = GL_IMAGE_CUBE_MAP_ARRAY,
  439. IMAGE_2D_MULTISAMPLE = GL_IMAGE_2D_MULTISAMPLE,
  440. IMAGE_2D_MULTISAMPLE_ARRAY = GL_IMAGE_2D_MULTISAMPLE_ARRAY,
  441. INT_IMAGE_1D = GL_INT_IMAGE_1D,
  442. INT_IMAGE_2D = GL_INT_IMAGE_2D,
  443. INT_IMAGE_3D = GL_INT_IMAGE_3D,
  444. INT_IMAGE_2D_RECT = GL_INT_IMAGE_2D_RECT,
  445. INT_IMAGE_CUBE = GL_INT_IMAGE_CUBE,
  446. INT_IMAGE_BUFFER = GL_INT_IMAGE_BUFFER,
  447. INT_IMAGE_1D_ARRAY = GL_INT_IMAGE_1D_ARRAY,
  448. INT_IMAGE_2D_ARRAY = GL_INT_IMAGE_2D_ARRAY,
  449. INT_IMAGE_CUBE_MAP_ARRAY = GL_INT_IMAGE_CUBE_MAP_ARRAY,
  450. INT_IMAGE_2D_MULTISAMPLE = GL_INT_IMAGE_2D_MULTISAMPLE,
  451. INT_IMAGE_2D_MULTISAMPLE_ARRAY = GL_INT_IMAGE_2D_MULTISAMPLE_ARRAY,
  452. UNSIGNED_INT_IMAGE_1D = GL_UNSIGNED_INT_IMAGE_1D,
  453. UNSIGNED_INT_IMAGE_2D = GL_UNSIGNED_INT_IMAGE_2D,
  454. UNSIGNED_INT_IMAGE_3D = GL_UNSIGNED_INT_IMAGE_3D,
  455. UNSIGNED_INT_IMAGE_2D_RECT = GL_UNSIGNED_INT_IMAGE_2D_RECT,
  456. UNSIGNED_INT_IMAGE_CUBE = GL_UNSIGNED_INT_IMAGE_CUBE,
  457. UNSIGNED_INT_IMAGE_BUFFER = GL_UNSIGNED_INT_IMAGE_BUFFER,
  458. UNSIGNED_INT_IMAGE_1D_ARRAY = GL_UNSIGNED_INT_IMAGE_1D_ARRAY,
  459. UNSIGNED_INT_IMAGE_2D_ARRAY = GL_UNSIGNED_INT_IMAGE_2D_ARRAY,
  460. UNSIGNED_INT_IMAGE_CUBE_MAP_ARRAY = GL_UNSIGNED_INT_IMAGE_CUBE_MAP_ARRAY,
  461. UNSIGNED_INT_IMAGE_2D_MULTISAMPLE = GL_UNSIGNED_INT_IMAGE_2D_MULTISAMPLE,
  462. UNSIGNED_INT_IMAGE_2D_MULTISAMPLE_ARRAY = GL_UNSIGNED_INT_IMAGE_2D_MULTISAMPLE_ARRAY,
  463. UNDEFINED = 0x0
  464. };
  465. public:
  466. Uniform();
  467. Uniform( Type type, const std::string& name, int numElements=1 );
  468. /** Copy constructor using CopyOp to manage deep vs shallow copy. */
  469. Uniform(const Uniform& rhs, const CopyOp& copyop=CopyOp::SHALLOW_COPY);
  470. META_Object(osg, Uniform);
  471. /** Convert 'this' into a Uniform pointer if Object is a Uniform, otherwise return 0.
  472. * Equivalent to dynamic_cast<Uniform*>(this).*/
  473. virtual Uniform* asUniform() { return this; }
  474. /** convert 'const this' into a const Uniform pointer if Object is a Uniform, otherwise return 0.
  475. * Equivalent to dynamic_cast<const Uniform*>(this).*/
  476. virtual const Uniform* asUniform() const { return this; }
  477. /** Set the type of glUniform, ensuring it is only set once.*/
  478. bool setType( Type t );
  479. /** Get the type of glUniform as enum. */
  480. Type getType() const { return _type; }
  481. /** Set the name of the glUniform, ensuring it is only set once.*/
  482. virtual void setName( const std::string& name );
  483. /** Set the length of a uniform, ensuring it is only set once (1==scalar)*/
  484. void setNumElements( unsigned int numElements );
  485. /** Get the number of GLSL elements of the osg::Uniform (1==scalar) */
  486. unsigned int getNumElements() const { return _numElements; }
  487. /** Get the number of elements required for the internal data array.
  488. * Returns 0 if the osg::Uniform is not properly configured. */
  489. unsigned int getInternalArrayNumElements() const;
  490. /** Return the name of a Type enum as string. */
  491. static const char* getTypename( Type t );
  492. /** Return the number of components for a GLSL type. */
  493. static int getTypeNumComponents( Type t );
  494. /** Return the Type enum of a Uniform typename string */
  495. static Uniform::Type getTypeId( const std::string& tname );
  496. /** Return the GL API type corresponding to a GLSL type */
  497. static Type getGlApiType( Type t );
  498. /** Return the internal data array type corresponding to a GLSL type */
  499. static GLenum getInternalArrayType( Type t );
  500. /** Return the number that the name maps to uniquely */
  501. static unsigned int getNameID(const std::string& name);
  502. /** convenient scalar (non-array) constructors w/ assignment */
  503. explicit Uniform( const char* name, float f );
  504. explicit Uniform( const char* name, double d );
  505. explicit Uniform( const char* name, int i );
  506. explicit Uniform( const char* name, unsigned int ui );
  507. explicit Uniform( const char* name, bool b );
  508. explicit Uniform( const char* name, unsigned long long ull);
  509. explicit Uniform( const char* name, long long ll );
  510. Uniform( const char* name, const osg::Vec2& v2 );
  511. Uniform( const char* name, const osg::Vec3& v3 );
  512. Uniform( const char* name, const osg::Vec4& v4 );
  513. Uniform( const char* name, const osg::Vec2d& v2 );
  514. Uniform( const char* name, const osg::Vec3d& v3 );
  515. Uniform( const char* name, const osg::Vec4d& v4 );
  516. Uniform( const char* name, const osg::Matrix2& m2 );
  517. Uniform( const char* name, const osg::Matrix3& m3 );
  518. Uniform( const char* name, const osg::Matrixf& m4 );
  519. Uniform( const char* name, const osg::Matrix2x3& m2x3 );
  520. Uniform( const char* name, const osg::Matrix2x4& m2x4 );
  521. Uniform( const char* name, const osg::Matrix3x2& m3x2 );
  522. Uniform( const char* name, const osg::Matrix3x4& m3x4 );
  523. Uniform( const char* name, const osg::Matrix4x2& m4x2 );
  524. Uniform( const char* name, const osg::Matrix4x3& m4x3 );
  525. Uniform( const char* name, const osg::Matrix2d& m2 );
  526. Uniform( const char* name, const osg::Matrix3d& m3 );
  527. Uniform( const char* name, const osg::Matrixd& m4 );
  528. Uniform( const char* name, const osg::Matrix2x3d& m2x3 );
  529. Uniform( const char* name, const osg::Matrix2x4d& m2x4 );
  530. Uniform( const char* name, const osg::Matrix3x2d& m3x2 );
  531. Uniform( const char* name, const osg::Matrix3x4d& m3x4 );
  532. Uniform( const char* name, const osg::Matrix4x2d& m4x2 );
  533. Uniform( const char* name, const osg::Matrix4x3d& m4x3 );
  534. Uniform( const char* name, int i0, int i1 );
  535. Uniform( const char* name, int i0, int i1, int i2 );
  536. Uniform( const char* name, int i0, int i1, int i2, int i3 );
  537. Uniform( const char* name, unsigned int ui0, unsigned int ui1 );
  538. Uniform( const char* name, unsigned int ui0, unsigned int ui1, unsigned int ui2 );
  539. Uniform( const char* name, unsigned int ui0, unsigned int ui1, unsigned int ui2, unsigned int ui3 );
  540. Uniform( const char* name, bool b0, bool b1 );
  541. Uniform( const char* name, bool b0, bool b1, bool b2 );
  542. Uniform( const char* name, bool b0, bool b1, bool b2, bool b3 );
  543. /** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs. */
  544. virtual int compare(const Uniform& rhs) const;
  545. virtual int compareData(const Uniform& rhs) const;
  546. bool operator < (const Uniform& rhs) const { return compare(rhs)<0; }
  547. bool operator == (const Uniform& rhs) const { return compare(rhs)==0; }
  548. bool operator != (const Uniform& rhs) const { return compare(rhs)!=0; }
  549. void copyData( const Uniform& rhs );
  550. /** A vector of osg::StateSet pointers which is used to store the parent(s) of this Uniform, the parents could be osg::Node or osg::Drawable.*/
  551. typedef std::vector<StateSet*> ParentList;
  552. /** Get the parent list of this Uniform. */
  553. inline const ParentList& getParents() const { return _parents; }
  554. /** Get the a copy of parent list of node. A copy is returned to
  555. * prevent modification of the parent list.*/
  556. inline ParentList getParents() { return _parents; }
  557. inline StateSet* getParent(unsigned int i) { return _parents[i]; }
  558. /**
  559. * Get a single const parent of this Uniform.
  560. * @param i index of the parent to get.
  561. * @return the parent i.
  562. */
  563. inline const StateSet* getParent(unsigned int i) const { return _parents[i]; }
  564. /**
  565. * Get the number of parents of this Uniform.
  566. * @return the number of parents of this Uniform.
  567. */
  568. inline unsigned int getNumParents() const { return static_cast<unsigned int>(_parents.size()); }
  569. /** convenient scalar (non-array) value assignment */
  570. bool set( float f );
  571. bool set( double d );
  572. bool set( int i );
  573. bool set( unsigned int ui );
  574. bool set( bool b );
  575. bool set( unsigned long long ull );
  576. bool set( long long ll );
  577. bool set( const osg::Vec2& v2 );
  578. bool set( const osg::Vec3& v3 );
  579. bool set( const osg::Vec4& v4 );
  580. bool set( const osg::Vec2d& v2 );
  581. bool set( const osg::Vec3d& v3 );
  582. bool set( const osg::Vec4d& v4 );
  583. bool set( const osg::Matrix2& m2 );
  584. bool set( const osg::Matrix3& m3 );
  585. bool set( const osg::Matrixf& m4 );
  586. bool set( const osg::Matrix2x3& m2x3 );
  587. bool set( const osg::Matrix2x4& m2x4 );
  588. bool set( const osg::Matrix3x2& m3x2 );
  589. bool set( const osg::Matrix3x4& m3x4 );
  590. bool set( const osg::Matrix4x2& m4x2 );
  591. bool set( const osg::Matrix4x3& m4x3 );
  592. bool set( const osg::Matrix2d& m2 );
  593. bool set( const osg::Matrix3d& m3 );
  594. bool set( const osg::Matrixd& m4 );
  595. bool set( const osg::Matrix2x3d& m2x3 );
  596. bool set( const osg::Matrix2x4d& m2x4 );
  597. bool set( const osg::Matrix3x2d& m3x2 );
  598. bool set( const osg::Matrix3x4d& m3x4 );
  599. bool set( const osg::Matrix4x2d& m4x2 );
  600. bool set( const osg::Matrix4x3d& m4x3 );
  601. bool set( int i0, int i1 );
  602. bool set( int i0, int i1, int i2 );
  603. bool set( int i0, int i1, int i2, int i3 );
  604. bool set( unsigned int ui0, unsigned int ui1 );
  605. bool set( unsigned int ui0, unsigned int ui1, unsigned int ui2 );
  606. bool set( unsigned int ui0, unsigned int ui1, unsigned int ui2, unsigned int ui3 );
  607. bool set( bool b0, bool b1 );
  608. bool set( bool b0, bool b1, bool b2 );
  609. bool set( bool b0, bool b1, bool b2, bool b3 );
  610. /** convenient scalar (non-array) value query */
  611. bool get( float& f ) const;
  612. bool get( double& d ) const;
  613. bool get( int& i ) const;
  614. bool get( unsigned int& ui ) const;
  615. bool get( bool& b ) const;
  616. bool get( unsigned long long & ull ) const;
  617. bool get( long long& ll ) const;
  618. bool get( osg::Vec2& v2 ) const;
  619. bool get( osg::Vec3& v3 ) const;
  620. bool get( osg::Vec4& v4 ) const;
  621. bool get( osg::Vec2d& v2 ) const;
  622. bool get( osg::Vec3d& v3 ) const;
  623. bool get( osg::Vec4d& v4 ) const;
  624. bool get( osg::Matrix2& m2 ) const;
  625. bool get( osg::Matrix3& m3 ) const;
  626. bool get( osg::Matrixf& m4 ) const;
  627. bool get( osg::Matrix2x3& m2x3 ) const;
  628. bool get( osg::Matrix2x4& m2x4 ) const;
  629. bool get( osg::Matrix3x2& m3x2 ) const;
  630. bool get( osg::Matrix3x4& m3x4 ) const;
  631. bool get( osg::Matrix4x2& m4x2 ) const;
  632. bool get( osg::Matrix4x3& m4x3 ) const;
  633. bool get( osg::Matrix2d& m2 ) const;
  634. bool get( osg::Matrix3d& m3 ) const;
  635. bool get( osg::Matrixd& m4 ) const;
  636. bool get( osg::Matrix2x3d& m2x3 ) const;
  637. bool get( osg::Matrix2x4d& m2x4 ) const;
  638. bool get( osg::Matrix3x2d& m3x2 ) const;
  639. bool get( osg::Matrix3x4d& m3x4 ) const;
  640. bool get( osg::Matrix4x2d& m4x2 ) const;
  641. bool get( osg::Matrix4x3d& m4x3 ) const;
  642. bool get( int& i0, int& i1 ) const;
  643. bool get( int& i0, int& i1, int& i2 ) const;
  644. bool get( int& i0, int& i1, int& i2, int& i3 ) const;
  645. bool get( unsigned int& ui0, unsigned int& ui1 ) const;
  646. bool get( unsigned int& ui0, unsigned int& ui1, unsigned int& ui2 ) const;
  647. bool get( unsigned int& ui0, unsigned int& ui1, unsigned int& ui2, unsigned int& ui3 ) const;
  648. bool get( bool& b0, bool& b1 ) const;
  649. bool get( bool& b0, bool& b1, bool& b2 ) const;
  650. bool get( bool& b0, bool& b1, bool& b2, bool& b3 ) const;
  651. /** value assignment for array uniforms */
  652. bool setElement( unsigned int index, float f );
  653. bool setElement( unsigned int index, double d );
  654. bool setElement( unsigned int index, int i );
  655. bool setElement( unsigned int index, unsigned int ui );
  656. bool setElement( unsigned int index, bool b );
  657. bool setElement( unsigned int index, unsigned long long ull );
  658. bool setElement( unsigned int index, long long ll );
  659. bool setElement( unsigned int index, const osg::Vec2& v2 );
  660. bool setElement( unsigned int index, const osg::Vec3& v3 );
  661. bool setElement( unsigned int index, const osg::Vec4& v4 );
  662. bool setElement( unsigned int index, const osg::Vec2d& v2 );
  663. bool setElement( unsigned int index, const osg::Vec3d& v3 );
  664. bool setElement( unsigned int index, const osg::Vec4d& v4 );
  665. bool setElement( unsigned int index, const osg::Matrix2& m2 );
  666. bool setElement( unsigned int index, const osg::Matrix3& m3 );
  667. bool setElement( unsigned int index, const osg::Matrixf& m4 );
  668. bool setElement( unsigned int index, const osg::Matrix2x3& m2x3 );
  669. bool setElement( unsigned int index, const osg::Matrix2x4& m2x4 );
  670. bool setElement( unsigned int index, const osg::Matrix3x2& m3x2 );
  671. bool setElement( unsigned int index, const osg::Matrix3x4& m3x4 );
  672. bool setElement( unsigned int index, const osg::Matrix4x2& m4x2 );
  673. bool setElement( unsigned int index, const osg::Matrix4x3& m4x3 );
  674. bool setElement( unsigned int index, const osg::Matrix2d& m2 );
  675. bool setElement( unsigned int index, const osg::Matrix3d& m3 );
  676. bool setElement( unsigned int index, const osg::Matrixd& m4 );
  677. bool setElement( unsigned int index, const osg::Matrix2x3d& m2x3 );
  678. bool setElement( unsigned int index, const osg::Matrix2x4d& m2x4 );
  679. bool setElement( unsigned int index, const osg::Matrix3x2d& m3x2 );
  680. bool setElement( unsigned int index, const osg::Matrix3x4d& m3x4 );
  681. bool setElement( unsigned int index, const osg::Matrix4x2d& m4x2 );
  682. bool setElement( unsigned int index, const osg::Matrix4x3d& m4x3 );
  683. bool setElement( unsigned int index, int i0, int i1 );
  684. bool setElement( unsigned int index, int i0, int i1, int i2 );
  685. bool setElement( unsigned int index, int i0, int i1, int i2, int i3 );
  686. bool setElement( unsigned int index, unsigned int ui0, unsigned int ui1 );
  687. bool setElement( unsigned int index, unsigned int ui0, unsigned int ui1, unsigned int ui2 );
  688. bool setElement( unsigned int index, unsigned int ui0, unsigned int ui1, unsigned int ui2, unsigned int ui3 );
  689. bool setElement( unsigned int index, bool b0, bool b1 );
  690. bool setElement( unsigned int index, bool b0, bool b1, bool b2 );
  691. bool setElement( unsigned int index, bool b0, bool b1, bool b2, bool b3 );
  692. /** value query for array uniforms */
  693. bool getElement( unsigned int index, float& f ) const;
  694. bool getElement( unsigned int index, double& d ) const;
  695. bool getElement( unsigned int index, int& i ) const;
  696. bool getElement( unsigned int index, unsigned int& ui ) const;
  697. bool getElement( unsigned int index, bool& b ) const;
  698. bool getElement( unsigned int index, unsigned long long & ull ) const;
  699. bool getElement( unsigned int index, long long& ll ) const;
  700. bool getElement( unsigned int index, osg::Vec2& v2 ) const;
  701. bool getElement( unsigned int index, osg::Vec3& v3 ) const;
  702. bool getElement( unsigned int index, osg::Vec4& v4 ) const;
  703. bool getElement( unsigned int index, osg::Vec2d& v2 ) const;
  704. bool getElement( unsigned int index, osg::Vec3d& v3 ) const;
  705. bool getElement( unsigned int index, osg::Vec4d& v4 ) const;
  706. bool getElement( unsigned int index, osg::Matrix2& m2 ) const;
  707. bool getElement( unsigned int index, osg::Matrix3& m3 ) const;
  708. bool getElement( unsigned int index, osg::Matrixf& m4 ) const;
  709. bool getElement( unsigned int index, osg::Matrix2x3& m2x3 ) const;
  710. bool getElement( unsigned int index, osg::Matrix2x4& m2x4 ) const;
  711. bool getElement( unsigned int index, osg::Matrix3x2& m3x2 ) const;
  712. bool getElement( unsigned int index, osg::Matrix3x4& m3x4 ) const;
  713. bool getElement( unsigned int index, osg::Matrix4x2& m4x2 ) const;
  714. bool getElement( unsigned int index, osg::Matrix4x3& m4x3 ) const;
  715. bool getElement( unsigned int index, osg::Matrix2d& m2 ) const;
  716. bool getElement( unsigned int index, osg::Matrix3d& m3 ) const;
  717. bool getElement( unsigned int index, osg::Matrixd& m4 ) const;
  718. bool getElement( unsigned int index, osg::Matrix2x3d& m2x3 ) const;
  719. bool getElement( unsigned int index, osg::Matrix2x4d& m2x4 ) const;
  720. bool getElement( unsigned int index, osg::Matrix3x2d& m3x2 ) const;
  721. bool getElement( unsigned int index, osg::Matrix3x4d& m3x4 ) const;
  722. bool getElement( unsigned int index, osg::Matrix4x2d& m4x2 ) const;
  723. bool getElement( unsigned int index, osg::Matrix4x3d& m4x3 ) const;
  724. bool getElement( unsigned int index, int& i0, int& i1 ) const;
  725. bool getElement( unsigned int index, int& i0, int& i1, int& i2 ) const;
  726. bool getElement( unsigned int index, int& i0, int& i1, int& i2, int& i3 ) const;
  727. bool getElement( unsigned int index, unsigned int& ui0, unsigned int& ui1 ) const;
  728. bool getElement( unsigned int index, unsigned int& ui0, unsigned int& ui1, unsigned int& ui2 ) const;
  729. bool getElement( unsigned int index, unsigned int& ui0, unsigned int& ui1, unsigned int& ui2, unsigned int& ui3 ) const;
  730. bool getElement( unsigned int index, bool& b0, bool& b1 ) const;
  731. bool getElement( unsigned int index, bool& b0, bool& b1, bool& b2 ) const;
  732. bool getElement( unsigned int index, bool& b0, bool& b1, bool& b2, bool& b3 ) const;
  733. /** provide typedef for backwards compatibility to OSG-3.2 and other previous versions. */
  734. typedef UniformCallback Callback;
  735. /** Set the UpdateCallback which allows users to attach customize the updating of an object during the update traversal.*/
  736. void setUpdateCallback(UniformCallback* uc);
  737. /** Get the non const UpdateCallback.*/
  738. UniformCallback* getUpdateCallback() { return _updateCallback.get(); }
  739. /** Get the const UpdateCallback.*/
  740. const UniformCallback* getUpdateCallback() const { return _updateCallback.get(); }
  741. /** Set the EventCallback which allows users to attach customize the updating of an object during the Event traversal.*/
  742. void setEventCallback(UniformCallback* ec);
  743. /** Get the non const EventCallback.*/
  744. UniformCallback* getEventCallback() { return _eventCallback.get(); }
  745. /** Get the const EventCallback.*/
  746. const UniformCallback* getEventCallback() const { return _eventCallback.get(); }
  747. /** Increment the modified count on the Uniform so Programs watching it know it update themselves.
  748. * NOTE: automatically called during osg::Uniform::set*();
  749. * you must call if modifying the internal data array directly. */
  750. inline void dirty() { ++_modifiedCount; }
  751. /** Set the internal data array for a osg::Uniform */
  752. bool setArray( FloatArray* array );
  753. bool setArray( DoubleArray* array );
  754. bool setArray( IntArray* array );
  755. bool setArray( UIntArray* array );
  756. bool setArray( UInt64Array* array );
  757. bool setArray( Int64Array* array );
  758. /** Get the internal data array for a float osg::Uniform. */
  759. FloatArray* getFloatArray() { return _floatArray.get(); }
  760. const FloatArray* getFloatArray() const { return _floatArray.get(); }
  761. /** Get the internal data array for a double osg::Uniform. */
  762. DoubleArray* getDoubleArray() { return _doubleArray.get(); }
  763. const DoubleArray* getDoubleArray() const { return _doubleArray.get(); }
  764. /** Get the internal data array for an int osg::Uniform. */
  765. IntArray* getIntArray() { return _intArray.get(); }
  766. const IntArray* getIntArray() const { return _intArray.get(); }
  767. /** Get the internal data array for an unsigned int osg::Uniform. */
  768. UIntArray* getUIntArray() { return _uintArray.get(); }
  769. const UIntArray* getUIntArray() const { return _uintArray.get(); }
  770. /** Get the internal data array for an unsigned int osg::Uniform. */
  771. UInt64Array* getUInt64Array() { return _uint64Array.get(); }
  772. const UInt64Array* getUInt64Array() const { return _uint64Array.get(); }
  773. /** Get the internal data array for an unsigned int osg::Uniform. */
  774. Int64Array* getInt64Array() { return _int64Array.get(); }
  775. const Int64Array* getInt64Array() const { return _int64Array.get(); }
  776. inline void setModifiedCount(unsigned int mc) { _modifiedCount = mc; }
  777. inline unsigned int getModifiedCount() const { return _modifiedCount; }
  778. /** Get the number that the Uniform's name maps to uniquely */
  779. unsigned int getNameID() const;
  780. void apply(const GLExtensions* ext, GLint location) const;
  781. protected:
  782. virtual ~Uniform();
  783. Uniform& operator=(const Uniform&) { return *this; }
  784. bool isCompatibleType( Type t ) const;
  785. // for backward compatibility only
  786. // see getElement(index, osg::Matrixd &)
  787. // see setElement(index, osg::Matrixd &)
  788. bool isCompatibleType( Type t1, Type t2 ) const;
  789. bool isScalar() const { return _numElements==1; }
  790. void allocateDataArray();
  791. void addParent(osg::StateSet* object);
  792. void removeParent(osg::StateSet* object);
  793. ParentList _parents;
  794. friend class osg::StateSet;
  795. Type _type;
  796. unsigned int _numElements;
  797. unsigned int _nameID;
  798. // The internal data for osg::Uniforms are stored as an array of
  799. // getInternalArrayType() of length getInternalArrayNumElements().
  800. ref_ptr<FloatArray> _floatArray;
  801. ref_ptr<DoubleArray> _doubleArray;
  802. ref_ptr<IntArray> _intArray;
  803. ref_ptr<UIntArray> _uintArray;
  804. ref_ptr<Int64Array> _int64Array;
  805. ref_ptr<UInt64Array> _uint64Array;
  806. ref_ptr<UniformCallback> _updateCallback;
  807. ref_ptr<UniformCallback> _eventCallback;
  808. unsigned int _modifiedCount;
  809. };
  810. }
  811. #endif