Skip to content

Commit

Permalink
Get metal renderer working with local toolkit. Bump deployment ios ve…
Browse files Browse the repository at this point in the history
…rsion to 12. turn ios video implementation off by default.
  • Loading branch information
Hugh Sanderson committed Dec 3, 2024
1 parent 05ff3d7 commit a0406e2
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 6 deletions.
3 changes: 2 additions & 1 deletion project/ToolkitBuild.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<xml>

<set name="ios" value="1" if="iphone" />
<set name="ios" value="1" if="iphone||iphonesim" />
<set name="tvos" value="1" if="appletv" />
<set name="mac" value="1" if="macos" />
<set name="native_toolkit_sdl_static" value="1" if="static_link" />
Expand All @@ -23,6 +23,7 @@

<set name="NME_METAL" value="1" if="nme_metal" />
<set name="NME_METAL" value="1" if="mac" unless="nme_no_metal" />
<set name="NME_VIDEO" value="1" unless="ios" />
<set name="NME_NO_OGL" value="1" if="nme_no_ogl" />
<set name="NME_NO_OGL" value="1" if="nme_metal" unless="mac" />
<set name="NME_ANGLE" value="1" if="windows||winrt" unless="NME_NO_ANGLE || NME_LOCAL_TOOLKIT" />
Expand Down
5 changes: 5 additions & 0 deletions project/include/Hardware.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#define NME_FLOAT32_VERT_VALUES
#endif


namespace nme
{

Expand Down Expand Up @@ -141,7 +142,11 @@ class HardwareRenderer : public HardwareContext

static HardwareRenderer *current;

#ifndef IPHONE
static HardwareRenderer *CreateMetal(void *inMetalLayer);
#endif
static HardwareRenderer *CreateMetalNull();

static HardwareRenderer *CreateOpenGL(void *inWindow, void *inGLCtx, bool shaders);
static HardwareRenderer *CreateDX11(void *inDevice, void *inContext);

Expand Down
6 changes: 4 additions & 2 deletions project/src/common/ManagedStage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@ ManagedStage::ManagedStage(int inWidth,int inHeight,int inFlags)
if (nmeOpenglRenderer)
mHardwareRenderer = HardwareRenderer::CreateOpenGL(0, 0, inFlags & wfAllowShaders);
else
{
// TODO?
mHardwareRenderer = HardwareRenderer::CreateMetal(0);
mHardwareRenderer = HardwareRenderer::CreateMetalNull();
}
#elif defined(NME_OGL)
mHardwareRenderer = HardwareRenderer::CreateOpenGL(0, 0, inFlags & wfAllowShaders);
#elif defined(NME_METAL)
// TODO?
mHardwareRenderer = HardwareRenderer::CreateMetal(0);
mHardwareRenderer = HardwareRenderer::CreateMetalNull();
#else
#error "No valid HardwareRenderer"
#endif
Expand Down
14 changes: 14 additions & 0 deletions project/src/metal/MetalContext.mm
Original file line number Diff line number Diff line change
Expand Up @@ -971,7 +971,20 @@ void BeginDirectRender(const Rect &inRect) { }
void EndDirectRender() { }
};

HardwareRenderer *HardwareRenderer::CreateMetalNull()
{
HardwareRenderer *ctx = new MetalContext( nullptr );
return ctx;
}

#ifdef IPHONE
HardwareRenderer *HardwareRendererCreateMetal(CAMetalLayer *metalLayer)
{
HardwareRenderer *ctx = new MetalContext( metalLayer );

return ctx;
}
#else
HardwareRenderer *HardwareRenderer::CreateMetal(void *inRenderer)
{
SDL_Renderer *renderer = (SDL_Renderer *)renderer;
Expand All @@ -986,6 +999,7 @@ void EndDirectRender() { }

return ctx;
}
#endif


} // end namespace nme
Expand Down
2 changes: 1 addition & 1 deletion project/toolkit/jpeg/files.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<!-- nasm on mac x64 generate a whole lot of warning messages. Nice just to skip it? -->
<set name="JPEG_SUPPRESS_SIMD" value="1" if="macos HXCPP_M64 NME_STATIC_LINK" unless="NME_NOISY_SIMD" />
<set name="JPEG_SUPPRESS_SIMD" value="1" if="wasm" />
<set name="JPEG_SUPPRESS_SIMD" value="1" if="wasm || iphonesim" />


