2019-04-11 14:40:54 +08:00
|
|
|
// Copyright (c) 2016-2018 Kiwano - Nomango
|
2020-01-21 10:09:55 +08:00
|
|
|
//
|
2019-03-31 01:37:06 +08:00
|
|
|
// 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:
|
2020-01-21 10:09:55 +08:00
|
|
|
//
|
2019-03-31 01:37:06 +08:00
|
|
|
// The above copyright notice and this permission notice shall be included in
|
|
|
|
|
// all copies or substantial portions of the Software.
|
2020-01-21 10:09:55 +08:00
|
|
|
//
|
2019-03-31 01:37:06 +08:00
|
|
|
// 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
|
2019-11-13 14:33:15 +08:00
|
|
|
#include <kiwano/core/Component.h>
|
2020-01-17 16:55:47 +08:00
|
|
|
#include <kiwano/render/Font.h>
|
2020-01-21 10:09:55 +08:00
|
|
|
#include <kiwano/render/GifImage.h>
|
2020-01-17 16:55:47 +08:00
|
|
|
#include <kiwano/render/TextStyle.hpp>
|
2020-02-08 00:17:31 +08:00
|
|
|
#include <kiwano/render/RenderContext.h>
|
|
|
|
|
#include <kiwano/render/TextureRenderContext.h>
|
2019-03-31 01:37:06 +08:00
|
|
|
|
2019-04-11 14:40:54 +08:00
|
|
|
namespace kiwano
|
2019-03-31 01:37:06 +08:00
|
|
|
{
|
2019-07-30 00:41:06 +08:00
|
|
|
|
2020-01-21 10:09:55 +08:00
|
|
|
/**
|
|
|
|
|
* \~chinese
|
2020-02-10 17:32:04 +08:00
|
|
|
* \defgroup Render 渲染引擎
|
2020-01-21 10:09:55 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \addtogroup Render
|
|
|
|
|
* @{
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \~chinese
|
2020-02-10 17:32:04 +08:00
|
|
|
* @brief 渲染器
|
2020-01-21 10:09:55 +08:00
|
|
|
*/
|
2020-02-09 18:41:59 +08:00
|
|
|
class KGE_API Renderer : public EventComponent
|
2020-01-21 10:09:55 +08:00
|
|
|
{
|
|
|
|
|
public:
|
2020-02-09 18:41:59 +08:00
|
|
|
/// \~chinese
|
2020-02-10 17:32:04 +08:00
|
|
|
/// @brief 获取实例
|
2020-02-09 18:41:59 +08:00
|
|
|
static Renderer& GetInstance();
|
|
|
|
|
|
2020-01-21 10:09:55 +08:00
|
|
|
/// \~chinese
|
2020-02-10 17:32:04 +08:00
|
|
|
/// @brief 获取清屏颜色
|
2020-02-09 18:41:59 +08:00
|
|
|
virtual Color GetClearColor() const;
|
2020-01-21 10:09:55 +08:00
|
|
|
|
|
|
|
|
/// \~chinese
|
2020-02-10 17:32:04 +08:00
|
|
|
/// @brief 设置清屏颜色
|
2020-02-09 18:41:59 +08:00
|
|
|
virtual void SetClearColor(Color const& clear_color);
|
2020-01-21 10:09:55 +08:00
|
|
|
|
|
|
|
|
/// \~chinese
|
2020-02-10 17:32:04 +08:00
|
|
|
/// @brief 开启或关闭垂直同步
|
2020-02-09 18:41:59 +08:00
|
|
|
virtual void SetVSyncEnabled(bool enabled);
|
2020-01-21 10:09:55 +08:00
|
|
|
|
|
|
|
|
/// \~chinese
|
2020-02-10 17:32:04 +08:00
|
|
|
/// @brief 创建纹理内部资源
|
|
|
|
|
/// @param[out] texture 纹理
|
|
|
|
|
/// @param[in] file_path 图片路径
|
|
|
|
|
/// @throw kiwano::SystemException 创建失败时抛出
|
2020-02-09 18:41:59 +08:00
|
|
|
virtual void CreateTexture(Texture& texture, String const& file_path) = 0;
|
2020-01-21 10:09:55 +08:00
|
|
|
|
|
|
|
|
/// \~chinese
|
2020-02-10 17:32:04 +08:00
|
|
|
/// @brief 创建纹理内部资源
|
|
|
|
|
/// @param[out] texture 纹理
|
|
|
|
|
/// @param[in] resource 图片资源
|
|
|
|
|
/// @throw kiwano::SystemException 创建失败时抛出
|
2020-02-09 18:41:59 +08:00
|
|
|
virtual void CreateTexture(Texture& texture, Resource const& resource) = 0;
|
2020-01-21 10:09:55 +08:00
|
|
|
|
|
|
|
|
/// \~chinese
|
2020-02-10 17:32:04 +08:00
|
|
|
/// @brief 创建GIF图像内部资源
|
|
|
|
|
/// @param[out] gif GIF图像
|
|
|
|
|
/// @param[in] file_path 图片路径
|
|
|
|
|
/// @throw kiwano::SystemException 创建失败时抛出
|
2020-02-09 18:41:59 +08:00
|
|
|
virtual void CreateGifImage(GifImage& gif, String const& file_path) = 0;
|
2020-01-21 10:09:55 +08:00
|
|
|
|
|
|
|
|
/// \~chinese
|
2020-02-10 17:32:04 +08:00
|
|
|
/// @brief 创建GIF图像内部资源
|
|
|
|
|
/// @param[out] gif GIF图像
|
|
|
|
|
/// @param[in] resource 图片资源
|
|
|
|
|
/// @throw kiwano::SystemException 创建失败时抛出
|
2020-02-09 18:41:59 +08:00
|
|
|
virtual void CreateGifImage(GifImage& gif, Resource const& resource) = 0;
|
2020-01-21 10:09:55 +08:00
|
|
|
|
|
|
|
|
/// \~chinese
|
2020-02-10 17:32:04 +08:00
|
|
|
/// @brief 创建GIF图像帧内部资源
|
|
|
|
|
/// @param[out] frame GIF图像帧
|
|
|
|
|
/// @param[in] gif GIF图像
|
|
|
|
|
/// @param[in] frame_index 帧下标
|
|
|
|
|
/// @throw kiwano::SystemException 创建失败时抛出
|
2020-02-09 18:41:59 +08:00
|
|
|
virtual void CreateGifImageFrame(GifImage::Frame& frame, GifImage const& gif, size_t frame_index) = 0;
|
2020-01-21 10:09:55 +08:00
|
|
|
|
|
|
|
|
/// \~chinese
|
2020-02-10 17:32:04 +08:00
|
|
|
/// @brief 创建字体集内部资源
|
|
|
|
|
/// @param[out] font 字体
|
|
|
|
|
/// @param[in] file_paths 字体文件路径
|
|
|
|
|
/// @throw kiwano::SystemException 创建失败时抛出
|
2020-02-09 18:41:59 +08:00
|
|
|
virtual void CreateFontCollection(Font& font, String const& file_path) = 0;
|
2020-01-21 10:09:55 +08:00
|
|
|
|
|
|
|
|
/// \~chinese
|
2020-02-10 17:32:04 +08:00
|
|
|
/// @brief 创建字体集内部资源
|
|
|
|
|
/// @param[out] font 字体
|
|
|
|
|
/// @param[in] res_arr 字体资源
|
|
|
|
|
/// @throw kiwano::SystemException 创建失败时抛出
|
2020-02-09 18:41:59 +08:00
|
|
|
virtual void CreateFontCollection(Font& font, Resource const& res) = 0;
|
2020-01-21 10:09:55 +08:00
|
|
|
|
|
|
|
|
/// \~chinese
|
2020-02-10 17:32:04 +08:00
|
|
|
/// @brief 创建文字格式内部资源
|
|
|
|
|
/// @param[out] layout 字体布局
|
|
|
|
|
/// @throw kiwano::SystemException 创建失败时抛出
|
2020-02-09 18:41:59 +08:00
|
|
|
virtual void CreateTextFormat(TextLayout& layout) = 0;
|
2020-01-21 10:09:55 +08:00
|
|
|
|
|
|
|
|
/// \~chinese
|
2020-02-10 17:32:04 +08:00
|
|
|
/// @brief 创建文字布局内部资源
|
|
|
|
|
/// @param[out] layout 字体布局
|
|
|
|
|
/// @throw kiwano::SystemException 创建失败时抛出
|
2020-02-09 18:41:59 +08:00
|
|
|
virtual void CreateTextLayout(TextLayout& layout) = 0;
|
2020-01-21 10:09:55 +08:00
|
|
|
|
|
|
|
|
/// \~chinese
|
2020-02-10 17:32:04 +08:00
|
|
|
/// @brief 创建线段形状内部资源
|
|
|
|
|
/// @param[out] shape 形状
|
|
|
|
|
/// @param[in] begin_pos 线段起点
|
|
|
|
|
/// @param[in] end_pos 线段终点
|
|
|
|
|
/// @throw kiwano::SystemException 创建失败时抛出
|
2020-02-09 18:41:59 +08:00
|
|
|
virtual void CreateLineShape(Shape& shape, Point const& begin_pos, Point const& end_pos) = 0;
|
2020-01-21 10:09:55 +08:00
|
|
|
|
|
|
|
|
/// \~chinese
|
2020-02-10 17:32:04 +08:00
|
|
|
/// @brief 创建矩形形状内部资源
|
|
|
|
|
/// @param[out] shape 形状
|
|
|
|
|
/// @param[in] rect 矩形大小
|
|
|
|
|
/// @throw kiwano::SystemException 创建失败时抛出
|
2020-02-09 18:41:59 +08:00
|
|
|
virtual void CreateRectShape(Shape& shape, Rect const& rect) = 0;
|
2020-01-21 10:09:55 +08:00
|
|
|
|
|
|
|
|
/// \~chinese
|
2020-02-10 17:32:04 +08:00
|
|
|
/// @brief 创建圆角矩形形状内部资源
|
|
|
|
|
/// @param[out] shape 形状
|
|
|
|
|
/// @param[in] rect 矩形大小
|
|
|
|
|
/// @param[in] radius 圆角半径
|
|
|
|
|
/// @throw kiwano::SystemException 创建失败时抛出
|
2020-02-09 18:41:59 +08:00
|
|
|
virtual void CreateRoundedRectShape(Shape& shape, Rect const& rect, Vec2 const& radius) = 0;
|
2020-01-21 10:09:55 +08:00
|
|
|
|
|
|
|
|
/// \~chinese
|
2020-02-10 17:32:04 +08:00
|
|
|
/// @brief 创建椭圆形状内部资源
|
|
|
|
|
/// @param[out] shape 形状
|
|
|
|
|
/// @param[in] center 椭圆圆心
|
|
|
|
|
/// @param[in] radius 椭圆半径
|
|
|
|
|
/// @throw kiwano::SystemException 创建失败时抛出
|
2020-02-09 18:41:59 +08:00
|
|
|
virtual void CreateEllipseShape(Shape& shape, Point const& center, Vec2 const& radius) = 0;
|
2020-01-21 10:09:55 +08:00
|
|
|
|
|
|
|
|
/// \~chinese
|
2020-02-10 17:32:04 +08:00
|
|
|
/// @brief 创建几何图形生成器内部资源
|
|
|
|
|
/// @param[out] sink 形状生成器
|
|
|
|
|
/// @throw kiwano::SystemException 创建失败时抛出
|
2020-02-09 18:41:59 +08:00
|
|
|
virtual void CreateShapeSink(ShapeSink& sink) = 0;
|
2020-01-21 10:09:55 +08:00
|
|
|
|
|
|
|
|
/// \~chinese
|
2020-02-10 17:32:04 +08:00
|
|
|
/// @brief 创建纯色画刷内部资源
|
|
|
|
|
/// @param[out] brush 画刷
|
|
|
|
|
/// @param[in] color 颜色
|
|
|
|
|
/// @throw kiwano::SystemException 创建失败时抛出
|
2020-02-09 18:41:59 +08:00
|
|
|
virtual void CreateBrush(Brush& brush, Color const& color) = 0;
|
2020-01-21 10:09:55 +08:00
|
|
|
|
|
|
|
|
/// \~chinese
|
2020-02-10 17:32:04 +08:00
|
|
|
/// @brief 创建线性渐变画刷内部资源
|
|
|
|
|
/// @param[out] brush 画刷
|
|
|
|
|
/// @param[in] style 线性渐变样式
|
|
|
|
|
/// @throw kiwano::SystemException 创建失败时抛出
|
2020-02-09 18:41:59 +08:00
|
|
|
virtual void CreateBrush(Brush& brush, LinearGradientStyle const& style) = 0;
|
2020-01-21 10:09:55 +08:00
|
|
|
|
|
|
|
|
/// \~chinese
|
2020-02-10 17:32:04 +08:00
|
|
|
/// @brief 创建径向渐变画刷内部资源
|
|
|
|
|
/// @param[out] brush 画刷
|
|
|
|
|
/// @param[in] style 径向渐变样式
|
|
|
|
|
/// @throw kiwano::SystemException 创建失败时抛出
|
2020-02-09 18:41:59 +08:00
|
|
|
virtual void CreateBrush(Brush& brush, RadialGradientStyle const& style) = 0;
|
2020-01-21 10:09:55 +08:00
|
|
|
|
|
|
|
|
/// \~chinese
|
2020-02-10 17:32:04 +08:00
|
|
|
/// @brief 创建线条样式内部资源
|
|
|
|
|
/// @param[out] stroke_style 线条样式
|
|
|
|
|
/// @param[in] cap 线段端点样式
|
|
|
|
|
/// @param[in] line_join 线段相交样式
|
|
|
|
|
/// @param[in] dash_array 虚线长度与间隙数组
|
|
|
|
|
/// @param[in] dash_size 虚线数组大小
|
|
|
|
|
/// @param[in] dash_offset 虚线偏移量
|
|
|
|
|
/// @throw kiwano::SystemException 创建失败时抛出
|
2020-02-09 18:41:59 +08:00
|
|
|
virtual void CreateStrokeStyle(StrokeStyle& stroke_style, CapStyle cap, LineJoinStyle line_join,
|
|
|
|
|
const float* dash_array, size_t dash_size, float dash_offset) = 0;
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
2020-02-10 17:32:04 +08:00
|
|
|
/// @brief 创建纹理渲染上下文
|
|
|
|
|
/// @param[in] desired_size 期望的输出大小
|
|
|
|
|
/// @return 纹理渲染上下文
|
|
|
|
|
/// @throw kiwano::SystemException 创建失败时抛出
|
2020-02-09 18:41:59 +08:00
|
|
|
virtual TextureRenderContextPtr CreateTextureRenderContext(const Size* desired_size = nullptr) = 0;
|
2020-01-21 10:09:55 +08:00
|
|
|
|
|
|
|
|
public:
|
2020-02-03 14:15:30 +08:00
|
|
|
/// \~chinese
|
2020-02-10 17:32:04 +08:00
|
|
|
/// @brief 开始渲染
|
2020-02-09 18:41:59 +08:00
|
|
|
virtual void BeginDraw() = 0;
|
2020-02-03 14:15:30 +08:00
|
|
|
|
|
|
|
|
/// \~chinese
|
2020-02-10 17:32:04 +08:00
|
|
|
/// @brief 结束渲染
|
2020-02-09 18:41:59 +08:00
|
|
|
virtual void EndDraw() = 0;
|
2020-02-03 14:15:30 +08:00
|
|
|
|
|
|
|
|
/// \~chinese
|
2020-02-10 17:32:04 +08:00
|
|
|
/// @brief 清除绘制内容
|
2020-02-09 18:41:59 +08:00
|
|
|
virtual void Clear() = 0;
|
2020-02-03 14:15:30 +08:00
|
|
|
|
|
|
|
|
/// \~chinese
|
2020-02-10 17:32:04 +08:00
|
|
|
/// @brief 将绘制内容呈现至窗口
|
|
|
|
|
/// @throw kiwano::SystemException 呈现失败时抛出
|
2020-02-09 18:41:59 +08:00
|
|
|
virtual void Present() = 0;
|
2020-02-03 14:15:30 +08:00
|
|
|
|
|
|
|
|
/// \~chinese
|
2020-02-10 17:32:04 +08:00
|
|
|
/// @brief 获取渲染上下文
|
2020-02-09 18:41:59 +08:00
|
|
|
virtual RenderContext& GetContext() = 0;
|
2020-02-03 14:15:30 +08:00
|
|
|
|
2020-01-21 10:09:55 +08:00
|
|
|
/// \~chinese
|
2020-02-10 17:32:04 +08:00
|
|
|
/// @brief 获取渲染输出大小
|
2020-02-09 18:41:59 +08:00
|
|
|
virtual Size GetOutputSize() const;
|
2020-01-21 10:09:55 +08:00
|
|
|
|
2020-02-09 18:41:59 +08:00
|
|
|
protected:
|
2020-01-21 10:09:55 +08:00
|
|
|
Renderer();
|
|
|
|
|
|
2020-02-09 18:41:59 +08:00
|
|
|
protected:
|
|
|
|
|
bool vsync_;
|
|
|
|
|
Color clear_color_;
|
|
|
|
|
Size output_size_;
|
2020-01-21 10:09:55 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/** @} */
|
|
|
|
|
|
2020-02-09 18:41:59 +08:00
|
|
|
inline Size Renderer::GetOutputSize() const
|
2020-01-21 10:09:55 +08:00
|
|
|
{
|
|
|
|
|
return output_size_;
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-09 18:41:59 +08:00
|
|
|
inline Color Renderer::GetClearColor() const
|
2020-01-21 10:09:55 +08:00
|
|
|
{
|
|
|
|
|
return clear_color_;
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-09 18:41:59 +08:00
|
|
|
inline void Renderer::SetVSyncEnabled(bool enabled)
|
2020-02-03 14:15:30 +08:00
|
|
|
{
|
2020-02-09 18:41:59 +08:00
|
|
|
vsync_ = enabled;
|
2020-02-03 14:15:30 +08:00
|
|
|
}
|
|
|
|
|
|
2020-02-09 18:41:59 +08:00
|
|
|
inline void Renderer::SetClearColor(const Color& color)
|
2020-01-21 10:09:55 +08:00
|
|
|
{
|
2020-02-09 18:41:59 +08:00
|
|
|
clear_color_ = color;
|
2020-01-21 10:09:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace kiwano
|