Experimental support for OpenGL Vertex Array Object
This commit is contained in:
parent
d51036f57e
commit
14d1483b06
@ -113,6 +113,10 @@ public:
|
|||||||
return _ptr;
|
return _ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual const GLvoid* getDataPointer(unsigned int index) const {
|
||||||
|
return &((*_ptr)[index]);
|
||||||
|
}
|
||||||
|
|
||||||
/** Returns the number of elements in the array. */
|
/** Returns the number of elements in the array. */
|
||||||
virtual unsigned int getNumElements() const {
|
virtual unsigned int getNumElements() const {
|
||||||
return _numElements;
|
return _numElements;
|
||||||
|
@ -164,6 +164,7 @@ class OSG_EXPORT Array : public BufferData
|
|||||||
|
|
||||||
virtual unsigned int getElementSize() const = 0;
|
virtual unsigned int getElementSize() const = 0;
|
||||||
virtual const GLvoid* getDataPointer() const = 0;
|
virtual const GLvoid* getDataPointer() const = 0;
|
||||||
|
virtual const GLvoid* getDataPointer(unsigned int index) const = 0;
|
||||||
virtual unsigned int getTotalDataSize() const = 0;
|
virtual unsigned int getTotalDataSize() const = 0;
|
||||||
virtual unsigned int getNumElements() const = 0;
|
virtual unsigned int getNumElements() const = 0;
|
||||||
virtual void reserveArray(unsigned int num) = 0;
|
virtual void reserveArray(unsigned int num) = 0;
|
||||||
@ -285,8 +286,9 @@ class TemplateArray : public Array, public MixinVector<T>
|
|||||||
MixinVector<T>( *this ).swap( *this );
|
MixinVector<T>( *this ).swap( *this );
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual unsigned int getElementSize() const { return sizeof(ElementDataType); }
|
virtual unsigned int getElementSize() const { return sizeof(ElementDataType); }
|
||||||
virtual const GLvoid* getDataPointer() const { if (!this->empty()) return &this->front(); else return 0; }
|
virtual const GLvoid* getDataPointer() const { if (!this->empty()) return &this->front(); else return 0; }
|
||||||
|
virtual const GLvoid* getDataPointer(unsigned int index) const { if (!this->empty()) return &((*this)[index]); else return 0; }
|
||||||
virtual unsigned int getTotalDataSize() const { return static_cast<unsigned int>(this->size()*sizeof(ElementDataType)); }
|
virtual unsigned int getTotalDataSize() const { return static_cast<unsigned int>(this->size()*sizeof(ElementDataType)); }
|
||||||
virtual unsigned int getNumElements() const { return static_cast<unsigned int>(this->size()); }
|
virtual unsigned int getNumElements() const { return static_cast<unsigned int>(this->size()); }
|
||||||
virtual void reserveArray(unsigned int num) { this->reserve(num); }
|
virtual void reserveArray(unsigned int num) { this->reserve(num); }
|
||||||
@ -376,6 +378,7 @@ class TemplateIndexArray : public IndexArray, public MixinVector<T>
|
|||||||
|
|
||||||
virtual unsigned int getElementSize() const { return sizeof(ElementDataType); }
|
virtual unsigned int getElementSize() const { return sizeof(ElementDataType); }
|
||||||
virtual const GLvoid* getDataPointer() const { if (!this->empty()) return &this->front(); else return 0; }
|
virtual const GLvoid* getDataPointer() const { if (!this->empty()) return &this->front(); else return 0; }
|
||||||
|
virtual const GLvoid* getDataPointer(unsigned int index) const { if (!this->empty()) return &((*this)[index]); else return 0; }
|
||||||
virtual unsigned int getTotalDataSize() const { return static_cast<unsigned int>(this->size()*sizeof(T)); }
|
virtual unsigned int getTotalDataSize() const { return static_cast<unsigned int>(this->size()*sizeof(T)); }
|
||||||
virtual unsigned int getNumElements() const { return static_cast<unsigned int>(this->size()); }
|
virtual unsigned int getNumElements() const { return static_cast<unsigned int>(this->size()); }
|
||||||
virtual void reserveArray(unsigned int num) { this->reserve(num); }
|
virtual void reserveArray(unsigned int num) { this->reserve(num); }
|
||||||
|
@ -299,6 +299,17 @@ class OSG_EXPORT DisplaySettings : public osg::Referenced
|
|||||||
int getNvOptimusEnablement() const;
|
int getNvOptimusEnablement() const;
|
||||||
|
|
||||||
|
|
||||||
|
enum GeometryImplementation
|
||||||
|
{
|
||||||
|
OLD_GEOMETRY_IMPLEMENTATION,
|
||||||
|
NEW_GEOMETRY_IMPLEMENTATION,
|
||||||
|
VERTEX_ARRAY_OBJECT
|
||||||
|
};
|
||||||
|
|
||||||
|
void setGeometryImplementation(GeometryImplementation gi) { _geometryImplementation = gi; }
|
||||||
|
GeometryImplementation getGeometryImplementation() const { return _geometryImplementation; }
|
||||||
|
|
||||||
|
|
||||||
void setKeystoneHint(bool enabled) { _keystoneHint = enabled; }
|
void setKeystoneHint(bool enabled) { _keystoneHint = enabled; }
|
||||||
bool getKeystoneHint() const { return _keystoneHint; }
|
bool getKeystoneHint() const { return _keystoneHint; }
|
||||||
|
|
||||||
@ -388,6 +399,8 @@ class OSG_EXPORT DisplaySettings : public osg::Referenced
|
|||||||
SwapMethod _swapMethod;
|
SwapMethod _swapMethod;
|
||||||
unsigned int _syncSwapBuffers;
|
unsigned int _syncSwapBuffers;
|
||||||
|
|
||||||
|
GeometryImplementation _geometryImplementation;
|
||||||
|
|
||||||
bool _keystoneHint;
|
bool _keystoneHint;
|
||||||
FileNames _keystoneFileNames;
|
FileNames _keystoneFileNames;
|
||||||
Objects _keystones;
|
Objects _keystones;
|
||||||
|
@ -20,11 +20,13 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
#include <map>
|
||||||
|
|
||||||
|
|
||||||
namespace osg {
|
namespace osg {
|
||||||
|
|
||||||
/** Return floating-point OpenGL version number.
|
/** Return floating-point OpenGL/GLES version number.
|
||||||
* Note: Must only be called within a valid OpenGL context,
|
* Note: Must only be called within a valid OpenGL context,
|
||||||
* undefined behavior may occur otherwise.
|
* undefined behavior may occur otherwise.
|
||||||
*/
|
*/
|
||||||
@ -34,19 +36,25 @@ extern OSG_EXPORT float getGLVersionNumber();
|
|||||||
*/
|
*/
|
||||||
extern OSG_EXPORT bool isExtensionInExtensionString(const char *extension, const char *extensionString);
|
extern OSG_EXPORT bool isExtensionInExtensionString(const char *extension, const char *extensionString);
|
||||||
|
|
||||||
/** Return true if OpenGL "extension" is supported.
|
/** Return true if OpenGL/GLES "extension" is supported.
|
||||||
* Note: Must only be called within a valid OpenGL context,
|
* Note: Must only be called within a valid OpenGL context,
|
||||||
* undefined behavior may occur otherwise.
|
* undefined behavior may occur otherwise.
|
||||||
*/
|
*/
|
||||||
extern OSG_EXPORT bool isGLExtensionSupported(unsigned int contextID, const char *extension);
|
extern OSG_EXPORT bool isGLExtensionSupported(unsigned int contextID, const char *extension);
|
||||||
|
|
||||||
/** Return true if OpenGL "extension" or minimum OpenGL version number is supported.
|
/** Return true if either OpenGL/GLES "extension1" or "extension2" is supported.
|
||||||
|
* Note: Must only be called within a valid OpenGL context,
|
||||||
|
* undefined behavior may occur otherwise.
|
||||||
|
*/
|
||||||
|
extern OSG_EXPORT bool isGLExtensionSupported(unsigned int contextID, const char *extension1, const char *extension2);
|
||||||
|
|
||||||
|
/** Return true if OpenGL/GLES "extension" or minimum OpenGL version number is supported.
|
||||||
* Note: Must only be called within a valid OpenGL context,
|
* Note: Must only be called within a valid OpenGL context,
|
||||||
* undefined behavior may occur otherwise.
|
* undefined behavior may occur otherwise.
|
||||||
*/
|
*/
|
||||||
extern OSG_EXPORT bool isGLExtensionOrVersionSupported(unsigned int contextID, const char *extension, float requiredGlVersion);
|
extern OSG_EXPORT bool isGLExtensionOrVersionSupported(unsigned int contextID, const char *extension, float requiredGlVersion);
|
||||||
|
|
||||||
/** Return the address of the specified OpenGL function.
|
/** Return the address of the specified OpenGL/GLES function.
|
||||||
* Return NULL if function not supported by OpenGL library.
|
* Return NULL if function not supported by OpenGL library.
|
||||||
* Note, glGLExtensionFuncPtr is declared inline so that the code
|
* Note, glGLExtensionFuncPtr is declared inline so that the code
|
||||||
* is compiled locally to the calling code. This should get by Windows'
|
* is compiled locally to the calling code. This should get by Windows'
|
||||||
@ -123,11 +131,35 @@ bool setGLExtensionFuncPtr(T& t, const char* str1, const char* str2, const char*
|
|||||||
return convertPointer(t, validContext ? osg::getGLExtensionFuncPtr(str1, str2, str3) : 0);
|
return convertPointer(t, validContext ? osg::getGLExtensionFuncPtr(str1, str2, str3) : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class VertexAttribAlias
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
VertexAttribAlias():
|
||||||
|
_location(0) {}
|
||||||
|
|
||||||
|
VertexAttribAlias(const VertexAttribAlias& rhs):
|
||||||
|
_location(rhs._location),
|
||||||
|
_glName(rhs._glName),
|
||||||
|
_osgName(rhs._osgName),
|
||||||
|
_declaration(rhs._declaration) {}
|
||||||
|
|
||||||
|
VertexAttribAlias(GLuint location, const std::string glName, const std::string osgName, const std::string& declaration):
|
||||||
|
_location(location),
|
||||||
|
_glName(glName),
|
||||||
|
_osgName(osgName),
|
||||||
|
_declaration(declaration) {}
|
||||||
|
|
||||||
|
GLuint _location;
|
||||||
|
std::string _glName;
|
||||||
|
std::string _osgName;
|
||||||
|
std::string _declaration;
|
||||||
|
};
|
||||||
|
|
||||||
/** Main GLExtensions class for managing OpenGL extensions per graphics context.*/
|
/** Main GLExtensions class for managing OpenGL extensions per graphics context.*/
|
||||||
class OSG_EXPORT GLExtensions : public osg::Referenced
|
class OSG_EXPORT GLExtensions : public osg::Referenced
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
GLExtensions(unsigned int contextID);
|
GLExtensions(unsigned int in_contextID);
|
||||||
|
|
||||||
/** Function to call to get the extension of a specified context.
|
/** Function to call to get the extension of a specified context.
|
||||||
* If the Exentsion object for that context has not yet been created then
|
* If the Exentsion object for that context has not yet been created then
|
||||||
@ -135,12 +167,12 @@ class OSG_EXPORT GLExtensions : public osg::Referenced
|
|||||||
* If 'createIfNotInitalized' is true then the Extensions object is
|
* If 'createIfNotInitalized' is true then the Extensions object is
|
||||||
* automatically created. However, in this case the extension object
|
* automatically created. However, in this case the extension object
|
||||||
* only be created with the graphics context associated with ContextID..*/
|
* only be created with the graphics context associated with ContextID..*/
|
||||||
static GLExtensions* Get(unsigned int contextID,bool createIfNotInitalized);
|
static GLExtensions* Get(unsigned int in_contextID,bool createIfNotInitalized);
|
||||||
|
|
||||||
/** allows users to override the extensions across graphics contexts.
|
/** allows users to override the extensions across graphics contexts.
|
||||||
* typically used when you have different extensions supported across graphics pipes
|
* typically used when you have different extensions supported across graphics pipes
|
||||||
* but need to ensure that they all use the same low common denominator extensions.*/
|
* but need to ensure that they all use the same low common denominator extensions.*/
|
||||||
static void Set(unsigned int contextID, GLExtensions* extensions);
|
static void Set(unsigned int in_contextID, GLExtensions* extensions);
|
||||||
|
|
||||||
// C++-friendly convenience wrapper methods
|
// C++-friendly convenience wrapper methods
|
||||||
GLuint getCurrentProgram() const;
|
GLuint getCurrentProgram() const;
|
||||||
@ -149,6 +181,7 @@ class OSG_EXPORT GLExtensions : public osg::Referenced
|
|||||||
bool getAttribLocation( const char* attribName, GLuint& slot ) const;
|
bool getAttribLocation( const char* attribName, GLuint& slot ) const;
|
||||||
bool getFragDataLocation( const char* fragDataName, GLuint& slot) const;
|
bool getFragDataLocation( const char* fragDataName, GLuint& slot) const;
|
||||||
|
|
||||||
|
unsigned int contextID;
|
||||||
|
|
||||||
float glVersion;
|
float glVersion;
|
||||||
float glslLanguageVersion;
|
float glslLanguageVersion;
|
||||||
@ -260,8 +293,11 @@ class OSG_EXPORT GLExtensions : public osg::Referenced
|
|||||||
void (GL_APIENTRY * glVertexAttrib4ubv)(GLuint index, const GLubyte *v);
|
void (GL_APIENTRY * glVertexAttrib4ubv)(GLuint index, const GLubyte *v);
|
||||||
void (GL_APIENTRY * glVertexAttrib4uiv)(GLuint index, const GLuint *v);
|
void (GL_APIENTRY * glVertexAttrib4uiv)(GLuint index, const GLuint *v);
|
||||||
void (GL_APIENTRY * glVertexAttrib4usv)(GLuint index, const GLushort *v);
|
void (GL_APIENTRY * glVertexAttrib4usv)(GLuint index, const GLushort *v);
|
||||||
void (GL_APIENTRY * glVertexAttribPointer)(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid *pointer);
|
void (GL_APIENTRY * glVertexAttribPointer) (unsigned int, GLint, GLenum, GLboolean normalized, GLsizei stride, const GLvoid *pointer);
|
||||||
|
void (GL_APIENTRY * glVertexAttribIPointer) (unsigned int, GLint, GLenum, GLsizei stride, const GLvoid *pointer);
|
||||||
|
void (GL_APIENTRY * glVertexAttribLPointer) (unsigned int, GLint, GLenum, GLsizei stride, const GLvoid *pointer);
|
||||||
void (GL_APIENTRY * glVertexAttribDivisor)(GLuint index, GLuint divisor);
|
void (GL_APIENTRY * glVertexAttribDivisor)(GLuint index, GLuint divisor);
|
||||||
|
|
||||||
void (GL_APIENTRY * glUniformMatrix2x3fv)( GLint location, GLsizei count, GLboolean transpose, const GLfloat* value );
|
void (GL_APIENTRY * glUniformMatrix2x3fv)( GLint location, GLsizei count, GLboolean transpose, const GLfloat* value );
|
||||||
void (GL_APIENTRY * glUniformMatrix3x2fv)( GLint location, GLsizei count, GLboolean transpose, const GLfloat* value );
|
void (GL_APIENTRY * glUniformMatrix3x2fv)( GLint location, GLsizei count, GLboolean transpose, const GLfloat* value );
|
||||||
void (GL_APIENTRY * glUniformMatrix2x4fv)( GLint location, GLsizei count, GLboolean transpose, const GLfloat* value );
|
void (GL_APIENTRY * glUniformMatrix2x4fv)( GLint location, GLsizei count, GLboolean transpose, const GLfloat* value );
|
||||||
@ -313,8 +349,10 @@ class OSG_EXPORT GLExtensions : public osg::Referenced
|
|||||||
void (GL_APIENTRY * glGetActiveAtomicCounterBufferiv)( GLuint program, GLuint bufferIndex, GLenum pname, GLint* params );
|
void (GL_APIENTRY * glGetActiveAtomicCounterBufferiv)( GLuint program, GLuint bufferIndex, GLenum pname, GLint* params );
|
||||||
void (GL_APIENTRY * glDispatchCompute)( GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ );
|
void (GL_APIENTRY * glDispatchCompute)( GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ );
|
||||||
|
|
||||||
|
|
||||||
// Buffer Object extensions
|
// Buffer Object extensions
|
||||||
bool isBufferObjectSupported;
|
bool isBufferObjectSupported;
|
||||||
|
bool isVBOSupported;
|
||||||
bool isPBOSupported;
|
bool isPBOSupported;
|
||||||
bool isTBOSupported;
|
bool isTBOSupported;
|
||||||
bool isVAOSupported;
|
bool isVAOSupported;
|
||||||
@ -355,12 +393,19 @@ class OSG_EXPORT GLExtensions : public osg::Referenced
|
|||||||
bool isTimerQuerySupported;
|
bool isTimerQuerySupported;
|
||||||
bool isARBTimerQuerySupported;
|
bool isARBTimerQuerySupported;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void (GL_APIENTRY * glDrawArraysInstanced)( GLenum mode, GLint first, GLsizei count, GLsizei primcount );
|
||||||
|
void (GL_APIENTRY * glDrawElementsInstanced)( GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei primcount );
|
||||||
|
|
||||||
void (GL_APIENTRY * glSecondaryColor3ubv) (const GLubyte* coord);
|
void (GL_APIENTRY * glSecondaryColor3ubv) (const GLubyte* coord);
|
||||||
void (GL_APIENTRY * glSecondaryColor3fv) (const GLfloat* coord);
|
void (GL_APIENTRY * glSecondaryColor3fv) (const GLfloat* coord);
|
||||||
|
|
||||||
void (GL_APIENTRY * glFogCoordfv) (const GLfloat* coord);
|
void (GL_APIENTRY * glFogCoordfv) (const GLfloat* coord);
|
||||||
|
|
||||||
void (GL_APIENTRY * glMultiTexCoord1f) (GLenum target,GLfloat coord);
|
void (GL_APIENTRY * glMultiTexCoord1f) (GLenum target,GLfloat coord);
|
||||||
|
void (GL_APIENTRY * glMultiTexCoord4f) (GLenum target, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
|
||||||
|
|
||||||
void (GL_APIENTRY * glMultiTexCoord1fv) (GLenum target,const GLfloat* coord);
|
void (GL_APIENTRY * glMultiTexCoord1fv) (GLenum target,const GLfloat* coord);
|
||||||
void (GL_APIENTRY * glMultiTexCoord2fv) (GLenum target,const GLfloat* coord);
|
void (GL_APIENTRY * glMultiTexCoord2fv) (GLenum target,const GLfloat* coord);
|
||||||
void (GL_APIENTRY * glMultiTexCoord3fv) (GLenum target,const GLfloat* coord);
|
void (GL_APIENTRY * glMultiTexCoord3fv) (GLenum target,const GLfloat* coord);
|
||||||
@ -645,6 +690,67 @@ class OSG_EXPORT GLExtensions : public osg::Referenced
|
|||||||
void (GL_APIENTRY * glEnableIndexedEXT) (GLenum target, GLuint index);
|
void (GL_APIENTRY * glEnableIndexedEXT) (GLenum target, GLuint index);
|
||||||
void (GL_APIENTRY * glDisableIndexedEXT) (GLenum target, GLuint index);
|
void (GL_APIENTRY * glDisableIndexedEXT) (GLenum target, GLuint index);
|
||||||
GLboolean (GL_APIENTRY * glIsEnabledIndexedEXT) (GLenum target, GLuint index);
|
GLboolean (GL_APIENTRY * glIsEnabledIndexedEXT) (GLenum target, GLuint index);
|
||||||
|
|
||||||
|
void (GL_APIENTRY * glClientActiveTexture) (GLenum texture);
|
||||||
|
void (GL_APIENTRY * glActiveTexture) (GLenum texture);
|
||||||
|
void (GL_APIENTRY * glFogCoordPointer) (GLenum type, GLsizei stride, const GLvoid *pointer);
|
||||||
|
void (GL_APIENTRY * glSecondaryColorPointer) (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer);
|
||||||
|
|
||||||
|
GLint glMaxTextureCoords;
|
||||||
|
GLint glMaxTextureUnits;
|
||||||
|
public:
|
||||||
|
|
||||||
|
|
||||||
|
void setUseVertexAttributeAliasing(bool flag) { _useVertexAttributeAliasing = flag; }
|
||||||
|
bool getUseVertexAttributeAliasing() const { return _useVertexAttributeAliasing ; }
|
||||||
|
|
||||||
|
typedef std::vector<VertexAttribAlias> VertexAttribAliasList;
|
||||||
|
typedef std::map<std::string,GLuint> AttribBindingList;
|
||||||
|
|
||||||
|
void setUpVertexAttribAlias(VertexAttribAlias& alias, GLuint location, const std::string glName, const std::string osgName, const std::string& declaration);
|
||||||
|
|
||||||
|
/** Reset the vertex attribute aliasing to osg's default. This method needs to be called before render anything unless you really know what you're doing !*/
|
||||||
|
void resetVertexAttributeAlias(bool compactAliasing=true, unsigned int numTextureUnits=8);
|
||||||
|
|
||||||
|
/** Set the vertex attribute aliasing for "vertex". This method needs to be called before render anything unless you really know what you're doing !*/
|
||||||
|
void setVertexAlias(const VertexAttribAlias& alias) { _vertexAlias = alias; }
|
||||||
|
const VertexAttribAlias& getVertexAlias() { return _vertexAlias; }
|
||||||
|
|
||||||
|
/** Set the vertex attribute aliasing for "normal". This method needs to be called before render anything unless you really know what you're doing !*/
|
||||||
|
void setNormalAlias(const VertexAttribAlias& alias) { _normalAlias = alias; }
|
||||||
|
const VertexAttribAlias& getNormalAlias() { return _normalAlias; }
|
||||||
|
|
||||||
|
/** Set the vertex attribute aliasing for "color". This method needs to be called before render anything unless you really know what you're doing !*/
|
||||||
|
void setColorAlias(const VertexAttribAlias& alias) { _colorAlias = alias; }
|
||||||
|
const VertexAttribAlias& getColorAlias() { return _colorAlias; }
|
||||||
|
|
||||||
|
/** Set the vertex attribute aliasing for "secondary color". This method needs to be called before render anything unless you really know what you're doing !*/
|
||||||
|
void setSecondaryColorAlias(const VertexAttribAlias& alias) { _secondaryColorAlias = alias; }
|
||||||
|
const VertexAttribAlias& getSecondaryColorAlias() { return _secondaryColorAlias; }
|
||||||
|
|
||||||
|
/** Set the vertex attribute aliasing for "fog coord". This method needs to be called before render anything unless you really know what you're doing !*/
|
||||||
|
void setFogCoordAlias(const VertexAttribAlias& alias) { _fogCoordAlias = alias; }
|
||||||
|
const VertexAttribAlias& getFogCoordAlias() { return _fogCoordAlias; }
|
||||||
|
|
||||||
|
/** Set the vertex attribute aliasing list for texture coordinates. This method needs to be called before render anything unless you really know what you're doing !*/
|
||||||
|
void setTexCoordAliasList(const VertexAttribAliasList& aliasList) { _texCoordAliasList = aliasList; }
|
||||||
|
const VertexAttribAliasList& getTexCoordAliasList() { return _texCoordAliasList; }
|
||||||
|
|
||||||
|
/** Set the vertex attribute binding list. This method needs to be called before render anything unless you really know what you're doing !*/
|
||||||
|
void setAttributeBindingList(const AttribBindingList& attribBindingList) { _attributeBindingList = attribBindingList; }
|
||||||
|
const AttribBindingList& getAttributeBindingList() { return _attributeBindingList; }
|
||||||
|
|
||||||
|
|
||||||
|
bool _useVertexAttributeAliasing;
|
||||||
|
VertexAttribAlias _vertexAlias;
|
||||||
|
VertexAttribAlias _normalAlias;
|
||||||
|
VertexAttribAlias _colorAlias;
|
||||||
|
VertexAttribAlias _secondaryColorAlias;
|
||||||
|
VertexAttribAlias _fogCoordAlias;
|
||||||
|
VertexAttribAliasList _texCoordAliasList;
|
||||||
|
|
||||||
|
AttribBindingList _attributeBindingList;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -176,11 +176,17 @@ class OSG_EXPORT Geometry : public Drawable
|
|||||||
*/
|
*/
|
||||||
virtual void drawImplementation(RenderInfo& renderInfo) const;
|
virtual void drawImplementation(RenderInfo& renderInfo) const;
|
||||||
|
|
||||||
|
|
||||||
/** Set up the vertex arrays for the purpose of rendering, called by drawImplemtation() prior to it calling drawPrimitivesImplementation().*/
|
/** Set up the vertex arrays for the purpose of rendering, called by drawImplemtation() prior to it calling drawPrimitivesImplementation().*/
|
||||||
void drawVertexArraysImplementation(RenderInfo& renderInfo) const;
|
void old_drawVertexArraysImplementation(RenderInfo& renderInfo) const;
|
||||||
|
|
||||||
/** dispatch the primitives to OpenGL, called by drawImplemtation() after calling drawVertexArraysImplementation().*/
|
/** dispatch the primitives to OpenGL, called by drawImplemtation() after calling drawVertexArraysImplementation().*/
|
||||||
void drawPrimitivesImplementation(RenderInfo& renderInfo) const;
|
void old_drawPrimitivesImplementation(RenderInfo& renderInfo) const;
|
||||||
|
|
||||||
|
|
||||||
|
/** Set up the vertex arrays for the purpose of rendering, called by drawImplemtation() prior to it calling drawPrimitivesImplementation().*/
|
||||||
|
void new_drawImplementation(RenderInfo& renderInfo) const;
|
||||||
|
|
||||||
|
|
||||||
/** Return true, osg::Geometry does support accept(Drawable::AttributeFunctor&). */
|
/** Return true, osg::Geometry does support accept(Drawable::AttributeFunctor&). */
|
||||||
virtual bool supports(const Drawable::AttributeFunctor&) const { return true; }
|
virtual bool supports(const Drawable::AttributeFunctor&) const { return true; }
|
||||||
@ -217,6 +223,9 @@ class OSG_EXPORT Geometry : public Drawable
|
|||||||
void addVertexBufferObjectIfRequired(osg::Array* array);
|
void addVertexBufferObjectIfRequired(osg::Array* array);
|
||||||
void addElementBufferObjectIfRequired(osg::PrimitiveSet* primitiveSet);
|
void addElementBufferObjectIfRequired(osg::PrimitiveSet* primitiveSet);
|
||||||
|
|
||||||
|
typedef buffered_object< osg::ref_ptr<VertexArrayState> > VertexArrayStateList;
|
||||||
|
mutable VertexArrayStateList _vertexArrayStateList;
|
||||||
|
|
||||||
|
|
||||||
PrimitiveSetList _primitives;
|
PrimitiveSetList _primitives;
|
||||||
osg::ref_ptr<Array> _vertexArray;
|
osg::ref_ptr<Array> _vertexArray;
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
#include <osg/BufferObject>
|
#include <osg/BufferObject>
|
||||||
#include <osg/Observer>
|
#include <osg/Observer>
|
||||||
#include <osg/Timer>
|
#include <osg/Timer>
|
||||||
|
#include <osg/VertexArrayState>
|
||||||
|
|
||||||
#include <osg/ShaderComposer>
|
#include <osg/ShaderComposer>
|
||||||
#include <osg/FrameStamp>
|
#include <osg/FrameStamp>
|
||||||
@ -72,31 +73,20 @@ namespace osg {
|
|||||||
// forward declare GraphicsContext, View and State
|
// forward declare GraphicsContext, View and State
|
||||||
class GraphicsContext;
|
class GraphicsContext;
|
||||||
|
|
||||||
class VertexAttribAlias
|
struct EnabledArrayPair
|
||||||
{
|
{
|
||||||
public:
|
EnabledArrayPair():_arrayType(0), _lazy_disable(false),_dirty(true),_enabled(false),_normalized(0),_pointer(0) {}
|
||||||
VertexAttribAlias():
|
EnabledArrayPair(const EnabledArrayPair& eap):_arrayType(0), _lazy_disable(eap._lazy_disable),_dirty(eap._dirty), _enabled(eap._enabled),_normalized(eap._normalized),_pointer(eap._pointer) {}
|
||||||
_location(0) {}
|
EnabledArrayPair& operator = (const EnabledArrayPair& eap) { _arrayType = eap._arrayType; _lazy_disable = eap._lazy_disable;_dirty=eap._dirty; _enabled=eap._enabled; _normalized=eap._normalized;_pointer=eap._pointer; return *this; }
|
||||||
|
|
||||||
VertexAttribAlias(const VertexAttribAlias& rhs):
|
GLenum _arrayType;
|
||||||
_location(rhs._location),
|
bool _lazy_disable;
|
||||||
_glName(rhs._glName),
|
bool _dirty;
|
||||||
_osgName(rhs._osgName),
|
bool _enabled;
|
||||||
_declaration(rhs._declaration) {}
|
GLboolean _normalized;
|
||||||
|
const GLvoid* _pointer;
|
||||||
VertexAttribAlias(GLuint location, const std::string glName, const std::string osgName, const std::string& declaration):
|
|
||||||
_location(location),
|
|
||||||
_glName(glName),
|
|
||||||
_osgName(osgName),
|
|
||||||
_declaration(declaration) {}
|
|
||||||
|
|
||||||
GLuint _location;
|
|
||||||
std::string _glName;
|
|
||||||
std::string _osgName;
|
|
||||||
std::string _declaration;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/** Encapsulates the current applied OpenGL modes, attributes and vertex arrays settings,
|
/** Encapsulates the current applied OpenGL modes, attributes and vertex arrays settings,
|
||||||
* implements lazy state updating and provides accessors for querying the current state.
|
* implements lazy state updating and provides accessors for querying the current state.
|
||||||
* The venerable Red Book says that "OpenGL is a state machine", and this class
|
* The venerable Red Book says that "OpenGL is a state machine", and this class
|
||||||
@ -500,12 +490,24 @@ class OSG_EXPORT State : public Referenced
|
|||||||
const StateAttribute* getLastAppliedTextureAttribute(unsigned int unit, StateAttribute::Type type, unsigned int member=0) const;
|
const StateAttribute* getLastAppliedTextureAttribute(unsigned int unit, StateAttribute::Type type, unsigned int member=0) const;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/** Dirty the modes previously applied in osg::State.*/
|
/** Dirty the modes previously applied in osg::State.*/
|
||||||
void dirtyAllModes();
|
void dirtyAllModes();
|
||||||
|
|
||||||
/** Dirty the modes attributes previously applied in osg::State.*/
|
/** Dirty the modes attributes previously applied in osg::State.*/
|
||||||
void dirtyAllAttributes();
|
void dirtyAllAttributes();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/** Set the CurrentVetexArrayState object that take which vertex arrays are bound.*/
|
||||||
|
void setCurrentVertexArrayState(VertexArrayState* vas) { _currentVertexArrayState = vas; }
|
||||||
|
|
||||||
|
/** Get the CurrentVetexArrayState object that take which vertex arrays are bound.*/
|
||||||
|
VertexArrayState* getCurrentVertexArrayState() const { return _currentVertexArrayState.get(); }
|
||||||
|
|
||||||
|
|
||||||
/** disable the vertex, normal, color, tex coords, secondary color, fog coord and index arrays.*/
|
/** disable the vertex, normal, color, tex coords, secondary color, fog coord and index arrays.*/
|
||||||
void disableAllVertexArrays();
|
void disableAllVertexArrays();
|
||||||
|
|
||||||
@ -513,6 +515,8 @@ class OSG_EXPORT State : public Referenced
|
|||||||
void dirtyAllVertexArrays();
|
void dirtyAllVertexArrays();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void setCurrentVertexBufferObject(osg::GLBufferObject* vbo) { _currentVBO = vbo; }
|
void setCurrentVertexBufferObject(osg::GLBufferObject* vbo) { _currentVBO = vbo; }
|
||||||
const GLBufferObject* getCurrentVertexBufferObject() { return _currentVBO; }
|
const GLBufferObject* getCurrentVertexBufferObject() { return _currentVBO; }
|
||||||
inline void bindVertexBufferObject(osg::GLBufferObject* vbo)
|
inline void bindVertexBufferObject(osg::GLBufferObject* vbo)
|
||||||
@ -551,7 +555,7 @@ class OSG_EXPORT State : public Referenced
|
|||||||
|
|
||||||
inline void unbindElementBufferObject()
|
inline void unbindElementBufferObject()
|
||||||
{
|
{
|
||||||
if (!_currentEBO) return;
|
//if (!_currentEBO) return;
|
||||||
_glBindBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB,0);
|
_glBindBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB,0);
|
||||||
_currentEBO = 0;
|
_currentEBO = 0;
|
||||||
}
|
}
|
||||||
@ -1667,6 +1671,8 @@ class OSG_EXPORT State : public Referenced
|
|||||||
GraphicsContext* _graphicsContext;
|
GraphicsContext* _graphicsContext;
|
||||||
unsigned int _contextID;
|
unsigned int _contextID;
|
||||||
|
|
||||||
|
osg::ref_ptr<VertexArrayState> _currentVertexArrayState;
|
||||||
|
|
||||||
bool _shaderCompositionEnabled;
|
bool _shaderCompositionEnabled;
|
||||||
bool _shaderCompositionDirty;
|
bool _shaderCompositionDirty;
|
||||||
osg::ref_ptr<ShaderComposer> _shaderComposer;
|
osg::ref_ptr<ShaderComposer> _shaderComposer;
|
||||||
@ -1706,6 +1712,7 @@ class OSG_EXPORT State : public Referenced
|
|||||||
Program::AttribBindingList _attributeBindingList;
|
Program::AttribBindingList _attributeBindingList;
|
||||||
|
|
||||||
void setUpVertexAttribAlias(VertexAttribAlias& alias, GLuint location, const std::string glName, const std::string osgName, const std::string& declaration);
|
void setUpVertexAttribAlias(VertexAttribAlias& alias, GLuint location, const std::string glName, const std::string osgName, const std::string& declaration);
|
||||||
|
|
||||||
/** Apply an OpenGL mode if required, passing in mode, enable flag and
|
/** Apply an OpenGL mode if required, passing in mode, enable flag and
|
||||||
* appropriate mode stack. This is a wrapper around \c glEnable() and
|
* appropriate mode stack. This is a wrapper around \c glEnable() and
|
||||||
* \c glDisable(), that just actually calls these functions if the
|
* \c glDisable(), that just actually calls these functions if the
|
||||||
|
222
include/osg/VertexArrayState
Normal file
222
include/osg/VertexArrayState
Normal file
@ -0,0 +1,222 @@
|
|||||||
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
||||||
|
*
|
||||||
|
* This library is open source and may be redistributed and/or modified under
|
||||||
|
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
||||||
|
* (at your option) any later version. The full license is in LICENSE file
|
||||||
|
* included with this distribution, and on the openscenegraph.org website.
|
||||||
|
*
|
||||||
|
* This library 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. See the
|
||||||
|
* OpenSceneGraph Public License for more details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef OSG_VertexArrayState
|
||||||
|
#define OSG_VertexArrayState 1
|
||||||
|
|
||||||
|
#include <osg/Referenced>
|
||||||
|
#include <osg/GLExtensions>
|
||||||
|
#include <osg/Array>
|
||||||
|
#include <osg/ArrayDispatchers>
|
||||||
|
|
||||||
|
namespace osg {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class VertexArrayState : public osg::Referenced
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
VertexArrayState(osg::GLExtensions* ext);
|
||||||
|
|
||||||
|
struct ArrayDispatch : public osg::Referenced
|
||||||
|
{
|
||||||
|
ArrayDispatch(Array* in_array):
|
||||||
|
array(in_array),
|
||||||
|
modifiedCount(0xffffffff) {}
|
||||||
|
|
||||||
|
inline void dispatchIfDirty(osg::State& state, unsigned int index=0)
|
||||||
|
{
|
||||||
|
if (modifiedCount!=array->getModifiedCount()) dispatch(state, index);
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void dispatch(osg::State& state, unsigned int index=0) = 0;
|
||||||
|
|
||||||
|
virtual void dispatchDeprecated(osg::State& state, unsigned int index=0);
|
||||||
|
|
||||||
|
osg::Array* array;
|
||||||
|
unsigned int modifiedCount;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef std::vector< ref_ptr<ArrayDispatch> > ArrayDispatchList;
|
||||||
|
|
||||||
|
ArrayDispatchList& getArrayDispatchList(Array::Binding binding)
|
||||||
|
{
|
||||||
|
switch(binding)
|
||||||
|
{
|
||||||
|
case(osg::Array::BIND_PER_VERTEX): return _dispatchArrays;
|
||||||
|
case(osg::Array::BIND_PER_PRIMITIVE_SET): return _dispatchPerPrimitiveSet;
|
||||||
|
default: return _dispatchOverall;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
enum VertexArrayIdentifier
|
||||||
|
{
|
||||||
|
VERTEX_ARRAY,
|
||||||
|
NORMAL_ARRAY,
|
||||||
|
COLOR_ARRAY,
|
||||||
|
SECONDARY_COLOR_ARRAY,
|
||||||
|
FOG_COORD_ARRAY,
|
||||||
|
TEX_COORD_ARRAY,
|
||||||
|
VERTEX_ATTRIB_ARRAY=TEX_COORD_ARRAY+32
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
void assignVertexArray(osg::Array* array);
|
||||||
|
void assignColorArray(osg::Array* array);
|
||||||
|
void assignNormalArray(osg::Array* array);
|
||||||
|
|
||||||
|
void assignSecondaryColorArray(osg::Array* array);
|
||||||
|
void assignFogCoordArray(osg::Array* array);
|
||||||
|
|
||||||
|
void assignTexCoordArray(unsigned int unit, osg::Array* array);
|
||||||
|
void assignVertexAttribArray(unsigned int unit, osg::Array* array);
|
||||||
|
|
||||||
|
inline void dispatchOverall(osg::State& state)
|
||||||
|
{
|
||||||
|
for(ArrayDispatchList::iterator itr = _dispatchOverall.begin();
|
||||||
|
itr != _dispatchOverall.end();
|
||||||
|
++itr)
|
||||||
|
{
|
||||||
|
(*(*itr)).dispatch(state);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void dispatchPerPrimitveSet(osg::State& state, unsigned int index)
|
||||||
|
{
|
||||||
|
for(ArrayDispatchList::iterator itr = _dispatchPerPrimitiveSet.begin();
|
||||||
|
itr != _dispatchPerPrimitiveSet.end();
|
||||||
|
++itr)
|
||||||
|
{
|
||||||
|
(*(*itr)).dispatch(state, index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void dispatchArrays(osg::State& state)
|
||||||
|
{
|
||||||
|
// need to check previous enabled/disabled mode
|
||||||
|
|
||||||
|
if (_vertexArrayObject)
|
||||||
|
{
|
||||||
|
for(ArrayDispatchList::iterator itr = _dispatchArrays.begin();
|
||||||
|
itr != _dispatchArrays.end();
|
||||||
|
++itr)
|
||||||
|
{
|
||||||
|
(*(*itr)).dispatch(state);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for(ArrayDispatchList::iterator itr = _dispatchArrays.begin();
|
||||||
|
itr != _dispatchArrays.end();
|
||||||
|
++itr)
|
||||||
|
{
|
||||||
|
(*(*itr)).dispatchDeprecated(state);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void dispatchArraysIfDirty(osg::State& state)
|
||||||
|
{
|
||||||
|
// need to check previous enabled/disabled mode
|
||||||
|
|
||||||
|
for(ArrayDispatchList::iterator itr = _dispatchArrays.begin();
|
||||||
|
itr != _dispatchArrays.end();
|
||||||
|
++itr)
|
||||||
|
{
|
||||||
|
(*(*itr)).dispatchIfDirty(state);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Verex Array Object methods.
|
||||||
|
void generateVretexArrayObject();
|
||||||
|
|
||||||
|
void bindVertexArrayObject() const;
|
||||||
|
|
||||||
|
void unbindVertexArrayObject() const;
|
||||||
|
|
||||||
|
GLint getVertexArrayObject() const { return _vertexArrayObject; }
|
||||||
|
|
||||||
|
void releaseGLObjects();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void setCurrentVertexBufferObject(osg::GLBufferObject* vbo) { _currentVBO = vbo; }
|
||||||
|
const GLBufferObject* getCurrentVertexBufferObject() { return _currentVBO; }
|
||||||
|
inline void bindVertexBufferObject(osg::GLBufferObject* vbo)
|
||||||
|
{
|
||||||
|
if (vbo)
|
||||||
|
{
|
||||||
|
if (vbo == _currentVBO) return;
|
||||||
|
if (vbo->isDirty()) vbo->compileBuffer();
|
||||||
|
else vbo->bindBuffer();
|
||||||
|
_currentVBO = vbo;
|
||||||
|
}
|
||||||
|
else unbindVertexBufferObject();
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void unbindVertexBufferObject()
|
||||||
|
{
|
||||||
|
if (!_currentVBO) return;
|
||||||
|
_ext->glBindBuffer(GL_ARRAY_BUFFER_ARB,0);
|
||||||
|
_currentVBO = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void setCurrentElementBufferObject(osg::GLBufferObject* ebo) { _currentEBO = ebo; }
|
||||||
|
const GLBufferObject* getCurrentElementBufferObject() { return _currentEBO; }
|
||||||
|
|
||||||
|
inline void bindElementBufferObject(osg::GLBufferObject* ebo)
|
||||||
|
{
|
||||||
|
if (ebo)
|
||||||
|
{
|
||||||
|
if (ebo == _currentEBO) return;
|
||||||
|
if (ebo->isDirty()) ebo->compileBuffer();
|
||||||
|
else ebo->bindBuffer();
|
||||||
|
_currentEBO = ebo;
|
||||||
|
}
|
||||||
|
else unbindElementBufferObject();
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void unbindElementBufferObject()
|
||||||
|
{
|
||||||
|
if (!_currentEBO) return;
|
||||||
|
_ext->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB,0);
|
||||||
|
_currentEBO = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
|
||||||
|
osg::GLBufferObject* getGLBufferObject(osg::Array* array);
|
||||||
|
|
||||||
|
osg::ref_ptr<osg::GLExtensions> _ext;
|
||||||
|
|
||||||
|
GLuint _vertexArrayObject;
|
||||||
|
|
||||||
|
GLBufferObject* _currentVBO;
|
||||||
|
GLBufferObject* _currentEBO;
|
||||||
|
|
||||||
|
ArrayDispatchList _dispatchOverall;
|
||||||
|
ArrayDispatchList _dispatchPerPrimitiveSet;
|
||||||
|
ArrayDispatchList _dispatchArrays;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
@ -221,6 +221,7 @@ SET(TARGET_H
|
|||||||
${HEADER_PATH}/Vec4ui
|
${HEADER_PATH}/Vec4ui
|
||||||
${HEADER_PATH}/Vec4us
|
${HEADER_PATH}/Vec4us
|
||||||
${HEADER_PATH}/VertexAttribDivisor
|
${HEADER_PATH}/VertexAttribDivisor
|
||||||
|
${HEADER_PATH}/VertexArrayState
|
||||||
${HEADER_PATH}/VertexProgram
|
${HEADER_PATH}/VertexProgram
|
||||||
${HEADER_PATH}/View
|
${HEADER_PATH}/View
|
||||||
${HEADER_PATH}/Viewport
|
${HEADER_PATH}/Viewport
|
||||||
@ -390,6 +391,7 @@ SET(TARGET_SRC
|
|||||||
ValueStack.cpp
|
ValueStack.cpp
|
||||||
Version.cpp
|
Version.cpp
|
||||||
VertexAttribDivisor.cpp
|
VertexAttribDivisor.cpp
|
||||||
|
VertexArrayState.cpp
|
||||||
VertexProgram.cpp
|
VertexProgram.cpp
|
||||||
View.cpp
|
View.cpp
|
||||||
Viewport.cpp
|
Viewport.cpp
|
||||||
|
@ -116,6 +116,8 @@ void DisplaySettings::setDisplaySettings(const DisplaySettings& vs)
|
|||||||
_glContextProfileMask = vs._glContextProfileMask;
|
_glContextProfileMask = vs._glContextProfileMask;
|
||||||
_swapMethod = vs._swapMethod;
|
_swapMethod = vs._swapMethod;
|
||||||
|
|
||||||
|
_geometryImplementation = vs._geometryImplementation;
|
||||||
|
|
||||||
_keystoneHint = vs._keystoneHint;
|
_keystoneHint = vs._keystoneHint;
|
||||||
_keystoneFileNames = vs._keystoneFileNames;
|
_keystoneFileNames = vs._keystoneFileNames;
|
||||||
_keystones = vs._keystones;
|
_keystones = vs._keystones;
|
||||||
@ -241,6 +243,8 @@ void DisplaySettings::setDefaults()
|
|||||||
_swapMethod = SWAP_DEFAULT;
|
_swapMethod = SWAP_DEFAULT;
|
||||||
_syncSwapBuffers = 0;
|
_syncSwapBuffers = 0;
|
||||||
|
|
||||||
|
_geometryImplementation = VERTEX_ARRAY_OBJECT;
|
||||||
|
|
||||||
_keystoneHint = false;
|
_keystoneHint = false;
|
||||||
|
|
||||||
_OSXMenubarBehavior = MENUBAR_AUTO_HIDE;
|
_OSXMenubarBehavior = MENUBAR_AUTO_HIDE;
|
||||||
@ -361,6 +365,9 @@ static ApplicationUsageProxy DisplaySetting_e30(ApplicationUsage::ENVIRONMENTAL_
|
|||||||
static ApplicationUsageProxy DisplaySetting_e31(ApplicationUsage::ENVIRONMENTAL_VARIABLE,
|
static ApplicationUsageProxy DisplaySetting_e31(ApplicationUsage::ENVIRONMENTAL_VARIABLE,
|
||||||
"OSG_NvOptimusEnablement <value>",
|
"OSG_NvOptimusEnablement <value>",
|
||||||
"Set the hint to NvOptimus of whether to enable it or not, set 1 to enable, 0 to disable");
|
"Set the hint to NvOptimus of whether to enable it or not, set 1 to enable, 0 to disable");
|
||||||
|
static ApplicationUsageProxy DisplaySetting_e32(ApplicationUsage::ENVIRONMENTAL_VARIABLE,
|
||||||
|
"OSG_GEOMETRY_IMPLEMENTATION <value>",
|
||||||
|
"Set the hint to what backend osg::Geometry implementation to use. OLD | NEW | VERTEX_ARRAY_OBJECT");
|
||||||
|
|
||||||
void DisplaySettings::readEnvironmentalVariables()
|
void DisplaySettings::readEnvironmentalVariables()
|
||||||
{
|
{
|
||||||
@ -671,6 +678,24 @@ void DisplaySettings::readEnvironmentalVariables()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if ((ptr = getenv("OSG_GEOMETRY_IMPLEMENTATION")) != 0)
|
||||||
|
{
|
||||||
|
if (strcmp(ptr,"OLD")==0)
|
||||||
|
{
|
||||||
|
_geometryImplementation = OLD_GEOMETRY_IMPLEMENTATION;
|
||||||
|
}
|
||||||
|
else if (strcmp(ptr,"NEW")==0 )
|
||||||
|
{
|
||||||
|
_geometryImplementation = NEW_GEOMETRY_IMPLEMENTATION;
|
||||||
|
}
|
||||||
|
else if (strcmp(ptr,"VERTEX_ARRAY_OBJECT")==0 || strcmp(ptr,"VAO")==0)
|
||||||
|
{
|
||||||
|
_geometryImplementation = VERTEX_ARRAY_OBJECT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if( (ptr = getenv("OSG_KEYSTONE")) != 0)
|
if( (ptr = getenv("OSG_KEYSTONE")) != 0)
|
||||||
{
|
{
|
||||||
if (strcmp(ptr,"OFF")==0)
|
if (strcmp(ptr,"OFF")==0)
|
||||||
|
@ -226,9 +226,14 @@ Drawable::Drawable()
|
|||||||
_useDisplayList = false;
|
_useDisplayList = false;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if 0
|
||||||
_supportsVertexBufferObjects = false;
|
_supportsVertexBufferObjects = false;
|
||||||
|
//_useVertexBufferObjects = false;
|
||||||
_useVertexBufferObjects = false;
|
_useVertexBufferObjects = false;
|
||||||
// _useVertexBufferObjects = true;
|
#else
|
||||||
|
_supportsVertexBufferObjects = true;
|
||||||
|
_useVertexBufferObjects = false;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
Drawable::Drawable(const Drawable& drawable,const CopyOp& copyop):
|
Drawable::Drawable(const Drawable& drawable,const CopyOp& copyop):
|
||||||
|
@ -246,6 +246,8 @@ void GLBeginEndAdapter::End()
|
|||||||
}
|
}
|
||||||
|
|
||||||
_state->lazyDisablingOfVertexAttributes();
|
_state->lazyDisablingOfVertexAttributes();
|
||||||
|
_state->unbindVertexBufferObject();
|
||||||
|
_state->unbindElementBufferObject();
|
||||||
|
|
||||||
if (_colorAssigned)
|
if (_colorAssigned)
|
||||||
{
|
{
|
||||||
@ -286,6 +288,8 @@ void GLBeginEndAdapter::End()
|
|||||||
|
|
||||||
_state->applyDisablingOfVertexAttributes();
|
_state->applyDisablingOfVertexAttributes();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (_primitiveMode==GL_QUADS)
|
if (_primitiveMode==GL_QUADS)
|
||||||
{
|
{
|
||||||
_state->drawQuads(0, _vertices->size());
|
_state->drawQuads(0, _vertices->size());
|
||||||
|
@ -22,8 +22,8 @@
|
|||||||
#include <float.h>
|
#include <float.h>
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
|
||||||
#include <set>
|
#include <set>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
#if defined(WIN32)
|
#if defined(WIN32)
|
||||||
#ifndef WIN32_LEAN_AND_MEAN
|
#ifndef WIN32_LEAN_AND_MEAN
|
||||||
@ -92,6 +92,12 @@ bool osg::isGLExtensionSupported(unsigned int contextID, const char *extension)
|
|||||||
return osg::isGLExtensionOrVersionSupported(contextID, extension, FLT_MAX);
|
return osg::isGLExtensionOrVersionSupported(contextID, extension, FLT_MAX);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool osg::isGLExtensionSupported(unsigned int contextID, const char *extension1, const char *extension2)
|
||||||
|
{
|
||||||
|
return osg::isGLExtensionOrVersionSupported(contextID, extension1, FLT_MAX) ||
|
||||||
|
osg::isGLExtensionOrVersionSupported(contextID, extension2, FLT_MAX);
|
||||||
|
}
|
||||||
|
|
||||||
bool osg::isGLExtensionOrVersionSupported(unsigned int contextID, const char *extension, float requiredGLVersion)
|
bool osg::isGLExtensionOrVersionSupported(unsigned int contextID, const char *extension, float requiredGLVersion)
|
||||||
{
|
{
|
||||||
ExtensionSet& extensionSet = s_glExtensionSetList[contextID];
|
ExtensionSet& extensionSet = s_glExtensionSetList[contextID];
|
||||||
@ -415,23 +421,24 @@ OSG_INIT_SINGLETON_PROXY(GLExtensionDisableStringInitializationProxy, osg::getGL
|
|||||||
typedef osg::buffered_object< osg::ref_ptr<GLExtensions> > BufferedExtensions;
|
typedef osg::buffered_object< osg::ref_ptr<GLExtensions> > BufferedExtensions;
|
||||||
static BufferedExtensions s_extensions;
|
static BufferedExtensions s_extensions;
|
||||||
|
|
||||||
GLExtensions* GLExtensions::Get(unsigned int contextID, bool createIfNotInitalized)
|
GLExtensions* GLExtensions::Get(unsigned int in_contextID, bool createIfNotInitalized)
|
||||||
{
|
{
|
||||||
if (!s_extensions[contextID] && createIfNotInitalized)
|
if (!s_extensions[in_contextID] && createIfNotInitalized)
|
||||||
s_extensions[contextID] = new GLExtensions(contextID);
|
s_extensions[in_contextID] = new GLExtensions(in_contextID);
|
||||||
|
|
||||||
return s_extensions[contextID].get();
|
return s_extensions[in_contextID].get();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLExtensions::Set(unsigned int contextID, GLExtensions* extensions)
|
void GLExtensions::Set(unsigned int in_contextID, GLExtensions* extensions)
|
||||||
{
|
{
|
||||||
s_extensions[contextID] = extensions;
|
s_extensions[in_contextID] = extensions;
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
// Extension function pointers for OpenGL v2.x
|
// Extension function pointers for OpenGL v2.x
|
||||||
|
|
||||||
GLExtensions::GLExtensions(unsigned int contextID)
|
GLExtensions::GLExtensions(unsigned int in_contextID):
|
||||||
|
contextID(in_contextID)
|
||||||
{
|
{
|
||||||
const char* versionString = (const char*) glGetString( GL_VERSION );
|
const char* versionString = (const char*) glGetString( GL_VERSION );
|
||||||
bool validContext = versionString!=0;
|
bool validContext = versionString!=0;
|
||||||
@ -589,7 +596,9 @@ GLExtensions::GLExtensions(unsigned int contextID)
|
|||||||
setGLExtensionFuncPtr(glVertexAttrib4ubv, "glVertexAttrib4ubv", validContext);
|
setGLExtensionFuncPtr(glVertexAttrib4ubv, "glVertexAttrib4ubv", validContext);
|
||||||
setGLExtensionFuncPtr(glVertexAttrib4uiv, "glVertexAttrib4uiv", validContext);
|
setGLExtensionFuncPtr(glVertexAttrib4uiv, "glVertexAttrib4uiv", validContext);
|
||||||
setGLExtensionFuncPtr(glVertexAttrib4usv, "glVertexAttrib4usv", validContext);
|
setGLExtensionFuncPtr(glVertexAttrib4usv, "glVertexAttrib4usv", validContext);
|
||||||
setGLExtensionFuncPtr(glVertexAttribPointer, "glVertexAttribPointer", validContext);
|
setGLExtensionFuncPtr(glVertexAttribPointer, "glVertexAttribPointer","glVertexAttribPointerARB", validContext);
|
||||||
|
setGLExtensionFuncPtr(glVertexAttribIPointer, "glVertexAttribIPointer","glVertexAttribIPointerARB", validContext);
|
||||||
|
setGLExtensionFuncPtr(glVertexAttribLPointer, "glVertexAttribLPointer","glVertexAttribPointerARB", validContext);
|
||||||
setGLExtensionFuncPtr(glVertexAttribDivisor, "glVertexAttribDivisor", validContext);
|
setGLExtensionFuncPtr(glVertexAttribDivisor, "glVertexAttribDivisor", validContext);
|
||||||
|
|
||||||
// v1.5-only ARB entry points, in case they're needed for fallback
|
// v1.5-only ARB entry points, in case they're needed for fallback
|
||||||
@ -666,6 +675,7 @@ GLExtensions::GLExtensions(unsigned int contextID)
|
|||||||
// ARB_compute_shader
|
// ARB_compute_shader
|
||||||
setGLExtensionFuncPtr(glDispatchCompute, "glDispatchCompute" , validContext);
|
setGLExtensionFuncPtr(glDispatchCompute, "glDispatchCompute" , validContext);
|
||||||
|
|
||||||
|
|
||||||
setGLExtensionFuncPtr(glMemoryBarrier, "glMemoryBarrier", "glMemoryBarrierEXT" , validContext);
|
setGLExtensionFuncPtr(glMemoryBarrier, "glMemoryBarrier", "glMemoryBarrierEXT" , validContext);
|
||||||
|
|
||||||
// BufferObject extensions
|
// BufferObject extensions
|
||||||
@ -685,12 +695,13 @@ GLExtensions::GLExtensions(unsigned int contextID)
|
|||||||
setGLExtensionFuncPtr(glBindBufferBase, "glBindBufferBase", "glBindBufferBaseEXT", "glBindBufferBaseNV" , validContext);
|
setGLExtensionFuncPtr(glBindBufferBase, "glBindBufferBase", "glBindBufferBaseEXT", "glBindBufferBaseNV" , validContext);
|
||||||
setGLExtensionFuncPtr(glTexBuffer, "glTexBuffer","glTexBufferARB" , validContext);
|
setGLExtensionFuncPtr(glTexBuffer, "glTexBuffer","glTexBufferARB" , validContext);
|
||||||
|
|
||||||
isPBOSupported = validContext && (OSG_GL3_FEATURES || osg::isGLExtensionSupported(contextID,"GL_ARB_pixel_buffer_object"));
|
isVBOSupported = validContext && (OSG_GLES2_FEATURES || OSG_GL3_FEATURES || osg::isGLExtensionSupported(contextID,"GL_ARB_vertex_buffer_object"));
|
||||||
|
isPBOSupported = validContext && (OSG_GLES2_FEATURES || OSG_GL3_FEATURES || osg::isGLExtensionSupported(contextID,"GL_ARB_pixel_buffer_object"));
|
||||||
isUniformBufferObjectSupported = validContext && osg::isGLExtensionSupported(contextID, "GL_ARB_uniform_buffer_object");
|
isUniformBufferObjectSupported = validContext && osg::isGLExtensionSupported(contextID, "GL_ARB_uniform_buffer_object");
|
||||||
isTBOSupported = validContext && osg::isGLExtensionSupported(contextID,"GL_ARB_texture_buffer_object");
|
isTBOSupported = validContext && osg::isGLExtensionSupported(contextID,"GL_ARB_texture_buffer_object");
|
||||||
isVAOSupported = validContext && osg::isGLExtensionSupported(contextID, "GL_ARB_vertex_array_object");
|
isVAOSupported = validContext && (OSG_GL3_FEATURES || osg::isGLExtensionSupported(contextID, "GL_ARB_vertex_array_object", "GL_OES_vertex_array_object"));
|
||||||
isTransformFeedbackSupported = validContext && osg::isGLExtensionSupported(contextID, "GL_ARB_transform_feedback2");
|
isTransformFeedbackSupported = validContext && osg::isGLExtensionSupported(contextID, "GL_ARB_transform_feedback2");
|
||||||
isBufferObjectSupported = isPBOSupported && isVAOSupported;
|
isBufferObjectSupported = isVBOSupported && isPBOSupported;
|
||||||
|
|
||||||
|
|
||||||
// BlendFunc extensions
|
// BlendFunc extensions
|
||||||
@ -715,14 +726,24 @@ GLExtensions::GLExtensions(unsigned int contextID)
|
|||||||
isTimerQuerySupported = validContext && osg::isGLExtensionSupported(contextID, "GL_EXT_timer_query");
|
isTimerQuerySupported = validContext && osg::isGLExtensionSupported(contextID, "GL_EXT_timer_query");
|
||||||
isARBTimerQuerySupported = validContext && osg::isGLExtensionSupported(contextID, "GL_ARB_timer_query");
|
isARBTimerQuerySupported = validContext && osg::isGLExtensionSupported(contextID, "GL_ARB_timer_query");
|
||||||
|
|
||||||
|
|
||||||
|
setGLExtensionFuncPtr(glDrawArraysInstanced, "glDrawArraysInstanced","glDrawArraysInstancedARB","glDrawArraysInstancedEXT", validContext);
|
||||||
|
setGLExtensionFuncPtr(glDrawElementsInstanced, "glDrawElementsInstanced","glDrawElementsInstancedARB","glDrawElementsInstancedEXT", validContext);
|
||||||
|
|
||||||
|
|
||||||
setGLExtensionFuncPtr(glFogCoordfv, "glFogCoordfv","glFogCoordfvEXT", validContext);
|
setGLExtensionFuncPtr(glFogCoordfv, "glFogCoordfv","glFogCoordfvEXT", validContext);
|
||||||
setGLExtensionFuncPtr(glSecondaryColor3ubv, "glSecondaryColor3ubv","glSecondaryColor3ubvEXT", validContext);
|
setGLExtensionFuncPtr(glSecondaryColor3ubv, "glSecondaryColor3ubv","glSecondaryColor3ubvEXT", validContext);
|
||||||
setGLExtensionFuncPtr(glSecondaryColor3fv, "glSecondaryColor3fv","glSecondaryColor3fvEXT", validContext);
|
setGLExtensionFuncPtr(glSecondaryColor3fv, "glSecondaryColor3fv","glSecondaryColor3fvEXT", validContext);
|
||||||
|
|
||||||
setGLExtensionFuncPtr(glMultiTexCoord1f, "glMultiTexCoord1f","glMultiTexCoord1fARB", validContext);
|
setGLExtensionFuncPtr(glMultiTexCoord1f, "glMultiTexCoord1f","glMultiTexCoord1fARB", validContext);
|
||||||
|
setGLExtensionFuncPtr(glMultiTexCoord4f, "glMultiTexCoord4f","glMultiTexCoord4fARB", validContext);
|
||||||
|
|
||||||
setGLExtensionFuncPtr(glMultiTexCoord1fv, "glMultiTexCoord1fv","glMultiTexCoord1fvARB", validContext);
|
setGLExtensionFuncPtr(glMultiTexCoord1fv, "glMultiTexCoord1fv","glMultiTexCoord1fvARB", validContext);
|
||||||
setGLExtensionFuncPtr(glMultiTexCoord2fv, "glMultiTexCoord2fv","glMultiTexCoord2fvARB", validContext);
|
setGLExtensionFuncPtr(glMultiTexCoord2fv, "glMultiTexCoord2fv","glMultiTexCoord2fvARB", validContext);
|
||||||
setGLExtensionFuncPtr(glMultiTexCoord3fv, "glMultiTexCoord3fv","glMultiTexCoord3fvARB", validContext);
|
setGLExtensionFuncPtr(glMultiTexCoord3fv, "glMultiTexCoord3fv","glMultiTexCoord3fvARB", validContext);
|
||||||
setGLExtensionFuncPtr(glMultiTexCoord4fv, "glMultiTexCoord4fv","glMultiTexCoord4fvARB", validContext);
|
setGLExtensionFuncPtr(glMultiTexCoord4fv, "glMultiTexCoord4fv","glMultiTexCoord4fvARB", validContext);
|
||||||
|
|
||||||
|
|
||||||
setGLExtensionFuncPtr(glMultiTexCoord1d, "glMultiTexCoord1d","glMultiTexCoorddfARB", validContext);
|
setGLExtensionFuncPtr(glMultiTexCoord1d, "glMultiTexCoord1d","glMultiTexCoorddfARB", validContext);
|
||||||
setGLExtensionFuncPtr(glMultiTexCoord1dv, "glMultiTexCoord1dv","glMultiTexCoord1dvARB", validContext);
|
setGLExtensionFuncPtr(glMultiTexCoord1dv, "glMultiTexCoord1dv","glMultiTexCoord1dvARB", validContext);
|
||||||
setGLExtensionFuncPtr(glMultiTexCoord2dv, "glMultiTexCoord2dv","glMultiTexCoord2dvARB", validContext);
|
setGLExtensionFuncPtr(glMultiTexCoord2dv, "glMultiTexCoord2dv","glMultiTexCoord2dvARB", validContext);
|
||||||
@ -1122,6 +1143,43 @@ GLExtensions::GLExtensions(unsigned int contextID)
|
|||||||
osg::setGLExtensionFuncPtr(glDisableIndexedEXT, "glDisableIndexedEXT", validContext);
|
osg::setGLExtensionFuncPtr(glDisableIndexedEXT, "glDisableIndexedEXT", validContext);
|
||||||
osg::setGLExtensionFuncPtr(glIsEnabledIndexedEXT, "glIsEnabledIndexedEXT", validContext);
|
osg::setGLExtensionFuncPtr(glIsEnabledIndexedEXT, "glIsEnabledIndexedEXT", validContext);
|
||||||
|
|
||||||
|
setGLExtensionFuncPtr(glClientActiveTexture,"glClientActiveTexture","glClientActiveTextureARB", validContext);
|
||||||
|
setGLExtensionFuncPtr(glActiveTexture, "glActiveTexture","glActiveTextureARB", validContext);
|
||||||
|
setGLExtensionFuncPtr(glFogCoordPointer, "glFogCoordPointer","glFogCoordPointerEXT", validContext);
|
||||||
|
setGLExtensionFuncPtr(glSecondaryColorPointer, "glSecondaryColorPointer","glSecondaryColorPointerEXT", validContext);
|
||||||
|
|
||||||
|
if (validContext)
|
||||||
|
{
|
||||||
|
if (osg::getGLVersionNumber() >= 2.0 || osg::isGLExtensionSupported(contextID, "GL_ARB_vertex_shader") || OSG_GLES2_FEATURES || OSG_GL3_FEATURES)
|
||||||
|
{
|
||||||
|
glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS,&glMaxTextureUnits);
|
||||||
|
#ifdef OSG_GL_FIXED_FUNCTION_AVAILABLE
|
||||||
|
glGetIntegerv(GL_MAX_TEXTURE_COORDS, &glMaxTextureCoords);
|
||||||
|
#else
|
||||||
|
glMaxTextureCoords = _glMaxTextureUnits;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
else if ( osg::getGLVersionNumber() >= 1.3 ||
|
||||||
|
osg::isGLExtensionSupported(contextID,"GL_ARB_multitexture") ||
|
||||||
|
osg::isGLExtensionSupported(contextID,"GL_EXT_multitexture") ||
|
||||||
|
OSG_GLES1_FEATURES)
|
||||||
|
{
|
||||||
|
GLint maxTextureUnits = 0;
|
||||||
|
glGetIntegerv(GL_MAX_TEXTURE_UNITS,&maxTextureUnits);
|
||||||
|
glMaxTextureUnits = maxTextureUnits;
|
||||||
|
glMaxTextureCoords = maxTextureUnits;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
glMaxTextureUnits = 1;
|
||||||
|
glMaxTextureCoords = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
glMaxTextureUnits = 0;
|
||||||
|
glMaxTextureCoords = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1230,3 +1288,62 @@ bool GLExtensions::getFragDataLocation( const char* fragDataName, GLuint& locati
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Vertex Attrib Aliasing
|
||||||
|
//
|
||||||
|
void GLExtensions::setUpVertexAttribAlias(VertexAttribAlias& alias, GLuint location, const std::string glName, const std::string osgName, const std::string& declaration)
|
||||||
|
{
|
||||||
|
alias = VertexAttribAlias(location, glName, osgName, declaration);
|
||||||
|
_attributeBindingList[osgName] = location;
|
||||||
|
// OSG_NOTICE<<"State::setUpVertexAttribAlias("<<location<<" "<<glName<<" "<<osgName<<")"<<std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GLExtensions::resetVertexAttributeAlias(bool compactAliasing, unsigned int numTextureUnits)
|
||||||
|
{
|
||||||
|
_texCoordAliasList.clear();
|
||||||
|
_attributeBindingList.clear();
|
||||||
|
|
||||||
|
if (compactAliasing)
|
||||||
|
{
|
||||||
|
unsigned int slot = 0;
|
||||||
|
setUpVertexAttribAlias(_vertexAlias, slot++, "gl_Vertex","osg_Vertex","attribute vec4 ");
|
||||||
|
setUpVertexAttribAlias(_normalAlias, slot++, "gl_Normal","osg_Normal","attribute vec3 ");
|
||||||
|
setUpVertexAttribAlias(_colorAlias, slot++, "gl_Color","osg_Color","attribute vec4 ");
|
||||||
|
|
||||||
|
_texCoordAliasList.resize(numTextureUnits);
|
||||||
|
for(unsigned int i=0; i<_texCoordAliasList.size(); i++)
|
||||||
|
{
|
||||||
|
std::stringstream gl_MultiTexCoord;
|
||||||
|
std::stringstream osg_MultiTexCoord;
|
||||||
|
gl_MultiTexCoord<<"gl_MultiTexCoord"<<i;
|
||||||
|
osg_MultiTexCoord<<"osg_MultiTexCoord"<<i;
|
||||||
|
|
||||||
|
setUpVertexAttribAlias(_texCoordAliasList[i], slot++, gl_MultiTexCoord.str(), osg_MultiTexCoord.str(), "attribute vec4 ");
|
||||||
|
}
|
||||||
|
|
||||||
|
setUpVertexAttribAlias(_secondaryColorAlias, slot++, "gl_SecondaryColor","osg_SecondaryColor","attribute vec4 ");
|
||||||
|
setUpVertexAttribAlias(_fogCoordAlias, slot++, "gl_FogCoord","osg_FogCoord","attribute float ");
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
setUpVertexAttribAlias(_vertexAlias,0, "gl_Vertex","osg_Vertex","attribute vec4 ");
|
||||||
|
setUpVertexAttribAlias(_normalAlias, 2, "gl_Normal","osg_Normal","attribute vec3 ");
|
||||||
|
setUpVertexAttribAlias(_colorAlias, 3, "gl_Color","osg_Color","attribute vec4 ");
|
||||||
|
setUpVertexAttribAlias(_secondaryColorAlias, 4, "gl_SecondaryColor","osg_SecondaryColor","attribute vec4 ");
|
||||||
|
setUpVertexAttribAlias(_fogCoordAlias, 5, "gl_FogCoord","osg_FogCoord","attribute float ");
|
||||||
|
|
||||||
|
unsigned int base = 8;
|
||||||
|
_texCoordAliasList.resize(numTextureUnits);
|
||||||
|
for(unsigned int i=0; i<_texCoordAliasList.size(); i++)
|
||||||
|
{
|
||||||
|
std::stringstream gl_MultiTexCoord;
|
||||||
|
std::stringstream osg_MultiTexCoord;
|
||||||
|
gl_MultiTexCoord<<"gl_MultiTexCoord"<<i;
|
||||||
|
osg_MultiTexCoord<<"osg_MultiTexCoord"<<i;
|
||||||
|
|
||||||
|
setUpVertexAttribAlias(_texCoordAliasList[i], base+i, gl_MultiTexCoord.str(), osg_MultiTexCoord.str(), "attribute vec4 ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
|
|
||||||
#include <osg/Geometry>
|
#include <osg/Geometry>
|
||||||
#include <osg/ArrayDispatchers>
|
#include <osg/ArrayDispatchers>
|
||||||
|
#include <osg/VertexArrayState>
|
||||||
#include <osg/Notify>
|
#include <osg/Notify>
|
||||||
|
|
||||||
using namespace osg;
|
using namespace osg;
|
||||||
@ -603,6 +604,8 @@ void Geometry::resizeGLObjectBuffers(unsigned int maxSize)
|
|||||||
{
|
{
|
||||||
Drawable::resizeGLObjectBuffers(maxSize);
|
Drawable::resizeGLObjectBuffers(maxSize);
|
||||||
|
|
||||||
|
_vertexArrayStateList.resize(maxSize);
|
||||||
|
|
||||||
ArrayList arrays;
|
ArrayList arrays;
|
||||||
if (getArrayList(arrays))
|
if (getArrayList(arrays))
|
||||||
{
|
{
|
||||||
@ -630,6 +633,9 @@ void Geometry::releaseGLObjects(State* state) const
|
|||||||
{
|
{
|
||||||
Drawable::releaseGLObjects(state);
|
Drawable::releaseGLObjects(state);
|
||||||
|
|
||||||
|
if (state) _vertexArrayStateList[state->getContextID()];
|
||||||
|
else _vertexArrayStateList.clear();
|
||||||
|
|
||||||
ArrayList arrays;
|
ArrayList arrays;
|
||||||
if (getArrayList(arrays))
|
if (getArrayList(arrays))
|
||||||
{
|
{
|
||||||
@ -734,28 +740,41 @@ void Geometry::drawImplementation(RenderInfo& renderInfo) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
State& state = *renderInfo.getState();
|
State& state = *renderInfo.getState();
|
||||||
|
const DisplaySettings* ds = state.getDisplaySettings() ? state.getDisplaySettings() : osg::DisplaySettings::instance();
|
||||||
|
|
||||||
bool checkForGLErrors = state.getCheckForGLErrors()==osg::State::ONCE_PER_ATTRIBUTE;
|
bool checkForGLErrors = state.getCheckForGLErrors()==osg::State::ONCE_PER_ATTRIBUTE;
|
||||||
if (checkForGLErrors) state.checkGLErrors("start of Geometry::drawImplementation()");
|
if (checkForGLErrors) state.checkGLErrors("start of Geometry::drawImplementation()");
|
||||||
|
|
||||||
drawVertexArraysImplementation(renderInfo);
|
|
||||||
|
|
||||||
if (checkForGLErrors) state.checkGLErrors("Geometry::drawImplementation() after vertex arrays setup.");
|
bool useNewImplementation = (ds->getGeometryImplementation()!=DisplaySettings::OLD_GEOMETRY_IMPLEMENTATION);
|
||||||
|
if (useNewImplementation)
|
||||||
|
{
|
||||||
|
new_drawImplementation(renderInfo);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// OSG_NOTICE<<"Old implementation"<<std::endl;
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
old_drawVertexArraysImplementation(renderInfo);
|
||||||
//
|
|
||||||
// draw the primitives themselves.
|
|
||||||
//
|
|
||||||
drawPrimitivesImplementation(renderInfo);
|
|
||||||
|
|
||||||
// unbind the VBO's if any are used.
|
if (checkForGLErrors) state.checkGLErrors("Geometry::drawImplementation() after vertex arrays setup.");
|
||||||
state.unbindVertexBufferObject();
|
|
||||||
state.unbindElementBufferObject();
|
|
||||||
|
|
||||||
if (checkForGLErrors) state.checkGLErrors("end of Geometry::drawImplementation().");
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// draw the primitives themselves.
|
||||||
|
//
|
||||||
|
|
||||||
|
old_drawPrimitivesImplementation(renderInfo);
|
||||||
|
|
||||||
|
// unbind the VBO's if any are used.
|
||||||
|
state.unbindVertexBufferObject();
|
||||||
|
state.unbindElementBufferObject();
|
||||||
|
|
||||||
|
if (checkForGLErrors) state.checkGLErrors("end of Geometry::drawImplementation().");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Geometry::drawVertexArraysImplementation(RenderInfo& renderInfo) const
|
void Geometry::old_drawVertexArraysImplementation(RenderInfo& renderInfo) const
|
||||||
{
|
{
|
||||||
State& state = *renderInfo.getState();
|
State& state = *renderInfo.getState();
|
||||||
|
|
||||||
@ -834,7 +853,7 @@ void Geometry::drawVertexArraysImplementation(RenderInfo& renderInfo) const
|
|||||||
state.applyDisablingOfVertexAttributes();
|
state.applyDisablingOfVertexAttributes();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Geometry::drawPrimitivesImplementation(RenderInfo& renderInfo) const
|
void Geometry::old_drawPrimitivesImplementation(RenderInfo& renderInfo) const
|
||||||
{
|
{
|
||||||
State& state = *renderInfo.getState();
|
State& state = *renderInfo.getState();
|
||||||
ArrayDispatchers& arrayDispatchers = state.getArrayDispatchers();
|
ArrayDispatchers& arrayDispatchers = state.getArrayDispatchers();
|
||||||
@ -852,6 +871,112 @@ void Geometry::drawPrimitivesImplementation(RenderInfo& renderInfo) const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Geometry::new_drawImplementation(RenderInfo& renderInfo) const
|
||||||
|
{
|
||||||
|
State& state = *renderInfo.getState();
|
||||||
|
const DisplaySettings* ds = state.getDisplaySettings() ? state.getDisplaySettings() : osg::DisplaySettings::instance();
|
||||||
|
|
||||||
|
unsigned int contextID = state.getContextID();
|
||||||
|
|
||||||
|
bool usingVertexBufferObjects = _useVertexBufferObjects && state.isVertexBufferObjectSupported();
|
||||||
|
bool useVAO = usingVertexBufferObjects && (ds->getGeometryImplementation()==DisplaySettings::VERTEX_ARRAY_OBJECT);
|
||||||
|
bool dispatchIfDirty = useVAO;
|
||||||
|
|
||||||
|
VertexArrayState* vas = _vertexArrayStateList[contextID].get();
|
||||||
|
|
||||||
|
bool checkForGLErrors = state.getCheckForGLErrors()==osg::State::ONCE_PER_ATTRIBUTE;
|
||||||
|
|
||||||
|
if (checkForGLErrors) state.checkGLErrors("Geometry::new_drawImplementation() before vertex arrays setup.");
|
||||||
|
|
||||||
|
if (!useVAO)
|
||||||
|
{
|
||||||
|
state.lazyDisablingOfVertexAttributes();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!vas)
|
||||||
|
{
|
||||||
|
OSG_NOTICE<<"Creating new osg::VertexArrayState"<<std::endl;
|
||||||
|
_vertexArrayStateList[contextID] = vas = new osg::VertexArrayState(state.get<GLExtensions>());
|
||||||
|
|
||||||
|
if (_vertexArray.valid()) vas->assignVertexArray(_vertexArray.get());
|
||||||
|
if (_colorArray.valid()) vas->assignColorArray(_colorArray.get());
|
||||||
|
if (_normalArray.valid()) vas->assignNormalArray(_normalArray.get());
|
||||||
|
if (_secondaryColorArray.valid()) vas->assignSecondaryColorArray(_secondaryColorArray.get());
|
||||||
|
if (_fogCoordArray.valid()) vas->assignFogCoordArray(_fogCoordArray.get());
|
||||||
|
|
||||||
|
for(unsigned int i=0; i<_texCoordList.size(); ++i)
|
||||||
|
{
|
||||||
|
if (_texCoordList[i].valid()) vas->assignTexCoordArray(i, _texCoordList[i].get());
|
||||||
|
}
|
||||||
|
|
||||||
|
for(unsigned int i=0; i<_vertexAttribList.size(); ++i)
|
||||||
|
{
|
||||||
|
if (_vertexAttribList[i].valid()) vas->assignVertexAttribArray(i, _vertexAttribList[i].get());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (useVAO)
|
||||||
|
{
|
||||||
|
OSG_NOTICE<<" Setup VertexArrayState to use VAO"<<std::endl;
|
||||||
|
|
||||||
|
vas->generateVretexArrayObject();
|
||||||
|
dispatchIfDirty = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
OSG_NOTICE<<" Setup VertexArrayState to wihtout using VAO"<<std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (useVAO)
|
||||||
|
{
|
||||||
|
vas->bindVertexArrayObject();
|
||||||
|
}
|
||||||
|
|
||||||
|
osg::ref_ptr<VertexArrayState> previous_vas = state.getCurrentVertexArrayState();
|
||||||
|
|
||||||
|
state.setCurrentVertexArrayState(vas);
|
||||||
|
|
||||||
|
vas->dispatchOverall(state);
|
||||||
|
|
||||||
|
|
||||||
|
if (dispatchIfDirty)
|
||||||
|
{
|
||||||
|
vas->dispatchArraysIfDirty(state);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
vas->dispatchArrays(state);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!useVAO)
|
||||||
|
{
|
||||||
|
state.applyDisablingOfVertexAttributes();
|
||||||
|
}
|
||||||
|
|
||||||
|
for(unsigned int primitiveSetNum=0; primitiveSetNum<_primitives.size(); ++primitiveSetNum)
|
||||||
|
{
|
||||||
|
// dispatch any attributes that are bound per primitive
|
||||||
|
vas->dispatchPerPrimitveSet(state, primitiveSetNum);
|
||||||
|
|
||||||
|
// disaptch the primitives
|
||||||
|
_primitives[primitiveSetNum]->draw(state, usingVertexBufferObjects);
|
||||||
|
}
|
||||||
|
|
||||||
|
state.setCurrentVertexArrayState(previous_vas);
|
||||||
|
|
||||||
|
if (!useVAO && usingVertexBufferObjects)
|
||||||
|
{
|
||||||
|
// unbind the VBO's if any are used.
|
||||||
|
state.unbindVertexBufferObject();
|
||||||
|
state.unbindElementBufferObject();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (checkForGLErrors) state.checkGLErrors("Geometry::new_drawImplementation() after primitive dispatch.");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void Geometry::accept(AttributeFunctor& af)
|
void Geometry::accept(AttributeFunctor& af)
|
||||||
{
|
{
|
||||||
AttributeFunctorArrayVisitor afav(af);
|
AttributeFunctorArrayVisitor afav(af);
|
||||||
|
@ -172,6 +172,7 @@ unsigned int DrawArrayLengths::getNumIndices() const
|
|||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// DrawElementsUByte
|
// DrawElementsUByte
|
||||||
@ -192,7 +193,10 @@ void DrawElementsUByte::draw(State& state, bool useVertexBufferObjects) const
|
|||||||
if (useVertexBufferObjects)
|
if (useVertexBufferObjects)
|
||||||
{
|
{
|
||||||
GLBufferObject* ebo = getOrCreateGLBufferObject(state.getContextID());
|
GLBufferObject* ebo = getOrCreateGLBufferObject(state.getContextID());
|
||||||
state.bindElementBufferObject(ebo);
|
|
||||||
|
if (state.getCurrentVertexArrayState()) state.getCurrentVertexArrayState()->bindElementBufferObject(ebo);
|
||||||
|
else state.bindElementBufferObject(ebo);
|
||||||
|
|
||||||
if (ebo)
|
if (ebo)
|
||||||
{
|
{
|
||||||
if (_numInstances>=1) state.glDrawElementsInstanced(mode, size(), GL_UNSIGNED_BYTE, (const GLvoid *)(ebo->getOffset(getBufferIndex())), _numInstances);
|
if (_numInstances>=1) state.glDrawElementsInstanced(mode, size(), GL_UNSIGNED_BYTE, (const GLvoid *)(ebo->getOffset(getBufferIndex())), _numInstances);
|
||||||
@ -252,7 +256,19 @@ void DrawElementsUShort::draw(State& state, bool useVertexBufferObjects) const
|
|||||||
if (useVertexBufferObjects)
|
if (useVertexBufferObjects)
|
||||||
{
|
{
|
||||||
GLBufferObject* ebo = getOrCreateGLBufferObject(state.getContextID());
|
GLBufferObject* ebo = getOrCreateGLBufferObject(state.getContextID());
|
||||||
state.bindElementBufferObject(ebo);
|
|
||||||
|
|
||||||
|
if (state.getCurrentVertexArrayState())
|
||||||
|
{
|
||||||
|
OSG_NOTICE<<" DrawElementsUShort::draw() size="<<size()<<" A bind="<<ebo<<std::endl;
|
||||||
|
state.getCurrentVertexArrayState()->bindElementBufferObject(ebo);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
OSG_NOTICE<<" DrawElementsUShort::draw() size="<<size()<<" B bind="<<ebo<<std::endl;
|
||||||
|
state.bindElementBufferObject(ebo);
|
||||||
|
}
|
||||||
|
|
||||||
if (ebo)
|
if (ebo)
|
||||||
{
|
{
|
||||||
if (_numInstances>=1) state.glDrawElementsInstanced(mode, size(), GL_UNSIGNED_SHORT, (const GLvoid *)(ebo->getOffset(getBufferIndex())), _numInstances);
|
if (_numInstances>=1) state.glDrawElementsInstanced(mode, size(), GL_UNSIGNED_SHORT, (const GLvoid *)(ebo->getOffset(getBufferIndex())), _numInstances);
|
||||||
@ -311,7 +327,10 @@ void DrawElementsUInt::draw(State& state, bool useVertexBufferObjects) const
|
|||||||
if (useVertexBufferObjects)
|
if (useVertexBufferObjects)
|
||||||
{
|
{
|
||||||
GLBufferObject* ebo = getOrCreateGLBufferObject(state.getContextID());
|
GLBufferObject* ebo = getOrCreateGLBufferObject(state.getContextID());
|
||||||
state.bindElementBufferObject(ebo);
|
|
||||||
|
if (state.getCurrentVertexArrayState()) state.getCurrentVertexArrayState()->bindElementBufferObject(ebo);
|
||||||
|
else state.bindElementBufferObject(ebo);
|
||||||
|
|
||||||
if (ebo)
|
if (ebo)
|
||||||
{
|
{
|
||||||
if (_numInstances>=1) state.glDrawElementsInstanced(mode, size(), GL_UNSIGNED_INT, (const GLvoid *)(ebo->getOffset(getBufferIndex())), _numInstances);
|
if (_numInstances>=1) state.glDrawElementsInstanced(mode, size(), GL_UNSIGNED_INT, (const GLvoid *)(ebo->getOffset(getBufferIndex())), _numInstances);
|
||||||
|
@ -981,6 +981,8 @@ void State::initializeExtensionProcs()
|
|||||||
_glExtensions = new GLExtensions(_contextID);
|
_glExtensions = new GLExtensions(_contextID);
|
||||||
GLExtensions::Set(_contextID, _glExtensions.get());
|
GLExtensions::Set(_contextID, _glExtensions.get());
|
||||||
|
|
||||||
|
// _currentVertexArrayState = new VertexArrayState(_glExtensions.get());
|
||||||
|
|
||||||
setGLExtensionFuncPtr(_glClientActiveTexture,"glClientActiveTexture","glClientActiveTextureARB");
|
setGLExtensionFuncPtr(_glClientActiveTexture,"glClientActiveTexture","glClientActiveTextureARB");
|
||||||
setGLExtensionFuncPtr(_glActiveTexture, "glActiveTexture","glActiveTextureARB");
|
setGLExtensionFuncPtr(_glActiveTexture, "glActiveTexture","glActiveTextureARB");
|
||||||
setGLExtensionFuncPtr(_glFogCoordPointer, "glFogCoordPointer","glFogCoordPointerEXT");
|
setGLExtensionFuncPtr(_glFogCoordPointer, "glFogCoordPointer","glFogCoordPointerEXT");
|
||||||
|
1097
src/osg/VertexArrayState.cpp
Normal file
1097
src/osg/VertexArrayState.cpp
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user