OS X fixes

This commit is contained in:
Jack Andersen 2016-02-24 11:07:48 -10:00
parent d657f3c8f8
commit b11b727c4d
4 changed files with 148 additions and 148 deletions

View File

@ -27,11 +27,12 @@ class MetalDataFactory : public IGraphicsDataFactory
std::unordered_set<struct MetalData*> m_committedData;
std::mutex m_committedMutex;
struct MetalContext* m_ctx;
uint32_t m_sampleCount;
void destroyData(IGraphicsData*);
void destroyAllData();
public:
MetalDataFactory(IGraphicsContext* parent, MetalContext* ctx);
MetalDataFactory(IGraphicsContext* parent, MetalContext* ctx, uint32_t sampleCount);
~MetalDataFactory() {}
Platform platform() const {return Platform::Metal;}
@ -44,11 +45,11 @@ public:
const void* data, size_t sz);
GraphicsDataToken
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,
const void* data, size_t sz);
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;}
IVertexFormat* newVertexFormat(size_t elementCount, const VertexElementDescriptor* elements);

View File

@ -648,23 +648,14 @@ struct MetalCommandQueue : IGraphicsCommandQueue
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)
{
[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)
{
[m_enc drawIndexedPrimitives:m_primType
[m_enc drawIndexedPrimitives:MTLPrimitiveTypeTriangleStrip
indexCount:count
indexType:MTLIndexTypeUInt32
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)
{
[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)
{
[m_enc drawIndexedPrimitives:m_primType
[m_enc drawIndexedPrimitives:MTLPrimitiveTypeTriangleStrip
indexCount:count
indexType:MTLIndexTypeUInt32
indexBuffer:GetBufferGPUResource(m_boundData->m_ibuf, m_fillBuf)
@ -839,8 +831,8 @@ void MetalTextureD::unmap()
m_validSlots = 0;
}
MetalDataFactory::MetalDataFactory(IGraphicsContext* parent, MetalContext* ctx)
: m_parent(parent), m_ctx(ctx) {}
MetalDataFactory::MetalDataFactory(IGraphicsContext* parent, MetalContext* ctx, uint32_t sampleCount)
: m_parent(parent), m_ctx(ctx), m_sampleCount(sampleCount) {}
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
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);
MetalData* tokData = new struct MetalData();
tokData->m_STexs.emplace_back(retval);
*texOut = retval;
texOut = retval;
std::unique_lock<std::mutex> lk(m_committedMutex);
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);
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())
m_deferredData.reset(new struct MetalData());
m_deferredData->m_RTexs.emplace_back(retval);

View File

@ -24,7 +24,8 @@ namespace boo
{
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
{
@ -151,9 +152,9 @@ public:
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;
return newWindow;
}

View File

@ -183,11 +183,12 @@ class GraphicsContextCocoaGL : public GraphicsContextCocoa
public:
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),
m_lastCtx(lastGLCtx)
{
m_dataFactory = new GLDataFactory(this);
m_dataFactory = new GLDataFactory(this, sampleCount);
}
~GraphicsContextCocoaGL()
@ -290,7 +291,8 @@ public:
};
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)
return NULL;
@ -321,7 +323,7 @@ IGraphicsContext* _GraphicsContextCocoaGLNew(IGraphicsContext::EGraphicsAPI api,
if (api == IGraphicsContext::EGraphicsAPI::OpenGL4_2)
return NULL;
return new GraphicsContextCocoaGL(api, parentWindow, lastGLCtx);
return new GraphicsContextCocoaGL(api, parentWindow, lastGLCtx, sampleCount);
}
#if BOO_HAS_METAL
@ -337,11 +339,11 @@ public:
MetalContext* m_metalCtx;
GraphicsContextCocoaMetal(EGraphicsAPI api, IWindow* parentWindow,
MetalContext* metalCtx)
MetalContext* metalCtx, uint32_t sampleCount)
: GraphicsContextCocoa(api, EPixelFormat::RGBA8, parentWindow),
m_parentWindow(parentWindow), m_metalCtx(metalCtx)
{
m_dataFactory = new MetalDataFactory(this, metalCtx);
m_dataFactory = new MetalDataFactory(this, metalCtx, sampleCount);
}
~GraphicsContextCocoaMetal()
@ -430,11 +432,12 @@ public:
IGraphicsContext* _GraphicsContextCocoaMetalNew(IGraphicsContext::EGraphicsAPI api,
IWindow* parentWindow,
MetalContext* metalCtx)
MetalContext* metalCtx,
uint32_t sampleCount)
{
if (api != IGraphicsContext::EGraphicsAPI::Metal)
return nullptr;
return new GraphicsContextCocoaMetal(api, parentWindow, metalCtx);
return new GraphicsContextCocoaMetal(api, parentWindow, metalCtx, sampleCount);
}
#endif
@ -1230,17 +1233,19 @@ class WindowCocoa : public IWindow
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(),
^{
m_nsWindow = [[WindowCocoaInternal alloc] initWithBooWindow:this title:title];
#if BOO_HAS_METAL
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
#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();
});
}
@ -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);
}
}