diff options
author | chai <chaifix@163.com> | 2019-06-21 22:47:36 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2019-06-21 22:47:36 +0800 |
commit | 7894c2971626f9560b4ec77a1ce5a9a64a4f3810 (patch) | |
tree | c7bd04fbf4b8e21b48c4d6902c4bd910987e7560 /source/modules/asura-core/graphics/gfx_device.cpp | |
parent | 8ee3f7453bf7b0db5c7358e697e91714d825c87d (diff) |
*格式化代码
Diffstat (limited to 'source/modules/asura-core/graphics/gfx_device.cpp')
-rw-r--r-- | source/modules/asura-core/graphics/gfx_device.cpp | 61 |
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(); } |