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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
#ifndef __ASURA_ENGINE_OPENGL_H__
#define __ASURA_ENGINE_OPENGL_H__
#include <stack>
#include <glad/glad.h>
#include <asura-utils/scripting/portable.hpp>
#include <asura-utils/math/rect.hpp>
#include <asura-utils/math/matrix44.h>
#include "matrix_stack.h"
namespace AsuraEngine
{
namespace Graphics
{
class Profiler;
class Shader;
class GPUBuffer;
enum MatrixMode
{
MATRIX_PROJECTION = 0,
MATRIX_MODELVIEW = 1,
};
///
/// OpenGLģһЩopengl״̬١ڱ༭രڻ£һڶӦһhwnd
/// һhdcԼopengl contextʹwglMakeCurrent(hdc, glc)ָǰ̶߳
/// Ⱦhdcopenglglcglм¼ľһ̵߳һڵһOpenGL
/// ĵ״ֶ̬֧Ⱦ
///
class OpenGL : public AEScripting::Portable<OpenGL>
{
public:
OpenGL();
~OpenGL();
///
/// ʼOpenGLIJڴOpenGL֮˺עOpenGLĵַ
///
bool Init(const AEMath::Recti& viewport);
void SetViewport(const AEMath::Recti viewport);
const AEMath::Recti& GetViewport();
void UseShader(Shader* shader);
void UnuseShader();
///
/// Matrix stackز
///
void SetMatrixMode(MatrixMode mode);
MatrixMode GetMatrixMode();
void PushMatrix();
void PopMatrix();
void LoadIdentity();
void Rotate(float angle, float x, float y, float z);
void Translate(float x, float y, float z);
void Scale(float x, float y, float z);
void Ortho(float l, float r, float b, float t, float n, float f);
AEMath::Matrix44& GetMatrix(MatrixMode mode);
uint GetMatrixDepth();
uint GetMatrixIndex();
///
/// ʾ
///
void WipeError();
bool HasError();
GLenum GetError();
///
/// OpenGL3.0Ժû任ӿڡshaderȲﱣһЩOpenGL״̬ע
/// ƺȫ̵ģҲ˵Asuraֶ֧߳ȾOpenGLĵĴʹһ
/// İһHDC\ϣڴض̴߳ģOpenGLҲһ
/// ض̡߳ͬһ̵߳IJͬHDC\ڿԹͬһOpenGLġΪ
/// дtextuer\shaderhandle
///
struct
{
Shader* shader; ///< ǰʹõshader
AEMath::Recti viewport; ///< ǰлHDC߱ڴСı߲ˢʱ䶯
MatrixStack matrix[2]; ///< 任
MatrixMode matrixMode; ///< ǰľ
} state;
private:
friend class Profiler;
LUAX_DECL_SINGLETON(OpenGL);
//----------------------------------------------------------------------------//
LUAX_DECL_ENUM(MatrixMode, 0);
LUAX_DECL_METHOD(_SetMatrixMode);
LUAX_DECL_METHOD(_GetMatrixMode);
LUAX_DECL_METHOD(_PushMatrix);
LUAX_DECL_METHOD(_PopMatrix);
LUAX_DECL_METHOD(_LoadIdentity);
LUAX_DECL_METHOD(_Rotate);
LUAX_DECL_METHOD(_Translate);
LUAX_DECL_METHOD(_Scale);
LUAX_DECL_METHOD(_Ortho);
LUAX_DECL_METHOD(_GetMatrixDepth);
LUAX_DECL_METHOD(_GetMatrixIndex);
LUAX_DECL_METHOD(_UseShader);
LUAX_DECL_METHOD(_UnuseShader);
//----------------------------------------------------------------------------//
};
///
/// OpenGL
///
extern OpenGL gl;
}
}
#endif
|