From 6f09acace9d4c1630306c9242697568ec454f5d1 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 14 Feb 2011 15:01:56 +0000 Subject: [PATCH] Moved ProgramBinary into osg::Program scope --- include/osg/Program | 89 +++++++++++++++++++++++---------------------- src/osg/Program.cpp | 16 ++++---- 2 files changed, 53 insertions(+), 52 deletions(-) diff --git a/include/osg/Program b/include/osg/Program index 173b99bf6..0d7febfec 100644 --- a/include/osg/Program +++ b/include/osg/Program @@ -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 _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 _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.*/ diff --git a/src/osg/Program.cpp b/src/osg/Program.cpp index ccbe3b25a..c37d42a4e 100644 --- a/src/osg/Program.cpp +++ b/src/osg/Program.cpp @@ -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;