Skip to content

Commit

Permalink
[macOS] add GL3Plus support for macOS
Browse files Browse the repository at this point in the history
Reestablish support for GL3+ on maOS in Ogre2.2

Cmake

- Update cmake version
- Add extra library name for zzip (required to find homebrew installed version on macOS)
- Exclude morph animations sample that breaks compilation

Cocoa Windowing

- Remove GeneralAllocatedObject as superclass of CocoaContext
- Update class documentation in line with OgreEGL classes
- Allocate arrays for table data source in config dialog init.
  This fixes a memory access segfault that occurred when altering
  a value in the option selector.
- Remove not implemented exception from swapBuffers

TextureGpuManager

- Apply to TextureGpuManager and TextureFilters from:
    Commit: 42bbd89
    From: "Matias N. Goldberg" <[email protected]>
    Date: Wed, 9 Sep 2020 17:03:23 -0300

    Commit: 1cebf78
    Author: Matias N. Goldberg <[email protected]>
    Date:   Fri Sep 11 20:19:07 2020 -0300
- Add condition to disable HW mipmap generation on macOS

GL3Plus RenderSystem

- Add GL4.3 checks to GL3PlusRenderPassDescriptor
- Apply changes to

Signed-off-by: Rhys Mainwaring <[email protected]>
  • Loading branch information
srmainwaring committed Jul 7, 2021
1 parent 0a5b177 commit e1989ac
Show file tree
Hide file tree
Showing 23 changed files with 465 additions and 413 deletions.
2 changes: 1 addition & 1 deletion CMake/Packages/FindZZip.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion OgreMain/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 2 additions & 0 deletions OgreMain/include/OgreTextureFilters.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
19 changes: 19 additions & 0 deletions OgreMain/include/OgreTextureGpuManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
14 changes: 8 additions & 6 deletions OgreMain/src/OSX/OgreConfigDialog.mm
Original file line number Diff line number Diff line change
Expand Up @@ -212,28 +212,30 @@ - (id)init
[mRenderSystemsPopUp addItemWithTitle:renderSystemName];
}

// Initalise storage for the table data source
mOptionsKeys = [[NSMutableArray alloc] init];
mOptionsValues = [[NSMutableArray alloc] init];

[self refreshConfigOptions];
}
return self;
}

-(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]);
RenderSystem *rs = Root::getSingleton().getRenderSystemByName(selectedRenderSystemName);
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];
}

Expand Down
2 changes: 2 additions & 0 deletions OgreMain/src/OgrePlatformInformation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ THE SOFTWARE.
#if OGRE_PLATFORM != OGRE_PLATFORM_WIN32
#if OGRE_PLATFORM == OGRE_PLATFORM_ANDROID
#include <linux/sysctl.h>
#elif OGRE_PLATFORM == OGRE_PLATFORM_APPLE || OGRE_PLATFORM == OGRE_PLATFORM_APPLE_IOS
#include <sys/sysctl.h>
#endif
#endif

Expand Down
31 changes: 21 additions & 10 deletions OgreMain/src/OgreTextureFilters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ namespace TextureFilter
}
//-----------------------------------------------------------------------------------
uint8 FilterBase::selectMipmapGen( uint32 filters, const Image2 &image,
PixelFormatGpu finalPixelFormat,
const TextureGpuManager *textureManager )
{
DefaultMipmapGen::DefaultMipmapGen retVal = DefaultMipmapGen::NoMipmaps;
Expand All @@ -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;
Expand All @@ -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.
Expand Down Expand Up @@ -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<Image2::Filter>(
GenerateSwMipmaps::getFilter( image ) ) ) );
( mipmapGen == DefaultMipmapGen::HwMode &&
textureGpuManager->checkSupport( inOutPixelFormat,
TextureFlags::AllowAutomipmaps ) ) ||
( mipmapGen == DefaultMipmapGen::SwMode &&
Image2::supportsSwMipmaps(
inOutPixelFormat, image.getDepthOrSlices(), image.getTextureType(),
static_cast<Image2::Filter>( GenerateSwMipmaps::getFilter( image ) ) ) );

if( canDoMipmaps && inOutNumMipmaps <= 1u)
{
Expand Down
20 changes: 20 additions & 0 deletions OgreMain/src/OgreTextureGpuManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ),
Expand Down
1 change: 1 addition & 0 deletions RenderSystems/GL3Plus/include/OgreGL3PlusPrerequisites.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ namespace Ogre {
# include <GL/glext.h>
#elif OGRE_PLATFORM == OGRE_PLATFORM_APPLE
# include <GL/gl3w.h>
# include <GL/glext.h>
# include <OpenGL/OpenGLAvailability.h>
# include <OpenGL/gl3ext.h>
#endif
Expand Down
24 changes: 10 additions & 14 deletions RenderSystems/GL3Plus/include/windowing/OSX/OgreOSXCocoaContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -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__
13 changes: 6 additions & 7 deletions RenderSystems/GL3Plus/include/windowing/OSX/OgreOSXCocoaView.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,22 @@ THE SOFTWARE.
#ifndef __OSXCocoaView_H__
#define __OSXCocoaView_H__

#include "OgreRenderWindow.h"
#include "OgreWindow.h"
#include <AppKit/NSOpenGLView.h>

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

0 comments on commit e1989ac

Please sign in to comment.