summaryrefslogtreecommitdiff
path: root/source/modules/asura-core/graphics/gl.cpp
blob: 47476a7102a9a1cc9917f1777627f4ca69892a12 (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
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
#include <asura-utils/type.h>

#include "../core_config.h"

#include "gl.h"
#include "shader.h"

using namespace AEMath;

namespace AsuraEngine
{
	namespace Graphics
	{

#if ASURA_DEBUG
		static bool _instantiated = false;
#endif

		OpenGL gl;

		OpenGL::OpenGL()
		{
#if ASURA_DEBUG 
			ASSERT(!_instantiated);
			_instantiated = true;
#endif
		}

		OpenGL::~OpenGL()
		{
		}

		void OpenGL::SetViewport(const Recti v)
		{
			glViewport(v.x, v.y, v.w, v.h);
			state.viewport = v; 
		}

		Recti OpenGL::GetViewport()
		{
			return state.viewport;
		}

		void OpenGL::UseShader(Shader* shader)
		{
			glUseProgram(shader->GetGLProgramHandle());
			state.shader = shader;
		}

		void OpenGL::UnuseShader()
		{
			state.shader = nullptr;
		}

		//------------------------------------------------------------------------------//

		void OpenGL::SetMatrixMode(MatrixMode mode)
		{
			state.matrixMode = mode;
		}

		MatrixMode OpenGL::GetMatrixMode()
		{
			return state.matrixMode; 
		}

		void OpenGL::PushMatrix()
		{
			state.matrix[state.matrixMode].Push();
		}

		void OpenGL::PopMatrix()
		{
			state.matrix[state.matrixMode].Pop();
		}

		void OpenGL::LoadIdentity()
		{
			state.matrix[state.matrixMode].LoadIdentity();
		}

		void OpenGL::Rotate(float angle, float x, float y, float z)
		{
			state.matrix[state.matrixMode].Rotate(angle, x, y, z);
		}

		void OpenGL::Translate(float x, float y, float z)
		{
			state.matrix[state.matrixMode].Translate(x, y, z);
		}

		void OpenGL::Scale(float x, float y, float z)
		{
			state.matrix[state.matrixMode].Scale(x, y, z);
		}

		void OpenGL::Ortho(float l, float r, float b, float t, float n, float f)
		{
			state.matrix[state.matrixMode].Ortho(l, r, b, t, n, f);
		}

		AEMath::Matrix44& OpenGL::GetMatrix(MatrixMode mode)
		{
			return state.matrix[state.matrixMode].GetTop();
		}

		uint OpenGL::GetMatrixDepth()
		{
			return state.matrix[state.matrixMode].GetCapacity();
		}

		uint OpenGL::GetMatrixIndex()
		{
			return state.matrix[state.matrixMode].GetTopIndex();
		}

		//------------------------------------------------------------------------------//

	}
}