diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index c915d19de..7a9094f6f 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -70,6 +70,7 @@ IF(DYNAMIC_OPENSCENEGRAPH) ADD_SUBDIRECTORY(osgscribe) ADD_SUBDIRECTORY(osgsequence) ADD_SUBDIRECTORY(osgshaders) + ADD_SUBDIRECTORY(osggeometryshaders) ADD_SUBDIRECTORY(osgshaderterrain) ADD_SUBDIRECTORY(osgshadow) ADD_SUBDIRECTORY(osgshape) diff --git a/examples/osggeometryshaders/CMakeLists.txt b/examples/osggeometryshaders/CMakeLists.txt new file mode 100644 index 000000000..0a3391538 --- /dev/null +++ b/examples/osggeometryshaders/CMakeLists.txt @@ -0,0 +1,2 @@ +SET(TARGET_SRC osggeometryshaders.cpp ) +SETUP_EXAMPLE(osggeometryshaders) diff --git a/examples/osggeometryshaders/osggeometryshaders.cpp b/examples/osggeometryshaders/osggeometryshaders.cpp new file mode 100644 index 000000000..45d2ccbed --- /dev/null +++ b/examples/osggeometryshaders/osggeometryshaders.cpp @@ -0,0 +1,191 @@ +/* OpenSceneGraph example, osgshaders2 +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. +*/ + +/* file: examples/osgshaders2/osgshaders2.cpp + * author: Mike Weiblen 2008-01-03 + * copyright: (C) 2008 Zebra Imaging + * license: OpenSceneGraph Public License (OSGPL) + * + * A demo of GLSL geometry shaders using OSG + * Tested on Dell Precision M4300 w/ NVIDIA Quadro FX 360M +*/ + + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// play with these #defines to see their effect +#define ENABLE_GLSL +#define ENABLE_GEOMETRY_SHADER + +/////////////////////////////////////////////////////////////////////////// + +#ifdef ENABLE_GLSL + +class SineAnimation: public osg::Uniform::Callback +{ +public: + SineAnimation( float rate = 1.0f, float scale = 1.0f, float offset = 0.0f ) : + _rate(rate), _scale(scale), _offset(offset) + {} + + void operator()( osg::Uniform* uniform, osg::NodeVisitor* nv ) + { + float angle = _rate * nv->getFrameStamp()->getSimulationTime(); + float value = sinf( angle ) * _scale + _offset; + uniform->set( value ); + } + +private: + const float _rate; + const float _scale; + const float _offset; +}; + +/////////////////////////////////////////////////////////////////////////// + +static const char* vertSource = { +"#version 120\n" +"#extension GL_EXT_geometry_shader4 : enable\n" +"uniform float u_anim1;\n" +"varying vec4 v_color;\n" +"void main(void)\n" +"{\n" +" v_color = gl_Vertex;\n" +" gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n" +"}\n" +}; + +static const char* geomSource = { +"#version 120\n" +"#extension GL_EXT_geometry_shader4 : enable\n" +"uniform float u_anim1;\n" +"varying vec4 v_color;\n" +"void main(void)\n" +"{\n" +" vec4 v = gl_PositionIn[0];\n" +" v_color = v;\n" +"\n" +" gl_Position = v + vec4(u_anim1,0.,0.,0.); EmitVertex();\n" +" gl_Position = v - vec4(u_anim1,0.,0.,0.); EmitVertex();\n" +" EndPrimitive();\n" +"\n" +" gl_Position = v + vec4(0.,1.0-u_anim1,0.,0.); EmitVertex();\n" +" gl_Position = v - vec4(0.,1.0-u_anim1,0.,0.); EmitVertex();\n" +" EndPrimitive();\n" +"}\n" +}; + + +static const char* fragSource = { +"#version 120\n" +"#extension GL_EXT_geometry_shader4 : enable\n" +"uniform float u_anim1;\n" +"varying vec4 v_color;\n" +"void main(void)\n" +"{\n" +" gl_FragColor = v_color;\n" +"}\n" +}; + +osg::Program* createShader() +{ + osg::Program* pgm = new osg::Program; + pgm->setName( "osgshader2 demo" ); + + pgm->addShader( new osg::Shader( osg::Shader::VERTEX, vertSource ) ); + pgm->addShader( new osg::Shader( osg::Shader::FRAGMENT, fragSource ) ); + +#ifdef ENABLE_GEOMETRY_SHADER + pgm->addShader( new osg::Shader( osg::Shader::GEOMETRY, geomSource ) ); + pgm->setParameter( GL_GEOMETRY_VERTICES_OUT_EXT, 4 ); + pgm->setParameter( GL_GEOMETRY_INPUT_TYPE_EXT, GL_POINTS ); + pgm->setParameter( GL_GEOMETRY_OUTPUT_TYPE_EXT, GL_LINE_STRIP ); +#endif + + return pgm; +} + +#endif + +/////////////////////////////////////////////////////////////////////////// + +class SomePoints : public osg::Geometry +{ +public: + SomePoints() + { + osg::Vec4Array* cAry = new osg::Vec4Array; + setColorArray( cAry ); + setColorBinding( osg::Geometry::BIND_OVERALL ); + cAry->push_back( osg::Vec4(1,1,1,1) ); + + osg::Vec3Array* vAry = new osg::Vec3Array; + setVertexArray( vAry ); + vAry->push_back( osg::Vec3(0,0,0) ); + vAry->push_back( osg::Vec3(0,1,0) ); + vAry->push_back( osg::Vec3(1,0,0) ); + vAry->push_back( osg::Vec3(1,1,0) ); + vAry->push_back( osg::Vec3(0,0,1) ); + vAry->push_back( osg::Vec3(0,1,1) ); + vAry->push_back( osg::Vec3(1,0,1) ); + vAry->push_back( osg::Vec3(1,1,1) ); + + addPrimitiveSet( new osg::DrawArrays( GL_POINTS, 0, vAry->size() ) ); + + osg::StateSet* sset = getOrCreateStateSet(); + sset->setMode( GL_LIGHTING, osg::StateAttribute::OFF ); + + // if things go wrong, fall back to big points + osg::Point* p = new osg::Point; + p->setSize(6); + sset->setAttribute( p ); + +#ifdef ENABLE_GLSL + sset->setAttribute( createShader() ); + + // a generic cyclic animation value + osg::Uniform* u_anim1( new osg::Uniform( "u_anim1", 0.0f ) ); + u_anim1->setUpdateCallback( new SineAnimation( 4, 0.5, 0.5 ) ); + sset->addUniform( u_anim1 ); +#endif + } +}; + +/////////////////////////////////////////////////////////////////////////// + +int main( int argc, char *argv[] ) +{ + osg::Geode* root( new osg::Geode ); + root->addDrawable( new SomePoints ); + + osgViewer::Viewer viewer; + viewer.setSceneData( root ); + return viewer.run(); +} + +// vim: set sw=4 ts=8 et ic ai: diff --git a/include/osg/GL2Extensions b/include/osg/GL2Extensions index ab837f6de..bc5a6c362 100644 --- a/include/osg/GL2Extensions +++ b/include/osg/GL2Extensions @@ -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; }; } diff --git a/include/osg/Program b/include/osg/Program index c9d35e642..9958c1d12 100644 --- a/include/osg/Program +++ b/include/osg/Program @@ -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 > ShaderList; ShaderList _shaderList; + /** Parameters maintained with glProgramParameteriEXT */ + GLint _geometryVerticesOut; + GLint _geometryInputType; + GLint _geometryOutputType; + private: Program& operator=(const Program&); // disallowed }; diff --git a/include/osg/Shader b/include/osg/Shader index a1791ba24..e9fd4f4d6 100644 --- a/include/osg/Shader +++ b/include/osg/Shader @@ -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 }; diff --git a/include/osg/Uniform b/include/osg/Uniform index 68e909f9d..3a6dba21c 100644 --- a/include/osg/Uniform +++ b/include/osg/Uniform @@ -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; diff --git a/src/osg/Program.cpp b/src/osg/Program.cpp index 85df1026a..b85c4db3a 100644 --- a/src/osg/Program.cpp +++ b/src/osg/Program.cpp @@ -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 @@ -13,7 +14,7 @@ */ /* file: src/osg/Program.cpp - * author: Mike Weiblen 2006-03-25 + * author: Mike Weiblen 2008-01-02 */ #include @@ -54,6 +55,8 @@ GL2Extensions::GL2Extensions(const GL2Extensions& rhs) : osg::Referenced() _isVertexShaderSupported = rhs._isVertexShaderSupported; _isFragmentShaderSupported = rhs._isFragmentShaderSupported; _isLanguage100Supported = rhs._isLanguage100Supported; + _isGeometryShader4Supported = rhs._isGeometryShader4Supported; + _isGpuShader4Supported = rhs._isGpuShader4Supported; _glBlendEquationSeparate = rhs._glBlendEquationSeparate; _glDrawBuffers = rhs._glDrawBuffers; @@ -154,8 +157,32 @@ GL2Extensions::GL2Extensions(const GL2Extensions& rhs) : osg::Referenced() _glDeleteObjectARB = rhs._glDeleteObjectARB; _glGetHandleARB = rhs._glGetHandleARB; + // GL 2.1 + _glUniformMatrix2x3fv = rhs._glUniformMatrix2x3fv; + _glUniformMatrix3x2fv = rhs._glUniformMatrix3x2fv; + _glUniformMatrix2x4fv = rhs._glUniformMatrix2x4fv; + _glUniformMatrix4x2fv = rhs._glUniformMatrix4x2fv; + _glUniformMatrix3x4fv = rhs._glUniformMatrix3x4fv; + _glUniformMatrix4x3fv = rhs._glUniformMatrix4x3fv; + + // EXT_geometry_shader4 + _glProgramParameteri = rhs._glProgramParameteri; + _glFramebufferTexture = rhs._glFramebufferTexture; + _glFramebufferTextureLayer = rhs._glFramebufferTextureLayer; + _glFramebufferTextureFace = rhs._glFramebufferTextureFace; + + // EXT_gpu_shader4 + _glGetUniformuiv = rhs._glGetUniformuiv; _glBindFragDataLocation = rhs._glBindFragDataLocation; _glGetFragDataLocation = rhs._glGetFragDataLocation; + _glUniform1ui = rhs._glUniform1ui; + _glUniform2ui = rhs._glUniform2ui; + _glUniform3ui = rhs._glUniform3ui; + _glUniform4ui = rhs._glUniform4ui; + _glUniform1uiv = rhs._glUniform1uiv; + _glUniform2uiv = rhs._glUniform2uiv; + _glUniform3uiv = rhs._glUniform3uiv; + _glUniform4uiv = rhs._glUniform4uiv; } @@ -169,6 +196,8 @@ void GL2Extensions::lowestCommonDenominator(const GL2Extensions& rhs) if (!rhs._isVertexShaderSupported) _isVertexShaderSupported = false; if (!rhs._isFragmentShaderSupported) _isFragmentShaderSupported = false; if (!rhs._isLanguage100Supported) _isLanguage100Supported = false; + if (!rhs._isGeometryShader4Supported) _isGeometryShader4Supported = false; + if (!rhs._isGpuShader4Supported) _isGpuShader4Supported = false; if (!rhs._glBlendEquationSeparate) _glBlendEquationSeparate = 0; if (!rhs._glDrawBuffers) _glDrawBuffers = 0; @@ -269,8 +298,32 @@ void GL2Extensions::lowestCommonDenominator(const GL2Extensions& rhs) if (!rhs._glDeleteObjectARB) _glDeleteObjectARB = 0; if (!rhs._glGetHandleARB) _glGetHandleARB = 0; + // GL 2.1 + if (!rhs._glUniformMatrix2x3fv) _glUniformMatrix2x3fv = 0; + if (!rhs._glUniformMatrix3x2fv) _glUniformMatrix3x2fv = 0; + if (!rhs._glUniformMatrix2x4fv) _glUniformMatrix2x4fv = 0; + if (!rhs._glUniformMatrix4x2fv) _glUniformMatrix4x2fv = 0; + if (!rhs._glUniformMatrix3x4fv) _glUniformMatrix3x4fv = 0; + if (!rhs._glUniformMatrix4x3fv) _glUniformMatrix4x3fv = 0; + + // EXT_geometry_shader4 + if (!rhs._glProgramParameteri) _glProgramParameteri = 0; + if (!rhs._glFramebufferTexture) _glFramebufferTexture = 0; + if (!rhs._glFramebufferTextureLayer) _glFramebufferTextureLayer = 0; + if (!rhs._glFramebufferTextureFace) _glFramebufferTextureFace = 0; + + // EXT_gpu_shader4 + if (!rhs._glGetUniformuiv) _glGetUniformuiv = 0; if (!rhs._glBindFragDataLocation) _glBindFragDataLocation = 0; if (!rhs._glGetFragDataLocation) _glGetFragDataLocation = 0; + if (!rhs._glUniform1ui) _glUniform1ui = 0; + if (!rhs._glUniform2ui) _glUniform2ui = 0; + if (!rhs._glUniform3ui) _glUniform3ui = 0; + if (!rhs._glUniform4ui) _glUniform4ui = 0; + if (!rhs._glUniform1uiv) _glUniform1uiv = 0; + if (!rhs._glUniform2uiv) _glUniform2uiv = 0; + if (!rhs._glUniform3uiv) _glUniform3uiv = 0; + if (!rhs._glUniform4uiv) _glUniform4uiv = 0; } @@ -290,6 +343,8 @@ void GL2Extensions::setupGL2Extensions(unsigned int contextID) _isVertexShaderSupported = osg::isGLExtensionSupported(contextID,"GL_ARB_vertex_shader"); _isFragmentShaderSupported = osg::isGLExtensionSupported(contextID,"GL_ARB_fragment_shader"); _isLanguage100Supported = osg::isGLExtensionSupported(contextID,"GL_ARB_shading_language_100"); + _isGeometryShader4Supported = osg::isGLExtensionSupported(contextID,"GL_EXT_geometry_shader4"); + _isGpuShader4Supported = osg::isGLExtensionSupported(contextID,"GL_EXT_gpu_shader4"); if( isGlslSupported() ) { @@ -409,12 +464,32 @@ void GL2Extensions::setupGL2Extensions(unsigned int contextID) _glDeleteObjectARB = osg::getGLExtensionFuncPtr("glDeleteObjectARB"); _glGetHandleARB = osg::getGLExtensionFuncPtr("glGetHandleARB"); - // v2.1 check also for EXT and ARB names, since this extension can became ARB later - _glBindFragDataLocation = osg::getGLExtensionFuncPtr("glBindFragDataLocation", "glBindFragDataLocationARB"); - if (_glBindFragDataLocation == NULL) _glBindFragDataLocation = osg::getGLExtensionFuncPtr("glBindFragDataLocationEXT"); - _glGetFragDataLocation = osg::getGLExtensionFuncPtr("glGetFragDataLocation", "glGetFragDataLocationARB"); - if (_glGetFragDataLocation == NULL) _glGetFragDataLocation = osg::getGLExtensionFuncPtr("glGetFragDataLocationEXT"); + // GL 2.1 + _glUniformMatrix2x3fv = osg::getGLExtensionFuncPtr( "glUniformMatrix2x3fv" ); + _glUniformMatrix3x2fv = osg::getGLExtensionFuncPtr( "glUniformMatrix3x2fv" ); + _glUniformMatrix2x4fv = osg::getGLExtensionFuncPtr( "glUniformMatrix2x4fv" ); + _glUniformMatrix4x2fv = osg::getGLExtensionFuncPtr( "glUniformMatrix4x2fv" ); + _glUniformMatrix3x4fv = osg::getGLExtensionFuncPtr( "glUniformMatrix3x4fv" ); + _glUniformMatrix4x3fv = osg::getGLExtensionFuncPtr( "glUniformMatrix4x3fv" ); + // EXT_geometry_shader4 + _glProgramParameteri = osg::getGLExtensionFuncPtr( "glProgramParameteri", "glProgramParameteriEXT" ); + _glFramebufferTexture = osg::getGLExtensionFuncPtr( "glFramebufferTexture", "glFramebufferTextureEXT" ); + _glFramebufferTextureLayer = osg::getGLExtensionFuncPtr( "glFramebufferTextureLayer", "glFramebufferTextureLayerEXT" ); + _glFramebufferTextureFace = osg::getGLExtensionFuncPtr( "glFramebufferTextureFace", "glFramebufferTextureFaceEXT" ); + + // EXT_gpu_shader4 + _glGetUniformuiv = osg::getGLExtensionFuncPtr( "glGetUniformuiv", "glGetUniformuivEXT" ); + _glBindFragDataLocation = osg::getGLExtensionFuncPtr( "glBindFragDataLocation", "glBindFragDataLocationEXT" ); + _glGetFragDataLocation = osg::getGLExtensionFuncPtr( "glGetFragDataLocation", "glGetFragDataLocationEXT" ); + _glUniform1ui = osg::getGLExtensionFuncPtr( "glUniform1ui", "glUniform1uiEXT" ); + _glUniform2ui = osg::getGLExtensionFuncPtr( "glUniform2ui", "glUniform2uiEXT" ); + _glUniform3ui = osg::getGLExtensionFuncPtr( "glUniform3ui", "glUniform3uiEXT" ); + _glUniform4ui = osg::getGLExtensionFuncPtr( "glUniform4ui", "glUniform4uiEXT" ); + _glUniform1uiv = osg::getGLExtensionFuncPtr( "glUniform1uiv", "glUniform1uivEXT" ); + _glUniform2uiv = osg::getGLExtensionFuncPtr( "glUniform2uiv", "glUniform2uivEXT" ); + _glUniform3uiv = osg::getGLExtensionFuncPtr( "glUniform3uiv", "glUniform3uivEXT" ); + _glUniform4uiv = osg::getGLExtensionFuncPtr( "glUniform4uiv", "glUniform4uivEXT" ); } @@ -1795,12 +1870,158 @@ void GL2Extensions::glVertexAttribPointer(GLuint index, GLint size, GLenum type, } } -void GL2Extensions::glBindFragDataLocation(GLuint program, GLuint colorIndex, const GLchar *name) const + +void GL2Extensions::glUniformMatrix2x3fv( GLint location, GLsizei count, GLboolean transpose, const GLfloat* value ) const +{ + if (_glUniformMatrix2x3fv) + { + typedef void (APIENTRY * UniformMatrix2x3fvProc)( GLint location, GLsizei count, GLboolean transpose, const GLfloat* value ); + ((UniformMatrix2x3fvProc)_glUniformMatrix2x3fv)( location, count, transpose, value ); + } + else + { + NotSupported( "glUniformMatrix2x3fv" ); + } +} + +void GL2Extensions::glUniformMatrix3x2fv( GLint location, GLsizei count, GLboolean transpose, const GLfloat* value ) const +{ + if (_glUniformMatrix3x2fv) + { + typedef void (APIENTRY * UniformMatrix3x2fvProc)( GLint location, GLsizei count, GLboolean transpose, const GLfloat* value ); + ((UniformMatrix3x2fvProc)_glUniformMatrix3x2fv)( location, count, transpose, value ); + } + else + { + NotSupported( "glUniformMatrix3x2fv" ); + } +} + +void GL2Extensions::glUniformMatrix2x4fv( GLint location, GLsizei count, GLboolean transpose, const GLfloat* value ) const +{ + if (_glUniformMatrix2x4fv) + { + typedef void (APIENTRY * UniformMatrix2x4fvProc)( GLint location, GLsizei count, GLboolean transpose, const GLfloat* value ); + ((UniformMatrix2x4fvProc)_glUniformMatrix2x4fv)( location, count, transpose, value ); + } + else + { + NotSupported( "glUniformMatrix2x4fv" ); + } +} + +void GL2Extensions::glUniformMatrix4x2fv( GLint location, GLsizei count, GLboolean transpose, const GLfloat* value ) const +{ + if (_glUniformMatrix4x2fv) + { + typedef void (APIENTRY * UniformMatrix4x2fvProc)( GLint location, GLsizei count, GLboolean transpose, const GLfloat* value ); + ((UniformMatrix4x2fvProc)_glUniformMatrix4x2fv)( location, count, transpose, value ); + } + else + { + NotSupported( "glUniformMatrix4x2fv" ); + } +} + +void GL2Extensions::glUniformMatrix3x4fv( GLint location, GLsizei count, GLboolean transpose, const GLfloat* value ) const +{ + if (_glUniformMatrix3x4fv) + { + typedef void (APIENTRY * UniformMatrix3x4fvProc)( GLint location, GLsizei count, GLboolean transpose, const GLfloat* value ); + ((UniformMatrix3x4fvProc)_glUniformMatrix3x4fv)( location, count, transpose, value ); + } + else + { + NotSupported( "glUniformMatrix3x4fv" ); + } +} + +void GL2Extensions::glUniformMatrix4x3fv( GLint location, GLsizei count, GLboolean transpose, const GLfloat* value ) const +{ + if (_glUniformMatrix4x3fv) + { + typedef void (APIENTRY * UniformMatrix4x3fvProc)( GLint location, GLsizei count, GLboolean transpose, const GLfloat* value ); + ((UniformMatrix4x3fvProc)_glUniformMatrix4x3fv)( location, count, transpose, value ); + } + else + { + NotSupported( "glUniformMatrix4x3fv" ); + } +} + + +void GL2Extensions::glProgramParameteri( GLuint program, GLenum pname, GLint value ) const +{ + if (_glProgramParameteri) + { + typedef void (APIENTRY * ProgramParameteriProc)( GLuint program, GLenum pname, GLint value ); + ((ProgramParameteriProc)_glProgramParameteri)( program, pname, value ); + } + else + { + NotSupported( "glProgramParameteri" ); + } +} + +void GL2Extensions::glFramebufferTexture( GLenum target, GLenum attachment, GLuint texture, GLint level ) const +{ + if (_glFramebufferTexture) + { + typedef void (APIENTRY * FramebufferTextureProc)( GLenum target, GLenum attachment, GLuint texture, GLint level ); + ((FramebufferTextureProc)_glFramebufferTexture)( target, attachment, texture, level ); + } + else + { + NotSupported( "glFramebufferTexture" ); + } +} + +void GL2Extensions::glFramebufferTextureLayer( GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer ) const +{ + if (_glFramebufferTextureLayer) + { + typedef void (APIENTRY * FramebufferTextureLayerProc)( GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer ); + ((FramebufferTextureLayerProc)_glFramebufferTextureLayer)( target, attachment, texture, level, layer ); + } + else + { + NotSupported( "glFramebufferTextureLayer" ); + } +} + +void GL2Extensions::glFramebufferTextureFace( GLenum target, GLenum attachment, GLuint texture, GLint level, GLenum face ) const +{ + if (_glFramebufferTextureFace) + { + typedef void (APIENTRY * FramebufferTextureFaceProc)( GLenum target, GLenum attachment, GLuint texture, GLint level, GLenum face ); + ((FramebufferTextureFaceProc)_glFramebufferTextureFace)( target, attachment, texture, level, face ); + } + else + { + NotSupported( "glFramebufferTextureFace" ); + } +} + + +void GL2Extensions::glGetUniformuiv( GLuint program, GLint location, GLuint* params ) const +{ + if (_glGetUniformuiv) + { + typedef void (APIENTRY * GetUniformuivProc)( GLuint program, GLint location, GLuint* params ); + ((GetUniformuivProc)_glGetUniformuiv)( program, location, params ); + } + else + { + NotSupported( "glGetUniformuiv" ); + } +} + +void GL2Extensions::glBindFragDataLocation( GLuint program, GLuint color, const GLchar* name ) const { if (_glBindFragDataLocation) { - typedef void (APIENTRY * BindFragDataLocationProc)(GLuint , GLuint, const GLchar*); - ((BindFragDataLocationProc)_glBindFragDataLocation)(program, colorIndex, name); + typedef void (APIENTRY * BindFragDataLocationProc)( GLuint program, GLuint color, const GLchar* name ); + ((BindFragDataLocationProc)_glBindFragDataLocation)( program, color, name ); } else { @@ -1808,12 +2029,12 @@ void GL2Extensions::glBindFragDataLocation(GLuint program, GLuint colorIndex, co } } -GLint GL2Extensions::glGetFragDataLocation(GLuint program, const GLchar *name) const +GLint GL2Extensions::glGetFragDataLocation( GLuint program, const GLchar* name ) const { if (_glGetFragDataLocation) { - typedef GLint (APIENTRY * GetFragDataLocationProc)(GLuint, const GLchar*); - return ((GetFragDataLocationProc)_glGetFragDataLocation)(program, name); + typedef GLint (APIENTRY * GetFragDataLocationProc)( GLuint program, const GLchar* name ); + return ((GetFragDataLocationProc)_glGetFragDataLocation)( program, name ); } else { @@ -1822,6 +2043,112 @@ GLint GL2Extensions::glGetFragDataLocation(GLuint program, const GLchar *name) c } } + +void GL2Extensions::glUniform1ui( GLint location, GLuint v0 ) const +{ + if (_glUniform1ui) + { + typedef void (APIENTRY * Uniform1uiProc)( GLint location, GLuint v0 ); + ((Uniform1uiProc)_glUniform1ui)( location, v0 ); + } + else + { + NotSupported( "glUniform1ui" ); + } +} + +void GL2Extensions::glUniform2ui( GLint location, GLuint v0, GLuint v1 ) const +{ + if (_glUniform2ui) + { + typedef void (APIENTRY * Uniform2uiProc)( GLint location, GLuint v0, GLuint v1 ); + ((Uniform2uiProc)_glUniform2ui)( location, v0, v1 ); + } + else + { + NotSupported( "glUniform2ui" ); + } +} + +void GL2Extensions::glUniform3ui( GLint location, GLuint v0, GLuint v1, GLuint v2 ) const +{ + if (_glUniform3ui) + { + typedef void (APIENTRY * Uniform3uiProc)( GLint location, GLuint v0, GLuint v1, GLuint v2 ); + ((Uniform3uiProc)_glUniform3ui)( location, v0, v1, v2 ); + } + else + { + NotSupported( "glUniform3ui" ); + } +} + +void GL2Extensions::glUniform4ui( GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3 ) const +{ + if (_glUniform4ui) + { + typedef void (APIENTRY * Uniform4uiProc)( GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3 ); + ((Uniform4uiProc)_glUniform4ui)( location, v0, v1, v2, v3 ); + } + else + { + NotSupported( "glUniform4ui" ); + } +} + +void GL2Extensions::glUniform1uiv( GLint location, GLsizei count, const GLuint *value ) const +{ + if (_glUniform1uiv) + { + typedef void (APIENTRY * Uniform1uivProc)( GLint location, GLsizei count, const GLuint *value ); + ((Uniform1uivProc)_glUniform1uiv)( location, count, value ); + } + else + { + NotSupported( "glUniform1uiv" ); + } +} + +void GL2Extensions::glUniform2uiv( GLint location, GLsizei count, const GLuint *value ) const +{ + if (_glUniform2uiv) + { + typedef void (APIENTRY * Uniform2uivProc)( GLint location, GLsizei count, const GLuint *value ); + ((Uniform2uivProc)_glUniform2uiv)( location, count, value ); + } + else + { + NotSupported( "glUniform2uiv" ); + } +} + +void GL2Extensions::glUniform3uiv( GLint location, GLsizei count, const GLuint *value ) const +{ + if (_glUniform3uiv) + { + typedef void (APIENTRY * Uniform3uivProc)( GLint location, GLsizei count, const GLuint *value ); + ((Uniform3uivProc)_glUniform3uiv)( location, count, value ); + } + else + { + NotSupported( "glUniform3uiv" ); + } +} + +void GL2Extensions::glUniform4uiv( GLint location, GLsizei count, const GLuint *value ) const +{ + if (_glUniform4uiv) + { + typedef void (APIENTRY * Uniform4uivProc)( GLint location, GLsizei count, const GLuint *value ); + ((Uniform4uivProc)_glUniform4uiv)( location, count, value ); + } + else + { + NotSupported( "glUniform4uiv" ); + } +} + + /////////////////////////////////////////////////////////////////////////// // C++-friendly convenience methods @@ -1989,7 +2316,9 @@ void Program::discardDeletedGlPrograms(unsigned int contextID) // osg::Program /////////////////////////////////////////////////////////////////////////// -Program::Program() +Program::Program() : + _geometryVerticesOut(0), _geometryInputType(GL_TRIANGLES), + _geometryOutputType(GL_TRIANGLE_STRIP) { } @@ -1998,6 +2327,9 @@ Program::Program(const Program& rhs, const osg::CopyOp& copyop): osg::StateAttribute(rhs, copyop) { osg::notify(osg::FATAL) << "how got here?" << std::endl; + _geometryVerticesOut = rhs._geometryVerticesOut; + _geometryInputType = rhs._geometryInputType; + _geometryOutputType = rhs._geometryOutputType; } @@ -2023,6 +2355,15 @@ int Program::compare(const osg::StateAttribute& sa) const if( getName() < rhs.getName() ) return -1; if( rhs.getName() < getName() ) return 1; + if( _geometryVerticesOut < rhs._geometryVerticesOut ) return -1; + if( rhs._geometryVerticesOut < _geometryVerticesOut ) return 1; + + if( _geometryInputType < rhs._geometryInputType ) return -1; + if( rhs._geometryInputType < _geometryInputType ) return 1; + + if( _geometryOutputType < rhs._geometryOutputType ) return -1; + if( rhs._geometryOutputType < _geometryOutputType ) return 1; + ShaderList::const_iterator litr=_shaderList.begin(); ShaderList::const_iterator ritr=rhs._shaderList.begin(); for(; @@ -2149,6 +2490,41 @@ bool Program::removeShader( Shader* shader ) } +void Program::setParameter( GLenum pname, GLint value ) +{ + switch( pname ) + { + case GL_GEOMETRY_VERTICES_OUT_EXT: + _geometryVerticesOut = value; + dirtyProgram(); + break; + case GL_GEOMETRY_INPUT_TYPE_EXT: + _geometryInputType = value; + dirtyProgram(); // needed? + break; + case GL_GEOMETRY_OUTPUT_TYPE_EXT: + _geometryOutputType = value; + dirtyProgram(); // needed? + break; + default: + osg::notify(osg::WARN) << "setParameter invalid param " << pname << std::endl; + break; + } +} + +GLint Program::getParameter( GLenum pname ) const +{ + switch( pname ) + { + case GL_GEOMETRY_VERTICES_OUT_EXT: return _geometryVerticesOut; + case GL_GEOMETRY_INPUT_TYPE_EXT: return _geometryInputType; + case GL_GEOMETRY_OUTPUT_TYPE_EXT: return _geometryOutputType; + } + osg::notify(osg::WARN) << "getParameter invalid param " << pname << std::endl; + return 0; +} + + void Program::addBindAttribLocation( const std::string& name, GLuint index ) { _attribBindingList[name] = index; @@ -2288,6 +2664,10 @@ void Program::PerContextProgram::linkProgram() << " contextID=" << _contextID << std::endl; + _extensions->glProgramParameteri( _glProgramHandle, GL_GEOMETRY_VERTICES_OUT_EXT, _program->_geometryVerticesOut ); + _extensions->glProgramParameteri( _glProgramHandle, GL_GEOMETRY_INPUT_TYPE_EXT, _program->_geometryInputType ); + _extensions->glProgramParameteri( _glProgramHandle, GL_GEOMETRY_OUTPUT_TYPE_EXT, _program->_geometryOutputType ); + // Detach removed shaders for( unsigned int i=0; i < _shadersToDetach.size(); ++i ) { diff --git a/src/osg/Shader.cpp b/src/osg/Shader.cpp index 8fd0cc598..22a8982d9 100644 --- a/src/osg/Shader.cpp +++ b/src/osg/Shader.cpp @@ -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 @@ -13,7 +14,7 @@ */ /* file: src/osg/Shader.cpp - * author: Mike Weiblen 2005-06-15 + * author: Mike Weiblen 2008-01-02 */ #include @@ -191,6 +192,7 @@ const char* Shader::getTypename() const { case VERTEX: return "VERTEX"; case FRAGMENT: return "FRAGMENT"; + case GEOMETRY: return "GEOMETRY"; default: return "UNDEFINED"; } } @@ -200,6 +202,7 @@ Shader::Type Shader::getTypeId( const std::string& tname ) { if( tname == "VERTEX" ) return VERTEX; if( tname == "FRAGMENT" ) return FRAGMENT; + if( tname == "GEOMETRY" ) return GEOMETRY; return UNDEFINED; } diff --git a/src/osg/Uniform.cpp b/src/osg/Uniform.cpp index bed28ec58..b5d9e63ce 100644 --- a/src/osg/Uniform.cpp +++ b/src/osg/Uniform.cpp @@ -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: src/osg/Uniform.cpp - * author: Mike Weiblen 2006-05-15 + * author: Mike Weiblen 2008-01-02 */ #include @@ -273,7 +274,34 @@ const char* Uniform::getTypename( Type t ) case SAMPLER_2D_SHADOW: return "sampler2DShadow"; case SAMPLER_1D_ARRAY_SHADOW: return "sampler1DArrayShadow"; case SAMPLER_2D_ARRAY_SHADOW: return "sampler2DArrayShadow"; - default: return "UNDEFINED"; + case FLOAT_MAT2x3: return "mat2x3"; + case FLOAT_MAT2x4: return "mat2x4"; + case FLOAT_MAT3x2: return "mat3x2"; + case FLOAT_MAT3x4: return "mat3x4"; + case FLOAT_MAT4x2: return "mat4x2"; + case FLOAT_MAT4x3: return "mat4x3"; + case SAMPLER_BUFFER: return "samplerBuffer"; + case SAMPLER_CUBE_SHADOW: return "samplerCubeShadow"; + case UNSIGNED_INT_VEC2: return "uvec2"; + case UNSIGNED_INT_VEC3: return "uvec3"; + case UNSIGNED_INT_VEC4: return "uvec4"; + case INT_SAMPLER_1D: return "isampler1D"; + case INT_SAMPLER_2D: return "isampler2D"; + case INT_SAMPLER_3D: return "isampler3D"; + case INT_SAMPLER_CUBE: return "isamplerCube"; + case INT_SAMPLER_2D_RECT: return "isampler2DRect"; + case INT_SAMPLER_1D_ARRAY: return "isampler1DArray"; + case INT_SAMPLER_2D_ARRAY: return "isampler2DArray"; + case INT_SAMPLER_BUFFER: return "isamplerBuffer"; + case UNSIGNED_INT_SAMPLER_1D: return "usampler1D"; + case UNSIGNED_INT_SAMPLER_2D: return "usampler2D"; + case UNSIGNED_INT_SAMPLER_3D: return "usampler3D"; + case UNSIGNED_INT_SAMPLER_CUBE: return "usamplerCube"; + case UNSIGNED_INT_SAMPLER_2D_RECT: return "usampler2DRect"; + case UNSIGNED_INT_SAMPLER_1D_ARRAY: return "usampler1DArray"; + case UNSIGNED_INT_SAMPLER_2D_ARRAY: return "usampler2DArray"; + case UNSIGNED_INT_SAMPLER_BUFFER: return "usamplerBuffer"; + default: return "UNDEFINED"; } } @@ -294,27 +322,60 @@ int Uniform::getTypeNumComponents( Type t ) case SAMPLER_2D_SHADOW: case SAMPLER_1D_ARRAY_SHADOW: case SAMPLER_2D_ARRAY_SHADOW: + case SAMPLER_BUFFER: + case SAMPLER_CUBE_SHADOW: + case INT_SAMPLER_1D: + case INT_SAMPLER_2D: + case INT_SAMPLER_3D: + case INT_SAMPLER_CUBE: + case INT_SAMPLER_2D_RECT: + case INT_SAMPLER_1D_ARRAY: + case INT_SAMPLER_2D_ARRAY: + case INT_SAMPLER_BUFFER: + case UNSIGNED_INT_SAMPLER_1D: + case UNSIGNED_INT_SAMPLER_2D: + case UNSIGNED_INT_SAMPLER_3D: + case UNSIGNED_INT_SAMPLER_CUBE: + case UNSIGNED_INT_SAMPLER_2D_RECT: + case UNSIGNED_INT_SAMPLER_1D_ARRAY: + case UNSIGNED_INT_SAMPLER_2D_ARRAY: + case UNSIGNED_INT_SAMPLER_BUFFER: return 1; case FLOAT_VEC2: case INT_VEC2: case BOOL_VEC2: + case UNSIGNED_INT_VEC2: return 2; case FLOAT_VEC3: case INT_VEC3: case BOOL_VEC3: + case UNSIGNED_INT_VEC3: return 3; case FLOAT_VEC4: case FLOAT_MAT2: case INT_VEC4: case BOOL_VEC4: + case UNSIGNED_INT_VEC4: return 4; + case FLOAT_MAT2x3: + case FLOAT_MAT3x2: + return 6; + + case FLOAT_MAT2x4: + case FLOAT_MAT4x2: + return 8; + case FLOAT_MAT3: return 9; + case FLOAT_MAT3x4: + case FLOAT_MAT4x3: + return 12; + case FLOAT_MAT4: return 16; @@ -337,9 +398,9 @@ Uniform::Type Uniform::getTypeId( const std::string& tname ) if( tname == "bvec2" ) return BOOL_VEC2; if( tname == "bvec3" ) return BOOL_VEC3; if( tname == "bvec4" ) return BOOL_VEC4; - if( tname == "mat2" ) return FLOAT_MAT2; - if( tname == "mat3" ) return FLOAT_MAT3; - if( tname == "mat4" ) return FLOAT_MAT4; + if( tname == "mat2" || tname == "mat2x2" ) return FLOAT_MAT2; + if( tname == "mat3" || tname == "mat3x3" ) return FLOAT_MAT3; + if( tname == "mat4" || tname == "mat4x4" ) return FLOAT_MAT4; if( tname == "sampler1D" ) return SAMPLER_1D; if( tname == "sampler2D" ) return SAMPLER_2D; if( tname == "sampler1DArray" ) return SAMPLER_1D_ARRAY; @@ -350,6 +411,34 @@ Uniform::Type Uniform::getTypeId( const std::string& tname ) if( tname == "sampler2DShadow" ) return SAMPLER_2D_SHADOW; if( tname == "sampler1DArrayShadow" ) return SAMPLER_1D_ARRAY_SHADOW; if( tname == "sampler2DArrayShadow" ) return SAMPLER_2D_ARRAY_SHADOW; + if( tname == "mat2x3" ) return FLOAT_MAT2x3; + if( tname == "mat2x4" ) return FLOAT_MAT2x4; + if( tname == "mat3x2" ) return FLOAT_MAT3x2; + if( tname == "mat3x4" ) return FLOAT_MAT3x4; + if( tname == "mat4x2" ) return FLOAT_MAT4x2; + if( tname == "mat4x3" ) return FLOAT_MAT4x3; + if( tname == "samplerBuffer" ) return SAMPLER_BUFFER; + if( tname == "samplerCubeShadow" ) return SAMPLER_CUBE_SHADOW; + if( tname == "uvec2" ) return UNSIGNED_INT_VEC2; + if( tname == "uvec3" ) return UNSIGNED_INT_VEC3; + if( tname == "uvec4" ) return UNSIGNED_INT_VEC4; + if( tname == "isampler1D" ) return INT_SAMPLER_1D; + if( tname == "isampler2D" ) return INT_SAMPLER_2D; + if( tname == "isampler3D" ) return INT_SAMPLER_3D; + if( tname == "isamplerCube" ) return INT_SAMPLER_CUBE; + if( tname == "isampler2DRect" ) return INT_SAMPLER_2D_RECT; + if( tname == "isampler1DArray" ) return INT_SAMPLER_1D_ARRAY; + if( tname == "isampler2DArray" ) return INT_SAMPLER_2D_ARRAY; + if( tname == "isamplerBuffer" ) return INT_SAMPLER_BUFFER; + if( tname == "usampler1D" ) return UNSIGNED_INT_SAMPLER_1D; + if( tname == "usampler2D" ) return UNSIGNED_INT_SAMPLER_2D; + if( tname == "usampler3D" ) return UNSIGNED_INT_SAMPLER_3D; + if( tname == "usamplerCube" ) return UNSIGNED_INT_SAMPLER_CUBE; + if( tname == "usampler2DRect" ) return UNSIGNED_INT_SAMPLER_2D_RECT; + if( tname == "usampler1DArray" ) return UNSIGNED_INT_SAMPLER_1D_ARRAY; + if( tname == "usampler2DArray" ) return UNSIGNED_INT_SAMPLER_2D_ARRAY; + if( tname == "usamplerBuffer" ) return UNSIGNED_INT_SAMPLER_BUFFER; + return UNDEFINED; } @@ -368,6 +457,24 @@ Uniform::Type Uniform::getGlApiType( Type t ) case SAMPLER_2D_SHADOW: case SAMPLER_1D_ARRAY_SHADOW: case SAMPLER_2D_ARRAY_SHADOW: + case SAMPLER_BUFFER: + case SAMPLER_CUBE_SHADOW: + case INT_SAMPLER_1D: + case INT_SAMPLER_2D: + case INT_SAMPLER_3D: + case INT_SAMPLER_CUBE: + case INT_SAMPLER_2D_RECT: + case INT_SAMPLER_1D_ARRAY: + case INT_SAMPLER_2D_ARRAY: + case INT_SAMPLER_BUFFER: + case UNSIGNED_INT_SAMPLER_1D: + case UNSIGNED_INT_SAMPLER_2D: + case UNSIGNED_INT_SAMPLER_3D: + case UNSIGNED_INT_SAMPLER_CUBE: + case UNSIGNED_INT_SAMPLER_2D_RECT: + case UNSIGNED_INT_SAMPLER_1D_ARRAY: + case UNSIGNED_INT_SAMPLER_2D_ARRAY: + case UNSIGNED_INT_SAMPLER_BUFFER: return INT; case BOOL_VEC2: @@ -395,6 +502,12 @@ GLenum Uniform::getInternalArrayType( Type t ) case FLOAT_MAT2: case FLOAT_MAT3: case FLOAT_MAT4: + case FLOAT_MAT2x3: + case FLOAT_MAT2x4: + case FLOAT_MAT3x2: + case FLOAT_MAT3x4: + case FLOAT_MAT4x2: + case FLOAT_MAT4x3: return GL_FLOAT; case INT: @@ -415,8 +528,30 @@ GLenum Uniform::getInternalArrayType( Type t ) case SAMPLER_2D_SHADOW: case SAMPLER_1D_ARRAY_SHADOW: case SAMPLER_2D_ARRAY_SHADOW: + case SAMPLER_BUFFER: + case SAMPLER_CUBE_SHADOW: + case INT_SAMPLER_1D: + case INT_SAMPLER_2D: + case INT_SAMPLER_3D: + case INT_SAMPLER_CUBE: + case INT_SAMPLER_2D_RECT: + case INT_SAMPLER_1D_ARRAY: + case INT_SAMPLER_2D_ARRAY: + case INT_SAMPLER_BUFFER: + case UNSIGNED_INT_SAMPLER_1D: + case UNSIGNED_INT_SAMPLER_2D: + case UNSIGNED_INT_SAMPLER_3D: + case UNSIGNED_INT_SAMPLER_CUBE: + case UNSIGNED_INT_SAMPLER_2D_RECT: + case UNSIGNED_INT_SAMPLER_1D_ARRAY: + case UNSIGNED_INT_SAMPLER_2D_ARRAY: + case UNSIGNED_INT_SAMPLER_BUFFER: return GL_INT; + // TODO integrate new types + case UNSIGNED_INT_VEC2: + case UNSIGNED_INT_VEC3: + case UNSIGNED_INT_VEC4: default: return 0; }