From e47baca4f23db43ec91fbf64d5d06d7c0dbee495 Mon Sep 17 00:00:00 2001 From: chai Date: Sat, 6 Apr 2019 07:39:49 +0800 Subject: *misc --- 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 +- 32 files changed, 361 insertions(+), 205 deletions(-) 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/modules') 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 -- cgit v1.1-26-g67d0