Moved ProgramBinary into osg::Program scope
This commit is contained in:
parent
3128c8063e
commit
6f09acace9
@ -35,50 +35,6 @@ namespace osg {
|
||||
|
||||
class State;
|
||||
|
||||
/** Simple class for wrapping up the data used in glProgramBinary and glGetProgramBinary.
|
||||
* On the first run of your application Programs should be assigned an empty ProgramBinary.
|
||||
* Before your application exits it should retrieve the program binary via
|
||||
* Program::PerContextProgram::compileProgramBinary and save it to disk.
|
||||
* When your application is run subsequently, load your binary from disk and use it to set
|
||||
* the data of a ProgramBinary, and set the ProgramBinary on the associated Program.
|
||||
* This will typically result in Program::compileGLObjects executing much faster.*/
|
||||
class OSG_EXPORT ProgramBinary : public osg::Object
|
||||
{
|
||||
public:
|
||||
|
||||
ProgramBinary();
|
||||
|
||||
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
|
||||
ProgramBinary(const ProgramBinary& rhs, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
|
||||
|
||||
META_Object(osg, ProgramBinary);
|
||||
|
||||
/** Allocated a data buffer of specified size/*/
|
||||
void allocate(unsigned int size);
|
||||
|
||||
/** Assign program binary data, copying the specified data into locally stored data buffer, the original data can then be deleted.*/
|
||||
void assign(unsigned int size, const unsigned char* data);
|
||||
|
||||
/** Set the format of the program binary data.*/
|
||||
void setFormat(GLenum format) {_format = format;}
|
||||
|
||||
/** Get the format of the program binary data.*/
|
||||
GLenum getFormat() const {return _format;}
|
||||
|
||||
/** Get the size of the program binary data.*/
|
||||
unsigned int getSize() const { return _data.size(); }
|
||||
|
||||
/** Get a ptr to the program binary data.*/
|
||||
unsigned char* getData() { return _data.empty() ? 0 : &(_data.front()); }
|
||||
|
||||
/** Get a const ptr to the program binary data.*/
|
||||
const unsigned char* getData() const { return _data.empty() ? 0 : &(_data.front()); }
|
||||
|
||||
protected:
|
||||
std::vector<unsigned char> _data;
|
||||
GLenum _format;
|
||||
};
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
/** osg::Program is an application-level abstraction of an OpenGL glProgram.
|
||||
@ -167,6 +123,51 @@ class OSG_EXPORT Program : public osg::StateAttribute
|
||||
/** Remove a uniform block binding. */
|
||||
void removeBindUniformBlock(const std::string& name);
|
||||
|
||||
/** Simple class for wrapping up the data used in glProgramBinary and glGetProgramBinary.
|
||||
* On the first run of your application Programs should be assigned an empty ProgramBinary.
|
||||
* Before your application exits it should retrieve the program binary via
|
||||
* Program::PerContextProgram::compileProgramBinary and save it to disk.
|
||||
* When your application is run subsequently, load your binary from disk and use it to set
|
||||
* the data of a ProgramBinary, and set the ProgramBinary on the associated Program.
|
||||
* This will typically result in Program::compileGLObjects executing much faster.*/
|
||||
class OSG_EXPORT ProgramBinary : public osg::Object
|
||||
{
|
||||
public:
|
||||
|
||||
ProgramBinary();
|
||||
|
||||
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
|
||||
ProgramBinary(const ProgramBinary& rhs, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
|
||||
|
||||
META_Object(osg, ProgramBinary);
|
||||
|
||||
/** Allocated a data buffer of specified size/*/
|
||||
void allocate(unsigned int size);
|
||||
|
||||
/** Assign program binary data, copying the specified data into locally stored data buffer, the original data can then be deleted.*/
|
||||
void assign(unsigned int size, const unsigned char* data);
|
||||
|
||||
/** Set the format of the program binary data.*/
|
||||
void setFormat(GLenum format) {_format = format;}
|
||||
|
||||
/** Get the format of the program binary data.*/
|
||||
GLenum getFormat() const {return _format;}
|
||||
|
||||
/** Get the size of the program binary data.*/
|
||||
unsigned int getSize() const { return _data.size(); }
|
||||
|
||||
/** Get a ptr to the program binary data.*/
|
||||
unsigned char* getData() { return _data.empty() ? 0 : &(_data.front()); }
|
||||
|
||||
/** Get a const ptr to the program binary data.*/
|
||||
const unsigned char* getData() const { return _data.empty() ? 0 : &(_data.front()); }
|
||||
|
||||
protected:
|
||||
std::vector<unsigned char> _data;
|
||||
GLenum _format;
|
||||
};
|
||||
|
||||
|
||||
/** Set the Program using a ProgramBinary. If a ProgramBinary is not yet
|
||||
* available then setting an empty one signals that compileProgramBinary
|
||||
* will be called later.*/
|
||||
|
@ -95,25 +95,25 @@ void Program::discardDeletedGlPrograms(unsigned int contextID)
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// osg::ProgramBinary
|
||||
// osg::Program::ProgramBinary
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ProgramBinary::ProgramBinary() : _format(0)
|
||||
Program::ProgramBinary::ProgramBinary() : _format(0)
|
||||
{
|
||||
}
|
||||
|
||||
ProgramBinary::ProgramBinary(const ProgramBinary& rhs, const osg::CopyOp&) :
|
||||
Program::ProgramBinary::ProgramBinary(const ProgramBinary& rhs, const osg::CopyOp&) :
|
||||
_data(rhs._data), _format(rhs._format)
|
||||
{
|
||||
}
|
||||
|
||||
void ProgramBinary::allocate(unsigned int size)
|
||||
void Program::ProgramBinary::allocate(unsigned int size)
|
||||
{
|
||||
_data.clear();
|
||||
_data.resize(size);
|
||||
}
|
||||
|
||||
void ProgramBinary::assign(unsigned int size, const unsigned char* data)
|
||||
void Program::ProgramBinary::assign(unsigned int size, const unsigned char* data)
|
||||
{
|
||||
allocate(size);
|
||||
if (data)
|
||||
@ -516,8 +516,8 @@ const Program::ActiveVarInfoMap& Program::getActiveAttribs(unsigned int contextI
|
||||
|
||||
Program::PerContextProgram::PerContextProgram(const Program* program, unsigned int contextID ) :
|
||||
osg::Referenced(),
|
||||
_contextID( contextID ),
|
||||
_loadedBinary(false)
|
||||
_loadedBinary(false),
|
||||
_contextID( contextID )
|
||||
{
|
||||
_program = program;
|
||||
_extensions = GL2Extensions::Get( _contextID, true );
|
||||
@ -808,7 +808,7 @@ bool Program::PerContextProgram::getInfoLog( std::string& infoLog ) const
|
||||
return _extensions->getProgramInfoLog( _glProgramHandle, infoLog );
|
||||
}
|
||||
|
||||
ProgramBinary* Program::PerContextProgram::compileProgramBinary(osg::State& state)
|
||||
Program::ProgramBinary* Program::PerContextProgram::compileProgramBinary(osg::State& state)
|
||||
{
|
||||
linkProgram(state);
|
||||
GLint binaryLength = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user