<files id="native-toolkit-jpeg-depends" >
Expand Down
1 change: 1 addition & 0 deletions project/toolkit/sdl-mixer/files.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
<compilerflag value="-DMUSIC_MID_TIMIDITY" unless="linux || winrt" />
<compilerflag value="-DMUSIC_MID_NATIVE" unless="linux || winrt" />
<compilerflag value='-DMODPLUG_HEADER="../../../../modplug/libmodplug/src/modplug.h"' />
<compilerflag value='-Wno-deprecated-register' if='ios' />

<cache value="1" />

Expand Down
22 changes: 21 additions & 1 deletion templates/ios/UIStageView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@
#define APP_LOG(x) { }
#endif

#ifdef IPHONE
namespace nme
{
HardwareRenderer *HardwareRendererCreateMetal(CAMetalLayer *metalLayer);
}
#endif

#ifndef IPHONESIM
CMMotionManager *sgCmManager = 0;
Expand Down Expand Up @@ -171,7 +177,9 @@ - (void) mainLoop:(id) sender;
UIView *container;
UIView *playerView;
NMEView *nmeView;
#ifdef NME_VIDEO
class IOSVideo *video;
#endif

bool popupEnabled;
bool multiTouchEnabled;
Expand Down Expand Up @@ -459,7 +467,7 @@ - (void) setupStageLayer:(NMEStage *)inStage

self.enableSetNeedsDisplay = YES;

mHardwareRenderer = HardwareRenderer::CreateMetal(metalLayer);
mHardwareRenderer = HardwareRendererCreateMetal(metalLayer);

mHardwareRenderer->IncRef();
mHardwareRenderer->SetWindowSize(backingSize.width, backingSize.height);
Expand Down Expand Up @@ -1160,6 +1168,7 @@ - (void) dealloc
@end // End NMEView


#ifdef NME_VIDEO
class IOSVideo;
@interface PlayerHandler : NSObject
{
Expand Down Expand Up @@ -1752,6 +1761,7 @@ -(void)removeMovieNotificationHandlers

@end

#endif // NME_VIDEO

double sgWakeUp = 0.0;

Expand All @@ -1769,7 +1779,9 @@ -(void)removeMovieNotificationHandlers
NMEStage::NMEStage(CGRect inRect) : nme::Stage(true)
{
APP_LOG(@"new NMEStage");
#ifdef NME_VIDEO
video = 0;
#endif
//printf("New NMEStage\n");

sgNmeStage = this;
Expand Down Expand Up @@ -1915,6 +1927,7 @@ -(void)removeMovieNotificationHandlers

void NMEStage::onVideoPlay()
{
#ifdef NME_VIDEO
if (!playerView)
{
playerView = video->getPlayerView();
Expand All @@ -1925,17 +1938,22 @@ -(void)removeMovieNotificationHandlers
if (wantOpaqueBg!=haveOpaqueBg)
recreateNmeView();
}
#endif
}

StageVideo *NMEStage::createStageVideo(void *inOwner)
{
#ifdef NME_VIDEO
if (!video)
{
video = new IOSVideo(this,1.0/getDPIScale());
video->setOwner( (value) inOwner );
}

return video;
#else
return nullptr;
#endif
}


Expand Down Expand Up @@ -2008,11 +2026,13 @@ -(void)removeMovieNotificationHandlers
int top = 0;
gc_set_top_of_stack(&top,false);

#ifdef NME_VIDEO
if (inEvt.type==etPoll && video)
video->onPoll();

if ((inEvt.type==etActivate || inEvt.type==etDeactivate) && video)
video->setActive(inEvt.type==etActivate);
#endif
HandleEvent(inEvt);
}

Expand Down
2 changes: 1 addition & 1 deletion tools/nme/src/project/NMEProject.hx
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class IOSConfig
public function new()
{
compiler = "clang";
deployment = "9.0";
deployment = "12.0";
deviceConfig = UNIVERSAL;
linkerFlags = new Array();
viewTestDir = "";
Expand Down

0 comments on commit a0406e2

Please sign in to comment.