Skip to content

Commit

Permalink
Add support for MTKView and Metal APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
mogemimi committed Mar 15, 2017
1 parent 2d9b49a commit af5de17
Show file tree
Hide file tree
Showing 4 changed files with 754 additions and 0 deletions.
28 changes: 28 additions & 0 deletions include/Pomdog/Platform/Cocoa/PomdogMetalViewController.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (c) 2013-2017 mogemimi. Distributed under the MIT license.

#pragma once

#include "Pomdog/Basic/Export.hpp"
#include "Pomdog/Signals/detail/ForwardDeclarations.hpp"
#include <memory>
#include <functional>

#import <Cocoa/Cocoa.h>
#import <MetalKit/MTKView.h>

namespace Pomdog {

class Game;
class GameHost;
class GraphicsDevice;
class GraphicsCommandQueue;

} // namespace Pomdog

POMDOG_EXPORT
@interface PomdogMetalViewController : NSViewController<MTKViewDelegate>

- (void)loadAssetsPomdog:(std::shared_ptr<Pomdog::GameHost>)gameHost;
- (void)startGame:(std::shared_ptr<Pomdog::Game>)game;

@end
68 changes: 68 additions & 0 deletions src/Platform.Cocoa/GameHostMetal.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Copyright (c) 2013-2017 mogemimi. Distributed under the MIT license.

#pragma once

#include "Pomdog/Signals/EventQueue.hpp"
#include "Pomdog/Application/GameHost.hpp"
#include <memory>

#import <MetalKit/MTKView.h>

namespace Pomdog {

class Game;
struct PresentationParameters;

namespace Detail {
namespace Cocoa {

class GameWindowCocoa;

class GameHostMetal final : public GameHost {
public:
GameHostMetal(
MTKView* metalView,
const std::shared_ptr<GameWindowCocoa>& window,
const std::shared_ptr<EventQueue>& eventQueue,
const PresentationParameters& presentationParameters);

~GameHostMetal();

void InitializeGame(
const std::weak_ptr<Game>& game,
const std::function<void()>& onCompleted);

void GameLoop();

bool IsMetalSupported() const;

void Exit() override;

std::shared_ptr<GameWindow> GetWindow() override;

std::shared_ptr<GameClock> GetClock() override;

std::shared_ptr<GraphicsDevice> GetGraphicsDevice() override;

std::shared_ptr<GraphicsCommandQueue> GetGraphicsCommandQueue() override;

std::shared_ptr<AudioEngine> GetAudioEngine() override;

std::shared_ptr<AssetManager> GetAssetManager() override;

std::shared_ptr<Keyboard> GetKeyboard() override;

std::shared_ptr<Mouse> GetMouse() override;

SurfaceFormat GetBackBufferSurfaceFormat() const override;

DepthFormat GetBackBufferDepthStencilFormat() const override;

private:
class Impl;
std::unique_ptr<Impl> impl;
};

} // namespace Cocoa
} // namespace Detail
} // namespace Pomdog
Loading

0 comments on commit af5de17

Please sign in to comment.