From 8ee3f7453bf7b0db5c7358e697e91714d825c87d Mon Sep 17 00:00:00 2001 From: chai Date: Sun, 9 Jun 2019 21:12:25 +0800 Subject: *misc --- source/modules/asura-core/graphics/canvas.h | 8 ++--- source/modules/asura-core/graphics/color.h | 4 +-- source/modules/asura-core/graphics/color32.h | 8 ++--- source/modules/asura-core/graphics/gfx_device.cpp | 13 +++---- source/modules/asura-core/graphics/gfx_device.h | 31 ++++++---------- source/modules/asura-core/graphics/gpu_buffer.cpp | 4 +-- source/modules/asura-core/graphics/gpu_buffer.h | 41 +++++++--------------- source/modules/asura-core/graphics/image.cpp | 4 +-- source/modules/asura-core/graphics/image.h | 34 ++++-------------- source/modules/asura-core/graphics/index_buffer.h | 2 ++ source/modules/asura-core/graphics/matrix_stack.h | 25 +------------ source/modules/asura-core/graphics/mesh2d.h | 11 +++--- source/modules/asura-core/graphics/shader.h | 25 +++++++------ source/modules/asura-core/graphics/sprite_batch.h | 4 +-- source/modules/asura-core/graphics/texture.h | 40 ++++++++------------- source/modules/asura-core/graphics/vertex_buffer.h | 2 ++ source/modules/asura-core/image/image_data.h | 24 ++++++------- .../modules/asura-core/image/image_decode_task.h | 2 +- source/modules/asura-core/input/clipboard.h | 10 +++--- source/modules/asura-core/input/cursor.h | 6 ++-- 20 files changed, 104 insertions(+), 194 deletions(-) (limited to 'source/modules/asura-core') diff --git a/source/modules/asura-core/graphics/canvas.h b/source/modules/asura-core/graphics/canvas.h index 4175561..5c11706 100644 --- a/source/modules/asura-core/graphics/canvas.h +++ b/source/modules/asura-core/graphics/canvas.h @@ -53,18 +53,14 @@ namespace AsuraEngine uint mWidth, mHeight; - public: - - //----------------------------------------------------------------------------// + luaxport: - LUAX_DECL_FACTORY(Canvas); + LUAX_DECL_FACTORY(Canvas, RenderTarget); LUAX_DECL_METHOD(_SetSize); LUAX_DECL_METHOD(_Bind); LUAX_DECL_METHOD(_Unbind); - //----------------------------------------------------------------------------// - }; /// diff --git a/source/modules/asura-core/graphics/color.h b/source/modules/asura-core/graphics/color.h index ababcf7..b29c43f 100644 --- a/source/modules/asura-core/graphics/color.h +++ b/source/modules/asura-core/graphics/color.h @@ -42,7 +42,7 @@ namespace AsuraEngine float r, g, b, a; - //----------------------------------------------------------------------------// + luaxport: LUAX_DECL_FACTORY(Color); @@ -61,8 +61,6 @@ namespace AsuraEngine LUAX_DECL_METHOD(___mul); // __mul LUAX_DECL_METHOD(___div); // __div - //----------------------------------------------------------------------------// - }; } diff --git a/source/modules/asura-core/graphics/color32.h b/source/modules/asura-core/graphics/color32.h index 5b10931..9f14155 100644 --- a/source/modules/asura-core/graphics/color32.h +++ b/source/modules/asura-core/graphics/color32.h @@ -20,8 +20,6 @@ namespace AsuraEngine { public: - LUAX_DECL_FACTORY(Color32); - static const uint32 RMASK; static const uint32 GMASK; static const uint32 BMASK; @@ -41,10 +39,12 @@ namespace AsuraEngine byte r, g, b, a; - LUAX_DECL_METHOD(_ToColor); + luaxport: - LUAX_DECL_METHOD(_SetColor); + LUAX_DECL_FACTORY(Color32); + LUAX_DECL_METHOD(_ToColor); + LUAX_DECL_METHOD(_SetColor); LUAX_DECL_METHOD(_GetColor); LUAX_DECL_METHOD(_GetRed); LUAX_DECL_METHOD(_GetGreen); diff --git a/source/modules/asura-core/graphics/gfx_device.cpp b/source/modules/asura-core/graphics/gfx_device.cpp index edfa784..c520127 100644 --- a/source/modules/asura-core/graphics/gfx_device.cpp +++ b/source/modules/asura-core/graphics/gfx_device.cpp @@ -32,6 +32,11 @@ namespace AsuraEngine { } + GfxDevice& GfxDevice::Get() + { + return gfx; + } + static bool inited = false; bool GfxDevice::Init(const AEMath::Recti& view) @@ -122,8 +127,6 @@ namespace AsuraEngine #endif } - //------------------------------------------------------------------------------// - void GfxDevice::SetMatrixMode(MatrixMode mode) { state.matrixMode = mode; @@ -191,7 +194,5 @@ namespace AsuraEngine return state.matrix[state.matrixMode].GetTopIndex(); } - //------------------------------------------------------------------------------// - - } -} \ No newline at end of file + } // Graphics +} // AsuraEngine \ No newline at end of file diff --git a/source/modules/asura-core/graphics/gfx_device.h b/source/modules/asura-core/graphics/gfx_device.h index c93717f..3c5b383 100644 --- a/source/modules/asura-core/graphics/gfx_device.h +++ b/source/modules/asura-core/graphics/gfx_device.h @@ -33,12 +33,6 @@ namespace AsuraEngine GL_PARAM_MAX_TEXTURE_UNIT = 1, }; - /// - /// OpenGL上下文,用来做一些opengl状态的追踪。在编辑器多窗口环境下,一个窗口对应一个hwnd, - /// 一个hdc,以及数个opengl context,如果使用wglMakeCurrent(hdc, glc)指定当前线程耳朵 - /// 渲染窗口hdc和opengl上下文glc,gl中记录的就是任意一个线程的任意一个窗口的任意一个OpenGL - /// 上下文的状态,不支持多上下文渲染。 - /// class GfxDevice : public AEScripting::Portable { public: @@ -46,6 +40,8 @@ namespace AsuraEngine GfxDevice(); ~GfxDevice(); + static GfxDevice& Get(); + int GetParam(GLParams param); bool Init(const AEMath::Recti& viewport); @@ -54,8 +50,8 @@ namespace AsuraEngine void SetViewport(const AEMath::Recti viewport); const AEMath::Recti& GetViewport(); - void UseShader(Shader* shader); - void UnuseShader(); + void UseShader(Shader* shader); + void UnuseShader(); Shader* GetShader(); void DrawArrays(GLenum mode, GLint first, GLsizei count); @@ -69,16 +65,16 @@ namespace AsuraEngine void Translate(float x, float y); void Scale(float x, float y); void Ortho(float l, float r, float b, float t, float n, float f); - AEMath::Matrix44& GetMatrix(MatrixMode mode); - AEMath::Matrix44 GetMVPMatrix(); uint GetMatrixDepth(); uint GetMatrixIndex(); + AEMath::Matrix44& GetMatrix(MatrixMode mode); + AEMath::Matrix44 GetMVPMatrix(); - void SetDrawColor(float r, float g, float b, float a); + void SetDrawColor(float r, float g, float b, float a); Color& GetDrawColor(); - void WipeError(); - bool HasError(); + void WipeError(); + bool HasError(); GLenum GetError(); struct @@ -103,7 +99,7 @@ namespace AsuraEngine friend class Profiler; - //----------------------------------------------------------------------------// + luaxport: LUAX_DECL_SINGLETON(GfxDevice); @@ -121,17 +117,12 @@ namespace AsuraEngine LUAX_DECL_METHOD(_Ortho); LUAX_DECL_METHOD(_GetMatrixDepth); LUAX_DECL_METHOD(_GetMatrixIndex); - LUAX_DECL_METHOD(_UseShader); LUAX_DECL_METHOD(_UnuseShader); - //----------------------------------------------------------------------------// - }; - /// - /// OpenGL单例。 - /// + // 全局gfx device单例 extern GfxDevice gfx; } diff --git a/source/modules/asura-core/graphics/gpu_buffer.cpp b/source/modules/asura-core/graphics/gpu_buffer.cpp index 4c84b7e..8d6f491 100644 --- a/source/modules/asura-core/graphics/gpu_buffer.cpp +++ b/source/modules/asura-core/graphics/gpu_buffer.cpp @@ -71,13 +71,12 @@ namespace AsuraEngine return false; if (mBuffer == 0) { - // 初始化 gfx.WipeError(); glGenBuffers(1, &mBuffer); if (mBuffer == 0) throw Exception("OpenGL glGenBuffers failed."); glBindBuffer(mTarget, mBuffer); - glBufferData(mTarget, mSize, NULL, mUsage); // 初始化大小为size的缓冲,并根据usage存放到对应显存区块 + glBufferData(mTarget, mSize, NULL, mUsage); if (gfx.HasError()) { glBindBuffer(mTarget, 0); @@ -98,7 +97,6 @@ namespace AsuraEngine } glBindBuffer(mTarget, 0); #if ASURA_DEBUG - // 拷贝一份,调试用 memcpy(mData + offset, data, size); #endif return true; diff --git a/source/modules/asura-core/graphics/gpu_buffer.h b/source/modules/asura-core/graphics/gpu_buffer.h index 9013619..f4f518f 100644 --- a/source/modules/asura-core/graphics/gpu_buffer.h +++ b/source/modules/asura-core/graphics/gpu_buffer.h @@ -44,44 +44,18 @@ namespace AsuraEngine static size_t GetDataTypeSize(GLenum datatype); - /// - /// 初始化\更新缓存,如果没有gpu buffer资源,认为是初始化,否则认为是更新。 - /// bool Fill(const void* data, size_t size, uint offset = 0) ASURA_THROW(Exception); - /// - /// 绑定到对应的目标上,接下来就可以使用了。 - /// void Bind(); void UnBind(); - /// - /// 获得buffer的大小(Byte) - /// uint GetBufferSize(); - /// - /// 获得buffer的元素个数=size/datatypesize - /// uint GetBufferCount(); GLenum GetDataType(); size_t GetDataTypeSize(); private: - //----------------------------------------------------------------------------// - - LUAX_DECL_ABSTRACT_FACTORY(GPUBuffer); - - LUAX_DECL_ENUM(BufferType, 1); - LUAX_DECL_ENUM(BufferUsage, 1); - LUAX_DECL_ENUM(BufferDataType, 2); - - LUAX_DECL_METHOD(_Fill); - LUAX_DECL_METHOD(_GetSize); - LUAX_DECL_METHOD(_GetCount); - - //----------------------------------------------------------------------------// - GLenum ConvertBufferType(BufferType type); GLenum ConvertBufferUsage(BufferUsage type); GLenum ConvertBufferDataType(BufferDataType type); @@ -99,12 +73,21 @@ namespace AsuraEngine uint mSize; #if ASURA_DEBUG - /// - /// 本地保存的buffer数据,和显存数据保持一致,用来调试和更新显存。 - /// byte* mData; #endif + luaxport: + + LUAX_DECL_ABSTRACT_FACTORY(GPUBuffer); + + LUAX_DECL_ENUM(BufferType, 1); + LUAX_DECL_ENUM(BufferUsage, 1); + LUAX_DECL_ENUM(BufferDataType, 2); + + LUAX_DECL_METHOD(_Fill); + LUAX_DECL_METHOD(_GetSize); + LUAX_DECL_METHOD(_GetCount); + }; } diff --git a/source/modules/asura-core/graphics/image.cpp b/source/modules/asura-core/graphics/image.cpp index 42fc2ab..ef01730 100644 --- a/source/modules/asura-core/graphics/image.cpp +++ b/source/modules/asura-core/graphics/image.cpp @@ -101,5 +101,5 @@ namespace AsuraEngine return mHeight; } - } -} \ No newline at end of file + } // Graphics +} // AsuraEngine \ No newline at end of file diff --git a/source/modules/asura-core/graphics/image.h b/source/modules/asura-core/graphics/image.h index 8e3e7d3..d7cd37f 100644 --- a/source/modules/asura-core/graphics/image.h +++ b/source/modules/asura-core/graphics/image.h @@ -24,40 +24,26 @@ namespace AsuraEngine namespace Graphics { - /// - /// Image是图片从内存中载入后,读取进游戏后保存的结果。一个Image在内存、显存中只会保存一 - /// 份,不会产生副本。需要特征化的区别image,如锚点位置,缩放和旋转角度,使用sprite。 - /// 是一个只读类。主要是考虑到editor和engine使用不同的封装。Image只提供渲染时需要的 - /// sampler2D,顶点数据严格来说和Image无关,不应该由Image类提供。在Framework中,真正的 - /// 渲染实体是sprite,sprite提供了顶点数据和仿射变换参数。 - /// - class Image ASURA_FINAL - : public AEScripting::Portable + class Image ASURA_FINAL : public AEScripting::Portable { public: Image(); - ~Image(); - /// - /// 将解析后的图像数据提交到GPU,更新像素信息。用来重新构建image,使用glTexImage2D重 - /// 新提交image的像素数据。 - /// bool Load(AEImage::ImageData* decodeData); bool Load(AEImage::ImageData* decodeData, const AEMath::Vector2i& pos); uint GetWidth(); uint GetHeight(); - /// - /// 创建一个gpu buffer,填充顶点的position数据和UV数据. - /// GPUBuffer* GenGPUBuffer(); private: - //----------------------------------------------------------------------------// + uint32 mWidth, mHeight; + + luaxport: LUAX_DECL_FACTORY(Image, Texture); @@ -69,18 +55,10 @@ namespace AsuraEngine LUAX_DECL_METHOD(_GetPixel); LUAX_DECL_METHOD(_Render); - //----------------------------------------------------------------------------// - - uint32 mWidth, mHeight; - -#if ASURA_EDITOR - -#endif - }; - } -} + } // Graphics +} // AsuraEngine namespace AEGraphics = AsuraEngine::Graphics; diff --git a/source/modules/asura-core/graphics/index_buffer.h b/source/modules/asura-core/graphics/index_buffer.h index ac77162..c5d2e9e 100644 --- a/source/modules/asura-core/graphics/index_buffer.h +++ b/source/modules/asura-core/graphics/index_buffer.h @@ -24,6 +24,8 @@ namespace AsuraEngine private: + luaxport: + LUAX_DECL_FACTORY(IndexBuffer); LUAX_DECL_METHOD(_New); diff --git a/source/modules/asura-core/graphics/matrix_stack.h b/source/modules/asura-core/graphics/matrix_stack.h index 1a318fa..ae983e7 100644 --- a/source/modules/asura-core/graphics/matrix_stack.h +++ b/source/modules/asura-core/graphics/matrix_stack.h @@ -27,9 +27,6 @@ namespace AsuraEngine MatrixStack(); ~MatrixStack(); - /// - /// 对栈顶元素的操作只能通过以下函数实现 - /// void LoadIdentity(); bool Push(); bool Pop(); @@ -40,39 +37,19 @@ namespace AsuraEngine void LoadMatrix(const AEMath::Matrix44& mat44); void MultMatrix(const AEMath::Matrix44& mat44); - /// - /// 仿射变换 - /// void Rotate(float angle); void Translate(float x, float y); void Scale(float x, float y); - /// - /// 投影变换 - /// 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); - /// - /// 获得栈顶的索引,范围在0~ASURA_MAX_MATRIX_STACK_DEPTH-1 - /// uint GetTopIndex(); - - /// - /// 获得最大栈容量,即ASURA_MAX_MATRIX_STACK_DEPTH - /// uint GetCapacity(); private: AEMath::Matrix44 mStack[ASURA_MAX_MATRIX_STACK_DEPTH]; - - /// - /// 栈顶索引,0~ASURA_MAX_MATRIX_STACK_DEPTH-1 - /// - uint8 top; + uint8 top; }; diff --git a/source/modules/asura-core/graphics/mesh2d.h b/source/modules/asura-core/graphics/mesh2d.h index f2770e1..5330967 100644 --- a/source/modules/asura-core/graphics/mesh2d.h +++ b/source/modules/asura-core/graphics/mesh2d.h @@ -37,15 +37,14 @@ namespace AsuraEngine private: + VertexBuffer* mVBO; ///< vertex buffer + IndexBuffer* mIBO; ///< index buffer + + luaxport: + LUAX_DECL_FACTORY(Mesh2D); LUAX_DECL_METHOD(_SetVertex); - - /// - /// 从mesh2d data中构建的vertex buffer和index buffer - /// - VertexBuffer* mVBO; - IndexBuffer* mIBO; }; diff --git a/source/modules/asura-core/graphics/shader.h b/source/modules/asura-core/graphics/shader.h index f4553ec..61aa6f1 100644 --- a/source/modules/asura-core/graphics/shader.h +++ b/source/modules/asura-core/graphics/shader.h @@ -71,7 +71,17 @@ namespace AsuraEngine private: - //----------------------------------------------------------------------------// + bool CompileVertexShader(const std::string& vert, std::string& outError); + bool CompileFragementShader(const std::string& frag, std::string& outError); + + std::string GetProgramWarnings(); + std::string GetShaderWarnings(GLuint shader); + + GLuint mProgram; + GLuint mVertShader; + GLuint mFragShader; + + luaxport: LUAX_DECL_FACTORY(Shader); @@ -93,20 +103,9 @@ namespace AsuraEngine LUAX_DECL_METHOD(_SetBuiltInUniforms); - //----------------------------------------------------------------------------// - - bool CompileVertexShader(const std::string& vert, std::string& outError); - bool CompileFragementShader(const std::string& frag, std::string& outError); - - std::string GetProgramWarnings(); - std::string GetShaderWarnings(GLuint shader); - - GLuint mProgram; - GLuint mVertShader; - GLuint mFragShader; - }; + // 别名,用于表明这是一个GPU程序 typedef Shader GpuProgram; } diff --git a/source/modules/asura-core/graphics/sprite_batch.h b/source/modules/asura-core/graphics/sprite_batch.h index 17ecb40..b517334 100644 --- a/source/modules/asura-core/graphics/sprite_batch.h +++ b/source/modules/asura-core/graphics/sprite_batch.h @@ -24,9 +24,9 @@ namespace AsuraEngine private: - LUAX_DECL_FACTORY(SpriteBatch); - + luaxport: + LUAX_DECL_FACTORY(SpriteBatch); }; diff --git a/source/modules/asura-core/graphics/texture.h b/source/modules/asura-core/graphics/texture.h index 799227e..7cfddec 100644 --- a/source/modules/asura-core/graphics/texture.h +++ b/source/modules/asura-core/graphics/texture.h @@ -46,10 +46,10 @@ namespace AsuraEngine /// struct TextureFormat { - GLenum internalformat; // GPU内部格式 + GLenum internalformat; ///< GPU内部格式 - GLenum externalformat; // CPU外部格式 - GLenum type; // 外部格式每个channel数值类型 + GLenum externalformat; ///< CPU外部格式 + GLenum type; ///< 外部格式每个channel数值类型 }; /// @@ -81,42 +81,30 @@ namespace AsuraEngine protected: - //----------------------------------------------------------------------------// - - LUAX_DECL_ENUM(ColorFormat, 1); - LUAX_DECL_ENUM(FilterMode, 1); - LUAX_DECL_ENUM(WrapMode, 1); - - LUAX_DECL_METHOD(_SetFilterMode); - LUAX_DECL_METHOD(_SetWrapMode); - LUAX_DECL_METHOD(_GetFilterMode); - LUAX_DECL_METHOD(_GetWrapMode); - LUAX_DECL_METHOD(_IsGenMipmap); - - //----------------------------------------------------------------------------// - /// /// 转换color format为texture format。 /// TextureFormat ConvertColorFormat(const ColorFormat& colorformat); - //----------------------------------------------------------------------------// - - /// - /// OpenGL纹理名 - /// GLuint mTex; - FilterMode mMinFilter; FilterMode mMagFilter; - WrapMode mWrapMode; - bool mIsGenMipmap; + LUAX_DECL_ENUM(ColorFormat, 1); + LUAX_DECL_ENUM(FilterMode, 1); + LUAX_DECL_ENUM(WrapMode, 1); + + LUAX_DECL_METHOD(_SetFilterMode); + LUAX_DECL_METHOD(_SetWrapMode); + LUAX_DECL_METHOD(_GetFilterMode); + LUAX_DECL_METHOD(_GetWrapMode); + LUAX_DECL_METHOD(_IsGenMipmap); + }; - using Drawable = Texture; + typedef Texture Drawable; } } diff --git a/source/modules/asura-core/graphics/vertex_buffer.h b/source/modules/asura-core/graphics/vertex_buffer.h index b078c2b..7aad27d 100644 --- a/source/modules/asura-core/graphics/vertex_buffer.h +++ b/source/modules/asura-core/graphics/vertex_buffer.h @@ -25,6 +25,8 @@ namespace AsuraEngine private: + luaxport: + LUAX_DECL_FACTORY(VertexBuffer); LUAX_DECL_METHOD(_New); diff --git a/source/modules/asura-core/image/image_data.h b/source/modules/asura-core/image/image_data.h index c377407..ca459e7 100644 --- a/source/modules/asura-core/image/image_data.h +++ b/source/modules/asura-core/image/image_data.h @@ -49,7 +49,17 @@ namespace AsuraEngine private: - //----------------------------------------------------------------------------// + /// + /// 在第一次准备image data时构建所有提供的decoder。在几个decoders中间选择解析策略。 + /// + static std::list ImageDecoders; + + /// + /// 写数据的锁。 + /// + AEThreading::Mutex mMutex; + + luaxport: LUAX_DECL_FACTORY(ImageData); @@ -63,18 +73,6 @@ namespace AsuraEngine LUAX_DECL_METHOD(_DecodeAsync); LUAX_DECL_METHOD(_IsAvailable); - //----------------------------------------------------------------------------// - - /// - /// 在第一次准备image data时构建所有提供的decoder。在几个decoders中间选择解析策略。 - /// - static std::list ImageDecoders; - - /// - /// 写数据的锁。 - /// - AEThreading::Mutex mMutex; - }; } diff --git a/source/modules/asura-core/image/image_decode_task.h b/source/modules/asura-core/image/image_decode_task.h index fc695fa..5108c23 100644 --- a/source/modules/asura-core/image/image_decode_task.h +++ b/source/modules/asura-core/image/image_decode_task.h @@ -24,7 +24,7 @@ namespace AsuraEngine /// void Invoke(lua_State* invokeThreaad) override; - private: + luaxport: LUAX_DECL_FACTORY(ImageDecodeTask, AEThreading::Task); diff --git a/source/modules/asura-core/input/clipboard.h b/source/modules/asura-core/input/clipboard.h index b3b9a1a..1b7c2b8 100644 --- a/source/modules/asura-core/input/clipboard.h +++ b/source/modules/asura-core/input/clipboard.h @@ -19,16 +19,14 @@ namespace AsuraEngine void SetString(const Text::String& text); - //----------------------------------------------------------------------------// - - LUAX_DECL_SINGLETON(Clipboard); - - //----------------------------------------------------------------------------// - private: ~Clipboard(); + luaxport: + + LUAX_DECL_SINGLETON(Clipboard); + }; }; diff --git a/source/modules/asura-core/input/cursor.h b/source/modules/asura-core/input/cursor.h index d420d66..e3df7ee 100644 --- a/source/modules/asura-core/input/cursor.h +++ b/source/modules/asura-core/input/cursor.h @@ -49,8 +49,6 @@ namespace AsuraEngine { public: - LUAX_DECL_FACTORY(Cursor); - Cursor(Graphics::ImageData& imageData, int hotx, int hoty); Cursor(SystemCursor cursortype); @@ -66,6 +64,10 @@ namespace AsuraEngine SystemCursor mSystemType; CursorImpl* mImpl; + luaxport: + + LUAX_DECL_FACTORY(Cursor); + }; ASURA_ABSTRACT class CursorImpl -- cgit v1.1-26-g67d0