OS X updates; post-frame handler event

This commit is contained in:
Jack Andersen 2015-12-20 14:40:52 -10:00
parent 886ae22e08
commit 01ab873e06
4 changed files with 37 additions and 9 deletions

View File

@ -3,6 +3,7 @@
#include "IGraphicsDataFactory.hpp" #include "IGraphicsDataFactory.hpp"
#include "boo/IWindow.hpp" #include "boo/IWindow.hpp"
#include <functional>
namespace boo namespace boo
{ {
@ -26,6 +27,7 @@ struct IGraphicsCommandQueue
virtual void setScissor(const SWindowRect& rect)=0; virtual void setScissor(const SWindowRect& rect)=0;
virtual void resizeRenderTexture(ITextureR* tex, size_t width, size_t height)=0; virtual void resizeRenderTexture(ITextureR* tex, size_t width, size_t height)=0;
virtual void schedulePostFrameHandler(std::function<void(void)>&& func)=0;
virtual void setClearColor(const float rgba[4])=0; virtual void setClearColor(const float rgba[4])=0;
virtual void clearTarget(bool render=true, bool depth=true)=0; virtual void clearTarget(bool render=true, bool depth=true)=0;

View File

@ -727,6 +727,8 @@ struct GLCommandQueue : IGraphicsCommandQueue
/* These members are locked for multithreaded access */ /* These members are locked for multithreaded access */
std::vector<RenderTextureResize> m_pendingResizes; std::vector<RenderTextureResize> m_pendingResizes;
std::vector<std::function<void(void)>> m_pendingPosts1;
std::vector<std::function<void(void)>> m_pendingPosts2;
std::vector<GLVertexFormat*> m_pendingFmtAdds; std::vector<GLVertexFormat*> m_pendingFmtAdds;
std::vector<std::array<GLuint, 3>> m_pendingFmtDels; std::vector<std::array<GLuint, 3>> m_pendingFmtDels;
std::vector<GLTextureR*> m_pendingFboAdds; std::vector<GLTextureR*> m_pendingFboAdds;
@ -812,6 +814,7 @@ struct GLCommandQueue : IGraphicsCommandQueue
self->m_initcv.notify_one(); self->m_initcv.notify_one();
while (self->m_running) while (self->m_running)
{ {
std::vector<std::function<void(void)>> posts;
{ {
std::unique_lock<std::mutex> lk(self->m_mt); std::unique_lock<std::mutex> lk(self->m_mt);
self->m_cv.wait(lk); self->m_cv.wait(lk);
@ -853,6 +856,9 @@ struct GLCommandQueue : IGraphicsCommandQueue
glDeleteFramebuffers(1, &fbo); glDeleteFramebuffers(1, &fbo);
self->m_pendingFboDels.clear(); self->m_pendingFboDels.clear();
} }
if (self->m_pendingPosts2.size())
posts.swap(self->m_pendingPosts2);
} }
std::vector<Command>& cmds = self->m_cmdBufs[self->m_drawBuf]; std::vector<Command>& cmds = self->m_cmdBufs[self->m_drawBuf];
GLenum prim = GL_TRIANGLES; GLenum prim = GL_TRIANGLES;
@ -924,6 +930,8 @@ struct GLCommandQueue : IGraphicsCommandQueue
} }
} }
cmds.clear(); cmds.clear();
for (auto& p : posts)
p();
} }
} }
@ -983,6 +991,11 @@ struct GLCommandQueue : IGraphicsCommandQueue
m_pendingResizes.push_back({texgl, width, height}); m_pendingResizes.push_back({texgl, width, height});
} }
void schedulePostFrameHandler(std::function<void(void)>&& func)
{
m_pendingPosts1.push_back(std::move(func));
}
void setClearColor(const float rgba[4]) void setClearColor(const float rgba[4])
{ {
std::vector<Command>& cmds = m_cmdBufs[m_fillBuf]; std::vector<Command>& cmds = m_cmdBufs[m_fillBuf];
@ -1113,6 +1126,10 @@ struct GLCommandQueue : IGraphicsCommandQueue
datalk.unlock(); datalk.unlock();
glFlush(); glFlush();
for (auto& p : m_pendingPosts1)
m_pendingPosts2.push_back(std::move(p));
m_pendingPosts1.clear();
lk.unlock(); lk.unlock();
m_cv.notify_one(); m_cv.notify_one();
m_cmdBufs[m_fillBuf].clear(); m_cmdBufs[m_fillBuf].clear();

View File

@ -611,6 +611,11 @@ struct MetalCommandQueue : IGraphicsCommandQueue
MetalTextureR* ctex = static_cast<MetalTextureR*>(tex); MetalTextureR* ctex = static_cast<MetalTextureR*>(tex);
m_texResizes[ctex] = std::make_pair(width, height); m_texResizes[ctex] = std::make_pair(width, height);
} }
void schedulePostFrameHandler(std::function<void(void)>&& func)
{
func();
}
void flushBufferUpdates() {} void flushBufferUpdates() {}

