diff --git a/projects/kiwano/kiwano.vcxproj b/projects/kiwano/kiwano.vcxproj
index f20b1ee3..63ae8b0c 100644
--- a/projects/kiwano/kiwano.vcxproj
+++ b/projects/kiwano/kiwano.vcxproj
@@ -83,7 +83,6 @@
-
@@ -97,7 +96,6 @@
-
@@ -159,7 +157,6 @@
-
@@ -171,7 +168,6 @@
-
diff --git a/projects/kiwano/kiwano.vcxproj.filters b/projects/kiwano/kiwano.vcxproj.filters
index cb14a7c6..cc64a0da 100644
--- a/projects/kiwano/kiwano.vcxproj.filters
+++ b/projects/kiwano/kiwano.vcxproj.filters
@@ -270,15 +270,9 @@
math
-
- render
-
render\DirectX
-
- render\DirectX
-
render\DirectX
@@ -509,15 +503,9 @@
render
-
- render
-
render\DirectX
-
- render\DirectX
-
render\DirectX
diff --git a/src/kiwano-audio/Sound.h b/src/kiwano-audio/Sound.h
index a03d63a4..f40934b5 100644
--- a/src/kiwano-audio/Sound.h
+++ b/src/kiwano-audio/Sound.h
@@ -42,7 +42,7 @@ KGE_DECLARE_SMART_PTR(Sound);
* \~chinese
* @brief 音频对象
*/
-class KGE_API Sound : public virtual ObjectBase
+class KGE_API Sound : public ObjectBase
{
friend class AudioModule;
diff --git a/src/kiwano-audio/SoundPlayer.h b/src/kiwano-audio/SoundPlayer.h
index abe296dc..a37e679b 100644
--- a/src/kiwano-audio/SoundPlayer.h
+++ b/src/kiwano-audio/SoundPlayer.h
@@ -37,7 +37,7 @@ KGE_DECLARE_SMART_PTR(SoundPlayer);
* \~chinese
* @brief 音频播放器
*/
-class KGE_API SoundPlayer : public virtual ObjectBase
+class KGE_API SoundPlayer : public ObjectBase
{
public:
/// \~chinese
diff --git a/src/kiwano-network/HttpRequest.h b/src/kiwano-network/HttpRequest.h
index e9d3f583..947e408a 100644
--- a/src/kiwano-network/HttpRequest.h
+++ b/src/kiwano-network/HttpRequest.h
@@ -51,7 +51,7 @@ enum class HttpType
* \~chinese
* @brief HTTP请求
*/
-class KGE_API HttpRequest : public virtual ObjectBase
+class KGE_API HttpRequest : public ObjectBase
{
public:
/// \~chinese
diff --git a/src/kiwano-network/HttpResponse.hpp b/src/kiwano-network/HttpResponse.hpp
index ba517ee4..55a8f5ce 100644
--- a/src/kiwano-network/HttpResponse.hpp
+++ b/src/kiwano-network/HttpResponse.hpp
@@ -36,7 +36,7 @@ KGE_DECLARE_SMART_PTR(HttpResponse);
* \~chinese
* @brief HTTP响应
*/
-class KGE_API HttpResponse : public virtual ObjectBase
+class KGE_API HttpResponse : public ObjectBase
{
public:
HttpResponse(HttpRequestPtr request);
diff --git a/src/kiwano-physics/Fixture.h b/src/kiwano-physics/Fixture.h
index ad9a0767..64c6dc0c 100644
--- a/src/kiwano-physics/Fixture.h
+++ b/src/kiwano-physics/Fixture.h
@@ -36,7 +36,7 @@ KGE_DECLARE_SMART_PTR(Fixture);
/// \~chinese
/// @brief 物理夹具
-class Fixture : public virtual ObjectBase
+class KGE_API Fixture : public ObjectBase
{
public:
/// \~chinese
diff --git a/src/kiwano-physics/Joint.h b/src/kiwano-physics/Joint.h
index 30737a5e..c39e6290 100644
--- a/src/kiwano-physics/Joint.h
+++ b/src/kiwano-physics/Joint.h
@@ -45,7 +45,7 @@ KGE_DECLARE_SMART_PTR(WheelJoint);
/// \~chinese
/// @brief 关节
-class KGE_API Joint : public virtual ObjectBase
+class KGE_API Joint : public ObjectBase
{
public:
/// \~chinese
diff --git a/src/kiwano/2d/Actor.h b/src/kiwano/2d/Actor.h
index 48bbe448..4435194c 100644
--- a/src/kiwano/2d/Actor.h
+++ b/src/kiwano/2d/Actor.h
@@ -57,7 +57,7 @@ typedef IntrusiveList ActorList;
* 角色是舞台上最基本的元素,是完成渲染、更新、事件分发等功能的最小单位,也是动画、定时器、事件监听等功能的载体
*/
class KGE_API Actor
- : public virtual ObjectBase
+ : public ObjectBase
, public TimerManager
, public ActionManager
, public EventDispatcher
diff --git a/src/kiwano/2d/Canvas.cpp b/src/kiwano/2d/Canvas.cpp
index acc77726..7bcf195a 100644
--- a/src/kiwano/2d/Canvas.cpp
+++ b/src/kiwano/2d/Canvas.cpp
@@ -20,7 +20,6 @@
#include
#include
-#include
namespace kiwano
{
@@ -32,11 +31,9 @@ CanvasPtr Canvas::Create(const Size& size)
{
try
{
- ptr->ctx_ = TextureRenderContext::Create();
ptr->stroke_brush_ = Brush::Create(Color::White);
ptr->fill_brush_ = Brush::Create(Color::White);
-
- ptr->SetSize(ptr->ctx_->GetSize());
+ ptr->ResizeAndClear(size);
}
catch (std::exception)
{
@@ -47,28 +44,24 @@ CanvasPtr Canvas::Create(const Size& size)
}
Canvas::Canvas()
- : cache_expired_(false)
{
}
void Canvas::BeginDraw()
{
- KGE_ASSERT(ctx_);
- ctx_->BeginDraw();
+ KGE_ASSERT(render_ctx_);
+ render_ctx_->BeginDraw();
}
void Canvas::EndDraw()
{
- KGE_ASSERT(ctx_);
- ctx_->EndDraw();
- cache_expired_ = true;
+ KGE_ASSERT(render_ctx_);
+ render_ctx_->EndDraw();
}
void Canvas::OnRender(RenderContext& ctx)
{
- UpdateCache();
-
- if (texture_cached_ && texture_cached_->IsValid())
+ if (texture_cached_)
{
PrepareToRender(ctx);
ctx.DrawTexture(*texture_cached_, nullptr, &GetBounds());
@@ -77,156 +70,153 @@ void Canvas::OnRender(RenderContext& ctx)
void Canvas::SetBrush(BrushPtr brush)
{
- KGE_ASSERT(ctx_);
- ctx_->SetCurrentBrush(brush);
+ KGE_ASSERT(render_ctx_);
+ render_ctx_->SetCurrentBrush(brush);
}
void Canvas::SetBrushTransform(const Transform& transform)
{
- KGE_ASSERT(ctx_);
- ctx_->SetTransform(transform.ToMatrix());
+ KGE_ASSERT(render_ctx_);
+ render_ctx_->SetTransform(transform.ToMatrix());
}
void Canvas::SetBrushTransform(const Matrix3x2& transform)
{
- KGE_ASSERT(ctx_);
- ctx_->SetTransform(transform);
+ KGE_ASSERT(render_ctx_);
+ render_ctx_->SetTransform(transform);
}
void Canvas::PushLayer(LayerPtr layer)
{
- KGE_ASSERT(ctx_);
+ KGE_ASSERT(render_ctx_);
if (layer)
{
- ctx_->PushLayer(*layer);
+ render_ctx_->PushLayer(*layer);
}
}
void Canvas::PopLayer()
{
- KGE_ASSERT(ctx_);
- ctx_->PopLayer();
+ KGE_ASSERT(render_ctx_);
+ render_ctx_->PopLayer();
}
void Canvas::PushClipRect(const Rect& clip_rect)
{
- KGE_ASSERT(ctx_);
- ctx_->PushClipRect(clip_rect);
+ KGE_ASSERT(render_ctx_);
+ render_ctx_->PushClipRect(clip_rect);
}
void Canvas::PopClipRect()
{
- KGE_ASSERT(ctx_);
- ctx_->PopClipRect();
+ KGE_ASSERT(render_ctx_);
+ render_ctx_->PopClipRect();
}
void Canvas::DrawShape(ShapePtr shape)
{
- KGE_ASSERT(ctx_);
+ KGE_ASSERT(render_ctx_);
if (shape)
{
- ctx_->SetCurrentBrush(stroke_brush_);
- ctx_->SetCurrentStrokeStyle(stroke_style_);
- ctx_->DrawShape(*shape);
- cache_expired_ = true;
+ render_ctx_->SetCurrentBrush(stroke_brush_);
+ render_ctx_->SetCurrentStrokeStyle(stroke_style_);
+ render_ctx_->DrawShape(*shape);
}
}
void Canvas::DrawLine(const Point& begin, const Point& end)
{
- KGE_ASSERT(ctx_);
- ctx_->SetCurrentBrush(stroke_brush_);
- ctx_->SetCurrentStrokeStyle(stroke_style_);
- ctx_->DrawLine(begin, end);
- cache_expired_ = true;
+ KGE_ASSERT(render_ctx_);
+ render_ctx_->SetCurrentBrush(stroke_brush_);
+ render_ctx_->SetCurrentStrokeStyle(stroke_style_);
+ render_ctx_->DrawLine(begin, end);
}
void Canvas::DrawCircle(const Point& center, float radius)
{
- KGE_ASSERT(ctx_);
- ctx_->SetCurrentBrush(stroke_brush_);
- ctx_->SetCurrentStrokeStyle(stroke_style_);
- ctx_->DrawEllipse(center, Vec2(radius, radius));
- cache_expired_ = true;
+ KGE_ASSERT(render_ctx_);
+ render_ctx_->SetCurrentBrush(stroke_brush_);
+ render_ctx_->SetCurrentStrokeStyle(stroke_style_);
+ render_ctx_->DrawEllipse(center, Vec2(radius, radius));
}
void Canvas::DrawEllipse(const Point& center, const Vec2& radius)
{
- KGE_ASSERT(ctx_);
- ctx_->SetCurrentBrush(stroke_brush_);
- ctx_->SetCurrentStrokeStyle(stroke_style_);
- ctx_->DrawEllipse(center, radius);
- cache_expired_ = true;
+ KGE_ASSERT(render_ctx_);
+ render_ctx_->SetCurrentBrush(stroke_brush_);
+ render_ctx_->SetCurrentStrokeStyle(stroke_style_);
+ render_ctx_->DrawEllipse(center, radius);
}
void Canvas::DrawRect(const Rect& rect)
{
- KGE_ASSERT(ctx_);
- ctx_->SetCurrentBrush(stroke_brush_);
- ctx_->SetCurrentStrokeStyle(stroke_style_);
- ctx_->DrawRectangle(rect);
- cache_expired_ = true;
+ KGE_ASSERT(render_ctx_);
+ render_ctx_->SetCurrentBrush(stroke_brush_);
+ render_ctx_->SetCurrentStrokeStyle(stroke_style_);
+ render_ctx_->DrawRectangle(rect);
}
void Canvas::DrawRoundedRect(const Rect& rect, const Vec2& radius)
{
- KGE_ASSERT(ctx_);
- ctx_->SetCurrentBrush(stroke_brush_);
- ctx_->SetCurrentStrokeStyle(stroke_style_);
- ctx_->DrawRoundedRectangle(rect, radius);
- cache_expired_ = true;
+ KGE_ASSERT(render_ctx_);
+ render_ctx_->SetCurrentBrush(stroke_brush_);
+ render_ctx_->SetCurrentStrokeStyle(stroke_style_);
+ render_ctx_->DrawRoundedRectangle(rect, radius);
}
void Canvas::FillShape(ShapePtr shape)
{
- KGE_ASSERT(ctx_);
+ KGE_ASSERT(render_ctx_);
if (shape)
{
- ctx_->SetCurrentBrush(fill_brush_);
- ctx_->FillShape(*shape);
- cache_expired_ = true;
+ render_ctx_->SetCurrentBrush(fill_brush_);
+ render_ctx_->FillShape(*shape);
}
}
void Canvas::FillCircle(const Point& center, float radius)
{
- KGE_ASSERT(ctx_);
- ctx_->SetCurrentBrush(fill_brush_);
- ctx_->FillEllipse(center, Vec2(radius, radius));
- cache_expired_ = true;
+ KGE_ASSERT(render_ctx_);
+ render_ctx_->SetCurrentBrush(fill_brush_);
+ render_ctx_->FillEllipse(center, Vec2(radius, radius));
}
void Canvas::FillEllipse(const Point& center, const Vec2& radius)
{
- KGE_ASSERT(ctx_);
- ctx_->SetCurrentBrush(fill_brush_);
- ctx_->FillEllipse(center, radius);
- cache_expired_ = true;
+ KGE_ASSERT(render_ctx_);
+ render_ctx_->SetCurrentBrush(fill_brush_);
+ render_ctx_->FillEllipse(center, radius);
}
void Canvas::FillRect(const Rect& rect)
{
- KGE_ASSERT(ctx_);
- ctx_->SetCurrentBrush(fill_brush_);
- ctx_->FillRectangle(rect);
- cache_expired_ = true;
+ KGE_ASSERT(render_ctx_);
+ render_ctx_->SetCurrentBrush(fill_brush_);
+ render_ctx_->FillRectangle(rect);
}
void Canvas::FillRoundedRect(const Rect& rect, const Vec2& radius)
{
- KGE_ASSERT(ctx_);
- ctx_->SetCurrentBrush(fill_brush_);
- ctx_->FillRoundedRectangle(rect, radius);
- cache_expired_ = true;
+ KGE_ASSERT(render_ctx_);
+ render_ctx_->SetCurrentBrush(fill_brush_);
+ render_ctx_->FillRoundedRectangle(rect, radius);
}
-void Canvas::DrawTexture(TexturePtr texture, const Rect* src_rect, const Rect* dest_rect)
+void Canvas::DrawFrame(FramePtr frame, const Point& pos)
{
- KGE_ASSERT(ctx_);
- if (texture)
+ KGE_ASSERT(render_ctx_);
+ if (frame && frame->IsValid())
{
- ctx_->DrawTexture(*texture, src_rect, dest_rect);
- cache_expired_ = true;
+ render_ctx_->DrawTexture(*frame->GetTexture(), &frame->GetCropRect(), &Rect(pos, frame->GetSize()));
+ }
+}
+
+void Canvas::DrawFrame(FramePtr frame, const Point& pos, const Size& size)
+{
+ KGE_ASSERT(render_ctx_);
+ if (frame && frame->IsValid())
+ {
+ render_ctx_->DrawTexture(*frame->GetTexture(), &frame->GetCropRect(), &Rect(pos, size));
}
}
@@ -240,11 +230,10 @@ void Canvas::DrawTextLayout(const String& text, const TextStyle& style, const Po
void Canvas::DrawTextLayout(TextLayoutPtr layout, const Point& point)
{
- KGE_ASSERT(ctx_);
+ KGE_ASSERT(render_ctx_);
if (layout)
{
- ctx_->DrawTextLayout(*layout, point);
- cache_expired_ = true;
+ render_ctx_->DrawTextLayout(*layout, point);
}
}
@@ -280,60 +269,42 @@ void Canvas::AddArc(const Point& point, const Size& radius, float rotation, bool
void Canvas::StrokePath()
{
- KGE_ASSERT(ctx_);
- ctx_->SetCurrentBrush(stroke_brush_);
- ctx_->SetCurrentStrokeStyle(stroke_style_);
- ctx_->DrawShape(*shape_maker_.GetShape());
- cache_expired_ = true;
+ KGE_ASSERT(render_ctx_);
+ render_ctx_->SetCurrentBrush(stroke_brush_);
+ render_ctx_->SetCurrentStrokeStyle(stroke_style_);
+ render_ctx_->DrawShape(*shape_maker_.GetShape());
}
void Canvas::FillPath()
{
- KGE_ASSERT(ctx_);
- ctx_->SetCurrentBrush(fill_brush_);
- ctx_->FillShape(*shape_maker_.GetShape());
- cache_expired_ = true;
+ KGE_ASSERT(render_ctx_);
+ render_ctx_->SetCurrentBrush(fill_brush_);
+ render_ctx_->FillShape(*shape_maker_.GetShape());
}
void Canvas::Clear()
{
- KGE_ASSERT(ctx_);
- ctx_->Clear();
- cache_expired_ = true;
+ KGE_ASSERT(render_ctx_);
+ render_ctx_->Clear();
}
void Canvas::Clear(const Color& clear_color)
{
- KGE_ASSERT(ctx_);
- ctx_->Clear(clear_color);
- cache_expired_ = true;
+ KGE_ASSERT(render_ctx_);
+ render_ctx_->Clear(clear_color);
}
void Canvas::ResizeAndClear(Size size)
{
- ctx_ = TextureRenderContext::Create(size);
+ texture_cached_ = new Texture;
+ render_ctx_ = RenderContext::Create(*texture_cached_, size);
+
+ SetSize(render_ctx_->GetSize());
}
TexturePtr Canvas::ExportToTexture() const
{
- UpdateCache();
return texture_cached_;
}
-void Canvas::UpdateCache() const
-{
- if (cache_expired_ && ctx_)
- {
- if (!texture_cached_)
- {
- texture_cached_ = new Texture;
- }
-
- if (ctx_->GetOutput(*texture_cached_))
- {
- cache_expired_ = false;
- }
- }
-}
-
} // namespace kiwano
diff --git a/src/kiwano/2d/Canvas.h b/src/kiwano/2d/Canvas.h
index f32f99df..0d80968f 100644
--- a/src/kiwano/2d/Canvas.h
+++ b/src/kiwano/2d/Canvas.h
@@ -20,8 +20,9 @@
#pragma once
#include
+#include
#include
-#include
+#include
namespace kiwano
{
@@ -117,11 +118,17 @@ public:
void FillRoundedRect(const Rect& rect, const Vec2& radius);
/// \~chinese
- /// @brief 绘制纹理
- /// @param texture 纹理
- /// @param src_rect 纹理裁剪区域
- /// @param dest_rect 绘制目标区域
- void DrawTexture(TexturePtr texture, const Rect* src_rect = nullptr, const Rect* dest_rect = nullptr);
+ /// @brief 绘制图像帧
+ /// @param frame 图像帧
+ /// @param pos 绘制图像的位置
+ void DrawFrame(FramePtr frame, const Point& pos);
+
+ /// \~chinese
+ /// @brief 绘制图像帧
+ /// @param frame 图像帧
+ /// @param pos 绘制图像的位置
+ /// @param size 渲染的图像大小
+ void DrawFrame(FramePtr frame, const Point& pos, const Size& size);
/// \~chinese
/// @brief 绘制文字布局
@@ -268,17 +275,13 @@ public:
private:
Canvas();
- void UpdateCache() const;
-
private:
- StrokeStylePtr stroke_style_;
- ShapeMaker shape_maker_;
- BrushPtr fill_brush_;
- BrushPtr stroke_brush_;
-
- mutable bool cache_expired_;
- mutable TexturePtr texture_cached_;
- mutable TextureRenderContextPtr ctx_;
+ StrokeStylePtr stroke_style_;
+ ShapeMaker shape_maker_;
+ BrushPtr fill_brush_;
+ BrushPtr stroke_brush_;
+ TexturePtr texture_cached_;
+ RenderContextPtr render_ctx_;
};
/** @} */
diff --git a/src/kiwano/2d/Component.h b/src/kiwano/2d/Component.h
index 3fb2f6b0..60c35e64 100644
--- a/src/kiwano/2d/Component.h
+++ b/src/kiwano/2d/Component.h
@@ -40,7 +40,7 @@ typedef IntrusiveList ComponentList;
* @brief 组件
*/
class KGE_API Component
- : public virtual ObjectBase
+ : public ObjectBase
, protected IntrusiveListValue
{
friend class Actor;
diff --git a/src/kiwano/2d/Frame.h b/src/kiwano/2d/Frame.h
index 01dc2f40..63b28771 100644
--- a/src/kiwano/2d/Frame.h
+++ b/src/kiwano/2d/Frame.h
@@ -30,7 +30,7 @@ KGE_DECLARE_SMART_PTR(Frame);
* \~chinese
* @brief 图像帧
*/
-class KGE_API Frame : public virtual ObjectBase
+class KGE_API Frame : public ObjectBase
{
public:
/// \~chinese
diff --git a/src/kiwano/2d/FrameSequence.h b/src/kiwano/2d/FrameSequence.h
index 71e0693a..f45c42a5 100644
--- a/src/kiwano/2d/FrameSequence.h
+++ b/src/kiwano/2d/FrameSequence.h
@@ -31,7 +31,7 @@ KGE_DECLARE_SMART_PTR(FrameSequence);
* \~chinese
* @brief 序列帧
*/
-class KGE_API FrameSequence : public virtual ObjectBase
+class KGE_API FrameSequence : public ObjectBase
{
public:
/// \~chinese
diff --git a/src/kiwano/2d/GifSprite.cpp b/src/kiwano/2d/GifSprite.cpp
index 93674629..10c85431 100644
--- a/src/kiwano/2d/GifSprite.cpp
+++ b/src/kiwano/2d/GifSprite.cpp
@@ -87,11 +87,13 @@ bool GifSprite::Load(GifImagePtr gif)
loop_count_ = 0;
frame_ = GifImage::Frame();
- if (!frame_rt_)
- {
- Size frame_size = Size(float(gif_->GetWidthInPixels()), float(gif_->GetHeightInPixels()));
- frame_rt_ = TextureRenderContext::Create(frame_size);
- }
+ saved_frame_.Reset();
+ frame_to_render_.Reset();
+ frame_rt_.Reset();
+
+ Size frame_size = Size(float(gif_->GetWidthInPixels()), float(gif_->GetHeightInPixels()));
+ frame_to_render_ = new Texture;
+ frame_rt_ = RenderContext::Create(*frame_to_render_, frame_size);
SetSize(frame_rt_->GetSize());
@@ -149,7 +151,7 @@ void GifSprite::ComposeNextFrame()
KGE_ASSERT(frame_rt_);
KGE_ASSERT(gif_);
- if (frame_rt_->IsValid())
+ if (frame_rt_)
{
do
{
@@ -191,7 +193,7 @@ void GifSprite::OverlayNextFrame()
SaveComposedFrame();
}
- if (frame_rt_->IsValid())
+ if (frame_rt_)
{
frame_rt_->BeginDraw();
@@ -208,15 +210,7 @@ void GifSprite::OverlayNextFrame()
frame_rt_->EndDraw();
- if (!frame_to_render_)
- {
- frame_to_render_ = new Texture;
- }
-
- if (frame_rt_->GetOutput(*frame_to_render_))
- {
- next_index_ = (++next_index_) % gif_->GetFramesCount();
- }
+ next_index_ = (++next_index_) % gif_->GetFramesCount();
}
// Execute callback
@@ -235,18 +229,12 @@ void GifSprite::SaveComposedFrame()
{
KGE_ASSERT(frame_rt_);
- TexturePtr frame_to_be_saved = new Texture;
-
- if (frame_rt_->GetOutput(*frame_to_be_saved))
+ if (!saved_frame_)
{
- if (!saved_frame_)
- {
- saved_frame_ = new Texture;
- frame_rt_->CreateTexture(*saved_frame_, frame_to_be_saved->GetSizeInPixels());
- }
-
- saved_frame_->CopyFrom(frame_to_be_saved);
+ saved_frame_ = new Texture;
+ frame_rt_->CreateTexture(*saved_frame_, frame_to_render_->GetSizeInPixels());
}
+ saved_frame_->CopyFrom(frame_to_render_);
}
void GifSprite::RestoreSavedFrame()
@@ -255,12 +243,7 @@ void GifSprite::RestoreSavedFrame()
if (saved_frame_)
{
- TexturePtr frame_to_copy_to = new Texture;
-
- if (frame_rt_->GetOutput(*frame_to_copy_to))
- {
- frame_to_copy_to->CopyFrom(saved_frame_);
- }
+ frame_to_render_->CopyFrom(saved_frame_);
}
}
diff --git a/src/kiwano/2d/GifSprite.h b/src/kiwano/2d/GifSprite.h
index f0dca3cc..47d1647a 100644
--- a/src/kiwano/2d/GifSprite.h
+++ b/src/kiwano/2d/GifSprite.h
@@ -22,7 +22,7 @@
#include
#include
#include
-#include
+#include
namespace kiwano
{
@@ -150,18 +150,18 @@ private:
void ClearCurrentFrameArea();
private:
- bool animating_;
- int total_loop_count_;
- int loop_count_;
- size_t next_index_;
- Duration frame_elapsed_;
- LoopDoneCallback loop_cb_;
- DoneCallback done_cb_;
- GifImagePtr gif_;
- GifImage::Frame frame_;
- TexturePtr saved_frame_;
- TexturePtr frame_to_render_;
- TextureRenderContextPtr frame_rt_;
+ bool animating_;
+ int total_loop_count_;
+ int loop_count_;
+ size_t next_index_;
+ Duration frame_elapsed_;
+ LoopDoneCallback loop_cb_;
+ DoneCallback done_cb_;
+ GifImagePtr gif_;
+ GifImage::Frame frame_;
+ TexturePtr saved_frame_;
+ TexturePtr frame_to_render_;
+ RenderContextPtr frame_rt_;
};
/** @} */
diff --git a/src/kiwano/2d/Sprite.cpp b/src/kiwano/2d/Sprite.cpp
index 7d6f69b1..c0f754a0 100644
--- a/src/kiwano/2d/Sprite.cpp
+++ b/src/kiwano/2d/Sprite.cpp
@@ -160,7 +160,10 @@ void Sprite::SetFrame(FramePtr frame, bool autoresize)
void Sprite::OnRender(RenderContext& ctx)
{
- ctx.DrawTexture(*frame_->GetTexture(), &frame_->GetCropRect(), &GetBounds());
+ if (frame_ && frame_->IsValid())
+ {
+ ctx.DrawTexture(*frame_->GetTexture(), &frame_->GetCropRect(), &GetBounds());
+ }
}
bool Sprite::CheckVisibility(RenderContext& ctx) const
diff --git a/src/kiwano/2d/Transition.h b/src/kiwano/2d/Transition.h
index 7ab74b45..94e614e5 100644
--- a/src/kiwano/2d/Transition.h
+++ b/src/kiwano/2d/Transition.h
@@ -38,7 +38,7 @@ KGE_DECLARE_SMART_PTR(RotationTransition);
* \~chinese
* @brief 舞台过渡动画
*/
-class KGE_API Transition : public virtual ObjectBase
+class KGE_API Transition : public ObjectBase
{
friend class Director;
diff --git a/src/kiwano/2d/action/Action.h b/src/kiwano/2d/action/Action.h
index 3e92b903..14540185 100644
--- a/src/kiwano/2d/action/Action.h
+++ b/src/kiwano/2d/action/Action.h
@@ -50,7 +50,7 @@ typedef IntrusiveList ActionList;
/// \~chinese
/// @brief 动画
class KGE_API Action
- : public virtual ObjectBase
+ : public ObjectBase
, protected IntrusiveListValue
{
friend class ActionManager;
diff --git a/src/kiwano/core/AsyncTask.h b/src/kiwano/core/AsyncTask.h
index 35c7528a..fb10688b 100644
--- a/src/kiwano/core/AsyncTask.h
+++ b/src/kiwano/core/AsyncTask.h
@@ -38,7 +38,7 @@ typedef Function AsyncTaskCallback;
/// task->Then(DoSomething);
/// task->Start();
/// @endcode
-class AsyncTask : public virtual ObjectBase
+class KGE_API AsyncTask : public ObjectBase
{
public:
/// \~chinese
diff --git a/src/kiwano/core/EventListener.h b/src/kiwano/core/EventListener.h
index a7fe75fb..18d9894d 100644
--- a/src/kiwano/core/EventListener.h
+++ b/src/kiwano/core/EventListener.h
@@ -43,7 +43,7 @@ typedef IntrusiveList ListenerList;
* @brief 事件监听器
*/
class KGE_API EventListener
- : public virtual ObjectBase
+ : public ObjectBase
, protected IntrusiveListValue
{
friend class EventDispatcher;
diff --git a/src/kiwano/core/Exception.cpp b/src/kiwano/core/Exception.cpp
index f01111f9..5b64baef 100644
--- a/src/kiwano/core/Exception.cpp
+++ b/src/kiwano/core/Exception.cpp
@@ -28,6 +28,24 @@
namespace kiwano
{
+// wide-to-ANSI string conversion helper
+namespace detail
+{
+inline std::unique_ptr to_narrow(BSTR msg)
+{
+ return std::unique_ptr(_com_util::ConvertBSTRToString(msg));
+}
+
+inline std::unique_ptr to_narrow(const wchar_t* msg)
+{
+ static_assert(std::is_same::value, "BSTR must be wchar_t*");
+ // const_cast is fine:
+ // BSTR is a wchar_t*;
+ // ConvertBSTRToString internally uses _wcslen and WideCharToMultiByte;
+ return to_narrow(const_cast(msg));
+}
+}
+
class com_error_category : public std::error_category
{
public:
@@ -38,16 +56,12 @@ public:
return "com";
}
- // @note If _UNICODE is defined the error description gets
- // converted to an ANSI string using the CP_ACP codepage.
std::string message(int hr) const override
{
- return string::ToNarrow(_com_error{ hr }.ErrorMessage());
+ auto narrow = detail::to_narrow(_com_error{ hr }.ErrorMessage());
+ return narrow.get();
}
- // Make error_condition for error code (generic if possible)
- // @return system's default error condition if error value can be mapped to a Windows error, error condition with
- // com category otherwise
std::error_condition default_error_condition(int hr) const noexcept override
{
if (HRESULT_CODE(hr) || hr == 0)
diff --git a/src/kiwano/core/Timer.h b/src/kiwano/core/Timer.h
index 18394d22..0c3a6109 100644
--- a/src/kiwano/core/Timer.h
+++ b/src/kiwano/core/Timer.h
@@ -37,7 +37,7 @@ typedef IntrusiveList TimerList;
/// @brief 定时器
/// @details 定时器用于每隔一段时间执行一次回调函数,且可以指定执行总次数
class KGE_API Timer
- : public virtual ObjectBase
+ : public ObjectBase
, protected IntrusiveListValue
{
friend class TimerManager;
diff --git a/src/kiwano/platform/Runner.h b/src/kiwano/platform/Runner.h
index 6b22016f..a8f49f90 100644
--- a/src/kiwano/platform/Runner.h
+++ b/src/kiwano/platform/Runner.h
@@ -34,7 +34,7 @@ KGE_DECLARE_SMART_PTR(Runner);
* \~chinese
* @brief 程序运行器
*/
-class KGE_API Runner : public virtual ObjectBase
+class KGE_API Runner : public ObjectBase
{
friend class Application;
diff --git a/src/kiwano/render/DirectX/RenderContextImpl.cpp b/src/kiwano/render/DirectX/RenderContextImpl.cpp
index 187f744e..cbf90978 100644
--- a/src/kiwano/render/DirectX/RenderContextImpl.cpp
+++ b/src/kiwano/render/DirectX/RenderContextImpl.cpp
@@ -33,12 +33,12 @@ RenderContextImpl::~RenderContextImpl()
DiscardDeviceResources();
}
-HRESULT RenderContextImpl::CreateDeviceResources(ComPtr factory, ComPtr ctx)
+HRESULT RenderContextImpl::CreateDeviceResources(ComPtr factory, ComPtr render_target)
{
- if (!factory || !ctx)
+ if (!factory || !render_target)
return E_INVALIDARG;
- render_target_ = ctx;
+ render_target_ = render_target;
text_renderer_.Reset();
current_brush_.Reset();
@@ -49,7 +49,7 @@ HRESULT RenderContextImpl::CreateDeviceResources(ComPtr factory, C
SetAntialiasMode(antialias_);
SetTextAntialiasMode(text_antialias_);
- Resize(reinterpret_cast(ctx->GetSize()));
+ Resize(reinterpret_cast(render_target->GetSize()));
}
// DrawingStateBlock
@@ -58,6 +58,10 @@ HRESULT RenderContextImpl::CreateDeviceResources(ComPtr factory, C
hr = factory->CreateDrawingStateBlock(&drawing_state_);
}
+ if (SUCCEEDED(hr))
+ {
+ NativePtr::Set(this, render_target);
+ }
return hr;
}
@@ -66,11 +70,8 @@ void RenderContextImpl::DiscardDeviceResources()
text_renderer_.Reset();
render_target_.Reset();
current_brush_.Reset();
-}
-bool RenderContextImpl::IsValid() const
-{
- return render_target_ != nullptr;
+ ResetNativePointer();
}
void RenderContextImpl::BeginDraw()
diff --git a/src/kiwano/render/DirectX/RenderContextImpl.h b/src/kiwano/render/DirectX/RenderContextImpl.h
index 14abc9fa..d10f3ca0 100644
--- a/src/kiwano/render/DirectX/RenderContextImpl.h
+++ b/src/kiwano/render/DirectX/RenderContextImpl.h
@@ -25,16 +25,16 @@
namespace kiwano
{
-class RendererImpl;
-
KGE_DECLARE_SMART_PTR(RenderContextImpl);
-class KGE_API RenderContextImpl : public virtual RenderContext
+class KGE_API RenderContextImpl : public RenderContext
{
- friend class RendererImpl;
-
public:
- bool IsValid() const override;
+ RenderContextImpl();
+
+ virtual ~RenderContextImpl();
+
+ HRESULT CreateDeviceResources(ComPtr factory, ComPtr render_target);
void BeginDraw() override;
@@ -92,20 +92,14 @@ public:
void Resize(const Size& size) override;
-protected:
- RenderContextImpl();
-
- virtual ~RenderContextImpl();
-
- HRESULT CreateDeviceResources(ComPtr factory, ComPtr ctx);
-
+private:
void DiscardDeviceResources();
void SaveDrawingState();
void RestoreDrawingState();
-protected:
+private:
ComPtr text_renderer_;
ComPtr render_target_;
ComPtr drawing_state_;
diff --git a/src/kiwano/render/DirectX/RendererImpl.cpp b/src/kiwano/render/DirectX/RendererImpl.cpp
index 8330c955..e23fe32c 100644
--- a/src/kiwano/render/DirectX/RendererImpl.cpp
+++ b/src/kiwano/render/DirectX/RendererImpl.cpp
@@ -24,7 +24,6 @@
#include
#include
#include
-#include
#include
#include
@@ -44,7 +43,6 @@ RendererImpl& RendererImpl::GetInstance()
RendererImpl::RendererImpl()
{
- render_ctx_ = new RenderContextImpl;
}
void RendererImpl::MakeContextForWindow(WindowPtr window)
@@ -74,7 +72,13 @@ void RendererImpl::MakeContextForWindow(WindowPtr window)
// Other device resources
if (SUCCEEDED(hr))
{
- hr = render_ctx_->CreateDeviceResources(d2d_res_->GetFactory(), d2d_res_->GetDeviceContext());
+ RenderContextImplPtr ctx = new RenderContextImpl;
+
+ hr = ctx->CreateDeviceResources(d2d_res_->GetFactory(), d2d_res_->GetDeviceContext());
+ if (SUCCEEDED(hr))
+ {
+ render_ctx_ = ctx;
+ }
}
// FontFileLoader and FontCollectionLoader
@@ -133,20 +137,6 @@ void RendererImpl::Destroy()
::CoUninitialize();
}
-void RendererImpl::BeginDraw()
-{
- KGE_ASSERT(render_ctx_);
-
- render_ctx_->BeginDraw();
-}
-
-void RendererImpl::EndDraw()
-{
- KGE_ASSERT(render_ctx_);
-
- render_ctx_->EndDraw();
-}
-
void RendererImpl::Clear()
{
KGE_ASSERT(d3d_res_);
@@ -159,34 +149,9 @@ void RendererImpl::Present()
KGE_ASSERT(d3d_res_);
HRESULT hr = d3d_res_->Present(vsync_);
-
- if (hr == DXGI_ERROR_DEVICE_REMOVED || hr == DXGI_ERROR_DEVICE_RESET)
- {
- // 如果 Direct3D 设备在执行过程中消失,将丢弃当前的设备相关资源
- hr = HandleDeviceLost();
- }
-
KGE_THROW_IF_FAILED(hr, "Unexpected DXGI exception");
}
-HRESULT RendererImpl::HandleDeviceLost()
-{
- KGE_ASSERT(d3d_res_ && d2d_res_ && render_ctx_);
-
- HRESULT hr = d3d_res_->HandleDeviceLost();
-
- if (SUCCEEDED(hr))
- {
- hr = d2d_res_->HandleDeviceLost(d3d_res_->GetDXGIDevice(), d3d_res_->GetDXGISwapChain());
- }
-
- if (SUCCEEDED(hr))
- {
- hr = render_ctx_->CreateDeviceResources(d2d_res_->GetFactory(), d2d_res_->GetDeviceContext());
- }
- return hr;
-}
-
void RendererImpl::CreateTexture(Texture& texture, const String& file_path)
{
HRESULT hr = S_OK;
@@ -937,9 +902,9 @@ void RendererImpl::CreateStrokeStyle(StrokeStyle& stroke_style)
KGE_THROW_IF_FAILED(hr, "Create ID2D1StrokeStyle failed");
}
-TextureRenderContextPtr RendererImpl::CreateTextureRenderContext(const Size* desired_size)
+RenderContextPtr RendererImpl::CreateTextureRenderContext(Texture& texture, const Size* desired_size)
{
- TextureRenderContextImplPtr ptr = new TextureRenderContextImpl;
+ RenderContextImplPtr ptr = new RenderContextImpl;
HRESULT hr = S_OK;
if (!d2d_res_)
@@ -968,13 +933,17 @@ TextureRenderContextPtr RendererImpl::CreateTextureRenderContext(const Size* des
if (SUCCEEDED(hr))
{
- ptr->bitmap_rt_ = bitmap_rt;
+ ComPtr output;
+ hr = bitmap_rt->GetBitmap(&output);
+ if (SUCCEEDED(hr))
+ {
+ NativePtr::Set(texture, output);
+ }
}
}
if (SUCCEEDED(hr))
return ptr;
-
return nullptr;
}
diff --git a/src/kiwano/render/DirectX/RendererImpl.h b/src/kiwano/render/DirectX/RendererImpl.h
index 1f0e1dda..6df1ce21 100644
--- a/src/kiwano/render/DirectX/RendererImpl.h
+++ b/src/kiwano/render/DirectX/RendererImpl.h
@@ -80,19 +80,13 @@ public:
void CreateStrokeStyle(StrokeStyle& stroke_style) override;
- TextureRenderContextPtr CreateTextureRenderContext(const Size* desired_size = nullptr) override;
+ RenderContextPtr CreateTextureRenderContext(Texture& texture, const Size* desired_size = nullptr) override;
public:
- void BeginDraw() override;
-
- void EndDraw() override;
-
void Clear() override;
void Present() override;
- RenderContext& GetContext() override;
-
/// \~chinese
/// @brief 获取Direct2D设备资源
ID2DDeviceResources* GetD2DDeviceResources();
@@ -112,10 +106,7 @@ protected:
void Destroy() override;
- HRESULT HandleDeviceLost();
-
private:
- RenderContextImplPtr render_ctx_;
ComPtr d2d_res_;
ComPtr d3d_res_;
ComPtr font_collection_loader_;
@@ -125,11 +116,6 @@ private:
/** @} */
-inline RenderContext& RendererImpl::GetContext()
-{
- return *render_ctx_;
-}
-
inline ID2DDeviceResources* RendererImpl::GetD2DDeviceResources()
{
KGE_ASSERT(d2d_res_);
diff --git a/src/kiwano/render/DirectX/TextureRenderContextImpl.cpp b/src/kiwano/render/DirectX/TextureRenderContextImpl.cpp
deleted file mode 100644
index 171a06ff..00000000
--- a/src/kiwano/render/DirectX/TextureRenderContextImpl.cpp
+++ /dev/null
@@ -1,50 +0,0 @@
-// Copyright (c) 2016-2019 Kiwano - Nomango
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy
-// of this software and associated documentation files (the "Software"), to deal
-// in the Software without restriction, including without limitation the rights
-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the Software is
-// furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-// THE SOFTWARE.
-
-#include
-#include
-#include
-#include
-
-namespace kiwano
-{
-
-bool TextureRenderContextImpl::GetOutput(Texture& texture)
-{
- HRESULT hr = E_FAIL;
-
- if (bitmap_rt_)
- {
- ComPtr bitmap;
-
- hr = bitmap_rt_->GetBitmap(&bitmap);
-
- if (SUCCEEDED(hr))
- {
- NativePtr::Set(texture, bitmap);
-
- texture.SetSize({ bitmap->GetSize().width, bitmap->GetSize().height });
- texture.SetSizeInPixels({ bitmap->GetPixelSize().width, bitmap->GetPixelSize().height });
- }
- }
- return SUCCEEDED(hr);
-}
-
-} // namespace kiwano
diff --git a/src/kiwano/render/DirectX/TextureRenderContextImpl.h b/src/kiwano/render/DirectX/TextureRenderContextImpl.h
deleted file mode 100644
index b8274f13..00000000
--- a/src/kiwano/render/DirectX/TextureRenderContextImpl.h
+++ /dev/null
@@ -1,104 +0,0 @@
-// Copyright (c) 2016-2019 Kiwano - Nomango
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy
-// of this software and associated documentation files (the "Software"), to deal
-// in the Software without restriction, including without limitation the rights
-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the Software is
-// furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-// THE SOFTWARE.
-
-#pragma once
-#include
-#include
-
-namespace kiwano
-{
-
-class RendererImpl;
-
-KGE_DECLARE_SMART_PTR(TextureRenderContextImpl);
-
-KGE_SUPPRESS_WARNING_PUSH
-KGE_SUPPRESS_WARNING(4250) // inherits via domainance
-
-class KGE_API TextureRenderContextImpl
- : public RenderContextImpl
- , public TextureRenderContext
-{
- friend class RendererImpl;
-
-public:
- bool GetOutput(Texture& texture) override;
-
- using RenderContextImpl::IsValid;
-
- using RenderContextImpl::BeginDraw;
-
- using RenderContextImpl::EndDraw;
-
- using RenderContextImpl::DrawTexture;
-
- using RenderContextImpl::DrawTextLayout;
-
- using RenderContextImpl::DrawShape;
-
- using RenderContextImpl::DrawLine;
-
- using RenderContextImpl::DrawRectangle;
-
- using RenderContextImpl::DrawRoundedRectangle;
-
- using RenderContextImpl::DrawEllipse;
-
- using RenderContextImpl::FillShape;
-
- using RenderContextImpl::FillRectangle;
-
- using RenderContextImpl::FillRoundedRectangle;
-
- using RenderContextImpl::FillEllipse;
-
- using RenderContextImpl::CreateTexture;
-
- using RenderContextImpl::PushClipRect;
-
- using RenderContextImpl::PopClipRect;
-
- using RenderContextImpl::PushLayer;
-
- using RenderContextImpl::PopLayer;
-
- using RenderContextImpl::Clear;
-
- using RenderContextImpl::GetSize;
-
- using RenderContextImpl::SetCurrentBrush;
-
- using RenderContextImpl::SetTransform;
-
- using RenderContextImpl::SetAntialiasMode;
-
- using RenderContextImpl::SetTextAntialiasMode;
-
- using RenderContextImpl::CheckVisibility;
-
- using RenderContextImpl::Resize;
-
-private:
- ComPtr bitmap_rt_;
-};
-
-KGE_SUPPRESS_WARNING_POP
-
-} // namespace kiwano
diff --git a/src/kiwano/render/NativeObject.h b/src/kiwano/render/NativeObject.h
index 67e54fd5..855e6545 100644
--- a/src/kiwano/render/NativeObject.h
+++ b/src/kiwano/render/NativeObject.h
@@ -39,7 +39,7 @@ KGE_DECLARE_SMART_PTR(NativeObject);
* \~chinese
* @brief 含有本机指针的对象
*/
-class KGE_API NativeObject : public virtual ObjectBase
+class KGE_API NativeObject : public ObjectBase
{
public:
virtual bool IsValid() const;
diff --git a/src/kiwano/render/RenderContext.cpp b/src/kiwano/render/RenderContext.cpp
index 3a7d8457..fcb281d2 100644
--- a/src/kiwano/render/RenderContext.cpp
+++ b/src/kiwano/render/RenderContext.cpp
@@ -19,10 +19,21 @@
// THE SOFTWARE.
#include
+#include
namespace kiwano
{
+RenderContextPtr RenderContext::Create(Texture& texture)
+{
+ return Renderer::GetInstance().CreateTextureRenderContext(texture, nullptr);
+}
+
+RenderContextPtr RenderContext::Create(Texture& texture, const Size& size)
+{
+ return Renderer::GetInstance().CreateTextureRenderContext(texture, &size);
+}
+
RenderContext::RenderContext()
: collecting_status_(false)
, fast_global_transform_(true)
diff --git a/src/kiwano/render/RenderContext.h b/src/kiwano/render/RenderContext.h
index 592f9aac..ecc43f96 100644
--- a/src/kiwano/render/RenderContext.h
+++ b/src/kiwano/render/RenderContext.h
@@ -19,7 +19,6 @@
// THE SOFTWARE.
#pragma once
-#include
#include
#include
#include
@@ -29,7 +28,6 @@
namespace kiwano
{
-class Renderer;
KGE_DECLARE_SMART_PTR(RenderContext);
@@ -50,16 +48,20 @@ enum class TextAntialiasMode
/// \~chinese
/// @brief 渲染上下文
-/// @details
-/// 渲染上下文将完成基础图元的绘制,并将绘制结果输出到特定的目标中(如窗口或纹理)
-class KGE_API RenderContext : public virtual ObjectBase
+/// @details 渲染上下文将完成基础图元的绘制,并将绘制结果输出到特定的平面中
+class KGE_API RenderContext : public NativeObject
{
- friend class Renderer;
-
public:
/// \~chinese
- /// @brief 是否有效
- virtual bool IsValid() const = 0;
+ /// @brief 创建纹理渲染上下文,将绘制结果输出到纹理中
+ /// @param texture 保存绘制结果的纹理
+ static RenderContextPtr Create(Texture& texture);
+
+ /// \~chinese
+ /// @brief 创建纹理渲染上下文,将绘制结果输出到纹理中
+ /// @param texture 保存绘制结果的纹理
+ /// @param size 渲染输出大小
+ static RenderContextPtr Create(Texture& texture, const Size& size);
/// \~chinese
/// @brief 开始渲染
diff --git a/src/kiwano/render/Renderer.cpp b/src/kiwano/render/Renderer.cpp
index c9e3ed55..f25086ef 100644
--- a/src/kiwano/render/Renderer.cpp
+++ b/src/kiwano/render/Renderer.cpp
@@ -51,4 +51,18 @@ void Renderer::HandleEvent(Event* evt)
}
}
+void Renderer::BeginDraw()
+{
+ KGE_ASSERT(render_ctx_);
+
+ render_ctx_->BeginDraw();
+}
+
+void Renderer::EndDraw()
+{
+ KGE_ASSERT(render_ctx_);
+
+ render_ctx_->EndDraw();
+}
+
} // namespace kiwano
diff --git a/src/kiwano/render/Renderer.h b/src/kiwano/render/Renderer.h
index 3c6bfd1d..0736ef38 100644
--- a/src/kiwano/render/Renderer.h
+++ b/src/kiwano/render/Renderer.h
@@ -24,7 +24,6 @@
#include
#include
#include
-#include
#include
namespace kiwano
@@ -198,28 +197,29 @@ public:
virtual void CreateStrokeStyle(StrokeStyle& stroke_style) = 0;
/// \~chinese
- /// @brief 创建纹理渲染上下文
+ /// @brief 创建纹理渲染上下文,将上下文的渲染输出到纹理中
+ /// @param[in,out] texture 渲染输出的纹理
/// @param[in] desired_size 期望的输出大小
/// @return 纹理渲染上下文
/// @throw kiwano::SystemError 创建失败时抛出
- virtual TextureRenderContextPtr CreateTextureRenderContext(const Size* desired_size = nullptr) = 0;
+ virtual RenderContextPtr CreateTextureRenderContext(Texture& texture, const Size* desired_size = nullptr) = 0;
public:
/// \~chinese
/// @brief 获取渲染上下文
- virtual RenderContext& GetContext() = 0;
+ RenderContext& GetContext();
/// \~chinese
/// @brief 获取渲染输出大小
- virtual Size GetOutputSize() const;
+ Size GetOutputSize() const;
/// \~chinese
/// @brief 开始渲染
- virtual void BeginDraw() = 0;
+ virtual void BeginDraw();
/// \~chinese
/// @brief 结束渲染
- virtual void EndDraw() = 0;
+ virtual void EndDraw();
/// \~chinese
/// @brief 清除绘制内容
@@ -249,13 +249,19 @@ protected:
virtual void Destroy() = 0;
protected:
- bool vsync_;
- Color clear_color_;
- Size output_size_;
+ bool vsync_;
+ Color clear_color_;
+ Size output_size_;
+ RenderContextPtr render_ctx_;
};
/** @} */
+inline RenderContext& Renderer::GetContext()
+{
+ return *render_ctx_;
+}
+
inline Size Renderer::GetOutputSize() const
{
return output_size_;
diff --git a/src/kiwano/render/TextureRenderContext.cpp b/src/kiwano/render/TextureRenderContext.cpp
deleted file mode 100644
index a17c8ebf..00000000
--- a/src/kiwano/render/TextureRenderContext.cpp
+++ /dev/null
@@ -1,56 +0,0 @@
-// Copyright (c) 2016-2019 Kiwano - Nomango
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy
-// of this software and associated documentation files (the "Software"), to deal
-// in the Software without restriction, including without limitation the rights
-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the Software is
-// furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-// THE SOFTWARE.
-
-#include
-#include
-#include
-
-namespace kiwano
-{
-
-TextureRenderContextPtr TextureRenderContext::Create()
-{
- TextureRenderContextPtr ptr;
- try
- {
- ptr = Renderer::GetInstance().CreateTextureRenderContext(nullptr);
- }
- catch (std::exception&)
- {
- return nullptr;
- }
- return ptr;
-}
-
-TextureRenderContextPtr TextureRenderContext::Create(const Size& desired_size)
-{
- TextureRenderContextPtr ptr;
- try
- {
- ptr = Renderer::GetInstance().CreateTextureRenderContext(&desired_size);
- }
- catch (std::exception&)
- {
- return nullptr;
- }
- return ptr;
-}
-
-} // namespace kiwano
diff --git a/src/kiwano/render/TextureRenderContext.h b/src/kiwano/render/TextureRenderContext.h
deleted file mode 100644
index 421ed6dd..00000000
--- a/src/kiwano/render/TextureRenderContext.h
+++ /dev/null
@@ -1,57 +0,0 @@
-// Copyright (c) 2016-2019 Kiwano - Nomango
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy
-// of this software and associated documentation files (the "Software"), to deal
-// in the Software without restriction, including without limitation the rights
-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the Software is
-// furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-// THE SOFTWARE.
-
-#pragma once
-#include
-
-namespace kiwano
-{
-KGE_DECLARE_SMART_PTR(TextureRenderContext);
-
-/**
- * \addtogroup Render
- * @{
- */
-
-/// \~chinese
-/// @brief 纹理渲染上下文
-/// @details 纹理渲染上下文将渲染输出到一个纹理对象中
-class KGE_API TextureRenderContext : public virtual RenderContext
-{
-public:
- /// \~chinese
- /// @brief 创建纹理渲染上下文
- static TextureRenderContextPtr Create();
-
- /// \~chinese
- /// @brief 创建纹理渲染上下文
- /// @param size 期望的输出大小
- static TextureRenderContextPtr Create(const Size& desired_size);
-
- /// \~chinese
- /// @brief 获取渲染输出
- /// @param[out] texture 纹理输出
- /// @return 操作是否成功
- virtual bool GetOutput(Texture& texture) = 0;
-};
-
-/** @} */
-
-} // namespace kiwano
diff --git a/src/kiwano/utils/LocalStorage.h b/src/kiwano/utils/LocalStorage.h
index 8db83d3d..6b3a1fd2 100644
--- a/src/kiwano/utils/LocalStorage.h
+++ b/src/kiwano/utils/LocalStorage.h
@@ -37,7 +37,7 @@ KGE_DECLARE_SMART_PTR(LocalStorage);
/// data.SaveInt("best-score", 20); // 保存最高分 20
/// int best = data.GetInt("best-score"); // 读取之前储存的最高分
/// @endcode
-class KGE_API LocalStorage : public virtual ObjectBase
+class KGE_API LocalStorage : public ObjectBase
{
public:
/// \~chinese