Merge remote-tracking branch 'upstream/master' into MDI7

This commit is contained in:
Julien Valentin
2017-08-24 11:26:23 +02:00
108 changed files with 2569 additions and 415 deletions

View File

@@ -1,6 +1,7 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
* Copyright (C) 2010 Tim Moore
* Copyright (C) 2012 David Callu
* Copyright (C) 2017 Julien Valentin
*
* 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
@@ -18,25 +19,31 @@
#include <string.h> // for memcpy
#ifndef GL_DRAW_INDIRECT_BUFFER
#define GL_DRAW_INDIRECT_BUFFER 0x8F3F
#endif
namespace osg {
BufferIndexBinding::BufferIndexBinding(GLenum target, GLuint index)
: _target(target), _index(index), _offset(0), _size(0)
:_target(target), _bufferData(0), _index(index), _offset(0), _size(0)
{
}
BufferIndexBinding::BufferIndexBinding(GLenum target, GLuint index, BufferObject* bo,
BufferIndexBinding::BufferIndexBinding(GLenum target, GLuint index, BufferData* bo,
GLintptr offset, GLsizeiptr size)
: _target(target), _index(index), _bufferObject(bo), _offset(offset), _size(size)
: _target(target), _index(index), _offset(offset), _size(size)
{
setBufferData(bo);
}
BufferIndexBinding::BufferIndexBinding(const BufferIndexBinding& rhs, const CopyOp& copyop)
: StateAttribute(rhs, copyop),
_target(rhs._target), _index(rhs._index),
_bufferObject(static_cast<BufferObject*>(copyop(rhs._bufferObject.get()))),
_offset(rhs._offset),
_size(rhs._size)
BufferIndexBinding::BufferIndexBinding(const BufferIndexBinding& rhs, const CopyOp& copyop):StateAttribute(rhs,copyop),
_target(rhs._target),
_bufferData(static_cast<BufferData*>(copyop(rhs._bufferData.get()))),
_index(rhs._index),
_offset(rhs._offset),
_size(rhs._size)
{
}
@@ -55,15 +62,13 @@ void BufferIndexBinding::setIndex(unsigned int index)
void BufferIndexBinding::apply(State& state) const
{
if (_bufferObject.valid())
if (_bufferData.valid())
{
GLBufferObject* glObject
= _bufferObject->getOrCreateGLBufferObject(state.getContextID());
if (!glObject->_extensions->isUniformBufferObjectSupported)
return;
= _bufferData->getBufferObject()->getOrCreateGLBufferObject(state.getContextID());
if (glObject->isDirty()) glObject->compileBuffer();
glObject->_extensions->glBindBufferRange(_target, _index,
glObject->getGLObjectID(), _offset, _size);
glObject->getGLObjectID(), glObject->getOffset(_bufferData->getBufferIndex())+_offset, _size-_offset);
}
}
@@ -73,30 +78,30 @@ UniformBufferBinding::UniformBufferBinding()
}
UniformBufferBinding::UniformBufferBinding(GLuint index)
: BufferIndexBinding(GL_UNIFORM_BUFFER, index)
: BufferIndexBinding(GL_UNIFORM_BUFFER, index)
{
}
UniformBufferBinding::UniformBufferBinding(GLuint index, BufferObject* bo, GLintptr offset,
GLsizeiptr size)
UniformBufferBinding::UniformBufferBinding(GLuint index, BufferData* bo, GLintptr offset,
GLsizeiptr size)
: BufferIndexBinding(GL_UNIFORM_BUFFER, index, bo, offset, size)
{
}
UniformBufferBinding::UniformBufferBinding(const UniformBufferBinding& rhs,
const CopyOp& copyop)
const CopyOp& copyop)
: BufferIndexBinding(rhs, copyop)
{
}
TransformFeedbackBufferBinding::TransformFeedbackBufferBinding(GLuint index)
: BufferIndexBinding(GL_TRANSFORM_FEEDBACK_BUFFER, index)
: BufferIndexBinding(GL_TRANSFORM_FEEDBACK_BUFFER, index)
{
}
TransformFeedbackBufferBinding::TransformFeedbackBufferBinding(GLuint index, BufferObject* bo, GLintptr offset, GLsizeiptr size)
TransformFeedbackBufferBinding::TransformFeedbackBufferBinding(GLuint index, BufferData* bo, GLintptr offset, GLsizeiptr size)
: BufferIndexBinding(GL_TRANSFORM_FEEDBACK_BUFFER, index, bo, offset, size)
{
@@ -109,11 +114,11 @@ TransformFeedbackBufferBinding::TransformFeedbackBufferBinding(const TransformFe
AtomicCounterBufferBinding::AtomicCounterBufferBinding(GLuint index)
: BufferIndexBinding(GL_ATOMIC_COUNTER_BUFFER, index)
: BufferIndexBinding(GL_ATOMIC_COUNTER_BUFFER, index)
{
}
AtomicCounterBufferBinding::AtomicCounterBufferBinding(GLuint index, BufferObject* bo, GLintptr offset, GLsizeiptr size)
AtomicCounterBufferBinding::AtomicCounterBufferBinding(GLuint index, BufferData* bo, GLintptr offset, GLsizeiptr size)
: BufferIndexBinding(GL_ATOMIC_COUNTER_BUFFER, index, bo, offset, size)
{
@@ -126,9 +131,9 @@ AtomicCounterBufferBinding::AtomicCounterBufferBinding(const AtomicCounterBuffer
void AtomicCounterBufferBinding::readData(osg::State & state, osg::UIntArray & uintArray) const
{
if (!_bufferObject) return;
if (!_bufferData) return;
GLBufferObject* bo = _bufferObject->getOrCreateGLBufferObject( state.getContextID() );
GLBufferObject* bo = _bufferData->getBufferObject()->getOrCreateGLBufferObject( state.getContextID() );
if (!bo) return;
@@ -139,7 +144,7 @@ void AtomicCounterBufferBinding::readData(osg::State & state, osg::UIntArray & u
bo->_extensions->glBindBuffer(GL_ATOMIC_COUNTER_BUFFER, bo->getGLObjectID());
GLubyte* src = (GLubyte*)bo->_extensions->glMapBuffer(GL_ATOMIC_COUNTER_BUFFER,
GL_READ_ONLY_ARB);
GL_READ_ONLY_ARB);
if(src)
{
size_t size = osg::minimum<int>(_size, uintArray.getTotalDataSize());
@@ -157,7 +162,7 @@ ShaderStorageBufferBinding::ShaderStorageBufferBinding(GLuint index)
{
}
ShaderStorageBufferBinding::ShaderStorageBufferBinding(GLuint index, BufferObject* bo, GLintptr offset, GLsizeiptr size)
ShaderStorageBufferBinding::ShaderStorageBufferBinding(GLuint index, BufferData* bo, GLintptr offset, GLsizeiptr size)
: BufferIndexBinding(GL_SHADER_STORAGE_BUFFER, index, bo, offset, size)
{
@@ -168,4 +173,5 @@ ShaderStorageBufferBinding::ShaderStorageBufferBinding(const ShaderStorageBuffer
{
}
} // namespace osg

View File

@@ -41,7 +41,11 @@ void DepthRangeIndexed::apply(State& state) const
const GLExtensions* extensions = state.get<GLExtensions>();
if (extensions->glDepthRangeIndexed)
{
extensions->glDepthRangeIndexed(static_cast<GLuint>(_index), static_cast<GLclampd>(_zNear), static_cast<GLclampd>(_zFar));
extensions->glDepthRangeIndexed(static_cast<GLuint>(_index), static_cast<GLdouble>(_zNear), static_cast<GLdouble>(_zFar));
}
else if (extensions->glDepthRangeIndexedf)
{
extensions->glDepthRangeIndexedf(static_cast<GLuint>(_index), static_cast<GLfloat>(_zNear), static_cast<GLfloat>(_zFar));
}
else
{

View File

@@ -817,7 +817,7 @@ void DisplaySettings::readCommandLine(ArgumentParser& arguments)
if (arguments.getApplicationUsage())
{
arguments.getApplicationUsage()->addCommandLineOption("--display <type>","MONITOR | POWERWALL | REALITY_CENTER | HEAD_MOUNTED_DISPLAY");
arguments.getApplicationUsage()->addCommandLineOption("--stereo","Use default stereo mode which is ANAGLYPHIC if not overriden by environmental variable");
arguments.getApplicationUsage()->addCommandLineOption("--stereo","Use default stereo mode which is ANAGLYPHIC if not overridden by environmental variable");
arguments.getApplicationUsage()->addCommandLineOption("--stereo <mode>","ANAGLYPHIC | QUAD_BUFFER | HORIZONTAL_SPLIT | VERTICAL_SPLIT | LEFT_EYE | RIGHT_EYE | HORIZONTAL_INTERLACE | VERTICAL_INTERLACE | CHECKERBOARD | ON | OFF ");
arguments.getApplicationUsage()->addCommandLineOption("--rgba","Request a RGBA color buffer visual");
arguments.getApplicationUsage()->addCommandLineOption("--stencil","Request a stencil buffer visual");

View File

@@ -47,6 +47,9 @@
#else
#include <dlfcn.h>
#endif
#elif defined(__EMSCRIPTEN__)
// Emscripten ships EGL, which we use to get OpenGL function addresses.
#include <EGL/egl.h>
#else
#include <dlfcn.h>
#endif
@@ -407,6 +410,10 @@ OSG_INIT_SINGLETON_PROXY(GLExtensionDisableStringInitializationProxy, osg::getGL
return dlsym(RTLD_DEFAULT, funcName);
#elif defined(__EMSCRIPTEN__)
// Use EGL to get OpenGL function address for Emscripten.
return convertPointerType<void*, __eglMustCastToProperFunctionPointerType>(eglGetProcAddress(funcName));
#else // all other unixes
return dlsym(0, funcName);
@@ -1164,6 +1171,7 @@ GLExtensions::GLExtensions(unsigned int in_contextID):
osg::setGLExtensionFuncPtr(glScissorIndexedv, "glScissorIndexedv", validContext);
osg::setGLExtensionFuncPtr(glDepthRangeArrayv, "glDepthRangeArrayv", validContext);
osg::setGLExtensionFuncPtr(glDepthRangeIndexed, "glDepthRangeIndexed", validContext);
osg::setGLExtensionFuncPtr(glDepthRangeIndexedf, "glDepthRangeIndexedfOES", "glDepthRangeIndexedfNV", validContext);
osg::setGLExtensionFuncPtr(glGetFloati_v, "glGetFloati_v", validContext);
osg::setGLExtensionFuncPtr(glGetDoublei_v, "glGetDoublei_v", validContext);
osg::setGLExtensionFuncPtr(glGetIntegerIndexedvEXT, "glGetIntegerIndexedvEXT", validContext);

View File

@@ -791,6 +791,9 @@ void Geometry::compileGLObjects(RenderInfo& renderInfo) const
if ((*itr)->getBufferObject()) bufferObjects.insert((*itr)->getBufferObject());
}
if (bufferObjects.empty())
return; // no buffers, nothing to compile
//osg::ElapsedTime timer;
// now compile any buffer objects that require it.
@@ -808,11 +811,7 @@ void Geometry::compileGLObjects(RenderInfo& renderInfo) const
// OSG_NOTICE<<"Time to compile "<<timer.elapsedTime_m()<<"ms"<<std::endl;
// unbind the BufferObjects
extensions->glBindBuffer(GL_ARRAY_BUFFER_ARB,0);
extensions->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB,0);
if (state.useVertexArrayObject(_useVertexArrayObject) && !bufferObjects.empty())
if (state.useVertexArrayObject(_useVertexArrayObject))
{
VertexArrayState* vas = 0;
@@ -826,6 +825,10 @@ void Geometry::compileGLObjects(RenderInfo& renderInfo) const
state.unbindVertexArrayObject();
}
// unbind the BufferObjects
extensions->glBindBuffer(GL_ARRAY_BUFFER_ARB,0);
extensions->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB,0);
}
else
{
@@ -1156,8 +1159,6 @@ Geometry* osg::createTexturedQuadGeometry(const Vec3& corner,const Vec3& widthVe
(*normals)[0].normalize();
geom->setNormalArray(normals, osg::Array::BIND_OVERALL);
#if defined(OSG_GLES1_AVAILABLE) || defined(OSG_GLES2_AVAILABLE)
DrawElementsUByte* elems = new DrawElementsUByte(PrimitiveSet::TRIANGLES);
elems->push_back(0);
elems->push_back(1);
@@ -1167,9 +1168,6 @@ Geometry* osg::createTexturedQuadGeometry(const Vec3& corner,const Vec3& widthVe
elems->push_back(3);
elems->push_back(0);
geom->addPrimitiveSet(elems);
#else
geom->addPrimitiveSet(new DrawArrays(PrimitiveSet::QUADS,0,4));
#endif
return geom;
}

View File

@@ -742,6 +742,41 @@ inline T SGL_ABS(T a)
#define SGL_SWAP(a,b,temp) ((temp)=(a),(a)=(b),(b)=(temp))
#endif
bool Matrix_implementation::transpose(const Matrix_implementation&mat){
if (&mat==this) {
Matrix_implementation tm(mat);
return transpose(tm);
}
_mat[0][1]=mat._mat[1][0];
_mat[0][2]=mat._mat[2][0];
_mat[0][3]=mat._mat[3][0];
_mat[1][0]=mat._mat[0][1];
_mat[1][2]=mat._mat[2][1];
_mat[1][3]=mat._mat[3][1];
_mat[2][0]=mat._mat[0][2];
_mat[2][1]=mat._mat[1][2];
_mat[2][3]=mat._mat[3][2];
_mat[3][0]=mat._mat[0][3];
_mat[3][1]=mat._mat[1][3];
_mat[3][2]=mat._mat[2][3];
return true;
}
bool Matrix_implementation::transpose3x3(const Matrix_implementation&mat){
if (&mat==this) {
Matrix_implementation tm(mat);
return transpose3x3(tm);
}
_mat[0][1]=mat._mat[1][0];
_mat[0][2]=mat._mat[2][0];
_mat[1][0]=mat._mat[0][1];
_mat[1][2]=mat._mat[2][1];
_mat[2][0]=mat._mat[0][2];
_mat[2][1]=mat._mat[1][2];
return true;
}
bool Matrix_implementation::invert_4x4( const Matrix_implementation& mat )
{
if (&mat==this) {
@@ -763,7 +798,7 @@ bool Matrix_implementation::invert_4x4( const Matrix_implementation& mat )
for(i=0;i<4;i++)
{
big=0.0;
for (j=0; j<4; j++)
for (j=0; j<4; ++j)
if (ipiv[j] != 1)
for (k=0; k<4; k++)
{
@@ -781,7 +816,7 @@ bool Matrix_implementation::invert_4x4( const Matrix_implementation& mat )
}
++(ipiv[icol]);
if (irow != icol)
for (l=0; l<4; l++) SGL_SWAP(operator()(irow,l),
for (l=0; l<4; ++l) SGL_SWAP(operator()(irow,l),
operator()(icol,l),
temp);
@@ -792,13 +827,13 @@ bool Matrix_implementation::invert_4x4( const Matrix_implementation& mat )
pivinv = 1.0/operator()(icol,icol);
operator()(icol,icol) = 1;
for (l=0; l<4; l++) operator()(icol,l) *= pivinv;
for (ll=0; ll<4; ll++)
for (l=0; l<4; ++l) operator()(icol,l) *= pivinv;
for (ll=0; ll<4; ++ll)
if (ll != icol)
{
dum=operator()(ll,icol);
operator()(ll,icol) = 0;
for (l=0; l<4; l++) operator()(ll,l) -= operator()(icol,l)*dum;
for (l=0; l<4; ++l) operator()(ll,l) -= operator()(icol,l)*dum;
}
}
for (int lx=4; lx>0; --lx)

View File

@@ -61,6 +61,9 @@ struct NotifyStreamBuffer : public std::stringbuf
{
NotifyStreamBuffer() : _severity(osg::NOTICE)
{
/* reduce the need to reallocate the std::ostream buffer behind osg::Notify (causing multitreading issues) by pre-allocating 4095 bytes */
str(std::string(4095, 0));
pubseekpos(0, std::ios_base::out);
}
void setNotifyHandler(osg::NotifyHandler *handler) { _handler = handler; }

View File

@@ -1634,7 +1634,7 @@ void Texture::computeInternalFormatWithImage(const osg::Image& image) const
{
case(GL_INTENSITY) : internalFormat = GL_RED; break; // should it be swizzled to match RGBA(INTENSITY, INTENSITY, INTENSITY, INTENSITY)?
case(GL_LUMINANCE) : internalFormat = GL_RED; break; // should it be swizzled to match RGBA(LUMINANCE, LUMINANCE, LUMINANCE, 1.0)?
case(1) : internalFormat = GL_RED; break; // or sould this be GL_ALPHA?
case(1) : internalFormat = GL_RED; break; // or should this be GL_ALPHA?
case(2) : internalFormat = GL_RG; break; // should we assume GL_LUMINANCE_ALPHA?
case(GL_LUMINANCE_ALPHA) : internalFormat = GL_RG; break; // should it be swizlled to match RGAB(LUMUNIANCE, LUMINANCE, LUMINANCE, ALPHA)?
case(3) : internalFormat = GL_RGB; break;

View File

@@ -63,7 +63,7 @@ void TextureBuffer::setBufferData(BufferData *bufferdata)
{
_bufferData->addClient(this);
///set BufferObject if not setted by user
///set BufferObject if not set by user
if(!_bufferData->getBufferObject())
{
VertexBufferObject* bo=new VertexBufferObject();