summaryrefslogtreecommitdiff
path: root/Source
diff options
context:
space:
mode:
Diffstat (limited to 'Source')
-rw-r--r--Source/3rdParty/Luax/luax_class.h14
-rw-r--r--Source/3rdParty/Luax/luax_runtime.h6
-rw-r--r--Source/Asura.Editor/Source/Graphics/Shader.cpp0
-rw-r--r--Source/Asura.Editor/Source/Graphics/Shader.h21
-rw-r--r--Source/Asura.Engine/Asura.h8
-rw-r--r--Source/Asura.Engine/Graphics/Canvas.h43
-rw-r--r--Source/Asura.Engine/Graphics/Color.cpp2
-rw-r--r--Source/Asura.Engine/Graphics/Color.h21
-rw-r--r--Source/Asura.Engine/Graphics/Image.cpp37
-rw-r--r--Source/Asura.Engine/Graphics/Image.h42
-rw-r--r--Source/Asura.Engine/Graphics/Mesh2D.h5
-rw-r--r--Source/Asura.Engine/Graphics/Port/Canvas.cpp0
-rw-r--r--Source/Asura.Engine/Graphics/Port/Color.cpp0
-rw-r--r--Source/Asura.Engine/Graphics/Port/Image.cpp0
-rw-r--r--Source/Asura.Engine/Graphics/Port/Mesh2D.cpp0
-rw-r--r--Source/Asura.Engine/Graphics/Port/Shader.cpp105
-rw-r--r--Source/Asura.Engine/Graphics/Port/SpriteBatch.cpp0
-rw-r--r--Source/Asura.Engine/Graphics/RenderTarget.cpp0
-rw-r--r--Source/Asura.Engine/Graphics/RenderTarget.h30
-rw-r--r--Source/Asura.Engine/Graphics/Shader.cpp81
-rw-r--r--Source/Asura.Engine/Graphics/Shader.h92
-rw-r--r--Source/Asura.Engine/Graphics/SpriteBatch.h7
-rw-r--r--Source/Asura.Engine/Graphics/Texture.cpp26
-rw-r--r--Source/Asura.Engine/Graphics/Texture.h33
-rw-r--r--Source/Asura.Engine/Math/Rect.cpp0
-rw-r--r--Source/Asura.Engine/Math/Rect.h17
-rw-r--r--Source/Asura.Engine/Object.h1
-rw-r--r--Source/Asura.Engine/SimClass.h22
-rw-r--r--Source/Asura.Engine/Window/Window.h9
-rw-r--r--Source/Asura.Framework/scripts/graphics/material.lua1
-rw-r--r--Source/Asura.Framework/scripts/graphics/shader.lua24
-rw-r--r--Source/Asura.Framework/scripts/graphics/shaderHelper.lua14
-rw-r--r--Source/Asura.Framework/scripts/gui/widget.lua3
33 files changed, 574 insertions, 90 deletions
diff --git a/Source/3rdParty/Luax/luax_class.h b/Source/3rdParty/Luax/luax_class.h
index 46918af..1721ec4 100644
--- a/Source/3rdParty/Luax/luax_class.h
+++ b/Source/3rdParty/Luax/luax_class.h
@@ -6,18 +6,18 @@
namespace Luax
{
+#define LUAX_DECL_METHOD(MTD) static int MTD(lua_State*)
+#define LUAX_DECL_FACTORY(CLS) static int RegisterLuaClass(lua_State*);
+#define LUAX_DECL_SINGLETON(CLS)
+
+#define LUAX_REGISTER_CLASS(CLS) CLS::RegisterLuaType()
+ /*
///
/// Ҫ¶luaclassҪ̳дࡣ
///
class LuaxClass
{
public:
-
-#define LUAX_DECL_METHOD(MTD) static int MTD(lua_State*)
-#define LUAX_DECL_FACTORY(CLS)
-#define LUAX_DECL_SINGLETON(CLS)
-
-#define LUAX_REGISTER_CLASS(CLS) CLS::RegisterLuaType()
static void RegisterLuaType();
@@ -46,7 +46,7 @@ namespace Luax
private:
};
-
+ */
}
#endif \ No newline at end of file
diff --git a/Source/3rdParty/Luax/luax_runtime.h b/Source/3rdParty/Luax/luax_runtime.h
index a0dbea3..94d8ecc 100644
--- a/Source/3rdParty/Luax/luax_runtime.h
+++ b/Source/3rdParty/Luax/luax_runtime.h
@@ -4,7 +4,11 @@
namespace Luax
{
-
+ enum RegisterIndex
+ {
+ LUAX_OBJECT_INDEX = 1,
+ LUAX_OBJECT_MODULE = 2,
+ };
}
diff --git a/Source/Asura.Editor/Source/Graphics/Shader.cpp b/Source/Asura.Editor/Source/Graphics/Shader.cpp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Source/Asura.Editor/Source/Graphics/Shader.cpp
diff --git a/Source/Asura.Editor/Source/Graphics/Shader.h b/Source/Asura.Editor/Source/Graphics/Shader.h
new file mode 100644
index 0000000..7511e1c
--- /dev/null
+++ b/Source/Asura.Editor/Source/Graphics/Shader.h
@@ -0,0 +1,21 @@
+#ifndef __ASURA_EDITOR_SHADER_H__
+#define __ASURA_EDITOR_SHADER_H__
+
+#include <Asura.h>
+
+namespace AsuraEditor
+{
+
+ ///
+ /// ༭ʹõshaderluaӿڡ
+ ///
+ class Shader : public AEGraphics::Shader
+ {
+ public:
+
+
+ };
+
+}
+
+#endif \ No newline at end of file
diff --git a/Source/Asura.Engine/Asura.h b/Source/Asura.Engine/Asura.h
index 2b86fad..ae6f68e 100644
--- a/Source/Asura.Engine/Asura.h
+++ b/Source/Asura.Engine/Asura.h
@@ -1,6 +1,12 @@
#ifndef __ASURA_ENGINE_H__
#define __ASURA_ENGINE_H__
-#include "Graphics/Window.h"
+#include "Graphics/Shader.h"
+
+namespace AEGraphics = AsuraEngine::Graphics;
+namespace AEMath = AsuraEngine::Math;
+namespace AETime = AsuraEngine::Time;
+namespace AEInput = AsuraEngine::Input;
+namespace AEProfiler = AsuraEngine::Profiler;
#endif \ No newline at end of file
diff --git a/Source/Asura.Engine/Graphics/Canvas.h b/Source/Asura.Engine/Graphics/Canvas.h
index c9adf2d..fc8a527 100644
--- a/Source/Asura.Engine/Graphics/Canvas.h
+++ b/Source/Asura.Engine/Graphics/Canvas.h
@@ -1,25 +1,64 @@
#ifndef __ASURA_ENGINE_CANVAS_H__
#define __ASURA_ENGINE_CANVAS_H__
+#include <Scripting/Luax.hpp>
+
+#include "GL.h"
+#include "SimClass.h"
#include "Texture.h"
+#include "RenderTarget.h"
namespace AsuraEngine
{
namespace Graphics
{
- class Canvas : public Texture
+ ///
+ /// CanvasҲԳΪrender textureҲΪtextureȾ
+ ///
+ class Canvas final : public Texture, public RenderTarget, public SimClass
{
public:
Canvas();
+ ///
+ /// 󶨴canvasΪ
+ ///
+ void Bind();
+
+ ///
+ /// Ϊǻ󶨻screen
+ ///
+ void Unbind();
+
+ void Render(int x, int y, int sx, int sy, int ox, int oy, int r) override;
+
+ void Render(const Math::Rect& quad, int x, int y, int sx, int sy, int ox, int oy, int r) override;
+
+ //----------------------------------------------------------------------------------------------------------
+
+ LUAX_DECL_FACTORY(SimCanvas);
+
+ LUAX_DECL_METHOD(l_Bind);
+ LUAX_DECL_METHOD(l_Unbind);
+
+ //----------------------------------------------------------------------------------------------------------
+
private:
- LUAX_DECL_FACTORY(SimCanvas); // AsuraEngine.SimCanvas
+ ///
+ /// Frame buffer object id.
+ ///
+ GLuint mFBO;
};
+ ///
+ /// CanvasΪRenderTexture
+ ///
+ using RenderTexture = Canvas;
+
}
}
diff --git a/Source/Asura.Engine/Graphics/Color.cpp b/Source/Asura.Engine/Graphics/Color.cpp
index a047f53..106493d 100644
--- a/Source/Asura.Engine/Graphics/Color.cpp
+++ b/Source/Asura.Engine/Graphics/Color.cpp
@@ -54,7 +54,7 @@ namespace AsuraEngine
}
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////
+ //------------------------------------------------------------------------------------------------------------
Color::Color()
{
diff --git a/Source/Asura.Engine/Graphics/Color.h b/Source/Asura.Engine/Graphics/Color.h
index daf6a09..6383602 100644
--- a/Source/Asura.Engine/Graphics/Color.h
+++ b/Source/Asura.Engine/Graphics/Color.h
@@ -2,7 +2,7 @@
#define __ASURA_ENGINE_COLOR_H__
#include "Scripting/Luax.hpp"
-
+#include "Object.h"
#include "Type.h"
namespace AsuraEngine
@@ -15,7 +15,7 @@ namespace AsuraEngine
///
/// 32bitsɫ
///
- class Color32
+ class Color32 : virtual public Object
{
public:
@@ -29,7 +29,7 @@ namespace AsuraEngine
byte r, g, b, a;
- private:
+ //----------------------------------------------------------------------------------------------------------
LUAX_DECL_FACTORY(Color32);
@@ -37,18 +37,18 @@ namespace AsuraEngine
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
+ class Color : virtual public Object
{
public:
@@ -64,9 +64,7 @@ namespace AsuraEngine
float r, g, b, a;
- private:
-
- ////////////////////////////////////////////////////////////////////////////////////////////////////////////
+ //----------------------------------------------------------------------------------------------------------
LUAX_DECL_FACTORY(Color);
@@ -74,12 +72,11 @@ namespace AsuraEngine
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/Image.cpp b/Source/Asura.Engine/Graphics/Image.cpp
index e69de29..e19d57f 100644
--- a/Source/Asura.Engine/Graphics/Image.cpp
+++ b/Source/Asura.Engine/Graphics/Image.cpp
@@ -0,0 +1,37 @@
+#include "Image.h"
+
+namespace AsuraEngine
+{
+ namespace Graphics
+ {
+
+ Image::Image()
+ : Texture()
+ , mPixels(nullptr)
+ , mWidth(0)
+ , mHeight(0)
+ {
+ }
+
+ Image::~Image()
+ {
+ delete mPixels;
+ }
+
+ bool Image::Load(const void* data, size_t size)
+ {
+
+ }
+
+ void Image::Render(int x, int y, int sx, int sy, int ox, int oy, int r)
+ {
+
+ }
+
+ void Image::Render(const Math::Rect& quad, int x, int y, int sx, int sy, int ox, int oy, int r)
+ {
+
+ }
+
+ }
+}
diff --git a/Source/Asura.Engine/Graphics/Image.h b/Source/Asura.Engine/Graphics/Image.h
index bdd7c1c..391d1c4 100644
--- a/Source/Asura.Engine/Graphics/Image.h
+++ b/Source/Asura.Engine/Graphics/Image.h
@@ -7,6 +7,7 @@
#include "Texture.h"
#include "Color.h"
#include "Factory.h"
+#include "SimClass.h"
namespace AsuraEngine
{
@@ -19,10 +20,19 @@ namespace AsuraEngine
/// ImageͼƬڴ󣬶ȡϷ󱣴ĽһImageڴ桢ԴֻᱣһݣҪ
/// imageêλãźתǶȣʹspriteһֻࡣҪǿǵeditorengineʹòͬķװ
///
- class Image final : public Texture
+ class Image final : public Texture, public SimClass
{
public:
+ Image();
+ ~Image();
+
+ ///
+ /// bufferimagemPixelsΪգݡ¹imageʹglTexImage2Dύimage
+ /// ݡ
+ ///
+ bool Load(const void* data, size_t size);
+
uint GetWidth();
uint GetHeight();
@@ -31,29 +41,29 @@ namespace AsuraEngine
///
Color GetPixel(uint x, uint y);
- private:
+ void Render(int x, int y, int sx, int sy, int ox, int oy, int r) override;
- friend class ImageFactory;
+ void Render(const Math::Rect& quad, int x, int y, int sx, int sy, int ox, int oy, int r) override;
- Image(Color* pixels, int width, int height);
- ~Image();
+ //----------------------------------------------------------------------------------------------------------
+
+ LUAX_DECL_FACTORY(SimImage);
+
+ LUAX_DECL_METHOD(l_Load);
+ LUAX_DECL_METHOD(l_GetPixel);
+ LUAX_DECL_METHOD(l_GetWidth);
+ LUAX_DECL_METHOD(l_GetHeight);
+
+ //----------------------------------------------------------------------------------------------------------
+
+ private:
///
/// СΪλ
///
uint mWidth, mHeight;
- Color* mPixels;
-
- ///
- /// ID
- ///
- uint mID;
-
- //----------------------------------------------------------------------------------------------------
- // ͼƬSim࣬ķװAsuraEngine.Image棬һԱAsuraEngine.SimImageAsuraEngine.Image
- // һ档
- LUAX_DECL_FACTORY(SimImage);
+ Color* mPixels;
};
diff --git a/Source/Asura.Engine/Graphics/Mesh2D.h b/Source/Asura.Engine/Graphics/Mesh2D.h
index 0d5113a..921ae80 100644
--- a/Source/Asura.Engine/Graphics/Mesh2D.h
+++ b/Source/Asura.Engine/Graphics/Mesh2D.h
@@ -1,6 +1,9 @@
#ifndef __ASURA_ENGINE_MESH2D_H__
#define __ASURA_ENGINE_MESH2D_H__
+#include "Object.h"
+#include "SimClass.h"
+
namespace AsuraEngine
{
namespace Graphics
@@ -9,7 +12,7 @@ namespace AsuraEngine
///
/// 2D meshһЩ㶯
///
- class Mesh2D
+ class Mesh2D : virtual public Object, public SimClass
{
};
diff --git a/Source/Asura.Engine/Graphics/Port/Canvas.cpp b/Source/Asura.Engine/Graphics/Port/Canvas.cpp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Source/Asura.Engine/Graphics/Port/Canvas.cpp
diff --git a/Source/Asura.Engine/Graphics/Port/Color.cpp b/Source/Asura.Engine/Graphics/Port/Color.cpp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Source/Asura.Engine/Graphics/Port/Color.cpp
diff --git a/Source/Asura.Engine/Graphics/Port/Image.cpp b/Source/Asura.Engine/Graphics/Port/Image.cpp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Source/Asura.Engine/Graphics/Port/Image.cpp
diff --git a/Source/Asura.Engine/Graphics/Port/Mesh2D.cpp b/Source/Asura.Engine/Graphics/Port/Mesh2D.cpp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Source/Asura.Engine/Graphics/Port/Mesh2D.cpp
diff --git a/Source/Asura.Engine/Graphics/Port/Shader.cpp b/Source/Asura.Engine/Graphics/Port/Shader.cpp
new file mode 100644
index 0000000..887cfae
--- /dev/null
+++ b/Source/Asura.Engine/Graphics/Port/Shader.cpp
@@ -0,0 +1,105 @@
+#include "../Shader.h"
+
+using namespace Luax;
+
+namespace AsuraEngine
+{
+ namespace Graphics
+ {
+
+ ///
+ /// shaderΪ
+ ///
+ int Shader::l_Use(lua_State* L)
+ {
+ LuaxState state = LuaxState(L);
+
+ }
+
+ ///
+ /// shaderΪǻ
+ ///
+ int Shader::l_Unuse(lua_State* L)
+ {
+ LuaxState state = LuaxState(L);
+
+ }
+
+ ///
+ /// ɫйshaderɹtrueʧܷfalse
+ ///
+ int Shader::l_Load(lua_State* L)
+ {
+ LuaxState state = LuaxState(L);
+
+ }
+
+ ///
+ /// жshaderǷuniformзtrue,򷵻false
+ ///
+ int Shader::l_HasUniform(lua_State* L)
+ {
+ LuaxState state = LuaxState(L);
+
+ }
+
+ ///
+ /// uniformslocationûuniformnil򷵻ضӦloc
+ ///
+ int Shader::l_GetUniformLocation(lua_State* L)
+ {
+ LuaxState state = LuaxState(L);
+
+ }
+
+ int Shader::l_SetBuiltInUniforms(lua_State* L)
+ {
+ LuaxState state = LuaxState(L);
+
+ }
+
+ int Shader::l_SetUniformFloat(lua_State* L)
+ {
+ LuaxState state = LuaxState(L);
+
+ }
+
+ int Shader::l_SetUniformTexture(lua_State* L)
+ {
+ LuaxState state = LuaxState(L);
+
+ }
+
+ int Shader::l_SetUniformVector2(lua_State* L)
+ {
+ LuaxState state = LuaxState(L);
+
+ }
+
+ int Shader::l_SetUniformVector3(lua_State* L)
+ {
+ LuaxState state = LuaxState(L);
+
+ }
+
+ int Shader::l_SetUniformVector4(lua_State* L)
+ {
+ LuaxState state = LuaxState(L);
+
+ }
+
+ int Shader::l_SetUniformColor(lua_State* L)
+ {
+ LuaxState state = LuaxState(L);
+
+ }
+
+ //עluaijԱ
+ int Shader::RegisterLuaClass(lua_State* L)
+ {
+ LuaxState state = LuaxState(L);
+
+ }
+
+ }
+} \ No newline at end of file
diff --git a/Source/Asura.Engine/Graphics/Port/SpriteBatch.cpp b/Source/Asura.Engine/Graphics/Port/SpriteBatch.cpp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Source/Asura.Engine/Graphics/Port/SpriteBatch.cpp
diff --git a/Source/Asura.Engine/Graphics/RenderTarget.cpp b/Source/Asura.Engine/Graphics/RenderTarget.cpp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Source/Asura.Engine/Graphics/RenderTarget.cpp
diff --git a/Source/Asura.Engine/Graphics/RenderTarget.h b/Source/Asura.Engine/Graphics/RenderTarget.h
new file mode 100644
index 0000000..05d7068
--- /dev/null
+++ b/Source/Asura.Engine/Graphics/RenderTarget.h
@@ -0,0 +1,30 @@
+#ifndef __ASURA_ENGINE_RENDERTARGET_H__
+#define __ASURA_ENGINE_RENDERTARGET_H__
+
+#include "Texture.h"
+#include "Object.h"
+
+namespace AsuraEngine
+{
+ namespace Graphics
+ {
+
+ ///
+ /// ɱΪȾĿ࣬
+ /// Canvas(RenderTexture)
+ /// Window(RenderWindow)
+ ///
+ class RenderTarget : virtual public Object
+ {
+ public:
+
+ RenderTarget() {};
+
+ virtual ~RenderTarget() {};
+
+ };
+
+ }
+}
+
+#endif \ No newline at end of file
diff --git a/Source/Asura.Engine/Graphics/Shader.cpp b/Source/Asura.Engine/Graphics/Shader.cpp
index e69de29..6cf65e0 100644
--- a/Source/Asura.Engine/Graphics/Shader.cpp
+++ b/Source/Asura.Engine/Graphics/Shader.cpp
@@ -0,0 +1,81 @@
+#include "Shader.h"
+
+namespace AsuraEngine
+{
+ namespace Graphics
+ {
+
+ Shader::Shader()
+ {
+
+ }
+
+ Shader::~Shader()
+ {
+
+ }
+
+ bool Shader::Load(const std::string& vertexShader, const std::string& fragmentShader)
+ {
+
+ }
+
+ uint Shader::GetUniformLocation(const std::string& uniform)
+ {
+
+ }
+
+ GLuint Shader::GetGLProgramHandle()
+ {
+ return mProgramHandle;
+ }
+
+ void Shader::Use()
+ {
+
+ }
+
+ void Shader::Unuse()
+ {
+
+ }
+
+ void Shader::SetUniformFloat(uint loc, float value)
+ {
+
+ }
+
+ void Shader::SetUniformFloat(uint loc, float value)
+ {
+
+ }
+
+ void Shader::SetUniformTexture(uint loc, const Texture& texture)
+ {
+
+ }
+
+ void Shader::SetUniformVector2(uint loc, const Math::Vector2& vec2)
+ {
+
+ }
+
+ void Shader::SetUniformVector3(uint loc, const Math::Vector3& vec3)
+ {
+
+ }
+
+ void Shader::SetUniformVector4(uint loc, const Math::Vector4& vec4)
+ {
+
+ }
+
+ uint Shader::GetGLTextureUnitCount()
+ {
+ GLint maxTextureUnits = 0;
+ glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &maxTextureUnits);
+ return (uint)maxTextureUnits;
+ }
+
+ }
+} \ No newline at end of file
diff --git a/Source/Asura.Engine/Graphics/Shader.h b/Source/Asura.Engine/Graphics/Shader.h
index 02d9f46..2cc482b 100644
--- a/Source/Asura.Engine/Graphics/Shader.h
+++ b/Source/Asura.Engine/Graphics/Shader.h
@@ -4,16 +4,18 @@
#include <map>
#include <string>
-#include "luax/luax.h"
+#include "Scripting/Luax.hpp"
+#include "Math/Vector2.h"
+#include "Math/Vector3.h"
+#include "Math/Vector4.h"
+#include "Math/Matrix44.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"
+#include "SimClass.h"
namespace AsuraEngine
{
@@ -21,10 +23,10 @@ namespace AsuraEngine
{
///
- /// һshaderһڲʼ乲ijShaderuniformsͶݣֻṩuniformsuseɫķ༭ÿ
- /// shaderͨshaderҵuniforms¶frameworkmaterialá
+ /// һshaderһڲʼ乲ijShaderuniformsͶݣֻṩuniformsuseɫķ༭
+ /// ÿshaderͨshaderҵuniforms¶frameworkmaterialá
///
- class Shader : virtual public Object
+ class Shader final : virtual public Object, public SimClass
{
public:
@@ -32,9 +34,10 @@ namespace AsuraEngine
~Shader();
///
- /// ӴshaderʱȼǷϴλuniforms location map
+ /// ӴshaderʱȼǷϴλuniforms location mapʹglAttachShader±ɫ
+ /// ɫ
///
- void Load(const std::string& vertexShader, const std::string& fragmentShader);
+ bool Load(const std::string& vertexShader, const std::string& fragmentShader);
///
/// shaderΪ
@@ -44,16 +47,7 @@ namespace AsuraEngine
///
/// shaderΪǻ
///
- void UnUse();
-
- ///
- /// һϵuniformsķ
- ///
- 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);
+ void Unuse();
///
/// Ѿ֪uniform location£ֵ
@@ -63,46 +57,58 @@ namespace AsuraEngine
void SetUniformVector2(uint loc, const Math::Vector2& vec2);
void SetUniformVector3(uint loc, const Math::Vector3& vec3);
void SetUniformVector4(uint loc, const Math::Vector4& vec4);
-
-/*
- ///
- /// עܷframeworkʵ֣㣬shadereditorҲõ
- /// ջunifrom location±shaderµuniform location
- ///
- void ClearUniformLocation();
-*/
- ///
- /// program id
- ///
- GLint GetNativeHandle();
+ void SetUniformColor(uint loc, const Color& color);
+ void SetUniformMatrix44(uint loc, const Math::Matrix44& mat44);
uint GetUniformLocation(const std::string& uniform);
- private:
+ bool HasUniform(const std::string& uniform);
+
+ GLuint GetGLProgramHandle();
///
- /// ñ
- /// vec2 Asura_Time xֵΪ뵱ǰʼʱ䣬yֵΪһ֡ʱ
- /// vec2 Asura_RenderTargetSize RTĴСΪλ
- /// Texture Asura_MainTexture
+ /// texture unitһΪ16
///
- void SetBuiltInUniforms();
-
- // OpenGLɫʶprogram id
- GLuint mPID;
- //// Uniformlocations
- //StringMap<uint> mUniformLocation;
+ static uint GetGLTextureUnitCount();
- ////////////////////////////////////////////////////////////////////////////////////////////////////////////
+ //----------------------------------------------------------------------------------------------------------
LUAX_DECL_FACTORY(SimShader);
+ LUAX_DECL_METHOD(l_Use);
+ LUAX_DECL_METHOD(l_Unuse);
+ LUAX_DECL_METHOD(l_Load);
+ LUAX_DECL_METHOD(l_HasUniform);
+ LUAX_DECL_METHOD(l_GetUniformLocation);
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);
+ LUAX_DECL_METHOD(l_SetUniformColor);
+
+ //----------------------------------------------------------------------------------------------------------
+
+ private:
+
+ ///
+ /// ǰshader
+ ///
+ static Shader* mCurrentShader;
+
+ ///
+ /// ñ
+ /// vec2 Asura_Time xֵΪ뵱ǰʼʱ䣬yֵΪһ֡ʱ
+ /// vec2 Asura_RenderTargetSize RTĴСΪλ
+ /// Texture Asura_MainTexture
+ ///
+ void SetBuiltInUniforms();
+
+ ///
+ /// OpenGL shader program handle.
+ ///
+ GLuint mProgramHandle;
};
diff --git a/Source/Asura.Engine/Graphics/SpriteBatch.h b/Source/Asura.Engine/Graphics/SpriteBatch.h
index 17d5e75..a571775 100644
--- a/Source/Asura.Engine/Graphics/SpriteBatch.h
+++ b/Source/Asura.Engine/Graphics/SpriteBatch.h
@@ -1,6 +1,8 @@
#ifndef __ASURA_ENGINE_SPRITE_BATCH_H__
#define __ASURA_ENGINE_SPRITE_BATCH_H__
+#include "Object.h"
+
namespace AsuraEngine
{
namespace Graphics
@@ -9,8 +11,11 @@ namespace AsuraEngine
///
/// Sprite batchȾͼƬĵطϵͳ
///
- class SpriteBatch
+ class SpriteBatch : virtual public Object
{
+ public:
+
+ SpriteBatch();
};
diff --git a/Source/Asura.Engine/Graphics/Texture.cpp b/Source/Asura.Engine/Graphics/Texture.cpp
index e69de29..6cb6497 100644
--- a/Source/Asura.Engine/Graphics/Texture.cpp
+++ b/Source/Asura.Engine/Graphics/Texture.cpp
@@ -0,0 +1,26 @@
+#include "Texture.h"
+
+namespace AsuraEngine
+{
+ namespace Graphics
+ {
+
+ Texture::Texture()
+ : mTextureHandle(0)
+ {
+ // GL texture
+ glGenTextures(1, &mTextureHandle);
+ }
+
+ Texture::~Texture()
+ {
+ glDeleteTextures(1, &mTextureHandle);
+ }
+
+ GLuint Texture::GetGLTextureHandle() const
+ {
+ return mTextureHandle;
+ }
+
+ }
+} \ No newline at end of file
diff --git a/Source/Asura.Engine/Graphics/Texture.h b/Source/Asura.Engine/Graphics/Texture.h
index 06461ce..e5b713c 100644
--- a/Source/Asura.Engine/Graphics/Texture.h
+++ b/Source/Asura.Engine/Graphics/Texture.h
@@ -1,8 +1,10 @@
#ifndef __ASURA_ENGINE_TEXTURE_H__
#define __ASURA_ENGINE_TEXTURE_H__
+#include "Math/Rect.h"
+#include "Scripting/Luax.hpp"
#include "Object.h"
-#include "Luax/luax.h"
+#include "GL.h"
namespace AsuraEngine
{
@@ -10,13 +12,40 @@ namespace AsuraEngine
{
///
- /// 2D࣬2d meshrender targetбʹ
+ /// 2D࣬2d meshrender targetбʹáTextureȾԭϽǣϷϲԵѿϵΪ׼
+ /// EditorҲϽΪԭ㣬Ϊ˷㡣
///
class Texture : virtual public Object
{
+ public:
+
+ Texture();
+
+ virtual ~Texture();
+
+ GLuint GetGLTextureHandle() const;
+
+ ///
+ /// ȾtexturertϣԭϽǣң
+ ///
+ virtual void Render(int x, int y, int sx, int sy, int ox, int oy, int r) = 0;
+
+ ///
+ /// ȾtextureһֵrtϣԭϽǣң졣
+ ///
+ virtual void Render(const Math::Rect& quad, int x, int y, int sx, int sy, int ox, int oy, int r) = 0;
+
+ protected:
+
+ ///
+ /// OpenGL texture handle
+ ///
+ GLuint mTextureHandle;
};
+ using Renderable = Texture;
+
}
}
diff --git a/Source/Asura.Engine/Math/Rect.cpp b/Source/Asura.Engine/Math/Rect.cpp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Source/Asura.Engine/Math/Rect.cpp
diff --git a/Source/Asura.Engine/Math/Rect.h b/Source/Asura.Engine/Math/Rect.h
new file mode 100644
index 0000000..5dd8631
--- /dev/null
+++ b/Source/Asura.Engine/Math/Rect.h
@@ -0,0 +1,17 @@
+#ifndef __ASURA_ENGINE_RECT_H__
+#define __ASURA_ENGINE_RECT_H__
+
+namespace AsuraEngine
+{
+ namespace Math
+ {
+
+ struct Rect
+ {
+ int x, y, w, h;
+ };
+
+ }
+}
+
+#endif \ No newline at end of file
diff --git a/Source/Asura.Engine/Object.h b/Source/Asura.Engine/Object.h
index f9a9f43..4f00d64 100644
--- a/Source/Asura.Engine/Object.h
+++ b/Source/Asura.Engine/Object.h
@@ -8,6 +8,7 @@
/// //ࡣΪ˱֤nativeͷŵʱ򲻻ᵼԼָ뱻ͷţҪһülua
/// //ͷʱǷͷnativenativeָ롣
/// //Object࣬ǴڶϵģӦͨObject::Releaseֶͷš
+/// Objectָ뱾Ϊlight userdataΪweak tablekeyobjectsʹַһЩͳơ
///
class Object
{
diff --git a/Source/Asura.Engine/SimClass.h b/Source/Asura.Engine/SimClass.h
new file mode 100644
index 0000000..5901fd5
--- /dev/null
+++ b/Source/Asura.Engine/SimClass.h
@@ -0,0 +1,22 @@
+#ifndef __ASURA_ENGINE_SIMCLASS_H__
+#define __ASURA_ENGINE_SIMCLASS_H__
+
+namespace AsuraEngine
+{
+
+ ///
+ ///
+ ///
+ class SimClass
+ {
+ public:
+
+ SimClass() {};
+
+ virtual ~SimClass() {};
+
+ };
+
+}
+
+#endif \ No newline at end of file
diff --git a/Source/Asura.Engine/Window/Window.h b/Source/Asura.Engine/Window/Window.h
index 3a09266..4e16e79 100644
--- a/Source/Asura.Engine/Window/Window.h
+++ b/Source/Asura.Engine/Window/Window.h
@@ -1,6 +1,8 @@
#ifndef __ASURA_ENGINE_WINDOW_H__
#define __ASURA_ENGINE_WINDOW_H__
+#include "Graphics/RenderTarget.h"
+
namespace AsuraEngine
{
namespace Graphics
@@ -9,16 +11,21 @@ namespace AsuraEngine
///
/// ڣֶ֧രڡڱ༭Ҫ֧֣runnerֻҪһڡ
///
- class Window
+ class Window final : public RenderTarget
{
public:
+ Window();
+
+ ~Window();
private:
};
+ using RenderWindow = Window;
+
}
}
diff --git a/Source/Asura.Framework/scripts/graphics/material.lua b/Source/Asura.Framework/scripts/graphics/material.lua
index e985b3c..64d70f7 100644
--- a/Source/Asura.Framework/scripts/graphics/material.lua
+++ b/Source/Asura.Framework/scripts/graphics/material.lua
@@ -5,6 +5,7 @@ local Material = AsuraEngine.Material
function Material.Ctor(self)
self.uniforms = {} --uniform变量和值
+ self.shader = nil
self.isShared = false
end
diff --git a/Source/Asura.Framework/scripts/graphics/shader.lua b/Source/Asura.Framework/scripts/graphics/shader.lua
index 728ab34..86ed8bb 100644
--- a/Source/Asura.Framework/scripts/graphics/shader.lua
+++ b/Source/Asura.Framework/scripts/graphics/shader.lua
@@ -1,10 +1,30 @@
AsuraEngine.Shader = AsuraEngine.Asset.Sub("Shader")
+local helper = AsuraEngine.Framework.Require("graphics/shaderHelper")
+
local Shader = AsuraEngine.Shader
-function Shader.Ctor(self, vert, frag)
+function Shader.Ctor(self)
+ self.simShader = nil
+ self.uniforms = {} -- 映射uniform name到location
+end
+
+--编译shader
+function Shader.Load(self, vert, frag)
+ self.uniforms = {}
self.simShader = AsuraEngine.SimShader.New(vert, frag)
- self.uniforms = {} -- 映射uniform name到location
+ if self.simShader == nil then
+ --shader编译错误
+ return
+ end
+ --在编译的时候就获得所有的uniform和loc
+ local uniforms = helper.GetUniforms(vert, frag)
+ if uniforms == nil then
+ return
+ end
+ for _, uniform in uniforms do
+ self.uniforms[uniform] = self.simShader:GetUniformLocation(uniform)
+ end
end
function Shader.GetUniformLocation(self, name)
diff --git a/Source/Asura.Framework/scripts/graphics/shaderHelper.lua b/Source/Asura.Framework/scripts/graphics/shaderHelper.lua
new file mode 100644
index 0000000..b1b42a6
--- /dev/null
+++ b/Source/Asura.Framework/scripts/graphics/shaderHelper.lua
@@ -0,0 +1,14 @@
+--[[
+解析vertex shader和 fragment shader,并取得两个shader里面定义的uniforms
+]]
+local helper = {}
+
+function helper.GetUniforms(vert, frag)
+
+end
+
+function helper.TryCompileShader(vert, frag)
+
+end
+
+return helper \ No newline at end of file
diff --git a/Source/Asura.Framework/scripts/gui/widget.lua b/Source/Asura.Framework/scripts/gui/widget.lua
index 98876e6..430ade0 100644
--- a/Source/Asura.Framework/scripts/gui/widget.lua
+++ b/Source/Asura.Framework/scripts/gui/widget.lua
@@ -1,3 +1,6 @@
+--[[
+Imgui,用在游戏里面
+]]
local Widget = AsuraEngine.Component("Widget")
function Widget.Ctor(self)