Kiwano Engine v1.3.x
Renderer.h
1// Copyright (c) 2016-2018 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/base/Module.h>
23#include <kiwano/render/Font.h>
24#include <kiwano/render/GifImage.h>
25#include <kiwano/render/TextStyle.h>
26#include <kiwano/render/RenderContext.h>
27#include <kiwano/platform/Window.h>
28
29namespace kiwano
30{
31
46class KGE_API Renderer : public Module
47{
48public:
51 static Renderer& GetInstance();
52
55 virtual Color GetClearColor() const;
56
59 Size GetOutputSize() const;
60
63 RenderContext& GetContext();
64
67 virtual void Resize(uint32_t width, uint32_t height) = 0;
68
71 void SetClearColor(const Color& clear_color);
72
75 void SetVSyncEnabled(bool enabled);
76
79 void ResetResolutionWhenWindowResized(bool enabled);
80
85 virtual void CreateTexture(Texture& texture, StringView file_path) = 0;
86
91 virtual void CreateTexture(Texture& texture, const BinaryData& data) = 0;
92
99 virtual void CreateTexture(Texture& texture, const PixelSize& size, const BinaryData& data, PixelFormat format) = 0;
100
105 virtual void CreateGifImage(GifImage& gif, StringView file_path) = 0;
106
111 virtual void CreateGifImage(GifImage& gif, const BinaryData& data) = 0;
112
118 virtual void CreateGifImageFrame(GifImage::Frame& frame, const GifImage& gif, size_t frame_index) = 0;
119
125 virtual void CreateFontCollection(Font& font, Vector<String>& family_names, StringView file_path) = 0;
126
132 virtual void CreateFontCollection(Font& font, Vector<String>& family_names, const BinaryData& data) = 0;
133
139 virtual void CreateTextLayout(TextLayout& layout, StringView content, const TextStyle& style) = 0;
140
146 virtual void CreateLineShape(Shape& shape, const Point& begin_pos, const Point& end_pos) = 0;
147
152 virtual void CreateRectShape(Shape& shape, const Rect& rect) = 0;
153
159 virtual void CreateRoundedRectShape(Shape& shape, const Rect& rect, const Vec2& radius) = 0;
160
166 virtual void CreateEllipseShape(Shape& shape, const Point& center, const Vec2& radius) = 0;
167
171 virtual void CreateShapeSink(ShapeMaker& maker) = 0;
172
177 virtual void CreateBrush(Brush& brush, const Color& color) = 0;
178
183 virtual void CreateBrush(Brush& brush, const LinearGradientStyle& style) = 0;
184
189 virtual void CreateBrush(Brush& brush, const RadialGradientStyle& style) = 0;
190
195 virtual void CreateBrush(Brush& brush, RefPtr<Texture> texture) = 0;
196
205 virtual void CreateStrokeStyle(StrokeStyle& stroke_style) = 0;
206
213 const PixelSize& desired_size) = 0;
214
215public:
218 virtual void Clear() = 0;
219
223 virtual void Present() = 0;
224
228 virtual void MakeContextForWindow(RefPtr<Window> window) = 0;
229
232 virtual void Destroy();
233
236 void HandleEvent(EventModuleContext& ctx) override;
237
238protected:
239 Renderer();
240
241protected:
242 bool vsync_;
243 bool auto_reset_resolution_;
244 Color clear_color_;
245 Size output_size_;
246 RefPtr<RenderContext> render_ctx_;
247};
248
252{
253 return *render_ctx_;
254}
255
257{
258 return output_size_;
259}
260
262{
263 return clear_color_;
264}
265
266} // namespace kiwano
画刷
Definition: Brush.h:92
Definition: Color.h:41
时间模块上下文
Definition: Module.h:96
字体
Definition: Font.h:89
GIF图像
Definition: GifImage.h:38
基础模块
Definition: Module.h:111
引用计数智能指针
Definition: RefBasePtr.hpp:35
渲染上下文
Definition: RenderContext.h:62
渲染器
Definition: Renderer.h:47
virtual void CreateRoundedRectShape(Shape &shape, const Rect &rect, const Vec2 &radius)=0
创建圆角矩形形状内部资源
virtual void CreateTexture(Texture &texture, StringView file_path)=0
创建纹理内部资源
RenderContext & GetContext()
获取渲染上下文
Definition: Renderer.h:251
virtual void CreateLineShape(Shape &shape, const Point &begin_pos, const Point &end_pos)=0
创建线段形状内部资源
virtual void CreateRectShape(Shape &shape, const Rect &rect)=0
创建矩形形状内部资源
virtual void CreateShapeSink(ShapeMaker &maker)=0
创建几何图形生成器内部资源
virtual void CreateFontCollection(Font &font, Vector< String > &family_names, const BinaryData &data)=0
创建字体集内部资源
virtual void CreateTexture(Texture &texture, const BinaryData &data)=0
创建纹理内部资源
virtual void CreateBrush(Brush &brush, const RadialGradientStyle &style)=0
创建径向渐变画刷内部资源
Size GetOutputSize() const
获取渲染输出大小
Definition: Renderer.h:256
virtual void CreateGifImageFrame(GifImage::Frame &frame, const GifImage &gif, size_t frame_index)=0
创建GIF关键帧内部资源
virtual Color GetClearColor() const
获取清屏颜色
Definition: Renderer.h:261
virtual void CreateTextLayout(TextLayout &layout, StringView content, const TextStyle &style)=0
创建文字布局内部资源
virtual void Present()=0
将绘制内容呈现至窗口
virtual void CreateBrush(Brush &brush, const LinearGradientStyle &style)=0
创建线性渐变画刷内部资源
virtual void CreateStrokeStyle(StrokeStyle &stroke_style)=0
创建线条样式内部资源
virtual void Resize(uint32_t width, uint32_t height)=0
重设渲染输出大小
virtual void CreateBrush(Brush &brush, RefPtr< Texture > texture)=0
创建纹理画刷内部资源
virtual void CreateBrush(Brush &brush, const Color &color)=0
创建纯色画刷内部资源
virtual void CreateGifImage(GifImage &gif, StringView file_path)=0
创建GIF图像内部资源
virtual void Clear()=0
清除绘制内容
virtual void CreateTexture(Texture &texture, const PixelSize &size, const BinaryData &data, PixelFormat format)=0
从内存加载位图纹理资源
virtual void MakeContextForWindow(RefPtr< Window > window)=0
为窗口创建渲染上下文
virtual void CreateFontCollection(Font &font, Vector< String > &family_names, StringView file_path)=0
创建字体集内部资源
virtual void CreateEllipseShape(Shape &shape, const Point &center, const Vec2 &radius)=0
创建椭圆形状内部资源
virtual RefPtr< RenderContext > CreateTextureRenderContext(RefPtr< Texture > texture, const PixelSize &desired_size)=0
创建纹理渲染上下文,将上下文的渲染输出到纹理中
virtual void CreateGifImage(GifImage &gif, const BinaryData &data)=0
创建GIF图像内部资源
形状生成器
Definition: ShapeMaker.h:45
形状
Definition: Shape.h:38
线条样式
Definition: StrokeStyle.h:68
文本布局
Definition: TextLayout.h:37
文本样式
Definition: TextStyle.h:51
纹理
Definition: Texture.h:64
PixelFormat
像素格式
Definition: Texture.h:54
二进制数据
Definition: BinaryData.h:30
GIF帧
Definition: GifImage.h:88
线性渐变样式
Definition: Brush.h:59
径向渐变样式
Definition: Brush.h:74