From d7b161078af3873d717ff202d08182bffda17945 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 25 Nov 2010 16:06:04 +0000 Subject: [PATCH] From Thomas Hogarth and Stephan Huber, "attached you'll find part one of iphone-support. It includes * support for NPOT-textures on IOS * support for FBOs (only renderToTexture for now) on IOS (should work for other OpenGL ES 1/2 targets, too) * FileUtils-support for IOS" --- include/osg/GL | 4 ++-- include/osg/GraphicsContext | 7 +++++++ src/osg/FrameBufferObject.cpp | 10 +++++++++- src/osg/GraphicsContext.cpp | 6 ++++-- src/osg/Texture.cpp | 2 +- src/osgDB/FileUtils.cpp | 26 +++++++++++++++++++++++--- src/osgUtil/RenderStage.cpp | 6 ++++-- 7 files changed, 50 insertions(+), 11 deletions(-) diff --git a/include/osg/GL b/include/osg/GL index cd3f52f58..585343a70 100644 --- a/include/osg/GL +++ b/include/osg/GL @@ -20,7 +20,7 @@ #if defined(OSG_GLES1_AVAILABLE) #ifdef __APPLE__ - //if its apple include the target defines so we can check for iphone + //if its apple include the target defines so we can check for IOS #include "TargetConditionals.h" #include #else @@ -30,7 +30,7 @@ #elif defined(OSG_GLES2_AVAILABLE) #ifdef __APPLE__ - //if its apple include the target defines so we can check for iphone + //if its apple include the target defines so we can check for IOS #include "TargetConditionals.h" #include #else diff --git a/include/osg/GraphicsContext b/include/osg/GraphicsContext index 040e35b7b..84c261e24 100644 --- a/include/osg/GraphicsContext +++ b/include/osg/GraphicsContext @@ -460,6 +460,11 @@ class OSG_EXPORT GraphicsContext : public Object /** Get the the const list of cameras associated with this graphics context.*/ const Cameras& getCameras() const { return _cameras; } + + /** set the default FBO-id, this id will be used when the rendering-backend is finished with RTT FBOs */ + void setDefaultFboId(GLuint i) { _defaultFboId = i; } + + GLuint getDefaultFboId() const { return _defaultFboId; } public: @@ -510,6 +515,8 @@ class OSG_EXPORT GraphicsContext : public Object ref_ptr _swapCallback; Timer_t _lastClearTick; + + GLuint _defaultFboId; }; diff --git a/src/osg/FrameBufferObject.cpp b/src/osg/FrameBufferObject.cpp index 220cfe87e..e50c158b1 100644 --- a/src/osg/FrameBufferObject.cpp +++ b/src/osg/FrameBufferObject.cpp @@ -39,7 +39,15 @@ FBOExtensions* FBOExtensions::instance(unsigned contextID, bool createIfNotInita /************************************************************************** * FBOExtensions **************************************************************************/ -#define LOAD_FBO_EXT(name) setGLExtensionFuncPtr(name, (#name), ( std::string(#name)+std::string("EXT") ).c_str() ) +#if defined(OSG_GLES1_AVAILABLE) || defined(OSG_GLES2_AVAILABLE) + #if defined(OSG_GLES1_AVAILABLE) + #define LOAD_FBO_EXT(name) setGLExtensionFuncPtr(name, (#name), (std::string(#name)+std::string("OES") ).c_str() ) + #else + #define LOAD_FBO_EXT(name) setGLExtensionFuncPtr(name, (#name), std::string(#name).c_str() ) + #endif +#else + #define LOAD_FBO_EXT(name) setGLExtensionFuncPtr(name, (#name), (std::string(#name)+std::string("EXT") ).c_str() ) +#endif FBOExtensions::FBOExtensions(unsigned int contextID) : glBindRenderbuffer(0), diff --git a/src/osg/GraphicsContext.cpp b/src/osg/GraphicsContext.cpp index ceba69df6..dc41d29e6 100644 --- a/src/osg/GraphicsContext.cpp +++ b/src/osg/GraphicsContext.cpp @@ -444,7 +444,8 @@ GraphicsContext::GraphicsContext(): _clearColor(osg::Vec4(0.0f,0.0f,0.0f,1.0f)), _clearMask(0), _threadOfLastMakeCurrent(0), - _lastClearTick(0) + _lastClearTick(0), + _defaultFboId(0) { setThreadSafeRefUnref(true); _operationsBlock = new RefBlock; @@ -456,7 +457,8 @@ GraphicsContext::GraphicsContext(const GraphicsContext&, const osg::CopyOp&): _clearColor(osg::Vec4(0.0f,0.0f,0.0f,1.0f)), _clearMask(0), _threadOfLastMakeCurrent(0), - _lastClearTick(0) + _lastClearTick(0), + _defaultFboId(0) { setThreadSafeRefUnref(true); _operationsBlock = new RefBlock; diff --git a/src/osg/Texture.cpp b/src/osg/Texture.cpp index c6b4759c1..cc26a637b 100644 --- a/src/osg/Texture.cpp +++ b/src/osg/Texture.cpp @@ -2336,7 +2336,7 @@ Texture::Extensions::Extensions(unsigned int contextID) _isClientStorageSupported = isGLExtensionSupported(contextID,"GL_APPLE_client_storage"); - _isNonPowerOfTwoTextureNonMipMappedSupported = builtInSupport || isGLExtensionOrVersionSupported(contextID,"GL_ARB_texture_non_power_of_two", 2.0); + _isNonPowerOfTwoTextureNonMipMappedSupported = builtInSupport || isGLExtensionOrVersionSupported(contextID,"GL_ARB_texture_non_power_of_two", 2.0) || isGLExtensionSupported(contextID,"GL_APPLE_texture_2D_limited_npot"); _isNonPowerOfTwoTextureMipMappedSupported = builtInSupport || _isNonPowerOfTwoTextureNonMipMappedSupported; diff --git a/src/osgDB/FileUtils.cpp b/src/osgDB/FileUtils.cpp index ede10b99c..3e2069a79 100644 --- a/src/osgDB/FileUtils.cpp +++ b/src/osgDB/FileUtils.cpp @@ -47,6 +47,24 @@ typedef char TCHAR; // I'm not sure how we would handle this in raw Darwin // without the AvailablilityMacros. #include + + //>OSG_IOS + //IOS includes + #include "TargetConditionals.h" + + #if (TARGET_OS_IPHONE) + #include + // workaround a bug which appears when compiling for SDK < 4.0 and for the simulator + #ifdef __IPHONE_4_0 && (__IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_4_0) + #define stat64 stat + #else + #if !TARGET_IPHONE_SIMULATOR + #define stat64 stat + #endif + #endif + #endif + // diff --git a/src/osgUtil/RenderStage.cpp b/src/osgUtil/RenderStage.cpp index 9ab3fe806..2bdd86fb2 100644 --- a/src/osgUtil/RenderStage.cpp +++ b/src/osgUtil/RenderStage.cpp @@ -524,7 +524,8 @@ void RenderStage::runCameraSetUp(osg::RenderInfo& renderInfo) OSG_NOTICE<<"RenderStage::runCameraSetUp(), FBO setup failed, FBO status= 0x"<glBindFramebuffer(GL_FRAMEBUFFER_EXT, 0); + GLuint fboId = state.getGraphicsContext() ? state.getGraphicsContext()->getDefaultFboId() : 0; + fbo_ext->glBindFramebuffer(GL_FRAMEBUFFER_EXT, fboId); fbo = 0; // clean up. @@ -1050,7 +1051,8 @@ void RenderStage::drawInner(osg::RenderInfo& renderInfo,RenderLeaf*& previous, b if (getDisableFboAfterRender()) { // switch off the frame buffer object - fbo_ext->glBindFramebuffer(GL_FRAMEBUFFER_EXT, 0); + GLuint fboId = state.getGraphicsContext() ? state.getGraphicsContext()->getDefaultFboId() : 0; + fbo_ext->glBindFramebuffer(GL_FRAMEBUFFER_EXT, fboId); } doCopyTexture = true;