From e47baca4f23db43ec91fbf64d5d06d7c0dbee495 Mon Sep 17 00:00:00 2001 From: chai Date: Sat, 6 Apr 2019 07:39:49 +0800 Subject: *misc --- source/3rd-party/Luax/luax_class.hpp | 42 ++++----- source/3rd-party/Luax/luax_class.inl | 9 +- source/3rd-party/Luax/luax_dog.cpp | 0 source/3rd-party/Luax/luax_dog.h | 33 -------- source/3rd-party/Luax/luax_watchdog.cpp | 0 source/3rd-party/Luax/luax_watchdog.h | 33 ++++++++ source/Asura.Editor/config.h | 0 source/Asura.Editor/core/slot.h | 2 +- source/Asura.Editor/editor.h | 9 +- source/Asura.Editor/system/window.cpp | 13 +++ source/Asura.Editor/system/window.h | 82 ++++++++++++++++++ source/Asura.Editor/type.h | 30 +++++++ .../libs/asura-lib-utils/profiler/memory_leak.cpp | 0 source/libs/asura-lib-utils/profiler/memory_leak.h | 0 source/modules/asura-core/core_config.h | 5 ++ .../modules/asura-core/graphics/binding/_image.cpp | 2 +- source/modules/asura-core/graphics/canvas.h | 15 ++-- source/modules/asura-core/graphics/gl.cpp | 30 ++++++- source/modules/asura-core/graphics/gl.h | 22 ++++- source/modules/asura-core/graphics/gpu_buffer.cpp | 94 ++++++++++++++++++++ source/modules/asura-core/graphics/gpu_buffer.h | 69 +++++++++++++++ source/modules/asura-core/graphics/image.cpp | 10 +-- source/modules/asura-core/graphics/image.h | 15 ++-- source/modules/asura-core/graphics/matrix_stack.h | 2 +- source/modules/asura-core/graphics/render_target.h | 2 +- source/modules/asura-core/graphics/shader.cpp | 99 ++++++++++++---------- source/modules/asura-core/graphics/shader.h | 52 +++--------- source/modules/asura-core/graphics/shader_source.h | 39 --------- source/modules/asura-core/graphics/sprite_batch.h | 10 ++- source/modules/asura-core/graphics/texture.h | 7 +- source/modules/asura-core/image/image_data.h | 8 +- .../modules/asura-core/image/image_decode_task.h | 3 +- source/modules/asura-core/window/window.cpp | 12 +-- source/modules/asura-core/window/window.h | 3 +- source/modules/asura-utils/io/binding/_file.cpp | 2 +- .../asura-utils/io/binding/_file_system.cpp | 4 +- source/modules/asura-utils/io/decoded_data.h | 1 + source/modules/asura-utils/io/file.cpp | 8 +- source/modules/asura-utils/io/file.h | 12 +-- source/modules/asura-utils/io/file_data.h | 2 +- source/modules/asura-utils/io/file_system.cpp | 8 +- source/modules/asura-utils/io/file_system.h | 10 +-- source/modules/asura-utils/io/renewable.h | 9 -- source/modules/asura-utils/math/matrix44.h | 2 + source/modules/asura-utils/scripting/portable.hpp | 3 +- source/modules/asura-utils/type.h | 6 +- source/tests/win32/01-window/03_sub_menu.cpp | 12 +-- 47 files changed, 561 insertions(+), 270 deletions(-) delete mode 100644 source/3rd-party/Luax/luax_dog.cpp delete mode 100644 source/3rd-party/Luax/luax_dog.h create mode 100644 source/3rd-party/Luax/luax_watchdog.cpp create mode 100644 source/3rd-party/Luax/luax_watchdog.h create mode 100644 source/Asura.Editor/config.h create mode 100644 source/Asura.Editor/system/window.cpp create mode 100644 source/Asura.Editor/system/window.h create mode 100644 source/Asura.Editor/type.h create mode 100644 source/libs/asura-lib-utils/profiler/memory_leak.cpp create mode 100644 source/libs/asura-lib-utils/profiler/memory_leak.h create mode 100644 source/modules/asura-core/graphics/gpu_buffer.cpp create mode 100644 source/modules/asura-core/graphics/gpu_buffer.h delete mode 100644 source/modules/asura-core/graphics/shader_source.h (limited to 'source') diff --git a/source/3rd-party/Luax/luax_class.hpp b/source/3rd-party/Luax/luax_class.hpp index c41adbd..e6e0696 100644 --- a/source/3rd-party/Luax/luax_class.hpp +++ b/source/3rd-party/Luax/luax_class.hpp @@ -12,7 +12,7 @@ #include "luax_ref.h" #include "luax_memberref.h" #include "luax_cfunctions.h" -#include "luax_dog.h" +#include "luax_watchdog.h" namespace Luax { @@ -24,8 +24,9 @@ namespace Luax /// LuaxGetFactoryName 获得工厂的类名,同时用来避免注册时错误注册为了singleton,通过编译 /// 时报错避免 /// -#define LUAX_DECL_FACTORY(type) \ +#define LUAX_DECL_FACTORY(type, ...) \ friend class Luax::LuaxState; \ + friend class Luax::LuaxNativeClass; \ static void RegisterLuaxClass(Luax::LuaxState&); \ static void RegisterLuaxPostprocess(Luax::LuaxState&); \ static const char* GetLuaxFactoryName() { return #type; };\ @@ -44,8 +45,9 @@ namespace Luax /// RegisterLuaxClass 注册类的方法和成员,比如枚举、常量等到class table /// LuaxGetSingletonName 获得单例的类名 /// -#define LUAX_DECL_SINGLETON(type) \ +#define LUAX_DECL_SINGLETON(type, ...) \ friend class Luax::LuaxState; \ + friend class Luax::LuaxNativeClass; \ static void RegisterLuaxClass(Luax::LuaxState&); \ static void RegisterLuaxPostprocess(Luax::LuaxState&); \ static const char* GetLuaxSingletonName() { return #type; }; \ @@ -114,13 +116,14 @@ namespace Luax virtual bool PushLuaxRefTable(LuaxState& state) = 0; /// - /// 被LuaxNativeClass实现。 + /// 被LuaxNativeClass实现。保持和释放native资源。 /// virtual void Retain() = 0; virtual void Release() = 0; }; + // TODO: 将公共部分提取出来,不要重复生成代码 //class LuaxNativeClassBase //{ //} @@ -139,12 +142,12 @@ namespace Luax /// 相比较member ref,这个用在实体会被多次被不同其他实体引用的情况,并频繁销毁这些实体, /// 避免lua频繁的调用gc检测。 /// - template void LuaxRetain(LuaxState& state, USERDATA* userdata); + template void LuaxRetain(LuaxState& state, DATATYPE* userdata); /// /// 对userdata减少一个引用在ref table里,以尝试回收userdata。 /// - template void LuaxRelease(LuaxState& state, USERDATA* userdata); + template void LuaxRelease(LuaxState& state, DATATYPE* userdata); /// /// 将userdata push到栈顶,如果没有初始化mUserdata,初始化设置好元表并把初始化好的 @@ -162,8 +165,8 @@ namespace Luax /// /// 这两个函数是native接口。 /// - void Retain() override; - void Release() override; + void Retain() override final; + void Release() override final; #if LUAX_PROFILER // 对堆上创建的实例进行delete保险检查 @@ -201,21 +204,18 @@ namespace Luax //------------------------------------------------------------------------------// // 公共内容 - LUAX_DECL_METHOD(__tostring); - LUAX_DECL_METHOD(_GetClass); - LUAX_DECL_METHOD(_GetClassName); - + static int __tostring (lua_State*); + static int _GetClass (lua_State*); + static int _GetClassName (lua_State*); + // 工厂类相关 - LUAX_DECL_METHOD(__gc); -#if LUAX_ENABLE_NATIVE_EXTEND - LUAX_DECL_METHOD(_ExtendFactory); -#endif - LUAX_DECL_METHOD(_GetRefTable); - LUAX_DECL_METHOD(_New); + static int __gc (lua_State*); + static int _GetRefTable (lua_State*); + static int _New (lua_State*); - // 单例类相关 #if LUAX_ENABLE_NATIVE_EXTEND - LUAX_DECL_METHOD(_ExtendSingleton); + static int _ExtendFactory (lua_State*); + static int _ExtendSingleton (lua_State*); #endif //--------------------------------------------------------------------------------// @@ -244,7 +244,7 @@ namespace Luax /// /// 通过后才能删除 /// - LuaxDog mWatchDog; + LuaxWatchDog mWatchDog; #if LUAX_PROFILER // 托管此对象的虚拟机 diff --git a/source/3rd-party/Luax/luax_class.inl b/source/3rd-party/Luax/luax_class.inl index 95965ff..1d6a89f 100644 --- a/source/3rd-party/Luax/luax_class.inl +++ b/source/3rd-party/Luax/luax_class.inl @@ -95,7 +95,7 @@ namespace Luax if (pdead == nullptr) return; // 堆上创建的实例必须使用Release释放。 - LuaxNativeClass* p = static_cast(pdead); + TYPE* p = static_cast(pdead); assert(p->mSafer); ::operator delete(pdead, size); } @@ -384,6 +384,7 @@ namespace Luax int LuaxNativeClass::__gc(lua_State* L) { LUAX_STATE(L); + TYPE* self = state.GetUserdata(1); assert(self); @@ -391,8 +392,10 @@ namespace Luax std::cout << "Luax: GC<" << TYPE::GetLuaxClassName() << ">\n"; #endif - --self->mWatchDog.mVMRef; - self->LuaxNativeClass::Release(); + if(self->mWatchDog.mVMRef > 0) + --self->mWatchDog.mVMRef; + + self->Release(); return 0; } diff --git a/source/3rd-party/Luax/luax_dog.cpp b/source/3rd-party/Luax/luax_dog.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/source/3rd-party/Luax/luax_dog.h b/source/3rd-party/Luax/luax_dog.h deleted file mode 100644 index f6d95d5..0000000 --- a/source/3rd-party/Luax/luax_dog.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef __LUAX_DOG_H__ -#define __LUAX_DOG_H__ - -#include "luax_config.h" - -namespace Luax -{ - - /// - /// LuaxNativeClass实例的引用计数额watch dog,只有在watch dog通过时才可以delete。 - /// - class LuaxDog - { - public: - LuaxDog() - : mVMRef(0) - , mNativeRef(0) - { - } - - inline operator bool() - { - return mVMRef == 0 && mNativeRef == 0; - } - - uint mVMRef; // 托管给的虚拟机数 - uint mNativeRef; // 本地引用数 - - }; - -} - -#endif \ No newline at end of file diff --git a/source/3rd-party/Luax/luax_watchdog.cpp b/source/3rd-party/Luax/luax_watchdog.cpp new file mode 100644 index 0000000..e69de29 diff --git a/source/3rd-party/Luax/luax_watchdog.h b/source/3rd-party/Luax/luax_watchdog.h new file mode 100644 index 0000000..b07b007 --- /dev/null +++ b/source/3rd-party/Luax/luax_watchdog.h @@ -0,0 +1,33 @@ +#ifndef __LUAX_DOG_H__ +#define __LUAX_DOG_H__ + +#include "luax_config.h" + +namespace Luax +{ + + /// + /// LuaxNativeClass实例的引用计数额watch dog,只有在watch dog通过时才可以delete。 + /// + class LuaxWatchDog + { + public: + LuaxWatchDog() + : mVMRef(0) + , mNativeRef(0) + { + } + + inline operator bool() + { + return mVMRef == 0 && mNativeRef == 0; + } + + uint mVMRef; // 托管给的虚拟机数 + uint mNativeRef; // 本地引用数 + + }; + +} + +#endif \ No newline at end of file diff --git a/source/Asura.Editor/config.h b/source/Asura.Editor/config.h new file mode 100644 index 0000000..e69de29 diff --git a/source/Asura.Editor/core/slot.h b/source/Asura.Editor/core/slot.h index b62f406..f569cfe 100644 --- a/source/Asura.Editor/core/slot.h +++ b/source/Asura.Editor/core/slot.h @@ -4,7 +4,7 @@ #include #include -#include "../widgets/widget.h" +#include "../controls/widget.h" namespace AsuraEditor { diff --git a/source/Asura.Editor/editor.h b/source/Asura.Editor/editor.h index b086532..fbcfb62 100644 --- a/source/Asura.Editor/editor.h +++ b/source/Asura.Editor/editor.h @@ -21,9 +21,14 @@ namespace AsuraEditor private: /// - /// 界面和逻辑运行的state。 + /// 界面和逻辑运行的虚拟机。 /// - lua_State* mMainState; + Luax::LuaxVM* mEditorVM; + + /// + /// 游戏运行时的虚拟机。 + /// + Luax::LuaxVM* mRunnerVM; }; diff --git a/source/Asura.Editor/system/window.cpp b/source/Asura.Editor/system/window.cpp new file mode 100644 index 0000000..440c88c --- /dev/null +++ b/source/Asura.Editor/system/window.cpp @@ -0,0 +1,13 @@ +#include "window.h" + +namespace AsuraEditor +{ + + bool Window::Init(int posx, uint posy, uint w, uint h) + { + if (mHWND) + return false; + + } + +} \ No newline at end of file diff --git a/source/Asura.Editor/system/window.h b/source/Asura.Editor/system/window.h new file mode 100644 index 0000000..c9837e3 --- /dev/null +++ b/source/Asura.Editor/system/window.h @@ -0,0 +1,82 @@ +#ifndef __ASURA_EDITOR_WINDOW_H__ +#define __ASURA_EDITOR_WINDOW_H__ + +#include +#include + +#include + +#include "../type.h" + +namespace AsuraEditor +{ + + /// + /// 窗口风格,只指明了框架的风格,具体的控件由应用程序绘制。 + /// + enum WindowStyle + { + WINDOW_STYLE_BASIC, ///< 基础风格 + WINDOW_STYLE_TOOL, ///< 工具栏风格 + WINDOW_STYLE_CONFIRM, ///< 确认窗口 + }; + + /// + /// 创建窗口时需要的配置项。 + /// + struct WindowConfig + { + std::string title; ///< 标题 + uint x, y; ///< 坐标 + uint width, height; ///< 大小 + WindowStyle style; ///< 风格 + }; + + /// + /// 编辑器创建的win32窗口,每一个窗口包含一个HWND和一个HDC + /// + class Window + : public AEScripting::Portable + { + public: + + Window(); + ~Window(); + + bool Init(WindowConfig& config); + + private: + + //------------------------------------------------------------------------------// + + LUAX_DECL_FACTORY(Window); + + LUAX_DECL_ENUM(WindowStyle); + + LUAX_DECL_METHOD(_New); + LUAX_DECL_METHOD(_Init); + LUAX_DECL_METHOD(_SetPosition); + + //------------------------------------------------------------------------------// + + /// + /// 父窗口。 + /// + Window* mParent; + + /// + /// 窗口句柄和设备上下文。 + /// + HWND mHWND; + HDC mHDC; + + /// + /// 窗口风格。 + /// + WindowStyle mStyle; + + }; + +} + +#endif \ No newline at end of file diff --git a/source/Asura.Editor/type.h b/source/Asura.Editor/type.h new file mode 100644 index 0000000..d58cf87 --- /dev/null +++ b/source/Asura.Editor/type.h @@ -0,0 +1,30 @@ +#ifndef __ASURA_EDITOR_TYPE_H__ +#define __ASURA_EDITOR_TYPE_H__ + +#include +#include + +namespace AsuraEditor +{ + + typedef int8_t int8; + typedef uint8_t uint8; + //typedef uint8 byte; + typedef char byte; + typedef int16_t int16; + typedef uint16_t uint16; + typedef int32_t int32; + typedef uint32_t uint32; + typedef int64_t int64; + typedef uint64_t uint64; + + typedef uint32_t uint; + typedef int32_t sint; + + typedef std::size_t size_t; + + typedef const char cc8; + +} + +#endif \ No newline at end of file diff --git a/source/libs/asura-lib-utils/profiler/memory_leak.cpp b/source/libs/asura-lib-utils/profiler/memory_leak.cpp new file mode 100644 index 0000000..e69de29 diff --git a/source/libs/asura-lib-utils/profiler/memory_leak.h b/source/libs/asura-lib-utils/profiler/memory_leak.h new file mode 100644 index 0000000..e69de29 diff --git a/source/modules/asura-core/core_config.h b/source/modules/asura-core/core_config.h index 2286189..717f254 100644 --- a/source/modules/asura-core/core_config.h +++ b/source/modules/asura-core/core_config.h @@ -3,4 +3,9 @@ #define ASURA_WINDOW_SDL 1 +#define ASURA_OPENGL_GLAD (1 << 1) +#define ASURA_OPENGL_GLEE (1 << 2) +#define ASURA_OPENGL_GLUT (1 << 3) +#define ASURA_OPENGL_LOADER (ASURA_OPENGL_GLAD|ASURA_OPENGL_GLEE|ASURA_OPENGL_GLUT) + #endif \ No newline at end of file diff --git a/source/modules/asura-core/graphics/binding/_image.cpp b/source/modules/asura-core/graphics/binding/_image.cpp index 6179706..76ac635 100644 --- a/source/modules/asura-core/graphics/binding/_image.cpp +++ b/source/modules/asura-core/graphics/binding/_image.cpp @@ -39,7 +39,7 @@ namespace AsuraEngine { LUAX_PREPARE(L, Image); ImageData* imgData = state.CheckUserdata(2); - state.Push(self->Update(imgData)); + state.Push(self->Load(imgData)); return 1; } diff --git a/source/modules/asura-core/graphics/canvas.h b/source/modules/asura-core/graphics/canvas.h index 6af81d7..555ce5d 100644 --- a/source/modules/asura-core/graphics/canvas.h +++ b/source/modules/asura-core/graphics/canvas.h @@ -20,9 +20,7 @@ namespace AsuraEngine /// Canvas也可以称为render texture,自身也可以作为texture渲染。 /// class Canvas ASURA_FINAL - : public Drawable - , public RenderTarget - , public Scripting::Portable + : public Scripting::Portable { public: @@ -33,12 +31,12 @@ namespace AsuraEngine /// /// 设置render texture的大小 /// - void SetSize(uint w, uint h) asura_throw(Exception); + void SetSize(uint w, uint h) ASURA_THROW(Exception); void Clear(const Color& col = Color::Black) override; - +/* void Clear(const Math::Recti& quad, const Color& col = Color::Black) override; - +*/ void Render(const RenderTarget* rt, const Math::Vector2i& pos, const Math::Vector2i& scale, const Math::Vector2i& center, float rot); void Render(const RenderTarget* rt, const Math::Rectf& quad, const Math::Vector2i& pos, const Math::Vector2i& scale, const Math::Vector2i& center, float rot); @@ -54,6 +52,11 @@ namespace AsuraEngine /// GLuint mFBO; + /// + /// 绑定的tex + /// + GLuint mTex; + /// /// canvas的大小 /// diff --git a/source/modules/asura-core/graphics/gl.cpp b/source/modules/asura-core/graphics/gl.cpp index 47476a7..54fadb7 100644 --- a/source/modules/asura-core/graphics/gl.cpp +++ b/source/modules/asura-core/graphics/gl.cpp @@ -30,13 +30,41 @@ namespace AsuraEngine { } + bool OpenGL::Init(const AEMath::Recti& view) + { + bool loaded = false; +#if ASURA_OPENGL_LOADER & ASURA_OPENGL_GLAD + if (!loaded) + loaded = gladLoadGL(); +#endif + if (!loaded) + return false; + state.viewport = view; + return true; + } + + void OpenGL::WipeError() + { + while (glGetError() != GL_NO_ERROR); + } + + bool OpenGL::HasError() + { + return glGetError() != GL_NO_ERROR; + } + + GLenum OpenGL::GetError() + { + return glGetError(); + } + void OpenGL::SetViewport(const Recti v) { glViewport(v.x, v.y, v.w, v.h); state.viewport = v; } - Recti OpenGL::GetViewport() + const Recti& OpenGL::GetViewport() { return state.viewport; } diff --git a/source/modules/asura-core/graphics/gl.h b/source/modules/asura-core/graphics/gl.h index 6838bc9..e3c2ffc 100644 --- a/source/modules/asura-core/graphics/gl.h +++ b/source/modules/asura-core/graphics/gl.h @@ -18,6 +18,7 @@ namespace AsuraEngine class Profiler; class Shader; + class GPUBuffer; enum MatrixMode { @@ -35,17 +36,23 @@ namespace AsuraEngine { public: - LUAX_DECL_SINGLETON(GL); - OpenGL(); ~OpenGL(); + /// + /// 初始化OpenGL上下文参数,发生在创建OpenGL上下文之后。此函数会注册OpenGL函数的地址。 + /// + bool Init(const AEMath::Recti& viewport); + void SetViewport(const AEMath::Recti viewport); - AEMath::Recti GetViewport(); + const AEMath::Recti& GetViewport(); void UseShader(Shader* shader); void UnuseShader(); + /// + /// Matrix stack相关操作 + /// void SetMatrixMode(MatrixMode mode); MatrixMode GetMatrixMode(); void PushMatrix(); @@ -59,6 +66,13 @@ namespace AsuraEngine uint GetMatrixDepth(); uint GetMatrixIndex(); + /// + /// 清理错误提示 + /// + void WipeError(); + bool HasError(); + GLenum GetError(); + /// /// OpenGL3.0以后由用户管理矩阵变换、视口、shader等参数,这里保存一些OpenGL状态。注意 /// 似乎全进程的,也就是说,Asura不支持多线程渲染。OpenGL上下文的创建使得一个上下 @@ -78,6 +92,8 @@ namespace AsuraEngine friend class Profiler; + LUAX_DECL_SINGLETON(OpenGL); + //----------------------------------------------------------------------------// LUAX_DECL_ENUM(MatrixMode, 0); diff --git a/source/modules/asura-core/graphics/gpu_buffer.cpp b/source/modules/asura-core/graphics/gpu_buffer.cpp new file mode 100644 index 0000000..c796bb0 --- /dev/null +++ b/source/modules/asura-core/graphics/gpu_buffer.cpp @@ -0,0 +1,94 @@ +#include "gpu_buffer.h" + +namespace AsuraEngine +{ + namespace Graphics + { + + GPUBuffer::GPUBuffer(BufferType type, BufferUsage usage, size_t size) + : mTarget(GL_ZERO) + , mBuffer(GL_ZERO) + , mSize(0) +#if ASURA_DEBUG + , mData(nullptr) +#endif + { + switch (type) + { + case BUFFER_TYPE_VERTEX: + mTarget = GL_ARRAY_BUFFER; + break; + case BUFFER_TYPE_INDEX: + mTarget = GL_ELEMENT_ARRAY_BUFFER; + break; + } + switch (usage) + { + case BUFFER_USAGE_STREAM: + mUsage = GL_STREAM_DRAW; + break; + case BUFFER_USAGE_DYNAMIC: + mUsage = GL_DYNAMIC_DRAW; + break; + case BUFFER_USAGE_STATIC: + mUsage = GL_STATIC_DRAW; + break; + } + gl.WipeError(); + glGenBuffers(1, &mBuffer); + if (mBuffer == 0) + throw Exception("OpenGL glGenBuffers failed."); + glBindBuffer(mTarget, mBuffer); + glBufferData(mTarget, size, NULL, mUsage); // 初始化大小为size的缓冲 + if (gl.HasError()) + throw Exception("OpenGL glBufferData failed. Errorcode=%d.", gl.GetError()); + glBindBuffer(mTarget, 0); +#if ASURA_DEBUG + mData = (byte*)malloc(size); + memset(mData, 0, size); +#endif + mSize = size; + } + + GPUBuffer::~GPUBuffer() + { +#if ASURA_DEBUG + if (mData) + free(mData); +#endif + glDeleteBuffers(1, &mBuffer); + } + + bool GPUBuffer::Fill(const void * data, size_t size, uint offset) + { + if (data == nullptr) + return false; + glBindBuffer(mTarget, mBuffer); + glBufferSubData(mTarget, offset, size, data); + if (gl.HasError()) + throw Exception("OpenGL glBufferSubData failed. Errorcode=%d.", gl.GetError()); + glBindBuffer(mTarget, 0); +#if ASURA_DEBUG + // 拷贝一份,调试用 + memcpy(mData + offset, data, size); +#endif + return true; + } + + void GPUBuffer::Bind() + { + glBindBuffer(mTarget, mBuffer); + } + + void GPUBuffer::UnBind() + { + glBindBuffer(mTarget, 0); + } + + uint GPUBuffer::GetBufferSize() + { + return mSize; + } + + } +} \ No newline at end of file diff --git a/source/modules/asura-core/graphics/gpu_buffer.h b/source/modules/asura-core/graphics/gpu_buffer.h new file mode 100644 index 0000000..aba1157 --- /dev/null +++ b/source/modules/asura-core/graphics/gpu_buffer.h @@ -0,0 +1,69 @@ +#ifndef __ASURA_GPU_BUFFER_H__ +#define __ASURA_GPU_BUFFER_H__ + +#include +#include + +#include "gl.h" + +namespace AsuraEngine +{ + namespace Graphics + { + + enum BufferType + { + BUFFER_TYPE_VERTEX, ///< 顶点缓冲 + BUFFER_TYPE_INDEX, ///< 索引缓冲 + }; + + enum BufferUsage + { + BUFFER_USAGE_STREAM, ///< 修改一次,使用次数低 + BUFFER_USAGE_DYNAMIC, ///< 修改一次,经常使用 + BUFFER_USAGE_STATIC, ///< 经常修改和使用 + }; + + /// + /// GPU缓冲,分顶点缓冲和索引缓冲两种,避免每次都从内存向显存上传数据。 + /// + class GPUBuffer + { + public: + + GPUBuffer(BufferType type, BufferUsage usage, size_t size) ASURA_THROW(Exception); + ~GPUBuffer(); + + /// + /// 初始化\更新缓存,如果没有gpu buffer资源,认为是初始化,否则认为是更新。 + /// + bool Fill(const void* data, size_t size, uint offset = 0) ASURA_THROW(Exception); + + /// + /// 绑定到对应的目标上,接下来就可以使用了。 + /// + void Bind(); + void UnBind(); + + uint GetBufferSize(); + + private: + + GLenum mTarget; + GLuint mBuffer; + GLuint mUsage; + uint mSize; + +#if ASURA_DEBUG + /// + /// 本地保存的buffer数据,和显存数据保持一致,用来调试和更新显存。 + /// + byte* mData; +#endif + + }; + + } +} + +#endif \ No newline at end of file diff --git a/source/modules/asura-core/graphics/image.cpp b/source/modules/asura-core/graphics/image.cpp index 4cbe826..d4c4cdd 100644 --- a/source/modules/asura-core/graphics/image.cpp +++ b/source/modules/asura-core/graphics/image.cpp @@ -20,11 +20,9 @@ namespace AsuraEngine { } - bool Image::Update(DecodedData* data) + bool Image::Load(ImageData* imgData) { - if (!data) return false; - ImageData* imgData = static_cast(data); - if (!imgData) return false; + if (!imgData) return false; if (mTex == 0) { @@ -59,10 +57,8 @@ namespace AsuraEngine return true; } - bool Image::Update(AEIO::DecodedData* data, const AEMath::Vector2i& pos) + bool Image::Load(ImageData* imgData, const AEMath::Vector2i& pos) { - if (!data) return false; - ImageData* imgData = static_cast(data); if (!imgData) return false; glBindTexture(GL_TEXTURE_2D, mTex); diff --git a/source/modules/asura-core/graphics/image.h b/source/modules/asura-core/graphics/image.h index e4aecd1..d3cca4b 100644 --- a/source/modules/asura-core/graphics/image.h +++ b/source/modules/asura-core/graphics/image.h @@ -20,21 +20,16 @@ namespace AsuraEngine namespace Graphics { - class ImageFactory; - /// /// Image是图片从内存中载入后,读取进游戏后保存的结果。一个Image在内存、显存中只会保存一 /// 份,不会产生副本。需要特征化的区别image,如锚点位置,缩放和旋转角度,使用sprite。 /// 是一个只读类。主要是考虑到editor和engine使用不同的封装。 /// class Image ASURA_FINAL - : public AEIO::Renewable - , public AEScripting::Portable + : public AEScripting::Portable { public: - LUAX_DECL_FACTORY(Image); - Image(); ~Image(); @@ -43,19 +38,21 @@ namespace AsuraEngine /// 将解析后的图像数据提交到GPU,更新像素信息。用来重新构建image,使用glTexImage2D重 /// 新提交image的像素数据。 /// - bool Update(AEIO::DecodedData* decodeData) override; - bool Update(AEIO::DecodedData* decodeData, const AEMath::Vector2i& pos); + bool Load(ImageData* decodeData); + bool Load(ImageData* decodeData, const AEMath::Vector2i& pos); uint GetWidth(); uint GetHeight(); void Render(const RenderTarget* rt, const RenderState& state) override {}; - void Render(const RenderTarget* rt, const Math::Rectf& quad, const RenderState& state) override {}; + void Render(const RenderTarget* rt, const AEMath::Rectf& quad, const RenderState& state) override {}; private: //----------------------------------------------------------------------------// + LUAX_DECL_FACTORY(Image, Texture); + LUAX_DECL_METHOD(_New); LUAX_DECL_METHOD(_Update); LUAX_DECL_METHOD(_GetWidth); diff --git a/source/modules/asura-core/graphics/matrix_stack.h b/source/modules/asura-core/graphics/matrix_stack.h index e69ee98..db7248b 100644 --- a/source/modules/asura-core/graphics/matrix_stack.h +++ b/source/modules/asura-core/graphics/matrix_stack.h @@ -35,7 +35,7 @@ namespace AsuraEngine bool Pop(); AEMath::Matrix44& GetTop(); - void GetTop(asura_out AEMath::Matrix44& mat44); + void GetTop(ASURA_OUT AEMath::Matrix44& mat44); void LoadMatrix(const AEMath::Matrix44& mat44); void MultMatrix(const AEMath::Matrix44& mat44); diff --git a/source/modules/asura-core/graphics/render_target.h b/source/modules/asura-core/graphics/render_target.h index 0749cab..1992f6c 100644 --- a/source/modules/asura-core/graphics/render_target.h +++ b/source/modules/asura-core/graphics/render_target.h @@ -18,7 +18,7 @@ namespace AsuraEngine /// Canvas(RenderTexture) /// Window(RenderWindow) /// - class RenderTarget + class RenderTarget : public AEScripting::Object { public: diff --git a/source/modules/asura-core/graphics/shader.cpp b/source/modules/asura-core/graphics/shader.cpp index c26ddf1..e6779df 100644 --- a/source/modules/asura-core/graphics/shader.cpp +++ b/source/modules/asura-core/graphics/shader.cpp @@ -1,6 +1,5 @@ #include -#include "shader_source.h" #include "shader.h" using namespace std; @@ -12,47 +11,49 @@ namespace AsuraEngine Shader::Shader() { - //Fix: 等需要的时候再申请 - //mProgram = glCreateProgram(); - //if (mProgram == 0) - // throw Exception("Cannot create OpenGL shader program."); - - //mVertShader = glCreateShader(GL_VERTEX_SHADER); - //if (mVertShader == 0) - //{ - // glDeleteProgram(mProgram); - // throw Exception("Cannot create OpenGL vertex shader."); - //} - - //mFragShader = glCreateShader(GL_FRAGMENT_SHADER); - //if (mFragShader == 0) - //{ - // glDeleteProgram(mProgram); - // glDeleteShader(mVertShader); - // throw Exception("Cannot create OpenGL fragment shader."); - //} } Shader::~Shader() { - glDeleteShader(mVertShader); - glDeleteShader(mFragShader); - glDeleteProgram(mProgram); + if(mVertShader != 0) + glDeleteShader(mVertShader); + if(mFragShader != 0) + glDeleteShader(mFragShader); + if(mProgram != 0) + glDeleteProgram(mProgram); } - bool Shader::Update(AEIO::DecodedData* db) + bool Shader::Load(const string& vert, const string& frag) { - if (!db) return false; - ShaderSouce* shaderSource = static_cast(db); - if (!shaderSource) return false; - GLenum err = GL_NO_ERROR; - const GLchar* source; GLint success; string warnning = ""; + if (mProgram == 0) + { + mProgram = glCreateProgram(); + if (mProgram == 0) + throw Exception("Cannot create OpenGL shader program."); + } + + if (mVertShader == 0) + { + mVertShader = glCreateShader(GL_VERTEX_SHADER); + if (mVertShader == 0) + throw Exception("Cannot create OpenGL vertex shader."); + } + + if (mFragShader == 0) + { + mFragShader = glCreateShader(GL_FRAGMENT_SHADER); + if(mFragShader == 0) + throw Exception("Cannot create OpenGL fragment shader."); + } + + const GLchar* source; + // Compile vertex shader. - source = shaderSource->mVert.c_str(); + source = vert.c_str(); glShaderSource(mVertShader, 1, &source, NULL); glCompileShader(mVertShader); glGetShaderiv(mVertShader, GL_COMPILE_STATUS, &success); @@ -63,7 +64,7 @@ namespace AsuraEngine } // Compile fragment shader. - source = shaderSource->mFrag.c_str(); + source = frag.c_str(); glShaderSource(mFragShader, 1, &source, NULL); glCompileShader(mFragShader); glGetShaderiv(mFragShader, GL_COMPILE_STATUS, &success); @@ -83,29 +84,27 @@ namespace AsuraEngine warnning = GetProgramWarnings(); throw Exception("Link shader program failed:\n%s", warnning.c_str()); } - } - uint Shader::GetUniformLocation(const std::string& uniform) - { - return 0; + return true; } - GLuint Shader::GetGLProgramHandle() + uint Shader::GetUniformLocation(const std::string& uniform) { - return mProgram; + // This function returns -1 if name does not correspond to an active uniform variable + // in program or if name starts with the reserved prefix "gl_". + GLint loc = glGetUniformLocation(mProgram, uniform.c_str()); + return loc; } - void Shader::Use() + bool Shader::HasUniform(const std::string& uniform) { - if (mProgram != 0) - { - gl.UseShader(this); - } + GLint loc = glGetUniformLocation(mProgram, uniform.c_str()); + return loc != -1; } - void Shader::Unuse() + GLuint Shader::GetGLProgramHandle() { - gl.UnuseShader(); + return mProgram; } void Shader::SetUniformFloat(uint loc, float value) @@ -138,6 +137,18 @@ namespace AsuraEngine glUniform4f(loc, vec4.x, vec4.y, vec4.z, vec4.w); } + void Shader::SetUniformMatrix44(uint loc, const Math::Matrix44& mat) + { + if (gl.state.shader == this) + glUniformMatrix4fv(loc, 1, GL_FALSE, mat.GetElements()); + } + + //void Shader::GetUniform() + //{ + // //if(gl.state.shader == this) + // // glGetUniformfv() + //} + uint Shader::GetGLTextureUnitCount() { GLint maxTextureUnits = 0; diff --git a/source/modules/asura-core/graphics/shader.h b/source/modules/asura-core/graphics/shader.h index f4bce25..9cf9653 100644 --- a/source/modules/asura-core/graphics/shader.h +++ b/source/modules/asura-core/graphics/shader.h @@ -14,7 +14,6 @@ #include #include -#include "shader_source.h" #include "color.h" #include "texture.h" #include "gl.h" @@ -35,31 +34,14 @@ namespace AsuraEngine { public: - LUAX_DECL_FACTORY(Shader); - - Shader() asura_throw(Exception); + Shader(); ~Shader(); - /// - /// 从代码编译shader,编译时会先检测是否有上次缓存的uniforms location map。使用 - /// glAttachShader重新编译生成着色器,不会重新申请着色器程序。 - /// - bool Update(AEIO::DecodedData* decodeData) override; - - /// - /// 将当期shader设置为活动 - /// - void Use(); - - /// - /// 将当期shader设置为非活动 - /// - void Unuse(); - - /// - /// 在已经知道uniform location的情况下,设置值。 - /// + bool Load(const std::string& vert, const std::string& frag); + + uint GetAttributeLocation(const std::string& name); + void SetUniformFloat(uint loc, float value); void SetUniformTexture(uint loc, const Texture& texture); void SetUniformVector2(uint loc, const Math::Vector2f& vec2); @@ -68,40 +50,32 @@ namespace AsuraEngine void SetUniformColor(uint loc, const Color& color); void SetUniformMatrix44(uint loc, const Math::Matrix44& mat44); + float GetUniformFloat(uint loc); + AEMath::Vector2f GetUniformVector2(uint loc); + AEMath::Vector3f GetUniformVector3(uint loc); + AEMath::Vector4f GetUniformVector4s(uint loc); + AEMath::Matrix44 GetUniformMatrix44(uint loc); + uint GetUniformLocation(const std::string& uniform); bool HasUniform(const std::string& uniform); GLuint GetGLProgramHandle(); - /// - /// 获得texture unit数量,一般为16个 - /// static uint GetGLTextureUnitCount(); private: - /// - /// 设置内置变量: - /// vec2 Asura_Time x值为进入当前场景开始的时间,y值为上一帧的时间间隔 - /// vec2 Asura_RenderTargetSize RT的大小,以像素为单位 - /// Texture Asura_MainTexture 主纹理 - /// - void SetBuiltInUniforms(); - - /// - /// OpenGL shader program handle. - /// GLuint mProgram; GLuint mVertShader; GLuint mFragShader; - Luax::LuaxMemberRef mCodeRef; - private: //----------------------------------------------------------------------------// + LUAX_DECL_FACTORY(Shader); + LUAX_DECL_METHOD(_New); LUAX_DECL_METHOD(_Use); LUAX_DECL_METHOD(_Unuse); diff --git a/source/modules/asura-core/graphics/shader_source.h b/source/modules/asura-core/graphics/shader_source.h deleted file mode 100644 index eedbe53..0000000 --- a/source/modules/asura-core/graphics/shader_source.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef __ASURA_SHADER_SOURCE_H__ -#define __ASURA_SHADER_SOURCE_H__ - -#include - -#include - -namespace AsuraEngine -{ - namespace Graphics - { - - class Shader; - - /// - /// Asura Engine使用的shader源代码,基于GLSL。 - /// - class ShaderSouce : public AEIO::DecodedData - { - public: - - void Decode(AEIO::DataBuffer& vert, AEIO::DataBuffer& frag); - void Load(const std::string& vert, const std::string& frag); - - private: - - friend class Shader; - - void Decode(AEIO::DataBuffer& buffer) override; - - std::string mVert; - std::string mFrag; - - }; - - } -} - -#endif \ No newline at end of file diff --git a/source/modules/asura-core/graphics/sprite_batch.h b/source/modules/asura-core/graphics/sprite_batch.h index eb1c89c..17ecb40 100644 --- a/source/modules/asura-core/graphics/sprite_batch.h +++ b/source/modules/asura-core/graphics/sprite_batch.h @@ -3,6 +3,8 @@ #include +#include "gpu_buffer.h" + namespace AsuraEngine { namespace Graphics @@ -16,12 +18,16 @@ namespace AsuraEngine { public: - LUAX_DECL_FACTORY(SpriteBatch); - SpriteBatch(); ~SpriteBatch(); + private: + + LUAX_DECL_FACTORY(SpriteBatch); + + + }; } diff --git a/source/modules/asura-core/graphics/texture.h b/source/modules/asura-core/graphics/texture.h index 571c617..4a414b4 100644 --- a/source/modules/asura-core/graphics/texture.h +++ b/source/modules/asura-core/graphics/texture.h @@ -1,8 +1,8 @@ #ifndef __ASURA_TEXTURE_H__ #define __ASURA_TEXTURE_H__ -#include #include +#include #include "../core_config.h" @@ -87,7 +87,7 @@ namespace AsuraEngine /// /// 渲染texture的一部分到rt上,原点在左上角,向右,向下延伸。 /// - virtual void Render(const RenderTarget* rt, const Math::Rectf& quad, const RenderState& state) = 0; + virtual void Render(const RenderTarget* rt, const AEMath::Rectf& quad, const RenderState& state) = 0; protected: @@ -112,6 +112,9 @@ namespace AsuraEngine //----------------------------------------------------------------------------// + /// + /// OpenGL纹理名 + /// GLuint mTex; FilterMode mMinFilter; diff --git a/source/modules/asura-core/image/image_data.h b/source/modules/asura-core/image/image_data.h index d9427d3..b05507a 100644 --- a/source/modules/asura-core/image/image_data.h +++ b/source/modules/asura-core/image/image_data.h @@ -20,13 +20,11 @@ namespace AsuraEngine class ImageDecoder; class ImageData ASURA_FINAL - : public AEIO::DecodedData - , public Scripting::Portable + : public Scripting::Portable + , public AEIO::DecodedData { public: - LUAX_DECL_FACTORY(ImageData); - /// /// 解析图片数据文件,并构建像素信息,如果解析失败,抛出异常 /// @@ -53,6 +51,8 @@ namespace AsuraEngine //----------------------------------------------------------------------------// + LUAX_DECL_FACTORY(ImageData); + LUAX_DECL_METHOD(_New); LUAX_DECL_METHOD(_GetPixel); LUAX_DECL_METHOD(_GetSize); diff --git a/source/modules/asura-core/image/image_decode_task.h b/source/modules/asura-core/image/image_decode_task.h index 15b0837..666d00f 100644 --- a/source/modules/asura-core/image/image_decode_task.h +++ b/source/modules/asura-core/image/image_decode_task.h @@ -10,8 +10,7 @@ namespace AsuraEngine { class ImageDecodeTask - : public AEScripting::Portable - , public AEThreading::Task + : public AEScripting::Portable { public: diff --git a/source/modules/asura-core/window/window.cpp b/source/modules/asura-core/window/window.cpp index 99433d5..9dc247d 100644 --- a/source/modules/asura-core/window/window.cpp +++ b/source/modules/asura-core/window/window.cpp @@ -84,23 +84,23 @@ namespace AsuraEngine glClearColor(col.r, col.g, col.b, col.a); } - void Window::Clear(const Math::Recti& quad, const AEGraphics::Color& col /*= AEGraphics::Color::Black*/) - { - ASSERT(mImpl); + //void Window::Clear(const Math::Recti& quad, const AEGraphics::Color& col /*= AEGraphics::Color::Black*/) + //{ + // ASSERT(mImpl); - } + //} void Window::Draw(const AEGraphics::Drawable* texture, const AEGraphics::RenderState& state) { ASSERT(mImpl); } - +/* void Window::Draw(const AEGraphics::Drawable* texture, const Math::Recti& quad, const AEGraphics::RenderState& state) { ASSERT(mImpl); } - +*/ } } diff --git a/source/modules/asura-core/window/window.h b/source/modules/asura-core/window/window.h index 8ce0e64..61adae1 100644 --- a/source/modules/asura-core/window/window.h +++ b/source/modules/asura-core/window/window.h @@ -58,8 +58,7 @@ namespace AsuraEngine /// 会导入此类,将会嫁接到编辑器的虚拟窗口上。 /// class Window ASURA_FINAL - : public AEGraphics::RenderTarget - , public AEScripting::Portable + : public AEScripting::Portable , public Singleton { public: diff --git a/source/modules/asura-utils/io/binding/_file.cpp b/source/modules/asura-utils/io/binding/_file.cpp index 2de7882..c44bc90 100644 --- a/source/modules/asura-utils/io/binding/_file.cpp +++ b/source/modules/asura-utils/io/binding/_file.cpp @@ -186,7 +186,7 @@ namespace AsuraEngine LUAX_PREPARE(L, File); size_t size = 0; - BufferMode mode = self->GetBuffer(asura_out size); + BufferMode mode = self->GetBuffer(ASURA_OUT size); state.Push((int)size); state.Push((int)mode); return 2; diff --git a/source/modules/asura-utils/io/binding/_file_system.cpp b/source/modules/asura-utils/io/binding/_file_system.cpp index 2efc4f6..3843451 100644 --- a/source/modules/asura-utils/io/binding/_file_system.cpp +++ b/source/modules/asura-utils/io/binding/_file_system.cpp @@ -113,7 +113,7 @@ namespace AsuraEngine cc8* path = state.CheckValue(1); std::string mp; - if (fs->GetMountPoint(path, asura_out mp)) + if (fs->GetMountPoint(path, ASURA_OUT mp)) state.Push(mp); else state.PushNil(); @@ -246,7 +246,7 @@ namespace AsuraEngine cc8* path = state.CheckValue(1); std::vector items; - if(fs->GetDirectoryItems(path, asura_out items)) + if(fs->GetDirectoryItems(path, ASURA_OUT items)) { lua_newtable(L); // item list for (int i = 0; i < items.size(); ++i) diff --git a/source/modules/asura-utils/io/decoded_data.h b/source/modules/asura-utils/io/decoded_data.h index 724dbac..882556c 100644 --- a/source/modules/asura-utils/io/decoded_data.h +++ b/source/modules/asura-utils/io/decoded_data.h @@ -2,6 +2,7 @@ #define __ASURA_ENGINE_DATA_H__ #include + #include #include "../scripting/portable.hpp" diff --git a/source/modules/asura-utils/io/file.cpp b/source/modules/asura-utils/io/file.cpp index 690f405..9e89c85 100644 --- a/source/modules/asura-utils/io/file.cpp +++ b/source/modules/asura-utils/io/file.cpp @@ -118,7 +118,7 @@ namespace AsuraEngine return PHYSFS_fileLength(mFileHandle); } - size_t File::Read(asura_out DataBuffer* dst, size_t length) + size_t File::Read(ASURA_OUT DataBuffer* dst, size_t length) { ASSERT(dst); @@ -140,7 +140,7 @@ namespace AsuraEngine return size; } - size_t File::ReadAll(asura_out DataBuffer* dst) + size_t File::ReadAll(ASURA_OUT DataBuffer* dst) { ASSERT(dst); @@ -192,7 +192,7 @@ namespace AsuraEngine return mFileHandle != nullptr && PHYSFS_seek(mFileHandle, pos) != 0; } - bool File::Write(asura_ref DataBuffer* src) + bool File::Write(ASURA_REF DataBuffer* src) { if (!mFileHandle || (mMode != FILE_MODE_APPEND && mMode != FILE_MODE_WRITE)) throw Exception("File is not opened for writing."); @@ -264,7 +264,7 @@ namespace AsuraEngine return true; } - File::BufferMode File::GetBuffer(asura_out size_t& size) + File::BufferMode File::GetBuffer(ASURA_OUT size_t& size) { size = mBufferSize; return mBufferMode; diff --git a/source/modules/asura-utils/io/file.h b/source/modules/asura-utils/io/file.h index 9af8919..56077e0 100644 --- a/source/modules/asura-utils/io/file.h +++ b/source/modules/asura-utils/io/file.h @@ -57,9 +57,9 @@ namespace AsuraEngine /// /// 读取到data buffer里,并返回读入的内容 /// - size_t Read(asura_out DataBuffer* dst, size_t length); - size_t ReadAll(asura_out DataBuffer* dst); - size_t ReadAsync(asura_out DataBuffer* dst); + size_t Read(ASURA_OUT DataBuffer* dst, size_t length); + size_t ReadAll(ASURA_OUT DataBuffer* dst); + size_t ReadAsync(ASURA_OUT DataBuffer* dst); /// /// 是否读到了文件结尾 @@ -69,12 +69,12 @@ namespace AsuraEngine /// /// 将data buffer中的内容写入,并返回是否成功 /// - bool Write(asura_ref DataBuffer* src); + bool Write(ASURA_REF DataBuffer* src); /// /// 异步写文件,将写文件task加入thread的队列。 /// - bool WriteAsync(asura_ref DataBuffer* src, AEThreading::Thread* thread); + bool WriteAsync(ASURA_REF DataBuffer* src, AEThreading::Thread* thread); /// /// 如果开启了缓冲,强制清空缓冲区,写入文件。 @@ -99,7 +99,7 @@ namespace AsuraEngine /// /// 获取缓冲区大小和模式 /// - BufferMode GetBuffer(asura_out size_t& size); + BufferMode GetBuffer(ASURA_OUT size_t& size); const std::string& GetFileName(); const std::string& GetName(); diff --git a/source/modules/asura-utils/io/file_data.h b/source/modules/asura-utils/io/file_data.h index f5a6085..cd69477 100644 --- a/source/modules/asura-utils/io/file_data.h +++ b/source/modules/asura-utils/io/file_data.h @@ -49,7 +49,7 @@ namespace AsuraEngine /// /// Data buffer不会再filedata析构时销毁,当lua引用计数为0时由lua调用GC销毁。创建mData时会添加一个成员引用。 /// - asura_ref DataBuffer* mData; + ASURA_REF DataBuffer* mData; Luax::LuaxMemberRef mDataRef; std::string mFileName; ///< 包含扩展名的文件名 diff --git a/source/modules/asura-utils/io/file_system.cpp b/source/modules/asura-utils/io/file_system.cpp index 30e7861..20f3cb2 100644 --- a/source/modules/asura-utils/io/file_system.cpp +++ b/source/modules/asura-utils/io/file_system.cpp @@ -83,7 +83,7 @@ namespace AsuraEngine } } - bool Filesystem::GetMountPoint(const std::string& locpath, asura_out std::string& mountpoint) + bool Filesystem::GetMountPoint(const std::string& locpath, ASURA_OUT std::string& mountpoint) { if (!mInited) return false; @@ -125,7 +125,7 @@ namespace AsuraEngine return true; } - bool Filesystem::Write(const std::string& name, asura_ref DataBuffer* buffer) + bool Filesystem::Write(const std::string& name, ASURA_REF DataBuffer* buffer) { File file(name); file.Open(File::FILE_MODE_WRITE); @@ -133,7 +133,7 @@ namespace AsuraEngine throw Exception("Data could not be written."); } - bool Filesystem::Append(const std::string& name, asura_ref DataBuffer* buffer) + bool Filesystem::Append(const std::string& name, ASURA_REF DataBuffer* buffer) { File file(name); file.Open(File::FILE_MODE_APPEND); @@ -170,7 +170,7 @@ namespace AsuraEngine return true; } - bool Filesystem::GetFileInfo(const std::string& filepath, asura_out FileInfo* info) + bool Filesystem::GetFileInfo(const std::string& filepath, ASURA_OUT FileInfo* info) { if (!mInited) return false; diff --git a/source/modules/asura-utils/io/file_system.h b/source/modules/asura-utils/io/file_system.h index 3a33504..849cbb6 100644 --- a/source/modules/asura-utils/io/file_system.h +++ b/source/modules/asura-utils/io/file_system.h @@ -59,20 +59,20 @@ namespace AsuraEngine bool Unmount(const std::string& locpath); bool Unmount(DataBuffer* db); - bool GetMountPoint(const std::string& locpath, asura_out std::string& mountpoint); + bool GetMountPoint(const std::string& locpath, ASURA_OUT std::string& mountpoint); void SetWriteDirectory(const std::string locpath); std::string GetWriteDirectory(); File* NewFile(const std::string& name); bool NewDirectory(const std::string& path); - bool Write(const std::string& path, asura_ref DataBuffer* buffer); - bool Append(const std::string& path, asura_ref DataBuffer* buffer); + bool Write(const std::string& path, ASURA_REF DataBuffer* buffer); + bool Append(const std::string& path, ASURA_REF DataBuffer* buffer); bool Remove(const std::string& path); FileData* Read(const std::string& path); - bool GetFileInfo(const std::string& path, asura_out FileInfo* info); + bool GetFileInfo(const std::string& path, ASURA_OUT FileInfo* info); - bool GetDirectoryItems(const std::string& path, asura_out std::vector& items) { return false; }; + bool GetDirectoryItems(const std::string& path, ASURA_OUT std::vector& items) { return false; }; private: diff --git a/source/modules/asura-utils/io/renewable.h b/source/modules/asura-utils/io/renewable.h index 4d047ea..fd6c638 100644 --- a/source/modules/asura-utils/io/renewable.h +++ b/source/modules/asura-utils/io/renewable.h @@ -19,15 +19,6 @@ namespace AsuraEngine public: Renewable() {}; virtual ~Renewable() {}; - - /// - /// 继承Renewable的需要提供一个Update方法 - /// - /// 依据Effective C++条款09.应该禁止在构造函数中调用virtual方法,所以这里的Update - /// 被从构造函数中抽离,需要手动调用Update。 - /// - virtual bool Update(AEIO::DecodedData* decode_data) = 0; - }; } diff --git a/source/modules/asura-utils/math/matrix44.h b/source/modules/asura-utils/math/matrix44.h index fa5be33..9ff0288 100644 --- a/source/modules/asura-utils/math/matrix44.h +++ b/source/modules/asura-utils/math/matrix44.h @@ -1,6 +1,8 @@ #ifndef __ASURA_MATRIX_H__ #define __ASURA_MATRIX_H__ +#include "../scripting/portable.hpp" + namespace AsuraEngine { namespace Math diff --git a/source/modules/asura-utils/scripting/portable.hpp b/source/modules/asura-utils/scripting/portable.hpp index 1c05163..cb8e2eb 100644 --- a/source/modules/asura-utils/scripting/portable.hpp +++ b/source/modules/asura-utils/scripting/portable.hpp @@ -20,7 +20,8 @@ namespace AsuraEngine using Object = Luax::LuaxObject; /// - /// 要注册给lua的native类需要继承此模板。 + /// 要注册给lua的native类需要继承此模板。BASE指定基类,默认是LuaxObject,如果指定基类 + /// 必须是LuaxObject的派生类、 /// template using Portable = Luax::LuaxNativeClass; diff --git a/source/modules/asura-utils/type.h b/source/modules/asura-utils/type.h index 738c4f1..f760205 100644 --- a/source/modules/asura-utils/type.h +++ b/source/modules/asura-utils/type.h @@ -82,10 +82,10 @@ namespace AsuraEngine //--------------------------------------------------------------------------------// // 扩展关键字 -#define asura_throw(ex) throw(ex) // 暗示抛出异常 +#define ASURA_THROW(ex) throw(ex) // 暗示抛出异常 -#define asura_out -#define asura_ref +#define ASURA_OUT +#define ASURA_REF } // namespace AsuraEngine diff --git a/source/tests/win32/01-window/03_sub_menu.cpp b/source/tests/win32/01-window/03_sub_menu.cpp index 24b9654..091db6d 100644 --- a/source/tests/win32/01-window/03_sub_menu.cpp +++ b/source/tests/win32/01-window/03_sub_menu.cpp @@ -20,6 +20,8 @@ void AddMenus(HWND); #define IDM_ASSET 20 +HWND wnd; + int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR lpCmdLine, int nCmdShow) { @@ -32,9 +34,9 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR lpCmdLin wc.hbrBackground = GetSysColorBrush(COLOR_3DFACE); wc.lpfnWndProc = WndProc; wc.hCursor = LoadCursor(0, IDC_ARROW); - RegisterClassW(&wc); - CreateWindowW(wc.lpszClassName, L"Asura v0.1", + + wnd = CreateWindowW(wc.lpszClassName, L"Asura v0.1", WS_OVERLAPPEDWINDOW | WS_VISIBLE, 200, 200, 550, 450, 0, 0, hInstance, 0); @@ -104,14 +106,14 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, imgdata->Decode(db); img = new Image(); - img->Update(imgdata); + img->Load(imgdata); wglMakeCurrent(hdc, glc); file2 = new File("root/img.png"); file2->Open(File::FILE_MODE_READ); file2->ReadAll(&db); imgdata->Decode(db); - img->Update(imgdata, {50, 100}); + img->Load(imgdata, {50, 100}); imgdata->Release(); break; @@ -121,7 +123,7 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, switch (LOWORD(wParam)) { case IDM_FILE_NEW: - MessageBoxW(NULL, L"New file selected", + MessageBoxW(wnd, L"New file selected", L"Information", MB_OK); break; -- cgit v1.1-26-g67d0