2015-11-09 02:24:45 +00:00
|
|
|
#ifndef BOO_COCOACOMMON_HPP
|
|
|
|
#define BOO_COCOACOMMON_HPP
|
|
|
|
#if __APPLE__
|
|
|
|
|
2015-11-16 22:03:46 +00:00
|
|
|
#include <Availability.h>
|
2015-12-27 04:20:07 +00:00
|
|
|
#include <utility>
|
2015-11-09 02:24:45 +00:00
|
|
|
|
|
|
|
template <class T>
|
|
|
|
class NSPtr
|
|
|
|
{
|
2015-12-27 04:20:07 +00:00
|
|
|
void* m_ptr = nullptr;
|
2015-11-09 02:24:45 +00:00
|
|
|
public:
|
|
|
|
NSPtr() = default;
|
2015-12-27 04:20:07 +00:00
|
|
|
~NSPtr()
|
|
|
|
{
|
|
|
|
T ptr = (__bridge_transfer T)m_ptr;
|
|
|
|
(void)ptr;
|
|
|
|
}
|
|
|
|
NSPtr(T&& recv) {*this = std::move(recv);}
|
|
|
|
NSPtr& operator=(T&& recv)
|
|
|
|
{
|
|
|
|
T old = (__bridge_transfer T)m_ptr;
|
|
|
|
(void)old;
|
|
|
|
m_ptr = (__bridge_retained void*)recv;
|
|
|
|
return *this;
|
|
|
|
}
|
2015-11-09 02:24:45 +00:00
|
|
|
NSPtr(const NSPtr& other) = delete;
|
|
|
|
NSPtr(NSPtr&& other) = default;
|
|
|
|
NSPtr& operator=(const NSPtr& other) = delete;
|
|
|
|
NSPtr& operator=(NSPtr&& other) = default;
|
|
|
|
operator bool() const {return m_ptr != 0;}
|
2015-12-27 04:20:07 +00:00
|
|
|
T get() const {return (__bridge T)m_ptr;}
|
|
|
|
void reset()
|
|
|
|
{
|
|
|
|
T old = (__bridge_transfer T)m_ptr;
|
|
|
|
(void)old;
|
|
|
|
m_ptr = nullptr;
|
|
|
|
}
|
2015-11-09 02:24:45 +00:00
|
|
|
};
|
|
|
|
|
2015-11-16 22:03:46 +00:00
|
|
|
#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 101100
|
|
|
|
#define BOO_HAS_METAL 1
|
|
|
|
|
|
|
|
#include <Metal/Metal.h>
|
|
|
|
#include <QuartzCore/CAMetalLayer.h>
|
2015-11-18 23:55:25 +00:00
|
|
|
#include <unordered_map>
|
2015-12-09 22:23:22 +00:00
|
|
|
#include <mutex>
|
2015-11-16 22:03:46 +00:00
|
|
|
|
2015-11-09 02:24:45 +00:00
|
|
|
namespace boo
|
|
|
|
{
|
2015-11-18 23:55:25 +00:00
|
|
|
class IWindow;
|
2015-11-09 02:24:45 +00:00
|
|
|
struct MetalContext
|
|
|
|
{
|
|
|
|
NSPtr<id<MTLDevice>> m_dev;
|
|
|
|
NSPtr<id<MTLCommandQueue>> m_q;
|
|
|
|
struct Window
|
|
|
|
{
|
|
|
|
CAMetalLayer* m_metalLayer = nullptr;
|
2015-12-09 22:23:22 +00:00
|
|
|
std::mutex m_resizeLock;
|
|
|
|
bool m_needsResize;
|
|
|
|
CGSize m_size;
|
2015-11-09 02:24:45 +00:00
|
|
|
};
|
|
|
|
std::unordered_map<IWindow*, Window> m_windows;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2015-11-16 22:03:46 +00:00
|
|
|
#else
|
|
|
|
#define BOO_HAS_METAL 0
|
|
|
|
namespace boo
|
|
|
|
{
|
|
|
|
struct MetalContext {};
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-11-09 02:24:45 +00:00
|
|
|
#endif // __APPLE__
|
|
|
|
#endif // BOO_COCOACOMMON_HPP
|