From f59c87daeed486c04b5821a3eb13240e949307e7 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 21 Nov 2017 15:40:01 +0000 Subject: [PATCH 01/13] Adopted the improvements to TangentSpaceGenerator.cpp from master --- src/osgUtil/TangentSpaceGenerator.cpp | 167 +++++++++++--------------- 1 file changed, 67 insertions(+), 100 deletions(-) diff --git a/src/osgUtil/TangentSpaceGenerator.cpp b/src/osgUtil/TangentSpaceGenerator.cpp index c82bffbfb..027e8be8a 100644 --- a/src/osgUtil/TangentSpaceGenerator.cpp +++ b/src/osgUtil/TangentSpaceGenerator.cpp @@ -12,8 +12,8 @@ TangentSpaceGenerator::TangentSpaceGenerator() N_(new osg::Vec4Array) { T_->setBinding(osg::Array::BIND_PER_VERTEX); T_->setNormalize(false); - B_->setBinding(osg::Array::BIND_PER_VERTEX); T_->setNormalize(false); - N_->setBinding(osg::Array::BIND_PER_VERTEX); T_->setNormalize(false); + B_->setBinding(osg::Array::BIND_PER_VERTEX); B_->setNormalize(false); + N_->setBinding(osg::Array::BIND_PER_VERTEX); N_->setNormalize(false); } TangentSpaceGenerator::TangentSpaceGenerator(const TangentSpaceGenerator ©, const osg::CopyOp ©op) @@ -281,107 +281,74 @@ void TangentSpaceGenerator::compute(osg::PrimitiveSet *pset, OSG_WARN << "Warning: TangentSpaceGenerator: texture coord array must be Vec2Array, Vec3Array or Vec4Array" << std::endl; } - if(nx){ - osg::Vec3 V, T1, T2, T3, B1, B2, B3; + osg::Vec3 V, T1, T2, T3, B1, B2, B3; - V = osg::Vec3(P2.x() - P1.x(), uv2.x() - uv1.x(), uv2.y() - uv1.y()) ^ - osg::Vec3(P3.x() - P1.x(), uv3.x() - uv1.x(), uv3.y() - uv1.y()); - if (V.x() != 0) { - V.normalize(); - T1.x() += -V.y() / V.x(); - B1.x() += -V.z() / V.x(); - T2.x() += -V.y() / V.x(); - B2.x() += -V.z() / V.x(); - T3.x() += -V.y() / V.x(); - B3.x() += -V.z() / V.x(); - } - - V = osg::Vec3(P2.y() - P1.y(), uv2.x() - uv1.x(), uv2.y() - uv1.y()) ^ - osg::Vec3(P3.y() - P1.y(), uv3.x() - uv1.x(), uv3.y() - uv1.y()); - if (V.x() != 0) { - V.normalize(); - T1.y() += -V.y() / V.x(); - B1.y() += -V.z() / V.x(); - T2.y() += -V.y() / V.x(); - B2.y() += -V.z() / V.x(); - T3.y() += -V.y() / V.x(); - B3.y() += -V.z() / V.x(); - } - - V = osg::Vec3(P2.z() - P1.z(), uv2.x() - uv1.x(), uv2.y() - uv1.y()) ^ - osg::Vec3(P3.z() - P1.z(), uv3.x() - uv1.x(), uv3.y() - uv1.y()); - if (V.x() != 0) { - V.normalize(); - T1.z() += -V.y() / V.x(); - B1.z() += -V.z() / V.x(); - T2.z() += -V.y() / V.x(); - B2.z() += -V.z() / V.x(); - T3.z() += -V.y() / V.x(); - B3.z() += -V.z() / V.x(); - } - - osg::Vec3 tempvec; - tempvec = N1 ^ T1; - (*T_)[iA] = osg::Vec4(tempvec ^ N1, 0); - tempvec = B1 ^ N1; - (*B_)[iA] = osg::Vec4(N1 ^ tempvec, 0); - tempvec = N2 ^ T2; - (*T_)[iB] = osg::Vec4(tempvec ^ N2, 0); - tempvec = B2 ^ N2; - (*B_)[iB] = osg::Vec4(N2 ^ tempvec, 0); - tempvec = N3 ^ T3; - (*T_)[iC] = osg::Vec4(tempvec ^ N3, 0); - tempvec = B3 ^ N3; - (*B_)[iC] = osg::Vec4(N3 ^ tempvec, 0); - - (*N_)[iA] += osg::Vec4(N1, 0); - (*N_)[iB] += osg::Vec4(N2, 0); - (*N_)[iC] += osg::Vec4(N3, 0); + // no normal per vertex use the one by face + if (!nx) { + N1 = (P2 - P1) ^ (P3 - P1); + N2 = N1; + N3 = N1; } - else{ - osg::Vec3 face_normal = (P2 - P1) ^ (P3 - P1); - osg::Vec3 V; - - V = osg::Vec3(P2.x() - P1.x(), uv2.x() - uv1.x(), uv2.y() - uv1.y()) ^ - osg::Vec3(P3.x() - P1.x(), uv3.x() - uv1.x(), uv3.y() - uv1.y()); - if (V.x() != 0) { - V.normalize(); - (*T_)[iA].x() += -V.y() / V.x(); - (*B_)[iA].x() += -V.z() / V.x(); - (*T_)[iB].x() += -V.y() / V.x(); - (*B_)[iB].x() += -V.z() / V.x(); - (*T_)[iC].x() += -V.y() / V.x(); - (*B_)[iC].x() += -V.z() / V.x(); - } - - V = osg::Vec3(P2.y() - P1.y(), uv2.x() - uv1.x(), uv2.y() - uv1.y()) ^ - osg::Vec3(P3.y() - P1.y(), uv3.x() - uv1.x(), uv3.y() - uv1.y()); - if (V.x() != 0) { - V.normalize(); - (*T_)[iA].y() += -V.y() / V.x(); - (*B_)[iA].y() += -V.z() / V.x(); - (*T_)[iB].y() += -V.y() / V.x(); - (*B_)[iB].y() += -V.z() / V.x(); - (*T_)[iC].y() += -V.y() / V.x(); - (*B_)[iC].y() += -V.z() / V.x(); - } - - V = osg::Vec3(P2.z() - P1.z(), uv2.x() - uv1.x(), uv2.y() - uv1.y()) ^ - osg::Vec3(P3.z() - P1.z(), uv3.x() - uv1.x(), uv3.y() - uv1.y()); - if (V.x() != 0) { - V.normalize(); - (*T_)[iA].z() += -V.y() / V.x(); - (*B_)[iA].z() += -V.z() / V.x(); - (*T_)[iB].z() += -V.y() / V.x(); - (*B_)[iB].z() += -V.z() / V.x(); - (*T_)[iC].z() += -V.y() / V.x(); - (*B_)[iC].z() += -V.z() / V.x(); - } - - (*N_)[iA] += osg::Vec4(face_normal, 0); - (*N_)[iB] += osg::Vec4(face_normal, 0); - (*N_)[iC] += osg::Vec4(face_normal, 0); + V = osg::Vec3(P2.x() - P1.x(), uv2.x() - uv1.x(), uv2.y() - uv1.y()) ^ + osg::Vec3(P3.x() - P1.x(), uv3.x() - uv1.x(), uv3.y() - uv1.y()); + if (V.x() != 0) { + V.normalize(); + T1.x() += -V.y() / V.x(); + B1.x() += -V.z() / V.x(); + T2.x() += -V.y() / V.x(); + B2.x() += -V.z() / V.x(); + T3.x() += -V.y() / V.x(); + B3.x() += -V.z() / V.x(); } + + V = osg::Vec3(P2.y() - P1.y(), uv2.x() - uv1.x(), uv2.y() - uv1.y()) ^ + osg::Vec3(P3.y() - P1.y(), uv3.x() - uv1.x(), uv3.y() - uv1.y()); + if (V.x() != 0) { + V.normalize(); + T1.y() += -V.y() / V.x(); + B1.y() += -V.z() / V.x(); + T2.y() += -V.y() / V.x(); + B2.y() += -V.z() / V.x(); + T3.y() += -V.y() / V.x(); + B3.y() += -V.z() / V.x(); + } + + V = osg::Vec3(P2.z() - P1.z(), uv2.x() - uv1.x(), uv2.y() - uv1.y()) ^ + osg::Vec3(P3.z() - P1.z(), uv3.x() - uv1.x(), uv3.y() - uv1.y()); + if (V.x() != 0) { + V.normalize(); + T1.z() += -V.y() / V.x(); + B1.z() += -V.z() / V.x(); + T2.z() += -V.y() / V.x(); + B2.z() += -V.z() / V.x(); + T3.z() += -V.y() / V.x(); + B3.z() += -V.z() / V.x(); + } + + osg::Vec3 tempvec; + + tempvec = N1 ^ T1; + (*T_)[iA] += osg::Vec4(tempvec ^ N1, 0); + + tempvec = B1 ^ N1; + (*B_)[iA] += osg::Vec4(N1 ^ tempvec, 0); + + tempvec = N2 ^ T2; + (*T_)[iB] += osg::Vec4(tempvec ^ N2, 0); + + tempvec = B2 ^ N2; + (*B_)[iB] += osg::Vec4(N2 ^ tempvec, 0); + + tempvec = N3 ^ T3; + (*T_)[iC] += osg::Vec4(tempvec ^ N3, 0); + + tempvec = B3 ^ N3; + (*B_)[iC] += osg::Vec4(N3 ^ tempvec, 0); + + (*N_)[iA] += osg::Vec4(N1, 0); + (*N_)[iB] += osg::Vec4(N2, 0); + (*N_)[iC] += osg::Vec4(N3, 0); + } From bc562a58580cd3f064edf257dce390909c0529c5 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 22 Nov 2017 11:05:17 +0000 Subject: [PATCH 02/13] Removed use of local static to avoid threading issue. --- src/osgPlugins/dxf/dxfReader.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/osgPlugins/dxf/dxfReader.cpp b/src/osgPlugins/dxf/dxfReader.cpp index 9a8c9ceb6..bce713b72 100644 --- a/src/osgPlugins/dxf/dxfReader.cpp +++ b/src/osgPlugins/dxf/dxfReader.cpp @@ -85,7 +85,7 @@ bool readerText::success(bool inSuccess, string type) bool readerText::getTrimmedLine(std::ifstream& f) { - static string line = ""; + std::string line; if (getline(f, line, _delim)) { ++_lineCount; _str.clear(); From 1c4f0b93a0ebfa5e7b51c24744cb6afa0ab3cee1 Mon Sep 17 00:00:00 2001 From: Mathieu Date: Wed, 29 Nov 2017 11:06:16 +0100 Subject: [PATCH 03/13] Make the culling be disables at the drawable level not at the geode level --- src/osgPlugins/logo/ReaderWriterLOGO.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/osgPlugins/logo/ReaderWriterLOGO.cpp b/src/osgPlugins/logo/ReaderWriterLOGO.cpp index 0f4a7c215..067492419 100644 --- a/src/osgPlugins/logo/ReaderWriterLOGO.cpp +++ b/src/osgPlugins/logo/ReaderWriterLOGO.cpp @@ -321,7 +321,7 @@ class LOGOReaderWriter : public osgDB::ReaderWriter if( ld->hasLogos() ) geode->addDrawable( ld ); - geode->setCullingActive(false); + ld->setCullingActive(false); return geode; } }; From a99937e43aef31d9f343d3165d6bcd8edfc42b5f Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 29 Nov 2017 11:04:02 +0000 Subject: [PATCH 04/13] Added support for .vs, .fs. .gs, .cs etc, GLSL file extensions --- src/osgDB/Registry.cpp | 7 +++++++ src/osgPlugins/glsl/ReaderWriterGLSL.cpp | 12 ++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/osgDB/Registry.cpp b/src/osgDB/Registry.cpp index 7a3aad6f6..f3817a971 100644 --- a/src/osgDB/Registry.cpp +++ b/src/osgDB/Registry.cpp @@ -307,6 +307,13 @@ Registry::Registry() addFileExtensionAlias("vert", "glsl"); addFileExtensionAlias("frag", "glsl"); addFileExtensionAlias("geom", "glsl"); + addFileExtensionAlias("compute", "glsl"); + addFileExtensionAlias("vs", "glsl"); + addFileExtensionAlias("fs", "glsl"); + addFileExtensionAlias("gs", "glsl"); + addFileExtensionAlias("cs", "glsl"); + addFileExtensionAlias("tctrl", "glsl"); + addFileExtensionAlias("teval", "glsl"); addFileExtensionAlias("js", "V8"); diff --git a/src/osgPlugins/glsl/ReaderWriterGLSL.cpp b/src/osgPlugins/glsl/ReaderWriterGLSL.cpp index 60c4842a4..dccaa3cf5 100644 --- a/src/osgPlugins/glsl/ReaderWriterGLSL.cpp +++ b/src/osgPlugins/glsl/ReaderWriterGLSL.cpp @@ -18,12 +18,16 @@ class ReaderWriterGLSL : public osgDB::ReaderWriter { supportsExtension("gl","OpenGL Shader Language format"); supportsExtension("frag","OpenGL Shader Language format"); + supportsExtension("fs","OpenGL Shader Language format"); supportsExtension("vert","OpenGL Shader Language format"); + supportsExtension("vs","OpenGL Shader Language format"); supportsExtension("geom","OpenGL Shader Language format"); + supportsExtension("gs","OpenGL Shader Language format"); supportsExtension("glsl","OpenGL Shader Language format"); supportsExtension("tctrl","OpenGL Shader Language format"); supportsExtension("teval","OpenGL Shader Language format"); supportsExtension("compute","OpenGL Shader Language format"); + supportsExtension("cs","OpenGL Shader Language format"); } virtual const char* className() const { return "GLSL Shader Reader"; } @@ -126,12 +130,12 @@ class ReaderWriterGLSL : public osgDB::ReaderWriter if (shader->getType() == osg::Shader::UNDEFINED) { // set type based on filename extension, where possible - if (ext == "frag") shader->setType(osg::Shader::FRAGMENT); - if (ext == "vert") shader->setType(osg::Shader::VERTEX); - if (ext == "geom") shader->setType(osg::Shader::GEOMETRY); + if (ext == "frag" || ext == "fs") shader->setType(osg::Shader::FRAGMENT); + if (ext == "vert" || ext == "vs" ) shader->setType(osg::Shader::VERTEX); + if (ext == "geom" || ext == "geom") shader->setType(osg::Shader::GEOMETRY); if (ext == "tctrl") shader->setType(osg::Shader::TESSCONTROL); if (ext == "teval") shader->setType(osg::Shader::TESSEVALUATION); - if (ext == "compute") shader->setType(osg::Shader::COMPUTE); + if (ext == "compute" || ext == "cs") shader->setType(osg::Shader::COMPUTE); } } return rr; From abbfc6c2eb56b3f7537003975a24c36d7a9e52b9 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 29 Nov 2017 11:04:53 +0000 Subject: [PATCH 05/13] Fixed file search for shaders --- examples/osgSSBO/osgSSBO.cpp | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/examples/osgSSBO/osgSSBO.cpp b/examples/osgSSBO/osgSSBO.cpp index c08b5ea74..ac42978eb 100644 --- a/examples/osgSSBO/osgSSBO.cpp +++ b/examples/osgSSBO/osgSSBO.cpp @@ -200,15 +200,10 @@ public: ComputeNode() { - const char* envOsgFilePath = getenv("OSG_FILE_PATH"); - std::stringstream computeshaderpath; computeshaderpath << envOsgFilePath << "/shaders/osgssboComputeShader.cs"; - _computeShaderSourcePath = computeshaderpath.str(); - std::stringstream vertexshaderpath; vertexshaderpath << envOsgFilePath << "/shaders/osgssboVertexShader.vs"; - _vertexShaderSourcePath = vertexshaderpath.str(); - std::stringstream geometryshaderpath; geometryshaderpath << envOsgFilePath << "/shaders/osgssboGeometryShader.gs"; - _geometryShaderSourcePath = geometryshaderpath.str(); - std::stringstream fragmentshaderpath; fragmentshaderpath << envOsgFilePath << "/shaders/osgssboFragmentShader.fs"; - _fragmentShaderSourcePath = fragmentshaderpath.str(); + _computeShaderSourcePath = "shaders/osgssboComputeShader.cs"; + _vertexShaderSourcePath = "shaders/osgssboVertexShader.vs"; + _geometryShaderSourcePath = "shaders/osgssboGeometryShader.gs"; + _fragmentShaderSourcePath = "shaders/osgssboFragmentShader.fs"; } }; @@ -243,7 +238,7 @@ public: if (_computeNode->_computeShader.valid()) { runningSource = _computeNode->_computeShader->getShaderSource(); - reloadedshader = osg::Shader::readShaderFile(osg::Shader::COMPUTE, _computeNode->_computeShaderSourcePath); + reloadedshader = osgDB::readRefShaderFile(osg::Shader::COMPUTE, _computeNode->_computeShaderSourcePath); reloadedstring = reloadedshader->getShaderSource(); if (!osgDB::equalCaseInsensitive(runningSource.c_str(), reloadedstring.c_str())) @@ -258,7 +253,7 @@ public: { runningSource = _computeNode->_vertexShader->getShaderSource(); - reloadedshader = osg::Shader::readShaderFile(osg::Shader::VERTEX, _computeNode->_vertexShaderSourcePath); + reloadedshader = osgDB::readRefShaderFile(osg::Shader::VERTEX, _computeNode->_vertexShaderSourcePath); reloadedstring = reloadedshader->getShaderSource(); if (!osgDB::equalCaseInsensitive(runningSource.c_str(), reloadedstring.c_str())) @@ -274,7 +269,7 @@ public: if (_computeNode->_geometryShader.valid()) { runningSource = _computeNode->_geometryShader->getShaderSource(); - reloadedshader = osg::Shader::readShaderFile(osg::Shader::GEOMETRY, _computeNode->_geometryShaderSourcePath); + reloadedshader = osgDB::readRefShaderFile(osg::Shader::GEOMETRY, _computeNode->_geometryShaderSourcePath); reloadedstring = reloadedshader->getShaderSource(); if (!osgDB::equalCaseInsensitive(runningSource.c_str(), reloadedstring.c_str())) @@ -288,7 +283,7 @@ public: if (_computeNode->_fragmentShader.valid()) { runningSource = _computeNode->_fragmentShader->getShaderSource(); - reloadedshader = osg::Shader::readShaderFile(osg::Shader::FRAGMENT, _computeNode->_fragmentShaderSourcePath); + reloadedshader = osgDB::readRefShaderFile(osg::Shader::FRAGMENT, _computeNode->_fragmentShaderSourcePath); reloadedstring = reloadedshader->getShaderSource(); if (!osgDB::equalCaseInsensitive(runningSource.c_str(), reloadedstring.c_str())) @@ -518,13 +513,13 @@ void ComputeNode::addComputationResultsRenderTree() _computationResultsRenderProgram = new osg::Program; - _vertexShader = osg::Shader::readShaderFile(osg::Shader::VERTEX, _vertexShaderSourcePath); + _vertexShader = osgDB::readRefShaderFile(osg::Shader::VERTEX, _vertexShaderSourcePath); _computationResultsRenderProgram->addShader(_vertexShader.get()); - _geometryShader = osg::Shader::readShaderFile(osg::Shader::GEOMETRY, _geometryShaderSourcePath); + _geometryShader = osgDB::readRefShaderFile(osg::Shader::GEOMETRY, _geometryShaderSourcePath); _computationResultsRenderProgram->addShader(_geometryShader.get()); - _fragmentShader = osg::Shader::readShaderFile(osg::Shader::FRAGMENT, _fragmentShaderSourcePath); + _fragmentShader = osgDB::readRefShaderFile(osg::Shader::FRAGMENT, _fragmentShaderSourcePath); _computationResultsRenderProgram->addShader(_fragmentShader.get()); @@ -629,7 +624,7 @@ void ComputeNode::initComputingSetup() _computeProgram = new osg::Program; _computeProgram->setComputeGroups((NUM_ELEMENTS_X / WORK_GROUP_SIZE) <= 1 ? 1 : (NUM_ELEMENTS_X / WORK_GROUP_SIZE), (NUM_ELEMENTS_Y / WORK_GROUP_SIZE) <= 1 ? 1 : (NUM_ELEMENTS_Y / WORK_GROUP_SIZE), 1); - _computeShader = osg::Shader::readShaderFile(osg::Shader::COMPUTE, _computeShaderSourcePath); + _computeShader = osgDB::readRefShaderFile(osg::Shader::COMPUTE, _computeShaderSourcePath); _computeProgram->addShader(_computeShader.get()); setDataVariance(osg::Object::DYNAMIC); From 7e592cf1e03869e6ab0e0eb902ebb573ecbcf552 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 5 Jan 2018 12:12:24 +0000 Subject: [PATCH 06/13] Fixed return values --- src/osgPlugins/zip/ZipArchive.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/osgPlugins/zip/ZipArchive.cpp b/src/osgPlugins/zip/ZipArchive.cpp index ae5a8df2e..8123a9b81 100644 --- a/src/osgPlugins/zip/ZipArchive.cpp +++ b/src/osgPlugins/zip/ZipArchive.cpp @@ -121,11 +121,11 @@ bool ZipArchive::open(const std::string& file, ArchiveStatus status, const osgDB if ( !_zipLoaded ) // double-check avoids race condition { std::string ext = osgDB::getLowerCaseFileExtension(file); - if (!acceptsExtension(ext)) return osgDB::ReaderWriter::ReadResult::FILE_NOT_HANDLED; + if (!acceptsExtension(ext)) return false; // save the filename + password so other threads can open the file _filename = osgDB::findDataFile( file, options ); - if (_filename.empty()) return osgDB::ReaderWriter::ReadResult::FILE_NOT_FOUND; + if (_filename.empty()) return false; _password = ReadPassword(options); From 5f7b388c1644140a25a3484c44310d0ccc85e7e3 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 5 Jan 2018 13:43:53 +0000 Subject: [PATCH 07/13] Commented out osx build --- .travis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6e57505cd..56a730cb4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -24,9 +24,9 @@ matrix: #- clang-3.8 - g++ - cmake - # OSX build - - os: osx - language: cpp +# # OSX build +# - os: osx +# language: cpp script: - mkdir build From 7118910edd11582ebc3fc7c22a0d3eeb9d8c54dc Mon Sep 17 00:00:00 2001 From: mp3butcher Win32 Date: Wed, 10 Jan 2018 21:32:07 +0100 Subject: [PATCH 08/13] improve FindNVTT.cmake and add missing NVTT libraries --- CMakeModules/FindNVTT.cmake | 42 ++++++++++++++++++++++-------- src/osgPlugins/nvtt/CMakeLists.txt | 2 +- 2 files changed, 32 insertions(+), 12 deletions(-) diff --git a/CMakeModules/FindNVTT.cmake b/CMakeModules/FindNVTT.cmake index b4193d16e..2e24a9fea 100644 --- a/CMakeModules/FindNVTT.cmake +++ b/CMakeModules/FindNVTT.cmake @@ -16,7 +16,7 @@ FIND_PATH(NVTT_INCLUDE_DIR nvtt/nvtt.h ) # NVTT -FIND_LIBRARY(NVTT_LIBRARY +FIND_LIBRARY(NVTT_LIBRARY_RELEASE NAMES nvtt PATHS /usr/local @@ -37,7 +37,7 @@ FIND_LIBRARY(NVTT_LIBRARY_DEBUG ) # NVIMAGE -FIND_LIBRARY(NVIMAGE_LIBRARY +FIND_LIBRARY(NVIMAGE_LIBRARY_RELEASE NAMES nvimage PATHS /usr/local @@ -58,7 +58,7 @@ FIND_LIBRARY(NVIMAGE_LIBRARY_DEBUG ) # NVMATH -FIND_LIBRARY(NVMATH_LIBRARY +FIND_LIBRARY(NVMATH_LIBRARY_RELEASE NAMES nvmath PATHS /usr/local @@ -79,7 +79,7 @@ FIND_LIBRARY(NVMATH_LIBRARY_DEBUG ) # NVCORE -FIND_LIBRARY(NVCORE_LIBRARY +FIND_LIBRARY(NVCORE_LIBRARY_RELEASE NAMES nvcore PATHS /usr/local @@ -99,7 +99,7 @@ FIND_LIBRARY(NVCORE_LIBRARY_DEBUG ) # NVTHREAD -FIND_LIBRARY(NVTHREAD_LIBRARY +FIND_LIBRARY(NVTHREAD_LIBRARY_RELEASE NAMES nvthread PATHS /usr/local @@ -119,7 +119,7 @@ FIND_LIBRARY(NVTHREAD_LIBRARY_DEBUG ) # SQUISH -FIND_LIBRARY(NVSQUISH_LIBRARY +FIND_LIBRARY(NVSQUISH_LIBRARY_RELEASE NAMES squish PATHS /usr/local @@ -139,7 +139,7 @@ FIND_LIBRARY(NVSQUISH_LIBRARY_DEBUG ) # BC6H -FIND_LIBRARY(NVBC6H_LIBRARY +FIND_LIBRARY(NVBC6H_LIBRARY_RELEASE NAMES bc6h PATHS /usr/local @@ -159,7 +159,7 @@ FIND_LIBRARY(NVBC6H_LIBRARY_DEBUG ) # BC7 -FIND_LIBRARY(NVBC7_LIBRARY +FIND_LIBRARY(NVBC7_LIBRARY_RELEASE NAMES bc7 PATHS /usr/local @@ -178,9 +178,29 @@ FIND_LIBRARY(NVBC7_LIBRARY_DEBUG PATH_SUFFIXES lib64 lib lib/shared lib/static lib64/static ) +SET(LIBS_TO_SETUP "NVTT" "NVCORE" "NVMATH" "NVIMAGE" "NVTHREAD" "NVBC7" "NVBC6H" "NVSQUISH") +FOREACH(LIB ${LIBS_TO_SETUP}) + IF(${LIB}_LIBRARY_DEBUG) + SET(${LIB}_LIBRARIES optimized ${${LIB}_LIBRARY_RELEASE} debug ${${LIB}_LIBRARY_DEBUG}) + ELSE(${LIB}_LIBRARY_DEBUG) + SET(${LIB}_LIBRARY_DEBUG ${${LIB}_LIBRARY_RELEASE}) + SET(${LIB}_LIBRARIES optimized ${${LIB}_LIBRARY_RELEASE} debug ${${LIB}_LIBRARY_DEBUG}) + ENDIF(${LIB}_LIBRARY_DEBUG) +ENDFOREACH(LIB ${LIBS_TO_SETUP}) + +SET(NVTT_LIBRARIES + ${NVTT_LIBRARIES} + ${NVCORE_LIBRARIES} + ${NVMATH_LIBRARIES} + ${NVIMAGE_LIBRARIES} + ${NVTHREAD_LIBRARIES} + ${NVBC7_LIBRARIES} + ${NVBC6H_LIBRARIES} + ${NVSQUISH_LIBRARIES} +) SET(NVTT_FOUND "NO") -IF(NVTT_LIBRARY AND NVTT_INCLUDE_DIR) - SET(NVTT_FOUND "YES") -ENDIF(NVTT_LIBRARY AND NVTT_INCLUDE_DIR) +IF(NVTT_LIBRARY_RELEASE AND NVTT_INCLUDE_DIR) + SET(NVTT_FOUND "YES" ) +ENDIF(NVTT_LIBRARY_RELEASE AND NVTT_INCLUDE_DIR) diff --git a/src/osgPlugins/nvtt/CMakeLists.txt b/src/osgPlugins/nvtt/CMakeLists.txt index 4a91eadc8..4fc58b4ae 100644 --- a/src/osgPlugins/nvtt/CMakeLists.txt +++ b/src/osgPlugins/nvtt/CMakeLists.txt @@ -5,7 +5,7 @@ SET(TARGET_SRC NVTTImageProcessor.cpp ) -SET(TARGET_LIBRARIES_VARS NVTT_LIBRARY) +SET(TARGET_EXTERNAL_LIBRARIES ${TARGET_EXTERNAL_LIBRARIES} ${NVTT_LIBRARIES}) #### end var setup ### SETUP_PLUGIN(nvtt) From 559dad93b882a35e1fc86fbc60149aec4391413f Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 11 Jan 2018 08:51:08 +0000 Subject: [PATCH 09/13] Added returns to avoid fall through between case statements --- src/osgSim/ShapeAttribute.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/osgSim/ShapeAttribute.cpp b/src/osgSim/ShapeAttribute.cpp index c18f70cd8..753322d5e 100644 --- a/src/osgSim/ShapeAttribute.cpp +++ b/src/osgSim/ShapeAttribute.cpp @@ -135,11 +135,13 @@ int ShapeAttribute::compare(const osgSim::ShapeAttribute& sa) const { if (_string Date: Thu, 11 Jan 2018 10:10:43 +0000 Subject: [PATCH 10/13] Fixed Linux NVTT build issue by restricting the addition of the new libs to just Windows --- CMakeModules/FindNVTT.cmake | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/CMakeModules/FindNVTT.cmake b/CMakeModules/FindNVTT.cmake index 2e24a9fea..d0e7414ac 100644 --- a/CMakeModules/FindNVTT.cmake +++ b/CMakeModules/FindNVTT.cmake @@ -178,7 +178,12 @@ FIND_LIBRARY(NVBC7_LIBRARY_DEBUG PATH_SUFFIXES lib64 lib lib/shared lib/static lib64/static ) -SET(LIBS_TO_SETUP "NVTT" "NVCORE" "NVMATH" "NVIMAGE" "NVTHREAD" "NVBC7" "NVBC6H" "NVSQUISH") +IF (WIN32) + SET(LIBS_TO_SETUP "NVTT" "NVCORE" "NVMATH" "NVIMAGE" "NVTHREAD" "NVBC7" "NVBC6H" "NVSQUISH") +ELSE() + SET(LIBS_TO_SETUP "NVTT" "NVCORE" "NVMATH" "NVIMAGE") +ENDIF() + FOREACH(LIB ${LIBS_TO_SETUP}) IF(${LIB}_LIBRARY_DEBUG) From 54ccde5d02ffc2b91ca0ec03a24418a9aba6c8e5 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 7 Feb 2018 17:23:14 +0000 Subject: [PATCH 11/13] Refactored the event handler so that it contains a helper NodeVistor class rather than inherits from inappropriately using multiple inheritance. --- examples/osgsidebyside/osgsidebyside.cpp | 94 ++++++++++++++---------- 1 file changed, 54 insertions(+), 40 deletions(-) diff --git a/examples/osgsidebyside/osgsidebyside.cpp b/examples/osgsidebyside/osgsidebyside.cpp index b946b1a23..19dce979a 100644 --- a/examples/osgsidebyside/osgsidebyside.cpp +++ b/examples/osgsidebyside/osgsidebyside.cpp @@ -41,43 +41,14 @@ using namespace osg; using namespace osgGA; -class SwitchDOFVisitor : public osg::NodeVisitor, public osgGA::GUIEventHandler +class SwitchDOFHandler : public osgGA::GUIEventHandler { public: - SwitchDOFVisitor(): - osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN) + + SwitchDOFHandler() { } - SwitchDOFVisitor(const SwitchDOFVisitor& sdfv, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY) {} - - META_Object(osg, SwitchDOFVisitor) - - virtual void apply(Group& node) - { - osgSim::MultiSwitch* pMSwitch = dynamic_cast(&node); - - if (pMSwitch) - { - mSwitches.push_back(pMSwitch); - } - - osg::NodeVisitor::apply(node); - } - - virtual void apply(Transform& node) - { - osgSim::DOFTransform* pDof = dynamic_cast(&node); - - if (pDof) - { - mDofs.push_back(pDof); - pDof->setAnimationOn(true); - } - - osg::NodeVisitor::apply(node); - } - void nextSwitch() { for (size_t i=0; i < mSwitches.size(); i++) @@ -151,9 +122,53 @@ public: return false; } + void collectNodesOfInterest(osg::Node* node) + { + CollectNodes cn(this); + node->accept(cn); + } + private: - std::vector mSwitches; - std::vector mDofs; + + friend class CollectNodes; + + class CollectNodes : public osg::NodeVisitor + { + public: + SwitchDOFHandler* _parent; + + CollectNodes(SwitchDOFHandler* parent): + osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN), + _parent(parent) + { + } + + virtual void apply(Group& node) + { + osgSim::MultiSwitch* pMSwitch = dynamic_cast(&node); + if (pMSwitch) + { + _parent->mSwitches.push_back(pMSwitch); + } + + traverse(node); + } + + virtual void apply(Transform& node) + { + osgSim::DOFTransform* pDof = dynamic_cast(&node); + if (pDof) + { + _parent->mDofs.push_back(pDof); + pDof->setAnimationOn(true); + } + + traverse(node); + } + }; + + std::vector< osg::ref_ptr > mSwitches; + std::vector< osg::ref_ptr > mDofs; }; void singleWindowSideBySideCameras(osgViewer::Viewer& viewer) @@ -262,8 +277,8 @@ int main( int argc, char **argv ) viewer.addEventHandler(new osgViewer::LODScaleHandler()); viewer.addEventHandler(new osgGA::StateSetManipulator()); - SwitchDOFVisitor* visit = new SwitchDOFVisitor; - viewer.addEventHandler(visit); + SwitchDOFHandler* switchOFHandler = new SwitchDOFHandler; + viewer.addEventHandler(switchOFHandler); // load the scene. osg::ref_ptr loadedModel = osgDB::readRefNodeFiles(arguments); @@ -289,13 +304,12 @@ int main( int argc, char **argv ) group2->addChild(convertedModel.get()); group2->setNodeMask(2); - // Activate DOF animations and collect switches - loadedModel->accept(*visit); - convertedModel->accept(*visit); - group->addChild(group1); group->addChild(group2); + // Activate DOF animations and collect switches + switchOFHandler->collectNodesOfInterest(group); + viewer.setSceneData(group); viewer.setThreadingModel(osgViewer::Viewer::DrawThreadPerContext); From b99f7aaf5a1f4198b2173bb01a7d7068ec71ca44 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Sat, 10 Feb 2018 18:37:57 +0000 Subject: [PATCH 12/13] Changed internalFormat to use pixelFormat --- src/osgPlugins/tga/ReaderWriterTGA.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/osgPlugins/tga/ReaderWriterTGA.cpp b/src/osgPlugins/tga/ReaderWriterTGA.cpp index 5c2f11f0f..bcc8404f4 100644 --- a/src/osgPlugins/tga/ReaderWriterTGA.cpp +++ b/src/osgPlugins/tga/ReaderWriterTGA.cpp @@ -491,16 +491,17 @@ class ReaderWriterTGA : public osgDB::ReaderWriter int t = height_ret; int r = 1; - int internalFormat = numComponents_ret; - unsigned int pixelFormat = numComponents_ret == 1 ? GL_LUMINANCE : - numComponents_ret == 2 ? GL_LUMINANCE_ALPHA : - numComponents_ret == 3 ? GL_RGB : - numComponents_ret == 4 ? GL_RGBA : (GLenum)-1; + numComponents_ret == 2 ? GL_LUMINANCE_ALPHA : + numComponents_ret == 3 ? GL_RGB : + numComponents_ret == 4 ? GL_RGBA : (GLenum)-1; + + int internalFormat = pixelFormat; unsigned int dataType = GL_UNSIGNED_BYTE; + osg::Image* pOsgImage = new osg::Image; pOsgImage->setImage(s,t,r, internalFormat, From 14fdc5da8eb1829edb5cb9805a32fb5e9cb05edd Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 6 Mar 2018 10:22:05 +0000 Subject: [PATCH 13/13] Merged fixes from master --- src/osgPlugins/gdal/ReaderWriterGDAL.cpp | 44 ++++++++++++------------ 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/src/osgPlugins/gdal/ReaderWriterGDAL.cpp b/src/osgPlugins/gdal/ReaderWriterGDAL.cpp index 1d41c903d..30b046dbe 100644 --- a/src/osgPlugins/gdal/ReaderWriterGDAL.cpp +++ b/src/osgPlugins/gdal/ReaderWriterGDAL.cpp @@ -256,7 +256,7 @@ class ReaderWriterGDAL : public osgDB::ReaderWriter int internalFormat = GL_LUMINANCE; unsigned int pixelFormat = GL_LUMINANCE; unsigned int dataType = 0; - unsigned int numBytesPerPixel = 0; + unsigned int numBytesPerComponent = 0; GDALDataType targetGDALType = GDT_Byte; @@ -327,14 +327,14 @@ class ReaderWriterGDAL : public osgDB::ReaderWriter targetGDALType = band->GetRasterDataType(); switch(band->GetRasterDataType()) { - case(GDT_Byte): dataType = GL_UNSIGNED_BYTE; numBytesPerPixel = 1; break; - case(GDT_UInt16): dataType = GL_UNSIGNED_SHORT; numBytesPerPixel = 2; break; - case(GDT_Int16): dataType = GL_SHORT; numBytesPerPixel = 2; break; - case(GDT_UInt32): dataType = GL_UNSIGNED_INT; numBytesPerPixel = 4; break; - case(GDT_Int32): dataType = GL_INT; numBytesPerPixel = 4; break; - case(GDT_Float32): dataType = GL_FLOAT; numBytesPerPixel = 4; break; - case(GDT_Float64): dataType = GL_DOUBLE; numBytesPerPixel = 8; break; // not handled - default: dataType = 0; numBytesPerPixel = 0; break; // not handled + case(GDT_Byte): dataType = GL_UNSIGNED_BYTE; numBytesPerComponent = 1; break; + case(GDT_UInt16): dataType = GL_UNSIGNED_SHORT; numBytesPerComponent = 2; break; + case(GDT_Int16): dataType = GL_SHORT; numBytesPerComponent = 2; break; + case(GDT_UInt32): dataType = GL_UNSIGNED_INT; numBytesPerComponent = 4; break; + case(GDT_Int32): dataType = GL_INT; numBytesPerComponent = 4; break; + case(GDT_Float32): dataType = GL_FLOAT; numBytesPerComponent = 4; break; + case(GDT_Float64): dataType = GL_DOUBLE; numBytesPerComponent = 8; break; // not handled + default: dataType = 0; numBytesPerComponent = 0; break; // not handled } } } @@ -348,7 +348,7 @@ class ReaderWriterGDAL : public osgDB::ReaderWriter if (dataType==0) { dataType = GL_UNSIGNED_BYTE; - numBytesPerPixel = 1; + numBytesPerComponent = 1; targetGDALType = GDT_Byte; } @@ -360,7 +360,7 @@ class ReaderWriterGDAL : public osgDB::ReaderWriter { // RGBA - int pixelSpace=4*numBytesPerPixel; + int pixelSpace=4*numBytesPerComponent; int lineSpace=destWidth * pixelSpace; imageData = new unsigned char[destWidth * destHeight * pixelSpace]; @@ -370,16 +370,16 @@ class ReaderWriterGDAL : public osgDB::ReaderWriter OSG_INFO << "reading RGBA"<RasterIO(GF_Read,windowX,windowY,windowWidth,windowHeight,(void*)(imageData+0),destWidth,destHeight,targetGDALType,pixelSpace,lineSpace); - bandGreen->RasterIO(GF_Read,windowX,windowY,windowWidth,windowHeight,(void*)(imageData+1),destWidth,destHeight,targetGDALType,pixelSpace,lineSpace); - bandBlue->RasterIO(GF_Read,windowX,windowY,windowWidth,windowHeight,(void*)(imageData+2),destWidth,destHeight,targetGDALType,pixelSpace,lineSpace); - bandAlpha->RasterIO(GF_Read,windowX,windowY,windowWidth,windowHeight,(void*)(imageData+3),destWidth,destHeight,targetGDALType,pixelSpace,lineSpace); + bandGreen->RasterIO(GF_Read,windowX,windowY,windowWidth,windowHeight,(void*)(imageData+1*numBytesPerComponent),destWidth,destHeight,targetGDALType,pixelSpace,lineSpace); + bandBlue->RasterIO(GF_Read,windowX,windowY,windowWidth,windowHeight,(void*)(imageData+2*numBytesPerComponent),destWidth,destHeight,targetGDALType,pixelSpace,lineSpace); + bandAlpha->RasterIO(GF_Read,windowX,windowY,windowWidth,windowHeight,(void*)(imageData+3*numBytesPerComponent),destWidth,destHeight,targetGDALType,pixelSpace,lineSpace); } else { // RGB - int pixelSpace=3*numBytesPerPixel; + int pixelSpace=3*numBytesPerComponent; int lineSpace=destWidth * pixelSpace; imageData = new unsigned char[destWidth * destHeight * pixelSpace]; @@ -389,8 +389,8 @@ class ReaderWriterGDAL : public osgDB::ReaderWriter OSG_INFO << "reading RGB"<RasterIO(GF_Read,windowX,windowY,windowWidth,windowHeight,(void*)(imageData+0),destWidth,destHeight,targetGDALType,pixelSpace,lineSpace); - bandGreen->RasterIO(GF_Read,windowX,windowY,windowWidth,windowHeight,(void*)(imageData+1),destWidth,destHeight,targetGDALType,pixelSpace,lineSpace); - bandBlue->RasterIO(GF_Read,windowX,windowY,windowWidth,windowHeight,(void*)(imageData+2),destWidth,destHeight,targetGDALType,pixelSpace,lineSpace); + bandGreen->RasterIO(GF_Read,windowX,windowY,windowWidth,windowHeight,(void*)(imageData+1*numBytesPerComponent),destWidth,destHeight,targetGDALType,pixelSpace,lineSpace); + bandBlue->RasterIO(GF_Read,windowX,windowY,windowWidth,windowHeight,(void*)(imageData+2*numBytesPerComponent),destWidth,destHeight,targetGDALType,pixelSpace,lineSpace); } } @@ -399,7 +399,7 @@ class ReaderWriterGDAL : public osgDB::ReaderWriter if (bandAlpha) { // Luminance alpha - int pixelSpace=2*numBytesPerPixel; + int pixelSpace=2*numBytesPerComponent; int lineSpace=destWidth * pixelSpace; imageData = new unsigned char[destWidth * destHeight * pixelSpace]; @@ -414,7 +414,7 @@ class ReaderWriterGDAL : public osgDB::ReaderWriter else { // Luminance map - int pixelSpace=1*numBytesPerPixel; + int pixelSpace=1*numBytesPerComponent; int lineSpace=destWidth * pixelSpace; imageData = new unsigned char[destWidth * destHeight * pixelSpace]; @@ -429,7 +429,7 @@ class ReaderWriterGDAL : public osgDB::ReaderWriter else if (bandAlpha) { // alpha map - int pixelSpace=1*numBytesPerPixel; + int pixelSpace=1*numBytesPerComponent; int lineSpace=destWidth * pixelSpace; imageData = new unsigned char[destWidth * destHeight * pixelSpace]; @@ -444,7 +444,7 @@ class ReaderWriterGDAL : public osgDB::ReaderWriter else if (bandPalette) { // Paletted map - int pixelSpace=1*numBytesPerPixel; + int pixelSpace=1*numBytesPerComponent; int lineSpace=destWidth * pixelSpace; unsigned char *rawImageData; @@ -454,7 +454,7 @@ class ReaderWriterGDAL : public osgDB::ReaderWriter internalFormat = GL_RGBA; OSG_INFO << "reading palette"<RasterIO(GF_Read,windowX,windowY,windowWidth,windowHeight,(void*)(rawImageData),destWidth,destHeight,targetGDALType,pixelSpace,lineSpace);