summaryrefslogtreecommitdiff
path: root/Runtime/Graphics/GfxDevice.h
blob: 0931eaeae9bd36df7c4a3fea2cbfc023fc45252d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#ifndef DEVICE_H
#define DEVICE_H

#include "../Utilities/NonCopyable.h"
#include "../Utilities/Type.h"
#include "../Utilities/Assert.h"

#include "Texture.h"
#include "DeviceDefine.h"
#include "VertexBuffer.h"
#include "SharedVertexBuffer.h"
#include "Color.h"

struct GfxDeviceSetting 
{
	ETextureFilterMode filterMode; // 默认的贴图过滤模式 
	ETextureWrapMode wrapMode;     // 默认的贴图平铺模式
};

// 对渲染相关API的封装
class GfxDevice : public NonCopyable
{
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 BeginFrame();
	void EndFrame();
	void PresentFrame();

	bool IsInsideFrame();

	SharedVertexBuffer* GetSharedVBO() { return &m_SharedVBO; }

	GET_SET(Internal::Color, ClearColor, m_ClearColor);
	GET_SET(ETextureFilterMode, DefaultFilterMode, m_DefaultFilterMode);
	GET_SET(ETextureWrapMode, DefaultWrapMode, m_DefaultWrapMode);

private: 
	bool m_IsInsideFrame;

	// 渲染状态
	uint            m_EnableFlag;
	Internal::Color m_ClearColor;
	EDepthTest      m_DepthTest;
	EStencilTest    m_StencilTest;
	EStencilOp      m_StencilOp;
	byte            m_StencilMask;

	// 贴图默认设置
	ETextureFilterMode m_DefaultFilterMode;
	ETextureWrapMode m_DefaultWrapMode;

	SharedVertexBuffer m_SharedVBO; // 共享的VBO,用来做立即渲染

};

extern GfxDevice g_GfxDevice;

#define g_SharedVBO (*g_GfxDevice.GetSharedVBO())

#endif