From 5e4543513bd5ecb348990da0c5f6c5196d2fd097 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Gait=C3=A1n?= Date: Tue, 19 Jul 2016 13:40:19 +0200 Subject: [PATCH 01/18] Added OSG_CURL_SSL_VERIFYPEER option to the curl plugin to allow connecting to secure servers without the certificate --- src/osgPlugins/curl/ReaderWriterCURL.cpp | 22 +++++++++++++++++++--- src/osgPlugins/curl/ReaderWriterCURL.h | 5 ++++- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/osgPlugins/curl/ReaderWriterCURL.cpp b/src/osgPlugins/curl/ReaderWriterCURL.cpp index e0562f6d8..913662a08 100644 --- a/src/osgPlugins/curl/ReaderWriterCURL.cpp +++ b/src/osgPlugins/curl/ReaderWriterCURL.cpp @@ -142,6 +142,7 @@ EasyCurl::EasyCurl() _previousHttpAuthentication = 0; _connectTimeout = 0; // no timeout by default. _timeout = 0; + _sslVerifyPeer = 1L; _curl = curl_easy_init(); @@ -252,6 +253,9 @@ void EasyCurl::setOptions(const std::string& proxyAddress, const std::string& fi curl_easy_setopt(_curl, CURLOPT_PROXY, proxyAddress.c_str()); //Sets proxy address and port on libcurl } + // setting ssl verify peer (default is enabled) + curl_easy_setopt(_curl, CURLOPT_SSL_VERIFYPEER, _sslVerifyPeer); + const osgDB::AuthenticationDetails* details = authenticationMap ? authenticationMap->getAuthenticationDetails(fileName) : 0; @@ -385,6 +389,7 @@ ReaderWriterCURL::ReaderWriterCURL() supportsOption("OSG_CURL_PROXYPORT","Specify the http proxy port."); supportsOption("OSG_CURL_CONNECTTIMEOUT","Specify the connection timeout duration in seconds [default = 0 = not set]."); supportsOption("OSG_CURL_TIMEOUT","Specify the timeout duration of the whole transfer in seconds [default = 0 = not set]."); + supportsOption("OSG_CURL_SSL_VERIFYPEER","Specify ssl verification peer [default = 1 = set]."); } ReaderWriterCURL::~ReaderWriterCURL() @@ -428,11 +433,13 @@ osgDB::ReaderWriter::WriteResult ReaderWriterCURL::writeFile(const osg::Object& std::string proxyAddress; long connectTimeout = 0; long timeout = 0; - getConnectionOptions(options, proxyAddress, connectTimeout, timeout); + long sslVerifyPeer = 1; + getConnectionOptions(options, proxyAddress, connectTimeout, timeout, sslVerifyPeer); EasyCurl::StreamObject sp(&responseBuffer, &requestBuffer, std::string()); EasyCurl& easyCurl = getEasyCurl(); easyCurl.setConnectionTimeout(connectTimeout); easyCurl.setTimeout(timeout); + easyCurl.setSSLVerifyPeer(sslVerifyPeer); // Output requestBuffer via curl, and return responseBuffer in message of result. return easyCurl.write(proxyAddress, fullFileName, sp, options); @@ -452,7 +459,11 @@ osgDB::ReaderWriter::ReadResult ReaderWriterCURL::readFile(ObjectType objectType return ReadResult::FILE_NOT_HANDLED; } -void ReaderWriterCURL::getConnectionOptions(const osgDB::ReaderWriter::Options *options, std::string& proxyAddress, long& connectTimeout, long& timeout) const +void ReaderWriterCURL::getConnectionOptions(const osgDB::ReaderWriter::Options *options, + std::string& proxyAddress, + long& connectTimeout, + long& timeout, + long& sslVerifyPeer) const { if (options) { @@ -469,8 +480,11 @@ void ReaderWriterCURL::getConnectionOptions(const osgDB::ReaderWriter::Options * connectTimeout = atol(opt.substr( index+1 ).c_str()); // this will return 0 in case of improper format. else if( opt.substr( 0, index ) == "OSG_CURL_TIMEOUT" ) timeout = atol(opt.substr( index+1 ).c_str()); // this will return 0 in case of improper format. + else if( opt.substr(0, index) == "OSG_CURL_SSL_VERIFYPEER" ) + sslVerifyPeer = atol(opt.substr( index+1 ).c_str()); // this will return 0 in case of improper format. } + //Setting Proxy by OSG Options if(!optProxy.empty()) { @@ -529,7 +543,8 @@ osgDB::ReaderWriter::ReadResult ReaderWriterCURL::readFile(ObjectType objectType std::string proxyAddress; long connectTimeout = 0; long timeout = 0; - getConnectionOptions(options, proxyAddress, connectTimeout, timeout); + long sslVerifyPeer = 1; + getConnectionOptions(options, proxyAddress, connectTimeout, timeout, sslVerifyPeer); bool uncompress = false; @@ -568,6 +583,7 @@ osgDB::ReaderWriter::ReadResult ReaderWriterCURL::readFile(ObjectType objectType // setup the timeouts: easyCurl.setConnectionTimeout(connectTimeout); easyCurl.setTimeout(timeout); + easyCurl.setSSLVerifyPeer(sslVerifyPeer); ReadResult curlResult = easyCurl.read(proxyAddress, fileName, sp, options); diff --git a/src/osgPlugins/curl/ReaderWriterCURL.h b/src/osgPlugins/curl/ReaderWriterCURL.h index bac63bcd9..783954646 100644 --- a/src/osgPlugins/curl/ReaderWriterCURL.h +++ b/src/osgPlugins/curl/ReaderWriterCURL.h @@ -61,6 +61,8 @@ class EasyCurl : public osg::Referenced // the timeout variable is used to limit the whole transfer duration instead of the connection phase only. inline void setTimeout(long val) { _timeout = val; } + inline void setSSLVerifyPeer(long verifyPeer) { _sslVerifyPeer = verifyPeer; } + // Perform HTTP GET to download data from web server. osgDB::ReaderWriter::ReadResult read(const std::string& proxyAddress, const std::string& fileName, StreamObject& sp, const osgDB::ReaderWriter::Options *options); @@ -91,6 +93,7 @@ class EasyCurl : public osg::Referenced long _previousHttpAuthentication; long _connectTimeout; long _timeout; + long _sslVerifyPeer; }; @@ -171,7 +174,7 @@ class ReaderWriterCURL : public osgDB::ReaderWriter bool read(std::istream& fin, std::string& destination) const; protected: - void getConnectionOptions(const osgDB::ReaderWriter::Options *options, std::string& proxyAddress, long& connectTimeout, long& timeout) const; + void getConnectionOptions(const osgDB::ReaderWriter::Options *options, std::string& proxyAddress, long& connectTimeout, long& timeout, long& sslVerifyPeer) const; typedef std::map< OpenThreads::Thread*, osg::ref_ptr > ThreadCurlMap; From e1c0b74454f09148ca0dfb2ed41c1408cc6f7f15 Mon Sep 17 00:00:00 2001 From: Cedric Pinson Date: Thu, 31 Jan 2013 02:16:34 +0100 Subject: [PATCH 02/18] OsgUtil::TangentSpaceGenerator, merge tangent space for index array --- src/osgUtil/TangentSpaceGenerator.cpp | 163 ++++++++++---------------- 1 file changed, 65 insertions(+), 98 deletions(-) diff --git a/src/osgUtil/TangentSpaceGenerator.cpp b/src/osgUtil/TangentSpaceGenerator.cpp index c82bffbfb..a57988e12 100644 --- a/src/osgUtil/TangentSpaceGenerator.cpp +++ b/src/osgUtil/TangentSpaceGenerator.cpp @@ -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 1794374c78145d5a0e99fa91060c44eece1f81fc Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Sun, 31 Jul 2016 11:06:51 +0100 Subject: [PATCH 03/18] Fixed build error reported on gcc 4.6.4/Ubuntu 12.04 32bit, issue #108 --- src/osgPlugins/osgjs/json_stream | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/osgPlugins/osgjs/json_stream b/src/osgPlugins/osgjs/json_stream index 611a9b088..00e31162d 100644 --- a/src/osgPlugins/osgjs/json_stream +++ b/src/osgPlugins/osgjs/json_stream @@ -28,8 +28,6 @@ #include "utf8_string" -using namespace std; - // A simple class wrapping ofstream calls to enable generic cleaning of json data. // Especially 'standard' json should: // * have utf-8 encoded string @@ -37,8 +35,11 @@ using namespace std; // * does not support inf or nan values #if defined(WIN32) && !defined(__MINGW32__) && (!defined(_MSC_VER) || _MSC_VER<=1700) -inline int isfinite( double x ) { return _finite( x ); } -inline int isinf( double x ) { return !_finite( x ) && !_isnan( x ); } +namespace std +{ + inline int isfinite( double x ) { return _finite( x ); } + inline int isinf( double x ) { return !_finite( x ) && !_isnan( x ); } +} #endif @@ -91,11 +92,11 @@ class json_stream : public osgDB::ofstream { } double to_valid_float(const double d) { - if(isfinite(d)) { + if(std::isfinite(d)) { return d; } else { - if(isinf(d)) { + if(std::isinf(d)) { return std::numeric_limits::max(); } // no much way to do better than replace invalid float NaN by 0 From 2578fce085c26ce42711a596b956ac5f5434a2b5 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Sun, 31 Jul 2016 14:00:30 +0100 Subject: [PATCH 04/18] Added FT_LOAD_NO_HINTING --- src/osgPlugins/freetype/FreeTypeFont.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/osgPlugins/freetype/FreeTypeFont.cpp b/src/osgPlugins/freetype/FreeTypeFont.cpp index 0dcebb6a9..c647e2cf9 100644 --- a/src/osgPlugins/freetype/FreeTypeFont.cpp +++ b/src/osgPlugins/freetype/FreeTypeFont.cpp @@ -446,7 +446,7 @@ osgText::Glyph3D * FreeTypeFont::getGlyph3D(const osgText::FontResolution& fontR } } - FT_Error error = FT_Load_Char( _face, charindex, FT_LOAD_DEFAULT|_flags ); + FT_Error error = FT_Load_Char( _face, charindex, FT_LOAD_DEFAULT | FT_LOAD_NO_HINTING | _flags ); if (error) { OSG_WARN << "FT_Load_Char(...) error 0x"< Date: Mon, 1 Aug 2016 17:47:32 +0200 Subject: [PATCH 05/18] Fix RenderBuffer not being attached (bug introduced with commit 55b3becb7c0ceecf26b0dae2c6db80f9f2a8a6d4 ) --- src/osg/FrameBufferObject.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/osg/FrameBufferObject.cpp b/src/osg/FrameBufferObject.cpp index 1c37761cf..cb79979ba 100644 --- a/src/osg/FrameBufferObject.cpp +++ b/src/osg/FrameBufferObject.cpp @@ -449,6 +449,13 @@ void FrameBufferAttachment::attach(State &state, GLenum target, GLenum attachmen { unsigned int contextID = state.getContextID(); + if (_ximpl->targetType == Pimpl::RENDERBUFFER) + { + ext->glFramebufferRenderbuffer(target, attachment_point, GL_RENDERBUFFER_EXT, _ximpl->renderbufferTarget->getObjectID(contextID, ext)); + return; + } + + // targetType must be a texture, make sure we have a valid texture object Texture::TextureObject *tobj = 0; if (_ximpl->textureTarget.valid()) { @@ -465,10 +472,8 @@ void FrameBufferAttachment::attach(State &state, GLenum target, GLenum attachmen switch (_ximpl->targetType) { - default: case Pimpl::RENDERBUFFER: - ext->glFramebufferRenderbuffer(target, attachment_point, GL_RENDERBUFFER_EXT, _ximpl->renderbufferTarget->getObjectID(contextID, ext)); - break; + break; // already handled above. case should never be hit, just here to quieten compiler warning. case Pimpl::TEXTURE1D: ext->glFramebufferTexture1D(target, attachment_point, GL_TEXTURE_1D, tobj->id(), _ximpl->level); break; From 2550c95c32c91e430c3e681b429ed84b127e1423 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 2 Aug 2016 17:52:45 +0100 Subject: [PATCH 06/18] Added GL_NORMALIZE usage to handle the case of the FlattenStaticTransform visitor not being applied to the scaled subgraphs causing lighting problems --- examples/osganimate/osganimate.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/examples/osganimate/osganimate.cpp b/examples/osganimate/osganimate.cpp index f8db214b7..3a790c4d8 100644 --- a/examples/osganimate/osganimate.cpp +++ b/examples/osganimate/osganimate.cpp @@ -26,6 +26,7 @@ #include #include +#include #include #include @@ -146,7 +147,7 @@ osg::Node* createMovingModel(const osg::Vec3& center, float radius) float size = radius/bs.radius()*0.3f; osg::MatrixTransform* positioned = new osg::MatrixTransform; positioned->setDataVariance(osg::Object::STATIC); - positioned->setMatrix(osg::Matrix::translate(-bs.center())* + positioned ->setMatrix(osg::Matrix::translate(-bs.center())* osg::Matrix::scale(size,size,size)* osg::Matrix::rotate(osg::inDegrees(-90.0f),0.0f,0.0f,1.0f)); @@ -180,6 +181,10 @@ osg::Node* createMovingModel(const osg::Vec3& center, float radius) model->addChild(xform); } + #ifndef OSG_GLES2_AVAILABLE + model->getOrCreateStateSet()->setMode(GL_NORMALIZE, osg::StateAttribute::ON); + #endif + return model.release(); } @@ -247,6 +252,13 @@ int main( int argc, char **argv ) osgUtil::Optimizer optimzer; optimzer.optimize(rootnode); + std::string filename; + if (arguments.read("-o",filename)) + { + osgDB::writeNodeFile(*rootnode, filename); + return 1; + } + // set the scene to render viewer.setSceneData(rootnode); From b3c242e270f14860936fae8ae0075befac212d51 Mon Sep 17 00:00:00 2001 From: Juan Hernando Vieites Date: Thu, 4 Aug 2016 17:03:51 +0200 Subject: [PATCH 07/18] Added missing GL enums to Texture::computeInternalFormatType --- src/osg/Texture.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/osg/Texture.cpp b/src/osg/Texture.cpp index 4b862b485..e44e06736 100644 --- a/src/osg/Texture.cpp +++ b/src/osg/Texture.cpp @@ -1669,6 +1669,14 @@ void Texture::computeInternalFormatType() const case GL_RGB16UI_EXT: case GL_RGB8UI_EXT: + case GL_RG32UI: + case GL_RG16UI: + case GL_RG8UI: + + case GL_R32UI: + case GL_R16UI: + case GL_R8UI: + case GL_LUMINANCE32UI_EXT: case GL_LUMINANCE16UI_EXT: case GL_LUMINANCE8UI_EXT: @@ -1691,6 +1699,14 @@ void Texture::computeInternalFormatType() const case GL_RGB16I_EXT: case GL_RGB8I_EXT: + case GL_RG32I: + case GL_RG16I: + case GL_RG8I: + + case GL_R32I: + case GL_R16I: + case GL_R8I: + case GL_LUMINANCE32I_EXT: case GL_LUMINANCE16I_EXT: case GL_LUMINANCE8I_EXT: @@ -1711,6 +1727,12 @@ void Texture::computeInternalFormatType() const case GL_RGB32F_ARB: case GL_RGB16F_ARB: + case GL_RG32F: + case GL_RG16F: + + case GL_R32F: + case GL_R16F: + case GL_LUMINANCE32F_ARB: case GL_LUMINANCE16F_ARB: From a54dc347520ef85e62dcda2fa17636cedd22336f Mon Sep 17 00:00:00 2001 From: Mathieu MARACHE Date: Fri, 5 Aug 2016 07:49:22 +0200 Subject: [PATCH 08/18] Added CoreProfile selection if OSG_GL3_AVAILABLE defined --- src/osgViewer/GraphicsWindowCocoa.mm | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/osgViewer/GraphicsWindowCocoa.mm b/src/osgViewer/GraphicsWindowCocoa.mm index 72220d16b..c2ab32b80 100644 --- a/src/osgViewer/GraphicsWindowCocoa.mm +++ b/src/osgViewer/GraphicsWindowCocoa.mm @@ -1202,6 +1202,11 @@ bool GraphicsWindowCocoa::realizeImplementation() attr[i++] = static_cast(_traits->samples); } +#ifdef OSG_GL3_AVAILABLE + attr[i++] = NSOpenGLPFAOpenGLProfile; + attr[i++] = NSOpenGLProfileVersion3_2Core; + OSG_DEBUG << "GraphicsWindowCocoa::realizeImplementation :: set up for GL3 Core Profile"<< std::endl; +#endif attr[i++] = NSOpenGLPFAAccelerated; attr[i] = static_cast(0); From c77a7ecae920dcfc0c1da1154c626c492ab44f7f Mon Sep 17 00:00:00 2001 From: Mathieu MARACHE Date: Fri, 5 Aug 2016 07:51:33 +0200 Subject: [PATCH 09/18] Added usage of osgUtil::Optimizer to tessellate input geometry --- examples/osgsimplegl3/osgsimplegl3.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/examples/osgsimplegl3/osgsimplegl3.cpp b/examples/osgsimplegl3/osgsimplegl3.cpp index c1385d5d9..6a35b1fb6 100644 --- a/examples/osgsimplegl3/osgsimplegl3.cpp +++ b/examples/osgsimplegl3/osgsimplegl3.cpp @@ -16,7 +16,7 @@ #include #include #include - +#include void configureShaders( osg::StateSet* stateSet ) { @@ -73,6 +73,10 @@ int main( int argc, char** argv ) osg::notify( osg::FATAL ) << "Unable to load model from command line." << std::endl; return( 1 ); } + + osgUtil::Optimizer optimizer; + optimizer.optimize(root.get(), osgUtil::Optimizer::ALL_OPTIMIZATIONS | osgUtil::Optimizer::TESSELLATE_GEOMETRY); + configureShaders( root->getOrCreateStateSet() ); const int width( 800 ), height( 450 ); From 26bce07f2b28f206ad34e38251c9d2cb1aa3ac9e Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 10 Aug 2016 12:00:18 +0100 Subject: [PATCH 10/18] Fixed handlinge of fgets returning a 0 length string --- src/osgPlugins/stl/ReaderWriterSTL.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/osgPlugins/stl/ReaderWriterSTL.cpp b/src/osgPlugins/stl/ReaderWriterSTL.cpp index 89556149b..92aed56fd 100644 --- a/src/osgPlugins/stl/ReaderWriterSTL.cpp +++ b/src/osgPlugins/stl/ReaderWriterSTL.cpp @@ -588,9 +588,11 @@ ReaderWriterSTL::ReaderObject::ReadResult ReaderWriterSTL::AsciiReaderObject::re while (fgets(buf, sizeof(buf), fp)) { - // strip '\n' or '\r\n' and trailing whitespace - unsigned int len = strlen(buf) - 1; + unsigned int len = strlen(buf); + if (len==0) continue; + // strip '\n' or '\r\n' and trailing whitespace + --len; while (len && (buf[len] == '\n' || buf[len] == '\r' || isspace(buf[len]))) { buf[len--] = '\0'; From e6d4d99edb4dd71e0455b7fc8a303aaf21a4c299 Mon Sep 17 00:00:00 2001 From: "Konstantin S. Matveyev" Date: Wed, 10 Aug 2016 12:58:38 +0100 Subject: [PATCH 11/18] Fixed filename encoding bug --- src/osgDB/OutputStream.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/osgDB/OutputStream.cpp b/src/osgDB/OutputStream.cpp index 4132ff93f..41e72ae55 100644 --- a/src/osgDB/OutputStream.cpp +++ b/src/osgDB/OutputStream.cpp @@ -18,7 +18,7 @@ #include #include #include -#include +#include #include #include @@ -558,7 +558,7 @@ void OutputStream::writeImage( const osg::Image* img ) if ( isBinary() ) { std::string fullPath = osgDB::findDataFile( img->getFileName() ); - std::ifstream infile( fullPath.c_str(), std::ios::in|std::ios::binary ); + osgDB::ifstream infile( fullPath.c_str(), std::ios::in|std::ios::binary ); if ( infile ) { infile.seekg( 0, std::ios::end ); From 2b9dfab1fc0ece49715b7d12bb0448ac95e4ebd8 Mon Sep 17 00:00:00 2001 From: Anish Thomas Date: Wed, 10 Aug 2016 14:12:27 +0100 Subject: [PATCH 12/18] GLSL 1.3 support for vertex-attrib aliasing --- src/osg/State.cpp | 57 ++++++++++++++++++++++++++--------------------- 1 file changed, 32 insertions(+), 25 deletions(-) diff --git a/src/osg/State.cpp b/src/osg/State.cpp index e91af6adb..354275162 100644 --- a/src/osg/State.cpp +++ b/src/osg/State.cpp @@ -884,9 +884,9 @@ void State::resetVertexAttributeAlias(bool compactAliasing, unsigned int numText if (compactAliasing) { unsigned int slot = 0; - setUpVertexAttribAlias(_vertexAlias, slot++, "gl_Vertex","osg_Vertex","attribute vec4 "); - setUpVertexAttribAlias(_normalAlias, slot++, "gl_Normal","osg_Normal","attribute vec3 "); - setUpVertexAttribAlias(_colorAlias, slot++, "gl_Color","osg_Color","attribute vec4 "); + setUpVertexAttribAlias(_vertexAlias, slot++, "gl_Vertex","osg_Vertex","vec4 "); + setUpVertexAttribAlias(_normalAlias, slot++, "gl_Normal","osg_Normal","vec3 "); + setUpVertexAttribAlias(_colorAlias, slot++, "gl_Color","osg_Color","vec4 "); _texCoordAliasList.resize(numTextureUnits); for(unsigned int i=0; i<_texCoordAliasList.size(); i++) @@ -896,20 +896,20 @@ void State::resetVertexAttributeAlias(bool compactAliasing, unsigned int numText gl_MultiTexCoord<<"gl_MultiTexCoord"<= 130) attributeQualifier = "in "; // found the string, now find the next linefeed and set the insertion point after it. declPos = source.find( '\n', declPos ); declPos = declPos != std::string::npos ? declPos+1 : source.length(); @@ -1477,23 +1485,23 @@ bool State::convertVertexShaderSourceToOsgBuiltIns(std::string& source) const State_Utils::replace(source, "ftransform()", "gl_ModelViewProjectionMatrix * gl_Vertex"); // replace built in uniform - State_Utils::replaceAndInsertDeclaration(source, declPos, "gl_ModelViewMatrix", "osg_ModelViewMatrix", "uniform mat4 "); - State_Utils::replaceAndInsertDeclaration(source, declPos, "gl_ModelViewProjectionMatrix", "osg_ModelViewProjectionMatrix", "uniform mat4 "); - State_Utils::replaceAndInsertDeclaration(source, declPos, "gl_ProjectionMatrix", "osg_ProjectionMatrix", "uniform mat4 "); - State_Utils::replaceAndInsertDeclaration(source, declPos, "gl_NormalMatrix", "osg_NormalMatrix", "uniform mat3 "); + State_Utils::replaceAndInsertDeclaration(source, declPos, "gl_ModelViewMatrix", "osg_ModelViewMatrix", "uniform ", "mat4 "); + State_Utils::replaceAndInsertDeclaration(source, declPos, "gl_ModelViewProjectionMatrix", "osg_ModelViewProjectionMatrix", "uniform ", "mat4 "); + State_Utils::replaceAndInsertDeclaration(source, declPos, "gl_ProjectionMatrix", "osg_ProjectionMatrix", "uniform ", "mat4 "); + State_Utils::replaceAndInsertDeclaration(source, declPos, "gl_NormalMatrix", "osg_NormalMatrix", "uniform ", "mat3 "); } if (_useVertexAttributeAliasing) { - State_Utils::replaceAndInsertDeclaration(source, declPos, _vertexAlias._glName, _vertexAlias._osgName, _vertexAlias._declaration); - State_Utils::replaceAndInsertDeclaration(source, declPos, _normalAlias._glName, _normalAlias._osgName, _normalAlias._declaration); - State_Utils::replaceAndInsertDeclaration(source, declPos, _colorAlias._glName, _colorAlias._osgName, _colorAlias._declaration); - State_Utils::replaceAndInsertDeclaration(source, declPos, _secondaryColorAlias._glName, _secondaryColorAlias._osgName, _secondaryColorAlias._declaration); - State_Utils::replaceAndInsertDeclaration(source, declPos, _fogCoordAlias._glName, _fogCoordAlias._osgName, _fogCoordAlias._declaration); + State_Utils::replaceAndInsertDeclaration(source, declPos, _vertexAlias._glName, _vertexAlias._osgName, attributeQualifier, _vertexAlias._declaration); + State_Utils::replaceAndInsertDeclaration(source, declPos, _normalAlias._glName, _normalAlias._osgName, attributeQualifier, _normalAlias._declaration); + State_Utils::replaceAndInsertDeclaration(source, declPos, _colorAlias._glName, _colorAlias._osgName, attributeQualifier, _colorAlias._declaration); + State_Utils::replaceAndInsertDeclaration(source, declPos, _secondaryColorAlias._glName, _secondaryColorAlias._osgName, attributeQualifier, _secondaryColorAlias._declaration); + State_Utils::replaceAndInsertDeclaration(source, declPos, _fogCoordAlias._glName, _fogCoordAlias._osgName, attributeQualifier, _fogCoordAlias._declaration); for (size_t i=0; i<_texCoordAliasList.size(); i++) { const VertexAttribAlias& texCoordAlias = _texCoordAliasList[i]; - State_Utils::replaceAndInsertDeclaration(source, declPos, texCoordAlias._glName, texCoordAlias._osgName, texCoordAlias._declaration); + State_Utils::replaceAndInsertDeclaration(source, declPos, texCoordAlias._glName, texCoordAlias._osgName, attributeQualifier, texCoordAlias._declaration); } } @@ -1725,7 +1733,6 @@ void State::print(std::ostream& fout) const #if 0 GraphicsContext* _graphicsContext; unsigned int _contextID; - bool _shaderCompositionEnabled; bool _shaderCompositionDirty; osg::ref_ptr _shaderComposer; From e9d6737ec49a13da784a2d1bf19141534e2ac51f Mon Sep 17 00:00:00 2001 From: Ravi Mathur Date: Wed, 10 Aug 2016 14:30:28 +0100 Subject: [PATCH 13/18] Updates to the CMake build system for Mac OSX --- CMakeLists.txt | 151 ++++++++++++++++----- CMakeModules/FindAVFoundation.cmake | 8 +- CMakeModules/FindQuickTime.cmake | 23 ++-- examples/osgmultitouch/CMakeLists.txt | 6 + examples/osgoscdevice/CMakeLists.txt | 7 +- examples/osgviewerCocoa/CMakeLists.txt | 6 + src/osgPlugins/avfoundation/CMakeLists.txt | 5 + src/osgViewer/CMakeLists.txt | 43 +----- 8 files changed, 159 insertions(+), 90 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e4a512b62..735f64f36 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -49,6 +49,82 @@ if(COMMAND cmake_policy) endif() +IF(APPLE) + # Get OSX version in MAJOR.MINOR format + EXECUTE_PROCESS(COMMAND sw_vers -productVersion + OUTPUT_VARIABLE OSG_OSX_VERSION + OUTPUT_STRIP_TRAILING_WHITESPACE) + STRING(REGEX REPLACE "^([0-9]+\\.[0-9]+).*$" "\\1" + OSG_OSX_VERSION "${OSG_OSX_VERSION}") +ENDIF() + +# Set OSX architecture flags here, since they must be specified before +# creating the actual OSG project. +# Note that the CMAKE_OSX_* variables are not well documented in +# CMake 2.8, but they do officially exist. +# See https://cmake.org/Bug/view.php?id=14695#c34953 +# Additionally, OSG_WINDOWING_SYSTEM is set here for OSX since its +# value is needed to find the correct version of OpenGL (X11 or Cocoa). +IF(APPLE AND NOT ANDROID) + + # Here we check if the user specified IPhone SDK + # These options are formally defined later, but can also be specified + # by the user at the command line using the cmake -D switch + # Note that FORCE is used since the user will likely enable IPhone + # build via CMake GUI after already having configured once + IF(OSG_BUILD_PLATFORM_IPHONE OR OSG_BUILD_PLATFORM_IPHONE_SIMULATOR) + SET(OSG_WINDOWING_SYSTEM "IOS" CACHE STRING "Windowing system type for graphics window creation, options only IOS.") + + #set iphone arch and flags taken from http://sites.google.com/site/michaelsafyan/coding/resources/how-to-guides/cross-compile-for-the-iphone/how-to-cross-compile-for-the-iphone-using-cmake + IF(OSG_BUILD_PLATFORM_IPHONE) + IF(${IPHONE_VERSION_MIN} LESS "7.0") + SET(CMAKE_OSX_ARCHITECTURES "armv6;armv7" CACHE STRING "Build architectures for iOS" FORCE) + ELSE() + SET(CMAKE_OSX_ARCHITECTURES "armv7;armv7s;arm64" CACHE STRING "Build architectures for iOS" FORCE) + ENDIF() + + ELSE() + #simulator uses i386 architectures + SET(CMAKE_OSX_ARCHITECTURES "i386" CACHE STRING "Build architectures for iOS Simulator" FORCE) + ENDIF() + + #here we set the specific iphone sdk version. We can only set either device or simulator sdk. So if you want both you currently have to have two seperate projects + SET(CMAKE_OSX_SYSROOT "${IPHONE_SDKROOT}" CACHE STRING "System root for iOS" FORCE) + + ELSE() + # OSX >= 10.5 uses Cocoa windowing system, otherwise Carbon + IF(OSG_OSX_VERSION VERSION_LESS 10.5) + SET(OSG_WINDOWING_SYSTEM "Carbon" CACHE STRING "Windowing system type for graphics window creation, options Carbon, Cocoa or X11.") + ELSE() + SET(OSG_WINDOWING_SYSTEM "Cocoa" CACHE STRING "Windowing system type for graphics window creation, options Carbon, Cocoa or X11.") + ENDIF() + + # Set defaults for Universal Binaries. We want 32-bit Intel/PPC on 10.4 + # and 32/64-bit Intel/PPC on >= 10.5. Anything <= 10.3 doesn't support. + # These are set the first time CMake is run, and can be changed by + # the user at any time. + IF(OSG_OSX_VERSION VERSION_GREATER 10.7) + # 64 Bit Works, i386,ppc is not supported any more + SET(CMAKE_OSX_ARCHITECTURES "x86_64" CACHE STRING "Build architectures for OSX") + SET(CMAKE_OSX_DEPLOYMENT_TARGET "10.8" CACHE STRING "Target OSX version") + ELSEIF(OSG_OSX_VERSION VERSION_EQUAL 10.7) + # 64 Bit Works, PPC is not supported any more + SET(CMAKE_OSX_ARCHITECTURES "i386;x86_64" CACHE STRING "Build architectures for OSX") + ELSEIF(OSG_OSX_VERSION VERSION_GREATER 10.4) + # 64-bit compiles are not supported with Carbon. + SET(CMAKE_OSX_ARCHITECTURES "ppc;i386" CACHE STRING "Build architectures for OSX") + SET(CMAKE_OSX_DEPLOYMENT_TARGET "10.5" CACHE STRING "Target OSX version") + ELSEIF(OSG_OSX_VERSION VERSION_EQUAL 10.4) + # 64-bit compiles are not supported with Carbon. + SET(CMAKE_OSX_ARCHITECTURES "ppc;i386" CACHE STRING "Build architectures for OSX") + ELSE() + # No Universal Binary support and SDK detection is too unreliable. + # Warn user and continue at their own peril. + MESSAGE(WARNING "OSX 10.3 and earlier not supported.") + ENDIF() + ENDIF() +ENDIF() + PROJECT(OpenSceneGraph) SET(OPENSCENEGRAPH_MAJOR_VERSION 3) @@ -168,16 +244,6 @@ ENDIF(OSG_MAINTAINER) IF(NOT ANDROID) IF(APPLE) - # Determine the canonical name of the selected Platform SDK - EXECUTE_PROCESS(COMMAND "/usr/bin/sw_vers" "-productVersion" - OUTPUT_VARIABLE OSG_OSX_SDK_NAME - OUTPUT_STRIP_TRAILING_WHITESPACE) - STRING(REPLACE "." ";" MACOS_VERSION_LIST ${OSG_OSX_SDK_NAME}) - LIST(GET MACOS_VERSION_LIST 0 MACOS_VERSION_MAJOR) - LIST(GET MACOS_VERSION_LIST 1 MACOS_VERSION_MINOR) - - SET(OSG_OSX_SDK_NAME "macosx${MACOS_VERSION_MAJOR}.${MACOS_VERSION_MINOR}") - # Trying to get CMake to generate an XCode IPhone project, current efforts are to get iphoneos sdk 3.1 working # Added option which needs manually setting to select the IPhone SDK for building. We can only have one of the below # set to true. Should realy have an OSG_BUILD_PLATFORM variable that we set to our desired platform @@ -214,9 +280,33 @@ IF(APPLE) FIND_LIBRARY(CARBON_LIBRARY Carbon) FIND_LIBRARY(COCOA_LIBRARY Cocoa) - # Apple OS X: Find OpenGL and AGL + # Apple OS X: Find OpenGL and AGL based on OSG_WINDOWING_SYSTEM + # This is the accepted way of finding X11/OpenGL on OSX, as + # documented in CMake's FindOpenGL module. + # Note that without this check, libosg would use Cocoa/OpenGL but + # libosgViewer would use X11/OpenGL, which causes compatibility + # issues for applications using OSG. + UNSET(OPENGL_gl_LIBRARY CACHE) + UNSET(OPENGL_glu_LIBRARY CACHE) + UNSET(OPENGL_INCLUDE_DIR CACHE) + IF(OSG_WINDOWING_SYSTEM STREQUAL "X11") + FIND_PACKAGE(X11) + IF(NOT X11_FOUND) + MESSAGE(FATAL_ERROR "OSG_WINDOWING_SYSTEM is X11, but no X11 installation was found. Please make sure X11 is properly installed.") + ENDIF() + + # Use X11 version of OpenGL as seed for CMake FindOpenGL + GET_FILENAME_COMPONENT(X11LIBDIR ${X11_X11_LIB} DIRECTORY) + FIND_LIBRARY(OPENGL_gl_LIBRARY GL PATHS ${X11LIBDIR} DOC "OpenGL lib for OSX" NO_DEFAULT_PATH) + FIND_LIBRARY(OPENGL_glu_LIBRARY GLU PATHS ${X11LIBDIR} DOC "GLU lib for OSX" NO_DEFAULT_PATH) + SET(OPENGL_INCLUDE_DIR ${X11_INCLUDE_DIR} CACHE PATH "Include for OpenGL on OSX" FORCE) + + ELSEIF(OSG_WINDOWING_SYSTEM STREQUAL "Carbon") + # AGL needed for Carbon windowing systems + FIND_LIBRARY(AGL_LIBRARY AGL) + ENDIF() + FIND_PACKAGE(OpenGL) - FIND_LIBRARY(AGL_LIBRARY AGL) ENDIF () OPTION(OSG_COMPILE_FRAMEWORKS "compile frameworks instead of dylibs (experimental)" OFF) @@ -1108,30 +1198,19 @@ IF(APPLE AND NOT ANDROID) # FORCE is used because the options are not reflected in the UI otherwise. # Seems like a good place to add version specific compiler flags too. IF(NOT OSG_CONFIG_HAS_BEEN_RUN_BEFORE) - IF(${MACOS_VERSION_MAJOR} EQUAL 10 AND ${MACOS_VERSION_MINOR} GREATER 7) - SET(OSG_DEFAULT_IMAGE_PLUGIN_FOR_OSX "imageio" CACHE STRING "Forced imageio default image plugin for OSX" FORCE) - # 64 Bit Works, i386,ppc is not supported any more - SET(CMAKE_OSX_ARCHITECTURES "x86_64" CACHE STRING "Build architectures for OSX" FORCE) - SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mmacosx-version-min=10.8 -fvisibility-inlines-hidden" CACHE STRING "Flags used by the compiler during all build types." FORCE) - ELSEIF(${OSG_OSX_SDK_NAME} STREQUAL "macosx10.7") - SET(OSG_DEFAULT_IMAGE_PLUGIN_FOR_OSX "imageio" CACHE STRING "Forced imageio default image plugin for OSX" FORCE) - # 64 Bit Works, PPC is not supported any more - SET(CMAKE_OSX_ARCHITECTURES "i386;x86_64" CACHE STRING "Build architectures for OSX" FORCE) - SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mmacosx-version-min=10.7 -fvisibility-inlines-hidden" CACHE STRING "Flags used by the compiler during all build types." FORCE) - ELSEIF(${OSG_OSX_SDK_NAME} STREQUAL "macosx10.6" OR ${OSG_OSX_SDK_NAME} STREQUAL "macosx10.5") - SET(OSG_DEFAULT_IMAGE_PLUGIN_FOR_OSX "imageio" CACHE STRING "Forced imageio default image plugin for OSX" FORCE) - # 64-bit compiles are not supported with Carbon. - SET(CMAKE_OSX_ARCHITECTURES "ppc;i386" CACHE STRING "Build architectures for OSX" FORCE) - SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mmacosx-version-min=10.5 -ftree-vectorize -fvisibility-inlines-hidden" CACHE STRING "Flags used by the compiler during all build types." FORCE) - ELSEIF(${OSG_OSX_SDK_NAME} STREQUAL "macosx10.4") - SET(OSG_DEFAULT_IMAGE_PLUGIN_FOR_OSX "quicktime" CACHE STRING "Forced imageio default image plugin for OSX" FORCE) - SET(CMAKE_OSX_ARCHITECTURES "ppc;i386" CACHE STRING "Build architectures for OSX" FORCE) - SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mmacosx-version-min=10.4 -ftree-vectorize -fvisibility-inlines-hidden" CACHE STRING "Flags used by the compiler during all build types." FORCE) - ELSE() - # No Universal Binary support - # Should break down further to set the -mmacosx-version-min, - # but the SDK detection is too unreliable here. - ENDIF() + IF(OSG_OSX_VERSION VERSION_GREATER 10.7) + SET(OSG_DEFAULT_IMAGE_PLUGIN_FOR_OSX "imageio" CACHE STRING "Forced imageio default image plugin for OSX" FORCE) + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility-inlines-hidden" CACHE STRING "Flags used by the compiler during all build types." FORCE) + ELSEIF(OSG_OSX_VERSION VERSION_EQUAL 10.7) + SET(OSG_DEFAULT_IMAGE_PLUGIN_FOR_OSX "imageio" CACHE STRING "Forced imageio default image plugin for OSX" FORCE) + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility-inlines-hidden" CACHE STRING "Flags used by the compiler during all build types." FORCE) + ELSEIF(OSG_OSX_VERSION VERSION_GREATER 10.4) + SET(OSG_DEFAULT_IMAGE_PLUGIN_FOR_OSX "imageio" CACHE STRING "Forced imageio default image plugin for OSX" FORCE) + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ftree-vectorize -fvisibility-inlines-hidden" CACHE STRING "Flags used by the compiler during all build types." FORCE) + ELSEIF(OSG_OSX_VERSION VERSION_EQUAL 10.4) + SET(OSG_DEFAULT_IMAGE_PLUGIN_FOR_OSX "quicktime" CACHE STRING "Forced imageio default image plugin for OSX" FORCE) + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ftree-vectorize -fvisibility-inlines-hidden" CACHE STRING "Flags used by the compiler during all build types." FORCE) + ENDIF() ENDIF() OPTION(OSG_BUILD_APPLICATION_BUNDLES "Enable the building of applications and examples as OSX Bundles" OFF) diff --git a/CMakeModules/FindAVFoundation.cmake b/CMakeModules/FindAVFoundation.cmake index 21ce76be0..efbc260be 100644 --- a/CMakeModules/FindAVFoundation.cmake +++ b/CMakeModules/FindAVFoundation.cmake @@ -30,11 +30,9 @@ ELSE() # AVFoundation exists since 10.7, but only 10.8 has all features necessary for OSG # so check the SDK-setting - IF(${OSG_OSX_SDK_NAME} STREQUAL "macosx10.8" OR ${OSG_OSX_SDK_NAME} STREQUAL "macosx10.9" OR ${OSG_OSX_SDK_NAME} STREQUAL "macosx10.10" OR ${OSG_OSX_SDK_NAME} STREQUAL "macosx10.11") - # nothing special here ;-) - ELSE() - MESSAGE("AVFoundation disabled for SDK < 10.8") - SET(AV_FOUNDATION_FOUND "NO") + IF(OSG_OSX_VERSION VERSION_LESS 10.8) + MESSAGE("AVFoundation disabled for SDK < 10.8") + SET(AV_FOUNDATION_FOUND "NO") ENDIF() ENDIF() ENDIF() diff --git a/CMakeModules/FindQuickTime.cmake b/CMakeModules/FindQuickTime.cmake index bffc99b94..a9ea895f0 100644 --- a/CMakeModules/FindQuickTime.cmake +++ b/CMakeModules/FindQuickTime.cmake @@ -55,19 +55,20 @@ ELSE() #Quicktime is not supported under 64bit OSX build so we need to detect it and disable it. #First check to see if we are running with a native 64-bit compiler (10.6 default) and implicit arch IF(NOT CMAKE_OSX_ARCHITECTURES AND CMAKE_SIZEOF_VOID_P EQUAL 8) - SET(QUICKTIME_FOUND "NO") + MESSAGE("Disabling QuickTime on 64-bit architectures") + SET(QUICKTIME_FOUND "NO") + ELSEIF(OSG_OSX_VERSION VERSION_GREATER 10.6) + # Quicktime officially deprecated starting 10.7 + MESSAGE("Disabling QuickTime because it's not supported by the selected SDK ${OSG_OSX_VERSION}") + SET(QUICKTIME_FOUND "NO") ELSE() - #Otherwise check to see if 64-bit is explicitly called for. - LIST(FIND CMAKE_OSX_ARCHITECTURES "x86_64" has64Compile) - IF(NOT has64Compile EQUAL -1) - SET(QUICKTIME_FOUND "NO") - ENDIF() - ENDIF() - # Disable quicktime for >= 10.7, as it's officially deprecated - - IF(${OSG_OSX_SDK_NAME} STREQUAL "macosx10.7" OR ${OSG_OSX_SDK_NAME} STREQUAL "macosx10.8" OR ${OSG_OSX_SDK_NAME} STREQUAL "macosx10.9" OR ${OSG_OSX_SDK_NAME} STREQUAL "macosx10.10") - MESSAGE("disabling quicktime because it's not supported by the selected SDK ${OSG_OSX_SDK_NAME}") + #Otherwise check to see if 64-bit is explicitly called for. + LIST(FIND CMAKE_OSX_ARCHITECTURES "x86_64" has64Compile) + IF(NOT has64Compile EQUAL -1) + MESSAGE("Disabling QuickTime on 64-bit architectures") SET(QUICKTIME_FOUND "NO") + ENDIF() ENDIF() + ENDIF() ENDIF() diff --git a/examples/osgmultitouch/CMakeLists.txt b/examples/osgmultitouch/CMakeLists.txt index 84e80a14f..cdf4bdb17 100644 --- a/examples/osgmultitouch/CMakeLists.txt +++ b/examples/osgmultitouch/CMakeLists.txt @@ -1,3 +1,9 @@ +# On OSX, this example only compiles if using Cocoa +IF(APPLE AND NOT (OSG_WINDOWING_SYSTEM STREQUAL "Cocoa")) + MESSAGE(WARNING "Disabling osgmultitouch example because it requires OSG_WINDOWING_SYSTEM to be Cocoa") + RETURN() +ENDIF() + SET(TARGET_SRC osgmultitouch.cpp ) #### end var setup ### diff --git a/examples/osgoscdevice/CMakeLists.txt b/examples/osgoscdevice/CMakeLists.txt index 4c0ece7fc..63d4a2c81 100644 --- a/examples/osgoscdevice/CMakeLists.txt +++ b/examples/osgoscdevice/CMakeLists.txt @@ -1,5 +1,8 @@ -#this file is automatically generated - +# On OSX, this example only compiles if using Cocoa +IF(APPLE AND NOT (OSG_WINDOWING_SYSTEM STREQUAL "Cocoa")) + MESSAGE(WARNING "Disabling osgoscdevice example because it requires OSG_WINDOWING_SYSTEM to be Cocoa") + RETURN() +ENDIF() SET(TARGET_SRC osgoscdevice.cpp ) #### end var setup ### diff --git a/examples/osgviewerCocoa/CMakeLists.txt b/examples/osgviewerCocoa/CMakeLists.txt index cb11af1ef..601bba33c 100644 --- a/examples/osgviewerCocoa/CMakeLists.txt +++ b/examples/osgviewerCocoa/CMakeLists.txt @@ -1,3 +1,9 @@ +# On OSX, this example only compiles if using Cocoa +IF(APPLE AND NOT (OSG_WINDOWING_SYSTEM STREQUAL "Cocoa")) + MESSAGE(WARNING "Disabling osgviewerCocoa example because it requires OSG_WINDOWING_SYSTEM to be Cocoa") + RETURN() +ENDIF() + FILE(GLOB ui_files_1 "English.lproj/*.strings") FILE(GLOB ui_files_2 "English.lproj/MainMenu.nib/*.nib") SET(TARGET_SRC ViewerCocoa.mm main.mm Info.plist ${ui_files_1} ${ui_files_2}) diff --git a/src/osgPlugins/avfoundation/CMakeLists.txt b/src/osgPlugins/avfoundation/CMakeLists.txt index b09d36e93..07b276b30 100644 --- a/src/osgPlugins/avfoundation/CMakeLists.txt +++ b/src/osgPlugins/avfoundation/CMakeLists.txt @@ -1,3 +1,8 @@ +# AVFoundation plugin only works with OSX/Cocoa (not X11 or Carbon) +IF(NOT OSG_WINDOWING_SYSTEM STREQUAL "Cocoa") + MESSAGE(WARNING "Disabling AVFoundation plugin because it requires OSG_WINDOWING_SYSTEM to be Cocoa") + RETURN() +ENDIF() SET(TARGET_SRC OSXAVFoundationVideo.mm diff --git a/src/osgViewer/CMakeLists.txt b/src/osgViewer/CMakeLists.txt index 4872aaf86..a57865b65 100644 --- a/src/osgViewer/CMakeLists.txt +++ b/src/osgViewer/CMakeLists.txt @@ -81,27 +81,10 @@ IF(WIN32 AND NOT ANDROID) PixelBufferWin32.cpp ) ELSE() - IF(APPLE AND NOT ANDROID) - - IF(OSG_BUILD_PLATFORM_IPHONE OR OSG_BUILD_PLATFORM_IPHONE_SIMULATOR) - SET(OSG_WINDOWING_SYSTEM "IOS" CACHE STRING "Windowing system type for graphics window creation, options only IOS.") - ELSE() - IF(${OSG_OSX_SDK_NAME} STREQUAL "macosx10.4" OR - ${OSG_OSX_SDK_NAME} STREQUAL "macosx10.3" OR - ${OSG_OSX_SDK_NAME} STREQUAL "macosx10.2" OR - ${OSG_OSX_SDK_NAME} STREQUAL "macosx10.1") - SET(OSG_WINDOWING_SYSTEM "Carbon" CACHE STRING "Windowing system type for graphics window creation, options Carbon, Cocoa or X11.") - ELSE() - SET(OSG_WINDOWING_SYSTEM "Cocoa" CACHE STRING "Windowing system type for graphics window creation, options Carbon, Cocoa or X11.") - ENDIF() - ENDIF() - + IF(ANDROID) + SET(OSG_WINDOWING_SYSTEM "None" CACHE STRING "None Windowing system type for graphics window creation.") ELSE() - IF(ANDROID) - SET(OSG_WINDOWING_SYSTEM "None" CACHE STRING "None Windowing system type for graphics window creation.") - ELSE() - SET(OSG_WINDOWING_SYSTEM "X11" CACHE STRING "Windowing system type for graphics window creation. options only X11") - ENDIF() + SET(OSG_WINDOWING_SYSTEM "X11" CACHE STRING "Windowing system type for graphics window creation. options only X11") ENDIF() IF(${OSG_WINDOWING_SYSTEM} STREQUAL "Cocoa") @@ -222,30 +205,18 @@ ELSE() ENDIF() ENDIF() - # X11 on Apple requires X11 library plus OpenGL linking hack on Leopard IF(APPLE) # hack for finding the iphone opengl es lib IF(OSG_BUILD_PLATFORM_IPHONE OR OSG_BUILD_PLATFORM_IPHONE_SIMULATOR) - SET(OPENGL_INCLUDE_DIR ${IPHONE_SDKROOT}System/Library/Frameworks) - SET(OPENGL_LIBRARIES ${IPHONE_SDKROOT}System/Library/Frameworks/OpenGLES) + SET(OPENGL_INCLUDE_DIR ${IPHONE_SDKROOT}/System/Library/Frameworks) + SET(OPENGL_LIBRARIES ${IPHONE_SDKROOT}/System/Library/Frameworks/OpenGLES) ELSE() - # Find GL/glx.h - IF(EXISTS ${CMAKE_OSX_SYSROOT}/usr/X11/include/GL/glx.h) - SET(OPENGL_INCLUDE_DIR /usr/X11/include) - SET(OPENGL_LIBRARIES /usr/X11/lib/libGL.dylib) - ELSEIF(EXISTS ${CMAKE_OSX_SYSROOT}/usr/X11R6/include/GL/glx.h) - SET(OPENGL_INCLUDE_DIR /usr/X11R6/include) - SET(OPENGL_LIBRARIES /usr/X11R6/lib/libGL.dylib) - ENDIF() - INCLUDE_DIRECTORIES(BEFORE SYSTEM ${OPENGL_INCLUDE_DIR}) - - SET(LIB_EXTRA_LIBS ${X11_X11_LIB} ${OPENGL_LIBRARIES} ${LIB_EXTRA_LIBS}) - SET(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,-dylib_file,/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib:${CMAKE_OSX_SYSROOT}/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib") + SET(LIB_EXTRA_LIBS ${X11_X11_LIB} ${LIB_EXTRA_LIBS}) ENDIF() ELSE(APPLE) - SET(LIB_EXTRA_LIBS ${X11_X11_LIB} ${LIB_EXTRA_LIBS}) + SET(LIB_EXTRA_LIBS ${X11_X11_LIB} ${LIB_EXTRA_LIBS}) ENDIF(APPLE) ELSE() MESSAGE(STATUS "Windowing system not supported") From 0b450a5113755ee8e31e10477462afb290ebd206 Mon Sep 17 00:00:00 2001 From: scrawl Date: Sun, 14 Aug 2016 19:30:55 +0200 Subject: [PATCH 14/18] Remove an unneeded const_cast --- src/osg/GraphicsContext.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/osg/GraphicsContext.cpp b/src/osg/GraphicsContext.cpp index b0530b976..3beddee93 100644 --- a/src/osg/GraphicsContext.cpp +++ b/src/osg/GraphicsContext.cpp @@ -767,7 +767,7 @@ void GraphicsContext::removeCamera(osg::Camera* camera) nitr != nodes.end(); ++nitr) { - const_cast(*nitr)->releaseGLObjects(_state.get()); + (*nitr)->releaseGLObjects(_state.get()); } // release the context of the any RenderingCache that the Camera has. From 06cb31a3d265a63c6db693120abec3c9fac591f3 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 15 Aug 2016 11:45:58 +0100 Subject: [PATCH 15/18] Added automatic assignment of _markerObject to CompileSet. --- include/osgUtil/IncrementalCompileOperation | 4 +++- src/osgUtil/IncrementalCompileOperation.cpp | 6 +++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/include/osgUtil/IncrementalCompileOperation b/include/osgUtil/IncrementalCompileOperation index c739cd6d5..76f51dbb8 100644 --- a/include/osgUtil/IncrementalCompileOperation +++ b/include/osgUtil/IncrementalCompileOperation @@ -24,7 +24,7 @@ class OSGUTIL_EXPORT StateToCompile : public osg::NodeVisitor { public: - StateToCompile(GLObjectsVisitor::Mode mode, osg::Object* markerObject=0); + StateToCompile(GLObjectsVisitor::Mode mode, osg::Object* markerObject); typedef std::set DrawableSet; typedef std::set StateSetSet; @@ -266,6 +266,8 @@ class OSGUTIL_EXPORT IncrementalCompileOperation : public osg::GraphicsOperation typedef std::map CompileMap; CompileMap _compileMap; + osg::ref_ptr _markerObject; + protected: virtual ~CompileSet() {} diff --git a/src/osgUtil/IncrementalCompileOperation.cpp b/src/osgUtil/IncrementalCompileOperation.cpp index 8cf2a2c78..c0b0aa3bb 100644 --- a/src/osgUtil/IncrementalCompileOperation.cpp +++ b/src/osgUtil/IncrementalCompileOperation.cpp @@ -420,7 +420,8 @@ void IncrementalCompileOperation::CompileSet::buildCompileMap(ContextSet& contex { if (contexts.empty() || !_subgraphToCompile) return; - StateToCompile stc(mode); + StateToCompile stc(mode, _markerObject.get()); + _subgraphToCompile->accept(stc); buildCompileMap(contexts, stc); @@ -579,6 +580,9 @@ void IncrementalCompileOperation::add(CompileSet* compileSet, bool callBuildComp { if (!compileSet) return; + // pass on the markerObject to the CompileSet + compileSet->_markerObject = _markerObject; + if (compileSet->_subgraphToCompile.valid()) { // force a compute of the bound of the subgraph to avoid the update traversal from having to do this work From 9d9025a6b41d7638fd27ff46cac14ee4286636c3 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 15 Aug 2016 12:13:07 +0100 Subject: [PATCH 16/18] Changed the default paramter for the osgUtil::StateToCompile to retain the OSG-3.4 ABI and fixed indentation. --- include/osgUtil/IncrementalCompileOperation | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/osgUtil/IncrementalCompileOperation b/include/osgUtil/IncrementalCompileOperation index 76f51dbb8..9a753b7e0 100644 --- a/include/osgUtil/IncrementalCompileOperation +++ b/include/osgUtil/IncrementalCompileOperation @@ -24,7 +24,7 @@ class OSGUTIL_EXPORT StateToCompile : public osg::NodeVisitor { public: - StateToCompile(GLObjectsVisitor::Mode mode, osg::Object* markerObject); + StateToCompile(GLObjectsVisitor::Mode mode, osg::Object* markerObject=0); typedef std::set DrawableSet; typedef std::set StateSetSet; @@ -266,7 +266,7 @@ class OSGUTIL_EXPORT IncrementalCompileOperation : public osg::GraphicsOperation typedef std::map CompileMap; CompileMap _compileMap; - osg::ref_ptr _markerObject; + osg::ref_ptr _markerObject; protected: From 8f68da89d7fb75264fde742d59ea888415b489a6 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 15 Aug 2016 12:56:57 +0100 Subject: [PATCH 17/18] Fixed handling in osgUtil::IncrementalCompileOperation/CompileSet/StateToCompile when the _markerObject is NULL. --- src/osgUtil/IncrementalCompileOperation.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/osgUtil/IncrementalCompileOperation.cpp b/src/osgUtil/IncrementalCompileOperation.cpp index c0b0aa3bb..f43c9f31a 100644 --- a/src/osgUtil/IncrementalCompileOperation.cpp +++ b/src/osgUtil/IncrementalCompileOperation.cpp @@ -77,7 +77,7 @@ void StateToCompile::apply(osg::Drawable& drawable) _drawablesHandled.insert(&drawable); - if (_markerObject.get()!=drawable.getUserData()) + if (!_markerObject || _markerObject.get()!=drawable.getUserData()) { if (drawable.getDataVariance()!=osg::Object::STATIC) { @@ -114,7 +114,7 @@ void StateToCompile::apply(osg::Drawable& drawable) } // mark the drawable as visited - if (drawable.getUserData()==0) drawable.setUserData(_markerObject.get()); + if (_markerObject.valid() && drawable.getUserData()==0) drawable.setUserData(_markerObject.get()); } } @@ -125,15 +125,15 @@ void StateToCompile::apply(osg::StateSet& stateset) _statesetsHandled.insert(&stateset); if ((_mode & GLObjectsVisitor::COMPILE_STATE_ATTRIBUTES)!=0 && - _markerObject.get()!=stateset.getUserData()) + (!_markerObject || _markerObject.get()!=stateset.getUserData())) { osg::Program* program = dynamic_cast(stateset.getAttribute(osg::StateAttribute::PROGRAM)); - if (program && _markerObject.get()!=program->getUserData()) + if (program && (!_markerObject || _markerObject.get()!=program->getUserData())) { _programs.insert(program); // mark the stateset as visited - if (program->getUserData()==0) program->setUserData(_markerObject.get()); + if (_markerObject.valid() && program->getUserData()==0) program->setUserData(_markerObject.get()); } const osg::StateSet::TextureAttributeList& tal = stateset.getTextureAttributeList(); @@ -159,14 +159,14 @@ void StateToCompile::apply(osg::StateSet& stateset) } // mark the stateset as visited - if (stateset.getUserData()==0) stateset.setUserData(_markerObject.get()); + if (_markerObject.valid() && stateset.getUserData()==0) stateset.setUserData(_markerObject.get()); } } void StateToCompile::apply(osg::Texture& texture) { // don't make any changes if Texture already processed - if (_markerObject.get()==texture.getUserData()) return; + if (_markerObject.valid() && _markerObject.get()==texture.getUserData()) return; if (_assignPBOToImages) { @@ -213,7 +213,7 @@ void StateToCompile::apply(osg::Texture& texture) } } - if (texture.getUserData()==0) texture.setUserData(_markerObject.get()); + if (_markerObject.valid() && texture.getUserData()==0) texture.setUserData(_markerObject.get()); _textures.insert(&texture); } From ea9f479674da71c222696bd2254a7c91433365f1 Mon Sep 17 00:00:00 2001 From: James Turner Date: Fri, 5 Aug 2016 13:16:07 +0100 Subject: [PATCH 18/18] Attempt to fix broken DLL exports from osgDB Only export the osgDB method implementations, instead of the entire class, and hence avoid exporting symbols from the base class, which then conflict with other compilation units when linking. This avoids the need for /FORCE:MULTIPLE linker option with MSVC. --- include/osgDB/fstream | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/include/osgDB/fstream b/include/osgDB/fstream index cb3c1bdcd..fb6f840aa 100644 --- a/include/osgDB/fstream +++ b/include/osgDB/fstream @@ -31,27 +31,27 @@ namespace osgDB void OSGDB_EXPORT open(std::fstream& fs, const char* filename,std::ios_base::openmode mode); -class OSGDB_EXPORT ifstream : public std::ifstream +class ifstream : public std::ifstream { public: - ifstream(); - explicit ifstream(const char* filename, + OSGDB_EXPORT ifstream(); + OSGDB_EXPORT explicit ifstream(const char* filename, std::ios_base::openmode mode = std::ios_base::in); - ~ifstream(); + OSGDB_EXPORT ~ifstream(); - void open(const char* filename, + void OSGDB_EXPORT open(const char* filename, std::ios_base::openmode mode = std::ios_base::in); }; -class OSGDB_EXPORT ofstream : public std::ofstream +class ofstream : public std::ofstream { public: - ofstream(); - explicit ofstream(const char* filename, + OSGDB_EXPORT ofstream(); + OSGDB_EXPORT explicit ofstream(const char* filename, std::ios_base::openmode mode = std::ios_base::out); - ~ofstream(); + OSGDB_EXPORT ~ofstream(); - void open(const char* filename, + void OSGDB_EXPORT open(const char* filename, std::ios_base::openmode mode = std::ios_base::out); };