diff options
author | chai <chaifix@163.com> | 2021-12-13 00:07:19 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2021-12-13 00:07:19 +0800 |
commit | 60cbbdec07ab7a5636eac5b3c024ae44e937f4d4 (patch) | |
tree | b2c7b0a868f18159dbc43d8954e1bd7668549a88 /Client/Source/Graphics/GfxDevice.h |
+init
Diffstat (limited to 'Client/Source/Graphics/GfxDevice.h')
-rw-r--r-- | Client/Source/Graphics/GfxDevice.h | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/Client/Source/Graphics/GfxDevice.h b/Client/Source/Graphics/GfxDevice.h new file mode 100644 index 0000000..d81d574 --- /dev/null +++ b/Client/Source/Graphics/GfxDevice.h @@ -0,0 +1,109 @@ +#ifndef DEVICE_H +#define DEVICE_H +#include "../Math/Math.h" + +#include "../Utilities/Type.h" +#include "../Utilities/Assert.h" +#include "../Graphics/Shader.h" +#include "../Math/Vector2.hpp" +#include "../Math/Vector3.hpp" +#include "../Math/Vector4.hpp" +#include "../Math/Matrix44.h" + +#include "Shader.h" +#include "Texture.h" +#include "DeviceDefine.h" +#include "VertexBuffer.h" +#include "DynamicVertexBuffer.h" +#include "Color.h" + +struct GfxDeviceSetting +{ + ETextureFilterMode filterMode; // 默认的贴图过滤模式 + ETextureWrapMode wrapMode; // 默认的贴图平铺模式 +}; + +// 当前绑定的shader +struct ShaderState +{ + Shader* shader; + operator bool() + { + return shader != NULL; + } + GLuint GetID() { + if (shader == nullptr) + return 0; + GLint id = shader->GetID(); + return id; + } +}; + +// 对渲染相关API的封装 +class GfxDevice +{ +public: + GfxDevice(); + ~GfxDevice(); + + void Initialize(GfxDeviceSetting setting); + + void Enable(EDeviceEnable enabled); + void Disable(EDeviceEnable enabled); + void IsEnable(uint flag); + + void SetDepthTest(EDepthTest testing); + void SetCullFace(ECullFace face); + void SetStencilMask(byte stencilMask); + void SetStencilOp(EStencilOp op); + + void SetAntiAliasing(int level = 0); + + void Clear(int clearFlag); + + void UseShader(Shader* shader, int idx); + void UnuseShader(); + void SetUniformVec2(const char* name, Vector2f vec2); + void SetUniformVec3(const char* name, Vector3f vec3); + void SetUniformVec4(const char* name, Vector4f vec4); + void SetUniformMat4(const char* name, Matrix44 mat4); + void SetUniformTexture(const char* name, Texture* texture); + + void BeginFrame(); + void EndFrame(); + void PresentFrame(); + + bool IsInsideFrame(); + + DynamicVertexBuffer* GetSharedVBO() { return &m_DynamicVBO; } + + GET_SET(Color, ClearColor, m_ClearColor); + GET_SET(ETextureFilterMode, DefaultFilterMode, m_DefaultFilterMode); + GET_SET(ETextureWrapMode, DefaultWrapMode, m_DefaultWrapMode); + +private: + bool m_IsInsideFrame; + + // 渲染状态 + uint m_EnableFlag; + Color m_ClearColor; + EDepthTest m_DepthTest; + EStencilTest m_StencilTest; + EStencilOp m_StencilOp; + byte m_StencilMask; + + ShaderState m_Shader; // 当前绑定的shader + + // 贴图默认设置 + ETextureFilterMode m_DefaultFilterMode; + ETextureWrapMode m_DefaultWrapMode; + + DynamicVertexBuffer m_DynamicVBO; // 共享的VBO,用来做立即渲染 + +}; + +extern GfxDevice g_GfxDevice; + +#define g_SharedVBO (*g_GfxDevice.GetSharedVBO()) + +#endif
\ No newline at end of file |