From 7d34a54a3b2ddd37ac107003b952bf1d45d61d52 Mon Sep 17 00:00:00 2001 From: "John W. Terrell" Date: Thu, 14 Nov 2019 11:18:34 -0800 Subject: [PATCH 01/40] thogarth - added ovr_multiview support to FrameBufferObject and const to camera to enable the extension on attachments --- include/osg/Camera | 1 + include/osg/GLExtensions | 1 + src/osg/Camera.cpp | 1 + src/osg/FrameBufferObject.cpp | 7 +++++++ src/osg/GLExtensions.cpp | 2 ++ 5 files changed, 12 insertions(+) diff --git a/include/osg/Camera b/include/osg/Camera index b1cfc95dcce..1050ee5e3e7 100644 --- a/include/osg/Camera +++ b/include/osg/Camera @@ -347,6 +347,7 @@ class OSG_EXPORT Camera : public Transform, public CullSettings }; static const unsigned int FACE_CONTROLLED_BY_GEOMETRY_SHADER; + static const unsigned int FACE_CONTROLLED_BY_MULTIVIEW_SHADER; /** Attach a buffer with specified OpenGL internal format.*/ void attach(BufferComponent buffer, GLenum internalFormat); diff --git a/include/osg/GLExtensions b/include/osg/GLExtensions index aa868e9cf2f..b2517419886 100644 --- a/include/osg/GLExtensions +++ b/include/osg/GLExtensions @@ -680,6 +680,7 @@ class OSG_EXPORT GLExtensions : public osg::Referenced void (GL_APIENTRY * glFramebufferTexture) (GLenum, GLenum, GLint, GLint); void (GL_APIENTRY * glFramebufferTextureLayer) (GLenum, GLenum, GLuint, GLint, GLint); void (GL_APIENTRY * glFramebufferTextureFace)( GLenum target, GLenum attachment, GLuint texture, GLint level, GLenum face ); + void (GL_APIENTRY * glFramebufferTextureMultiviewOVR) (GLenum, GLenum, GLenum, GLuint, GLint, GLint); void (GL_APIENTRY * glFramebufferRenderbuffer) (GLenum, GLenum, GLenum, GLuint); void (GL_APIENTRY * glGenerateMipmap) (GLenum); diff --git a/src/osg/Camera.cpp b/src/osg/Camera.cpp index 640efc16556..024a1c22da6 100644 --- a/src/osg/Camera.cpp +++ b/src/osg/Camera.cpp @@ -23,6 +23,7 @@ using namespace osg; const unsigned int Camera::FACE_CONTROLLED_BY_GEOMETRY_SHADER = 0xffffffff; +const unsigned int Camera::FACE_CONTROLLED_BY_MULTIVIEW_SHADER = 0xfffffff0; Camera::Camera(): _view(0), diff --git a/src/osg/FrameBufferObject.cpp b/src/osg/FrameBufferObject.cpp index c3988e06743..c5bde7cc02d 100644 --- a/src/osg/FrameBufferObject.cpp +++ b/src/osg/FrameBufferObject.cpp @@ -492,6 +492,13 @@ void FrameBufferAttachment::attach(State &state, GLenum target, GLenum attachmen case Pimpl::TEXTURE2DARRAY: if (_ximpl->zoffset == Camera::FACE_CONTROLLED_BY_GEOMETRY_SHADER) ext->glFramebufferTexture(target, attachment_point, tobj->id(), _ximpl->level); + else if(_ximpl->zoffset == Camera::FACE_CONTROLLED_BY_MULTIVIEW_SHADER) + { + if (ext->glFramebufferTextureMultiviewOVR) + { + ext->glFramebufferTextureMultiviewOVR(target, attachment_point, tobj->id(), _ximpl->level, 0, 2); + } + } else ext->glFramebufferTextureLayer(target, attachment_point, tobj->id(), _ximpl->level, _ximpl->zoffset); break; diff --git a/src/osg/GLExtensions.cpp b/src/osg/GLExtensions.cpp index 375ba86be4d..c361a421f4e 100644 --- a/src/osg/GLExtensions.cpp +++ b/src/osg/GLExtensions.cpp @@ -1099,6 +1099,8 @@ GLExtensions::GLExtensions(unsigned int in_contextID): setGLExtensionFuncPtr(glFramebufferTextureLayer, "glFramebufferTextureLayer", "glFramebufferTextureLayerEXT", "glFramebufferTextureLayerOES", validContext); setGLExtensionFuncPtr(glFramebufferTextureFace, "glFramebufferTextureFace", "glFramebufferTextureFaceEXT", "glFramebufferTextureFaceOES" , validContext); setGLExtensionFuncPtr(glFramebufferRenderbuffer, "glFramebufferRenderbuffer", "glFramebufferRenderbufferEXT", "glFramebufferRenderbufferOES", validContext); + setGLExtensionFuncPtr(glFramebufferTextureMultiviewOVR, "glFramebufferTextureMultiviewOVR", validContext); + //ARB_framebuffer_no_attachments //OpenGL 4.3 setGLExtensionFuncPtr(glFramebufferParameteri, "glFramebufferParameteri", "glFramebufferParameteriARB", "glFramebufferParameteriOES", validContext); From 3ecd94babc846a54f92e60d4fd100ba41de5c4a9 Mon Sep 17 00:00:00 2001 From: "John W. Terrell" Date: Fri, 10 Jan 2020 03:07:59 +0000 Subject: [PATCH 02/40] thogarth - merged multiview branch to add multisampling support to texture2d arrays --- include/osg/FrameBufferObject | 5 + include/osg/Texture | 4 + include/osg/Texture2DMultisampleArray | 95 ++++++++++++++ include/osgUtil/RenderStage | 7 ++ src/osg/CMakeLists.txt | 2 + src/osg/FrameBufferObject.cpp | 63 +++++++++- src/osg/StateSet.cpp | 1 + src/osg/Texture2DMultisampleArray.cpp | 156 +++++++++++++++++++++++ src/osgUtil/RenderStage.cpp | 173 ++++++++++++++++++++------ 9 files changed, 467 insertions(+), 39 deletions(-) create mode 100644 include/osg/Texture2DMultisampleArray create mode 100644 src/osg/Texture2DMultisampleArray.cpp diff --git a/include/osg/FrameBufferObject b/include/osg/FrameBufferObject index 9bcb8e8edf5..fd081d2c2cd 100644 --- a/include/osg/FrameBufferObject +++ b/include/osg/FrameBufferObject @@ -265,6 +265,7 @@ class Texture2D; class Texture2DMultisample; class Texture3D; class Texture2DArray; +class Texture2DMultisampleArray; class TextureCubeMap; class TextureRectangle; @@ -280,6 +281,7 @@ class OSG_EXPORT FrameBufferAttachment explicit FrameBufferAttachment(Texture2DMultisample* target, unsigned int level = 0); explicit FrameBufferAttachment(Texture3D* target, unsigned int zoffset, unsigned int level = 0); explicit FrameBufferAttachment(Texture2DArray* target, unsigned int layer, unsigned int level = 0); + explicit FrameBufferAttachment(Texture2DMultisampleArray* target, unsigned int layer, unsigned int level = 0); explicit FrameBufferAttachment(TextureCubeMap* target, unsigned int face, unsigned int level = 0); explicit FrameBufferAttachment(TextureRectangle* target); explicit FrameBufferAttachment(Camera::Attachment& attachment); @@ -304,6 +306,8 @@ class OSG_EXPORT FrameBufferAttachment unsigned int getTexture3DZOffset() const; unsigned int getTextureArrayLayer() const; + bool isArray() const; + void resizeGLObjectBuffers(unsigned int maxSize); void releaseGLObjects(osg::State* = 0) const; @@ -341,6 +345,7 @@ class OSG_EXPORT FrameBufferObject: public StateAttribute inline const MultipleRenderingTargets& getMultipleRenderingTargets() const { return _drawBuffers; } bool isMultisample() const; + bool isArray() const; int compare(const StateAttribute &sa) const; diff --git a/include/osg/Texture b/include/osg/Texture index 22f0b91c1d0..02ad7a583c1 100644 --- a/include/osg/Texture +++ b/include/osg/Texture @@ -240,6 +240,10 @@ #define GL_TEXTURE_2D_MULTISAMPLE 0x9100 #endif +#ifndef GL_TEXTURE_2D_MULTISAMPLE_ARRAY + #define GL_TEXTURE_2D_MULTISAMPLE_ARRAY 0x9102 +#endif + // Integer texture extension as in http://www.opengl.org/registry/specs/EXT/texture_integer.txt #ifndef GL_EXT_texture_integer #define GL_RGBA32UI_EXT 0x8D70 diff --git a/include/osg/Texture2DMultisampleArray b/include/osg/Texture2DMultisampleArray new file mode 100644 index 00000000000..983dad4d4f7 --- /dev/null +++ b/include/osg/Texture2DMultisampleArray @@ -0,0 +1,95 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2010 Robert Osfield + * + * 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 + * (at your option) any later version. The full license is in LICENSE file + * included with this distribution, and on the openscenegraph.org website. + * + * This library 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. See the + * OpenSceneGraph Public License for more details. + * +*/ + +#ifndef OSG_TEXTURE2DMSARRAY +#define OSG_TEXTURE2DMSARRAY 1 + +#include + +namespace osg { + +class OSG_EXPORT Texture2DMultisampleArray : public Texture +{ + public : + + Texture2DMultisampleArray(); + + Texture2DMultisampleArray(GLsizei numSamples, GLboolean fixedsamplelocations); + + Texture2DMultisampleArray(int width, int height, int depth, GLenum internalFormat, GLsizei numSamples, GLboolean fixedsamplelocations); + + /** Copy constructor using CopyOp to manage deep vs shallow copy. */ + Texture2DMultisampleArray(const Texture2DMultisampleArray& text,const CopyOp& copyop=CopyOp::SHALLOW_COPY); + + META_StateAttribute(osg, Texture2DMultisampleArray,TEXTURE); + + /** Return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs. */ + virtual int compare(const StateAttribute& rhs) const; + + virtual GLenum getTextureTarget() const + { + return GL_TEXTURE_2D_MULTISAMPLE_ARRAY; + } + + /** Texture2DMultisampleArray is related to non fixed pipeline usage only so isn't appropriate to enable/disable.*/ + virtual bool getModeUsage(StateAttribute::ModeUsage&) const { return false; } + + /** Sets the texture width and height. **/ + inline void setTextureSize(int width, int height, int depth) const + { + _textureWidth = width; + _textureHeight = height; + _textureDepth = depth; + } + + inline void setNumSamples( int samples ) { _numSamples = samples; } + GLsizei getNumSamples() const { return _numSamples; } + + // unnecessary for Texture2DMultisampleArray + virtual void setImage(unsigned int /*face*/, Image* /*image*/) {} + virtual Image* getImage(unsigned int /*face*/) { return NULL; } + virtual const Image* getImage(unsigned int /*face*/) const { return NULL; } + virtual unsigned int getNumImages() const {return 0; } + virtual void allocateMipmap(State& /*state*/) const {} + + void setTextureWidth(int width) { _textureWidth=width; } + void setTextureHeight(int height) { _textureHeight=height; } + void setTextureDepth(int depth) { _textureDepth=depth; } + + virtual int getTextureWidth() const { return _textureWidth; } + virtual int getTextureHeight() const { return _textureHeight; } + virtual int getTextureDepth() const { return _textureDepth; } + + /** Bind the texture object. If the texture object hasn't already been + * compiled, create the texture mipmap levels. */ + virtual void apply(State& state) const; + + protected : + + virtual ~Texture2DMultisampleArray(); + + virtual void computeInternalFormat() const; + + /** Subloaded images can have different texture and image sizes. */ + mutable GLsizei _textureWidth, _textureHeight, _textureDepth; + + mutable GLsizei _numSamples; + + mutable GLboolean _fixedsamplelocations; + +}; + +} + +#endif diff --git a/include/osgUtil/RenderStage b/include/osgUtil/RenderStage index 3025ac36b06..3dc70b499c4 100644 --- a/include/osgUtil/RenderStage +++ b/include/osgUtil/RenderStage @@ -313,6 +313,13 @@ protected: osg::ref_ptr _fbo; osg::ref_ptr _resolveFbo; + + // VRV_PATCH BEGIN + // for resolving individual layers of a multisampled texture 2d array + std::vector> _arrayLayerFbos; + std::vector> _resolveArrayLayerFbos; + // VRV_PATCH END + osg::ref_ptr _graphicsContext; bool _disableFboAfterRender; diff --git a/src/osg/CMakeLists.txt b/src/osg/CMakeLists.txt index df6f14ad499..31b88cfe02c 100644 --- a/src/osg/CMakeLists.txt +++ b/src/osg/CMakeLists.txt @@ -182,6 +182,7 @@ SET(TARGET_H ${HEADER_PATH}/Texture2D ${HEADER_PATH}/Texture2DMultisample ${HEADER_PATH}/Texture2DArray + ${HEADER_PATH}/Texture2DMultisampleArray ${HEADER_PATH}/Texture3D ${HEADER_PATH}/TextureBuffer ${HEADER_PATH}/TextureCubeMap @@ -385,6 +386,7 @@ SET(TARGET_SRC TexMat.cpp Texture1D.cpp Texture2DArray.cpp + Texture2DMultisampleArray.cpp Texture2D.cpp Texture2DMultisample.cpp Texture3D.cpp diff --git a/src/osg/FrameBufferObject.cpp b/src/osg/FrameBufferObject.cpp index c5bde7cc02d..abe020a96f1 100644 --- a/src/osg/FrameBufferObject.cpp +++ b/src/osg/FrameBufferObject.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -209,7 +210,8 @@ struct FrameBufferAttachment::Pimpl TEXTURECUBE, TEXTURERECT, TEXTURE2DARRAY, - TEXTURE2DMULTISAMPLE + TEXTURE2DMULTISAMPLE, + TEXTURE2DMULTISAMPLEARRAY }; TargetType targetType; @@ -286,6 +288,13 @@ FrameBufferAttachment::FrameBufferAttachment(Texture2DArray* target, unsigned in _ximpl->zoffset = layer; } +FrameBufferAttachment::FrameBufferAttachment(Texture2DMultisampleArray* target, unsigned int layer, unsigned int level) +{ + _ximpl = new Pimpl(Pimpl::TEXTURE2DMULTISAMPLEARRAY, level); + _ximpl->textureTarget = target; + _ximpl->zoffset = layer; +} + FrameBufferAttachment::FrameBufferAttachment(TextureCubeMap* target, unsigned int face, unsigned int level) { _ximpl = new Pimpl(Pimpl::TEXTURECUBE, level); @@ -347,6 +356,15 @@ FrameBufferAttachment::FrameBufferAttachment(Camera::Attachment& attachment) return; } + osg::Texture2DMultisampleArray* texture2DMSArray = dynamic_cast(texture); + if (texture2DMSArray) + { + _ximpl = new Pimpl(Pimpl::TEXTURE2DMULTISAMPLEARRAY, attachment._level); + _ximpl->textureTarget = texture2DMSArray; + _ximpl->zoffset = attachment._face; + return; + } + osg::TextureCubeMap* textureCubeMap = dynamic_cast(texture); if (textureCubeMap) { @@ -410,6 +428,14 @@ bool FrameBufferAttachment::isMultisample() const { return _ximpl->renderbufferTarget->getSamples() > 0; } + else if(_ximpl->textureTarget.valid()) + { + osg::Texture2DMultisampleArray* tex2DMSArray = dynamic_cast(_ximpl->textureTarget.get()); + if (tex2DMSArray != NULL) + { + return tex2DMSArray->getNumSamples() > 0; + } + } return false; } @@ -502,6 +528,24 @@ void FrameBufferAttachment::attach(State &state, GLenum target, GLenum attachmen else ext->glFramebufferTextureLayer(target, attachment_point, tobj->id(), _ximpl->level, _ximpl->zoffset); break; + case Pimpl::TEXTURE2DMULTISAMPLEARRAY: + if (_ximpl->zoffset == Camera::FACE_CONTROLLED_BY_GEOMETRY_SHADER) + { + if (ext->glFramebufferTexture) + { + ext->glFramebufferTexture(target, attachment_point, tobj->id(), _ximpl->level); + } + } + else if (_ximpl->zoffset == Camera::FACE_CONTROLLED_BY_MULTIVIEW_SHADER) + { + if (ext->glFramebufferTextureMultiviewOVR) + { + ext->glFramebufferTextureMultiviewOVR(target, attachment_point, tobj->id(), _ximpl->level, 0, 2); + } + } + else + ext->glFramebufferTextureLayer(target, attachment_point, tobj->id(), _ximpl->level, _ximpl->zoffset); + break; case Pimpl::TEXTURERECT: ext->glFramebufferTexture2D(target, attachment_point, GL_TEXTURE_RECTANGLE, tobj->id(), 0); break; @@ -572,6 +616,11 @@ unsigned int FrameBufferAttachment::getTextureArrayLayer() const return _ximpl->zoffset; } +bool FrameBufferAttachment::isArray() const +{ + return _ximpl->targetType == Pimpl::TEXTURE2DARRAY || _ximpl->targetType == Pimpl::TEXTURE2DMULTISAMPLEARRAY; +} + void FrameBufferAttachment::resizeGLObjectBuffers(unsigned int maxSize) { if (_ximpl->renderbufferTarget.valid()) _ximpl->renderbufferTarget->resizeGLObjectBuffers(maxSize); @@ -807,6 +856,18 @@ bool FrameBufferObject::isMultisample() const return false; } +bool FrameBufferObject::isArray() const +{ + if (_attachments.size()) + { + // If the FBO is correctly set up then all attachments will be either + // arrays or standard types + return _attachments.begin()->second.isArray(); + } + + return false; +} + int FrameBufferObject::compare(const StateAttribute &sa) const { COMPARE_StateAttribute_Types(FrameBufferObject, sa); diff --git a/src/osg/StateSet.cpp b/src/osg/StateSet.cpp index d5ef599bcbd..8355bc400b6 100644 --- a/src/osg/StateSet.cpp +++ b/src/osg/StateSet.cpp @@ -142,6 +142,7 @@ class TextureGLModeSet _textureModeSet.insert(GL_TEXTURE_RECTANGLE_NV); _textureModeSet.insert(GL_TEXTURE_2D_ARRAY); _textureModeSet.insert(GL_TEXTURE_2D_MULTISAMPLE); + _textureModeSet.insert(GL_TEXTURE_2D_MULTISAMPLE_ARRAY); _textureModeSet.insert(GL_TEXTURE_GEN_Q); _textureModeSet.insert(GL_TEXTURE_GEN_R); diff --git a/src/osg/Texture2DMultisampleArray.cpp b/src/osg/Texture2DMultisampleArray.cpp new file mode 100644 index 00000000000..35aaa1a1be5 --- /dev/null +++ b/src/osg/Texture2DMultisampleArray.cpp @@ -0,0 +1,156 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2010 Robert Osfield + * + * 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 + * (at your option) any later version. The full license is in LICENSE file + * included with this distribution, and on the openscenegraph.org website. + * + * This library 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. See the + * OpenSceneGraph Public License for more details. + * +*/ + +#include +#include +#include +#include + +using namespace osg; + +Texture2DMultisampleArray::Texture2DMultisampleArray(): + _textureWidth(0), + _textureHeight(0), + _textureDepth(0), + _numSamples(1), + _fixedsamplelocations(GL_FALSE) +{ +} + +Texture2DMultisampleArray::Texture2DMultisampleArray(GLsizei numSamples, GLboolean fixedsamplelocations): + _textureWidth(0), + _textureHeight(0), + _textureDepth(0), + _numSamples(numSamples), + _fixedsamplelocations(fixedsamplelocations) +{ +} + +Texture2DMultisampleArray::Texture2DMultisampleArray(int width, int height, int depth, GLenum internalFormat, GLsizei numSamples, GLboolean fixedsamplelocations) : + _textureWidth(width), + _textureHeight(height), + _textureDepth(depth), + _numSamples(numSamples), + _fixedsamplelocations(fixedsamplelocations) +{ + setInternalFormat(internalFormat); +} + +Texture2DMultisampleArray::Texture2DMultisampleArray(const Texture2DMultisampleArray& text,const CopyOp& copyop): + Texture(text,copyop), + _textureWidth(text._textureWidth), + _textureHeight(text._textureHeight), + _textureDepth(text._textureDepth), + _numSamples(text._numSamples), + _fixedsamplelocations(text._fixedsamplelocations) +{ +} + +Texture2DMultisampleArray::~Texture2DMultisampleArray() +{ +} + +int Texture2DMultisampleArray::compare(const StateAttribute& sa) const +{ + // check the types are equal and then create the rhs variable + // used by the COMPARE_StateAttribute_Parameter macros below. + COMPARE_StateAttribute_Types(Texture2DMultisampleArray,sa) + + + int result = compareTexture(rhs); + if (result!=0) return result; + + // compare each parameter in turn against the rhs. + if (_textureWidth != 0 && rhs._textureWidth != 0) + { + COMPARE_StateAttribute_Parameter(_textureWidth) + } + if (_textureHeight != 0 && rhs._textureHeight != 0) + { + COMPARE_StateAttribute_Parameter(_textureHeight) + } + if (_textureDepth != 0 && rhs._textureDepth != 0) + { + COMPARE_StateAttribute_Parameter(_textureDepth) + } + if (_numSamples != 0 && rhs._numSamples != 0) + { + COMPARE_StateAttribute_Parameter(_numSamples) + } + if (_fixedsamplelocations != 0 && rhs._fixedsamplelocations != 0) + { + COMPARE_StateAttribute_Parameter(_fixedsamplelocations) + } + + + return 0; // passed all the above comparison macros, must be equal. +} + +void Texture2DMultisampleArray::apply(State& state) const +{ + // current OpenGL context. + const unsigned int contextID = state.getContextID(); + const GLExtensions* extensions = state.get(); + if (!extensions->isTextureMultisampledSupported) + { + OSG_INFO<<"Texture2DMultisampleArray not supported."<getApplyTime())); + tom->getNumberApplied()++; +#endif + + // get the texture object for the current contextID. + TextureObject* textureObject = getTextureObject(contextID); + + if (textureObject) + { + textureObject->bind(); + } + else if ( (_textureWidth!=0) && (_textureHeight!=0) && (_textureDepth != 0) && (_numSamples!=0) ) + { + textureObject = generateAndAssignTextureObject( + contextID, + getTextureTarget(), + 1, + _internalFormat, + _textureWidth, + _textureHeight, + _textureDepth, + _borderWidth); + + textureObject->bind(); + + extensions->glTexImage3DMultisample( getTextureTarget(), + _numSamples, + _internalFormat, + _textureWidth, + _textureHeight, + _textureDepth, + _fixedsamplelocations ); + } + else + { + glBindTexture( getTextureTarget(), 0 ); + } +} + +void Texture2DMultisampleArray::computeInternalFormat() const +{ + computeInternalFormatType(); +} + diff --git a/src/osgUtil/RenderStage.cpp b/src/osgUtil/RenderStage.cpp index d8300d2e35c..05f0c3cfc8c 100644 --- a/src/osgUtil/RenderStage.cpp +++ b/src/osgUtil/RenderStage.cpp @@ -17,6 +17,8 @@ #include #include #include +#include +#include #include #include #include @@ -243,11 +245,14 @@ void RenderStage::runCameraSetUp(osg::RenderInfo& renderInfo) osg::Camera::BufferAttachmentMap& bufferAttachments = _camera->getBufferAttachmentMap(); _bufferAttachmentMap.clear(); + _resolveArrayLayerFbos.clear(); + _arrayLayerFbos.clear(); // compute the required dimensions int width = static_cast(_viewport->x() + _viewport->width()); int height = static_cast(_viewport->y() + _viewport->height()); int depth = 1; + bool isArray = false; for(osg::Camera::BufferAttachmentMap::iterator itr = bufferAttachments.begin(); itr != bufferAttachments.end(); ++itr) @@ -296,6 +301,7 @@ void RenderStage::runCameraSetUp(osg::RenderInfo& renderInfo) osg::Texture3D* texture3D = 0; osg::TextureCubeMap* textureCubeMap = 0; osg::TextureRectangle* textureRectangle = 0; + osg::Texture2DArray* texture2DArray = 0; if (0 != (texture1D=dynamic_cast(texture))) { if (texture1D->getTextureWidth()==0) @@ -339,7 +345,13 @@ void RenderStage::runCameraSetUp(osg::RenderInfo& renderInfo) textureRectangle->setTextureSize(width,height); } } - + else if (0 != (texture2DArray = dynamic_cast(texture))) + { + isArray = true; + //width = texture2DArray->getTextureWidth(); + //height = texture2DArray->getTextureHeight(); + depth = texture2DArray->getTextureDepth(); + } } } @@ -437,10 +449,62 @@ void RenderStage::runCameraSetUp(osg::RenderInfo& renderInfo) break; } } - fbo_multisample->setAttachment(buffer, - osg::FrameBufferAttachment(new osg::RenderBuffer( - width, height, internalFormat, - samples, colorSamples))); + + // VRV_PATCH BEGIN + if(!isArray) + { + fbo_multisample->setAttachment(buffer, + osg::FrameBufferAttachment(new osg::RenderBuffer( + width, height, internalFormat, + samples, colorSamples))); + } + else + { + if(ext->isTextureMultisampledSupported) + { + osg::Texture2DMultisampleArray* multiSampleTexArray = new osg::Texture2DMultisampleArray(width, height, depth, internalFormat, samples, GL_FALSE); + fbo_multisample->setAttachment(buffer, osg::FrameBufferAttachment(multiSampleTexArray, attachment._face, 0)); + + osg::Texture2DArray* attachmentAsTex2dArray = dynamic_cast(attachment._texture.get()); + + // make a read and draw fbos for each layer so we can resolve later + for(unsigned int i=0; i layerfbo; + osg::ref_ptr resolvelayerfbo; + + if(static_cast(_arrayLayerFbos.size()) <= i) + { + layerfbo = new osg::FrameBufferObject; + layerfbo->setName(_camera->getName() + "_layer_"); + _arrayLayerFbos.push_back(layerfbo); + } + else + { + layerfbo = _arrayLayerFbos[i]; + } + + if (static_cast(_resolveArrayLayerFbos.size()) <= i) + { + resolvelayerfbo = new osg::FrameBufferObject; + resolvelayerfbo->setName(_camera->getName() + "_resolvelayer_"); + _resolveArrayLayerFbos.push_back(resolvelayerfbo); + } + else + { + resolvelayerfbo = _resolveArrayLayerFbos[i]; + } + + resolvelayerfbo->setAttachment(buffer, osg::FrameBufferAttachment(attachmentAsTex2dArray, i, 0)); + layerfbo->setAttachment(buffer, osg::FrameBufferAttachment(multiSampleTexArray, i, 0)); + } + } + else + { + fbo_multisample = NULL; + } + } + // VRV_PATCH END } if (buffer==osg::Camera::DEPTH_BUFFER) depthAttached = true; @@ -542,7 +606,11 @@ void RenderStage::runCameraSetUp(osg::RenderInfo& renderInfo) } else { - setDrawBuffer(GL_NONE, false ); + //OSG_WARN << "Camera '" << _camera->getName() << "' fbo details" << std::endl; + + //dumpFboInfo(fbo); + + setDrawBuffer(GL_NONE, false); setReadBuffer(GL_NONE, false ); _fbo = fbo; @@ -558,6 +626,8 @@ void RenderStage::runCameraSetUp(osg::RenderInfo& renderInfo) "multisample FBO setup failed, FBO status = 0x" << std::hex << status << std::dec << std::endl; + //dumpFboInfo(fbo_multisample); + fbo->apply(state); fbo_multisample = 0; _resolveFbo = 0; @@ -951,6 +1021,8 @@ void RenderStage::drawInner(osg::RenderInfo& renderInfo,RenderLeaf*& previous, b if (fbo_supported && _resolveFbo.valid() && ext->glBlitFramebuffer) { + bool isArray = _resolveFbo->getAttachmentMap().begin()->second.isArray(); // VRV_PATCH + GLbitfield blitMask = 0; bool needToBlitColorBuffers = false; @@ -979,52 +1051,77 @@ void RenderStage::drawInner(osg::RenderInfo& renderInfo,RenderLeaf*& previous, b } } - // Bind the resolve framebuffer to blit into. - _fbo->apply(state, FrameBufferObject::READ_FRAMEBUFFER); - _resolveFbo->apply(state, FrameBufferObject::DRAW_FRAMEBUFFER); - - if (blitMask) + if (!isArray) // VRV_PATCH { - // Blit to the resolve framebuffer. - // Note that (with nvidia 175.16 windows drivers at least) if the read - // framebuffer is multisampled then the dimension arguments are ignored - // and the whole framebuffer is always copied. - ext->glBlitFramebuffer( - static_cast(_viewport->x()), static_cast(_viewport->y()), - static_cast(_viewport->x() + _viewport->width()), static_cast(_viewport->y() + _viewport->height()), - static_cast(_viewport->x()), static_cast(_viewport->y()), - static_cast(_viewport->x() + _viewport->width()), static_cast(_viewport->y() + _viewport->height()), - blitMask, GL_NEAREST); - } -#if !defined(OSG_GLES1_AVAILABLE) && !defined(OSG_GLES2_AVAILABLE) && !defined(OSG_GLES3_AVAILABLE) - if (needToBlitColorBuffers) + // Bind the resolve framebuffer to blit into. + _fbo->apply(state, FrameBufferObject::READ_FRAMEBUFFER); + _resolveFbo->apply(state, FrameBufferObject::DRAW_FRAMEBUFFER); + + if (blitMask) + { + // Blit to the resolve framebuffer. + // Note that (with nvidia 175.16 windows drivers at least) if the read + // framebuffer is multisampled then the dimension arguments are ignored + // and the whole framebuffer is always copied. + ext->glBlitFramebuffer( + static_cast(_viewport->x()), static_cast(_viewport->y()), + static_cast(_viewport->x() + _viewport->width()), static_cast(_viewport->y() + _viewport->height()), + static_cast(_viewport->x()), static_cast(_viewport->y()), + static_cast(_viewport->x() + _viewport->width()), static_cast(_viewport->y() + _viewport->height()), + blitMask, GL_NEAREST); + } + +#if !defined(OSG_GLES1_AVAILABLE) && !defined(OSG_GLES2_AVAILABLE) + if (needToBlitColorBuffers) + { + for (FrameBufferObject::AttachmentMap::const_iterator + it = _resolveFbo->getAttachmentMap().begin(), + end =_resolveFbo->getAttachmentMap().end(); it != end; ++it) + { + osg::Camera::BufferComponent attachment = it->first; + if (attachment >= osg::Camera::COLOR_BUFFER0) + { + glReadBuffer(GL_COLOR_ATTACHMENT0_EXT + (attachment - osg::Camera::COLOR_BUFFER0)); + glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT + (attachment - osg::Camera::COLOR_BUFFER0)); + + ext->glBlitFramebuffer( + static_cast(_viewport->x()), static_cast(_viewport->y()), + static_cast(_viewport->x() + _viewport->width()), static_cast(_viewport->y() + _viewport->height()), + static_cast(_viewport->x()), static_cast(_viewport->y()), + static_cast(_viewport->x() + _viewport->width()), static_cast(_viewport->y() + _viewport->height()), + GL_COLOR_BUFFER_BIT, GL_NEAREST); + } + } + // reset the read and draw buffers? will comment out for now with the assumption that + // the buffers will be set explicitly when needed elsewhere. + // glReadBuffer(GL_COLOR_ATTACHMENT0_EXT); + // glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT); + } +#endif + } + else { - for (FrameBufferObject::AttachmentMap::const_iterator - it = _resolveFbo->getAttachmentMap().begin(), - end =_resolveFbo->getAttachmentMap().end(); it != end; ++it) + // VRV_PATCH BEGIN + if (blitMask) { - osg::Camera::BufferComponent attachment = it->first; - if (attachment >=osg::Camera::COLOR_BUFFER0) + for(unsigned int i = 0; i < _resolveArrayLayerFbos.size(); i++) { - state.glReadBuffer(GL_COLOR_ATTACHMENT0_EXT + (attachment - osg::Camera::COLOR_BUFFER0)); - state.glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT + (attachment - osg::Camera::COLOR_BUFFER0)); + //_arrayLayerFbos[i]->dirtyAll(); + _arrayLayerFbos[i]->apply(state, FrameBufferObject::READ_FRAMEBUFFER); + _resolveArrayLayerFbos[i]->apply(state, FrameBufferObject::DRAW_FRAMEBUFFER); ext->glBlitFramebuffer( static_cast(_viewport->x()), static_cast(_viewport->y()), static_cast(_viewport->x() + _viewport->width()), static_cast(_viewport->y() + _viewport->height()), static_cast(_viewport->x()), static_cast(_viewport->y()), static_cast(_viewport->x() + _viewport->width()), static_cast(_viewport->y() + _viewport->height()), - GL_COLOR_BUFFER_BIT, GL_NEAREST); + blitMask, GL_NEAREST); } } - // reset the read and draw buffers? will comment out for now with the assumption that - // the buffers will be set explicitly when needed elsewhere. - // glReadBuffer(GL_COLOR_ATTACHMENT0_EXT); - // glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT); + // VRV_PATCH END } -#endif - + apply_read_fbo = true; read_fbo = _resolveFbo.get(); From 6831e072e4dc1fd83d97ffc46f6e859f9d5c4501 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 11 Nov 2020 14:32:28 +0000 Subject: [PATCH 03/40] Moved osgmultiviewpaging to osgcustompager to avoid name confusion with new multiview extension example --- examples/CMakeLists.txt | 2 +- examples/osgcustompager/CMakeLists.txt | 4 ++++ .../osgcustompager.cpp} | 0 examples/osgmultiviewpaging/CMakeLists.txt | 4 ---- src/osg/CMakeLists.txt | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) create mode 100644 examples/osgcustompager/CMakeLists.txt rename examples/{osgmultiviewpaging/osgmultiviewpaging.cpp => osgcustompager/osgcustompager.cpp} (100%) delete mode 100644 examples/osgmultiviewpaging/CMakeLists.txt diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 788e5075f5c..0cbfa9b7ddd 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -39,6 +39,7 @@ IF(DYNAMIC_OPENSCENEGRAPH) ADD_SUBDIRECTORY(osgcubemap) ADD_SUBDIRECTORY(osgdeferred) ADD_SUBDIRECTORY(osgcluster) + ADD_SUBDIRECTORY(osgcustompager) ADD_SUBDIRECTORY(osgdatabaserevisions) ADD_SUBDIRECTORY(osgdepthpartition) ADD_SUBDIRECTORY(osgdepthpeeling) @@ -76,7 +77,6 @@ IF(DYNAMIC_OPENSCENEGRAPH) ADD_SUBDIRECTORY(osgmultitexture) ADD_SUBDIRECTORY(osgmultitexturecontrol) ADD_SUBDIRECTORY(osgmultitouch) - ADD_SUBDIRECTORY(osgmultiviewpaging) ADD_SUBDIRECTORY(osgobjectcache) ADD_SUBDIRECTORY(osgoccluder) ADD_SUBDIRECTORY(osgocclusionquery) diff --git a/examples/osgcustompager/CMakeLists.txt b/examples/osgcustompager/CMakeLists.txt new file mode 100644 index 00000000000..7ba22752510 --- /dev/null +++ b/examples/osgcustompager/CMakeLists.txt @@ -0,0 +1,4 @@ +SET(TARGET_SRC osgcustompager.cpp ) + +#### end var setup ### +SETUP_EXAMPLE(osgcustompager) diff --git a/examples/osgmultiviewpaging/osgmultiviewpaging.cpp b/examples/osgcustompager/osgcustompager.cpp similarity index 100% rename from examples/osgmultiviewpaging/osgmultiviewpaging.cpp rename to examples/osgcustompager/osgcustompager.cpp diff --git a/examples/osgmultiviewpaging/CMakeLists.txt b/examples/osgmultiviewpaging/CMakeLists.txt deleted file mode 100644 index d8d1a8514f0..00000000000 --- a/examples/osgmultiviewpaging/CMakeLists.txt +++ /dev/null @@ -1,4 +0,0 @@ -SET(TARGET_SRC osgmultiviewpaging.cpp ) - -#### end var setup ### -SETUP_EXAMPLE(osgmultiviewpaging) diff --git a/src/osg/CMakeLists.txt b/src/osg/CMakeLists.txt index 31b88cfe02c..9deed7af932 100644 --- a/src/osg/CMakeLists.txt +++ b/src/osg/CMakeLists.txt @@ -386,7 +386,7 @@ SET(TARGET_SRC TexMat.cpp Texture1D.cpp Texture2DArray.cpp - Texture2DMultisampleArray.cpp + Texture2DMultisampleArray.cpp Texture2D.cpp Texture2DMultisample.cpp Texture3D.cpp From d6ce7550e318c36e0608be1f6f906c2d2e2e4ab6 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 12 Nov 2020 12:22:40 +0000 Subject: [PATCH 04/40] Added standard side by side stereo config to use as a comparison to multviewOVR implementation --- examples/CMakeLists.txt | 1 + examples/osgmultiviewOVR/StandardStereo.cpp | 267 ++++++++++++++++++++ examples/osgmultiviewOVR/StandardStereo.h | 45 ++++ examples/osgmultiviewOVR/standard.frag | 9 + examples/osgmultiviewOVR/standard.vert | 7 + 5 files changed, 329 insertions(+) create mode 100644 examples/osgmultiviewOVR/StandardStereo.cpp create mode 100644 examples/osgmultiviewOVR/StandardStereo.h create mode 100644 examples/osgmultiviewOVR/standard.frag create mode 100644 examples/osgmultiviewOVR/standard.vert diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 0cbfa9b7ddd..d499d05b6c7 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -77,6 +77,7 @@ IF(DYNAMIC_OPENSCENEGRAPH) ADD_SUBDIRECTORY(osgmultitexture) ADD_SUBDIRECTORY(osgmultitexturecontrol) ADD_SUBDIRECTORY(osgmultitouch) + ADD_SUBDIRECTORY(osgmultiviewOVR) ADD_SUBDIRECTORY(osgobjectcache) ADD_SUBDIRECTORY(osgoccluder) ADD_SUBDIRECTORY(osgocclusionquery) diff --git a/examples/osgmultiviewOVR/StandardStereo.cpp b/examples/osgmultiviewOVR/StandardStereo.cpp new file mode 100644 index 00000000000..c7acff347d8 --- /dev/null +++ b/examples/osgmultiviewOVR/StandardStereo.cpp @@ -0,0 +1,267 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield + * + * 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 + * (at your option) any later version. The full license is in LICENSE file + * included with this distribution, and on the openscenegraph.org website. + * + * This library 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. See the + * OpenSceneGraph Public License for more details. +*/ + +#include "StandardStereo.h" + +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +using namespace osgViewer; + +osg::ref_ptr StandardStereo::createStereoMesh(const osg::Vec3& origin, const osg::Vec3& widthVector, const osg::Vec3& heightVector) const +{ + osg::Vec3d center(0.0,0.0,0.0); + osg::Vec3d eye(0.0,0.0,0.0); + + // create the quad to visualize. + osg::Geometry* geometry = new osg::Geometry(); + + geometry->setSupportsDisplayList(false); + + osg::DrawElementsUShort* elements = new osg::DrawElementsUShort(osg::PrimitiveSet::TRIANGLES); + osg::Vec3Array* vertices = new osg::Vec3Array; + osg::Vec3Array* texcoords = new osg::Vec3Array; + osg::Vec4Array* colors = new osg::Vec4Array; + colors->push_back(osg::Vec4(1.0, 1.0, 0.0, 1.0)); + + // left hand side + vertices->push_back(origin); texcoords->push_back(osg::Vec3(0.0f, 0.0f, 0.0f)); + vertices->push_back(origin + widthVector*0.5f); texcoords->push_back(osg::Vec3(1.0f, 0.0f, 0.0f)); + vertices->push_back(origin + widthVector*0.5f +heightVector); texcoords->push_back(osg::Vec3(1.0f, 1.0f, 0.0f)); + vertices->push_back(origin + heightVector); texcoords->push_back(osg::Vec3(0.0f, 1.0f, 0.0f)); + + elements->push_back(0); + elements->push_back(1); + elements->push_back(2); + elements->push_back(2); + elements->push_back(3); + elements->push_back(0); + + // right hand side + vertices->push_back(origin + widthVector*0.5f); texcoords->push_back(osg::Vec3(0.0f, 0.0f, 1.0f)); + vertices->push_back(origin + widthVector); texcoords->push_back(osg::Vec3(1.0f, 0.0f, 1.0f)); + vertices->push_back(origin + widthVector +heightVector); texcoords->push_back(osg::Vec3(1.0f, 1.0f, 1.0f)); + vertices->push_back(origin + widthVector*0.5f + heightVector); texcoords->push_back(osg::Vec3(0.0f, 1.0f, 1.0f)); + + elements->push_back(4); + elements->push_back(5); + elements->push_back(6); + elements->push_back(6); + elements->push_back(7); + elements->push_back(4); + + geometry->setVertexArray(vertices); + geometry->setColorArray(colors, osg::Array::BIND_OVERALL); + geometry->setTexCoordArray(0, texcoords); + geometry->addPrimitiveSet(elements); + + return geometry; +} + +void StandardStereo::configure(osgViewer::View& view) const +{ + osg::GraphicsContext::WindowingSystemInterface* wsi = osg::GraphicsContext::getWindowingSystemInterface(); + if (!wsi) + { + OSG_NOTICE<<"Error, no WindowSystemInterface available, cannot create windows."<getScreenResolution(si, width, height); + + osg::ref_ptr traits = new osg::GraphicsContext::Traits; + traits->hostName = si.hostName; + traits->displayNum = si.displayNum; + traits->screenNum = si.screenNum; + traits->x = 0; + traits->y = 0; + traits->width = width; + traits->height = height; + traits->windowDecoration = false; + traits->doubleBuffer = true; + traits->sharedContext = 0; + + osg::ref_ptr gc = osg::GraphicsContext::createGraphicsContext(traits.get()); + if (!gc) + { + OSG_NOTICE<<"GraphicsWindow has not been created successfully."<setTextureSize(tex_width, tex_height, 2); + texture->setInternalFormat(GL_RGBA); + texture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR); + texture->setFilter(osg::Texture::MAG_FILTER,osg::Texture::LINEAR); + texture->setWrap(osg::Texture::WRAP_S,osg::Texture::CLAMP_TO_EDGE); + texture->setWrap(osg::Texture::WRAP_T,osg::Texture::CLAMP_TO_EDGE); + texture->setWrap(osg::Texture::WRAP_R,osg::Texture::CLAMP_TO_EDGE); + +#if 0 + osg::Camera::RenderTargetImplementation renderTargetImplementation = osg::Camera::SEPERATE_WINDOW; + GLenum buffer = GL_FRONT; +#else + osg::Camera::RenderTargetImplementation renderTargetImplementation = osg::Camera::FRAME_BUFFER_OBJECT; + GLenum buffer = GL_FRONT; +#endif + + // left eye + { + osg::ref_ptr camera = new osg::Camera; + camera->setName("Left eye camera"); + camera->setGraphicsContext(gc.get()); + camera->setViewport(new osg::Viewport(0,0,camera_width, camera_height)); + camera->setDrawBuffer(buffer); + camera->setReadBuffer(buffer); + camera->setAllowEventFocus(false); + + // tell the camera to use OpenGL frame buffer object where supported. + camera->setRenderTargetImplementation(renderTargetImplementation); + + // attach the texture and use it as the color buffer. + camera->attach(osg::Camera::COLOR_BUFFER, texture, 0, 0); + + // set up the projection and view matrices + osg::Matrixd projectionOffset = displaySettings->computeLeftEyeProjectionImplementation(osg::Matrixd()); + osg::Matrixd viewOffset = displaySettings->computeLeftEyeViewImplementation(osg::Matrixd()); + + std::cout<<"left projectionOffset = "<setGraphicsContext(gc.get()); + camera->setViewport(new osg::Viewport(0,0,camera_width, camera_height)); + camera->setDrawBuffer(buffer); + camera->setReadBuffer(buffer); + camera->setAllowEventFocus(false); + camera->setClearColor(osg::Vec4(0.2f, 0.2f, 0.2f, 1.0f)); + + // tell the camera to use OpenGL frame buffer object where supported. + camera->setRenderTargetImplementation(renderTargetImplementation); + + // attach the texture and use it as the color buffer. + camera->attach(osg::Camera::COLOR_BUFFER, texture, 0, 1); + + // set up the projection and view matrices + osg::Matrixd projectionOffset = displaySettings->computeRightEyeProjectionImplementation(osg::Matrixd()); + osg::Matrixd viewOffset = displaySettings->computeRightEyeViewImplementation(osg::Matrixd()); + + std::cout<<"right projectionOffset = "< vertexShader = osgDB::readRefShaderFile( osg::Shader::VERTEX, vsFileName) ; + if (vertexShader.get()) program->addShader( vertexShader.get() ); + + osg::ref_ptr fragmentShader = osgDB::readRefShaderFile( osg::Shader::FRAGMENT, fsFileName) ; + if (fragmentShader.get()) program->addShader( fragmentShader.get() ); + } + + osg::ref_ptr camera = new osg::Camera; + camera->setGraphicsContext(gc.get()); + camera->setClearMask(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT ); + camera->setClearColor( osg::Vec4(0.0,0.0,0.0,1.0) ); + camera->setViewport(new osg::Viewport(0, 0, width, height)); + + GLenum window_buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT; + camera->setDrawBuffer(window_buffer); + camera->setReadBuffer(window_buffer); + camera->setReferenceFrame(osg::Camera::ABSOLUTE_RF); + camera->setAllowEventFocus(true); + camera->setInheritanceMask(camera->getInheritanceMask() & ~osg::CullSettings::CLEAR_COLOR & ~osg::CullSettings::COMPUTE_NEAR_FAR_MODE); + //camera->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR); + + camera->setProjectionMatrixAsOrtho2D(0,width,0,height); + camera->setViewMatrix(osg::Matrix::identity()); + + // add subgraph to render + camera->addChild(mesh.get()); + + camera->setName("DistortionCorrectionCamera"); + + osgDB::writeNodeFile(*mesh, "mesh.osgt"); + + view.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd(), false); + } + + view.getCamera()->setNearFarRatio(0.0001f); + + if (view.getLightingMode()==osg::View::HEADLIGHT) + { + // set a local light source for headlight to ensure that lighting is consistent across sides of cube. + view.getLight()->setPosition(osg::Vec4(0.0f,0.0f,0.0f,1.0f)); + } +} diff --git a/examples/osgmultiviewOVR/StandardStereo.h b/examples/osgmultiviewOVR/StandardStereo.h new file mode 100644 index 00000000000..db187abcfd6 --- /dev/null +++ b/examples/osgmultiviewOVR/StandardStereo.h @@ -0,0 +1,45 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield + * + * 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 + * (at your option) any later version. The full license is in LICENSE file + * included with this distribution, and on the openscenegraph.org website. + * + * This library 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. See the + * OpenSceneGraph Public License for more details. +*/ + +#ifndef OSGVIEWER_StandardStereo +#define OSGVIEWER_StandardStereo 1 + +#include + +/** spherical display using 6 slave cameras rendering the 6 sides of a cube map, and 7th camera doing distortion correction to present on a spherical display.*/ +class StandardStereo : public osgViewer::ViewConfig +{ + public: + + StandardStereo(unsigned int screenNum=0): + _screenNum(screenNum) {} + + StandardStereo(const StandardStereo& rhs, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY): + ViewConfig(rhs,copyop), + _screenNum(rhs._screenNum) {} + + META_Object(osgViewer,StandardStereo); + + virtual void configure(osgViewer::View& view) const; + + void setScreenNum(unsigned int n) { _screenNum = n; } + unsigned int getScreenNum() const { return _screenNum; } + + protected: + + osg::ref_ptr createStereoMesh(const osg::Vec3& origin, const osg::Vec3& widthVector, const osg::Vec3& heightVector) const; + + unsigned int _screenNum; +}; + +#endif diff --git a/examples/osgmultiviewOVR/standard.frag b/examples/osgmultiviewOVR/standard.frag new file mode 100644 index 00000000000..d8e1924fd24 --- /dev/null +++ b/examples/osgmultiviewOVR/standard.frag @@ -0,0 +1,9 @@ +#extension GL_EXT_texture_array : enable + +uniform sampler2DArray texture; +varying vec3 texcoord; + +void main(void) +{ + gl_FragColor = texture2DArray( texture, texcoord.xyz); +} diff --git a/examples/osgmultiviewOVR/standard.vert b/examples/osgmultiviewOVR/standard.vert new file mode 100644 index 00000000000..8b1e0892a72 --- /dev/null +++ b/examples/osgmultiviewOVR/standard.vert @@ -0,0 +1,7 @@ +varying vec3 texcoord; + +void main(void) +{ + texcoord = gl_MultiTexCoord0.xyz; + gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; +} From c1b3a30e7c24af092c4991a1e03462ac92f322e9 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 12 Nov 2020 12:36:24 +0000 Subject: [PATCH 05/40] Copied StandardStereo class renamed to MultivewOVR to use as base of multiviewOVR work. --- examples/osgmultiviewOVR/MultiviewOVR.cpp | 259 ++++++++++++++++++++ examples/osgmultiviewOVR/MultiviewOVR.h | 45 ++++ examples/osgmultiviewOVR/StandardStereo.cpp | 8 - examples/osgmultiviewOVR/multiviewOVR.frag | 9 + examples/osgmultiviewOVR/multiviewOVR.vert | 7 + 5 files changed, 320 insertions(+), 8 deletions(-) create mode 100644 examples/osgmultiviewOVR/MultiviewOVR.cpp create mode 100644 examples/osgmultiviewOVR/MultiviewOVR.h create mode 100644 examples/osgmultiviewOVR/multiviewOVR.frag create mode 100644 examples/osgmultiviewOVR/multiviewOVR.vert diff --git a/examples/osgmultiviewOVR/MultiviewOVR.cpp b/examples/osgmultiviewOVR/MultiviewOVR.cpp new file mode 100644 index 00000000000..e814adfda3a --- /dev/null +++ b/examples/osgmultiviewOVR/MultiviewOVR.cpp @@ -0,0 +1,259 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield + * + * 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 + * (at your option) any later version. The full license is in LICENSE file + * included with this distribution, and on the openscenegraph.org website. + * + * This library 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. See the + * OpenSceneGraph Public License for more details. +*/ + +#include "MultiviewOVR.h" + +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +using namespace osgViewer; + +osg::ref_ptr MultiviewOVR::createStereoMesh(const osg::Vec3& origin, const osg::Vec3& widthVector, const osg::Vec3& heightVector) const +{ + osg::Vec3d center(0.0,0.0,0.0); + osg::Vec3d eye(0.0,0.0,0.0); + + // create the quad to visualize. + osg::Geometry* geometry = new osg::Geometry(); + + geometry->setSupportsDisplayList(false); + + osg::DrawElementsUShort* elements = new osg::DrawElementsUShort(osg::PrimitiveSet::TRIANGLES); + osg::Vec3Array* vertices = new osg::Vec3Array; + osg::Vec3Array* texcoords = new osg::Vec3Array; + osg::Vec4Array* colors = new osg::Vec4Array; + colors->push_back(osg::Vec4(1.0, 1.0, 0.0, 1.0)); + + // left hand side + vertices->push_back(origin); texcoords->push_back(osg::Vec3(0.0f, 0.0f, 0.0f)); + vertices->push_back(origin + widthVector*0.5f); texcoords->push_back(osg::Vec3(1.0f, 0.0f, 0.0f)); + vertices->push_back(origin + widthVector*0.5f +heightVector); texcoords->push_back(osg::Vec3(1.0f, 1.0f, 0.0f)); + vertices->push_back(origin + heightVector); texcoords->push_back(osg::Vec3(0.0f, 1.0f, 0.0f)); + + elements->push_back(0); + elements->push_back(1); + elements->push_back(2); + elements->push_back(2); + elements->push_back(3); + elements->push_back(0); + + // right hand side + vertices->push_back(origin + widthVector*0.5f); texcoords->push_back(osg::Vec3(0.0f, 0.0f, 1.0f)); + vertices->push_back(origin + widthVector); texcoords->push_back(osg::Vec3(1.0f, 0.0f, 1.0f)); + vertices->push_back(origin + widthVector +heightVector); texcoords->push_back(osg::Vec3(1.0f, 1.0f, 1.0f)); + vertices->push_back(origin + widthVector*0.5f + heightVector); texcoords->push_back(osg::Vec3(0.0f, 1.0f, 1.0f)); + + elements->push_back(4); + elements->push_back(5); + elements->push_back(6); + elements->push_back(6); + elements->push_back(7); + elements->push_back(4); + + geometry->setVertexArray(vertices); + geometry->setColorArray(colors, osg::Array::BIND_OVERALL); + geometry->setTexCoordArray(0, texcoords); + geometry->addPrimitiveSet(elements); + + return geometry; +} + +void MultiviewOVR::configure(osgViewer::View& view) const +{ + osg::GraphicsContext::WindowingSystemInterface* wsi = osg::GraphicsContext::getWindowingSystemInterface(); + if (!wsi) + { + OSG_NOTICE<<"Error, no WindowSystemInterface available, cannot create windows."<getScreenResolution(si, width, height); + + osg::ref_ptr traits = new osg::GraphicsContext::Traits; + traits->hostName = si.hostName; + traits->displayNum = si.displayNum; + traits->screenNum = si.screenNum; + traits->x = 0; + traits->y = 0; + traits->width = width; + traits->height = height; + traits->windowDecoration = false; + traits->doubleBuffer = true; + traits->sharedContext = 0; + + osg::ref_ptr gc = osg::GraphicsContext::createGraphicsContext(traits.get()); + if (!gc) + { + OSG_NOTICE<<"GraphicsWindow has not been created successfully."<setTextureSize(tex_width, tex_height, 2); + texture->setInternalFormat(GL_RGBA); + texture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR); + texture->setFilter(osg::Texture::MAG_FILTER,osg::Texture::LINEAR); + texture->setWrap(osg::Texture::WRAP_S,osg::Texture::CLAMP_TO_EDGE); + texture->setWrap(osg::Texture::WRAP_T,osg::Texture::CLAMP_TO_EDGE); + texture->setWrap(osg::Texture::WRAP_R,osg::Texture::CLAMP_TO_EDGE); + +#if 0 + osg::Camera::RenderTargetImplementation renderTargetImplementation = osg::Camera::SEPERATE_WINDOW; + GLenum buffer = GL_FRONT; +#else + osg::Camera::RenderTargetImplementation renderTargetImplementation = osg::Camera::FRAME_BUFFER_OBJECT; + GLenum buffer = GL_FRONT; +#endif + + // left eye + { + osg::ref_ptr camera = new osg::Camera; + camera->setName("Left eye camera"); + camera->setGraphicsContext(gc.get()); + camera->setViewport(new osg::Viewport(0,0,camera_width, camera_height)); + camera->setDrawBuffer(buffer); + camera->setReadBuffer(buffer); + camera->setAllowEventFocus(false); + + // tell the camera to use OpenGL frame buffer object where supported. + camera->setRenderTargetImplementation(renderTargetImplementation); + + // attach the texture and use it as the color buffer. + camera->attach(osg::Camera::COLOR_BUFFER, texture, 0, 0); + + // set up the projection and view matrices + osg::Matrixd projectionOffset = displaySettings->computeLeftEyeProjectionImplementation(osg::Matrixd()); + osg::Matrixd viewOffset = displaySettings->computeLeftEyeViewImplementation(osg::Matrixd()); + + view.addSlave(camera.get(), projectionOffset, viewOffset); + } + + // right eye + { + osg::ref_ptr camera = new osg::Camera; + camera->setName("Right eyecamera"); + camera->setGraphicsContext(gc.get()); + camera->setViewport(new osg::Viewport(0,0,camera_width, camera_height)); + camera->setDrawBuffer(buffer); + camera->setReadBuffer(buffer); + camera->setAllowEventFocus(false); + camera->setClearColor(osg::Vec4(0.2f, 0.2f, 0.5f, 1.0f)); + + // tell the camera to use OpenGL frame buffer object where supported. + camera->setRenderTargetImplementation(renderTargetImplementation); + + // attach the texture and use it as the color buffer. + camera->attach(osg::Camera::COLOR_BUFFER, texture, 0, 1); + + // set up the projection and view matrices + osg::Matrixd projectionOffset = displaySettings->computeRightEyeProjectionImplementation(osg::Matrixd()); + osg::Matrixd viewOffset = displaySettings->computeRightEyeViewImplementation(osg::Matrixd()); + + view.addSlave(camera.get(), projectionOffset, viewOffset); + } + + view.getCamera()->setProjectionMatrixAsPerspective(90.0f, 1.0, 1, 1000.0); + + // distortion correction set up. + { + osg::ref_ptr mesh = createStereoMesh(osg::Vec3(0.0f,0.0f,0.0f), osg::Vec3(width,0.0f,0.0f), osg::Vec3(0.0f,height,0.0f)); + + // new we need to add the texture to the mesh, we do so by creating a + // StateSet to contain the Texture StateAttribute. + osg::StateSet* stateset = mesh->getOrCreateStateSet(); + stateset->setTextureAttribute(0, texture, osg::StateAttribute::ON); + stateset->setMode(GL_LIGHTING, osg::StateAttribute::OFF); + + { + osg::ref_ptr program = new osg::Program(); + stateset->setAttribute(program.get(), osg::StateAttribute::ON); + + std::string vsFileName("multiviewOVR.vert"); + std::string fsFileName("multiviewOVR.frag"); + + osg::ref_ptr vertexShader = osgDB::readRefShaderFile( osg::Shader::VERTEX, vsFileName) ; + if (vertexShader.get()) program->addShader( vertexShader.get() ); + + osg::ref_ptr fragmentShader = osgDB::readRefShaderFile( osg::Shader::FRAGMENT, fsFileName) ; + if (fragmentShader.get()) program->addShader( fragmentShader.get() ); + } + + osg::ref_ptr camera = new osg::Camera; + camera->setGraphicsContext(gc.get()); + camera->setClearMask(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT ); + camera->setClearColor( osg::Vec4(0.0,0.0,0.0,1.0) ); + camera->setViewport(new osg::Viewport(0, 0, width, height)); + + GLenum window_buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT; + camera->setDrawBuffer(window_buffer); + camera->setReadBuffer(window_buffer); + camera->setReferenceFrame(osg::Camera::ABSOLUTE_RF); + camera->setAllowEventFocus(true); + camera->setInheritanceMask(camera->getInheritanceMask() & ~osg::CullSettings::CLEAR_COLOR & ~osg::CullSettings::COMPUTE_NEAR_FAR_MODE); + //camera->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR); + + camera->setProjectionMatrixAsOrtho2D(0,width,0,height); + camera->setViewMatrix(osg::Matrix::identity()); + + // add subgraph to render + camera->addChild(mesh.get()); + + camera->setName("DistortionCorrectionCamera"); + + osgDB::writeNodeFile(*mesh, "mesh.osgt"); + + view.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd(), false); + } + + view.getCamera()->setNearFarRatio(0.0001f); + + if (view.getLightingMode()==osg::View::HEADLIGHT) + { + // set a local light source for headlight to ensure that lighting is consistent across sides of cube. + view.getLight()->setPosition(osg::Vec4(0.0f,0.0f,0.0f,1.0f)); + } +} diff --git a/examples/osgmultiviewOVR/MultiviewOVR.h b/examples/osgmultiviewOVR/MultiviewOVR.h new file mode 100644 index 00000000000..04a71f500fc --- /dev/null +++ b/examples/osgmultiviewOVR/MultiviewOVR.h @@ -0,0 +1,45 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield + * + * 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 + * (at your option) any later version. The full license is in LICENSE file + * included with this distribution, and on the openscenegraph.org website. + * + * This library 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. See the + * OpenSceneGraph Public License for more details. +*/ + +#ifndef OSGVIEWER_MultiviewOVR +#define OSGVIEWER_MultiviewOVR 1 + +#include + +/** spherical display using 6 slave cameras rendering the 6 sides of a cube map, and 7th camera doing distortion correction to present on a spherical display.*/ +class MultiviewOVR : public osgViewer::ViewConfig +{ + public: + + MultiviewOVR(unsigned int screenNum=0): + _screenNum(screenNum) {} + + MultiviewOVR(const MultiviewOVR& rhs, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY): + ViewConfig(rhs,copyop), + _screenNum(rhs._screenNum) {} + + META_Object(osgViewer,MultiviewOVR); + + virtual void configure(osgViewer::View& view) const; + + void setScreenNum(unsigned int n) { _screenNum = n; } + unsigned int getScreenNum() const { return _screenNum; } + + protected: + + osg::ref_ptr createStereoMesh(const osg::Vec3& origin, const osg::Vec3& widthVector, const osg::Vec3& heightVector) const; + + unsigned int _screenNum; +}; + +#endif diff --git a/examples/osgmultiviewOVR/StandardStereo.cpp b/examples/osgmultiviewOVR/StandardStereo.cpp index c7acff347d8..b620ffc53af 100644 --- a/examples/osgmultiviewOVR/StandardStereo.cpp +++ b/examples/osgmultiviewOVR/StandardStereo.cpp @@ -169,10 +169,6 @@ void StandardStereo::configure(osgViewer::View& view) const osg::Matrixd projectionOffset = displaySettings->computeLeftEyeProjectionImplementation(osg::Matrixd()); osg::Matrixd viewOffset = displaySettings->computeLeftEyeViewImplementation(osg::Matrixd()); - std::cout<<"left projectionOffset = "< Date: Thu, 12 Nov 2020 12:40:22 +0000 Subject: [PATCH 06/40] fix for typo in windows branch of delimiter definition --- src/osgDB/FileUtils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/osgDB/FileUtils.cpp b/src/osgDB/FileUtils.cpp index 2328e5f87bf..3c61dae629d 100644 --- a/src/osgDB/FileUtils.cpp +++ b/src/osgDB/FileUtils.cpp @@ -275,7 +275,7 @@ bool osgDB::setCurrentWorkingDirectory( const std::string &newCurrentWorkingDire void osgDB::convertStringPathIntoFilePathList(const std::string& paths,FilePathList& filepath) { #if defined(_WIN32) && !defined(__CYGWIN__) - char delimitor = ';'; + char delimiter = ';'; #else char delimiter = ':'; #endif From efe358048b048b4b184ab5da7cbaf051ed68d413 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 12 Nov 2020 15:13:29 +0000 Subject: [PATCH 07/40] Updated shaders for GL_OVR_multiview2 usage --- examples/osgmultiviewOVR/CMakeLists.txt | 8 +++ examples/osgmultiviewOVR/MultiviewOVR.cpp | 54 +++++++++---------- examples/osgmultiviewOVR/multiviewOVR.frag | 11 ++-- examples/osgmultiviewOVR/multiviewOVR.vert | 16 ++++-- examples/osgmultiviewOVR/osgmultiviewOVR.cpp | 57 ++++++++++++++++++++ 5 files changed, 111 insertions(+), 35 deletions(-) create mode 100644 examples/osgmultiviewOVR/CMakeLists.txt create mode 100644 examples/osgmultiviewOVR/osgmultiviewOVR.cpp diff --git a/examples/osgmultiviewOVR/CMakeLists.txt b/examples/osgmultiviewOVR/CMakeLists.txt new file mode 100644 index 00000000000..6d26ddb6031 --- /dev/null +++ b/examples/osgmultiviewOVR/CMakeLists.txt @@ -0,0 +1,8 @@ +SET(TARGET_SRC + MultiviewOVR.cpp + StandardStereo.cpp + osgmultiviewOVR.cpp +) + +#### end var setup ### +SETUP_EXAMPLE(osgmultiviewOVR) diff --git a/examples/osgmultiviewOVR/MultiviewOVR.cpp b/examples/osgmultiviewOVR/MultiviewOVR.cpp index e814adfda3a..0c7a52a0eb6 100644 --- a/examples/osgmultiviewOVR/MultiviewOVR.cpp +++ b/examples/osgmultiviewOVR/MultiviewOVR.cpp @@ -149,10 +149,14 @@ void MultiviewOVR::configure(osgViewer::View& view) const GLenum buffer = GL_FRONT; #endif - // left eye + // left/right eye multiviewOVR camera { + // GL_OVR_multiview2 extensions requires modern versions of GLSL without fixed function fallback + gc->getState()->setUseModelViewAndProjectionUniforms(true); + gc->getState()->setUseVertexAttributeAliasing(true); + osg::ref_ptr camera = new osg::Camera; - camera->setName("Left eye camera"); + camera->setName("multview eye camera"); camera->setGraphicsContext(gc.get()); camera->setViewport(new osg::Viewport(0,0,camera_width, camera_height)); camera->setDrawBuffer(buffer); @@ -162,38 +166,32 @@ void MultiviewOVR::configure(osgViewer::View& view) const // tell the camera to use OpenGL frame buffer object where supported. camera->setRenderTargetImplementation(renderTargetImplementation); - // attach the texture and use it as the color buffer. - camera->attach(osg::Camera::COLOR_BUFFER, texture, 0, 0); + // attach the texture and use it as the color buffer, specify that the face is controlled by the multiview extension + camera->attach(osg::Camera::COLOR_BUFFER, texture, 0, osg::Camera::FACE_CONTROLLED_BY_MULTIVIEW_SHADER); // set up the projection and view matrices - osg::Matrixd projectionOffset = displaySettings->computeLeftEyeProjectionImplementation(osg::Matrixd()); - osg::Matrixd viewOffset = displaySettings->computeLeftEyeViewImplementation(osg::Matrixd()); + osg::Matrixd left_projectionOffset = displaySettings->computeLeftEyeProjectionImplementation(osg::Matrixd()); + osg::Matrixd left_viewOffset = displaySettings->computeLeftEyeViewImplementation(osg::Matrixd()); + osg::Matrixd right_projectionOffset = displaySettings->computeRightEyeProjectionImplementation(osg::Matrixd()); + osg::Matrixd right_viewOffset = displaySettings->computeRightEyeViewImplementation(osg::Matrixd()); - view.addSlave(camera.get(), projectionOffset, viewOffset); - } + view.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd()); - // right eye - { - osg::ref_ptr camera = new osg::Camera; - camera->setName("Right eyecamera"); - camera->setGraphicsContext(gc.get()); - camera->setViewport(new osg::Viewport(0,0,camera_width, camera_height)); - camera->setDrawBuffer(buffer); - camera->setReadBuffer(buffer); - camera->setAllowEventFocus(false); - camera->setClearColor(osg::Vec4(0.2f, 0.2f, 0.5f, 1.0f)); + osg::StateSet* stateset = camera->getOrCreateStateSet(); + { + osg::ref_ptr program = new osg::Program(); + stateset->setAttribute(program.get(), osg::StateAttribute::ON); - // tell the camera to use OpenGL frame buffer object where supported. - camera->setRenderTargetImplementation(renderTargetImplementation); + std::string vsFileName("multiviewOVR.vert"); + std::string fsFileName("multiviewOVR.frag"); - // attach the texture and use it as the color buffer. - camera->attach(osg::Camera::COLOR_BUFFER, texture, 0, 1); + osg::ref_ptr vertexShader = osgDB::readRefShaderFile( osg::Shader::VERTEX, vsFileName) ; + if (vertexShader.get()) program->addShader( vertexShader.get() ); - // set up the projection and view matrices - osg::Matrixd projectionOffset = displaySettings->computeRightEyeProjectionImplementation(osg::Matrixd()); - osg::Matrixd viewOffset = displaySettings->computeRightEyeViewImplementation(osg::Matrixd()); + osg::ref_ptr fragmentShader = osgDB::readRefShaderFile( osg::Shader::FRAGMENT, fsFileName) ; + if (fragmentShader.get()) program->addShader( fragmentShader.get() ); + } - view.addSlave(camera.get(), projectionOffset, viewOffset); } view.getCamera()->setProjectionMatrixAsPerspective(90.0f, 1.0, 1, 1000.0); @@ -212,8 +210,8 @@ void MultiviewOVR::configure(osgViewer::View& view) const osg::ref_ptr program = new osg::Program(); stateset->setAttribute(program.get(), osg::StateAttribute::ON); - std::string vsFileName("multiviewOVR.vert"); - std::string fsFileName("multiviewOVR.frag"); + std::string vsFileName("standard.vert"); + std::string fsFileName("standard.frag"); osg::ref_ptr vertexShader = osgDB::readRefShaderFile( osg::Shader::VERTEX, vsFileName) ; if (vertexShader.get()) program->addShader( vertexShader.get() ); diff --git a/examples/osgmultiviewOVR/multiviewOVR.frag b/examples/osgmultiviewOVR/multiviewOVR.frag index d8e1924fd24..19b4e006df4 100644 --- a/examples/osgmultiviewOVR/multiviewOVR.frag +++ b/examples/osgmultiviewOVR/multiviewOVR.frag @@ -1,9 +1,12 @@ -#extension GL_EXT_texture_array : enable +#version 330 -uniform sampler2DArray texture; -varying vec3 texcoord; +uniform sampler2D texture; + +in vec2 texcoord; + +out vec4 fragColor; void main(void) { - gl_FragColor = texture2DArray( texture, texcoord.xyz); + fragColor = texture2D( texture, texcoord.xy); } diff --git a/examples/osgmultiviewOVR/multiviewOVR.vert b/examples/osgmultiviewOVR/multiviewOVR.vert index 8b1e0892a72..2951437497b 100644 --- a/examples/osgmultiviewOVR/multiviewOVR.vert +++ b/examples/osgmultiviewOVR/multiviewOVR.vert @@ -1,7 +1,17 @@ -varying vec3 texcoord; +#version 330 +#extension GL_OVR_multiview2 : enable + +layout(num_views = 2) in; + +uniform mat4 osg_ModelViewProjectionMatrix; + +in vec4 osg_Vertex; +in vec4 osg_MultiTexCoord0; + +out vec2 texcoord; void main(void) { - texcoord = gl_MultiTexCoord0.xyz; - gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; + texcoord = osg_MultiTexCoord0.xy; + gl_Position = osg_ModelViewProjectionMatrix * osg_Vertex; } diff --git a/examples/osgmultiviewOVR/osgmultiviewOVR.cpp b/examples/osgmultiviewOVR/osgmultiviewOVR.cpp new file mode 100644 index 00000000000..ab414aa3411 --- /dev/null +++ b/examples/osgmultiviewOVR/osgmultiviewOVR.cpp @@ -0,0 +1,57 @@ +// This is public domain software and comes with +// absolutely no warranty. Use of public domain software +// may vary between counties, but in general you are free +// to use and distribute this software for any purpose. + + +// Example: OSG using an OpenGL 3.1 context. +// The comment block at the end of the source describes building OSG +// for use with OpenGL 3.x. + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "StandardStereo.h" +#include "MultiviewOVR.h" + +int main( int argc, char** argv ) +{ + osg::ArgumentParser arguments(&argc, argv); + + osgViewer::Viewer viewer(arguments); + + if (arguments.read("--standard")) + { + viewer.apply(new StandardStereo()); + } + else + { + viewer.apply(new MultiviewOVR()); + } + + osg::ref_ptr root = osgDB::readRefNodeFiles( arguments ); + if (!root) + { + osg::notify( osg::FATAL ) << "Unable to load model from command line." << std::endl; + return 1; + } + + viewer.setSceneData( root ); + + viewer.addEventHandler(new osgViewer::StatsHandler()); + + + return viewer.run(); +} From 39dc12fb6b020514d498725af2f164b067d5a8dd Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 12 Nov 2020 15:49:11 +0000 Subject: [PATCH 08/40] Set up the number of views to be the size of the texture array --- src/osg/FrameBufferObject.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/osg/FrameBufferObject.cpp b/src/osg/FrameBufferObject.cpp index abe020a96f1..b53b1fdd948 100644 --- a/src/osg/FrameBufferObject.cpp +++ b/src/osg/FrameBufferObject.cpp @@ -522,7 +522,7 @@ void FrameBufferAttachment::attach(State &state, GLenum target, GLenum attachmen { if (ext->glFramebufferTextureMultiviewOVR) { - ext->glFramebufferTextureMultiviewOVR(target, attachment_point, tobj->id(), _ximpl->level, 0, 2); + ext->glFramebufferTextureMultiviewOVR(target, attachment_point, tobj->id(), _ximpl->level, 0, _ximpl->textureTarget->getTextureDepth()); } } else From c4c0577726caedb76a86d0eb8494ae8bdf24c496 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 12 Nov 2020 15:52:24 +0000 Subject: [PATCH 09/40] Selected single threading to avoid multibuffering of multiview structures --- examples/osgmultiviewOVR/osgmultiviewOVR.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/osgmultiviewOVR/osgmultiviewOVR.cpp b/examples/osgmultiviewOVR/osgmultiviewOVR.cpp index ab414aa3411..17de5a7ba35 100644 --- a/examples/osgmultiviewOVR/osgmultiviewOVR.cpp +++ b/examples/osgmultiviewOVR/osgmultiviewOVR.cpp @@ -38,6 +38,8 @@ int main( int argc, char** argv ) } else { + viewer.setThreadingModel(osgViewer::Viewer::SingleThreaded); + viewer.apply(new MultiviewOVR()); } From e93753e2619c3600361b89b3f2cf68de4f358ee7 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 12 Nov 2020 15:53:38 +0000 Subject: [PATCH 10/40] Added ovr related shader variables --- examples/osgmultiviewOVR/multiviewOVR.vert | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/examples/osgmultiviewOVR/multiviewOVR.vert b/examples/osgmultiviewOVR/multiviewOVR.vert index 2951437497b..4827aaa9358 100644 --- a/examples/osgmultiviewOVR/multiviewOVR.vert +++ b/examples/osgmultiviewOVR/multiviewOVR.vert @@ -1,10 +1,15 @@ #version 330 #extension GL_OVR_multiview2 : enable -layout(num_views = 2) in; +#define NUM_VIEWS 2 + +layout(num_views = NUM_VIEWS) in; uniform mat4 osg_ModelViewProjectionMatrix; +// uniform mat4 ovr_projectionMatrix[NUM_VIEWS]; +// uniform mat4 ovr_viewMatrix[NUM_VIEWS]; + in vec4 osg_Vertex; in vec4 osg_MultiTexCoord0; @@ -12,6 +17,10 @@ out vec2 texcoord; void main(void) { + // gl_ViewID_OVR + + mat4 mvp = osg_ModelViewProjectionMatrix; + texcoord = osg_MultiTexCoord0.xy; - gl_Position = osg_ModelViewProjectionMatrix * osg_Vertex; + gl_Position = mvp * osg_Vertex; } From 0b0457f46b3266e234799c3e0641a3d6f55501a8 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 12 Nov 2020 17:04:22 +0000 Subject: [PATCH 11/40] Added uniform arrays for left and right view and projection matrix offsets --- examples/osgmultiviewOVR/MultiviewOVR.cpp | 60 +++++++++++++++------- examples/osgmultiviewOVR/multiviewOVR.vert | 14 ++--- 2 files changed, 49 insertions(+), 25 deletions(-) diff --git a/examples/osgmultiviewOVR/MultiviewOVR.cpp b/examples/osgmultiviewOVR/MultiviewOVR.cpp index 0c7a52a0eb6..6c059a56e6c 100644 --- a/examples/osgmultiviewOVR/MultiviewOVR.cpp +++ b/examples/osgmultiviewOVR/MultiviewOVR.cpp @@ -131,17 +131,27 @@ void MultiviewOVR::configure(osgViewer::View& view) const int camera_width = tex_width; int camera_height = tex_height; - osg::Texture2DArray* texture = new osg::Texture2DArray; - - texture->setTextureSize(tex_width, tex_height, 2); - texture->setInternalFormat(GL_RGBA); - texture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR); - texture->setFilter(osg::Texture::MAG_FILTER,osg::Texture::LINEAR); - texture->setWrap(osg::Texture::WRAP_S,osg::Texture::CLAMP_TO_EDGE); - texture->setWrap(osg::Texture::WRAP_T,osg::Texture::CLAMP_TO_EDGE); - texture->setWrap(osg::Texture::WRAP_R,osg::Texture::CLAMP_TO_EDGE); - -#if 0 + osg::Texture2DArray* color_texture = new osg::Texture2DArray; + + color_texture->setTextureSize(tex_width, tex_height, 2); + color_texture->setInternalFormat(GL_RGBA); + color_texture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR); + color_texture->setFilter(osg::Texture::MAG_FILTER,osg::Texture::LINEAR); + color_texture->setWrap(osg::Texture::WRAP_S,osg::Texture::CLAMP_TO_EDGE); + color_texture->setWrap(osg::Texture::WRAP_T,osg::Texture::CLAMP_TO_EDGE); + color_texture->setWrap(osg::Texture::WRAP_R,osg::Texture::CLAMP_TO_EDGE); + + osg::Texture2DArray* depth_texture = new osg::Texture2DArray; + + depth_texture->setTextureSize(tex_width, tex_height, 2); + depth_texture->setInternalFormat(GL_DEPTH_COMPONENT24); + depth_texture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR); + depth_texture->setFilter(osg::Texture::MAG_FILTER,osg::Texture::LINEAR); + depth_texture->setWrap(osg::Texture::WRAP_S,osg::Texture::CLAMP_TO_EDGE); + depth_texture->setWrap(osg::Texture::WRAP_T,osg::Texture::CLAMP_TO_EDGE); + depth_texture->setWrap(osg::Texture::WRAP_R,osg::Texture::CLAMP_TO_EDGE); + + #if 0 osg::Camera::RenderTargetImplementation renderTargetImplementation = osg::Camera::SEPERATE_WINDOW; GLenum buffer = GL_FRONT; #else @@ -167,18 +177,32 @@ void MultiviewOVR::configure(osgViewer::View& view) const camera->setRenderTargetImplementation(renderTargetImplementation); // attach the texture and use it as the color buffer, specify that the face is controlled by the multiview extension - camera->attach(osg::Camera::COLOR_BUFFER, texture, 0, osg::Camera::FACE_CONTROLLED_BY_MULTIVIEW_SHADER); + camera->attach(osg::Camera::COLOR_BUFFER, color_texture, 0, osg::Camera::FACE_CONTROLLED_BY_MULTIVIEW_SHADER); + camera->attach(osg::Camera::DEPTH_BUFFER, depth_texture, 0, osg::Camera::FACE_CONTROLLED_BY_MULTIVIEW_SHADER); - // set up the projection and view matrices - osg::Matrixd left_projectionOffset = displaySettings->computeLeftEyeProjectionImplementation(osg::Matrixd()); - osg::Matrixd left_viewOffset = displaySettings->computeLeftEyeViewImplementation(osg::Matrixd()); - osg::Matrixd right_projectionOffset = displaySettings->computeRightEyeProjectionImplementation(osg::Matrixd()); - osg::Matrixd right_viewOffset = displaySettings->computeRightEyeViewImplementation(osg::Matrixd()); view.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd()); osg::StateSet* stateset = camera->getOrCreateStateSet(); { + // set up the projection and view matrix uniforms + osg::Matrixd left_projectionOffset = displaySettings->computeLeftEyeProjectionImplementation(osg::Matrixd()); + osg::Matrixd left_viewOffset = displaySettings->computeLeftEyeViewImplementation(osg::Matrixd()); + osg::Matrixd right_projectionOffset = displaySettings->computeRightEyeProjectionImplementation(osg::Matrixd()); + osg::Matrixd right_viewOffset = displaySettings->computeRightEyeViewImplementation(osg::Matrixd()); + + osg::ref_ptr ovr_viewMatrix_uniform = new osg::Uniform(osg::Uniform::FLOAT_MAT4, "ovr_viewMatrix", 2); + osg::ref_ptr ovr_projectionMatrix_uniform = new osg::Uniform(osg::Uniform::FLOAT_MAT4, "ovr_projectionMatrix", 2); + stateset->addUniform(ovr_viewMatrix_uniform); + stateset->addUniform(ovr_projectionMatrix_uniform); + + ovr_viewMatrix_uniform->setElement(0, left_viewOffset); + ovr_projectionMatrix_uniform->setElement(0, left_projectionOffset); + + ovr_viewMatrix_uniform->setElement(1, right_viewOffset); + ovr_projectionMatrix_uniform->setElement(1, right_projectionOffset); + + // set up the shaders osg::ref_ptr program = new osg::Program(); stateset->setAttribute(program.get(), osg::StateAttribute::ON); @@ -203,7 +227,7 @@ void MultiviewOVR::configure(osgViewer::View& view) const // new we need to add the texture to the mesh, we do so by creating a // StateSet to contain the Texture StateAttribute. osg::StateSet* stateset = mesh->getOrCreateStateSet(); - stateset->setTextureAttribute(0, texture, osg::StateAttribute::ON); + stateset->setTextureAttribute(0, color_texture, osg::StateAttribute::ON); stateset->setMode(GL_LIGHTING, osg::StateAttribute::OFF); { diff --git a/examples/osgmultiviewOVR/multiviewOVR.vert b/examples/osgmultiviewOVR/multiviewOVR.vert index 4827aaa9358..bca31aeb4fd 100644 --- a/examples/osgmultiviewOVR/multiviewOVR.vert +++ b/examples/osgmultiviewOVR/multiviewOVR.vert @@ -5,10 +5,11 @@ layout(num_views = NUM_VIEWS) in; -uniform mat4 osg_ModelViewProjectionMatrix; +uniform mat4 osg_ModelViewMatrix; +uniform mat4 osg_ProjectionMatrix; -// uniform mat4 ovr_projectionMatrix[NUM_VIEWS]; -// uniform mat4 ovr_viewMatrix[NUM_VIEWS]; +uniform mat4 ovr_projectionMatrix[NUM_VIEWS]; +uniform mat4 ovr_viewMatrix[NUM_VIEWS]; in vec4 osg_Vertex; in vec4 osg_MultiTexCoord0; @@ -17,10 +18,9 @@ out vec2 texcoord; void main(void) { - // gl_ViewID_OVR - - mat4 mvp = osg_ModelViewProjectionMatrix; + mat4 mvp = ovr_projectionMatrix[gl_ViewID_OVR] * osg_ProjectionMatrix * ovr_viewMatrix[gl_ViewID_OVR] * osg_ModelViewMatrix; texcoord = osg_MultiTexCoord0.xy; - gl_Position = mvp * osg_Vertex; + + gl_Position = mvp * osg_Vertex; } From 9e161a555928f71af73925cc00f5eac1d82fa2fe Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 12 Nov 2020 17:19:23 +0000 Subject: [PATCH 12/40] Removed the copyright notices as the code is new and doesn't require the standar OSGPL license. --- examples/osgmultiviewOVR/MultiviewOVR.cpp | 13 ------------- examples/osgmultiviewOVR/MultiviewOVR.h | 13 ------------- examples/osgmultiviewOVR/StandardStereo.cpp | 13 ------------- examples/osgmultiviewOVR/StandardStereo.h | 13 ------------- 4 files changed, 52 deletions(-) diff --git a/examples/osgmultiviewOVR/MultiviewOVR.cpp b/examples/osgmultiviewOVR/MultiviewOVR.cpp index 6c059a56e6c..4425e58ceb3 100644 --- a/examples/osgmultiviewOVR/MultiviewOVR.cpp +++ b/examples/osgmultiviewOVR/MultiviewOVR.cpp @@ -1,16 +1,3 @@ -/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield - * - * 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 - * (at your option) any later version. The full license is in LICENSE file - * included with this distribution, and on the openscenegraph.org website. - * - * This library 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. See the - * OpenSceneGraph Public License for more details. -*/ - #include "MultiviewOVR.h" #include diff --git a/examples/osgmultiviewOVR/MultiviewOVR.h b/examples/osgmultiviewOVR/MultiviewOVR.h index 04a71f500fc..59381eaae00 100644 --- a/examples/osgmultiviewOVR/MultiviewOVR.h +++ b/examples/osgmultiviewOVR/MultiviewOVR.h @@ -1,16 +1,3 @@ -/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield - * - * 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 - * (at your option) any later version. The full license is in LICENSE file - * included with this distribution, and on the openscenegraph.org website. - * - * This library 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. See the - * OpenSceneGraph Public License for more details. -*/ - #ifndef OSGVIEWER_MultiviewOVR #define OSGVIEWER_MultiviewOVR 1 diff --git a/examples/osgmultiviewOVR/StandardStereo.cpp b/examples/osgmultiviewOVR/StandardStereo.cpp index b620ffc53af..39472e92c61 100644 --- a/examples/osgmultiviewOVR/StandardStereo.cpp +++ b/examples/osgmultiviewOVR/StandardStereo.cpp @@ -1,16 +1,3 @@ -/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield - * - * 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 - * (at your option) any later version. The full license is in LICENSE file - * included with this distribution, and on the openscenegraph.org website. - * - * This library 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. See the - * OpenSceneGraph Public License for more details. -*/ - #include "StandardStereo.h" #include diff --git a/examples/osgmultiviewOVR/StandardStereo.h b/examples/osgmultiviewOVR/StandardStereo.h index db187abcfd6..11d92dd2c8a 100644 --- a/examples/osgmultiviewOVR/StandardStereo.h +++ b/examples/osgmultiviewOVR/StandardStereo.h @@ -1,16 +1,3 @@ -/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield - * - * 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 - * (at your option) any later version. The full license is in LICENSE file - * included with this distribution, and on the openscenegraph.org website. - * - * This library 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. See the - * OpenSceneGraph Public License for more details. -*/ - #ifndef OSGVIEWER_StandardStereo #define OSGVIEWER_StandardStereo 1 From b244e658d679fd2d93770dd462c2aea276e5b61f Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 12 Nov 2020 17:22:03 +0000 Subject: [PATCH 13/40] Removed debug code path --- examples/osgmultiviewOVR/MultiviewOVR.cpp | 5 ----- examples/osgmultiviewOVR/StandardStereo.cpp | 5 ----- 2 files changed, 10 deletions(-) diff --git a/examples/osgmultiviewOVR/MultiviewOVR.cpp b/examples/osgmultiviewOVR/MultiviewOVR.cpp index 4425e58ceb3..0ce91b94bbd 100644 --- a/examples/osgmultiviewOVR/MultiviewOVR.cpp +++ b/examples/osgmultiviewOVR/MultiviewOVR.cpp @@ -138,13 +138,8 @@ void MultiviewOVR::configure(osgViewer::View& view) const depth_texture->setWrap(osg::Texture::WRAP_T,osg::Texture::CLAMP_TO_EDGE); depth_texture->setWrap(osg::Texture::WRAP_R,osg::Texture::CLAMP_TO_EDGE); - #if 0 - osg::Camera::RenderTargetImplementation renderTargetImplementation = osg::Camera::SEPERATE_WINDOW; - GLenum buffer = GL_FRONT; -#else osg::Camera::RenderTargetImplementation renderTargetImplementation = osg::Camera::FRAME_BUFFER_OBJECT; GLenum buffer = GL_FRONT; -#endif // left/right eye multiviewOVR camera { diff --git a/examples/osgmultiviewOVR/StandardStereo.cpp b/examples/osgmultiviewOVR/StandardStereo.cpp index 39472e92c61..62edde6855d 100644 --- a/examples/osgmultiviewOVR/StandardStereo.cpp +++ b/examples/osgmultiviewOVR/StandardStereo.cpp @@ -128,13 +128,8 @@ void StandardStereo::configure(osgViewer::View& view) const texture->setWrap(osg::Texture::WRAP_T,osg::Texture::CLAMP_TO_EDGE); texture->setWrap(osg::Texture::WRAP_R,osg::Texture::CLAMP_TO_EDGE); -#if 0 - osg::Camera::RenderTargetImplementation renderTargetImplementation = osg::Camera::SEPERATE_WINDOW; - GLenum buffer = GL_FRONT; -#else osg::Camera::RenderTargetImplementation renderTargetImplementation = osg::Camera::FRAME_BUFFER_OBJECT; GLenum buffer = GL_FRONT; -#endif // left eye { From d77a08bfe71bbf546df9c5ebd8458a1e855dcbcf Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 12 Nov 2020 18:05:12 +0000 Subject: [PATCH 14/40] Fixed format --- examples/osgmultiviewOVR/MultiviewOVR.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/osgmultiviewOVR/MultiviewOVR.cpp b/examples/osgmultiviewOVR/MultiviewOVR.cpp index 0ce91b94bbd..365c7ab6799 100644 --- a/examples/osgmultiviewOVR/MultiviewOVR.cpp +++ b/examples/osgmultiviewOVR/MultiviewOVR.cpp @@ -131,7 +131,7 @@ void MultiviewOVR::configure(osgViewer::View& view) const osg::Texture2DArray* depth_texture = new osg::Texture2DArray; depth_texture->setTextureSize(tex_width, tex_height, 2); - depth_texture->setInternalFormat(GL_DEPTH_COMPONENT24); + depth_texture->setInternalFormat(GL_DEPTH_COMPONENT); depth_texture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR); depth_texture->setFilter(osg::Texture::MAG_FILTER,osg::Texture::LINEAR); depth_texture->setWrap(osg::Texture::WRAP_S,osg::Texture::CLAMP_TO_EDGE); From 8bad3be99566c87e7e6a44f2d3d1897a5b66436b Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 12 Nov 2020 18:32:27 +0000 Subject: [PATCH 15/40] Removed debug right eye camera clear colour setting --- examples/osgmultiviewOVR/StandardStereo.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/osgmultiviewOVR/StandardStereo.cpp b/examples/osgmultiviewOVR/StandardStereo.cpp index 62edde6855d..b2ec4aaffb9 100644 --- a/examples/osgmultiviewOVR/StandardStereo.cpp +++ b/examples/osgmultiviewOVR/StandardStereo.cpp @@ -163,7 +163,6 @@ void StandardStereo::configure(osgViewer::View& view) const camera->setDrawBuffer(buffer); camera->setReadBuffer(buffer); camera->setAllowEventFocus(false); - camera->setClearColor(osg::Vec4(0.2f, 0.2f, 0.2f, 1.0f)); // tell the camera to use OpenGL frame buffer object where supported. camera->setRenderTargetImplementation(renderTargetImplementation); From 5f03aec6bc21f6d9cb3e0daa4622d093d7e22ac6 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 12 Nov 2020 18:35:16 +0000 Subject: [PATCH 16/40] Added support for vertex colours --- examples/osgmultiviewOVR/multiviewOVR.frag | 4 +++- examples/osgmultiviewOVR/multiviewOVR.vert | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/examples/osgmultiviewOVR/multiviewOVR.frag b/examples/osgmultiviewOVR/multiviewOVR.frag index 19b4e006df4..7f4d05d18c0 100644 --- a/examples/osgmultiviewOVR/multiviewOVR.frag +++ b/examples/osgmultiviewOVR/multiviewOVR.frag @@ -2,11 +2,13 @@ uniform sampler2D texture; +in vec4 color; in vec2 texcoord; out vec4 fragColor; void main(void) { - fragColor = texture2D( texture, texcoord.xy); + fragColor = color * texture2D( texture, texcoord.xy); + if (fragColor.a==0.0) discard; } diff --git a/examples/osgmultiviewOVR/multiviewOVR.vert b/examples/osgmultiviewOVR/multiviewOVR.vert index bca31aeb4fd..79e8164dd69 100644 --- a/examples/osgmultiviewOVR/multiviewOVR.vert +++ b/examples/osgmultiviewOVR/multiviewOVR.vert @@ -12,14 +12,17 @@ uniform mat4 ovr_projectionMatrix[NUM_VIEWS]; uniform mat4 ovr_viewMatrix[NUM_VIEWS]; in vec4 osg_Vertex; +in vec4 osg_Color; in vec4 osg_MultiTexCoord0; +out vec4 color; out vec2 texcoord; void main(void) { mat4 mvp = ovr_projectionMatrix[gl_ViewID_OVR] * osg_ProjectionMatrix * ovr_viewMatrix[gl_ViewID_OVR] * osg_ModelViewMatrix; + color = osg_Color; texcoord = osg_MultiTexCoord0.xy; gl_Position = mvp * osg_Vertex; From 08c8f3bd7b8832aa7f4ae918ad78529d8491910c Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 22 Dec 2020 12:23:59 +0000 Subject: [PATCH 17/40] Updated width of background quad --- src/osgViewer/StatsHandler.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/osgViewer/StatsHandler.cpp b/src/osgViewer/StatsHandler.cpp index 665ce4acf62..c026cfc2bb8 100644 --- a/src/osgViewer/StatsHandler.cpp +++ b/src/osgViewer/StatsHandler.cpp @@ -434,6 +434,9 @@ void StatsHandler::setWindowSize(int width, int height) if (width <= 0 || height <= 0) return; + _statsWidth = width; + _statsHeight = height; + _camera->setViewport(0, 0, width, height); if (fabs(height*_statsWidth) <= fabs(width*_statsHeight)) { From 2d6e0b6a6637e1b0b81f802e390c24b4b97215c0 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 23 Dec 2020 16:16:56 +0000 Subject: [PATCH 18/40] Added CullSettings::InitialFrustumCallback to enable Camera to provide customization of the the initialzation of the frustum. --- include/osg/CullSettings | 15 ++++++++++++++- src/osg/CullSettings.cpp | 3 +++ src/osg/CullStack.cpp | 10 +++++++++- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/include/osg/CullSettings b/include/osg/CullSettings index c61fe913825..1c3f3a6656a 100644 --- a/include/osg/CullSettings +++ b/include/osg/CullSettings @@ -23,6 +23,7 @@ namespace osg { // forward declare class ArgumentParser; class ApplicationUsage; +class Polytope; class OSG_EXPORT CullSettings { @@ -77,6 +78,7 @@ class OSG_EXPORT CullSettings LIGHT = (0x1 << 16), DRAW_BUFFER = (0x1 << 17), READ_BUFFER = (0x1 << 18), + INITIAL_FRUSTUM_CALLBACK = (0x1 << 19), NO_VARIABLES = 0x00000000, ALL_VARIABLES = 0x7FFFFFFF @@ -243,6 +245,17 @@ class OSG_EXPORT CullSettings const ClampProjectionMatrixCallback* getClampProjectionMatrixCallback() const { return _clampProjectionMatrixCallback.get(); } + /** Callback to override the initial frustum, in clip space, set up at the start of cull traversal prior to projection and view matrices transforming.*/ + struct InitialFrustumCallback : public osg::Referenced + { + virtual void setInitialFrustum(CullStack& cullStack, Polytope& frustum) const = 0; + }; + + void setInitialFrustumCallback(InitialFrustumCallback* ifc) { _initialFrustumCallback = ifc; applyMaskAction(INITIAL_FRUSTUM_CALLBACK); } + InitialFrustumCallback* getInitialFrustumCallback() { return _initialFrustumCallback.get(); } + const InitialFrustumCallback* getInitialFrustumCallback() const { return _initialFrustumCallback.get(); } + + /** Write out internal settings of CullSettings. */ void write(std::ostream& out); @@ -267,7 +280,7 @@ class OSG_EXPORT CullSettings Node::NodeMask _cullMaskLeft; Node::NodeMask _cullMaskRight; - + ref_ptr _initialFrustumCallback; }; template diff --git a/src/osg/CullSettings.cpp b/src/osg/CullSettings.cpp index 04cf45ad549..0a221890e65 100644 --- a/src/osg/CullSettings.cpp +++ b/src/osg/CullSettings.cpp @@ -70,6 +70,8 @@ void CullSettings::setCullSettings(const CullSettings& rhs) _cullMask = rhs._cullMask; _cullMaskLeft = rhs._cullMaskLeft; _cullMaskRight = rhs._cullMaskRight; + + _initialFrustumCallback = rhs._initialFrustumCallback; } @@ -88,6 +90,7 @@ void CullSettings::inheritCullSettings(const CullSettings& settings, unsigned in if (inheritanceMask & LOD_SCALE) _LODScale = settings._LODScale; if (inheritanceMask & SMALL_FEATURE_CULLING_PIXEL_SIZE) _smallFeatureCullingPixelSize = settings._smallFeatureCullingPixelSize; if (inheritanceMask & CLAMP_PROJECTION_MATRIX_CALLBACK) _clampProjectionMatrixCallback = settings._clampProjectionMatrixCallback; + if (inheritanceMask & INITIAL_FRUSTUM_CALLBACK) _initialFrustumCallback = settings._initialFrustumCallback; } diff --git a/src/osg/CullStack.cpp b/src/osg/CullStack.cpp index a5cad7b98ba..653e3ea3011 100644 --- a/src/osg/CullStack.cpp +++ b/src/osg/CullStack.cpp @@ -162,7 +162,15 @@ void CullStack::pushProjectionMatrix(RefMatrix* matrix) osg::CullingSet& cullingSet = _projectionCullingStack.back(); // set up view frustum. - cullingSet.getFrustum().setToUnitFrustum(((_cullingMode&NEAR_PLANE_CULLING)!=0),((_cullingMode&FAR_PLANE_CULLING)!=0)); + if (_initialFrustumCallback.valid()) + { + _initialFrustumCallback->setInitialFrustum(*this, cullingSet.getFrustum()); + } + else + { + cullingSet.getFrustum().setToUnitFrustum(((_cullingMode&NEAR_PLANE_CULLING)!=0),((_cullingMode&FAR_PLANE_CULLING)!=0)); + } + cullingSet.getFrustum().transformProvidingInverse(*matrix); // set the culling mask ( There should be a more elegant way!) Nikolaus H. From 6cabb0b0127696f906a558cb83fcd8e395c493d9 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 24 Dec 2020 09:45:00 +0000 Subject: [PATCH 19/40] Added near/far flags to Polytope::setToBoundingBox(). --- include/osg/Polytope | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/osg/Polytope b/include/osg/Polytope index c3dceceb3c9..04a9c35b3a6 100644 --- a/include/osg/Polytope +++ b/include/osg/Polytope @@ -70,15 +70,15 @@ class OSG_EXPORT Polytope } /** Create a Polytope which is a equivalent to BoundingBox.*/ - void setToBoundingBox(const BoundingBox& bb) + void setToBoundingBox(const BoundingBox& bb, bool withNear=true, bool withFar=true) { _planeList.clear(); _planeList.push_back(Plane(1.0,0.0,0.0,-bb.xMin())); // left plane. _planeList.push_back(Plane(-1.0,0.0,0.0,bb.xMax())); // right plane. _planeList.push_back(Plane(0.0,1.0,0.0,-bb.yMin())); // bottom plane. _planeList.push_back(Plane(0.0,-1.0,0.0,bb.yMax())); // top plane. - _planeList.push_back(Plane(0.0,0.0,1.0,-bb.zMin())); // near plane - _planeList.push_back(Plane(0.0,0.0,-1.0,bb.zMax())); // far plane + if (withNear) _planeList.push_back(Plane(0.0,0.0,1.0,-bb.zMin())); // near plane + if (withFar) _planeList.push_back(Plane(0.0,0.0,-1.0,bb.zMax())); // far plane setupMask(); } From 38ed11b924a7ae9003c90a889f564fde0dc99694 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 24 Dec 2020 09:53:09 +0000 Subject: [PATCH 20/40] Added custom InitialFrustumCallback --- examples/osgmultiviewOVR/MultiviewOVR.cpp | 91 ++++++++++++++++++++--- 1 file changed, 81 insertions(+), 10 deletions(-) diff --git a/examples/osgmultiviewOVR/MultiviewOVR.cpp b/examples/osgmultiviewOVR/MultiviewOVR.cpp index 365c7ab6799..8dfe04df58c 100644 --- a/examples/osgmultiviewOVR/MultiviewOVR.cpp +++ b/examples/osgmultiviewOVR/MultiviewOVR.cpp @@ -14,12 +14,68 @@ #include #include #include +#include #include #include using namespace osgViewer; + +struct CustomIntialFrustumCallback : public osg::CullSettings::InitialFrustumCallback +{ + std::vector projectionOffsets; + std::vector viewOffsets; + + osg::BoundingBoxd bb; + + void computeClipSpaceBound(osg::Camera& camera) + { + osg::Matrixd pmv = camera.getViewMatrix() * camera.getViewMatrix(); + + size_t numOffsets = std::min(projectionOffsets.size(), viewOffsets.size()); + + std::vector world_vertices; + world_vertices.reserve(numOffsets*8); + + for(size_t i=0; i MultiviewOVR::createStereoMesh(const osg::Vec3& origin, const osg::Vec3& widthVector, const osg::Vec3& heightVector) const { osg::Vec3d center(0.0,0.0,0.0); @@ -141,11 +197,13 @@ void MultiviewOVR::configure(osgViewer::View& view) const osg::Camera::RenderTargetImplementation renderTargetImplementation = osg::Camera::FRAME_BUFFER_OBJECT; GLenum buffer = GL_FRONT; + // left/right eye multiviewOVR camera { // GL_OVR_multiview2 extensions requires modern versions of GLSL without fixed function fallback gc->getState()->setUseModelViewAndProjectionUniforms(true); gc->getState()->setUseVertexAttributeAliasing(true); + //osg::DisplaySettings::instance()->setShaderHint(osg::DisplaySettings::SHADER_GL3); osg::ref_ptr camera = new osg::Camera; camera->setName("multview eye camera"); @@ -155,6 +213,12 @@ void MultiviewOVR::configure(osgViewer::View& view) const camera->setReadBuffer(buffer); camera->setAllowEventFocus(false); + osg::ref_ptr ifc = new CustomIntialFrustumCallback; + + // assign custom frustum callback + camera->setInitialFrustumCallback(ifc.get()); + + // tell the camera to use OpenGL frame buffer object where supported. camera->setRenderTargetImplementation(renderTargetImplementation); @@ -168,21 +232,28 @@ void MultiviewOVR::configure(osgViewer::View& view) const osg::StateSet* stateset = camera->getOrCreateStateSet(); { // set up the projection and view matrix uniforms - osg::Matrixd left_projectionOffset = displaySettings->computeLeftEyeProjectionImplementation(osg::Matrixd()); - osg::Matrixd left_viewOffset = displaySettings->computeLeftEyeViewImplementation(osg::Matrixd()); - osg::Matrixd right_projectionOffset = displaySettings->computeRightEyeProjectionImplementation(osg::Matrixd()); - osg::Matrixd right_viewOffset = displaySettings->computeRightEyeViewImplementation(osg::Matrixd()); + ifc->projectionOffsets.push_back(displaySettings->computeLeftEyeProjectionImplementation(osg::Matrixd())); + ifc->viewOffsets.push_back(displaySettings->computeLeftEyeViewImplementation(osg::Matrixd())); + + ifc->projectionOffsets.push_back(displaySettings->computeRightEyeProjectionImplementation(osg::Matrixd())); + ifc->viewOffsets.push_back(displaySettings->computeRightEyeViewImplementation(osg::Matrixd())); + + ifc->computeClipSpaceBound(*camera); - osg::ref_ptr ovr_viewMatrix_uniform = new osg::Uniform(osg::Uniform::FLOAT_MAT4, "ovr_viewMatrix", 2); - osg::ref_ptr ovr_projectionMatrix_uniform = new osg::Uniform(osg::Uniform::FLOAT_MAT4, "ovr_projectionMatrix", 2); + osg::ref_ptr ovr_viewMatrix_uniform = new osg::Uniform(osg::Uniform::FLOAT_MAT4, "ovr_viewMatrix", ifc->projectionOffsets.size()); + osg::ref_ptr ovr_projectionMatrix_uniform = new osg::Uniform(osg::Uniform::FLOAT_MAT4, "ovr_projectionMatrix", ifc->viewOffsets.size()); stateset->addUniform(ovr_viewMatrix_uniform); stateset->addUniform(ovr_projectionMatrix_uniform); - ovr_viewMatrix_uniform->setElement(0, left_viewOffset); - ovr_projectionMatrix_uniform->setElement(0, left_projectionOffset); + for(size_t i=0; iprojectionOffsets.size(); ++i) + { + ovr_projectionMatrix_uniform->setElement(i, ifc->projectionOffsets[i]); + } - ovr_viewMatrix_uniform->setElement(1, right_viewOffset); - ovr_projectionMatrix_uniform->setElement(1, right_projectionOffset); + for(size_t i=0; iviewOffsets.size(); ++i) + { + ovr_viewMatrix_uniform->setElement(i, ifc->viewOffsets[i]); + } // set up the shaders osg::ref_ptr program = new osg::Program(); From 19499d410933e3a0b0f529a6d13bcc98604b6db5 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 24 Dec 2020 13:41:42 +0000 Subject: [PATCH 21/40] Added ToggleFrustumHandler that toggles the use of the custom frustum when the 'c' key is pressed. --- examples/osgmultiviewOVR/MultiviewOVR.cpp | 50 ++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/examples/osgmultiviewOVR/MultiviewOVR.cpp b/examples/osgmultiviewOVR/MultiviewOVR.cpp index 8dfe04df58c..d6a75becb38 100644 --- a/examples/osgmultiviewOVR/MultiviewOVR.cpp +++ b/examples/osgmultiviewOVR/MultiviewOVR.cpp @@ -27,8 +27,14 @@ struct CustomIntialFrustumCallback : public osg::CullSettings::InitialFrustumCal std::vector projectionOffsets; std::vector viewOffsets; + bool applyBB = true; osg::BoundingBoxd bb; + void toggle() + { + applyBB = !applyBB; + } + void computeClipSpaceBound(osg::Camera& camera) { osg::Matrixd pmv = camera.getViewMatrix() * camera.getViewMatrix(); @@ -71,10 +77,49 @@ struct CustomIntialFrustumCallback : public osg::CullSettings::InitialFrustumCal virtual void setInitialFrustum(osg::CullStack& cullStack, osg::Polytope& frustum) const { osg::CullSettings::CullingMode cullingMode = cullStack.getCullingMode(); - frustum.setToBoundingBox(bb, ((cullingMode&osg::CullSettings::NEAR_PLANE_CULLING)!=0),((cullingMode&osg::CullSettings::FAR_PLANE_CULLING)!=0)); + if (applyBB) + { + frustum.setToBoundingBox(bb, ((cullingMode&osg::CullSettings::NEAR_PLANE_CULLING)!=0),((cullingMode&osg::CullSettings::FAR_PLANE_CULLING)!=0)); + } + else + { + frustum.setToUnitFrustum(((cullingMode&osg::CullSettings::NEAR_PLANE_CULLING)!=0),((cullingMode&osg::CullSettings::FAR_PLANE_CULLING)!=0)); + } } }; +class ToggleFrustumHandler : public osgGA::GUIEventHandler +{ + public: + + ToggleFrustumHandler(CustomIntialFrustumCallback* callback) : + cifc(callback) {} + + osg::ref_ptr cifc; + + bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter&) + { + if (ea.getHandled()) return false; + + switch(ea.getEventType()) + { + case(osgGA::GUIEventAdapter::KEYUP): + { + if (ea.getKey()=='c') + { + cifc->toggle(); + return true; + } + break; + } + + default: + return false; + } + return false; + } +}; + osg::ref_ptr MultiviewOVR::createStereoMesh(const osg::Vec3& origin, const osg::Vec3& widthVector, const osg::Vec3& heightVector) const { @@ -215,6 +260,9 @@ void MultiviewOVR::configure(osgViewer::View& view) const osg::ref_ptr ifc = new CustomIntialFrustumCallback; + + view.addEventHandler(new ToggleFrustumHandler(ifc.get())); + // assign custom frustum callback camera->setInitialFrustumCallback(ifc.get()); From ba7334ef29abfd1974af4901d0a23f51764193cd Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 29 Dec 2020 13:30:27 +0000 Subject: [PATCH 22/40] Added initial template for Leia ViewConfig implementation --- examples/osgmultiviewOVR/CMakeLists.txt | 1 + examples/osgmultiviewOVR/Leia.cpp | 432 +++++++++++++++++++ examples/osgmultiviewOVR/Leia.h | 32 ++ examples/osgmultiviewOVR/leia.frag | 14 + examples/osgmultiviewOVR/leia.vert | 26 ++ examples/osgmultiviewOVR/osgmultiviewOVR.cpp | 5 + 6 files changed, 510 insertions(+) create mode 100644 examples/osgmultiviewOVR/Leia.cpp create mode 100644 examples/osgmultiviewOVR/Leia.h create mode 100644 examples/osgmultiviewOVR/leia.frag create mode 100644 examples/osgmultiviewOVR/leia.vert diff --git a/examples/osgmultiviewOVR/CMakeLists.txt b/examples/osgmultiviewOVR/CMakeLists.txt index 6d26ddb6031..ce8add92a24 100644 --- a/examples/osgmultiviewOVR/CMakeLists.txt +++ b/examples/osgmultiviewOVR/CMakeLists.txt @@ -1,6 +1,7 @@ SET(TARGET_SRC MultiviewOVR.cpp StandardStereo.cpp + Leia.cpp osgmultiviewOVR.cpp ) diff --git a/examples/osgmultiviewOVR/Leia.cpp b/examples/osgmultiviewOVR/Leia.cpp new file mode 100644 index 00000000000..5bca252c893 --- /dev/null +++ b/examples/osgmultiviewOVR/Leia.cpp @@ -0,0 +1,432 @@ +#include "Leia.h" + +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +using namespace osgViewer; + +#if 0 +// https://docs.leialoft.com/developer/android-sdk/rendering-for-leia + +// https://docs.leialoft.com/developer/android-sdk/rendering-for-leia/leiainitializecameradata +void leiaInitializeCameraData(LeiaCameraData * data, + int num_horizontal_views, + int num_vertical_views, + float system_disparity_in_pixels, + float baseline_scaling, + float convergence_distance, + float vertical_field_of_view_degrees, + float near, float far, + int view_resolution_x_pixels, + int view_resolution_y_pixels); + +// https://docs.leialoft.com/developer/android-sdk/rendering-for-leia/leiacalculateviews +int leiaCalculateViews(LeiaCameraData * data, + LeiaCameraView * out_views, + int len_views_in_x, + int len_views_in_y); + +// https://docs.leialoft.com/developer/android-sdk/rendering-for-leia/leiainitializecameradatafrommatrix +void leiaInitializeCameraDataFromMatrix(float* matrix_4_4, + LeiaCameraData* data, + int num_horizontal_views, + int num_vertical_views, + float system_disparity_in_pixels, + float baseline_scaling, + float convergence_distance, + int view_resolution_x_pixels, + int view_resolution_y_pixels); + +// https://docs.leialoft.com/developer/android-sdk/rendering-for-leia/updating-your-matrices +void leiaSetNumberOfViews(LeiaCameraData* data, + int num_horizontal_views, + int num_vertical_views); +void leiaSetSystemDisparityInPixels(LeiaCameraData* data, + float disparity_in_pixels); +void leiaSetApplicationBaselineScale(LeiaCameraData* data, + float baseline_scaling); +void leiaSetFieldOfView(LeiaCameraData* data, + float fov_in_degrees); +void leiaSetFrustumPlanes(LeiaCameraData* data, + float near, + float focal_distance, + float far); +void leiaSetViewSizeInPixels(LeiaCameraData* data, + int resolution_x, + int resolution_y); + +// shaders +// https://docs.leialoft.com/developer/android-sdk/rendering-for-leia/shaders + +// updating the pipeline +// https://docs.leialoft.com/developer/android-sdk/updating-the-gl-pipeline + + +// Example Shaders in SDK +~/3rdParty/Lumia/LeiaLoft_NativeAndroid_SDK_2018-07-19/Samples/TeapotsWithLeia/classic-teapot/src/main/assets/Shaders + + +#endif + +struct LeiaIntialFrustumCallback : public osg::CullSettings::InitialFrustumCallback +{ + std::vector projectionMatrices; + + bool applyBB = true; + osg::BoundingBoxd bb; + + void toggle() + { + applyBB = !applyBB; + } + + void computeClipSpaceBound(osg::Camera& camera) + { + osg::Matrixd pmv = camera.getProjectionMatrix() * camera.getViewMatrix(); + + size_t numOffsets = projectionMatrices.size(); + + std::vector world_vertices; + world_vertices.reserve(numOffsets*8); + + for(size_t i=0; i cifc; + + bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter&) + { + if (ea.getHandled()) return false; + + switch(ea.getEventType()) + { + case(osgGA::GUIEventAdapter::KEYUP): + { + if (ea.getKey()=='c') + { + cifc->toggle(); + return true; + } + break; + } + + default: + return false; + } + return false; + } +}; + + +osg::ref_ptr Leia::createLeiaMesh(const osg::Vec3& origin, const osg::Vec3& widthVector, const osg::Vec3& heightVector) const +{ + osg::Vec3d center(0.0,0.0,0.0); + osg::Vec3d eye(0.0,0.0,0.0); + + // create the quad to visualize. + osg::Geometry* geometry = new osg::Geometry(); + + geometry->setSupportsDisplayList(false); + + osg::DrawElementsUShort* elements = new osg::DrawElementsUShort(osg::PrimitiveSet::TRIANGLES); + osg::Vec3Array* vertices = new osg::Vec3Array; + osg::Vec3Array* texcoords = new osg::Vec3Array; + osg::Vec4Array* colors = new osg::Vec4Array; + colors->push_back(osg::Vec4(1.0, 1.0, 0.0, 1.0)); + + // left hand side + vertices->push_back(origin); texcoords->push_back(osg::Vec3(0.0f, 0.0f, 0.0f)); + vertices->push_back(origin + widthVector*0.5f); texcoords->push_back(osg::Vec3(1.0f, 0.0f, 0.0f)); + vertices->push_back(origin + widthVector*0.5f +heightVector); texcoords->push_back(osg::Vec3(1.0f, 1.0f, 0.0f)); + vertices->push_back(origin + heightVector); texcoords->push_back(osg::Vec3(0.0f, 1.0f, 0.0f)); + + elements->push_back(0); + elements->push_back(1); + elements->push_back(2); + elements->push_back(2); + elements->push_back(3); + elements->push_back(0); + + // right hand side + vertices->push_back(origin + widthVector*0.5f); texcoords->push_back(osg::Vec3(0.0f, 0.0f, 1.0f)); + vertices->push_back(origin + widthVector); texcoords->push_back(osg::Vec3(1.0f, 0.0f, 1.0f)); + vertices->push_back(origin + widthVector +heightVector); texcoords->push_back(osg::Vec3(1.0f, 1.0f, 1.0f)); + vertices->push_back(origin + widthVector*0.5f + heightVector); texcoords->push_back(osg::Vec3(0.0f, 1.0f, 1.0f)); + + elements->push_back(4); + elements->push_back(5); + elements->push_back(6); + elements->push_back(6); + elements->push_back(7); + elements->push_back(4); + + geometry->setVertexArray(vertices); + geometry->setColorArray(colors, osg::Array::BIND_OVERALL); + geometry->setTexCoordArray(0, texcoords); + geometry->addPrimitiveSet(elements); + + return geometry; +} + +void Leia::configure(osgViewer::View& view) const +{ + osg::GraphicsContext::WindowingSystemInterface* wsi = osg::GraphicsContext::getWindowingSystemInterface(); + if (!wsi) + { + OSG_NOTICE<<"Error, no WindowSystemInterface available, cannot create windows."<getScreenResolution(si, width, height); + + osg::ref_ptr traits = new osg::GraphicsContext::Traits; + traits->hostName = si.hostName; + traits->displayNum = si.displayNum; + traits->screenNum = si.screenNum; + traits->x = 0; + traits->y = 0; + traits->width = width; + traits->height = height; + traits->windowDecoration = false; + traits->doubleBuffer = true; + traits->sharedContext = 0; + + osg::ref_ptr gc = osg::GraphicsContext::createGraphicsContext(traits.get()); + if (!gc) + { + OSG_NOTICE<<"GraphicsWindow has not been created successfully."<setTextureSize(tex_width, tex_height, 2); + color_texture->setInternalFormat(GL_RGBA); + color_texture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR); + color_texture->setFilter(osg::Texture::MAG_FILTER,osg::Texture::LINEAR); + color_texture->setWrap(osg::Texture::WRAP_S,osg::Texture::CLAMP_TO_EDGE); + color_texture->setWrap(osg::Texture::WRAP_T,osg::Texture::CLAMP_TO_EDGE); + color_texture->setWrap(osg::Texture::WRAP_R,osg::Texture::CLAMP_TO_EDGE); + + osg::Texture2DArray* depth_texture = new osg::Texture2DArray; + + depth_texture->setTextureSize(tex_width, tex_height, 2); + depth_texture->setInternalFormat(GL_DEPTH_COMPONENT); + depth_texture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR); + depth_texture->setFilter(osg::Texture::MAG_FILTER,osg::Texture::LINEAR); + depth_texture->setWrap(osg::Texture::WRAP_S,osg::Texture::CLAMP_TO_EDGE); + depth_texture->setWrap(osg::Texture::WRAP_T,osg::Texture::CLAMP_TO_EDGE); + depth_texture->setWrap(osg::Texture::WRAP_R,osg::Texture::CLAMP_TO_EDGE); + + osg::Camera::RenderTargetImplementation renderTargetImplementation = osg::Camera::FRAME_BUFFER_OBJECT; + GLenum buffer = GL_FRONT; + + view.getCamera()->setProjectionMatrixAsPerspective(90.0f, 1.0, 1, 1000.0); + + // left/right eye multiviewOVR camera + { + // GL_OVR_multiview2 extensions requires modern versions of GLSL without fixed function fallback + gc->getState()->setUseModelViewAndProjectionUniforms(true); + gc->getState()->setUseVertexAttributeAliasing(true); + //osg::DisplaySettings::instance()->setShaderHint(osg::DisplaySettings::SHADER_GL3); + + osg::ref_ptr camera = new osg::Camera; + camera->setName("multview eye camera"); + camera->setGraphicsContext(gc.get()); + camera->setViewport(new osg::Viewport(0,0,camera_width, camera_height)); + camera->setDrawBuffer(buffer); + camera->setReadBuffer(buffer); + camera->setAllowEventFocus(false); + + osg::ref_ptr ifc = new LeiaIntialFrustumCallback; + + + view.addEventHandler(new LeiaToggleFrustumHandler(ifc.get())); + + // assign custom frustum callback + camera->setInitialFrustumCallback(ifc.get()); + + + // tell the camera to use OpenGL frame buffer object where supported. + camera->setRenderTargetImplementation(renderTargetImplementation); + + // attach the texture and use it as the color buffer, specify that the face is controlled by the multiview extension + camera->attach(osg::Camera::COLOR_BUFFER, color_texture, 0, osg::Camera::FACE_CONTROLLED_BY_MULTIVIEW_SHADER); + camera->attach(osg::Camera::DEPTH_BUFFER, depth_texture, 0, osg::Camera::FACE_CONTROLLED_BY_MULTIVIEW_SHADER); + + + view.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd()); + + osg::StateSet* stateset = camera->getOrCreateStateSet(); + { + // set up the projection and view matrix uniforms + ifc->projectionMatrices.push_back(camera->getProjectionMatrix()); + ifc->projectionMatrices.push_back(camera->getProjectionMatrix()); + + ifc->computeClipSpaceBound(*camera); + + osg::ref_ptr projectionMatrices_uniform = new osg::Uniform(osg::Uniform::FLOAT_MAT4, "osg_ProjectionMatrices", ifc->projectionMatrices.size()); + stateset->addUniform(projectionMatrices_uniform); + + for(size_t i=0; iprojectionMatrices.size(); ++i) + { + projectionMatrices_uniform->setElement(i, ifc->projectionMatrices[i]); + } + + // set up the shaders + osg::ref_ptr program = new osg::Program(); + stateset->setAttribute(program.get(), osg::StateAttribute::ON); + + std::string vsFileName("leia.vert"); + std::string fsFileName("leia.frag"); + + osg::ref_ptr vertexShader = osgDB::readRefShaderFile( osg::Shader::VERTEX, vsFileName) ; + if (vertexShader.get()) program->addShader( vertexShader.get() ); + + osg::ref_ptr fragmentShader = osgDB::readRefShaderFile( osg::Shader::FRAGMENT, fsFileName) ; + if (fragmentShader.get()) program->addShader( fragmentShader.get() ); + } + + } + + + // distortion correction set up. + { + osg::ref_ptr mesh = createLeiaMesh(osg::Vec3(0.0f,0.0f,0.0f), osg::Vec3(width,0.0f,0.0f), osg::Vec3(0.0f,height,0.0f)); + + // new we need to add the texture to the mesh, we do so by creating a + // StateSet to contain the Texture StateAttribute. + osg::StateSet* stateset = mesh->getOrCreateStateSet(); + stateset->setTextureAttribute(0, color_texture, osg::StateAttribute::ON); + stateset->setMode(GL_LIGHTING, osg::StateAttribute::OFF); + + { + osg::ref_ptr program = new osg::Program(); + stateset->setAttribute(program.get(), osg::StateAttribute::ON); + + std::string vsFileName("standard.vert"); + std::string fsFileName("standard.frag"); + + osg::ref_ptr vertexShader = osgDB::readRefShaderFile( osg::Shader::VERTEX, vsFileName) ; + if (vertexShader.get()) program->addShader( vertexShader.get() ); + + osg::ref_ptr fragmentShader = osgDB::readRefShaderFile( osg::Shader::FRAGMENT, fsFileName) ; + if (fragmentShader.get()) program->addShader( fragmentShader.get() ); + } + + osg::ref_ptr camera = new osg::Camera; + camera->setGraphicsContext(gc.get()); + camera->setClearMask(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT ); + camera->setClearColor( osg::Vec4(0.0,0.0,0.0,1.0) ); + camera->setViewport(new osg::Viewport(0, 0, width, height)); + + GLenum window_buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT; + camera->setDrawBuffer(window_buffer); + camera->setReadBuffer(window_buffer); + camera->setReferenceFrame(osg::Camera::ABSOLUTE_RF); + camera->setAllowEventFocus(true); + camera->setInheritanceMask(camera->getInheritanceMask() & ~osg::CullSettings::CLEAR_COLOR & ~osg::CullSettings::COMPUTE_NEAR_FAR_MODE); + //camera->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR); + + camera->setProjectionMatrixAsOrtho2D(0,width,0,height); + camera->setViewMatrix(osg::Matrix::identity()); + + // add subgraph to render + camera->addChild(mesh.get()); + + camera->setName("DistortionCorrectionCamera"); + + osgDB::writeNodeFile(*mesh, "mesh.osgt"); + + view.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd(), false); + } + + view.getCamera()->setNearFarRatio(0.0001f); + + if (view.getLightingMode()==osg::View::HEADLIGHT) + { + // set a local light source for headlight to ensure that lighting is consistent across sides of cube. + view.getLight()->setPosition(osg::Vec4(0.0f,0.0f,0.0f,1.0f)); + } +} diff --git a/examples/osgmultiviewOVR/Leia.h b/examples/osgmultiviewOVR/Leia.h new file mode 100644 index 00000000000..48976a44be1 --- /dev/null +++ b/examples/osgmultiviewOVR/Leia.h @@ -0,0 +1,32 @@ +#ifndef OSGVIEWER_Leia +#define OSGVIEWER_Leia 1 + +#include + +/** spherical display using 6 slave cameras rendering the 6 sides of a cube map, and 7th camera doing distortion correction to present on a spherical display.*/ +class Leia : public osgViewer::ViewConfig +{ + public: + + Leia(unsigned int screenNum=0): + _screenNum(screenNum) {} + + Leia(const Leia& rhs, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY): + ViewConfig(rhs,copyop), + _screenNum(rhs._screenNum) {} + + META_Object(osgViewer, Leia); + + virtual void configure(osgViewer::View& view) const; + + void setScreenNum(unsigned int n) { _screenNum = n; } + unsigned int getScreenNum() const { return _screenNum; } + + protected: + + osg::ref_ptr createLeiaMesh(const osg::Vec3& origin, const osg::Vec3& widthVector, const osg::Vec3& heightVector) const; + + unsigned int _screenNum; +}; + +#endif diff --git a/examples/osgmultiviewOVR/leia.frag b/examples/osgmultiviewOVR/leia.frag new file mode 100644 index 00000000000..7f4d05d18c0 --- /dev/null +++ b/examples/osgmultiviewOVR/leia.frag @@ -0,0 +1,14 @@ +#version 330 + +uniform sampler2D texture; + +in vec4 color; +in vec2 texcoord; + +out vec4 fragColor; + +void main(void) +{ + fragColor = color * texture2D( texture, texcoord.xy); + if (fragColor.a==0.0) discard; +} diff --git a/examples/osgmultiviewOVR/leia.vert b/examples/osgmultiviewOVR/leia.vert new file mode 100644 index 00000000000..cbc189ac6bf --- /dev/null +++ b/examples/osgmultiviewOVR/leia.vert @@ -0,0 +1,26 @@ +#version 330 +#extension GL_OVR_multiview2 : enable + +#define NUM_VIEWS 2 + +layout(num_views = NUM_VIEWS) in; + +uniform mat4 osg_ModelViewMatrix; +uniform mat4 osg_ProjectionMatrices[NUM_VIEWS]; + +in vec4 osg_Vertex; +in vec4 osg_Color; +in vec4 osg_MultiTexCoord0; + +out vec4 color; +out vec2 texcoord; + +void main(void) +{ + mat4 mvp = osg_ProjectionMatrices[gl_ViewID_OVR] * osg_ModelViewMatrix; + + color = osg_Color; + texcoord = osg_MultiTexCoord0.xy; + + gl_Position = mvp * osg_Vertex; +} diff --git a/examples/osgmultiviewOVR/osgmultiviewOVR.cpp b/examples/osgmultiviewOVR/osgmultiviewOVR.cpp index 17de5a7ba35..a87e9df1f14 100644 --- a/examples/osgmultiviewOVR/osgmultiviewOVR.cpp +++ b/examples/osgmultiviewOVR/osgmultiviewOVR.cpp @@ -25,6 +25,7 @@ #include "StandardStereo.h" #include "MultiviewOVR.h" +#include "Leia.h" int main( int argc, char** argv ) { @@ -36,6 +37,10 @@ int main( int argc, char** argv ) { viewer.apply(new StandardStereo()); } + if (arguments.read("--leia")) + { + viewer.apply(new Leia()); + } else { viewer.setThreadingModel(osgViewer::Viewer::SingleThreaded); From f027c4c420a771fe1bd3a2b1fbe8f83cb07219b2 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 29 Dec 2020 13:31:15 +0000 Subject: [PATCH 23/40] Fixed setting of pmv matrix --- examples/osgmultiviewOVR/MultiviewOVR.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/osgmultiviewOVR/MultiviewOVR.cpp b/examples/osgmultiviewOVR/MultiviewOVR.cpp index d6a75becb38..7749dfc9802 100644 --- a/examples/osgmultiviewOVR/MultiviewOVR.cpp +++ b/examples/osgmultiviewOVR/MultiviewOVR.cpp @@ -37,7 +37,7 @@ struct CustomIntialFrustumCallback : public osg::CullSettings::InitialFrustumCal void computeClipSpaceBound(osg::Camera& camera) { - osg::Matrixd pmv = camera.getViewMatrix() * camera.getViewMatrix(); + osg::Matrixd pmv = camera.getProjectionMatrix() * camera.getViewMatrix(); size_t numOffsets = std::min(projectionOffsets.size(), viewOffsets.size()); From 0feeb79d05fecf0896a8fb67811a9dfd017d77e6 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 29 Dec 2020 18:28:17 +0000 Subject: [PATCH 24/40] Added 4x4 grid of images, currently repeating each row 4 times as step towards full 4x4 rendering. --- examples/osgmultiviewOVR/Leia.cpp | 61 ++++++++++++++++-------------- examples/osgmultiviewOVR/leia.vert | 2 +- 2 files changed, 33 insertions(+), 30 deletions(-) diff --git a/examples/osgmultiviewOVR/Leia.cpp b/examples/osgmultiviewOVR/Leia.cpp index 5bca252c893..eb2b4364778 100644 --- a/examples/osgmultiviewOVR/Leia.cpp +++ b/examples/osgmultiviewOVR/Leia.cpp @@ -198,31 +198,32 @@ osg::ref_ptr Leia::createLeiaMesh(const osg::Vec3& origin, const osg: osg::Vec4Array* colors = new osg::Vec4Array; colors->push_back(osg::Vec4(1.0, 1.0, 0.0, 1.0)); - // left hand side - vertices->push_back(origin); texcoords->push_back(osg::Vec3(0.0f, 0.0f, 0.0f)); - vertices->push_back(origin + widthVector*0.5f); texcoords->push_back(osg::Vec3(1.0f, 0.0f, 0.0f)); - vertices->push_back(origin + widthVector*0.5f +heightVector); texcoords->push_back(osg::Vec3(1.0f, 1.0f, 0.0f)); - vertices->push_back(origin + heightVector); texcoords->push_back(osg::Vec3(0.0f, 1.0f, 0.0f)); - - elements->push_back(0); - elements->push_back(1); - elements->push_back(2); - elements->push_back(2); - elements->push_back(3); - elements->push_back(0); - - // right hand side - vertices->push_back(origin + widthVector*0.5f); texcoords->push_back(osg::Vec3(0.0f, 0.0f, 1.0f)); - vertices->push_back(origin + widthVector); texcoords->push_back(osg::Vec3(1.0f, 0.0f, 1.0f)); - vertices->push_back(origin + widthVector +heightVector); texcoords->push_back(osg::Vec3(1.0f, 1.0f, 1.0f)); - vertices->push_back(origin + widthVector*0.5f + heightVector); texcoords->push_back(osg::Vec3(0.0f, 1.0f, 1.0f)); - - elements->push_back(4); - elements->push_back(5); - elements->push_back(6); - elements->push_back(6); - elements->push_back(7); - elements->push_back(4); + for(uint32_t row = 0; row<4; ++row) + { + for(uint32_t column = 0; column<4; ++column) + { + uint16_t base = static_cast(vertices->size()); + + vertices->push_back(origin + widthVector*static_cast(column)*0.25f + heightVector*static_cast(row)*0.25f); + texcoords->push_back(osg::Vec3(0.0f, 0.0f, static_cast(column))); + + vertices->push_back(origin + widthVector*static_cast(column+1)*0.25f + heightVector*static_cast(row)*0.25f); + texcoords->push_back(osg::Vec3(1.0f, 0.0f, static_cast(column))); + + vertices->push_back(origin + widthVector*static_cast(column+1)*0.25f + heightVector*static_cast(row+1)*0.25f); + texcoords->push_back(osg::Vec3(1.0f, 1.0f, static_cast(column))); + + vertices->push_back(origin + widthVector*static_cast(column)*0.25f + heightVector*static_cast(row+1)*0.25f); + texcoords->push_back(osg::Vec3(0.0f, 1.0f, static_cast(column))); + + elements->push_back(base + 0); + elements->push_back(base + 1); + elements->push_back(base + 2); + elements->push_back(base + 2); + elements->push_back(base + 3); + elements->push_back(base + 0); + } + } geometry->setVertexArray(vertices); geometry->setColorArray(colors, osg::Array::BIND_OVERALL); @@ -281,7 +282,7 @@ void Leia::configure(osgViewer::View& view) const osg::Texture2DArray* color_texture = new osg::Texture2DArray; - color_texture->setTextureSize(tex_width, tex_height, 2); + color_texture->setTextureSize(tex_width, tex_height, 4); color_texture->setInternalFormat(GL_RGBA); color_texture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR); color_texture->setFilter(osg::Texture::MAG_FILTER,osg::Texture::LINEAR); @@ -291,7 +292,7 @@ void Leia::configure(osgViewer::View& view) const osg::Texture2DArray* depth_texture = new osg::Texture2DArray; - depth_texture->setTextureSize(tex_width, tex_height, 2); + depth_texture->setTextureSize(tex_width, tex_height, 4); depth_texture->setInternalFormat(GL_DEPTH_COMPONENT); depth_texture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR); depth_texture->setFilter(osg::Texture::MAG_FILTER,osg::Texture::LINEAR); @@ -341,8 +342,10 @@ void Leia::configure(osgViewer::View& view) const osg::StateSet* stateset = camera->getOrCreateStateSet(); { // set up the projection and view matrix uniforms - ifc->projectionMatrices.push_back(camera->getProjectionMatrix()); - ifc->projectionMatrices.push_back(camera->getProjectionMatrix()); + ifc->projectionMatrices.push_back(camera->getProjectionMatrix()*osg::Matrixd::translate(-0.2, 0.0, 0.0)); + ifc->projectionMatrices.push_back(camera->getProjectionMatrix()*osg::Matrixd::translate(-0.1, 0.0, 0.0)); + ifc->projectionMatrices.push_back(camera->getProjectionMatrix()*osg::Matrixd::translate(0.1, 0.0, 0.0)); + ifc->projectionMatrices.push_back(camera->getProjectionMatrix()*osg::Matrixd::translate(0.2, 0.0, 0.0)); ifc->computeClipSpaceBound(*camera); diff --git a/examples/osgmultiviewOVR/leia.vert b/examples/osgmultiviewOVR/leia.vert index cbc189ac6bf..8d785806248 100644 --- a/examples/osgmultiviewOVR/leia.vert +++ b/examples/osgmultiviewOVR/leia.vert @@ -1,7 +1,7 @@ #version 330 #extension GL_OVR_multiview2 : enable -#define NUM_VIEWS 2 +#define NUM_VIEWS 4 layout(num_views = NUM_VIEWS) in; From b3d39de2087d7a175c9afa770e87f360b6736ba4 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 30 Dec 2020 12:40:03 +0000 Subject: [PATCH 25/40] Moved texture array creation into method. --- examples/osgmultiviewOVR/Leia.cpp | 34 ++++++++++++++----------------- examples/osgmultiviewOVR/Leia.h | 3 ++- 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/examples/osgmultiviewOVR/Leia.cpp b/examples/osgmultiviewOVR/Leia.cpp index eb2b4364778..3a8f9567a22 100644 --- a/examples/osgmultiviewOVR/Leia.cpp +++ b/examples/osgmultiviewOVR/Leia.cpp @@ -233,6 +233,19 @@ osg::ref_ptr Leia::createLeiaMesh(const osg::Vec3& origin, const osg: return geometry; } +osg::ref_ptr Leia::createTexture2DArray(unsigned int width, unsigned int height, unsigned int depth, GLenum format) const +{ + osg::ref_ptr texture = new osg::Texture2DArray; + texture->setTextureSize(width, height, depth); + texture->setInternalFormat(format); + texture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR); + texture->setFilter(osg::Texture::MAG_FILTER,osg::Texture::LINEAR); + texture->setWrap(osg::Texture::WRAP_S,osg::Texture::CLAMP_TO_EDGE); + texture->setWrap(osg::Texture::WRAP_T,osg::Texture::CLAMP_TO_EDGE); + texture->setWrap(osg::Texture::WRAP_R,osg::Texture::CLAMP_TO_EDGE); + return texture; +} + void Leia::configure(osgViewer::View& view) const { osg::GraphicsContext::WindowingSystemInterface* wsi = osg::GraphicsContext::getWindowingSystemInterface(); @@ -280,25 +293,8 @@ void Leia::configure(osgViewer::View& view) const int camera_width = tex_width; int camera_height = tex_height; - osg::Texture2DArray* color_texture = new osg::Texture2DArray; - - color_texture->setTextureSize(tex_width, tex_height, 4); - color_texture->setInternalFormat(GL_RGBA); - color_texture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR); - color_texture->setFilter(osg::Texture::MAG_FILTER,osg::Texture::LINEAR); - color_texture->setWrap(osg::Texture::WRAP_S,osg::Texture::CLAMP_TO_EDGE); - color_texture->setWrap(osg::Texture::WRAP_T,osg::Texture::CLAMP_TO_EDGE); - color_texture->setWrap(osg::Texture::WRAP_R,osg::Texture::CLAMP_TO_EDGE); - - osg::Texture2DArray* depth_texture = new osg::Texture2DArray; - - depth_texture->setTextureSize(tex_width, tex_height, 4); - depth_texture->setInternalFormat(GL_DEPTH_COMPONENT); - depth_texture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR); - depth_texture->setFilter(osg::Texture::MAG_FILTER,osg::Texture::LINEAR); - depth_texture->setWrap(osg::Texture::WRAP_S,osg::Texture::CLAMP_TO_EDGE); - depth_texture->setWrap(osg::Texture::WRAP_T,osg::Texture::CLAMP_TO_EDGE); - depth_texture->setWrap(osg::Texture::WRAP_R,osg::Texture::CLAMP_TO_EDGE); + osg::ref_ptr color_texture = createTexture2DArray(tex_width, tex_height, 4, GL_RGBA); + osg::ref_ptr depth_texture = createTexture2DArray(tex_width, tex_height, 4, GL_RGBA); osg::Camera::RenderTargetImplementation renderTargetImplementation = osg::Camera::FRAME_BUFFER_OBJECT; GLenum buffer = GL_FRONT; diff --git a/examples/osgmultiviewOVR/Leia.h b/examples/osgmultiviewOVR/Leia.h index 48976a44be1..4365824410b 100644 --- a/examples/osgmultiviewOVR/Leia.h +++ b/examples/osgmultiviewOVR/Leia.h @@ -23,7 +23,8 @@ class Leia : public osgViewer::ViewConfig unsigned int getScreenNum() const { return _screenNum; } protected: - + + osg::ref_ptr createTexture2DArray(unsigned int width, unsigned int height, unsigned int depth, GLenum format) const; osg::ref_ptr createLeiaMesh(const osg::Vec3& origin, const osg::Vec3& widthVector, const osg::Vec3& heightVector) const; unsigned int _screenNum; From faae6288a570cb9d5e0502fe183d49815f19c090 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 30 Dec 2020 12:46:49 +0000 Subject: [PATCH 26/40] Fixed depth component type --- examples/osgmultiviewOVR/Leia.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/osgmultiviewOVR/Leia.cpp b/examples/osgmultiviewOVR/Leia.cpp index 3a8f9567a22..7acb99bcc12 100644 --- a/examples/osgmultiviewOVR/Leia.cpp +++ b/examples/osgmultiviewOVR/Leia.cpp @@ -294,7 +294,7 @@ void Leia::configure(osgViewer::View& view) const int camera_height = tex_height; osg::ref_ptr color_texture = createTexture2DArray(tex_width, tex_height, 4, GL_RGBA); - osg::ref_ptr depth_texture = createTexture2DArray(tex_width, tex_height, 4, GL_RGBA); + osg::ref_ptr depth_texture = createTexture2DArray(tex_width, tex_height, 4, GL_DEPTH_COMPONENT); osg::Camera::RenderTargetImplementation renderTargetImplementation = osg::Camera::FRAME_BUFFER_OBJECT; GLenum buffer = GL_FRONT; From 7aec64564c19f3cb3600064a4a8435976696ae81 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 30 Dec 2020 13:05:42 +0000 Subject: [PATCH 27/40] Restructd set up of LeiaIntialFrustumCallback setup. --- examples/osgmultiviewOVR/Leia.cpp | 38 ++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/examples/osgmultiviewOVR/Leia.cpp b/examples/osgmultiviewOVR/Leia.cpp index 7acb99bcc12..198123d1d05 100644 --- a/examples/osgmultiviewOVR/Leia.cpp +++ b/examples/osgmultiviewOVR/Leia.cpp @@ -293,14 +293,34 @@ void Leia::configure(osgViewer::View& view) const int camera_width = tex_width; int camera_height = tex_height; - osg::ref_ptr color_texture = createTexture2DArray(tex_width, tex_height, 4, GL_RGBA); - osg::ref_ptr depth_texture = createTexture2DArray(tex_width, tex_height, 4, GL_DEPTH_COMPONENT); + osg::ref_ptr color_texture_0 = createTexture2DArray(tex_width, tex_height, 4, GL_RGBA); + osg::ref_ptr depth_texture_0 = createTexture2DArray(tex_width, tex_height, 4, GL_DEPTH_COMPONENT); +#if 0 + osg::ref_ptr color_texture_1 = createTexture2DArray(tex_width, tex_height, 4, GL_RGBA); + osg::ref_ptr depth_texture_1 = createTexture2DArray(tex_width, tex_height, 4, GL_DEPTH_COMPONENT); + + osg::ref_ptr color_texture_2 = createTexture2DArray(tex_width, tex_height, 4, GL_RGBA); + osg::ref_ptr depth_texture_2 = createTexture2DArray(tex_width, tex_height, 4, GL_DEPTH_COMPONENT); + + osg::ref_ptr color_texture_3 = createTexture2DArray(tex_width, tex_height, 4, GL_RGBA); + osg::ref_ptr depth_texture_3 = createTexture2DArray(tex_width, tex_height, 4, GL_DEPTH_COMPONENT); +#endif osg::Camera::RenderTargetImplementation renderTargetImplementation = osg::Camera::FRAME_BUFFER_OBJECT; GLenum buffer = GL_FRONT; view.getCamera()->setProjectionMatrixAsPerspective(90.0f, 1.0, 1, 1000.0); + osg::ref_ptr ifc = new LeiaIntialFrustumCallback; + + // set up the projection and view matrix uniforms + ifc->projectionMatrices.push_back(view.getCamera()->getProjectionMatrix()*osg::Matrixd::translate(-0.2, 0.0, 0.0)); + ifc->projectionMatrices.push_back(view.getCamera()->getProjectionMatrix()*osg::Matrixd::translate(-0.1, 0.0, 0.0)); + ifc->projectionMatrices.push_back(view.getCamera()->getProjectionMatrix()*osg::Matrixd::translate(0.1, 0.0, 0.0)); + ifc->projectionMatrices.push_back(view.getCamera()->getProjectionMatrix()*osg::Matrixd::translate(0.2, 0.0, 0.0)); + + ifc->computeClipSpaceBound(*(view.getCamera())); + // left/right eye multiviewOVR camera { // GL_OVR_multiview2 extensions requires modern versions of GLSL without fixed function fallback @@ -316,7 +336,6 @@ void Leia::configure(osgViewer::View& view) const camera->setReadBuffer(buffer); camera->setAllowEventFocus(false); - osg::ref_ptr ifc = new LeiaIntialFrustumCallback; view.addEventHandler(new LeiaToggleFrustumHandler(ifc.get())); @@ -329,21 +348,14 @@ void Leia::configure(osgViewer::View& view) const camera->setRenderTargetImplementation(renderTargetImplementation); // attach the texture and use it as the color buffer, specify that the face is controlled by the multiview extension - camera->attach(osg::Camera::COLOR_BUFFER, color_texture, 0, osg::Camera::FACE_CONTROLLED_BY_MULTIVIEW_SHADER); - camera->attach(osg::Camera::DEPTH_BUFFER, depth_texture, 0, osg::Camera::FACE_CONTROLLED_BY_MULTIVIEW_SHADER); + camera->attach(osg::Camera::COLOR_BUFFER, color_texture_0, 0, osg::Camera::FACE_CONTROLLED_BY_MULTIVIEW_SHADER); + camera->attach(osg::Camera::DEPTH_BUFFER, depth_texture_0, 0, osg::Camera::FACE_CONTROLLED_BY_MULTIVIEW_SHADER); view.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd()); osg::StateSet* stateset = camera->getOrCreateStateSet(); { - // set up the projection and view matrix uniforms - ifc->projectionMatrices.push_back(camera->getProjectionMatrix()*osg::Matrixd::translate(-0.2, 0.0, 0.0)); - ifc->projectionMatrices.push_back(camera->getProjectionMatrix()*osg::Matrixd::translate(-0.1, 0.0, 0.0)); - ifc->projectionMatrices.push_back(camera->getProjectionMatrix()*osg::Matrixd::translate(0.1, 0.0, 0.0)); - ifc->projectionMatrices.push_back(camera->getProjectionMatrix()*osg::Matrixd::translate(0.2, 0.0, 0.0)); - - ifc->computeClipSpaceBound(*camera); osg::ref_ptr projectionMatrices_uniform = new osg::Uniform(osg::Uniform::FLOAT_MAT4, "osg_ProjectionMatrices", ifc->projectionMatrices.size()); stateset->addUniform(projectionMatrices_uniform); @@ -377,7 +389,7 @@ void Leia::configure(osgViewer::View& view) const // new we need to add the texture to the mesh, we do so by creating a // StateSet to contain the Texture StateAttribute. osg::StateSet* stateset = mesh->getOrCreateStateSet(); - stateset->setTextureAttribute(0, color_texture, osg::StateAttribute::ON); + stateset->setTextureAttribute(0, color_texture_0, osg::StateAttribute::ON); stateset->setMode(GL_LIGHTING, osg::StateAttribute::OFF); { From 1d4bf56fd3f17974eb79274b1e721cda11ea9c3d Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 30 Dec 2020 18:23:21 +0000 Subject: [PATCH 28/40] Implemented rows in prep for interleaving of 4x4 --- examples/osgmultiviewOVR/Leia.cpp | 186 ++++++++++-------- examples/osgmultiviewOVR/Leia.h | 2 +- examples/osgmultiviewOVR/leia_interleave.frag | 27 +++ examples/osgmultiviewOVR/leia_interleave.vert | 7 + 4 files changed, 138 insertions(+), 84 deletions(-) create mode 100644 examples/osgmultiviewOVR/leia_interleave.frag create mode 100644 examples/osgmultiviewOVR/leia_interleave.vert diff --git a/examples/osgmultiviewOVR/Leia.cpp b/examples/osgmultiviewOVR/Leia.cpp index 198123d1d05..09dfff25f0d 100644 --- a/examples/osgmultiviewOVR/Leia.cpp +++ b/examples/osgmultiviewOVR/Leia.cpp @@ -194,36 +194,29 @@ osg::ref_ptr Leia::createLeiaMesh(const osg::Vec3& origin, const osg: osg::DrawElementsUShort* elements = new osg::DrawElementsUShort(osg::PrimitiveSet::TRIANGLES); osg::Vec3Array* vertices = new osg::Vec3Array; - osg::Vec3Array* texcoords = new osg::Vec3Array; + osg::Vec2Array* texcoords = new osg::Vec2Array; osg::Vec4Array* colors = new osg::Vec4Array; colors->push_back(osg::Vec4(1.0, 1.0, 0.0, 1.0)); - for(uint32_t row = 0; row<4; ++row) - { - for(uint32_t column = 0; column<4; ++column) - { - uint16_t base = static_cast(vertices->size()); - - vertices->push_back(origin + widthVector*static_cast(column)*0.25f + heightVector*static_cast(row)*0.25f); - texcoords->push_back(osg::Vec3(0.0f, 0.0f, static_cast(column))); + vertices->push_back(origin); + texcoords->push_back(osg::Vec2(0.0f, 0.0f)); - vertices->push_back(origin + widthVector*static_cast(column+1)*0.25f + heightVector*static_cast(row)*0.25f); - texcoords->push_back(osg::Vec3(1.0f, 0.0f, static_cast(column))); + vertices->push_back(origin + widthVector); + texcoords->push_back(osg::Vec2(1.0f, 0.0f)); - vertices->push_back(origin + widthVector*static_cast(column+1)*0.25f + heightVector*static_cast(row+1)*0.25f); - texcoords->push_back(osg::Vec3(1.0f, 1.0f, static_cast(column))); + vertices->push_back(origin + widthVector + heightVector); + texcoords->push_back(osg::Vec2(1.0f, 1.0f)); - vertices->push_back(origin + widthVector*static_cast(column)*0.25f + heightVector*static_cast(row+1)*0.25f); - texcoords->push_back(osg::Vec3(0.0f, 1.0f, static_cast(column))); + vertices->push_back(origin + heightVector); + texcoords->push_back(osg::Vec2(0.0f, 1.0f)); - elements->push_back(base + 0); - elements->push_back(base + 1); - elements->push_back(base + 2); - elements->push_back(base + 2); - elements->push_back(base + 3); - elements->push_back(base + 0); - } - } + uint16_t base = 0; + elements->push_back(base + 0); + elements->push_back(base + 1); + elements->push_back(base + 2); + elements->push_back(base + 2); + elements->push_back(base + 3); + elements->push_back(base + 0); geometry->setVertexArray(vertices); geometry->setColorArray(colors, osg::Array::BIND_OVERALL); @@ -287,98 +280,116 @@ void Leia::configure(osgViewer::View& view) const return; } + // GL_OVR_multiview2 extensions requires modern versions of GLSL without fixed function fallback + gc->getState()->setUseModelViewAndProjectionUniforms(true); + gc->getState()->setUseVertexAttributeAliasing(true); + //osg::DisplaySettings::instance()->setShaderHint(osg::DisplaySettings::SHADER_GL3); + int tex_width = width; int tex_height = height; int camera_width = tex_width; int camera_height = tex_height; - osg::ref_ptr color_texture_0 = createTexture2DArray(tex_width, tex_height, 4, GL_RGBA); - osg::ref_ptr depth_texture_0 = createTexture2DArray(tex_width, tex_height, 4, GL_DEPTH_COMPONENT); -#if 0 - osg::ref_ptr color_texture_1 = createTexture2DArray(tex_width, tex_height, 4, GL_RGBA); - osg::ref_ptr depth_texture_1 = createTexture2DArray(tex_width, tex_height, 4, GL_DEPTH_COMPONENT); - - osg::ref_ptr color_texture_2 = createTexture2DArray(tex_width, tex_height, 4, GL_RGBA); - osg::ref_ptr depth_texture_2 = createTexture2DArray(tex_width, tex_height, 4, GL_DEPTH_COMPONENT); + struct TexturePair + { + TexturePair(unsigned int width, unsigned int height, unsigned int rows) + { + color = new osg::Texture2DArray; + color->setTextureSize(width, height, rows); + color->setInternalFormat(GL_RGBA); + color->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR); + color->setFilter(osg::Texture::MAG_FILTER,osg::Texture::LINEAR); + color->setWrap(osg::Texture::WRAP_S,osg::Texture::CLAMP_TO_EDGE); + color->setWrap(osg::Texture::WRAP_T,osg::Texture::CLAMP_TO_EDGE); + color->setWrap(osg::Texture::WRAP_R,osg::Texture::CLAMP_TO_EDGE); + + depth = new osg::Texture2DArray; + depth->setTextureSize(width, height, rows); + depth->setInternalFormat(GL_DEPTH_COMPONENT); + depth->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR); + depth->setFilter(osg::Texture::MAG_FILTER,osg::Texture::LINEAR); + depth->setWrap(osg::Texture::WRAP_S,osg::Texture::CLAMP_TO_EDGE); + depth->setWrap(osg::Texture::WRAP_T,osg::Texture::CLAMP_TO_EDGE); + depth->setWrap(osg::Texture::WRAP_R,osg::Texture::CLAMP_TO_EDGE); + } - osg::ref_ptr color_texture_3 = createTexture2DArray(tex_width, tex_height, 4, GL_RGBA); - osg::ref_ptr depth_texture_3 = createTexture2DArray(tex_width, tex_height, 4, GL_DEPTH_COMPONENT); -#endif + osg::ref_ptr color; + osg::ref_ptr depth; + }; - osg::Camera::RenderTargetImplementation renderTargetImplementation = osg::Camera::FRAME_BUFFER_OBJECT; - GLenum buffer = GL_FRONT; + typedef std::vector Textures; + Textures textures; view.getCamera()->setProjectionMatrixAsPerspective(90.0f, 1.0, 1, 1000.0); osg::ref_ptr ifc = new LeiaIntialFrustumCallback; // set up the projection and view matrix uniforms - ifc->projectionMatrices.push_back(view.getCamera()->getProjectionMatrix()*osg::Matrixd::translate(-0.2, 0.0, 0.0)); - ifc->projectionMatrices.push_back(view.getCamera()->getProjectionMatrix()*osg::Matrixd::translate(-0.1, 0.0, 0.0)); - ifc->projectionMatrices.push_back(view.getCamera()->getProjectionMatrix()*osg::Matrixd::translate(0.1, 0.0, 0.0)); - ifc->projectionMatrices.push_back(view.getCamera()->getProjectionMatrix()*osg::Matrixd::translate(0.2, 0.0, 0.0)); + double delta = 0.2; + for(size_t i=0; i<4; ++i) + { + double y = delta*(static_cast(i)-1.5); + ifc->projectionMatrices.push_back(view.getCamera()->getProjectionMatrix()*osg::Matrixd::translate(-delta*2.0, y, 0.0)); + ifc->projectionMatrices.push_back(view.getCamera()->getProjectionMatrix()*osg::Matrixd::translate(-delta, y, 0.0)); + ifc->projectionMatrices.push_back(view.getCamera()->getProjectionMatrix()*osg::Matrixd::translate(delta, y, 0.0)); + ifc->projectionMatrices.push_back(view.getCamera()->getProjectionMatrix()*osg::Matrixd::translate(delta*2.0, y, 0.0)); + + textures.push_back(TexturePair(tex_width, tex_height, 4)); + } ifc->computeClipSpaceBound(*(view.getCamera())); + view.addEventHandler(new LeiaToggleFrustumHandler(ifc.get())); + + // set up the shaders + osg::ref_ptr multiview_program = new osg::Program(); + { + std::string vsFileName("leia.vert"); + std::string fsFileName("leia.frag"); + + osg::ref_ptr vertexShader = osgDB::readRefShaderFile( osg::Shader::VERTEX, vsFileName) ; + if (vertexShader.get()) multiview_program->addShader( vertexShader.get() ); + + osg::ref_ptr fragmentShader = osgDB::readRefShaderFile( osg::Shader::FRAGMENT, fsFileName) ; + if (fragmentShader.get()) multiview_program->addShader( fragmentShader.get() ); + } + // left/right eye multiviewOVR camera + for(unsigned int row=0; rowgetState()->setUseModelViewAndProjectionUniforms(true); - gc->getState()->setUseVertexAttributeAliasing(true); - //osg::DisplaySettings::instance()->setShaderHint(osg::DisplaySettings::SHADER_GL3); + TexturePair& texturePair = textures[row]; osg::ref_ptr camera = new osg::Camera; camera->setName("multview eye camera"); camera->setGraphicsContext(gc.get()); camera->setViewport(new osg::Viewport(0,0,camera_width, camera_height)); - camera->setDrawBuffer(buffer); - camera->setReadBuffer(buffer); + camera->setDrawBuffer(GL_FRONT); + camera->setReadBuffer(GL_FRONT); camera->setAllowEventFocus(false); - - - - view.addEventHandler(new LeiaToggleFrustumHandler(ifc.get())); + camera->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT); // assign custom frustum callback camera->setInitialFrustumCallback(ifc.get()); - - // tell the camera to use OpenGL frame buffer object where supported. - camera->setRenderTargetImplementation(renderTargetImplementation); - // attach the texture and use it as the color buffer, specify that the face is controlled by the multiview extension - camera->attach(osg::Camera::COLOR_BUFFER, color_texture_0, 0, osg::Camera::FACE_CONTROLLED_BY_MULTIVIEW_SHADER); - camera->attach(osg::Camera::DEPTH_BUFFER, depth_texture_0, 0, osg::Camera::FACE_CONTROLLED_BY_MULTIVIEW_SHADER); - + camera->attach(osg::Camera::COLOR_BUFFER, texturePair.color, 0, osg::Camera::FACE_CONTROLLED_BY_MULTIVIEW_SHADER); + camera->attach(osg::Camera::DEPTH_BUFFER, texturePair.depth, 0, osg::Camera::FACE_CONTROLLED_BY_MULTIVIEW_SHADER); view.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd()); - osg::StateSet* stateset = camera->getOrCreateStateSet(); - { - - osg::ref_ptr projectionMatrices_uniform = new osg::Uniform(osg::Uniform::FLOAT_MAT4, "osg_ProjectionMatrices", ifc->projectionMatrices.size()); - stateset->addUniform(projectionMatrices_uniform); - - for(size_t i=0; iprojectionMatrices.size(); ++i) - { - projectionMatrices_uniform->setElement(i, ifc->projectionMatrices[i]); - } - - // set up the shaders - osg::ref_ptr program = new osg::Program(); - stateset->setAttribute(program.get(), osg::StateAttribute::ON); - std::string vsFileName("leia.vert"); - std::string fsFileName("leia.frag"); + // setup state for RTT Camera + osg::StateSet* stateset = camera->getOrCreateStateSet(); + stateset->setAttribute(multiview_program.get(), osg::StateAttribute::ON); - osg::ref_ptr vertexShader = osgDB::readRefShaderFile( osg::Shader::VERTEX, vsFileName) ; - if (vertexShader.get()) program->addShader( vertexShader.get() ); + osg::ref_ptr projectionMatrices_uniform = new osg::Uniform(osg::Uniform::FLOAT_MAT4, "osg_ProjectionMatrices", 4); + stateset->addUniform(projectionMatrices_uniform); - osg::ref_ptr fragmentShader = osgDB::readRefShaderFile( osg::Shader::FRAGMENT, fsFileName) ; - if (fragmentShader.get()) program->addShader( fragmentShader.get() ); + for(size_t i=0; i<4; ++i) + { + projectionMatrices_uniform->setElement(i, ifc->projectionMatrices[row*4 + i]); } - } @@ -389,21 +400,30 @@ void Leia::configure(osgViewer::View& view) const // new we need to add the texture to the mesh, we do so by creating a // StateSet to contain the Texture StateAttribute. osg::StateSet* stateset = mesh->getOrCreateStateSet(); - stateset->setTextureAttribute(0, color_texture_0, osg::StateAttribute::ON); stateset->setMode(GL_LIGHTING, osg::StateAttribute::OFF); + for(size_t row = 0; rowsetTextureAttribute(row, textures[row].color, osg::StateAttribute::ON); + + osg::MakeString uniformName; + uniformName<<"texture_"<addUniform( new osg::Uniform(uniformName.str().c_str(), int(row))); + } + { osg::ref_ptr program = new osg::Program(); stateset->setAttribute(program.get(), osg::StateAttribute::ON); - std::string vsFileName("standard.vert"); - std::string fsFileName("standard.frag"); + std::string vsFileName("leia_interleave.vert"); + std::string fsFileName("leia_interleave.frag"); osg::ref_ptr vertexShader = osgDB::readRefShaderFile( osg::Shader::VERTEX, vsFileName) ; if (vertexShader.get()) program->addShader( vertexShader.get() ); osg::ref_ptr fragmentShader = osgDB::readRefShaderFile( osg::Shader::FRAGMENT, fsFileName) ; if (fragmentShader.get()) program->addShader( fragmentShader.get() ); + } osg::ref_ptr camera = new osg::Camera; @@ -426,9 +446,9 @@ void Leia::configure(osgViewer::View& view) const // add subgraph to render camera->addChild(mesh.get()); - camera->setName("DistortionCorrectionCamera"); + camera->setName("Row"); - osgDB::writeNodeFile(*mesh, "mesh.osgt"); + osgDB::writeNodeFile(*camera, "camera.osgt"); view.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd(), false); } diff --git a/examples/osgmultiviewOVR/Leia.h b/examples/osgmultiviewOVR/Leia.h index 4365824410b..c28901a4120 100644 --- a/examples/osgmultiviewOVR/Leia.h +++ b/examples/osgmultiviewOVR/Leia.h @@ -21,7 +21,7 @@ class Leia : public osgViewer::ViewConfig void setScreenNum(unsigned int n) { _screenNum = n; } unsigned int getScreenNum() const { return _screenNum; } - + protected: osg::ref_ptr createTexture2DArray(unsigned int width, unsigned int height, unsigned int depth, GLenum format) const; diff --git a/examples/osgmultiviewOVR/leia_interleave.frag b/examples/osgmultiviewOVR/leia_interleave.frag new file mode 100644 index 00000000000..f0f7d7e79cc --- /dev/null +++ b/examples/osgmultiviewOVR/leia_interleave.frag @@ -0,0 +1,27 @@ +#extension GL_EXT_texture_array : enable + +uniform sampler2DArray texture_0; +uniform sampler2DArray texture_1; +uniform sampler2DArray texture_2; +uniform sampler2DArray texture_3; + +varying vec2 texcoord; + +void main(void) +{ + float WINDOW_WIDTH = 1920.0; + float WINDOW_HEIGHT = 1080.0; + + float cell_width = WINDOW_WIDTH/4.0; + float cell_height = WINDOW_HEIGHT/4.0; + + float i = floor(gl_FragCoord.x / cell_width); + float j = floor(gl_FragCoord.y / cell_height); + + vec3 tc = vec3(gl_FragCoord.x / cell_width - i, gl_FragCoord.y / cell_height - j, i); + + if (j < 1.0) gl_FragColor = texture2DArray( texture_0, tc); + else if (j < 2.0) gl_FragColor = texture2DArray( texture_1, tc); + else if (j < 3.0) gl_FragColor = texture2DArray( texture_2, tc); + else gl_FragColor = texture2DArray( texture_3, tc); +} diff --git a/examples/osgmultiviewOVR/leia_interleave.vert b/examples/osgmultiviewOVR/leia_interleave.vert new file mode 100644 index 00000000000..2ae4c663591 --- /dev/null +++ b/examples/osgmultiviewOVR/leia_interleave.vert @@ -0,0 +1,7 @@ +varying vec2 texcoord; + +void main(void) +{ + texcoord = gl_MultiTexCoord0.xy; + gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; +} From e9c8e3d4a799575586f44e2df11ed6a031fdc014 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 31 Dec 2020 11:47:56 +0000 Subject: [PATCH 29/40] Added #Pragma(tic) shader composition for passing widht and height into the shader --- examples/osgmultiviewOVR/Leia.cpp | 8 ++++++++ examples/osgmultiviewOVR/leia_interleave.frag | 5 ++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/examples/osgmultiviewOVR/Leia.cpp b/examples/osgmultiviewOVR/Leia.cpp index 09dfff25f0d..32d053a9d6e 100644 --- a/examples/osgmultiviewOVR/Leia.cpp +++ b/examples/osgmultiviewOVR/Leia.cpp @@ -415,6 +415,14 @@ void Leia::configure(osgViewer::View& view) const osg::ref_ptr program = new osg::Program(); stateset->setAttribute(program.get(), osg::StateAttribute::ON); + osg::MakeString defineValue; + defineValue << width; + stateset->setDefine("WINDOW_WIDTH", defineValue.str()); + + defineValue.clear(); + defineValue << height; + stateset->setDefine("WINDOW_HEIGHT", defineValue.str()); + std::string vsFileName("leia_interleave.vert"); std::string fsFileName("leia_interleave.frag"); diff --git a/examples/osgmultiviewOVR/leia_interleave.frag b/examples/osgmultiviewOVR/leia_interleave.frag index f0f7d7e79cc..b4c98fdff30 100644 --- a/examples/osgmultiviewOVR/leia_interleave.frag +++ b/examples/osgmultiviewOVR/leia_interleave.frag @@ -1,5 +1,7 @@ #extension GL_EXT_texture_array : enable +#pragma import_defines ( WINDOW_WIDTH, WINDOW_HEIGHT ) + uniform sampler2DArray texture_0; uniform sampler2DArray texture_1; uniform sampler2DArray texture_2; @@ -9,9 +11,6 @@ varying vec2 texcoord; void main(void) { - float WINDOW_WIDTH = 1920.0; - float WINDOW_HEIGHT = 1080.0; - float cell_width = WINDOW_WIDTH/4.0; float cell_height = WINDOW_HEIGHT/4.0; From 3d28edf52881be142a5a9ffb87e986f6c5e5f6be Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 31 Dec 2020 15:06:30 +0000 Subject: [PATCH 30/40] Added intleave shader and more flexible projection matrix setup. --- examples/osgmultiviewOVR/Leia.cpp | 1 + examples/osgmultiviewOVR/leia.vert | 17 ++++++++++---- examples/osgmultiviewOVR/leia_interleave.frag | 23 ++++++++++++++++++- 3 files changed, 35 insertions(+), 6 deletions(-) diff --git a/examples/osgmultiviewOVR/Leia.cpp b/examples/osgmultiviewOVR/Leia.cpp index 32d053a9d6e..fc6c98cf06c 100644 --- a/examples/osgmultiviewOVR/Leia.cpp +++ b/examples/osgmultiviewOVR/Leia.cpp @@ -382,6 +382,7 @@ void Leia::configure(osgViewer::View& view) const // setup state for RTT Camera osg::StateSet* stateset = camera->getOrCreateStateSet(); stateset->setAttribute(multiview_program.get(), osg::StateAttribute::ON); + stateset->setDefine("NUM_VIEWS", "4"); osg::ref_ptr projectionMatrices_uniform = new osg::Uniform(osg::Uniform::FLOAT_MAT4, "osg_ProjectionMatrices", 4); stateset->addUniform(projectionMatrices_uniform); diff --git a/examples/osgmultiviewOVR/leia.vert b/examples/osgmultiviewOVR/leia.vert index 8d785806248..64e90f89397 100644 --- a/examples/osgmultiviewOVR/leia.vert +++ b/examples/osgmultiviewOVR/leia.vert @@ -1,12 +1,19 @@ #version 330 -#extension GL_OVR_multiview2 : enable -#define NUM_VIEWS 4 +#pragma import_defines ( NUM_VIEWS ) -layout(num_views = NUM_VIEWS) in; +#ifdef NUM_VIEWS + #extension GL_OVR_multiview2 : enable + + layout(num_views = NUM_VIEWS) in; + + uniform mat4 osg_ProjectionMatrices[NUM_VIEWS]; + #define osg_ProjectionMatrix osg_ProjectionMatrices[gl_ViewID_OVR] +#else + uniform mat4 osg_ProjectionMatrix; +#endif uniform mat4 osg_ModelViewMatrix; -uniform mat4 osg_ProjectionMatrices[NUM_VIEWS]; in vec4 osg_Vertex; in vec4 osg_Color; @@ -17,7 +24,7 @@ out vec2 texcoord; void main(void) { - mat4 mvp = osg_ProjectionMatrices[gl_ViewID_OVR] * osg_ModelViewMatrix; + mat4 mvp = osg_ProjectionMatrix * osg_ModelViewMatrix; color = osg_Color; texcoord = osg_MultiTexCoord0.xy; diff --git a/examples/osgmultiviewOVR/leia_interleave.frag b/examples/osgmultiviewOVR/leia_interleave.frag index b4c98fdff30..a425b49a9de 100644 --- a/examples/osgmultiviewOVR/leia_interleave.frag +++ b/examples/osgmultiviewOVR/leia_interleave.frag @@ -1,6 +1,6 @@ #extension GL_EXT_texture_array : enable -#pragma import_defines ( WINDOW_WIDTH, WINDOW_HEIGHT ) +#pragma import_defines ( WINDOW_WIDTH, WINDOW_HEIGHT, INTERLEAVE ) uniform sampler2DArray texture_0; uniform sampler2DArray texture_1; @@ -9,8 +9,28 @@ uniform sampler2DArray texture_3; varying vec2 texcoord; +#ifndef WINDOW_WIDTH + #define WINDOW_WIDTH 1920 + #define WINDOW_HEIGHT 1080 +#endif + +#define INTERLEAVE + void main(void) { +#ifdef INTERLEAVE + + float i = mod(gl_FragCoord.x, 4.0); + float j = mod(gl_FragCoord.y, 4.0); + + vec3 tc = vec3(gl_FragCoord.x / WINDOW_WIDTH, gl_FragCoord.y / WINDOW_HEIGHT, i); + + if (j < 1.0) gl_FragColor = texture2DArray( texture_0, tc); + else if (j < 2.0) gl_FragColor = texture2DArray( texture_1, tc); + else if (j < 3.0) gl_FragColor = texture2DArray( texture_2, tc); + else gl_FragColor = texture2DArray( texture_3, tc); + +#else float cell_width = WINDOW_WIDTH/4.0; float cell_height = WINDOW_HEIGHT/4.0; @@ -23,4 +43,5 @@ void main(void) else if (j < 2.0) gl_FragColor = texture2DArray( texture_1, tc); else if (j < 3.0) gl_FragColor = texture2DArray( texture_2, tc); else gl_FragColor = texture2DArray( texture_3, tc); +#endif } From a39f8775662f89061018e5404f20b4aa92084d08 Mon Sep 17 00:00:00 2001 From: tomhog Date: Fri, 19 Feb 2021 12:39:13 +0000 Subject: [PATCH 31/40] Setting numViews value in glFramebufferTextureMultiviewOVR call, same as standard texture2d arrays --- src/osg/FrameBufferObject.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/osg/FrameBufferObject.cpp b/src/osg/FrameBufferObject.cpp index b53b1fdd948..76f6f6e8735 100644 --- a/src/osg/FrameBufferObject.cpp +++ b/src/osg/FrameBufferObject.cpp @@ -540,7 +540,7 @@ void FrameBufferAttachment::attach(State &state, GLenum target, GLenum attachmen { if (ext->glFramebufferTextureMultiviewOVR) { - ext->glFramebufferTextureMultiviewOVR(target, attachment_point, tobj->id(), _ximpl->level, 0, 2); + ext->glFramebufferTextureMultiviewOVR(target, attachment_point, tobj->id(), _ximpl->level, 0, _ximpl->textureTarget->getTextureDepth()); } } else From a74dd06243b1ca23db567ee716a0f7e2a8c1ac19 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 22 Feb 2021 18:17:09 +0000 Subject: [PATCH 32/40] Removed dbug output --- src/osgPlugins/tf/ReaderWriterTF.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/osgPlugins/tf/ReaderWriterTF.cpp b/src/osgPlugins/tf/ReaderWriterTF.cpp index 7146de79694..618581f6182 100644 --- a/src/osgPlugins/tf/ReaderWriterTF.cpp +++ b/src/osgPlugins/tf/ReaderWriterTF.cpp @@ -162,8 +162,6 @@ class ReaderWriterTF : public osgDB::ReaderWriter virtual WriteResult writeObject(const osg::Object& object, const std::string& fileName, const osgDB::ReaderWriter::Options*) const { - OSG_NOTICE<<"ReaderWriterTF::writeObject"<(&object); if (!tf) return WriteResult::FILE_NOT_HANDLED; From b218d91ea1a801e5cb19474de91c24968df7c9d7 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 22 Feb 2021 18:18:14 +0000 Subject: [PATCH 33/40] Revmoed debug output --- src/osgPlugins/trk/ReaderWriterTRK.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/osgPlugins/trk/ReaderWriterTRK.cpp b/src/osgPlugins/trk/ReaderWriterTRK.cpp index 0150eb2fc9b..2346fac681a 100644 --- a/src/osgPlugins/trk/ReaderWriterTRK.cpp +++ b/src/osgPlugins/trk/ReaderWriterTRK.cpp @@ -189,8 +189,6 @@ class ReaderWriterTRK : public osgDB::ReaderWriter ReaderWriterTRK() { supportsExtension("trk","Track file format"); - - OSG_NOTICE<<"sizeof(TrkHeader)="< Date: Thu, 29 Apr 2021 00:55:37 +0200 Subject: [PATCH 34/40] Add move constructor and move assignment operator to ref_ptr Use conditional compilation to make it work only with C++11 support. --- include/osg/ref_ptr | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/include/osg/ref_ptr b/include/osg/ref_ptr index 693e98e2ce6..d79cde39708 100644 --- a/include/osg/ref_ptr +++ b/include/osg/ref_ptr @@ -22,6 +22,10 @@ #include #endif +#if __cplusplus >= 201103L +#include +#endif + namespace osg { template class observer_ptr; @@ -36,6 +40,9 @@ class ref_ptr ref_ptr() : _ptr(0) {} ref_ptr(T* ptr) : _ptr(ptr) { if (_ptr) _ptr->ref(); } ref_ptr(const ref_ptr& rp) : _ptr(rp._ptr) { if (_ptr) _ptr->ref(); } +#if __cplusplus >= 201103L + ref_ptr(ref_ptr&& rp) noexcept : _ptr(rp._ptr) { rp._ptr = 0; } +#endif template ref_ptr(const ref_ptr& rp) : _ptr(rp._ptr) { if (_ptr) _ptr->ref(); } ref_ptr(observer_ptr& optr) : _ptr(0) { optr.lock(*this); } ~ref_ptr() { if (_ptr) _ptr->unref(); _ptr = 0; } @@ -52,6 +59,17 @@ class ref_ptr return *this; } +#if __cplusplus >= 201103L + template ref_ptr& operator = (ref_ptr&& rp) + { + if (_ptr == rp._ptr) return *this; + if (_ptr != nullptr) _ptr->unref(); + _ptr = rp._ptr; + rp._ptr = nullptr; + return *this; + } +#endif + inline ref_ptr& operator = (T* ptr) { if (_ptr==ptr) return *this; From 8a8c03cd5ae508e7ab1b36ffacb1a49e31b27f18 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 6 May 2021 10:20:16 +0100 Subject: [PATCH 35/40] Removed unnedded include --- include/osg/ref_ptr | 4 ---- 1 file changed, 4 deletions(-) diff --git a/include/osg/ref_ptr b/include/osg/ref_ptr index d79cde39708..eb8e3666250 100644 --- a/include/osg/ref_ptr +++ b/include/osg/ref_ptr @@ -22,10 +22,6 @@ #include #endif -#if __cplusplus >= 201103L -#include -#endif - namespace osg { template class observer_ptr; From af49c20fd20bbb0d04fab0786bdd4b838a3d2036 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 31 Aug 2021 16:21:18 +0100 Subject: [PATCH 36/40] Added alias from asc to 3dc --- src/osgDB/Registry.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/osgDB/Registry.cpp b/src/osgDB/Registry.cpp index 4a36c40d27d..c47439b611e 100644 --- a/src/osgDB/Registry.cpp +++ b/src/osgDB/Registry.cpp @@ -460,6 +460,8 @@ Registry::Registry() addFileExtensionAlias("igs", "opencascade"); addFileExtensionAlias("iges", "opencascade"); + // asc point could files. + addFileExtensionAlias("asc", "3dc"); // add built-in mime-type extension mappings for( int i=0; ; i+=2 ) From c36afcc008472a939921f5e157c154ef47d82691 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 9 Sep 2021 08:28:06 +0100 Subject: [PATCH 37/40] Fixed build error with debug code path --- src/osgShadow/ParallelSplitShadowMap.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/osgShadow/ParallelSplitShadowMap.cpp b/src/osgShadow/ParallelSplitShadowMap.cpp index e627d8fee63..3c73e9470d9 100644 --- a/src/osgShadow/ParallelSplitShadowMap.cpp +++ b/src/osgShadow/ParallelSplitShadowMap.cpp @@ -609,7 +609,7 @@ void ParallelSplitShadowMap::cull(osgUtil::CullVisitor& cv){ PSSMShadowSplitTextureMap::iterator tm_itr=_PSSMShadowSplitTextureMap.begin(); #else // do traversal of shadow receiving scene which does need to be decorated by the shadow map - for (PSSMShadowSplitTextureMap::iterator tm_itr=_PSSMShadowSplitTextureMap.begin();it!=_PSSMShadowSplitTextureMap.end();it++) + for (PSSMShadowSplitTextureMap::iterator tm_itr=_PSSMShadowSplitTextureMap.begin();tm_itr!=_PSSMShadowSplitTextureMap.end();tm_itr++) #endif { PSSMShadowSplitTexture pssmShadowSplitTexture = tm_itr->second; From 226bdd0d58884ef2080d18adcbca9cb5327bc5f9 Mon Sep 17 00:00:00 2001 From: Bo Svensson <90132211+bosvensson1@users.noreply.github.com> Date: Thu, 7 Oct 2021 13:57:01 +0000 Subject: [PATCH 38/40] removes invalid glReadBuffer calls --- src/osgUtil/RenderStage.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/osgUtil/RenderStage.cpp b/src/osgUtil/RenderStage.cpp index 05f0c3cfc8c..0ed49909c97 100644 --- a/src/osgUtil/RenderStage.cpp +++ b/src/osgUtil/RenderStage.cpp @@ -583,9 +583,7 @@ void RenderStage::runCameraSetUp(osg::RenderInfo& renderInfo) { #if !defined(OSG_GLES1_AVAILABLE) && !defined(OSG_GLES2_AVAILABLE) && !defined(OSG_GLES3_AVAILABLE) setDrawBuffer( GL_NONE, true ); - setReadBuffer( GL_NONE, true ); state.glDrawBuffer( GL_NONE ); - state.glReadBuffer( GL_NONE ); #endif } From d2ee5aa8f2f479eb14880c637cffbea37532607a Mon Sep 17 00:00:00 2001 From: Mads Buvik Sandvei Date: Thu, 25 Aug 2022 23:26:25 +0200 Subject: [PATCH 39/40] MultiView: Recreate resolve layers if user calls RenderStage::setFrameBufferObject() or RenderStage::setMultisampleResolveFramebufferObject --- .../Windows/OpenSceneGraphVersionInfo.rc | 31 +++ .../Windows/OpenThreadsVersionInfo.rc | 31 +++ build/include/OpenThreads/Config | 34 +++ build/include/OpenThreads/Version | 38 ++++ build/include/osg/Config | 42 ++++ build/include/osg/GL | 194 ++++++++++++++++++ build/include/osg/Version | 73 +++++++ .../Windows/OpenSceneGraphVersionInfo.rc | 31 +++ .../Windows/OpenThreadsVersionInfo.rc | 31 +++ build2019/include/OpenThreads/Config | 34 +++ build2019/include/OpenThreads/Version | 38 ++++ build2019/include/osg/Config | 42 ++++ build2019/include/osg/GL | 194 ++++++++++++++++++ build2019/include/osg/Version | 73 +++++++ include/osgUtil/RenderStage | 4 +- src/osgUtil/RenderStage.cpp | 152 ++++++++++---- 16 files changed, 1005 insertions(+), 37 deletions(-) create mode 100644 build/PlatformSpecifics/Windows/OpenSceneGraphVersionInfo.rc create mode 100644 build/PlatformSpecifics/Windows/OpenThreadsVersionInfo.rc create mode 100644 build/include/OpenThreads/Config create mode 100644 build/include/OpenThreads/Version create mode 100644 build/include/osg/Config create mode 100644 build/include/osg/GL create mode 100644 build/include/osg/Version create mode 100644 build2019/PlatformSpecifics/Windows/OpenSceneGraphVersionInfo.rc create mode 100644 build2019/PlatformSpecifics/Windows/OpenThreadsVersionInfo.rc create mode 100644 build2019/include/OpenThreads/Config create mode 100644 build2019/include/OpenThreads/Version create mode 100644 build2019/include/osg/Config create mode 100644 build2019/include/osg/GL create mode 100644 build2019/include/osg/Version diff --git a/build/PlatformSpecifics/Windows/OpenSceneGraphVersionInfo.rc b/build/PlatformSpecifics/Windows/OpenSceneGraphVersionInfo.rc new file mode 100644 index 00000000000..c2073ff7960 --- /dev/null +++ b/build/PlatformSpecifics/Windows/OpenSceneGraphVersionInfo.rc @@ -0,0 +1,31 @@ +1 VERSIONINFO + FILEVERSION 3, 6, 5, 162 + PRODUCTVERSION 3, 6, 5, 162 + FILEFLAGSMASK 0x17L +#ifdef _DEBUG + FILEFLAGS 0x1L +#else + FILEFLAGS 0x0L +#endif + FILEOS 0x4L + FILETYPE 0x0L + FILESUBTYPE 0x0L +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904b0" + BEGIN + VALUE "FileDescription", "OpenSceneGraph Binary" + VALUE "FileVersion", "3, 6, 5, 162" + VALUE "InternalName", "OSG" + VALUE "LegalCopyright", "Copyright (C) 2009" + VALUE "OriginalFilename", "" + VALUE "ProductName", "OpenSceneGraph" + VALUE "ProductVersion", "3, 6, 5, 162" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x409, 1200 + END +END diff --git a/build/PlatformSpecifics/Windows/OpenThreadsVersionInfo.rc b/build/PlatformSpecifics/Windows/OpenThreadsVersionInfo.rc new file mode 100644 index 00000000000..205ba181caf --- /dev/null +++ b/build/PlatformSpecifics/Windows/OpenThreadsVersionInfo.rc @@ -0,0 +1,31 @@ +1 VERSIONINFO + FILEVERSION 3, 3, 1, 21 + PRODUCTVERSION 3, 3, 1, 21 + FILEFLAGSMASK 0x17L +#ifdef _DEBUG + FILEFLAGS 0x1L +#else + FILEFLAGS 0x0L +#endif + FILEOS 0x4L + FILETYPE 0x0L + FILESUBTYPE 0x0L +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904b0" + BEGIN + VALUE "FileDescription", "OPENTHREADS Binary" + VALUE "FileVersion", "3, 3, 1, 21" + VALUE "InternalName", "OSG" + VALUE "LegalCopyright", "Copyright (C) 2009" + VALUE "OriginalFilename", "" + VALUE "ProductName", "OPENTHREADS" + VALUE "ProductVersion", "3, 3, 1, 21" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x409, 1200 + END +END diff --git a/build/include/OpenThreads/Config b/build/include/OpenThreads/Config new file mode 100644 index 00000000000..713905d64c1 --- /dev/null +++ b/build/include/OpenThreads/Config @@ -0,0 +1,34 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) 2008 Robert Osfield + * + * 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 + * (at your option) any later version. The full license is in LICENSE file + * included with this distribution, and on the openscenegraph.org website. + * + * This library 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. See the + * OpenSceneGraph Public License for more details. +*/ + +/**************************************************************************** + * THIS FILE IS AUTOGENERATED BY CMAKE. DO NOT EDIT! + ****************************************************************************/ + +/* Changes to the configuration reflected here can be made with ccmake on + * unix or with cmake-gui on windows. Alternatively you can use cmake's -D + * or -P switches to set some configuration values at cmake configuration time. + */ + +#ifndef _OPENTHREADS_CONFIG +#define _OPENTHREADS_CONFIG + +/* #undef _OPENTHREADS_ATOMIC_USE_GCC_BUILTINS */ +/* #undef _OPENTHREADS_ATOMIC_USE_MIPOSPRO_BUILTINS */ +/* #undef _OPENTHREADS_ATOMIC_USE_SUN */ +#define _OPENTHREADS_ATOMIC_USE_WIN32_INTERLOCKED +/* #undef _OPENTHREADS_ATOMIC_USE_BSD_ATOMIC */ +/* #undef _OPENTHREADS_ATOMIC_USE_MUTEX */ +/* #undef OT_LIBRARY_STATIC */ + +#endif diff --git a/build/include/OpenThreads/Version b/build/include/OpenThreads/Version new file mode 100644 index 00000000000..1381595fd85 --- /dev/null +++ b/build/include/OpenThreads/Version @@ -0,0 +1,38 @@ +/* -*-c++-*- OpenThreads library, Copyright (C) 2002 - 2007 The Open Thread Group + * + * 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 + * (at your option) any later version. The full license is in LICENSE file + * included with this distribution, and on the openscenegraph.org website. + * + * This library 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. See the + * OpenSceneGraph Public License for more details. +*/ + +#ifndef OPENTHREADS_VERSION +#define OPENTHREADS_VERSION 1 + +#include + +extern "C" { + +#define OPENTHREADS_MAJOR_VERSION 3 +#define OPENTHREADS_MINOR_VERSION 3 +#define OPENTHREADS_PATCH_VERSION 1 +#define OPENTHREADS_SOVERSION 21 + +/** OpenThreadsGetVersion() returns the library version number. + * Numbering convention : OpenThreads-1.0 will return 1.0 from OpenThreadsGetVersion. */ +extern OPENTHREAD_EXPORT_DIRECTIVE const char* OpenThreadsGetVersion(); + +/** The OpenThreadsGetSOVersion() method returns the OpenSceneGraph soversion number. */ +extern OPENTHREAD_EXPORT_DIRECTIVE const char* OpenThreadsGetSOVersion(); + +/** The OpenThreadsGetLibraryName() method returns the library name in human-friendly form. */ +extern OPENTHREAD_EXPORT_DIRECTIVE const char* OpenThreadsGetLibraryName(); + +} + +#endif diff --git a/build/include/osg/Config b/build/include/osg/Config new file mode 100644 index 00000000000..d5e0300f065 --- /dev/null +++ b/build/include/osg/Config @@ -0,0 +1,42 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) 2008-2009 Robert Osfield + * + * 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 + * (at your option) any later version. The full license is in LICENSE file + * included with this distribution, and on the openscenegraph.org website. + * + * This library 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. See the + * OpenSceneGraph Public License for more details. +*/ + +/**************************************************************************** + * THIS FILE IS AUTOGENERATED BY CMAKE. DO NOT EDIT! + ****************************************************************************/ + +/* Changes to the configuration reflected here can be made with ccmake on + * unix or with cmake-gui on windows. Alternatively you can use cmake's -D + * or -P switches to set some configuration values at cmake configuration time. + */ + +#ifndef OSG_CONFIG +#define OSG_CONFIG 1 + +/* #undef OSG_NOTIFY_DISABLED */ +/* #undef OSG_USE_FLOAT_MATRIX */ +/* #undef OSG_USE_FLOAT_PLANE */ +#define OSG_USE_FLOAT_BOUNDINGSPHERE +#define OSG_USE_FLOAT_BOUNDINGBOX +/* #undef OSG_USE_FLOAT_QUAT */ +#define OSG_USE_REF_PTR_IMPLICIT_OUTPUT_CONVERSION +/* #undef OSG_USE_REF_PTR_SAFE_DEREFERENCE */ +/* #undef OSG_USE_UTF8_FILENAME */ +#define OSG_DISABLE_MSVC_WARNINGS +#define OSG_PROVIDE_READFILE +#define OSG_USE_DEPRECATED_API +#define OSG_ENVVAR_SUPPORTED +/* #undef OSG_WINDOWING_SYSTEM_CARBON */ +/* #undef OSG_WINDOWING_SYSTEM_NONE */ + +#endif diff --git a/build/include/osg/GL b/build/include/osg/GL new file mode 100644 index 00000000000..f678ba46342 --- /dev/null +++ b/build/include/osg/GL @@ -0,0 +1,194 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2009 Robert Osfield + * + * 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 + * (at your option) any later version. The full license is in LICENSE file + * included with this distribution, and on the openscenegraph.org website. + * + * This library 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. See the + * OpenSceneGraph Public License for more details. +*/ + +#ifndef OSG_OPENGL +#define OSG_OPENGL 1 + +#include +#include +#include + +#define OSG_GL1_AVAILABLE +#define OSG_GL2_AVAILABLE +/* #undef OSG_GL3_AVAILABLE */ +/* #undef OSG_GLES1_AVAILABLE */ +/* #undef OSG_GLES2_AVAILABLE */ +/* #undef OSG_GLES3_AVAILABLE */ +/* #undef OSG_GL_LIBRARY_STATIC */ +#define OSG_GL_DISPLAYLISTS_AVAILABLE +#define OSG_GL_MATRICES_AVAILABLE +#define OSG_GL_VERTEX_FUNCS_AVAILABLE +#define OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE +#define OSG_GL_FIXED_FUNCTION_AVAILABLE +/* #undef GL_HEADER_HAS_GLINT64 */ +/* #undef GL_HEADER_HAS_GLUINT64 */ + +#define OSG_GL1_FEATURES 1 +#define OSG_GL2_FEATURES 1 +#define OSG_GL3_FEATURES 0 +#define OSG_GLES1_FEATURES 0 +#define OSG_GLES2_FEATURES 0 +#define OSG_GLES3_FEATURES 0 +#define OSG_GL_CONTEXT_VERSION "1.0" + + +#ifndef _WIN32 + + // Required for compatibility with glext.h style function definitions of + // OpenGL extensions, such as in src/osg/Point.cpp. + #ifndef APIENTRY + #define APIENTRY + #endif + +#else // _WIN32 + + #if defined(__CYGWIN__) || defined(__MINGW32__) + + #ifndef APIENTRY + #define GLUT_APIENTRY_DEFINED + #define APIENTRY __stdcall + #endif + // XXX This is from Win32's + #ifndef CALLBACK + #define CALLBACK __stdcall + #endif + + #else // ! __CYGWIN__ + + // Under Windows avoid including + // to avoid name space pollution, but Win32's + // needs APIENTRY and WINGDIAPI defined properly. + // XXX This is from Win32's + #ifndef APIENTRY + #define GLUT_APIENTRY_DEFINED + #if (_MSC_VER >= 800) || defined(_STDCALL_SUPPORTED) + #define WINAPI __stdcall + #define APIENTRY WINAPI + #else + #define APIENTRY + #endif + #endif + + // XXX This is from Win32's + #ifndef CALLBACK + #if (_MSC_VER >= 800) || defined(_STDCALL_SUPPORTED) + #define CALLBACK __stdcall + #else + #define CALLBACK + #endif + #endif + + #endif // __CYGWIN__ + + // XXX This is from Win32's and + #ifndef WINGDIAPI + #define GLUT_WINGDIAPI_DEFINED + #define DECLSPEC_IMPORT __declspec(dllimport) + #define WINGDIAPI DECLSPEC_IMPORT + #endif + + // XXX This is from Win32's + #if !defined(_WCHAR_T_DEFINED) && !(defined(__GNUC__)&&(__GNUC__ > 2)) + typedef unsigned short wchar_t; + #define _WCHAR_T_DEFINED + #endif + +#endif // _WIN32 + +#if defined(OSG_GL3_AVAILABLE) + #define GL3_PROTOTYPES 1 + #define GL_GLEXT_PROTOTYPES 1 +#endif + + +#include + + + +#ifndef GL_APIENTRY + #define GL_APIENTRY APIENTRY +#endif // GL_APIENTRY + + +#ifndef GL_HEADER_HAS_GLINT64 + typedef int64_t GLint64; +#endif + +#ifndef GL_HEADER_HAS_GLUINT64 + typedef uint64_t GLuint64; +#endif + +#ifdef OSG_GL_MATRICES_AVAILABLE + + inline void glLoadMatrix(const float* mat) { glLoadMatrixf(static_cast(mat)); } + inline void glMultMatrix(const float* mat) { glMultMatrixf(static_cast(mat)); } + + #ifdef OSG_GLES1_AVAILABLE + inline void glLoadMatrix(const double* mat) + { + GLfloat flt_mat[16]; + for(unsigned int i=0;i<16;++i) flt_mat[i] = mat[i]; + glLoadMatrixf(flt_mat); + } + + inline void glMultMatrix(const double* mat) + { + GLfloat flt_mat[16]; + for(unsigned int i=0;i<16;++i) flt_mat[i] = mat[i]; + glMultMatrixf(flt_mat); + } + + #else + inline void glLoadMatrix(const double* mat) { glLoadMatrixd(static_cast(mat)); } + inline void glMultMatrix(const double* mat) { glMultMatrixd(static_cast(mat)); } + #endif +#endif + +// add defines for OpenGL targets that don't define them, just to ease compatibility across targets +#ifndef GL_DOUBLE + #define GL_DOUBLE 0x140A + typedef double GLdouble; +#endif + +#ifndef GL_INT + #define GL_INT 0x1404 +#endif + +#ifndef GL_UNSIGNED_INT + #define GL_UNSIGNED_INT 0x1405 +#endif + +#ifndef GL_NONE + // OpenGL ES1 doesn't provide GL_NONE + #define GL_NONE 0x0 +#endif + +#if defined(OSG_GLES1_AVAILABLE) || defined(OSG_GLES2_AVAILABLE) || defined(OSG_GLES3_AVAILABLE) + //GLES defines (OES) + #define GL_RGB8_OES 0x8051 + #define GL_RGBA8_OES 0x8058 +#endif + +#if defined(OSG_GLES1_AVAILABLE) || defined(OSG_GLES2_AVAILABLE) || defined(OSG_GLES3_AVAILABLE) || defined(OSG_GL3_AVAILABLE) + #define GL_POLYGON 0x0009 + #define GL_QUADS 0x0007 + #define GL_QUAD_STRIP 0x0008 +#endif + +#if defined(OSG_GL3_AVAILABLE) + #define GL_LUMINANCE 0x1909 + #define GL_LUMINANCE_ALPHA 0x190A +#endif + + +#endif diff --git a/build/include/osg/Version b/build/include/osg/Version new file mode 100644 index 00000000000..def75985126 --- /dev/null +++ b/build/include/osg/Version @@ -0,0 +1,73 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2009 Robert Osfield + * + * 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 + * (at your option) any later version. The full license is in LICENSE file + * included with this distribution, and on the openscenegraph.org website. + * + * This library 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. See the + * OpenSceneGraph Public License for more details. +*/ + +#ifndef OSG_VERSION +#define OSG_VERSION 1 + +#include + +extern "C" { + +#define OPENSCENEGRAPH_MAJOR_VERSION 3 +#define OPENSCENEGRAPH_MINOR_VERSION 6 +#define OPENSCENEGRAPH_PATCH_VERSION 5 +#define OPENSCENEGRAPH_SOVERSION 162 + +/* Convenience macro that can be used to decide whether a feature is present or not i.e. + * #if OSG_MIN_VERSION_REQUIRED(2,9,5) + * your code here + * #endif + */ +#define OSG_MIN_VERSION_REQUIRED(MAJOR, MINOR, PATCH) ((OPENSCENEGRAPH_MAJOR_VERSION>MAJOR) || (OPENSCENEGRAPH_MAJOR_VERSION==MAJOR && (OPENSCENEGRAPH_MINOR_VERSION>MINOR || (OPENSCENEGRAPH_MINOR_VERSION==MINOR && OPENSCENEGRAPH_PATCH_VERSION>=PATCH)))) +#define OSG_VERSION_LESS_THAN(MAJOR, MINOR, PATCH) ((OPENSCENEGRAPH_MAJOR_VERSIONMAJOR) || (OPENSCENEGRAPH_MAJOR_VERSION==MAJOR && (OPENSCENEGRAPH_MINOR_VERSION>MINOR || (OPENSCENEGRAPH_MINOR_VERSION==MINOR && OPENSCENEGRAPH_PATCH_VERSION>PATCH)))) +#define OSG_VERSION_GREATER_OR_EQUAL(MAJOR, MINOR, PATCH) ((OPENSCENEGRAPH_MAJOR_VERSION>MAJOR) || (OPENSCENEGRAPH_MAJOR_VERSION==MAJOR && (OPENSCENEGRAPH_MINOR_VERSION>MINOR || (OPENSCENEGRAPH_MINOR_VERSION==MINOR && OPENSCENEGRAPH_PATCH_VERSION>=PATCH)))) + + +/** + * osgGetVersion() returns the library version number. + * Numbering convention : OpenSceneGraph-1.0 will return 1.0 from osgGetVersion. + * + * This C function can be also used to check for the existence of the OpenSceneGraph + * library using autoconf and its m4 macro AC_CHECK_LIB. + * + * Here is the code to add to your configure.in: + \verbatim + # + # Check for the OpenSceneGraph (OSG) library + # + AC_CHECK_LIB(osg, osgGetVersion, , + [AC_MSG_ERROR(OpenSceneGraph library not found. See http://www.openscenegraph.org)],) + \endverbatim +*/ +extern OSG_EXPORT const char* osgGetVersion(); + +/** The osgGetSOVersion() method returns the OpenSceneGraph shared object version number. */ +extern OSG_EXPORT const char* osgGetSOVersion(); + +/** The osgGetLibraryName() method returns the library name in human-friendly form. */ +extern OSG_EXPORT const char* osgGetLibraryName(); + +// old defines for backwards compatibility. +#define OSG_VERSION_MAJOR OPENSCENEGRAPH_MAJOR_VERSION +#define OSG_VERSION_MINOR OPENSCENEGRAPH_MINOR_VERSION +#define OSG_VERSION_PATCH OPENSCENEGRAPH_PATCH_VERSION + +#define OSG_VERSION_RELEASE OSG_VERSION_PATCH +#define OSG_VERSION_REVISION 0 + + +} + +#endif diff --git a/build2019/PlatformSpecifics/Windows/OpenSceneGraphVersionInfo.rc b/build2019/PlatformSpecifics/Windows/OpenSceneGraphVersionInfo.rc new file mode 100644 index 00000000000..c2073ff7960 --- /dev/null +++ b/build2019/PlatformSpecifics/Windows/OpenSceneGraphVersionInfo.rc @@ -0,0 +1,31 @@ +1 VERSIONINFO + FILEVERSION 3, 6, 5, 162 + PRODUCTVERSION 3, 6, 5, 162 + FILEFLAGSMASK 0x17L +#ifdef _DEBUG + FILEFLAGS 0x1L +#else + FILEFLAGS 0x0L +#endif + FILEOS 0x4L + FILETYPE 0x0L + FILESUBTYPE 0x0L +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904b0" + BEGIN + VALUE "FileDescription", "OpenSceneGraph Binary" + VALUE "FileVersion", "3, 6, 5, 162" + VALUE "InternalName", "OSG" + VALUE "LegalCopyright", "Copyright (C) 2009" + VALUE "OriginalFilename", "" + VALUE "ProductName", "OpenSceneGraph" + VALUE "ProductVersion", "3, 6, 5, 162" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x409, 1200 + END +END diff --git a/build2019/PlatformSpecifics/Windows/OpenThreadsVersionInfo.rc b/build2019/PlatformSpecifics/Windows/OpenThreadsVersionInfo.rc new file mode 100644 index 00000000000..205ba181caf --- /dev/null +++ b/build2019/PlatformSpecifics/Windows/OpenThreadsVersionInfo.rc @@ -0,0 +1,31 @@ +1 VERSIONINFO + FILEVERSION 3, 3, 1, 21 + PRODUCTVERSION 3, 3, 1, 21 + FILEFLAGSMASK 0x17L +#ifdef _DEBUG + FILEFLAGS 0x1L +#else + FILEFLAGS 0x0L +#endif + FILEOS 0x4L + FILETYPE 0x0L + FILESUBTYPE 0x0L +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904b0" + BEGIN + VALUE "FileDescription", "OPENTHREADS Binary" + VALUE "FileVersion", "3, 3, 1, 21" + VALUE "InternalName", "OSG" + VALUE "LegalCopyright", "Copyright (C) 2009" + VALUE "OriginalFilename", "" + VALUE "ProductName", "OPENTHREADS" + VALUE "ProductVersion", "3, 3, 1, 21" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x409, 1200 + END +END diff --git a/build2019/include/OpenThreads/Config b/build2019/include/OpenThreads/Config new file mode 100644 index 00000000000..713905d64c1 --- /dev/null +++ b/build2019/include/OpenThreads/Config @@ -0,0 +1,34 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) 2008 Robert Osfield + * + * 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 + * (at your option) any later version. The full license is in LICENSE file + * included with this distribution, and on the openscenegraph.org website. + * + * This library 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. See the + * OpenSceneGraph Public License for more details. +*/ + +/**************************************************************************** + * THIS FILE IS AUTOGENERATED BY CMAKE. DO NOT EDIT! + ****************************************************************************/ + +/* Changes to the configuration reflected here can be made with ccmake on + * unix or with cmake-gui on windows. Alternatively you can use cmake's -D + * or -P switches to set some configuration values at cmake configuration time. + */ + +#ifndef _OPENTHREADS_CONFIG +#define _OPENTHREADS_CONFIG + +/* #undef _OPENTHREADS_ATOMIC_USE_GCC_BUILTINS */ +/* #undef _OPENTHREADS_ATOMIC_USE_MIPOSPRO_BUILTINS */ +/* #undef _OPENTHREADS_ATOMIC_USE_SUN */ +#define _OPENTHREADS_ATOMIC_USE_WIN32_INTERLOCKED +/* #undef _OPENTHREADS_ATOMIC_USE_BSD_ATOMIC */ +/* #undef _OPENTHREADS_ATOMIC_USE_MUTEX */ +/* #undef OT_LIBRARY_STATIC */ + +#endif diff --git a/build2019/include/OpenThreads/Version b/build2019/include/OpenThreads/Version new file mode 100644 index 00000000000..1381595fd85 --- /dev/null +++ b/build2019/include/OpenThreads/Version @@ -0,0 +1,38 @@ +/* -*-c++-*- OpenThreads library, Copyright (C) 2002 - 2007 The Open Thread Group + * + * 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 + * (at your option) any later version. The full license is in LICENSE file + * included with this distribution, and on the openscenegraph.org website. + * + * This library 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. See the + * OpenSceneGraph Public License for more details. +*/ + +#ifndef OPENTHREADS_VERSION +#define OPENTHREADS_VERSION 1 + +#include + +extern "C" { + +#define OPENTHREADS_MAJOR_VERSION 3 +#define OPENTHREADS_MINOR_VERSION 3 +#define OPENTHREADS_PATCH_VERSION 1 +#define OPENTHREADS_SOVERSION 21 + +/** OpenThreadsGetVersion() returns the library version number. + * Numbering convention : OpenThreads-1.0 will return 1.0 from OpenThreadsGetVersion. */ +extern OPENTHREAD_EXPORT_DIRECTIVE const char* OpenThreadsGetVersion(); + +/** The OpenThreadsGetSOVersion() method returns the OpenSceneGraph soversion number. */ +extern OPENTHREAD_EXPORT_DIRECTIVE const char* OpenThreadsGetSOVersion(); + +/** The OpenThreadsGetLibraryName() method returns the library name in human-friendly form. */ +extern OPENTHREAD_EXPORT_DIRECTIVE const char* OpenThreadsGetLibraryName(); + +} + +#endif diff --git a/build2019/include/osg/Config b/build2019/include/osg/Config new file mode 100644 index 00000000000..74b19b18889 --- /dev/null +++ b/build2019/include/osg/Config @@ -0,0 +1,42 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) 2008-2009 Robert Osfield + * + * 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 + * (at your option) any later version. The full license is in LICENSE file + * included with this distribution, and on the openscenegraph.org website. + * + * This library 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. See the + * OpenSceneGraph Public License for more details. +*/ + +/**************************************************************************** + * THIS FILE IS AUTOGENERATED BY CMAKE. DO NOT EDIT! + ****************************************************************************/ + +/* Changes to the configuration reflected here can be made with ccmake on + * unix or with cmake-gui on windows. Alternatively you can use cmake's -D + * or -P switches to set some configuration values at cmake configuration time. + */ + +#ifndef OSG_CONFIG +#define OSG_CONFIG 1 + +/* #undef OSG_NOTIFY_DISABLED */ +#define OSG_USE_FLOAT_MATRIX +#define OSG_USE_FLOAT_PLANE +#define OSG_USE_FLOAT_BOUNDINGSPHERE +#define OSG_USE_FLOAT_BOUNDINGBOX +#define OSG_USE_FLOAT_QUAT +#define OSG_USE_REF_PTR_IMPLICIT_OUTPUT_CONVERSION +/* #undef OSG_USE_REF_PTR_SAFE_DEREFERENCE */ +/* #undef OSG_USE_UTF8_FILENAME */ +#define OSG_DISABLE_MSVC_WARNINGS +#define OSG_PROVIDE_READFILE +#define OSG_USE_DEPRECATED_API +#define OSG_ENVVAR_SUPPORTED +/* #undef OSG_WINDOWING_SYSTEM_CARBON */ +/* #undef OSG_WINDOWING_SYSTEM_NONE */ + +#endif diff --git a/build2019/include/osg/GL b/build2019/include/osg/GL new file mode 100644 index 00000000000..f678ba46342 --- /dev/null +++ b/build2019/include/osg/GL @@ -0,0 +1,194 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2009 Robert Osfield + * + * 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 + * (at your option) any later version. The full license is in LICENSE file + * included with this distribution, and on the openscenegraph.org website. + * + * This library 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. See the + * OpenSceneGraph Public License for more details. +*/ + +#ifndef OSG_OPENGL +#define OSG_OPENGL 1 + +#include +#include +#include + +#define OSG_GL1_AVAILABLE +#define OSG_GL2_AVAILABLE +/* #undef OSG_GL3_AVAILABLE */ +/* #undef OSG_GLES1_AVAILABLE */ +/* #undef OSG_GLES2_AVAILABLE */ +/* #undef OSG_GLES3_AVAILABLE */ +/* #undef OSG_GL_LIBRARY_STATIC */ +#define OSG_GL_DISPLAYLISTS_AVAILABLE +#define OSG_GL_MATRICES_AVAILABLE +#define OSG_GL_VERTEX_FUNCS_AVAILABLE +#define OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE +#define OSG_GL_FIXED_FUNCTION_AVAILABLE +/* #undef GL_HEADER_HAS_GLINT64 */ +/* #undef GL_HEADER_HAS_GLUINT64 */ + +#define OSG_GL1_FEATURES 1 +#define OSG_GL2_FEATURES 1 +#define OSG_GL3_FEATURES 0 +#define OSG_GLES1_FEATURES 0 +#define OSG_GLES2_FEATURES 0 +#define OSG_GLES3_FEATURES 0 +#define OSG_GL_CONTEXT_VERSION "1.0" + + +#ifndef _WIN32 + + // Required for compatibility with glext.h style function definitions of + // OpenGL extensions, such as in src/osg/Point.cpp. + #ifndef APIENTRY + #define APIENTRY + #endif + +#else // _WIN32 + + #if defined(__CYGWIN__) || defined(__MINGW32__) + + #ifndef APIENTRY + #define GLUT_APIENTRY_DEFINED + #define APIENTRY __stdcall + #endif + // XXX This is from Win32's + #ifndef CALLBACK + #define CALLBACK __stdcall + #endif + + #else // ! __CYGWIN__ + + // Under Windows avoid including + // to avoid name space pollution, but Win32's + // needs APIENTRY and WINGDIAPI defined properly. + // XXX This is from Win32's + #ifndef APIENTRY + #define GLUT_APIENTRY_DEFINED + #if (_MSC_VER >= 800) || defined(_STDCALL_SUPPORTED) + #define WINAPI __stdcall + #define APIENTRY WINAPI + #else + #define APIENTRY + #endif + #endif + + // XXX This is from Win32's + #ifndef CALLBACK + #if (_MSC_VER >= 800) || defined(_STDCALL_SUPPORTED) + #define CALLBACK __stdcall + #else + #define CALLBACK + #endif + #endif + + #endif // __CYGWIN__ + + // XXX This is from Win32's and + #ifndef WINGDIAPI + #define GLUT_WINGDIAPI_DEFINED + #define DECLSPEC_IMPORT __declspec(dllimport) + #define WINGDIAPI DECLSPEC_IMPORT + #endif + + // XXX This is from Win32's + #if !defined(_WCHAR_T_DEFINED) && !(defined(__GNUC__)&&(__GNUC__ > 2)) + typedef unsigned short wchar_t; + #define _WCHAR_T_DEFINED + #endif + +#endif // _WIN32 + +#if defined(OSG_GL3_AVAILABLE) + #define GL3_PROTOTYPES 1 + #define GL_GLEXT_PROTOTYPES 1 +#endif + + +#include + + + +#ifndef GL_APIENTRY + #define GL_APIENTRY APIENTRY +#endif // GL_APIENTRY + + +#ifndef GL_HEADER_HAS_GLINT64 + typedef int64_t GLint64; +#endif + +#ifndef GL_HEADER_HAS_GLUINT64 + typedef uint64_t GLuint64; +#endif + +#ifdef OSG_GL_MATRICES_AVAILABLE + + inline void glLoadMatrix(const float* mat) { glLoadMatrixf(static_cast(mat)); } + inline void glMultMatrix(const float* mat) { glMultMatrixf(static_cast(mat)); } + + #ifdef OSG_GLES1_AVAILABLE + inline void glLoadMatrix(const double* mat) + { + GLfloat flt_mat[16]; + for(unsigned int i=0;i<16;++i) flt_mat[i] = mat[i]; + glLoadMatrixf(flt_mat); + } + + inline void glMultMatrix(const double* mat) + { + GLfloat flt_mat[16]; + for(unsigned int i=0;i<16;++i) flt_mat[i] = mat[i]; + glMultMatrixf(flt_mat); + } + + #else + inline void glLoadMatrix(const double* mat) { glLoadMatrixd(static_cast(mat)); } + inline void glMultMatrix(const double* mat) { glMultMatrixd(static_cast(mat)); } + #endif +#endif + +// add defines for OpenGL targets that don't define them, just to ease compatibility across targets +#ifndef GL_DOUBLE + #define GL_DOUBLE 0x140A + typedef double GLdouble; +#endif + +#ifndef GL_INT + #define GL_INT 0x1404 +#endif + +#ifndef GL_UNSIGNED_INT + #define GL_UNSIGNED_INT 0x1405 +#endif + +#ifndef GL_NONE + // OpenGL ES1 doesn't provide GL_NONE + #define GL_NONE 0x0 +#endif + +#if defined(OSG_GLES1_AVAILABLE) || defined(OSG_GLES2_AVAILABLE) || defined(OSG_GLES3_AVAILABLE) + //GLES defines (OES) + #define GL_RGB8_OES 0x8051 + #define GL_RGBA8_OES 0x8058 +#endif + +#if defined(OSG_GLES1_AVAILABLE) || defined(OSG_GLES2_AVAILABLE) || defined(OSG_GLES3_AVAILABLE) || defined(OSG_GL3_AVAILABLE) + #define GL_POLYGON 0x0009 + #define GL_QUADS 0x0007 + #define GL_QUAD_STRIP 0x0008 +#endif + +#if defined(OSG_GL3_AVAILABLE) + #define GL_LUMINANCE 0x1909 + #define GL_LUMINANCE_ALPHA 0x190A +#endif + + +#endif diff --git a/build2019/include/osg/Version b/build2019/include/osg/Version new file mode 100644 index 00000000000..def75985126 --- /dev/null +++ b/build2019/include/osg/Version @@ -0,0 +1,73 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2009 Robert Osfield + * + * 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 + * (at your option) any later version. The full license is in LICENSE file + * included with this distribution, and on the openscenegraph.org website. + * + * This library 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. See the + * OpenSceneGraph Public License for more details. +*/ + +#ifndef OSG_VERSION +#define OSG_VERSION 1 + +#include + +extern "C" { + +#define OPENSCENEGRAPH_MAJOR_VERSION 3 +#define OPENSCENEGRAPH_MINOR_VERSION 6 +#define OPENSCENEGRAPH_PATCH_VERSION 5 +#define OPENSCENEGRAPH_SOVERSION 162 + +/* Convenience macro that can be used to decide whether a feature is present or not i.e. + * #if OSG_MIN_VERSION_REQUIRED(2,9,5) + * your code here + * #endif + */ +#define OSG_MIN_VERSION_REQUIRED(MAJOR, MINOR, PATCH) ((OPENSCENEGRAPH_MAJOR_VERSION>MAJOR) || (OPENSCENEGRAPH_MAJOR_VERSION==MAJOR && (OPENSCENEGRAPH_MINOR_VERSION>MINOR || (OPENSCENEGRAPH_MINOR_VERSION==MINOR && OPENSCENEGRAPH_PATCH_VERSION>=PATCH)))) +#define OSG_VERSION_LESS_THAN(MAJOR, MINOR, PATCH) ((OPENSCENEGRAPH_MAJOR_VERSIONMAJOR) || (OPENSCENEGRAPH_MAJOR_VERSION==MAJOR && (OPENSCENEGRAPH_MINOR_VERSION>MINOR || (OPENSCENEGRAPH_MINOR_VERSION==MINOR && OPENSCENEGRAPH_PATCH_VERSION>PATCH)))) +#define OSG_VERSION_GREATER_OR_EQUAL(MAJOR, MINOR, PATCH) ((OPENSCENEGRAPH_MAJOR_VERSION>MAJOR) || (OPENSCENEGRAPH_MAJOR_VERSION==MAJOR && (OPENSCENEGRAPH_MINOR_VERSION>MINOR || (OPENSCENEGRAPH_MINOR_VERSION==MINOR && OPENSCENEGRAPH_PATCH_VERSION>=PATCH)))) + + +/** + * osgGetVersion() returns the library version number. + * Numbering convention : OpenSceneGraph-1.0 will return 1.0 from osgGetVersion. + * + * This C function can be also used to check for the existence of the OpenSceneGraph + * library using autoconf and its m4 macro AC_CHECK_LIB. + * + * Here is the code to add to your configure.in: + \verbatim + # + # Check for the OpenSceneGraph (OSG) library + # + AC_CHECK_LIB(osg, osgGetVersion, , + [AC_MSG_ERROR(OpenSceneGraph library not found. See http://www.openscenegraph.org)],) + \endverbatim +*/ +extern OSG_EXPORT const char* osgGetVersion(); + +/** The osgGetSOVersion() method returns the OpenSceneGraph shared object version number. */ +extern OSG_EXPORT const char* osgGetSOVersion(); + +/** The osgGetLibraryName() method returns the library name in human-friendly form. */ +extern OSG_EXPORT const char* osgGetLibraryName(); + +// old defines for backwards compatibility. +#define OSG_VERSION_MAJOR OPENSCENEGRAPH_MAJOR_VERSION +#define OSG_VERSION_MINOR OPENSCENEGRAPH_MINOR_VERSION +#define OSG_VERSION_PATCH OPENSCENEGRAPH_PATCH_VERSION + +#define OSG_VERSION_RELEASE OSG_VERSION_PATCH +#define OSG_VERSION_REVISION 0 + + +} + +#endif diff --git a/include/osgUtil/RenderStage b/include/osgUtil/RenderStage index 3dc70b499c4..04d33cc34e5 100644 --- a/include/osgUtil/RenderStage +++ b/include/osgUtil/RenderStage @@ -167,7 +167,7 @@ class OSGUTIL_EXPORT RenderStage : public RenderBin /** Set a framebuffer object to render into. It is permissible for the * framebuffer object to be multisampled, in which case you should also * set a resolve framebuffer object - see setMultisampleResolveFramebufferObject(). */ - void setFrameBufferObject(osg::FrameBufferObject* fbo) { _fbo = fbo; } + void setFrameBufferObject(osg::FrameBufferObject* fbo); osg::FrameBufferObject* getFrameBufferObject() { return _fbo.get(); } const osg::FrameBufferObject* getFrameBufferObject() const { return _fbo.get(); } @@ -316,6 +316,8 @@ protected: // VRV_PATCH BEGIN // for resolving individual layers of a multisampled texture 2d array + void runResolveArrayLayersSetup(); + bool _resolveArrayLayersNeedSetup; std::vector> _arrayLayerFbos; std::vector> _resolveArrayLayerFbos; // VRV_PATCH END diff --git a/src/osgUtil/RenderStage.cpp b/src/osgUtil/RenderStage.cpp index 0ed49909c97..842d493f1e6 100644 --- a/src/osgUtil/RenderStage.cpp +++ b/src/osgUtil/RenderStage.cpp @@ -64,6 +64,8 @@ RenderStage::RenderStage(): _imageReadPixelFormat = GL_RGBA; _imageReadPixelDataType = GL_UNSIGNED_BYTE; + + _resolveArrayLayersNeedSetup = false; } RenderStage::RenderStage(SortMode mode): @@ -131,6 +133,69 @@ RenderStage::~RenderStage() { } +void osgUtil::RenderStage::runResolveArrayLayersSetup() +{ + _resolveArrayLayersNeedSetup = false; + + if (!_fbo || !_resolveFbo) return; + + OSG_INFO << "RenderStage::runResolveArrayLayersSetup() " << this << std::endl; + + const osg::FrameBufferObject::AttachmentMap& bufferAttachments = _fbo->getAttachmentMap(); + const osg::FrameBufferObject::AttachmentMap& resolveBufferAttachments = _resolveFbo->getAttachmentMap(); + _resolveArrayLayerFbos.clear(); + _arrayLayerFbos.clear(); + + for (osg::FrameBufferObject::AttachmentMap::const_iterator itr = bufferAttachments.begin(); + itr != bufferAttachments.end(); + ++itr) + { + osg::FrameBufferObject::BufferComponent buffer = itr->first; + if (resolveBufferAttachments.count(buffer) == 0) + continue; + + osg::FrameBufferAttachment msaaAttachment = _fbo->getAttachment(buffer); + osg::FrameBufferAttachment resolveAttachment = _resolveFbo->getAttachment(buffer); + osg::Texture2DMultisampleArray* msaaAttachmentAsTex2dArray = dynamic_cast(msaaAttachment.getTexture()); + osg::Texture2DArray* attachmentAsTex2dArray = dynamic_cast(resolveAttachment.getTexture()); + + int depth = attachmentAsTex2dArray->getTextureDepth(); + + // make a read and draw fbos for each layer so we can resolve later + for (unsigned int i = 0; i < static_cast(depth); i++) + { + osg::ref_ptr layerfbo; + osg::ref_ptr resolvelayerfbo; + + if (static_cast(_arrayLayerFbos.size()) <= i) + { + layerfbo = new osg::FrameBufferObject; + layerfbo->setName(_camera->getName() + "_layer_"); + _arrayLayerFbos.push_back(layerfbo); + } + else + { + layerfbo = _arrayLayerFbos[i]; + } + + if (static_cast(_resolveArrayLayerFbos.size()) <= i) + { + resolvelayerfbo = new osg::FrameBufferObject; + resolvelayerfbo->setName(_camera->getName() + "_resolvelayer_"); + _resolveArrayLayerFbos.push_back(resolvelayerfbo); + } + else + { + resolvelayerfbo = _resolveArrayLayerFbos[i]; + } + + resolvelayerfbo->setAttachment(buffer, osg::FrameBufferAttachment(attachmentAsTex2dArray, i, 0)); + layerfbo->setAttachment(buffer, osg::FrameBufferAttachment(msaaAttachmentAsTex2dArray, i, 0)); + + } + } +} + void RenderStage::reset() { _stageDrawnThisFrame = false; @@ -465,39 +530,11 @@ void RenderStage::runCameraSetUp(osg::RenderInfo& renderInfo) osg::Texture2DMultisampleArray* multiSampleTexArray = new osg::Texture2DMultisampleArray(width, height, depth, internalFormat, samples, GL_FALSE); fbo_multisample->setAttachment(buffer, osg::FrameBufferAttachment(multiSampleTexArray, attachment._face, 0)); - osg::Texture2DArray* attachmentAsTex2dArray = dynamic_cast(attachment._texture.get()); + // The default MIN_FILTER is LINEAR_MIPMAP_LINEAR which would cause mipmap generation, which + // does not work for Texture2DMultisampleArray and would throw an error. + multiSampleTexArray->setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR); - // make a read and draw fbos for each layer so we can resolve later - for(unsigned int i=0; i layerfbo; - osg::ref_ptr resolvelayerfbo; - - if(static_cast(_arrayLayerFbos.size()) <= i) - { - layerfbo = new osg::FrameBufferObject; - layerfbo->setName(_camera->getName() + "_layer_"); - _arrayLayerFbos.push_back(layerfbo); - } - else - { - layerfbo = _arrayLayerFbos[i]; - } - - if (static_cast(_resolveArrayLayerFbos.size()) <= i) - { - resolvelayerfbo = new osg::FrameBufferObject; - resolvelayerfbo->setName(_camera->getName() + "_resolvelayer_"); - _resolveArrayLayerFbos.push_back(resolvelayerfbo); - } - else - { - resolvelayerfbo = _resolveArrayLayerFbos[i]; - } - - resolvelayerfbo->setAttachment(buffer, osg::FrameBufferAttachment(attachmentAsTex2dArray, i, 0)); - layerfbo->setAttachment(buffer, osg::FrameBufferAttachment(multiSampleTexArray, i, 0)); - } + _resolveArrayLayersNeedSetup = true; } else { @@ -1101,13 +1138,17 @@ void RenderStage::drawInner(osg::RenderInfo& renderInfo,RenderLeaf*& previous, b else { // VRV_PATCH BEGIN - if (blitMask) + if (_resolveArrayLayersNeedSetup || _arrayLayerFbos.empty() || _resolveArrayLayerFbos.empty()) + runResolveArrayLayersSetup(); + + for (unsigned int i = 0; i < _resolveArrayLayerFbos.size(); i++) { - for(unsigned int i = 0; i < _resolveArrayLayerFbos.size(); i++) + _arrayLayerFbos[i]->apply(state, FrameBufferObject::READ_FRAMEBUFFER); + _resolveArrayLayerFbos[i]->apply(state, FrameBufferObject::DRAW_FRAMEBUFFER); + + if (blitMask) { //_arrayLayerFbos[i]->dirtyAll(); - _arrayLayerFbos[i]->apply(state, FrameBufferObject::READ_FRAMEBUFFER); - _resolveArrayLayerFbos[i]->apply(state, FrameBufferObject::DRAW_FRAMEBUFFER); ext->glBlitFramebuffer( static_cast(_viewport->x()), static_cast(_viewport->y()), @@ -1116,6 +1157,35 @@ void RenderStage::drawInner(osg::RenderInfo& renderInfo,RenderLeaf*& previous, b static_cast(_viewport->x() + _viewport->width()), static_cast(_viewport->y() + _viewport->height()), blitMask, GL_NEAREST); } + + +#if !defined(OSG_GLES1_AVAILABLE) && !defined(OSG_GLES2_AVAILABLE) + if (needToBlitColorBuffers) + { + for (FrameBufferObject::AttachmentMap::const_iterator + it = _resolveArrayLayerFbos[i]->getAttachmentMap().begin(), + end = _resolveArrayLayerFbos[i]->getAttachmentMap().end(); it != end; ++it) + { + osg::Camera::BufferComponent attachment = it->first; + if (attachment >= osg::Camera::COLOR_BUFFER0) + { + glReadBuffer(GL_COLOR_ATTACHMENT0_EXT + (attachment - osg::Camera::COLOR_BUFFER0)); + glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT + (attachment - osg::Camera::COLOR_BUFFER0)); + + ext->glBlitFramebuffer( + static_cast(_viewport->x()), static_cast(_viewport->y()), + static_cast(_viewport->x() + _viewport->width()), static_cast(_viewport->y() + _viewport->height()), + static_cast(_viewport->x()), static_cast(_viewport->y()), + static_cast(_viewport->x() + _viewport->width()), static_cast(_viewport->y() + _viewport->height()), + GL_COLOR_BUFFER_BIT, GL_NEAREST); + } + } + // reset the read and draw buffers? will comment out for now with the assumption that + // the buffers will be set explicitly when needed elsewhere. + // glReadBuffer(GL_COLOR_ATTACHMENT0_EXT); + // glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT); + } +#endif } // VRV_PATCH END } @@ -1579,6 +1649,13 @@ unsigned int RenderStage::computeNumberOfDynamicRenderLeaves() const } +void osgUtil::RenderStage::setFrameBufferObject(osg::FrameBufferObject* fbo) +{ + _fbo = fbo; + if (!_arrayLayerFbos.empty()) + _resolveArrayLayersNeedSetup = true; +} + void RenderStage::setMultisampleResolveFramebufferObject(osg::FrameBufferObject* fbo) { if (fbo && fbo->isMultisample()) @@ -1587,6 +1664,9 @@ void RenderStage::setMultisampleResolveFramebufferObject(osg::FrameBufferObject* " multisampled." << std::endl; } _resolveFbo = fbo; + + if (!_resolveArrayLayerFbos.empty()) + _resolveArrayLayersNeedSetup = true; } void RenderStage::collateReferencesToDependentCameras() From 4975c2f2dbb1901ad0ae670a61850f171c2e9bbf Mon Sep 17 00:00:00 2001 From: Mads Buvik Sandvei Date: Sun, 23 Apr 2023 16:53:48 +0200 Subject: [PATCH 40/40] Add sized depth and stencil formats. Fix OSG calling glTexImage3D on immutable textures already allocated using glTexStorage3D. --- include/osg/Texture | 2 ++ src/osg/Texture.cpp | 30 +++++++++++++++++++++++++++--- src/osg/Texture2DArray.cpp | 37 ++++++++++++++++++++----------------- 3 files changed, 49 insertions(+), 20 deletions(-) diff --git a/include/osg/Texture b/include/osg/Texture index ba6d874e932..e972db6eb61 100644 --- a/include/osg/Texture +++ b/include/osg/Texture @@ -415,6 +415,8 @@ //#define OSG_COLLECT_TEXTURE_APPLIED_STATS 1 +#define OSG_TEXTURE_HAS_SIZED_DEPTH_AND_STENCIL_INTERNAL_FORMATS + namespace osg { diff --git a/src/osg/Texture.cpp b/src/osg/Texture.cpp index 998f9dde952..e0e3b8bc32f 100644 --- a/src/osg/Texture.cpp +++ b/src/osg/Texture.cpp @@ -52,6 +52,22 @@ #define GL_RGB565 0x8D62 #endif +#ifndef GL_DEPTH32F_STENCIL8 +#define GL_DEPTH32F_STENCIL8 0x8CAD +#endif + +#ifndef GL_FLOAT_32_UNSIGNED_INT_24_8_REV +#define GL_FLOAT_32_UNSIGNED_INT_24_8_REV 0x8DAD +#endif + +#ifndef GL_DEPTH24_STENCIL8 +#define GL_DEPTH24_STENCIL8 0x88F0 +#endif + +#ifndef GL_DEPTH_STENCIL_EXT +#define GL_DEPTH_STENCIL_EXT 0x84F9 +#endif + #if 0 #define CHECK_CONSISTENCY checkConsistency(); #else @@ -171,8 +187,8 @@ InternalPixelRelations sizedDepthAndStencilInternalFormats[] = { , { GL_DEPTH_COMPONENT24 , GL_DEPTH_COMPONENT , GL_UNSIGNED_INT } , { GL_DEPTH_COMPONENT32 , GL_DEPTH_COMPONENT , GL_UNSIGNED_INT } , { GL_DEPTH_COMPONENT32F , GL_DEPTH_COMPONENT , GL_FLOAT } - // , { GL_DEPTH24_STENCIL8 , GL_DEPTH_STENCIL , GL_UNSIGNED_INT_24_8 } - // , { GL_DEPTH32F_STENCIL8 , GL_DEPTH_STENCIL , GL_FLOAT_32_UNSIGNED_INT_24_8_REV } + , { GL_DEPTH24_STENCIL8 , GL_DEPTH_STENCIL_EXT, GL_UNSIGNED_INT_24_8_EXT } + , { GL_DEPTH32F_STENCIL8 , GL_DEPTH_STENCIL_EXT, GL_FLOAT_32_UNSIGNED_INT_24_8_REV } }; InternalPixelRelations compressedInternalFormats[] = { @@ -234,7 +250,7 @@ InternalPixelRelations compressedInternalFormats[] = { bool isSizedInternalFormat(GLint internalFormat) { - const size_t formatsCount = sizeof(sizedInternalFormats) / sizeof(sizedInternalFormats[0]); + size_t formatsCount = sizeof(sizedInternalFormats) / sizeof(sizedInternalFormats[0]); for (size_t i=0; i < formatsCount; ++i) { @@ -242,6 +258,14 @@ bool isSizedInternalFormat(GLint internalFormat) return true; } + formatsCount = sizeof(sizedDepthAndStencilInternalFormats) / sizeof(sizedDepthAndStencilInternalFormats[0]); + + for (size_t i=0; i < formatsCount; ++i) + { + if((GLenum)internalFormat == sizedDepthAndStencilInternalFormats[i].sizedInternalFormat) + return true; + } + return false; } diff --git a/src/osg/Texture2DArray.cpp b/src/osg/Texture2DArray.cpp index 1ee98df4b4e..bb16976488e 100644 --- a/src/osg/Texture2DArray.cpp +++ b/src/osg/Texture2DArray.cpp @@ -440,26 +440,29 @@ void Texture2DArray::apply(State& state) const // generate texture GLenum texStorageSizedInternalFormat = extensions->isTextureStorageEnabled ? selectSizedInternalFormat() : 0; - textureObject = generateAndAssignTextureObject( - contextID, GL_TEXTURE_2D_ARRAY, _numMipmapLevels, - texStorageSizedInternalFormat!=0 ? texStorageSizedInternalFormat :_internalFormat, - _textureWidth, _textureHeight, _textureDepth, 0); - - textureObject->bind(); - - applyTexParameters(GL_TEXTURE_2D_ARRAY,state); - - if (texStorageSizedInternalFormat!=0 && !textureObject->_allocated) + if (texStorageSizedInternalFormat != 0) { - extensions->glTexStorage3D( GL_TEXTURE_2D_ARRAY, osg::maximum(_numMipmapLevels,1), texStorageSizedInternalFormat, _textureWidth, _textureHeight, _textureDepth); + textureObject = generateAndAssignTextureObject(contextID, GL_TEXTURE_2D_ARRAY, _numMipmapLevels, texStorageSizedInternalFormat, _textureWidth, _textureHeight, _textureDepth, 0); + textureObject->bind(); + applyTexParameters(GL_TEXTURE_2D_ARRAY, state); + if (!textureObject->_allocated) + { + extensions->glTexStorage3D(GL_TEXTURE_2D_ARRAY, osg::maximum(_numMipmapLevels, 1), texStorageSizedInternalFormat, + _textureWidth, _textureHeight, _textureDepth); + } } else - extensions->glTexImage3D( GL_TEXTURE_2D_ARRAY, 0, _internalFormat, - _textureWidth, _textureHeight, _textureDepth, - _borderWidth, - _sourceFormat ? _sourceFormat : _internalFormat, - _sourceType ? _sourceType : GL_UNSIGNED_BYTE, - 0); + { + GLenum internalFormat = _sourceFormat ? _sourceFormat : _internalFormat; + textureObject = generateAndAssignTextureObject(contextID, GL_TEXTURE_2D_ARRAY, _numMipmapLevels, internalFormat, _textureWidth, _textureHeight, _textureDepth, 0); + textureObject->bind(); + applyTexParameters(GL_TEXTURE_2D_ARRAY, state); + extensions->glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, _internalFormat, + _textureWidth, _textureHeight, _textureDepth, _borderWidth, + internalFormat, + _sourceType ? _sourceType : GL_UNSIGNED_BYTE, + 0); + } textureObject->setAllocated(_numMipmapLevels, texStorageSizedInternalFormat!=0 ? texStorageSizedInternalFormat :_internalFormat, _textureWidth, _textureHeight, _textureDepth, 0); }