summaryrefslogtreecommitdiff
path: root/source/modules/asura-core/graphics/gfx_device.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/modules/asura-core/graphics/gfx_device.cpp')
-rw-r--r--source/modules/asura-core/graphics/gfx_device.cpp61
1 files changed, 36 insertions, 25 deletions
diff --git a/source/modules/asura-core/graphics/gfx_device.cpp b/source/modules/asura-core/graphics/gfx_device.cpp
index c520127..83ea7f4 100644
--- a/source/modules/asura-core/graphics/gfx_device.cpp
+++ b/source/modules/asura-core/graphics/gfx_device.cpp
@@ -15,7 +15,7 @@ namespace AsuraEngine
{
#if ASURA_DEBUG
- static bool _instantiated = false;
+ static bool instantiated = false;
#endif
GfxDevice gfx;
@@ -23,8 +23,8 @@ namespace AsuraEngine
GfxDevice::GfxDevice()
{
#if ASURA_DEBUG
- ASSERT(!_instantiated);
- _instantiated = true;
+ ASSERT(!instantiated);
+ instantiated = true;
#endif
}
@@ -84,6 +84,16 @@ namespace AsuraEngine
return state.drawColor;
}
+ Canvas* GfxDevice::GetActiveCanvas() const
+ {
+ return state.canvas;
+ }
+
+ void GfxDevice::SetActiveCanvas(Canvas* canvas)
+ {
+ state.canvas = canvas;
+ }
+
void GfxDevice::SetViewport(const Recti v)
{
state.viewport = v;
@@ -95,26 +105,25 @@ namespace AsuraEngine
return state.viewport;
}
- void GfxDevice::UseShader(Shader* shader)
+ void GfxDevice::SetActiveShader(Shader* shader)
{
- if (state.shader != shader)
+ if (state.shader == shader)
+ return;
+ if (state.shader)
+ state.shader->OnDisable();
+ state.shader = shader;
+ if (shader)
{
- glUseProgram(shader->GetGLProgram());
- state.shader = shader;
+ GLint program = shader->GetGLProgram();
+ glUseProgram(program);
#if ASURA_GL_PROFILE
++stats.shaderSwitch;
#endif
+ shader->OnEnable();
}
- shader->OnUse();
- }
-
- void GfxDevice::UnuseShader()
- {
- state.shader->OnUnuse();
- state.shader = nullptr;
}
- Shader* GfxDevice::GetShader()
+ Shader* GfxDevice::GetActiveShader() const
{
return state.shader;
}
@@ -125,24 +134,26 @@ namespace AsuraEngine
#if ASURA_GL_PROFILE
++stats.drawCall;
#endif
+ if (state.shader)
+ state.shader->OnUsed();
}
- void GfxDevice::SetMatrixMode(MatrixMode mode)
+ void GfxDevice::SetMatrixMode (MatrixMode mode)
{
state.matrixMode = mode;
}
- MatrixMode GfxDevice::GetMatrixMode()
+ MatrixMode GfxDevice::GetMatrixMode ()
{
return state.matrixMode;
}
- void GfxDevice::PushMatrix()
+ void GfxDevice::PushMatrix ()
{
- state.matrix[state.matrixMode].Push();
+ state.matrix[state.matrixMode].Push ();
}
- void GfxDevice::PopMatrix()
+ void GfxDevice::PopMatrix ()
{
state.matrix[state.matrixMode].Pop();
}
@@ -152,17 +163,17 @@ namespace AsuraEngine
state.matrix[state.matrixMode].LoadIdentity();
}
- void GfxDevice::Rotate(float angle)
+ void GfxDevice::Rotate (float angle)
{
state.matrix[state.matrixMode].Rotate(angle);
}
- void GfxDevice::Translate(float x, float y)
+ void GfxDevice::Translate (float x, float y)
{
state.matrix[state.matrixMode].Translate(x, y);
}
- void GfxDevice::Scale(float x, float y)
+ void GfxDevice::Scale (float x, float y)
{
state.matrix[state.matrixMode].Scale(x, y);
}
@@ -179,8 +190,8 @@ namespace AsuraEngine
AEMath::Matrix44 GfxDevice::GetMVPMatrix()
{
- return state.matrix[MATRIX_MODE_MODEL].GetTop()
- * state.matrix[MATRIX_MODE_MODEL].GetTop()
+ return state.matrix[MATRIX_MODE_PROJECTION].GetTop()
+ * state.matrix[MATRIX_MODE_VIEW].GetTop()
* state.matrix[MATRIX_MODE_MODEL].GetTop();
}