From a077eb38b01292611f4f6031b75e3e2c1c20f06e Mon Sep 17 00:00:00 2001 From: chai Date: Fri, 16 Aug 2019 08:54:08 +0800 Subject: *misc --- Source/modules/asura-core/Graphics/DrawInfo.h | 8 ++ Source/modules/asura-core/Graphics/GPUBuffer.cpp | 13 +- Source/modules/asura-core/Graphics/GfxDevice.cpp | 76 +++++------ Source/modules/asura-core/Graphics/GfxDevice.h | 110 +++++++++++---- Source/modules/asura-core/Graphics/Image.cpp | 103 -------------- Source/modules/asura-core/Graphics/Image.h | 63 --------- Source/modules/asura-core/Graphics/MatrixStack.cpp | 2 +- Source/modules/asura-core/Graphics/MatrixStack.h | 26 ++-- Source/modules/asura-core/Graphics/Mesh.cpp | 0 Source/modules/asura-core/Graphics/Mesh.h | 0 Source/modules/asura-core/Graphics/Mesh2D.cpp | 0 Source/modules/asura-core/Graphics/Mesh2D.h | 52 ------- .../modules/asura-core/Graphics/RenderTarget.cpp | 0 Source/modules/asura-core/Graphics/RenderTarget.h | 52 ------- .../modules/asura-core/Graphics/RenderTexture.cpp | 0 Source/modules/asura-core/Graphics/RenderTexture.h | 22 +++ Source/modules/asura-core/Graphics/Shader.cpp | 26 ++-- Source/modules/asura-core/Graphics/Shader.h | 27 +++- Source/modules/asura-core/Graphics/Texture.h | 38 +++++- Source/modules/asura-core/Graphics/VBO.cpp | 0 Source/modules/asura-core/Graphics/VBO.h | 27 ---- Source/modules/asura-core/Graphics/VBOs.cpp | 0 Source/modules/asura-core/Graphics/VBOs.h | 56 ++++++++ .../asura-core/Graphics/binding/Canvas.binding.cpp | 48 +++++++ .../asura-core/Graphics/binding/Color.binding.cpp | 130 ++++++++++++++++++ .../Graphics/binding/Color32.binding.cpp | 66 +++++++++ .../Graphics/binding/GPUBuffer.binding.cpp | 118 ++++++++++++++++ .../Graphics/binding/GfxDevice.binding.cpp | 151 +++++++++++++++++++++ .../asura-core/Graphics/binding/Image.binding.cpp | 71 ++++++++++ .../Graphics/binding/IndexBuffer.binding.cpp | 31 +++++ .../asura-core/Graphics/binding/Mesh.binding.cpp | 20 +++ .../asura-core/Graphics/binding/Shader.binding.cpp | 131 ++++++++++++++++++ .../Graphics/binding/SpriteBatch.binding.cpp | 20 +++ .../Graphics/binding/Texture.binding.cpp | 85 ++++++++++++ .../Graphics/binding/VertexBuffer.binding.cpp | 38 ++++++ .../asura-core/Graphics/binding/_canvas.cpp | 48 ------- .../modules/asura-core/Graphics/binding/_color.cpp | 130 ------------------ .../asura-core/Graphics/binding/_color32.cpp | 66 --------- .../asura-core/Graphics/binding/_gfx_device.cpp | 151 --------------------- .../asura-core/Graphics/binding/_gpu_buffer.cpp | 118 ---------------- .../modules/asura-core/Graphics/binding/_image.cpp | 71 ---------- .../asura-core/Graphics/binding/_index_buffer.cpp | 31 ----- .../asura-core/Graphics/binding/_mesh2d.cpp | 20 --- .../asura-core/Graphics/binding/_shader.cpp | 131 ------------------ .../asura-core/Graphics/binding/_sprite_batch.cpp | 20 --- .../asura-core/Graphics/binding/_texture.cpp | 85 ------------ .../asura-core/Graphics/binding/_vertex_buffer.cpp | 38 ------ 47 files changed, 1192 insertions(+), 1327 deletions(-) delete mode 100644 Source/modules/asura-core/Graphics/Image.cpp delete mode 100644 Source/modules/asura-core/Graphics/Image.h create mode 100644 Source/modules/asura-core/Graphics/Mesh.cpp create mode 100644 Source/modules/asura-core/Graphics/Mesh.h delete mode 100644 Source/modules/asura-core/Graphics/Mesh2D.cpp delete mode 100644 Source/modules/asura-core/Graphics/Mesh2D.h delete mode 100644 Source/modules/asura-core/Graphics/RenderTarget.cpp delete mode 100644 Source/modules/asura-core/Graphics/RenderTarget.h create mode 100644 Source/modules/asura-core/Graphics/RenderTexture.cpp create mode 100644 Source/modules/asura-core/Graphics/RenderTexture.h delete mode 100644 Source/modules/asura-core/Graphics/VBO.cpp delete mode 100644 Source/modules/asura-core/Graphics/VBO.h create mode 100644 Source/modules/asura-core/Graphics/VBOs.cpp create mode 100644 Source/modules/asura-core/Graphics/VBOs.h create mode 100644 Source/modules/asura-core/Graphics/binding/Canvas.binding.cpp create mode 100644 Source/modules/asura-core/Graphics/binding/Color.binding.cpp create mode 100644 Source/modules/asura-core/Graphics/binding/Color32.binding.cpp create mode 100644 Source/modules/asura-core/Graphics/binding/GPUBuffer.binding.cpp create mode 100644 Source/modules/asura-core/Graphics/binding/GfxDevice.binding.cpp create mode 100644 Source/modules/asura-core/Graphics/binding/Image.binding.cpp create mode 100644 Source/modules/asura-core/Graphics/binding/IndexBuffer.binding.cpp create mode 100644 Source/modules/asura-core/Graphics/binding/Mesh.binding.cpp create mode 100644 Source/modules/asura-core/Graphics/binding/Shader.binding.cpp create mode 100644 Source/modules/asura-core/Graphics/binding/SpriteBatch.binding.cpp create mode 100644 Source/modules/asura-core/Graphics/binding/Texture.binding.cpp create mode 100644 Source/modules/asura-core/Graphics/binding/VertexBuffer.binding.cpp delete mode 100644 Source/modules/asura-core/Graphics/binding/_canvas.cpp delete mode 100644 Source/modules/asura-core/Graphics/binding/_color.cpp delete mode 100644 Source/modules/asura-core/Graphics/binding/_color32.cpp delete mode 100644 Source/modules/asura-core/Graphics/binding/_gfx_device.cpp delete mode 100644 Source/modules/asura-core/Graphics/binding/_gpu_buffer.cpp delete mode 100644 Source/modules/asura-core/Graphics/binding/_image.cpp delete mode 100644 Source/modules/asura-core/Graphics/binding/_index_buffer.cpp delete mode 100644 Source/modules/asura-core/Graphics/binding/_mesh2d.cpp delete mode 100644 Source/modules/asura-core/Graphics/binding/_shader.cpp delete mode 100644 Source/modules/asura-core/Graphics/binding/_sprite_batch.cpp delete mode 100644 Source/modules/asura-core/Graphics/binding/_texture.cpp delete mode 100644 Source/modules/asura-core/Graphics/binding/_vertex_buffer.cpp (limited to 'Source/modules/asura-core/Graphics') diff --git a/Source/modules/asura-core/Graphics/DrawInfo.h b/Source/modules/asura-core/Graphics/DrawInfo.h index 0082102..6167359 100644 --- a/Source/modules/asura-core/Graphics/DrawInfo.h +++ b/Source/modules/asura-core/Graphics/DrawInfo.h @@ -6,6 +6,14 @@ namespace_begin(AsuraEngine) namespace_begin(Graphics) +struct ShaderUniform; + +struct ShaderUniformSheet +{ + + +}; + /// struct DrawInfo { diff --git a/Source/modules/asura-core/Graphics/GPUBuffer.cpp b/Source/modules/asura-core/Graphics/GPUBuffer.cpp index f28b914..ded4708 100644 --- a/Source/modules/asura-core/Graphics/GPUBuffer.cpp +++ b/Source/modules/asura-core/Graphics/GPUBuffer.cpp @@ -69,16 +69,16 @@ bool GPUBuffer::Fill(const void * data, size_t size, uint offset) return false; if (m_Buffer == 0) { - g_Device.WipeError(); + g_GfxDevice.WipeError(); glGenBuffers(1, &m_Buffer); if (m_Buffer == 0) throw Exception("OpenGL glGenBuffers failed."); glBindBuffer(m_Target, m_Buffer); glBufferData(m_Target, m_Size, NULL, m_Usage); - if (g_Device.HasError()) + if (g_GfxDevice.HasError()) { glBindBuffer(m_Target, 0); - throw Exception("OpenGL glBufferData failed. Errorcode=%d.", g_Device.GetError()); + throw Exception("OpenGL glBufferData failed. Errorcode=%d.", g_GfxDevice.GetError()); } #if ASURA_DEBUG m_Data = (byte*)malloc(size); @@ -87,11 +87,12 @@ bool GPUBuffer::Fill(const void * data, size_t size, uint offset) } else glBindBuffer(m_Target, m_Buffer); - glBufferSubData(m_Target, offset, size, data); - if (g_Device.HasError()) + //glBufferSubData(m_Target, offset, size, data); + GL_CALL(glBufferSubData, m_Target, offset, size, data); + if (g_GfxDevice.HasError()) { glBindBuffer(m_Target, 0); - throw Exception("OpenGL glBufferSubData failed. Errorcode=%d.", g_Device.GetError()); + throw Exception("OpenGL glBufferSubData failed. Errorcode=%d.", g_GfxDevice.GetError()); } glBindBuffer(m_Target, 0); #if ASURA_DEBUG diff --git a/Source/modules/asura-core/Graphics/GfxDevice.cpp b/Source/modules/asura-core/Graphics/GfxDevice.cpp index 529a76c..ab5e281 100644 --- a/Source/modules/asura-core/Graphics/GfxDevice.cpp +++ b/Source/modules/asura-core/Graphics/GfxDevice.cpp @@ -7,7 +7,7 @@ #include "MatrixStack.h" #include "Color.h" -using namespace AEMath; + namespace_begin(AsuraEngine) namespace_begin(Graphics) @@ -16,7 +16,13 @@ namespace_begin(Graphics) static bool instantiated = false; #endif -GfxDevice g_Device; +#if ASURA_GL_PROFILE +#define Stats(f) m_Stats.f +#else +#define Stats(f) +#endif + +GfxDevice g_GfxDevice; GfxDevice::GfxDevice() { @@ -32,12 +38,12 @@ GfxDevice::~GfxDevice() GfxDevice& GfxDevice::Get() { - return g_Device; + return g_GfxDevice; } static bool inited = false; -bool GfxDevice::Init(const AEMath::Recti& view) +bool GfxDevice::Init(const Recti& view) { bool loaded = false; #if ASURA_OPENGL_LOADER & ASURA_OPENGL_GLAD @@ -74,113 +80,101 @@ GLenum GfxDevice::GetError() void GfxDevice::SetDrawColor(float r, float g, float b, float a) { - state.drawColor.Set(r, g, b, a); + m_State.drawColor.Set(r, g, b, a); } Color& GfxDevice::GetDrawColor() { - return state.drawColor; + return m_State.drawColor; } void GfxDevice::SetViewport(const Recti v) { - state.viewport = v; + m_State.viewport = v; glViewport(v.x, v.y, v.w, v.h); } const Recti& GfxDevice::GetViewport() { - return state.viewport; + return m_State.viewport; } void GfxDevice::SetActiveShader(Shader* shader) { - if (state.shader == shader) + if (m_State.activeShader == shader) return; - if (state.shader) - state.shader->OnDisable(); - state.shader = shader; + if (m_State.activeShader) + m_State.activeShader->OnDisable(); + m_State.activeShader = shader; if (shader) { GLint program = shader->GetGLProgram(); glUseProgram(program); -#if ASURA_GL_PROFILE - ++stats.shaderSwitch; -#endif shader->OnEnable(); + Stats(AddShaderSwitch()); } } Shader* GfxDevice::GetActiveShader() const { - return state.shader; -} - -void GfxDevice::DrawArrays(GLenum mode, GLint first, GLsizei count) -{ - glDrawArrays(mode, first, count); -#if ASURA_GL_PROFILE - ++stats.drawCall; -#endif - if (state.shader) - state.shader->OnUsed(); + return m_State.activeShader; } void GfxDevice::PushMatrix () { - state.matrix[state.matrixMode].Push (); + m_State.matrix[m_State.matrixMode].Push (); } void GfxDevice::PopMatrix () { - state.matrix[state.matrixMode].Pop(); + m_State.matrix[m_State.matrixMode].Pop(); } void GfxDevice::LoadIdentity() { - state.matrix[state.matrixMode].LoadIdentity(); + m_State.matrix[m_State.matrixMode].LoadIdentity(); } void GfxDevice::Rotate (float angle) { - state.matrix[state.matrixMode].Rotate(angle); + m_State.matrix[m_State.matrixMode].Rotate(angle); } void GfxDevice::Translate (float x, float y) { - state.matrix[state.matrixMode].Translate(x, y); + m_State.matrix[m_State.matrixMode].Translate(x, y); } void GfxDevice::Scale (float x, float y) { - state.matrix[state.matrixMode].Scale(x, y); + m_State.matrix[m_State.matrixMode].Scale(x, y); } void GfxDevice::Ortho(float l, float r, float b, float t, float n, float f) { - state.matrix[state.matrixMode].Ortho(l, r, b, t, n, f); + m_State.matrix[m_State.matrixMode].Ortho(l, r, b, t, n, f); } -AEMath::Matrix44& GfxDevice::GetMatrix(MatrixMode mode) +Matrix44& GfxDevice::GetMatrix(MatrixMode mode) { - return state.matrix[mode].GetTop(); + return m_State.matrix[mode].GetTop(); } -AEMath::Matrix44 GfxDevice::GetMVPMatrix() +Matrix44 GfxDevice::GetMVPMatrix() { - return state.matrix[MATRIX_MODE_PROJECTION].GetTop() - * state.matrix[MATRIX_MODE_VIEW].GetTop() - * state.matrix[MATRIX_MODE_MODEL].GetTop(); + return m_State.matrix[MATRIX_MODE_PROJECTION].GetTop() + * m_State.matrix[MATRIX_MODE_VIEW].GetTop() + * m_State.matrix[MATRIX_MODE_MODEL].GetTop(); } uint GfxDevice::GetMatrixDepth() { - return state.matrix[state.matrixMode].GetCapacity(); + return m_State.matrix[m_State.matrixMode].GetCapacity(); } uint GfxDevice::GetMatrixIndex() { - return state.matrix[state.matrixMode].GetTopIndex(); + return m_State.matrix[m_State.matrixMode].GetTopIndex(); } diff --git a/Source/modules/asura-core/Graphics/GfxDevice.h b/Source/modules/asura-core/Graphics/GfxDevice.h index 2b105df..7ef03a3 100644 --- a/Source/modules/asura-core/Graphics/GfxDevice.h +++ b/Source/modules/asura-core/Graphics/GfxDevice.h @@ -16,10 +16,40 @@ namespace_begin(AsuraEngine) namespace_begin(Graphics) +class Mesh; class Profiler; class Shader; class GPUBuffer; class Canvas; +class DynamicVBO; +class VBO; +class VBOList; + +#define GFX_STATS_PROPERTY(TYPE,PROP_NAME,VAR_NAME) \ +private: \ + TYPE VAR_NAME; \ +public: \ + void Set##PROP_NAME (TYPE val) { VAR_NAME = val; } \ + TYPE Get##PROP_NAME () {return VAR_NAME; } \ + void Add##PROP_NAME (TYPE v=1) { VAR_NAME+=v;}; + +struct GfxDeviceStats +{ + GFX_STATS_PROPERTY(uint, DrawCall, drawCall); ///< 统计drawcall + GFX_STATS_PROPERTY(uint, CanvasSwitch, canvasSwitch); ///< 切换texture的次数 + GFX_STATS_PROPERTY(uint, ShaderSwitch, shaderSwitch); ///< 切换shader的次数 + GFX_STATS_PROPERTY(uint64, PrimsCount, primsCount); ///< 图元数量统计 + + void Reset() + { + drawCall = 0; + canvasSwitch = 0; + shaderSwitch = 0; + primsCount = 0; + } +}; + +#undef GFX_STATS_PROPERTY enum MatrixMode { @@ -28,6 +58,20 @@ enum MatrixMode MATRIX_MODE_VIEW = 2, }; + +enum GfxPrimitiveType +{ + GFX_PRIMITIVE_TRIANGLES = 0, + GFX_PRIMITIVE_TRIANGLESTRIPDEPRECATED, + GFX_PRIMITIVE_QUADS, + GFX_PRIMITIVE_LINES, + GFX_PRIMITIVE_LINESTRIP, + GFX_PRIMITIVE_POINTS, + + GFX_PRIMITIVE_TYPECOUNT, // KEEP THIS LAST! + GFX_PRIMITIVE_FORCE32BITINT = 0X7FFFFFFF // FORCE 32 BIT ENUM SIZE +}; + enum GLParams { GL_PARAM_MAX_TEXTURE_UNIT = 1, @@ -44,12 +88,12 @@ public: int GetParam(GLParams param); - bool Init(const AEMath::Recti& viewport); + bool Init(const Recti& viewport); bool Inited(); - void SetViewport(const AEMath::Recti viewport); + void SetViewport(const Recti viewport); - const AEMath::Recti& GetViewport(); + const Recti& GetViewport(); void PushMatrix(); void PopMatrix(); @@ -63,10 +107,8 @@ public: uint GetMatrixDepth(); uint GetMatrixIndex(); - void DrawArrays(GLenum mode, GLint first, GLsizei count); - - AEMath::Matrix44& GetMatrix(MatrixMode mode); - AEMath::Matrix44 GetMVPMatrix(); + Matrix44& GetMatrix(MatrixMode mode); + Matrix44 GetMVPMatrix(); void SetDrawColor(float r, float g, float b, float a); Color& GetDrawColor(); @@ -74,36 +116,47 @@ public: void SetActiveShader(Shader* = NULL); Shader* GetActiveShader() const; + VBO* CreateVBO(); + void DeleteVBO(); + + void DrawMesh(Mesh* mesh); + void DrawVBO(VBO* vbo); + void DrawDynamicVBO(); + void DrawTexture(Texture*); + void WipeError(); bool HasError(); GLenum GetError(); - GET_SET(MatrixMode, MatrixMode, state.matrixMode); - GET_SET(Canvas*, ActiveCanvas, state.canvas); + GET_SET(MatrixMode, MatrixMode, m_State.matrixMode); + GET_SET(Canvas*, ActiveCanvas, m_State.activeCanvas); private: + void BeforeDrawCall(); + + // Callbacks + void OnCreateVBO(VBO* vbo); + void OnDeleteVBO(VBO* vbo); + friend class Profiler; - struct - { - AEMath::Recti viewport; ///< 当前的视区,在切换HDC或者本窗口大小改变或者部分刷新时变动 - MatrixStack matrix[3]; ///< model, view, projection矩阵 - MatrixMode matrixMode; ///< 当前操作的矩阵 - Color drawColor; ///< 绘制的颜色 - Canvas* canvas; ///< 当前canvas - Shader* shader; ///< 当前使用的shader - } state; + struct { + Recti viewport; ///< 当前的视区,在切换HDC或者本窗口大小改变或者部分刷新时变动 + MatrixStack matrix[3]; ///< model, view, projection矩阵 + MatrixMode matrixMode; ///< 当前操作的矩阵 + Color drawColor; ///< 绘制的颜色 + Canvas* activeCanvas; ///< 当前canvas + Shader* activeShader; ///< 当前使用的shader + } m_State; #if ASURA_GL_PROFILE - struct - { - uint drawCall; ///< 统计drawcall - uint canvasSwitch; ///< 切换texture的次数 - uint shaderSwitch; ///< 切换shader的次数 - } stats; + GfxDeviceStats m_Stats; #endif + DynamicVBO* m_DynamicVBO; + VBOList* m_VBOList; + luaxport: LUAX_DECL_SINGLETON(GfxDevice); @@ -127,13 +180,12 @@ luaxport: }; -extern GfxDevice g_Device; - - -#define GL_CALL(x) do { x; /*GLAssert(); */} while(0) - +// 全局gfx device,runner和editor都适用 +extern GfxDevice g_GfxDevice; +inline GfxDevice& GetGfxDevice() { return g_GfxDevice; }; +#define GL_CALL(f, ...) do { f(__VA_ARGS__); /*GLAssert(); */} while(0) namespace_end namespace_end diff --git a/Source/modules/asura-core/Graphics/Image.cpp b/Source/modules/asura-core/Graphics/Image.cpp deleted file mode 100644 index 36d2478..0000000 --- a/Source/modules/asura-core/Graphics/Image.cpp +++ /dev/null @@ -1,103 +0,0 @@ -#include - -#include "../CoreConfig.h" - -#include "Shader.h" -#include "Image.h" -#include "GfxDevice.h" - -using namespace AEFileSystem; -using namespace AEImage; - -namespace_begin(AsuraEngine) -namespace_begin(Graphics) - -Image::Image() - : m_Width(0) - , m_Height(0) -{ -} - -Image::~Image() -{ -} - -bool Image::Load(ImageData* imgData) -{ - if (!imgData) return false; - - if (m_TexID == 0) - { - glGenTextures(1, &m_TexID); - if (m_TexID == 0) - throw Exception("OpenGL glGenTextures failed."); - } - - glBindTexture(GL_TEXTURE_2D, m_TexID); - imgData->Lock(); - int width = imgData->width; - int height = imgData->height; - TextureFormat tf = ConvertColorFormat(imgData->format); - glTexImage2D( - GL_TEXTURE_2D - , 0 - , tf.internalformat - , width, height - , 0 - , tf.externalformat - , tf.type - , imgData->pixels - ); - - m_Width = imgData->width; - m_Height = imgData->height; - imgData->Unlock(); - GLenum err = glGetError(); - if (err != GL_NO_ERROR) - throw Exception("OpenGL glTexImage2D cause error, error code=%d", err); - glBindTexture(GL_TEXTURE_2D, 0); - - return true; -} - -bool Image::Load(ImageData* imgData, const AEMath::Vector2i& pos) -{ - if (!imgData) return false; - - glBindTexture(GL_TEXTURE_2D, m_TexID); - imgData->Lock(); - int width = imgData->width; - int height = imgData->height; - TextureFormat tf = ConvertColorFormat(imgData->format); - glTexSubImage2D( - GL_TEXTURE_2D - , 0 - , pos.x - , pos.y - , imgData->width - , imgData->height - , tf.externalformat - , tf.type - , imgData->pixels - ); - imgData->Unlock(); - GLenum err = glGetError(); - if (err != GL_NO_ERROR) - throw Exception("OpenGL glTexSubImage2D cause error, error code=%d", err); - glBindTexture(GL_TEXTURE_2D, 0); - - return true; -} - -uint32 Image::GetWidth() -{ - return m_Width; -} - -uint32 Image::GetHeight() -{ - return m_Height; -} - -namespace_end -namespace_end \ No newline at end of file diff --git a/Source/modules/asura-core/Graphics/Image.h b/Source/modules/asura-core/Graphics/Image.h deleted file mode 100644 index a76d06f..0000000 --- a/Source/modules/asura-core/Graphics/Image.h +++ /dev/null @@ -1,63 +0,0 @@ -#ifndef _ASURA_ENGINE_IMAGE_H_ -#define _ASURA_ENGINE_IMAGE_H_ - -// asura modules -#include -#include -#include -#include -#include -#include - -// module -#include "../Image/ImageData.h" - -// folder -#include "Color.h" -#include "Color32.h" -#include "RenderState.h" -#include "GPUBuffer.h" -#include "Texture.h" - -namespace_begin(AsuraEngine) -namespace_begin(Graphics) - -class Image ASURA_FINAL : public AEScripting::Portable -{ -public: - - Image(); - ~Image(); - - bool Load(AEImage::ImageData* decodeData); - bool Load(AEImage::ImageData* decodeData, const AEMath::Vector2i& pos); - - uint GetWidth(); - uint GetHeight(); - - GPUBuffer* GenGPUBuffer(); - -private: - - uint32 m_Width, m_Height; - -luaxport: - - LUAX_DECL_FACTORY(Image, Texture); - - LUAX_DECL_METHOD(_New); - LUAX_DECL_METHOD(_Load); - LUAX_DECL_METHOD(_GetWidth); - LUAX_DECL_METHOD(_GetHeight); - LUAX_DECL_METHOD(_GetSize); - LUAX_DECL_METHOD(_GetPixel); - LUAX_DECL_METHOD(_Render); - -}; - -namespace_end -namespace_end - -namespace AEGraphics = AsuraEngine::Graphics; - -#endif \ No newline at end of file diff --git a/Source/modules/asura-core/Graphics/MatrixStack.cpp b/Source/modules/asura-core/Graphics/MatrixStack.cpp index 987d29c..88b9b6b 100644 --- a/Source/modules/asura-core/Graphics/MatrixStack.cpp +++ b/Source/modules/asura-core/Graphics/MatrixStack.cpp @@ -36,7 +36,7 @@ bool MatrixStack::Pop() return true; } -AEMath::Matrix44& MatrixStack::GetTop() +Matrix44& MatrixStack::GetTop() { return m_Stack[top]; } diff --git a/Source/modules/asura-core/Graphics/MatrixStack.h b/Source/modules/asura-core/Graphics/MatrixStack.h index 8dd56bf..15ae7e5 100644 --- a/Source/modules/asura-core/Graphics/MatrixStack.h +++ b/Source/modules/asura-core/Graphics/MatrixStack.h @@ -8,17 +8,9 @@ namespace_begin(AsuraEngine) namespace_begin(Graphics) -/// -/// 栈的矩阵深度。 -/// -#define ASURA_MAX_MATRIX_STACK_DEPTH 32 // 2KB - -/// -/// 保存栈状态,用来恢复之前的状态。栈中的一个矩阵stack[i]的值是stack[0]*..*stack[i-1] -/// 的值,并附加一系列transform。 -/// -/// TODO: template MatrixStack -/// +// 保存栈状态,用来恢复之前的状态。栈中的一个矩阵stack[i]的值是stack[0]*..*stack[i-1]的值,并附加一系列transform。 +// +// TODO: template MatrixStack class MatrixStack { public: @@ -30,11 +22,11 @@ public: bool Push(); bool Pop(); - AEMath::Matrix44& GetTop(); - void GetTop(ASURA_OUT AEMath::Matrix44& mat44); + Matrix44& GetTop(); + void GetTop(ASURA_OUT Matrix44& mat44); - void LoadMatrix(const AEMath::Matrix44& mat44); - void MultMatrix(const AEMath::Matrix44& mat44); + void LoadMatrix(const Matrix44& mat44); + void MultMatrix(const Matrix44& mat44); void Rotate(float angle); void Translate(float x, float y); @@ -47,8 +39,8 @@ public: private: - AEMath::Matrix44 m_Stack[ASURA_MAX_MATRIX_STACK_DEPTH]; - uint8 top; + Matrix44 m_Stack[32]; // 2kB + uint8 m_Top; }; diff --git a/Source/modules/asura-core/Graphics/Mesh.cpp b/Source/modules/asura-core/Graphics/Mesh.cpp new file mode 100644 index 0000000..e69de29 diff --git a/Source/modules/asura-core/Graphics/Mesh.h b/Source/modules/asura-core/Graphics/Mesh.h new file mode 100644 index 0000000..e69de29 diff --git a/Source/modules/asura-core/Graphics/Mesh2D.cpp b/Source/modules/asura-core/Graphics/Mesh2D.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/Source/modules/asura-core/Graphics/Mesh2D.h b/Source/modules/asura-core/Graphics/Mesh2D.h deleted file mode 100644 index 7a0f62e..0000000 --- a/Source/modules/asura-core/Graphics/Mesh2D.h +++ /dev/null @@ -1,52 +0,0 @@ -#ifndef _ASURA_ENGINE_MESH2D_H__ -#define _ASURA_ENGINE_MESH2D_H__ - -// cpp -#include - -// asura modules -#include -#include - -// module -#include "../Mesh/Mesh2dData.h" - -// folder -#include "Color.h" -#include "VertexBuffer.h" -#include "IndexBuffer.h" - -namespace_begin(AsuraEngine) -namespace_begin(Graphics) - -/// -/// 2D mesh,用于做一些顶点动画。 -/// https://en.wikipedia.org/wiki/Polygon_mesh -/// -class Mesh2D ASURA_FINAL - : public Scripting::Portable -{ -public: - - Mesh2D(); - ~Mesh2D(); - - bool Load(AEMesh::Mesh2DData* data); - -private: - - VertexBuffer* m_VBO; ///< vertex buffer - IndexBuffer* m_IBO; ///< index buffer - -luaxport: - - LUAX_DECL_FACTORY(Mesh2D); - - LUAX_DECL_METHOD(_SetVertex); - -}; - -namespace_end -namespace_end - -#endif \ No newline at end of file diff --git a/Source/modules/asura-core/Graphics/RenderTarget.cpp b/Source/modules/asura-core/Graphics/RenderTarget.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/Source/modules/asura-core/Graphics/RenderTarget.h b/Source/modules/asura-core/Graphics/RenderTarget.h deleted file mode 100644 index ab09e35..0000000 --- a/Source/modules/asura-core/Graphics/RenderTarget.h +++ /dev/null @@ -1,52 +0,0 @@ -#ifndef _ASURA_ENGINE_RENDERTARGET_H_ -#define _ASURA_ENGINE_RENDERTARGET_H_ - -#include -#include -#include - -#include "Texture.h" -#include "Color.h" - -namespace_begin(AsuraEngine) -namespace_begin(Graphics) - -/// -/// 可被作为渲染目标的类,派生类有 -/// Canvas(RenderTexture) -/// Window(RenderWindow) -/// -class RenderTarget : public AEScripting::Object -{ -public: - - RenderTarget() {}; - - virtual ~RenderTarget() {}; - - /// - /// 用颜色col清空整个RT - /// - virtual void Clear(const Color& col = Color::Black) = 0; - - /// - /// 用颜色col清空部分RT - /// - virtual void Clear(const Math::Recti& quad, const Color& col = Color::Black) = 0; - - /// - /// 绘制texture到本RT上 - /// - virtual void Draw(const Drawable* texture, const RenderState& state) = 0; - - /// - /// 绘制一部分texture到本RT上 - /// - virtual void Draw(const Drawable* texture, const Math::Recti& quad, const RenderState& state) = 0; - -}; - -namespace_end -namespace_end - -#endif \ No newline at end of file diff --git a/Source/modules/asura-core/Graphics/RenderTexture.cpp b/Source/modules/asura-core/Graphics/RenderTexture.cpp new file mode 100644 index 0000000..e69de29 diff --git a/Source/modules/asura-core/Graphics/RenderTexture.h b/Source/modules/asura-core/Graphics/RenderTexture.h new file mode 100644 index 0000000..08199bf --- /dev/null +++ b/Source/modules/asura-core/Graphics/RenderTexture.h @@ -0,0 +1,22 @@ +#ifndef _ASURA_ENGINE_RENDERTARGET_H_ +#define _ASURA_ENGINE_RENDERTARGET_H_ + +#include +#include +#include + +#include "Texture.h" +#include "Color.h" + +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + +class RenderTexture : public Texture +{ + +}; + +namespace_end +namespace_end + +#endif \ No newline at end of file diff --git a/Source/modules/asura-core/Graphics/Shader.cpp b/Source/modules/asura-core/Graphics/Shader.cpp index 329b3f1..56d638d 100644 --- a/Source/modules/asura-core/Graphics/Shader.cpp +++ b/Source/modules/asura-core/Graphics/Shader.cpp @@ -24,12 +24,12 @@ Shader::~Shader() void Shader::SetActive(Shader* shader) { - g_Device.SetActiveShader(shader); + g_GfxDevice.SetActiveShader(shader); } Shader* Shader::GetActive() { - return g_Device.GetActiveShader(); + return g_GfxDevice.GetActiveShader(); } bool Shader::Load(const string& vert, const string& frag) @@ -157,56 +157,56 @@ GLuint Shader::GetGLProgram() void Shader::SetUniformFloat(uint loc, float value) { - if(g_Device.GetActiveShader() == this) + if(g_GfxDevice.GetActiveShader() == this) glUniform1f(loc, value); } bool Shader::SetUniformTexture(uint loc, const Texture& texture) { - if (g_Device.GetActiveShader() != this) + if (g_GfxDevice.GetActiveShader() != this) return false; - g_Device.WipeError(); + g_GfxDevice.WipeError(); glActiveTexture(GL_TEXTURE0 + texUnit); - if (g_Device.HasError()) + if (g_GfxDevice.HasError()) return false; GLint tex = texture.GetGLTexture(); glBindTexture(GL_TEXTURE_2D, tex); - if (g_Device.HasError()) + if (g_GfxDevice.HasError()) return false; glUniform1i(loc, texUnit); - if (g_Device.HasError()) + if (g_GfxDevice.HasError()) return false; ++texUnit; } void Shader::SetUniformVector2(uint loc, const Math::Vector2f& vec2) { - if (g_Device.GetActiveShader() == this) + if (g_GfxDevice.GetActiveShader() == this) glUniform2f(loc, vec2.x, vec2.y); } void Shader::SetUniformVector3(uint loc, const Math::Vector3f& vec3) { - if (g_Device.GetActiveShader() == this) + if (g_GfxDevice.GetActiveShader() == this) glUniform3f(loc, vec3.x, vec3.y, vec3.z); } void Shader::SetUniformVector4(uint loc, const Math::Vector4f& vec4) { - if (g_Device.GetActiveShader() == this) + if (g_GfxDevice.GetActiveShader() == this) glUniform4f(loc, vec4.x, vec4.y, vec4.z, vec4.w); } void Shader::SetUniformMatrix44(uint loc, const Math::Matrix44& mat) { - if (g_Device.GetActiveShader() == this) + if (g_GfxDevice.GetActiveShader() == this) glUniformMatrix4fv(loc, 1, GL_FALSE, mat.GetElements()); } void Shader::SetUniformColor(uint loc, const Color& color) { - if (g_Device.GetActiveShader() == this) + if (g_GfxDevice.GetActiveShader() == this) glUniform4f(loc, color.r, color.g, color.b, color.a); } diff --git a/Source/modules/asura-core/Graphics/Shader.h b/Source/modules/asura-core/Graphics/Shader.h index 615b028..6d7ef90 100644 --- a/Source/modules/asura-core/Graphics/Shader.h +++ b/Source/modules/asura-core/Graphics/Shader.h @@ -3,6 +3,7 @@ #include #include +#include #include #include @@ -23,10 +24,21 @@ namespace_begin(AsuraEngine) namespace_begin(Graphics) +enum ShaderChannel +{ + SHADER_CHANNEL_NONE = -1, + SHADER_CHANNEL_VERTEX = 0, // Vertex (vector3) + SHADER_CHANNEL_NORMAL, // Normal (vector3) + SHADER_CHANNEL_COLOR, // Vertex color + SHADER_CHANNEL_TEXCOORD0, // UV set 0 (vector2) + SHADER_CHANNEL_TEXCOORD1, // UV set 1 (vector2) + SHADER_CHANNEL_TANGENT, // Tangent (vector4) + SHADER_CHANNEL_COUNT, // Keep this last! +}; + /// -/// 一个shader是一个在材质间共享的程序。Shader本身不保存uniforms和顶点数据,只提供设置 uniforms和use着色 -/// 器的方法。编辑器针对每个shader,会通过shader代码找到声明的uniforms变量,并暴露给framework的material -/// 设置。 +/// 一个shader是一个在材质间共享的程序。Shader本身不保存uniforms和顶点数据,只提供设置 uniforms和use着色器的方法。 +/// 编辑器针对每个shader,会通过shader代码找到声明的uniforms变量,并暴露给framework的material设置。 /// class Shader ASURA_FINAL : public Scripting::Portable @@ -64,10 +76,10 @@ public: bool SetUniformTexture(uint loc, const Texture& texture); float GetUniformFloat(uint loc); - AEMath::Vector2f GetUniformVector2(uint loc); - AEMath::Vector3f GetUniformVector3(uint loc); - AEMath::Vector4f GetUniformVector4s(uint loc); - AEMath::Matrix44 GetUniformMatrix44(uint loc); + Vector2f GetUniformVector2(uint loc); + Vector3f GetUniformVector3(uint loc); + Vector4f GetUniformVector4s(uint loc); + Matrix44 GetUniformMatrix44(uint loc); GLuint GetGLProgram(); @@ -109,6 +121,7 @@ luaxport: }; +// GPU program typedef Shader GpuProgram; namespace_end diff --git a/Source/modules/asura-core/Graphics/Texture.h b/Source/modules/asura-core/Graphics/Texture.h index 76b9a8f..572fad4 100644 --- a/Source/modules/asura-core/Graphics/Texture.h +++ b/Source/modules/asura-core/Graphics/Texture.h @@ -3,6 +3,7 @@ #include #include +#include #include "../CoreConfig.h" @@ -14,6 +15,17 @@ namespace_begin(Graphics) class RenderTarget; +/// 图片数据 +class ImageData +{ +public: + uint8* GetData(); +private: + int m_Format; + uint8* m_ImageData; + Vector2i m_ImageSize; +}; + /// UV采样方式 enum WrapMode { @@ -34,8 +46,8 @@ enum FilterMode enum ColorFormat { COLOR_FORMAT_UNKNOWN, - COLOR_FORMAT_RGBA8, ///< RGBA都是8bits int - COLOR_FORMAT_RGBA32F, ///< RGBA都是32bits float + COLOR_FORMAT_RGBA8, + COLOR_FORMAT_RGBA32F, }; /// 纹理格式,GPU内部和CPU外部格式 @@ -50,11 +62,14 @@ struct TextureFormat /// 2D纹理抽象类,在2d mesh和render target中被使用。Texture的渲染原点在左上角,游戏里面的上层会以笛卡尔 /// 坐标系为标准。在Editor里面界面和组件也是以左上角为原点,这样是为了方便。 /// -ASURA_ABSTRACT class Texture : public AEScripting::Object +class Texture : public AEScripting::Object { public: - LUAX_DECL_ABSTRACT_FACTORY(Texture); + LUAX_DECL_FACTORY(Texture); + + // Texture generator + static Texture* GenerateTexture(); Texture(); virtual ~Texture(); @@ -67,9 +82,12 @@ public: void GetFilterMode(); void GetWrapMode(); - /// 如果设置U或V方向filter为 bool IsGenMipmap(); + int GetWidth(); + int GetHeight(); + Vector2i GetSize(); + protected: /// 转换color format为texture format。 @@ -79,7 +97,12 @@ protected: FilterMode m_MinFilter; FilterMode m_MagFilter; WrapMode m_WrapMode; + int m_UsageMode; bool m_IsGenMipmap; + Vector2f m_TexelSize; + Vector2f m_UVScale; + +luaxport: LUAX_DECL_ENUM(ColorFormat, 1); LUAX_DECL_ENUM(FilterMode, 1); @@ -90,11 +113,12 @@ protected: LUAX_DECL_METHOD(_GetFilterMode); LUAX_DECL_METHOD(_GetWrapMode); LUAX_DECL_METHOD(_IsGenMipmap); + LUAX_DECL_METHOD(_GetWidth); + LUAX_DECL_METHOD(_GetHeight); + LUAX_DECL_METHOD(_GetSize); }; -typedef Texture Drawable; - namespace_end namespace_end diff --git a/Source/modules/asura-core/Graphics/VBO.cpp b/Source/modules/asura-core/Graphics/VBO.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/Source/modules/asura-core/Graphics/VBO.h b/Source/modules/asura-core/Graphics/VBO.h deleted file mode 100644 index f80991e..0000000 --- a/Source/modules/asura-core/Graphics/VBO.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef _ASURA_ENGINE_VBO_H_ -#define _ASURA_ENGINE_VBO_H_ - -#include - -namespace_begin(AsuraEngine) -namespace_begin(Graphics) - -struct VertexBufferData -{ - -}; - -struct IndexBufferData -{ - -}; - -class VBO -{ - -}; - -namespace_end -namespace_end - -#endif \ No newline at end of file diff --git a/Source/modules/asura-core/Graphics/VBOs.cpp b/Source/modules/asura-core/Graphics/VBOs.cpp new file mode 100644 index 0000000..e69de29 diff --git a/Source/modules/asura-core/Graphics/VBOs.h b/Source/modules/asura-core/Graphics/VBOs.h new file mode 100644 index 0000000..0833534 --- /dev/null +++ b/Source/modules/asura-core/Graphics/VBOs.h @@ -0,0 +1,56 @@ +#ifndef _ASURA_ENGINE_VBO_H_ +#define _ASURA_ENGINE_VBO_H_ + +#include +#include + +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + +struct VertexBufferData +{ + +}; + +struct IndexBufferData +{ + +}; + +class VBO +{ +public: + +private: + + + +}; + +class SharedVBO; + +class DynamicVBO +{ +public: + + void GetChunk(uint32 maxVertices, uint32 maxIndices, void** outVB, void** outIB); + void ReleaseChunk(uint32 actualVertices, uint32 actualIndices); + +private: + + // vertex buffer + SharedVBO* m_VB; + SharedVBO* m_LargeVB; + SharedVBO* m_ActiveVB; + + // index buffer + SharedVBO* m_IB; + SharedVBO* m_LargeIB; + SharedVBO* m_ActiveIB; + +}; + +namespace_end +namespace_end + +#endif \ No newline at end of file diff --git a/Source/modules/asura-core/Graphics/binding/Canvas.binding.cpp b/Source/modules/asura-core/Graphics/binding/Canvas.binding.cpp new file mode 100644 index 0000000..a038e67 --- /dev/null +++ b/Source/modules/asura-core/Graphics/binding/Canvas.binding.cpp @@ -0,0 +1,48 @@ +#include "../Canvas.h" + +using namespace std; + +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + + +LUAX_REGISTRY(Canvas) +{ + LUAX_REGISTER_METHODS(state, + { "SetSize", _SetSize }, + { "Bind", _Bind }, + { "Unbind", _Unbind } + ); +} + +LUAX_POSTPROCESS(Canvas) +{ + +} + +// canvas:SetSize() +LUAX_IMPL_METHOD(Canvas, _SetSize) +{ + LUAX_PREPARE(L, Canvas); + return 0; + +} + +// canvas:Bind() +LUAX_IMPL_METHOD(Canvas, _Bind) +{ + LUAX_PREPARE(L, Canvas); + + return 0; +} + +// canvas:Unbind() +LUAX_IMPL_METHOD(Canvas, _Unbind) +{ + LUAX_PREPARE(L, Canvas); + return 0; + +} + +namespace_end +namespace_end \ No newline at end of file diff --git a/Source/modules/asura-core/Graphics/binding/Color.binding.cpp b/Source/modules/asura-core/Graphics/binding/Color.binding.cpp new file mode 100644 index 0000000..008d9c2 --- /dev/null +++ b/Source/modules/asura-core/Graphics/binding/Color.binding.cpp @@ -0,0 +1,130 @@ +#include "../Color.h" + +using namespace std; +using namespace Luax; + +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + + +LUAX_REGISTRY(Color) +{ + LUAX_REGISTER_METHODS(state, + { "ToColor32", _ToColor32 }, + { "SetColor", _SetColor }, + { "GetColor", _GetColor }, + { "GetR", _GetR }, + { "GetG", _GetG }, + { "GetB", _GetB }, + { "GetA", _GetA }, + { "__eq", ___eq }, + { "__add", ___add }, + { "__sub", ___sub }, + { "__mul", ___mul }, + { "__div", ___div } + ); +} + +LUAX_POSTPROCESS(Color) +{ + +} + +// color:ToColor32() +LUAX_IMPL_METHOD(Color, _ToColor32) +{ + LUAX_PREPARE(L, Color); + + return 0; +} + +// color:SetColor() +LUAX_IMPL_METHOD(Color, _SetColor) +{ + LUAX_PREPARE(L, Color); + + return 0; +} + +// color:GetColor() +LUAX_IMPL_METHOD(Color, _GetColor) +{ + LUAX_PREPARE(L, Color); + + return 0; +} + +// color:GetR() +LUAX_IMPL_METHOD(Color, _GetR) +{ + LUAX_PREPARE(L, Color); + + return 0; +} + +// color:GetG() +LUAX_IMPL_METHOD(Color, _GetG) +{ + LUAX_PREPARE(L, Color); + + return 0; +} + +// color:GetB() +LUAX_IMPL_METHOD(Color, _GetB) +{ + LUAX_PREPARE(L, Color); + + return 0; +} + +// color:GetA() +LUAX_IMPL_METHOD(Color, _GetA) +{ + LUAX_PREPARE(L, Color); + + return 0; +} + +// color:__eq() +LUAX_IMPL_METHOD(Color, ___eq) +{ + LUAX_PREPARE(L, Color); + + return 0; +} + +// color:__add() +LUAX_IMPL_METHOD(Color, ___add) +{ + LUAX_PREPARE(L, Color); + + return 0; +} + +// color:__sub() +LUAX_IMPL_METHOD(Color, ___sub) +{ + LUAX_PREPARE(L, Color); + + return 0; +} + +// color:__mul() +LUAX_IMPL_METHOD(Color, ___mul) +{ + LUAX_PREPARE(L, Color); + + return 0; +} + +// color:__div() +LUAX_IMPL_METHOD(Color, ___div) +{ + LUAX_PREPARE(L, Color); + + return 0; +} + +} +} \ No newline at end of file diff --git a/Source/modules/asura-core/Graphics/binding/Color32.binding.cpp b/Source/modules/asura-core/Graphics/binding/Color32.binding.cpp new file mode 100644 index 0000000..7613361 --- /dev/null +++ b/Source/modules/asura-core/Graphics/binding/Color32.binding.cpp @@ -0,0 +1,66 @@ +#include "../Color32.h" + +using namespace std; + +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + + + LUAX_REGISTRY(Color32) + { + LUAX_REGISTER_METHODS(state, + { "ToColor", _ToColor }, + { "GetRed", _GetRed }, + { "GetGreen", _GetGreen }, + { "GetBlue", _GetBlue }, + { "GetAlpha", _GetAlpha } + ); + } + + LUAX_POSTPROCESS(Color32) + { + + } + + // color32:ToColor() + LUAX_IMPL_METHOD(Color32, _ToColor) + { + LUAX_PREPARE(L, Color32); + return 0; + + } + + // color32:GetRed() + LUAX_IMPL_METHOD(Color32, _GetRed) + { + LUAX_PREPARE(L, Color32); + return 0; + } + + // color32:GetGreen() + LUAX_IMPL_METHOD(Color32, _GetGreen) + { + LUAX_PREPARE(L, Color32); + + return 0; + } + + // color32:GetBlue() + LUAX_IMPL_METHOD(Color32, _GetBlue) + { + LUAX_PREPARE(L, Color32); + + return 0; + } + + // color32:GetAlpha() + LUAX_IMPL_METHOD(Color32, _GetAlpha) + { + LUAX_PREPARE(L, Color32); + + return 0; + } + + } +} + \ No newline at end of file diff --git a/Source/modules/asura-core/Graphics/binding/GPUBuffer.binding.cpp b/Source/modules/asura-core/Graphics/binding/GPUBuffer.binding.cpp new file mode 100644 index 0000000..8c39a59 --- /dev/null +++ b/Source/modules/asura-core/Graphics/binding/GPUBuffer.binding.cpp @@ -0,0 +1,118 @@ +#include + +#include "../image.h" +#include "../GPUBuffer.h" + +using namespace std; +using namespace Luax; + +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + + + LUAX_REGISTRY(GPUBuffer) + { + LUAX_REGISTER_METHODS(state, + { "Fill", _Fill }, + { "GetSize", _GetSize }, + { "GetCount", _GetCount } + ); + } + + LUAX_POSTPROCESS(GPUBuffer) + { + LUAX_REGISTER_ENUM(state, "EBufferType", + { "VERTEX", BUFFER_TYPE_VERTEX }, + { "INDEX", BUFFER_TYPE_INDEX } + ); + LUAX_REGISTER_ENUM(state, "EBufferUsage", + { "STREAM", BUFFER_USAGE_STREAM }, + { "DYNAMIC", BUFFER_USAGE_DYNAMIC }, + { "STATIC", BUFFER_USAGE_STATIC } + ); + LUAX_REGISTER_ENUM(state, "EBufferDataType", + { "INT", BUFFER_DATA_TYPE_INT }, + { "FLOAT", BUFFER_DATA_TYPE_FLOAT }, + { "UNSIGNED_BYTE", BUFFER_DATA_TYPE_UNSIGNED_BYTE } + ); + + } + + // buffer = GPUBuffer.New(bufferType, bufferUsage, bufferDataType, size) + // buffer = GPUBuffer.New(image) + // buffer = GPUBuffer.New(mesh2d) + // buffer = GPUBuffer.New(canvas) + // buffer = GPUBuffer.New(shape) + //LUAX_IMPL_METHOD(GPUBuffer, _New) + //{ + // LUAX_STATE(L); + + // return 0; + //} + + // gpubuffer:Fill({data_unit_list}, offseti) + // data_unit_list :存放数据的table + // offseti : 开始覆盖的地方所在的索引(从0开始) + LUAX_IMPL_METHOD(GPUBuffer, _Fill) + { + LUAX_PREPARE(L, GPUBuffer); + + // 使用buffer对应的类型数据修改buffer,在第一次调用时会初始化size大小的buffer,然后填充。 + int offset = state.GetValue(3, 0); + int count = lua_objlen(L, 2); + int size = count * self->GetDataTypeSize(); + byte* data = (byte*)malloc(size); + int unit = self->GetDataTypeSize(); + int i = 1; + lua_rawgeti(L, 2, i); + while (!lua_isnil(L, -1)) + { + switch (self->m_DataType) + { + case GL_INT: + { + int n = state.CheckValue(-1); + memcpy(data + (i - 1)*unit, &n, unit); + break; + } + case GL_FLOAT: + { + float n = state.CheckValue(-1); + memcpy(data + (i - 1)*unit, &n, unit); + break; + } + case GL_UNSIGNED_BYTE: + { + unsigned char n = state.CheckValue(-1); + memcpy(data + (i - 1)*unit, &n, unit); + break; + } + } + state.Pop(1); // value + lua_rawgeti(L, 2, ++i); + } + state.Pop(); // nil + + self->Fill(data, size, offset * unit); + + free(data); + return 0; + } + + // gpubuffer:GetSize() + LUAX_IMPL_METHOD(GPUBuffer, _GetSize) + { + LUAX_PREPARE(L, GPUBuffer); + state.Push(self->m_Size); + return 0; + } + + LUAX_IMPL_METHOD(GPUBuffer, _GetCount) + { + LUAX_PREPARE(L, GPUBuffer); + state.Push(self->m_Size / self->GetDataTypeSize()); + return 0; + } + + } +} diff --git a/Source/modules/asura-core/Graphics/binding/GfxDevice.binding.cpp b/Source/modules/asura-core/Graphics/binding/GfxDevice.binding.cpp new file mode 100644 index 0000000..f6c2004 --- /dev/null +++ b/Source/modules/asura-core/Graphics/binding/GfxDevice.binding.cpp @@ -0,0 +1,151 @@ +#include "../GfxDevice.h" + +using namespace std; +using namespace Luax; + +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + + + LUAX_REGISTRY(GfxDevice) + { + 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 }, + { "UseShader", _UseShader }, + { "UnuseShader", _UnuseShader } + ); + } + + LUAX_POSTPROCESS(GfxDevice) + { + LUAX_REGISTER_ENUM(state, "EMatrixMode", + { "PROJECTION", MATRIX_MODE_PROJECTION }, + { "0", 0 }, + { "MODEL", MATRIX_MODE_MODEL }, + { "1", 1 }, + { "VIEW", MATRIX_MODE_VIEW }, + { "2", 2 } + ); + LUAX_REGISTER_ENUM(state, "EGLParams", + { "MAX_TEXTURE_UNIT", GL_PARAM_MAX_TEXTURE_UNIT }, + { "1", 1 } + ); + + } + + // gfxdevice:SetMatrixMode() + LUAX_IMPL_METHOD(GfxDevice, _SetMatrixMode) + { + LUAX_PREPARE(L, GfxDevice); + + return 0; + } + + // gfxdevice:GetMatrixMode() + LUAX_IMPL_METHOD(GfxDevice, _GetMatrixMode) + { + LUAX_PREPARE(L, GfxDevice); + + return 0; + } + + // gfxdevice:PushMatrix() + LUAX_IMPL_METHOD(GfxDevice, _PushMatrix) + { + LUAX_PREPARE(L, GfxDevice); + + return 0; + } + + // gfxdevice:PopMatrix() + LUAX_IMPL_METHOD(GfxDevice, _PopMatrix) + { + LUAX_PREPARE(L, GfxDevice); + + return 0; + } + + // gfxdevice:LoadIdentity() + LUAX_IMPL_METHOD(GfxDevice, _LoadIdentity) + { + LUAX_PREPARE(L, GfxDevice); + + return 0; + } + + // gfxdevice:Rotate() + LUAX_IMPL_METHOD(GfxDevice, _Rotate) + { + LUAX_PREPARE(L, GfxDevice); + + return 0; + } + + // gfxdevice:Translate() + LUAX_IMPL_METHOD(GfxDevice, _Translate) + { + LUAX_PREPARE(L, GfxDevice); + + return 0; + } + + // gfxdevice:Scale() + LUAX_IMPL_METHOD(GfxDevice, _Scale) + { + LUAX_PREPARE(L, GfxDevice); + + return 0; + } + + // gfxdevice:Ortho() + LUAX_IMPL_METHOD(GfxDevice, _Ortho) + { + LUAX_PREPARE(L, GfxDevice); + + return 0; + } + + // gfxdevice:GetMatrixDepth() + LUAX_IMPL_METHOD(GfxDevice, _GetMatrixDepth) + { + LUAX_PREPARE(L, GfxDevice); + + return 0; + } + + // gfxdevice:GetMatrixIndex() + LUAX_IMPL_METHOD(GfxDevice, _GetMatrixIndex) + { + LUAX_PREPARE(L, GfxDevice); + + return 0; + } + + // gfxdevice:UseShader() + LUAX_IMPL_METHOD(GfxDevice, _UseShader) + { + LUAX_PREPARE(L, GfxDevice); + + return 0; + } + + // gfxdevice:UnuseShader() + LUAX_IMPL_METHOD(GfxDevice, _UnuseShader) + { + LUAX_PREPARE(L, GfxDevice); + + return 0; + } + + } +} diff --git a/Source/modules/asura-core/Graphics/binding/Image.binding.cpp b/Source/modules/asura-core/Graphics/binding/Image.binding.cpp new file mode 100644 index 0000000..94f88b8 --- /dev/null +++ b/Source/modules/asura-core/Graphics/binding/Image.binding.cpp @@ -0,0 +1,71 @@ +#include "../image.h" + +using namespace std; + +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + + +LUAX_REGISTRY(Image) +{ + LUAX_INHERIT(state, Texture); + + LUAX_REGISTER_METHODS(state, + { "New", _New }, + { "GetWidth", _GetWidth }, + { "GetHeight", _GetHeight }, + { "GetSize", _GetSize }, + { "Render", _Render } + ); +} + +LUAX_POSTPROCESS(Image) +{ +} + +// image = Image.New() +LUAX_IMPL_METHOD(Image, _New) +{ + LUAX_STATE(L); + Image* img = new Image(); + img->PushLuaxUserdata(state); + return 1; +} + +// width = image:GetWidth() +LUAX_IMPL_METHOD(Image, _GetWidth) +{ + LUAX_PREPARE(L, Image); + state.Push(self->GetWidth()); + return 1; +} + +// height = image:GetHeight() +LUAX_IMPL_METHOD(Image, _GetHeight) +{ + LUAX_PREPARE(L, Image); + state.Push(self->GetHeight()); + return 1; +} + +// width, height = image:GetSize() +LUAX_IMPL_METHOD(Image, _GetSize) +{ + LUAX_PREPARE(L, Image); + int width = self->GetWidth(); + int height = self->GetHeight(); + state.Push(width); + state.Push(height); + return 2; +} + +// image:Render() +LUAX_IMPL_METHOD(Image, _Render) +{ + LUAX_PREPARE(L, Image); + + return 0; +} + +} +} diff --git a/Source/modules/asura-core/Graphics/binding/IndexBuffer.binding.cpp b/Source/modules/asura-core/Graphics/binding/IndexBuffer.binding.cpp new file mode 100644 index 0000000..151dc98 --- /dev/null +++ b/Source/modules/asura-core/Graphics/binding/IndexBuffer.binding.cpp @@ -0,0 +1,31 @@ +#include "../IndexBuffer.h" + +using namespace std; +using namespace Luax; + +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + + + LUAX_REGISTRY(IndexBuffer) + { + LUAX_REGISTER_METHODS(state, + { "New", _New } + ); + } + + LUAX_POSTPROCESS(IndexBuffer) + { + + } + + // IndexBuffer.New() + LUAX_IMPL_METHOD(IndexBuffer, _New) + { + LUAX_STATE(L); + + return 0; + } + + } +} diff --git a/Source/modules/asura-core/Graphics/binding/Mesh.binding.cpp b/Source/modules/asura-core/Graphics/binding/Mesh.binding.cpp new file mode 100644 index 0000000..4e3f426 --- /dev/null +++ b/Source/modules/asura-core/Graphics/binding/Mesh.binding.cpp @@ -0,0 +1,20 @@ +#include "../mesh2d.h" + +using namespace std; + +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + + + LUAX_REGISTRY(Mesh2D) + { + + } + + LUAX_POSTPROCESS(Mesh2D) + { + + } + + } +} diff --git a/Source/modules/asura-core/Graphics/binding/Shader.binding.cpp b/Source/modules/asura-core/Graphics/binding/Shader.binding.cpp new file mode 100644 index 0000000..85fd388 --- /dev/null +++ b/Source/modules/asura-core/Graphics/binding/Shader.binding.cpp @@ -0,0 +1,131 @@ +#include "../shader.h" + +using namespace std; +using namespace Luax; + +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + + + LUAX_REGISTRY(Shader) + { + LUAX_REGISTER_METHODS(state, + { "New", _New }, + { "Load", _Load }, + { "Update", _Update }, + { "HasUniform", _HasUniform }, + { "GetUniformLocation", _GetUniformLocation }, + { "SetBuiltInUniforms", _SetBuiltInUniforms }, + { "SetUniformFloat", _SetUniformFloat }, + { "SetUniformTexture", _SetUniformTexture }, + { "SetUniformVector2", _SetUniformVector2 }, + { "SetUniformVector3", _SetUniformVector3 }, + { "SetUniformVector4", _SetUniformVector4 }, + { "SetUniformColor", _SetUniformColor }, + { "SetBuiltInUniforms", _SetBuiltInUniforms } + ); + } + + LUAX_POSTPROCESS(Shader) + { + + } + + // Shader.New() + LUAX_IMPL_METHOD(Shader, _New) + { + LUAX_STATE(L); + + return 0; + } + + // shader:Load() + LUAX_IMPL_METHOD(Shader, _Load) + { + LUAX_PREPARE(L, Shader); + + return 0; + } + + // shader:Update() + LUAX_IMPL_METHOD(Shader, _Update) + { + LUAX_PREPARE(L, Shader); + + return 0; + } + + // shader:HasUniform() + LUAX_IMPL_METHOD(Shader, _HasUniform) + { + LUAX_PREPARE(L, Shader); + + return 0; + } + + // shader:GetUniformLocation() + LUAX_IMPL_METHOD(Shader, _GetUniformLocation) + { + LUAX_PREPARE(L, Shader); + + return 0; + } + + // shader:SetBuiltInUniforms() + LUAX_IMPL_METHOD(Shader, _SetBuiltInUniforms) + { + LUAX_PREPARE(L, Shader); + + return 0; + } + + // shader:SetUniformFloat() + LUAX_IMPL_METHOD(Shader, _SetUniformFloat) + { + LUAX_PREPARE(L, Shader); + + return 0; + } + + // shader:SetUniformTexture() + LUAX_IMPL_METHOD(Shader, _SetUniformTexture) + { + LUAX_PREPARE(L, Shader); + + return 0; + } + + // shader:SetUniformVector2() + LUAX_IMPL_METHOD(Shader, _SetUniformVector2) + { + LUAX_PREPARE(L, Shader); + + return 0; + } + + // shader:SetUniformVector3() + LUAX_IMPL_METHOD(Shader, _SetUniformVector3) + { + LUAX_PREPARE(L, Shader); + + return 0; + } + + // shader:SetUniformVector4() + LUAX_IMPL_METHOD(Shader, _SetUniformVector4) + { + LUAX_PREPARE(L, Shader); + + return 0; + } + + // shader:SetUniformColor() + LUAX_IMPL_METHOD(Shader, _SetUniformColor) + { + LUAX_PREPARE(L, Shader); + + return 0; + } + + } +} diff --git a/Source/modules/asura-core/Graphics/binding/SpriteBatch.binding.cpp b/Source/modules/asura-core/Graphics/binding/SpriteBatch.binding.cpp new file mode 100644 index 0000000..6b7d25c --- /dev/null +++ b/Source/modules/asura-core/Graphics/binding/SpriteBatch.binding.cpp @@ -0,0 +1,20 @@ +#include "../SpriteBatch.h" + +using namespace std; + +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + + + LUAX_REGISTRY(SpriteBatch) + { + + } + + LUAX_POSTPROCESS(SpriteBatch) + { + + } + + } +} diff --git a/Source/modules/asura-core/Graphics/binding/Texture.binding.cpp b/Source/modules/asura-core/Graphics/binding/Texture.binding.cpp new file mode 100644 index 0000000..f5e5f17 --- /dev/null +++ b/Source/modules/asura-core/Graphics/binding/Texture.binding.cpp @@ -0,0 +1,85 @@ +#include "../texture.h" + +using namespace std; + +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + + + LUAX_REGISTRY(Texture) + { + LUAX_REGISTER_METHODS(state, + { "SetFilterMode", _SetFilterMode }, + { "SetWrapMode", _SetWrapMode }, + { "GetFilterMode", _GetFilterMode }, + { "GetWrapMode", _GetWrapMode }, + { "IsGenMipmap", _IsGenMipmap } + ); + } + + LUAX_POSTPROCESS(Texture) + { + LUAX_REGISTER_ENUM(state, "EColorFormat", + { "UNKNOWN", COLOR_FORMAT_UNKNOWN }, + { "RGBA8", COLOR_FORMAT_RGBA8 }, + { "RGBA32F", COLOR_FORMAT_RGBA32F } + ); + LUAX_REGISTER_ENUM(state, "EFilterMode", + { "NEAREST", FILTER_MODE_NEAREST }, + { "LINEAR", FILTER_MODE_LINEAR } + ); + LUAX_REGISTER_ENUM(state, "EWrapMode", + { "REPEAT", WRAP_MODE_REPEAT }, + { "MIRROR", WRAP_MODE_MIRROR }, + { "CLAMPTOEDGE", WRAP_MODE_CLAMPTOEDGE }, + { "CLAMPTOBORDER", WRAP_MODE_CLAMPTOBORDER } + ); + + } + + // texture:SetFilterMode(minFilter, magFilter) + LUAX_IMPL_METHOD(Texture, _SetFilterMode) + { + LUAX_PREPARE(L, Texture); + FilterMode min = (FilterMode)state.CheckValue(2); + FilterMode mag = (FilterMode)state.CheckValue(3); + self->SetFilterMode(min, mag); + return 0; + } + + // texture:SetWrapMode(wrap_mode) + LUAX_IMPL_METHOD(Texture, _SetWrapMode) + { + LUAX_PREPARE(L, Texture); + WrapMode wrap_mode = (WrapMode)state.CheckValue(2); + self->SetWrapMode(wrap_mode); + return 0; + } + + // min, mag = texture:GetFilterMode() + LUAX_IMPL_METHOD(Texture, _GetFilterMode) + { + LUAX_PREPARE(L, Texture); + state.Push((int)self->m_MinFilter); + state.Push((int)self->m_MagFilter); + return 2; + } + + // wrapmode= texture:GetWrapMode() + LUAX_IMPL_METHOD(Texture, _GetWrapMode) + { + LUAX_PREPARE(L, Texture); + state.Push((int)self->m_WrapMode); + return 1; + } + + // texture:IsGenMipmap() + LUAX_IMPL_METHOD(Texture, _IsGenMipmap) + { + LUAX_PREPARE(L, Texture); + state.Push(self->IsGenMipmap()); + return 1; + } + + } +} \ No newline at end of file diff --git a/Source/modules/asura-core/Graphics/binding/VertexBuffer.binding.cpp b/Source/modules/asura-core/Graphics/binding/VertexBuffer.binding.cpp new file mode 100644 index 0000000..8ed487b --- /dev/null +++ b/Source/modules/asura-core/Graphics/binding/VertexBuffer.binding.cpp @@ -0,0 +1,38 @@ +#include "../VertexBuffer.h" + +using namespace std; +using namespace Luax; + +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + + + LUAX_REGISTRY(VertexBuffer) + { + LUAX_REGISTER_METHODS(state, + { "New", _New } + ); + } + + LUAX_POSTPROCESS(VertexBuffer) + { + + } + + // vbo = VertexBuffer.New(usage, data_type, count) + LUAX_IMPL_METHOD(VertexBuffer, _New) + { + LUAX_STATE(L); + + BufferUsage usage = (BufferUsage)state.CheckValue(1); + BufferDataType datatype = (BufferDataType)state.CheckValue(2); + uint count = state.CheckValue(3); + + VertexBuffer* vbo = new VertexBuffer(usage, datatype, count * GPUBuffer::GetDataTypeSize(datatype)); + vbo->PushLuaxUserdata(state); + + return 1; + } + + } +} diff --git a/Source/modules/asura-core/Graphics/binding/_canvas.cpp b/Source/modules/asura-core/Graphics/binding/_canvas.cpp deleted file mode 100644 index 44841f5..0000000 --- a/Source/modules/asura-core/Graphics/binding/_canvas.cpp +++ /dev/null @@ -1,48 +0,0 @@ -#include "../Canvas.h" - -using namespace std; - -namespace_begin(AsuraEngine) -namespace_begin(Graphics) - - - LUAX_REGISTRY(Canvas) - { - LUAX_REGISTER_METHODS(state, - { "SetSize", _SetSize }, - { "Bind", _Bind }, - { "Unbind", _Unbind } - ); - } - - LUAX_POSTPROCESS(Canvas) - { - - } - - // canvas:SetSize() - LUAX_IMPL_METHOD(Canvas, _SetSize) - { - LUAX_PREPARE(L, Canvas); - return 0; - - } - - // canvas:Bind() - LUAX_IMPL_METHOD(Canvas, _Bind) - { - LUAX_PREPARE(L, Canvas); - - return 0; - } - - // canvas:Unbind() - LUAX_IMPL_METHOD(Canvas, _Unbind) - { - LUAX_PREPARE(L, Canvas); - return 0; - - } - - } -} diff --git a/Source/modules/asura-core/Graphics/binding/_color.cpp b/Source/modules/asura-core/Graphics/binding/_color.cpp deleted file mode 100644 index 008d9c2..0000000 --- a/Source/modules/asura-core/Graphics/binding/_color.cpp +++ /dev/null @@ -1,130 +0,0 @@ -#include "../Color.h" - -using namespace std; -using namespace Luax; - -namespace_begin(AsuraEngine) -namespace_begin(Graphics) - - -LUAX_REGISTRY(Color) -{ - LUAX_REGISTER_METHODS(state, - { "ToColor32", _ToColor32 }, - { "SetColor", _SetColor }, - { "GetColor", _GetColor }, - { "GetR", _GetR }, - { "GetG", _GetG }, - { "GetB", _GetB }, - { "GetA", _GetA }, - { "__eq", ___eq }, - { "__add", ___add }, - { "__sub", ___sub }, - { "__mul", ___mul }, - { "__div", ___div } - ); -} - -LUAX_POSTPROCESS(Color) -{ - -} - -// color:ToColor32() -LUAX_IMPL_METHOD(Color, _ToColor32) -{ - LUAX_PREPARE(L, Color); - - return 0; -} - -// color:SetColor() -LUAX_IMPL_METHOD(Color, _SetColor) -{ - LUAX_PREPARE(L, Color); - - return 0; -} - -// color:GetColor() -LUAX_IMPL_METHOD(Color, _GetColor) -{ - LUAX_PREPARE(L, Color); - - return 0; -} - -// color:GetR() -LUAX_IMPL_METHOD(Color, _GetR) -{ - LUAX_PREPARE(L, Color); - - return 0; -} - -// color:GetG() -LUAX_IMPL_METHOD(Color, _GetG) -{ - LUAX_PREPARE(L, Color); - - return 0; -} - -// color:GetB() -LUAX_IMPL_METHOD(Color, _GetB) -{ - LUAX_PREPARE(L, Color); - - return 0; -} - -// color:GetA() -LUAX_IMPL_METHOD(Color, _GetA) -{ - LUAX_PREPARE(L, Color); - - return 0; -} - -// color:__eq() -LUAX_IMPL_METHOD(Color, ___eq) -{ - LUAX_PREPARE(L, Color); - - return 0; -} - -// color:__add() -LUAX_IMPL_METHOD(Color, ___add) -{ - LUAX_PREPARE(L, Color); - - return 0; -} - -// color:__sub() -LUAX_IMPL_METHOD(Color, ___sub) -{ - LUAX_PREPARE(L, Color); - - return 0; -} - -// color:__mul() -LUAX_IMPL_METHOD(Color, ___mul) -{ - LUAX_PREPARE(L, Color); - - return 0; -} - -// color:__div() -LUAX_IMPL_METHOD(Color, ___div) -{ - LUAX_PREPARE(L, Color); - - return 0; -} - -} -} \ No newline at end of file diff --git a/Source/modules/asura-core/Graphics/binding/_color32.cpp b/Source/modules/asura-core/Graphics/binding/_color32.cpp deleted file mode 100644 index 7613361..0000000 --- a/Source/modules/asura-core/Graphics/binding/_color32.cpp +++ /dev/null @@ -1,66 +0,0 @@ -#include "../Color32.h" - -using namespace std; - -namespace_begin(AsuraEngine) -namespace_begin(Graphics) - - - LUAX_REGISTRY(Color32) - { - LUAX_REGISTER_METHODS(state, - { "ToColor", _ToColor }, - { "GetRed", _GetRed }, - { "GetGreen", _GetGreen }, - { "GetBlue", _GetBlue }, - { "GetAlpha", _GetAlpha } - ); - } - - LUAX_POSTPROCESS(Color32) - { - - } - - // color32:ToColor() - LUAX_IMPL_METHOD(Color32, _ToColor) - { - LUAX_PREPARE(L, Color32); - return 0; - - } - - // color32:GetRed() - LUAX_IMPL_METHOD(Color32, _GetRed) - { - LUAX_PREPARE(L, Color32); - return 0; - } - - // color32:GetGreen() - LUAX_IMPL_METHOD(Color32, _GetGreen) - { - LUAX_PREPARE(L, Color32); - - return 0; - } - - // color32:GetBlue() - LUAX_IMPL_METHOD(Color32, _GetBlue) - { - LUAX_PREPARE(L, Color32); - - return 0; - } - - // color32:GetAlpha() - LUAX_IMPL_METHOD(Color32, _GetAlpha) - { - LUAX_PREPARE(L, Color32); - - return 0; - } - - } -} - \ No newline at end of file diff --git a/Source/modules/asura-core/Graphics/binding/_gfx_device.cpp b/Source/modules/asura-core/Graphics/binding/_gfx_device.cpp deleted file mode 100644 index f6c2004..0000000 --- a/Source/modules/asura-core/Graphics/binding/_gfx_device.cpp +++ /dev/null @@ -1,151 +0,0 @@ -#include "../GfxDevice.h" - -using namespace std; -using namespace Luax; - -namespace_begin(AsuraEngine) -namespace_begin(Graphics) - - - LUAX_REGISTRY(GfxDevice) - { - 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 }, - { "UseShader", _UseShader }, - { "UnuseShader", _UnuseShader } - ); - } - - LUAX_POSTPROCESS(GfxDevice) - { - LUAX_REGISTER_ENUM(state, "EMatrixMode", - { "PROJECTION", MATRIX_MODE_PROJECTION }, - { "0", 0 }, - { "MODEL", MATRIX_MODE_MODEL }, - { "1", 1 }, - { "VIEW", MATRIX_MODE_VIEW }, - { "2", 2 } - ); - LUAX_REGISTER_ENUM(state, "EGLParams", - { "MAX_TEXTURE_UNIT", GL_PARAM_MAX_TEXTURE_UNIT }, - { "1", 1 } - ); - - } - - // gfxdevice:SetMatrixMode() - LUAX_IMPL_METHOD(GfxDevice, _SetMatrixMode) - { - LUAX_PREPARE(L, GfxDevice); - - return 0; - } - - // gfxdevice:GetMatrixMode() - LUAX_IMPL_METHOD(GfxDevice, _GetMatrixMode) - { - LUAX_PREPARE(L, GfxDevice); - - return 0; - } - - // gfxdevice:PushMatrix() - LUAX_IMPL_METHOD(GfxDevice, _PushMatrix) - { - LUAX_PREPARE(L, GfxDevice); - - return 0; - } - - // gfxdevice:PopMatrix() - LUAX_IMPL_METHOD(GfxDevice, _PopMatrix) - { - LUAX_PREPARE(L, GfxDevice); - - return 0; - } - - // gfxdevice:LoadIdentity() - LUAX_IMPL_METHOD(GfxDevice, _LoadIdentity) - { - LUAX_PREPARE(L, GfxDevice); - - return 0; - } - - // gfxdevice:Rotate() - LUAX_IMPL_METHOD(GfxDevice, _Rotate) - { - LUAX_PREPARE(L, GfxDevice); - - return 0; - } - - // gfxdevice:Translate() - LUAX_IMPL_METHOD(GfxDevice, _Translate) - { - LUAX_PREPARE(L, GfxDevice); - - return 0; - } - - // gfxdevice:Scale() - LUAX_IMPL_METHOD(GfxDevice, _Scale) - { - LUAX_PREPARE(L, GfxDevice); - - return 0; - } - - // gfxdevice:Ortho() - LUAX_IMPL_METHOD(GfxDevice, _Ortho) - { - LUAX_PREPARE(L, GfxDevice); - - return 0; - } - - // gfxdevice:GetMatrixDepth() - LUAX_IMPL_METHOD(GfxDevice, _GetMatrixDepth) - { - LUAX_PREPARE(L, GfxDevice); - - return 0; - } - - // gfxdevice:GetMatrixIndex() - LUAX_IMPL_METHOD(GfxDevice, _GetMatrixIndex) - { - LUAX_PREPARE(L, GfxDevice); - - return 0; - } - - // gfxdevice:UseShader() - LUAX_IMPL_METHOD(GfxDevice, _UseShader) - { - LUAX_PREPARE(L, GfxDevice); - - return 0; - } - - // gfxdevice:UnuseShader() - LUAX_IMPL_METHOD(GfxDevice, _UnuseShader) - { - LUAX_PREPARE(L, GfxDevice); - - return 0; - } - - } -} diff --git a/Source/modules/asura-core/Graphics/binding/_gpu_buffer.cpp b/Source/modules/asura-core/Graphics/binding/_gpu_buffer.cpp deleted file mode 100644 index 8c39a59..0000000 --- a/Source/modules/asura-core/Graphics/binding/_gpu_buffer.cpp +++ /dev/null @@ -1,118 +0,0 @@ -#include - -#include "../image.h" -#include "../GPUBuffer.h" - -using namespace std; -using namespace Luax; - -namespace_begin(AsuraEngine) -namespace_begin(Graphics) - - - LUAX_REGISTRY(GPUBuffer) - { - LUAX_REGISTER_METHODS(state, - { "Fill", _Fill }, - { "GetSize", _GetSize }, - { "GetCount", _GetCount } - ); - } - - LUAX_POSTPROCESS(GPUBuffer) - { - LUAX_REGISTER_ENUM(state, "EBufferType", - { "VERTEX", BUFFER_TYPE_VERTEX }, - { "INDEX", BUFFER_TYPE_INDEX } - ); - LUAX_REGISTER_ENUM(state, "EBufferUsage", - { "STREAM", BUFFER_USAGE_STREAM }, - { "DYNAMIC", BUFFER_USAGE_DYNAMIC }, - { "STATIC", BUFFER_USAGE_STATIC } - ); - LUAX_REGISTER_ENUM(state, "EBufferDataType", - { "INT", BUFFER_DATA_TYPE_INT }, - { "FLOAT", BUFFER_DATA_TYPE_FLOAT }, - { "UNSIGNED_BYTE", BUFFER_DATA_TYPE_UNSIGNED_BYTE } - ); - - } - - // buffer = GPUBuffer.New(bufferType, bufferUsage, bufferDataType, size) - // buffer = GPUBuffer.New(image) - // buffer = GPUBuffer.New(mesh2d) - // buffer = GPUBuffer.New(canvas) - // buffer = GPUBuffer.New(shape) - //LUAX_IMPL_METHOD(GPUBuffer, _New) - //{ - // LUAX_STATE(L); - - // return 0; - //} - - // gpubuffer:Fill({data_unit_list}, offseti) - // data_unit_list :存放数据的table - // offseti : 开始覆盖的地方所在的索引(从0开始) - LUAX_IMPL_METHOD(GPUBuffer, _Fill) - { - LUAX_PREPARE(L, GPUBuffer); - - // 使用buffer对应的类型数据修改buffer,在第一次调用时会初始化size大小的buffer,然后填充。 - int offset = state.GetValue(3, 0); - int count = lua_objlen(L, 2); - int size = count * self->GetDataTypeSize(); - byte* data = (byte*)malloc(size); - int unit = self->GetDataTypeSize(); - int i = 1; - lua_rawgeti(L, 2, i); - while (!lua_isnil(L, -1)) - { - switch (self->m_DataType) - { - case GL_INT: - { - int n = state.CheckValue(-1); - memcpy(data + (i - 1)*unit, &n, unit); - break; - } - case GL_FLOAT: - { - float n = state.CheckValue(-1); - memcpy(data + (i - 1)*unit, &n, unit); - break; - } - case GL_UNSIGNED_BYTE: - { - unsigned char n = state.CheckValue(-1); - memcpy(data + (i - 1)*unit, &n, unit); - break; - } - } - state.Pop(1); // value - lua_rawgeti(L, 2, ++i); - } - state.Pop(); // nil - - self->Fill(data, size, offset * unit); - - free(data); - return 0; - } - - // gpubuffer:GetSize() - LUAX_IMPL_METHOD(GPUBuffer, _GetSize) - { - LUAX_PREPARE(L, GPUBuffer); - state.Push(self->m_Size); - return 0; - } - - LUAX_IMPL_METHOD(GPUBuffer, _GetCount) - { - LUAX_PREPARE(L, GPUBuffer); - state.Push(self->m_Size / self->GetDataTypeSize()); - return 0; - } - - } -} diff --git a/Source/modules/asura-core/Graphics/binding/_image.cpp b/Source/modules/asura-core/Graphics/binding/_image.cpp deleted file mode 100644 index 0e4cb16..0000000 --- a/Source/modules/asura-core/Graphics/binding/_image.cpp +++ /dev/null @@ -1,71 +0,0 @@ -#include "../image.h" - -using namespace std; - -namespace_begin(AsuraEngine) -namespace_begin(Graphics) - - - LUAX_REGISTRY(Image) - { - LUAX_INHERIT(state, Texture); - - LUAX_REGISTER_METHODS(state, - { "New", _New }, - { "GetWidth", _GetWidth }, - { "GetHeight", _GetHeight }, - { "GetSize", _GetSize }, - { "Render", _Render } - ); - } - - LUAX_POSTPROCESS(Image) - { - } - - // image = Image.New() - LUAX_IMPL_METHOD(Image, _New) - { - LUAX_STATE(L); - Image* img = new Image(); - img->PushLuaxUserdata(state); - return 1; - } - - // width = image:GetWidth() - LUAX_IMPL_METHOD(Image, _GetWidth) - { - LUAX_PREPARE(L, Image); - state.Push(self->GetWidth()); - return 1; - } - - // height = image:GetHeight() - LUAX_IMPL_METHOD(Image, _GetHeight) - { - LUAX_PREPARE(L, Image); - state.Push(self->GetHeight()); - return 1; - } - - // width, height = image:GetSize() - LUAX_IMPL_METHOD(Image, _GetSize) - { - LUAX_PREPARE(L, Image); - int width = self->GetWidth(); - int height = self->GetHeight(); - state.Push(width); - state.Push(height); - return 2; - } - - // image:Render() - LUAX_IMPL_METHOD(Image, _Render) - { - LUAX_PREPARE(L, Image); - - return 0; - } - - } -} diff --git a/Source/modules/asura-core/Graphics/binding/_index_buffer.cpp b/Source/modules/asura-core/Graphics/binding/_index_buffer.cpp deleted file mode 100644 index 151dc98..0000000 --- a/Source/modules/asura-core/Graphics/binding/_index_buffer.cpp +++ /dev/null @@ -1,31 +0,0 @@ -#include "../IndexBuffer.h" - -using namespace std; -using namespace Luax; - -namespace_begin(AsuraEngine) -namespace_begin(Graphics) - - - LUAX_REGISTRY(IndexBuffer) - { - LUAX_REGISTER_METHODS(state, - { "New", _New } - ); - } - - LUAX_POSTPROCESS(IndexBuffer) - { - - } - - // IndexBuffer.New() - LUAX_IMPL_METHOD(IndexBuffer, _New) - { - LUAX_STATE(L); - - return 0; - } - - } -} diff --git a/Source/modules/asura-core/Graphics/binding/_mesh2d.cpp b/Source/modules/asura-core/Graphics/binding/_mesh2d.cpp deleted file mode 100644 index 4e3f426..0000000 --- a/Source/modules/asura-core/Graphics/binding/_mesh2d.cpp +++ /dev/null @@ -1,20 +0,0 @@ -#include "../mesh2d.h" - -using namespace std; - -namespace_begin(AsuraEngine) -namespace_begin(Graphics) - - - LUAX_REGISTRY(Mesh2D) - { - - } - - LUAX_POSTPROCESS(Mesh2D) - { - - } - - } -} diff --git a/Source/modules/asura-core/Graphics/binding/_shader.cpp b/Source/modules/asura-core/Graphics/binding/_shader.cpp deleted file mode 100644 index 85fd388..0000000 --- a/Source/modules/asura-core/Graphics/binding/_shader.cpp +++ /dev/null @@ -1,131 +0,0 @@ -#include "../shader.h" - -using namespace std; -using namespace Luax; - -namespace_begin(AsuraEngine) -namespace_begin(Graphics) - - - LUAX_REGISTRY(Shader) - { - LUAX_REGISTER_METHODS(state, - { "New", _New }, - { "Load", _Load }, - { "Update", _Update }, - { "HasUniform", _HasUniform }, - { "GetUniformLocation", _GetUniformLocation }, - { "SetBuiltInUniforms", _SetBuiltInUniforms }, - { "SetUniformFloat", _SetUniformFloat }, - { "SetUniformTexture", _SetUniformTexture }, - { "SetUniformVector2", _SetUniformVector2 }, - { "SetUniformVector3", _SetUniformVector3 }, - { "SetUniformVector4", _SetUniformVector4 }, - { "SetUniformColor", _SetUniformColor }, - { "SetBuiltInUniforms", _SetBuiltInUniforms } - ); - } - - LUAX_POSTPROCESS(Shader) - { - - } - - // Shader.New() - LUAX_IMPL_METHOD(Shader, _New) - { - LUAX_STATE(L); - - return 0; - } - - // shader:Load() - LUAX_IMPL_METHOD(Shader, _Load) - { - LUAX_PREPARE(L, Shader); - - return 0; - } - - // shader:Update() - LUAX_IMPL_METHOD(Shader, _Update) - { - LUAX_PREPARE(L, Shader); - - return 0; - } - - // shader:HasUniform() - LUAX_IMPL_METHOD(Shader, _HasUniform) - { - LUAX_PREPARE(L, Shader); - - return 0; - } - - // shader:GetUniformLocation() - LUAX_IMPL_METHOD(Shader, _GetUniformLocation) - { - LUAX_PREPARE(L, Shader); - - return 0; - } - - // shader:SetBuiltInUniforms() - LUAX_IMPL_METHOD(Shader, _SetBuiltInUniforms) - { - LUAX_PREPARE(L, Shader); - - return 0; - } - - // shader:SetUniformFloat() - LUAX_IMPL_METHOD(Shader, _SetUniformFloat) - { - LUAX_PREPARE(L, Shader); - - return 0; - } - - // shader:SetUniformTexture() - LUAX_IMPL_METHOD(Shader, _SetUniformTexture) - { - LUAX_PREPARE(L, Shader); - - return 0; - } - - // shader:SetUniformVector2() - LUAX_IMPL_METHOD(Shader, _SetUniformVector2) - { - LUAX_PREPARE(L, Shader); - - return 0; - } - - // shader:SetUniformVector3() - LUAX_IMPL_METHOD(Shader, _SetUniformVector3) - { - LUAX_PREPARE(L, Shader); - - return 0; - } - - // shader:SetUniformVector4() - LUAX_IMPL_METHOD(Shader, _SetUniformVector4) - { - LUAX_PREPARE(L, Shader); - - return 0; - } - - // shader:SetUniformColor() - LUAX_IMPL_METHOD(Shader, _SetUniformColor) - { - LUAX_PREPARE(L, Shader); - - return 0; - } - - } -} diff --git a/Source/modules/asura-core/Graphics/binding/_sprite_batch.cpp b/Source/modules/asura-core/Graphics/binding/_sprite_batch.cpp deleted file mode 100644 index 6b7d25c..0000000 --- a/Source/modules/asura-core/Graphics/binding/_sprite_batch.cpp +++ /dev/null @@ -1,20 +0,0 @@ -#include "../SpriteBatch.h" - -using namespace std; - -namespace_begin(AsuraEngine) -namespace_begin(Graphics) - - - LUAX_REGISTRY(SpriteBatch) - { - - } - - LUAX_POSTPROCESS(SpriteBatch) - { - - } - - } -} diff --git a/Source/modules/asura-core/Graphics/binding/_texture.cpp b/Source/modules/asura-core/Graphics/binding/_texture.cpp deleted file mode 100644 index f5e5f17..0000000 --- a/Source/modules/asura-core/Graphics/binding/_texture.cpp +++ /dev/null @@ -1,85 +0,0 @@ -#include "../texture.h" - -using namespace std; - -namespace_begin(AsuraEngine) -namespace_begin(Graphics) - - - LUAX_REGISTRY(Texture) - { - LUAX_REGISTER_METHODS(state, - { "SetFilterMode", _SetFilterMode }, - { "SetWrapMode", _SetWrapMode }, - { "GetFilterMode", _GetFilterMode }, - { "GetWrapMode", _GetWrapMode }, - { "IsGenMipmap", _IsGenMipmap } - ); - } - - LUAX_POSTPROCESS(Texture) - { - LUAX_REGISTER_ENUM(state, "EColorFormat", - { "UNKNOWN", COLOR_FORMAT_UNKNOWN }, - { "RGBA8", COLOR_FORMAT_RGBA8 }, - { "RGBA32F", COLOR_FORMAT_RGBA32F } - ); - LUAX_REGISTER_ENUM(state, "EFilterMode", - { "NEAREST", FILTER_MODE_NEAREST }, - { "LINEAR", FILTER_MODE_LINEAR } - ); - LUAX_REGISTER_ENUM(state, "EWrapMode", - { "REPEAT", WRAP_MODE_REPEAT }, - { "MIRROR", WRAP_MODE_MIRROR }, - { "CLAMPTOEDGE", WRAP_MODE_CLAMPTOEDGE }, - { "CLAMPTOBORDER", WRAP_MODE_CLAMPTOBORDER } - ); - - } - - // texture:SetFilterMode(minFilter, magFilter) - LUAX_IMPL_METHOD(Texture, _SetFilterMode) - { - LUAX_PREPARE(L, Texture); - FilterMode min = (FilterMode)state.CheckValue(2); - FilterMode mag = (FilterMode)state.CheckValue(3); - self->SetFilterMode(min, mag); - return 0; - } - - // texture:SetWrapMode(wrap_mode) - LUAX_IMPL_METHOD(Texture, _SetWrapMode) - { - LUAX_PREPARE(L, Texture); - WrapMode wrap_mode = (WrapMode)state.CheckValue(2); - self->SetWrapMode(wrap_mode); - return 0; - } - - // min, mag = texture:GetFilterMode() - LUAX_IMPL_METHOD(Texture, _GetFilterMode) - { - LUAX_PREPARE(L, Texture); - state.Push((int)self->m_MinFilter); - state.Push((int)self->m_MagFilter); - return 2; - } - - // wrapmode= texture:GetWrapMode() - LUAX_IMPL_METHOD(Texture, _GetWrapMode) - { - LUAX_PREPARE(L, Texture); - state.Push((int)self->m_WrapMode); - return 1; - } - - // texture:IsGenMipmap() - LUAX_IMPL_METHOD(Texture, _IsGenMipmap) - { - LUAX_PREPARE(L, Texture); - state.Push(self->IsGenMipmap()); - return 1; - } - - } -} \ No newline at end of file diff --git a/Source/modules/asura-core/Graphics/binding/_vertex_buffer.cpp b/Source/modules/asura-core/Graphics/binding/_vertex_buffer.cpp deleted file mode 100644 index 8ed487b..0000000 --- a/Source/modules/asura-core/Graphics/binding/_vertex_buffer.cpp +++ /dev/null @@ -1,38 +0,0 @@ -#include "../VertexBuffer.h" - -using namespace std; -using namespace Luax; - -namespace_begin(AsuraEngine) -namespace_begin(Graphics) - - - LUAX_REGISTRY(VertexBuffer) - { - LUAX_REGISTER_METHODS(state, - { "New", _New } - ); - } - - LUAX_POSTPROCESS(VertexBuffer) - { - - } - - // vbo = VertexBuffer.New(usage, data_type, count) - LUAX_IMPL_METHOD(VertexBuffer, _New) - { - LUAX_STATE(L); - - BufferUsage usage = (BufferUsage)state.CheckValue(1); - BufferDataType datatype = (BufferDataType)state.CheckValue(2); - uint count = state.CheckValue(3); - - VertexBuffer* vbo = new VertexBuffer(usage, datatype, count * GPUBuffer::GetDataTypeSize(datatype)); - vbo->PushLuaxUserdata(state); - - return 1; - } - - } -} -- cgit v1.1-26-g67d0