Ai
7 Star 22 Fork 16

Gitee 极速下载/OpenSceneGraph

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/openscenegraph/OpenSceneGraph
克隆/下载
Uniform 31.23 KB
一键复制 编辑 原始数据 按行查看 历史
Robert Osfield 提交于 2018-05-14 17:47 +08:00 . Imoroved backwards compatibility with 3.6
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
* Copyright (C) 2003-2005 3Dlabs Inc. Ltd.
* Copyright (C) 2008 Zebra Imaging
* Copyright (C) 2012 David Callu
*
* This application is open source and may be redistributed and/or modified
* freely and without restriction, both in commercial and non commercial
* applications, as long as this copyright notice is maintained.
*
* This application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
/* file: include/osg/Uniform
* author: Mike Weiblen 2008-01-02
*/
#ifndef OSG_UNIFORM
#define OSG_UNIFORM 1
#include <osg/UniformBase>
#include <osg/Array>
#include <osg/Callback>
#include <osg/Vec2>
#include <osg/Vec3>
#include <osg/Vec4>
#include <osg/Vec2i>
#include <osg/Vec3i>
#include <osg/Vec4i>
#include <osg/Vec2ui>
#include <osg/Vec3ui>
#include <osg/Vec4ui>
#include <osg/Vec2d>
#include <osg/Vec3d>
#include <osg/Vec4d>
#include <osg/Plane>
#include <osg/GLExtensions>
namespace osg {
template< typename T >
struct UniformClassNameTrait
{
static const char* className() { return "TemplateUniform"; }
};
template<typename T>
class TemplateUniform : public osg::UniformBase
{
public:
typedef T value_type;
TemplateUniform() {}
TemplateUniform(const std::string& name) : osg::UniformBase(name) {}
TemplateUniform(const value_type& value) : _value(value) {}
TemplateUniform(const std::string& name, const value_type& value) : osg::UniformBase(name), _value(value) {}
TemplateUniform(const TemplateUniform& rhs, const osg::CopyOp copyop=osg::CopyOp::SHALLOW_COPY) :
osg::UniformBase(rhs,copyop),
_value(rhs._value) {}
virtual Object* cloneType() const { return new TemplateUniform(); }
virtual Object* clone(const CopyOp& copyop) const { return new TemplateUniform(*this, copyop); }
virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const TemplateUniform*>(obj)!=NULL; }
virtual const char* libraryName() const { return "osg"; }
virtual const char* className() const { return UniformClassNameTrait<T>::className(); }
virtual void apply(const osg::GLExtensions* ext, GLint location) const
{
ext->glUniform(location, _value);
}
void setValue(const value_type& value) { if (_value!=value) { _value = value; dirty(); } }
value_type& getValue() { return _value; }
const value_type& getValue() const { return _value; }
protected:
value_type _value;
};
#define META_Uniform(TYPE,NAME) \
template<> struct UniformClassNameTrait<TYPE> { static const char* className() { return #NAME; } }; \
typedef TemplateUniform<TYPE> NAME;
META_Uniform(int, IntUniform)
META_Uniform(unsigned int, UIntUniform)
META_Uniform(float, FloatUniform)
META_Uniform(double, DoubleUniform)
META_Uniform(osg::Vec2i, Vec2iUniform)
META_Uniform(osg::Vec3i, Vec3iUniform)
META_Uniform(osg::Vec4i, Vec4iUniform)
META_Uniform(osg::Vec2ui, Vec2uiUniform)
META_Uniform(osg::Vec3ui, Vec3uiUniform)
META_Uniform(osg::Vec4ui, Vec4uiUniform)
META_Uniform(osg::Vec2, Vec2Uniform)
META_Uniform(osg::Vec3, Vec3Uniform)
META_Uniform(osg::Vec4, Vec4Uniform)
META_Uniform(osg::Vec2d, Vec2dUniform)
META_Uniform(osg::Vec3d, Vec3dUniform)
META_Uniform(osg::Vec4d, Vec4dUniform)
META_Uniform(osg::Plane, PlaneUniform)
META_Uniform(osg::Matrixf, MatrixfUniform)
META_Uniform(osg::Matrixd, MatrixdUniform)
template< typename T >
struct ArrayUniformClassNameTrait
{
static const char* className() { return "TemplateArrayUniform"; }
};
template<typename T>
class TemplateArrayUniform : public osg::UniformBase
{
public:
typedef T value_type;
typedef std::vector<value_type> array_type;
TemplateArrayUniform() {}
TemplateArrayUniform(const std::string& name) : osg::UniformBase(name) {}
TemplateArrayUniform(const std::string& name, unsigned int new_size) : osg::UniformBase(name), _array(new_size) {}
TemplateArrayUniform(const TemplateArrayUniform& rhs, const osg::CopyOp copyop=osg::CopyOp::SHALLOW_COPY) :
osg::UniformBase(rhs,copyop),
_array(rhs._array) {}
virtual Object* cloneType() const { return new TemplateArrayUniform(); }
virtual Object* clone(const CopyOp& copyop) const { return new TemplateArrayUniform(*this, copyop); }
virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const TemplateArrayUniform*>(obj)!=NULL; }
virtual const char* libraryName() const { return "osg"; }
virtual const char* className() const { return ArrayUniformClassNameTrait<T>::className(); }
virtual void apply(const osg::GLExtensions* ext, GLint location) const
{
ext->glUniform(location, _array);
}
bool empty() const { return _array.empty(); }
void resize(unsigned int new_size) { _array.resize(new_size); }
unsigned int size() const { return static_cast<unsigned int>(_array.size()); }
void setElement(unsigned int i, const value_type& value) { if (_array[i]!=value) { _array[i] = value; dirty(); } }
value_type& getElement(unsigned int i) { return _array[i]; }
const value_type& getElement(unsigned int i) const { return _array[i]; }
void setArray(const array_type& array) { if (_array!=array) { _array = array; dirty(); } }
array_type& getArray() { return _array; }
const array_type& getArray() const { return _array; }
protected:
array_type _array;
};
#define META_ArrayUniform(TYPE,NAME) \
template<> struct ArrayUniformClassNameTrait<TYPE> { static const char* className() { return #NAME; } }; \
typedef TemplateArrayUniform<TYPE> NAME;
META_ArrayUniform(int, IntArrayUniform)
META_ArrayUniform(unsigned int, UIntArrayUniform)
META_ArrayUniform(float, FloatArrayUniform)
META_ArrayUniform(double, DoubleArrayUniform)
META_ArrayUniform(osg::Vec2, Vec2ArrayUniform)
META_ArrayUniform(osg::Vec3, Vec3ArrayUniform)
META_ArrayUniform(osg::Vec4, Vec4ArrayUniform)
META_ArrayUniform(osg::Vec2d, Vec2dArrayUniform)
META_ArrayUniform(osg::Vec3d, Vec3dArrayUniform)
META_ArrayUniform(osg::Vec4d, Vec4dArrayUniform)
META_ArrayUniform(osg::Vec2i, Vec2iArrayUniform)
META_ArrayUniform(osg::Vec3i, Vec3iArrayUniform)
META_ArrayUniform(osg::Vec4i, Vec4iArrayUniform)
META_ArrayUniform(osg::Vec2ui, Vec2uiArrayUniform)
META_ArrayUniform(osg::Vec3ui, Vec3uiArrayUniform)
META_ArrayUniform(osg::Vec4ui, Vec4uiArrayUniform)
META_ArrayUniform(osg::Matrixf, MatrixfArrayUniform)
META_ArrayUniform(osg::Matrixd, MatrixdArrayUniform)
/** Deprecated Uniform provides backwards compatibility. */
class OSG_EXPORT Uniform : public UniformBase
{
public:
enum Type {
FLOAT = GL_FLOAT,
FLOAT_VEC2 = GL_FLOAT_VEC2,
FLOAT_VEC3 = GL_FLOAT_VEC3,
FLOAT_VEC4 = GL_FLOAT_VEC4,
DOUBLE = GL_DOUBLE,
DOUBLE_VEC2 = GL_DOUBLE_VEC2,
DOUBLE_VEC3 = GL_DOUBLE_VEC3,
DOUBLE_VEC4 = GL_DOUBLE_VEC4,
INT = GL_INT,
INT_VEC2 = GL_INT_VEC2,
INT_VEC3 = GL_INT_VEC3,
INT_VEC4 = GL_INT_VEC4,
UNSIGNED_INT = GL_UNSIGNED_INT,
UNSIGNED_INT_VEC2 = GL_UNSIGNED_INT_VEC2_EXT,
UNSIGNED_INT_VEC3 = GL_UNSIGNED_INT_VEC3_EXT,
UNSIGNED_INT_VEC4 = GL_UNSIGNED_INT_VEC4_EXT,
BOOL = GL_BOOL,
BOOL_VEC2 = GL_BOOL_VEC2,
BOOL_VEC3 = GL_BOOL_VEC3,
BOOL_VEC4 = GL_BOOL_VEC4,
INT64 = GL_INT64_ARB,
UNSIGNED_INT64 = GL_UNSIGNED_INT64_ARB,
FLOAT_MAT2 = GL_FLOAT_MAT2,
FLOAT_MAT3 = GL_FLOAT_MAT3,
FLOAT_MAT4 = GL_FLOAT_MAT4,
FLOAT_MAT2x3 = GL_FLOAT_MAT2x3,
FLOAT_MAT2x4 = GL_FLOAT_MAT2x4,
FLOAT_MAT3x2 = GL_FLOAT_MAT3x2,
FLOAT_MAT3x4 = GL_FLOAT_MAT3x4,
FLOAT_MAT4x2 = GL_FLOAT_MAT4x2,
FLOAT_MAT4x3 = GL_FLOAT_MAT4x3,
DOUBLE_MAT2 = GL_DOUBLE_MAT2,
DOUBLE_MAT3 = GL_DOUBLE_MAT3,
DOUBLE_MAT4 = GL_DOUBLE_MAT4,
DOUBLE_MAT2x3 = GL_DOUBLE_MAT2x3,
DOUBLE_MAT2x4 = GL_DOUBLE_MAT2x4,
DOUBLE_MAT3x2 = GL_DOUBLE_MAT3x2,
DOUBLE_MAT3x4 = GL_DOUBLE_MAT3x4,
DOUBLE_MAT4x2 = GL_DOUBLE_MAT4x2,
DOUBLE_MAT4x3 = GL_DOUBLE_MAT4x3,
SAMPLER_1D = GL_SAMPLER_1D,
SAMPLER_2D = GL_SAMPLER_2D,
SAMPLER_3D = GL_SAMPLER_3D,
SAMPLER_CUBE = GL_SAMPLER_CUBE,
SAMPLER_1D_SHADOW = GL_SAMPLER_1D_SHADOW,
SAMPLER_2D_SHADOW = GL_SAMPLER_2D_SHADOW,
SAMPLER_1D_ARRAY = GL_SAMPLER_1D_ARRAY_EXT,
SAMPLER_2D_ARRAY = GL_SAMPLER_2D_ARRAY_EXT,
SAMPLER_CUBE_MAP_ARRAY = GL_SAMPLER_CUBE_MAP_ARRAY,
SAMPLER_1D_ARRAY_SHADOW = GL_SAMPLER_1D_ARRAY_SHADOW_EXT,
SAMPLER_2D_ARRAY_SHADOW = GL_SAMPLER_2D_ARRAY_SHADOW_EXT,
SAMPLER_2D_MULTISAMPLE = GL_SAMPLER_2D_MULTISAMPLE,
SAMPLER_2D_MULTISAMPLE_ARRAY = GL_SAMPLER_2D_MULTISAMPLE_ARRAY,
SAMPLER_CUBE_SHADOW = GL_SAMPLER_CUBE_SHADOW_EXT,
SAMPLER_CUBE_MAP_ARRAY_SHADOW = GL_SAMPLER_CUBE_MAP_ARRAY_SHADOW,
SAMPLER_BUFFER = GL_SAMPLER_BUFFER_EXT,
SAMPLER_2D_RECT = GL_SAMPLER_2D_RECT,
SAMPLER_2D_RECT_SHADOW = GL_SAMPLER_2D_RECT_SHADOW,
INT_SAMPLER_1D = GL_INT_SAMPLER_1D_EXT,
INT_SAMPLER_2D = GL_INT_SAMPLER_2D_EXT,
INT_SAMPLER_3D = GL_INT_SAMPLER_3D_EXT,
INT_SAMPLER_CUBE = GL_INT_SAMPLER_CUBE_EXT,
INT_SAMPLER_1D_ARRAY = GL_INT_SAMPLER_1D_ARRAY_EXT,
INT_SAMPLER_2D_ARRAY = GL_INT_SAMPLER_2D_ARRAY_EXT,
INT_SAMPLER_CUBE_MAP_ARRAY = GL_INT_SAMPLER_CUBE_MAP_ARRAY,
INT_SAMPLER_2D_MULTISAMPLE = GL_INT_SAMPLER_2D_MULTISAMPLE,
INT_SAMPLER_2D_MULTISAMPLE_ARRAY = GL_INT_SAMPLER_2D_MULTISAMPLE_ARRAY,
INT_SAMPLER_BUFFER = GL_INT_SAMPLER_BUFFER_EXT,
INT_SAMPLER_2D_RECT = GL_INT_SAMPLER_2D_RECT_EXT,
UNSIGNED_INT_SAMPLER_1D = GL_UNSIGNED_INT_SAMPLER_1D_EXT,
UNSIGNED_INT_SAMPLER_2D = GL_UNSIGNED_INT_SAMPLER_2D_EXT,
UNSIGNED_INT_SAMPLER_3D = GL_UNSIGNED_INT_SAMPLER_3D_EXT,
UNSIGNED_INT_SAMPLER_CUBE = GL_UNSIGNED_INT_SAMPLER_CUBE_EXT,
UNSIGNED_INT_SAMPLER_1D_ARRAY = GL_UNSIGNED_INT_SAMPLER_1D_ARRAY_EXT,
UNSIGNED_INT_SAMPLER_2D_ARRAY = GL_UNSIGNED_INT_SAMPLER_2D_ARRAY_EXT,
UNSIGNED_INT_SAMPLER_CUBE_MAP_ARRAY = GL_UNSIGNED_INT_SAMPLER_CUBE_MAP_ARRAY,
UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE = GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE,
UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE_ARRAY = GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE_ARRAY,
UNSIGNED_INT_SAMPLER_BUFFER = GL_UNSIGNED_INT_SAMPLER_BUFFER_EXT,
UNSIGNED_INT_SAMPLER_2D_RECT = GL_UNSIGNED_INT_SAMPLER_2D_RECT_EXT,
IMAGE_1D = GL_IMAGE_1D,
IMAGE_2D = GL_IMAGE_2D,
IMAGE_3D = GL_IMAGE_3D,
IMAGE_2D_RECT = GL_IMAGE_2D_RECT,
IMAGE_CUBE = GL_IMAGE_CUBE,
IMAGE_BUFFER = GL_IMAGE_BUFFER,
IMAGE_1D_ARRAY = GL_IMAGE_1D_ARRAY,
IMAGE_2D_ARRAY = GL_IMAGE_2D_ARRAY,
IMAGE_CUBE_MAP_ARRAY = GL_IMAGE_CUBE_MAP_ARRAY,
IMAGE_2D_MULTISAMPLE = GL_IMAGE_2D_MULTISAMPLE,
IMAGE_2D_MULTISAMPLE_ARRAY = GL_IMAGE_2D_MULTISAMPLE_ARRAY,
INT_IMAGE_1D = GL_INT_IMAGE_1D,
INT_IMAGE_2D = GL_INT_IMAGE_2D,
INT_IMAGE_3D = GL_INT_IMAGE_3D,
INT_IMAGE_2D_RECT = GL_INT_IMAGE_2D_RECT,
INT_IMAGE_CUBE = GL_INT_IMAGE_CUBE,
INT_IMAGE_BUFFER = GL_INT_IMAGE_BUFFER,
INT_IMAGE_1D_ARRAY = GL_INT_IMAGE_1D_ARRAY,
INT_IMAGE_2D_ARRAY = GL_INT_IMAGE_2D_ARRAY,
INT_IMAGE_CUBE_MAP_ARRAY = GL_INT_IMAGE_CUBE_MAP_ARRAY,
INT_IMAGE_2D_MULTISAMPLE = GL_INT_IMAGE_2D_MULTISAMPLE,
INT_IMAGE_2D_MULTISAMPLE_ARRAY = GL_INT_IMAGE_2D_MULTISAMPLE_ARRAY,
UNSIGNED_INT_IMAGE_1D = GL_UNSIGNED_INT_IMAGE_1D,
UNSIGNED_INT_IMAGE_2D = GL_UNSIGNED_INT_IMAGE_2D,
UNSIGNED_INT_IMAGE_3D = GL_UNSIGNED_INT_IMAGE_3D,
UNSIGNED_INT_IMAGE_2D_RECT = GL_UNSIGNED_INT_IMAGE_2D_RECT,
UNSIGNED_INT_IMAGE_CUBE = GL_UNSIGNED_INT_IMAGE_CUBE,
UNSIGNED_INT_IMAGE_BUFFER = GL_UNSIGNED_INT_IMAGE_BUFFER,
UNSIGNED_INT_IMAGE_1D_ARRAY = GL_UNSIGNED_INT_IMAGE_1D_ARRAY,
UNSIGNED_INT_IMAGE_2D_ARRAY = GL_UNSIGNED_INT_IMAGE_2D_ARRAY,
UNSIGNED_INT_IMAGE_CUBE_MAP_ARRAY = GL_UNSIGNED_INT_IMAGE_CUBE_MAP_ARRAY,
UNSIGNED_INT_IMAGE_2D_MULTISAMPLE = GL_UNSIGNED_INT_IMAGE_2D_MULTISAMPLE,
UNSIGNED_INT_IMAGE_2D_MULTISAMPLE_ARRAY = GL_UNSIGNED_INT_IMAGE_2D_MULTISAMPLE_ARRAY,
UNDEFINED = 0x0
};
public:
Uniform();
Uniform( Type type, const std::string& name, int numElements=1 );
/** Copy constructor using CopyOp to manage deep vs shallow copy. */
Uniform(const Uniform& rhs, const CopyOp& copyop=CopyOp::SHALLOW_COPY);
META_Object(osg, Uniform);
/** Convert 'this' into a Uniform pointer if Object is a Uniform, otherwise return 0.
* Equivalent to dynamic_cast<Uniform*>(this).*/
virtual Uniform* asUniform() { return this; }
/** convert 'const this' into a const Uniform pointer if Object is a Uniform, otherwise return 0.
* Equivalent to dynamic_cast<const Uniform*>(this).*/
virtual const Uniform* asUniform() const { return this; }
/** Set the type of glUniform, ensuring it is only set once.*/
virtual bool setType( Type t );
/** Get the type of glUniform as enum. */
Type getType() const { return _type; }
/** Set the length of a uniform, ensuring it is only set once (1==scalar)*/
void setNumElements( unsigned int numElements );
/** Get the number of GLSL elements of the osg::Uniform (1==scalar) */
unsigned int getNumElements() const { return _numElements; }
/** Get the number of elements required for the internal data array.
* Returns 0 if the osg::Uniform is not properly configured. */
unsigned int getInternalArrayNumElements() const;
/** Return the name of a Type enum as string. */
static const char* getTypename( Type t );
/** Return the number of components for a GLSL type. */
static int getTypeNumComponents( Type t );
/** Return the Type enum of a Uniform typename string */
static Uniform::Type getTypeId( const std::string& tname );
/** Return the GL API type corresponding to a GLSL type */
static Type getGlApiType( Type t );
/** Return the internal data array type corresponding to a GLSL type */
static GLenum getInternalArrayType( Type t );
/** Return the number that the name maps to uniquely */
static unsigned int getNameID(const std::string& name);
/** convenient scalar (non-array) constructors w/ assignment */
explicit Uniform( const char* name, float f );
explicit Uniform( const char* name, double d );
explicit Uniform( const char* name, int i );
explicit Uniform( const char* name, unsigned int ui );
explicit Uniform( const char* name, bool b );
explicit Uniform( const char* name, unsigned long long ull);
explicit Uniform( const char* name, long long ll );
Uniform( const char* name, const osg::Vec2& v2 );
Uniform( const char* name, const osg::Vec3& v3 );
Uniform( const char* name, const osg::Vec4& v4 );
Uniform( const char* name, const osg::Vec2d& v2 );
Uniform( const char* name, const osg::Vec3d& v3 );
Uniform( const char* name, const osg::Vec4d& v4 );
Uniform( const char* name, const osg::Matrix2& m2 );
Uniform( const char* name, const osg::Matrix3& m3 );
Uniform( const char* name, const osg::Matrixf& m4 );
Uniform( const char* name, const osg::Matrix2x3& m2x3 );
Uniform( const char* name, const osg::Matrix2x4& m2x4 );
Uniform( const char* name, const osg::Matrix3x2& m3x2 );
Uniform( const char* name, const osg::Matrix3x4& m3x4 );
Uniform( const char* name, const osg::Matrix4x2& m4x2 );
Uniform( const char* name, const osg::Matrix4x3& m4x3 );
Uniform( const char* name, const osg::Matrix2d& m2 );
Uniform( const char* name, const osg::Matrix3d& m3 );
Uniform( const char* name, const osg::Matrixd& m4 );
Uniform( const char* name, const osg::Matrix2x3d& m2x3 );
Uniform( const char* name, const osg::Matrix2x4d& m2x4 );
Uniform( const char* name, const osg::Matrix3x2d& m3x2 );
Uniform( const char* name, const osg::Matrix3x4d& m3x4 );
Uniform( const char* name, const osg::Matrix4x2d& m4x2 );
Uniform( const char* name, const osg::Matrix4x3d& m4x3 );
Uniform( const char* name, int i0, int i1 );
Uniform( const char* name, int i0, int i1, int i2 );
Uniform( const char* name, int i0, int i1, int i2, int i3 );
Uniform( const char* name, unsigned int ui0, unsigned int ui1 );
Uniform( const char* name, unsigned int ui0, unsigned int ui1, unsigned int ui2 );
Uniform( const char* name, unsigned int ui0, unsigned int ui1, unsigned int ui2, unsigned int ui3 );
Uniform( const char* name, bool b0, bool b1 );
Uniform( const char* name, bool b0, bool b1, bool b2 );
Uniform( const char* name, bool b0, bool b1, bool b2, bool b3 );
/** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs. */
virtual int compare(const UniformBase& rhs) const;
virtual int compareData(const UniformBase& rhs) const;
void copyData( const Uniform& rhs );
/** convenient scalar (non-array) value assignment */
bool set( float f );
bool set( double d );
bool set( int i );
bool set( unsigned int ui );
bool set( bool b );
bool set( unsigned long long ull );
bool set( long long ll );
bool set( const osg::Vec2& v2 );
bool set( const osg::Vec3& v3 );
bool set( const osg::Vec4& v4 );
bool set( const osg::Vec2d& v2 );
bool set( const osg::Vec3d& v3 );
bool set( const osg::Vec4d& v4 );
bool set( const osg::Matrix2& m2 );
bool set( const osg::Matrix3& m3 );
bool set( const osg::Matrixf& m4 );
bool set( const osg::Matrix2x3& m2x3 );
bool set( const osg::Matrix2x4& m2x4 );
bool set( const osg::Matrix3x2& m3x2 );
bool set( const osg::Matrix3x4& m3x4 );
bool set( const osg::Matrix4x2& m4x2 );
bool set( const osg::Matrix4x3& m4x3 );
bool set( const osg::Matrix2d& m2 );
bool set( const osg::Matrix3d& m3 );
bool set( const osg::Matrixd& m4 );
bool set( const osg::Matrix2x3d& m2x3 );
bool set( const osg::Matrix2x4d& m2x4 );
bool set( const osg::Matrix3x2d& m3x2 );
bool set( const osg::Matrix3x4d& m3x4 );
bool set( const osg::Matrix4x2d& m4x2 );
bool set( const osg::Matrix4x3d& m4x3 );
bool set( int i0, int i1 );
bool set( int i0, int i1, int i2 );
bool set( int i0, int i1, int i2, int i3 );
bool set( unsigned int ui0, unsigned int ui1 );
bool set( unsigned int ui0, unsigned int ui1, unsigned int ui2 );
bool set( unsigned int ui0, unsigned int ui1, unsigned int ui2, unsigned int ui3 );
bool set( bool b0, bool b1 );
bool set( bool b0, bool b1, bool b2 );
bool set( bool b0, bool b1, bool b2, bool b3 );
/** convenient scalar (non-array) value query */
bool get( float& f ) const;
bool get( double& d ) const;
bool get( int& i ) const;
bool get( unsigned int& ui ) const;
bool get( bool& b ) const;
bool get( unsigned long long & ull ) const;
bool get( long long& ll ) const;
bool get( osg::Vec2& v2 ) const;
bool get( osg::Vec3& v3 ) const;
bool get( osg::Vec4& v4 ) const;
bool get( osg::Vec2d& v2 ) const;
bool get( osg::Vec3d& v3 ) const;
bool get( osg::Vec4d& v4 ) const;
bool get( osg::Matrix2& m2 ) const;
bool get( osg::Matrix3& m3 ) const;
bool get( osg::Matrixf& m4 ) const;
bool get( osg::Matrix2x3& m2x3 ) const;
bool get( osg::Matrix2x4& m2x4 ) const;
bool get( osg::Matrix3x2& m3x2 ) const;
bool get( osg::Matrix3x4& m3x4 ) const;
bool get( osg::Matrix4x2& m4x2 ) const;
bool get( osg::Matrix4x3& m4x3 ) const;
bool get( osg::Matrix2d& m2 ) const;
bool get( osg::Matrix3d& m3 ) const;
bool get( osg::Matrixd& m4 ) const;
bool get( osg::Matrix2x3d& m2x3 ) const;
bool get( osg::Matrix2x4d& m2x4 ) const;
bool get( osg::Matrix3x2d& m3x2 ) const;
bool get( osg::Matrix3x4d& m3x4 ) const;
bool get( osg::Matrix4x2d& m4x2 ) const;
bool get( osg::Matrix4x3d& m4x3 ) const;
bool get( int& i0, int& i1 ) const;
bool get( int& i0, int& i1, int& i2 ) const;
bool get( int& i0, int& i1, int& i2, int& i3 ) const;
bool get( unsigned int& ui0, unsigned int& ui1 ) const;
bool get( unsigned int& ui0, unsigned int& ui1, unsigned int& ui2 ) const;
bool get( unsigned int& ui0, unsigned int& ui1, unsigned int& ui2, unsigned int& ui3 ) const;
bool get( bool& b0, bool& b1 ) const;
bool get( bool& b0, bool& b1, bool& b2 ) const;
bool get( bool& b0, bool& b1, bool& b2, bool& b3 ) const;
/** value assignment for array uniforms */
bool setElement( unsigned int index, float f );
bool setElement( unsigned int index, double d );
bool setElement( unsigned int index, int i );
bool setElement( unsigned int index, unsigned int ui );
bool setElement( unsigned int index, bool b );
bool setElement( unsigned int index, unsigned long long ull );
bool setElement( unsigned int index, long long ll );
bool setElement( unsigned int index, const osg::Vec2& v2 );
bool setElement( unsigned int index, const osg::Vec3& v3 );
bool setElement( unsigned int index, const osg::Vec4& v4 );
bool setElement( unsigned int index, const osg::Vec2d& v2 );
bool setElement( unsigned int index, const osg::Vec3d& v3 );
bool setElement( unsigned int index, const osg::Vec4d& v4 );
bool setElement( unsigned int index, const osg::Matrix2& m2 );
bool setElement( unsigned int index, const osg::Matrix3& m3 );
bool setElement( unsigned int index, const osg::Matrixf& m4 );
bool setElement( unsigned int index, const osg::Matrix2x3& m2x3 );
bool setElement( unsigned int index, const osg::Matrix2x4& m2x4 );
bool setElement( unsigned int index, const osg::Matrix3x2& m3x2 );
bool setElement( unsigned int index, const osg::Matrix3x4& m3x4 );
bool setElement( unsigned int index, const osg::Matrix4x2& m4x2 );
bool setElement( unsigned int index, const osg::Matrix4x3& m4x3 );
bool setElement( unsigned int index, const osg::Matrix2d& m2 );
bool setElement( unsigned int index, const osg::Matrix3d& m3 );
bool setElement( unsigned int index, const osg::Matrixd& m4 );
bool setElement( unsigned int index, const osg::Matrix2x3d& m2x3 );
bool setElement( unsigned int index, const osg::Matrix2x4d& m2x4 );
bool setElement( unsigned int index, const osg::Matrix3x2d& m3x2 );
bool setElement( unsigned int index, const osg::Matrix3x4d& m3x4 );
bool setElement( unsigned int index, const osg::Matrix4x2d& m4x2 );
bool setElement( unsigned int index, const osg::Matrix4x3d& m4x3 );
bool setElement( unsigned int index, int i0, int i1 );
bool setElement( unsigned int index, int i0, int i1, int i2 );
bool setElement( unsigned int index, int i0, int i1, int i2, int i3 );
bool setElement( unsigned int index, unsigned int ui0, unsigned int ui1 );
bool setElement( unsigned int index, unsigned int ui0, unsigned int ui1, unsigned int ui2 );
bool setElement( unsigned int index, unsigned int ui0, unsigned int ui1, unsigned int ui2, unsigned int ui3 );
bool setElement( unsigned int index, bool b0, bool b1 );
bool setElement( unsigned int index, bool b0, bool b1, bool b2 );
bool setElement( unsigned int index, bool b0, bool b1, bool b2, bool b3 );
/** value query for array uniforms */
bool getElement( unsigned int index, float& f ) const;
bool getElement( unsigned int index, double& d ) const;
bool getElement( unsigned int index, int& i ) const;
bool getElement( unsigned int index, unsigned int& ui ) const;
bool getElement( unsigned int index, bool& b ) const;
bool getElement( unsigned int index, unsigned long long & ull ) const;
bool getElement( unsigned int index, long long& ll ) const;
bool getElement( unsigned int index, osg::Vec2& v2 ) const;
bool getElement( unsigned int index, osg::Vec3& v3 ) const;
bool getElement( unsigned int index, osg::Vec4& v4 ) const;
bool getElement( unsigned int index, osg::Vec2d& v2 ) const;
bool getElement( unsigned int index, osg::Vec3d& v3 ) const;
bool getElement( unsigned int index, osg::Vec4d& v4 ) const;
bool getElement( unsigned int index, osg::Matrix2& m2 ) const;
bool getElement( unsigned int index, osg::Matrix3& m3 ) const;
bool getElement( unsigned int index, osg::Matrixf& m4 ) const;
bool getElement( unsigned int index, osg::Matrix2x3& m2x3 ) const;
bool getElement( unsigned int index, osg::Matrix2x4& m2x4 ) const;
bool getElement( unsigned int index, osg::Matrix3x2& m3x2 ) const;
bool getElement( unsigned int index, osg::Matrix3x4& m3x4 ) const;
bool getElement( unsigned int index, osg::Matrix4x2& m4x2 ) const;
bool getElement( unsigned int index, osg::Matrix4x3& m4x3 ) const;
bool getElement( unsigned int index, osg::Matrix2d& m2 ) const;
bool getElement( unsigned int index, osg::Matrix3d& m3 ) const;
bool getElement( unsigned int index, osg::Matrixd& m4 ) const;
bool getElement( unsigned int index, osg::Matrix2x3d& m2x3 ) const;
bool getElement( unsigned int index, osg::Matrix2x4d& m2x4 ) const;
bool getElement( unsigned int index, osg::Matrix3x2d& m3x2 ) const;
bool getElement( unsigned int index, osg::Matrix3x4d& m3x4 ) const;
bool getElement( unsigned int index, osg::Matrix4x2d& m4x2 ) const;
bool getElement( unsigned int index, osg::Matrix4x3d& m4x3 ) const;
bool getElement( unsigned int index, int& i0, int& i1 ) const;
bool getElement( unsigned int index, int& i0, int& i1, int& i2 ) const;
bool getElement( unsigned int index, int& i0, int& i1, int& i2, int& i3 ) const;
bool getElement( unsigned int index, unsigned int& ui0, unsigned int& ui1 ) const;
bool getElement( unsigned int index, unsigned int& ui0, unsigned int& ui1, unsigned int& ui2 ) const;
bool getElement( unsigned int index, unsigned int& ui0, unsigned int& ui1, unsigned int& ui2, unsigned int& ui3 ) const;
bool getElement( unsigned int index, bool& b0, bool& b1 ) const;
bool getElement( unsigned int index, bool& b0, bool& b1, bool& b2 ) const;
bool getElement( unsigned int index, bool& b0, bool& b1, bool& b2, bool& b3 ) const;
/** Set the internal data array for a osg::Uniform */
bool setArray( FloatArray* array );
bool setArray( DoubleArray* array );
bool setArray( IntArray* array );
bool setArray( UIntArray* array );
bool setArray( UInt64Array* array );
bool setArray( Int64Array* array );
/** Get the internal data array for a float osg::Uniform. */
FloatArray* getFloatArray() { return _floatArray.get(); }
const FloatArray* getFloatArray() const { return _floatArray.get(); }
/** Get the internal data array for a double osg::Uniform. */
DoubleArray* getDoubleArray() { return _doubleArray.get(); }
const DoubleArray* getDoubleArray() const { return _doubleArray.get(); }
/** Get the internal data array for an int osg::Uniform. */
IntArray* getIntArray() { return _intArray.get(); }
const IntArray* getIntArray() const { return _intArray.get(); }
/** Get the internal data array for an unsigned int osg::Uniform. */
UIntArray* getUIntArray() { return _uintArray.get(); }
const UIntArray* getUIntArray() const { return _uintArray.get(); }
/** Get the internal data array for an unsigned int osg::Uniform. */
UInt64Array* getUInt64Array() { return _uint64Array.get(); }
const UInt64Array* getUInt64Array() const { return _uint64Array.get(); }
/** Get the internal data array for an unsigned int osg::Uniform. */
Int64Array* getInt64Array() { return _int64Array.get(); }
const Int64Array* getInt64Array() const { return _int64Array.get(); }
virtual void apply(const GLExtensions* ext, GLint location) const;
typedef osg::UniformCallback Callback;
protected:
virtual ~Uniform();
Uniform& operator=(const Uniform&) { return *this; }
bool isCompatibleType( Type t ) const;
// for backward compatibility only
// see getElement(index, osg::Matrixd &)
// see setElement(index, osg::Matrixd &)
bool isCompatibleType( Type t1, Type t2 ) const;
bool isScalar() const { return _numElements==1; }
void allocateDataArray();
Type _type;
unsigned int _numElements;
// The internal data for osg::Uniforms are stored as an array of
// getInternalArrayType() of length getInternalArrayNumElements().
ref_ptr<FloatArray> _floatArray;
ref_ptr<DoubleArray> _doubleArray;
ref_ptr<IntArray> _intArray;
ref_ptr<UIntArray> _uintArray;
ref_ptr<Int64Array> _int64Array;
ref_ptr<UInt64Array> _uint64Array;
ref_ptr<UniformCallback> _updateCallback;
ref_ptr<UniformCallback> _eventCallback;
unsigned int _modifiedCount;
};
}
#endif
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/mirrors/OpenSceneGraph.git
git@gitee.com:mirrors/OpenSceneGraph.git
mirrors
OpenSceneGraph
OpenSceneGraph
master

搜索帮助