From Mike Weiblen, support for geometry shaders, and osgeometryshaders example to demonstrate them.

This commit is contained in:
Robert Osfield
2008-01-08 14:29:44 +00:00
parent a33a0047a4
commit 578f385760
10 changed files with 934 additions and 34 deletions

View File

@@ -2,6 +2,7 @@
* Copyright (C) 2003-2005 3Dlabs Inc. Ltd.
* Copyright (C) 2004-2005 Nathan Cournia
* Copyright (C) 2007 Art Tevs
* Copyright (C) 2008 Zebra Imaging
*
* This application is open source and may be redistributed and/or modified
* freely and without restriction, both in commericial and non commericial
@@ -13,7 +14,7 @@
*/
/* file: include/osg/GL2Extensions
* author: Mike Weiblen 2005-05-05
* author: Mike Weiblen 2008-01-02
*/
#ifndef OSG_GL2EXTENSIONS
@@ -31,8 +32,7 @@
#define GL_SAMPLER_2D_ARRAY_SHADOW_EXT 0x8DC4
#endif
#ifndef GL_VERSION_2_0 //[
#ifndef GL_VERSION_2_0
#define GL_VERSION_2_0 1
typedef char GLchar;
#define GL_BLEND_EQUATION_RGB GL_BLEND_EQUATION
@@ -119,7 +119,90 @@ typedef char GLchar;
#define GL_STENCIL_BACK_REF 0x8CA3
#define GL_STENCIL_BACK_VALUE_MASK 0x8CA4
#define GL_STENCIL_BACK_WRITEMASK 0x8CA5
#endif //]
#endif
#ifndef GL_VERSION_2_1
#define GL_VERSION_2_1 1
#define GL_CURRENT_RASTER_SECONDARY_COLOR 0x845F
#define GL_PIXEL_PACK_BUFFER 0x88EB
#define GL_PIXEL_UNPACK_BUFFER 0x88EC
#define GL_PIXEL_PACK_BUFFER_BINDING 0x88ED
#define GL_PIXEL_UNPACK_BUFFER_BINDING 0x88EF
#define GL_FLOAT_MAT2x3 0x8B65
#define GL_FLOAT_MAT2x4 0x8B66
#define GL_FLOAT_MAT3x2 0x8B67
#define GL_FLOAT_MAT3x4 0x8B68
#define GL_FLOAT_MAT4x2 0x8B69
#define GL_FLOAT_MAT4x3 0x8B6A
#define GL_SRGB 0x8C40
#define GL_SRGB8 0x8C41
#define GL_SRGB_ALPHA 0x8C42
#define GL_SRGB8_ALPHA8 0x8C43
#define GL_SLUMINANCE_ALPHA 0x8C44
#define GL_SLUMINANCE8_ALPHA8 0x8C45
#define GL_SLUMINANCE 0x8C46
#define GL_SLUMINANCE8 0x8C47
#define GL_COMPRESSED_SRGB 0x8C48
#define GL_COMPRESSED_SRGB_ALPHA 0x8C49
#define GL_COMPRESSED_SLUMINANCE 0x8C4A
#define GL_COMPRESSED_SLUMINANCE_ALPHA 0x8C4B
#endif
// EXT_geometry_shader4
#ifndef GL_GEOMETRY_SHADER_EXT
#define GL_GEOMETRY_SHADER_EXT 0x8DD9
#define GL_GEOMETRY_VERTICES_OUT_EXT 0x8DDA
#define GL_GEOMETRY_INPUT_TYPE_EXT 0x8DDB
#define GL_GEOMETRY_OUTPUT_TYPE_EXT 0x8DDC
#define GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT 0x8C29
#define GL_MAX_GEOMETRY_VARYING_COMPONENTS_EXT 0x8DDD
#define GL_MAX_VERTEX_VARYING_COMPONENTS_EXT 0x8DDE
#define GL_MAX_VARYING_COMPONENTS_EXT 0x8B4B
#define GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT 0x8DDF
#define GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT 0x8DE0
#define GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT 0x8DE1
#define GL_LINES_ADJACENCY_EXT 0x000A
#define GL_LINE_STRIP_ADJACENCY_EXT 0x000B
#define GL_TRIANGLES_ADJACENCY_EXT 0x000C
#define GL_TRIANGLE_STRIP_ADJACENCY_EXT 0x000D
#define GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS_EXT 0x8DA8
#define GL_FRAMEBUFFER_INCOMPLETE_LAYER_COUNT_EXT 0x8DA9
#define GL_FRAMEBUFFER_ATTACHMENT_LAYERED_EXT 0x8DA7
#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER_EXT 0x8CD4
#define GL_PROGRAM_POINT_SIZE_EXT 0x8642
#endif
// EXT_gpu_shader4
#ifndef GL_INT_SAMPLER_2D_EXT
#define GL_SAMPLER_1D_ARRAY_EXT 0x8DC0
#define GL_SAMPLER_2D_ARRAY_EXT 0x8DC1
#define GL_SAMPLER_BUFFER_EXT 0x8DC2
#define GL_SAMPLER_1D_ARRAY_SHADOW_EXT 0x8DC3
#define GL_SAMPLER_2D_ARRAY_SHADOW_EXT 0x8DC4
#define GL_SAMPLER_CUBE_SHADOW_EXT 0x8DC5
#define GL_UNSIGNED_INT_VEC2_EXT 0x8DC6
#define GL_UNSIGNED_INT_VEC3_EXT 0x8DC7
#define GL_UNSIGNED_INT_VEC4_EXT 0x8DC8
#define GL_INT_SAMPLER_1D_EXT 0x8DC9
#define GL_INT_SAMPLER_2D_EXT 0x8DCA
#define GL_INT_SAMPLER_3D_EXT 0x8DCB
#define GL_INT_SAMPLER_CUBE_EXT 0x8DCC
#define GL_INT_SAMPLER_2D_RECT_EXT 0x8DCD
#define GL_INT_SAMPLER_1D_ARRAY_EXT 0x8DCE
#define GL_INT_SAMPLER_2D_ARRAY_EXT 0x8DCF
#define GL_INT_SAMPLER_BUFFER_EXT 0x8DD0
#define GL_UNSIGNED_INT_SAMPLER_1D_EXT 0x8DD1
#define GL_UNSIGNED_INT_SAMPLER_2D_EXT 0x8DD2
#define GL_UNSIGNED_INT_SAMPLER_3D_EXT 0x8DD3
#define GL_UNSIGNED_INT_SAMPLER_CUBE_EXT 0x8DD4
#define GL_UNSIGNED_INT_SAMPLER_2D_RECT_EXT 0x8DD5
#define GL_UNSIGNED_INT_SAMPLER_1D_ARRAY_EXT 0x8DD6
#define GL_UNSIGNED_INT_SAMPLER_2D_ARRAY_EXT 0x8DD7
#define GL_UNSIGNED_INT_SAMPLER_BUFFER_EXT 0x8DD8
#define GL_MIN_PROGRAM_TEXEL_OFFSET_EXT 0x8904
#define GL_MAX_PROGRAM_TEXEL_OFFSET_EXT 0x8905
#endif
namespace osg {
@@ -151,6 +234,12 @@ class OSG_EXPORT GL2Extensions : public osg::Referenced
void setLanguage100Supported(bool flag) { _isLanguage100Supported = flag; }
bool isLanguage100Supported() const { return _isLanguage100Supported; }
void setGeometryShader4Supported(bool flag) { _isGeometryShader4Supported = flag; }
bool isGeometryShader4Supported() const { return _isGeometryShader4Supported; }
void setGpuShader4Supported(bool flag) { _isGpuShader4Supported = flag; }
bool isGpuShader4Supported() const { return _isGpuShader4Supported; }
/** Function to call to get the extension of a specified context.
* If the Exentsion object for that context has not yet been created then
* and the 'createIfNotInitalized' flag been set to false then returns NULL.
@@ -266,9 +355,32 @@ class OSG_EXPORT GL2Extensions : public osg::Referenced
bool getAttribLocation( const char* attribName, GLuint& slot ) const;
bool getFragDataLocation( const char* fragDataName, GLuint& slot) const;
//EXT_gpu_shader4 to support frag data binding
void glBindFragDataLocation(GLuint program, GLuint colorNumber, const GLchar *name) const;
GLint glGetFragDataLocation(GLuint program, const GLchar *name) const;
// GL 2.1
void glUniformMatrix2x3fv( GLint location, GLsizei count, GLboolean transpose, const GLfloat* value ) const;
void glUniformMatrix3x2fv( GLint location, GLsizei count, GLboolean transpose, const GLfloat* value ) const;
void glUniformMatrix2x4fv( GLint location, GLsizei count, GLboolean transpose, const GLfloat* value ) const;
void glUniformMatrix4x2fv( GLint location, GLsizei count, GLboolean transpose, const GLfloat* value ) const;
void glUniformMatrix3x4fv( GLint location, GLsizei count, GLboolean transpose, const GLfloat* value ) const;
void glUniformMatrix4x3fv( GLint location, GLsizei count, GLboolean transpose, const GLfloat* value ) const;
// EXT_geometry_shader4
void glProgramParameteri( GLuint program, GLenum pname, GLint value ) const;
void glFramebufferTexture( GLenum target, GLenum attachment, GLuint texture, GLint level ) const;
void glFramebufferTextureLayer( GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer ) const;
void glFramebufferTextureFace( GLenum target, GLenum attachment, GLuint texture, GLint level, GLenum face ) const;
// EXT_gpu_shader4
void glGetUniformuiv( GLuint program, GLint location, GLuint *params ) const;
void glBindFragDataLocation( GLuint program, GLuint color, const GLchar *name ) const;
GLint glGetFragDataLocation( GLuint program, const GLchar *name ) const;
void glUniform1ui( GLint location, GLuint v0 ) const;
void glUniform2ui( GLint location, GLuint v0, GLuint v1 ) const;
void glUniform3ui( GLint location, GLuint v0, GLuint v1, GLuint v2 ) const;
void glUniform4ui( GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3 ) const;
void glUniform1uiv( GLint location, GLsizei count, const GLuint *value ) const;
void glUniform2uiv( GLint location, GLsizei count, const GLuint *value ) const;
void glUniform3uiv( GLint location, GLsizei count, const GLuint *value ) const;
void glUniform4uiv( GLint location, GLsizei count, const GLuint *value ) const;
protected:
~GL2Extensions() {}
@@ -280,6 +392,8 @@ class OSG_EXPORT GL2Extensions : public osg::Referenced
bool _isVertexShaderSupported;
bool _isFragmentShaderSupported;
bool _isLanguage100Supported;
bool _isGeometryShader4Supported;
bool _isGpuShader4Supported;
void* _glBlendEquationSeparate;
void* _glDrawBuffers;
@@ -380,8 +494,32 @@ class OSG_EXPORT GL2Extensions : public osg::Referenced
void* _glDeleteObjectARB;
void* _glGetHandleARB;
// GL 2.1
void* _glUniformMatrix2x3fv;
void* _glUniformMatrix3x2fv;
void* _glUniformMatrix2x4fv;
void* _glUniformMatrix4x2fv;
void* _glUniformMatrix3x4fv;
void* _glUniformMatrix4x3fv;
// EXT_geometry_shader4
void* _glProgramParameteri;
void* _glFramebufferTexture;
void* _glFramebufferTextureLayer;
void* _glFramebufferTextureFace;
// EXT_gpu_shader4
void* _glGetUniformuiv;
void* _glBindFragDataLocation;
void* _glGetFragDataLocation;
void* _glUniform1ui;
void* _glUniform2ui;
void* _glUniform3ui;
void* _glUniform4ui;
void* _glUniform1uiv;
void* _glUniform2uiv;
void* _glUniform3uiv;
void* _glUniform4uiv;
};
}

View File

@@ -1,6 +1,7 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
* Copyright (C) 2003-2005 3Dlabs Inc. Ltd.
* Copyright (C) 2004-2005 Nathan Cournia
* Copyright (C) 2008 Zebra Imaging
*
* This application is open source and may be redistributed and/or modified
* freely and without restriction, both in commericial and non commericial
@@ -12,7 +13,7 @@
*/
/* file: include/osg/Program
* author: Mike Weiblen 2006-03-25
* author: Mike Weiblen 2008-01-02
*/
#ifndef OSG_PROGRAM
@@ -91,6 +92,10 @@ class OSG_EXPORT Program : public osg::StateAttribute
* Mark Program as needing relink. Return true for success */
bool removeShader( Shader* shader );
/** Set/get GL program parameters */
void setParameter( GLenum pname, GLint value );
GLint getParameter( GLenum pname ) const;
/** Add an attribute location binding. */
void addBindAttribLocation( const std::string& name, GLuint index );
@@ -152,8 +157,6 @@ class OSG_EXPORT Program : public osg::StateAttribute
class OSG_EXPORT PerContextProgram : public osg::Referenced
{
public:
PerContextProgram(const Program* program, unsigned int contextID);
GLuint getHandle() const {return _glProgramHandle;}
@@ -234,7 +237,7 @@ class OSG_EXPORT Program : public osg::StateAttribute
/** Is our glProgram successfully linked? */
bool _isLinked;
const unsigned int _contextID;
ActiveVarInfoMap _uniformInfoMap;
ActiveVarInfoMap _attribInfoMap;
@@ -267,6 +270,11 @@ class OSG_EXPORT Program : public osg::StateAttribute
typedef std::vector< ref_ptr<Shader> > ShaderList;
ShaderList _shaderList;
/** Parameters maintained with glProgramParameteriEXT */
GLint _geometryVerticesOut;
GLint _geometryInputType;
GLint _geometryOutputType;
private:
Program& operator=(const Program&); // disallowed
};

View File

@@ -1,6 +1,7 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
* Copyright (C) 2003-2005 3Dlabs Inc. Ltd.
* Copyright (C) 2004-2005 Nathan Cournia
* Copyright (C) 2008 Zebra Imaging
*
* This application is open source and may be redistributed and/or modified
* freely and without restriction, both in commericial and non commericial
@@ -12,7 +13,7 @@
*/
/* file: include/osg/Shader
* author: Mike Weiblen 2005-06-15
* author: Mike Weiblen 2008-01-02
*/
#ifndef OSG_SHADER
@@ -46,6 +47,7 @@ class OSG_EXPORT Shader : public osg::Object
enum Type {
VERTEX = GL_VERTEX_SHADER,
FRAGMENT = GL_FRAGMENT_SHADER,
GEOMETRY = GL_GEOMETRY_SHADER_EXT,
UNDEFINED = -1
};

View File

@@ -1,5 +1,6 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
* Copyright (C) 2003-2005 3Dlabs Inc. Ltd.
* Copyright (C) 2008 Zebra Imaging
*
* This application is open source and may be redistributed and/or modified
* freely and without restriction, both in commericial and non commericial
@@ -11,7 +12,7 @@
*/
/* file: include/osg/Uniform
* author: Mike Weiblen 2006-05-15
* author: Mike Weiblen 2008-01-02
*/
#ifndef OSG_UNIFORM
@@ -35,7 +36,7 @@ class GL2Extensions;
class NodeVisitor;
///////////////////////////////////////////////////////////////////////////
// C++ classes to represent the GLSL-specific "mat2" & "mat3" types.
// C++ classes to represent the GLSL-specific types.
class OSG_EXPORT Matrix2
{
@@ -137,6 +138,15 @@ class OSG_EXPORT Matrix3
float _mat[3][3];
};
// TODO add new GL 2.1 non-square matrix types
// class OSG_EXPORT Matrix2x3
// class OSG_EXPORT Matrix3x2
// class OSG_EXPORT Matrix2x4
// class OSG_EXPORT Matrix4x2
// class OSG_EXPORT Matrix3x4
// class OSG_EXPORT Matrix4x3
///////////////////////////////////////////////////////////////////////////
/** Uniform encapsulates glUniform values */
@@ -170,7 +180,36 @@ class OSG_EXPORT Uniform : public Object
SAMPLER_2D_ARRAY = GL_SAMPLER_2D_ARRAY_EXT,
SAMPLER_1D_ARRAY_SHADOW = GL_SAMPLER_1D_ARRAY_SHADOW_EXT,
SAMPLER_2D_ARRAY_SHADOW = GL_SAMPLER_2D_ARRAY_SHADOW_EXT,
// TODO the following must be integrated fully here and Uniform.cpp
FLOAT_MAT2x3 = GL_FLOAT_MAT2x3,
FLOAT_MAT2x4 = GL_FLOAT_MAT2x4,
FLOAT_MAT3x2 = GL_FLOAT_MAT3x2,
FLOAT_MAT3x4 = GL_FLOAT_MAT3x4,
FLOAT_MAT4x2 = GL_FLOAT_MAT4x2,
FLOAT_MAT4x3 = GL_FLOAT_MAT4x3,
SAMPLER_BUFFER = GL_SAMPLER_BUFFER_EXT,
SAMPLER_CUBE_SHADOW = GL_SAMPLER_CUBE_SHADOW_EXT,
UNSIGNED_INT_VEC2 = GL_UNSIGNED_INT_VEC2_EXT,
UNSIGNED_INT_VEC3 = GL_UNSIGNED_INT_VEC3_EXT,
UNSIGNED_INT_VEC4 = GL_UNSIGNED_INT_VEC4_EXT,
INT_SAMPLER_1D = GL_INT_SAMPLER_1D_EXT,
INT_SAMPLER_2D = GL_INT_SAMPLER_2D_EXT,
INT_SAMPLER_3D = GL_INT_SAMPLER_3D_EXT,
INT_SAMPLER_CUBE = GL_INT_SAMPLER_CUBE_EXT,
INT_SAMPLER_2D_RECT = GL_INT_SAMPLER_2D_RECT_EXT,
INT_SAMPLER_1D_ARRAY = GL_INT_SAMPLER_1D_ARRAY_EXT,
INT_SAMPLER_2D_ARRAY = GL_INT_SAMPLER_2D_ARRAY_EXT,
INT_SAMPLER_BUFFER = GL_INT_SAMPLER_BUFFER_EXT,
UNSIGNED_INT_SAMPLER_1D = GL_UNSIGNED_INT_SAMPLER_1D_EXT,
UNSIGNED_INT_SAMPLER_2D = GL_UNSIGNED_INT_SAMPLER_2D_EXT,
UNSIGNED_INT_SAMPLER_3D = GL_UNSIGNED_INT_SAMPLER_3D_EXT,
UNSIGNED_INT_SAMPLER_CUBE = GL_UNSIGNED_INT_SAMPLER_CUBE_EXT,
UNSIGNED_INT_SAMPLER_2D_RECT = GL_UNSIGNED_INT_SAMPLER_2D_RECT_EXT,
UNSIGNED_INT_SAMPLER_1D_ARRAY = GL_UNSIGNED_INT_SAMPLER_1D_ARRAY_EXT,
UNSIGNED_INT_SAMPLER_2D_ARRAY = GL_UNSIGNED_INT_SAMPLER_2D_ARRAY_EXT,
UNSIGNED_INT_SAMPLER_BUFFER = GL_UNSIGNED_INT_SAMPLER_BUFFER_EXT,
UNDEFINED = 0x0
};
@@ -236,6 +275,7 @@ class OSG_EXPORT Uniform : public Object
Uniform( const char* name, bool b0, bool b1 );
Uniform( const char* name, bool b0, bool b1, bool b2 );
Uniform( const char* name, bool b0, bool b1, bool b2, bool b3 );
// TODO must add new types
/** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs. */
virtual int compare(const Uniform& rhs) const;