From 3d2f4ea4040bc14f94f40b7ef430e69d050cfb0c Mon Sep 17 00:00:00 2001 From: d-a-heitbrink Date: Fri, 13 Jan 2017 09:56:42 -0600 Subject: [PATCH] Added support for Bindless texture extension, 64 bit uniforms, 64 bit buffers Added new bindless texture example --- examples/CMakeLists.txt | 3 +- include/osg/Array | 20 +++++++++-- include/osg/GLDefines | 13 ++++++- include/osg/GLExtensions | 22 +++++++++++- include/osg/Uniform | 26 +++++++++++++- include/osgDB/DataTypes | 4 +++ include/osgDB/OutputStream | 2 ++ include/osgDB/StreamOperator | 2 ++ src/osgDB/ClassInterface.cpp | 2 ++ src/osgPlugins/ive/DataOutputStream.cpp | 34 ++++++++++++++++++- src/osgPlugins/ive/DataOutputStream.h | 6 +++- src/osgPlugins/ive/DataTypeSize.h | 2 +- src/osgPlugins/osg/AsciiStreamOperator.h | 6 ++++ src/osgPlugins/osg/BinaryStreamOperator.h | 12 +++++++ src/osgPlugins/osg/XmlStreamOperator.h | 12 +++++++ .../deprecated-dotosg/osg/Geometry.cpp | 15 ++++++++ 16 files changed, 171 insertions(+), 10 deletions(-) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 79d8ca3e6..d695fe86f 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -166,10 +166,9 @@ IF(DYNAMIC_OPENSCENEGRAPH) ADD_SUBDIRECTORY(osgwidgettable) ADD_SUBDIRECTORY(osgwidgetwindow) ADD_SUBDIRECTORY(osguserdata) - # GL3/GL4 example ADD_SUBDIRECTORY(osgsimplegl3) - + ADD_SUBDIRECTORY(osgbindlesstext) IF(OSG_CPP_EXCEPTIONS_AVAILABLE) ADD_SUBDIRECTORY(osgunittests) ADD_SUBDIRECTORY(osgmemorytest) diff --git a/include/osg/Array b/include/osg/Array index 3a602c000..d7ae6609c 100644 --- a/include/osg/Array +++ b/include/osg/Array @@ -112,7 +112,10 @@ class OSG_EXPORT Array : public BufferData MatrixArrayType = 33, MatrixdArrayType = 34, - QuatArrayType = 35 + QuatArrayType = 35, + + UInt64ArrayType = 36, + Int64ArrayType = 37 }; enum Binding @@ -442,7 +445,8 @@ typedef TemplateArray typedef TemplateArray QuatArray; - +typedef TemplateIndexArray UInt64Array; +typedef TemplateIndexArray Int64Array; class ArrayVisitor { public: @@ -497,6 +501,9 @@ class ArrayVisitor virtual void apply(MatrixfArray&) {} virtual void apply(MatrixdArray&) {} + + virtual void apply(UInt64Array&) {} + virtual void apply(Int64Array&) {} }; class ConstArrayVisitor @@ -553,6 +560,9 @@ class ConstArrayVisitor virtual void apply(const MatrixfArray&) {} virtual void apply(const MatrixdArray&) {} + + virtual void apply(const UInt64Array&) {} + virtual void apply(const Int64Array&) {} }; @@ -610,6 +620,9 @@ class ValueVisitor virtual void apply(Matrixd&) {} virtual void apply(Quat&) {} + + virtual void apply(GLuint64&){} + virtual void apply(GLint64&){} }; class ConstValueVisitor @@ -666,6 +679,9 @@ class ConstValueVisitor virtual void apply(const Matrixd&) {} virtual void apply(const Quat&) {} + + virtual void apply(const GLuint64&){} + virtual void apply(const GLint64&){} }; template diff --git a/include/osg/GLDefines b/include/osg/GLDefines index 51b9e6134..b5442820d 100644 --- a/include/osg/GLDefines +++ b/include/osg/GLDefines @@ -556,6 +556,14 @@ typedef char GLchar; #define GL_MAP_UNSYNCHRONIZED_BIT 0x0020 #endif +#define GL_INT64_ARB 0x140E +#define GL_UNSIGNED_INT64_ARB 0x140F +#define GL_INT64_VEC2_ARB 0x8FE9 +#define GL_INT64_VEC3_ARB 0x8FEA +#define GL_INT64_VEC4_ARB 0x8FEB +#define GL_UNSIGNED_INT64_VEC2_ARB 0x8FF5 +#define GL_UNSIGNED_INT64_VEC3_ARB 0x8FF6 +#define GL_UNSIGNED_INT64_VEC4_ARB 0x8FF7 /* ------------------------------ GL_KHR_debug ----------------------------- */ #ifndef GL_KHR_debug #define GL_KHR_debug 1 @@ -602,7 +610,6 @@ typedef char GLchar; #define GL_DEBUG_OUTPUT 0x92E0 #endif /* GL_KHR_debug */ - #ifndef GL_ARB_sync #define GL_MAX_SERVER_WAIT_TIMEOUT 0x9111 #define GL_OBJECT_TYPE 0x9112 @@ -653,6 +660,10 @@ typedef char GLchar; #define GL_ALPHA_TEST 0x0BC0 #endif +#ifndef GLuint64EXT + typedef uint64_t GLuint64EXT; +#endif + namespace osg { #ifndef GL_VERSION_3_2 diff --git a/include/osg/GLExtensions b/include/osg/GLExtensions index d4c46c093..3309660df 100644 --- a/include/osg/GLExtensions +++ b/include/osg/GLExtensions @@ -319,6 +319,22 @@ class OSG_EXPORT GLExtensions : public osg::Referenced void (GL_APIENTRY * glUniform2uiv)( GLint location, GLsizei count, const GLuint *value ); void (GL_APIENTRY * glUniform3uiv)( GLint location, GLsizei count, const GLuint *value ); void (GL_APIENTRY * glUniform4uiv)( GLint location, GLsizei count, const GLuint *value ); + void (GL_APIENTRY * glUniform1i64 )(GLint location, GLint64 x) ; + void (GL_APIENTRY * glUniform1i64v )(GLint location, GLsizei count, const GLint64* value) ; + void (GL_APIENTRY * glUniform1ui64 )(GLint location, GLuint64 x) ; + void (GL_APIENTRY * glUniform1ui64v)(GLint location, GLsizei count, const GLuint64* value) ; + void (GL_APIENTRY * glUniform2i64 )(GLint location, GLint64 x, GLint64 y) ; + void (GL_APIENTRY * glUniform2i64v )(GLint location, GLsizei count, const GLint64* value) ; + void (GL_APIENTRY * glUniform2ui64 )(GLint location, GLuint64 x, GLuint64 y) ; + void (GL_APIENTRY * glUniform2ui64v)(GLint location, GLsizei count, const GLuint64* value) ; + void (GL_APIENTRY * glUniform3i64 )(GLint location, GLint64 x, GLint64 y, GLint64 z) ; + void (GL_APIENTRY * glUniform3i64v )(GLint location, GLsizei count, const GLint64* value) ; + void (GL_APIENTRY * glUniform3ui64 )(GLint location, GLuint64 x, GLuint64 y, GLuint64 z) ; + void (GL_APIENTRY * glUniform3ui64v)(GLint location, GLsizei count, const GLuint64* value) ; + void (GL_APIENTRY * glUniform4i64 )(GLint location, GLint64 x, GLint64 y, GLint64 z, GLint64 w) ; + void (GL_APIENTRY * glUniform4i64v )(GLint location, GLsizei count, const GLint64* value) ; + void (GL_APIENTRY * glUniform4ui64 )(GLint location, GLuint64 x, GLuint64 y, GLuint64 z, GLuint64 w) ; + void (GL_APIENTRY * glUniform4ui64v)(GLint location, GLsizei count, const GLuint64* value) ; GLuint (GL_APIENTRY * glGetHandleARB) (GLenum pname); void (GL_APIENTRY * glGetUniformIndices)(GLuint program, GLsizei uniformCount, const GLchar* *uniformNames, GLuint *uniformIndices); void (GL_APIENTRY * glGetActiveUniformsiv)(GLuint program, GLsizei uniformCount, const GLuint *uniformIndices, GLenum pname, GLint *params); @@ -348,7 +364,11 @@ class OSG_EXPORT GLExtensions : public osg::Referenced void (GL_APIENTRY * glUniformMatrix4x3dv)( GLint location, GLsizei count, GLboolean transpose, const GLdouble* value ); void (GL_APIENTRY * glGetActiveAtomicCounterBufferiv)( GLuint program, GLuint bufferIndex, GLenum pname, GLint* params ); void (GL_APIENTRY * glDispatchCompute)( GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ ); - + GLuint64EXT (GL_APIENTRY* glGetTextureHandle)(GLint texture); + void (GL_APIENTRY* glMakeTextureHandleResident)(GLuint64EXT handle); + void (GL_APIENTRY* glMakeTextureHandleNonResident)(GLuint64EXT handle); + void (GL_APIENTRY* glUniformHandleui64)(GLint location, GLuint64EXT handle); + GLboolean (GL_APIENTRY* glIsTextureHandleResident)(GLuint64EXT handle); // Buffer Object extensions bool isBufferObjectSupported; diff --git a/include/osg/Uniform b/include/osg/Uniform index 134897a6e..22fbc3993 100644 --- a/include/osg/Uniform +++ b/include/osg/Uniform @@ -439,6 +439,9 @@ class OSG_EXPORT Uniform : public Object BOOL_VEC3 = GL_BOOL_VEC3, BOOL_VEC4 = GL_BOOL_VEC4, + INT64 = GL_INT64_ARB, + UNSIGNED_INT64 = GL_UNSIGNED_INT64_ARB, + FLOAT_MAT2 = GL_FLOAT_MAT2, FLOAT_MAT3 = GL_FLOAT_MAT3, FLOAT_MAT4 = GL_FLOAT_MAT4, @@ -603,6 +606,8 @@ class OSG_EXPORT Uniform : public Object explicit Uniform( const char* name, int i ); explicit Uniform( const char* name, unsigned int ui ); explicit Uniform( const char* name, bool b ); + explicit Uniform( const char* name, unsigned long long ull); + explicit Uniform( const char* name, long long ll ); Uniform( const char* name, const osg::Vec2& v2 ); Uniform( const char* name, const osg::Vec3& v3 ); Uniform( const char* name, const osg::Vec4& v4 ); @@ -679,6 +684,8 @@ class OSG_EXPORT Uniform : public Object bool set( int i ); bool set( unsigned int ui ); bool set( bool b ); + bool set( unsigned long long ull ); + bool set( long long ll ); bool set( const osg::Vec2& v2 ); bool set( const osg::Vec3& v3 ); bool set( const osg::Vec4& v4 ); @@ -719,6 +726,8 @@ class OSG_EXPORT Uniform : public Object bool get( int& i ) const; bool get( unsigned int& ui ) const; bool get( bool& b ) const; + bool get( unsigned long long & ull ) const; + bool get( long long& ll ) const; bool get( osg::Vec2& v2 ) const; bool get( osg::Vec3& v3 ) const; bool get( osg::Vec4& v4 ) const; @@ -759,6 +768,8 @@ class OSG_EXPORT Uniform : public Object bool setElement( unsigned int index, int i ); bool setElement( unsigned int index, unsigned int ui ); bool setElement( unsigned int index, bool b ); + bool setElement( unsigned int index, unsigned long long ull ); + bool setElement( unsigned int index, long long ll ); bool setElement( unsigned int index, const osg::Vec2& v2 ); bool setElement( unsigned int index, const osg::Vec3& v3 ); bool setElement( unsigned int index, const osg::Vec4& v4 ); @@ -799,6 +810,8 @@ class OSG_EXPORT Uniform : public Object bool getElement( unsigned int index, int& i ) const; bool getElement( unsigned int index, unsigned int& ui ) const; bool getElement( unsigned int index, bool& b ) const; + bool getElement( unsigned int index, unsigned long long & ull ) const; + bool getElement( unsigned int index, long long& ll ) const; bool getElement( unsigned int index, osg::Vec2& v2 ) const; bool getElement( unsigned int index, osg::Vec3& v3 ) const; bool getElement( unsigned int index, osg::Vec4& v4 ) const; @@ -866,7 +879,8 @@ class OSG_EXPORT Uniform : public Object bool setArray( DoubleArray* array ); bool setArray( IntArray* array ); bool setArray( UIntArray* array ); - + bool setArray( UInt64Array* array ); + bool setArray( Int64Array* array ); /** Get the internal data array for a float osg::Uniform. */ FloatArray* getFloatArray() { return _floatArray.get(); } const FloatArray* getFloatArray() const { return _floatArray.get(); } @@ -883,6 +897,14 @@ class OSG_EXPORT Uniform : public Object UIntArray* getUIntArray() { return _uintArray.get(); } const UIntArray* getUIntArray() const { return _uintArray.get(); } + /** Get the internal data array for an unsigned int osg::Uniform. */ + UInt64Array* getUInt64Array() { return _uint64Array.get(); } + const UInt64Array* getUInt64Array() const { return _uint64Array.get(); } + + /** Get the internal data array for an unsigned int osg::Uniform. */ + Int64Array* getInt64Array() { return _int64Array.get(); } + const Int64Array* getInt64Array() const { return _int64Array.get(); } + inline void setModifiedCount(unsigned int mc) { _modifiedCount = mc; } inline unsigned int getModifiedCount() const { return _modifiedCount; } @@ -922,6 +944,8 @@ class OSG_EXPORT Uniform : public Object ref_ptr _doubleArray; ref_ptr _intArray; ref_ptr _uintArray; + ref_ptr _int64Array; + ref_ptr _uint64Array; ref_ptr _updateCallback; ref_ptr _eventCallback; diff --git a/include/osgDB/DataTypes b/include/osgDB/DataTypes index db8a70cd2..8d319e806 100644 --- a/include/osgDB/DataTypes +++ b/include/osgDB/DataTypes @@ -33,6 +33,7 @@ const int CHAR_SIZE = 1; const int SHORT_SIZE = 2; const int INT_SIZE = 4; const int LONG_SIZE = 4; +const int INT64_SIZE = 8; const int FLOAT_SIZE = 4; const int DOUBLE_SIZE = 8; const int GLENUM_SIZE = 4; @@ -71,6 +72,9 @@ const int ID_VEC2UI_ARRAY = 29; const int ID_VEC3UI_ARRAY = 30; const int ID_VEC4UI_ARRAY = 31; +const int ID_UINT64_ARRAY = 32; +const int ID_INT64_ARRAY = 33; + const int ID_DRAWARRAYS = 50; const int ID_DRAWARRAY_LENGTH = 51; const int ID_DRAWELEMENTS_UBYTE = 52; diff --git a/include/osgDB/OutputStream b/include/osgDB/OutputStream index 538ff9755..d312680bb 100644 --- a/include/osgDB/OutputStream +++ b/include/osgDB/OutputStream @@ -102,6 +102,8 @@ public: OutputStream& operator<<( unsigned long l ) { _out->writeULong(l); return *this; } OutputStream& operator<<( float f ) { _out->writeFloat(f); return *this; } OutputStream& operator<<( double d ) { _out->writeDouble(d); return *this; } + OutputStream& operator<<( long long ll ) { _out->writeInt64(ll); return *this; } + OutputStream& operator<<( unsigned long long ull ) { _out->writeUInt64(ull); return *this; } OutputStream& operator<<( const std::string& s ) { _out->writeString(s); return *this; } OutputStream& operator<<( const char* s ) { _out->writeString(s); return *this; } OutputStream& operator<<( std::ostream& (*fn)(std::ostream&) ) { _out->writeStream(fn); return *this; } diff --git a/include/osgDB/StreamOperator b/include/osgDB/StreamOperator index c4abc1331..6b29e29dd 100644 --- a/include/osgDB/StreamOperator +++ b/include/osgDB/StreamOperator @@ -37,6 +37,8 @@ public: virtual void writeUInt( unsigned int i ) = 0; virtual void writeLong( long l ) = 0; virtual void writeULong( unsigned long l ) = 0; + virtual void writeInt64( int64_t ll ) = 0; + virtual void writeUInt64( uint64_t ull ) = 0; virtual void writeFloat( float f ) = 0; virtual void writeDouble( double d ) = 0; virtual void writeString( const std::string& s ) = 0; diff --git a/src/osgDB/ClassInterface.cpp b/src/osgDB/ClassInterface.cpp index 15253262b..f2c7c0b8b 100644 --- a/src/osgDB/ClassInterface.cpp +++ b/src/osgDB/ClassInterface.cpp @@ -58,6 +58,8 @@ public: virtual void writeULong( unsigned long l ) { write(l); } virtual void writeFloat( float f ) { write(f); } virtual void writeDouble( double d ) { write(d); } + virtual void writeInt64( long long ll ) { write(ll); } + virtual void writeUInt64( unsigned long long ull ) { write(ull); } virtual void writeString( const std::string& s ) { _str.insert(_str.end(), s.begin(), s.end()); } virtual void writeStream( std::ostream& (*)(std::ostream&) ) {} virtual void writeBase( std::ios_base& (*)(std::ios_base&) ) {} diff --git a/src/osgPlugins/ive/DataOutputStream.cpp b/src/osgPlugins/ive/DataOutputStream.cpp index dde9203c4..afeada60e 100644 --- a/src/osgPlugins/ive/DataOutputStream.cpp +++ b/src/osgPlugins/ive/DataOutputStream.cpp @@ -497,6 +497,34 @@ void DataOutputStream::writeVec4b(const osg::Vec4b& v){ if (_verboseOutput) std::cout<<"read/writeVec4b() ["<write((char*)&ull, INT64SIZE); + + if (_verboseOutput) std::cout<<"read/writeUInt64() ["<write((char*)&ll, INT64SIZE); + + if (_verboseOutput) std::cout<<"read/writeInt64() ["<getNumElements(); + writeUInt64(size); + for(int i =0; igetNumElements(); + writeInt64(size); + for(int i =0; i(a)); break; - case osg::Array::Vec4dArrayType: + case osg::Array::Vec4dArrayType: writeChar((char)17); writeVec4dArray(static_cast(a)); break; + case osg::Array::UInt64ArrayType: + writeChar((char)18); + writeUInt64Array(static_cast(a)); + break; default: throwException("Unknown array type in DataOutputStream::writeArray()"); } } diff --git a/src/osgPlugins/ive/DataOutputStream.h b/src/osgPlugins/ive/DataOutputStream.h index 9969079bc..262c5cb9a 100644 --- a/src/osgPlugins/ive/DataOutputStream.h +++ b/src/osgPlugins/ive/DataOutputStream.h @@ -72,7 +72,11 @@ public: void writeVec2b(const osg::Vec2b& v); void writeVec3b(const osg::Vec3b& v); void writeVec4b(const osg::Vec4b& v); - + + void writeUInt64(unsigned long long ull); + void writeInt64(long long ll); + void writeUInt64Array(const osg::UInt64Array* a); + void writeInt64Array(const osg::Int64Array* a); void writePackedFloatArray(const osg::FloatArray* a, float maxError); void writeFloatArray(const osg::FloatArray* a); diff --git a/src/osgPlugins/ive/DataTypeSize.h b/src/osgPlugins/ive/DataTypeSize.h index 7b9c0db8c..a82cf5fbc 100644 --- a/src/osgPlugins/ive/DataTypeSize.h +++ b/src/osgPlugins/ive/DataTypeSize.h @@ -9,7 +9,7 @@ #define FLOATSIZE 4 #define LONGSIZE 4 #define DOUBLESIZE 8 - +#define INT64SIZE 8 //Don't know where else to put this namespace ive{ diff --git a/src/osgPlugins/osg/AsciiStreamOperator.h b/src/osgPlugins/osg/AsciiStreamOperator.h index c0925e989..0097d575c 100644 --- a/src/osgPlugins/osg/AsciiStreamOperator.h +++ b/src/osgPlugins/osg/AsciiStreamOperator.h @@ -49,6 +49,12 @@ public: virtual void writeULong( unsigned long l ) { indentIfRequired(); *_out << l << ' '; } + virtual void writeInt64( long long ll ) + { indentIfRequired(); *_out << ll << ' '; } + + virtual void writeUInt64( unsigned long long ull ) + { indentIfRequired(); *_out << ull << ' '; } + virtual void writeFloat( float f ) { indentIfRequired(); *_out << f << ' '; } diff --git a/src/osgPlugins/osg/BinaryStreamOperator.h b/src/osgPlugins/osg/BinaryStreamOperator.h index 479a844e1..552bb10ff 100644 --- a/src/osgPlugins/osg/BinaryStreamOperator.h +++ b/src/osgPlugins/osg/BinaryStreamOperator.h @@ -49,6 +49,18 @@ public: _out->write( (char*)&value, osgDB::LONG_SIZE ); } + virtual void writeInt64( int64_t ll ) + {_out->write( (char*)&ll, osgDB::INT64_SIZE );} + + virtual void writeUInt64( uint64_t ull ) + {_out->write( (char*)&ull, osgDB::INT64_SIZE );} + + virtual void writeInt( long long ll ) + { _out->write( (char*)&ll, osgDB::INT64_SIZE ); } + + virtual void writeUInt( unsigned long long ull ) + { _out->write( (char*)&ull, osgDB::INT64_SIZE ); } + virtual void writeFloat( float f ) { _out->write( (char*)&f, osgDB::FLOAT_SIZE ); } diff --git a/src/osgPlugins/osg/XmlStreamOperator.h b/src/osgPlugins/osg/XmlStreamOperator.h index 33bb50f7a..07c740737 100644 --- a/src/osgPlugins/osg/XmlStreamOperator.h +++ b/src/osgPlugins/osg/XmlStreamOperator.h @@ -59,6 +59,18 @@ public: virtual void writeULong( unsigned long l ) { _sstream << l; addToCurrentNode( _sstream.str() ); _sstream.str(""); } + virtual void writeUInt64(uint64_t ull) + {_sstream << ull; addToCurrentNode( _sstream.str() ); _sstream.str("");} + + virtual void writeInt64(int64_t ll) + {_sstream << ll; addToCurrentNode( _sstream.str() ); _sstream.str("");} + + virtual void writeInt( unsigned long long ull ) + { _sstream << ull; addToCurrentNode( _sstream.str() ); _sstream.str(""); } + + virtual void writeUInt( long long ll ) + { _sstream << ll; addToCurrentNode( _sstream.str() ); _sstream.str(""); } + virtual void writeFloat( float f ) { _sstream << f; addToCurrentNode( _sstream.str() ); _sstream.str(""); } diff --git a/src/osgWrappers/deprecated-dotosg/osg/Geometry.cpp b/src/osgWrappers/deprecated-dotosg/osg/Geometry.cpp index 8b0489b3c..3d42e35e1 100644 --- a/src/osgWrappers/deprecated-dotosg/osg/Geometry.cpp +++ b/src/osgWrappers/deprecated-dotosg/osg/Geometry.cpp @@ -995,6 +995,21 @@ bool Array_writeLocalData(const Array& array,Output& fw) return true; } break; + case(Array::UInt64ArrayType): + { + fw<(array.getDataPointer()); + writeArray(fw,&base[0], &base[array.getNumElements()]); + return true; + } + case(Array::Int64ArrayType): + { + fw<(array.getDataPointer()); + writeArray(fw,&base[0], &base[array.getNumElements()]); + return true; + } + break; case(Array::ArrayType): default: return false;