From David Callu, "Here an update of osg::Uniform :

- add non square matrix
- add double
- add all uniform type available in OpenGL 4.2
- backward compatibility for Matrixd to set/get an float uniform matrix
- update of IVE / Wrapper ReadWriter

implementation of AtomicCounterBuffer based on BufferIndexBinding

add example that use AtomicCounterBuffer and show rendering order of fragments,
original idea from geeks3d.com."
This commit is contained in:
Robert Osfield 2012-03-29 09:43:12 +00:00
parent 59d6931b59
commit aab27e106c
16 changed files with 2915 additions and 381 deletions

View File

@ -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)

View File

@ -0,0 +1,4 @@
SET(TARGET_SRC osgatomiccounter.cpp)
#### end var setup ###
SETUP_EXAMPLE(osgatomiccounter)

View File

@ -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 <osg/BufferIndexBinding>
#include <osg/BufferObject>
#include <osg/Camera>
#include <osg/Program>
#include <osgDB/ReadFile>
#include <osgUtil/Optimizer>
#include <osgViewer/Viewer>
#include <osgViewer/ViewerEventHandlers>
#include <osgGA/TrackballManipulator>
#include <osgGA/FlightManipulator>
#include <osgGA/DriveManipulator>
#include <osgGA/KeySwitchMatrixManipulator>
#include <osgGA/StateSetManipulator>
#include <osgGA/AnimationPathManipulator>
#include <osgGA/TerrainManipulator>
#include <osgGA/SphericalManipulator>
#include <iostream>
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<float>(numPixel) );
}
osg::ref_ptr<osg::Uniform> _invNumPixelUniform;
osg::ref_ptr<osg::UIntArray> _atomicCounterArray;
osg::ref_ptr<osg::AtomicCounterBufferBinding> _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<osg::AtomicCounterBufferBinding *>(sa);
if (acbb)
{
osg::AtomicCounterBufferObject * acbo = dynamic_cast<osg::AtomicCounterBufferObject*>(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<osg::Node> 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<osg::UIntArray> atomicCounterArrayRedAndGreen = new osg::UIntArray;
atomicCounterArrayRedAndGreen->push_back(0);
atomicCounterArrayRedAndGreen->push_back(0);
osg::ref_ptr<osg::UIntArray> atomicCounterArrayBlue = new osg::UIntArray;
atomicCounterArrayBlue->push_back(0);
osg::ref_ptr<osg::AtomicCounterBufferObject> acboRedAndGreen = new osg::AtomicCounterBufferObject;
acboRedAndGreen->setUsage(GL_STREAM_COPY);
atomicCounterArrayRedAndGreen->setBufferObject(acboRedAndGreen.get());
osg::ref_ptr<osg::AtomicCounterBufferObject> acboBlue = new osg::AtomicCounterBufferObject;
acboBlue->setUsage(GL_STREAM_COPY);
atomicCounterArrayBlue->setBufferObject(acboBlue.get());
osg::ref_ptr<osg::AtomicCounterBufferBinding> acbbRedAndGreen = new osg::AtomicCounterBufferBinding(0, acboRedAndGreen.get(), 0, sizeof(GLuint)*3);
ss->setAttributeAndModes(acbbRedAndGreen.get());
osg::ref_ptr<osg::AtomicCounterBufferBinding> 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<osg::Uniform> 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();
}

View File

@ -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 <osg/Array>
#include <osg/Export>
#include <osg/BufferObject>
#include <osg/StateAttribute>
@ -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

View File

@ -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);

View File

@ -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;
};
}

View File

@ -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.*/

View File

