diff --git a/CMake/Packages/FindZZip.cmake b/CMake/Packages/FindZZip.cmake index c1120712cd9..e97951e2c60 100644 --- a/CMake/Packages/FindZZip.cmake +++ b/CMake/Packages/FindZZip.cmake @@ -32,7 +32,7 @@ clear_if_changed(ZZip_PREFIX_PATH ZZip_INCLUDE_DIR ) -set(ZZip_LIBRARY_NAMES zziplib zzip) +set(ZZip_LIBRARY_NAMES zziplib zzip zzip-0) get_debug_names(ZZip_LIBRARY_NAMES) use_pkgconfig(ZZip_PKGC zziplib) diff --git a/CMakeLists.txt b/CMakeLists.txt index 48af55b9630..5b794cc4af4 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,7 +14,7 @@ # and provide build configuration options. ###################################################################### -cmake_minimum_required(VERSION 2.8.0) +cmake_minimum_required(VERSION 3.5.1) set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS TRUE) cmake_policy(SET CMP0003 NEW) diff --git a/OgreMain/CMakeLists.txt b/OgreMain/CMakeLists.txt index 0424ebbc9fb..39f29f61f7e 100644 --- a/OgreMain/CMakeLists.txt +++ b/OgreMain/CMakeLists.txt @@ -419,7 +419,7 @@ else() set_target_properties(OgreMain PROPERTIES VERSION ${OGRE_SOVERSION} SOVERSION ${OGRE_SOVERSION}) endif() -if(OGRE_GCC_VERSION VERSION_EQUAL 4.8 OR OGRE_GCC_VERSION VERSION_GREATER 4.8) +if((OGRE_GCC_VERSION VERSION_EQUAL 4.8 OR OGRE_GCC_VERSION VERSION_GREATER 4.8) AND NOT APPLE) if(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD") list(APPEND LIBRARIES "-latomic_ops") else() diff --git a/OgreMain/include/OgreTextureFilters.h b/OgreMain/include/OgreTextureFilters.h index 0784878c609..dc61ba1abee 100644 --- a/OgreMain/include/OgreTextureFilters.h +++ b/OgreMain/include/OgreTextureFilters.h @@ -83,7 +83,9 @@ namespace TextureFilter See DefaultMipmapGen::DefaultMipmapGen */ static uint8 selectMipmapGen( uint32 filters, const Image2 &image, + PixelFormatGpu finalPixelFormat, const TextureGpuManager *textureManager ); + public: static void createFilters( uint32 filters, FilterBaseArray &outFilters, const TextureGpu *texture, const Image2 &image, diff --git a/OgreMain/include/OgreTextureGpuManager.h b/OgreMain/include/OgreTextureGpuManager.h index 1bd06525951..b35fdfb3b87 100644 --- a/OgreMain/include/OgreTextureGpuManager.h +++ b/OgreMain/include/OgreTextureGpuManager.h @@ -874,6 +874,25 @@ namespace Ogre bool saveOitd, bool saveOriginal, HlmsTextureExportListener *listener ); + /** Checks if the given format with the texture flags combination is supported + + @param format + @param textureFlags + See TextureFlags::TextureFlags + Supported flags are: + NotTexture + RenderToTexture + Uav + AllowAutomipmaps + + When NotTexture is set, we don't check whether it's possible to sample from + this texture. Note that some buggy Android drivers may report that it's not + possible to sample from that texture when it actually is. + @return + True if supported. False otherwise + */ + virtual bool checkSupport( PixelFormatGpu format, uint32 textureFlags ) const; + protected: /// Returns false if the entry was not found in the cache bool applyMetadataCacheTo( TextureGpu *texture ); diff --git a/OgreMain/src/OSX/OgreConfigDialog.mm b/OgreMain/src/OSX/OgreConfigDialog.mm index 3b6fe6c4743..76e664c5f27 100644 --- a/OgreMain/src/OSX/OgreConfigDialog.mm +++ b/OgreMain/src/OSX/OgreConfigDialog.mm @@ -212,6 +212,10 @@ - (id)init [mRenderSystemsPopUp addItemWithTitle:renderSystemName]; } + // Initalise storage for the table data source + mOptionsKeys = [[NSMutableArray alloc] init]; + mOptionsValues = [[NSMutableArray alloc] init]; + [self refreshConfigOptions]; } return self; @@ -219,8 +223,8 @@ - (id)init -(void) refreshConfigOptions { - NSMutableArray* keys = [NSMutableArray array]; - NSMutableArray* values = [NSMutableArray array]; + [mOptionsKeys removeAllObjects]; + [mOptionsValues removeAllObjects]; // Get detected option values and add them to our config dictionary String selectedRenderSystemName = String([[[mRenderSystemsPopUp selectedItem] title] UTF8String]); @@ -228,12 +232,10 @@ -(void) refreshConfigOptions const ConfigOptionMap& opts = rs->getConfigOptions(); for (ConfigOptionMap::const_iterator pOpt = opts.begin(); pOpt != opts.end(); ++pOpt) { - [keys addObject:[NSString stringWithUTF8String:pOpt->first.c_str()]]; - [values addObject:[NSString stringWithUTF8String:pOpt->second.currentValue.c_str()]]; + [mOptionsKeys addObject:[NSString stringWithUTF8String:pOpt->first.c_str()]]; + [mOptionsValues addObject:[NSString stringWithUTF8String:pOpt->second.currentValue.c_str()]]; } - mOptionsKeys = keys; - mOptionsValues = values; [mOptionsTable reloadData]; } diff --git a/OgreMain/src/OgrePlatformInformation.cpp b/OgreMain/src/OgrePlatformInformation.cpp index 7af3aafddef..8c58648a93c 100644 --- a/OgreMain/src/OgrePlatformInformation.cpp +++ b/OgreMain/src/OgrePlatformInformation.cpp @@ -43,6 +43,8 @@ THE SOFTWARE. #if OGRE_PLATFORM != OGRE_PLATFORM_WIN32 #if OGRE_PLATFORM == OGRE_PLATFORM_ANDROID #include + #elif OGRE_PLATFORM == OGRE_PLATFORM_APPLE || OGRE_PLATFORM == OGRE_PLATFORM_APPLE_IOS + #include #endif #endif diff --git a/OgreMain/src/OgreTextureFilters.cpp b/OgreMain/src/OgreTextureFilters.cpp index 04d57dabe75..9eff0d6ad80 100644 --- a/OgreMain/src/OgreTextureFilters.cpp +++ b/OgreMain/src/OgreTextureFilters.cpp @@ -45,6 +45,7 @@ namespace TextureFilter } //----------------------------------------------------------------------------------- uint8 FilterBase::selectMipmapGen( uint32 filters, const Image2 &image, + PixelFormatGpu finalPixelFormat, const TextureGpuManager *textureManager ) { DefaultMipmapGen::DefaultMipmapGen retVal = DefaultMipmapGen::NoMipmaps; @@ -64,7 +65,7 @@ namespace TextureFilter defaultMipmapGeneration : defaultMipmapGenerationCubemaps; - if( PixelFormatGpuUtils::supportsHwMipmaps( image.getPixelFormat() ) ) + if( textureManager->checkSupport( finalPixelFormat, TextureFlags::AllowAutomipmaps ) ) retVal = mipmapGen; else retVal = DefaultMipmapGen::SwMode; @@ -84,15 +85,24 @@ namespace TextureFilter FilterBaseArray filtersVec; filtersVec.swap( outFilters ); + PixelFormatGpu finalPixelFormat = image.getPixelFormat(); + if( filters & TextureFilter::TypePrepareForNormalMapping ) + { + finalPixelFormat = PrepareForNormalMapping::getDestinationFormat( finalPixelFormat ); filtersVec.push_back( OGRE_NEW TextureFilter::PrepareForNormalMapping() ); + } if( filters & TextureFilter::TypeLeaveChannelR ) + { + finalPixelFormat = LeaveChannelR::getDestinationFormat( finalPixelFormat ); filtersVec.push_back( OGRE_NEW TextureFilter::LeaveChannelR() ); + } //Add mipmap generation as one of the last steps if( filters & TextureFilter::TypeGenerateDefaultMipmaps ) { - const uint8 mipmapGen = selectMipmapGen( filters, image, texture->getTextureManager() ); + const uint8 mipmapGen = + selectMipmapGen( filters, image, finalPixelFormat, texture->getTextureManager() ); //If the user wants Mipmaps when loading OnStorage -> OnSystemRam //then he should either explicitly ask only for SW filters, or //load the texture to Resident first, then download to OnSystemRam. @@ -132,16 +142,17 @@ namespace TextureFilter //Add mipmap generation as one of the last steps if( filters & TextureFilter::TypeGenerateDefaultMipmaps ) { - const uint8 mipmapGen = selectMipmapGen( filters, image, textureGpuManager ); + const uint8 mipmapGen = + selectMipmapGen( filters, image, inOutPixelFormat, textureGpuManager ); const bool canDoMipmaps = - (mipmapGen == DefaultMipmapGen::HwMode && - PixelFormatGpuUtils::supportsHwMipmaps( image.getPixelFormat() )) || - (mipmapGen == DefaultMipmapGen::SwMode && - Image2::supportsSwMipmaps( image.getPixelFormat(), image.getDepthOrSlices(), - image.getTextureType(), - static_cast( - GenerateSwMipmaps::getFilter( image ) ) ) ); + ( mipmapGen == DefaultMipmapGen::HwMode && + textureGpuManager->checkSupport( inOutPixelFormat, + TextureFlags::AllowAutomipmaps ) ) || + ( mipmapGen == DefaultMipmapGen::SwMode && + Image2::supportsSwMipmaps( + inOutPixelFormat, image.getDepthOrSlices(), image.getTextureType(), + static_cast( GenerateSwMipmaps::getFilter( image ) ) ) ); if( canDoMipmaps && inOutNumMipmaps <= 1u) { diff --git a/OgreMain/src/OgreTextureGpuManager.cpp b/OgreMain/src/OgreTextureGpuManager.cpp index 65b4ebb2757..f176318ce9b 100644 --- a/OgreMain/src/OgreTextureGpuManager.cpp +++ b/OgreMain/src/OgreTextureGpuManager.cpp @@ -806,6 +806,26 @@ namespace Ogre savedTextures.insert( resourceName ); } //----------------------------------------------------------------------------------- + bool TextureGpuManager::checkSupport( PixelFormatGpu format, uint32 textureFlags ) const + { + OGRE_ASSERT_LOW( + textureFlags != TextureFlags::NotTexture && + "Invalid textureFlags combination. Asking to check if format is supported to do nothing" ); + + if( textureFlags & TextureFlags::AllowAutomipmaps ) + { +#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE + // Disable hardware mipmap generation on macOS while there is no fallback + // for OpenGL < 4.2 implemented in TextureGpuManager::copyTo + return false; +#endif + if( !PixelFormatGpuUtils::supportsHwMipmaps( format ) ) + return false; + } + + return true; + } + //----------------------------------------------------------------------------------- TextureGpuManager::MetadataCacheEntry::MetadataCacheEntry() : width( 0 ), height( 0 ), diff --git a/RenderSystems/GL3Plus/include/OgreGL3PlusPrerequisites.h b/RenderSystems/GL3Plus/include/OgreGL3PlusPrerequisites.h index cc999592c51..bf4b2ac9c0b 100644 --- a/RenderSystems/GL3Plus/include/OgreGL3PlusPrerequisites.h +++ b/RenderSystems/GL3Plus/include/OgreGL3PlusPrerequisites.h @@ -88,6 +88,7 @@ namespace Ogre { # include #elif OGRE_PLATFORM == OGRE_PLATFORM_APPLE # include +# include # include # include #endif diff --git a/RenderSystems/GL3Plus/include/windowing/OSX/OgreOSXCocoaContext.h b/RenderSystems/GL3Plus/include/windowing/OSX/OgreOSXCocoaContext.h index cd9c5805ca8..394d5205dba 100644 --- a/RenderSystems/GL3Plus/include/windowing/OSX/OgreOSXCocoaContext.h +++ b/RenderSystems/GL3Plus/include/windowing/OSX/OgreOSXCocoaContext.h @@ -33,36 +33,32 @@ THE SOFTWARE. namespace Ogre { - class _OgreGL3PlusExport CocoaContext : public GL3PlusContext, public GeneralAllocatedObject + class _OgrePrivate CocoaContext : public GL3PlusContext { public: CocoaContext(NSOpenGLContext *context, NSOpenGLPixelFormat *pixelFormat); virtual ~CocoaContext(); - /** See GL3PlusContext */ + /// @copydoc GL3PlusContext::setCurrent virtual void setCurrent(); - /** - * This is called before another context is made current. By default, - * nothing is done here. - */ + + /// @copydoc GL3PlusContext::endCurrent virtual void endCurrent(); - /** Create a new context based on the same window/pbuffer as this - context - mostly useful for additional threads. - @note The caller is responsible for deleting the returned context. - */ + + /// @copydoc GL3PlusContext::clone virtual GL3PlusContext* clone() const; - /** Grab the NSOpenGLContext if it exists */ + /// Grab the NSOpenGLContext if it exists NSOpenGLContext* getContext(); - /** Grab the NSOpenGLPixelFormat if it exists */ + /// Grab the NSOpenGLPixelFormat if it exists NSOpenGLPixelFormat* getPixelFormat(); private: NSOpenGLContext* mNSGLContext; NSOpenGLPixelFormat *mNSGLPixelFormat; }; -} +} // namespace Ogre -#endif +#endif // __OgreOSXCocoaContext_H__ diff --git a/RenderSystems/GL3Plus/include/windowing/OSX/OgreOSXCocoaView.h b/RenderSystems/GL3Plus/include/windowing/OSX/OgreOSXCocoaView.h index 4a290361312..99b6d7f3c07 100644 --- a/RenderSystems/GL3Plus/include/windowing/OSX/OgreOSXCocoaView.h +++ b/RenderSystems/GL3Plus/include/windowing/OSX/OgreOSXCocoaView.h @@ -29,23 +29,22 @@ THE SOFTWARE. #ifndef __OSXCocoaView_H__ #define __OSXCocoaView_H__ -#include "OgreRenderWindow.h" +#include "OgreWindow.h" #include @interface OgreGL3PlusView : NSOpenGLView { - Ogre::RenderWindow *window; + Ogre::Window *window; } - (id)initWithFrame:(NSRect)f; -- (id)initWithGLOSXWindow:(Ogre::RenderWindow*)w; +- (id)initWithGLOSXWindow:(Ogre::Window*)w; -- (void)setOgreWindow:(Ogre::RenderWindow*)w; -- (Ogre::RenderWindow*)ogreWindow; +- (void)setOgreWindow:(Ogre::Window*)w; +- (Ogre::Window*)ogreWindow; - (void)setFrameSize:(NSSize)s; @end -#endif - +#endif // __OSXCocoaView_H__ diff --git a/RenderSystems/GL3Plus/include/windowing/OSX/OgreOSXCocoaWindow.h b/RenderSystems/GL3Plus/include/windowing/OSX/OgreOSXCocoaWindow.h index 89756da34ea..8300c30f4c6 100644 --- a/RenderSystems/GL3Plus/include/windowing/OSX/OgreOSXCocoaWindow.h +++ b/RenderSystems/GL3Plus/include/windowing/OSX/OgreOSXCocoaWindow.h @@ -36,31 +36,41 @@ THE SOFTWARE. #include "OgreOSXCocoaView.h" #include "OgreOSXCocoaWindowDelegate.h" +#include "OgreWindow.h" +#include "OgreTextureGpu.h" + @class CocoaWindowDelegate; @interface OgreGL3PlusWindow : NSWindow @end -namespace Ogre { - class _OgreGL3PlusExport CocoaWindow : public RenderWindow +namespace Ogre +{ + class _OgreGL3PlusExport CocoaWindow : public Window { private: NSWindow *mWindow; NSView *mView; NSOpenGLContext *mGLContext; NSOpenGLPixelFormat *mGLPixelFormat; - CVDisplayLinkRef mDisplayLink; + // CVDisplayLinkRef mDisplayLink; NSPoint mWindowOriginPt; CocoaWindowDelegate *mWindowDelegate; CocoaContext* mContext; - bool mActive; bool mClosed; + bool mVisible; bool mHidden; + bool mIsExternal; + + // Legacy + bool mActive; + bool mAutoDeactivatedOnFocusChange; + + bool mHwGamma; bool mVSync; bool mHasResized; - bool mIsExternal; String mWindowTitle; bool mUseOgreGLView; float mContentScalingFactor; @@ -69,57 +79,76 @@ namespace Ogre { void _setWindowParameters(unsigned int widthPt, unsigned int heightPt); public: - CocoaWindow(); - ~CocoaWindow(); - - NSView* ogreView() const { return mView; }; - NSWindow* ogreWindow() const { return mWindow; }; - NSOpenGLContext* nsopenGLContext() const { return mGLContext; }; - void createWithView(OgreGL3PlusView *view); - - /** @copydoc see RenderWindow::getViewPointToPixelScale */ - float getViewPointToPixelScale(); - /** Overridden - see RenderWindow */ - void create(const String& name, unsigned int widthPt, unsigned int heightPt, - bool fullScreen, const NameValuePairList *miscParams); - /** Overridden - see RenderWindow */ - void destroy(void); - /** Overridden - see RenderWindow */ - bool isActive(void) const; - /** Overridden - see RenderWindow */ - bool isClosed(void) const; - /** @copydoc see RenderWindow::isHidden */ - bool isHidden(void) const { return mHidden; } + CocoaWindow(const String &title, uint32 widthPt, uint32 heightPt, bool fullscreenMode, + const NameValuePairList *miscParams); + + virtual ~CocoaWindow(); + + /** @copydoc see Window::_initialize */ + void _initialize(TextureGpuManager *textureManager) override; + + /** @copydoc see Window::setVSync */ + // void setVSync(bool vSync, uint32 vSyncInterval) override; + + /** @copydoc see Window::getViewPointToPixelScale */ + float getViewPointToPixelScale() const override; + + /** @copydoc see Window::destroy */ + void destroy(void) override; + + /** @copydoc see Window::isVisible */ + bool isVisible( void ) const override; + + /** @copydoc see Window::_setVisible */ + void _setVisible( bool visible ) override; + + /** @copydoc see Window::isClosed */ + bool isClosed(void) const override; + + /** @copydoc see Window::isHidden */ + bool isHidden(void) const override { return mHidden; } + /** @copydoc see RenderWindow::setHidden */ - void setHidden(bool hidden); - /** @copydoc see RenderWindow::setVSyncEnabled */ - void setVSyncEnabled(bool vsync); - /** @copydoc see RenderWindow::isVSyncEnabled */ - bool isVSyncEnabled() const; - /** Overridden - see RenderWindow */ - void reposition(int leftPt, int topPt); - /** Overridden - see RenderWindow */ - void resize(unsigned int widthPt, unsigned int heightPt); - /** Overridden - see RenderWindow */ - void swapBuffers(); - /** Overridden - see RenderTarget */ - virtual void copyContentsToMemory(const Box& src, const PixelBox &dst, FrameBuffer buffer); - /** Overridden - see RenderWindow */ - virtual void setFullscreen(bool fullScreen, unsigned int widthPt, unsigned int heightPt); - /** Overridden - see RenderWindow */ - virtual unsigned int getWidth(void) const; - /** Overridden - see RenderWindow */ - virtual unsigned int getHeight(void) const; - /** Overridden - see RenderWindow */ - void windowMovedOrResized(void); - void windowHasResized(void); - void createNewWindow(unsigned int width, unsigned int height, String title); - void createWindowFromExternal(NSView *viewRef); - - bool requiresTextureFlipping() const { return false; } - void getCustomAttribute( const String& name, void* pData ); + void setHidden(bool hidden) override; + + /** @copydoc see Window::reposition */ + void reposition(int leftPt, int topPt) override; + + /** @copydoc see Window::swapBuffers */ + void swapBuffers() override; + + /** @copydoc see Window::windowMovedOrResized */ + void windowMovedOrResized(void) override; + + /** @copydoc see Window::getCustomAttribute */ + /** + @remarks + * Get custom attribute; the following attributes are valid: + * GLCONTEXT + * WINDOW + * VIEW + * NSOPENGLCONTEXT + * NSOPENGLPIXELFORMAT + */ + void getCustomAttribute(IdString name, void* pData); + + public: + // Required by CocoaWindowDelegate + void setVisible(bool visible); + + // Legacy: from RenderTarget, RenderWindow + bool isActive() const; + void setActive(bool value); + bool isDeactivatedOnFocusChange() const; + void setDeactivateOnFocusChange(bool deactivate); + + private: + void _create(const String &name, unsigned int widthPt, unsigned int heightPt, + bool fullScreen, const NameValuePairList *miscParams); + + void _createNewWindow(String title, unsigned int widthPt, unsigned int heightPt); + }; } -#endif - +#endif // __OSXCocoaWindow_H__ diff --git a/RenderSystems/GL3Plus/include/windowing/OSX/OgreOSXCocoaWindowDelegate.h b/RenderSystems/GL3Plus/include/windowing/OSX/OgreOSXCocoaWindowDelegate.h index 3dac05c19b9..c79ae1506e5 100644 --- a/RenderSystems/GL3Plus/include/windowing/OSX/OgreOSXCocoaWindowDelegate.h +++ b/RenderSystems/GL3Plus/include/windowing/OSX/OgreOSXCocoaWindowDelegate.h @@ -26,18 +26,18 @@ ----------------------------------------------------------------------------- */ -#include "OgreRenderWindow.h" +#include "OgreWindow.h" #import @interface CocoaWindowDelegate : NSObject { @private - Ogre::RenderWindow *ogreWindow; + Ogre::Window *ogreWindow; NSWindow *window; } --(id)initWithNSWindow:(NSWindow*)nswin ogreWindow:(Ogre::RenderWindow*)ogrewin; +-(id)initWithNSWindow:(NSWindow*)nswin ogreWindow:(Ogre::Window*)ogrewin; @end diff --git a/RenderSystems/GL3Plus/include/windowing/OSX/OgreOSXGL3PlusSupport.h b/RenderSystems/GL3Plus/include/windowing/OSX/OgreOSXGL3PlusSupport.h index 41dcb41d324..e450668cc35 100644 --- a/RenderSystems/GL3Plus/include/windowing/OSX/OgreOSXGL3PlusSupport.h +++ b/RenderSystems/GL3Plus/include/windowing/OSX/OgreOSXGL3PlusSupport.h @@ -39,47 +39,34 @@ class OSXGL3PlusSupport : public GL3PlusSupport { public: OSXGL3PlusSupport(); - ~OSXGL3PlusSupport(); - /** - * Add any special config values to the system. - * Must have a "Full Screen" value that is a bool and a "Video Mode" value - * that is a string in the form of wxh - */ - void addConfig( void ); + virtual ~OSXGL3PlusSupport(); - /** - * Make sure all the extra options are valid - */ - String validateConfig( void ); + /// @copydoc GL3PlusSupport::addConfig + void addConfig( void ) override; + + /// @copydoc GL3PlusSupport::validateConfig + String validateConfig( void ) override; /// @copydoc GL3PlusSupport::createWindow - RenderWindow* createWindow( bool autoCreateWindow, GL3PlusRenderSystem* renderSystem, const String& windowTitle ); - - /// @copydoc RenderSystem::createRenderWindow - virtual RenderWindow* newWindow( const String &name, unsigned int width, unsigned int height, - bool fullScreen, const NameValuePairList *miscParams = 0 ); + Window* createWindow( bool autoCreateWindow, GL3PlusRenderSystem* renderSystem, const String& windowTitle ) override; + + /// @copydoc GL3PlusSupport::newWindow + virtual Window* newWindow( const String &name, unsigned int width, unsigned int height, + bool fullScreen, const NameValuePairList *miscParams = 0 ) override; - /** - * Start anything special - */ - void start(); + /// @copydoc GL3PlusSupport::start + void start() override; - /** - * Stop anything special - */ - void stop(); + /// @copydoc GL3PlusSupport::stop + void stop() override; - /** - * Get the address of a function - */ - void* getProcAddress(const char *procname) const; + /// @copydoc GL3PlusSupport::getProcAddress + void* getProcAddress(const char *procname) const override; +private: // Core Foundation Array callback function for sorting, must be static for the function ptr - static CFComparisonResult _compareModes (const void *val1, const void *val2, void *context); - // Core Fondation Dictionary helper functions, also static for ease of use in above static - static Boolean _getDictionaryBoolean(CFDictionaryRef dict, const void* key); - static long _getDictionaryLong(CFDictionaryRef dict, const void* key); + static CFComparisonResult _compareModes(const void *val1, const void *val2, void *context); }; // class OSXGL3PlusSupport diff --git a/RenderSystems/GL3Plus/src/OgreGL3PlusRenderPassDescriptor.cpp b/RenderSystems/GL3Plus/src/OgreGL3PlusRenderPassDescriptor.cpp index 36914727350..331ae6a9f62 100644 --- a/RenderSystems/GL3Plus/src/OgreGL3PlusRenderPassDescriptor.cpp +++ b/RenderSystems/GL3Plus/src/OgreGL3PlusRenderPassDescriptor.cpp @@ -29,6 +29,8 @@ THE SOFTWARE. #include "OgreStableHeaders.h" #include "OgreGL3PlusRenderPassDescriptor.h" +#include "OgreGL3PlusTextureGpuManager.h" +#include "OgreGL3PlusSupport.h" #include "OgreGL3PlusTextureGpu.h" #include "OgreGL3PlusRenderSystem.h" @@ -126,6 +128,14 @@ namespace Ogre //----------------------------------------------------------------------------------- void GL3PlusRenderPassDescriptor::switchToFBO(void) { + // Capabilities + auto *textureManager = mRenderSystem->getTextureGpuManager(); + auto *textureManagerGL = + static_cast(textureManager); + auto &support = textureManagerGL->getGlSupport(); + bool hasGL43 = support.hasMinGLVersion(4, 3); + bool hasARBCopyImage = support.checkExtension("GL_ARB_copy_image"); + FrameBufferDescKey key( *this ); GL3PlusFrameBufferDescMap &frameBufferDescMap = mRenderSystem->_getFrameBufferDescMap(); GL3PlusFrameBufferDescMap::iterator newItor = frameBufferDescMap.find( key ); @@ -141,8 +151,11 @@ namespace Ogre //Disable target independent rasterization to let the driver warn us //of wrong behavior during regular rendering. - OCGE( glFramebufferParameteri( GL_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_WIDTH, 0 ) ); - OCGE( glFramebufferParameteri( GL_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_HEIGHT, 0 ) ); + if (hasGL43 || hasARBCopyImage) + { + OCGE( glFramebufferParameteri( GL_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_WIDTH, 0 ) ); + OCGE( glFramebufferParameteri( GL_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_HEIGHT, 0 ) ); + } frameBufferDescMap[key] = value; newItor = frameBufferDescMap.find( key ); } @@ -193,6 +206,14 @@ namespace Ogre //----------------------------------------------------------------------------------- void GL3PlusRenderPassDescriptor::updateColourFbo( uint8 lastNumColourEntries ) { + // Capabilities + auto *textureManager = mRenderSystem->getTextureGpuManager(); + auto *textureManagerGL = + static_cast(textureManager); + auto &support = textureManagerGL->getGlSupport(); + bool hasGL43 = support.hasMinGLVersion(4, 3); + bool hasARBCopyImage = support.checkExtension("GL_ARB_copy_image"); + if( mNumColourEntries < lastNumColourEntries && !mHasRenderWindow ) { for( size_t i=mNumColourEntries; igetPixelFormat() ) ) mHasSRGB |= true; - if( !mHasRenderWindow && mColour[i].texture->getPixelFormat() != PFG_NULL ) + if( !mHasRenderWindow && mColour[i].texture->getPixelFormat() != PFG_NULL && (hasGL43 || hasARBCopyImage) ) { assert( dynamic_cast( mColour[i].texture ) ); GL3PlusTextureGpu *texture = static_cast( mColour[i].texture ); @@ -275,7 +296,7 @@ namespace Ogre } } } - else if( mColour[i].texture->getPixelFormat() == PFG_NULL ) + else if( mColour[i].texture->getPixelFormat() == PFG_NULL && (hasGL43 || hasARBCopyImage)) { OCGE( glFramebufferParameteri( GL_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_WIDTH, mColour[i].texture->getWidth() ) ); diff --git a/RenderSystems/GL3Plus/src/windowing/OSX/OgreOSXCocoaContext.mm b/RenderSystems/GL3Plus/src/windowing/OSX/OgreOSXCocoaContext.mm index 2a4d36ac466..a4420af88f5 100644 --- a/RenderSystems/GL3Plus/src/windowing/OSX/OgreOSXCocoaContext.mm +++ b/RenderSystems/GL3Plus/src/windowing/OSX/OgreOSXCocoaContext.mm @@ -27,8 +27,8 @@ of this software and associated documentation files (the "Software"), to deal */ #import "OgreOSXCocoaContext.h" -#include "OgreGL3PlusRenderSystem.h" -#include "OgreRoot.h" +#import "OgreGL3PlusRenderSystem.h" +#import "OgreRoot.h" namespace Ogre { @@ -71,3 +71,4 @@ of this software and associated documentation files (the "Software"), to deal return mNSGLPixelFormat; } } + diff --git a/RenderSystems/GL3Plus/src/windowing/OSX/OgreOSXCocoaView.mm b/RenderSystems/GL3Plus/src/windowing/OSX/OgreOSXCocoaView.mm index d0a9f40b9ea..df136367d80 100644 --- a/RenderSystems/GL3Plus/src/windowing/OSX/OgreOSXCocoaView.mm +++ b/RenderSystems/GL3Plus/src/windowing/OSX/OgreOSXCocoaView.mm @@ -42,7 +42,7 @@ - (id)initWithFrame:(NSRect)f return self; } -- (id)initWithGLOSXWindow:(Ogre::RenderWindow*)w +- (id)initWithGLOSXWindow:(Ogre::Window*)w { if((self = [super initWithFrame:NSMakeRect(0, 0, w->getWidth(), w->getHeight())])) { @@ -51,12 +51,12 @@ - (id)initWithGLOSXWindow:(Ogre::RenderWindow*)w return self; } -- (void)setOgreWindow:(Ogre::RenderWindow*)w +- (void)setOgreWindow:(Ogre::Window*)w { window = w; } -- (Ogre::RenderWindow*)ogreWindow +- (Ogre::Window*)ogreWindow { return window; } diff --git a/RenderSystems/GL3Plus/src/windowing/OSX/OgreOSXCocoaWindow.mm b/RenderSystems/GL3Plus/src/windowing/OSX/OgreOSXCocoaWindow.mm index 8faee6bae4c..e32770a66ec 100644 --- a/RenderSystems/GL3Plus/src/windowing/OSX/OgreOSXCocoaWindow.mm +++ b/RenderSystems/GL3Plus/src/windowing/OSX/OgreOSXCocoaWindow.mm @@ -27,12 +27,17 @@ of this software and associated documentation files (the "Software"), to deal */ #import "OgreOSXCocoaWindow.h" +#import "OgreException.h" #import "OgreRoot.h" #import "OgreLogManager.h" +#import "OgrePrerequisites.h" #import "OgreStringConverter.h" #import "OgreWindowEventUtilities.h" -#import "OgreGL3PlusPixelFormat.h" -#import "OgrePixelBox.h" + +#import "OgreGL3PlusTextureGpuManager.h" +#import "OgreTextureGpuListener.h" +#import "OgreDepthBuffer.h" +#import "OgrePixelFormatGpuUtils.h" #import "OgreGL3PlusRenderSystem.h" #import @@ -40,6 +45,7 @@ of this software and associated documentation files (the "Software"), to deal #import #import "OgreViewport.h" #import +#import @implementation OgreGL3PlusWindow @@ -70,14 +76,38 @@ - (BOOL)acceptsFirstResponder NSOpenGLContext *mPrevContext; }; - - CocoaWindow::CocoaWindow() : mWindow(nil), mView(nil), mGLContext(nil), mGLPixelFormat(nil), mWindowOriginPt(NSZeroPoint), - mWindowDelegate(NULL), mActive(false), mClosed(false), mHidden(false), mVSync(true), mHasResized(false), mIsExternal(false), mWindowTitle(""), - mUseOgreGLView(true), mContentScalingFactor(1.0) + //----------------------------------------------------------------------- + CocoaWindow::CocoaWindow(const String &title, + uint32 widthPt, uint32 heightPt, + bool fullscreenMode, + const NameValuePairList *miscParams) : + Window(title, widthPt, heightPt, fullscreenMode), + mWindow(nil), + mView(nil), + mGLContext(nil), + mGLPixelFormat(nil), + mWindowOriginPt(NSZeroPoint), + mWindowDelegate(nil), + mContext(nil), + mClosed(false), + mVisible(false), + mHidden(false), + mIsExternal(false), + mActive(false), + mAutoDeactivatedOnFocusChange(true), + mHwGamma(true), + mVSync(true), + mHasResized(false), + mWindowTitle(""), + mUseOgreGLView(true), + mContentScalingFactor(1.0) { // Set vsync by default to save battery and reduce tearing + + _create(title, widthPt, heightPt, fullscreenMode, miscParams); } + //----------------------------------------------------------------------- CocoaWindow::~CocoaWindow() { [mGLContext clearDrawable]; @@ -88,9 +118,78 @@ - (BOOL)acceptsFirstResponder { [(OgreGL3PlusView*)mView setOgreWindow:NULL]; } + + if (mTexture) + { + mTexture->notifyAllListenersTextureChanged( TextureGpuListener::Deleted ); + OGRE_DELETE mTexture; + mTexture = nil; + } + + if (mDepthBuffer) + { + mDepthBuffer->notifyAllListenersTextureChanged( TextureGpuListener::Deleted ); + OGRE_DELETE mDepthBuffer; + mDepthBuffer = nil; + } + + // Depth & Stencil buffers are the same pointer + mStencilBuffer = nil; } - - void CocoaWindow::create(const String& name, unsigned int widthPt, unsigned int heightPt, + + //----------------------------------------------------------------------- + void CocoaWindow::_initialize(TextureGpuManager *_textureManager) + { + // See: EglPBufferWindow::_initialize + // OgreGLXWindow::_initialize + // Win32Window::_initialize + GL3PlusTextureGpuManager *textureManager = + static_cast(_textureManager); + + mTexture = textureManager->createTextureGpuWindow(mContext, this); + mTexture->setResolution(mRequestedWidth, mRequestedHeight); + mTexture->setPixelFormat(mHwGamma ? PFG_RGBA8_UNORM_SRGB : PFG_RGBA8_UNORM); + + mDepthBuffer = textureManager->createTextureGpuWindow(mContext, this); + mDepthBuffer->setPixelFormat(DepthBuffer::DefaultDepthBufferFormat); + if(PixelFormatGpuUtils::isStencil(mDepthBuffer->getPixelFormat())) + { + mStencilBuffer = mDepthBuffer; + } + + setFinalResolution( mRequestedWidth, mRequestedHeight ); + + if(mDepthBuffer) + { + mTexture->_setDepthBufferDefaults(DepthBuffer::POOL_NON_SHAREABLE, false, + mDepthBuffer->getPixelFormat()); + } + else + { + mTexture->_setDepthBufferDefaults(DepthBuffer::POOL_NO_DEPTH, false, PFG_NULL); + } + + mTexture->setSampleDescription(mRequestedSampleDescription); + mDepthBuffer->setSampleDescription(mRequestedSampleDescription); + mSampleDescription = mRequestedSampleDescription; + + mTexture->_transitionTo(GpuResidency::Resident, (uint8 *)0); + if(mDepthBuffer) + { + mDepthBuffer->_transitionTo(GpuResidency::Resident, (uint8 *)0); + } + } + + //----------------------------------------------------------------------- + // void CocoaWindow::setVSync(bool vSync, uint32 vSyncInterval) + // { + // LogManager::getSingleton().logMessage("CocoaWindow::setVSync"); + + // OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "Not Implemented", "CocoaWindow::setVSync" ); + // } + + //----------------------------------------------------------------------- + void CocoaWindow::_create(const String &name, unsigned int widthPt, unsigned int heightPt, bool fullScreen, const NameValuePairList *miscParams) { @autoreleasepool { @@ -129,12 +228,11 @@ - (BOOL)acceptsFirstResponder NSString *windowTitle = [NSString stringWithCString:name.c_str() encoding:NSUTF8StringEncoding]; int winxPt = 0, winyPt = 0; int colourDepth = 32; - NSOpenGLContext *externalGLContext; - NSObject* externalWindowHandle; // NSOpenGLView, NSView or NSWindow + NSOpenGLContext *externalGLContext = nil; + NSObject* externalWindowHandle = nil; // NSOpenGLView, NSView or NSWindow NameValuePairList::const_iterator opt; - - mIsFullScreen = fullScreen; - + + // mIsFullScreen = fullScreen; if(miscParams) { opt = miscParams->find("title"); @@ -168,7 +266,8 @@ - (BOOL)acceptsFirstResponder opt = miscParams->find("vsync"); if(opt != miscParams->end()) mVSync = StringConverter::parseBool(opt->second); - + // setVSync(mVSync, getVSyncInterval()); + opt = miscParams->find("colourDepth"); if(opt != miscParams->end()) colourDepth = StringConverter::parseUnsignedInt(opt->second); @@ -207,8 +306,8 @@ - (BOOL)acceptsFirstResponder } #endif } - - if(externalGLContext) + + if(externalGLContext != nil) { mGLContext = externalGLContext; mGLPixelFormat = externalGLContext.pixelFormat; @@ -275,14 +374,14 @@ - (BOOL)acceptsFirstResponder setHidden(hidden); mActive = true; mClosed = false; - mName = [windowTitle cStringUsingEncoding:NSUTF8StringEncoding]; - mWidth = _getPixelFromPoint(widthPt); - mHeight = _getPixelFromPoint(heightPt); - mFSAA = fsaa_samples; - + // mName = [windowTitle cStringUsingEncoding:NSUTF8StringEncoding]; + // mWidth = _getPixelFromPoint(widthPt); + // mHeight = _getPixelFromPoint(heightPt); + // mFSAA = fsaa_samples; + if(!externalWindowHandle) { - createNewWindow(widthPt, heightPt, [windowTitle cStringUsingEncoding:NSUTF8StringEncoding]); + _createNewWindow([windowTitle cStringUsingEncoding:NSUTF8StringEncoding], widthPt, heightPt); } else { @@ -310,9 +409,9 @@ - (BOOL)acceptsFirstResponder } NSRect b = [mView bounds]; - mWidth = _getPixelFromPoint((int)b.size.width); - mHeight = _getPixelFromPoint((int)b.size.height); - + // mWidth = _getPixelFromPoint((int)b.size.width); + // mHeight = _getPixelFromPoint((int)b.size.height); + mWindow = [mView window]; mIsExternal = true; @@ -361,30 +460,16 @@ - (BOOL)acceptsFirstResponder StringStream ss; ss << "Cocoa: Window created " << widthPt << " x " << heightPt - << " with backing store size " << mWidth << " x " << mHeight - << " using content scaling factor " << std::fixed << std::setprecision(1) << getViewPointToPixelScale(); + // << " with backing store size " << mWidth << " x " << mHeight + << " using content scaling factor " + << std::fixed << std::setprecision(1) << getViewPointToPixelScale(); LogManager::getSingleton().logMessage(ss.str()); } - unsigned int CocoaWindow::getWidth() const - { - // keep mWidth in sync with reality - assert(mView == nil || int(mWidth) == _getPixelFromPoint([mView frame].size.width)); - - return mWidth; - } - - unsigned int CocoaWindow::getHeight() const - { - // keep mHeight in sync with reality - assert(mView == nil || int(mHeight) == _getPixelFromPoint([mView frame].size.height)); - - return mHeight; - } - + //----------------------------------------------------------------------- void CocoaWindow::destroy(void) { - if(!mIsFullScreen) + if(!isFullscreen()) { // Unregister and destroy OGRE GL3PlusContext OGRE_DELETE mContext; @@ -402,105 +487,62 @@ - (BOOL)acceptsFirstResponder } } - bool CocoaWindow::isActive() const + //----------------------------------------------------------------------- + bool CocoaWindow::isVisible(void) const { - return mActive; + return mVisible; } + //----------------------------------------------------------------------- + void CocoaWindow::_setVisible( bool visible ) + { + mVisible = visible; + } + + //----------------------------------------------------------------------- bool CocoaWindow::isClosed() const { - return false; + return mClosed; } + //----------------------------------------------------------------------- void CocoaWindow::setHidden(bool hidden) { mHidden = hidden; if (!mIsExternal) { if (hidden) + { [mWindow orderOut:nil]; + } else + { [mWindow makeKeyAndOrderFront:nil]; + + // TODO - check for full screen mode? + } } } - void CocoaWindow::setVSyncEnabled(bool vsync) - { - mVSync = vsync; - mContext->setCurrent(); - - GLint vsyncInterval = mVSync ? 1 : 0; - [mGLContext setValues:&vsyncInterval forParameter:NSOpenGLCPSwapInterval]; - - mContext->endCurrent(); - - if(mGLContext != [NSOpenGLContext currentContext]) - [mGLContext makeCurrentContext]; - } - - bool CocoaWindow::isVSyncEnabled() const - { - return mVSync; - } - - void CocoaWindow::copyContentsToMemory(const Box& src, const PixelBox &dst, FrameBuffer buffer) - { - if(src.right > mWidth || src.bottom > mHeight || src.front != 0 || src.back != 1 - || dst.getWidth() != src.getWidth() || dst.getHeight() != src.getHeight() || dst.getDepth() != 1) - { - OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, "Invalid box.", "CocoaWindow::copyContentsToMemory"); - } - - if (buffer == FB_AUTO) - { - buffer = mIsFullScreen? FB_FRONT : FB_BACK; - } - - GLenum format = GL3PlusPixelUtil::getGLOriginFormat(dst.format); - GLenum type = GL3PlusPixelUtil::getGLOriginDataType(dst.format); - - if ((format == GL_NONE) || (type == 0)) - { - OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, "Unsupported format.", "CocoaWindow::copyContentsToMemory"); - } - - if(dst.getWidth() != dst.rowPitch) - { - OGRE_CHECK_GL_ERROR(glPixelStorei(GL_PACK_ROW_LENGTH, static_cast(dst.rowPitch))); - } - if((dst.getWidth()*Ogre::PixelUtil::getNumElemBytes(dst.format)) & 3) - { - // Standard alignment of 4 is not right - OGRE_CHECK_GL_ERROR(glPixelStorei(GL_PACK_ALIGNMENT, 1)); - } - - OGRE_CHECK_GL_ERROR(glReadBuffer((buffer == FB_FRONT)? GL_FRONT : GL_BACK)); - OGRE_CHECK_GL_ERROR(glReadPixels((GLint)src.left, (GLint)(mHeight - src.bottom), - (GLsizei)src.getWidth(), (GLsizei)src.getHeight(), - format, type, dst.getTopLeftFrontPixelPtr())); - - OGRE_CHECK_GL_ERROR(glPixelStorei(GL_PACK_ALIGNMENT, 4)); - OGRE_CHECK_GL_ERROR(glPixelStorei(GL_PACK_ROW_LENGTH, 0)); - - PixelUtil::bulkPixelVerticalFlip(dst); - } - - float CocoaWindow::getViewPointToPixelScale() + //----------------------------------------------------------------------- + float CocoaWindow::getViewPointToPixelScale() const { return mContentScalingFactor > 1.0f ? mContentScalingFactor : 1.0f; } - + + //----------------------------------------------------------------------- int CocoaWindow::_getPixelFromPoint(int viewPt) const { return mContentScalingFactor > 1.0 ? viewPt * mContentScalingFactor : viewPt; } - + + //----------------------------------------------------------------------- void CocoaWindow::reposition(int leftPt, int topPt) { if(!mWindow) return; - if(mIsFullScreen) + if(isFullscreen()) return; NSRect frame = [mWindow frame]; @@ -511,63 +553,7 @@ - (BOOL)acceptsFirstResponder [mWindow setFrame:frame display:YES]; } - void CocoaWindow::resize(unsigned int widthPt, unsigned int heightPt) - { - if(!mWindow) - return; - - if(mIsFullScreen) - return; - - unsigned widthPx = _getPixelFromPoint(widthPt); - unsigned heightPx = _getPixelFromPoint(heightPt); - - // Check if the window size really changed - if(mWidth == widthPx && mHeight == heightPx) - return; - - mWidth = widthPx; - mHeight = heightPx; - - if(mIsExternal) - { - NSRect viewFrame = [mView frame]; - viewFrame.size.width = widthPt; - viewFrame.size.height = heightPt; - - NSRect windowFrame = [[mView window] frame]; - - CGFloat leftPt = viewFrame.origin.x; - CGFloat topPt = windowFrame.size.height - (viewFrame.origin.y + viewFrame.size.height); - mLeft = _getPixelFromPoint((int)leftPt); - mTop = _getPixelFromPoint((int)topPt); - mWindowOriginPt = NSMakePoint(leftPt, topPt); - - GLint bufferRect[4]; - bufferRect[0] = mLeft; // 0 = left edge - bufferRect[1] = mTop; // 0 = bottom edge - bufferRect[2] = mWidth; // width of buffer rect - bufferRect[3] = mHeight; // height of buffer rect - CGLContextObj ctx = (CGLContextObj)[mGLContext CGLContextObj]; - CGLSetParameter(ctx, kCGLCPSwapRectangle, bufferRect); - } - else - { - mWindowOriginPt = [mWindow frame].origin; - [mWindow setContentSize:NSMakeSize(widthPt, heightPt)]; - } - //make sure the context is current - NSOpenGLContextGuard ctx_guard(mGLContext); - - [mGLContext update]; - } - - void CocoaWindow::windowHasResized() - { - // Ensure the context is current - [mGLContext flushBuffer]; - } - + //----------------------------------------------------------------------- void CocoaWindow::windowMovedOrResized() { mContentScalingFactor = @@ -579,39 +565,43 @@ - (BOOL)acceptsFirstResponder NSRect screenFrame = [[NSScreen mainScreen] visibleFrame]; CGFloat leftPt = winFrame.origin.x; CGFloat topPt = screenFrame.size.height - winFrame.size.height; - mWidth = _getPixelFromPoint((unsigned int)viewFrame.size.width); - mHeight = _getPixelFromPoint((unsigned int)viewFrame.size.height); + uint32 mWidth = _getPixelFromPoint((unsigned int)viewFrame.size.width); + uint32 mHeight = _getPixelFromPoint((unsigned int)viewFrame.size.height); mLeft = _getPixelFromPoint((int)leftPt); mTop = _getPixelFromPoint((int)topPt); mWindowOriginPt = NSMakePoint(leftPt, topPt); - //make sure the context is current + // //make sure the context is current NSOpenGLContextGuard ctx_guard(mGLContext); - for (ViewportList::iterator it = mViewportList.begin(); it != mViewportList.end(); ++it) - { - (*it)->_updateDimensions(); - } + // TODO - implement update of texture GPU window + LogManager::getSingleton().logMessage( + "WARNING: CocoaWindow::windowMovedOrResized not fully implemented." ); + // for (ViewportList::iterator it = mViewportList.begin(); it != mViewportList.end(); ++it) + // { + // (*it)->_updateDimensions(); + // } [mGLContext update]; } + //----------------------------------------------------------------------- void CocoaWindow::swapBuffers() { CGLLockContext((CGLContextObj)[mGLContext CGLContextObj]); [mGLContext makeCurrentContext]; if([mGLContext view] != mView) + { [mGLContext setView:mView]; + } [mGLContext flushBuffer]; CGLUnlockContext((CGLContextObj)[mGLContext CGLContextObj]); - - RenderWindow::swapBuffers(); } - - //-------------------------------------------------------------------------------------------------// - void CocoaWindow::getCustomAttribute( const String& name, void* pData ) + + //----------------------------------------------------------------------- + void CocoaWindow::getCustomAttribute(IdString name, void* pData) { if( name == "GLCONTEXT" ) { @@ -638,14 +628,14 @@ - (BOOL)acceptsFirstResponder *(void**)(pData) = (__bridge_retained void*)mGLPixelFormat; return; } - } - void CocoaWindow::createNewWindow(unsigned int widthPt, unsigned int heightPt, String title) + //----------------------------------------------------------------------- + void CocoaWindow::_createNewWindow(String title, unsigned int widthPt, unsigned int heightPt) { // Get the dimensions of the display. We will use it for the window size but not context resolution NSRect windowRect = NSZeroRect; - if(mIsFullScreen) + if(isFullscreen()) { NSRect mainDisplayRect = [[NSScreen mainScreen] visibleFrame]; windowRect = NSMakeRect(0.0, 0.0, mainDisplayRect.size.width, mainDisplayRect.size.height); @@ -654,7 +644,7 @@ - (BOOL)acceptsFirstResponder windowRect = NSMakeRect(0.0, 0.0, widthPt, heightPt); mWindow = [[OgreGL3PlusWindow alloc] initWithContentRect:windowRect - styleMask:mIsFullScreen ? NSBorderlessWindowMask : NSResizableWindowMask|NSTitledWindowMask + styleMask:isFullscreen() ? NSBorderlessWindowMask : NSResizableWindowMask|NSTitledWindowMask backing:NSBackingStoreBuffered defer:YES]; [mWindow setTitle:[NSString stringWithCString:title.c_str() encoding:NSUTF8StringEncoding]]; @@ -664,8 +654,8 @@ - (BOOL)acceptsFirstResponder _setWindowParameters(widthPt, heightPt); -// GL3PlusRenderSystem *rs = static_cast(Root::getSingleton().getRenderSystem()); -// rs->clearFrameBuffer(FBT_COLOUR); + // GL3PlusRenderSystem *rs = static_cast(Root::getSingleton().getRenderSystem()); + // rs->clearFrameBuffer(FBT_COLOUR); // Show window setHidden(mHidden); @@ -674,32 +664,12 @@ - (BOOL)acceptsFirstResponder WindowEventUtilities::_addRenderWindow(this); } - void CocoaWindow::createWindowFromExternal(NSView *viewRef) - { - LogManager::getSingleton().logMessage("Creating external window"); - - NSRect viewBounds = [mView convertRectToBacking:[mView bounds]]; - - mWindow = [viewRef window]; - - mView = viewRef; - - GLint bufferRect[4]; - bufferRect[0] = viewBounds.origin.x; // 0 = left edge - bufferRect[1] = viewBounds.origin.y; // 0 = bottom edge - bufferRect[2] = viewBounds.size.width; // width of buffer rect - bufferRect[3] = viewBounds.size.height; // height of buffer rect - CGLContextObj ctx = (CGLContextObj)[mGLContext CGLContextObj]; - CGLSetParameter(ctx, kCGLCPSwapRectangle, bufferRect); - - mIsExternal = true; - } - + //----------------------------------------------------------------------- void CocoaWindow::_setWindowParameters(unsigned int widthPt, unsigned int heightPt) { if(mWindow) { - if(mIsFullScreen) + if(isFullscreen()) { // Set the backing store size to the viewport dimensions // This ensures that it will scale to the full screen size @@ -759,28 +729,34 @@ - (BOOL)acceptsFirstResponder } } - void CocoaWindow::setFullscreen(bool fullScreen, unsigned int widthPt, unsigned int heightPt) + //----------------------------------------------------------------------- + void CocoaWindow::setVisible(bool visible) { - unsigned widthPx = _getPixelFromPoint(widthPt); - unsigned heightPx = _getPixelFromPoint(heightPt); - if (mIsFullScreen != fullScreen || widthPx != mWidth || heightPx != mHeight) - { - // Set the full screen flag - mIsFullScreen = fullScreen; + _setVisible(visible); + } - // Create a window if we haven't already, existence check is done within the functions - if(!mWindow) - { - if(mIsExternal) - createWindowFromExternal(mView); - else - createNewWindow(widthPt, heightPt, mWindowTitle); - } + //----------------------------------------------------------------------- + bool CocoaWindow::isActive() const + { + return mActive; + } - _setWindowParameters(widthPt, heightPt); + //----------------------------------------------------------------------- + void CocoaWindow::setActive(bool value) + { + mActive = true; + } - mWidth = widthPx; - mHeight = heightPx; - } + //----------------------------------------------------------------------- + bool CocoaWindow::isDeactivatedOnFocusChange() const + { + return mAutoDeactivatedOnFocusChange; } -} + + //----------------------------------------------------------------------- + void CocoaWindow::setDeactivateOnFocusChange(bool deactivate) + { + mAutoDeactivatedOnFocusChange = deactivate; + } + +} // namespace Ogre diff --git a/RenderSystems/GL3Plus/src/windowing/OSX/OgreOSXCocoaWindowDelegate.mm b/RenderSystems/GL3Plus/src/windowing/OSX/OgreOSXCocoaWindowDelegate.mm index b1aee924097..23343b666c0 100644 --- a/RenderSystems/GL3Plus/src/windowing/OSX/OgreOSXCocoaWindowDelegate.mm +++ b/RenderSystems/GL3Plus/src/windowing/OSX/OgreOSXCocoaWindowDelegate.mm @@ -26,9 +26,8 @@ of this software and associated documentation files (the "Software"), to deal ----------------------------------------------------------------------------- */ -#import "OgreOSXCocoaWindow.h" - #import "OgreOSXCocoaWindowDelegate.h" +#import "OgreOSXCocoaWindow.h" #import "OgreWindowEventUtilities.h" using namespace Ogre; @@ -36,7 +35,7 @@ of this software and associated documentation files (the "Software"), to deal @implementation CocoaWindowDelegate --(id)initWithNSWindow:(NSWindow*)nswin ogreWindow:(RenderWindow*)ogrewin +-(id)initWithNSWindow:(NSWindow*)nswin ogreWindow:(Window*)ogrewin { if ((self = [super init])) { diff --git a/RenderSystems/GL3Plus/src/windowing/OSX/OgreOSXGL3PlusSupport.mm b/RenderSystems/GL3Plus/src/windowing/OSX/OgreOSXGL3PlusSupport.mm index 049b245a7ec..3fb172b2e81 100644 --- a/RenderSystems/GL3Plus/src/windowing/OSX/OgreOSXGL3PlusSupport.mm +++ b/RenderSystems/GL3Plus/src/windowing/OSX/OgreOSXGL3PlusSupport.mm @@ -26,17 +26,17 @@ of this software and associated documentation files (the "Software"), to deal ----------------------------------------------------------------------------- */ +#import "OgreOSXGL3PlusSupport.h" +#import "OgreOSXCocoaWindow.h" + +#import "OgreGL3PlusRenderSystem.h" +#import "OgreGL3PlusSupport.h" + #import "OgreException.h" #import "OgreLogManager.h" #import "OgreStringConverter.h" #import "OgreRoot.h" -#import "OgreGL3PlusSupport.h" -#import "OgreOSXGL3PlusSupport.h" -#import "OgreOSXCocoaWindow.h" -#import "OgreGL3PlusTexture.h" -#import "OgreGL3PlusRenderSystem.h" - #import "macUtils.h" #import @@ -45,17 +45,20 @@ of this software and associated documentation files (the "Software"), to deal namespace Ogre { +//----------------------------------------------------------------------- OSXGL3PlusSupport::OSXGL3PlusSupport() { } +//----------------------------------------------------------------------- OSXGL3PlusSupport::~OSXGL3PlusSupport() { } +//----------------------------------------------------------------------- void OSXGL3PlusSupport::addConfig( void ) { - ConfigOption optFullScreen; + ConfigOption optFullScreen; ConfigOption optVideoMode; ConfigOption optBitDepth; ConfigOption optFSAA; @@ -211,7 +214,8 @@ of this software and associated documentation files (the "Software"), to deal String resoString = StringConverter::toString(fWidth) + " x " + StringConverter::toString(fHeight); optVideoMode.possibleValues.push_back(resoString); } - + optVideoMode.currentValue = optVideoMode.possibleValues[0]; + // Release memory CFRelease(goodModes); @@ -236,12 +240,14 @@ of this software and associated documentation files (the "Software"), to deal setShaderLibraryPath(Ogre::macBundlePath() + "/Contents/Resources/RTShaderLib/GLSL150"); } +//----------------------------------------------------------------------- String OSXGL3PlusSupport::validateConfig( void ) { return String( "" ); } -RenderWindow* OSXGL3PlusSupport::createWindow( bool autoCreateWindow, GL3PlusRenderSystem* renderSystem, const String& windowTitle ) +//----------------------------------------------------------------------- +Window* OSXGL3PlusSupport::createWindow( bool autoCreateWindow, GL3PlusRenderSystem* renderSystem, const String& windowTitle ) { if( autoCreateWindow ) { @@ -307,17 +313,18 @@ of this software and associated documentation files (the "Software"), to deal } } -RenderWindow* OSXGL3PlusSupport::newWindow( const String &name, unsigned int width, unsigned int height, +//----------------------------------------------------------------------- +Window* OSXGL3PlusSupport::newWindow( const String &name, unsigned int width, unsigned int height, bool fullScreen, const NameValuePairList *miscParams ) { // Create the window, if Cocoa return a Cocoa window LogManager::getSingleton().logMessage("Creating a Cocoa Compatible Render System"); - CocoaWindow *window = OGRE_NEW CocoaWindow(); - window->create(name, width, height, fullScreen, miscParams); + CocoaWindow *window = OGRE_NEW CocoaWindow(name, width, height, fullScreen, miscParams); return window; } +//----------------------------------------------------------------------- void OSXGL3PlusSupport::start() { LogManager::getSingleton().logMessage( @@ -326,6 +333,7 @@ of this software and associated documentation files (the "Software"), to deal "***********************************************"); } +//----------------------------------------------------------------------- void OSXGL3PlusSupport::stop() { LogManager::getSingleton().logMessage( @@ -334,11 +342,13 @@ of this software and associated documentation files (the "Software"), to deal "***********************************************"); } +//----------------------------------------------------------------------- void* OSXGL3PlusSupport::getProcAddress(const char* procname) const { return dlsym (RTLD_DEFAULT, procname); } +//----------------------------------------------------------------------- CFComparisonResult OSXGL3PlusSupport::_compareModes (const void *val1, const void *val2, void *context) { // These are the values we will be interested in... @@ -346,7 +356,6 @@ of this software and associated documentation files (the "Software"), to deal CGDisplayModeGetWidth CGDisplayModeGetHeight CGDisplayModeGetRefreshRate - _getDictionaryLong((mode), kCGDisplayBitsPerPixel) CGDisplayModeGetIOFlags((mode), kDisplayModeStretchedFlag) CGDisplayModeGetIOFlags((mode), kDisplayModeSafetyFlags) */ @@ -388,28 +397,4 @@ of this software and associated documentation files (the "Software"), to deal return kCFCompareEqualTo; } -Boolean OSXGL3PlusSupport::_getDictionaryBoolean(CFDictionaryRef dict, const void* key) -{ - Boolean value = false; - CFBooleanRef boolRef; - boolRef = (CFBooleanRef)CFDictionaryGetValue(dict, key); - - if (boolRef != NULL) - value = CFBooleanGetValue(boolRef); - - return value; -} - -long OSXGL3PlusSupport::_getDictionaryLong(CFDictionaryRef dict, const void* key) -{ - long value = 0; - CFNumberRef numRef; - numRef = (CFNumberRef)CFDictionaryGetValue(dict, key); - - if (numRef != NULL) - CFNumberGetValue(numRef, kCFNumberLongType, &value); - - return value; -} - -} +} // namespace Ogre diff --git a/Samples/2.0/CMakeLists.txt b/Samples/2.0/CMakeLists.txt index fab8894605e..5ee2d982b40 100644 --- a/Samples/2.0/CMakeLists.txt +++ b/Samples/2.0/CMakeLists.txt @@ -129,8 +129,10 @@ if( OGRE_BUILD_SAMPLES2 AND NOT OGRE_BUILD_SAMPLES2_SKIP ) add_subdirectory(ApiUsage/InstantRadiosity) add_subdirectory(ApiUsage/LocalCubemaps) add_subdirectory(ApiUsage/LocalCubemapsManualProbes) - add_subdirectory(ApiUsage/MorphAnimations) - add_subdirectory(ApiUsage/Refractions) + if(NOT (APPLE AND NOT OGRE_BUILD_PLATFORM_APPLE_IOS)) + add_subdirectory(ApiUsage/MorphAnimations) + endif() + add_subdirectory(ApiUsage/Refractions) add_subdirectory(ApiUsage/V1Interfaces) add_subdirectory(ApiUsage/V2Mesh) add_subdirectory(ApiUsage/V2ManualObject) diff --git a/Samples/2.0/Tests/Restart/CMakeLists.txt b/Samples/2.0/Tests/Restart/CMakeLists.txt index 1b47e5ca1c8..48ea7c70a40 100644 --- a/Samples/2.0/Tests/Restart/CMakeLists.txt +++ b/Samples/2.0/Tests/Restart/CMakeLists.txt @@ -19,7 +19,7 @@ ogre_add_component_include_dir(Hlms/Pbs) add_recursive( ./ SOURCE_FILES ) set( RESTART_RESOURCES ${SAMPLE_COMMON_RESOURCES} ) -if( OGRE_BUILD_PLATFORM_APPLE_IOS ) +if( APPLE AND OGRE_BUILD_PLATFORM_APPLE_IOS) set( RESTART_RESOURCES ${RESTART_RESOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/iOS/Restart.storyboard ) set( SOURCE_FILES ${SOURCE_FILES} ${CMAKE_CURRENT_SOURCE_DIR}/iOS/RestartViewController.mm )