diff options
author | chai <chaifix@163.com> | 2019-01-14 17:37:28 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2019-01-14 17:37:28 +0800 |
commit | f2b0cd4582bdc3b8666ec7f6c4a29d67b06e7646 (patch) | |
tree | 050009b05aa40612b364ada1fb7b566b22cd4600 /Source | |
parent | b56f3e7b145e1f1aa01861a541fc5ec68f127ce0 (diff) |
*材质和shader
Diffstat (limited to 'Source')
-rw-r--r-- | Source/Asura/Component.h | 13 | ||||
-rw-r--r-- | Source/Asura/Containers/Map.h | 9 | ||||
-rw-r--r-- | Source/Asura/Containers/StringMap.hpp | 13 | ||||
-rw-r--r-- | Source/Asura/GameObject.h | 1 | ||||
-rw-r--r-- | Source/Asura/Graphics/Animation.cpp (renamed from Source/Asura/Graphics/Animations/Animation.cpp) | 0 | ||||
-rw-r--r-- | Source/Asura/Graphics/Animation.h (renamed from Source/Asura/Graphics/Animations/Animation.h) | 0 | ||||
-rw-r--r-- | Source/Asura/Graphics/Material.h | 81 | ||||
-rw-r--r-- | Source/Asura/Graphics/ParticleSystem.cpp (renamed from Source/Asura/Graphics/Effects/ParticleSystem.cpp) | 0 | ||||
-rw-r--r-- | Source/Asura/Graphics/ParticleSystem.h | 19 | ||||
-rw-r--r-- | Source/Asura/Graphics/Renderer.h | 6 | ||||
-rw-r--r-- | Source/Asura/Graphics/Shader.h | 37 | ||||
-rw-r--r-- | Source/Asura/Graphics/SpriteBatch.cpp (renamed from Source/Asura/Graphics/Effects/ParticleSystem.h) | 0 | ||||
-rw-r--r-- | Source/Asura/Graphics/SpriteBatch.h (renamed from Source/Asura/rename.bat) | 0 | ||||
-rw-r--r-- | Source/Asura/Object.cpp | 23 | ||||
-rw-r--r-- | Source/Asura/Object.h | 13 | ||||
-rw-r--r-- | Source/Asura/Transform.h | 2 |
16 files changed, 200 insertions, 17 deletions
diff --git a/Source/Asura/Component.h b/Source/Asura/Component.h index 20f0685..a602d50 100644 --- a/Source/Asura/Component.h +++ b/Source/Asura/Component.h @@ -11,6 +11,7 @@ namespace AsuraEngine class Component : public Object { public: + virtual void OnEnable(); virtual void OnEvent(); virtual void OnUpdate(uint32 milliseconds); @@ -18,6 +19,18 @@ namespace AsuraEngine virtual void OnDisable(); protected: + + enum class EnableCallback + { + OnEnable = 1, + OnEvent = 1 << 1, + OnUpdate = 1 << 2, + OnRender = 1 << 3, + OnDisable = 1 << 4, + }; + + EnableCallback mEnabledCallbacks; + GameObject* mGameObject; }; diff --git a/Source/Asura/Containers/Map.h b/Source/Asura/Containers/Map.h index cc2358e..2caedef 100644 --- a/Source/Asura/Containers/Map.h +++ b/Source/Asura/Containers/Map.h @@ -7,13 +7,10 @@ namespace AsuraEngine { namespace Containers { -/* - template<typename T> - class Map : public std::map< - { - }; -*/ + template<typename key_type, typename value_type> + using Map = std::map<key_type, value_type>; + } } diff --git a/Source/Asura/Containers/StringMap.hpp b/Source/Asura/Containers/StringMap.hpp index af5b856..94858a7 100644 --- a/Source/Asura/Containers/StringMap.hpp +++ b/Source/Asura/Containers/StringMap.hpp @@ -1,15 +1,28 @@ #ifndef __AE_STRINGMAP_H__ #define __AE_STRINGMAP_H__ +#include "String.h" + namespace AsuraEngine { namespace Containers { + /// + /// һ˫һһӦӳ䣬shader uniformsstatemathine state parameterID + /// + template<typename key_type> class StringMap { public: + bool ContainsKey(const key_type& key); + + bool ContainsString(const String& str); + + String GetStringByKey(const key_type& key); + + key_type GetKeyByString(const String& str); }; diff --git a/Source/Asura/GameObject.h b/Source/Asura/GameObject.h index 954ce6c..fcef864 100644 --- a/Source/Asura/GameObject.h +++ b/Source/Asura/GameObject.h @@ -38,6 +38,7 @@ namespace AsuraEngine void SetRotation(const Math::Vector2& rotation); private: + Transform mTransform; Containers::Vector<Component*> mComponents; diff --git a/Source/Asura/Graphics/Animations/Animation.cpp b/Source/Asura/Graphics/Animation.cpp index e69de29..e69de29 100644 --- a/Source/Asura/Graphics/Animations/Animation.cpp +++ b/Source/Asura/Graphics/Animation.cpp diff --git a/Source/Asura/Graphics/Animations/Animation.h b/Source/Asura/Graphics/Animation.h index e69de29..e69de29 100644 --- a/Source/Asura/Graphics/Animations/Animation.h +++ b/Source/Asura/Graphics/Animation.h diff --git a/Source/Asura/Graphics/Material.h b/Source/Asura/Graphics/Material.h index 6093d18..2b74879 100644 --- a/Source/Asura/Graphics/Material.h +++ b/Source/Asura/Graphics/Material.h @@ -25,14 +25,51 @@ namespace AsuraEngine class Material : public Object { public: + + enum class UniformsType + { + None = 0, + Float, + Int, + Vector2, + Vector3, + Vector4, + Matrix44, + Texture, + Color, + }; + + struct UniformsInfo + { + int id; // uniformID + UniformsType type; // uniform + union + { + float f; + int i; + Math::Vector2 v2; + Math::Vector3 v3; + Math::Vector4 v4; + Math::Matrix44 m44; + Texture* tex; + Color col; + }value; // uniformֵ + }; + Material(); Material(const Material& srcMat); ~Material(); Material* Clone(); - // Uniform + void SetShader(Shader* shader); + + // UniformڲУȾʱϴGPU + /// + /// uniformIDIDnamemapshader乲uniformֵʱͨIDѯuniform + /// shaderҵuniform locationlocationֵ + /// static int GetUniformID(const Containers::String& name); void SetTexture(int ID, Texture* texture); @@ -44,6 +81,16 @@ namespace AsuraEngine void SetInteger(int ID, int value); void SetColor(int ID, Color color); + UniformsInfo GetUniformInfo(int ID); + float GetUniformInfof(int ID); + int GetUniformInfoi(int ID); + Math::Vector2 GetUniformInfov2(int ID); + Math::Vector3 GetUniformInfov3(int ID); + Math::Vector4 GetUniformInfov4(int ID); + Math::Matrix44 GetUniformInfom44(int ID); + Texture* GetUniformInfotex(int ID); + Color GetUniformInfocol(int ID); + // ϴ void SetVertexAttributes(); @@ -52,6 +99,8 @@ namespace AsuraEngine LUAX_DECL_FACTORY( Material ); + LUAX_DECL_METHOD( l_SetShader ); + LUAX_DECL_METHOD( l_SetTexture ); LUAX_DECL_METHOD( l_SetVector2 ); LUAX_DECL_METHOD( l_SetVector3 ); @@ -62,10 +111,34 @@ namespace AsuraEngine LUAX_DECL_METHOD( l_SetColor ); LUAX_DECL_METHOD( l_SetVertexAttributes ); + LUAX_DECL_METHOD( l_GetUniformInfo ); + LUAX_DECL_METHOD( l_GetUniformInfof ); + LUAX_DECL_METHOD( l_GetUniformInfoi ); + LUAX_DECL_METHOD( l_GetUniformInfov2 ); + LUAX_DECL_METHOD( l_GetUniformInfov3 ); + LUAX_DECL_METHOD( l_GetUniformInfov4 ); + LUAX_DECL_METHOD( l_GetUniformInfom44 ); + LUAX_DECL_METHOD( l_GetUniformInfotex ); + LUAX_DECL_METHOD( l_GetUniformInfocol ); + + LUAX_DECL_METHOD( l_SetVertexAttributes ); + private: - //Color mColor; - //Shader* mShader; - //Texture* mMainTexture; + + /// + /// + /// + Shader* mShader; + + /// + /// UniformsֵӳIDֵ + /// + Containers::Map<int, UniformsInfo> mUniforms; + + /// + /// ǷǹIJ + /// + bool mIsShared; }; diff --git a/Source/Asura/Graphics/Effects/ParticleSystem.cpp b/Source/Asura/Graphics/ParticleSystem.cpp index e69de29..e69de29 100644 --- a/Source/Asura/Graphics/Effects/ParticleSystem.cpp +++ b/Source/Asura/Graphics/ParticleSystem.cpp diff --git a/Source/Asura/Graphics/ParticleSystem.h b/Source/Asura/Graphics/ParticleSystem.h new file mode 100644 index 0000000..98aba49 --- /dev/null +++ b/Source/Asura/Graphics/ParticleSystem.h @@ -0,0 +1,19 @@ +#ifndef __AE_PARTICLESYSTEM_H__ +#define __AE_PARTICLESYSTEM_H__ + +#include "Component.h" + +namespace AsuraEngine +{ + namespace Graphics + { + + class ParticleSystem : public Component + { + + }; + + } +} + +#endif
\ No newline at end of file diff --git a/Source/Asura/Graphics/Renderer.h b/Source/Asura/Graphics/Renderer.h index 004bbe4..2efa391 100644 --- a/Source/Asura/Graphics/Renderer.h +++ b/Source/Asura/Graphics/Renderer.h @@ -1,6 +1,7 @@ #ifndef __AE_RENDERER_H__ #define __AE_RENDERER_H__ +#include "Component.h" #include "Material.h" namespace AsuraEngine @@ -8,11 +9,12 @@ namespace AsuraEngine namespace Graphics { - class Renderer + class Renderer : public Component { public: /// - /// + /// һô˷ͻ´shared materialô˷ζҪmaterialýģʱʹõIJ + /// shared materialҪһݣӰrenderer /// Material* GetMaterial(); diff --git a/Source/Asura/Graphics/Shader.h b/Source/Asura/Graphics/Shader.h index 0589c70..7c09139 100644 --- a/Source/Asura/Graphics/Shader.h +++ b/Source/Asura/Graphics/Shader.h @@ -1,10 +1,11 @@ #ifndef __AE_SHADER_H__ #define __AE_SHADER_H__ -#include "../Object.h" - #include "luax/luax.h" +#include "Containers/Map.h" +#include "Containers/StringMap.hpp" +#include "Object.h" #include "Color.h" namespace AsuraEngine @@ -12,17 +13,45 @@ namespace AsuraEngine namespace Graphics { + class Material; + + /// + /// һshaderһڲʼ乲ijShaderuniformsͶݣֻuniforms location + /// class Shader : public Object { public: + Shader(); + ~Shader(); + + private: + + friend class Material; + + /// + /// shaderuniformsIDӳ䡣 + /// + static Containers::StringMap<int> sUniformsID; + + /// + /// uniformID + /// + static int GetUniformID(const Containers::String& name); + /// /// ñ - /// vec2 Asura_Time xֵΪ뵱ǰʼʱ䣬yֵΪһ֡ʱ - /// vec2 Asura_RenderTargetSize RTĴСΪλ + /// vec2 Asura_Time xֵΪ뵱ǰʼʱ䣬yֵΪһ֡ʱ + /// vec2 Asura_RenderTargetSize RTĴСΪλ + /// Texture Asura_MainTexture /// void SetBuiltInUniforms(); + /// + /// ӳuniforms IDlocation + /// + Containers::Map<int, int> mLocations; + }; } diff --git a/Source/Asura/Graphics/Effects/ParticleSystem.h b/Source/Asura/Graphics/SpriteBatch.cpp index e69de29..e69de29 100644 --- a/Source/Asura/Graphics/Effects/ParticleSystem.h +++ b/Source/Asura/Graphics/SpriteBatch.cpp diff --git a/Source/Asura/rename.bat b/Source/Asura/Graphics/SpriteBatch.h index e69de29..e69de29 100644 --- a/Source/Asura/rename.bat +++ b/Source/Asura/Graphics/SpriteBatch.h diff --git a/Source/Asura/Object.cpp b/Source/Asura/Object.cpp index e69de29..587dca7 100644 --- a/Source/Asura/Object.cpp +++ b/Source/Asura/Object.cpp @@ -0,0 +1,23 @@ +#include "Object.h" + +namespace AsuraEngine +{ + + Object::Object() + : mRC(0) + { + + } + + void Object::Retain(Object* obj) + { + ++obj->mRC; + } + + void Object::Release(Object* obj) + { + if (--obj->mRC == 0) + delete obj; + } + +}
\ No newline at end of file diff --git a/Source/Asura/Object.h b/Source/Asura/Object.h index 4617a4a..2511500 100644 --- a/Source/Asura/Object.h +++ b/Source/Asura/Object.h @@ -8,6 +8,19 @@ namespace AsuraEngine class Object { + public: + + Object(); + + virtual ~Object(); + + static void Retain(Object* obj); + + static void Release(Object* obj); + + private: + + int mRC; // }; diff --git a/Source/Asura/Transform.h b/Source/Asura/Transform.h index 9666ec4..98a0c77 100644 --- a/Source/Asura/Transform.h +++ b/Source/Asura/Transform.h @@ -1,7 +1,7 @@ #ifndef __AE_TRANSFORM_H__ #define __AE_TRANSFORM_H__ -#include "./Math/AE_Vector2.h" +#include "Math/Vector2.h" namespace AsuraEngine { |