From Mike Weiblen, updates to osgGL2 to support Uniform values

This commit is contained in:
Robert Osfield
2003-10-05 11:30:54 +00:00
parent 9d6bf8d1b6
commit ce15c880b1
17 changed files with 1350 additions and 319 deletions

View File

@@ -11,7 +11,7 @@
*/
/* file: src/osgGL2/Extensions.cpp
* author: Mike Weiblen 2003-07-14
* author: Mike Weiblen 2003-09-12
*
* See http://www.3dlabs.com/opengl2/ for more information regarding
* the OpenGL Shading Language.
@@ -477,11 +477,11 @@ void Extensions::glUniform4i(GLint location, GLint v0, GLint v1, GLint v2, GLint
}
}
void Extensions::glUniform1fv(GLint location, GLsizei count, GLfloat *value) const
void Extensions::glUniform1fv(GLint location, GLsizei count, const GLfloat *value) const
{
if (_glUniform1fv)
{
typedef void (APIENTRY * Uniform1fvProc) (GLint location, GLsizei count, GLfloat *value);
typedef void (APIENTRY * Uniform1fvProc) (GLint location, GLsizei count, const GLfloat *value);
((Uniform1fvProc)_glUniform1fv)(location, count, value);
}
else
@@ -490,11 +490,11 @@ void Extensions::glUniform1fv(GLint location, GLsizei count, GLfloat *value) con
}
}
void Extensions::glUniform2fv(GLint location, GLsizei count, GLfloat *value) const
void Extensions::glUniform2fv(GLint location, GLsizei count, const GLfloat *value) const
{
if (_glUniform2fv)
{
typedef void (APIENTRY * Uniform2fvProc) (GLint location, GLsizei count, GLfloat *value);
typedef void (APIENTRY * Uniform2fvProc) (GLint location, GLsizei count, const GLfloat *value);
((Uniform2fvProc)_glUniform2fv)(location, count, value);
}
else
@@ -503,11 +503,11 @@ void Extensions::glUniform2fv(GLint location, GLsizei count, GLfloat *value) con
}
}
void Extensions::glUniform3fv(GLint location, GLsizei count, GLfloat *value) const
void Extensions::glUniform3fv(GLint location, GLsizei count, const GLfloat *value) const
{
if (_glUniform3fv)
{
typedef void (APIENTRY * Uniform3fvProc) (GLint location, GLsizei count, GLfloat *value);
typedef void (APIENTRY * Uniform3fvProc) (GLint location, GLsizei count, const GLfloat *value);
((Uniform3fvProc)_glUniform3fv)(location, count, value);
}
else
@@ -516,11 +516,11 @@ void Extensions::glUniform3fv(GLint location, GLsizei count, GLfloat *value) con
}
}
void Extensions::glUniform4fv(GLint location, GLsizei count, GLfloat *value) const
void Extensions::glUniform4fv(GLint location, GLsizei count, const GLfloat *value) const
{
if (_glUniform4fv)
{
typedef void (APIENTRY * Uniform4fvProc) (GLint location, GLsizei count, GLfloat *value);
typedef void (APIENTRY * Uniform4fvProc) (GLint location, GLsizei count, const GLfloat *value);
((Uniform4fvProc)_glUniform4fv)(location, count, value);
}
else
@@ -529,11 +529,11 @@ void Extensions::glUniform4fv(GLint location, GLsizei count, GLfloat *value) con
}
}
void Extensions::glUniform1iv(GLint location, GLsizei count, GLint *value) const
void Extensions::glUniform1iv(GLint location, GLsizei count, const GLint *value) const
{
if (_glUniform1iv)
{
typedef void (APIENTRY * Uniform1ivProc) (GLint location, GLsizei count, GLint *value);
typedef void (APIENTRY * Uniform1ivProc) (GLint location, GLsizei count, const GLint *value);
((Uniform1ivProc)_glUniform1iv)(location, count, value);
}
else
@@ -542,11 +542,11 @@ void Extensions::glUniform1iv(GLint location, GLsizei count, GLint *value) const
}
}
void Extensions::glUniform2iv(GLint location, GLsizei count, GLint *value) const
void Extensions::glUniform2iv(GLint location, GLsizei count, const GLint *value) const
{
if (_glUniform2iv)
{
typedef void (APIENTRY * Uniform2ivProc) (GLint location, GLsizei count, GLint *value);
typedef void (APIENTRY * Uniform2ivProc) (GLint location, GLsizei count, const GLint *value);
((Uniform2ivProc)_glUniform2iv)(location, count, value);
}
else
@@ -555,11 +555,11 @@ void Extensions::glUniform2iv(GLint location, GLsizei count, GLint *value) const
}
}
void Extensions::glUniform3iv(GLint location, GLsizei count, GLint *value) const
void Extensions::glUniform3iv(GLint location, GLsizei count, const GLint *value) const
{
if (_glUniform3iv)
{
typedef void (APIENTRY * Uniform3ivProc) (GLint location, GLsizei count, GLint *value);
typedef void (APIENTRY * Uniform3ivProc) (GLint location, GLsizei count, const GLint *value);
((Uniform3ivProc)_glUniform3iv)(location, count, value);
}
else
@@ -568,11 +568,11 @@ void Extensions::glUniform3iv(GLint location, GLsizei count, GLint *value) const
}
}
void Extensions::glUniform4iv(GLint location, GLsizei count, GLint *value) const
void Extensions::glUniform4iv(GLint location, GLsizei count, const GLint *value) const
{
if (_glUniform4iv)
{
typedef void (APIENTRY * Uniform4ivProc) (GLint location, GLsizei count, GLint *value);
typedef void (APIENTRY * Uniform4ivProc) (GLint location, GLsizei count, const GLint *value);
((Uniform4ivProc)_glUniform4iv)(location, count, value);
}
else
@@ -581,11 +581,11 @@ void Extensions::glUniform4iv(GLint location, GLsizei count, GLint *value) const
}
}
void Extensions::glUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, GLfloat *value) const
void Extensions::glUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) const
{
if (_glUniformMatrix2fv)
{
typedef void (APIENTRY * UniformMatrix2fvProc) (GLint location, GLsizei count, GLboolean transpose, GLfloat *value);
typedef void (APIENTRY * UniformMatrix2fvProc) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
((UniformMatrix2fvProc)_glUniformMatrix2fv)(location, count, transpose, value);
}
else
@@ -594,11 +594,11 @@ void Extensions::glUniformMatrix2fv(GLint location, GLsizei count, GLboolean tra
}
}
void Extensions::glUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, GLfloat *value) const
void Extensions::glUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) const
{
if (_glUniformMatrix3fv)
{
typedef void (APIENTRY * UniformMatrix3fvProc) (GLint location, GLsizei count, GLboolean transpose, GLfloat *value);
typedef void (APIENTRY * UniformMatrix3fvProc) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
((UniformMatrix3fvProc)_glUniformMatrix3fv)(location, count, transpose, value);
}
else
@@ -607,11 +607,11 @@ void Extensions::glUniformMatrix3fv(GLint location, GLsizei count, GLboolean tra
}
}
void Extensions::glUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, GLfloat *value) const
void Extensions::glUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) const
{
if (_glUniformMatrix4fv)
{
typedef void (APIENTRY * UniformMatrix4fvProc) (GLint location, GLsizei count, GLboolean transpose, GLfloat *value);
typedef void (APIENTRY * UniformMatrix4fvProc) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
((UniformMatrix4fvProc)_glUniformMatrix4fv)(location, count, transpose, value);
}
else

View File

@@ -5,7 +5,8 @@ include $(TOPDIR)/Make/makedefs
CXXFILES = \
Extensions.cpp \
Version.cpp \
ProgramObject.cpp
ProgramObject.cpp\
UniformValue.cpp
DEF += -DOSGGL2_LIBRARY

View File

@@ -12,7 +12,7 @@
*/
/* file: src/osgGL2/ProgramObject.cpp
* author: Mike Weiblen 2003-07-14
* author: Mike Weiblen 2003-09-18
*
* See http://www.3dlabs.com/opengl2/ for more information regarding
* the OpenGL Shading Language.
@@ -22,16 +22,18 @@
#include <osg/Notify>
#include <osg/State>
#include <osg/ref_ptr>
#include <osg/Timer>
#include <osg/FrameStamp>
#include <osgGL2/ProgramObject>
#include <osgGL2/UniformValue>
#include <osgGL2/Extensions>
#include <list>
using namespace osgGL2;
///////////////////////////////////////////////////////////////////////////
// static cache of deleted GL2 objects which may only
// by actually deleted in the correct GL context.
@@ -63,8 +65,12 @@ void ProgramObject::flushDeletedGL2Objects(unsigned int contextID,double /*curre
{
const Extensions* extensions = Extensions::Get(contextID,true);
if (!extensions->isShaderObjectsSupported())
return;
if (!extensions->isShaderObjectsSupported())
{
// can we really get here?
osg::notify(osg::WARN) << "flushDeletedGL2Objects not supported by OpenGL driver" << std::endl;
return;
}
GL2ObjectList& vpObjectList = citr->second;
@@ -81,25 +87,33 @@ void ProgramObject::flushDeletedGL2Objects(unsigned int contextID,double /*curre
availableTime -= elapsedTime;
}
///////////////////////////////////////////////////////////////////////////
// osgGL2::ProgramObject
///////////////////////////////////////////////////////////////////////////
ProgramObject::ProgramObject()
{
// To ensure all PCPOs consistently get the same values, we must
// postpone updates until all PCPOs have been created.
// They are created during ProgramObject::apply(), so let a frame
// go by before sending the updates.
_frameNumberOfLastPCPOUpdate = 1;
_enabled = true;
}
ProgramObject::ProgramObject(const ProgramObject& rhs, const osg::CopyOp& copyop):
osg::StateAttribute(rhs, copyop)
{
osg::notify(osg::FATAL) << "how got here?" << std::endl;
}
// virtual
ProgramObject::~ProgramObject()
{
for( unsigned int cxt=0; cxt<_pcpoList.size(); ++cxt )
for( unsigned int cxt=0; cxt < _pcpoList.size(); ++cxt )
{
if( ! _pcpoList[cxt] ) continue;
@@ -112,10 +126,10 @@ ProgramObject::~ProgramObject()
}
// mark each PCPO (per-context ProgramObject) as needing a relink
// mark all PCPOs as needing a relink
void ProgramObject::dirtyProgramObject()
{
for( unsigned int cxt=0; cxt<_pcpoList.size(); ++cxt )
for( unsigned int cxt=0; cxt < _pcpoList.size(); ++cxt )
{
if( ! _pcpoList[cxt] ) continue;
@@ -124,58 +138,95 @@ void ProgramObject::dirtyProgramObject()
}
}
void ProgramObject::addShader( ShaderObject* shader )
// mark all attached ShaderObjects as needing a rebuild
void ProgramObject::dirtyShaderObjects()
{
_shaderObjectList.push_back(shader);
for( unsigned int i=0; i < _shaderObjectList.size() ; ++i )
{
_shaderObjectList[i]->dirtyShaderObject();
}
}
void ProgramObject::addShader( ShaderObject* shadObj )
{
_shaderObjectList.push_back( shadObj );
shadObj->addProgObjRef( this );
dirtyProgramObject();
}
void ProgramObject::setUniform( const char* uniformName, int value )
{
_univalList.push_back( new UniformValue_int( uniformName, value ) );
}
void ProgramObject::setUniform( const char* uniformName, float value )
{
_univalList.push_back( new UniformValue_float( uniformName, value ) );
}
void ProgramObject::setUniform( const char* uniformName, osg::Vec2 value )
{
_univalList.push_back( new UniformValue_Vec2( uniformName, value ) );
}
void ProgramObject::setUniform( const char* uniformName, osg::Vec3 value )
{
_univalList.push_back( new UniformValue_Vec3( uniformName, value ) );
}
void ProgramObject::setUniform( const char* uniformName, osg::Vec4 value )
{
_univalList.push_back( new UniformValue_Vec4( uniformName, value ) );
}
void ProgramObject::apply(osg::State& state) const
{
const unsigned int contextID = state.getContextID();
const Extensions* extensions = Extensions::Get(contextID,true);
if (!extensions->isShaderObjectsSupported())
return;
// if there are no ShaderObjects attached (ie it is "empty"),
// indicates to use GL 1.x "fixed functionality" rendering.
if( _shaderObjectList.size() == 0 )
// if there are no ShaderObjects on this ProgramObject,
// use GL 1.x "fixed functionality" rendering.
if( !_enabled || _shaderObjectList.empty() )
{
// glProgramObject handle 0 == GL 1.x fixed functionality
extensions->glUseProgramObject( 0 );
if( extensions->isShaderObjectsSupported() )
{
extensions->glUseProgramObject( 0 );
}
return;
}
PerContextProgObj* pcpo = getPCPO( contextID );
// if the first apply(), attach glShaderObjects to the glProgramObject
if( pcpo->isUnattached() )
if( ! extensions->isShaderObjectsSupported() )
{
for( unsigned int i=0; i < _shaderObjectList.size() ; ++i )
{
if( ! _shaderObjectList[i] ) continue;
_shaderObjectList[i]->attach( contextID, pcpo->getHandle() );
}
pcpo->markAsAttached();
osg::notify(osg::WARN) << "ARB_shader_objects not supported by OpenGL driver" << std::endl;
return;
}
// if we're dirty, build all attached objects, then build ourself
const osg::FrameStamp* frameStamp = state.getFrameStamp();
const int frameNumber = (frameStamp) ? frameStamp->getFrameNumber() : -1;
updateUniforms( frameNumber );
PerContextProgObj* pcpo = getPCPO( contextID );
if( pcpo->isDirty() )
{
for( unsigned int i=0; i < _shaderObjectList.size() ; ++i )
{
if( ! _shaderObjectList[i] ) continue;
_shaderObjectList[i]->build( contextID );
}
if( pcpo->build() )
pcpo->markAsClean();
pcpo->build();
}
// make this glProgramObject part of current GL state
pcpo->use();
// consume any pending setUniform messages
pcpo->applyUniformValues();
}
@@ -183,49 +234,121 @@ ProgramObject::PerContextProgObj* ProgramObject::getPCPO(unsigned int contextID)
{
if( ! _pcpoList[contextID].valid() )
{
_pcpoList[contextID] = new PerContextProgObj( this, Extensions::Get(contextID,true) );
_pcpoList[contextID] = new PerContextProgObj( this, contextID );
// attach all PCSOs to this new PCPO
for( unsigned int i=0; i < _shaderObjectList.size() ; ++i )
{
_shaderObjectList[i]->attach( contextID, _pcpoList[contextID]->getHandle() );
}
}
return _pcpoList[contextID].get();
}
void ProgramObject::updateUniforms( int frameNumber ) const
{
if( frameNumber <= _frameNumberOfLastPCPOUpdate )
return;
_frameNumberOfLastPCPOUpdate = frameNumber;
if( _univalList.empty() )
return;
for( unsigned int cxt=0; cxt < _pcpoList.size(); ++cxt )
{
if( ! _pcpoList[cxt] ) continue;
PerContextProgObj* pcpo = _pcpoList[cxt].get();
pcpo->updateUniforms( _univalList );
}
_univalList.clear();
}
///////////////////////////////////////////////////////////////////////////
// PCPO : OSG abstraction of the per-context Program Object
ProgramObject::PerContextProgObj::PerContextProgObj(const ProgramObject* parent, Extensions* extensions) :
osg::Referenced()
ProgramObject::PerContextProgObj::PerContextProgObj(const ProgramObject* progObj, unsigned int contextID ) :
osg::Referenced(),
_contextID( contextID )
{
_parent = parent;
_extensions = extensions;
_handle= _extensions->glCreateProgramObject();
_progObj = progObj;
_extensions = Extensions::Get( _contextID, true );
_glProgObjHandle = _extensions->glCreateProgramObject();
markAsDirty();
_unattached = true;
}
ProgramObject::PerContextProgObj::PerContextProgObj(const PerContextProgObj& rhs) :
osg::Referenced()
osg::Referenced(),
_contextID( rhs._contextID )
{
_parent = rhs._parent;
_progObj = rhs._progObj;
_extensions = rhs._extensions;
_handle= rhs._handle;
_glProgObjHandle = rhs._glProgObjHandle ;
_dirty = rhs._dirty;
_unattached = rhs._unattached;
}
ProgramObject::PerContextProgObj::~PerContextProgObj()
{
}
bool ProgramObject::PerContextProgObj::build() const
void ProgramObject::PerContextProgObj::build()
{
_extensions->glLinkProgram(_handle);
return true;
int linked;
_extensions->glLinkProgram( _glProgObjHandle );
_extensions->glGetObjectParameteriv(_glProgObjHandle,
GL_OBJECT_LINK_STATUS_ARB, &linked);
_dirty = (linked == 0);
if( _dirty )
{
osg::notify(osg::WARN) << "glLinkProgram FAILED:" << std::endl;
printInfoLog(osg::WARN);
}
}
void ProgramObject::PerContextProgObj::use() const
{
_extensions->glUseProgramObject( _handle );
_extensions->glUseProgramObject( _glProgObjHandle );
}
void ProgramObject::PerContextProgObj::updateUniforms( const UniformValueList& univalList )
{
// TODO: should the incoming list be appended rather than assigned?
_univalList = univalList;
}
void ProgramObject::PerContextProgObj::applyUniformValues()
{
Extensions *ext = _extensions.get();
for( unsigned int i=0; i < _univalList.size() ; ++i )
{
_univalList[i]->apply( ext, _glProgObjHandle );
}
_univalList.clear();
}
void ProgramObject::PerContextProgObj::printInfoLog(osg::NotifySeverity severity) const
{
int blen = 0; // length of buffer to allocate
int slen = 0; // strlen GL actually wrote to buffer
_extensions->glGetObjectParameteriv(_glProgObjHandle, GL_OBJECT_INFO_LOG_LENGTH_ARB , &blen);
if (blen > 1)
{
GLcharARB* infoLog = new GLcharARB[blen];
_extensions->glGetInfoLog(_glProgObjHandle, blen, &slen, infoLog);
osg::notify(severity) << infoLog << std::endl;
delete infoLog;
}
}
///////////////////////////////////////////////////////////////////////////
// osgGL2::ShaderObject
///////////////////////////////////////////////////////////////////////////
@@ -260,13 +383,19 @@ ShaderObject::~ShaderObject()
// mark each PCSO (per-context Shader Object) as needing a recompile
void ShaderObject::dirtyShaderObject()
{
for( unsigned int cxt=0; cxt<_pcsoList.size(); ++cxt )
for( unsigned int cxt=0; cxt < _pcsoList.size(); ++cxt )
{
if( ! _pcsoList[cxt] ) continue;
PerContextShaderObj* pcso = _pcsoList[cxt].get();
pcso->markAsDirty();
}
// mark attached ProgramObjects dirty as well
for( unsigned int i=0; i < _programObjectList.size(); ++i )
{
_programObjectList[i]->dirtyProgramObject();
}
}
void ShaderObject::setShaderSource( const char* sourceText )
@@ -302,17 +431,25 @@ bool ShaderObject::loadShaderSourceFromFile( const char* fileName )
}
const char* ShaderObject::getTypename() const
{
switch( getType() )
{
case VERTEX: return "Vertex";
case FRAGMENT: return "Fragment";
default: return "UNKNOWN";
}
}
bool ShaderObject::build(unsigned int contextID ) const
void ShaderObject::build(unsigned int contextID ) const
{
PerContextShaderObj* pcso = getPCSO( contextID );
if( pcso->isDirty() )
{
if( pcso->build() )
pcso->markAsClean();
pcso->build();
}
return true; /*TODO*/
}
@@ -320,34 +457,44 @@ ShaderObject::PerContextShaderObj* ShaderObject::getPCSO(unsigned int contextID)
{
if( ! _pcsoList[contextID].valid() )
{
_pcsoList[contextID] = new PerContextShaderObj( this, Extensions::Get(contextID,true) );
_pcsoList[contextID] = new PerContextShaderObj( this, contextID );
}
return _pcsoList[contextID].get();
}
void ShaderObject::attach(unsigned int contextID, GLhandleARB progObj) const
{
getPCSO( contextID )->attach( progObj );
}
void ShaderObject::addProgObjRef( ProgramObject* progObj )
{
_programObjectList.push_back( progObj );
}
///////////////////////////////////////////////////////////////////////////
// PCSO : OSG abstraction of the per-context Shader Object
ShaderObject::PerContextShaderObj::PerContextShaderObj(const ShaderObject* parent, Extensions* extensions) :
osg::Referenced()
ShaderObject::PerContextShaderObj::PerContextShaderObj(const ShaderObject* shadObj, unsigned int contextID) :
osg::Referenced(),
_contextID( contextID )
{
_parent = parent;
_extensions = extensions;
_handle = _extensions->glCreateShaderObject( parent->getType() );
_shadObj = shadObj;
_extensions = Extensions::Get( _contextID, true );
_glShaderObjHandle = _extensions->glCreateShaderObject( shadObj->getType() );
markAsDirty();
}
ShaderObject::PerContextShaderObj::PerContextShaderObj(const PerContextShaderObj& rhs) :
osg::Referenced()
osg::Referenced(),
_contextID( rhs._contextID )
{
_parent = rhs._parent;
_shadObj = rhs._shadObj;
_extensions = rhs._extensions;
_handle = rhs._handle;
_glShaderObjHandle = rhs._glShaderObjHandle;
_dirty = rhs._dirty;
}
@@ -355,21 +502,42 @@ ShaderObject::PerContextShaderObj::~PerContextShaderObj()
{
}
bool ShaderObject::PerContextShaderObj::build()
void ShaderObject::PerContextShaderObj::build()
{
const char* sourceText = _parent->getShaderSource().c_str();
int compiled;
const char* sourceText = _shadObj->getShaderSource().c_str();
_extensions->glShaderSource( _handle, 1, &sourceText, NULL );
_extensions->glCompileShader( _handle );
_extensions->glShaderSource( _glShaderObjHandle, 1, &sourceText, NULL );
_extensions->glCompileShader( _glShaderObjHandle );
_extensions->glGetObjectParameteriv(_glShaderObjHandle,
GL_OBJECT_COMPILE_STATUS_ARB, &compiled);
// _extensions->glAttachObject( _handle, vertShaderObject );
return true;
_dirty = (compiled == 0);
if( _dirty )
{
osg::notify(osg::WARN) << _shadObj->getTypename() << " glCompileShader FAILED:" << std::endl;
printInfoLog(osg::WARN);
}
}
void ShaderObject::PerContextShaderObj::attach(GLhandleARB progObj)
void ShaderObject::PerContextShaderObj::attach(GLhandleARB progObj) const
{
_extensions->glAttachObject(progObj, _handle);
_extensions->glAttachObject( progObj, _glShaderObjHandle );
}
void ShaderObject::PerContextShaderObj::printInfoLog(osg::NotifySeverity severity) const
{
int blen = 0; // length of buffer to allocate
int slen = 0; // strlen GL actually wrote to buffer
_extensions->glGetObjectParameteriv(_glShaderObjHandle, GL_OBJECT_INFO_LOG_LENGTH_ARB , &blen);
if (blen > 1)
{
GLcharARB* infoLog = new GLcharARB[blen];
_extensions->glGetInfoLog(_glShaderObjHandle, blen, &slen, infoLog);
osg::notify(severity) << infoLog << std::endl;
delete infoLog;
}
}
/*EOF*/

