add Renderer::ResetResolutionWhenWindowResized
This commit is contained in:
parent
2285449eef
commit
1c8c92862a
|
|
@ -150,8 +150,6 @@ void Director::OnUpdate(UpdateModuleContext& ctx)
|
||||||
|
|
||||||
if (debug_actor_)
|
if (debug_actor_)
|
||||||
debug_actor_->Update(ctx.dt);
|
debug_actor_->Update(ctx.dt);
|
||||||
|
|
||||||
ctx.Next();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Director::OnRender(RenderModuleContext& ctx)
|
void Director::OnRender(RenderModuleContext& ctx)
|
||||||
|
|
@ -174,8 +172,6 @@ void Director::OnRender(RenderModuleContext& ctx)
|
||||||
{
|
{
|
||||||
debug_actor_->Render(ctx.render_ctx);
|
debug_actor_->Render(ctx.render_ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.Next();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Director::HandleEvent(EventModuleContext& ctx)
|
void Director::HandleEvent(EventModuleContext& ctx)
|
||||||
|
|
@ -188,8 +184,6 @@ void Director::HandleEvent(EventModuleContext& ctx)
|
||||||
|
|
||||||
if (debug_actor_)
|
if (debug_actor_)
|
||||||
debug_actor_->DispatchEvent(ctx.evt);
|
debug_actor_->DispatchEvent(ctx.evt);
|
||||||
|
|
||||||
ctx.Next();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace kiwano
|
} // namespace kiwano
|
||||||
|
|
|
||||||
|
|
@ -161,8 +161,6 @@ void Input::HandleEvent(EventModuleContext& ctx)
|
||||||
UpdateKey(dynamic_cast<KeyUpEvent*>(evt)->code, false);
|
UpdateKey(dynamic_cast<KeyUpEvent*>(evt)->code, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.Next();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace kiwano
|
} // namespace kiwano
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,6 @@
|
||||||
// THE SOFTWARE.
|
// THE SOFTWARE.
|
||||||
|
|
||||||
#include <kiwano/utils/Logger.h>
|
#include <kiwano/utils/Logger.h>
|
||||||
#include <kiwano/event/WindowEvent.h>
|
|
||||||
#include <kiwano/platform/FileSystem.h>
|
#include <kiwano/platform/FileSystem.h>
|
||||||
#include <kiwano/platform/Application.h>
|
#include <kiwano/platform/Application.h>
|
||||||
#include <kiwano/render/ShapeMaker.h>
|
#include <kiwano/render/ShapeMaker.h>
|
||||||
|
|
@ -131,15 +130,6 @@ void RendererImpl::Destroy()
|
||||||
::CoUninitialize();
|
::CoUninitialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RendererImpl::HandleEvent(EventModuleContext& ctx)
|
|
||||||
{
|
|
||||||
if (ctx.evt->IsType<WindowResizedEvent>())
|
|
||||||
{
|
|
||||||
auto evt = ctx.evt->SafeCast<WindowResizedEvent>();
|
|
||||||
Resize(evt->width, evt->height);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void RendererImpl::Clear()
|
void RendererImpl::Clear()
|
||||||
{
|
{
|
||||||
KGE_ASSERT(d3d_res_);
|
KGE_ASSERT(d3d_res_);
|
||||||
|
|
|
||||||
|
|
@ -81,8 +81,6 @@ public:
|
||||||
|
|
||||||
void Destroy() override;
|
void Destroy() override;
|
||||||
|
|
||||||
void HandleEvent(EventModuleContext& ctx) override;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
RendererImpl();
|
RendererImpl();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,14 +19,43 @@
|
||||||
// THE SOFTWARE.
|
// THE SOFTWARE.
|
||||||
|
|
||||||
#include <kiwano/render/Renderer.h>
|
#include <kiwano/render/Renderer.h>
|
||||||
|
#include <kiwano/event/WindowEvent.h>
|
||||||
|
|
||||||
namespace kiwano
|
namespace kiwano
|
||||||
{
|
{
|
||||||
|
|
||||||
Renderer::Renderer()
|
Renderer::Renderer()
|
||||||
: vsync_(true)
|
: vsync_(true)
|
||||||
|
, auto_reset_resolution_(false)
|
||||||
, clear_color_(Color::Black)
|
, clear_color_(Color::Black)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Renderer::SetClearColor(const Color& color)
|
||||||
|
{
|
||||||
|
clear_color_ = color;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Renderer::SetVSyncEnabled(bool enabled)
|
||||||
|
{
|
||||||
|
vsync_ = enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Renderer::ResetResolutionWhenWindowResized(bool enabled)
|
||||||
|
{
|
||||||
|
auto_reset_resolution_ = enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Renderer::HandleEvent(EventModuleContext& ctx)
|
||||||
|
{
|
||||||
|
if (auto_reset_resolution_)
|
||||||
|
{
|
||||||
|
if (ctx.evt->IsType<WindowResizedEvent>())
|
||||||
|
{
|
||||||
|
auto evt = ctx.evt->SafeCast<WindowResizedEvent>();
|
||||||
|
Resize(evt->width, evt->height);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace kiwano
|
} // namespace kiwano
|
||||||
|
|
|
||||||
|
|
@ -69,11 +69,15 @@ public:
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置清屏颜色
|
/// @brief 设置清屏颜色
|
||||||
virtual void SetClearColor(const Color& clear_color);
|
void SetClearColor(const Color& clear_color);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 开启或关闭垂直同步
|
/// @brief 开启或关闭垂直同步
|
||||||
virtual void SetVSyncEnabled(bool enabled);
|
void SetVSyncEnabled(bool enabled);
|
||||||
|
|
||||||
|
/// \~chinese
|
||||||
|
/// @brief 窗口大小变化时自动调整分辨率
|
||||||
|
void ResetResolutionWhenWindowResized(bool enabled);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 创建纹理内部资源
|
/// @brief 创建纹理内部资源
|
||||||
|
|
@ -235,11 +239,14 @@ public:
|
||||||
/// @brief 销毁渲染器资源
|
/// @brief 销毁渲染器资源
|
||||||
virtual void Destroy() = 0;
|
virtual void Destroy() = 0;
|
||||||
|
|
||||||
|
void HandleEvent(EventModuleContext& ctx) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Renderer();
|
Renderer();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool vsync_;
|
bool vsync_;
|
||||||
|
bool auto_reset_resolution_;
|
||||||
Color clear_color_;
|
Color clear_color_;
|
||||||
Size output_size_;
|
Size output_size_;
|
||||||
RenderContextPtr render_ctx_;
|
RenderContextPtr render_ctx_;
|
||||||
|
|
@ -262,14 +269,4 @@ inline Color Renderer::GetClearColor() const
|
||||||
return clear_color_;
|
return clear_color_;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void Renderer::SetVSyncEnabled(bool enabled)
|
|
||||||
{
|
|
||||||
vsync_ = enabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void Renderer::SetClearColor(const Color& color)
|
|
||||||
{
|
|
||||||
clear_color_ = color;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace kiwano
|
} // namespace kiwano
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue