From Mike Weiblen, updates to Shander Language support

This commit is contained in:
Robert Osfield
2005-04-04 10:08:15 +00:00
parent 2e91a74f14
commit aa8dbea11c
7 changed files with 765 additions and 559 deletions

View File

@@ -12,21 +12,15 @@
*/
/* file: include/osg/Program
* author: Mike Weiblen 2005-03-23
* author: Mike Weiblen 2005-03-30
*/
// NOTICE: This code is CLOSED during construction and/or renovation!
// It is in active development, so DO NOT yet use in application code.
// This notice will be removed when the code is open for business.
// For development plan and status see:
// http://www.openscenegraph.org/index.php?page=Community.DevelopmentWork
#ifndef OSG_PROGRAM
#define OSG_PROGRAM 1
#include <string>
#include <vector>
#include <map>
#include <osg/buffered_value>
#include <osg/ref_ptr>
@@ -180,6 +174,7 @@ class SG_EXPORT GL2Extensions : public osg::Referenced
GLuint getCurrentProgram() const;
bool getProgramInfoLog( GLuint program, std::string& result ) const;
bool getShaderInfoLog( GLuint shader, std::string& result ) const;
bool getAttribLocation( const char* attribName, GLuint& slot ) const;
protected:
~GL2Extensions() {}
@@ -339,8 +334,10 @@ class SG_EXPORT Program : public osg::StateAttribute
* Mark Program as needing relink. Return true for success */
bool removeShader( Shader* shader );
/** */
/** Add an attribute location binding. */
void bindAttribLocation( GLuint index, const char* name );
typedef std::map<std::string,GLuint> AttribBindingList;
const AttribBindingList& getAttribBindingList() const { return _attribBindingList; }
/** Return true if this Program represents "fixed-functionality" rendering */
bool isFixedFunction() const;
@@ -353,12 +350,6 @@ class SG_EXPORT Program : public osg::StateAttribute
void setName( const char* name ) { _name = name; }
const std::string& getName() const { return _name; }
/** should Uniform values be tested to avoid redundant setting? */
void setAvoidRedundantUniformSetting( bool flag ) { _avoidRedundantUniformSetting = flag; }
bool getAvoidRedundantUniformSetting() const { return _avoidRedundantUniformSetting; }
// TODO glBindAttribLocation
/** Mark internal glProgram for deletion.
* Deletion requests are queued until they can be executed
* in the proper GL context. */
@@ -370,23 +361,22 @@ class SG_EXPORT Program : public osg::StateAttribute
protected:
/** An OSG-internal encapsulation of glProgram's active uniforms */
class ActiveUniform : public osg::Referenced
class ActiveUniform : public osg::Uniform
{
public:
ActiveUniform( const GLchar* name, GLenum type );
ActiveUniform( const char* name, GLenum type, GLint loc );
void applyData( const GL2Extensions* ext, GLuint prog );
protected:
virtual ~ActiveUniform() {}
Uniform::Value _value;
GLint _location;
const GLint _location;
private:
ActiveUniform(); // disallowed
ActiveUniform(ActiveUniform&); // disallowed
ActiveUniform& operator=(ActiveUniform&); // disallowed
};
typedef osg::ref_ptr< ActiveUniform > ActiveUniformPtr;
typedef std::vector< ActiveUniformPtr > ActiveUniformList;
typedef std::vector< osg::ref_ptr<ActiveUniform> > ActiveUniformList;
protected:
@@ -405,9 +395,11 @@ class SG_EXPORT Program : public osg::StateAttribute
void getInfoLog( std::string& infoLog ) const;
void useProgram() const;
void applyUniforms( osg::State& state ) const;
GLint getUniformLocation( const char* name ) const;
GLint getAttribLocation( const char* name ) const;
protected: /*methods*/
~PerContextProgram();
@@ -438,11 +430,13 @@ class SG_EXPORT Program : public osg::StateAttribute
PerContextProgram* getPCP(unsigned int contextID) const;
protected: /*data*/
bool _avoidRedundantUniformSetting;
std::string _name;
mutable osg::buffered_value< osg::ref_ptr<PerContextProgram> > _pcpList;
AttribBindingList _attribBindingList;
typedef std::vector< ref_ptr<Shader> > ShaderList;
ShaderList _shaderList;
mutable osg::buffered_value< osg::ref_ptr<PerContextProgram> > _pcpList;
private:
Program& operator=(const Program&); // disallowed

View File

@@ -12,16 +12,9 @@
*/
/* file: include/osg/Shader
* author: Mike Weiblen 2005-03-23
* author: Mike Weiblen 2005-03-30
*/
// NOTICE: This code is CLOSED during construction and/or renovation!
// It is in active development, so DO NOT yet use in application code.
// This notice will be removed when the code is open for business.
// For development plan and status see:
// http://www.openscenegraph.org/index.php?page=Community.DevelopmentWork
#ifndef OSG_SHADER
#define OSG_SHADER 1

