From 61fcd72a31770e6c42ea4b326e6c9f7ff52571ad Mon Sep 17 00:00:00 2001 From: hyzboy Date: Sat, 4 May 2019 16:52:44 +0800 Subject: [PATCH] =?UTF-8?q?1.win=E5=B9=B3=E5=8F=B0=E5=A2=9E=E5=8A=A0WaitMe?= =?UTF-8?q?ssage=E5=AE=9E=E7=8E=B0=E5=92=8C=E8=B0=83=E7=94=A8=202.Window?= =?UTF-8?q?=E7=B1=BB=E5=A2=9E=E5=8A=A0IsVisible=E5=87=BD=E6=95=B0=E7=94=A8?= =?UTF-8?q?=E4=BA=8E=E8=BF=94=E5=9B=9E=E5=BD=93=E5=89=8D=E6=98=AF=E5=90=A6?= =?UTF-8?q?=E9=9C=80=E8=A6=81=E6=98=BE=E7=A4=BA=203.WIndow=E7=B1=BB?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0Update=E5=87=BD=E6=95=B0=EF=BC=8C=E7=94=A8?= =?UTF-8?q?=E4=BA=8E=E5=A4=84=E7=90=86=E6=98=AF=E5=90=A6=E7=BB=98=E5=88=B6?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- example/Vulkan/VulkanAppFramework.h | 13 +++++++++++-- example/Vulkan/main.cpp | 6 ++---- inc/hgl/platform/Window.h | 8 +++++++- src/Platform/Win/WinWindow.cpp | 5 +++++ src/Platform/Win/WinWindow.h | 1 + src/Platform/Window.cpp | 12 ++++++++++++ 6 files changed, 38 insertions(+), 7 deletions(-) diff --git a/example/Vulkan/VulkanAppFramework.h b/example/Vulkan/VulkanAppFramework.h index e3934018..9e947603 100644 --- a/example/Vulkan/VulkanAppFramework.h +++ b/example/Vulkan/VulkanAppFramework.h @@ -82,9 +82,18 @@ public: device->QueuePresent(); } + virtual void Draw()=0; + bool Run() { - win->MessageProc(); - return !win->IsClose(); + if(!win->Update())return(false); + + if(win->IsVisible()) + { + AcquireNextFrame(); + Draw(); + } + + return(true); } };//class VulkanApplicationFramework diff --git a/example/Vulkan/main.cpp b/example/Vulkan/main.cpp index f7548389..8e7671ca 100644 --- a/example/Vulkan/main.cpp +++ b/example/Vulkan/main.cpp @@ -157,9 +157,8 @@ public: return(true); } - void Draw() + void Draw() override { - AcquireNextFrame(); Submit(cmd_buf[device->GetCurrentFrameIndices()]); } };//class TestApp:public VulkanApplicationFramework @@ -176,8 +175,7 @@ int main(int,char **) if(!app.Init()) return(-1); - while(app.Run()) - app.Draw(); + while(app.Run()); return 0; } diff --git a/inc/hgl/platform/Window.h b/inc/hgl/platform/Window.h index b07caa59..9201efbe 100644 --- a/inc/hgl/platform/Window.h +++ b/inc/hgl/platform/Window.h @@ -19,6 +19,11 @@ namespace hgl bool key_push[kbRangeSize]; + protected: + + virtual bool MessageProc()=0; + virtual bool WaitMessage()=0; + public: uint GetWidth()const{return width;} @@ -64,6 +69,7 @@ namespace hgl virtual void Close()=0; bool IsClose()const{return is_close;} + bool IsVisible()const{return (!is_close)&&width&&height;} virtual void SetCaption(const OSString &)=0; @@ -75,7 +81,7 @@ namespace hgl virtual void SetSystemCursor(bool){} - virtual bool MessageProc()=0; + virtual bool Update(); };//class Window Window *CreateRenderWindow(const OSString &win_name); diff --git a/src/Platform/Win/WinWindow.cpp b/src/Platform/Win/WinWindow.cpp index 2475938c..9e98121f 100644 --- a/src/Platform/Win/WinWindow.cpp +++ b/src/Platform/Win/WinWindow.cpp @@ -192,6 +192,11 @@ namespace hgl } } + bool WinWindow::WaitMessage() + { + return ::WaitMessage(); + } + Window *CreateRenderWindow(const WideString& win_name) { return(new WinWindow(win_name)); diff --git a/src/Platform/Win/WinWindow.h b/src/Platform/Win/WinWindow.h index a44656ab..05a0560d 100644 --- a/src/Platform/Win/WinWindow.h +++ b/src/Platform/Win/WinWindow.h @@ -46,5 +46,6 @@ namespace hgl void SetSystemCursor(bool visible) override; bool MessageProc() override; + bool WaitMessage() override; };//class WinWindow :public Window }//namespace win diff --git a/src/Platform/Window.cpp b/src/Platform/Window.cpp index 99a08503..ce3cf4b1 100644 --- a/src/Platform/Window.cpp +++ b/src/Platform/Window.cpp @@ -17,4 +17,16 @@ namespace hgl OnKeyUp(kb); key_push[kb]=false; } + + bool Window::Update() + { + while(MessageProc()) + { + } + + if(!active||width==0||height==0) + this->WaitMessage(); + + return(!is_close); + } }//namespace hgl