View File

@ -729,7 +729,8 @@ enum
}; };
static boo::ESpecialKey translateKeycode(short code) static boo::ESpecialKey translateKeycode(short code)
{ {
switch (code) { switch (code)
{
case kVK_F1: case kVK_F1:
return boo::ESpecialKey::F1; return boo::ESpecialKey::F1;
case kVK_F2: case kVK_F2:
@ -787,14 +788,13 @@ static boo::ESpecialKey translateKeycode(short code)
{ {
if (!booContext->m_callback) if (!booContext->m_callback)
return; return;
boo::ESpecialKey special = translateKeycode(theEvent.keyCode);
NSString* chars = theEvent.characters; NSString* chars = theEvent.characters;
if ([chars length] == 0 || if (special != boo::ESpecialKey::None)
[chars characterAtIndex:0] == '\n' || booContext->m_callback->specialKeyDown(special,
[chars characterAtIndex:0] == '\r')
booContext->m_callback->specialKeyDown(translateKeycode(theEvent.keyCode),
getMod(theEvent.modifierFlags), getMod(theEvent.modifierFlags),
theEvent.isARepeat); theEvent.isARepeat);
else else if ([chars length])
booContext->m_callback->charKeyDown([chars characterAtIndex:0], booContext->m_callback->charKeyDown([chars characterAtIndex:0],
getMod(theEvent.modifierFlags), getMod(theEvent.modifierFlags),
theEvent.isARepeat); theEvent.isARepeat);
@ -804,11 +804,12 @@ static boo::ESpecialKey translateKeycode(short code)
{ {
if (!booContext->m_callback) if (!booContext->m_callback)
return; return;
boo::ESpecialKey special = translateKeycode(theEvent.keyCode);
NSString* chars = theEvent.characters; NSString* chars = theEvent.characters;
if ([chars length] == 0) if (special != boo::ESpecialKey::None)
booContext->m_callback->specialKeyUp(translateKeycode(theEvent.keyCode), booContext->m_callback->specialKeyUp(special,
getMod(theEvent.modifierFlags)); getMod(theEvent.modifierFlags));
else else if ([chars length])
booContext->m_callback->charKeyUp([chars characterAtIndex:0], booContext->m_callback->charKeyUp([chars characterAtIndex:0],
getMod(theEvent.modifierFlags)); getMod(theEvent.modifierFlags));
} }
@ -1074,6 +1075,9 @@ public:
case EMouseCursor::VerticalArrow: case EMouseCursor::VerticalArrow:
[[NSCursor resizeUpDownCursor] set]; [[NSCursor resizeUpDownCursor] set];
break; break;
case EMouseCursor::IBeam:
[[NSCursor IBeamCursor] set];
break;
default: break; default: break;
} }
}); });