diff options
Diffstat (limited to 'source/modules/asura-core')
-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 |
8 files changed, 190 insertions, 19 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); |