From 684f71790401727cc45f4dad1822ddae46305072 Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 25 Feb 2019 09:07:37 +0800 Subject: +widgets --- Source/Asura.Engine/Graphics/Canvas.cpp | 11 +++ Source/Asura.Engine/Graphics/Canvas.h | 2 +- Source/Asura.Engine/Graphics/Color.cpp | 132 ++++++++++++++++++++++++++++++++ Source/Asura.Engine/Graphics/Color.h | 46 ++++++++++- Source/Asura.Engine/Graphics/GL.cpp | 11 +++ Source/Asura.Engine/Graphics/GL.h | 19 +++++ Source/Asura.Engine/Graphics/Image.h | 10 +-- Source/Asura.Engine/Graphics/OpenGL.cpp | 11 --- Source/Asura.Engine/Graphics/OpenGL.h | 17 ---- Source/Asura.Engine/Graphics/Shader.h | 90 ++++++++++++++++------ Source/Asura.Engine/Graphics/Texture.h | 4 +- Source/Asura.Engine/Graphics/Window.cpp | 0 Source/Asura.Engine/Graphics/Window.h | 25 ------ 13 files changed, 292 insertions(+), 86 deletions(-) create mode 100644 Source/Asura.Engine/Graphics/GL.cpp create mode 100644 Source/Asura.Engine/Graphics/GL.h delete mode 100644 Source/Asura.Engine/Graphics/OpenGL.cpp delete mode 100644 Source/Asura.Engine/Graphics/OpenGL.h delete mode 100644 Source/Asura.Engine/Graphics/Window.cpp delete mode 100644 Source/Asura.Engine/Graphics/Window.h (limited to 'Source/Asura.Engine/Graphics') diff --git a/Source/Asura.Engine/Graphics/Canvas.cpp b/Source/Asura.Engine/Graphics/Canvas.cpp index e69de29..8ca6fb2 100644 --- a/Source/Asura.Engine/Graphics/Canvas.cpp +++ b/Source/Asura.Engine/Graphics/Canvas.cpp @@ -0,0 +1,11 @@ +#include "Canvas.h" + +namespace AsuraEngine +{ + namespace Graphics + { + + + + } +} \ No newline at end of file diff --git a/Source/Asura.Engine/Graphics/Canvas.h b/Source/Asura.Engine/Graphics/Canvas.h index 93792a5..c9adf2d 100644 --- a/Source/Asura.Engine/Graphics/Canvas.h +++ b/Source/Asura.Engine/Graphics/Canvas.h @@ -12,7 +12,7 @@ namespace AsuraEngine { public: - + Canvas(); private: diff --git a/Source/Asura.Engine/Graphics/Color.cpp b/Source/Asura.Engine/Graphics/Color.cpp index e69de29..a047f53 100644 --- a/Source/Asura.Engine/Graphics/Color.cpp +++ b/Source/Asura.Engine/Graphics/Color.cpp @@ -0,0 +1,132 @@ +#include "Color.h" + +namespace AsuraEngine +{ + namespace Graphics + { + + 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; + } + + int Color32::l_GetRed(lua_State* L) + { + + } + + int Color32::l_GetGreen(lua_State* L) + { + + } + + int Color32::l_GetBlue(lua_State* L) + { + + } + + int Color32::l_GetAlpha(lua_State* L) + { + + } + + ////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + 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::operator *(const Color& c) + { + r *= c.r; + g *= c.g; + b *= c.b; + a *= c.a; + } + + int Color::l_GetRed(lua_State* L) + { + + } + + int Color::l_GetGreen(lua_State* L) + { + + } + + int Color::l_GetBlue(lua_State* L) + { + + } + + int Color::l_GetAlpha(lua_State* L) + { + + } + + int Color::l_Add(lua_State* L) + { + + } + + int Color::l_Minus(lua_State* L) + { + + } + + int Color::l_Multiply(lua_State* L) + { + + } + + } +} \ No newline at end of file diff --git a/Source/Asura.Engine/Graphics/Color.h b/Source/Asura.Engine/Graphics/Color.h index f62f9b8..daf6a09 100644 --- a/Source/Asura.Engine/Graphics/Color.h +++ b/Source/Asura.Engine/Graphics/Color.h @@ -1,6 +1,8 @@ #ifndef __ASURA_ENGINE_COLOR_H__ #define __ASURA_ENGINE_COLOR_H__ +#include "Scripting/Luax.hpp" + #include "Type.h" namespace AsuraEngine @@ -17,7 +19,12 @@ namespace AsuraEngine { public: - Color32(Color c); + Color32(); + + Color32(const Color32& c); + + Color32(const Color& c); + Color32(byte r, byte g, byte b, byte a); byte r, g, b, a; @@ -26,20 +33,53 @@ namespace AsuraEngine LUAX_DECL_FACTORY(Color32); + LUAX_DECL_METHOD(l_GetRed); + LUAX_DECL_METHOD(l_GetGreen); + LUAX_DECL_METHOD(l_GetBlue); + LUAX_DECL_METHOD(l_GetAlpha); + + // meta methods + LUAX_DECL_METHOD(l_Multiply); + LUAX_DECL_METHOD(l_Index); //索引r,g,b,a + LUAX_DECL_METHOD(l_NewIndex); //修改r,g,b,a + }; + /// + /// 规范化颜色 + /// class Color { public: - Color(Color32 c32); + Color(); + Color(const Color& c); + + Color(float r, float g, float b, float a); + + Color(const Color32& c); + + Color operator *(const Color& c); + float r, g, b, a; - private: + private: + + //////////////////////////////////////////////////////////////////////////////////////////////////////////// LUAX_DECL_FACTORY(Color); + LUAX_DECL_METHOD(l_GetRed); // color.r + LUAX_DECL_METHOD(l_GetGreen); // color.g + LUAX_DECL_METHOD(l_GetBlue); // color.b + LUAX_DECL_METHOD(l_GetAlpha); // color.a + + // meta methods + LUAX_DECL_METHOD(l_Multiply); // 颜色乘法 + //LUAX_DECL_METHOD(l_Index); // 索引r,g,b,a + LUAX_DECL_METHOD(l_NewIndex); // 修改r,g,b,a + }; } diff --git a/Source/Asura.Engine/Graphics/GL.cpp b/Source/Asura.Engine/Graphics/GL.cpp new file mode 100644 index 0000000..dac2ea4 --- /dev/null +++ b/Source/Asura.Engine/Graphics/GL.cpp @@ -0,0 +1,11 @@ +#include "OpenGL.h" + +namespace AsuraEngine +{ + namespace Graphics + { + + + + } +} \ No newline at end of file diff --git a/Source/Asura.Engine/Graphics/GL.h b/Source/Asura.Engine/Graphics/GL.h new file mode 100644 index 0000000..0661e17 --- /dev/null +++ b/Source/Asura.Engine/Graphics/GL.h @@ -0,0 +1,19 @@ +#ifndef __ASURA_ENGINE_OPENGL_H__ +#define __ASURA_ENGINE_OPENGL_H__ + +#include "glad/glad.h" + +namespace AsuraEngine +{ + namespace Graphics + { + + class OpenGL + { + + }; + + } +} + +#endif \ No newline at end of file diff --git a/Source/Asura.Engine/Graphics/Image.h b/Source/Asura.Engine/Graphics/Image.h index 553df21..bdd7c1c 100644 --- a/Source/Asura.Engine/Graphics/Image.h +++ b/Source/Asura.Engine/Graphics/Image.h @@ -1,10 +1,8 @@ #ifndef __ASURA_ENGINE_IMAGE_H__ #define __ASURA_ENGINE_IMAGE_H__ -#include "StringMap.hpp" -#include "String.h" -#include "Map.h" #include "Math/Vector2.h" +#include "StringMap.hpp" #include "Manager.hpp" #include "Texture.h" #include "Color.h" @@ -19,7 +17,7 @@ namespace AsuraEngine /// /// Image是图片从内存中载入后,读取进游戏后保存的结果。一个Image在内存、显存中只会保存一份,不会产生副本。需要特征 - /// 化的区别image,如锚点位置,缩放和旋转角度,使用sprite。基本是一个只读类。 + /// 化的区别image,如锚点位置,缩放和旋转角度,使用sprite。是一个只读类。主要是考虑到editor和engine使用不同的封装。 /// class Image final : public Texture { @@ -53,7 +51,9 @@ namespace AsuraEngine //---------------------------------------------------------------------------------------------------- - LUAX_DECL_FACTORY(SimImage); //AsuraEngine.SimImage + // 图片的Sim类,具体的封装在AsuraEngine.Image里面,包含一个成员AsuraEngine.SimImage,在AsuraEngine.Image里面对 + // 数据做一个缓存。 + LUAX_DECL_FACTORY(SimImage); }; diff --git a/Source/Asura.Engine/Graphics/OpenGL.cpp b/Source/Asura.Engine/Graphics/OpenGL.cpp deleted file mode 100644 index dac2ea4..0000000 --- a/Source/Asura.Engine/Graphics/OpenGL.cpp +++ /dev/null @@ -1,11 +0,0 @@ -#include "OpenGL.h" - -namespace AsuraEngine -{ - namespace Graphics - { - - - - } -} \ No newline at end of file diff --git a/Source/Asura.Engine/Graphics/OpenGL.h b/Source/Asura.Engine/Graphics/OpenGL.h deleted file mode 100644 index 315c09b..0000000 --- a/Source/Asura.Engine/Graphics/OpenGL.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef __ASURA_ENGINE_OPENGL_H__ -#define __ASURA_ENGINE_OPENGL_H__ - -namespace AsuraEngine -{ - namespace Graphics - { - - class OpenGL - { - - }; - - } -} - -#endif \ No newline at end of file diff --git a/Source/Asura.Engine/Graphics/Shader.h b/Source/Asura.Engine/Graphics/Shader.h index e22fc66..02d9f46 100644 --- a/Source/Asura.Engine/Graphics/Shader.h +++ b/Source/Asura.Engine/Graphics/Shader.h @@ -1,62 +1,108 @@ #ifndef __ASURA_ENGINE_SHADER_H__ #define __ASURA_ENGINE_SHADER_H__ -#include "luax/luax.h" +#include +#include -#include "Map.h" +#include "luax/luax.h" #include "StringMap.hpp" #include "Object.h" #include "Color.h" #include "Manager.hpp" +#include "Texture.h" +#include "Math/Vector2.h" +#include "Math/Vector3.h" +#include "Math/Vector4.h" +#include "GL.h" namespace AsuraEngine { namespace Graphics { - class Material; - /// - /// 一个shader是一个在材质间共享的程序。Shader本身不保存uniforms和顶点数据,只保存uniforms location。 + /// 一个shader是一个在材质间共享的程序。Shader本身不保存uniforms和顶点数据,只提供设置uniforms和use着色器的方法。编辑器针对每个 + /// shader,会通过shader代码找到声明的uniforms变量,并暴露给framework的material设置。 /// - class Shader + class Shader : virtual public Object { public: Shader(); ~Shader(); + + /// + /// 从代码编译shader,编译时会先检测是否有上次缓存的uniforms location map + /// + void Load(const std::string& vertexShader, const std::string& fragmentShader); - private: + /// + /// 将当期shader设置为活动 + /// + void Use(); - friend class Material; + /// + /// 将当期shader设置为非活动 + /// + void UnUse(); /// - /// 保存了所有shader的uniforms变量的ID映射。 + /// 一系列设置uniforms变量的方法 /// - static StringMap sUniformsID; + void SetUniformFloat(const std::string& uniform, float value); + void SetUniformTexture(const std::string& uniform, const Texture& texture); + void SetUniformVector2(const std::string& uniform, const Math::Vector2& vec2); + void SetUniformVector3(const std::string& uniform, const Math::Vector3& vec3); + void SetUniformVector4(const std::string& uniform, const Math::Vector4& vec4); /// - /// 获得uniform变量的ID。 + /// 在已经知道uniform location的情况下,设置值。 /// - static int GetUniformID(const String& name); + void SetUniformFloat(uint loc, float value); + void SetUniformTexture(uint loc, const Texture& texture); + void SetUniformVector2(uint loc, const Math::Vector2& vec2); + void SetUniformVector3(uint loc, const Math::Vector3& vec3); + void SetUniformVector4(uint loc, const Math::Vector4& vec4); +/* /// - /// 设置内置变量: - /// vec2 Asura_Time x值为进入当前场景开始的时间,y值为上一帧的时间间隔 - /// vec2 Asura_RenderTargetSize RT的大小,以像素为单位 - /// Texture Asura_MainTexture 主纹理 + /// 注:后来考虑这个功能放在framework里面实现,更方便,而且shader在editor里也会用到。 + /// 清空缓存的unifrom location,用于重新编译shader,更新最新的uniform location /// - void SetBuiltInUniforms(); + void ClearUniformLocation(); +*/ + /// + /// 获得program id + /// + GLint GetNativeHandle(); + + uint GetUniformLocation(const std::string& uniform); + + private: /// - /// 映射uniforms ID到location。 + /// 设置内置变量: + /// vec2 Asura_Time x值为进入当前场景开始的时间,y值为上一帧的时间间隔 + /// vec2 Asura_RenderTargetSize RT的大小,以像素为单位 + /// Texture Asura_MainTexture 主纹理 /// - Map mLocations; + void SetBuiltInUniforms(); - }; + // OpenGL着色器标识符program id + GLuint mPID; + //// Uniform的locations + //StringMap mUniformLocation; - class ShaderManager final : public Manager - { + //////////////////////////////////////////////////////////////////////////////////////////////////////////// + + LUAX_DECL_FACTORY(SimShader); + + LUAX_DECL_METHOD(l_SetBuiltInUniforms); + LUAX_DECL_METHOD(l_SetUniformFloat); + LUAX_DECL_METHOD(l_SetUniformTexture); + LUAX_DECL_METHOD(l_SetUniformVector2); + LUAX_DECL_METHOD(l_SetUniformVector3); + LUAX_DECL_METHOD(l_SetUniformVector4); }; diff --git a/Source/Asura.Engine/Graphics/Texture.h b/Source/Asura.Engine/Graphics/Texture.h index db5c72e..06461ce 100644 --- a/Source/Asura.Engine/Graphics/Texture.h +++ b/Source/Asura.Engine/Graphics/Texture.h @@ -10,9 +10,9 @@ namespace AsuraEngine { /// - /// 2D纹理(抽象类),在2d mesh和render target中被使用 + /// 2D纹理抽象类,在2d mesh和render target中被使用 /// - class Texture : public Object + class Texture : virtual public Object { }; diff --git a/Source/Asura.Engine/Graphics/Window.cpp b/Source/Asura.Engine/Graphics/Window.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/Source/Asura.Engine/Graphics/Window.h b/Source/Asura.Engine/Graphics/Window.h deleted file mode 100644 index 3a09266..0000000 --- a/Source/Asura.Engine/Graphics/Window.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef __ASURA_ENGINE_WINDOW_H__ -#define __ASURA_ENGINE_WINDOW_H__ - -namespace AsuraEngine -{ - namespace Graphics - { - - /// - /// 窗口,支持多窗口。在编辑器下需要多个窗口支持,runner只需要一个窗口。 - /// - class Window - { - public: - - - private: - - - }; - - } -} - -#endif \ No newline at end of file -- cgit v1.1-26-g67d0