This commit is contained in:
Robert Osfield 2016-08-26 18:00:52 +01:00
commit 322adc266c
25 changed files with 372 additions and 253 deletions

View File

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

View File

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

View File

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

View File

@ -26,6 +26,7 @@
#include <osgDB/Registry>
#include <osgDB/ReadFile>
#include <osgDB/WriteFile>
#include <osgGA/TrackballManipulator>
#include <osgGA/FlightManipulator>
@ -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);

View File

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

View File

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

View File

@ -16,7 +16,7 @@
#include <osg/StateSet>
#include <osg/Program>
#include <osg/Shader>
#include <osgUtil/Optimizer>
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 );

View File

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

View File

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

View File

@ -266,6 +266,8 @@ class OSGUTIL_EXPORT IncrementalCompileOperation : public osg::GraphicsOperation
typedef std::map<osg::GraphicsContext*, CompileList > CompileMap;
CompileMap _compileMap;
osg::ref_ptr<osg::Object> _markerObject;
protected:
virtual ~CompileSet() {}

View File

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

View File

@ -767,7 +767,7 @@ void GraphicsContext::removeCamera(osg::Camera* camera)
nitr != nodes.end();
++nitr)
{
const_cast<osg::Node*>(*nitr)->releaseGLObjects(_state.get());
(*nitr)->releaseGLObjects(_state.get());
}
// release the context of the any RenderingCache that the Camera has.

View File

@ -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"<<i;
osg_MultiTexCoord<<"osg_MultiTexCoord"<<i;
setUpVertexAttribAlias(_texCoordAliasList[i], slot++, gl_MultiTexCoord.str(), osg_MultiTexCoord.str(), "attribute vec4 ");
setUpVertexAttribAlias(_texCoordAliasList[i], slot++, gl_MultiTexCoord.str(), osg_MultiTexCoord.str(), "vec4 ");
}
setUpVertexAttribAlias(_secondaryColorAlias, slot++, "gl_SecondaryColor","osg_SecondaryColor","attribute vec4 ");
setUpVertexAttribAlias(_fogCoordAlias, slot++, "gl_FogCoord","osg_FogCoord","attribute float ");
setUpVertexAttribAlias(_secondaryColorAlias, slot++, "gl_SecondaryColor","osg_SecondaryColor","vec4 ");
setUpVertexAttribAlias(_fogCoordAlias, slot++, "gl_FogCoord","osg_FogCoord","float ");
}
else
{
setUpVertexAttribAlias(_vertexAlias,0, "gl_Vertex","osg_Vertex","attribute vec4 ");
setUpVertexAttribAlias(_normalAlias, 2, "gl_Normal","osg_Normal","attribute vec3 ");
setUpVertexAttribAlias(_colorAlias, 3, "gl_Color","osg_Color","attribute vec4 ");
setUpVertexAttribAlias(_secondaryColorAlias, 4, "gl_SecondaryColor","osg_SecondaryColor","attribute vec4 ");
setUpVertexAttribAlias(_fogCoordAlias, 5, "gl_FogCoord","osg_FogCoord","attribute float ");
setUpVertexAttribAlias(_vertexAlias,0, "gl_Vertex","osg_Vertex","vec4 ");
setUpVertexAttribAlias(_normalAlias, 2, "gl_Normal","osg_Normal","vec3 ");
setUpVertexAttribAlias(_colorAlias, 3, "gl_Color","osg_Color","vec4 ");
setUpVertexAttribAlias(_secondaryColorAlias, 4, "gl_SecondaryColor","osg_SecondaryColor","vec4 ");
setUpVertexAttribAlias(_fogCoordAlias, 5, "gl_FogCoord","osg_FogCoord","float ");
unsigned int base = 8;
_texCoordAliasList.resize(numTextureUnits);
@ -920,7 +920,7 @@ void State::resetVertexAttributeAlias(bool compactAliasing, unsigned int numText
gl_MultiTexCoord<<"gl_MultiTexCoord"<<i;
osg_MultiTexCoord<<"osg_MultiTexCoord"<<i;
setUpVertexAttribAlias(_texCoordAliasList[i], base+i, gl_MultiTexCoord.str(), osg_MultiTexCoord.str(), "attribute vec4 ");
setUpVertexAttribAlias(_texCoordAliasList[i], base+i, gl_MultiTexCoord.str(), osg_MultiTexCoord.str(), "vec4 ");
}
}
}
@ -1442,11 +1442,11 @@ namespace State_Utils
return replacedStr;
}
void replaceAndInsertDeclaration(std::string& source, std::string::size_type declPos, const std::string& originalStr, const std::string& newStr, const std::string& declarationPrefix)
void replaceAndInsertDeclaration(std::string& source, std::string::size_type declPos, const std::string& originalStr, const std::string& newStr, const std::string& qualifier, const std::string& declarationPrefix)
{
if (replace(source, originalStr, newStr))
{
source.insert(declPos, declarationPrefix + newStr + std::string(";\n"));
source.insert(declPos, qualifier + declarationPrefix + newStr + std::string(";\n"));
}
}
}
@ -1457,11 +1457,19 @@ bool State::convertVertexShaderSourceToOsgBuiltIns(std::string& source) const
OSG_INFO<<"++Before Converted source "<<std::endl<<source<<std::endl<<"++++++++"<<std::endl;
std::string attributeQualifier("attribute ");
// find the first legal insertion point for replacement declarations. GLSL requires that nothing
// precede a "#verson" compiler directive, so we must insert new declarations after it.
std::string::size_type declPos = source.rfind( "#version " );
if ( declPos != std::string::npos )
{
declPos = source.find(" ", declPos); // move to the first space after "#version"
declPos = source.find_first_not_of(std::string(" "), declPos); // skip all the spaces until you reach the version number
std::string versionNumber(source, declPos, 3);
int glslVersion = atoi(versionNumber.c_str());
OSG_INFO<<"shader version found: "<< glslVersion <<std::endl;
if (glslVersion >= 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> _shaderComposer;

View File

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

View File

@ -18,7 +18,7 @@
#include <osgDB/FileUtils>
#include <osgDB/WriteFile>
#include <osgDB/ObjectWrapper>
#include <fstream>
#include <osgDB/fstream>
#include <sstream>
#include <stdlib.h>
@ -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 );

View File

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

View File

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

View File

@ -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<EasyCurl> > ThreadCurlMap;

View File

@ -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"<<std::hex<<error<<std::dec<<std::endl;

View File

@ -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<double>::max();
}
// no much way to do better than replace invalid float NaN by 0

View File

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

View File

@ -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<osg::Program*>(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);
}
@ -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

View File

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

View File

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

View File

@ -1202,6 +1202,11 @@ bool GraphicsWindowCocoa::realizeImplementation()
attr[i++] = static_cast<NSOpenGLPixelFormatAttribute>(_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<NSOpenGLPixelFormatAttribute>(0);