Update RenderTarget

This commit is contained in:
Nomango 2019-12-27 10:51:34 +08:00
parent 8629d65797
commit ab50ec78b6
21 changed files with 268 additions and 238 deletions

View File

@ -40,12 +40,12 @@ namespace kiwano
void Canvas::BeginDraw()
{
rt_.BeginDraw();
rt_->BeginDraw();
}
void Canvas::EndDraw()
{
rt_.EndDraw();
rt_->EndDraw();
cache_expired_ = true;
}
@ -89,7 +89,7 @@ namespace kiwano
void Canvas::SetBrushOpacity(float opacity)
{
rt_.SetOpacity(opacity);
rt_->SetOpacity(opacity);
}
Color Canvas::GetStrokeColor() const
@ -109,43 +109,43 @@ namespace kiwano
float Canvas::GetBrushOpacity() const
{
return rt_.GetOpacity();
return rt_->GetOpacity();
}
void Canvas::SetBrushTransform(Transform const& transform)
{
rt_.SetTransform(transform.ToMatrix());
rt_->SetTransform(transform.ToMatrix());
}
void Canvas::SetBrushTransform(Matrix3x2 const & transform)
{
rt_.SetTransform(transform);
rt_->SetTransform(transform);
}
void Canvas::PushLayerArea(LayerArea& area)
{
rt_.PushLayer(area);
rt_->PushLayer(area);
}
void Canvas::PopLayerArea()
{
rt_.PopLayer();
rt_->PopLayer();
}
void Canvas::PushClipRect(Rect const& clip_rect)
{
rt_.PushClipRect(clip_rect);
rt_->PushClipRect(clip_rect);
}
void Canvas::PopClipRect()
{
rt_.PopClipRect();
rt_->PopClipRect();
}
void Canvas::DrawLine(Point const& begin, Point const& end)
{
rt_.SetDefaultBrushColor(stroke_color_);
rt_.DrawLine(
rt_->SetDefaultBrushColor(stroke_color_);
rt_->DrawLine(
begin,
end,
stroke_width_,
@ -156,8 +156,8 @@ namespace kiwano
void Canvas::DrawCircle(Point const& center, float radius)
{
rt_.SetDefaultBrushColor(stroke_color_);
rt_.DrawEllipse(
rt_->SetDefaultBrushColor(stroke_color_);
rt_->DrawEllipse(
center,
Vec2(radius, radius),
stroke_width_,
@ -168,8 +168,8 @@ namespace kiwano
void Canvas::DrawEllipse(Point const& center, Vec2 const& radius)
{
rt_.SetDefaultBrushColor(stroke_color_);
rt_.DrawEllipse(
rt_->SetDefaultBrushColor(stroke_color_);
rt_->DrawEllipse(
center,
radius,
stroke_width_,
@ -180,8 +180,8 @@ namespace kiwano
void Canvas::DrawRect(Rect const& rect)
{
rt_.SetDefaultBrushColor(stroke_color_);
rt_.DrawRectangle(
rt_->SetDefaultBrushColor(stroke_color_);
rt_->DrawRectangle(
rect,
stroke_width_,
stroke_style_
@ -191,8 +191,8 @@ namespace kiwano
void Canvas::DrawRoundedRect(Rect const& rect, Vec2 const& radius)
{
rt_.SetDefaultBrushColor(stroke_color_);
rt_.DrawRoundedRectangle(
rt_->SetDefaultBrushColor(stroke_color_);
rt_->DrawRoundedRectangle(
rect,
radius,
stroke_width_,
@ -203,8 +203,8 @@ namespace kiwano
void Canvas::FillCircle(Point const& center, float radius)
{
rt_.SetDefaultBrushColor(fill_color_);
rt_.FillEllipse(
rt_->SetDefaultBrushColor(fill_color_);
rt_->FillEllipse(
center,
Vec2(radius, radius)
);
@ -213,8 +213,8 @@ namespace kiwano
void Canvas::FillEllipse(Point const& center, Vec2 const& radius)
{
rt_.SetDefaultBrushColor(fill_color_);
rt_.FillEllipse(
rt_->SetDefaultBrushColor(fill_color_);
rt_->FillEllipse(
center,
radius
);
@ -223,8 +223,8 @@ namespace kiwano
void Canvas::FillRect(Rect const& rect)
{
rt_.SetDefaultBrushColor(fill_color_);
rt_.FillRectangle(
rt_->SetDefaultBrushColor(fill_color_);
rt_->FillRectangle(
rect
);
cache_expired_ = true;
@ -232,8 +232,8 @@ namespace kiwano
void Canvas::FillRoundedRect(Rect const& rect, Vec2 const& radius)
{
rt_.SetDefaultBrushColor(fill_color_);
rt_.FillRoundedRectangle(
rt_->SetDefaultBrushColor(fill_color_);
rt_->FillRoundedRectangle(
rect,
radius
);
@ -244,7 +244,7 @@ namespace kiwano
{
if (texture)
{
rt_.DrawTexture(*texture, src_rect, dest_rect);
rt_->DrawTexture(*texture, src_rect, dest_rect);
cache_expired_ = true;
}
}
@ -262,7 +262,7 @@ namespace kiwano
void Canvas::DrawTextLayout(TextLayout const& layout, Point const& point)
{
rt_.DrawTextLayout(layout, point);
rt_->DrawTextLayout(layout, point);
}
void Canvas::BeginPath(Point const& begin_pos)
@ -297,8 +297,8 @@ namespace kiwano
void Canvas::StrokePath()
{
rt_.SetDefaultBrushColor(stroke_color_);
rt_.DrawGeometry(
rt_->SetDefaultBrushColor(stroke_color_);
rt_->DrawGeometry(
geo_sink_.GetGeometry(),
stroke_width_,
stroke_style_
@ -308,8 +308,8 @@ namespace kiwano
void Canvas::FillPath()
{
rt_.SetDefaultBrushColor(fill_color_);
rt_.FillGeometry(
rt_->SetDefaultBrushColor(fill_color_);
rt_->FillGeometry(
geo_sink_.GetGeometry()
);
cache_expired_ = true;
@ -317,13 +317,13 @@ namespace kiwano
void Canvas::Clear()
{
rt_.Clear();
rt_->Clear();
cache_expired_ = true;
}
void Canvas::Clear(Color const& clear_color)
{
rt_.Clear(clear_color);
rt_->Clear(clear_color);
cache_expired_ = true;
}
@ -337,7 +337,7 @@ namespace kiwano
{
if (cache_expired_)
{
texture_cached_ = rt_.GetOutput();
texture_cached_ = rt_->GetOutput();
cache_expired_ = false;
}
}

View File

@ -268,10 +268,10 @@ namespace kiwano
TextStyle text_style_;
StrokeStyle stroke_style_;
GeometrySink geo_sink_;
TextureRenderTargetPtr rt_;
mutable bool cache_expired_;
mutable TexturePtr texture_cached_;
mutable TextureRenderTarget rt_;
};
/** @} */

View File

@ -73,7 +73,7 @@ namespace kiwano
SetSize(Size{ static_cast<float>(gif_->GetWidthInPixels()), static_cast<float>(gif_->GetHeightInPixels()) });
if (!frame_rt_.IsValid())
if (!frame_rt_)
{
Renderer::instance().CreateTextureRenderTarget(frame_rt_);
}
@ -129,9 +129,10 @@ namespace kiwano
void GifSprite::ComposeNextFrame()
{
KGE_ASSERT(gif_ && gif_->IsValid());
KGE_ASSERT(frame_rt_);
KGE_ASSERT(gif_);
if (frame_rt_.IsValid())
if (frame_rt_->IsValid())
{
do
{
@ -170,6 +171,7 @@ namespace kiwano
void GifSprite::OverlayNextFrame()
{
KGE_ASSERT(frame_rt_);
KGE_ASSERT(gif_ && gif_->IsValid());
frame_ = gif_->GetFrame(next_index_);
@ -179,9 +181,9 @@ namespace kiwano
SaveComposedFrame();
}
if (frame_rt_.IsValid())
if (frame_rt_->IsValid())
{
frame_rt_.BeginDraw();
frame_rt_->BeginDraw();
if (next_index_ == 0)
{
@ -190,12 +192,12 @@ namespace kiwano
if (frame_.raw)
{
frame_rt_.DrawTexture(*frame_.raw, nullptr, &frame_.rect);
frame_rt_->DrawTexture(*frame_.raw, nullptr, &frame_.rect);
}
frame_rt_.EndDraw();
frame_rt_->EndDraw();
frame_to_render_ = frame_rt_.GetOutput();
frame_to_render_ = frame_rt_->GetOutput();
if (frame_to_render_)
{
next_index_ = (++next_index_) % gif_->GetFramesCount();
@ -215,7 +217,8 @@ namespace kiwano
void GifSprite::SaveComposedFrame()
{
TexturePtr frame_to_be_saved = frame_rt_.GetOutput();
KGE_ASSERT(frame_rt_);
TexturePtr frame_to_be_saved = frame_rt_->GetOutput();
HRESULT hr = frame_to_be_saved ? S_OK : E_FAIL;
@ -223,17 +226,11 @@ namespace kiwano
{
if (!saved_frame_)
{
auto size = frame_to_be_saved->GetSizeInPixels();
auto prop = D2D1::BitmapProperties(frame_to_be_saved->GetPixelFormat());
ComPtr<ID2D1Bitmap> saved_bitmap;
hr = frame_rt_.GetRenderTarget()->CreateBitmap(D2D1::SizeU(size.x, size.y), prop, &saved_bitmap);
if (SUCCEEDED(hr))
{
saved_frame_->SetBitmap(saved_bitmap);
}
saved_frame_ = new Texture;
frame_rt_->CreateTexture(*saved_frame_, frame_to_be_saved->GetSizeInPixels(), frame_to_be_saved->GetPixelFormat());
}
hr = saved_frame_ ? S_OK : E_FAIL;
}
if (SUCCEEDED(hr))
@ -246,11 +243,12 @@ namespace kiwano
void GifSprite::RestoreSavedFrame()
{
KGE_ASSERT(frame_rt_);
HRESULT hr = saved_frame_ ? S_OK : E_FAIL;
if (SUCCEEDED(hr))
{
TexturePtr frame_to_copy_to = frame_rt_.GetOutput();
TexturePtr frame_to_copy_to = frame_rt_->GetOutput();
hr = frame_to_copy_to ? S_OK : E_FAIL;
@ -265,13 +263,14 @@ namespace kiwano
void GifSprite::ClearCurrentFrameArea()
{
frame_rt_.BeginDraw();
KGE_ASSERT(frame_rt_);
frame_rt_->BeginDraw();
frame_rt_.PushClipRect(frame_.rect);
frame_rt_.Clear();
frame_rt_.PopClipRect();
frame_rt_->PushClipRect(frame_.rect);
frame_rt_->Clear();
frame_rt_->PopClipRect();
return frame_rt_.EndDraw();
return frame_rt_->EndDraw();
}
}

View File

@ -162,7 +162,7 @@ namespace kiwano
GifImage::Frame frame_;
TexturePtr saved_frame_;
TexturePtr frame_to_render_;
TextureRenderTarget frame_rt_;
TextureRenderTargetPtr frame_rt_;
};
/** @} */

View File

@ -49,7 +49,7 @@ namespace kiwano
Rect ShapeActor::GetBoundingBox() const
{
if (!geo_)
if (!geo_.IsValid())
return Rect{};
return geo_.GetBoundingBox(GetTransformMatrix());
@ -83,7 +83,7 @@ namespace kiwano
void ShapeActor::SetGeometry(Geometry const& geometry)
{
geo_ = geometry;
if (geo_)
if (geo_.IsValid())
{
bounds_ = geo_.GetBoundingBox();
SetSize(bounds_.GetSize());
@ -97,7 +97,7 @@ namespace kiwano
void ShapeActor::OnRender(RenderTarget* rt)
{
if (geo_ && CheckVisibilty(rt))
if (geo_.IsValid() && CheckVisibilty(rt))
{
PrepareRender(rt);
@ -317,7 +317,7 @@ namespace kiwano
sink_.EndPath(closed);
Geometry geo = sink_.GetGeometry();
if (geo)
if (geo.IsValid())
{
SetGeometry(geo);
}

View File

@ -60,7 +60,7 @@ namespace kiwano
void ActionWalk::Init(Actor* target)
{
if (!path_)
if (!path_.IsValid())
{
Done();
return;
@ -121,7 +121,7 @@ namespace kiwano
void ActionWalk::ClearPath()
{
path_.SetGeometry(nullptr);
path_.Clear();
}
}

View File

@ -90,48 +90,32 @@ namespace kiwano
);
};
// ť­ąĘ
/**
* \~chinese
* @brief ť­Ë˘
*/
class KGE_API Brush
{
public:
Brush();
Brush(
Color const& color
);
Brush(Color const& color);
Brush(
SolidColorStyle const& style
);
Brush(SolidColorStyle const& style);
Brush(
LinearGradientStyle const& style
);
Brush(LinearGradientStyle const& style);
Brush(
RadialGradientStyle const& style
);
Brush(RadialGradientStyle const& style);
bool IsValid() const;
inline void SetColor(
Color const& color
)
{
SetStyle(SolidColorStyle{ color });
}
void SetColor(Color const& color);
void SetStyle(
SolidColorStyle const& style
);
void SetStyle(SolidColorStyle const& style);
void SetStyle(
LinearGradientStyle const& style
);
void SetStyle(LinearGradientStyle const& style);
void SetStyle(
RadialGradientStyle const& style
);
void SetStyle(RadialGradientStyle const& style);
float GetOpacity() const;
@ -149,9 +133,7 @@ namespace kiwano
Type GetType() const { return type_; }
public:
Brush(
ComPtr<ID2D1Brush> brush
);
Brush(ComPtr<ID2D1Brush> brush);
void SetBrush(ComPtr<ID2D1Brush> const& brush);
@ -163,4 +145,9 @@ namespace kiwano
ComPtr<ID2D1Brush> raw_;
};
inline void Brush::SetColor(Color const& color)
{
SetStyle(SolidColorStyle{ color });
}
}

View File

@ -27,16 +27,6 @@ namespace kiwano
{
}
Font::Font(String const& font_file)
{
Load(font_file);
}
Font::Font(Resource const& font_resource)
{
Load(font_resource);
}
bool Font::Load(String const& font_file)
{
try

View File

@ -39,10 +39,6 @@ namespace kiwano
public:
Font();
Font(String const& font_file);
Font(Resource const& font_resource);
bool Load(String const& font_file);
bool Load(Resource const& font_resource);

View File

@ -33,11 +33,6 @@ namespace kiwano
{
}
Geometry::Geometry(ComPtr<ID2D1Geometry> geo)
: geo_(geo)
{
}
bool Geometry::IsValid() const
{
return geo_ != nullptr;
@ -92,6 +87,11 @@ namespace kiwano
return false;
}
void Geometry::Clear()
{
geo_.reset();
}
void Geometry::CombineWith(GeometrySink& sink, Geometry input, CombineMode mode, Matrix3x2 const& input_matrix) const
{
if (geo_ && input.geo_)
@ -277,14 +277,17 @@ namespace kiwano
{
EndPath();
}
return Geometry(path_geo_);
Geometry geo;
geo.SetGeometry(path_geo_);
return geo;
}
void GeometrySink::Init()
{
if (!path_geo_)
{
Renderer::instance().CreatePathGeometrySink(*this);
Renderer::instance().CreateGeometrySink(*this);
}
}

View File

@ -23,26 +23,20 @@
namespace kiwano
{
class RenderTarget;
class Renderer;
class GeometrySink;
// 섯부竟
class KGE_API Geometry
{
public:
// 几何体组合模式
enum class CombineMode
{
Union, /* 并集 (A + B) */
Intersect, /* 交集 (A + B) */
Xor, /* 对称差集 ((A - B) + (B - A)) */
Exclude /* 差集 (A - B) */
};
friend class RenderTarget;
friend class Renderer;
friend class GeometrySink;
public:
Geometry();
Geometry(ComPtr<ID2D1Geometry> geo);
bool IsValid() const;
// 삿혤棍학관鍋분
@ -72,6 +66,19 @@ namespace kiwano
Vec2& tangent
) const;
// 헌뇜近榴
void Clear();
public:
// 섯부竟莉북친駕
enum class CombineMode
{
Union, /* 깻섞 (A + B) */
Intersect, /* 슥섞 (A + B) */
Xor, /* 뚤냔뀌섞 ((A - B) + (B - A)) */
Exclude /* 뀌섞 (A - B) */
};
// 莉북섯부竟
void CombineWith(
GeometrySink& sink,
@ -87,6 +94,7 @@ namespace kiwano
Matrix3x2 const& input_matrix = Matrix3x2()
) const;
public:
// 눼쉔殮窟
static Geometry CreateLine(
Point const& begin,
@ -116,13 +124,11 @@ namespace kiwano
Vec2 const& radius
);
public:
private:
inline ComPtr<ID2D1Geometry> GetGeometry() const { return geo_; }
inline void SetGeometry(ComPtr<ID2D1Geometry> geometry) { geo_ = geometry; }
inline operator bool() const { return IsValid(); }
private:
ComPtr<ID2D1Geometry> geo_;
};
@ -132,8 +138,12 @@ namespace kiwano
class KGE_API GeometrySink
: protected Noncopyable
{
friend class Geometry;
friend class Renderer;
public:
GeometrySink();
~GeometrySink();
// 역迦警속쨌쓺
@ -187,7 +197,7 @@ namespace kiwano
// 밑균직
void Close();
public:
private:
inline ComPtr<ID2D1PathGeometry> GetPathGeometry() const { return path_geo_; }
inline void SetPathGeometry(ComPtr<ID2D1PathGeometry> path) { path_geo_ = path; }

View File

@ -31,17 +31,6 @@ namespace kiwano
{
}
GifImage::GifImage(String const& file_path)
{
Load(file_path);
}
GifImage::GifImage(Resource const& res)
: GifImage()
{
Load(res);
}
bool GifImage::Load(String const& file_path)
{
Renderer::instance().CreateGifImage(*this, file_path);

View File

@ -24,19 +24,19 @@
namespace kiwano
{
class Renderer;
KGE_DECLARE_SMART_PTR(GifImage);
// GIF ͼÏñ
class KGE_API GifImage
: public ObjectBase
{
friend class Renderer;
public:
GifImage();
GifImage(String const& file_path);
GifImage(Resource const& res);
bool Load(String const& file_path);
bool Load(Resource const& res);
@ -70,11 +70,11 @@ namespace kiwano
Frame GetFrame(uint32_t index);
private:
ComPtr<IWICBitmapDecoder> GetDecoder() const;
void SetDecoder(ComPtr<IWICBitmapDecoder> decoder);
private:
HRESULT GetGlobalMetadata();
private:

View File

@ -23,9 +23,13 @@
namespace kiwano
{
class RenderTarget;
// 暠꿔
class KGE_API LayerArea
{
friend class RenderTarget;
public:
LayerArea();
@ -53,7 +57,7 @@ namespace kiwano
// <20>零섯부촁꿔긴뻣
inline void SetMaskTransform(Matrix3x2 const& matrix) { mask_transform_ = matrix; }
public:
private:
inline ComPtr<ID2D1Layer> GetLayer() const { return layer_; }
inline void SetLayer(ComPtr<ID2D1Layer> layer) { layer_ = layer; }

View File

@ -397,6 +397,29 @@ namespace kiwano
ThrowIfFailed(hr);
}
void RenderTarget::CreateTexture(Texture& texture, math::Vec2T<uint32_t> size, D2D1_PIXEL_FORMAT format)
{
HRESULT hr = S_OK;
if (!render_target_)
{
hr = E_UNEXPECTED;
}
if (SUCCEEDED(hr))
{
ComPtr<ID2D1Bitmap> saved_bitmap;
hr = render_target_->CreateBitmap(D2D1::SizeU(size.x, size.y), D2D1::BitmapProperties(format), &saved_bitmap);
if (SUCCEEDED(hr))
{
texture.SetBitmap(saved_bitmap);
}
}
ThrowIfFailed(hr);
}
void RenderTarget::CreateLayer(LayerArea& layer)
{
HRESULT hr = S_OK;
@ -714,19 +737,16 @@ namespace kiwano
{
}
TexturePtr TextureRenderTarget::GetOutput()
TexturePtr TextureRenderTarget::GetOutput() const
{
HRESULT hr = E_FAIL;
TexturePtr output;
if (GetRenderTarget())
{
ComPtr<ID2D1BitmapRenderTarget> bitmap_rt;
hr = GetRenderTarget()->QueryInterface<ID2D1BitmapRenderTarget>(&bitmap_rt);
if (SUCCEEDED(hr))
if (bitmap_rt_)
{
ComPtr<ID2D1BitmapRenderTarget> bitmap_rt = bitmap_rt_;
ComPtr<ID2D1Bitmap> bitmap;
hr = bitmap_rt->GetBitmap(&bitmap);
if (SUCCEEDED(hr))
@ -735,7 +755,6 @@ namespace kiwano
output->SetBitmap(bitmap);
}
}
}
ThrowIfFailed(hr);
return output;

View File

@ -20,6 +20,7 @@
#pragma once
#include <kiwano/core/time.h>
#include <kiwano/core/ObjectBase.h>
#include <kiwano/core/win32/ComPtr.hpp>
#include <kiwano/renderer/Brush.h>
#include <kiwano/renderer/Texture.h>
@ -30,6 +31,11 @@
namespace kiwano
{
class Renderer;
KGE_DECLARE_SMART_PTR(RenderTarget);
KGE_DECLARE_SMART_PTR(TextureRenderTarget);
// 文字抗锯齿模式
enum class TextAntialiasMode
{
@ -42,7 +48,7 @@ namespace kiwano
// 渲染目标
class KGE_API RenderTarget
: public Noncopyable
: public ObjectBase
{
public:
bool IsValid() const;
@ -51,10 +57,6 @@ namespace kiwano
void EndDraw();
void CreateLayer(
LayerArea& layer
);
void DrawGeometry(
Geometry const& geometry,
float stroke_width,
@ -123,6 +125,16 @@ namespace kiwano
Point const& offset = Point{}
);
void CreateTexture(
Texture& texture,
math::Vec2T<uint32_t> size,
D2D1_PIXEL_FORMAT format
);
void CreateLayer(
LayerArea& layer
);
void PushClipRect(
Rect const& clip_rect
);
@ -203,19 +215,17 @@ namespace kiwano
inline Status const& GetStatus() const { return status_; }
protected:
inline ComPtr<ID2D1RenderTarget> GetRenderTarget() const { KGE_ASSERT(render_target_); return render_target_; }
inline ComPtr<ITextRenderer> GetTextRenderer() const { KGE_ASSERT(text_renderer_); return text_renderer_; }
ComPtr<ID2D1StrokeStyle> GetStrokeStyle(StrokeStyle style);
public:
protected:
RenderTarget();
HRESULT CreateDeviceResources(
ComPtr<ID2D1RenderTarget> rt,
ComPtr<ID2DDeviceResources> dev_res
);
HRESULT CreateDeviceResources(ComPtr<ID2D1RenderTarget> rt, ComPtr<ID2DDeviceResources> dev_res);
void DiscardDeviceResources();
@ -239,9 +249,36 @@ namespace kiwano
class KGE_API TextureRenderTarget
: public RenderTarget
{
friend class Renderer;
public:
bool IsValid() const;
TexturePtr GetOutput() const;
private:
TextureRenderTarget();
TexturePtr GetOutput();
ComPtr<ID2D1BitmapRenderTarget> GetBitmapRenderTarget() const;
void SetBitmapRenderTarget(ComPtr<ID2D1BitmapRenderTarget> rt);
private:
ComPtr<ID2D1BitmapRenderTarget> bitmap_rt_;
};
inline bool TextureRenderTarget::IsValid() const
{
return !!bitmap_rt_;
}
inline ComPtr<ID2D1BitmapRenderTarget> TextureRenderTarget::GetBitmapRenderTarget() const
{
return bitmap_rt_;
}
inline void TextureRenderTarget::SetBitmapRenderTarget(ComPtr<ID2D1BitmapRenderTarget> rt)
{
bitmap_rt_ = rt;
}
}

View File

@ -835,7 +835,7 @@ namespace kiwano
ThrowIfFailed(hr);
}
void Renderer::CreatePathGeometrySink(GeometrySink& sink)
void Renderer::CreateGeometrySink(GeometrySink& sink)
{
HRESULT hr = S_OK;
if (!d2d_res_)
@ -857,7 +857,7 @@ namespace kiwano
ThrowIfFailed(hr);
}
void Renderer::CreateTextureRenderTarget(TextureRenderTarget& render_target)
void Renderer::CreateTextureRenderTarget(TextureRenderTargetPtr& render_target)
{
HRESULT hr = S_OK;
if (!d2d_res_)
@ -865,15 +865,27 @@ namespace kiwano
hr = E_UNEXPECTED;
}
ComPtr<ID2D1BitmapRenderTarget> output;
TextureRenderTargetPtr output;
if (SUCCEEDED(hr))
{
hr = d2d_res_->GetDeviceContext()->CreateCompatibleRenderTarget(&output);
ComPtr<ID2D1BitmapRenderTarget> bitmap_rt;
hr = d2d_res_->GetDeviceContext()->CreateCompatibleRenderTarget(&bitmap_rt);
if (SUCCEEDED(hr))
{
output = new TextureRenderTarget;
hr = output->CreateDeviceResources(bitmap_rt, d2d_res_);
}
if (SUCCEEDED(hr))
{
hr = render_target.CreateDeviceResources(output, d2d_res_);
output->SetBitmapRenderTarget(bitmap_rt);
}
}
if (SUCCEEDED(hr))
{
render_target = output;
}
ThrowIfFailed(hr);

View File

@ -141,12 +141,12 @@ namespace kiwano
Vec2 const& radius
);
void CreatePathGeometrySink(
void CreateGeometrySink(
GeometrySink& sink
);
void CreateTextureRenderTarget(
TextureRenderTarget& render_target
TextureRenderTargetPtr& render_target
);
void CreateSolidBrush(

View File

@ -24,10 +24,16 @@
namespace kiwano
{
class RenderTarget;
class Renderer;
/// \~chinese
/// @brief 文本布局
class KGE_API TextLayout
{
friend class RenderTarget;
friend class Renderer;
public:
/// \~chinese
/// @brief 构造空的文本布局
@ -136,7 +142,7 @@ namespace kiwano
/// @param length 长度
void SetStrikethrough(bool enable, uint32_t start, uint32_t length);
public:
private:
ComPtr<IDWriteTextFormat> GetTextFormat() const;
void SetTextFormat(ComPtr<IDWriteTextFormat> format);

View File

@ -31,24 +31,6 @@ namespace kiwano
{
}
Texture::Texture(String const& file_path)
: Texture()
{
Load(file_path);
}
Texture::Texture(Resource const& res)
: Texture()
{
Load(res);
}
Texture::Texture(ComPtr<ID2D1Bitmap> const & bitmap)
: Texture()
{
SetBitmap(bitmap);
}
Texture::~Texture()
{
}

View File

@ -24,6 +24,10 @@
namespace kiwano
{
class RenderTarget;
class TextureRenderTarget;
class Renderer;
// 插值模式
// 插值模式指定了位图在缩放和旋转时像素颜色的计算方式
// Linear (双线性插值): 对周围四个像素进行两次线性插值计算, 在图像放大时可能会模糊(默认)
@ -40,21 +44,13 @@ namespace kiwano
class KGE_API Texture
: public ObjectBase
{
friend class RenderTarget;
friend class TextureRenderTarget;
friend class Renderer;
public:
Texture();
explicit Texture(
String const& file_path
);
explicit Texture(
Resource const& res
);
explicit Texture(
ComPtr<ID2D1Bitmap> const& bitmap
);
virtual ~Texture();
// 加载本地文件
@ -91,6 +87,9 @@ namespace kiwano
// 获取像素插值方式
InterpolationMode GetBitmapInterpolationMode() const;
// »ñÈ¡ÏñËØ¸ñʽ
D2D1_PIXEL_FORMAT GetPixelFormat() const;
// 拷贝位图内存
void CopyFrom(TexturePtr copy_from);
@ -103,16 +102,13 @@ namespace kiwano
// 设置默认的像素插值方式
static void SetDefaultInterpolationMode(InterpolationMode mode);
public:
private:
// 获取源位图
ComPtr<ID2D1Bitmap> GetBitmap() const;
// 设置源位图
void SetBitmap(ComPtr<ID2D1Bitmap> bitmap);
// »ñÈ¡ÏñËØ¸ñʽ
D2D1_PIXEL_FORMAT GetPixelFormat() const;
private:
ComPtr<ID2D1Bitmap> bitmap_;
InterpolationMode interpolation_mode_;