diff options
author | chai <chaifix@163.com> | 2019-06-06 00:11:18 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2019-06-06 00:11:18 +0800 |
commit | 88b882ed0b432c6aff2063213e2f793a36dd25f7 (patch) | |
tree | 5fe5d5334050e1a1146aa63e61e88aa2f5170727 /source/modules/asura-core/graphics/gl.cpp | |
parent | f6c0498c9728a286c13980ed3b60763d02e1b3a0 (diff) |
*misc
Diffstat (limited to 'source/modules/asura-core/graphics/gl.cpp')
-rw-r--r-- | source/modules/asura-core/graphics/gl.cpp | 219 |
1 files changed, 0 insertions, 219 deletions
diff --git a/source/modules/asura-core/graphics/gl.cpp b/source/modules/asura-core/graphics/gl.cpp deleted file mode 100644 index 5e6f216..0000000 --- a/source/modules/asura-core/graphics/gl.cpp +++ /dev/null @@ -1,219 +0,0 @@ -#include <asura-utils/type.h> - -#include "../core_config.h" - -#include "gl.h" -#include "shader.h" -#include "matrix_stack.h" -#include "color.h" - -using namespace AEMath; - -namespace AsuraEngine -{ - namespace Graphics - { - -#if ASURA_DEBUG - static bool _instantiated = false; -#endif - - OpenGL gl; - - OpenGL::OpenGL() - : mUpdateMVPMatrix(true) - { -#if ASURA_DEBUG - ASSERT(!_instantiated); - _instantiated = true; -#endif - } - - OpenGL::~OpenGL() - { - } - - static bool inited = false; - - bool OpenGL::Init(const AEMath::Recti& view) - { - bool loaded = false; -#if ASURA_OPENGL_LOADER & ASURA_OPENGL_GLAD - if (!loaded) - loaded = gladLoadGL(); -#endif - if (!loaded) - return false; - SetViewport(view); - - inited = true; - return true; - } - - bool OpenGL::Inited() - { - return inited; - } - - void OpenGL::WipeError() - { - while (glGetError() != GL_NO_ERROR); - } - - bool OpenGL::HasError() - { - return glGetError() != GL_NO_ERROR; - } - - GLenum OpenGL::GetError() - { - return glGetError(); - } - - void OpenGL::SetDrawColor(float r, float g, float b, float a) - { - state.drawColor.Set(r, g, b, a); - } - - Color& OpenGL::GetDrawColor() - { - return state.drawColor; - } - - void OpenGL::SetViewport(const Recti v) - { - state.viewport = v; - glViewport(v.x, v.y, v.w, v.h); - } - - const Recti& OpenGL::GetViewport() - { - return state.viewport; - } - - void OpenGL::UseShader(Shader* shader) - { - if (state.shader != shader) - { - glUseProgram(shader->GetGLProgram()); - state.shader = shader; -#if ASURA_GL_PROFILE - ++stats.shaderSwitch; -#endif - } - shader->OnUse(); - } - - void OpenGL::UnuseShader() - { - state.shader->OnUnuse(); - state.shader = nullptr; - } - - Shader* OpenGL::GetShader() - { - return state.shader; - } - - void OpenGL::DrawArrays(GLenum mode, GLint first, GLsizei count) - { - glDrawArrays(mode, first, count); -#if ASURA_GL_PROFILE - ++stats.drawCall; -#endif - } - - //------------------------------------------------------------------------------// - - void OpenGL::SetMatrixMode(MatrixMode mode) - { - state.matrixMode = mode; - } - - MatrixMode OpenGL::GetMatrixMode() - { - return state.matrixMode; - } - - void OpenGL::PushMatrix() - { - state.matrix[state.matrixMode].Push(); - - mUpdateMVPMatrix = true; - } - - void OpenGL::PopMatrix() - { - state.matrix[state.matrixMode].Pop(); - - mUpdateMVPMatrix = true; - } - - void OpenGL::LoadIdentity() - { - state.matrix[state.matrixMode].LoadIdentity(); - - mUpdateMVPMatrix = true; - } - - void OpenGL::Rotate(float angle) - { - state.matrix[state.matrixMode].Rotate(angle); - - mUpdateMVPMatrix = true; - } - - void OpenGL::Translate(float x, float y) - { - state.matrix[state.matrixMode].Translate(x, y); - - mUpdateMVPMatrix = true; - } - - void OpenGL::Scale(float x, float y) - { - state.matrix[state.matrixMode].Scale(x, y); - - mUpdateMVPMatrix = true; - } - - 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); - - mUpdateMVPMatrix = true; - } - - AEMath::Matrix44& OpenGL::GetMatrix(MatrixMode mode) - { - return state.matrix[mode].GetTop(); - } - - AEMath::Matrix44 OpenGL::GetMVPMatrix() - { - if (mUpdateMVPMatrix) - { - Matrix44& m = state.matrix[MATRIX_MODE_MODEL].GetTop(); - Matrix44& v = state.matrix[MATRIX_MODE_VIEW].GetTop(); - Matrix44& p = state.matrix[MATRIX_MODE_PROJECTION].GetTop(); - state.mvpMatrix = p * (v * m); - - mUpdateMVPMatrix = false; - } - return state.mvpMatrix; - } - - uint OpenGL::GetMatrixDepth() - { - return state.matrix[state.matrixMode].GetCapacity(); - } - - uint OpenGL::GetMatrixIndex() - { - return state.matrix[state.matrixMode].GetTopIndex(); - } - - //------------------------------------------------------------------------------// - - } -}
\ No newline at end of file |