diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 00af399bd..59e6a22f4 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -23,6 +23,7 @@ IF(DYNAMIC_OPENSCENEGRAPH) ADD_SUBDIRECTORY(osg2cpp) ADD_SUBDIRECTORY(osganalysis) ADD_SUBDIRECTORY(osganimate) + ADD_SUBDIRECTORY(osgatomiccounter) ADD_SUBDIRECTORY(osgautocapture) ADD_SUBDIRECTORY(osgautotransform) ADD_SUBDIRECTORY(osgbillboard) diff --git a/examples/osgatomiccounter/CMakeLists.txt b/examples/osgatomiccounter/CMakeLists.txt new file mode 100644 index 000000000..c08d02a73 --- /dev/null +++ b/examples/osgatomiccounter/CMakeLists.txt @@ -0,0 +1,4 @@ +SET(TARGET_SRC osgatomiccounter.cpp) + +#### end var setup ### +SETUP_EXAMPLE(osgatomiccounter) diff --git a/examples/osgatomiccounter/osgatomiccounter.cpp b/examples/osgatomiccounter/osgatomiccounter.cpp new file mode 100644 index 000000000..9f58c8642 --- /dev/null +++ b/examples/osgatomiccounter/osgatomiccounter.cpp @@ -0,0 +1,238 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) 2012-2012 David Callu + * + * This application is open source and may be redistributed and/or modified + * freely and without restriction, both in commercial and non commercial applications, + * as long as this copyright notice is maintained. + * + * This application 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. +*/ + +#include +#include +#include +#include + +#include +#include + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + + +class AdaptNumPixelUniform : public osg::Camera::DrawCallback +{ + public: + AdaptNumPixelUniform() + { + _atomicCounterArray = new osg::UIntArray; + _atomicCounterArray->push_back(0); + } + + virtual void operator () (osg::RenderInfo& renderInfo) const + { + _acbb->readData(*renderInfo.getState(), *_atomicCounterArray); + unsigned int numPixel = osg::maximum(1u, _atomicCounterArray->front()); + + if ((renderInfo.getView()->getFrameStamp()->getFrameNumber() % 10) == 0) + { + OSG_INFO << "osgatomiccounter : draw " << numPixel << " pixels." << std::endl; + } + + _invNumPixelUniform->set( 1.0f / static_cast(numPixel) ); + } + + osg::ref_ptr _invNumPixelUniform; + osg::ref_ptr _atomicCounterArray; + osg::ref_ptr _acbb; +}; + + +osg::Program * createProgram() +{ + + std::stringstream vp; + vp << "#version 420 compatibility\n" + << "\n" + << "void main(void)\n" + << "{\n" + << " gl_Position = ftransform();\n" + << "}\n"; + osg::Shader * vpShader = new osg::Shader( osg::Shader::VERTEX, vp.str() ); + + + + std::stringstream fp; + fp << "#version 420 compatibility\n" + << "\n" + << "layout(binding = 0) uniform atomic_uint acRed;\n" + << "layout(binding = 0, offset = 4) uniform atomic_uint acGreen;\n" + << "layout(binding = 2) uniform atomic_uint acBlue;\n" + << "\n" + << "uniform float invNumPixel;\n" + << "\n" + << "void main(void)\n" + << "{\n" + << " float r = float(atomicCounterIncrement(acRed)) * invNumPixel;\n" + << " float g = float(atomicCounterIncrement(acGreen)) * invNumPixel;\n" + << " float b = float(atomicCounterIncrement(acBlue)) * invNumPixel;\n" + << " gl_FragColor = vec4(r, g, b, 1.0);\n" + << "}\n" + << "\n"; + osg::Shader * fpShader = new osg::Shader( osg::Shader::FRAGMENT, fp.str() ); + + osg::Program * program = new osg::Program; + program->addShader(vpShader); + program->addShader(fpShader); + + return program; +} + +class ResetAtomicCounter : public osg::StateAttributeCallback +{ + public: + virtual void operator () (osg::StateAttribute* sa, osg::NodeVisitor*) + { + osg::AtomicCounterBufferBinding * acbb = dynamic_cast(sa); + if (acbb) + { + osg::AtomicCounterBufferObject * acbo = dynamic_cast(acbb->getBufferObject()); + if (acbo && acbo->getBufferData(0)) + { + acbo->getBufferData(0)->dirty(); + } + } + } +}; + + +int main(int argc, char** argv) +{ + // use an ArgumentParser object to manage the program arguments. + osg::ArgumentParser arguments(&argc,argv); + + arguments.getApplicationUsage()->setApplicationName(arguments.getApplicationName()); + arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is a simple example which show draw order of pixel."); + arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] filename ..."); + + osgViewer::Viewer viewer(arguments); + + unsigned int helpType = 0; + if ((helpType = arguments.readHelpType())) + { + arguments.getApplicationUsage()->write(std::cout, helpType); + return 1; + } + + // report any errors if they have occurred when parsing the program arguments. + if (arguments.errors()) + { + arguments.writeErrorMessages(std::cout); + return 1; + } + + // set up the camera manipulators. + viewer.setCameraManipulator( new osgGA::TrackballManipulator() ); + + // add the state manipulator + viewer.addEventHandler( new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()) ); + + // add the thread model handler + viewer.addEventHandler(new osgViewer::ThreadingHandler); + + // add the window size toggle handler + viewer.addEventHandler(new osgViewer::WindowSizeHandler); + + // add the stats handler + viewer.addEventHandler(new osgViewer::StatsHandler); + + // add the help handler + viewer.addEventHandler(new osgViewer::HelpHandler(arguments.getApplicationUsage())); + + // add the screen capture handler + viewer.addEventHandler(new osgViewer::ScreenCaptureHandler); + + // load the data + osg::ref_ptr loadedModel = osgDB::readNodeFiles(arguments); + if (!loadedModel) + { + osg::Geometry * quad = osg::createTexturedQuadGeometry(osg::Vec3f(-2.0f, 0.0f, -2.0f), + osg::Vec3f(2.0f, 0.0f, 0.0f), + osg::Vec3f(0.0f, 0.0f, 2.0f) ); + + osg::Geode * geode = new osg::Geode; + geode->addDrawable(quad); + loadedModel = geode; + } + + // any option left unread are converted into errors to write out later. + arguments.reportRemainingOptionsAsUnrecognized(); + + // report any errors if they have occurred when parsing the program arguments. + if (arguments.errors()) + { + arguments.writeErrorMessages(std::cout); + return 1; + } + + + osg::StateSet * ss = loadedModel->asGeode()->getDrawable(0)->getOrCreateStateSet(); + ss->setAttributeAndModes( createProgram(), osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE | osg::StateAttribute::PROTECTED ); + + ss = loadedModel->getOrCreateStateSet(); + osg::ref_ptr atomicCounterArrayRedAndGreen = new osg::UIntArray; + atomicCounterArrayRedAndGreen->push_back(0); + atomicCounterArrayRedAndGreen->push_back(0); + + osg::ref_ptr atomicCounterArrayBlue = new osg::UIntArray; + atomicCounterArrayBlue->push_back(0); + + osg::ref_ptr acboRedAndGreen = new osg::AtomicCounterBufferObject; + acboRedAndGreen->setUsage(GL_STREAM_COPY); + atomicCounterArrayRedAndGreen->setBufferObject(acboRedAndGreen.get()); + + osg::ref_ptr acboBlue = new osg::AtomicCounterBufferObject; + acboBlue->setUsage(GL_STREAM_COPY); + atomicCounterArrayBlue->setBufferObject(acboBlue.get()); + + osg::ref_ptr acbbRedAndGreen = new osg::AtomicCounterBufferBinding(0, acboRedAndGreen.get(), 0, sizeof(GLuint)*3); + ss->setAttributeAndModes(acbbRedAndGreen.get()); + + osg::ref_ptr acbbBlue = new osg::AtomicCounterBufferBinding(2, acboBlue.get(), 0, sizeof(GLuint)); + ss->setAttributeAndModes(acbbBlue.get()); + + acbbRedAndGreen->setUpdateCallback(new ResetAtomicCounter); + acbbBlue->setUpdateCallback(new ResetAtomicCounter); + + osg::ref_ptr invNumPixelUniform = new osg::Uniform("invNumPixel", 1.0f/(800.0f*600.0f)); + ss->addUniform( invNumPixelUniform.get() ); + + AdaptNumPixelUniform * drawCallback = new AdaptNumPixelUniform; + drawCallback->_invNumPixelUniform = invNumPixelUniform; + drawCallback->_acbb = acbbBlue; + + viewer.getCamera()->setFinalDrawCallback(drawCallback); + + // optimize the scene graph, remove redundant nodes and state etc. + osgUtil::Optimizer optimizer; + optimizer.optimize(loadedModel.get()); + + viewer.setSceneData( loadedModel.get() ); + + viewer.realize(); + + return viewer.run(); + +} diff --git a/include/osg/BufferIndexBinding b/include/osg/BufferIndexBinding index 544c0f9dc..83a459490 100644 --- a/include/osg/BufferIndexBinding +++ b/include/osg/BufferIndexBinding @@ -1,5 +1,6 @@ /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield * Copyright (C) 2010 Tim Moore + * Copyright (C) 2012 David Callu * * 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 @@ -15,6 +16,7 @@ #ifndef OSG_BUFFERINDEXBINDING #define OSG_BUFFERINDEXBINDING 1 +#include #include #include #include @@ -23,6 +25,7 @@ #define GL_TRANSFORM_FEEDBACK_BUFFER 0x8C8E #endif + namespace osg { class State; @@ -129,6 +132,38 @@ class OSG_EXPORT TransformFeedbackBufferBinding : public BufferIndexBinding return 0; } }; -} + +/** StateAttribute for binding a atomic counter buffer index target. + */ +class OSG_EXPORT AtomicCounterBufferBinding : public BufferIndexBinding +{ + public: + AtomicCounterBufferBinding(GLuint index=0); + /** Create a binding for a atomic counter buffer index target. + * @param index the index target + * @param bo associated buffer object + * @param offset offset into buffer object + * @param size size of data in buffer object + */ + AtomicCounterBufferBinding(GLuint index, BufferObject* bo, GLintptr offset, GLsizeiptr size); + AtomicCounterBufferBinding(const AtomicCounterBufferBinding& rhs, const CopyOp& copyop=CopyOp::SHALLOW_COPY); + META_StateAttribute(osg, AtomicCounterBufferBinding, ATOMICCOUNTERBUFFERBINDING); + + void readData(osg::State & state, osg::UIntArray & uintArray) const; + + virtual int compare(const StateAttribute& bb) const + { + COMPARE_StateAttribute_Types(AtomicCounterBufferBinding, bb) + + COMPARE_StateAttribute_Parameter(_target) + COMPARE_StateAttribute_Parameter(_index) + COMPARE_StateAttribute_Parameter(_bufferObject) + COMPARE_StateAttribute_Parameter(_offset) + COMPARE_StateAttribute_Parameter(_size) + return 0; + } +}; + +} // namespace osg #endif diff --git a/include/osg/BufferObject b/include/osg/BufferObject index 9693efa71..86b5a8897 100644 --- a/include/osg/BufferObject +++ b/include/osg/BufferObject @@ -1,4 +1,5 @@ /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield + * Copyright (C) 2012 David Callu * * 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 @@ -829,6 +830,17 @@ class OSG_EXPORT UniformBufferObject : public BufferObject virtual ~UniformBufferObject(); }; +class OSG_EXPORT AtomicCounterBufferObject : public BufferObject +{ + public: + AtomicCounterBufferObject(); + AtomicCounterBufferObject(const AtomicCounterBufferObject& ubo, const CopyOp& copyop=CopyOp::SHALLOW_COPY); + META_Object(osg, AtomicCounterBufferObject); + + protected: + virtual ~AtomicCounterBufferObject(); +}; + inline void GLBufferObject::bindBuffer() { _extensions->glBindBuffer(_profile._target,_glObjectID); diff --git a/include/osg/GL2Extensions b/include/osg/GL2Extensions index 55a4fa7c4..7feac7b64 100644 --- a/include/osg/GL2Extensions +++ b/include/osg/GL2Extensions @@ -4,6 +4,7 @@ * Copyright (C) 2007 Art Tevs * Copyright (C) 2008 Zebra Imaging * Copyright (C) 2010 VIRES Simulationstechnologie GmbH + * Copyright (C) 2012 David Callu * * This application is open source and may be redistributed and/or modified * freely and without restriction, both in commercial and non commercial @@ -157,7 +158,7 @@ typedef char GLchar; #endif // EXT_geometry_shader4 -#ifndef GL_GEOMETRY_SHADER_EXT +#ifndef GL_EXT_geometry_shader4 #define GL_GEOMETRY_SHADER_EXT 0x8DD9 #define GL_GEOMETRY_VERTICES_OUT_EXT 0x8DDA #define GL_GEOMETRY_INPUT_TYPE_EXT 0x8DDB @@ -181,7 +182,7 @@ typedef char GLchar; #endif // ARB_tesselation_shader -#ifndef GL_TESS_EVALUATION_SHADER +#ifndef GL_ARB_tesselation_shader #define GL_PATCHES 0x000E #define GL_PATCH_VERTICES 0x8E72 #define GL_PATCH_DEFAULT_INNER_LEVEL 0x8E73 @@ -217,7 +218,7 @@ typedef char GLchar; #endif // EXT_gpu_shader4 -#ifndef GL_INT_SAMPLER_2D_EXT +#ifndef GL_EXT_gpu_shader4 #define GL_SAMPLER_1D_ARRAY_EXT 0x8DC0 #define GL_SAMPLER_2D_ARRAY_EXT 0x8DC1 #define GL_SAMPLER_BUFFER_EXT 0x8DC2 @@ -248,7 +249,7 @@ typedef char GLchar; #endif // ARB_uniform_buffer_object -#ifndef GL_UNIFORM_BUFFER +#ifndef GL_ARB_uniform_buffer_object #define GL_UNIFORM_BUFFER 0x8A11 #define GL_UNIFORM_BUFFER_BINDING 0x8A28 #define GL_UNIFORM_BUFFER_START 0x8A29 @@ -284,14 +285,127 @@ typedef char GLchar; #define GL_INVALID_INDEX 0xFFFFFFFFu #endif -//ARB_get_program_binary -#ifndef GL_PROGRAM_BINARY_RETRIEVABLE_HINT +// ARB_get_program_binary +#ifndef GL_ARB_get_program_binary #define GL_PROGRAM_BINARY_RETRIEVABLE_HINT 0x8257 #define GL_PROGRAM_BINARY_LENGTH 0x8741 #define GL_NUM_PROGRAM_BINARY_FORMATS 0x87FE #define GL_PROGRAM_BINARY_FORMATS 0x87FF #endif +// ARB_gpu_shader_fp64 +#ifndef GL_ARB_gpu_shader_fp64 +#define GL_DOUBLE_VEC2 0x8FFC +#define GL_DOUBLE_VEC3 0x8FFD +#define GL_DOUBLE_VEC4 0x8FFE +#define GL_DOUBLE_MAT2 0x8F46 +#define GL_DOUBLE_MAT3 0x8F47 +#define GL_DOUBLE_MAT4 0x8F48 +#define GL_DOUBLE_MAT2x3 0x8F49 +#define GL_DOUBLE_MAT2x4 0x8F4A +#define GL_DOUBLE_MAT3x2 0x8F4B +#define GL_DOUBLE_MAT3x4 0x8F4C +#define GL_DOUBLE_MAT4x2 0x8F4D +#define GL_DOUBLE_MAT4x3 0x8F4E +#endif + +// ARB_texture_multisample +#ifndef GL_ARB_texture_multisample +#define GL_SAMPLER_2D_MULTISAMPLE 0x9108 +#define GL_INT_SAMPLER_2D_MULTISAMPLE 0x9109 +#define GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE 0x910A +#define GL_SAMPLER_2D_MULTISAMPLE_ARRAY 0x910B +#define GL_INT_SAMPLER_2D_MULTISAMPLE_ARRAY 0x910C +#define GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE_ARRAY 0x910D +#endif + +// GL_ARB_shader_image_load_store +#ifndef GL_ARB_shader_image_load_store +#define GL_IMAGE_1D 0x904C +#define GL_IMAGE_2D 0x904D +#define GL_IMAGE_3D 0x904E +#define GL_IMAGE_2D_RECT 0x904F +#define GL_IMAGE_CUBE 0x9050 +#define GL_IMAGE_BUFFER 0x9051 +#define GL_IMAGE_1D_ARRAY 0x9052 +#define GL_IMAGE_2D_ARRAY 0x9053 +#define GL_IMAGE_CUBE_MAP_ARRAY 0x9054 +#define GL_IMAGE_2D_MULTISAMPLE 0x9055 +#define GL_IMAGE_2D_MULTISAMPLE_ARRAY 0x9056 +#define GL_INT_IMAGE_1D 0x9057 +#define GL_INT_IMAGE_2D 0x9058 +#define GL_INT_IMAGE_3D 0x9059 +#define GL_INT_IMAGE_2D_RECT 0x905A +#define GL_INT_IMAGE_CUBE 0x905B +#define GL_INT_IMAGE_BUFFER 0x905C +#define GL_INT_IMAGE_1D_ARRAY 0x905D +#define GL_INT_IMAGE_2D_ARRAY 0x905E +#define GL_INT_IMAGE_CUBE_MAP_ARRAY 0x905F +#define GL_INT_IMAGE_2D_MULTISAMPLE 0x9060 +#define GL_INT_IMAGE_2D_MULTISAMPLE_ARRAY 0x9061 +#define GL_UNSIGNED_INT_IMAGE_1D 0x9062 +#define GL_UNSIGNED_INT_IMAGE_2D 0x9063 +#define GL_UNSIGNED_INT_IMAGE_3D 0x9064 +#define GL_UNSIGNED_INT_IMAGE_2D_RECT 0x9065 +#define GL_UNSIGNED_INT_IMAGE_CUBE 0x9066 +#define GL_UNSIGNED_INT_IMAGE_BUFFER 0x9067 +#define GL_UNSIGNED_INT_IMAGE_1D_ARRAY 0x9068 +#define GL_UNSIGNED_INT_IMAGE_2D_ARRAY 0x9069 +#define GL_UNSIGNED_INT_IMAGE_CUBE_MAP_ARRAY 0x906A +#define GL_UNSIGNED_INT_IMAGE_2D_MULTISAMPLE 0x906B +#define GL_UNSIGNED_INT_IMAGE_2D_MULTISAMPLE_ARRAY 0x906C +#endif + +#ifndef GL_VERSION_3_1 +#define GL_SAMPLER_2D_RECT 0x8B63 +#define GL_SAMPLER_2D_RECT_SHADOW 0x8B64 +#define GL_SAMPLER_BUFFER 0x8DC2 +#define GL_INT_SAMPLER_2D_RECT 0x8DCD +#define GL_INT_SAMPLER_BUFFER 0x8DD0 +#define GL_UNSIGNED_INT_SAMPLER_2D_RECT 0x8DD5 +#define GL_UNSIGNED_INT_SAMPLER_BUFFER 0x8DD8 +#endif + +#ifndef GL_VERSION_4_0 +#define GL_SAMPLER_CUBE_MAP_ARRAY 0x900C +#define GL_SAMPLER_CUBE_MAP_ARRAY_SHADOW 0x900D +#define GL_INT_SAMPLER_CUBE_MAP_ARRAY 0x900E +#define GL_UNSIGNED_INT_SAMPLER_CUBE_MAP_ARRAY 0x900F +#endif + +// ARB_shader_atomic_counters +#ifndef GL_ARB_shader_atomic_counters +#define GL_ATOMIC_COUNTER_BUFFER 0x92C0 +#define GL_ATOMIC_COUNTER_BUFFER_BINDING 0x92C1 +#define GL_ATOMIC_COUNTER_BUFFER_START 0x92C2 +#define GL_ATOMIC_COUNTER_BUFFER_SIZE 0x92C3 +#define GL_ATOMIC_COUNTER_BUFFER_DATA_SIZE 0x92C4 +#define GL_ATOMIC_COUNTER_BUFFER_ACTIVE_ATOMIC_COUNTERS 0x92C5 +#define GL_ATOMIC_COUNTER_BUFFER_ACTIVE_ATOMIC_COUNTER_INDICES 0x92C6 +#define GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_VERTEX_SHADER 0x92C7 +#define GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_TESS_CONTROL_SHADER 0x92C8 +#define GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_TESS_EVALUATION_SHADER 0x92C9 +#define GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_GEOMETRY_SHADER 0x92CA +#define GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_FRAGMENT_SHADER 0x92CB +#define GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS 0x92CC +#define GL_MAX_TESS_CONTROL_ATOMIC_COUNTER_BUFFERS 0x92CD +#define GL_MAX_TESS_EVALUATION_ATOMIC_COUNTER_BUFFERS 0x92CE +#define GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS 0x92CF +#define GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS 0x92D0 +#define GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS 0x92D1 +#define GL_MAX_VERTEX_ATOMIC_COUNTERS 0x92D2 +#define GL_MAX_TESS_CONTROL_ATOMIC_COUNTERS 0x92D3 +#define GL_MAX_TESS_EVALUATION_ATOMIC_COUNTERS 0x92D4 +#define GL_MAX_GEOMETRY_ATOMIC_COUNTERS 0x92D5 +#define GL_MAX_FRAGMENT_ATOMIC_COUNTERS 0x92D6 +#define GL_MAX_COMBINED_ATOMIC_COUNTERS 0x92D7 +#define GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE 0x92D8 +#define GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS 0x92DC +#define GL_ACTIVE_ATOMIC_COUNTER_BUFFERS 0x92D9 +#define GL_UNIFORM_ATOMIC_COUNTER_BUFFER_INDEX 0x92DA +#define GL_UNSIGNED_INT_ATOMIC_COUNTER 0x92DB +#endif + namespace osg { class OSG_EXPORT GL2Extensions : public osg::Referenced @@ -337,6 +451,12 @@ class OSG_EXPORT GL2Extensions : public osg::Referenced void setGetProgramBinarySupported(bool flag) { _isGetProgramBinarySupported = flag; } bool isGetProgramBinarySupported() {return _isGetProgramBinarySupported; } + void setGpuShaderFp64Supported(bool flag) { _isGpuShaderFp64Supported = flag; } + bool isGpuShaderFp64Supported() {return _isGpuShaderFp64Supported; } + + void setShaderAtomicCounterSupported(bool flag) { _isShaderAtomicCountersSupported = flag; } + bool isShaderAtomicCounterSupported() {return _isShaderAtomicCountersSupported; } + /** 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. @@ -496,6 +616,29 @@ class OSG_EXPORT GL2Extensions : public osg::Referenced void glGetProgramBinary(GLuint program, GLsizei bufSize, GLsizei *length, GLenum *binaryFormat, GLvoid *binary) const; void glProgramBinary(GLuint program, GLenum binaryFormat, const GLvoid *binary, GLsizei length) const; + // ARB_gpu_shader_fp64 + void glUniform1d( GLint location, GLdouble v0 ) const; + void glUniform2d( GLint location, GLdouble v0, GLdouble v1 ) const; + void glUniform3d( GLint location, GLdouble v0, GLdouble v1, GLdouble v2 ) const; + void glUniform4d( GLint location, GLdouble v0, GLdouble v1, GLdouble v2, GLdouble v3 ) const; + void glUniform1dv( GLint location, GLsizei count, const GLdouble *value ) const; + void glUniform2dv( GLint location, GLsizei count, const GLdouble *value ) const; + void glUniform3dv( GLint location, GLsizei count, const GLdouble *value ) const; + void glUniform4dv( GLint location, GLsizei count, const GLdouble *value ) const; + void glUniformMatrix2dv(GLint location, GLsizei count, GLboolean transpose, const GLdouble *value) const; + void glUniformMatrix3dv(GLint location, GLsizei count, GLboolean transpose, const GLdouble *value) const; + void glUniformMatrix4dv(GLint location, GLsizei count, GLboolean transpose, const GLdouble *value) const; + void glUniformMatrix2x3dv( GLint location, GLsizei count, GLboolean transpose, const GLdouble* value ) const; + void glUniformMatrix3x2dv( GLint location, GLsizei count, GLboolean transpose, const GLdouble* value ) const; + void glUniformMatrix2x4dv( GLint location, GLsizei count, GLboolean transpose, const GLdouble* value ) const; + void glUniformMatrix4x2dv( GLint location, GLsizei count, GLboolean transpose, const GLdouble* value ) const; + void glUniformMatrix3x4dv( GLint location, GLsizei count, GLboolean transpose, const GLdouble* value ) const; + void glUniformMatrix4x3dv( GLint location, GLsizei count, GLboolean transpose, const GLdouble* value ) const; + + // ARB_shader_atomic_counters + void glGetActiveAtomicCounterBufferiv( GLuint program, GLuint bufferIndex, GLenum pname, GLint* params ) const; + + protected: ~GL2Extensions() {} @@ -511,6 +654,8 @@ class OSG_EXPORT GL2Extensions : public osg::Referenced bool _isGpuShader4Supported; bool _isUniformBufferObjectSupported; bool _isGetProgramBinarySupported; + bool _isGpuShaderFp64Supported; + bool _isShaderAtomicCountersSupported; typedef void (GL_APIENTRY * BlendEquationSeparateProc)(GLenum modeRGB, GLenum modeAlpha); typedef void (GL_APIENTRY * DrawBuffersProc)(GLsizei n, const GLenum *bufs); @@ -641,6 +786,24 @@ class OSG_EXPORT GL2Extensions : public osg::Referenced typedef void (GL_APIENTRY * UniformBlockBindingProc)(GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding); typedef void (GL_APIENTRY * GetProgramBinaryProc)(GLuint program, GLsizei bufSize, GLsizei *length, GLenum *binaryFormat, GLvoid *binary); typedef void (GL_APIENTRY * ProgramBinaryProc)(GLuint program, GLenum binaryFormat, const GLvoid *binary, GLsizei length); + typedef void (GL_APIENTRY * Uniform1dProc)(GLint location, GLdouble v0); + typedef void (GL_APIENTRY * Uniform2dProc)(GLint location, GLdouble v0, GLdouble v1); + typedef void (GL_APIENTRY * Uniform3dProc)(GLint location, GLdouble v0, GLdouble v1, GLdouble v2); + typedef void (GL_APIENTRY * Uniform4dProc)(GLint location, GLdouble v0, GLdouble v1, GLdouble v2, GLdouble v3); + typedef void (GL_APIENTRY * Uniform1dvProc)(GLint location, GLsizei count, const GLdouble *value); + typedef void (GL_APIENTRY * Uniform2dvProc)(GLint location, GLsizei count, const GLdouble *value); + typedef void (GL_APIENTRY * Uniform3dvProc)(GLint location, GLsizei count, const GLdouble *value); + typedef void (GL_APIENTRY * Uniform4dvProc)(GLint location, GLsizei count, const GLdouble *value); + typedef void (GL_APIENTRY * UniformMatrix2dvProc)(GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); + typedef void (GL_APIENTRY * UniformMatrix3dvProc)(GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); + typedef void (GL_APIENTRY * UniformMatrix4dvProc)(GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); + typedef void (GL_APIENTRY * UniformMatrix2x3dvProc)( GLint location, GLsizei count, GLboolean transpose, const GLdouble* value ); + typedef void (GL_APIENTRY * UniformMatrix3x2dvProc)( GLint location, GLsizei count, GLboolean transpose, const GLdouble* value ); + typedef void (GL_APIENTRY * UniformMatrix2x4dvProc)( GLint location, GLsizei count, GLboolean transpose, const GLdouble* value ); + typedef void (GL_APIENTRY * UniformMatrix4x2dvProc)( GLint location, GLsizei count, GLboolean transpose, const GLdouble* value ); + typedef void (GL_APIENTRY * UniformMatrix3x4dvProc)( GLint location, GLsizei count, GLboolean transpose, const GLdouble* value ); + typedef void (GL_APIENTRY * UniformMatrix4x3dvProc)( GLint location, GLsizei count, GLboolean transpose, const GLdouble* value ); + typedef void (GL_APIENTRY * GetActiveAtomicCounterBufferivProc)( GLuint program, GLuint bufferIndex, GLenum pname, GLint* params ); BlendEquationSeparateProc _glBlendEquationSeparate; DrawBuffersProc _glDrawBuffers; @@ -781,9 +944,31 @@ class OSG_EXPORT GL2Extensions : public osg::Referenced GetActiveUniformBlockNameProc _glGetActiveUniformBlockName; UniformBlockBindingProc _glUniformBlockBinding; - //ARB_get_program_binary + // ARB_get_program_binary GetProgramBinaryProc _glGetProgramBinary; ProgramBinaryProc _glProgramBinary; + + // ARB_gpu_shader_fp64 + Uniform1dProc _glUniform1d; + Uniform2dProc _glUniform2d; + Uniform3dProc _glUniform3d; + Uniform4dProc _glUniform4d; + Uniform1dvProc _glUniform1dv; + Uniform2dvProc _glUniform2dv; + Uniform3dvProc _glUniform3dv; + Uniform4dvProc _glUniform4dv; + UniformMatrix2dvProc _glUniformMatrix2dv; + UniformMatrix3dvProc _glUniformMatrix3dv; + UniformMatrix4dvProc _glUniformMatrix4dv; + UniformMatrix2x3dvProc _glUniformMatrix2x3dv; + UniformMatrix3x2dvProc _glUniformMatrix3x2dv; + UniformMatrix2x4dvProc _glUniformMatrix2x4dv; + UniformMatrix4x2dvProc _glUniformMatrix4x2dv; + UniformMatrix3x4dvProc _glUniformMatrix3x4dv; + UniformMatrix4x3dvProc _glUniformMatrix4x3dv; + + // ARB_shader_atomic_counters + GetActiveAtomicCounterBufferivProc _glGetActiveAtomicCounterBufferiv; }; } diff --git a/include/osg/StateAttribute b/include/osg/StateAttribute index 2b312ec66..32b4cb6cd 100644 --- a/include/osg/StateAttribute +++ b/include/osg/StateAttribute @@ -187,7 +187,9 @@ class OSG_EXPORT StateAttribute : public Object OSGNVPARSE_PROGRAM_PARSER, UNIFORMBUFFERBINDING, - TRANSFORMFEEDBACKBUFFERBINDING + TRANSFORMFEEDBACKBUFFERBINDING, + + ATOMICCOUNTERBUFFERBINDING }; /** Simple pairing between an attribute type and the member within that attribute type group.*/ diff --git a/include/osg/Uniform b/include/osg/Uniform index 30be71ad5..2563559df 100644 --- a/include/osg/Uniform +++ b/include/osg/Uniform @@ -1,6 +1,7 @@ /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield * Copyright (C) 2003-2005 3Dlabs Inc. Ltd. * Copyright (C) 2008 Zebra Imaging + * Copyright (C) 2012 David Callu * * This application is open source and may be redistributed and/or modified * freely and without restriction, both in commercial and non commercial @@ -23,137 +24,341 @@ #include #include #include +#include +#include +#include #include #include +#include // for memset #include #include -#ifndef GL_SAMPLER_1D - #define GL_SAMPLER_1D 0x8B5D - #define GL_SAMPLER_2D 0x8B5E - #define GL_SAMPLER_3D 0x8B5F - #define GL_SAMPLER_1D_SHADOW 0x8B61 - #define GL_SAMPLER_2D_SHADOW 0x8B62 -#endif - namespace osg { // forward declare -class GL2Extensions; class NodeVisitor; /////////////////////////////////////////////////////////////////////////// // C++ classes to represent the GLSL-specific types. -class OSG_EXPORT Matrix2 +template +class MatrixTemplate { public: - Matrix2() { makeIdentity(); } - Matrix2( const Matrix2& mat ) { set(mat.ptr()); } - Matrix2( float a00, float a01, - float a10, float a11 ) + enum { col_count = ColN }; + enum { row_count = RowN }; + enum { value_count = ColN * RowN }; + + typedef T value_type; + + + public: + MatrixTemplate() {} + ~MatrixTemplate() {} + + value_type& operator()(int row, int col) { return _mat[row][col]; } + value_type operator()(int row, int col) const { return _mat[row][col]; } + + MatrixTemplate& operator = (const MatrixTemplate& rhs) + { + if( &rhs == this ) return *this; + set(rhs.ptr()); + return *this; + } + + void set(const MatrixTemplate& rhs) { set(rhs.ptr()); } + + void set(value_type const * const ptr) + { + value_type* local_ptr = (value_type*)_mat; + for(int i=0;i +class Matrix2Template : public MatrixTemplate +{ + public: + typedef MatrixTemplate base_class; + typedef typename base_class::value_type value_type; + + + public: + Matrix2Template() { makeIdentity(); } + Matrix2Template( const Matrix2Template& mat ) { set(mat.ptr()); } + Matrix2Template( value_type a00, value_type a01, + value_type a10, value_type a11 ) { set( a00, a01, a10, a11 ); } - ~Matrix2() {} - float& operator()(int row, int col) { return _mat[row][col]; } - float operator()(int row, int col) const { return _mat[row][col]; } + ~Matrix2Template() {} - Matrix2& operator = (const Matrix2& rhs) - { - if( &rhs == this ) return *this; - set(rhs.ptr()); - return *this; - } - - void set(const Matrix2& rhs) { set(rhs.ptr()); } - - void set(float const * const ptr) - { - float* local_ptr = (float*)_mat; - for(int i=0;i<4;++i) local_ptr[i]=ptr[i]; - } - - void set(float a00, float a01, - float a10, float a11) + void set(value_type a00, value_type a10, + value_type a01, value_type a11) { - _mat[0][0]=a00; _mat[0][1]=a01; - _mat[1][0]=a10; _mat[1][1]=a11; + base_class::_mat[0][0]=a00; base_class::_mat[1][0]=a10; + base_class::_mat[0][1]=a01; base_class::_mat[1][1]=a11; } - float* ptr() { return (float*)_mat; } - const float* ptr() const { return (const float*)_mat; } - - float& operator [] (int i) {return ptr()[i];} - float operator [] (int i) const {return ptr()[i];} - - void makeIdentity() { set( 1, 0, 0, 1 ); } - - protected: - float _mat[2][2]; + void makeIdentity() + { + set( 1, 0, + 0, 1 ); + } }; - -class OSG_EXPORT Matrix3 +template +class Matrix2x3Template : public MatrixTemplate { public: - Matrix3() { makeIdentity(); } - Matrix3( const Matrix3& mat ) { set(mat.ptr()); } - Matrix3( float a00, float a01, float a02, - float a10, float a11, float a12, - float a20, float a21, float a22 ) + typedef MatrixTemplate base_class; + typedef typename base_class::value_type value_type; + + + public: + Matrix2x3Template() { base_class::reset(); } + Matrix2x3Template( const Matrix2x3Template& mat ) { set(mat.ptr()); } + Matrix2x3Template( value_type a00, value_type a10, + value_type a01, value_type a11, + value_type a02, value_type a12 ) { - set( a00, a01, a02, a10, a11, a12, a20, a21, a22 ); + set( a00, a10, a01, a11, a02, a12 ); } - ~Matrix3() {} - float& operator()(int row, int col) { return _mat[row][col]; } - float operator()(int row, int col) const { return _mat[row][col]; } + ~Matrix2x3Template() {} - Matrix3& operator = (const Matrix3& rhs) - { - if( &rhs == this ) return *this; - set(rhs.ptr()); - return *this; - } - - void set(const Matrix3& rhs) { set(rhs.ptr()); } - - void set(float const * const ptr) - { - float* local_ptr = (float*)_mat; - for(int i=0;i<9;++i) local_ptr[i]=ptr[i]; - } - - void set(float a00, float a01, float a02, - float a10, float a11, float a12, - float a20, float a21, float a22 ) + void set(value_type a00, value_type a10, + value_type a01, value_type a11, + value_type a02, value_type a12) { - _mat[0][0]=a00; _mat[0][1]=a01; _mat[0][2]=a02; - _mat[1][0]=a10; _mat[1][1]=a11; _mat[1][2]=a12; - _mat[2][0]=a20; _mat[2][1]=a21; _mat[2][2]=a22; + base_class::_mat[0][0]=a00; base_class::_mat[1][0]=a10; + base_class::_mat[0][1]=a01; base_class::_mat[1][1]=a11; + base_class::_mat[0][2]=a02; base_class::_mat[1][2]=a12; } - - float* ptr() { return (float*)_mat; } - const float* ptr() const { return (const float*)_mat; } - - float& operator [] (int i) {return ptr()[i];} - float operator [] (int i) const {return ptr()[i];} - - void makeIdentity() { set( 1, 0, 0, 0, 1, 0, 0, 0, 1 ); } - - protected: - 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 +template +class Matrix2x4Template : public MatrixTemplate +{ + public: + typedef MatrixTemplate base_class; + typedef typename base_class::value_type value_type; + + + public: + Matrix2x4Template() { base_class::reset(); } + Matrix2x4Template( const Matrix2x4Template& mat ) { set(mat.ptr()); } + Matrix2x4Template( value_type a00, value_type a10, + value_type a01, value_type a11, + value_type a02, value_type a12, + value_type a03, value_type a13 ) + { + set( a00, a10, + a01, a11, + a02, a12, + a03, a13 ); + } + ~Matrix2x4Template() {} + + void set(value_type a00, value_type a10, + value_type a01, value_type a11, + value_type a02, value_type a12, + value_type a03, value_type a13) + { + base_class::_mat[0][0]=a00; base_class::_mat[1][0]=a10; + base_class::_mat[0][1]=a01; base_class::_mat[1][1]=a11; + base_class::_mat[0][2]=a02; base_class::_mat[1][2]=a12; + base_class::_mat[0][3]=a03; base_class::_mat[1][3]=a13; + } +}; + +template +class Matrix3x2Template : public MatrixTemplate +{ + public: + typedef MatrixTemplate base_class; + typedef typename base_class::value_type value_type; + + public: + Matrix3x2Template() { base_class::reset(); } + Matrix3x2Template( const Matrix3x2Template& mat ) { set(mat.ptr()); } + Matrix3x2Template( value_type a00, value_type a10, value_type a20, + value_type a01, value_type a11, value_type a21 ) + { + set( a00, a10, a20, + a01, a11, a21 ); + } + ~Matrix3x2Template() {} + + void set( value_type a00, value_type a10, value_type a20, + value_type a01, value_type a11, value_type a21 ) + { + base_class::_mat[0][0]=a00; base_class::_mat[1][0]=a10; base_class::_mat[2][0]=a20; + base_class::_mat[0][1]=a01; base_class::_mat[1][1]=a11; base_class::_mat[2][1]=a21; + } +}; + +template +class Matrix3Template : public MatrixTemplate +{ + public: + typedef MatrixTemplate base_class; + typedef typename base_class::value_type value_type; + + public: + Matrix3Template() { base_class::reset(); } + Matrix3Template( const Matrix3Template& mat ) { set(mat.ptr()); } + Matrix3Template( value_type a00, value_type a10, value_type a20, + value_type a01, value_type a11, value_type a21, + value_type a02, value_type a12, value_type a22 ) + { + set( a00, a10, a20, + a01, a11, a21, + a02, a12, a22 ); + } + ~Matrix3Template() {} + + void set( value_type a00, value_type a10, value_type a20, + value_type a01, value_type a11, value_type a21, + value_type a02, value_type a12, value_type a22 ) + { + base_class::_mat[0][0]=a00; base_class::_mat[1][0]=a10; base_class::_mat[2][0]=a20; + base_class::_mat[0][1]=a01; base_class::_mat[1][1]=a11; base_class::_mat[2][1]=a21; + base_class::_mat[0][2]=a02; base_class::_mat[1][2]=a12; base_class::_mat[2][2]=a22; + } + + void makeIdentity() + { + set( 1, 0, 0, + 0, 1, 0, + 0, 0, 1 ); + } +}; + +template +class Matrix3x4Template : public MatrixTemplate +{ + public: + typedef MatrixTemplate base_class; + typedef typename base_class::value_type value_type; + + public: + Matrix3x4Template() { base_class::reset(); } + Matrix3x4Template( const Matrix3x4Template& mat ) { set(mat.ptr()); } + Matrix3x4Template( value_type a00, value_type a10, value_type a20, + value_type a01, value_type a11, value_type a21, + value_type a02, value_type a12, value_type a22, + value_type a03, value_type a13, value_type a23 ) + { + set( a00, a10, a20, + a01, a11, a21, + a02, a12, a22, + a03, a13, a23 ); + } + ~Matrix3x4Template() {} + + void set( value_type a00, value_type a10, value_type a20, + value_type a01, value_type a11, value_type a21, + value_type a02, value_type a12, value_type a22, + value_type a03, value_type a13, value_type a23 ) + { + base_class::_mat[0][0]=a00; base_class::_mat[1][0]=a10; base_class::_mat[2][0]=a20; + base_class::_mat[0][1]=a01; base_class::_mat[1][1]=a11; base_class::_mat[2][1]=a21; + base_class::_mat[0][2]=a02; base_class::_mat[1][2]=a12; base_class::_mat[2][2]=a22; + base_class::_mat[0][3]=a03; base_class::_mat[1][3]=a13; base_class::_mat[2][3]=a23; + } +}; + +template +class Matrix4x2Template : public MatrixTemplate +{ + public: + typedef MatrixTemplate base_class; + typedef typename base_class::value_type value_type; + + public: + Matrix4x2Template() { base_class::reset(); } + Matrix4x2Template( const Matrix4x2Template& mat ) { set(mat.ptr()); } + Matrix4x2Template( value_type a00, value_type a10, value_type a20, value_type a30, + value_type a01, value_type a11, value_type a21, value_type a31 ) + { + set( a00, a10, a20, a30, + a01, a11, a21, a31 ); + } + ~Matrix4x2Template() {} + + void set( value_type a00, value_type a10, value_type a20, value_type a30, + value_type a01, value_type a11, value_type a21, value_type a31 ) + { + base_class::_mat[0][0]=a00; base_class::_mat[1][0]=a10; base_class::_mat[2][0]=a20; base_class::_mat[3][0]=a30; + base_class::_mat[0][1]=a01; base_class::_mat[1][1]=a11; base_class::_mat[2][1]=a21; base_class::_mat[3][1]=a31; + } +}; + +template +class Matrix4x3Template : public MatrixTemplate +{ + public: + typedef MatrixTemplate base_class; + typedef typename base_class::value_type value_type; + + public: + Matrix4x3Template() { base_class::reset(); } + Matrix4x3Template( const Matrix4x3Template& mat ) { set(mat.ptr()); } + Matrix4x3Template( value_type a00, value_type a10, value_type a20, value_type a30, + value_type a01, value_type a11, value_type a21, value_type a31, + value_type a02, value_type a12, value_type a22, value_type a32 ) + { + set( a00, a10, a20, a30, + a01, a11, a21, a31 ); + } + ~Matrix4x3Template() {} + + void set( value_type a00, value_type a10, value_type a20, value_type a30, + value_type a01, value_type a11, value_type a21, value_type a31, + value_type a02, value_type a12, value_type a22, value_type a32 ) + { + base_class::_mat[0][0]=a00; base_class::_mat[1][0]=a10; base_class::_mat[2][0]=a20; base_class::_mat[3][0]=a30; + base_class::_mat[0][1]=a01; base_class::_mat[1][1]=a11; base_class::_mat[2][1]=a21; base_class::_mat[3][1]=a31; + base_class::_mat[0][2]=a01; base_class::_mat[1][2]=a12; base_class::_mat[2][2]=a22; base_class::_mat[3][2]=a32; + } +}; + +typedef Matrix2Template Matrix2; +typedef Matrix2x3Template Matrix2x3; +typedef Matrix2x4Template Matrix2x4; + +typedef Matrix3x2Template Matrix3x2; +typedef Matrix3Template Matrix3; +typedef Matrix3x4Template Matrix3x4; + +typedef Matrix4x2Template Matrix4x2; +typedef Matrix4x3Template Matrix4x3; + + +typedef Matrix2Template Matrix2d; +typedef Matrix2x3Template Matrix2x3d; +typedef Matrix2x4Template Matrix2x4d; + +typedef Matrix3x2Template Matrix3x2d; +typedef Matrix3Template Matrix3d; +typedef Matrix3x4Template Matrix3x4d; + +typedef Matrix4x2Template Matrix4x2d; +typedef Matrix4x3Template Matrix4x3d; + /////////////////////////////////////////////////////////////////////////// @@ -163,62 +368,129 @@ class OSG_EXPORT Uniform : public Object { public: enum Type { - FLOAT = GL_FLOAT, + FLOAT = GL_FLOAT, FLOAT_VEC2 = GL_FLOAT_VEC2, FLOAT_VEC3 = GL_FLOAT_VEC3, FLOAT_VEC4 = GL_FLOAT_VEC4, - INT = GL_INT, + + DOUBLE = GL_DOUBLE, + DOUBLE_VEC2 = GL_DOUBLE_VEC2, + DOUBLE_VEC3 = GL_DOUBLE_VEC3, + DOUBLE_VEC4 = GL_DOUBLE_VEC4, + + INT = GL_INT, INT_VEC2 = GL_INT_VEC2, INT_VEC3 = GL_INT_VEC3, INT_VEC4 = GL_INT_VEC4, - BOOL = GL_BOOL, + + UNSIGNED_INT = GL_UNSIGNED_INT, + UNSIGNED_INT_VEC2 = GL_UNSIGNED_INT_VEC2_EXT, + UNSIGNED_INT_VEC3 = GL_UNSIGNED_INT_VEC3_EXT, + UNSIGNED_INT_VEC4 = GL_UNSIGNED_INT_VEC4_EXT, + + BOOL = GL_BOOL, BOOL_VEC2 = GL_BOOL_VEC2, BOOL_VEC3 = GL_BOOL_VEC3, BOOL_VEC4 = GL_BOOL_VEC4, - FLOAT_MAT2 = GL_FLOAT_MAT2, - FLOAT_MAT3 = GL_FLOAT_MAT3, - FLOAT_MAT4 = GL_FLOAT_MAT4, - SAMPLER_1D = GL_SAMPLER_1D, - SAMPLER_2D = GL_SAMPLER_2D, - SAMPLER_3D = GL_SAMPLER_3D, - SAMPLER_CUBE = GL_SAMPLER_CUBE, - SAMPLER_1D_SHADOW = GL_SAMPLER_1D_SHADOW, - SAMPLER_2D_SHADOW = GL_SAMPLER_2D_SHADOW, - SAMPLER_1D_ARRAY = GL_SAMPLER_1D_ARRAY_EXT, - 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_MAT2 = GL_FLOAT_MAT2, + FLOAT_MAT3 = GL_FLOAT_MAT3, + FLOAT_MAT4 = GL_FLOAT_MAT4, 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 = GL_UNSIGNED_INT, - 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, + + DOUBLE_MAT2 = GL_DOUBLE_MAT2, + DOUBLE_MAT3 = GL_DOUBLE_MAT3, + DOUBLE_MAT4 = GL_DOUBLE_MAT4, + DOUBLE_MAT2x3 = GL_DOUBLE_MAT2x3, + DOUBLE_MAT2x4 = GL_DOUBLE_MAT2x4, + DOUBLE_MAT3x2 = GL_DOUBLE_MAT3x2, + DOUBLE_MAT3x4 = GL_DOUBLE_MAT3x4, + DOUBLE_MAT4x2 = GL_DOUBLE_MAT4x2, + DOUBLE_MAT4x3 = GL_DOUBLE_MAT4x3, + + SAMPLER_1D = GL_SAMPLER_1D, + SAMPLER_2D = GL_SAMPLER_2D, + SAMPLER_3D = GL_SAMPLER_3D, + SAMPLER_CUBE = GL_SAMPLER_CUBE, + SAMPLER_1D_SHADOW = GL_SAMPLER_1D_SHADOW, + SAMPLER_2D_SHADOW = GL_SAMPLER_2D_SHADOW, + SAMPLER_1D_ARRAY = GL_SAMPLER_1D_ARRAY_EXT, + SAMPLER_2D_ARRAY = GL_SAMPLER_2D_ARRAY_EXT, + SAMPLER_CUBE_MAP_ARRAY = GL_SAMPLER_CUBE_MAP_ARRAY, + SAMPLER_1D_ARRAY_SHADOW = GL_SAMPLER_1D_ARRAY_SHADOW_EXT, + SAMPLER_2D_ARRAY_SHADOW = GL_SAMPLER_2D_ARRAY_SHADOW_EXT, + SAMPLER_2D_MULTISAMPLE = GL_SAMPLER_2D_MULTISAMPLE, + SAMPLER_2D_MULTISAMPLE_ARRAY = GL_SAMPLER_2D_MULTISAMPLE_ARRAY, + SAMPLER_CUBE_SHADOW = GL_SAMPLER_CUBE_SHADOW_EXT, + SAMPLER_CUBE_MAP_ARRAY_SHADOW = GL_SAMPLER_CUBE_MAP_ARRAY_SHADOW, + SAMPLER_BUFFER = GL_SAMPLER_BUFFER_EXT, + SAMPLER_2D_RECT = GL_SAMPLER_2D_RECT, + SAMPLER_2D_RECT_SHADOW = GL_SAMPLER_2D_RECT_SHADOW, + + 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_1D_ARRAY = GL_INT_SAMPLER_1D_ARRAY_EXT, + INT_SAMPLER_2D_ARRAY = GL_INT_SAMPLER_2D_ARRAY_EXT, + INT_SAMPLER_CUBE_MAP_ARRAY = GL_INT_SAMPLER_CUBE_MAP_ARRAY, + INT_SAMPLER_2D_MULTISAMPLE = GL_INT_SAMPLER_2D_MULTISAMPLE, + INT_SAMPLER_2D_MULTISAMPLE_ARRAY = GL_INT_SAMPLER_2D_MULTISAMPLE_ARRAY, + INT_SAMPLER_BUFFER = GL_INT_SAMPLER_BUFFER_EXT, + INT_SAMPLER_2D_RECT = GL_INT_SAMPLER_2D_RECT_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_1D_ARRAY = GL_UNSIGNED_INT_SAMPLER_1D_ARRAY_EXT, + UNSIGNED_INT_SAMPLER_2D_ARRAY = GL_UNSIGNED_INT_SAMPLER_2D_ARRAY_EXT, + UNSIGNED_INT_SAMPLER_CUBE_MAP_ARRAY = GL_UNSIGNED_INT_SAMPLER_CUBE_MAP_ARRAY, + UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE = GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE, + UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE_ARRAY = GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE_ARRAY, + UNSIGNED_INT_SAMPLER_BUFFER = GL_UNSIGNED_INT_SAMPLER_BUFFER_EXT, + UNSIGNED_INT_SAMPLER_2D_RECT = GL_UNSIGNED_INT_SAMPLER_2D_RECT_EXT, + + IMAGE_1D = GL_IMAGE_1D, + IMAGE_2D = GL_IMAGE_2D, + IMAGE_3D = GL_IMAGE_3D, + IMAGE_2D_RECT = GL_IMAGE_2D_RECT, + IMAGE_CUBE = GL_IMAGE_CUBE, + IMAGE_BUFFER = GL_IMAGE_BUFFER, + IMAGE_1D_ARRAY = GL_IMAGE_1D_ARRAY, + IMAGE_2D_ARRAY = GL_IMAGE_2D_ARRAY, + IMAGE_CUBE_MAP_ARRAY = GL_IMAGE_CUBE_MAP_ARRAY, + IMAGE_2D_MULTISAMPLE = GL_IMAGE_2D_MULTISAMPLE, + IMAGE_2D_MULTISAMPLE_ARRAY = GL_IMAGE_2D_MULTISAMPLE_ARRAY, + + INT_IMAGE_1D = GL_INT_IMAGE_1D, + INT_IMAGE_2D = GL_INT_IMAGE_2D, + INT_IMAGE_3D = GL_INT_IMAGE_3D, + INT_IMAGE_2D_RECT = GL_INT_IMAGE_2D_RECT, + INT_IMAGE_CUBE = GL_INT_IMAGE_CUBE, + INT_IMAGE_BUFFER = GL_INT_IMAGE_BUFFER, + INT_IMAGE_1D_ARRAY = GL_INT_IMAGE_1D_ARRAY, + INT_IMAGE_2D_ARRAY = GL_INT_IMAGE_2D_ARRAY, + INT_IMAGE_CUBE_MAP_ARRAY = GL_INT_IMAGE_CUBE_MAP_ARRAY, + INT_IMAGE_2D_MULTISAMPLE = GL_INT_IMAGE_2D_MULTISAMPLE, + INT_IMAGE_2D_MULTISAMPLE_ARRAY = GL_INT_IMAGE_2D_MULTISAMPLE_ARRAY, + + UNSIGNED_INT_IMAGE_1D = GL_UNSIGNED_INT_IMAGE_1D, + UNSIGNED_INT_IMAGE_2D = GL_UNSIGNED_INT_IMAGE_2D, + UNSIGNED_INT_IMAGE_3D = GL_UNSIGNED_INT_IMAGE_3D, + UNSIGNED_INT_IMAGE_2D_RECT = GL_UNSIGNED_INT_IMAGE_2D_RECT, + UNSIGNED_INT_IMAGE_CUBE = GL_UNSIGNED_INT_IMAGE_CUBE, + UNSIGNED_INT_IMAGE_BUFFER = GL_UNSIGNED_INT_IMAGE_BUFFER, + UNSIGNED_INT_IMAGE_1D_ARRAY = GL_UNSIGNED_INT_IMAGE_1D_ARRAY, + UNSIGNED_INT_IMAGE_2D_ARRAY = GL_UNSIGNED_INT_IMAGE_2D_ARRAY, + UNSIGNED_INT_IMAGE_CUBE_MAP_ARRAY = GL_UNSIGNED_INT_IMAGE_CUBE_MAP_ARRAY, + UNSIGNED_INT_IMAGE_2D_MULTISAMPLE = GL_UNSIGNED_INT_IMAGE_2D_MULTISAMPLE, + UNSIGNED_INT_IMAGE_2D_MULTISAMPLE_ARRAY = GL_UNSIGNED_INT_IMAGE_2D_MULTISAMPLE_ARRAY, UNDEFINED = 0x0 }; @@ -273,26 +545,43 @@ class OSG_EXPORT Uniform : public Object /** convenient scalar (non-array) constructors w/ assignment */ explicit Uniform( const char* name, float f ); + explicit Uniform( const char* name, double d ); explicit Uniform( const char* name, int i ); - explicit Uniform( const char* name, unsigned int i ); + explicit Uniform( const char* name, unsigned int ui ); explicit Uniform( const char* name, bool b ); Uniform( const char* name, const osg::Vec2& v2 ); Uniform( const char* name, const osg::Vec3& v3 ); Uniform( const char* name, const osg::Vec4& v4 ); + Uniform( const char* name, const osg::Vec2d& v2 ); + Uniform( const char* name, const osg::Vec3d& v3 ); + Uniform( const char* name, const osg::Vec4d& v4 ); Uniform( const char* name, const osg::Matrix2& m2 ); Uniform( const char* name, const osg::Matrix3& m3 ); Uniform( const char* name, const osg::Matrixf& m4 ); + Uniform( const char* name, const osg::Matrix2x3& m2x3 ); + Uniform( const char* name, const osg::Matrix2x4& m2x4 ); + Uniform( const char* name, const osg::Matrix3x2& m3x2 ); + Uniform( const char* name, const osg::Matrix3x4& m3x4 ); + Uniform( const char* name, const osg::Matrix4x2& m4x2 ); + Uniform( const char* name, const osg::Matrix4x3& m4x3 ); + Uniform( const char* name, const osg::Matrix2d& m2 ); + Uniform( const char* name, const osg::Matrix3d& m3 ); Uniform( const char* name, const osg::Matrixd& m4 ); + Uniform( const char* name, const osg::Matrix2x3d& m2x3 ); + Uniform( const char* name, const osg::Matrix2x4d& m2x4 ); + Uniform( const char* name, const osg::Matrix3x2d& m3x2 ); + Uniform( const char* name, const osg::Matrix3x4d& m3x4 ); + Uniform( const char* name, const osg::Matrix4x2d& m4x2 ); + Uniform( const char* name, const osg::Matrix4x3d& m4x3 ); Uniform( const char* name, int i0, int i1 ); Uniform( const char* name, int i0, int i1, int i2 ); Uniform( const char* name, int i0, int i1, int i2, int i3 ); - Uniform( const char* name, unsigned int i0, unsigned int i1 ); - Uniform( const char* name, unsigned int i0, unsigned int i1, unsigned int i2 ); - Uniform( const char* name, unsigned int i0, unsigned int i1, unsigned int i2, unsigned int i3 ); + Uniform( const char* name, unsigned int ui0, unsigned int ui1 ); + Uniform( const char* name, unsigned int ui0, unsigned int ui1, unsigned int ui2 ); + Uniform( const char* name, unsigned int ui0, unsigned int ui1, unsigned int ui2, unsigned int ui3 ); 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; @@ -332,88 +621,160 @@ class OSG_EXPORT Uniform : public Object /** convenient scalar (non-array) value assignment */ bool set( float f ); + bool set( double d ); bool set( int i ); - bool set( unsigned int i ); + bool set( unsigned int ui ); bool set( bool b ); bool set( const osg::Vec2& v2 ); bool set( const osg::Vec3& v3 ); bool set( const osg::Vec4& v4 ); + bool set( const osg::Vec2d& v2 ); + bool set( const osg::Vec3d& v3 ); + bool set( const osg::Vec4d& v4 ); bool set( const osg::Matrix2& m2 ); bool set( const osg::Matrix3& m3 ); bool set( const osg::Matrixf& m4 ); + bool set( const osg::Matrix2x3& m2x3 ); + bool set( const osg::Matrix2x4& m2x4 ); + bool set( const osg::Matrix3x2& m3x2 ); + bool set( const osg::Matrix3x4& m3x4 ); + bool set( const osg::Matrix4x2& m4x2 ); + bool set( const osg::Matrix4x3& m4x3 ); + bool set( const osg::Matrix2d& m2 ); + bool set( const osg::Matrix3d& m3 ); bool set( const osg::Matrixd& m4 ); + bool set( const osg::Matrix2x3d& m2x3 ); + bool set( const osg::Matrix2x4d& m2x4 ); + bool set( const osg::Matrix3x2d& m3x2 ); + bool set( const osg::Matrix3x4d& m3x4 ); + bool set( const osg::Matrix4x2d& m4x2 ); + bool set( const osg::Matrix4x3d& m4x3 ); bool set( int i0, int i1 ); bool set( int i0, int i1, int i2 ); bool set( int i0, int i1, int i2, int i3 ); - bool set( unsigned int i0, unsigned int i1 ); - bool set( unsigned int i0, unsigned int i1, unsigned int i2 ); - bool set( unsigned int i0, unsigned int i1, unsigned int i2, unsigned int i3 ); + bool set( unsigned int ui0, unsigned int ui1 ); + bool set( unsigned int ui0, unsigned int ui1, unsigned int ui2 ); + bool set( unsigned int ui0, unsigned int ui1, unsigned int ui2, unsigned int ui3 ); bool set( bool b0, bool b1 ); bool set( bool b0, bool b1, bool b2 ); bool set( bool b0, bool b1, bool b2, bool b3 ); /** convenient scalar (non-array) value query */ bool get( float& f ) const; + bool get( double& d ) const; bool get( int& i ) const; - bool get( unsigned int& i ) const; + bool get( unsigned int& ui ) const; bool get( bool& b ) const; bool get( osg::Vec2& v2 ) const; bool get( osg::Vec3& v3 ) const; bool get( osg::Vec4& v4 ) const; + bool get( osg::Vec2d& v2 ) const; + bool get( osg::Vec3d& v3 ) const; + bool get( osg::Vec4d& v4 ) const; bool get( osg::Matrix2& m2 ) const; bool get( osg::Matrix3& m3 ) const; bool get( osg::Matrixf& m4 ) const; + bool get( osg::Matrix2x3& m2x3 ) const; + bool get( osg::Matrix2x4& m2x4 ) const; + bool get( osg::Matrix3x2& m3x2 ) const; + bool get( osg::Matrix3x4& m3x4 ) const; + bool get( osg::Matrix4x2& m4x2 ) const; + bool get( osg::Matrix4x3& m4x3 ) const; + bool get( osg::Matrix2d& m2 ) const; + bool get( osg::Matrix3d& m3 ) const; bool get( osg::Matrixd& m4 ) const; + bool get( osg::Matrix2x3d& m2x3 ) const; + bool get( osg::Matrix2x4d& m2x4 ) const; + bool get( osg::Matrix3x2d& m3x2 ) const; + bool get( osg::Matrix3x4d& m3x4 ) const; + bool get( osg::Matrix4x2d& m4x2 ) const; + bool get( osg::Matrix4x3d& m4x3 ) const; bool get( int& i0, int& i1 ) const; bool get( int& i0, int& i1, int& i2 ) const; bool get( int& i0, int& i1, int& i2, int& i3 ) const; - bool get( unsigned int& i0, unsigned int& i1 ) const; - bool get( unsigned int& i0, unsigned int& i1, unsigned int& i2 ) const; - bool get( unsigned int& i0, unsigned int& i1, unsigned int& i2, unsigned int& i3 ) const; + bool get( unsigned int& ui0, unsigned int& ui1 ) const; + bool get( unsigned int& ui0, unsigned int& ui1, unsigned int& ui2 ) const; + bool get( unsigned int& ui0, unsigned int& ui1, unsigned int& ui2, unsigned int& ui3 ) const; bool get( bool& b0, bool& b1 ) const; bool get( bool& b0, bool& b1, bool& b2 ) const; bool get( bool& b0, bool& b1, bool& b2, bool& b3 ) const; /** value assignment for array uniforms */ bool setElement( unsigned int index, float f ); + bool setElement( unsigned int index, double d ); bool setElement( unsigned int index, int i ); - bool setElement( unsigned int index, unsigned int i ); + bool setElement( unsigned int index, unsigned int ui ); bool setElement( unsigned int index, bool b ); bool setElement( unsigned int index, const osg::Vec2& v2 ); bool setElement( unsigned int index, const osg::Vec3& v3 ); bool setElement( unsigned int index, const osg::Vec4& v4 ); + bool setElement( unsigned int index, const osg::Vec2d& v2 ); + bool setElement( unsigned int index, const osg::Vec3d& v3 ); + bool setElement( unsigned int index, const osg::Vec4d& v4 ); bool setElement( unsigned int index, const osg::Matrix2& m2 ); bool setElement( unsigned int index, const osg::Matrix3& m3 ); bool setElement( unsigned int index, const osg::Matrixf& m4 ); + bool setElement( unsigned int index, const osg::Matrix2x3& m2x3 ); + bool setElement( unsigned int index, const osg::Matrix2x4& m2x4 ); + bool setElement( unsigned int index, const osg::Matrix3x2& m3x2 ); + bool setElement( unsigned int index, const osg::Matrix3x4& m3x4 ); + bool setElement( unsigned int index, const osg::Matrix4x2& m4x2 ); + bool setElement( unsigned int index, const osg::Matrix4x3& m4x3 ); + bool setElement( unsigned int index, const osg::Matrix2d& m2 ); + bool setElement( unsigned int index, const osg::Matrix3d& m3 ); bool setElement( unsigned int index, const osg::Matrixd& m4 ); + bool setElement( unsigned int index, const osg::Matrix2x3d& m2x3 ); + bool setElement( unsigned int index, const osg::Matrix2x4d& m2x4 ); + bool setElement( unsigned int index, const osg::Matrix3x2d& m3x2 ); + bool setElement( unsigned int index, const osg::Matrix3x4d& m3x4 ); + bool setElement( unsigned int index, const osg::Matrix4x2d& m4x2 ); + bool setElement( unsigned int index, const osg::Matrix4x3d& m4x3 ); bool setElement( unsigned int index, int i0, int i1 ); bool setElement( unsigned int index, int i0, int i1, int i2 ); bool setElement( unsigned int index, int i0, int i1, int i2, int i3 ); - bool setElement( unsigned int index, unsigned int i0, unsigned int i1 ); - bool setElement( unsigned int index, unsigned int i0, unsigned int i1, unsigned int i2 ); - bool setElement( unsigned int index, unsigned int i0, unsigned int i1, unsigned int i2, unsigned int i3 ); + bool setElement( unsigned int index, unsigned int ui0, unsigned int ui1 ); + bool setElement( unsigned int index, unsigned int ui0, unsigned int ui1, unsigned int ui2 ); + bool setElement( unsigned int index, unsigned int ui0, unsigned int ui1, unsigned int ui2, unsigned int ui3 ); bool setElement( unsigned int index, bool b0, bool b1 ); bool setElement( unsigned int index, bool b0, bool b1, bool b2 ); bool setElement( unsigned int index, bool b0, bool b1, bool b2, bool b3 ); /** value query for array uniforms */ bool getElement( unsigned int index, float& f ) const; + bool getElement( unsigned int index, double& d ) const; bool getElement( unsigned int index, int& i ) const; - bool getElement( unsigned int index, unsigned int& i ) const; + bool getElement( unsigned int index, unsigned int& ui ) const; bool getElement( unsigned int index, bool& b ) const; bool getElement( unsigned int index, osg::Vec2& v2 ) const; bool getElement( unsigned int index, osg::Vec3& v3 ) const; bool getElement( unsigned int index, osg::Vec4& v4 ) const; + bool getElement( unsigned int index, osg::Vec2d& v2 ) const; + bool getElement( unsigned int index, osg::Vec3d& v3 ) const; + bool getElement( unsigned int index, osg::Vec4d& v4 ) const; bool getElement( unsigned int index, osg::Matrix2& m2 ) const; bool getElement( unsigned int index, osg::Matrix3& m3 ) const; bool getElement( unsigned int index, osg::Matrixf& m4 ) const; + bool getElement( unsigned int index, osg::Matrix2x3& m2x3 ) const; + bool getElement( unsigned int index, osg::Matrix2x4& m2x4 ) const; + bool getElement( unsigned int index, osg::Matrix3x2& m3x2 ) const; + bool getElement( unsigned int index, osg::Matrix3x4& m3x4 ) const; + bool getElement( unsigned int index, osg::Matrix4x2& m4x2 ) const; + bool getElement( unsigned int index, osg::Matrix4x3& m4x3 ) const; + bool getElement( unsigned int index, osg::Matrix2d& m2 ) const; + bool getElement( unsigned int index, osg::Matrix3d& m3 ) const; bool getElement( unsigned int index, osg::Matrixd& m4 ) const; + bool getElement( unsigned int index, osg::Matrix2x3d& m2x3 ) const; + bool getElement( unsigned int index, osg::Matrix2x4d& m2x4 ) const; + bool getElement( unsigned int index, osg::Matrix3x2d& m3x2 ) const; + bool getElement( unsigned int index, osg::Matrix3x4d& m3x4 ) const; + bool getElement( unsigned int index, osg::Matrix4x2d& m4x2 ) const; + bool getElement( unsigned int index, osg::Matrix4x3d& m4x3 ) const; bool getElement( unsigned int index, int& i0, int& i1 ) const; bool getElement( unsigned int index, int& i0, int& i1, int& i2 ) const; bool getElement( unsigned int index, int& i0, int& i1, int& i2, int& i3 ) const; - bool getElement( unsigned int index, unsigned int& i0, unsigned int& i1 ) const; - bool getElement( unsigned int index, unsigned int& i0, unsigned int& i1, unsigned int& i2 ) const; - bool getElement( unsigned int index, unsigned int& i0, unsigned int& i1, unsigned int& i2, unsigned int& i3 ) const; + bool getElement( unsigned int index, unsigned int& ui0, unsigned int& ui1 ) const; + bool getElement( unsigned int index, unsigned int& ui0, unsigned int& ui1, unsigned int& ui2 ) const; + bool getElement( unsigned int index, unsigned int& ui0, unsigned int& ui1, unsigned int& ui2, unsigned int& ui3 ) const; bool getElement( unsigned int index, bool& b0, bool& b1 ) const; bool getElement( unsigned int index, bool& b0, bool& b1, bool& b2 ) const; bool getElement( unsigned int index, bool& b0, bool& b1, bool& b2, bool& b3 ) const; @@ -457,6 +818,7 @@ class OSG_EXPORT Uniform : public Object /** Set the internal data array for a osg::Uniform */ bool setArray( FloatArray* array ); + bool setArray( DoubleArray* array ); bool setArray( IntArray* array ); bool setArray( UIntArray* array ); @@ -464,6 +826,10 @@ class OSG_EXPORT Uniform : public Object FloatArray* getFloatArray() { return _floatArray.get(); } const FloatArray* getFloatArray() const { return _floatArray.get(); } + /** Get the internal data array for a double osg::Uniform. */ + DoubleArray* getDoubleArray() { return _doubleArray.get(); } + const DoubleArray* getDoubleArray() const { return _doubleArray.get(); } + /** Get the internal data array for an int osg::Uniform. */ IntArray* getIntArray() { return _intArray.get(); } const IntArray* getIntArray() const { return _intArray.get(); } @@ -487,6 +853,10 @@ class OSG_EXPORT Uniform : public Object Uniform& operator=(const Uniform&) { return *this; } bool isCompatibleType( Type t ) const; + // for backward compatibility only + // see getElement(index, osg::Matrixd &) + // see setElement(index, osg::Matrixd &) + bool isCompatibleType( Type t1, Type t2 ) const; bool isScalar() const { return _numElements==1; } void allocateDataArray(); @@ -496,21 +866,22 @@ class OSG_EXPORT Uniform : public Object ParentList _parents; friend class osg::StateSet; - Type _type; - unsigned int _numElements; - unsigned int _nameID; + Type _type; + unsigned int _numElements; + unsigned int _nameID; // The internal data for osg::Uniforms are stored as an array of // getInternalArrayType() of length getInternalArrayNumElements(). - ref_ptr _floatArray; - ref_ptr _intArray; - ref_ptr _uintArray; + ref_ptr _floatArray; + ref_ptr _doubleArray; + ref_ptr _intArray; + ref_ptr _uintArray; - ref_ptr _updateCallback; - ref_ptr _eventCallback; + ref_ptr _updateCallback; + ref_ptr _eventCallback; - unsigned int _modifiedCount; + unsigned int _modifiedCount; }; } diff --git a/src/osg/BufferIndexBinding.cpp b/src/osg/BufferIndexBinding.cpp index a3200f5e4..9789f7e9e 100644 --- a/src/osg/BufferIndexBinding.cpp +++ b/src/osg/BufferIndexBinding.cpp @@ -1,5 +1,6 @@ /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield * Copyright (C) 2010 Tim Moore + * Copyright (C) 2012 David Callu * * 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 @@ -15,6 +16,9 @@ #include #include +#include // for memcpy + + namespace osg { BufferIndexBinding::BufferIndexBinding(GLenum target, GLuint index) @@ -95,4 +99,48 @@ TransformFeedbackBufferBinding::TransformFeedbackBufferBinding(const TransformFe { } + +AtomicCounterBufferBinding::AtomicCounterBufferBinding(GLuint index) + : BufferIndexBinding(GL_ATOMIC_COUNTER_BUFFER, index) +{ } + +AtomicCounterBufferBinding::AtomicCounterBufferBinding(GLuint index, BufferObject* bo, GLintptr offset, GLsizeiptr size) + : BufferIndexBinding(GL_ATOMIC_COUNTER_BUFFER, index, bo, offset, size) +{ + +} + +AtomicCounterBufferBinding::AtomicCounterBufferBinding(const AtomicCounterBufferBinding& rhs, const CopyOp& copyop) + : BufferIndexBinding(rhs, copyop) +{ +} + +void AtomicCounterBufferBinding::readData(osg::State & state, osg::UIntArray & uintArray) const +{ + if (!_bufferObject) return; + + GLBufferObject* bo = _bufferObject->getOrCreateGLBufferObject( state.getContextID() ); + if (!bo) return; + + + GLint previousID = 0; + glGetIntegerv(GL_ATOMIC_COUNTER_BUFFER_BINDING, &previousID); + + if (static_cast(previousID) != bo->getGLObjectID()) + bo->_extensions->glBindBuffer(GL_ATOMIC_COUNTER_BUFFER, bo->getGLObjectID()); + + GLubyte* src = (GLubyte*)bo->_extensions->glMapBuffer(GL_ATOMIC_COUNTER_BUFFER, + GL_READ_ONLY_ARB); + if(src) + { + size_t size = osg::minimum(_size, uintArray.getTotalDataSize()); + memcpy((void*) &(uintArray.front()), src+_offset, size); + bo->_extensions->glUnmapBuffer(GL_ATOMIC_COUNTER_BUFFER); + } + + if (static_cast(previousID) != bo->getGLObjectID()) + bo->_extensions->glBindBuffer(GL_ATOMIC_COUNTER_BUFFER, static_cast(previousID)); +} + +} // namespace osg diff --git a/src/osg/BufferObject.cpp b/src/osg/BufferObject.cpp index 47ae81c7e..2f3de0b08 100644 --- a/src/osg/BufferObject.cpp +++ b/src/osg/BufferObject.cpp @@ -1,4 +1,5 @@ /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield + * Copyright (C) 2012 David Callu * * 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 @@ -1668,6 +1669,11 @@ void PixelDataBufferObject::resizeGLObjectBuffers(unsigned int maxSize) _mode.resize(maxSize); } + +////////////////////////////////////////////////////////////////////////////////// +// +// UniformBufferObject +// UniformBufferObject::UniformBufferObject() { setTarget(GL_UNIFORM_BUFFER); @@ -1682,3 +1688,24 @@ UniformBufferObject::UniformBufferObject(const UniformBufferObject& ubo, const C UniformBufferObject::~UniformBufferObject() { } + + + +////////////////////////////////////////////////////////////////////////////////// +// +// AtomicCounterBufferObject +// +AtomicCounterBufferObject::AtomicCounterBufferObject() +{ + setTarget(GL_ATOMIC_COUNTER_BUFFER); + setUsage(GL_DYNAMIC_DRAW); +} + +AtomicCounterBufferObject::AtomicCounterBufferObject(const AtomicCounterBufferObject& ubo, const CopyOp& copyop) + : BufferObject(ubo, copyop) +{ +} + +AtomicCounterBufferObject::~AtomicCounterBufferObject() +{ +} diff --git a/src/osg/GL2Extensions.cpp b/src/osg/GL2Extensions.cpp index 1aa8de9cb..a24a80eb3 100644 --- a/src/osg/GL2Extensions.cpp +++ b/src/osg/GL2Extensions.cpp @@ -2,6 +2,7 @@ * Copyright (C) 2003-2005 3Dlabs Inc. Ltd. * Copyright (C) 2004-2005 Nathan Cournia * Copyright (C) 2008 Zebra Imaging + * Copyright (C) 2012 David Callu * * This application is open source and may be redistributed and/or modified * freely and without restriction, both in commercial and non commercial @@ -46,9 +47,12 @@ GL2Extensions::GL2Extensions(const GL2Extensions& rhs) : osg::Referenced() _isFragmentShaderSupported = rhs._isFragmentShaderSupported; _isLanguage100Supported = rhs._isLanguage100Supported; _isGeometryShader4Supported = rhs._isGeometryShader4Supported; + _areTessellationShadersSupported = rhs._areTessellationShadersSupported; _isGpuShader4Supported = rhs._isGpuShader4Supported; _isUniformBufferObjectSupported = rhs._isUniformBufferObjectSupported; _isGetProgramBinarySupported = rhs._isGetProgramBinarySupported; + _isGpuShaderFp64Supported = rhs._isGpuShaderFp64Supported; + _isShaderAtomicCountersSupported = rhs._isShaderAtomicCountersSupported; _glBlendEquationSeparate = rhs._glBlendEquationSeparate; _glDrawBuffers = rhs._glDrawBuffers; @@ -189,7 +193,27 @@ GL2Extensions::GL2Extensions(const GL2Extensions& rhs) : osg::Referenced() _glGetProgramBinary = rhs._glGetProgramBinary; _glProgramBinary = rhs._glProgramBinary; - _areTessellationShadersSupported = rhs._areTessellationShadersSupported; + // ARB_gpu_shader_fp64 + _glUniform1d = rhs._glUniform1d; + _glUniform2d = rhs._glUniform2d; + _glUniform3d = rhs._glUniform3d; + _glUniform4d = rhs._glUniform4d; + _glUniform1dv = rhs._glUniform1dv; + _glUniform2dv = rhs._glUniform2dv; + _glUniform3dv = rhs._glUniform3dv; + _glUniform4dv = rhs._glUniform4dv; + _glUniformMatrix2dv = rhs._glUniformMatrix2dv; + _glUniformMatrix3dv = rhs._glUniformMatrix3dv; + _glUniformMatrix4dv = rhs._glUniformMatrix4dv; + _glUniformMatrix2x3dv = rhs._glUniformMatrix2x3dv; + _glUniformMatrix3x2dv = rhs._glUniformMatrix3x2dv; + _glUniformMatrix2x4dv = rhs._glUniformMatrix2x4dv; + _glUniformMatrix4x2dv = rhs._glUniformMatrix4x2dv; + _glUniformMatrix3x4dv = rhs._glUniformMatrix3x4dv; + _glUniformMatrix4x3dv = rhs._glUniformMatrix4x3dv; + + // ARB_shader_atomic_counters + _glGetActiveAtomicCounterBufferiv = rhs._glGetActiveAtomicCounterBufferiv; } @@ -204,7 +228,12 @@ void GL2Extensions::lowestCommonDenominator(const GL2Extensions& rhs) if (!rhs._isFragmentShaderSupported) _isFragmentShaderSupported = false; if (!rhs._isLanguage100Supported) _isLanguage100Supported = false; if (!rhs._isGeometryShader4Supported) _isGeometryShader4Supported = false; + if (!rhs._areTessellationShadersSupported) _areTessellationShadersSupported = false; if (!rhs._isGpuShader4Supported) _isGpuShader4Supported = false; + if (!rhs._isUniformBufferObjectSupported) _isUniformBufferObjectSupported = false; + if (!rhs._isGetProgramBinarySupported) _isGetProgramBinarySupported = false; + if (!rhs._isGpuShaderFp64Supported) _isGpuShaderFp64Supported = false; + if (!rhs._isShaderAtomicCountersSupported) _isShaderAtomicCountersSupported = false; if (!rhs._glBlendEquationSeparate) _glBlendEquationSeparate = 0; if (!rhs._glDrawBuffers) _glDrawBuffers = 0; @@ -348,6 +377,28 @@ void GL2Extensions::lowestCommonDenominator(const GL2Extensions& rhs) // ARB_get_program_binary if (!rhs._glGetProgramBinary) _glGetProgramBinary = 0; if (!rhs._glProgramBinary) _glProgramBinary = 0; + + // ARB_gpu_shader_fp64 + if(!rhs._glUniform1d) _glUniform1d = 0; + if(!rhs._glUniform2d) _glUniform2d = 0; + if(!rhs._glUniform3d) _glUniform3d = 0; + if(!rhs._glUniform4d) _glUniform4d = 0; + if(!rhs._glUniform1dv) _glUniform1dv = 0; + if(!rhs._glUniform2dv) _glUniform2dv = 0; + if(!rhs._glUniform3dv) _glUniform3dv = 0; + if(!rhs._glUniform4dv) _glUniform4dv = 0; + if(!rhs._glUniformMatrix2dv) _glUniformMatrix2dv = 0; + if(!rhs._glUniformMatrix3dv) _glUniformMatrix3dv = 0; + if(!rhs._glUniformMatrix4dv) _glUniformMatrix4dv = 0; + if(!rhs._glUniformMatrix2x3dv) _glUniformMatrix2x3dv = 0; + if(!rhs._glUniformMatrix3x2dv) _glUniformMatrix3x2dv = 0; + if(!rhs._glUniformMatrix2x4dv) _glUniformMatrix2x4dv = 0; + if(!rhs._glUniformMatrix4x2dv) _glUniformMatrix4x2dv = 0; + if(!rhs._glUniformMatrix3x4dv) _glUniformMatrix3x4dv = 0; + if(!rhs._glUniformMatrix4x3dv) _glUniformMatrix4x3dv = 0; + + // ARB_shader_atomic_counters + if(!rhs._glGetActiveAtomicCounterBufferiv) _glGetActiveAtomicCounterBufferiv = 0; } @@ -370,6 +421,8 @@ void GL2Extensions::setupGL2Extensions(unsigned int contextID) _isGpuShader4Supported = false; _isUniformBufferObjectSupported = false; _isGetProgramBinarySupported = false; + _isGpuShaderFp64Supported = false; + _isShaderAtomicCountersSupported = false; _glBlendEquationSeparate= 0; _glDrawBuffers= 0; @@ -510,10 +563,32 @@ void GL2Extensions::setupGL2Extensions(unsigned int contextID) _glGetActiveUniformBlockName= 0; _glUniformBlockBinding= 0; - //ARB_get_program_binary + // ARB_get_program_binary _glGetProgramBinary= 0; _glProgramBinary= 0; + // ARB_gpu_shader_fp64 + _glUniform1d= 0; + _glUniform2d= 0; + _glUniform3d= 0; + _glUniform4d= 0; + _glUniform1dv= 0; + _glUniform2dv= 0; + _glUniform3dv= 0; + _glUniform4dv= 0; + _glUniformMatrix2dv= 0; + _glUniformMatrix3dv= 0; + _glUniformMatrix4dv= 0; + _glUniformMatrix2x3dv= 0; + _glUniformMatrix3x2dv= 0; + _glUniformMatrix2x4dv= 0; + _glUniformMatrix4x2dv= 0; + _glUniformMatrix3x4dv= 0; + _glUniformMatrix4x3dv= 0; + + // ARB_shader_atomic_counters + _glGetActiveAtomicCounterBufferiv= 0; + return; } @@ -531,6 +606,8 @@ void GL2Extensions::setupGL2Extensions(unsigned int contextID) _areTessellationShadersSupported = osg::isGLExtensionSupported(contextID, "GL_ARB_tessellation_shader"); _isUniformBufferObjectSupported = osg::isGLExtensionSupported(contextID,"GL_ARB_uniform_buffer_object"); _isGetProgramBinarySupported = osg::isGLExtensionSupported(contextID,"GL_ARB_get_program_binary"); + _isGpuShaderFp64Supported = osg::isGLExtensionSupported(contextID,"GL_ARB_gpu_shader_fp64"); + _isShaderAtomicCountersSupported = osg::isGLExtensionSupported(contextID,"GL_ARB_shader_atomic_counters"); if( isGlslSupported() ) { @@ -691,9 +768,32 @@ void GL2Extensions::setupGL2Extensions(unsigned int contextID) setGLExtensionFuncPtr(_glGetActiveUniformBlockiv, "glGetActiveUniformBlockiv"); setGLExtensionFuncPtr(_glGetActiveUniformBlockName, "glGetActiveUniformBlockName"); setGLExtensionFuncPtr(_glUniformBlockBinding, "glUniformBlockBinding"); - //ARB_get_program_binary + + // ARB_get_program_binary setGLExtensionFuncPtr(_glGetProgramBinary, "glGetProgramBinary"); setGLExtensionFuncPtr(_glProgramBinary, "glProgramBinary"); + + // ARB_gpu_shader_fp64 + setGLExtensionFuncPtr(_glUniform1d, "glUniform1d" ); + setGLExtensionFuncPtr(_glUniform2d, "glUniform2d" ); + setGLExtensionFuncPtr(_glUniform3d, "glUniform3d" ); + setGLExtensionFuncPtr(_glUniform4d, "glUniform4d" ); + setGLExtensionFuncPtr(_glUniform1dv, "glUniform1dv" ); + setGLExtensionFuncPtr(_glUniform2dv, "glUniform2dv" ); + setGLExtensionFuncPtr(_glUniform3dv, "glUniform3dv" ); + setGLExtensionFuncPtr(_glUniform4dv, "glUniform4dv" ); + setGLExtensionFuncPtr(_glUniformMatrix2dv, "glUniformMatrix2dv" ); + setGLExtensionFuncPtr(_glUniformMatrix3dv, "glUniformMatrix3dv" ); + setGLExtensionFuncPtr(_glUniformMatrix4dv, "glUniformMatrix4dv" ); + setGLExtensionFuncPtr(_glUniformMatrix2x3dv, "glUniformMatrix2x3dv" ); + setGLExtensionFuncPtr(_glUniformMatrix3x2dv, "glUniformMatrix3x2dv" ); + setGLExtensionFuncPtr(_glUniformMatrix2x4dv, "glUniformMatrix2x4dv" ); + setGLExtensionFuncPtr(_glUniformMatrix4x2dv, "glUniformMatrix4x2dv" ); + setGLExtensionFuncPtr(_glUniformMatrix3x4dv, "glUniformMatrix3x4dv" ); + setGLExtensionFuncPtr(_glUniformMatrix4x3dv, "glUniformMatrix4x3dv" ); + + // ARB_shader_atomic_counters + setGLExtensionFuncPtr(_glGetActiveAtomicCounterBufferiv, "glGetActiveAtomicCounterBufferiv" ); } @@ -2492,6 +2592,240 @@ void GL2Extensions::glProgramBinary(GLuint program, } } +void GL2Extensions::glUniform1d(GLint location, GLdouble v0) const +{ + if (_glUniform1d) + { + + _glUniform1d(location, v0); + } + else + { + NotSupported( "glUniform1d" ); + } +} + +void GL2Extensions::glUniform2d(GLint location, GLdouble v0, GLdouble v1) const +{ + if (_glUniform2d) + { + + _glUniform2d(location, v0, v1); + } + else + { + NotSupported( "glUniform2d" ); + } +} + +void GL2Extensions::glUniform3d(GLint location, GLdouble v0, GLdouble v1, GLdouble v2) const +{ + if (_glUniform3d) + { + + _glUniform3d(location, v0, v1, v2); + } + else + { + NotSupported( "glUniform3d" ); + } +} + +void GL2Extensions::glUniform4d(GLint location, GLdouble v0, GLdouble v1, GLdouble v2, GLdouble v3) const +{ + if (_glUniform4d) + { + + _glUniform4d(location, v0, v1, v2, v3); + } + else + { + NotSupported( "glUniform4d" ); + } +} + +void GL2Extensions::glUniform1dv(GLint location, GLsizei count, const GLdouble *value) const +{ + if (_glUniform1dv) + { + + _glUniform1dv(location, count, value); + } + else + { + NotSupported( "glUniform1dv" ); + } +} + +void GL2Extensions::glUniform2dv(GLint location, GLsizei count, const GLdouble *value) const +{ + if (_glUniform2dv) + { + + _glUniform2dv(location, count, value); + } + else + { + NotSupported( "glUniform2dv" ); + } +} + +void GL2Extensions::glUniform3dv(GLint location, GLsizei count, const GLdouble *value) const +{ + if (_glUniform3dv) + { + + _glUniform3dv(location, count, value); + } + else + { + NotSupported( "glUniform3dv" ); + } +} + +void GL2Extensions::glUniform4dv(GLint location, GLsizei count, const GLdouble *value) const +{ + if (_glUniform4dv) + { + + _glUniform4dv(location, count, value); + } + else + { + NotSupported( "glUniform4dv" ); + } +} + +void GL2Extensions::glUniformMatrix2dv(GLint location, GLsizei count, GLboolean transpose, const GLdouble *value) const +{ + if (_glUniformMatrix2dv) + { + + _glUniformMatrix2dv(location, count, transpose, value); + } + else + { + NotSupported( "glUniformMatrix2dv" ); + } +} + +void GL2Extensions::glUniformMatrix3dv(GLint location, GLsizei count, GLboolean transpose, const GLdouble *value) const +{ + if (_glUniformMatrix3dv) + { + + _glUniformMatrix3dv(location, count, transpose, value); + } + else + { + NotSupported( "glUniformMatrix3dv" ); + } +} + +void GL2Extensions::glUniformMatrix4dv(GLint location, GLsizei count, GLboolean transpose, const GLdouble *value) const +{ + if (_glUniformMatrix4dv) + { + + _glUniformMatrix4dv(location, count, transpose, value); + } + else + { + NotSupported( "glUniformMatrix4dv" ); + } +} + +void GL2Extensions::glUniformMatrix2x3dv( GLint location, GLsizei count, GLboolean transpose, const GLdouble* value ) const +{ + if (_glUniformMatrix2x3dv) + { + + _glUniformMatrix2x3dv( location, count, transpose, value ); + } + else + { + NotSupported( "glUniformMatrix2x3dv" ); + } +} + +void GL2Extensions::glUniformMatrix3x2dv( GLint location, GLsizei count, GLboolean transpose, const GLdouble* value ) const +{ + if (_glUniformMatrix3x2dv) + { + + _glUniformMatrix3x2dv( location, count, transpose, value ); + } + else + { + NotSupported( "glUniformMatrix3x2dv" ); + } +} + +void GL2Extensions::glUniformMatrix2x4dv( GLint location, GLsizei count, GLboolean transpose, const GLdouble* value ) const +{ + if (_glUniformMatrix2x4dv) + { + + _glUniformMatrix2x4dv( location, count, transpose, value ); + } + else + { + NotSupported( "glUniformMatrix2x4dv" ); + } +} + +void GL2Extensions::glUniformMatrix4x2dv( GLint location, GLsizei count, GLboolean transpose, const GLdouble* value ) const +{ + if (_glUniformMatrix4x2dv) + { + + _glUniformMatrix4x2dv( location, count, transpose, value ); + } + else + { + NotSupported( "glUniformMatrix4x2dv" ); + } +} + +void GL2Extensions::glUniformMatrix3x4dv( GLint location, GLsizei count, GLboolean transpose, const GLdouble* value ) const +{ + if (_glUniformMatrix3x4dv) + { + + _glUniformMatrix3x4dv( location, count, transpose, value ); + } + else + { + NotSupported( "glUniformMatrix3x4dv" ); + } +} + +void GL2Extensions::glUniformMatrix4x3dv( GLint location, GLsizei count, GLboolean transpose, const GLdouble* value ) const +{ + if (_glUniformMatrix4x3dv) + { + + _glUniformMatrix4x3dv( location, count, transpose, value ); + } + else + { + NotSupported( "glUniformMatrix4x3dv" ); + } +} + +void GL2Extensions::glGetActiveAtomicCounterBufferiv( GLuint program, GLuint bufferIndex, GLenum pname, GLint* params ) const +{ + if (_glGetActiveAtomicCounterBufferiv) + { + + _glGetActiveAtomicCounterBufferiv( program, bufferIndex, pname, params ); + } + else + { + NotSupported( "glGetActiveAtomicCounterBufferiv" ); + } +} + /////////////////////////////////////////////////////////////////////////// // C++-friendly convenience methods diff --git a/src/osg/Program.cpp b/src/osg/Program.cpp index 2277ccd6a..49ac73ccc 100644 --- a/src/osg/Program.cpp +++ b/src/osg/Program.cpp @@ -3,6 +3,7 @@ * Copyright (C) 2004-2005 Nathan Cournia * Copyright (C) 2008 Zebra Imaging * Copyright (C) 2010 VIRES Simulationstechnologie GmbH + * Copyright (C) 2012 David Callu * * This application is open source and may be redistributed and/or modified * freely and without restriction, both in commercial and non commercial @@ -104,7 +105,8 @@ Program::ProgramBinary::ProgramBinary() : _format(0) { } -Program::ProgramBinary::ProgramBinary(const ProgramBinary& rhs, const osg::CopyOp&) : +Program::ProgramBinary::ProgramBinary(const ProgramBinary& rhs, const osg::CopyOp& copyop) : + osg::Object(rhs, copyop), _data(rhs._data), _format(rhs._format) { } @@ -353,7 +355,7 @@ void Program::setParameter( GLenum pname, GLint value ) } } -void Program::setParameterfv( GLenum pname, const GLfloat* value ) +void Program::setParameterfv( GLenum pname, const GLfloat* /*value*/ ) { switch( pname ) { @@ -714,11 +716,12 @@ void Program::PerContextProgram::linkProgram(osg::State& state) { OSG_WARN << "uniform block " << blockName << " has no binding.\n"; } - } - } + typedef std::map AtomicCounterMap; + AtomicCounterMap atomicCounterMap; + // build _uniformInfoMap GLint numUniforms = 0; GLsizei maxLen = 0; @@ -744,6 +747,11 @@ void Program::PerContextProgram::linkProgram(osg::State& state) name[pos] = 0; } + if (type == GL_UNSIGNED_INT_ATOMIC_COUNTER) + { + atomicCounterMap[i] = name; + } + GLint loc = _extensions->glGetUniformLocation( _glProgramHandle, name ); if( loc != -1 ) @@ -760,6 +768,83 @@ void Program::PerContextProgram::linkProgram(osg::State& state) delete [] name; } + // print atomic counter + if (_extensions->isShaderAtomicCounterSupported()) + { + std::vector bufferIndex( atomicCounterMap.size(), 0 ); + std::vector uniformIndex; + for (AtomicCounterMap::iterator it = atomicCounterMap.begin(), end = atomicCounterMap.end(); + it != end; ++it) + { + uniformIndex.push_back(it->first); + } + + _extensions->glGetActiveUniformsiv( _glProgramHandle, uniformIndex.size(), + &(uniformIndex[0]), GL_UNIFORM_ATOMIC_COUNTER_BUFFER_INDEX, + &(bufferIndex[0]) ); + + for (unsigned int j = 0; j < uniformIndex.size(); ++j) + { + OSG_INFO << "\tUniform atomic counter \""< > bufferIndexToUniformIndices; + for (unsigned int i=0; iglGetProgramiv(_glProgramHandle, GL_ACTIVE_ATOMIC_COUNTER_BUFFERS, + reinterpret_cast(&activeAtomicCounterBuffers)); + if (activeAtomicCounterBuffers > 0) + { + for (GLuint i = 0; i < activeAtomicCounterBuffers; ++i) + { + GLint bindID = 0; + _extensions->glGetActiveAtomicCounterBufferiv(_glProgramHandle, i, + GL_ATOMIC_COUNTER_BUFFER_BINDING, + &bindID); + + GLsizei num = 0; + _extensions->glGetActiveAtomicCounterBufferiv(_glProgramHandle, i, + GL_ATOMIC_COUNTER_BUFFER_ACTIVE_ATOMIC_COUNTERS, + &num); + GLsizei minSize = 0; + _extensions->glGetActiveAtomicCounterBufferiv(_glProgramHandle, i, + GL_ATOMIC_COUNTER_BUFFER_DATA_SIZE, + &minSize); + + + OSG_INFO << "\tUniform atomic counter buffer bind \"" << bindID << "\"" + << " num active atomic counter= "<< num + << " min size= " << minSize << "\n"; + + if (num) + { + std::vector indices(num); + _extensions->glGetActiveAtomicCounterBufferiv(_glProgramHandle, i, + GL_ATOMIC_COUNTER_BUFFER_ACTIVE_ATOMIC_COUNTER_INDICES, + &(indices[0])); + OSG_INFO << "\t\tindices used= "; + for (GLint j = 0; j < num; ++j) + { + OSG_INFO << indices[j]; + if (j < (num-1)) + { + OSG_INFO << ", "; + } + else + { + OSG_INFO << ".\n"; + } + } + } + } + } + } + // build _attribInfoMap GLint numAttrib = 0; _extensions->glGetProgramiv( _glProgramHandle, GL_ACTIVE_ATTRIBUTES, &numAttrib ); diff --git a/src/osg/Uniform.cpp b/src/osg/Uniform.cpp index 70f037731..459590eee 100644 --- a/src/osg/Uniform.cpp +++ b/src/osg/Uniform.cpp @@ -1,6 +1,7 @@ /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield * Copyright (C) 2003-2005 3Dlabs Inc. Ltd. * Copyright (C) 2008 Zebra Imaging + * Copyright (C) 2012 David Callu * * This application is open source and may be redistributed and/or modified * freely and without restriction, both in commercial and non commercial @@ -115,7 +116,7 @@ void Uniform::setNumElements( unsigned int numElements ) void Uniform::allocateDataArray() { // if one array is already allocated, the job is done. - if( _floatArray.valid() || _intArray.valid() || _uintArray.valid() ) return; + if( _floatArray.valid() || _doubleArray.valid() || _intArray.valid() || _uintArray.valid() ) return; // array cannot be created until _type and _numElements are specified int arrayNumElements = getInternalArrayNumElements(); @@ -125,29 +126,24 @@ void Uniform::allocateDataArray() { case GL_FLOAT: _floatArray = new FloatArray(arrayNumElements); - _intArray = 0; - _uintArray = 0; + return; + + case GL_DOUBLE: + _doubleArray = new DoubleArray(arrayNumElements); return; case GL_INT: _intArray = new IntArray(arrayNumElements); - _floatArray = 0; - _uintArray = 0; return; case GL_UNSIGNED_INT: _uintArray = new UIntArray(arrayNumElements); - _floatArray = 0; - _intArray = 0; return; default: break; } } - _floatArray = 0; - _intArray = 0; - _uintArray = 0; } bool Uniform::setArray( FloatArray* array ) @@ -162,6 +158,26 @@ bool Uniform::setArray( FloatArray* array ) } _floatArray = array; + _doubleArray = 0; + _intArray = 0; + _uintArray = 0; + dirty(); + return true; +} + +bool Uniform::setArray( DoubleArray* array ) +{ + if( !array ) return false; + + // incoming array must match configuration of the Uniform + if( getInternalArrayType(getType())!=GL_DOUBLE || getInternalArrayNumElements()!=array->getNumElements() ) + { + OSG_WARN << "Uniform::setArray : incompatible array" << std::endl; + return false; + } + + _doubleArray = array; + _floatArray = 0; _intArray = 0; _uintArray = 0; dirty(); @@ -181,6 +197,7 @@ bool Uniform::setArray( IntArray* array ) _intArray = array; _floatArray = 0; + _doubleArray = 0; _uintArray = 0; dirty(); return true; @@ -199,6 +216,7 @@ bool Uniform::setArray( UIntArray* array ) _uintArray = array; _floatArray = 0; + _doubleArray = 0; _intArray = 0; dirty(); return true; @@ -234,7 +252,15 @@ int Uniform::compareData(const Uniform& rhs) const _floatArray->getTotalDataSize() ); } - if( _intArray.valid() ) + else if( _doubleArray.valid() ) + { + if( ! rhs._doubleArray ) return 1; + if( _doubleArray == rhs._doubleArray ) return 0; + return memcmp( _doubleArray->getDataPointer(), rhs._doubleArray->getDataPointer(), + _doubleArray->getTotalDataSize() ); + } + + else if( _intArray.valid() ) { if( ! rhs._intArray ) return 1; if( _intArray == rhs._intArray ) return 0; @@ -242,7 +268,7 @@ int Uniform::compareData(const Uniform& rhs) const _intArray->getTotalDataSize() ); } - if( _uintArray.valid() ) + else if( _uintArray.valid() ) { if( ! rhs._uintArray ) return 1; if( _uintArray == rhs._uintArray ) return 0; @@ -258,10 +284,11 @@ void Uniform::copyData(const Uniform& rhs) // caller must ensure that _type==rhs._type _numElements = rhs._numElements; _nameID = rhs._nameID; - if (rhs._floatArray.valid() || rhs._intArray.valid() || rhs._uintArray.valid()) allocateDataArray(); - if( _floatArray.valid() && rhs._floatArray.valid() ) *_floatArray = *rhs._floatArray; - if( _intArray.valid() && rhs._intArray.valid() ) *_intArray = *rhs._intArray; - if( _uintArray.valid() && rhs._uintArray.valid() ) *_uintArray = *rhs._uintArray; + if (rhs._floatArray.valid() || rhs._doubleArray.valid() || rhs._intArray.valid() || rhs._uintArray.valid()) allocateDataArray(); + if( _floatArray.valid() && rhs._floatArray.valid() ) *_floatArray = *rhs._floatArray; + if( _doubleArray.valid() && rhs._doubleArray.valid() ) *_doubleArray = *rhs._doubleArray; + if( _intArray.valid() && rhs._intArray.valid() ) *_intArray = *rhs._intArray; + if( _uintArray.valid() && rhs._uintArray.valid() ) *_uintArray = *rhs._uintArray; dirty(); } @@ -276,6 +303,18 @@ bool Uniform::isCompatibleType( Type t ) const return false; } +bool Uniform::isCompatibleType( Type t1, Type t2 ) const +{ + if( (t1==UNDEFINED) || (t2==UNDEFINED) || (getType()==UNDEFINED) ) return false; + if( (t1 == getType()) || (t2 == getType()) ) return true; + if( getGlApiType(t1) == getGlApiType(getType()) ) return true; + if( getGlApiType(t2) == getGlApiType(getType()) ) return true; + + OSG_WARN << "Cannot assign between Uniform types " << getTypename(t1) << " or " << getTypename(t2) + << " and " << getTypename(getType()) << std::endl; + return false; +} + unsigned int Uniform::getInternalArrayNumElements() const { if( getNumElements()<1 || getType()==UNDEFINED ) return 0; @@ -290,59 +329,130 @@ const char* Uniform::getTypename( Type t ) { switch( t ) { - case FLOAT: return "float"; - case FLOAT_VEC2: return "vec2"; - case FLOAT_VEC3: return "vec3"; - case FLOAT_VEC4: return "vec4"; - case INT: return "int"; - case INT_VEC2: return "ivec2"; - case INT_VEC3: return "ivec3"; - case INT_VEC4: return "ivec4"; - case BOOL: return "bool"; - case BOOL_VEC2: return "bvec2"; - case BOOL_VEC3: return "bvec3"; - case BOOL_VEC4: return "bvec4"; - case FLOAT_MAT2: return "mat2"; - case FLOAT_MAT3: return "mat3"; - case FLOAT_MAT4: return "mat4"; - case SAMPLER_1D: return "sampler1D"; - case SAMPLER_2D: return "sampler2D"; - case SAMPLER_1D_ARRAY: return "sampler1DArray"; - case SAMPLER_2D_ARRAY: return "sampler2DArray"; - case SAMPLER_3D: return "sampler3D"; - case SAMPLER_CUBE: return "samplerCube"; - case SAMPLER_1D_SHADOW: return "sampler1DShadow"; - case SAMPLER_2D_SHADOW: return "sampler2DShadow"; - case SAMPLER_1D_ARRAY_SHADOW: return "sampler1DArrayShadow"; - case SAMPLER_2D_ARRAY_SHADOW: return "sampler2DArrayShadow"; - 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: return "unsigned int"; - 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"; + case FLOAT: return "float"; + case FLOAT_VEC2: return "vec2"; + case FLOAT_VEC3: return "vec3"; + case FLOAT_VEC4: return "vec4"; + + case DOUBLE: return "double"; + case DOUBLE_VEC2: return "dvec2"; + case DOUBLE_VEC3: return "dvec3"; + case DOUBLE_VEC4: return "dvec4"; + + case INT: return "int"; + case INT_VEC2: return "ivec2"; + case INT_VEC3: return "ivec3"; + case INT_VEC4: return "ivec4"; + + case UNSIGNED_INT: return "uint"; + case UNSIGNED_INT_VEC2: return "uivec2"; + case UNSIGNED_INT_VEC3: return "uivec3"; + case UNSIGNED_INT_VEC4: return "uivec4"; + + case BOOL: return "bool"; + case BOOL_VEC2: return "bvec2"; + case BOOL_VEC3: return "bvec3"; + case BOOL_VEC4: return "bvec4"; + + case FLOAT_MAT2: return "mat2"; + case FLOAT_MAT3: return "mat3"; + case FLOAT_MAT4: return "mat4"; + 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 DOUBLE_MAT2: return "dmat2"; + case DOUBLE_MAT3: return "dmat3"; + case DOUBLE_MAT4: return "dmat4"; + case DOUBLE_MAT2x3: return "dmat2x3"; + case DOUBLE_MAT2x4: return "dmat2x4"; + case DOUBLE_MAT3x2: return "dmat3x2"; + case DOUBLE_MAT3x4: return "dmat3x4"; + case DOUBLE_MAT4x2: return "dmat4x2"; + case DOUBLE_MAT4x3: return "dmat4x3"; + + case SAMPLER_1D: return "sampler1D"; + case SAMPLER_2D: return "sampler2D"; + case SAMPLER_3D: return "sampler3D"; + case SAMPLER_CUBE: return "samplerCube"; + case SAMPLER_1D_SHADOW: return "sampler1DShadow"; + case SAMPLER_2D_SHADOW: return "sampler2DShadow"; + case SAMPLER_1D_ARRAY: return "sampler1DArray"; + case SAMPLER_2D_ARRAY: return "sampler2DArray"; + case SAMPLER_CUBE_MAP_ARRAY: return "samplerCubeMapArray"; + case SAMPLER_1D_ARRAY_SHADOW: return "sampler1DArrayShadow"; + case SAMPLER_2D_ARRAY_SHADOW: return "sampler2DArrayShadow"; + case SAMPLER_2D_MULTISAMPLE: return "sampler2DMS"; + case SAMPLER_2D_MULTISAMPLE_ARRAY: return "sampler2DMSArray"; + case SAMPLER_CUBE_SHADOW: return "samplerCubeShadow"; + case SAMPLER_CUBE_MAP_ARRAY_SHADOW: return "samplerCubeMapArrayShadow"; + case SAMPLER_BUFFER: return "samplerBuffer"; + case SAMPLER_2D_RECT: return "sampler2DRect"; + case SAMPLER_2D_RECT_SHADOW: return "sampler2DRectShadow"; + + 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_1D_ARRAY: return "isampler1DArray"; + case INT_SAMPLER_2D_ARRAY: return "isampler2DArray"; + case INT_SAMPLER_CUBE_MAP_ARRAY: return "isamplerCubeMapArray"; + case INT_SAMPLER_2D_MULTISAMPLE: return "isampler2DMS"; + case INT_SAMPLER_2D_MULTISAMPLE_ARRAY: return "isampler2DMSArray"; + case INT_SAMPLER_BUFFER: return "isamplerBuffer"; + case INT_SAMPLER_2D_RECT: return "isampler2DRect"; + + case UNSIGNED_INT_SAMPLER_1D: return "usample1D"; + case UNSIGNED_INT_SAMPLER_2D: return "usample2D"; + case UNSIGNED_INT_SAMPLER_3D: return "usample3D"; + case UNSIGNED_INT_SAMPLER_CUBE: return "usampleCube"; + case UNSIGNED_INT_SAMPLER_1D_ARRAY: return "usample1DArray"; + case UNSIGNED_INT_SAMPLER_2D_ARRAY: return "usample2DArray"; + case UNSIGNED_INT_SAMPLER_CUBE_MAP_ARRAY: return "usampleCubeMapArray"; + case UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE: return "usample2DMS"; + case UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE_ARRAY: return "usample2DMSArray"; + case UNSIGNED_INT_SAMPLER_BUFFER: return "usampleBuffer"; + case UNSIGNED_INT_SAMPLER_2D_RECT: return "usample2DRect"; + + case IMAGE_1D: return "image1D"; + case IMAGE_2D: return "image2D"; + case IMAGE_3D: return "image3D"; + case IMAGE_2D_RECT: return "image2DRect"; + case IMAGE_CUBE: return "imageCube"; + case IMAGE_BUFFER: return "imageBuffer"; + case IMAGE_1D_ARRAY: return "image1DArray"; + case IMAGE_2D_ARRAY: return "image2DArray"; + case IMAGE_CUBE_MAP_ARRAY: return "imageCubeArray"; + case IMAGE_2D_MULTISAMPLE: return "image2DMS"; + case IMAGE_2D_MULTISAMPLE_ARRAY: return "image2DMSArray"; + + case INT_IMAGE_1D: return "iimage1D"; + case INT_IMAGE_2D: return "iimage2D"; + case INT_IMAGE_3D: return "iimage3D"; + case INT_IMAGE_2D_RECT: return "iimage2DRect"; + case INT_IMAGE_CUBE: return "iimageCube"; + case INT_IMAGE_BUFFER: return "iimageBuffer"; + case INT_IMAGE_1D_ARRAY: return "iimage1DArray"; + case INT_IMAGE_2D_ARRAY: return "iimage2DArray"; + case INT_IMAGE_CUBE_MAP_ARRAY: return "iimageCubeArray"; + case INT_IMAGE_2D_MULTISAMPLE: return "iimage2DMS"; + case INT_IMAGE_2D_MULTISAMPLE_ARRAY: return "iimage2DMSArray"; + + case UNSIGNED_INT_IMAGE_1D: return "uimage1D"; + case UNSIGNED_INT_IMAGE_2D: return "uimage2D"; + case UNSIGNED_INT_IMAGE_3D: return "uimage3D"; + case UNSIGNED_INT_IMAGE_2D_RECT: return "uimage2DRect"; + case UNSIGNED_INT_IMAGE_CUBE: return "uimageCube"; + case UNSIGNED_INT_IMAGE_BUFFER: return "uimageBuffer"; + case UNSIGNED_INT_IMAGE_1D_ARRAY: return "uimage1DArray"; + case UNSIGNED_INT_IMAGE_2D_ARRAY: return "uimage2DArray"; + case UNSIGNED_INT_IMAGE_CUBE_MAP_ARRAY: return "uimageCubeArray"; + case UNSIGNED_INT_IMAGE_2D_MULTISAMPLE: return "uimage2DMS"; + case UNSIGNED_INT_IMAGE_2D_MULTISAMPLE_ARRAY: return "uimage2DMSArray"; + default: return "UNDEFINED"; } } @@ -352,74 +462,138 @@ int Uniform::getTypeNumComponents( Type t ) switch( t ) { case FLOAT: + case DOUBLE: case INT: case UNSIGNED_INT: case BOOL: + case SAMPLER_1D: case SAMPLER_2D: - case SAMPLER_1D_ARRAY: - case SAMPLER_2D_ARRAY: case SAMPLER_3D: case SAMPLER_CUBE: case SAMPLER_1D_SHADOW: case SAMPLER_2D_SHADOW: + case SAMPLER_1D_ARRAY: + case SAMPLER_2D_ARRAY: + case SAMPLER_CUBE_MAP_ARRAY: case SAMPLER_1D_ARRAY_SHADOW: case SAMPLER_2D_ARRAY_SHADOW: - case SAMPLER_BUFFER: + case SAMPLER_2D_MULTISAMPLE: + case SAMPLER_2D_MULTISAMPLE_ARRAY: case SAMPLER_CUBE_SHADOW: + case SAMPLER_CUBE_MAP_ARRAY_SHADOW: + case SAMPLER_BUFFER: + case SAMPLER_2D_RECT: + case SAMPLER_2D_RECT_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_CUBE_MAP_ARRAY: + case INT_SAMPLER_2D_MULTISAMPLE: + case INT_SAMPLER_2D_MULTISAMPLE_ARRAY: case INT_SAMPLER_BUFFER: + case INT_SAMPLER_2D_RECT: + 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_CUBE_MAP_ARRAY: + case UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE: + case UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE_ARRAY: case UNSIGNED_INT_SAMPLER_BUFFER: + case UNSIGNED_INT_SAMPLER_2D_RECT: + + case IMAGE_1D: + case IMAGE_2D: + case IMAGE_3D: + case IMAGE_2D_RECT: + case IMAGE_CUBE: + case IMAGE_BUFFER: + case IMAGE_1D_ARRAY: + case IMAGE_2D_ARRAY: + case IMAGE_CUBE_MAP_ARRAY: + case IMAGE_2D_MULTISAMPLE: + case IMAGE_2D_MULTISAMPLE_ARRAY: + + case INT_IMAGE_1D: + case INT_IMAGE_2D: + case INT_IMAGE_3D: + case INT_IMAGE_2D_RECT: + case INT_IMAGE_CUBE: + case INT_IMAGE_BUFFER: + case INT_IMAGE_1D_ARRAY: + case INT_IMAGE_2D_ARRAY: + case INT_IMAGE_CUBE_MAP_ARRAY: + case INT_IMAGE_2D_MULTISAMPLE: + case INT_IMAGE_2D_MULTISAMPLE_ARRAY: + + case UNSIGNED_INT_IMAGE_1D: + case UNSIGNED_INT_IMAGE_2D: + case UNSIGNED_INT_IMAGE_3D: + case UNSIGNED_INT_IMAGE_2D_RECT: + case UNSIGNED_INT_IMAGE_CUBE: + case UNSIGNED_INT_IMAGE_BUFFER: + case UNSIGNED_INT_IMAGE_1D_ARRAY: + case UNSIGNED_INT_IMAGE_2D_ARRAY: + case UNSIGNED_INT_IMAGE_CUBE_MAP_ARRAY: + case UNSIGNED_INT_IMAGE_2D_MULTISAMPLE: + case UNSIGNED_INT_IMAGE_2D_MULTISAMPLE_ARRAY: return 1; case FLOAT_VEC2: + case DOUBLE_VEC2: case INT_VEC2: - case BOOL_VEC2: case UNSIGNED_INT_VEC2: + case BOOL_VEC2: return 2; case FLOAT_VEC3: + case DOUBLE_VEC3: case INT_VEC3: - case BOOL_VEC3: case UNSIGNED_INT_VEC3: + case BOOL_VEC3: return 3; case FLOAT_VEC4: + case DOUBLE_VEC4: case FLOAT_MAT2: + case DOUBLE_MAT2: case INT_VEC4: - case BOOL_VEC4: case UNSIGNED_INT_VEC4: + case BOOL_VEC4: return 4; case FLOAT_MAT2x3: case FLOAT_MAT3x2: + case DOUBLE_MAT2x3: + case DOUBLE_MAT3x2: return 6; case FLOAT_MAT2x4: case FLOAT_MAT4x2: + case DOUBLE_MAT2x4: + case DOUBLE_MAT4x2: return 8; case FLOAT_MAT3: + case DOUBLE_MAT3: return 9; case FLOAT_MAT3x4: case FLOAT_MAT4x3: + case DOUBLE_MAT3x4: + case DOUBLE_MAT4x3: return 12; case FLOAT_MAT4: + case DOUBLE_MAT4: return 16; default: @@ -433,55 +607,125 @@ Uniform::Type Uniform::getTypeId( const std::string& tname ) if( tname == "vec2" ) return FLOAT_VEC2; if( tname == "vec3" ) return FLOAT_VEC3; if( tname == "vec4" ) return FLOAT_VEC4; + + if( tname == "double" ) return DOUBLE; + if( tname == "dvec2" ) return DOUBLE_VEC2; + if( tname == "dvec3" ) return DOUBLE_VEC3; + if( tname == "dvec4" ) return DOUBLE_VEC4; + if( tname == "int" ) return INT; if( tname == "ivec2" ) return INT_VEC2; if( tname == "ivec3" ) return INT_VEC3; if( tname == "ivec4" ) return INT_VEC4; + + if( tname == "unsigned int" || tname == "uint" ) return UNSIGNED_INT; + if( tname == "uvec2" ) return UNSIGNED_INT_VEC2; + if( tname == "uvec3" ) return UNSIGNED_INT_VEC3; + if( tname == "uvec4" ) return UNSIGNED_INT_VEC4; + if( tname == "bool" ) return BOOL; if( tname == "bvec2" ) return BOOL_VEC2; if( tname == "bvec3" ) return BOOL_VEC3; if( tname == "bvec4" ) return BOOL_VEC4; + 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; - if( tname == "sampler2DArray" ) return SAMPLER_2D_ARRAY; - if( tname == "sampler3D" ) return SAMPLER_3D; - if( tname == "samplerCube" ) return SAMPLER_CUBE; - if( tname == "sampler1DShadow" ) return SAMPLER_1D_SHADOW; - 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 == "unsigned int" ) return UNSIGNED_INT; - 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; + 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 == "mat2d" || tname == "mat2x2d" ) return DOUBLE_MAT2; + if( tname == "mat3d" || tname == "mat3x3d" ) return DOUBLE_MAT3; + if( tname == "mat4d" || tname == "mat4x4d" ) return DOUBLE_MAT4; + if( tname == "mat2x3d" ) return DOUBLE_MAT2x3; + if( tname == "mat2x4d" ) return DOUBLE_MAT2x4; + if( tname == "mat3x2d" ) return DOUBLE_MAT3x2; + if( tname == "mat3x4d" ) return DOUBLE_MAT3x4; + if( tname == "mat4x2d" ) return DOUBLE_MAT4x2; + if( tname == "mat4x3d" ) return DOUBLE_MAT4x3; + + if( tname == "sampler1D" ) return SAMPLER_1D; + if( tname == "sampler2D" ) return SAMPLER_2D; + if( tname == "sampler3D" ) return SAMPLER_3D; + if( tname == "samplerCube" ) return SAMPLER_CUBE; + if( tname == "sampler1DShadow" ) return SAMPLER_1D_SHADOW; + if( tname == "sampler2DShadow" ) return SAMPLER_2D_SHADOW; + if( tname == "sampler1DArray" ) return SAMPLER_1D_ARRAY; + if( tname == "sampler2DArray" ) return SAMPLER_2D_ARRAY; + if( tname == "samplerCubeMapArray" ) return SAMPLER_CUBE_MAP_ARRAY; + if( tname == "sampler1DArrayShadow" ) return SAMPLER_1D_ARRAY_SHADOW; + if( tname == "sampler2DArrayShadow" ) return SAMPLER_2D_ARRAY_SHADOW; + if( tname == "sampler2DMS" ) return SAMPLER_2D_MULTISAMPLE; + if( tname == "sampler2DMSArray" ) return SAMPLER_2D_MULTISAMPLE_ARRAY; + if( tname == "samplerCubeShadow" ) return SAMPLER_CUBE_SHADOW; + if( tname == "samplerCubeMapArrayShadow" ) return SAMPLER_CUBE_MAP_ARRAY_SHADOW; + if( tname == "samplerBuffer" ) return SAMPLER_BUFFER; + if( tname == "sampler2DRect" ) return SAMPLER_2D_RECT; + if( tname == "sampler2DRectShadow" ) return SAMPLER_2D_RECT_SHADOW; + + 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 == "isampler1DArray" ) return INT_SAMPLER_1D_ARRAY; + if( tname == "isampler2DArray" ) return INT_SAMPLER_2D_ARRAY; + if( tname == "isamplerCubeMapArray" ) return INT_SAMPLER_CUBE_MAP_ARRAY; + if( tname == "isampler2DMS" ) return INT_SAMPLER_2D_MULTISAMPLE; + if( tname == "isampler2DMSArray" ) return INT_SAMPLER_2D_MULTISAMPLE_ARRAY; + if( tname == "isamplerBuffer" ) return INT_SAMPLER_BUFFER; + if( tname == "isampler2DRect" ) return INT_SAMPLER_2D_RECT; + + 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 == "usampler1DArray" ) return UNSIGNED_INT_SAMPLER_1D_ARRAY; + if( tname == "usampler2DArray" ) return UNSIGNED_INT_SAMPLER_2D_ARRAY; + if( tname == "usamplerCubeMapArray" ) return UNSIGNED_INT_SAMPLER_CUBE_MAP_ARRAY; + if( tname == "usampler2DMS" ) return UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE; + if( tname == "usampler2DMSArray" ) return UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE_ARRAY; + if( tname == "usamplerBuffer" ) return UNSIGNED_INT_SAMPLER_BUFFER; + if( tname == "usampler2DRect" ) return UNSIGNED_INT_SAMPLER_2D_RECT; + + if( tname == "image1D" ) return IMAGE_1D; + if( tname == "image2D" ) return IMAGE_2D; + if( tname == "image3D" ) return IMAGE_3D; + if( tname == "image2DRect" ) return IMAGE_2D_RECT; + if( tname == "imageCube" ) return IMAGE_CUBE; + if( tname == "imageBuffer" ) return IMAGE_BUFFER; + if( tname == "image1DArray" ) return IMAGE_1D_ARRAY; + if( tname == "image2DArray" ) return IMAGE_2D_ARRAY; + if( tname == "imageCubeArray" ) return IMAGE_CUBE_MAP_ARRAY; + if( tname == "image2DMS" ) return IMAGE_2D_MULTISAMPLE; + if( tname == "image2DMSArray" ) return IMAGE_2D_MULTISAMPLE_ARRAY; + + if( tname == "iimage1D" ) return INT_IMAGE_1D; + if( tname == "iimage2D" ) return INT_IMAGE_2D; + if( tname == "iimage3D" ) return INT_IMAGE_3D; + if( tname == "iimage2DRect" ) return INT_IMAGE_2D_RECT; + if( tname == "iimageCube" ) return INT_IMAGE_CUBE; + if( tname == "iimageBuffer" ) return INT_IMAGE_BUFFER; + if( tname == "iimage1DArray" ) return INT_IMAGE_1D_ARRAY; + if( tname == "iimage2DArray" ) return INT_IMAGE_2D_ARRAY; + if( tname == "iimageCubeArray" ) return INT_IMAGE_CUBE_MAP_ARRAY; + if( tname == "iimage2DMS" ) return INT_IMAGE_2D_MULTISAMPLE; + if( tname == "iimage2DMSArray" ) return INT_IMAGE_2D_MULTISAMPLE_ARRAY; + + if( tname == "uimage1D" ) return UNSIGNED_INT_IMAGE_1D; + if( tname == "uimage2D" ) return UNSIGNED_INT_IMAGE_2D; + if( tname == "uimage3D" ) return UNSIGNED_INT_IMAGE_3D; + if( tname == "uimage2DRect" ) return UNSIGNED_INT_IMAGE_2D_RECT; + if( tname == "uimageCube" ) return UNSIGNED_INT_IMAGE_CUBE; + if( tname == "uimageBuffer" ) return UNSIGNED_INT_IMAGE_BUFFER; + if( tname == "uimage1DArray" ) return UNSIGNED_INT_IMAGE_1D_ARRAY; + if( tname == "uimage2DArray" ) return UNSIGNED_INT_IMAGE_2D_ARRAY; + if( tname == "uimageCubeArray" ) return UNSIGNED_INT_IMAGE_CUBE_MAP_ARRAY; + if( tname == "uimage2DMS" ) return UNSIGNED_INT_IMAGE_2D_MULTISAMPLE; + if( tname == "uimage2DMSArray" ) return UNSIGNED_INT_IMAGE_2D_MULTISAMPLE_ARRAY; return UNDEFINED; } @@ -491,34 +735,85 @@ Uniform::Type Uniform::getGlApiType( Type t ) switch( t ) { case BOOL: + case SAMPLER_1D: case SAMPLER_2D: - case SAMPLER_1D_ARRAY: - case SAMPLER_2D_ARRAY: case SAMPLER_3D: case SAMPLER_CUBE: case SAMPLER_1D_SHADOW: case SAMPLER_2D_SHADOW: + case SAMPLER_1D_ARRAY: + case SAMPLER_2D_ARRAY: + case SAMPLER_CUBE_MAP_ARRAY: case SAMPLER_1D_ARRAY_SHADOW: case SAMPLER_2D_ARRAY_SHADOW: - case SAMPLER_BUFFER: + case SAMPLER_2D_MULTISAMPLE: + case SAMPLER_2D_MULTISAMPLE_ARRAY: case SAMPLER_CUBE_SHADOW: + case SAMPLER_CUBE_MAP_ARRAY_SHADOW: + case SAMPLER_BUFFER: + case SAMPLER_2D_RECT: + case SAMPLER_2D_RECT_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_CUBE_MAP_ARRAY: + case INT_SAMPLER_2D_MULTISAMPLE: + case INT_SAMPLER_2D_MULTISAMPLE_ARRAY: case INT_SAMPLER_BUFFER: + case INT_SAMPLER_2D_RECT: + 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_CUBE_MAP_ARRAY: + case UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE: + case UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE_ARRAY: case UNSIGNED_INT_SAMPLER_BUFFER: + case UNSIGNED_INT_SAMPLER_2D_RECT: + + case IMAGE_1D: + case IMAGE_2D: + case IMAGE_3D: + case IMAGE_2D_RECT: + case IMAGE_CUBE: + case IMAGE_BUFFER: + case IMAGE_1D_ARRAY: + case IMAGE_2D_ARRAY: + case IMAGE_CUBE_MAP_ARRAY: + case IMAGE_2D_MULTISAMPLE: + case IMAGE_2D_MULTISAMPLE_ARRAY: + + case INT_IMAGE_1D: + case INT_IMAGE_2D: + case INT_IMAGE_3D: + case INT_IMAGE_2D_RECT: + case INT_IMAGE_CUBE: + case INT_IMAGE_BUFFER: + case INT_IMAGE_1D_ARRAY: + case INT_IMAGE_2D_ARRAY: + case INT_IMAGE_CUBE_MAP_ARRAY: + case INT_IMAGE_2D_MULTISAMPLE: + case INT_IMAGE_2D_MULTISAMPLE_ARRAY: + + case UNSIGNED_INT_IMAGE_1D: + case UNSIGNED_INT_IMAGE_2D: + case UNSIGNED_INT_IMAGE_3D: + case UNSIGNED_INT_IMAGE_2D_RECT: + case UNSIGNED_INT_IMAGE_CUBE: + case UNSIGNED_INT_IMAGE_BUFFER: + case UNSIGNED_INT_IMAGE_1D_ARRAY: + case UNSIGNED_INT_IMAGE_2D_ARRAY: + case UNSIGNED_INT_IMAGE_CUBE_MAP_ARRAY: + case UNSIGNED_INT_IMAGE_2D_MULTISAMPLE: + case UNSIGNED_INT_IMAGE_2D_MULTISAMPLE_ARRAY: return INT; case BOOL_VEC2: @@ -554,6 +849,21 @@ GLenum Uniform::getInternalArrayType( Type t ) case FLOAT_MAT4x3: return GL_FLOAT; + case DOUBLE: + case DOUBLE_VEC2: + case DOUBLE_VEC3: + case DOUBLE_VEC4: + case DOUBLE_MAT2: + case DOUBLE_MAT3: + case DOUBLE_MAT4: + case DOUBLE_MAT2x3: + case DOUBLE_MAT2x4: + case DOUBLE_MAT3x2: + case DOUBLE_MAT3x4: + case DOUBLE_MAT4x2: + case DOUBLE_MAT4x3: + return GL_DOUBLE; + case INT: case INT_VEC2: case INT_VEC3: @@ -564,32 +874,82 @@ GLenum Uniform::getInternalArrayType( Type t ) case BOOL_VEC4: case SAMPLER_1D: case SAMPLER_2D: - case SAMPLER_1D_ARRAY: - case SAMPLER_2D_ARRAY: case SAMPLER_3D: case SAMPLER_CUBE: case SAMPLER_1D_SHADOW: case SAMPLER_2D_SHADOW: + case SAMPLER_1D_ARRAY: + case SAMPLER_2D_ARRAY: + case SAMPLER_CUBE_MAP_ARRAY: case SAMPLER_1D_ARRAY_SHADOW: case SAMPLER_2D_ARRAY_SHADOW: - case SAMPLER_BUFFER: + case SAMPLER_2D_MULTISAMPLE: + case SAMPLER_2D_MULTISAMPLE_ARRAY: case SAMPLER_CUBE_SHADOW: + case SAMPLER_CUBE_MAP_ARRAY_SHADOW: + case SAMPLER_BUFFER: + case SAMPLER_2D_RECT: + case SAMPLER_2D_RECT_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_CUBE_MAP_ARRAY: + case INT_SAMPLER_2D_MULTISAMPLE: + case INT_SAMPLER_2D_MULTISAMPLE_ARRAY: case INT_SAMPLER_BUFFER: + case INT_SAMPLER_2D_RECT: + 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_CUBE_MAP_ARRAY: + case UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE: + case UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE_ARRAY: case UNSIGNED_INT_SAMPLER_BUFFER: + case UNSIGNED_INT_SAMPLER_2D_RECT: + + case IMAGE_1D: + case IMAGE_2D: + case IMAGE_3D: + case IMAGE_2D_RECT: + case IMAGE_CUBE: + case IMAGE_BUFFER: + case IMAGE_1D_ARRAY: + case IMAGE_2D_ARRAY: + case IMAGE_CUBE_MAP_ARRAY: + case IMAGE_2D_MULTISAMPLE: + case IMAGE_2D_MULTISAMPLE_ARRAY: + + case INT_IMAGE_1D: + case INT_IMAGE_2D: + case INT_IMAGE_3D: + case INT_IMAGE_2D_RECT: + case INT_IMAGE_CUBE: + case INT_IMAGE_BUFFER: + case INT_IMAGE_1D_ARRAY: + case INT_IMAGE_2D_ARRAY: + case INT_IMAGE_CUBE_MAP_ARRAY: + case INT_IMAGE_2D_MULTISAMPLE: + case INT_IMAGE_2D_MULTISAMPLE_ARRAY: + + case UNSIGNED_INT_IMAGE_1D: + case UNSIGNED_INT_IMAGE_2D: + case UNSIGNED_INT_IMAGE_3D: + case UNSIGNED_INT_IMAGE_2D_RECT: + case UNSIGNED_INT_IMAGE_CUBE: + case UNSIGNED_INT_IMAGE_BUFFER: + case UNSIGNED_INT_IMAGE_1D_ARRAY: + case UNSIGNED_INT_IMAGE_2D_ARRAY: + case UNSIGNED_INT_IMAGE_CUBE_MAP_ARRAY: + case UNSIGNED_INT_IMAGE_2D_MULTISAMPLE: + case UNSIGNED_INT_IMAGE_2D_MULTISAMPLE_ARRAY: return GL_INT; case UNSIGNED_INT: @@ -681,14 +1041,158 @@ Uniform::Uniform( const char* name, const osg::Matrixf& m4 ) : set( m4 ); } +Uniform::Uniform( const char* name, const osg::Matrix2x3& m2x3 ) : + _type(FLOAT_MAT2x3), _numElements(1), _modifiedCount(0) +{ + setName(name); + allocateDataArray(); + set( m2x3 ); +} + +Uniform::Uniform( const char* name, const osg::Matrix2x4& m2x4 ) : + _type(FLOAT_MAT2x4), _numElements(1), _modifiedCount(0) +{ + setName(name); + allocateDataArray(); + set( m2x4 ); +} + +Uniform::Uniform( const char* name, const osg::Matrix3x2& m3x2 ) : + _type(FLOAT_MAT3x2), _numElements(1), _modifiedCount(0) +{ + setName(name); + allocateDataArray(); + set( m3x2 ); +} + +Uniform::Uniform( const char* name, const osg::Matrix3x4& m3x4 ) : + _type(FLOAT_MAT3x4), _numElements(1), _modifiedCount(0) +{ + setName(name); + allocateDataArray(); + set( m3x4 ); +} + +Uniform::Uniform( const char* name, const osg::Matrix4x2& m4x2 ) : + _type(FLOAT_MAT4x2), _numElements(1), _modifiedCount(0) +{ + setName(name); + allocateDataArray(); + set( m4x2 ); +} + +Uniform::Uniform( const char* name, const osg::Matrix4x3& m4x3 ) : + _type(FLOAT_MAT4x3), _numElements(1), _modifiedCount(0) +{ + setName(name); + allocateDataArray(); + set( m4x3 ); +} + +Uniform::Uniform( const char* name, double d ) : + _type(DOUBLE), _numElements(1), _modifiedCount(0) +{ + setName(name); + allocateDataArray(); + set( d ); +} + +Uniform::Uniform( const char* name, const osg::Vec2d& v2 ) : + _type(DOUBLE_VEC2), _numElements(1), _modifiedCount(0) +{ + setName(name); + allocateDataArray(); + set( v2 ); +} + +Uniform::Uniform( const char* name, const osg::Vec3d& v3 ) : + _type(DOUBLE_VEC3), _numElements(1), _modifiedCount(0) +{ + setName(name); + allocateDataArray(); + set( v3 ); +} + +Uniform::Uniform( const char* name, const osg::Vec4d& v4 ) : + _type(DOUBLE_VEC4), _numElements(1), _modifiedCount(0) +{ + setName(name); + allocateDataArray(); + set( v4 ); +} + +Uniform::Uniform( const char* name, const osg::Matrix2d& m2 ) : + _type(DOUBLE_MAT2), _numElements(1), _modifiedCount(0) +{ + setName(name); + allocateDataArray(); + set( m2 ); +} + +Uniform::Uniform( const char* name, const osg::Matrix3d& m3 ) : + _type(DOUBLE_MAT3), _numElements(1), _modifiedCount(0) +{ + setName(name); + allocateDataArray(); + set( m3 ); +} + Uniform::Uniform( const char* name, const osg::Matrixd& m4 ) : - _type(FLOAT_MAT4), _numElements(1), _modifiedCount(0) + _type(DOUBLE_MAT4), _numElements(1), _modifiedCount(0) { setName(name); allocateDataArray(); set( m4 ); } +Uniform::Uniform( const char* name, const osg::Matrix2x3d& m2x3 ) : + _type(DOUBLE_MAT2x3), _numElements(1), _modifiedCount(0) +{ + setName(name); + allocateDataArray(); + set( m2x3 ); +} + +Uniform::Uniform( const char* name, const osg::Matrix2x4d& m2x4 ) : + _type(DOUBLE_MAT2x4), _numElements(1), _modifiedCount(0) +{ + setName(name); + allocateDataArray(); + set( m2x4 ); +} + +Uniform::Uniform( const char* name, const osg::Matrix3x2d& m3x2 ) : + _type(DOUBLE_MAT3x2), _numElements(1), _modifiedCount(0) +{ + setName(name); + allocateDataArray(); + set( m3x2 ); +} + +Uniform::Uniform( const char* name, const osg::Matrix3x4d& m3x4 ) : + _type(DOUBLE_MAT3x4), _numElements(1), _modifiedCount(0) +{ + setName(name); + allocateDataArray(); + set( m3x4 ); +} + +Uniform::Uniform( const char* name, const osg::Matrix4x2d& m4x2 ) : + _type(DOUBLE_MAT4x2), _numElements(1), _modifiedCount(0) +{ + setName(name); + allocateDataArray(); + set( m4x2 ); +} + +Uniform::Uniform( const char* name, const osg::Matrix4x3d& m4x3 ) : + _type(DOUBLE_MAT4x3), _numElements(1), _modifiedCount(0) +{ + setName(name); + allocateDataArray(); + set( m4x3 ); +} + Uniform::Uniform( const char* name, int i ) : _type(INT), _numElements(1), _modifiedCount(0) { @@ -721,36 +1225,36 @@ Uniform::Uniform( const char* name, int i0, int i1, int i2, int i3 ) : set( i0, i1, i2, i3 ); } -Uniform::Uniform( const char* name, unsigned int i ) : +Uniform::Uniform( const char* name, unsigned int ui ) : _type(UNSIGNED_INT), _numElements(1), _modifiedCount(0) { setName(name); allocateDataArray(); - set( i ); + set( ui ); } -Uniform::Uniform( const char* name, unsigned int i0, unsigned int i1 ) : +Uniform::Uniform( const char* name, unsigned int ui0, unsigned int ui1 ) : _type(UNSIGNED_INT_VEC2), _numElements(1), _modifiedCount(0) { setName(name); allocateDataArray(); - set( i0, i1 ); + set( ui0, ui1 ); } -Uniform::Uniform( const char* name, unsigned int i0, unsigned int i1, unsigned int i2 ) : +Uniform::Uniform( const char* name, unsigned int ui0, unsigned int ui1, unsigned int ui2 ) : _type(UNSIGNED_INT_VEC3), _numElements(1), _modifiedCount(0) { setName(name); allocateDataArray(); - set( i0, i1, i2 ); + set( ui0, ui1, ui2 ); } -Uniform::Uniform( const char* name, unsigned int i0, unsigned int i1, unsigned int i2, unsigned int i3 ) : +Uniform::Uniform( const char* name, unsigned int ui0, unsigned int ui1, unsigned int ui2, unsigned int ui3 ) : _type(UNSIGNED_INT_VEC4), _numElements(1), _modifiedCount(0) { setName(name); allocateDataArray(); - set( i0, i1, i2, i3 ); + set( ui0, ui1, ui2, ui3 ); } Uniform::Uniform( const char* name, bool b ) : @@ -832,12 +1336,120 @@ bool Uniform::set( const osg::Matrixf& m4 ) return isScalar() ? setElement(0,m4) : false; } +bool Uniform::set( const osg::Matrix2x3& m2x3 ) +{ + if( getNumElements() == 0 ) setNumElements(1); + return isScalar() ? setElement(0,m2x3) : false; +} + +bool Uniform::set( const osg::Matrix2x4& m2x4 ) +{ + if( getNumElements() == 0 ) setNumElements(1); + return isScalar() ? setElement(0,m2x4) : false; +} + +bool Uniform::set( const osg::Matrix3x2& m3x2 ) +{ + if( getNumElements() == 0 ) setNumElements(1); + return isScalar() ? setElement(0,m3x2) : false; +} + +bool Uniform::set( const osg::Matrix3x4& m3x4 ) +{ + if( getNumElements() == 0 ) setNumElements(1); + return isScalar() ? setElement(0,m3x4) : false; +} + +bool Uniform::set( const osg::Matrix4x2& m4x2 ) +{ + if( getNumElements() == 0 ) setNumElements(1); + return isScalar() ? setElement(0,m4x2) : false; +} + +bool Uniform::set( const osg::Matrix4x3& m4x3 ) +{ + if( getNumElements() == 0 ) setNumElements(1); + return isScalar() ? setElement(0,m4x3) : false; +} + +bool Uniform::set( double d ) +{ + if( getNumElements() == 0 ) setNumElements(1); + return isScalar() ? setElement(0,d) : false; +} + +bool Uniform::set( const osg::Vec2d& v2 ) +{ + if( getNumElements() == 0 ) setNumElements(1); + return isScalar() ? setElement(0,v2) : false; +} + +bool Uniform::set( const osg::Vec3d& v3 ) +{ + if( getNumElements() == 0 ) setNumElements(1); + return isScalar() ? setElement(0,v3) : false; +} + +bool Uniform::set( const osg::Vec4d& v4 ) +{ + if( getNumElements() == 0 ) setNumElements(1); + return isScalar() ? setElement(0,v4) : false; +} + +bool Uniform::set( const osg::Matrix2d& m2 ) +{ + if( getNumElements() == 0 ) setNumElements(1); + return isScalar() ? setElement(0,m2) : false; +} + +bool Uniform::set( const osg::Matrix3d& m3 ) +{ + if( getNumElements() == 0 ) setNumElements(1); + return isScalar() ? setElement(0,m3) : false; +} + bool Uniform::set( const osg::Matrixd& m4 ) { if( getNumElements() == 0 ) setNumElements(1); return isScalar() ? setElement(0,m4) : false; } +bool Uniform::set( const osg::Matrix2x3d& m2x3 ) +{ + if( getNumElements() == 0 ) setNumElements(1); + return isScalar() ? setElement(0,m2x3) : false; +} + +bool Uniform::set( const osg::Matrix2x4d& m2x4 ) +{ + if( getNumElements() == 0 ) setNumElements(1); + return isScalar() ? setElement(0,m2x4) : false; +} + +bool Uniform::set( const osg::Matrix3x2d& m3x2 ) +{ + if( getNumElements() == 0 ) setNumElements(1); + return isScalar() ? setElement(0,m3x2) : false; +} + +bool Uniform::set( const osg::Matrix3x4d& m3x4 ) +{ + if( getNumElements() == 0 ) setNumElements(1); + return isScalar() ? setElement(0,m3x4) : false; +} + +bool Uniform::set( const osg::Matrix4x2d& m4x2 ) +{ + if( getNumElements() == 0 ) setNumElements(1); + return isScalar() ? setElement(0,m4x2) : false; +} + +bool Uniform::set( const osg::Matrix4x3d& m4x3 ) +{ + if( getNumElements() == 0 ) setNumElements(1); + return isScalar() ? setElement(0,m4x3) : false; +} + bool Uniform::set( int i ) { if( getNumElements() == 0 ) setNumElements(1); @@ -862,28 +1474,28 @@ bool Uniform::set( int i0, int i1, int i2, int i3 ) return isScalar() ? setElement(0,i0,i1,i2,i3) : false; } -bool Uniform::set( unsigned int i ) +bool Uniform::set( unsigned int ui ) { if( getNumElements() == 0 ) setNumElements(1); - return isScalar() ? setElement(0,i) : false; + return isScalar() ? setElement(0,ui) : false; } -bool Uniform::set( unsigned int i0, unsigned int i1 ) +bool Uniform::set( unsigned int ui0, unsigned int ui1 ) { if( getNumElements() == 0 ) setNumElements(1); - return isScalar() ? setElement(0,i0,i1) : false; + return isScalar() ? setElement(0,ui0,ui1) : false; } -bool Uniform::set( unsigned int i0, unsigned int i1, unsigned int i2 ) +bool Uniform::set( unsigned int ui0, unsigned int ui1, unsigned int ui2 ) { if( getNumElements() == 0 ) setNumElements(1); - return isScalar() ? setElement(0,i0,i1,i2) : false; + return isScalar() ? setElement(0,ui0,ui1,ui2) : false; } -bool Uniform::set( unsigned int i0, unsigned int i1, unsigned int i2, unsigned int i3 ) +bool Uniform::set( unsigned int ui0, unsigned int ui1, unsigned int ui2, unsigned int ui3 ) { if( getNumElements() == 0 ) setNumElements(1); - return isScalar() ? setElement(0,i0,i1,i2,i3) : false; + return isScalar() ? setElement(0,ui0,ui1,ui2,ui3) : false; } bool Uniform::set( bool b ) @@ -948,11 +1560,101 @@ bool Uniform::get( osg::Matrixf& m4 ) const return isScalar() ? getElement(0,m4) : false; } +bool Uniform::get( osg::Matrix2x3& m2x3 ) const +{ + return isScalar() ? getElement(0,m2x3) : false; +} + +bool Uniform::get( osg::Matrix2x4& m2x4 ) const +{ + return isScalar() ? getElement(0,m2x4) : false; +} + +bool Uniform::get( osg::Matrix3x2& m3x2 ) const +{ + return isScalar() ? getElement(0,m3x2) : false; +} + +bool Uniform::get( osg::Matrix3x4& m3x4 ) const +{ + return isScalar() ? getElement(0,m3x4) : false; +} + +bool Uniform::get( osg::Matrix4x2& m4x2 ) const +{ + return isScalar() ? getElement(0,m4x2) : false; +} + +bool Uniform::get( osg::Matrix4x3& m4x3 ) const +{ + return isScalar() ? getElement(0,m4x3) : false; +} + +bool Uniform::get( double& d ) const +{ + return isScalar() ? getElement(0,d) : false; +} + +bool Uniform::get( osg::Vec2d& v2 ) const +{ + return isScalar() ? getElement(0,v2) : false; +} + +bool Uniform::get( osg::Vec3d& v3 ) const +{ + return isScalar() ? getElement(0,v3) : false; +} + +bool Uniform::get( osg::Vec4d& v4 ) const +{ + return isScalar() ? getElement(0,v4) : false; +} + +bool Uniform::get( osg::Matrix2d& m2 ) const +{ + return isScalar() ? getElement(0,m2) : false; +} + +bool Uniform::get( osg::Matrix3d& m3 ) const +{ + return isScalar() ? getElement(0,m3) : false; +} + bool Uniform::get( osg::Matrixd& m4 ) const { return isScalar() ? getElement(0,m4) : false; } +bool Uniform::get( osg::Matrix2x3d& m2x3 ) const +{ + return isScalar() ? getElement(0,m2x3) : false; +} + +bool Uniform::get( osg::Matrix2x4d& m2x4 ) const +{ + return isScalar() ? getElement(0,m2x4) : false; +} + +bool Uniform::get( osg::Matrix3x2d& m3x2 ) const +{ + return isScalar() ? getElement(0,m3x2) : false; +} + +bool Uniform::get( osg::Matrix3x4d& m3x4 ) const +{ + return isScalar() ? getElement(0,m3x4) : false; +} + +bool Uniform::get( osg::Matrix4x2d& m4x2 ) const +{ + return isScalar() ? getElement(0,m4x2) : false; +} + +bool Uniform::get( osg::Matrix4x3d& m4x3 ) const +{ + return isScalar() ? getElement(0,m4x3) : false; +} + bool Uniform::get( int& i ) const { return isScalar() ? getElement(0,i) : false; @@ -973,24 +1675,24 @@ bool Uniform::get( int& i0, int& i1, int& i2, int& i3 ) const return isScalar() ? getElement(0,i0,i1,i2,i3) : false; } -bool Uniform::get( unsigned int& i ) const +bool Uniform::get( unsigned int& ui ) const { - return isScalar() ? getElement(0,i) : false; + return isScalar() ? getElement(0,ui) : false; } -bool Uniform::get( unsigned int& i0, unsigned int& i1 ) const +bool Uniform::get( unsigned int& ui0, unsigned int& ui1 ) const { - return isScalar() ? getElement(0,i0,i1) : false; + return isScalar() ? getElement(0,ui0,ui1) : false; } -bool Uniform::get( unsigned int& i0, unsigned int& i1, unsigned int& i2 ) const +bool Uniform::get( unsigned int& ui0, unsigned int& ui1, unsigned int& ui2 ) const { - return isScalar() ? getElement(0,i0,i1,i2) : false; + return isScalar() ? getElement(0,ui0,ui1,ui2) : false; } -bool Uniform::get( unsigned int& i0, unsigned int& i1, unsigned int& i2, unsigned int& i3 ) const +bool Uniform::get( unsigned int& ui0, unsigned int& ui1, unsigned int& ui2, unsigned int& ui3 ) const { - return isScalar() ? getElement(0,i0,i1,i2,i3) : false; + return isScalar() ? getElement(0,ui0,ui1,ui2,ui3) : false; } bool Uniform::get( bool& b ) const @@ -1086,12 +1788,189 @@ bool Uniform::setElement( unsigned int index, const osg::Matrixf& m4 ) return true; } +bool Uniform::setElement( unsigned int index, const osg::Matrix2x3& m2x3 ) +{ + if( index>=getNumElements() || !isCompatibleType(FLOAT_MAT2x3) ) return false; + unsigned int j = index * getTypeNumComponents(getType()); + for( int i = 0; i < 6; ++i ) (*_floatArray)[j+i] = m2x3[i]; + dirty(); + return true; +} + +bool Uniform::setElement( unsigned int index, const osg::Matrix2x4& m2x4 ) +{ + if( index>=getNumElements() || !isCompatibleType(FLOAT_MAT2x4) ) return false; + unsigned int j = index * getTypeNumComponents(getType()); + for( int i = 0; i < 8; ++i ) (*_floatArray)[j+i] = m2x4[i]; + dirty(); + return true; +} + +bool Uniform::setElement( unsigned int index, const osg::Matrix3x2& m3x2 ) +{ + if( index>=getNumElements() || !isCompatibleType(FLOAT_MAT3x2) ) return false; + unsigned int j = index * getTypeNumComponents(getType()); + for( int i = 0; i < 6; ++i ) (*_floatArray)[j+i] = m3x2[i]; + dirty(); + return true; +} + +bool Uniform::setElement( unsigned int index, const osg::Matrix3x4& m3x4 ) +{ + if( index>=getNumElements() || !isCompatibleType(FLOAT_MAT3x4) ) return false; + unsigned int j = index * getTypeNumComponents(getType()); + for( int i = 0; i < 12; ++i ) (*_floatArray)[j+i] = m3x4[i]; + dirty(); + return true; +} + +bool Uniform::setElement( unsigned int index, const osg::Matrix4x2& m4x2 ) +{ + if( index>=getNumElements() || !isCompatibleType(FLOAT_MAT4x2) ) return false; + unsigned int j = index * getTypeNumComponents(getType()); + for( int i = 0; i < 8; ++i ) (*_floatArray)[j+i] = m4x2[i]; + dirty(); + return true; +} + +bool Uniform::setElement( unsigned int index, const osg::Matrix4x3& m4x3 ) +{ + if( index>=getNumElements() || !isCompatibleType(FLOAT_MAT4x3) ) return false; + unsigned int j = index * getTypeNumComponents(getType()); + for( int i = 0; i < 12; ++i ) (*_floatArray)[j+i] = m4x3[i]; + dirty(); + return true; +} + +bool Uniform::setElement( unsigned int index, double d ) +{ + if( index>=getNumElements() || !isCompatibleType(DOUBLE) ) return false; + unsigned int j = index * getTypeNumComponents(getType()); + (*_doubleArray)[j] = d; + dirty(); + return true; +} + +bool Uniform::setElement( unsigned int index, const osg::Vec2d& v2 ) +{ + if( index>=getNumElements() || !isCompatibleType(DOUBLE_VEC2) ) return false; + unsigned int j = index * getTypeNumComponents(getType()); + (*_doubleArray)[j] = v2.x(); + (*_doubleArray)[j+1] = v2.y(); + dirty(); + return true; +} + +bool Uniform::setElement( unsigned int index, const osg::Vec3d& v3 ) +{ + if( index>=getNumElements() || !isCompatibleType(DOUBLE_VEC3) ) return false; + unsigned int j = index * getTypeNumComponents(getType()); + (*_doubleArray)[j] = v3.x(); + (*_doubleArray)[j+1] = v3.y(); + (*_doubleArray)[j+2] = v3.z(); + dirty(); + return true; +} + +bool Uniform::setElement( unsigned int index, const osg::Vec4d& v4 ) +{ + if( index>=getNumElements() || !isCompatibleType(DOUBLE_VEC4) ) return false; + unsigned int j = index * getTypeNumComponents(getType()); + (*_doubleArray)[j] = v4.x(); + (*_doubleArray)[j+1] = v4.y(); + (*_doubleArray)[j+2] = v4.z(); + (*_doubleArray)[j+3] = v4.w(); + dirty(); + return true; +} + +bool Uniform::setElement( unsigned int index, const osg::Matrix2d& m2 ) +{ + if( index>=getNumElements() || !isCompatibleType(DOUBLE_MAT2) ) return false; + unsigned int j = index * getTypeNumComponents(getType()); + for( int i = 0; i < 4; ++i ) (*_doubleArray)[j+i] = m2[i]; + dirty(); + return true; +} + +bool Uniform::setElement( unsigned int index, const osg::Matrix3d& m3 ) +{ + if( index>=getNumElements() || !isCompatibleType(DOUBLE_MAT3) ) return false; + unsigned int j = index * getTypeNumComponents(getType()); + for( int i = 0; i < 9; ++i ) (*_doubleArray)[j+i] = m3[i]; + dirty(); + return true; +} + bool Uniform::setElement( unsigned int index, const osg::Matrixd& m4 ) { - if( index>=getNumElements() || !isCompatibleType(FLOAT_MAT4) ) return false; + if( index>=getNumElements() || !isCompatibleType(DOUBLE_MAT4, FLOAT_MAT4) ) return false; unsigned int j = index * getTypeNumComponents(getType()); - const Matrixd::value_type* p = m4.ptr(); - for( int i = 0; i < 16; ++i ) (*_floatArray)[j+i] = static_cast(p[i]); + + if (_type == DOUBLE_MAT4) + { + const Matrixd::value_type* p = m4.ptr(); + for( int i = 0; i < 16; ++i ) (*_doubleArray)[j+i] = p[i]; + } + else //if (_type == FLOAT_MAT4) for backward compatibility only + { + const Matrixd::value_type* p = m4.ptr(); + for( int i = 0; i < 16; ++i ) (*_floatArray)[j+i] = static_cast(p[i]); + } + dirty(); + return true; +} + +bool Uniform::setElement( unsigned int index, const osg::Matrix2x3d& m2x3 ) +{ + if( index>=getNumElements() || !isCompatibleType(DOUBLE_MAT2x3) ) return false; + unsigned int j = index * getTypeNumComponents(getType()); + for( int i = 0; i < 6; ++i ) (*_doubleArray)[j+i] = m2x3[i]; + dirty(); + return true; +} + +bool Uniform::setElement( unsigned int index, const osg::Matrix2x4d& m2x4 ) +{ + if( index>=getNumElements() || !isCompatibleType(DOUBLE_MAT2x4) ) return false; + unsigned int j = index * getTypeNumComponents(getType()); + for( int i = 0; i < 8; ++i ) (*_doubleArray)[j+i] = m2x4[i]; + dirty(); + return true; +} + +bool Uniform::setElement( unsigned int index, const osg::Matrix3x2d& m3x2 ) +{ + if( index>=getNumElements() || !isCompatibleType(DOUBLE_MAT3x2) ) return false; + unsigned int j = index * getTypeNumComponents(getType()); + for( int i = 0; i < 6; ++i ) (*_doubleArray)[j+i] = m3x2[i]; + dirty(); + return true; +} + +bool Uniform::setElement( unsigned int index, const osg::Matrix3x4d& m3x4 ) +{ + if( index>=getNumElements() || !isCompatibleType(DOUBLE_MAT3x4) ) return false; + unsigned int j = index * getTypeNumComponents(getType()); + for( int i = 0; i < 12; ++i ) (*_doubleArray)[j+i] = m3x4[i]; + dirty(); + return true; +} + +bool Uniform::setElement( unsigned int index, const osg::Matrix4x2d& m4x2 ) +{ + if( index>=getNumElements() || !isCompatibleType(DOUBLE_MAT4x2) ) return false; + unsigned int j = index * getTypeNumComponents(getType()); + for( int i = 0; i < 8; ++i ) (*_doubleArray)[j+i] = m4x2[i]; + dirty(); + return true; +} + +bool Uniform::setElement( unsigned int index, const osg::Matrix4x3d& m4x3 ) +{ + if( index>=getNumElements() || !isCompatibleType(DOUBLE_MAT4x3) ) return false; + unsigned int j = index * getTypeNumComponents(getType()); + for( int i = 0; i < 12; ++i ) (*_doubleArray)[j+i] = m4x3[i]; dirty(); return true; } @@ -1138,44 +2017,44 @@ bool Uniform::setElement( unsigned int index, int i0, int i1, int i2, int i3 ) return true; } -bool Uniform::setElement( unsigned int index, unsigned int i ) +bool Uniform::setElement( unsigned int index, unsigned int ui ) { if( index>=getNumElements() || !isCompatibleType(UNSIGNED_INT) ) return false; unsigned int j = index * getTypeNumComponents(getType()); - (*_uintArray)[j] = i; + (*_uintArray)[j] = ui; dirty(); return true; } -bool Uniform::setElement( unsigned int index, unsigned int i0, unsigned int i1 ) +bool Uniform::setElement( unsigned int index, unsigned int ui0, unsigned int ui1 ) { if( index>=getNumElements() || !isCompatibleType(UNSIGNED_INT_VEC2) ) return false; unsigned int j = index * getTypeNumComponents(getType()); - (*_uintArray)[j] = i0; - (*_uintArray)[j+1] = i1; + (*_uintArray)[j] = ui0; + (*_uintArray)[j+1] = ui1; dirty(); return true; } -bool Uniform::setElement( unsigned int index, unsigned int i0, unsigned int i1, unsigned int i2 ) +bool Uniform::setElement( unsigned int index, unsigned int ui0, unsigned int ui1, unsigned int ui2 ) { if( index>=getNumElements() || !isCompatibleType(UNSIGNED_INT_VEC3) ) return false; unsigned int j = index * getTypeNumComponents(getType()); - (*_uintArray)[j] = i0; - (*_uintArray)[j+1] = i1; - (*_uintArray)[j+2] = i2; + (*_uintArray)[j] = ui0; + (*_uintArray)[j+1] = ui1; + (*_uintArray)[j+2] = ui2; dirty(); return true; } -bool Uniform::setElement( unsigned int index, unsigned int i0, unsigned int i1, unsigned int i2, unsigned int i3 ) +bool Uniform::setElement( unsigned int index, unsigned int ui0, unsigned int ui1, unsigned int ui2, unsigned int ui3 ) { if( index>=getNumElements() || !isCompatibleType(UNSIGNED_INT_VEC4) ) return false; unsigned int j = index * getTypeNumComponents(getType()); - (*_uintArray)[j] = i0; - (*_uintArray)[j+1] = i1; - (*_uintArray)[j+2] = i2; - (*_uintArray)[j+3] = i3; + (*_uintArray)[j] = ui0; + (*_uintArray)[j+1] = ui1; + (*_uintArray)[j+2] = ui2; + (*_uintArray)[j+3] = ui3; dirty(); return true; } @@ -1267,7 +2146,7 @@ bool Uniform::getElement( unsigned int index, osg::Matrix2& m2 ) const { if( index>=getNumElements() || !isCompatibleType(FLOAT_MAT2) ) return false; unsigned int j = index * getTypeNumComponents(getType()); - m2.set( &((*_floatArray)[j]) ); + m2.MatrixTemplate::set( &((*_floatArray)[j]) ); return true; } @@ -1275,7 +2154,7 @@ bool Uniform::getElement( unsigned int index, osg::Matrix3& m3 ) const { if( index>=getNumElements() || !isCompatibleType(FLOAT_MAT3) ) return false; unsigned int j = index * getTypeNumComponents(getType()); - m3.set( &((*_floatArray)[j]) ); + m3.MatrixTemplate::set( &((*_floatArray)[j]) ); return true; } @@ -1287,11 +2166,165 @@ bool Uniform::getElement( unsigned int index, osg::Matrixf& m4 ) const return true; } +bool Uniform::getElement( unsigned int index, osg::Matrix2x3& m2x3 ) const +{ + if( index>=getNumElements() || !isCompatibleType(FLOAT_MAT2x3) ) return false; + unsigned int j = index * getTypeNumComponents(getType()); + m2x3.MatrixTemplate::set( &((*_floatArray)[j]) ); + return true; +} + +bool Uniform::getElement( unsigned int index, osg::Matrix2x4& m2x4 ) const +{ + if( index>=getNumElements() || !isCompatibleType(FLOAT_MAT2x4) ) return false; + unsigned int j = index * getTypeNumComponents(getType()); + m2x4.MatrixTemplate::set( &((*_floatArray)[j]) ); + return true; +} + +bool Uniform::getElement( unsigned int index, osg::Matrix3x2& m3x2 ) const +{ + if( index>=getNumElements() || !isCompatibleType(FLOAT_MAT3x2) ) return false; + unsigned int j = index * getTypeNumComponents(getType()); + m3x2.MatrixTemplate::set( &((*_floatArray)[j]) ); + return true; +} + +bool Uniform::getElement( unsigned int index, osg::Matrix3x4& m3x4 ) const +{ + if( index>=getNumElements() || !isCompatibleType(FLOAT_MAT3x4) ) return false; + unsigned int j = index * getTypeNumComponents(getType()); + m3x4.MatrixTemplate::set( &((*_floatArray)[j]) ); + return true; +} + +bool Uniform::getElement( unsigned int index, osg::Matrix4x2& m4x2 ) const +{ + if( index>=getNumElements() || !isCompatibleType(FLOAT_MAT4x2) ) return false; + unsigned int j = index * getTypeNumComponents(getType()); + m4x2.MatrixTemplate::set( &((*_floatArray)[j]) ); + return true; +} + +bool Uniform::getElement( unsigned int index, osg::Matrix4x3& m4x3 ) const +{ + if( index>=getNumElements() || !isCompatibleType(FLOAT_MAT4x3) ) return false; + unsigned int j = index * getTypeNumComponents(getType()); + m4x3.MatrixTemplate::set( &((*_floatArray)[j]) ); + return true; +} + +bool Uniform::getElement( unsigned int index, double& d ) const +{ + if( index>=getNumElements() || !isCompatibleType(DOUBLE) ) return false; + unsigned int j = index * getTypeNumComponents(getType()); + d = (*_doubleArray)[j]; + return true; +} + +bool Uniform::getElement( unsigned int index, osg::Vec2d& v2 ) const +{ + if( index>=getNumElements() || !isCompatibleType(DOUBLE_VEC2) ) return false; + unsigned int j = index * getTypeNumComponents(getType()); + v2.x() = (*_doubleArray)[j]; + v2.y() = (*_doubleArray)[j+1]; + return true; +} + +bool Uniform::getElement( unsigned int index, osg::Vec3d& v3 ) const +{ + if( index>=getNumElements() || !isCompatibleType(DOUBLE_VEC3) ) return false; + unsigned int j = index * getTypeNumComponents(getType()); + v3.x() = (*_doubleArray)[j]; + v3.y() = (*_doubleArray)[j+1]; + v3.z() = (*_doubleArray)[j+2]; + return true; +} + +bool Uniform::getElement( unsigned int index, osg::Vec4d& v4 ) const +{ + if( index>=getNumElements() || !isCompatibleType(DOUBLE_VEC4) ) return false; + unsigned int j = index * getTypeNumComponents(getType()); + v4.x() = (*_doubleArray)[j]; + v4.y() = (*_doubleArray)[j+1]; + v4.z() = (*_doubleArray)[j+2]; + v4.w() = (*_doubleArray)[j+3]; + return true; +} + +bool Uniform::getElement( unsigned int index, osg::Matrix2d& m2 ) const +{ + if( index>=getNumElements() || !isCompatibleType(DOUBLE_MAT2) ) return false; + unsigned int j = index * getTypeNumComponents(getType()); + m2.MatrixTemplate::set( &((*_doubleArray)[j]) ); + return true; +} + +bool Uniform::getElement( unsigned int index, osg::Matrix3d& m3 ) const +{ + if( index>=getNumElements() || !isCompatibleType(DOUBLE_MAT3) ) return false; + unsigned int j = index * getTypeNumComponents(getType()); + m3.MatrixTemplate::set( &((*_doubleArray)[j]) ); + return true; +} + bool Uniform::getElement( unsigned int index, osg::Matrixd& m4 ) const { - if( index>=getNumElements() || !isCompatibleType(FLOAT_MAT4) ) return false; + if( index>=getNumElements() || !isCompatibleType(DOUBLE_MAT4, FLOAT_MAT4) ) return false; unsigned int j = index * getTypeNumComponents(getType()); - m4.set( &((*_floatArray)[j]) ); + + if (_type == DOUBLE_MAT4) + m4.set( &((*_doubleArray)[j]) ); + else // if (_type == FLOAT_MAT4) for backward compatibility only + m4.set( &((*_floatArray)[j]) ); + return true; +} + +bool Uniform::getElement( unsigned int index, osg::Matrix2x3d& m2x3 ) const +{ + if( index>=getNumElements() || !isCompatibleType(DOUBLE_MAT2x3) ) return false; + unsigned int j = index * getTypeNumComponents(getType()); + m2x3.MatrixTemplate::set( &((*_doubleArray)[j]) ); + return true; +} + +bool Uniform::getElement( unsigned int index, osg::Matrix2x4d& m2x4 ) const +{ + if( index>=getNumElements() || !isCompatibleType(DOUBLE_MAT2x4) ) return false; + unsigned int j = index * getTypeNumComponents(getType()); + m2x4.MatrixTemplate::set( &((*_doubleArray)[j]) ); + return true; +} + +bool Uniform::getElement( unsigned int index, osg::Matrix3x2d& m3x2 ) const +{ + if( index>=getNumElements() || !isCompatibleType(DOUBLE_MAT3x2) ) return false; + unsigned int j = index * getTypeNumComponents(getType()); + m3x2.MatrixTemplate::set( &((*_doubleArray)[j]) ); + return true; +} + +bool Uniform::getElement( unsigned int index, osg::Matrix3x4d& m3x4 ) const +{ + if( index>=getNumElements() || !isCompatibleType(DOUBLE_MAT3x4) ) return false; + unsigned int j = index * getTypeNumComponents(getType()); + m3x4.MatrixTemplate::set( &((*_doubleArray)[j]) ); + return true; +} + +bool Uniform::getElement( unsigned int index, osg::Matrix4x2d& m4x2 ) const +{ + if( index>=getNumElements() || !isCompatibleType(DOUBLE_MAT4x2) ) return false; + unsigned int j = index * getTypeNumComponents(getType()); + m4x2.MatrixTemplate::set( &((*_doubleArray)[j]) ); + return true; +} + +bool Uniform::getElement( unsigned int index, osg::Matrix4x3d& m4x3 ) const +{ + if( index>=getNumElements() || !isCompatibleType(DOUBLE_MAT4x3) ) return false; + unsigned int j = index * getTypeNumComponents(getType()); + m4x3.MatrixTemplate::set( &((*_doubleArray)[j]) ); return true; } @@ -1333,41 +2366,41 @@ bool Uniform::getElement( unsigned int index, int& i0, int& i1, int& i2, int& i3 return true; } -bool Uniform::getElement( unsigned int index, unsigned int& i ) const +bool Uniform::getElement( unsigned int index, unsigned int& ui ) const { if( index>=getNumElements() || !isCompatibleType(UNSIGNED_INT) ) return false; unsigned int j = index * getTypeNumComponents(getType()); - i = (*_uintArray)[j]; + ui = (*_uintArray)[j]; return true; } -bool Uniform::getElement( unsigned int index, unsigned int& i0, unsigned int& i1 ) const +bool Uniform::getElement( unsigned int index, unsigned int& ui0, unsigned int& ui1 ) const { if( index>=getNumElements() || !isCompatibleType(UNSIGNED_INT_VEC2) ) return false; unsigned int j = index * getTypeNumComponents(getType()); - i0 = (*_uintArray)[j]; - i1 = (*_uintArray)[j+1]; + ui0 = (*_uintArray)[j]; + ui1 = (*_uintArray)[j+1]; return true; } -bool Uniform::getElement( unsigned int index, unsigned int& i0, unsigned int& i1, unsigned int& i2 ) const +bool Uniform::getElement( unsigned int index, unsigned int& ui0, unsigned int& ui1, unsigned int& ui2 ) const { if( index>=getNumElements() || !isCompatibleType(UNSIGNED_INT_VEC3) ) return false; unsigned int j = index * getTypeNumComponents(getType()); - i0 = (*_uintArray)[j]; - i1 = (*_uintArray)[j+1]; - i2 = (*_uintArray)[j+2]; + ui0 = (*_uintArray)[j]; + ui1 = (*_uintArray)[j+1]; + ui2 = (*_uintArray)[j+2]; return true; } -bool Uniform::getElement( unsigned int index, unsigned int& i0, unsigned int& i1, unsigned int& i2, unsigned int& i3 ) const +bool Uniform::getElement( unsigned int index, unsigned int& ui0, unsigned int& ui1, unsigned int& ui2, unsigned int& ui3 ) const { if( index>=getNumElements() || !isCompatibleType(UNSIGNED_INT_VEC4) ) return false; unsigned int j = index * getTypeNumComponents(getType()); - i0 = (*_uintArray)[j]; - i1 = (*_uintArray)[j+1]; - i2 = (*_uintArray)[j+2]; - i3 = (*_uintArray)[j+3]; + ui0 = (*_uintArray)[j]; + ui1 = (*_uintArray)[j+1]; + ui2 = (*_uintArray)[j+2]; + ui3 = (*_uintArray)[j+3]; return true; } @@ -1453,6 +2486,82 @@ void Uniform::apply(const GL2Extensions* ext, GLint location) const if( _floatArray.valid() ) ext->glUniformMatrix4fv( location, num, GL_FALSE, &_floatArray->front() ); break; + case FLOAT_MAT2x3: + if( _floatArray.valid() ) ext->glUniformMatrix2x3fv( location, num, GL_FALSE, &_floatArray->front() ); + break; + + case FLOAT_MAT2x4: + if( _floatArray.valid() ) ext->glUniformMatrix2x4fv( location, num, GL_FALSE, &_floatArray->front() ); + break; + + case FLOAT_MAT3x2: + if( _floatArray.valid() ) ext->glUniformMatrix3x2fv( location, num, GL_FALSE, &_floatArray->front() ); + break; + + case FLOAT_MAT3x4: + if( _floatArray.valid() ) ext->glUniformMatrix3x4fv( location, num, GL_FALSE, &_floatArray->front() ); + break; + + case FLOAT_MAT4x2: + if( _floatArray.valid() ) ext->glUniformMatrix4x2fv( location, num, GL_FALSE, &_floatArray->front() ); + break; + + case FLOAT_MAT4x3: + if( _floatArray.valid() ) ext->glUniformMatrix4x3fv( location, num, GL_FALSE, &_floatArray->front() ); + break; + + case DOUBLE: + if( _doubleArray.valid() ) ext->glUniform1dv( location, num, &_doubleArray->front() ); + break; + + case DOUBLE_VEC2: + if( _doubleArray.valid() ) ext->glUniform2dv( location, num, &_doubleArray->front() ); + break; + + case DOUBLE_VEC3: + if( _doubleArray.valid() ) ext->glUniform3dv( location, num, &_doubleArray->front() ); + break; + + case DOUBLE_VEC4: + if( _doubleArray.valid() ) ext->glUniform4dv( location, num, &_doubleArray->front() ); + break; + + case DOUBLE_MAT2: + if( _doubleArray.valid() ) ext->glUniformMatrix2dv( location, num, GL_FALSE, &_doubleArray->front() ); + break; + + case DOUBLE_MAT3: + if( _doubleArray.valid() ) ext->glUniformMatrix3dv( location, num, GL_FALSE, &_doubleArray->front() ); + break; + + case DOUBLE_MAT4: + if( _doubleArray.valid() ) ext->glUniformMatrix4dv( location, num, GL_FALSE, &_doubleArray->front() ); + break; + + case DOUBLE_MAT2x3: + if( _doubleArray.valid() ) ext->glUniformMatrix2x3dv( location, num, GL_FALSE, &_doubleArray->front() ); + break; + + case DOUBLE_MAT2x4: + if( _doubleArray.valid() ) ext->glUniformMatrix2x4dv( location, num, GL_FALSE, &_doubleArray->front() ); + break; + + case DOUBLE_MAT3x2: + if( _doubleArray.valid() ) ext->glUniformMatrix3x2dv( location, num, GL_FALSE, &_doubleArray->front() ); + break; + + case DOUBLE_MAT3x4: + if( _doubleArray.valid() ) ext->glUniformMatrix3x4dv( location, num, GL_FALSE, &_doubleArray->front() ); + break; + + case DOUBLE_MAT4x2: + if( _doubleArray.valid() ) ext->glUniformMatrix4x2dv( location, num, GL_FALSE, &_doubleArray->front() ); + break; + + case DOUBLE_MAT4x3: + if( _doubleArray.valid() ) ext->glUniformMatrix4x3dv( location, num, GL_FALSE, &_doubleArray->front() ); + break; + case INT: if( _intArray.valid() ) ext->glUniform1iv( location, num, &_intArray->front() ); break; diff --git a/src/osgPlugins/ive/Uniform.cpp b/src/osgPlugins/ive/Uniform.cpp index 367598738..79140087a 100644 --- a/src/osgPlugins/ive/Uniform.cpp +++ b/src/osgPlugins/ive/Uniform.cpp @@ -43,7 +43,9 @@ void Uniform::write(DataOutputStream* out){ out->writeUInt(getNumElements()); if( getFloatArray() ) out->writeArray( getFloatArray() ); + if( getDoubleArray() ) out->writeArray( getDoubleArray() ); if( getIntArray() ) out->writeArray( getIntArray() ); + if( getUIntArray() ) out->writeArray( getUIntArray() ); } else { @@ -177,7 +179,9 @@ void Uniform::read(DataInputStream* in) osg::Array* data = in->readArray(); setArray( dynamic_cast(data) ); + setArray( dynamic_cast(data) ); setArray( dynamic_cast(data) ); + setArray( dynamic_cast(data) ); } else { diff --git a/src/osgWrappers/deprecated-dotosg/osg/Uniform.cpp b/src/osgWrappers/deprecated-dotosg/osg/Uniform.cpp index e41550cee..a93e85ae5 100644 --- a/src/osgWrappers/deprecated-dotosg/osg/Uniform.cpp +++ b/src/osgWrappers/deprecated-dotosg/osg/Uniform.cpp @@ -65,6 +65,7 @@ bool Uniform_readLocalData(Object& obj, Input& fr) Array* data = Array_readLocalData(fr); uniform.setArray( dynamic_cast(data) ); + uniform.setArray( dynamic_cast(data) ); uniform.setArray( dynamic_cast(data) ); uniform.setArray( dynamic_cast(data) ); } diff --git a/src/osgWrappers/serializers/osg/Uniform.cpp b/src/osgWrappers/serializers/osg/Uniform.cpp index 7f243f4c8..3c362a714 100644 --- a/src/osgWrappers/serializers/osg/Uniform.cpp +++ b/src/osgWrappers/serializers/osg/Uniform.cpp @@ -18,6 +18,8 @@ static bool readElements( osgDB::InputStream& is, osg::Uniform& uniform ) { case osg::Array::FloatArrayType: uniform.setArray( static_cast(array) ); break; + case osg::Array::DoubleArrayType: + uniform.setArray( static_cast(array) ); break; case osg::Array::IntArrayType: uniform.setArray( static_cast(array) ); break; case osg::Array::UIntArrayType: @@ -35,6 +37,11 @@ static bool writeElements( osgDB::OutputStream& os, const osg::Uniform& uniform os << (uniform.getFloatArray()!=NULL); os.writeArray( uniform.getFloatArray() ); } + if ( uniform.getDoubleArray()!=NULL ) + { + os << (uniform.getDoubleArray()!=NULL); + os.writeArray( uniform.getDoubleArray() ); + } else if ( uniform.getIntArray()!=NULL ) { os << (uniform.getIntArray()!=NULL); @@ -58,17 +65,47 @@ REGISTER_OBJECT_WRAPPER( Uniform, ADD_ENUM_VALUE( FLOAT_VEC2 ); ADD_ENUM_VALUE( FLOAT_VEC3 ); ADD_ENUM_VALUE( FLOAT_VEC4 ); + + ADD_ENUM_VALUE( DOUBLE ); + ADD_ENUM_VALUE( DOUBLE_VEC2 ); + ADD_ENUM_VALUE( DOUBLE_VEC3 ); + ADD_ENUM_VALUE( DOUBLE_VEC4 ); + ADD_ENUM_VALUE( INT ); ADD_ENUM_VALUE( INT_VEC2 ); ADD_ENUM_VALUE( INT_VEC3 ); ADD_ENUM_VALUE( INT_VEC4 ); + + ADD_ENUM_VALUE( UNSIGNED_INT ); + ADD_ENUM_VALUE( UNSIGNED_INT_VEC2 ); + ADD_ENUM_VALUE( UNSIGNED_INT_VEC3 ); + ADD_ENUM_VALUE( UNSIGNED_INT_VEC4 ); + ADD_ENUM_VALUE( BOOL ); ADD_ENUM_VALUE( BOOL_VEC2 ); ADD_ENUM_VALUE( BOOL_VEC3 ); ADD_ENUM_VALUE( BOOL_VEC4 ); + ADD_ENUM_VALUE( FLOAT_MAT2 ); ADD_ENUM_VALUE( FLOAT_MAT3 ); ADD_ENUM_VALUE( FLOAT_MAT4 ); + ADD_ENUM_VALUE( FLOAT_MAT2x3 ); + ADD_ENUM_VALUE( FLOAT_MAT2x4 ); + ADD_ENUM_VALUE( FLOAT_MAT3x2 ); + ADD_ENUM_VALUE( FLOAT_MAT3x4 ); + ADD_ENUM_VALUE( FLOAT_MAT4x2 ); + ADD_ENUM_VALUE( FLOAT_MAT4x3 ); + + ADD_ENUM_VALUE( DOUBLE_MAT2 ); + ADD_ENUM_VALUE( DOUBLE_MAT3 ); + ADD_ENUM_VALUE( DOUBLE_MAT4 ); + ADD_ENUM_VALUE( DOUBLE_MAT2x3 ); + ADD_ENUM_VALUE( DOUBLE_MAT2x4 ); + ADD_ENUM_VALUE( DOUBLE_MAT3x2 ); + ADD_ENUM_VALUE( DOUBLE_MAT3x4 ); + ADD_ENUM_VALUE( DOUBLE_MAT4x2 ); + ADD_ENUM_VALUE( DOUBLE_MAT4x3 ); + ADD_ENUM_VALUE( SAMPLER_1D ); ADD_ENUM_VALUE( SAMPLER_2D ); ADD_ENUM_VALUE( SAMPLER_3D ); @@ -77,41 +114,82 @@ REGISTER_OBJECT_WRAPPER( Uniform, ADD_ENUM_VALUE( SAMPLER_2D_SHADOW ); ADD_ENUM_VALUE( SAMPLER_1D_ARRAY ); ADD_ENUM_VALUE( SAMPLER_2D_ARRAY ); + ADD_ENUM_VALUE( SAMPLER_CUBE_MAP_ARRAY ); ADD_ENUM_VALUE( SAMPLER_1D_ARRAY_SHADOW ); ADD_ENUM_VALUE( SAMPLER_2D_ARRAY_SHADOW ); - ADD_ENUM_VALUE( FLOAT_MAT2x3 ); - ADD_ENUM_VALUE( FLOAT_MAT2x4 ); - ADD_ENUM_VALUE( FLOAT_MAT3x2 ); - ADD_ENUM_VALUE( FLOAT_MAT3x4 ); - ADD_ENUM_VALUE( FLOAT_MAT4x2 ); - ADD_ENUM_VALUE( FLOAT_MAT4x3 ); - ADD_ENUM_VALUE( SAMPLER_BUFFER ); + ADD_ENUM_VALUE( SAMPLER_2D_MULTISAMPLE ); + ADD_ENUM_VALUE( SAMPLER_2D_MULTISAMPLE_ARRAY ); ADD_ENUM_VALUE( SAMPLER_CUBE_SHADOW ); - ADD_ENUM_VALUE( UNSIGNED_INT ); - ADD_ENUM_VALUE( UNSIGNED_INT_VEC2 ); - ADD_ENUM_VALUE( UNSIGNED_INT_VEC3 ); - ADD_ENUM_VALUE( UNSIGNED_INT_VEC4 ); + ADD_ENUM_VALUE( SAMPLER_CUBE_MAP_ARRAY_SHADOW ); + ADD_ENUM_VALUE( SAMPLER_BUFFER ); + ADD_ENUM_VALUE( SAMPLER_2D_RECT ); + ADD_ENUM_VALUE( SAMPLER_2D_RECT_SHADOW ); + ADD_ENUM_VALUE( INT_SAMPLER_1D ); ADD_ENUM_VALUE( INT_SAMPLER_2D ); ADD_ENUM_VALUE( INT_SAMPLER_3D ); ADD_ENUM_VALUE( INT_SAMPLER_CUBE ); - ADD_ENUM_VALUE( INT_SAMPLER_2D_RECT ); ADD_ENUM_VALUE( INT_SAMPLER_1D_ARRAY ); ADD_ENUM_VALUE( INT_SAMPLER_2D_ARRAY ); + ADD_ENUM_VALUE( INT_SAMPLER_CUBE_MAP_ARRAY ); + ADD_ENUM_VALUE( INT_SAMPLER_2D_MULTISAMPLE ); + ADD_ENUM_VALUE( INT_SAMPLER_2D_MULTISAMPLE_ARRAY ); ADD_ENUM_VALUE( INT_SAMPLER_BUFFER ); + ADD_ENUM_VALUE( INT_SAMPLER_2D_RECT ); + ADD_ENUM_VALUE( UNSIGNED_INT_SAMPLER_1D ); ADD_ENUM_VALUE( UNSIGNED_INT_SAMPLER_2D ); ADD_ENUM_VALUE( UNSIGNED_INT_SAMPLER_3D ); ADD_ENUM_VALUE( UNSIGNED_INT_SAMPLER_CUBE ); - ADD_ENUM_VALUE( UNSIGNED_INT_SAMPLER_2D_RECT ); ADD_ENUM_VALUE( UNSIGNED_INT_SAMPLER_1D_ARRAY ); ADD_ENUM_VALUE( UNSIGNED_INT_SAMPLER_2D_ARRAY ); + ADD_ENUM_VALUE( UNSIGNED_INT_SAMPLER_CUBE_MAP_ARRAY ); + ADD_ENUM_VALUE( UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE ); + ADD_ENUM_VALUE( UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE_ARRAY ); ADD_ENUM_VALUE( UNSIGNED_INT_SAMPLER_BUFFER ); + ADD_ENUM_VALUE( UNSIGNED_INT_SAMPLER_2D_RECT ); + + ADD_ENUM_VALUE( IMAGE_1D ); + ADD_ENUM_VALUE( IMAGE_2D ); + ADD_ENUM_VALUE( IMAGE_3D ); + ADD_ENUM_VALUE( IMAGE_2D_RECT ); + ADD_ENUM_VALUE( IMAGE_CUBE ); + ADD_ENUM_VALUE( IMAGE_BUFFER ); + ADD_ENUM_VALUE( IMAGE_1D_ARRAY ); + ADD_ENUM_VALUE( IMAGE_2D_ARRAY ); + ADD_ENUM_VALUE( IMAGE_CUBE_MAP_ARRAY ); + ADD_ENUM_VALUE( IMAGE_2D_MULTISAMPLE ); + ADD_ENUM_VALUE( IMAGE_2D_MULTISAMPLE_ARRAY ); + + ADD_ENUM_VALUE( INT_IMAGE_1D ); + ADD_ENUM_VALUE( INT_IMAGE_2D ); + ADD_ENUM_VALUE( INT_IMAGE_3D ); + ADD_ENUM_VALUE( INT_IMAGE_2D_RECT ); + ADD_ENUM_VALUE( INT_IMAGE_CUBE ); + ADD_ENUM_VALUE( INT_IMAGE_BUFFER ); + ADD_ENUM_VALUE( INT_IMAGE_1D_ARRAY ); + ADD_ENUM_VALUE( INT_IMAGE_2D_ARRAY ); + ADD_ENUM_VALUE( INT_IMAGE_CUBE_MAP_ARRAY ); + ADD_ENUM_VALUE( INT_IMAGE_2D_MULTISAMPLE ); + ADD_ENUM_VALUE( INT_IMAGE_2D_MULTISAMPLE_ARRAY ); + + ADD_ENUM_VALUE( UNSIGNED_INT_IMAGE_1D ); + ADD_ENUM_VALUE( UNSIGNED_INT_IMAGE_2D ); + ADD_ENUM_VALUE( UNSIGNED_INT_IMAGE_3D ); + ADD_ENUM_VALUE( UNSIGNED_INT_IMAGE_2D_RECT ); + ADD_ENUM_VALUE( UNSIGNED_INT_IMAGE_CUBE ); + ADD_ENUM_VALUE( UNSIGNED_INT_IMAGE_BUFFER ); + ADD_ENUM_VALUE( UNSIGNED_INT_IMAGE_1D_ARRAY ); + ADD_ENUM_VALUE( UNSIGNED_INT_IMAGE_2D_ARRAY ); + ADD_ENUM_VALUE( UNSIGNED_INT_IMAGE_CUBE_MAP_ARRAY ); + ADD_ENUM_VALUE( UNSIGNED_INT_IMAGE_2D_MULTISAMPLE ); + ADD_ENUM_VALUE( UNSIGNED_INT_IMAGE_2D_MULTISAMPLE_ARRAY ); + ADD_ENUM_VALUE( UNDEFINED ); END_ENUM_SERIALIZER(); // _type ADD_UINT_SERIALIZER( NumElements, 0 ); // _numElements - ADD_USER_SERIALIZER( Elements ); // _floatArray, _intArray, _uintArray + ADD_USER_SERIALIZER( Elements ); // _floatArray, _doubleArray, _intArray, _uintArray ADD_OBJECT_SERIALIZER( UpdateCallback, osg::Uniform::Callback, NULL ); // _updateCallback ADD_OBJECT_SERIALIZER( EventCallback, osg::Uniform::Callback, NULL ); // _eventCallback }