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 | |
parent | 8ee3f7453bf7b0db5c7358e697e91714d825c87d (diff) |
*格式化代码
-rw-r--r-- | bin/win64/01-window.exe | bin | 1461248 -> 1461248 bytes | |||
-rw-r--r-- | bin/win64/SDL2.dll | bin | 2491904 -> 2491904 bytes | |||
-rw-r--r-- | source/Asura.Editor/system/editor_window.h | 2 | ||||
-rw-r--r-- | source/modules/asura-core/graphics/canvas.h | 2 | ||||
-rw-r--r-- | source/modules/asura-core/graphics/gfx_device.cpp | 61 | ||||
-rw-r--r-- | source/modules/asura-core/graphics/gfx_device.h | 74 | ||||
-rw-r--r-- | source/modules/asura-core/graphics/gif.cpp | 0 | ||||
-rw-r--r-- | source/modules/asura-core/graphics/gif.h | 20 | ||||
-rw-r--r-- | source/modules/asura-core/graphics/gpu_buffer.h | 13 | ||||
-rw-r--r-- | source/modules/asura-core/graphics/index_buffer.h | 2 | ||||
-rw-r--r-- | source/modules/asura-core/graphics/shader.cpp | 55 | ||||
-rw-r--r-- | source/modules/asura-core/graphics/shader.h | 17 | ||||
-rw-r--r-- | source/modules/asura-core/graphics/vertex_buffer.h | 2 | ||||
-rw-r--r-- | source/tests/win32/01-window/03_sub_menu.cpp | 4 |
14 files changed, 131 insertions, 121 deletions
diff --git a/bin/win64/01-window.exe b/bin/win64/01-window.exe Binary files differindex 2450989..e8d3928 100644 --- a/bin/win64/01-window.exe +++ b/bin/win64/01-window.exe diff --git a/bin/win64/SDL2.dll b/bin/win64/SDL2.dll Binary files differindex 76af463..becc4ba 100644 --- a/bin/win64/SDL2.dll +++ b/bin/win64/SDL2.dll diff --git a/source/Asura.Editor/system/editor_window.h b/source/Asura.Editor/system/editor_window.h index 8a3b0e1..50c9cb3 100644 --- a/source/Asura.Editor/system/editor_window.h +++ b/source/Asura.Editor/system/editor_window.h @@ -37,7 +37,7 @@ namespace AsuraEditor ~ContainerWindow(); bool Init(WindowConfig& config); - + private: ContainerWindow* mParent; diff --git a/source/modules/asura-core/graphics/canvas.h b/source/modules/asura-core/graphics/canvas.h index 5c11706..03326df 100644 --- a/source/modules/asura-core/graphics/canvas.h +++ b/source/modules/asura-core/graphics/canvas.h @@ -66,7 +66,7 @@ namespace AsuraEngine /// /// CanvasΪRenderTexture /// - using RenderTexture = Canvas; + typedef Canvas RenderTexture; } } 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(); } diff --git a/source/modules/asura-core/graphics/gfx_device.h b/source/modules/asura-core/graphics/gfx_device.h index 3c5b383..385f703 100644 --- a/source/modules/asura-core/graphics/gfx_device.h +++ b/source/modules/asura-core/graphics/gfx_device.h @@ -20,6 +20,8 @@ namespace AsuraEngine class Profiler; class Shader; + class GPUBuffer; + class Canvas; enum MatrixMode { @@ -40,50 +42,62 @@ namespace AsuraEngine GfxDevice(); ~GfxDevice(); - static GfxDevice& Get(); + static GfxDevice& Get(); - int GetParam(GLParams param); + int GetParam(GLParams param); - bool Init(const AEMath::Recti& viewport); - bool Inited(); + bool Init(const AEMath::Recti& viewport); + bool Inited(); + + void SetViewport(const AEMath::Recti viewport); - void SetViewport(const AEMath::Recti viewport); const AEMath::Recti& GetViewport(); - void UseShader(Shader* shader); - void UnuseShader(); - Shader* GetShader(); + void SetMatrixMode(MatrixMode mode); + MatrixMode GetMatrixMode(); - void DrawArrays(GLenum mode, GLint first, GLsizei count); + void PushMatrix(); + void PopMatrix(); + + void LoadIdentity(); + void Rotate(float angle); + void Translate(float x, float y); + void Scale(float x, float y); + void Ortho(float l, float r, float b, float t, float n, float f); + + uint GetMatrixDepth(); + uint GetMatrixIndex(); - void SetMatrixMode(MatrixMode mode); - MatrixMode GetMatrixMode(); - void PushMatrix(); - void PopMatrix(); - void LoadIdentity(); - void Rotate(float angle); - void Translate(float x, float y); - void Scale(float x, float y); - void Ortho(float l, float r, float b, float t, float n, float f); - uint GetMatrixDepth(); - uint GetMatrixIndex(); AEMath::Matrix44& GetMatrix(MatrixMode mode); - AEMath::Matrix44 GetMVPMatrix(); + AEMath::Matrix44 GetMVPMatrix(); + + void SetDrawColor(float r, float g, float b, float a); + Color& GetDrawColor(); + + void SetActiveCanvas(Canvas* = NULL); + Canvas* GetActiveCanvas() const; + + void SetActiveShader(Shader* = NULL); + Shader* GetActiveShader() const; + + void DrawArrays(GLenum mode, GLint first, GLsizei count); - void SetDrawColor(float r, float g, float b, float a); - Color& GetDrawColor(); + void WipeError(); + bool HasError(); + GLenum GetError(); - void WipeError(); - bool HasError(); - GLenum GetError(); + private: + + friend class Profiler; struct { - Shader* shader; ///< ǰʹõshader AEMath::Recti viewport; ///< ǰлHDC߱ڴСı߲ˢʱ䶯 MatrixStack matrix[3]; ///< model, view, projection MatrixMode matrixMode; ///< ǰľ Color drawColor; ///< Ƶɫ + Canvas* canvas; ///< ǰcanvas + Shader* shader; ///< ǰʹõshader } state; #if ASURA_GL_PROFILE @@ -95,10 +109,6 @@ namespace AsuraEngine } stats; #endif - private: - - friend class Profiler; - luaxport: LUAX_DECL_SINGLETON(GfxDevice); @@ -122,7 +132,7 @@ namespace AsuraEngine }; - // ȫgfx device + // ȫ GfxDevice extern GfxDevice gfx; } diff --git a/source/modules/asura-core/graphics/gif.cpp b/source/modules/asura-core/graphics/gif.cpp deleted file mode 100644 index e69de29..0000000 --- a/source/modules/asura-core/graphics/gif.cpp +++ /dev/null diff --git a/source/modules/asura-core/graphics/gif.h b/source/modules/asura-core/graphics/gif.h deleted file mode 100644 index 8b89858..0000000 --- a/source/modules/asura-core/graphics/gif.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef __ASURA_GIF_H__ -#define __ASURA_GIF_H__ - -namespace AsuraEngine -{ - namespace Graphics - { - - /// - /// Gif - /// - class Gif - { - - }; - - } -} - -#endif
\ No newline at end of file diff --git a/source/modules/asura-core/graphics/gpu_buffer.h b/source/modules/asura-core/graphics/gpu_buffer.h index f4f518f..f759c16 100644 --- a/source/modules/asura-core/graphics/gpu_buffer.h +++ b/source/modules/asura-core/graphics/gpu_buffer.h @@ -33,7 +33,8 @@ namespace AsuraEngine }; /// - /// VRAM壬ֶ㻺vboebo֣ÿζڴԴϴݡ + /// VRAM壬ֶ㻺vboebo֣ÿζڴԴϴݡframeworkrenderers + /// /// ASURA_ABSTRACT class GPUBuffer { @@ -44,13 +45,13 @@ namespace AsuraEngine static size_t GetDataTypeSize(GLenum datatype); - bool Fill(const void* data, size_t size, uint offset = 0) ASURA_THROW(Exception); + bool Fill(const void* data, size_t size, uint offset = 0) ASURA_THROW(Exception); - void Bind(); - void UnBind(); + void Bind(); + void UnBind(); - uint GetBufferSize(); - uint GetBufferCount(); + uint GetBufferSize(); + uint GetBufferCount(); GLenum GetDataType(); size_t GetDataTypeSize(); diff --git a/source/modules/asura-core/graphics/index_buffer.h b/source/modules/asura-core/graphics/index_buffer.h index c5d2e9e..98e901a 100644 --- a/source/modules/asura-core/graphics/index_buffer.h +++ b/source/modules/asura-core/graphics/index_buffer.h @@ -22,8 +22,6 @@ namespace AsuraEngine IndexBuffer(BufferUsage usage, BufferDataType datatype, size_t size); ~IndexBuffer(); - private: - luaxport: LUAX_DECL_FACTORY(IndexBuffer); diff --git a/source/modules/asura-core/graphics/shader.cpp b/source/modules/asura-core/graphics/shader.cpp index afd10b0..22b9ee3 100644 --- a/source/modules/asura-core/graphics/shader.cpp +++ b/source/modules/asura-core/graphics/shader.cpp @@ -10,10 +10,8 @@ namespace AsuraEngine namespace Graphics { - /// - /// texture unit - /// - static int _texture_unit; + // texture unit + static uint8 texUnit = 0; Shader::Shader() { @@ -26,6 +24,16 @@ namespace AsuraEngine if(mProgram) glDeleteProgram(mProgram); } + void Shader::SetActive(Shader* shader) + { + gfx.SetActiveShader(shader); + } + + Shader* Shader::GetActive() + { + return gfx.GetActiveShader(); + } + bool Shader::Load(const string& vert, const string& frag) { string warnning = ""; @@ -117,14 +125,19 @@ namespace AsuraEngine return true; } - void Shader::OnUse() + void Shader::OnEnable() { - _texture_unit = 0; + texUnit = 0; } - void Shader::OnUnuse() + void Shader::OnDisable() { - _texture_unit; + texUnit = 0; + } + + void Shader::OnUsed() + { + texUnit = 0; } uint Shader::GetUniformLocation(const std::string& uniform) @@ -146,65 +159,59 @@ namespace AsuraEngine void Shader::SetUniformFloat(uint loc, float value) { - if(gfx.state.shader == this) + if(gfx.GetActiveShader() == this) glUniform1f(loc, value); } bool Shader::SetUniformTexture(uint loc, const Texture& texture) { - if (gfx.state.shader != this) + if (gfx.GetActiveShader() != this) return false; gfx.WipeError(); - glActiveTexture(GL_TEXTURE0 + _texture_unit); + glActiveTexture(GL_TEXTURE0 + texUnit); if (gfx.HasError()) return false; GLint tex = texture.GetGLTexture(); glBindTexture(GL_TEXTURE_2D, tex); if (gfx.HasError()) return false; - glUniform1i(loc, _texture_unit); + glUniform1i(loc, texUnit); if (gfx.HasError()) return false; - ++_texture_unit; + ++texUnit; } void Shader::SetUniformVector2(uint loc, const Math::Vector2f& vec2) { - if (gfx.state.shader == this) + if (gfx.GetActiveShader() == this) glUniform2f(loc, vec2.x, vec2.y); } void Shader::SetUniformVector3(uint loc, const Math::Vector3f& vec3) { - if (gfx.state.shader == this) + if (gfx.GetActiveShader() == this) glUniform3f(loc, vec3.x, vec3.y, vec3.z); } void Shader::SetUniformVector4(uint loc, const Math::Vector4f& vec4) { - if (gfx.state.shader == this) + if (gfx.GetActiveShader() == this) glUniform4f(loc, vec4.x, vec4.y, vec4.z, vec4.w); } void Shader::SetUniformMatrix44(uint loc, const Math::Matrix44& mat) { - if (gfx.state.shader == this) + if (gfx.GetActiveShader() == this) glUniformMatrix4fv(loc, 1, GL_FALSE, mat.GetElements()); } void Shader::SetUniformColor(uint loc, const Color& color) { - if (gfx.state.shader == this) + if (gfx.GetActiveShader() == this) glUniform4f(loc, color.r, color.g, color.b, color.a); } - //void Shader::GetUniform() - //{ - // //if(gfx.state.shader == this) - // // glGetUniformfv() - //} - uint Shader::GetGLTextureUnitCount() { GLint maxTextureUnits; diff --git a/source/modules/asura-core/graphics/shader.h b/source/modules/asura-core/graphics/shader.h index 61aa6f1..30a386e 100644 --- a/source/modules/asura-core/graphics/shader.h +++ b/source/modules/asura-core/graphics/shader.h @@ -26,9 +26,9 @@ namespace AsuraEngine { /// - /// һshaderһڲʼ乲ijShaderuniformsͶݣֻṩ - /// uniformsuseɫķ༭ÿshaderͨshaderҵuniforms - /// ¶frameworkmaterialá + /// һshaderһڲʼ乲ijShaderuniformsͶݣֻṩ uniformsuseɫ + /// ķ༭ÿshaderͨshaderҵuniforms¶frameworkmaterial + /// á /// class Shader ASURA_FINAL : public Scripting::Portable<Shader> @@ -40,10 +40,16 @@ namespace AsuraEngine ~Shader(); + static void SetActive(Shader* shader); + static Shader* GetActive(); + bool Load(const std::string& vert, const std::string& frag) ASURA_THROW(Exception); - void OnUse(); - void OnUnuse(); + // ʹSetActiveлshaderʱ + void OnEnable(); + void OnDisable(); + // Draw call֮ + void OnUsed(); void SetAttribute(int loc, VertexBuffer* vbo, uint offseti = 0, uint stridei = 0, bool normalized = false); int GetAttributeLocation(const std::string& attribute); @@ -105,7 +111,6 @@ namespace AsuraEngine }; - // ڱһGPU typedef Shader GpuProgram; } diff --git a/source/modules/asura-core/graphics/vertex_buffer.h b/source/modules/asura-core/graphics/vertex_buffer.h index 7aad27d..83ca4d1 100644 --- a/source/modules/asura-core/graphics/vertex_buffer.h +++ b/source/modules/asura-core/graphics/vertex_buffer.h @@ -23,8 +23,6 @@ namespace AsuraEngine VertexBuffer(BufferUsage usage, BufferDataType datatype, size_t size); ~VertexBuffer(); - private: - luaxport: LUAX_DECL_FACTORY(VertexBuffer); diff --git a/source/tests/win32/01-window/03_sub_menu.cpp b/source/tests/win32/01-window/03_sub_menu.cpp index 6fe93d7..9467334 100644 --- a/source/tests/win32/01-window/03_sub_menu.cpp +++ b/source/tests/win32/01-window/03_sub_menu.cpp @@ -163,7 +163,7 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, { int imgLoc = shader->GetUniformLocation("img"); int code = gfx.GetError(); - gfx.UseShader(shader); + gfx.SetActiveShader(shader); shader->SetUniformTexture(imgLoc, *img); gfx.SetMatrixMode(MATRIX_MODE_PROJECTION); gfx.LoadIdentity(); @@ -183,7 +183,7 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, //gfx.DrawArrays(GL_TRIANGLE_STRIP, 0, 4); shader->DisableAttribute(locs.pos); shader->DisableAttribute(locs.tex); - gfx.UnuseShader(); + gfx.SetActiveShader(NULL); } glFlush(); BeginPaint(hwnd, &ps); EndPaint(hwnd, &ps); |