diff options
Diffstat (limited to 'source/modules')
-rw-r--r-- | source/modules/asura-core/graphics/binding/_gl.cpp | 127 | ||||
-rw-r--r-- | source/modules/asura-core/graphics/binding/_image.cpp | 8 | ||||
-rw-r--r-- | source/modules/asura-core/graphics/gl.h | 55 | ||||
-rw-r--r-- | source/modules/asura-core/graphics/image.cpp | 5 | ||||
-rw-r--r-- | source/modules/asura-core/graphics/image.h | 6 | ||||
-rw-r--r-- | source/modules/asura-core/graphics/matrix_stack.h | 2 | ||||
-rw-r--r-- | source/modules/asura-core/graphics/shader.cpp | 2 | ||||
-rw-r--r-- | source/modules/asura-core/graphics/shader.h | 4 | ||||
-rw-r--r-- | source/modules/asura-utils/io/renewable.h | 8 | ||||
-rw-r--r-- | source/modules/asura-utils/math/matrix44.cpp | 7 | ||||
-rw-r--r-- | source/modules/asura-utils/math/matrix44.h | 77 |
11 files changed, 204 insertions, 97 deletions
diff --git a/source/modules/asura-core/graphics/binding/_gl.cpp b/source/modules/asura-core/graphics/binding/_gl.cpp new file mode 100644 index 0000000..4c0605f --- /dev/null +++ b/source/modules/asura-core/graphics/binding/_gl.cpp @@ -0,0 +1,127 @@ +#include "../gl.h" + +using namespace std; +using namespace Luax; + +namespace AsuraEngine +{ + namespace Graphics + { + + LUAX_REGISTRY(OpenGL) + { + LUAX_REGISTER_METHODS(state, + { "SetMatrixMode", _SetMatrixMode }, + { "GetMatrixMode", _GetMatrixMode }, + { "PushMatrix", _PushMatrix }, + { "PopMatrix", _PopMatrix }, + { "LoadIdentity", _LoadIdentity }, + { "Rotate", _Rotate }, + { "Translate", _Translate }, + { "Scale", _Scale }, + { "Ortho", _Ortho }, + { "GetMatrixDepth", _GetMatrixDepth }, + { "GetMatrixIndex", _GetMatrixIndex } + ); + } + + LUAX_POSTPROCESS(OpenGL) + { + LUAX_REGISTER_ENUM(state, "EMatrixMode", + { "PROJECTION", MATRIX_PROJECTION }, + { "MODELVIEW", MATRIX_MODELVIEW } + ); + + } + + // GL.SetMatrixMode() + LUAX_IMPL_METHOD(OpenGL, _SetMatrixMode) + { + LUAX_PREPARE(L, OpenGL); + MatrixMode mode = (MatrixMode)state.CheckValue<int>(1); + gl.SetMatrixMode(mode); + return 0; + } + + // GL.GetMatrixMode() + LUAX_IMPL_METHOD(OpenGL, _GetMatrixMode) + { + LUAX_PREPARE(L, OpenGL); + + return 0; + } + + // GL.PushMatrix() + LUAX_IMPL_METHOD(OpenGL, _PushMatrix) + { + LUAX_PREPARE(L, OpenGL); + + return 0; + } + + // GL.PopMatrix() + LUAX_IMPL_METHOD(OpenGL, _PopMatrix) + { + LUAX_PREPARE(L, OpenGL); + + return 0; + } + + // GL.LoadIdentity() + LUAX_IMPL_METHOD(OpenGL, _LoadIdentity) + { + LUAX_PREPARE(L, OpenGL); + + return 0; + } + + // GL.Rotate() + LUAX_IMPL_METHOD(OpenGL, _Rotate) + { + LUAX_PREPARE(L, OpenGL); + + return 0; + } + + // GL.Translate() + LUAX_IMPL_METHOD(OpenGL, _Translate) + { + LUAX_PREPARE(L, OpenGL); + + return 0; + } + + // GL.Scale() + LUAX_IMPL_METHOD(OpenGL, _Scale) + { + LUAX_PREPARE(L, OpenGL); + + return 0; + } + + // GL.Ortho() + LUAX_IMPL_METHOD(OpenGL, _Ortho) + { + LUAX_PREPARE(L, OpenGL); + + return 0; + } + + // GL.GetMatrixDepth() + LUAX_IMPL_METHOD(OpenGL, _GetMatrixDepth) + { + LUAX_PREPARE(L, OpenGL); + + return 0; + } + + // GL.GetMatrixIndex() + LUAX_IMPL_METHOD(OpenGL, _GetMatrixIndex) + { + LUAX_PREPARE(L, OpenGL); + + return 0; + } + + } +} diff --git a/source/modules/asura-core/graphics/binding/_image.cpp b/source/modules/asura-core/graphics/binding/_image.cpp index 913bf5c..6179706 100644 --- a/source/modules/asura-core/graphics/binding/_image.cpp +++ b/source/modules/asura-core/graphics/binding/_image.cpp @@ -13,7 +13,7 @@ namespace AsuraEngine LUAX_REGISTER_METHODS(state, { "New", _New }, - { "Renew", _Renew }, + { "Update", _Update }, { "GetWidth", _GetWidth }, { "GetHeight", _GetHeight }, { "GetSize", _GetSize }, @@ -34,12 +34,12 @@ namespace AsuraEngine return 1; } - // successed = image:Renew(imgData) - LUAX_IMPL_METHOD(Image, _Renew) + // successed = image:Update(imgData) + LUAX_IMPL_METHOD(Image, _Update) { LUAX_PREPARE(L, Image); ImageData* imgData = state.CheckUserdata<ImageData>(2); - state.Push(self->Renew(imgData)); + state.Push(self->Update(imgData)); return 1; } diff --git a/source/modules/asura-core/graphics/gl.h b/source/modules/asura-core/graphics/gl.h index 9ca1f44..3104288 100644 --- a/source/modules/asura-core/graphics/gl.h +++ b/source/modules/asura-core/graphics/gl.h @@ -5,6 +5,7 @@ #include <glad/glad.h> +#include <asura-utils/scripting/portable.hpp> #include <asura-utils/math/rect.hpp> #include <asura-utils/math/matrix44.h> @@ -18,15 +19,25 @@ namespace AsuraEngine class Profiler; class Shader; + enum MatrixMode + { + MATRIX_PROJECTION = 0, + MATRIX_MODELVIEW, + _MATRIX_COUNT + }; + /// /// OpenGLģһЩopengl״̬١ڱ༭രڻ£һڶӦһhwnd /// һhdcԼopengl contextʹwglMakeCurrent(hdc, glc)ָǰ̶߳ /// Ⱦhdcopenglglcglм¼ľһ̵߳һڵһOpenGL /// ĵ״̬ /// - class OpenGL + class OpenGL : public AEScripting::Portable<OpenGL> { public: + + LUAX_DECL_SINGLETON(GL); + OpenGL(); ~OpenGL(); @@ -36,6 +47,19 @@ namespace AsuraEngine void UseShader(Shader* shader); void UnuseShader(); + void SetMatrixMode(MatrixMode mode); + MatrixMode GetMatrixMode(); + void PushMatrix(); + void PopMatrix(); + void LoadIdentity(); + void Rotate(float angle, float x, float y, float z); + void Translate(float x, float y, float z); + void Scale(float x, float y, float z); + void Ortho(float l, float r, float b, float t, float n, float f); + AEMath::Matrix44& GetMatrix(MatrixMode mode); + uint GetMatrixDepth(); + uint GetMatrixIndex(); + /// /// OpenGL3.0Ժû任ӿڡshaderȲﱣһЩOpenGL״̬ע /// ƺȫ̵ģҲ˵Asuraֶ֧߳ȾOpenGLĵĴʹһ @@ -45,16 +69,37 @@ namespace AsuraEngine /// struct { - Shader* shader; ///< ǰʹõshader - AEMath::Recti viewport; ///< ǰлHDC߱ڴСı߲ˢʱ䶯 - MatrixStack projectionMatrix; ///< ͶӰ - MatrixStack modelViewMatrix; ///< 任 + Shader* shader; ///< ǰʹõshader + AEMath::Recti viewport; ///< ǰлHDC߱ڴСı߲ˢʱ䶯 + MatrixStack matrix[_MATRIX_COUNT]; ///< ͶӰ + MatrixMode matrixMode; ///< ǰľ } state; private: friend class Profiler; + //----------------------------------------------------------------------------// + + LUAX_DECL_ENUM(MatrixMode, 0); + + 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); + + //----------------------------------------------------------------------------// + }; /// diff --git a/source/modules/asura-core/graphics/image.cpp b/source/modules/asura-core/graphics/image.cpp index 530ea97..4cbe826 100644 --- a/source/modules/asura-core/graphics/image.cpp +++ b/source/modules/asura-core/graphics/image.cpp @@ -20,13 +20,12 @@ namespace AsuraEngine { } - bool Image::Renew(DecodedData* data) + bool Image::Update(DecodedData* data) { if (!data) return false; ImageData* imgData = static_cast<ImageData*>(data); if (!imgData) return false; - // ûԴһ if (mTex == 0) { glGenTextures(1, &mTex); @@ -60,7 +59,7 @@ namespace AsuraEngine return true; } - bool Image::Renew(AEIO::DecodedData* data, const AEMath::Vector2i& pos) + bool Image::Update(AEIO::DecodedData* data, const AEMath::Vector2i& pos) { if (!data) return false; ImageData* imgData = static_cast<ImageData*>(data); diff --git a/source/modules/asura-core/graphics/image.h b/source/modules/asura-core/graphics/image.h index d60bd24..2e6ced2 100644 --- a/source/modules/asura-core/graphics/image.h +++ b/source/modules/asura-core/graphics/image.h @@ -44,8 +44,8 @@ namespace AsuraEngine /// ͼύGPUϢ¹imageʹglTexImage2D /// ύimageݡ /// - bool Renew(AEIO::DecodedData* decodeData) override; - bool Renew(AEIO::DecodedData* decodeData, const AEMath::Vector2i& pos); + bool Update(AEIO::DecodedData* decodeData) override; + bool Update(AEIO::DecodedData* decodeData, const AEMath::Vector2i& pos); uint GetWidth(); uint GetHeight(); @@ -58,7 +58,7 @@ namespace AsuraEngine //----------------------------------------------------------------------------// LUAX_DECL_METHOD(_New); - LUAX_DECL_METHOD(_Renew); + LUAX_DECL_METHOD(_Update); LUAX_DECL_METHOD(_GetWidth); LUAX_DECL_METHOD(_GetHeight); LUAX_DECL_METHOD(_GetSize); diff --git a/source/modules/asura-core/graphics/matrix_stack.h b/source/modules/asura-core/graphics/matrix_stack.h index 1923b30..e69ee98 100644 --- a/source/modules/asura-core/graphics/matrix_stack.h +++ b/source/modules/asura-core/graphics/matrix_stack.h @@ -50,7 +50,7 @@ namespace AsuraEngine /// /// ͶӰ任 /// - void Ortho(float left, float right, float bottom, float top, float near, float far); + void Ortho(float l, float r, float b, float t, float n, float f); //void Perspective(float fov, float aspect, float near, float far); //void Frustum(float left, float right, float top, float bottom, float near, float far); //void LookAt(float x, float y, float z, float cx, float cy, float cz, float ux, float uy, float uz); diff --git a/source/modules/asura-core/graphics/shader.cpp b/source/modules/asura-core/graphics/shader.cpp index a4738cd..fdcdf1b 100644 --- a/source/modules/asura-core/graphics/shader.cpp +++ b/source/modules/asura-core/graphics/shader.cpp @@ -39,7 +39,7 @@ namespace AsuraEngine glDeleteProgram(mProgram); } - bool Shader::Renew(AEIO::DecodedData* db) + bool Shader::Update(AEIO::DecodedData* db) { if (!db) return false; ShaderSouce* shaderSource = static_cast<ShaderSouce*>(db); diff --git a/source/modules/asura-core/graphics/shader.h b/source/modules/asura-core/graphics/shader.h index 9077599..6d51b8e 100644 --- a/source/modules/asura-core/graphics/shader.h +++ b/source/modules/asura-core/graphics/shader.h @@ -45,7 +45,7 @@ namespace AsuraEngine /// ӴshaderʱȼǷϴλuniforms location mapʹ /// glAttachShader±ɫɫ /// - bool Renew(AEIO::DecodedData* decodeData) override; + bool Update(AEIO::DecodedData* decodeData) override; /// /// shaderΪ @@ -111,7 +111,7 @@ namespace AsuraEngine LUAX_DECL_METHOD(_Use); LUAX_DECL_METHOD(_Unuse); LUAX_DECL_METHOD(_Load); - LUAX_DECL_METHOD(_Renew); + LUAX_DECL_METHOD(_Update); LUAX_DECL_METHOD(_HasUniform); LUAX_DECL_METHOD(_GetUniformLocation); LUAX_DECL_METHOD(_SetBuiltInUniforms); diff --git a/source/modules/asura-utils/io/renewable.h b/source/modules/asura-utils/io/renewable.h index a624c2c..4d047ea 100644 --- a/source/modules/asura-utils/io/renewable.h +++ b/source/modules/asura-utils/io/renewable.h @@ -21,12 +21,12 @@ namespace AsuraEngine virtual ~Renewable() {}; /// - /// ̳RenewableҪṩһRenew + /// ̳RenewableҪṩһUpdate /// - /// Effective C++09.Ӧýֹڹ캯еvirtualRenew - /// ӹ캯г룬ҪֶRenew + /// Effective C++09.Ӧýֹڹ캯еvirtualUpdate + /// ӹ캯г룬ҪֶUpdate /// - virtual bool Renew(AEIO::DecodedData* decode_data) = 0; + virtual bool Update(AEIO::DecodedData* decode_data) = 0; }; diff --git a/source/modules/asura-utils/math/matrix44.cpp b/source/modules/asura-utils/math/matrix44.cpp index 10c9ece..a1dc933 100644 --- a/source/modules/asura-utils/math/matrix44.cpp +++ b/source/modules/asura-utils/math/matrix44.cpp @@ -178,6 +178,13 @@ namespace AsuraEngine this->operator *=(t); } + void Matrix44::Transform(float x, float y, float angle, float sx, float sy, float ox, float oy) + { + Matrix44 t; + t.SetTransformation(x, y, angle, sx, sy, ox, oy); + this->operator *=(t); + } + // | x | // | y | // | 0 | diff --git a/source/modules/asura-utils/math/matrix44.h b/source/modules/asura-utils/math/matrix44.h index c0cea92..fa5be33 100644 --- a/source/modules/asura-utils/math/matrix44.h +++ b/source/modules/asura-utils/math/matrix44.h @@ -10,119 +10,48 @@ namespace AsuraEngine /// ҪתõOpenGLglm::mat4 /// https://blog.csdn.net/candycat1992/article/details/8830894 /// - class Matrix44 { public: static const Matrix44 Identity; - /// - /// Creates a new identity matrix. - /// Matrix44(); - /// - /// Copy constructor. - /// Matrix44(const Matrix44& m); - /// - /// Destructor. - /// ~Matrix44(); void operator = (const Matrix44& m); void SetOrtho(float _left, float _right, float _bottom, float _top, float _near, float _far); - /// - /// Multiplies this Matrix44 with another Matrix44, changing neither. - /// @param m The Matrix44 to multiply with this Matrix44. - /// @return The combined matrix. - /// Matrix44 operator * (const Matrix44 & m) const; - /// - /// Multiplies a Matrix44 into this Matrix44. - /// @param m The Matrix44 to combine into this Matrix44. - /// void operator *= (const Matrix44 & m); - /// - /// Gets a pointer to the 16 array elements. - /// @return The array elements. - /// const float* GetElements() const; - /// - /// ReSets this Matrix44 to the identity matrix. - /// void SetIdentity(); - /// - /// ReSets this Matrix44 to a translation. - /// @param x Translation along x-axis. - /// @param y Translation along y-axis. - /// void SetTranslation(float x, float y); - /// - /// ReSets this Matrix44 to a rotation. - /// @param r The angle in radians. - /// void SetRotation(float r); - /// - /// ReSets this Matrix44 to a scale transformation. - /// @param sx Scale factor along the x-axis. - /// @param sy Scale factor along the y-axis. - /// void SetScale(float sx, float sy); - /// - /// ReSets this Matrix44 to a shear transformation. - /// @param kx Shear along x-axis. - /// @param ky Shear along y-axis. - /// void SetShear(float kx, float ky); - /// - /// Creates a transformation with a certain position, orientation, scale - /// and offSet. Perfect for Drawables -- what a coincidence! - /// - /// @param x The translation along the x-axis. - /// @param y The translation along the y-axis. - /// @param angle The rotation (rad) around the center with offSet (ox,oy). - /// @param sx Scale along x-axis. - /// @param sy Scale along y-axis. - /// @param ox The offSet for rotation along the x-axis. - /// @param oy The offSet for rotation along the y-axis. - /// @param kx Shear along x-axis - /// @param ky Shear along y-axis - /// void SetTransformation(float x, float y, float angle, float sx, float sy, float ox, float oy); - /// - /// Multiplies this Matrix44 with a translation. - /// @param x Translation along x-axis. - /// @param y Translation along y-axis. - /// void Translate(float x, float y); - /// - /// Multiplies this Matrix44 with a rotation. - /// @param r Angle in radians. - /// void Rotate(float r); - /// - /// Multiplies this Matrix44 with a scale transformation. - /// @param sx Scale factor along the x-axis. - /// @param sy Scale factor along the y-axis. - /// void Scale(float sx, float sy); + void Transform(float x, float y, float angle, float sx, float sy, float ox, float oy); + /// /// Multiplies this Matrix44 with a shear transformation. /// @param kx Shear along the x-axis. @@ -157,4 +86,4 @@ namespace AsuraEngine namespace AEMath = AsuraEngine::Math; -#endif
\ No newline at end of file +#endif
\ No newline at end of file |