@ -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 <osg/Vec2>
#include <osg/Vec3>
#include <osg/Vec4>
#include <osg/Vec2d>
#include <osg/Vec3d>
#include <osg/Vec4d>
#include <osg/Matrix>
#include <osg/GL2Extensions>
#include <string.h> // for memset
#include <string>
#include <vector>
#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 <typename T, unsigned int ColN, unsigned int RowN>
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<value_count;++i) local_ptr[i]=ptr[i];
}
value_type* ptr() { return (value_type*)_mat; }
const value_type* ptr() const { return (const value_type*)_mat; }
value_type& operator [] (int i) {return ptr()[i];}
value_type operator [] (int i) const {return ptr()[i];}
void reset() { memset(_mat, 0, sizeof( value_type ) * value_count); }
protected:
value_type _mat[col_count][row_count];
};
template <typename T>
class Matrix2Template : public MatrixTemplate<T, 2, 2>
{
public:
typedef MatrixTemplate<T, 2, 2> 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 <typename T>
class Matrix2x3Template : public MatrixTemplate<T, 2, 3>
{
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<T, 2, 3> 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 <typename T>
class Matrix2x4Template : public MatrixTemplate<T, 2, 4>
{
public:
typedef MatrixTemplate<T, 2, 4> 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 <typename T>
class Matrix3x2Template : public MatrixTemplate<T, 3, 2>
{
public:
typedef MatrixTemplate<T, 3, 2> 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 <typename T>
class Matrix3Template : public MatrixTemplate<T, 3, 3>
{
public:
typedef MatrixTemplate<T, 3, 3> 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 <typename T>
class Matrix3x4Template : public MatrixTemplate<T, 3, 4>
{
public:
typedef MatrixTemplate<T, 3, 4> 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 <typename T>
class Matrix4x2Template : public MatrixTemplate<T, 4, 2>
{
public:
typedef MatrixTemplate<T, 4, 2> 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 <typename T>
class Matrix4x3Template : public MatrixTemplate<T, 4, 3>
{
public:
typedef MatrixTemplate<T, 4, 3> 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<float> Matrix2;
typedef Matrix2x3Template<float> Matrix2x3;
typedef Matrix2x4Template<float> Matrix2x4;
typedef Matrix3x2Template<float> Matrix3x2;
typedef Matrix3Template<float> Matrix3;
typedef Matrix3x4Template<float> Matrix3x4;
typedef Matrix4x2Template<float> Matrix4x2;
typedef Matrix4x3Template<float> Matrix4x3;
typedef Matrix2Template<double> Matrix2d;
typedef Matrix2x3Template<double> Matrix2x3d;
typedef Matrix2x4Template<double> Matrix2x4d;
typedef Matrix3x2Template<double> Matrix3x2d;
typedef Matrix3Template<double> Matrix3d;
typedef Matrix3x4Template<double> Matrix3x4d;
typedef Matrix4x2Template<double> Matrix4x2d;
typedef Matrix4x3Template<double> 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> _floatArray;
ref_ptr<IntArray> _intArray;
ref_ptr<UIntArray> _uintArray;
ref_ptr<FloatArray> _floatArray;
ref_ptr<DoubleArray> _doubleArray;
ref_ptr<IntArray> _intArray;
ref_ptr<UIntArray> _uintArray;
ref_ptr<Callback> _updateCallback;
ref_ptr<Callback> _eventCallback;
ref_ptr<Callback> _updateCallback;
ref_ptr<Callback> _eventCallback;
unsigned int _modifiedCount;
unsigned int _modifiedCount;
};
}

View File

@ -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 <osg/BufferIndexBinding>
#include <osg/State>
#include <string.h> // 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<GLuint>(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<int>(_size, uintArray.getTotalDataSize());
memcpy((void*) &(uintArray.front()), src+_offset, size);
bo->_extensions->glUnmapBuffer(GL_ATOMIC_COUNTER_BUFFER);
}
if (static_cast<GLuint>(previousID) != bo->getGLObjectID())
bo->_extensions->glBindBuffer(GL_ATOMIC_COUNTER_BUFFER, static_cast<GLuint>(previousID));
}
} // namespace osg

View File

@ -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()
{
}

View File

@ -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

View File

@ -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<GLuint, std::string> 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<GLint> bufferIndex( atomicCounterMap.size(), 0 );
std::vector<GLuint> 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 \""<<atomicCounterMap[ uniformIndex[j] ] <<"\""
<<" buffer bind= " << bufferIndex[j] << ".\n";
}
std::map<int, std::vector<int> > bufferIndexToUniformIndices;
for (unsigned int i=0; i<bufferIndex.size(); ++i)
{
bufferIndexToUniformIndices[ bufferIndex[i] ].push_back( uniformIndex[i] );
}
GLuint activeAtomicCounterBuffers = 0;
_extensions->glGetProgramiv(_glProgramHandle, GL_ACTIVE_ATOMIC_COUNTER_BUFFERS,
reinterpret_cast<GLint*>(&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<GLint> 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 );

File diff suppressed because it is too large Load Diff

View File

@ -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<osg::FloatArray*>(data) );
setArray( dynamic_cast<osg::DoubleArray*>(data) );
setArray( dynamic_cast<osg::IntArray*>(data) );
setArray( dynamic_cast<osg::UIntArray*>(data) );
}
else
{

View File

@ -65,6 +65,7 @@ bool Uniform_readLocalData(Object& obj, Input& fr)
Array* data = Array_readLocalData(fr);
uniform.setArray( dynamic_cast<FloatArray*>(data) );
uniform.setArray( dynamic_cast<DoubleArray*>(data) );
uniform.setArray( dynamic_cast<IntArray*>(data) );
uniform.setArray( dynamic_cast<UIntArray*>(data) );
}

View File

@ -18,6 +18,8 @@ static bool readElements( osgDB::InputStream& is, osg::Uniform& uniform )
{
case osg::Array::FloatArrayType:
uniform.setArray( static_cast<osg::FloatArray*>(array) ); break;
case osg::Array::DoubleArrayType:
uniform.setArray( static_cast<osg::DoubleArray*>(array) ); break;
case osg::Array::IntArrayType:
uniform.setArray( static_cast<osg::IntArray*>(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
}