View File

@@ -17,6 +17,7 @@
#include <osg/Export>
#include <osg/StateSet>
#include <osg/Matrix>
#include <osg/Uniform>
#include <osg/FrameStamp>
#include <osg/DisplaySettings>
@@ -25,6 +26,7 @@
#include <vector>
#include <map>
#include <string>
#ifndef GL_TEXTURE0
#define GL_TEXTURE0 0x84C0
@@ -710,6 +712,13 @@ class SG_EXPORT State : public Referenced
bool checkGLErrors(StateAttribute::GLMode mode) const;
bool checkGLErrors(const StateAttribute* attribute) const;
typedef std::map< std::string,ref_ptr<Uniform> > UniformMap;
const Uniform* findUniform( const std::string& name )
{
UniformMap::const_iterator itr = _uniformMap.find( name );
return (itr != _uniformMap.end()) ? itr->second.get() : 0;
}
protected:
virtual ~State();
@@ -840,6 +849,8 @@ class SG_EXPORT State : public Referenced
TextureModeMapList _textureModeMapList;
TextureAttributeMapList _textureAttributeMapList;
UniformMap _uniformMap;
StateSetStack _drawStateStack;
struct EnabledArrayPair

View File

@@ -11,7 +11,7 @@
*/
/* file: include/osg/Uniform
* author: Mike Weiblen 2005-03-23
* author: Mike Weiblen 2005-03-29
*/
// NOTICE: This code is CLOSED during construction and/or renovation!
@@ -33,8 +33,9 @@
#include <string>
#ifndef GL_VERSION_2_0
#ifndef GL_VERSION_2_0 //[
#define GL_VERSION_2_0 1
typedef char GLchar;
#define GL_BLEND_EQUATION_RGB GL_BLEND_EQUATION
#define GL_VERTEX_ATTRIB_ARRAY_ENABLED 0x8622
#define GL_VERTEX_ATTRIB_ARRAY_SIZE 0x8623
@@ -119,116 +120,60 @@
#define GL_STENCIL_BACK_REF 0x8CA3
#define GL_STENCIL_BACK_VALUE_MASK 0x8CA4
#define GL_STENCIL_BACK_WRITEMASK 0x8CA5
typedef char GLchar;
#endif
#endif //]
namespace osg {
///////////////////////////////////////////////////////////////////////////
/** Uniform encapsulates glUniform values */
class GL2Extensions;
class SG_EXPORT Uniform : public Object
{
public:
class Value
{
public:
enum Type {
FLOAT = GL_FLOAT,
FLOAT_VEC2 = GL_FLOAT_VEC2,
FLOAT_VEC3 = GL_FLOAT_VEC3,
FLOAT_VEC4 = GL_FLOAT_VEC4,
INT = GL_INT,
INT_VEC2 = GL_INT_VEC2,
INT_VEC3 = GL_INT_VEC3,
INT_VEC4 = GL_INT_VEC4,
BOOL = GL_BOOL,
BOOL_VEC2 = GL_BOOL_VEC2,
BOOL_VEC3 = GL_BOOL_VEC3,
BOOL_VEC4 = GL_BOOL_VEC4,
FLOAT_MAT2 = GL_FLOAT_MAT2,
FLOAT_MAT3 = GL_FLOAT_MAT3,
FLOAT_MAT4 = GL_FLOAT_MAT4,
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,
UNDEFINED = -1,
};
Value( const char* name, Type type );
Value( const Value& rhs );
/** Get the name of glUniform. */
const std::string& getName() const { return _name; }
/** Get the type of glUniform as enum. */
const Type getType() const { return _type; }
/** Return the name of a type as string. */
static const char* getTypename(Type t);
/** Does this Value contain real data? */
bool isValid() const { return _isValid; }
/** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs. */
int compare(const Value& rhs) const;
bool isCompatibleType( Type t ) const;
/** assignment */
void set( float f );
void set( const osg::Vec2& v2 );
void set( const osg::Vec3& v3 );
void set( const osg::Vec4& v4 );
//TODO void set( const osg::Matrix2& m2 );
//TODO void set( const osg::Matrix3& m3 );
void set( const osg::Matrix& m4 );
void set( int i );
void set( int i0, int i1 );
void set( int i0, int i1, int i2 );
void set( int i0, int i1, int i2, int i3 );
void set( bool b );
void set( bool b0, bool b1 );
void set( bool b0, bool b1, bool b2 );
void set( bool b0, bool b1, bool b2, bool b3 );
protected:
/** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs. */
int compareData(const Value& rhs) const;
void copyData(const Value& rhs);
protected:
const std::string _name;
const Type _type;
bool _isValid; // is _data valid?
union {
GLfloat f1; // float
GLfloat f2[2]; // vec2
GLfloat f3[3]; // vec3
GLfloat f4[4]; // vec4, mat2
GLfloat f9[9]; // mat3
GLfloat f16[16]; // mat4
GLint i1; // int, bool, sampler*
GLint i2[2]; // ivec2, bvec2
GLint i3[3]; // ivec3, bvec3
GLint i4[4]; // ivec4, bvec4
} _data;
private:
Value(); // disallowed
enum Type {
FLOAT = GL_FLOAT,
FLOAT_VEC2 = GL_FLOAT_VEC2,
FLOAT_VEC3 = GL_FLOAT_VEC3,
FLOAT_VEC4 = GL_FLOAT_VEC4,
INT = GL_INT,
INT_VEC2 = GL_INT_VEC2,
INT_VEC3 = GL_INT_VEC3,
INT_VEC4 = GL_INT_VEC4,
BOOL = GL_BOOL,
BOOL_VEC2 = GL_BOOL_VEC2,
BOOL_VEC3 = GL_BOOL_VEC3,
BOOL_VEC4 = GL_BOOL_VEC4,
FLOAT_MAT2 = GL_FLOAT_MAT2,
FLOAT_MAT3 = GL_FLOAT_MAT3,
FLOAT_MAT4 = GL_FLOAT_MAT4,
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,
UNDEFINED = -1,
};
public:
Uniform();
Uniform( const char* name, Value::Type type );
Uniform( const char* name, Type type );
/** Copy constructor using CopyOp to manage deep vs shallow copy. */
Uniform(const Uniform& rhs, const CopyOp& copyop=CopyOp::SHALLOW_COPY);
META_Object(osg, Uniform);
/** Get the name of glUniform. */
const std::string& getName() const { return _name; }
/** Get the type of glUniform as enum. */
const Type getType() const { return _type; }
/** Return the name of a type as string. */
static const char* getTypename( Type t );
/** convenient construction w/ assignment */
explicit Uniform( const char* name, float f );
@@ -247,26 +192,15 @@ class SG_EXPORT Uniform : public Object
Uniform( const char* name, bool b0, bool b1, bool b2 );
Uniform( const char* name, bool b0, bool b1, bool b2, bool b3 );
/** Copy constructor using CopyOp to manage deep vs shallow copy. */
Uniform(const Uniform& gu,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
/** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs. */
virtual int compare(const Uniform& rhs) const;
virtual int compareData(const Uniform& rhs) const;
META_Object(osg, Uniform);
virtual bool operator < (const Uniform& rhs) const { return (compare(rhs) == -1); }
/** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs. */
virtual int compare(const Uniform& rhs) const
{
return _value.compare( rhs._value );
}
void copyData( const Uniform& rhs );
bool operator < (const Uniform& rhs) const
{
if (_value.getName()<rhs._value.getName()) return true;
return false;
}
const std::string& getName() const { return _value.getName(); }
/** assignment */
/** value assignment */
bool set( float f );
bool set( int i );
bool set( bool b );
@@ -283,15 +217,49 @@ class SG_EXPORT Uniform : public Object
bool set( bool b0, bool b1, bool b2 );
bool set( bool b0, bool b1, bool b2, bool b3 );
/** value query */
bool get( float& f ) const;
bool get( int& i ) const;
bool get( bool& b ) const;
bool get( osg::Vec2& v2 ) const;
bool get( osg::Vec3& v3 ) const;
bool get( osg::Vec4& v4 ) const;
//TODO bool get( osg::Matrix2& m2 ) const;
//TODO bool get( osg::Matrix3& m3 ) const;
bool get( osg::Matrix& m4 ) 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( 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;
protected:
virtual ~Uniform() {}
bool isCompatibleType( Value::Type t ) const;
bool isCompatibleType( Type t ) const;
static Type repType( Type t );
protected:
Value _value;
const std::string _name;
const Type _type;
union {
GLfloat f1; // float
GLfloat f2[2]; // vec2
GLfloat f3[3]; // vec3
GLfloat f4[4]; // vec4, mat2
GLfloat f9[9]; // mat3
GLfloat f16[16]; // mat4
GLint i1; // int, bool, sampler*
GLint i2[2]; // ivec2, bvec2
GLint i3[3]; // ivec3, bvec3
GLint i4[4]; // ivec4, bvec4
} _data;
private:
Uniform(); // disallowed
Uniform& operator=(const Uniform&); // disallowed
};