Magic_Game/src/kiwano/render/Renderer.h

242 lines
6.8 KiB
C
Raw Normal View History

2019-04-11 14:40:54 +08:00
// Copyright (c) 2016-2018 Kiwano - Nomango
2020-01-21 10:09:55 +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
//
// 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
//
// 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-04-11 14:40:54 +08:00
namespace kiwano
{
2019-07-30 00:41:06 +08:00
2020-01-21 10:09:55 +08:00
/**
* \~chinese
* \defgroup Render <EFBFBD><EFBFBD>Ⱦ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
/**
* \addtogroup Render
* @{
*/
/**
* \~chinese
* @brief <EFBFBD><EFBFBD>Ⱦ<EFBFBD><EFBFBD>
*/
class KGE_API Renderer : public EventComponent
2020-01-21 10:09:55 +08:00
{
public:
/// \~chinese
/// @brief <20><>ȡʵ<C8A1><CAB5>
static Renderer& GetInstance();
2020-01-21 10:09:55 +08:00
/// \~chinese
/// @brief <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ
virtual Color GetClearColor() const;
2020-01-21 10:09:55 +08:00
/// \~chinese
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ
virtual void SetClearColor(Color const& clear_color);
2020-01-21 10:09:55 +08:00
/// \~chinese
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>رմ<D8B1>ֱͬ<D6B1><CDAC>
virtual void SetVSyncEnabled(bool enabled);
2020-01-21 10:09:55 +08:00
/// \~chinese
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
/// @param[out] texture <20><><EFBFBD><EFBFBD>
/// @param[in] file_path ͼƬ·<C6AC><C2B7>
virtual void CreateTexture(Texture& texture, String const& file_path) = 0;
2020-01-21 10:09:55 +08:00
/// \~chinese
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
/// @param[out] texture <20><><EFBFBD><EFBFBD>
/// @param[in] resource ͼƬ<CDBC><C6AC>Դ
virtual void CreateTexture(Texture& texture, Resource const& resource) = 0;
2020-01-21 10:09:55 +08:00
/// \~chinese
/// @brief <20><><EFBFBD><EFBFBD>GIFͼ<46><CDBC>
/// @param[out] gif GIFͼ<46><CDBC>
/// @param[in] file_path ͼƬ·<C6AC><C2B7>
virtual void CreateGifImage(GifImage& gif, String const& file_path) = 0;
2020-01-21 10:09:55 +08:00
/// \~chinese
/// @brief <20><><EFBFBD><EFBFBD>GIFͼ<46><CDBC>
/// @param[out] gif GIFͼ<46><CDBC>
/// @param[in] resource ͼƬ<CDBC><C6AC>Դ
virtual void CreateGifImage(GifImage& gif, Resource const& resource) = 0;
2020-01-21 10:09:55 +08:00
/// \~chinese
/// @brief <20><><EFBFBD><EFBFBD>GIFͼ<46><CDBC>֡
/// @param[out] frame GIFͼ<46><CDBC>֡
/// @param[in] gif GIFͼ<46><CDBC>
/// @param[in] frame_index ֡<>±<EFBFBD>
virtual void CreateGifImageFrame(GifImage::Frame& frame, GifImage const& gif, size_t frame_index) = 0;
2020-01-21 10:09:55 +08:00
/// \~chinese
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
/// @param[out] font <20><><EFBFBD><EFBFBD>
/// @param[in] file_paths <20><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>·<EFBFBD><C2B7>
virtual void CreateFontCollection(Font& font, String const& file_path) = 0;
2020-01-21 10:09:55 +08:00
/// \~chinese
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
/// @param[out] font <20><><EFBFBD><EFBFBD>
/// @param[in] res_arr <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ
virtual void CreateFontCollection(Font& font, Resource const& res) = 0;
2020-01-21 10:09:55 +08:00
/// \~chinese
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD>ʽ
/// @param[out] layout <20><><EFBFBD><EFBFBD><E5B2BC>
virtual void CreateTextFormat(TextLayout& layout) = 0;
2020-01-21 10:09:55 +08:00
/// \~chinese
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֲ<EFBFBD><D6B2><EFBFBD>
/// @param[out] layout <20><><EFBFBD><EFBFBD><E5B2BC>
virtual void CreateTextLayout(TextLayout& layout) = 0;
2020-01-21 10:09:55 +08:00
/// \~chinese
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD>߶<EFBFBD><DFB6><EFBFBD>״
/// @param[out] geo <20><>״
/// @param[in] begin_pos <20>߶<EFBFBD><DFB6><EFBFBD><EFBFBD><EFBFBD>
/// @param[in] end_pos <20>߶<EFBFBD><DFB6>յ<EFBFBD>
virtual void CreateLineShape(Shape& shape, Point const& begin_pos, Point const& end_pos) = 0;
2020-01-21 10:09:55 +08:00
/// \~chinese
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״
/// @param[out] geo <20><>״
/// @param[in] rect <20><><EFBFBD>δ<EFBFBD>С
virtual void CreateRectShape(Shape& shape, Rect const& rect) = 0;
2020-01-21 10:09:55 +08:00
/// \~chinese
/// @brief <20><><EFBFBD><EFBFBD>Բ<EFBFBD>Ǿ<EFBFBD><C7BE><EFBFBD><EFBFBD><EFBFBD>״
/// @param[out] geo <20><>״
/// @param[in] rect <20><><EFBFBD>δ<EFBFBD>С
/// @param[in] radius Բ<>ǰ뾶
virtual void CreateRoundedRectShape(Shape& shape, Rect const& rect, Vec2 const& radius) = 0;
2020-01-21 10:09:55 +08:00
/// \~chinese
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Բ<EFBFBD><D4B2>״
/// @param[out] geo <20><>״
/// @param[in] center <20><>ԲԲ<D4B2><D4B2>
/// @param[in] radius <20><>Բ<EFBFBD>
virtual void CreateEllipseShape(Shape& shape, Point const& center, Vec2 const& radius) = 0;
2020-01-21 10:09:55 +08:00
/// \~chinese
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
/// @param[out] sink <20><>״<EFBFBD><D7B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
virtual void CreateShapeSink(ShapeSink& sink) = 0;
2020-01-21 10:09:55 +08:00
/// \~chinese
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ<EFBFBD><C9AB>ˢ
/// @param[out] brush <20><>ˢ
/// @param[in] color <20><>ɫ
virtual void CreateBrush(Brush& brush, Color const& color) = 0;
2020-01-21 10:09:55 +08:00
/// \~chinese
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Խ<EFBFBD><D4BD>仭ˢ
/// @param[out] brush <20><>ˢ
/// @param[in] style <20><><EFBFBD>Խ<EFBFBD><D4BD><EFBFBD><EFBFBD><EFBFBD>ʽ
virtual void CreateBrush(Brush& brush, LinearGradientStyle const& style) = 0;
2020-01-21 10:09:55 +08:00
/// \~chinese
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>򽥱仭ˢ
/// @param[out] brush <20><>ˢ
/// @param[in] style <20><><EFBFBD>򽥱<EFBFBD><F2BDA5B1><EFBFBD>ʽ
virtual void CreateBrush(Brush& brush, RadialGradientStyle const& style) = 0;
2020-01-21 10:09:55 +08:00
/// \~chinese
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ
/// @param[out] stroke_style <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ
/// @param[in] cap <20>߶ζ˵<CEB6><CBB5><EFBFBD>ʽ
/// @param[in] line_join <20>߶<EFBFBD><DFB6><EFBFBD><E0BDBB>ʽ
/// @param[in] dash_array <20><><EFBFBD>߳<EFBFBD><DFB3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD>
/// @param[in] dash_size <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С
/// @param[in] dash_offset <20><><EFBFBD><EFBFBD>ƫ<EFBFBD><C6AB><EFBFBD><EFBFBD>
virtual void CreateStrokeStyle(StrokeStyle& stroke_style, CapStyle cap, LineJoinStyle line_join,
const float* dash_array, size_t dash_size, float dash_offset) = 0;
/// \~chinese
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ⱦ<EFBFBD><C8BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
/// @param[in] desired_size <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С
/// @return <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ⱦ<EFBFBD><C8BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
virtual TextureRenderContextPtr CreateTextureRenderContext(const Size* desired_size = nullptr) = 0;
2020-01-21 10:09:55 +08:00
public:
/// \~chinese
/// @brief <20><>ʼ<EFBFBD><CABC>Ⱦ
virtual void BeginDraw() = 0;
/// \~chinese
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ⱦ
virtual void EndDraw() = 0;
/// \~chinese
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
virtual void Clear() = 0;
/// \~chinese
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
virtual void Present() = 0;
/// \~chinese
/// @brief <20><>ȡ<EFBFBD><C8A1>Ⱦ<EFBFBD><C8BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
virtual RenderContext& GetContext() = 0;
2020-01-21 10:09:55 +08:00
/// \~chinese
/// @brief <20><>ȡ<EFBFBD><C8A1>Ⱦ<EFBFBD><C8BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С
virtual Size GetOutputSize() const;
2020-01-21 10:09:55 +08:00
protected:
2020-01-21 10:09:55 +08:00
Renderer();
protected:
bool vsync_;
Color clear_color_;
Size output_size_;
2020-01-21 10:09:55 +08:00
};
/** @} */
inline Size Renderer::GetOutputSize() const
2020-01-21 10:09:55 +08:00
{
return output_size_;
}
inline Color Renderer::GetClearColor() const
2020-01-21 10:09:55 +08:00
{
return clear_color_;
}
inline void Renderer::SetVSyncEnabled(bool enabled)
{
vsync_ = enabled;
}
inline void Renderer::SetClearColor(const Color& color)
2020-01-21 10:09:55 +08:00
{
clear_color_ = color;
2020-01-21 10:09:55 +08:00
}
} // namespace kiwano