summaryrefslogtreecommitdiff
path: root/source/modules/asura-core/Graphics/GfxDevice.cpp
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2019-08-16 08:54:08 +0800
committerchai <chaifix@163.com>2019-08-16 08:54:08 +0800
commita077eb38b01292611f4f6031b75e3e2c1c20f06e (patch)
tree8f760483d7b0290952bbdb5bcd8f3943102aeb3a /source/modules/asura-core/Graphics/GfxDevice.cpp
parent6a065c913e9308cc72e1ad0723b6167048f439b6 (diff)
Diffstat (limited to 'source/modules/asura-core/Graphics/GfxDevice.cpp')
-rw-r--r--source/modules/asura-core/Graphics/GfxDevice.cpp76
1 files changed, 35 insertions, 41 deletions
diff --git a/source/modules/asura-core/Graphics/GfxDevice.cpp b/source/modules/asura-core/Graphics/GfxDevice.cpp
index 529a76c..ab5e281 100644
--- a/source/modules/asura-core/Graphics/GfxDevice.cpp
+++ b/source/modules/asura-core/Graphics/GfxDevice.cpp
@@ -7,7 +7,7 @@
#include "MatrixStack.h"
#include "Color.h"
-using namespace AEMath;
+
namespace_begin(AsuraEngine)
namespace_begin(Graphics)
@@ -16,7 +16,13 @@ namespace_begin(Graphics)
static bool instantiated = false;
#endif
-GfxDevice g_Device;
+#if ASURA_GL_PROFILE
+#define Stats(f) m_Stats.f
+#else
+#define Stats(f)
+#endif
+
+GfxDevice g_GfxDevice;
GfxDevice::GfxDevice()
{
@@ -32,12 +38,12 @@ GfxDevice::~GfxDevice()
GfxDevice& GfxDevice::Get()
{
- return g_Device;
+ return g_GfxDevice;
}
static bool inited = false;
-bool GfxDevice::Init(const AEMath::Recti& view)
+bool GfxDevice::Init(const Recti& view)
{
bool loaded = false;
#if ASURA_OPENGL_LOADER & ASURA_OPENGL_GLAD
@@ -74,113 +80,101 @@ GLenum GfxDevice::GetError()
void GfxDevice::SetDrawColor(float r, float g, float b, float a)
{
- state.drawColor.Set(r, g, b, a);
+ m_State.drawColor.Set(r, g, b, a);
}
Color& GfxDevice::GetDrawColor()
{
- return state.drawColor;
+ return m_State.drawColor;
}
void GfxDevice::SetViewport(const Recti v)
{
- state.viewport = v;
+ m_State.viewport = v;
glViewport(v.x, v.y, v.w, v.h);
}
const Recti& GfxDevice::GetViewport()
{
- return state.viewport;
+ return m_State.viewport;
}
void GfxDevice::SetActiveShader(Shader* shader)
{
- if (state.shader == shader)
+ if (m_State.activeShader == shader)
return;
- if (state.shader)
- state.shader->OnDisable();
- state.shader = shader;
+ if (m_State.activeShader)
+ m_State.activeShader->OnDisable();
+ m_State.activeShader = shader;
if (shader)
{
GLint program = shader->GetGLProgram();
glUseProgram(program);
-#if ASURA_GL_PROFILE
- ++stats.shaderSwitch;
-#endif
shader->OnEnable();
+ Stats(AddShaderSwitch());
}
}
Shader* GfxDevice::GetActiveShader() const
{
- return state.shader;
-}
-
-void GfxDevice::DrawArrays(GLenum mode, GLint first, GLsizei count)
-{
- glDrawArrays(mode, first, count);
-#if ASURA_GL_PROFILE
- ++stats.drawCall;
-#endif
- if (state.shader)
- state.shader->OnUsed();
+ return m_State.activeShader;
}
void GfxDevice::PushMatrix ()
{
- state.matrix[state.matrixMode].Push ();
+ m_State.matrix[m_State.matrixMode].Push ();
}
void GfxDevice::PopMatrix ()
{
- state.matrix[state.matrixMode].Pop();
+ m_State.matrix[m_State.matrixMode].Pop();
}
void GfxDevice::LoadIdentity()
{
- state.matrix[state.matrixMode].LoadIdentity();
+ m_State.matrix[m_State.matrixMode].LoadIdentity();
}
void GfxDevice::Rotate (float angle)
{
- state.matrix[state.matrixMode].Rotate(angle);
+ m_State.matrix[m_State.matrixMode].Rotate(angle);
}
void GfxDevice::Translate (float x, float y)
{
- state.matrix[state.matrixMode].Translate(x, y);
+ m_State.matrix[m_State.matrixMode].Translate(x, y);
}
void GfxDevice::Scale (float x, float y)
{
- state.matrix[state.matrixMode].Scale(x, y);
+ m_State.matrix[m_State.matrixMode].Scale(x, y);
}
void GfxDevice::Ortho(float l, float r, float b, float t, float n, float f)
{
- state.matrix[state.matrixMode].Ortho(l, r, b, t, n, f);
+ m_State.matrix[m_State.matrixMode].Ortho(l, r, b, t, n, f);
}
-AEMath::Matrix44& GfxDevice::GetMatrix(MatrixMode mode)
+Matrix44& GfxDevice::GetMatrix(MatrixMode mode)
{
- return state.matrix[mode].GetTop();
+ return m_State.matrix[mode].GetTop();
}
-AEMath::Matrix44 GfxDevice::GetMVPMatrix()
+Matrix44 GfxDevice::GetMVPMatrix()
{
- return state.matrix[MATRIX_MODE_PROJECTION].GetTop()
- * state.matrix[MATRIX_MODE_VIEW].GetTop()
- * state.matrix[MATRIX_MODE_MODEL].GetTop();
+ return m_State.matrix[MATRIX_MODE_PROJECTION].GetTop()
+ * m_State.matrix[MATRIX_MODE_VIEW].GetTop()
+ * m_State.matrix[MATRIX_MODE_MODEL].GetTop();
}
uint GfxDevice::GetMatrixDepth()
{
- return state.matrix[state.matrixMode].GetCapacity();
+ return m_State.matrix[m_State.matrixMode].GetCapacity();
}
uint GfxDevice::GetMatrixIndex()
{
- return state.matrix[state.matrixMode].GetTopIndex();
+ return m_State.matrix[m_State.matrixMode].GetTopIndex();
}