diff --git a/include/boo/graphicsdev/IGraphicsCommandQueue.hpp b/include/boo/graphicsdev/IGraphicsCommandQueue.hpp index f36e4ba..edf29fc 100644 --- a/include/boo/graphicsdev/IGraphicsCommandQueue.hpp +++ b/include/boo/graphicsdev/IGraphicsCommandQueue.hpp @@ -3,6 +3,7 @@ #include "IGraphicsDataFactory.hpp" #include "boo/IWindow.hpp" +#include namespace boo { @@ -26,6 +27,7 @@ struct IGraphicsCommandQueue virtual void setScissor(const SWindowRect& rect)=0; virtual void resizeRenderTexture(ITextureR* tex, size_t width, size_t height)=0; + virtual void schedulePostFrameHandler(std::function&& func)=0; virtual void setClearColor(const float rgba[4])=0; virtual void clearTarget(bool render=true, bool depth=true)=0; diff --git a/lib/graphicsdev/GL.cpp b/lib/graphicsdev/GL.cpp index 9596b30..e193bc4 100644 --- a/lib/graphicsdev/GL.cpp +++ b/lib/graphicsdev/GL.cpp @@ -727,6 +727,8 @@ struct GLCommandQueue : IGraphicsCommandQueue /* These members are locked for multithreaded access */ std::vector m_pendingResizes; + std::vector> m_pendingPosts1; + std::vector> m_pendingPosts2; std::vector m_pendingFmtAdds; std::vector> m_pendingFmtDels; std::vector m_pendingFboAdds; @@ -812,6 +814,7 @@ struct GLCommandQueue : IGraphicsCommandQueue self->m_initcv.notify_one(); while (self->m_running) { + std::vector> posts; { std::unique_lock lk(self->m_mt); self->m_cv.wait(lk); @@ -853,6 +856,9 @@ struct GLCommandQueue : IGraphicsCommandQueue glDeleteFramebuffers(1, &fbo); self->m_pendingFboDels.clear(); } + + if (self->m_pendingPosts2.size()) + posts.swap(self->m_pendingPosts2); } std::vector& cmds = self->m_cmdBufs[self->m_drawBuf]; GLenum prim = GL_TRIANGLES; @@ -924,6 +930,8 @@ struct GLCommandQueue : IGraphicsCommandQueue } } cmds.clear(); + for (auto& p : posts) + p(); } } @@ -983,6 +991,11 @@ struct GLCommandQueue : IGraphicsCommandQueue m_pendingResizes.push_back({texgl, width, height}); } + void schedulePostFrameHandler(std::function&& func) + { + m_pendingPosts1.push_back(std::move(func)); + } + void setClearColor(const float rgba[4]) { std::vector& cmds = m_cmdBufs[m_fillBuf]; @@ -1113,6 +1126,10 @@ struct GLCommandQueue : IGraphicsCommandQueue datalk.unlock(); glFlush(); + for (auto& p : m_pendingPosts1) + m_pendingPosts2.push_back(std::move(p)); + m_pendingPosts1.clear(); + lk.unlock(); m_cv.notify_one(); m_cmdBufs[m_fillBuf].clear(); diff --git a/lib/graphicsdev/Metal.mm b/lib/graphicsdev/Metal.mm index ec38360..cb2df07 100644 --- a/lib/graphicsdev/Metal.mm +++ b/lib/graphicsdev/Metal.mm @@ -611,6 +611,11 @@ struct MetalCommandQueue : IGraphicsCommandQueue MetalTextureR* ctex = static_cast(tex); m_texResizes[ctex] = std::make_pair(width, height); } + + void schedulePostFrameHandler(std::function&& func) + { + func(); + } void flushBufferUpdates() {} diff --git a/lib/mac/WindowCocoa.mm b/lib/mac/WindowCocoa.mm index 828b39e..29b40b5 100644 --- a/lib/mac/WindowCocoa.mm +++ b/lib/mac/WindowCocoa.mm @@ -729,7 +729,8 @@ enum }; static boo::ESpecialKey translateKeycode(short code) { - switch (code) { + switch (code) + { case kVK_F1: return boo::ESpecialKey::F1; case kVK_F2: @@ -787,14 +788,13 @@ static boo::ESpecialKey translateKeycode(short code) { if (!booContext->m_callback) return; + boo::ESpecialKey special = translateKeycode(theEvent.keyCode); NSString* chars = theEvent.characters; - if ([chars length] == 0 || - [chars characterAtIndex:0] == '\n' || - [chars characterAtIndex:0] == '\r') - booContext->m_callback->specialKeyDown(translateKeycode(theEvent.keyCode), + if (special != boo::ESpecialKey::None) + booContext->m_callback->specialKeyDown(special, getMod(theEvent.modifierFlags), theEvent.isARepeat); - else + else if ([chars length]) booContext->m_callback->charKeyDown([chars characterAtIndex:0], getMod(theEvent.modifierFlags), theEvent.isARepeat); @@ -804,11 +804,12 @@ static boo::ESpecialKey translateKeycode(short code) { if (!booContext->m_callback) return; + boo::ESpecialKey special = translateKeycode(theEvent.keyCode); NSString* chars = theEvent.characters; - if ([chars length] == 0) - booContext->m_callback->specialKeyUp(translateKeycode(theEvent.keyCode), + if (special != boo::ESpecialKey::None) + booContext->m_callback->specialKeyUp(special, getMod(theEvent.modifierFlags)); - else + else if ([chars length]) booContext->m_callback->charKeyUp([chars characterAtIndex:0], getMod(theEvent.modifierFlags)); } @@ -1074,6 +1075,9 @@ public: case EMouseCursor::VerticalArrow: [[NSCursor resizeUpDownCursor] set]; break; + case EMouseCursor::IBeam: + [[NSCursor IBeamCursor] set]; + break; default: break; } });