diff options
author | chai <chaifix@163.com> | 2019-07-31 21:35:12 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2019-07-31 21:35:12 +0800 |
commit | 084623519e95f0ab0cf4bc328b5fa736d679c5bd (patch) | |
tree | 9d409dceda50335e9fb881fc5107c9c1c561f988 /source/modules/asura-core/graphics | |
parent | 012a44bd13ab41d056e7d3884a39027b6cea62b5 (diff) |
*修改名称空间风格
Diffstat (limited to 'source/modules/asura-core/graphics')
39 files changed, 1706 insertions, 1758 deletions
diff --git a/source/modules/asura-core/graphics/binding/_canvas.cpp b/source/modules/asura-core/graphics/binding/_canvas.cpp index 6728ff3..6dda773 100644 --- a/source/modules/asura-core/graphics/binding/_canvas.cpp +++ b/source/modules/asura-core/graphics/binding/_canvas.cpp @@ -2,10 +2,9 @@ using namespace std; -namespace AsuraEngine -{ - namespace Graphics - { +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + LUAX_REGISTRY(Canvas) { diff --git a/source/modules/asura-core/graphics/binding/_color.cpp b/source/modules/asura-core/graphics/binding/_color.cpp index f06622c..c990d8b 100644 --- a/source/modules/asura-core/graphics/binding/_color.cpp +++ b/source/modules/asura-core/graphics/binding/_color.cpp @@ -3,129 +3,128 @@ using namespace std; using namespace Luax; -namespace AsuraEngine -{ - namespace Graphics - { +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + - LUAX_REGISTRY(Color) - { - LUAX_REGISTER_METHODS(state, - { "ToColor32", _ToColor32 }, - { "SetColor", _SetColor }, - { "GetColor", _GetColor }, - { "GetR", _GetR }, - { "GetG", _GetG }, - { "GetB", _GetB }, - { "GetA", _GetA }, - { "__eq", ___eq }, - { "__add", ___add }, - { "__sub", ___sub }, - { "__mul", ___mul }, - { "__div", ___div } - ); - } - - LUAX_POSTPROCESS(Color) - { - - } - - // color:ToColor32() - LUAX_IMPL_METHOD(Color, _ToColor32) - { - LUAX_PREPARE(L, Color); - - return 0; - } - - // color:SetColor() - LUAX_IMPL_METHOD(Color, _SetColor) - { - LUAX_PREPARE(L, Color); - - return 0; - } - - // color:GetColor() - LUAX_IMPL_METHOD(Color, _GetColor) - { - LUAX_PREPARE(L, Color); - - return 0; - } - - // color:GetR() - LUAX_IMPL_METHOD(Color, _GetR) - { - LUAX_PREPARE(L, Color); - - return 0; - } - - // color:GetG() - LUAX_IMPL_METHOD(Color, _GetG) - { - LUAX_PREPARE(L, Color); - - return 0; - } - - // color:GetB() - LUAX_IMPL_METHOD(Color, _GetB) - { - LUAX_PREPARE(L, Color); - - return 0; - } - - // color:GetA() - LUAX_IMPL_METHOD(Color, _GetA) - { - LUAX_PREPARE(L, Color); - - return 0; - } - - // color:__eq() - LUAX_IMPL_METHOD(Color, ___eq) - { - LUAX_PREPARE(L, Color); - - return 0; - } - - // color:__add() - LUAX_IMPL_METHOD(Color, ___add) - { - LUAX_PREPARE(L, Color); - - return 0; - } - - // color:__sub() - LUAX_IMPL_METHOD(Color, ___sub) - { - LUAX_PREPARE(L, Color); - - return 0; - } - - // color:__mul() - LUAX_IMPL_METHOD(Color, ___mul) - { - LUAX_PREPARE(L, Color); - - return 0; - } +LUAX_REGISTRY(Color) +{ + LUAX_REGISTER_METHODS(state, + { "ToColor32", _ToColor32 }, + { "SetColor", _SetColor }, + { "GetColor", _GetColor }, + { "GetR", _GetR }, + { "GetG", _GetG }, + { "GetB", _GetB }, + { "GetA", _GetA }, + { "__eq", ___eq }, + { "__add", ___add }, + { "__sub", ___sub }, + { "__mul", ___mul }, + { "__div", ___div } + ); +} + +LUAX_POSTPROCESS(Color) +{ + +} + +// color:ToColor32() +LUAX_IMPL_METHOD(Color, _ToColor32) +{ + LUAX_PREPARE(L, Color); + + return 0; +} + +// color:SetColor() +LUAX_IMPL_METHOD(Color, _SetColor) +{ + LUAX_PREPARE(L, Color); + + return 0; +} + +// color:GetColor() +LUAX_IMPL_METHOD(Color, _GetColor) +{ + LUAX_PREPARE(L, Color); + + return 0; +} + +// color:GetR() +LUAX_IMPL_METHOD(Color, _GetR) +{ + LUAX_PREPARE(L, Color); + + return 0; +} + +// color:GetG() +LUAX_IMPL_METHOD(Color, _GetG) +{ + LUAX_PREPARE(L, Color); + + return 0; +} + +// color:GetB() +LUAX_IMPL_METHOD(Color, _GetB) +{ + LUAX_PREPARE(L, Color); + + return 0; +} + +// color:GetA() +LUAX_IMPL_METHOD(Color, _GetA) +{ + LUAX_PREPARE(L, Color); - // color:__div() - LUAX_IMPL_METHOD(Color, ___div) - { - LUAX_PREPARE(L, Color); + return 0; +} + +// color:__eq() +LUAX_IMPL_METHOD(Color, ___eq) +{ + LUAX_PREPARE(L, Color); + + return 0; +} + +// color:__add() +LUAX_IMPL_METHOD(Color, ___add) +{ + LUAX_PREPARE(L, Color); - return 0; - } + return 0; +} + +// color:__sub() +LUAX_IMPL_METHOD(Color, ___sub) +{ + LUAX_PREPARE(L, Color); + + return 0; +} + +// color:__mul() +LUAX_IMPL_METHOD(Color, ___mul) +{ + LUAX_PREPARE(L, Color); + + return 0; +} + +// color:__div() +LUAX_IMPL_METHOD(Color, ___div) +{ + LUAX_PREPARE(L, Color); + + return 0; +} - } } +}
\ No newline at end of file diff --git a/source/modules/asura-core/graphics/binding/_color32.cpp b/source/modules/asura-core/graphics/binding/_color32.cpp index f2f716a..96c63af 100644 --- a/source/modules/asura-core/graphics/binding/_color32.cpp +++ b/source/modules/asura-core/graphics/binding/_color32.cpp @@ -2,10 +2,9 @@ using namespace std; -namespace AsuraEngine -{ - namespace Graphics - { +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + LUAX_REGISTRY(Color32) { diff --git a/source/modules/asura-core/graphics/binding/_gfx_device.cpp b/source/modules/asura-core/graphics/binding/_gfx_device.cpp index 5ae475c..60a0b0b 100644 --- a/source/modules/asura-core/graphics/binding/_gfx_device.cpp +++ b/source/modules/asura-core/graphics/binding/_gfx_device.cpp @@ -3,10 +3,9 @@ using namespace std; using namespace Luax; -namespace AsuraEngine -{ - namespace Graphics - { +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + LUAX_REGISTRY(GfxDevice) { diff --git a/source/modules/asura-core/graphics/binding/_gpu_buffer.cpp b/source/modules/asura-core/graphics/binding/_gpu_buffer.cpp index 785496e..479901e 100644 --- a/source/modules/asura-core/graphics/binding/_gpu_buffer.cpp +++ b/source/modules/asura-core/graphics/binding/_gpu_buffer.cpp @@ -6,10 +6,9 @@ using namespace std; using namespace Luax; -namespace AsuraEngine -{ - namespace Graphics - { +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + LUAX_REGISTRY(GPUBuffer) { diff --git a/source/modules/asura-core/graphics/binding/_image.cpp b/source/modules/asura-core/graphics/binding/_image.cpp index 99373e3..0e4cb16 100644 --- a/source/modules/asura-core/graphics/binding/_image.cpp +++ b/source/modules/asura-core/graphics/binding/_image.cpp @@ -2,10 +2,9 @@ using namespace std; -namespace AsuraEngine -{ - namespace Graphics - { +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + LUAX_REGISTRY(Image) { diff --git a/source/modules/asura-core/graphics/binding/_index_buffer.cpp b/source/modules/asura-core/graphics/binding/_index_buffer.cpp index 56bffb7..eb81699 100644 --- a/source/modules/asura-core/graphics/binding/_index_buffer.cpp +++ b/source/modules/asura-core/graphics/binding/_index_buffer.cpp @@ -3,10 +3,9 @@ using namespace std; using namespace Luax; -namespace AsuraEngine -{ - namespace Graphics - { +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + LUAX_REGISTRY(IndexBuffer) { diff --git a/source/modules/asura-core/graphics/binding/_mesh2d.cpp b/source/modules/asura-core/graphics/binding/_mesh2d.cpp index 07e9f12..4e3f426 100644 --- a/source/modules/asura-core/graphics/binding/_mesh2d.cpp +++ b/source/modules/asura-core/graphics/binding/_mesh2d.cpp @@ -2,10 +2,9 @@ using namespace std; -namespace AsuraEngine -{ - namespace Graphics - { +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + LUAX_REGISTRY(Mesh2D) { diff --git a/source/modules/asura-core/graphics/binding/_shader.cpp b/source/modules/asura-core/graphics/binding/_shader.cpp index 71f4e28..85fd388 100644 --- a/source/modules/asura-core/graphics/binding/_shader.cpp +++ b/source/modules/asura-core/graphics/binding/_shader.cpp @@ -3,10 +3,9 @@ using namespace std; using namespace Luax; -namespace AsuraEngine -{ - namespace Graphics - { +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + LUAX_REGISTRY(Shader) { diff --git a/source/modules/asura-core/graphics/binding/_sprite_batch.cpp b/source/modules/asura-core/graphics/binding/_sprite_batch.cpp index 8556c02..7795d26 100644 --- a/source/modules/asura-core/graphics/binding/_sprite_batch.cpp +++ b/source/modules/asura-core/graphics/binding/_sprite_batch.cpp @@ -2,10 +2,9 @@ using namespace std; -namespace AsuraEngine -{ - namespace Graphics - { +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + LUAX_REGISTRY(SpriteBatch) { diff --git a/source/modules/asura-core/graphics/binding/_texture.cpp b/source/modules/asura-core/graphics/binding/_texture.cpp index 305ac22..f5e5f17 100644 --- a/source/modules/asura-core/graphics/binding/_texture.cpp +++ b/source/modules/asura-core/graphics/binding/_texture.cpp @@ -2,10 +2,9 @@ using namespace std; -namespace AsuraEngine -{ - namespace Graphics - { +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + LUAX_REGISTRY(Texture) { diff --git a/source/modules/asura-core/graphics/binding/_vertex_buffer.cpp b/source/modules/asura-core/graphics/binding/_vertex_buffer.cpp index 666e529..b181df3 100644 --- a/source/modules/asura-core/graphics/binding/_vertex_buffer.cpp +++ b/source/modules/asura-core/graphics/binding/_vertex_buffer.cpp @@ -3,10 +3,9 @@ using namespace std; using namespace Luax; -namespace AsuraEngine -{ - namespace Graphics - { +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + LUAX_REGISTRY(VertexBuffer) { diff --git a/source/modules/asura-core/graphics/blend_mode.h b/source/modules/asura-core/graphics/blend_mode.h index 775cc45..73e1a41 100644 --- a/source/modules/asura-core/graphics/blend_mode.h +++ b/source/modules/asura-core/graphics/blend_mode.h @@ -1,17 +1,17 @@ #ifndef __ASURA_ENGINE_BLEND_MODE_H__ #define __ASURA_ENGINE_BLEND_MODE_H__ -namespace AsuraEngine -{ - namespace Graphics - { +#include <asura-utils/classes.h> + +namespace_begin(AsuraEngine) +namespace_begin(Graphics) - enum BlendMode - { +enum BlendMode +{ - }; +}; - } -} +namespace_end +namespace_end #endif
\ No newline at end of file diff --git a/source/modules/asura-core/graphics/canvas.cpp b/source/modules/asura-core/graphics/canvas.cpp index e922a51..60c8f87 100644 --- a/source/modules/asura-core/graphics/canvas.cpp +++ b/source/modules/asura-core/graphics/canvas.cpp @@ -1,50 +1,49 @@ #include "Canvas.h" -namespace AsuraEngine +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + +Canvas::Canvas() + : m_Width(0) + , m_Height(0) + , m_FBO(0) { - namespace Graphics - { + // Fix: ôСʼʱframebufferԴ + //glGenFramebuffers(1, &m_FBO); + //GLint current_fbo; + //glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, ¤t_fbo); + //glBindFramebuffer(GL_FRAMEBUFFER, m_FBO); + //glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_TexID, 0); + //glBindFramebuffer(GL_FRAMEBUFFER, current_fbo); +} - Canvas::Canvas() - : m_Width(0) - , m_Height(0) - , m_FBO(0) +void Canvas::SetSize(uint w, uint h) +{ + if (m_FBO == 0) + { + glGenFramebuffers(1, &m_FBO); + if (m_FBO == 0) + throw Exception("OpenGL glGenFramebuffers cannot generate frame buffer object."); + // + if (m_TexID == 0) { - // Fix: ôСʼʱframebufferԴ - //glGenFramebuffers(1, &m_FBO); - //GLint current_fbo; - //glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, ¤t_fbo); - //glBindFramebuffer(GL_FRAMEBUFFER, m_FBO); - //glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_TexID, 0); - //glBindFramebuffer(GL_FRAMEBUFFER, current_fbo); + glGenTextures(1, &m_TexID); + if (m_TexID == 0) + throw Exception("OpenGL glGenTextures cannot generate texture."); } + GLint current_fbo; + glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, ¤t_fbo); + glBindFramebuffer(GL_FRAMEBUFFER, m_FBO); + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_TexID, 0); + glBindFramebuffer(GL_FRAMEBUFFER, current_fbo); + } + GLint current_tex; + glGetIntegerv(GL_TEXTURE_BINDING_2D, ¤t_tex); + glBindTexture(GL_TEXTURE_2D, m_TexID); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); + glBindTexture(GL_TEXTURE_2D, current_tex); +} - void Canvas::SetSize(uint w, uint h) - { - if (m_FBO == 0) - { - glGenFramebuffers(1, &m_FBO); - if (m_FBO == 0) - throw Exception("OpenGL glGenFramebuffers cannot generate frame buffer object."); - // - if (m_TexID == 0) - { - glGenTextures(1, &m_TexID); - if (m_TexID == 0) - throw Exception("OpenGL glGenTextures cannot generate texture."); - } - GLint current_fbo; - glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, ¤t_fbo); - glBindFramebuffer(GL_FRAMEBUFFER, m_FBO); - glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_TexID, 0); - glBindFramebuffer(GL_FRAMEBUFFER, current_fbo); - } - GLint current_tex; - glGetIntegerv(GL_TEXTURE_BINDING_2D, ¤t_tex); - glBindTexture(GL_TEXTURE_2D, m_TexID); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); - glBindTexture(GL_TEXTURE_2D, current_tex); - } +namespace_end - } -}
\ No newline at end of file +namespace_end
\ No newline at end of file diff --git a/source/modules/asura-core/graphics/canvas.h b/source/modules/asura-core/graphics/canvas.h index 332e973..bbd098a 100644 --- a/source/modules/asura-core/graphics/canvas.h +++ b/source/modules/asura-core/graphics/canvas.h @@ -11,64 +11,63 @@ #include "render_target.h" #include "render_state.h" -namespace AsuraEngine -{ - namespace Graphics - { +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + - /// - /// CanvasҲԳΪrender textureҲΪtextureȾ - /// - class Canvas ASURA_FINAL - : public Scripting::Portable<Canvas, RenderTarget> - { - public: +/// +/// CanvasҲԳΪrender textureҲΪtextureȾ +/// +class Canvas ASURA_FINAL + : public Scripting::Portable<Canvas, RenderTarget> +{ +public: - Canvas(); + Canvas(); - ~Canvas(); + ~Canvas(); - /// - /// render textureĴС - /// - void SetSize(uint w, uint h) ASURA_THROW(Exception); + /// + /// render textureĴС + /// + void SetSize(uint w, uint h) ASURA_THROW(Exception); - void Clear(const Color& col = Color::Black) override; + void Clear(const Color& col = Color::Black) override; /* - void Clear(const Math::Recti& quad, const Color& col = Color::Black) override; + void Clear(const Math::Recti& quad, const Color& col = Color::Black) override; */ - void Render(const RenderTarget* rt, const Math::Vector2i& pos, const Math::Vector2i& scale, const Math::Vector2i& center, float rot); + void Render(const RenderTarget* rt, const Math::Vector2i& pos, const Math::Vector2i& scale, const Math::Vector2i& center, float rot); - void Render(const RenderTarget* rt, const Math::Rectf& quad, const Math::Vector2i& pos, const Math::Vector2i& scale, const Math::Vector2i& center, float rot); + void Render(const RenderTarget* rt, const Math::Rectf& quad, const Math::Vector2i& pos, const Math::Vector2i& scale, const Math::Vector2i& center, float rot); - void Draw(const Drawable* texture, const RenderState& state); + void Draw(const Drawable* texture, const RenderState& state); - void Draw(const Drawable* texture, const Math::Recti& quad, const RenderState& state); + void Draw(const Drawable* texture, const Math::Recti& quad, const RenderState& state); - private: +private: - GLuint m_FBO; + GLuint m_FBO; - GLuint m_TexID; + GLuint m_TexID; - uint m_Width, m_Height; + uint m_Width, m_Height; - luaxport: +luaxport: - LUAX_DECL_FACTORY(Canvas, RenderTarget); + LUAX_DECL_FACTORY(Canvas, RenderTarget); - LUAX_DECL_METHOD(_SetSize); - LUAX_DECL_METHOD(_Bind); - LUAX_DECL_METHOD(_Unbind); + LUAX_DECL_METHOD(_SetSize); + LUAX_DECL_METHOD(_Bind); + LUAX_DECL_METHOD(_Unbind); - }; +}; - /// - /// CanvasΪRenderTexture - /// - typedef Canvas RenderTexture; +/// +/// CanvasΪRenderTexture +/// +typedef Canvas RenderTexture; - } -} +} // Graphics +} // AsuraEngine #endif
\ No newline at end of file diff --git a/source/modules/asura-core/graphics/color.cpp b/source/modules/asura-core/graphics/color.cpp index 76e0942..47e039f 100644 --- a/source/modules/asura-core/graphics/color.cpp +++ b/source/modules/asura-core/graphics/color.cpp @@ -1,60 +1,58 @@ #include "color.h" #include "color32.h" -namespace AsuraEngine +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + +Color::Color() +{ + r = g = b = a = 0; +} + +Color::Color(const Color& c) +{ + r = c.r; + g = c.g; + b = c.b; + a = c.a; +} + +Color::Color(float r, float g, float b, float a) +{ + this->r = r; + this->g = g; + this->b = b; + this->a = a; +} + +Color::Color(const Color32& c) +{ + r = c.r / 255.f; + g = c.g / 255.f; + b = c.b / 255.f; + a = c.a / 255.f; +} + +Color::~Color() +{ +} + +void Color::Set(float r, float g, float b, float a) { - namespace Graphics - { - - Color::Color() - { - r = g = b = a = 0; - } - - Color::Color(const Color& c) - { - r = c.r; - g = c.g; - b = c.b; - a = c.a; - } - - Color::Color(float r, float g, float b, float a) - { - this->r = r; - this->g = g; - this->b = b; - this->a = a; - } - - Color::Color(const Color32& c) - { - r = c.r / 255.f; - g = c.g / 255.f; - b = c.b / 255.f; - a = c.a / 255.f; - } - - Color::~Color() - { - } - - void Color::Set(float r, float g, float b, float a) - { - this->r = r; - this->g = g; - this->b = b; - this->a = a; - } - - //Color Color::operator *(const Color& c) - //{ - // r *= c.r; - // g *= c.g; - // b *= c.b; - // a *= c.a; - - //} - - } -}
\ No newline at end of file + this->r = r; + this->g = g; + this->b = b; + this->a = a; +} + +//Color Color::operator *(const Color& c) +//{ +// r *= c.r; +// g *= c.g; +// b *= c.b; +// a *= c.a; + +//} + +namespace_end +namespace_end diff --git a/source/modules/asura-core/graphics/color.h b/source/modules/asura-core/graphics/color.h index b29c43f..99a9b00 100644 --- a/source/modules/asura-core/graphics/color.h +++ b/source/modules/asura-core/graphics/color.h @@ -2,69 +2,73 @@ #define __ASURA_ENGINE_COLOR_H__ #include <asura-utils/scripting/portable.hpp> +#include <asura-utils/classes.h> #include "../core_config.h" -namespace AsuraEngine -{ - namespace Graphics - { +namespace_begin(AsuraEngine) +namespace_begin(Graphics) - class Color32; +class Color32; - /// - /// 淶ɫColor32иIJԡ - /// - class Color ASURA_FINAL - : public Scripting::Portable<Color> - { - public: +/// +/// 淶ɫColor32иIJԡ +/// +class Color ASURA_FINAL + : public Scripting::Portable<Color> +{ +public: - static Color Black; - static Color White; - static Color Red; - static Color Green; - static Color Blue; + static Color Black; + static Color White; + static Color Red; + static Color Green; + static Color Blue; - Color(); + Color(); - Color(const Color& c); + Color(const Color& c); - Color(float r, float g, float b, float a); + Color(float r, float g, float b, float a); - Color(const Color32& c); + Color(const Color32& c); - ~Color(); + ~Color(); - Color operator *(const Color& c); + Color operator *(const Color& c); - void Set(float r, float g, float b, float a); + void Set(float r, float g, float b, float a); + + GET_SET(float, Red, r); + GET_SET(float, Green, g); + GET_SET(float, Blue, b); + GET_SET(float, Alpha, a); - float r, g, b, a; + float r, g, b, a; - luaxport: +luaxport: - LUAX_DECL_FACTORY(Color); + LUAX_DECL_FACTORY(Color); - LUAX_DECL_METHOD(_ToColor32); - LUAX_DECL_METHOD(_SetColor); - LUAX_DECL_METHOD(_GetColor); - LUAX_DECL_METHOD(_GetR); - LUAX_DECL_METHOD(_GetG); - LUAX_DECL_METHOD(_GetB); - LUAX_DECL_METHOD(_GetA); + LUAX_DECL_METHOD(_ToColor32); + LUAX_DECL_METHOD(_SetColor); + LUAX_DECL_METHOD(_GetColor); + LUAX_DECL_METHOD(_GetR); + LUAX_DECL_METHOD(_GetG); + LUAX_DECL_METHOD(_GetB); + LUAX_DECL_METHOD(_GetA); - // Ԫ - LUAX_DECL_METHOD(___eq); // __eq - LUAX_DECL_METHOD(___add); // __add - LUAX_DECL_METHOD(___sub); // __sub - LUAX_DECL_METHOD(___mul); // __mul - LUAX_DECL_METHOD(___div); // __div + // Ԫ + LUAX_DECL_METHOD(___eq); // __eq + LUAX_DECL_METHOD(___add); // __add + LUAX_DECL_METHOD(___sub); // __sub + LUAX_DECL_METHOD(___mul); // __mul + LUAX_DECL_METHOD(___div); // __div - }; +}; - } -} +namespace_end +namespace_end namespace AEGraphics = AsuraEngine::Graphics; diff --git a/source/modules/asura-core/graphics/color32.cpp b/source/modules/asura-core/graphics/color32.cpp index 28260d5..11239c8 100644 --- a/source/modules/asura-core/graphics/color32.cpp +++ b/source/modules/asura-core/graphics/color32.cpp @@ -1,55 +1,53 @@ #include "color.h" #include "color32.h" -namespace AsuraEngine -{ - namespace Graphics - { +namespace_begin(AsuraEngine) +namespace_begin(Graphics) #if ASURA_LITTLE_ENDIAN - // СˣֽڵAlphaڸߵַ - const uint32 Color32::RMASK = 0x000000ff; - const uint32 Color32::GMASK = 0x0000ff00; - const uint32 Color32::BMASK = 0x00ff0000; - const uint32 Color32::AMASK = 0xff000000; +// СˣֽڵAlphaڸߵַ +const uint32 Color32::RMASK = 0x000000ff; +const uint32 Color32::GMASK = 0x0000ff00; +const uint32 Color32::BMASK = 0x00ff0000; +const uint32 Color32::AMASK = 0xff000000; #endif - Color32::Color32() - { - r = g = b = a = 0; - } - - Color32::Color32(const Color32& c) - { - r = c.r; - g = c.g; - b = c.b; - a = c.a; - } - - Color32::Color32(const Color& c) - { - r = 255.f * c.r; - g = 255.f * c.g; - b = 255.f * c.b; - a = 255.f * c.a; - } - - Color32::Color32(byte r, byte g, byte b, byte a) - { - this->r = r; - this->g = g; - this->b = b; - this->a = a; - } - - void Color32::Set(const Color32& c32) - { - r = c32.r; - g = c32.g; - b = c32.b; - a = c32.a; - } - - } -}
\ No newline at end of file +Color32::Color32() +{ + r = g = b = a = 0; +} + +Color32::Color32(const Color32& c) +{ + r = c.r; + g = c.g; + b = c.b; + a = c.a; +} + +Color32::Color32(const Color& c) +{ + r = 255.f * c.r; + g = 255.f * c.g; + b = 255.f * c.b; + a = 255.f * c.a; +} + +Color32::Color32(byte r, byte g, byte b, byte a) +{ + this->r = r; + this->g = g; + this->b = b; + this->a = a; +} + +void Color32::Set(const Color32& c32) +{ + r = c32.r; + g = c32.g; + b = c32.b; + a = c32.a; +} + +namespace_end +namespace_end
\ No newline at end of file diff --git a/source/modules/asura-core/graphics/color32.h b/source/modules/asura-core/graphics/color32.h index 9f14155..52405e9 100644 --- a/source/modules/asura-core/graphics/color32.h +++ b/source/modules/asura-core/graphics/color32.h @@ -1,59 +1,58 @@ #ifndef __ASURA_ENGINE_COLOR32_H__ #define __ASURA_ENGINE_COLOR32_H__ +#include <asura-utils/classes.h> #include <asura-utils/scripting/portable.hpp> #include "../core_config.h" -namespace AsuraEngine -{ - namespace Graphics - { +namespace_begin(AsuraEngine) +namespace_begin(Graphics) - class Color; +class Color; - /// - /// 32bitsɫ - /// - class Color32 ASURA_FINAL - : public Scripting::Portable<Color32> - { - public: +/// +/// 32bitsɫ +/// +class Color32 ASURA_FINAL + : public Scripting::Portable<Color32> +{ +public: - static const uint32 RMASK; - static const uint32 GMASK; - static const uint32 BMASK; - static const uint32 AMASK; + static const uint32 RMASK; + static const uint32 GMASK; + static const uint32 BMASK; + static const uint32 AMASK; - Color32(); + Color32(); - ~Color32(); + ~Color32(); - Color32(const Color32& c); + Color32(const Color32& c); - Color32(const Color& c); + Color32(const Color& c); - Color32(byte r, byte g, byte b, byte a); + Color32(byte r, byte g, byte b, byte a); - void Set(const Color32& c32); + void Set(const Color32& c32); - byte r, g, b, a; + byte r, g, b, a; - luaxport: +luaxport: - LUAX_DECL_FACTORY(Color32); + LUAX_DECL_FACTORY(Color32); - LUAX_DECL_METHOD(_ToColor); - LUAX_DECL_METHOD(_SetColor); - LUAX_DECL_METHOD(_GetColor); - LUAX_DECL_METHOD(_GetRed); - LUAX_DECL_METHOD(_GetGreen); - LUAX_DECL_METHOD(_GetBlue); - LUAX_DECL_METHOD(_GetAlpha); + LUAX_DECL_METHOD(_ToColor); + LUAX_DECL_METHOD(_SetColor); + LUAX_DECL_METHOD(_GetColor); + LUAX_DECL_METHOD(_GetRed); + LUAX_DECL_METHOD(_GetGreen); + LUAX_DECL_METHOD(_GetBlue); + LUAX_DECL_METHOD(_GetAlpha); - }; +}; - } -} +namespace_end +namespace_end #endif
\ No newline at end of file diff --git a/source/modules/asura-core/graphics/gfx_device.cpp b/source/modules/asura-core/graphics/gfx_device.cpp index 83ea7f4..234ab23 100644 --- a/source/modules/asura-core/graphics/gfx_device.cpp +++ b/source/modules/asura-core/graphics/gfx_device.cpp @@ -9,201 +9,200 @@ using namespace AEMath; -namespace AsuraEngine -{ - namespace Graphics - { +namespace_begin(AsuraEngine) +namespace_begin(Graphics) #if ASURA_DEBUG - static bool instantiated = false; +static bool instantiated = false; #endif - GfxDevice gfx; +GfxDevice gfx; - GfxDevice::GfxDevice() - { +GfxDevice::GfxDevice() +{ #if ASURA_DEBUG - ASSERT(!instantiated); - instantiated = true; + ASSERT(!instantiated); + instantiated = true; #endif - } +} - GfxDevice::~GfxDevice() - { - } +GfxDevice::~GfxDevice() +{ +} - GfxDevice& GfxDevice::Get() - { - return gfx; - } +GfxDevice& GfxDevice::Get() +{ + return gfx; +} - static bool inited = false; +static bool inited = false; - bool GfxDevice::Init(const AEMath::Recti& view) - { - bool loaded = false; +bool GfxDevice::Init(const AEMath::Recti& view) +{ + bool loaded = false; #if ASURA_OPENGL_LOADER & ASURA_OPENGL_GLAD - if (!loaded) - loaded = gladLoadGL(); + if (!loaded) + loaded = gladLoadGL(); #endif - if (!loaded) - return false; - SetViewport(view); - - inited = true; - return true; - } - - bool GfxDevice::Inited() - { - return inited; - } - - void GfxDevice::WipeError() - { - while (glGetError() != GL_NO_ERROR); - } - - bool GfxDevice::HasError() - { - return glGetError() != GL_NO_ERROR; - } - - GLenum GfxDevice::GetError() - { - return glGetError(); - } - - void GfxDevice::SetDrawColor(float r, float g, float b, float a) - { - state.drawColor.Set(r, g, b, a); - } - - Color& GfxDevice::GetDrawColor() - { - 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; - glViewport(v.x, v.y, v.w, v.h); - } - - const Recti& GfxDevice::GetViewport() - { - return state.viewport; - } - - void GfxDevice::SetActiveShader(Shader* shader) - { - if (state.shader == shader) - return; - if (state.shader) - state.shader->OnDisable(); - state.shader = shader; - if (shader) - { - GLint program = shader->GetGLProgram(); - glUseProgram(program); + if (!loaded) + return false; + SetViewport(view); + + inited = true; + return true; +} + +bool GfxDevice::Inited() +{ + return inited; +} + +void GfxDevice::WipeError() +{ + while (glGetError() != GL_NO_ERROR); +} + +bool GfxDevice::HasError() +{ + return glGetError() != GL_NO_ERROR; +} + +GLenum GfxDevice::GetError() +{ + return glGetError(); +} + +void GfxDevice::SetDrawColor(float r, float g, float b, float a) +{ + state.drawColor.Set(r, g, b, a); +} + +Color& GfxDevice::GetDrawColor() +{ + 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; + glViewport(v.x, v.y, v.w, v.h); +} + +const Recti& GfxDevice::GetViewport() +{ + return state.viewport; +} + +void GfxDevice::SetActiveShader(Shader* shader) +{ + if (state.shader == shader) + return; + if (state.shader) + state.shader->OnDisable(); + state.shader = shader; + if (shader) + { + GLint program = shader->GetGLProgram(); + glUseProgram(program); #if ASURA_GL_PROFILE - ++stats.shaderSwitch; + ++stats.shaderSwitch; #endif - shader->OnEnable(); - } - } - - Shader* GfxDevice::GetActiveShader() const - { - return state.shader; - } - - void GfxDevice::DrawArrays(GLenum mode, GLint first, GLsizei count) - { - glDrawArrays(mode, first, count); + shader->OnEnable(); + } +} + +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; + ++stats.drawCall; #endif - if (state.shader) - state.shader->OnUsed(); - } - - void GfxDevice::SetMatrixMode (MatrixMode mode) - { - state.matrixMode = mode; - } - - MatrixMode GfxDevice::GetMatrixMode () - { - return state.matrixMode; - } - - void GfxDevice::PushMatrix () - { - state.matrix[state.matrixMode].Push (); - } - - void GfxDevice::PopMatrix () - { - state.matrix[state.matrixMode].Pop(); - } - - void GfxDevice::LoadIdentity() - { - state.matrix[state.matrixMode].LoadIdentity(); - } - - void GfxDevice::Rotate (float angle) - { - state.matrix[state.matrixMode].Rotate(angle); - } - - void GfxDevice::Translate (float x, float y) - { - state.matrix[state.matrixMode].Translate(x, y); - } - - void GfxDevice::Scale (float x, float y) - { - state.matrix[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); - } - - AEMath::Matrix44& GfxDevice::GetMatrix(MatrixMode mode) - { - return state.matrix[mode].GetTop(); - } - - AEMath::Matrix44 GfxDevice::GetMVPMatrix() - { - return state.matrix[MATRIX_MODE_PROJECTION].GetTop() - * state.matrix[MATRIX_MODE_VIEW].GetTop() - * state.matrix[MATRIX_MODE_MODEL].GetTop(); - } - - uint GfxDevice::GetMatrixDepth() - { - return state.matrix[state.matrixMode].GetCapacity(); - } - - uint GfxDevice::GetMatrixIndex() - { - return state.matrix[state.matrixMode].GetTopIndex(); - } - - } // Graphics -} // AsuraEngine
\ No newline at end of file + if (state.shader) + state.shader->OnUsed(); +} + +void GfxDevice::SetMatrixMode (MatrixMode mode) +{ + state.matrixMode = mode; +} + +MatrixMode GfxDevice::GetMatrixMode () +{ + return state.matrixMode; +} + +void GfxDevice::PushMatrix () +{ + state.matrix[state.matrixMode].Push (); +} + +void GfxDevice::PopMatrix () +{ + state.matrix[state.matrixMode].Pop(); +} + +void GfxDevice::LoadIdentity() +{ + state.matrix[state.matrixMode].LoadIdentity(); +} + +void GfxDevice::Rotate (float angle) +{ + state.matrix[state.matrixMode].Rotate(angle); +} + +void GfxDevice::Translate (float x, float y) +{ + state.matrix[state.matrixMode].Translate(x, y); +} + +void GfxDevice::Scale (float x, float y) +{ + state.matrix[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); +} + +AEMath::Matrix44& GfxDevice::GetMatrix(MatrixMode mode) +{ + return state.matrix[mode].GetTop(); +} + +AEMath::Matrix44 GfxDevice::GetMVPMatrix() +{ + return state.matrix[MATRIX_MODE_PROJECTION].GetTop() + * state.matrix[MATRIX_MODE_VIEW].GetTop() + * state.matrix[MATRIX_MODE_MODEL].GetTop(); +} + +uint GfxDevice::GetMatrixDepth() +{ + return state.matrix[state.matrixMode].GetCapacity(); +} + +uint GfxDevice::GetMatrixIndex() +{ + return state.matrix[state.matrixMode].GetTopIndex(); +} + + +namespace_end +namespace_end
\ No newline at end of file diff --git a/source/modules/asura-core/graphics/gfx_device.h b/source/modules/asura-core/graphics/gfx_device.h index 385f703..8d401dc 100644 --- a/source/modules/asura-core/graphics/gfx_device.h +++ b/source/modules/asura-core/graphics/gfx_device.h @@ -13,129 +13,127 @@ #include "color.h" #include "matrix_stack.h" -namespace AsuraEngine -{ - namespace Graphics - { +namespace_begin(AsuraEngine) +namespace_begin(Graphics) - class Profiler; - class Shader; - class GPUBuffer; - class Canvas; +class Profiler; +class Shader; +class GPUBuffer; +class Canvas; - enum MatrixMode - { - MATRIX_MODE_PROJECTION = 0, - MATRIX_MODE_MODEL = 1, - MATRIX_MODE_VIEW = 2, - }; +enum MatrixMode +{ + MATRIX_MODE_PROJECTION = 0, + MATRIX_MODE_MODEL = 1, + MATRIX_MODE_VIEW = 2, +}; - enum GLParams - { - GL_PARAM_MAX_TEXTURE_UNIT = 1, - }; +enum GLParams +{ + GL_PARAM_MAX_TEXTURE_UNIT = 1, +}; - class GfxDevice : public AEScripting::Portable<GfxDevice> - { - public: +class GfxDevice : public AEScripting::Portable<GfxDevice> +{ +public: - GfxDevice(); - ~GfxDevice(); + 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(); + const AEMath::Recti& GetViewport(); - void SetMatrixMode(MatrixMode mode); - MatrixMode GetMatrixMode(); + void SetMatrixMode(MatrixMode mode); + MatrixMode GetMatrixMode(); - void PushMatrix(); - void PopMatrix(); + 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); + 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(); + uint GetMatrixDepth(); + uint GetMatrixIndex(); - AEMath::Matrix44& GetMatrix(MatrixMode mode); - AEMath::Matrix44 GetMVPMatrix(); + AEMath::Matrix44& GetMatrix(MatrixMode mode); + AEMath::Matrix44 GetMVPMatrix(); - void SetDrawColor(float r, float g, float b, float a); - Color& GetDrawColor(); + void SetDrawColor(float r, float g, float b, float a); + Color& GetDrawColor(); - void SetActiveCanvas(Canvas* = NULL); - Canvas* GetActiveCanvas() const; + void SetActiveCanvas(Canvas* = NULL); + Canvas* GetActiveCanvas() const; - void SetActiveShader(Shader* = NULL); - Shader* GetActiveShader() const; + void SetActiveShader(Shader* = NULL); + Shader* GetActiveShader() const; - void DrawArrays(GLenum mode, GLint first, GLsizei count); + void DrawArrays(GLenum mode, GLint first, GLsizei count); - void WipeError(); - bool HasError(); - GLenum GetError(); + void WipeError(); + bool HasError(); + GLenum GetError(); - private: +private: - friend class Profiler; + friend class Profiler; - struct - { - AEMath::Recti viewport; ///< ǰлHDC߱ڴСı߲ˢʱ䶯 - MatrixStack matrix[3]; ///< model, view, projection - MatrixMode matrixMode; ///< ǰľ - Color drawColor; ///< Ƶɫ - Canvas* canvas; ///< ǰcanvas - Shader* shader; ///< ǰʹõshader - } state; + struct + { + 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 - struct - { - uint drawCall; ///< ͳdrawcall - uint canvasSwitch; ///< лtextureĴ - uint shaderSwitch; ///< лshaderĴ - } stats; + struct + { + uint drawCall; ///< ͳdrawcall + uint canvasSwitch; ///< лtextureĴ + uint shaderSwitch; ///< лshaderĴ + } stats; #endif - luaxport: +luaxport: - LUAX_DECL_SINGLETON(GfxDevice); + LUAX_DECL_SINGLETON(GfxDevice); - LUAX_DECL_ENUM(MatrixMode, 1); - LUAX_DECL_ENUM(GLParams, 1); + LUAX_DECL_ENUM(MatrixMode, 1); + LUAX_DECL_ENUM(GLParams, 1); - LUAX_DECL_METHOD(_SetMatrixMode); - LUAX_DECL_METHOD(_GetMatrixMode); - LUAX_DECL_METHOD(_PushMatrix); - LUAX_DECL_METHOD(_PopMatrix); - LUAX_DECL_METHOD(_LoadIdentity); - LUAX_DECL_METHOD(_Rotate); - LUAX_DECL_METHOD(_Translate); - LUAX_DECL_METHOD(_Scale); - LUAX_DECL_METHOD(_Ortho); - LUAX_DECL_METHOD(_GetMatrixDepth); - LUAX_DECL_METHOD(_GetMatrixIndex); - LUAX_DECL_METHOD(_UseShader); - LUAX_DECL_METHOD(_UnuseShader); + LUAX_DECL_METHOD(_SetMatrixMode); + LUAX_DECL_METHOD(_GetMatrixMode); + LUAX_DECL_METHOD(_PushMatrix); + LUAX_DECL_METHOD(_PopMatrix); + LUAX_DECL_METHOD(_LoadIdentity); + LUAX_DECL_METHOD(_Rotate); + LUAX_DECL_METHOD(_Translate); + LUAX_DECL_METHOD(_Scale); + LUAX_DECL_METHOD(_Ortho); + LUAX_DECL_METHOD(_GetMatrixDepth); + LUAX_DECL_METHOD(_GetMatrixIndex); + LUAX_DECL_METHOD(_UseShader); + LUAX_DECL_METHOD(_UnuseShader); - }; +}; - // ȫ GfxDevice - extern GfxDevice gfx; +// ȫ GfxDevice +extern GfxDevice gfx; - } -} +namespace_end +namespace_end #endif
\ No newline at end of file diff --git a/source/modules/asura-core/graphics/gpu_buffer.cpp b/source/modules/asura-core/graphics/gpu_buffer.cpp index 4d59009..bf5ac6a 100644 --- a/source/modules/asura-core/graphics/gpu_buffer.cpp +++ b/source/modules/asura-core/graphics/gpu_buffer.cpp @@ -1,153 +1,151 @@ #include "gpu_buffer.h" -namespace AsuraEngine -{ - namespace Graphics - { +namespace_begin(AsuraEngine) +namespace_begin(Graphics) - GPUBuffer::GPUBuffer(BufferType type, BufferUsage usage, BufferDataType dataType, size_t size) - : m_Target(GL_ZERO) - , m_Buffer(GL_ZERO) - , m_Size(0) +GPUBuffer::GPUBuffer(BufferType type, BufferUsage usage, BufferDataType dataType, size_t size) + : m_Target(GL_ZERO) + , m_Buffer(GL_ZERO) + , m_Size(0) #if ASURA_DEBUG - , m_Data(nullptr) + , m_Data(nullptr) #endif - { - m_Target = ConvertBufferType(type); - m_Usage = ConvertBufferUsage(usage); - m_DataType = ConvertBufferDataType(dataType); - m_Size = size; - } +{ + m_Target = ConvertBufferType(type); + m_Usage = ConvertBufferUsage(usage); + m_DataType = ConvertBufferDataType(dataType); + m_Size = size; +} - GPUBuffer::~GPUBuffer() - { +GPUBuffer::~GPUBuffer() +{ #if ASURA_DEBUG - if (m_Data) - free(m_Data); + if (m_Data) + free(m_Data); #endif - glDeleteBuffers(1, &m_Buffer); - } + glDeleteBuffers(1, &m_Buffer); +} - GLenum GPUBuffer::ConvertBufferType(BufferType type) - { - switch (type) - { - case BUFFER_TYPE_VERTEX: - return GL_ARRAY_BUFFER; - case BUFFER_TYPE_INDEX: - return GL_ELEMENT_ARRAY_BUFFER; - } - } +GLenum GPUBuffer::ConvertBufferType(BufferType type) +{ + switch (type) + { + case BUFFER_TYPE_VERTEX: + return GL_ARRAY_BUFFER; + case BUFFER_TYPE_INDEX: + return GL_ELEMENT_ARRAY_BUFFER; + } +} - GLenum GPUBuffer::ConvertBufferUsage(BufferUsage usage) - { - switch (usage) - { - case BUFFER_USAGE_STREAM: - return GL_STREAM_DRAW; - case BUFFER_USAGE_DYNAMIC: - return GL_DYNAMIC_DRAW; - case BUFFER_USAGE_STATIC: - return GL_STATIC_DRAW; - } - } +GLenum GPUBuffer::ConvertBufferUsage(BufferUsage usage) +{ + switch (usage) + { + case BUFFER_USAGE_STREAM: + return GL_STREAM_DRAW; + case BUFFER_USAGE_DYNAMIC: + return GL_DYNAMIC_DRAW; + case BUFFER_USAGE_STATIC: + return GL_STATIC_DRAW; + } +} - GLenum GPUBuffer::ConvertBufferDataType(BufferDataType type) - { - switch (type) - { - case BUFFER_DATA_TYPE_INT: - return GL_INT; - case BUFFER_DATA_TYPE_FLOAT: - return GL_FLOAT; - case BUFFER_DATA_TYPE_UNSIGNED_BYTE: - return GL_UNSIGNED_BYTE; - } - } +GLenum GPUBuffer::ConvertBufferDataType(BufferDataType type) +{ + switch (type) + { + case BUFFER_DATA_TYPE_INT: + return GL_INT; + case BUFFER_DATA_TYPE_FLOAT: + return GL_FLOAT; + case BUFFER_DATA_TYPE_UNSIGNED_BYTE: + return GL_UNSIGNED_BYTE; + } +} - bool GPUBuffer::Fill(const void * data, size_t size, uint offset) +bool GPUBuffer::Fill(const void * data, size_t size, uint offset) +{ + if (data == nullptr) + return false; + if (m_Buffer == 0) + { + gfx.WipeError(); + glGenBuffers(1, &m_Buffer); + if (m_Buffer == 0) + throw Exception("OpenGL glGenBuffers failed."); + glBindBuffer(m_Target, m_Buffer); + glBufferData(m_Target, m_Size, NULL, m_Usage); + if (gfx.HasError()) { - if (data == nullptr) - return false; - if (m_Buffer == 0) - { - gfx.WipeError(); - glGenBuffers(1, &m_Buffer); - if (m_Buffer == 0) - throw Exception("OpenGL glGenBuffers failed."); - glBindBuffer(m_Target, m_Buffer); - glBufferData(m_Target, m_Size, NULL, m_Usage); - if (gfx.HasError()) - { - glBindBuffer(m_Target, 0); - throw Exception("OpenGL glBufferData failed. Errorcode=%d.", gfx.GetError()); - } + glBindBuffer(m_Target, 0); + throw Exception("OpenGL glBufferData failed. Errorcode=%d.", gfx.GetError()); + } #if ASURA_DEBUG - m_Data = (byte*)malloc(size); - memset(m_Data, 0, size); + m_Data = (byte*)malloc(size); + memset(m_Data, 0, size); #endif - } - else - glBindBuffer(m_Target, m_Buffer); - glBufferSubData(m_Target, offset, size, data); - if (gfx.HasError()) - { - glBindBuffer(m_Target, 0); - throw Exception("OpenGL glBufferSubData failed. Errorcode=%d.", gfx.GetError()); - } - glBindBuffer(m_Target, 0); + } + else + glBindBuffer(m_Target, m_Buffer); + glBufferSubData(m_Target, offset, size, data); + if (gfx.HasError()) + { + glBindBuffer(m_Target, 0); + throw Exception("OpenGL glBufferSubData failed. Errorcode=%d.", gfx.GetError()); + } + glBindBuffer(m_Target, 0); #if ASURA_DEBUG - memcpy(m_Data + offset, data, size); + memcpy(m_Data + offset, data, size); #endif - return true; - } + return true; +} - void GPUBuffer::Bind() - { - glBindBuffer(m_Target, m_Buffer); - } +void GPUBuffer::Bind() +{ + glBindBuffer(m_Target, m_Buffer); +} - void GPUBuffer::UnBind() - { - glBindBuffer(m_Target, 0); - } - - uint GPUBuffer::GetBufferSize() - { - return m_Size; - } +void GPUBuffer::UnBind() +{ + glBindBuffer(m_Target, 0); +} - GLenum GPUBuffer::GetDataType() - { - return m_DataType; - } +uint GPUBuffer::GetBufferSize() +{ + return m_Size; +} - size_t GPUBuffer::GetDataTypeSize() - { - //https://blog.csdn.net/nklinux/article/details/16919017 - switch (m_DataType) - { - case GL_UNSIGNED_BYTE: - return sizeof(GLbyte); - case GL_FLOAT : - return sizeof(GLfloat); - case GL_INT: - return sizeof(GLint); - } - } +GLenum GPUBuffer::GetDataType() +{ + return m_DataType; +} - size_t GPUBuffer::GetDataTypeSize(GLenum datatype) - { - switch (datatype) - { - case GL_UNSIGNED_BYTE: - return sizeof(GLbyte); - case GL_FLOAT: - return sizeof(GLfloat); - case GL_INT: - return sizeof(GLint); - } - } +size_t GPUBuffer::GetDataTypeSize() +{ + //https://blog.csdn.net/nklinux/article/details/16919017 + switch (m_DataType) + { + case GL_UNSIGNED_BYTE: + return sizeof(GLbyte); + case GL_FLOAT : + return sizeof(GLfloat); + case GL_INT: + return sizeof(GLint); + } +} +size_t GPUBuffer::GetDataTypeSize(GLenum datatype) +{ + switch (datatype) + { + case GL_UNSIGNED_BYTE: + return sizeof(GLbyte); + case GL_FLOAT: + return sizeof(GLfloat); + case GL_INT: + return sizeof(GLint); } -}
\ No newline at end of file +} + +namespace_end +namespace_end
\ 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 09c5476..3153904 100644 --- a/source/modules/asura-core/graphics/gpu_buffer.h +++ b/source/modules/asura-core/graphics/gpu_buffer.h @@ -7,91 +7,89 @@ #include "gfx_device.h" -namespace AsuraEngine +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + +enum BufferType +{ + BUFFER_TYPE_VERTEX, ///< 㻺壬position\tangent\normal\color\texcoord(n) + BUFFER_TYPE_INDEX, ///< +}; + +enum BufferUsage +{ + BUFFER_USAGE_STREAM, ///< һΣʹô + BUFFER_USAGE_DYNAMIC, ///< һΣʹ + BUFFER_USAGE_STATIC, ///< ĺʹ +}; + +enum BufferDataType +{ + BUFFER_DATA_TYPE_INT, + BUFFER_DATA_TYPE_FLOAT, + BUFFER_DATA_TYPE_UNSIGNED_BYTE, +}; + +/// +/// VRAM壬ֶ㻺vboebo֣ÿζڴԴϴݡframeworkrenderers +/// +/// +ASURA_ABSTRACT class GPUBuffer { - namespace Graphics - { - - enum BufferType - { - BUFFER_TYPE_VERTEX, ///< 㻺壬position\tangent\normal\color\texcoord(n) - BUFFER_TYPE_INDEX, ///< - }; - - enum BufferUsage - { - BUFFER_USAGE_STREAM, ///< һΣʹô - BUFFER_USAGE_DYNAMIC, ///< һΣʹ - BUFFER_USAGE_STATIC, ///< ĺʹ - }; - - enum BufferDataType - { - BUFFER_DATA_TYPE_INT, - BUFFER_DATA_TYPE_FLOAT, - BUFFER_DATA_TYPE_UNSIGNED_BYTE, - }; - - /// - /// VRAM壬ֶ㻺vboebo֣ÿζڴԴϴݡframeworkrenderers - /// - /// - ASURA_ABSTRACT class GPUBuffer - { - public: - - GPUBuffer(BufferType type, BufferUsage usage, BufferDataType datatype, size_t size); - virtual ~GPUBuffer(); - - static size_t GetDataTypeSize(GLenum datatype); - - bool Fill(const void* data, size_t size, uint offset = 0) ASURA_THROW(Exception); - - void Bind(); - void UnBind(); - - uint GetBufferSize(); - uint GetBufferCount(); - GLenum GetDataType(); - size_t GetDataTypeSize(); - - private: - - GLenum ConvertBufferType(BufferType type); - GLenum ConvertBufferUsage(BufferUsage type); - GLenum ConvertBufferDataType(BufferDataType type); - - GLenum m_Target; - GLuint m_Buffer; - /// - /// openglԴ滺岢ûж͵ҪֻglVertexAttribPointerʱָ - /// drawcall ʱݸʼַʹbufferȡඥݣԲͬ - /// ԱһbufferСΪ˱ֽӿڵļ࣬ڳʼbufferʱָ - /// ͣڱ͵һ£Բͬͷͬbuffer - /// - GLenum m_DataType; - GLuint m_Usage; - uint m_Size; +public: + + GPUBuffer(BufferType type, BufferUsage usage, BufferDataType datatype, size_t size); + virtual ~GPUBuffer(); + + static size_t GetDataTypeSize(GLenum datatype); + + bool Fill(const void* data, size_t size, uint offset = 0) ASURA_THROW(Exception); + + void Bind(); + void UnBind(); + + uint GetBufferSize(); + uint GetBufferCount(); + GLenum GetDataType(); + size_t GetDataTypeSize(); + +private: + + GLenum ConvertBufferType(BufferType type); + GLenum ConvertBufferUsage(BufferUsage type); + GLenum ConvertBufferDataType(BufferDataType type); + + GLenum m_Target; + GLuint m_Buffer; + + /// openglԴ滺岢ûж͵ҪֻglVertexAttribPointerʱָdrawcall ʱݸ + /// ʼַʹbufferȡඥݣԲͬͿԱһbufferСΪ˱ + /// ӿڵļ࣬ڳʼbufferʱָͣڱ͵һ£Բͬ + /// ͷͬbuffer + + GLenum m_DataType; + GLuint m_Usage; + uint m_Size; #if ASURA_DEBUG - byte* m_Data; + byte* m_Data; #endif - luaxport: +luaxport: - LUAX_DECL_ABSTRACT_FACTORY(GPUBuffer); + LUAX_DECL_ABSTRACT_FACTORY(GPUBuffer); - LUAX_DECL_ENUM(BufferType, 1); - LUAX_DECL_ENUM(BufferUsage, 1); - LUAX_DECL_ENUM(BufferDataType, 2); + LUAX_DECL_ENUM(BufferType, 1); + LUAX_DECL_ENUM(BufferUsage, 1); + LUAX_DECL_ENUM(BufferDataType, 2); - LUAX_DECL_METHOD(_Fill); - LUAX_DECL_METHOD(_GetSize); - LUAX_DECL_METHOD(_GetCount); + LUAX_DECL_METHOD(_Fill); + LUAX_DECL_METHOD(_GetSize); + LUAX_DECL_METHOD(_GetCount); - }; +}; - } -} +namespace_end +namespace_end #endif
\ No newline at end of file diff --git a/source/modules/asura-core/graphics/image.cpp b/source/modules/asura-core/graphics/image.cpp index a0dff8d..32fa870 100644 --- a/source/modules/asura-core/graphics/image.cpp +++ b/source/modules/asura-core/graphics/image.cpp @@ -9,97 +9,95 @@ using namespace AEIO; using namespace AEImage; -namespace AsuraEngine +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + +Image::Image() + : m_Width(0) + , m_Height(0) +{ +} + +Image::~Image() +{ +} + +bool Image::Load(ImageData* imgData) { - namespace Graphics + if (!imgData) return false; + + if (m_TexID == 0) { + glGenTextures(1, &m_TexID); + if (m_TexID == 0) + throw Exception("OpenGL glGenTextures failed."); + } + + glBindTexture(GL_TEXTURE_2D, m_TexID); + imgData->Lock(); + int width = imgData->width; + int height = imgData->height; + TextureFormat tf = ConvertColorFormat(imgData->format); + glTexImage2D( + GL_TEXTURE_2D + , 0 + , tf.internalformat + , width, height + , 0 + , tf.externalformat + , tf.type + , imgData->pixels + ); + + m_Width = imgData->width; + m_Height = imgData->height; + imgData->Unlock(); + GLenum err = glGetError(); + if (err != GL_NO_ERROR) + throw Exception("OpenGL glTexImage2D cause error, error code=%d", err); + glBindTexture(GL_TEXTURE_2D, 0); + + return true; +} + +bool Image::Load(ImageData* imgData, const AEMath::Vector2i& pos) +{ + if (!imgData) return false; + + glBindTexture(GL_TEXTURE_2D, m_TexID); + imgData->Lock(); + int width = imgData->width; + int height = imgData->height; + TextureFormat tf = ConvertColorFormat(imgData->format); + glTexSubImage2D( + GL_TEXTURE_2D + , 0 + , pos.x + , pos.y + , imgData->width + , imgData->height + , tf.externalformat + , tf.type + , imgData->pixels + ); + imgData->Unlock(); + GLenum err = glGetError(); + if (err != GL_NO_ERROR) + throw Exception("OpenGL glTexSubImage2D cause error, error code=%d", err); + glBindTexture(GL_TEXTURE_2D, 0); + + return true; +} + +uint32 Image::GetWidth() +{ + return m_Width; +} + +uint32 Image::GetHeight() +{ + return m_Height; +} - Image::Image() - : m_Width(0) - , m_Height(0) - { - } - - Image::~Image() - { - } - - bool Image::Load(ImageData* imgData) - { - if (!imgData) return false; - - if (m_TexID == 0) - { - glGenTextures(1, &m_TexID); - if (m_TexID == 0) - throw Exception("OpenGL glGenTextures failed."); - } - - glBindTexture(GL_TEXTURE_2D, m_TexID); - imgData->Lock(); - int width = imgData->width; - int height = imgData->height; - TextureFormat tf = ConvertColorFormat(imgData->format); - glTexImage2D( - GL_TEXTURE_2D - , 0 - , tf.internalformat - , width, height - , 0 - , tf.externalformat - , tf.type - , imgData->pixels - ); - - m_Width = imgData->width; - m_Height = imgData->height; - imgData->Unlock(); - GLenum err = glGetError(); - if (err != GL_NO_ERROR) - throw Exception("OpenGL glTexImage2D cause error, error code=%d", err); - glBindTexture(GL_TEXTURE_2D, 0); - - return true; - } - - bool Image::Load(ImageData* imgData, const AEMath::Vector2i& pos) - { - if (!imgData) return false; - - glBindTexture(GL_TEXTURE_2D, m_TexID); - imgData->Lock(); - int width = imgData->width; - int height = imgData->height; - TextureFormat tf = ConvertColorFormat(imgData->format); - glTexSubImage2D( - GL_TEXTURE_2D - , 0 - , pos.x - , pos.y - , imgData->width - , imgData->height - , tf.externalformat - , tf.type - , imgData->pixels - ); - imgData->Unlock(); - GLenum err = glGetError(); - if (err != GL_NO_ERROR) - throw Exception("OpenGL glTexSubImage2D cause error, error code=%d", err); - glBindTexture(GL_TEXTURE_2D, 0); - - return true; - } - - uint32 Image::GetWidth() - { - return m_Width; - } - - uint32 Image::GetHeight() - { - return m_Height; - } - - } // Graphics -} // AsuraEngine
\ No newline at end of file +namespace_end +namespace_end
\ No newline at end of file diff --git a/source/modules/asura-core/graphics/image.h b/source/modules/asura-core/graphics/image.h index 229a849..72f1281 100644 --- a/source/modules/asura-core/graphics/image.h +++ b/source/modules/asura-core/graphics/image.h @@ -19,46 +19,44 @@ #include "gpu_buffer.h" #include "texture.h" -namespace AsuraEngine -{ - namespace Graphics - { +namespace_begin(AsuraEngine) +namespace_begin(Graphics) - class Image ASURA_FINAL : public AEScripting::Portable<Image, Texture> - { - public: +class Image ASURA_FINAL : public AEScripting::Portable<Image, Texture> +{ +public: - Image(); - ~Image(); + Image(); + ~Image(); - bool Load(AEImage::ImageData* decodeData); - bool Load(AEImage::ImageData* decodeData, const AEMath::Vector2i& pos); + bool Load(AEImage::ImageData* decodeData); + bool Load(AEImage::ImageData* decodeData, const AEMath::Vector2i& pos); - uint GetWidth(); - uint GetHeight(); + uint GetWidth(); + uint GetHeight(); - GPUBuffer* GenGPUBuffer(); + GPUBuffer* GenGPUBuffer(); - private: +private: - uint32 m_Width, m_Height; + uint32 m_Width, m_Height; - luaxport: +luaxport: - LUAX_DECL_FACTORY(Image, Texture); + LUAX_DECL_FACTORY(Image, Texture); - LUAX_DECL_METHOD(_New); - LUAX_DECL_METHOD(_Load); - LUAX_DECL_METHOD(_GetWidth); - LUAX_DECL_METHOD(_GetHeight); - LUAX_DECL_METHOD(_GetSize); - LUAX_DECL_METHOD(_GetPixel); - LUAX_DECL_METHOD(_Render); + LUAX_DECL_METHOD(_New); + LUAX_DECL_METHOD(_Load); + LUAX_DECL_METHOD(_GetWidth); + LUAX_DECL_METHOD(_GetHeight); + LUAX_DECL_METHOD(_GetSize); + LUAX_DECL_METHOD(_GetPixel); + LUAX_DECL_METHOD(_Render); - }; +}; - } // Graphics -} // AsuraEngine +namespace_end +namespace_end namespace AEGraphics = AsuraEngine::Graphics; diff --git a/source/modules/asura-core/graphics/index_buffer.cpp b/source/modules/asura-core/graphics/index_buffer.cpp index fd0295d..9d7416f 100644 --- a/source/modules/asura-core/graphics/index_buffer.cpp +++ b/source/modules/asura-core/graphics/index_buffer.cpp @@ -1,18 +1,17 @@ #include "index_buffer.h" -namespace AsuraEngine -{ - namespace Graphics - { +namespace_begin(AsuraEngine) +namespace_begin(Graphics) - IndexBuffer::IndexBuffer(BufferUsage usage, BufferDataType datatype, size_t size) - : GPUBuffer(BUFFER_TYPE_INDEX, usage, datatype, size) - { - } - IndexBuffer::~IndexBuffer() - { - } +IndexBuffer::IndexBuffer(BufferUsage usage, BufferDataType datatype, size_t size) + : GPUBuffer(BUFFER_TYPE_INDEX, usage, datatype, size) +{ +} - } +IndexBuffer::~IndexBuffer() +{ } + +namespace_end +namespace_end diff --git a/source/modules/asura-core/graphics/index_buffer.h b/source/modules/asura-core/graphics/index_buffer.h index 98e901a..538b43b 100644 --- a/source/modules/asura-core/graphics/index_buffer.h +++ b/source/modules/asura-core/graphics/index_buffer.h @@ -5,32 +5,30 @@ #include "gpu_buffer.h" -namespace AsuraEngine +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + +/// +/// +/// +class IndexBuffer ASURA_FINAL + : public AEScripting::Portable<IndexBuffer> + , public GPUBuffer { - namespace Graphics - { +public: - /// - /// - /// - class IndexBuffer ASURA_FINAL - : public AEScripting::Portable<IndexBuffer> - , public GPUBuffer - { - public: + IndexBuffer(BufferUsage usage, BufferDataType datatype, size_t size); + ~IndexBuffer(); - IndexBuffer(BufferUsage usage, BufferDataType datatype, size_t size); - ~IndexBuffer(); +luaxport: - luaxport: + LUAX_DECL_FACTORY(IndexBuffer); - LUAX_DECL_FACTORY(IndexBuffer); + LUAX_DECL_METHOD(_New); - LUAX_DECL_METHOD(_New); +}; - }; - - } -} +namespace_end +namespace_end #endif
\ No newline at end of file diff --git a/source/modules/asura-core/graphics/matrix_stack.cpp b/source/modules/asura-core/graphics/matrix_stack.cpp index 2211158..eaa686f 100644 --- a/source/modules/asura-core/graphics/matrix_stack.cpp +++ b/source/modules/asura-core/graphics/matrix_stack.cpp @@ -1,77 +1,75 @@ #include "matrix_stack.h" -namespace AsuraEngine -{ - namespace Graphics - { +namespace_begin(AsuraEngine) +namespace_begin(Graphics) - MatrixStack::MatrixStack() - : top(0) - { - // ջʼջô˱֤ջԶǿգȡֵ - m_Stack[top].SetIdentity(); - } +MatrixStack::MatrixStack() + : top(0) +{ + // ջʼջô˱֤ջԶǿգȡֵ + m_Stack[top].SetIdentity(); +} - MatrixStack::~MatrixStack() - { - } +MatrixStack::~MatrixStack() +{ +} - void MatrixStack::LoadIdentity() - { - m_Stack[top].SetIdentity(); - } +void MatrixStack::LoadIdentity() +{ + m_Stack[top].SetIdentity(); +} - bool MatrixStack::Push() - { - if (top == ASURA_MAX_MATRIX_STACK_DEPTH - 1) - return false; - ++top; - m_Stack[top] = m_Stack[top - 1]; - return true; - } +bool MatrixStack::Push() +{ + if (top == ASURA_MAX_MATRIX_STACK_DEPTH - 1) + return false; + ++top; + m_Stack[top] = m_Stack[top - 1]; + return true; +} - bool MatrixStack::Pop() - { - if (top == 0) - return false; - --top; - return true; - } +bool MatrixStack::Pop() +{ + if (top == 0) + return false; + --top; + return true; +} - AEMath::Matrix44& MatrixStack::GetTop() - { - return m_Stack[top]; - } +AEMath::Matrix44& MatrixStack::GetTop() +{ + return m_Stack[top]; +} - uint MatrixStack::GetTopIndex() - { - return top; - } +uint MatrixStack::GetTopIndex() +{ + return top; +} - uint MatrixStack::GetCapacity() - { - return ASURA_MAX_MATRIX_STACK_DEPTH; - } +uint MatrixStack::GetCapacity() +{ + return ASURA_MAX_MATRIX_STACK_DEPTH; +} - void MatrixStack::Ortho(float left, float right, float bottom, float top, float near, float far) - { - m_Stack[this->top].Ortho(left, right, bottom, top, near, far); - } +void MatrixStack::Ortho(float left, float right, float bottom, float top, float near, float far) +{ + m_Stack[this->top].Ortho(left, right, bottom, top, near, far); +} - void MatrixStack::Rotate(float angle) - { - m_Stack[top].Rotate(angle); - } +void MatrixStack::Rotate(float angle) +{ + m_Stack[top].Rotate(angle); +} - void MatrixStack::Translate(float x, float y) - { - m_Stack[top].Translate(x, y); - } +void MatrixStack::Translate(float x, float y) +{ + m_Stack[top].Translate(x, y); +} - void MatrixStack::Scale(float x, float y) - { - m_Stack[top].Scale(x, y); - } +void MatrixStack::Scale(float x, float y) +{ + m_Stack[top].Scale(x, y); +} - } -}
\ No newline at end of file +namespace_end +namespace_end
\ No newline at end of file diff --git a/source/modules/asura-core/graphics/matrix_stack.h b/source/modules/asura-core/graphics/matrix_stack.h index 67401d0..ad32bb4 100644 --- a/source/modules/asura-core/graphics/matrix_stack.h +++ b/source/modules/asura-core/graphics/matrix_stack.h @@ -3,57 +3,56 @@ #include <asura-utils/type.h> #include <asura-utils/math/matrix44.h> +#include <asura-utils/classes.h> -namespace AsuraEngine -{ - namespace Graphics - { +namespace_begin(AsuraEngine) +namespace_begin(Graphics) - /// - /// ջľȡ - /// +/// +/// ջľȡ +/// #define ASURA_MAX_MATRIX_STACK_DEPTH 32 // 2KB - /// - /// ջ״ָ̬֮ǰ״̬ջеһstack[i]ֵstack[0]*..*stack[i-1] - /// ֵһϵtransform - /// - /// TODO: template<uint _capacity> MatrixStack - /// - class MatrixStack - { - public: +/// +/// ջ״ָ̬֮ǰ״̬ջеһstack[i]ֵstack[0]*..*stack[i-1] +/// ֵһϵtransform +/// +/// TODO: template<uint _capacity> MatrixStack +/// +class MatrixStack +{ +public: - MatrixStack(); - ~MatrixStack(); + MatrixStack(); + ~MatrixStack(); - void LoadIdentity(); - bool Push(); - bool Pop(); + void LoadIdentity(); + bool Push(); + bool Pop(); - AEMath::Matrix44& GetTop(); - void GetTop(ASURA_OUT AEMath::Matrix44& mat44); + AEMath::Matrix44& GetTop(); + void GetTop(ASURA_OUT AEMath::Matrix44& mat44); - void LoadMatrix(const AEMath::Matrix44& mat44); - void MultMatrix(const AEMath::Matrix44& mat44); + void LoadMatrix(const AEMath::Matrix44& mat44); + void MultMatrix(const AEMath::Matrix44& mat44); - void Rotate(float angle); - void Translate(float x, float y); - void Scale(float x, float y); + 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); + void Ortho(float l, float r, float b, float t, float n, float f); - uint GetTopIndex(); - uint GetCapacity(); + uint GetTopIndex(); + uint GetCapacity(); - private: +private: - AEMath::Matrix44 m_Stack[ASURA_MAX_MATRIX_STACK_DEPTH]; - uint8 top; + AEMath::Matrix44 m_Stack[ASURA_MAX_MATRIX_STACK_DEPTH]; + uint8 top; - }; +}; - } -} +namespace_end +namespace_end #endif
\ No newline at end of file diff --git a/source/modules/asura-core/graphics/mesh2d.h b/source/modules/asura-core/graphics/mesh2d.h index 8c26564..d2d7d3b 100644 --- a/source/modules/asura-core/graphics/mesh2d.h +++ b/source/modules/asura-core/graphics/mesh2d.h @@ -16,39 +16,37 @@ #include "vertex_buffer.h" #include "index_buffer.h" -namespace AsuraEngine -{ - namespace Graphics - { +namespace_begin(AsuraEngine) +namespace_begin(Graphics) - /// - /// 2D meshһЩ㶯 - /// https://en.wikipedia.org/wiki/Polygon_mesh - /// - class Mesh2D ASURA_FINAL - : public Scripting::Portable<Mesh2D> - { - public: +/// +/// 2D meshһЩ㶯 +/// https://en.wikipedia.org/wiki/Polygon_mesh +/// +class Mesh2D ASURA_FINAL + : public Scripting::Portable<Mesh2D> +{ +public: - Mesh2D(); - ~Mesh2D(); + Mesh2D(); + ~Mesh2D(); - bool Load(AEMesh::Mesh2DData* data); + bool Load(AEMesh::Mesh2DData* data); - private: +private: - VertexBuffer* m_VBO; ///< vertex buffer - IndexBuffer* m_IBO; ///< index buffer + VertexBuffer* m_VBO; ///< vertex buffer + IndexBuffer* m_IBO; ///< index buffer - luaxport: +luaxport: - LUAX_DECL_FACTORY(Mesh2D); + LUAX_DECL_FACTORY(Mesh2D); - LUAX_DECL_METHOD(_SetVertex); + LUAX_DECL_METHOD(_SetVertex); - }; +}; - } -} +namespace_end +namespace_end #endif
\ No newline at end of file diff --git a/source/modules/asura-core/graphics/render_state.h b/source/modules/asura-core/graphics/render_state.h index b5814d3..9f138c0 100644 --- a/source/modules/asura-core/graphics/render_state.h +++ b/source/modules/asura-core/graphics/render_state.h @@ -6,44 +6,42 @@ #include "blend_mode.h" -namespace AsuraEngine +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + +class Shader; + +/// +/// Ⱦǰķʽ +/// +struct RenderState ASURA_FINAL { - namespace Graphics - { - - class Shader; - - /// - /// Ⱦǰķʽ - /// - struct RenderState ASURA_FINAL - { - /// - /// Ĭϵrender state - /// - static RenderState Default; - - RenderState(); - ~RenderState(); - - /// - /// λášλúת - /// - Math::Transform transform; - - /// - /// ɫ - /// - Shader* shader; - - /// - /// Ϸʽ - /// - BlendMode blendMode; - - }; - - } -} + /// + /// Ĭϵrender state + /// + static RenderState Default; + + RenderState(); + ~RenderState(); + + /// + /// λášλúת + /// + Math::Transform transform; + + /// + /// ɫ + /// + Shader* shader; + + /// + /// Ϸʽ + /// + BlendMode blendMode; + +}; + +namespace_end +namespace_end #endif
\ No newline at end of file diff --git a/source/modules/asura-core/graphics/render_target.h b/source/modules/asura-core/graphics/render_target.h index 1992f6c..a52e7b0 100644 --- a/source/modules/asura-core/graphics/render_target.h +++ b/source/modules/asura-core/graphics/render_target.h @@ -8,47 +8,45 @@ #include "texture.h" #include "color.h" -namespace AsuraEngine +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + +/// +/// ɱΪȾĿ࣬ +/// Canvas(RenderTexture) +/// Window(RenderWindow) +/// +class RenderTarget : public AEScripting::Object { - namespace Graphics - { - - /// - /// ɱΪȾĿ࣬ - /// Canvas(RenderTexture) - /// Window(RenderWindow) - /// - class RenderTarget : public AEScripting::Object - { - public: - - RenderTarget() {}; - - virtual ~RenderTarget() {}; - - /// - /// ɫcolRT - /// - virtual void Clear(const Color& col = Color::Black) = 0; - - /// - /// ɫcolղRT - /// - virtual void Clear(const Math::Recti& quad, const Color& col = Color::Black) = 0; - - /// - /// textureRT - /// - virtual void Draw(const Drawable* texture, const RenderState& state) = 0; - - /// - /// һtextureRT - /// - virtual void Draw(const Drawable* texture, const Math::Recti& quad, const RenderState& state) = 0; - - }; - - } -} +public: + + RenderTarget() {}; + + virtual ~RenderTarget() {}; + + /// + /// ɫcolRT + /// + virtual void Clear(const Color& col = Color::Black) = 0; + + /// + /// ɫcolղRT + /// + virtual void Clear(const Math::Recti& quad, const Color& col = Color::Black) = 0; + + /// + /// textureRT + /// + virtual void Draw(const Drawable* texture, const RenderState& state) = 0; + + /// + /// һtextureRT + /// + virtual void Draw(const Drawable* texture, const Math::Recti& quad, const RenderState& state) = 0; + +}; + +namespace_end +namespace_end #endif
\ No newline at end of file diff --git a/source/modules/asura-core/graphics/shader.cpp b/source/modules/asura-core/graphics/shader.cpp index 8606e79..eff62f0 100644 --- a/source/modules/asura-core/graphics/shader.cpp +++ b/source/modules/asura-core/graphics/shader.cpp @@ -5,280 +5,278 @@ using namespace std; -namespace AsuraEngine +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + +// texture unit +static uint8 texUnit = 0; + +Shader::Shader() +{ +} + +Shader::~Shader() { - namespace Graphics + if(m_VertShader) glDeleteShader(m_VertShader); + if(m_FragShader) glDeleteShader(m_FragShader); + if(m_Program) glDeleteProgram(m_Program); +} + +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 = ""; + + if (!m_Program) { + m_Program = glCreateProgram(); + if (!m_Program) + throw Exception("Cannot create OpenGL shader program."); + } - // texture unit - static uint8 texUnit = 0; + if (!CompileVertexShader(vert, warnning)) + { + throw Exception("Compile vertex shader failed:%s", warnning); + } - Shader::Shader() - { - } + if (!CompileFragementShader(frag, warnning)) + { + throw Exception("Compile fragment shader failed:%s", warnning); + } - Shader::~Shader() - { - if(m_VertShader) glDeleteShader(m_VertShader); - if(m_FragShader) glDeleteShader(m_FragShader); - if(m_Program) glDeleteProgram(m_Program); - } + glAttachShader(m_Program, m_VertShader); + glAttachShader(m_Program, m_FragShader); - void Shader::SetActive(Shader* shader) - { - gfx.SetActiveShader(shader); - } + glLinkProgram(m_Program); + GLint success; + glGetProgramiv(m_Program, GL_LINK_STATUS, &success); + if (success == GL_FALSE) + { + warnning = GetProgramWarnings(); + throw Exception("Link shader program failed:\n%s", warnning.c_str()); + } - Shader* Shader::GetActive() - { - return gfx.GetActiveShader(); - } + return true; +} - bool Shader::Load(const string& vert, const string& frag) +bool Shader::CompileVertexShader(const string& vert, string& outError) +{ + if (!m_VertShader) + { + m_VertShader = glCreateShader(GL_VERTEX_SHADER); + if (!m_VertShader) { - string warnning = ""; - - if (!m_Program) - { - m_Program = glCreateProgram(); - if (!m_Program) - throw Exception("Cannot create OpenGL shader program."); - } - - if (!CompileVertexShader(vert, warnning)) - { - throw Exception("Compile vertex shader failed:%s", warnning); - } - - if (!CompileFragementShader(frag, warnning)) - { - throw Exception("Compile fragment shader failed:%s", warnning); - } - - glAttachShader(m_Program, m_VertShader); - glAttachShader(m_Program, m_FragShader); - - glLinkProgram(m_Program); - GLint success; - glGetProgramiv(m_Program, GL_LINK_STATUS, &success); - if (success == GL_FALSE) - { - warnning = GetProgramWarnings(); - throw Exception("Link shader program failed:\n%s", warnning.c_str()); - } - - return true; + outError = "Cannot create OpenGL Vertex shader."; + return false; } + } - bool Shader::CompileVertexShader(const string& vert, string& outError) - { - if (!m_VertShader) - { - m_VertShader = glCreateShader(GL_VERTEX_SHADER); - if (!m_VertShader) - { - outError = "Cannot create OpenGL Vertex shader."; - return false; - } - } - - const GLchar* source = vert.c_str(); - GLint success; - - glShaderSource(m_VertShader, 1, &source, NULL); - glCompileShader(m_VertShader); - glGetShaderiv(m_VertShader, GL_COMPILE_STATUS, &success); - if (success == GL_FALSE) - { - outError = GetShaderWarnings(m_VertShader); - return false; - } - - return true; - } + const GLchar* source = vert.c_str(); + GLint success; - bool Shader::CompileFragementShader(const string& frag, string& outError) - { - if (!m_FragShader) - { - m_FragShader = glCreateShader(GL_FRAGMENT_SHADER); - if (!m_FragShader) - { - outError = "Cannot create OpenGL fragment shader."; - return false; - } - } - - const GLchar* source = frag.c_str(); - GLint success; - - source = frag.c_str(); - glShaderSource(m_FragShader, 1, &source, NULL); - glCompileShader(m_FragShader); - glGetShaderiv(m_FragShader, GL_COMPILE_STATUS, &success); - if (success == GL_FALSE) - { - outError = GetShaderWarnings(m_FragShader); - return false; - } - - return true; - } + glShaderSource(m_VertShader, 1, &source, NULL); + glCompileShader(m_VertShader); + glGetShaderiv(m_VertShader, GL_COMPILE_STATUS, &success); + if (success == GL_FALSE) + { + outError = GetShaderWarnings(m_VertShader); + return false; + } - void Shader::OnEnable() - { - texUnit = 0; - } + return true; +} - void Shader::OnDisable() +bool Shader::CompileFragementShader(const string& frag, string& outError) +{ + if (!m_FragShader) + { + m_FragShader = glCreateShader(GL_FRAGMENT_SHADER); + if (!m_FragShader) { - texUnit = 0; + outError = "Cannot create OpenGL fragment shader."; + return false; } + } - void Shader::OnUsed() - { - texUnit = 0; - } + const GLchar* source = frag.c_str(); + GLint success; - uint Shader::GetUniformLocation(const std::string& uniform) - { - GLint loc = glGetUniformLocation(m_Program, uniform.c_str()); - return loc; - } + source = frag.c_str(); + glShaderSource(m_FragShader, 1, &source, NULL); + glCompileShader(m_FragShader); + glGetShaderiv(m_FragShader, GL_COMPILE_STATUS, &success); + if (success == GL_FALSE) + { + outError = GetShaderWarnings(m_FragShader); + return false; + } - bool Shader::HasUniform(const std::string& uniform) - { - GLint loc = glGetUniformLocation(m_Program, uniform.c_str()); - return loc != -1; - } + return true; +} - GLuint Shader::GetGLProgram() - { - return m_Program; - } +void Shader::OnEnable() +{ + texUnit = 0; +} - void Shader::SetUniformFloat(uint loc, float value) - { - if(gfx.GetActiveShader() == this) - glUniform1f(loc, value); - } +void Shader::OnDisable() +{ + texUnit = 0; +} - bool Shader::SetUniformTexture(uint loc, const Texture& texture) - { - if (gfx.GetActiveShader() != this) - return false; - - gfx.WipeError(); - 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, texUnit); - if (gfx.HasError()) - return false; - ++texUnit; - } +void Shader::OnUsed() +{ + texUnit = 0; +} - void Shader::SetUniformVector2(uint loc, const Math::Vector2f& vec2) - { - if (gfx.GetActiveShader() == this) - glUniform2f(loc, vec2.x, vec2.y); - } +uint Shader::GetUniformLocation(const std::string& uniform) +{ + GLint loc = glGetUniformLocation(m_Program, uniform.c_str()); + return loc; +} - void Shader::SetUniformVector3(uint loc, const Math::Vector3f& vec3) - { - if (gfx.GetActiveShader() == this) - glUniform3f(loc, vec3.x, vec3.y, vec3.z); - } +bool Shader::HasUniform(const std::string& uniform) +{ + GLint loc = glGetUniformLocation(m_Program, uniform.c_str()); + return loc != -1; +} - void Shader::SetUniformVector4(uint loc, const Math::Vector4f& vec4) - { - if (gfx.GetActiveShader() == this) - glUniform4f(loc, vec4.x, vec4.y, vec4.z, vec4.w); - } +GLuint Shader::GetGLProgram() +{ + return m_Program; +} - void Shader::SetUniformMatrix44(uint loc, const Math::Matrix44& mat) - { - if (gfx.GetActiveShader() == this) - glUniformMatrix4fv(loc, 1, GL_FALSE, mat.GetElements()); - } +void Shader::SetUniformFloat(uint loc, float value) +{ + if(gfx.GetActiveShader() == this) + glUniform1f(loc, value); +} - void Shader::SetUniformColor(uint loc, const Color& color) - { - if (gfx.GetActiveShader() == this) - glUniform4f(loc, color.r, color.g, color.b, color.a); - } +bool Shader::SetUniformTexture(uint loc, const Texture& texture) +{ + if (gfx.GetActiveShader() != this) + return false; + + gfx.WipeError(); + 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, texUnit); + if (gfx.HasError()) + return false; + ++texUnit; +} + +void Shader::SetUniformVector2(uint loc, const Math::Vector2f& vec2) +{ + if (gfx.GetActiveShader() == this) + glUniform2f(loc, vec2.x, vec2.y); +} - uint Shader::GetGLTextureUnitCount() - { - GLint maxTextureUnits; - glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &maxTextureUnits); - return (uint)maxTextureUnits; - } +void Shader::SetUniformVector3(uint loc, const Math::Vector3f& vec3) +{ + if (gfx.GetActiveShader() == this) + glUniform3f(loc, vec3.x, vec3.y, vec3.z); +} - std::string Shader::GetProgramWarnings() - { - GLint strsize, nullpos; - glGetProgramiv(m_Program, GL_INFO_LOG_LENGTH, &strsize); +void Shader::SetUniformVector4(uint loc, const Math::Vector4f& vec4) +{ + if (gfx.GetActiveShader() == this) + glUniform4f(loc, vec4.x, vec4.y, vec4.z, vec4.w); +} - if (strsize == 0) - return ""; +void Shader::SetUniformMatrix44(uint loc, const Math::Matrix44& mat) +{ + if (gfx.GetActiveShader() == this) + glUniformMatrix4fv(loc, 1, GL_FALSE, mat.GetElements()); +} - char *tempstr = new char[strsize]; +void Shader::SetUniformColor(uint loc, const Color& color) +{ + if (gfx.GetActiveShader() == this) + glUniform4f(loc, color.r, color.g, color.b, color.a); +} - memset(tempstr, '\0', strsize); - glGetProgramInfoLog(m_Program, strsize, &nullpos, tempstr); - tempstr[nullpos] = '\0'; +uint Shader::GetGLTextureUnitCount() +{ + GLint maxTextureUnits; + glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &maxTextureUnits); + return (uint)maxTextureUnits; +} - std::string warnings(tempstr); - delete[] tempstr; +std::string Shader::GetProgramWarnings() +{ + GLint strsize, nullpos; + glGetProgramiv(m_Program, GL_INFO_LOG_LENGTH, &strsize); - return warnings; - } + if (strsize == 0) + return ""; - std::string Shader::GetShaderWarnings(GLuint shader) - { - GLint strsize, nullpos; - glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &strsize); + char *tempstr = new char[strsize]; - if (strsize == 0) - return ""; + memset(tempstr, '\0', strsize); + glGetProgramInfoLog(m_Program, strsize, &nullpos, tempstr); + tempstr[nullpos] = '\0'; - char *tempstr = new char[strsize]; + std::string warnings(tempstr); + delete[] tempstr; - memset(tempstr, '\0', strsize); - glGetShaderInfoLog(shader, strsize, &nullpos, tempstr); - tempstr[nullpos] = '\0'; + return warnings; +} - std::string warnings(tempstr); - delete[] tempstr; +std::string Shader::GetShaderWarnings(GLuint shader) +{ + GLint strsize, nullpos; + glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &strsize); - return warnings; - } + if (strsize == 0) + return ""; - void Shader::SetAttribute(int loc, VertexBuffer* vbo, uint offseti, uint stridei, bool normalized) - { - GLsizei offset = offseti * vbo->GetDataTypeSize(); - GLsizei stride = stridei * vbo->GetDataTypeSize(); - glEnableVertexAttribArray(loc); - vbo->Bind(); - glVertexAttribPointer(loc, 2, vbo->GetDataType(), normalized, stride, (GLvoid*)offset); - vbo->UnBind(); - } + char *tempstr = new char[strsize]; - int Shader::GetAttributeLocation(const std::string& attribute) - { - int loc = glGetAttribLocation(m_Program, attribute.c_str()); - return loc; - } + memset(tempstr, '\0', strsize); + glGetShaderInfoLog(shader, strsize, &nullpos, tempstr); + tempstr[nullpos] = '\0'; - void Shader::DisableAttribute(int loc) - { - glDisableVertexAttribArray(loc); - } + std::string warnings(tempstr); + delete[] tempstr; - } -}
\ No newline at end of file + return warnings; +} + +void Shader::SetAttribute(int loc, VertexBuffer* vbo, uint offseti, uint stridei, bool normalized) +{ + GLsizei offset = offseti * vbo->GetDataTypeSize(); + GLsizei stride = stridei * vbo->GetDataTypeSize(); + glEnableVertexAttribArray(loc); + vbo->Bind(); + glVertexAttribPointer(loc, 2, vbo->GetDataType(), normalized, stride, (GLvoid*)offset); + vbo->UnBind(); +} + +int Shader::GetAttributeLocation(const std::string& attribute) +{ + int loc = glGetAttribLocation(m_Program, attribute.c_str()); + return loc; +} + +void Shader::DisableAttribute(int loc) +{ + glDisableVertexAttribArray(loc); +} + +namespace_end +namespace_end
\ No newline at end of file diff --git a/source/modules/asura-core/graphics/shader.h b/source/modules/asura-core/graphics/shader.h index dc8dbe0..c535570 100644 --- a/source/modules/asura-core/graphics/shader.h +++ b/source/modules/asura-core/graphics/shader.h @@ -20,100 +20,98 @@ #include "vertex_buffer.h" #include "index_buffer.h" -namespace AsuraEngine +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + +/// +/// һshaderһڲʼ乲ijShaderuniformsͶݣֻṩ uniformsuseɫ +/// ķ༭ÿshaderͨshaderҵuniforms¶frameworkmaterial +/// á +/// +class Shader ASURA_FINAL + : public Scripting::Portable<Shader> + , public AEIO::Renewable { - namespace Graphics - { - - /// - /// һshaderһڲʼ乲ijShaderuniformsͶݣֻṩ uniformsuseɫ - /// ķ༭ÿshaderͨshaderҵuniforms¶frameworkmaterial - /// á - /// - class Shader ASURA_FINAL - : public Scripting::Portable<Shader> - , public AEIO::Renewable - { - public: - - Shader(); - - ~Shader(); - - static void SetActive(Shader* shader); - static Shader* GetActive(); - - bool Load(const std::string& vert, const std::string& frag) ASURA_THROW(Exception); - - // ʹSetActiveлshaderʱ - void OnEnable(); - void OnDisable(); - // Draw call֮ - void OnUsed(); +public: + + Shader(); + + ~Shader(); + + static void SetActive(Shader* shader); + static Shader* GetActive(); + + bool Load(const std::string& vert, const std::string& frag) ASURA_THROW(Exception); + + // ʹ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); - void DisableAttribute(int loc); + void SetAttribute(int loc, VertexBuffer* vbo, uint offseti = 0, uint stridei = 0, bool normalized = false); + int GetAttributeLocation(const std::string& attribute); + void DisableAttribute(int loc); - bool HasUniform(const std::string& uniform); - uint GetUniformLocation(const std::string& uniform); - void SetUniformFloat(uint loc, float value); - void SetUniformVector2(uint loc, const Math::Vector2f& vec2); - void SetUniformVector3(uint loc, const Math::Vector3f& vec3); - void SetUniformVector4(uint loc, const Math::Vector4f& vec4); - void SetUniformColor(uint loc, const Color& color); - void SetUniformMatrix44(uint loc, const Math::Matrix44& mat44); - bool SetUniformTexture(uint loc, const Texture& texture); + bool HasUniform(const std::string& uniform); + uint GetUniformLocation(const std::string& uniform); + void SetUniformFloat(uint loc, float value); + void SetUniformVector2(uint loc, const Math::Vector2f& vec2); + void SetUniformVector3(uint loc, const Math::Vector3f& vec3); + void SetUniformVector4(uint loc, const Math::Vector4f& vec4); + void SetUniformColor(uint loc, const Color& color); + void SetUniformMatrix44(uint loc, const Math::Matrix44& mat44); + bool SetUniformTexture(uint loc, const Texture& texture); - float GetUniformFloat(uint loc); - AEMath::Vector2f GetUniformVector2(uint loc); - AEMath::Vector3f GetUniformVector3(uint loc); - AEMath::Vector4f GetUniformVector4s(uint loc); - AEMath::Matrix44 GetUniformMatrix44(uint loc); + float GetUniformFloat(uint loc); + AEMath::Vector2f GetUniformVector2(uint loc); + AEMath::Vector3f GetUniformVector3(uint loc); + AEMath::Vector4f GetUniformVector4s(uint loc); + AEMath::Matrix44 GetUniformMatrix44(uint loc); - GLuint GetGLProgram(); + GLuint GetGLProgram(); - static uint GetGLTextureUnitCount(); + static uint GetGLTextureUnitCount(); - private: +private: - bool CompileVertexShader(const std::string& vert, std::string& outError); - bool CompileFragementShader(const std::string& frag, std::string& outError); + bool CompileVertexShader(const std::string& vert, std::string& outError); + bool CompileFragementShader(const std::string& frag, std::string& outError); - std::string GetProgramWarnings(); - std::string GetShaderWarnings(GLuint shader); + std::string GetProgramWarnings(); + std::string GetShaderWarnings(GLuint shader); - GLuint m_Program; - GLuint m_VertShader; - GLuint m_FragShader; + GLuint m_Program; + GLuint m_VertShader; + GLuint m_FragShader; - luaxport: +luaxport: - LUAX_DECL_FACTORY(Shader); + LUAX_DECL_FACTORY(Shader); - LUAX_DECL_METHOD(_New); - LUAX_DECL_METHOD(_Load); - LUAX_DECL_METHOD(_Update); - LUAX_DECL_METHOD(_HasUniform); - LUAX_DECL_METHOD(_GetUniformLocation); - LUAX_DECL_METHOD(_SetUniformFloat); - LUAX_DECL_METHOD(_SetUniformTexture); - LUAX_DECL_METHOD(_SetUniformVector2); - LUAX_DECL_METHOD(_SetUniformVector3); - LUAX_DECL_METHOD(_SetUniformVector4); - LUAX_DECL_METHOD(_SetUniformColor); + LUAX_DECL_METHOD(_New); + LUAX_DECL_METHOD(_Load); + LUAX_DECL_METHOD(_Update); + LUAX_DECL_METHOD(_HasUniform); + LUAX_DECL_METHOD(_GetUniformLocation); + LUAX_DECL_METHOD(_SetUniformFloat); + LUAX_DECL_METHOD(_SetUniformTexture); + LUAX_DECL_METHOD(_SetUniformVector2); + LUAX_DECL_METHOD(_SetUniformVector3); + LUAX_DECL_METHOD(_SetUniformVector4); + LUAX_DECL_METHOD(_SetUniformColor); - LUAX_DECL_METHOD(_GetAttributeLocation); - LUAX_DECL_METHOD(_SetAttribute); - LUAX_DECL_METHOD(_DisableAttribute); + LUAX_DECL_METHOD(_GetAttributeLocation); + LUAX_DECL_METHOD(_SetAttribute); + LUAX_DECL_METHOD(_DisableAttribute); - LUAX_DECL_METHOD(_SetBuiltInUniforms); + LUAX_DECL_METHOD(_SetBuiltInUniforms); - }; +}; - typedef Shader GpuProgram; +typedef Shader GpuProgram; - } -} +namespace_end +namespace_end #endif
\ No newline at end of file diff --git a/source/modules/asura-core/graphics/sprite_batch.h b/source/modules/asura-core/graphics/sprite_batch.h index b517334..7f22da0 100644 --- a/source/modules/asura-core/graphics/sprite_batch.h +++ b/source/modules/asura-core/graphics/sprite_batch.h @@ -5,32 +5,30 @@ #include "gpu_buffer.h" -namespace AsuraEngine +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + +/// +/// Sprite batchȾͼƬĵطϵͳ +/// +class SpriteBatch ASURA_FINAL + : public Scripting::Portable<SpriteBatch> { - namespace Graphics - { +public: - /// - /// Sprite batchȾͼƬĵطϵͳ - /// - class SpriteBatch ASURA_FINAL - : public Scripting::Portable<SpriteBatch> - { - public: + SpriteBatch(); - SpriteBatch(); + ~SpriteBatch(); - ~SpriteBatch(); +private: - private: +luaxport: - luaxport: + LUAX_DECL_FACTORY(SpriteBatch); - LUAX_DECL_FACTORY(SpriteBatch); +}; - }; - - } -} +namespace_end +namespace_end #endif
\ No newline at end of file diff --git a/source/modules/asura-core/graphics/texture.cpp b/source/modules/asura-core/graphics/texture.cpp index ef85ceb..42e3851 100644 --- a/source/modules/asura-core/graphics/texture.cpp +++ b/source/modules/asura-core/graphics/texture.cpp @@ -2,48 +2,46 @@ #include "Texture.h" -namespace AsuraEngine -{ - namespace Graphics - { - - Texture::Texture() - : m_TexID(0) - { - } +namespace_begin(AsuraEngine) +namespace_begin(Graphics) - Texture::~Texture() - { - // ͷԴ - if(m_TexID != 0) - glDeleteTextures(1, &m_TexID); - } +Texture::Texture() + : m_TexID(0) +{ +} - GLuint Texture::GetGLTexture() const - { - return m_TexID; - } +Texture::~Texture() +{ + // ͷԴ + if(m_TexID != 0) + glDeleteTextures(1, &m_TexID); +} - TextureFormat Texture::ConvertColorFormat(const ColorFormat& colorformat) - { - TextureFormat t; - switch (colorformat) - { - case COLOR_FORMAT_RGBA8: - t.internalformat = GL_RGBA8; // 4*sizeof(byte) ~= 4 bytes - t.externalformat = GL_RGBA; - t.type = GL_UNSIGNED_BYTE; - break; - case COLOR_FORMAT_RGBA32F: - t.internalformat = GL_RGBA32F; // 4*sizeof(float) = 16 bytes - t.externalformat = GL_RGBA; - t.type = GL_FLOAT; - break; - default: - ASSERT(false); - } - return t; - } +GLuint Texture::GetGLTexture() const +{ + return m_TexID; +} +TextureFormat Texture::ConvertColorFormat(const ColorFormat& colorformat) +{ + TextureFormat t; + switch (colorformat) + { + case COLOR_FORMAT_RGBA8: + t.internalformat = GL_RGBA8; // 4*sizeof(byte) ~= 4 bytes + t.externalformat = GL_RGBA; + t.type = GL_UNSIGNED_BYTE; + break; + case COLOR_FORMAT_RGBA32F: + t.internalformat = GL_RGBA32F; // 4*sizeof(float) = 16 bytes + t.externalformat = GL_RGBA; + t.type = GL_FLOAT; + break; + default: + ASSERT(false); } -}
\ No newline at end of file + return t; +} + +namespace_end +namespace_end
\ No newline at end of file diff --git a/source/modules/asura-core/graphics/texture.h b/source/modules/asura-core/graphics/texture.h index 5d754eb..458e35a 100644 --- a/source/modules/asura-core/graphics/texture.h +++ b/source/modules/asura-core/graphics/texture.h @@ -9,95 +9,93 @@ #include "render_state.h" #include "gfx_device.h" -namespace AsuraEngine +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + +class RenderTarget; + +/// UVʽ +enum WrapMode +{ + WRAP_MODE_REPEAT, + WRAP_MODE_MIRROR, + WRAP_MODE_CLAMPTOEDGE, + WRAP_MODE_CLAMPTOBORDER, +}; + +/// ˲ģʽ +enum FilterMode { - namespace Graphics - { - - class RenderTarget; - - /// UVʽ - enum WrapMode - { - WRAP_MODE_REPEAT, - WRAP_MODE_MIRROR, - WRAP_MODE_CLAMPTOEDGE, - WRAP_MODE_CLAMPTOBORDER, - }; - - /// ˲ģʽ - enum FilterMode - { - FILTER_MODE_NEAREST, - FILTER_MODE_LINEAR, - }; - - /// ͼݵɫʽ - enum ColorFormat - { - COLOR_FORMAT_UNKNOWN, - COLOR_FORMAT_RGBA8, ///< RGBA8bits int - COLOR_FORMAT_RGBA32F, ///< RGBA32bits float - }; - - /// ʽGPUڲCPUⲿʽ - struct TextureFormat - { - GLenum internalformat; ///< GPUڲʽ - GLenum externalformat; ///< CPUⲿʽ - GLenum type; ///< ⲿʽÿchannelֵ - }; - - /// - /// 2D࣬2d meshrender targetбʹáTextureȾԭϽǣϷϲԵѿ - /// ϵΪEditorҲϽΪԭ㣬Ϊ˷㡣 - /// - ASURA_ABSTRACT class Texture : public AEScripting::Object - { - public: - - LUAX_DECL_ABSTRACT_FACTORY(Texture); - - Texture(); - virtual ~Texture(); - - GLuint GetGLTexture() const; - - void SetFilterMode(FilterMode min, FilterMode mag); - void SetWrapMode(WrapMode wrapMode); - - void GetFilterMode(); - void GetWrapMode(); - - /// UVfilterΪ - bool IsGenMipmap(); - - protected: - - /// תcolor formatΪtexture format - TextureFormat ConvertColorFormat(const ColorFormat& colorformat); - - GLuint m_TexID; - FilterMode m_MinFilter; - FilterMode m_MagFilter; - WrapMode m_WrapMode; - bool m_IsGenMipmap; - - LUAX_DECL_ENUM(ColorFormat, 1); - LUAX_DECL_ENUM(FilterMode, 1); - LUAX_DECL_ENUM(WrapMode, 1); - - LUAX_DECL_METHOD(_SetFilterMode); - LUAX_DECL_METHOD(_SetWrapMode); - LUAX_DECL_METHOD(_GetFilterMode); - LUAX_DECL_METHOD(_GetWrapMode); - LUAX_DECL_METHOD(_IsGenMipmap); - - }; - - typedef Texture Drawable; - - } -} + FILTER_MODE_NEAREST, + FILTER_MODE_LINEAR, +}; + +/// ͼݵɫʽ +enum ColorFormat +{ + COLOR_FORMAT_UNKNOWN, + COLOR_FORMAT_RGBA8, ///< RGBA8bits int + COLOR_FORMAT_RGBA32F, ///< RGBA32bits float +}; + +/// ʽGPUڲCPUⲿʽ +struct TextureFormat +{ + GLenum internalformat; ///< GPUڲʽ + GLenum externalformat; ///< CPUⲿʽ + GLenum type; ///< ⲿʽÿchannelֵ +}; + +/// +/// 2D࣬2d meshrender targetбʹáTextureȾԭϽǣϷϲԵѿ +/// ϵΪEditorҲϽΪԭ㣬Ϊ˷㡣 +/// +ASURA_ABSTRACT class Texture : public AEScripting::Object +{ +public: + + LUAX_DECL_ABSTRACT_FACTORY(Texture); + + Texture(); + virtual ~Texture(); + + GLuint GetGLTexture() const; + + void SetFilterMode(FilterMode min, FilterMode mag); + void SetWrapMode(WrapMode wrapMode); + + void GetFilterMode(); + void GetWrapMode(); + + /// UVfilterΪ + bool IsGenMipmap(); + +protected: + + /// תcolor formatΪtexture format + TextureFormat ConvertColorFormat(const ColorFormat& colorformat); + + GLuint m_TexID; + FilterMode m_MinFilter; + FilterMode m_MagFilter; + WrapMode m_WrapMode; + bool m_IsGenMipmap; + + LUAX_DECL_ENUM(ColorFormat, 1); + LUAX_DECL_ENUM(FilterMode, 1); + LUAX_DECL_ENUM(WrapMode, 1); + + LUAX_DECL_METHOD(_SetFilterMode); + LUAX_DECL_METHOD(_SetWrapMode); + LUAX_DECL_METHOD(_GetFilterMode); + LUAX_DECL_METHOD(_GetWrapMode); + LUAX_DECL_METHOD(_IsGenMipmap); + +}; + +typedef Texture Drawable; + +namespace_end +namespace_end #endif
\ No newline at end of file diff --git a/source/modules/asura-core/graphics/vertex_buffer.cpp b/source/modules/asura-core/graphics/vertex_buffer.cpp index 437bd48..7fcd3d4 100644 --- a/source/modules/asura-core/graphics/vertex_buffer.cpp +++ b/source/modules/asura-core/graphics/vertex_buffer.cpp @@ -1,18 +1,16 @@ #include "vertex_buffer.h" -namespace AsuraEngine -{ - namespace Graphics - { - - VertexBuffer::VertexBuffer(BufferUsage usage, BufferDataType datatype, size_t size) - : GPUBuffer(BUFFER_TYPE_VERTEX, usage, datatype, size) - { - } +namespace_begin(AsuraEngine) +namespace_begin(Graphics) - VertexBuffer::~VertexBuffer() - { - } +VertexBuffer::VertexBuffer(BufferUsage usage, BufferDataType datatype, size_t size) + : GPUBuffer(BUFFER_TYPE_VERTEX, usage, datatype, size) +{ +} - } +VertexBuffer::~VertexBuffer() +{ } + +namespace_end +namespace_end diff --git a/source/modules/asura-core/graphics/vertex_buffer.h b/source/modules/asura-core/graphics/vertex_buffer.h index c16c6d2..f0bfb9e 100644 --- a/source/modules/asura-core/graphics/vertex_buffer.h +++ b/source/modules/asura-core/graphics/vertex_buffer.h @@ -5,32 +5,30 @@ #include "gpu_buffer.h" -namespace AsuraEngine +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + +/// +/// frameworkṩ˴Դ滺Ĺܣֱû壬ֱܶͨöݡ +/// +class VertexBuffer ASURA_FINAL + : public AEScripting::Portable<VertexBuffer> + , public GPUBuffer { - namespace Graphics - { +public: - /// - /// frameworkṩ˴Դ滺Ĺܣֱû壬ֱܶͨöݡ - /// - class VertexBuffer ASURA_FINAL - : public AEScripting::Portable<VertexBuffer> - , public GPUBuffer - { - public: + VertexBuffer(BufferUsage usage, BufferDataType datatype, size_t size); + ~VertexBuffer(); - VertexBuffer(BufferUsage usage, BufferDataType datatype, size_t size); - ~VertexBuffer(); +luaxport: - luaxport: + LUAX_DECL_FACTORY(VertexBuffer); - LUAX_DECL_FACTORY(VertexBuffer); + LUAX_DECL_METHOD(_New); - LUAX_DECL_METHOD(_New); +}; - }; - - } -} +namespace_end +namespace_end #endif
\ No newline at end of file |