diff --git a/include/boo/IGraphicsContext.hpp b/include/boo/IGraphicsContext.hpp index deb7317..8d31fb2 100644 --- a/include/boo/IGraphicsContext.hpp +++ b/include/boo/IGraphicsContext.hpp @@ -58,7 +58,6 @@ public: /* Creates a new context on current thread!! Call from client loading thread */ virtual IGraphicsDataFactory* getLoadContextDataFactory()=0; - }; } diff --git a/include/boo/IWindow.hpp b/include/boo/IWindow.hpp index ad7bdf3..76bbb13 100644 --- a/include/boo/IWindow.hpp +++ b/include/boo/IWindow.hpp @@ -18,25 +18,31 @@ enum class EMouseButton Aux2 = 5 }; +struct SWindowCoord +{ + int pixel[2]; + int virtualPixel[2]; + float norm[2]; +}; + struct SWindowRect { int location[2]; int size[2]; - bool operator !=(const SWindowRect& other) const + bool operator!=(const SWindowRect& other) const { return location[0] != other.location[0] || location[1] != other.location[1] || size[0] != other.size[0] || size[1] != other.size[1]; } - bool operator ==(const SWindowRect& other) const {return !(*this != other);} -}; + bool operator==(const SWindowRect& other) const {return !(*this != other);} -struct SWindowCoord -{ - int pixel[2]; - int virtualPixel[2]; - float norm[2]; + bool coordInRect(const SWindowCoord& coord) const + { + return coord.pixel[0] >= location[0] && coord.pixel[0] < location[0] + size[0] && + coord.pixel[1] >= location[1] && coord.pixel[1] < location[1] + size[1]; + } }; struct STouchCoord @@ -246,7 +252,6 @@ public: /* Creates a new context on current thread!! Call from client loading thread */ virtual IGraphicsDataFactory* getLoadContextDataFactory()=0; - }; } diff --git a/include/boo/graphicsdev/GL.hpp b/include/boo/graphicsdev/GL.hpp index b7cf795..4a40ee5 100644 --- a/include/boo/graphicsdev/GL.hpp +++ b/include/boo/graphicsdev/GL.hpp @@ -17,9 +17,11 @@ class GLDataFactory : public IGraphicsDataFactory struct GLData* m_deferredData = nullptr; std::unordered_set m_committedData; std::vector m_texUnis; + void destroyData(IGraphicsData*); + void destroyAllData(); public: GLDataFactory(IGraphicsContext* parent); - ~GLDataFactory() {} + ~GLDataFactory() {destroyAllData();} Platform platform() const {return Platform::OGL;} const SystemChar* platformName() const {return _S("OGL");} @@ -54,9 +56,7 @@ public: size_t texCount, ITexture** texs); void reset(); - IGraphicsData* commit(); - void destroyData(IGraphicsData*); - void destroyAllData(); + IGraphicsDataToken commit(); }; } diff --git a/include/boo/graphicsdev/IGraphicsCommandQueue.hpp b/include/boo/graphicsdev/IGraphicsCommandQueue.hpp index 648c423..f36e4ba 100644 --- a/include/boo/graphicsdev/IGraphicsCommandQueue.hpp +++ b/include/boo/graphicsdev/IGraphicsCommandQueue.hpp @@ -38,6 +38,8 @@ struct IGraphicsCommandQueue virtual void resolveDisplay(ITextureR* source)=0; virtual void execute()=0; + + virtual void stopRenderer()=0; }; } diff --git a/include/boo/graphicsdev/IGraphicsDataFactory.hpp b/include/boo/graphicsdev/IGraphicsDataFactory.hpp index 916d261..ceee268 100644 --- a/include/boo/graphicsdev/IGraphicsDataFactory.hpp +++ b/include/boo/graphicsdev/IGraphicsDataFactory.hpp @@ -7,6 +7,7 @@ namespace boo { +struct IGraphicsCommandQueue; struct IGraphicsBuffer { @@ -145,12 +146,9 @@ struct IShaderPipeline {}; * as a reference */ struct IShaderDataBinding {}; -/** Opaque token for maintaining ownership of factory-created resources - * deletion of this token triggers mass-deallocation of the factory's - * resource batch. */ -struct IGraphicsData -{ -}; +/** Opaque object for maintaining ownership of factory-created resources */ +struct IGraphicsData {}; +class IGraphicsDataToken; /** Used by platform shader pipeline constructors */ enum class BlendFactor @@ -220,11 +218,55 @@ struct IGraphicsDataFactory size_t texCount, ITexture** texs)=0; virtual void reset()=0; - virtual IGraphicsData* commit()=0; + virtual IGraphicsDataToken commit()=0; + +private: + friend class IGraphicsDataToken; virtual void destroyData(IGraphicsData*)=0; virtual void destroyAllData()=0; }; +/** Opaque token for maintaining ownership of factory-created resources + * deletion of this token triggers mass-deallocation of the factory's + * IGraphicsData. */ +class IGraphicsDataToken +{ + friend class GLDataFactory; + friend class D3D12DataFactory; + friend class D3D11DataFactory; + friend class MetalDataFactory; + IGraphicsDataFactory* m_factory = nullptr; + IGraphicsData* m_data = nullptr; + IGraphicsDataToken(IGraphicsDataFactory* factory, IGraphicsData* data) + : m_factory(factory), m_data(data) {} + void doDestroy() + { + if (m_factory && m_data) + m_factory->destroyData(m_data); + } +public: + IGraphicsDataToken() = default; + IGraphicsDataToken(const IGraphicsDataToken& other) = delete; + IGraphicsDataToken(IGraphicsDataToken&& other) + { + m_factory = other.m_factory; + other.m_factory = nullptr; + m_data = other.m_data; + other.m_data = nullptr; + } + IGraphicsDataToken& operator=(const IGraphicsDataToken& other) = delete; + IGraphicsDataToken& operator=(IGraphicsDataToken&& other) + { + doDestroy(); + m_factory = other.m_factory; + other.m_factory = nullptr; + m_data = other.m_data; + other.m_data = nullptr; + return *this; + } + ~IGraphicsDataToken() {doDestroy();} +}; + } #endif // IGFXDATAFACTORY_HPP diff --git a/lib/graphicsdev/GL.cpp b/lib/graphicsdev/GL.cpp index 330c0e1..0fa791a 100644 --- a/lib/graphicsdev/GL.cpp +++ b/lib/graphicsdev/GL.cpp @@ -557,7 +557,7 @@ void GLDataFactory::reset() m_deferredData = new struct GLData(); } -IGraphicsData* GLDataFactory::commit() +IGraphicsDataToken GLDataFactory::commit() { GLData* retval = m_deferredData; m_deferredData = new struct GLData(); @@ -566,7 +566,7 @@ IGraphicsData* GLDataFactory::commit() While this isn't strictly required, some drivers might behave differently */ glFlush(); - return retval; + return IGraphicsDataToken(this, retval); } void GLDataFactory::destroyData(IGraphicsData* d) @@ -900,13 +900,18 @@ struct GLCommandQueue : IGraphicsCommandQueue m_initlk.unlock(); } - ~GLCommandQueue() + void stopRenderer() { m_running = false; m_cv.notify_one(); m_thr.join(); } + ~GLCommandQueue() + { + if (m_running) stopRenderer(); + } + void setShaderDataBinding(IShaderDataBinding* binding) { std::vector& cmds = m_cmdBufs[m_fillBuf]; diff --git a/lib/x11/ApplicationXlib.hpp b/lib/x11/ApplicationXlib.hpp index b33f34c..32a5a80 100644 --- a/lib/x11/ApplicationXlib.hpp +++ b/lib/x11/ApplicationXlib.hpp @@ -60,7 +60,7 @@ static Window GetWindowOfEvent(XEvent* event, bool& windowEvent) case ButtonRelease: { windowEvent = true; - return event->xbutton.window;; + return event->xbutton.window; } case MotionNotify: { @@ -290,7 +290,6 @@ public: XNextEvent(m_xDisp, &event); bool windowEvent; Window evWindow = GetWindowOfEvent(&event, windowEvent); - //fprintf(stderr, "EVENT %d\n", XCB_EVENT_RESPONSE_TYPE(event)); if (windowEvent) { auto window = m_windows.find(evWindow); diff --git a/lib/x11/WindowXlib.cpp b/lib/x11/WindowXlib.cpp index 1b97a12..09bceac 100644 --- a/lib/x11/WindowXlib.cpp +++ b/lib/x11/WindowXlib.cpp @@ -25,7 +25,7 @@ #include "XlibCommon.hpp" -#define REF_DPMM 3.7824 /* 96 DPI */ +#define REF_DPMM 3.78138 #define FS_ATOM "_NET_WM_STATE_FULLSCREEN" #define MWM_HINTS_FUNCTIONS (1L << 0) diff --git a/test/main.cpp b/test/main.cpp index 3e9aecd..1b9f80d 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -377,7 +377,7 @@ struct TestApplicationCallback : IApplicationCallback factory->newShaderDataBinding(pipeline, vfmt, vbo, nullptr, nullptr, 0, nullptr, 1, &texture); /* Commit objects */ - IGraphicsData* data = factory->commit(); + IGraphicsDataToken data = factory->commit(); /* Return control to client */ lk.unlock(); @@ -458,6 +458,7 @@ struct TestApplicationCallback : IApplicationCallback } } + gfxQ->stopRenderer(); m_cv.notify_one(); loaderThread.join(); return 0;