View File

@@ -0,0 +1,98 @@
/* -*-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: src/osgGL2/UniformValue
* author: Mike Weiblen 2003-09-12
*
* See http://www.3dlabs.com/opengl2/ for more information regarding
* the OpenGL Shading Language.
*/
#include <string>
#include <osg/Notify>
#include <osgGL2/UniformValue>
using namespace osgGL2;
using namespace osg;
int UniformValue::getLocation( Extensions *ext, const GLhandleARB progObj ) const
{
GLint loc = ext->glGetUniformLocation( progObj, _name.c_str() );
if( loc == -1 )
{
osg::notify(osg::INFO) << "Uniform \"" << _name <<
"\" not found in ProgramObject" << std::endl;
}
return loc;
}
///////////////////////////////////////////////////////////////////////////
#define META_UniformValueCtor( typeName ) \
UniformValue_##typeName::UniformValue_##typeName( const char* uniformName, typeName value ) : \
UniformValue( uniformName ) \
{ _value = value; } \
META_UniformValueCtor( int );
void UniformValue_int::apply( Extensions *ext, const GLhandleARB progObj ) const
{
int loc = getLocation( ext, progObj );
if( loc != -1 )
{
ext->glUniform1i( loc, _value );
}
}
META_UniformValueCtor( float );
void UniformValue_float::apply( Extensions *ext, const GLhandleARB progObj ) const
{
int loc = getLocation( ext, progObj );
if( loc != -1 )
{
ext->glUniform1f( loc, _value );
}
}
META_UniformValueCtor( Vec2 );
void UniformValue_Vec2::apply( Extensions *ext, const GLhandleARB progObj ) const
{
int loc = getLocation( ext, progObj );
if( loc != -1 )
{
ext->glUniform2fv( loc, 1, _value.ptr() );
}
}
META_UniformValueCtor( Vec3 );
void UniformValue_Vec3::apply( Extensions *ext, const GLhandleARB progObj ) const
{
int loc = getLocation( ext, progObj );
if( loc != -1 )
{
ext->glUniform3fv( loc, 1, _value.ptr() );
}
}
META_UniformValueCtor( Vec4 );
void UniformValue_Vec4::apply( Extensions *ext, const GLhandleARB progObj ) const
{
int loc = getLocation( ext, progObj );
if( loc != -1 )
{
ext->glUniform4fv( loc, 1, _value.ptr() );
}
}
/*EOF*/

View File

@@ -2,7 +2,7 @@
const char* osgGL2GetVersion()
{
return "0.1.0";
return "0.2.3";
}

View File

@@ -581,10 +581,12 @@ osg::Drawable* ReaderWriterOBJ::makeDrawable_useSeperateIndices(GLMmodel* obj, G
geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::TRIANGLES,0,ntris*3));
}
osgUtil::SmoothingVisitor tsv;
tsv.smooth(*geom);
if (obj->numnormals==0)
{
osgUtil::SmoothingVisitor tsv;
tsv.smooth(*geom);
}
return geom;
}