Kiwano Engine v1.3.x
RenderContext.h
1// Copyright (c) 2016-2019 Kiwano - Nomango
2//
3// Permission is hereby granted, free of charge, to any person obtaining a copy
4// of this software and associated documentation files (the "Software"), to deal
5// in the Software without restriction, including without limitation the rights
6// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7// copies of the Software, and to permit persons to whom the Software is
8// furnished to do so, subject to the following conditions:
9//
10// The above copyright notice and this permission notice shall be included in
11// all copies or substantial portions of the Software.
12//
13// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19// THE SOFTWARE.
20
21#pragma once
22#include <kiwano/core/Time.h>
23#include <kiwano/render/Brush.h>
24#include <kiwano/render/Shape.h>
25#include <kiwano/render/Layer.h>
26#include <kiwano/render/TextLayout.h>
27#include <kiwano/render/Texture.h>
28
29namespace kiwano
30{
31
40{
41 Default,
42 ClearType,
43 GrayScale,
44 None
45};
46
49enum class BlendMode
50{
51 SourceOver = 0,
52 Copy = 1,
53 Min = 2,
54 Add = 3,
55 Max = 4,
56};
57
61class KGE_API RenderContext : public NativeObject
62{
63public:
68 static RefPtr<RenderContext> Create(RefPtr<Texture> texture, const PixelSize& size);
69
72 virtual void BeginDraw();
73
76 virtual void EndDraw();
77
82 virtual void CreateTexture(Texture& texture, const PixelSize& size) = 0;
83
89 virtual void DrawTexture(const Texture& texture, const Rect* src_rect = nullptr,
90 const Rect* dest_rect = nullptr) = 0;
91
97 virtual void DrawTextLayout(const TextLayout& layout, const Point& offset, RefPtr<Brush> outline_brush) = 0;
98
102 virtual void DrawShape(const Shape& shape) = 0;
103
108 virtual void DrawLine(const Point& point1, const Point& point2) = 0;
109
113 virtual void DrawRectangle(const Rect& rect) = 0;
114
119 virtual void DrawRoundedRectangle(const Rect& rect, const Vec2& radius) = 0;
120
125 virtual void DrawCircle(const Point& center, float radius);
126
131 virtual void DrawEllipse(const Point& center, const Vec2& radius) = 0;
132
136 virtual void FillShape(const Shape& shape) = 0;
137
141 virtual void FillRectangle(const Rect& rect) = 0;
142
147 virtual void FillRoundedRectangle(const Rect& rect, const Vec2& radius) = 0;
148
153 virtual void FillCircle(const Point& center, float radius);
154
159 virtual void FillEllipse(const Point& center, const Vec2& radius) = 0;
160
164 virtual void PushClipRect(const Rect& clip_rect) = 0;
165
168 virtual void PopClipRect() = 0;
169
173 virtual void PushLayer(Layer& layer) = 0;
174
177 virtual void PopLayer() = 0;
178
181 virtual void Clear() = 0;
182
186 virtual void Clear(const Color& clear_color) = 0;
187
190 virtual Size GetSize() const = 0;
191
194 virtual float GetBrushOpacity() const;
195
198 virtual RefPtr<Brush> GetCurrentBrush() const;
199
202 virtual const Matrix3x2& GetGlobalTransform() const;
203
206 virtual void SetBrushOpacity(float opacity);
207
210 virtual void SetCurrentBrush(RefPtr<Brush> brush);
211
214 virtual void SetCurrentStrokeStyle(RefPtr<StrokeStyle> stroke);
215
218 virtual void SetBlendMode(BlendMode blend) = 0;
219
222 virtual void SetAntialiasMode(bool enabled) = 0;
223
227
230 virtual bool CheckVisibility(const Rect& bounds, const Matrix3x2& transform) = 0;
231
234 virtual void Resize(const Size& size) = 0;
235
238 virtual void SetTransform(const Matrix3x2& matrix) = 0;
239
242 virtual void SetGlobalTransform(const Matrix3x2& matrix);
243
246 virtual void SetGlobalTransform(const Matrix3x2* matrix);
247
250 virtual RefPtr<Texture> GetTarget() const = 0;
251
252public:
255 struct Status
256 {
257 uint32_t primitives;
260
261 Status();
262 };
263
266 void SetCollectingStatus(bool enable);
267
270 const Status& GetStatus() const;
271
272protected:
274
277 void IncreasePrimitivesCount(uint32_t increase = 1) const;
278
279protected:
280 bool antialias_;
281 bool fast_global_transform_;
282 mutable bool collecting_status_;
283 float brush_opacity_;
284 TextAntialiasMode text_antialias_;
285 RefPtr<Brush> current_brush_;
286 RefPtr<StrokeStyle> current_stroke_;
287 Rect visible_size_;
288 Matrix3x2 global_transform_;
289 mutable Status status_;
290};
291
294inline RenderContext::Status::Status()
295 : primitives(0)
296{
297}
298
300{
301 return status_;
302}
303
304} // namespace kiwano
Definition: Color.h:41
图层
Definition: Layer.h:37
含有本地指针的对象
Definition: NativeObject.hpp:32
引用计数智能指针
Definition: RefBasePtr.hpp:35
渲染上下文
Definition: RenderContext.h:62
virtual void FillShape(const Shape &shape)=0
填充形状
virtual void SetTransform(const Matrix3x2 &matrix)=0
设置上下文的二维变换
virtual void DrawTexture(const Texture &texture, const Rect *src_rect=nullptr, const Rect *dest_rect=nullptr)=0
绘制纹理
virtual void FillRectangle(const Rect &rect)=0
填充矩形
virtual void DrawShape(const Shape &shape)=0
绘制形状轮廓
virtual RefPtr< Texture > GetTarget() const =0
获取渲染目标
virtual void FillEllipse(const Point &center, const Vec2 &radius)=0
填充椭圆
virtual void Resize(const Size &size)=0
重设渲染上下文大小
virtual void PopLayer()=0
取消上一次设置的图层区域
virtual void DrawEllipse(const Point &center, const Vec2 &radius)=0
绘制椭圆边框
virtual void DrawRoundedRectangle(const Rect &rect, const Vec2 &radius)=0
绘制圆角矩形边框
virtual void PushClipRect(const Rect &clip_rect)=0
设置绘制的裁剪区域
virtual void Clear()=0
清空渲染内容
virtual void DrawRectangle(const Rect &rect)=0
绘制矩形边框
virtual Size GetSize() const =0
获取渲染区域大小
virtual void PushLayer(Layer &layer)=0
设置图层区域
virtual void DrawLine(const Point &point1, const Point &point2)=0
绘制线段
virtual bool CheckVisibility(const Rect &bounds, const Matrix3x2 &transform)=0
检查边界是否在视区内
virtual void SetBlendMode(BlendMode blend)=0
设置混合模式
virtual void SetAntialiasMode(bool enabled)=0
设置抗锯齿模式
virtual void Clear(const Color &clear_color)=0
使用纯色清空渲染内容
virtual void SetTextAntialiasMode(TextAntialiasMode mode)=0
设置文字抗锯齿模式
const Status & GetStatus() const
获取渲染上下文状态
Definition: RenderContext.h:299
virtual void PopClipRect()=0
取消上一次设置的绘制裁剪区域
virtual void DrawTextLayout(const TextLayout &layout, const Point &offset, RefPtr< Brush > outline_brush)=0
绘制文本布局
virtual void FillRoundedRectangle(const Rect &rect, const Vec2 &radius)=0
填充圆角矩形
virtual void CreateTexture(Texture &texture, const PixelSize &size)=0
创建空纹理
形状
Definition: Shape.h:38
文本布局
Definition: TextLayout.h:37
纹理
Definition: Texture.h:64
TextAntialiasMode
文字抗锯齿模式
Definition: RenderContext.h:40
BlendMode
混合模式
Definition: RenderContext.h:50
@ GrayScale
灰度抗锯齿
@ None
不启用抗锯齿
@ ClearType
ClearType 抗锯齿
时间段
Definition: Duration.h:48
渲染上下文状态
Definition: RenderContext.h:256
Duration duration
渲染时长
Definition: RenderContext.h:259
uint32_t primitives
渲染图元数量
Definition: RenderContext.h:257
Time start
渲染起始时间
Definition: RenderContext.h:258
时间
Definition: Time.h:42