2019-04-11 14:40:54 +08:00
|
|
|
|
// Copyright (c) 2016-2018 Kiwano - Nomango
|
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:
|
|
|
|
|
|
//
|
|
|
|
|
|
// The above copyright notice and this permission notice shall be included in
|
|
|
|
|
|
// all copies or substantial portions of the Software.
|
|
|
|
|
|
//
|
|
|
|
|
|
// 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
|
|
|
|
|
|
#include "../base/Component.h"
|
2019-08-18 10:23:54 +08:00
|
|
|
|
#include "win32/FontCollectionLoader.h"
|
2019-08-16 00:50:54 +08:00
|
|
|
|
#include "RenderTarget.h"
|
|
|
|
|
|
#include "GifImage.h"
|
2019-07-30 00:41:06 +08:00
|
|
|
|
|
|
|
|
|
|
#if defined(KGE_USE_DIRECTX10)
|
|
|
|
|
|
# include "D3D10DeviceResources.h"
|
|
|
|
|
|
#else
|
2019-08-18 10:23:54 +08:00
|
|
|
|
# include "win32/D3D11DeviceResources.h"
|
2019-07-30 00:41:06 +08:00
|
|
|
|
#endif
|
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
|
|
|
|
|
|
|
|
|
|
#if defined(KGE_USE_DIRECTX10)
|
|
|
|
|
|
typedef ID3D10DeviceResources ID3DDeviceResources;
|
|
|
|
|
|
#else
|
|
|
|
|
|
typedef ID3D11DeviceResources ID3DDeviceResources;
|
|
|
|
|
|
#endif
|
2019-03-31 01:37:06 +08:00
|
|
|
|
|
2019-08-23 13:00:43 +08:00
|
|
|
|
// <20><>Ⱦ<EFBFBD><C8BE><EFBFBD><EFBFBD>
|
|
|
|
|
|
struct RenderConfig
|
|
|
|
|
|
{
|
|
|
|
|
|
Color clear_color; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ
|
|
|
|
|
|
bool vsync; // <20><>ֱͬ<D6B1><CDAC>
|
|
|
|
|
|
|
|
|
|
|
|
RenderConfig(
|
|
|
|
|
|
Color clear_color = Color::Black,
|
|
|
|
|
|
bool vsync = true
|
|
|
|
|
|
);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2019-08-21 16:33:41 +08:00
|
|
|
|
|
2019-09-09 16:20:40 +08:00
|
|
|
|
// <20><>Ⱦ<EFBFBD><C8BE>
|
2019-04-11 14:40:54 +08:00
|
|
|
|
class KGE_API Renderer
|
2019-03-31 01:37:06 +08:00
|
|
|
|
: public Singleton<Renderer>
|
2019-09-10 13:17:47 +08:00
|
|
|
|
, public RenderComponent
|
|
|
|
|
|
, public EventComponent
|
2019-08-16 00:50:54 +08:00
|
|
|
|
, public RenderTarget
|
2019-03-31 01:37:06 +08:00
|
|
|
|
{
|
2019-04-11 14:40:54 +08:00
|
|
|
|
KGE_DECLARE_SINGLETON(Renderer);
|
2019-03-31 01:37:06 +08:00
|
|
|
|
|
2019-08-15 11:22:51 +08:00
|
|
|
|
public:
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ
|
|
|
|
|
|
void SetClearColor(
|
|
|
|
|
|
Color const& clear_color
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>رմ<D8B1>ֱͬ<D6B1><CDAC>
|
|
|
|
|
|
void SetVSyncEnabled(
|
|
|
|
|
|
bool enabled
|
|
|
|
|
|
);
|
|
|
|
|
|
|
2019-03-31 01:37:06 +08:00
|
|
|
|
public:
|
2019-08-21 16:33:41 +08:00
|
|
|
|
void CreateTexture(
|
|
|
|
|
|
Texture& texture,
|
2019-08-18 17:49:13 +08:00
|
|
|
|
String const& file_path
|
|
|
|
|
|
);
|
|
|
|
|
|
|
2019-08-21 16:33:41 +08:00
|
|
|
|
void CreateTexture(
|
|
|
|
|
|
Texture& texture,
|
2019-08-23 13:00:43 +08:00
|
|
|
|
Resource const& resource
|
2019-08-16 00:50:54 +08:00
|
|
|
|
);
|
|
|
|
|
|
|
2019-08-18 17:49:13 +08:00
|
|
|
|
void CreateGifImage(
|
2019-08-23 13:00:43 +08:00
|
|
|
|
GifImage& gif,
|
2019-08-18 17:49:13 +08:00
|
|
|
|
String const& file_path
|
|
|
|
|
|
);
|
|
|
|
|
|
|
2019-08-16 00:50:54 +08:00
|
|
|
|
void CreateGifImage(
|
2019-08-23 13:00:43 +08:00
|
|
|
|
GifImage& gif,
|
|
|
|
|
|
Resource const& resource
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
void CreateGifImageFrame(
|
|
|
|
|
|
GifImage::Frame& frame,
|
|
|
|
|
|
GifImage const& gif,
|
|
|
|
|
|
UInt32 frame_index
|
2019-03-31 01:37:06 +08:00
|
|
|
|
);
|
|
|
|
|
|
|
2019-08-18 17:49:13 +08:00
|
|
|
|
void CreateFontCollection(
|
2019-08-18 10:23:54 +08:00
|
|
|
|
FontCollection& collection,
|
2019-08-18 17:49:13 +08:00
|
|
|
|
Vector<String> const& file_paths
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
void CreateFontCollection(
|
|
|
|
|
|
FontCollection& collection,
|
|
|
|
|
|
Vector<Resource> const& res_arr
|
2019-08-18 10:23:54 +08:00
|
|
|
|
);
|
|
|
|
|
|
|
2019-08-15 11:22:51 +08:00
|
|
|
|
void CreateTextFormat(
|
|
|
|
|
|
TextFormat& format,
|
|
|
|
|
|
Font const& font
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
void CreateTextLayout(
|
|
|
|
|
|
TextLayout& layout,
|
|
|
|
|
|
String const& text,
|
|
|
|
|
|
TextFormat const& format
|
|
|
|
|
|
);
|
|
|
|
|
|
|
2019-08-14 21:38:37 +08:00
|
|
|
|
void CreateLineGeometry(
|
|
|
|
|
|
Geometry& geo,
|
|
|
|
|
|
Point const& begin_pos,
|
|
|
|
|
|
Point const& end_pos
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
void CreateRectGeometry(
|
|
|
|
|
|
Geometry& geo,
|
|
|
|
|
|
Rect const& rect
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
void CreateRoundedRectGeometry(
|
|
|
|
|
|
Geometry& geo,
|
|
|
|
|
|
Rect const& rect,
|
|
|
|
|
|
Vec2 const& radius
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
void CreateEllipseGeometry(
|
|
|
|
|
|
Geometry& geo,
|
|
|
|
|
|
Point const& center,
|
|
|
|
|
|
Vec2 const& radius
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
void CreatePathGeometrySink(
|
|
|
|
|
|
GeometrySink& sink
|
|
|
|
|
|
);
|
|
|
|
|
|
|
2019-08-21 16:33:41 +08:00
|
|
|
|
void CreateTextureRenderTarget(
|
|
|
|
|
|
TextureRenderTarget& render_target
|
2019-03-31 01:37:06 +08:00
|
|
|
|
);
|
|
|
|
|
|
|
2019-09-09 22:02:53 +08:00
|
|
|
|
void CreateSolidBrush(
|
|
|
|
|
|
Brush& brush,
|
|
|
|
|
|
Color const& color
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
void CreateLinearGradientBrush(
|
|
|
|
|
|
Brush& brush,
|
|
|
|
|
|
Point const& begin,
|
|
|
|
|
|
Point const& end,
|
|
|
|
|
|
Vector<GradientStop> const& stops,
|
|
|
|
|
|
GradientExtendMode extend_mode
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
void CreateRadialGradientBrush(
|
|
|
|
|
|
Brush& brush,
|
|
|
|
|
|
Point const& center,
|
|
|
|
|
|
Vec2 const& offset,
|
|
|
|
|
|
Vec2 const& radius,
|
|
|
|
|
|
Vector<GradientStop> const& stops,
|
|
|
|
|
|
GradientExtendMode extend_mode
|
|
|
|
|
|
);
|
|
|
|
|
|
|
2019-07-30 13:32:10 +08:00
|
|
|
|
public:
|
2019-08-23 13:00:43 +08:00
|
|
|
|
void Init(RenderConfig const& config);
|
|
|
|
|
|
|
2019-08-12 14:51:54 +08:00
|
|
|
|
void SetupComponent() override;
|
2019-07-30 13:32:10 +08:00
|
|
|
|
|
|
|
|
|
|
void DestroyComponent() override;
|
|
|
|
|
|
|
|
|
|
|
|
void BeforeRender() override;
|
|
|
|
|
|
|
|
|
|
|
|
void AfterRender() override;
|
|
|
|
|
|
|
2019-08-18 22:49:44 +08:00
|
|
|
|
void HandleMessage(HWND hwnd, UInt32 msg, WPARAM wparam, LPARAM lparam) override;
|
2019-07-30 13:32:10 +08:00
|
|
|
|
|
2019-03-31 01:37:06 +08:00
|
|
|
|
public:
|
2019-07-30 00:41:06 +08:00
|
|
|
|
inline HWND GetTargetWindow() const { return hwnd_; }
|
|
|
|
|
|
|
|
|
|
|
|
inline Size const& GetOutputSize() const { return output_size_; }
|
2019-03-31 01:37:06 +08:00
|
|
|
|
|
2019-08-20 23:51:12 +08:00
|
|
|
|
inline Color const& GetClearColor() const { return clear_color_; }
|
|
|
|
|
|
|
2019-08-13 21:16:38 +08:00
|
|
|
|
inline ID2DDeviceResources* GetD2DDeviceResources() const { KGE_ASSERT(d2d_res_); return d2d_res_.get(); }
|
2019-03-31 01:37:06 +08:00
|
|
|
|
|
2019-08-13 21:16:38 +08:00
|
|
|
|
inline ID3DDeviceResources* GetD3DDeviceResources() const { KGE_ASSERT(d3d_res_); return d3d_res_.get(); }
|
2019-03-31 01:37:06 +08:00
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
Renderer();
|
|
|
|
|
|
|
|
|
|
|
|
~Renderer();
|
|
|
|
|
|
|
|
|
|
|
|
HRESULT CreateDeviceResources();
|
|
|
|
|
|
|
|
|
|
|
|
HRESULT HandleDeviceLost();
|
|
|
|
|
|
|
2019-08-20 23:51:12 +08:00
|
|
|
|
void ResizeTarget(UInt32 width, UInt32 height);
|
|
|
|
|
|
|
2019-08-14 08:52:01 +08:00
|
|
|
|
private:
|
2019-08-20 23:51:12 +08:00
|
|
|
|
bool vsync_;
|
|
|
|
|
|
HWND hwnd_;
|
|
|
|
|
|
Color clear_color_;
|
|
|
|
|
|
Size output_size_;
|
2019-03-31 01:37:06 +08:00
|
|
|
|
|
2019-07-30 00:41:06 +08:00
|
|
|
|
ComPtr<ID2DDeviceResources> d2d_res_;
|
|
|
|
|
|
ComPtr<ID3DDeviceResources> d3d_res_;
|
2019-03-31 01:37:06 +08:00
|
|
|
|
ComPtr<ID2D1DrawingStateBlock> drawing_state_block_;
|
2019-08-18 10:23:54 +08:00
|
|
|
|
|
|
|
|
|
|
ComPtr<IFontCollectionLoader> font_collection_loader_;
|
|
|
|
|
|
ComPtr<IResourceFontFileLoader> res_font_file_loader_;
|
|
|
|
|
|
ComPtr<IResourceFontCollectionLoader> res_font_collection_loader_;
|
2019-03-31 01:37:06 +08:00
|
|
|
|
};
|
|
|
|
|
|
}
|