2003-10-05 19:30:54 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 Robert Osfield
|
|
|
|
* Copyright (C) 2003 3Dlabs Inc. Ltd.
|
|
|
|
*
|
|
|
|
* This application is open source and may be redistributed and/or modified
|
|
|
|
* freely and without restriction, both in commericial and non commericial
|
|
|
|
* 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/osgGL2/UniformValue
|
2004-01-03 17:06:52 +08:00
|
|
|
* author: Mike Weiblen 2003-12-28
|
2003-10-05 19:30:54 +08:00
|
|
|
*
|
|
|
|
* See http://www.3dlabs.com/opengl2/ for more information regarding
|
|
|
|
* the OpenGL Shading Language.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef OSGGL2_UNIFORMVALUE
|
|
|
|
#define OSGGL2_UNIFORMVALUE 1
|
|
|
|
|
|
|
|
#include <osg/ref_ptr>
|
|
|
|
#include <osg/Vec2>
|
|
|
|
#include <osg/Vec3>
|
|
|
|
#include <osg/Vec4>
|
|
|
|
#include <osg/Referenced>
|
|
|
|
|
|
|
|
#include <osgGL2/Extensions>
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
|
|
|
namespace osgGL2 {
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2004-01-03 17:06:52 +08:00
|
|
|
/** osgGL2::UniformValue is for internal use by osgGL2::ProgramObject.
|
|
|
|
* UniformValue is an abstract class to encapsulate a new value for a glUniform.
|
2003-10-05 19:30:54 +08:00
|
|
|
* osgGL2::ProgramObject.setUniform() constructs and sends a UniformValue
|
2004-01-03 17:06:52 +08:00
|
|
|
* to all its PerContextProgramObjects (PCPOs) to set the value of a
|
|
|
|
* glUniform.
|
|
|
|
* The value contained in each UniformValue value is propagated to the
|
|
|
|
* glProgramObjects during the next osgGL2::ProgramObject.apply().
|
2003-10-05 19:30:54 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
class UniformValue : public osg::Referenced
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual void apply( Extensions *ext, const GLhandleARB progObj ) const = 0;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
UniformValue( const char* uniformName ) : _name( uniformName ) {};
|
|
|
|
virtual ~UniformValue() {};
|
2004-01-03 17:06:52 +08:00
|
|
|
UniformValue();
|
|
|
|
UniformValue(const UniformValue&);
|
|
|
|
UniformValue& operator=(const UniformValue&);
|
2003-10-05 19:30:54 +08:00
|
|
|
|
|
|
|
int getLocation( Extensions *ext, const GLhandleARB progObj ) const;
|
|
|
|
|
|
|
|
std::string _name;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef std::vector< osg::ref_ptr<UniformValue> > UniformValueList;
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2004-01-03 17:06:52 +08:00
|
|
|
/** UniformValueTemplate creates the concrete classes for each of the
|
|
|
|
* uniform value types */
|
2003-10-05 19:30:54 +08:00
|
|
|
|
2004-01-03 17:06:52 +08:00
|
|
|
template<typename T>
|
|
|
|
class UniformValueTemplate: public UniformValue
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
UniformValueTemplate( const char* uniformName, T value ) :
|
|
|
|
UniformValue( uniformName ), _value( value ) {}
|
|
|
|
virtual void apply( Extensions *ext, const GLhandleARB progObj ) const;
|
2003-10-05 19:30:54 +08:00
|
|
|
|
2004-01-03 17:06:52 +08:00
|
|
|
protected:
|
|
|
|
UniformValueTemplate();
|
|
|
|
const T _value;
|
|
|
|
};
|
2003-10-05 19:30:54 +08:00
|
|
|
|
2004-01-03 17:06:52 +08:00
|
|
|
typedef UniformValueTemplate<int> UniformValue_int;
|
|
|
|
typedef UniformValueTemplate<float> UniformValue_float;
|
|
|
|
typedef UniformValueTemplate<osg::Vec2> UniformValue_Vec2;
|
|
|
|
typedef UniformValueTemplate<osg::Vec3> UniformValue_Vec3;
|
|
|
|
typedef UniformValueTemplate<osg::Vec4> UniformValue_Vec4;
|
2003-10-05 19:30:54 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*EOF*/
|