mirror of https://github.com/AxioDL/boo.git
OS X fixes
This commit is contained in:
parent
d657f3c8f8
commit
b11b727c4d
|
@ -27,11 +27,12 @@ class MetalDataFactory : public IGraphicsDataFactory
|
||||||
std::unordered_set<struct MetalData*> m_committedData;
|
std::unordered_set<struct MetalData*> m_committedData;
|
||||||
std::mutex m_committedMutex;
|
std::mutex m_committedMutex;
|
||||||
struct MetalContext* m_ctx;
|
struct MetalContext* m_ctx;
|
||||||
|
uint32_t m_sampleCount;
|
||||||
|
|
||||||
void destroyData(IGraphicsData*);
|
void destroyData(IGraphicsData*);
|
||||||
void destroyAllData();
|
void destroyAllData();
|
||||||
public:
|
public:
|
||||||
MetalDataFactory(IGraphicsContext* parent, MetalContext* ctx);
|
MetalDataFactory(IGraphicsContext* parent, MetalContext* ctx, uint32_t sampleCount);
|
||||||
~MetalDataFactory() {}
|
~MetalDataFactory() {}
|
||||||
|
|
||||||
Platform platform() const {return Platform::Metal;}
|
Platform platform() const {return Platform::Metal;}
|
||||||
|
@ -44,11 +45,11 @@ public:
|
||||||
const void* data, size_t sz);
|
const void* data, size_t sz);
|
||||||
GraphicsDataToken
|
GraphicsDataToken
|
||||||
newStaticTextureNoContext(size_t width, size_t height, size_t mips, TextureFormat fmt,
|
newStaticTextureNoContext(size_t width, size_t height, size_t mips, TextureFormat fmt,
|
||||||
const void* data, size_t sz, ITextureS** texOut);
|
const void* data, size_t sz, ITextureS*& texOut);
|
||||||
ITextureSA* newStaticArrayTexture(size_t width, size_t height, size_t layers, TextureFormat fmt,
|
ITextureSA* newStaticArrayTexture(size_t width, size_t height, size_t layers, TextureFormat fmt,
|
||||||
const void* data, size_t sz);
|
const void* data, size_t sz);
|
||||||
ITextureD* newDynamicTexture(size_t width, size_t height, TextureFormat fmt);
|
ITextureD* newDynamicTexture(size_t width, size_t height, TextureFormat fmt);
|
||||||
ITextureR* newRenderTexture(size_t width, size_t height, size_t samples);
|
ITextureR* newRenderTexture(size_t width, size_t height);
|
||||||
|
|
||||||
bool bindingNeedsVertexFormat() const {return false;}
|
bool bindingNeedsVertexFormat() const {return false;}
|
||||||
IVertexFormat* newVertexFormat(size_t elementCount, const VertexElementDescriptor* elements);
|
IVertexFormat* newVertexFormat(size_t elementCount, const VertexElementDescriptor* elements);
|
||||||
|
|
|
@ -648,23 +648,14 @@ struct MetalCommandQueue : IGraphicsCommandQueue
|
||||||
setRenderTarget(m_boundTarget);
|
setRenderTarget(m_boundTarget);
|
||||||
}
|
}
|
||||||
|
|
||||||
MTLPrimitiveType m_primType = MTLPrimitiveTypeTriangle;
|
|
||||||
void setDrawPrimitive(Primitive prim)
|
|
||||||
{
|
|
||||||
if (prim == Primitive::Triangles)
|
|
||||||
m_primType = MTLPrimitiveTypeTriangle;
|
|
||||||
else if (prim == Primitive::TriStrips)
|
|
||||||
m_primType = MTLPrimitiveTypeTriangleStrip;
|
|
||||||
}
|
|
||||||
|
|
||||||
void draw(size_t start, size_t count)
|
void draw(size_t start, size_t count)
|
||||||
{
|
{
|
||||||
[m_enc drawPrimitives:m_primType vertexStart:start vertexCount:count];
|
[m_enc drawPrimitives:MTLPrimitiveTypeTriangleStrip vertexStart:start vertexCount:count];
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawIndexed(size_t start, size_t count)
|
void drawIndexed(size_t start, size_t count)
|
||||||
{
|
{
|
||||||
[m_enc drawIndexedPrimitives:m_primType
|
[m_enc drawIndexedPrimitives:MTLPrimitiveTypeTriangleStrip
|
||||||
indexCount:count
|
indexCount:count
|
||||||
indexType:MTLIndexTypeUInt32
|
indexType:MTLIndexTypeUInt32
|
||||||
indexBuffer:GetBufferGPUResource(m_boundData->m_ibuf, m_fillBuf)
|
indexBuffer:GetBufferGPUResource(m_boundData->m_ibuf, m_fillBuf)
|
||||||
|
@ -673,12 +664,13 @@ struct MetalCommandQueue : IGraphicsCommandQueue
|
||||||
|
|
||||||
void drawInstances(size_t start, size_t count, size_t instCount)
|
void drawInstances(size_t start, size_t count, size_t instCount)
|
||||||
{
|
{
|
||||||
[m_enc drawPrimitives:m_primType vertexStart:start vertexCount:count instanceCount:instCount];
|
[m_enc drawPrimitives:MTLPrimitiveTypeTriangleStrip
|
||||||
|
vertexStart:start vertexCount:count instanceCount:instCount];
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawInstancesIndexed(size_t start, size_t count, size_t instCount)
|
void drawInstancesIndexed(size_t start, size_t count, size_t instCount)
|
||||||
{
|
{
|
||||||
[m_enc drawIndexedPrimitives:m_primType
|
[m_enc drawIndexedPrimitives:MTLPrimitiveTypeTriangleStrip
|
||||||
indexCount:count
|
indexCount:count
|
||||||
indexType:MTLIndexTypeUInt32
|
indexType:MTLIndexTypeUInt32
|
||||||
indexBuffer:GetBufferGPUResource(m_boundData->m_ibuf, m_fillBuf)
|
indexBuffer:GetBufferGPUResource(m_boundData->m_ibuf, m_fillBuf)
|
||||||
|
@ -839,8 +831,8 @@ void MetalTextureD::unmap()
|
||||||
m_validSlots = 0;
|
m_validSlots = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
MetalDataFactory::MetalDataFactory(IGraphicsContext* parent, MetalContext* ctx)
|
MetalDataFactory::MetalDataFactory(IGraphicsContext* parent, MetalContext* ctx, uint32_t sampleCount)
|
||||||
: m_parent(parent), m_ctx(ctx) {}
|
: m_parent(parent), m_ctx(ctx), m_sampleCount(sampleCount) {}
|
||||||
|
|
||||||
IGraphicsBufferS* MetalDataFactory::newStaticBuffer(BufferUse use, const void* data, size_t stride, size_t count)
|
IGraphicsBufferS* MetalDataFactory::newStaticBuffer(BufferUse use, const void* data, size_t stride, size_t count)
|
||||||
{
|
{
|
||||||
|
@ -871,12 +863,12 @@ ITextureS* MetalDataFactory::newStaticTexture(size_t width, size_t height, size_
|
||||||
}
|
}
|
||||||
GraphicsDataToken
|
GraphicsDataToken
|
||||||
MetalDataFactory::newStaticTextureNoContext(size_t width, size_t height, size_t mips, TextureFormat fmt,
|
MetalDataFactory::newStaticTextureNoContext(size_t width, size_t height, size_t mips, TextureFormat fmt,
|
||||||
const void* data, size_t sz, ITextureS** texOut)
|
const void* data, size_t sz, ITextureS*& texOut)
|
||||||
{
|
{
|
||||||
MetalTextureS* retval = new MetalTextureS(m_ctx, width, height, mips, fmt, data, sz);
|
MetalTextureS* retval = new MetalTextureS(m_ctx, width, height, mips, fmt, data, sz);
|
||||||
MetalData* tokData = new struct MetalData();
|
MetalData* tokData = new struct MetalData();
|
||||||
tokData->m_STexs.emplace_back(retval);
|
tokData->m_STexs.emplace_back(retval);
|
||||||
*texOut = retval;
|
texOut = retval;
|
||||||
|
|
||||||
std::unique_lock<std::mutex> lk(m_committedMutex);
|
std::unique_lock<std::mutex> lk(m_committedMutex);
|
||||||
m_committedData.insert(tokData);
|
m_committedData.insert(tokData);
|
||||||
|
@ -900,9 +892,9 @@ ITextureD* MetalDataFactory::newDynamicTexture(size_t width, size_t height, Text
|
||||||
m_deferredData->m_DTexs.emplace_back(retval);
|
m_deferredData->m_DTexs.emplace_back(retval);
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
ITextureR* MetalDataFactory::newRenderTexture(size_t width, size_t height, size_t samples)
|
ITextureR* MetalDataFactory::newRenderTexture(size_t width, size_t height)
|
||||||
{
|
{
|
||||||
MetalTextureR* retval = new MetalTextureR(m_ctx, width, height, samples);
|
MetalTextureR* retval = new MetalTextureR(m_ctx, width, height, m_sampleCount);
|
||||||
if (!m_deferredData.get())
|
if (!m_deferredData.get())
|
||||||
m_deferredData.reset(new struct MetalData());
|
m_deferredData.reset(new struct MetalData());
|
||||||
m_deferredData->m_RTexs.emplace_back(retval);
|
m_deferredData->m_RTexs.emplace_back(retval);
|
||||||
|
|
|
@ -24,7 +24,8 @@ namespace boo
|
||||||
{
|
{
|
||||||
static LogVisor::LogModule Log("boo::ApplicationCocoa");
|
static LogVisor::LogModule Log("boo::ApplicationCocoa");
|
||||||
|
|
||||||
IWindow* _WindowCocoaNew(const SystemString& title, NSOpenGLContext* lastGLCtx, MetalContext* metalCtx);
|
IWindow* _WindowCocoaNew(const SystemString& title, NSOpenGLContext* lastGLCtx,
|
||||||
|
MetalContext* metalCtx, uint32_t sampleCount);
|
||||||
|
|
||||||
class ApplicationCocoa : public IApplication
|
class ApplicationCocoa : public IApplication
|
||||||
{
|
{
|
||||||
|
@ -151,9 +152,9 @@ public:
|
||||||
return m_args;
|
return m_args;
|
||||||
}
|
}
|
||||||
|
|
||||||
IWindow* newWindow(const std::string& title)
|
IWindow* newWindow(const std::string& title, uint32_t sampleCount)
|
||||||
{
|
{
|
||||||
IWindow* newWindow = _WindowCocoaNew(title, m_lastGLCtx, &m_metalCtx);
|
IWindow* newWindow = _WindowCocoaNew(title, m_lastGLCtx, &m_metalCtx, sampleCount);
|
||||||
m_windows[newWindow->getPlatformHandle()] = newWindow;
|
m_windows[newWindow->getPlatformHandle()] = newWindow;
|
||||||
return newWindow;
|
return newWindow;
|
||||||
}
|
}
|
||||||
|
|
|
@ -183,11 +183,12 @@ class GraphicsContextCocoaGL : public GraphicsContextCocoa
|
||||||
public:
|
public:
|
||||||
NSOpenGLContext* m_lastCtx = nullptr;
|
NSOpenGLContext* m_lastCtx = nullptr;
|
||||||
|
|
||||||
GraphicsContextCocoaGL(EGraphicsAPI api, IWindow* parentWindow, NSOpenGLContext* lastGLCtx)
|
GraphicsContextCocoaGL(EGraphicsAPI api, IWindow* parentWindow,
|
||||||
|
NSOpenGLContext* lastGLCtx, uint32_t sampleCount)
|
||||||
: GraphicsContextCocoa(api, EPixelFormat::RGBA8, parentWindow),
|
: GraphicsContextCocoa(api, EPixelFormat::RGBA8, parentWindow),
|
||||||
m_lastCtx(lastGLCtx)
|
m_lastCtx(lastGLCtx)
|
||||||
{
|
{
|
||||||
m_dataFactory = new GLDataFactory(this);
|
m_dataFactory = new GLDataFactory(this, sampleCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
~GraphicsContextCocoaGL()
|
~GraphicsContextCocoaGL()
|
||||||
|
@ -290,7 +291,8 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
IGraphicsContext* _GraphicsContextCocoaGLNew(IGraphicsContext::EGraphicsAPI api,
|
IGraphicsContext* _GraphicsContextCocoaGLNew(IGraphicsContext::EGraphicsAPI api,
|
||||||
IWindow* parentWindow, NSOpenGLContext* lastGLCtx)
|
IWindow* parentWindow, NSOpenGLContext* lastGLCtx,
|
||||||
|
uint32_t sampleCount)
|
||||||
{
|
{
|
||||||
if (api != IGraphicsContext::EGraphicsAPI::OpenGL3_3 && api != IGraphicsContext::EGraphicsAPI::OpenGL4_2)
|
if (api != IGraphicsContext::EGraphicsAPI::OpenGL3_3 && api != IGraphicsContext::EGraphicsAPI::OpenGL4_2)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -321,7 +323,7 @@ IGraphicsContext* _GraphicsContextCocoaGLNew(IGraphicsContext::EGraphicsAPI api,
|
||||||
if (api == IGraphicsContext::EGraphicsAPI::OpenGL4_2)
|
if (api == IGraphicsContext::EGraphicsAPI::OpenGL4_2)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
return new GraphicsContextCocoaGL(api, parentWindow, lastGLCtx);
|
return new GraphicsContextCocoaGL(api, parentWindow, lastGLCtx, sampleCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if BOO_HAS_METAL
|
#if BOO_HAS_METAL
|
||||||
|
@ -337,11 +339,11 @@ public:
|
||||||
MetalContext* m_metalCtx;
|
MetalContext* m_metalCtx;
|
||||||
|
|
||||||
GraphicsContextCocoaMetal(EGraphicsAPI api, IWindow* parentWindow,
|
GraphicsContextCocoaMetal(EGraphicsAPI api, IWindow* parentWindow,
|
||||||
MetalContext* metalCtx)
|
MetalContext* metalCtx, uint32_t sampleCount)
|
||||||
: GraphicsContextCocoa(api, EPixelFormat::RGBA8, parentWindow),
|
: GraphicsContextCocoa(api, EPixelFormat::RGBA8, parentWindow),
|
||||||
m_parentWindow(parentWindow), m_metalCtx(metalCtx)
|
m_parentWindow(parentWindow), m_metalCtx(metalCtx)
|
||||||
{
|
{
|
||||||
m_dataFactory = new MetalDataFactory(this, metalCtx);
|
m_dataFactory = new MetalDataFactory(this, metalCtx, sampleCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
~GraphicsContextCocoaMetal()
|
~GraphicsContextCocoaMetal()
|
||||||
|
@ -430,11 +432,12 @@ public:
|
||||||
|
|
||||||
IGraphicsContext* _GraphicsContextCocoaMetalNew(IGraphicsContext::EGraphicsAPI api,
|
IGraphicsContext* _GraphicsContextCocoaMetalNew(IGraphicsContext::EGraphicsAPI api,
|
||||||
IWindow* parentWindow,
|
IWindow* parentWindow,
|
||||||
MetalContext* metalCtx)
|
MetalContext* metalCtx,
|
||||||
|
uint32_t sampleCount)
|
||||||
{
|
{
|
||||||
if (api != IGraphicsContext::EGraphicsAPI::Metal)
|
if (api != IGraphicsContext::EGraphicsAPI::Metal)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
return new GraphicsContextCocoaMetal(api, parentWindow, metalCtx);
|
return new GraphicsContextCocoaMetal(api, parentWindow, metalCtx, sampleCount);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -1230,17 +1233,19 @@ class WindowCocoa : public IWindow
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
WindowCocoa(const std::string& title, NSOpenGLContext* lastGLCtx, MetalContext* metalCtx)
|
WindowCocoa(const std::string& title, NSOpenGLContext* lastGLCtx, MetalContext* metalCtx, uint32_t sampleCount)
|
||||||
{
|
{
|
||||||
dispatch_sync(dispatch_get_main_queue(),
|
dispatch_sync(dispatch_get_main_queue(),
|
||||||
^{
|
^{
|
||||||
m_nsWindow = [[WindowCocoaInternal alloc] initWithBooWindow:this title:title];
|
m_nsWindow = [[WindowCocoaInternal alloc] initWithBooWindow:this title:title];
|
||||||
#if BOO_HAS_METAL
|
#if BOO_HAS_METAL
|
||||||
if (metalCtx->m_dev)
|
if (metalCtx->m_dev)
|
||||||
m_gfxCtx = static_cast<GraphicsContextCocoa*>(_GraphicsContextCocoaMetalNew(IGraphicsContext::EGraphicsAPI::Metal, this, metalCtx));
|
m_gfxCtx = static_cast<GraphicsContextCocoa*>(_GraphicsContextCocoaMetalNew(IGraphicsContext::EGraphicsAPI::Metal,
|
||||||
|
this, metalCtx, sampleCount));
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
m_gfxCtx = static_cast<GraphicsContextCocoa*>(_GraphicsContextCocoaGLNew(IGraphicsContext::EGraphicsAPI::OpenGL3_3, this, lastGLCtx));
|
m_gfxCtx = static_cast<GraphicsContextCocoa*>(_GraphicsContextCocoaGLNew(IGraphicsContext::EGraphicsAPI::OpenGL3_3,
|
||||||
|
this, lastGLCtx, sampleCount));
|
||||||
m_gfxCtx->initializeContext();
|
m_gfxCtx->initializeContext();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1496,9 +1501,10 @@ public:
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
IWindow* _WindowCocoaNew(const SystemString& title, NSOpenGLContext* lastGLCtx, MetalContext* metalCtx)
|
IWindow* _WindowCocoaNew(const SystemString& title, NSOpenGLContext* lastGLCtx,
|
||||||
|
MetalContext* metalCtx, uint32_t sampleCount)
|
||||||
{
|
{
|
||||||
return new WindowCocoa(title, lastGLCtx, metalCtx);
|
return new WindowCocoa(title, lastGLCtx, metalCtx, sampleCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue