MGL(Win32)
読み取り中…
検索中…
一致する文字列を見つけられません
mgl_renderer_2d.h
[詳解]
1// SPDX-License-Identifier: Zlib
2/* ------------------------------------------------------------------------- */
9/* ------------------------------------------------------------------------- */
10
11#ifndef INCGUARD_MGL_RENDERER_2D_H_1608429988
12#define INCGUARD_MGL_RENDERER_2D_H_1608429988
13
14#include <mgl/mgl_environment.h>
19
20namespace MGL::Render
21{
24{
25public:
26 /* ------------------------------------------------------------------------- */
30 /* ------------------------------------------------------------------------- */
31 Renderer2D() noexcept
32 : _renderer(RendererSet::GetInstance().GetRenderer2D())
33 {
34 }
35
36 /* ------------------------------------------------------------------------- */
41 /* ------------------------------------------------------------------------- */
42 [[nodiscard]] constexpr Renderer2DDelegate &GetRenderer() const noexcept
43 {
44 return _renderer;
45 }
46
47 /* ------------------------------------------------------------------------- */
52 /* ------------------------------------------------------------------------- */
53 [[nodiscard]] RendererType GetRendererType() const noexcept
54 {
55 return _renderer.GetRendererType();
56 }
57
58 /* ------------------------------------------------------------------------- */
63 /* ------------------------------------------------------------------------- */
64 void Clear(const Color &color) noexcept
65 {
66 _renderer.Clear(color);
67 }
68
69 /* ------------------------------------------------------------------------- */
76 /* ------------------------------------------------------------------------- */
77 void DrawLine(const Vector2 &start, const Vector2 &end, const Color &color) noexcept
78 {
79 _renderer.DrawLine(start, end, color);
80 }
81
82 /* ------------------------------------------------------------------------- */
89 /* ------------------------------------------------------------------------- */
90 void DrawRectangle(const Rectangle &rectangle, const Color &color, const DrawOption2D &option) noexcept
91 {
92 _renderer.DrawRectangle(rectangle, color, option);
93 }
94
95 /* ------------------------------------------------------------------------- */
101 /* ------------------------------------------------------------------------- */
102 void DrawRectangle(const Rectangle &rectangle, const Color &color) noexcept
103 {
104 DrawRectangle(rectangle, color, _option);
105 }
106
107 /* ------------------------------------------------------------------------- */
115 /* ------------------------------------------------------------------------- */
116 void DrawSprite(const Vector2 &position,
117 const Texture &texture,
118 const Rectangle &sourceRectangle,
119 const DrawOption2D &option) noexcept
120 {
121 if (!texture.IsValid() || texture.IsLoading())
122 {
123 return;
124 }
125
126 _renderer.DrawSprite(position, texture.GetResource(), sourceRectangle, option);
127 }
128
129 /* ------------------------------------------------------------------------- */
136 /* ------------------------------------------------------------------------- */
137 void DrawSprite(const Vector2 &position,
138 const Texture &texture,
139 const Rectangle &sourceRectangle) noexcept
140 {
141 DrawSprite(position, texture, sourceRectangle, _option);
142 }
143
144 /* ------------------------------------------------------------------------- */
151 /* ------------------------------------------------------------------------- */
152 void DrawSprite(const Vector2 &position,
153 const TextureWithBounds &textureWithBound,
154 const DrawOption2D &option) noexcept
155 {
156 DrawSprite(position, textureWithBound.GetTexture(), textureWithBound.GetBounds(), option);
157 }
158
159 /* ------------------------------------------------------------------------- */
165 /* ------------------------------------------------------------------------- */
166 void DrawSprite(const Vector2 &position, const TextureWithBounds &textureWithBound) noexcept
167 {
168 DrawSprite(position, textureWithBound.GetTexture(), textureWithBound.GetBounds());
169 }
170
171 /* ------------------------------------------------------------------------- */
178 /* ------------------------------------------------------------------------- */
179 bool SetRenderTarget(const Texture &renderTarget) noexcept
180 {
181 return _renderer.SetRenderTarget(renderTarget.GetResource());
182 }
183
184 /* ------------------------------------------------------------------------- */
189 /* ------------------------------------------------------------------------- */
190 [[nodiscard]] Texture GetRenderTarget() const noexcept
191 {
192 return {_renderer.GetRenderTarget()};
193 }
194
195 /* ------------------------------------------------------------------------- */
200 /* ------------------------------------------------------------------------- */
201 [[nodiscard]] Texture GetMainRenderTarget() const noexcept
202 {
203 return {_renderer.GetMainRenderTarget()};
204 }
205
206 /* ------------------------------------------------------------------------- */
210 /* ------------------------------------------------------------------------- */
211 void ResetRenderTarget() noexcept
212 {
214 }
215
216 /* ------------------------------------------------------------------------- */
222 /* ------------------------------------------------------------------------- */
223 void SetScissor(bool isEnabled, const Rectangle &rectangle = Rectangle()) noexcept
224 {
225 _renderer.SetScissor(isEnabled, rectangle);
226 }
227
228 /* ------------------------------------------------------------------------- */
233 /* ------------------------------------------------------------------------- */
234 constexpr DrawOption2D &GetDrawOption() noexcept
235 {
236 return _option;
237 }
238
239private:
240 Renderer2DDelegate &_renderer;
241 DrawOption2D _option;
242};
243} // namespace MGL::Render
244
245#endif // INCGUARD_MGL_RENDERER_2D_H_1608429988
246
247// vim: et ts=4 sw=4 sts=4
2D描画オプション
Definition mgl_draw_option_2d.h:23
MGL 2Dレンダラデリゲート
Definition mgl_renderer_2d_delegate.h:25
virtual void DrawRectangle(const Rectangle &rectangle, const Color &color, const DrawOption2D &option) noexcept=0
矩形の描画
virtual SharedTextureResource GetRenderTarget() const noexcept=0
現在のレンダーターゲットを取得
virtual void SetScissor(bool isEnabled, const Rectangle &rectangle) noexcept=0
シザーを設定
virtual void DrawSprite(const Vector2 &position, SharedTextureResource textureResource, const Rectangle &sourceRectangle, const DrawOption2D &option) noexcept=0
スプライトの描画
virtual RendererType GetRendererType() const noexcept=0
レンダラの種類を取得
virtual void DrawLine(const Vector2 &start, const Vector2 &end, const Color &color) noexcept=0
ラインの描画
virtual SharedTextureResource GetMainRenderTarget() const noexcept=0
メインレンダーターゲットを取得
virtual bool SetRenderTarget(SharedTextureResource renderTarget) noexcept=0
レンダーターゲットの設定
virtual void Clear(const Color &color) noexcept=0
描画領域のクリア
2Dレンダラクラス
Definition mgl_renderer_2d.h:24
void DrawLine(const Vector2 &start, const Vector2 &end, const Color &color) noexcept
ラインの描画
Definition mgl_renderer_2d.h:77
void DrawRectangle(const Rectangle &rectangle, const Color &color, const DrawOption2D &option) noexcept
矩形の描画
Definition mgl_renderer_2d.h:90
void DrawSprite(const Vector2 &position, const Texture &texture, const Rectangle &sourceRectangle, const DrawOption2D &option) noexcept
スプライトの描画
Definition mgl_renderer_2d.h:116
Renderer2D() noexcept
コンストラクタ
Definition mgl_renderer_2d.h:31
Texture GetMainRenderTarget() const noexcept
メインレンダーターゲットを取得
Definition mgl_renderer_2d.h:201
constexpr Renderer2DDelegate & GetRenderer() const noexcept
レンダラ本体を取得
Definition mgl_renderer_2d.h:42
void SetScissor(bool isEnabled, const Rectangle &rectangle=Rectangle()) noexcept
シザーの設定
Definition mgl_renderer_2d.h:223
void DrawSprite(const Vector2 &position, const TextureWithBounds &textureWithBound, const DrawOption2D &option) noexcept
スプライトの描画
Definition mgl_renderer_2d.h:152
constexpr DrawOption2D & GetDrawOption() noexcept
描画オプションの取得
Definition mgl_renderer_2d.h:234
void DrawSprite(const Vector2 &position, const TextureWithBounds &textureWithBound) noexcept
スプライトの描画
Definition mgl_renderer_2d.h:166
void ResetRenderTarget() noexcept
デフォルトのレンダーターゲットに戻す
Definition mgl_renderer_2d.h:211
bool SetRenderTarget(const Texture &renderTarget) noexcept
レンダーターゲットの設定
Definition mgl_renderer_2d.h:179
void DrawSprite(const Vector2 &position, const Texture &texture, const Rectangle &sourceRectangle) noexcept
スプライトの描画
Definition mgl_renderer_2d.h:137
RendererType GetRendererType() const noexcept
レンダラの種類を取得
Definition mgl_renderer_2d.h:53
void Clear(const Color &color) noexcept
描画領域のクリア
Definition mgl_renderer_2d.h:64
Texture GetRenderTarget() const noexcept
現在のレンダーターゲットを取得
Definition mgl_renderer_2d.h:190
void DrawRectangle(const Rectangle &rectangle, const Color &color) noexcept
矩形の描画
Definition mgl_renderer_2d.h:102
MGL レンダラセット
Definition mgl_renderer_set.h:24
MGL テクスチャクラス
Definition mgl_texture.h:20
領域付きテクスチャクラス
Definition mgl_texture_with_bounds.h:22
MGL 環境定義
RendererType
レンダラタイプの型
Definition mgl_render_types.h:21
MGL 2Dレンダラ デリゲート
MGL レンダラセット
MGL テクスチャ
MGL 領域付きテクスチャ
色情報
Definition mgl_color.h:22
矩形
Definition mgl_rectangle.h:20
2Dベクトル
Definition mgl_vector2.h:23