MxEngine
Renderer.h
1 // Copyright(c) 2019 - 2020, #Momo
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are met :
6 //
7 // 1. Redistributions of source code must retain the above copyright notice, this
8 // list of conditions and the following disclaimer.
9 //
10 // 2. Redistributions in binary form must reproduce the above copyright notice,
11 // this list of conditions and the following disclaimer in the documentation
12 // and /or other materials provided with the distribution.
13 //
14 // 3. Neither the name of the copyright holder nor the names of its
15 // contributors may be used to endorse or promote products derived from
16 // this software without specific prior written permission.
17 //
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 // DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 // DAMAGES(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 // OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 
29 #pragma once
30 
31 #include "Platform/GraphicAPI.h"
32 
33 enum class BlendFactor
34 {
35  NONE,
36  ONE_MINUS_SRC_COLOR,
37  SRC_ALPHA,
38  ONE_MINUS_SRC_ALPHA,
39  DST_ALPHA,
40  ONE_MINUS_DST_ALPHA,
41  DST_COLOR,
42  ONE_MINUS_DST_COLOR,
43  CONSTANT_COLOR,
44  ONE_MINUS_CONSTANT_COLOR,
45  CONSTANT_ALPHA,
46  ONE_MINUS_CONSTANT_ALPHA,
47 };
48 
49 namespace MxEngine
50 {
51  class Renderer
52  {
53  bool depthBufferEnabled = false;
54  unsigned int clearMask = 0;
55  public:
56  Renderer();
57 
58  void DrawTriangles(const VertexArray& vao, const IndexBuffer& ibo, const Shader& shader) const;
59  void DrawTriangles(const VertexArray& vao, size_t vertexCount, const Shader& shader) const;
60  void DrawTrianglesInstanced(const VertexArray& vao, const IndexBuffer& ibo, const Shader& shader, size_t count) const;
61  void DrawTrianglesInstanced(const VertexArray& vao, size_t vertexCount, const Shader& shader, size_t count) const;
62  void DrawLines(const VertexArray& vao, size_t vertexCount, const Shader& shader) const;
63  void DrawLines(const VertexArray& vao, const IndexBuffer& ibo, const Shader& shader) const;
64  void DrawLinesInstanced(const VertexArray& vao, const IndexBuffer& ibo, const Shader& shader, size_t count) const;
65  void DrawLinesInstanced(const VertexArray& vao, size_t vertexCount, const Shader& shader, size_t count) const;
66  void SetDefaultVertexAttribute(size_t index, float v) const;
67  void SetDefaultVertexAttribute(size_t index, const Vector2& vec) const;
68  void SetDefaultVertexAttribute(size_t index, const Vector3& vec) const;
69  void SetDefaultVertexAttribute(size_t index, const Vector4& vec) const;
70  void SetDefaultVertexAttribute(size_t index, const Matrix4x4& mat) const;
71  void SetDefaultVertexAttribute(size_t index, const Matrix3x3& mat) const;
72  void Clear() const;
73  void Flush() const;
74  void Finish() const;
75  void SetViewport(int x, int y, int width, int height) const;
76  Renderer& UseColorMask(bool r, bool g, bool b, bool a);
77  Renderer& UseDepthBufferMask(bool value = true);
78  Renderer& UseSampling(bool value = true);
79  Renderer& UseDepthBuffer(bool value = true);
80  Renderer& UseReversedDepth(bool value = true);
81  Renderer& UseCulling(bool value = true, bool counterClockWise = true, bool cullBack = true);
82  Renderer& UseClearColor(float r, float g, float b, float a = 0.0f);
83  Renderer& UseBlending(BlendFactor src, BlendFactor dist);
84  Renderer& UseAnisotropicFiltering(float factor);
85  Renderer& UseLineWidth(size_t width);
86  float GetLargestAnisotropicFactor() const;
87  };
88 }
Definition: Shader.h:38
Definition: VertexArray.h:36
Definition: IndexBuffer.h:35
Definition: Renderer.h:51
Definition: Application.cpp:49