diff options
author | chai <chaifix@163.com> | 2019-04-06 07:39:49 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2019-04-06 07:39:49 +0800 |
commit | e47baca4f23db43ec91fbf64d5d06d7c0dbee495 (patch) | |
tree | 9e909413bbf61834570e7dbdbe37fc8705f12730 /source/modules | |
parent | e13616b5c40f912853be99f0603f0e4c97b22062 (diff) |
*misc
Diffstat (limited to 'source/modules')
32 files changed, 361 insertions, 205 deletions
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<ImageData>(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<Canvas> + : public Scripting::Portable<Canvas, RenderTarget> { 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); @@ -55,6 +53,11 @@ namespace AsuraEngine GLuint mFBO; /// + /// tex + /// + GLuint mTex; + + /// /// canvasĴС /// uint mWidth, mHeight; 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(); + /// + /// ʼOpenGLIJڴ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 <asura-utils/exceptions/exception.h> +#include <asura-utils/type.h> + +#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ԴΪdzʼΪǸ¡ + /// + 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<ImageData*>(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<ImageData*>(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 /// һֻࡣҪǿǵeditorengineʹòͬķװ /// class Image ASURA_FINAL - : public AEIO::Renewable - , public AEScripting::Portable<Image, Texture> + : public AEScripting::Portable<Image, Texture> { 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 <asura-utils/exceptions/exception.h> -#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<ShaderSouce*>(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 <asura-utils/stringmap.hpp> #include <asura-utils/manager.hpp> -#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 <string> - -#include <asura-utils/io/decoded_data.h> - -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 <asura-utils/scripting/portable.hpp> +#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 <asura-utils/math/rect.hpp> #include <asura-utils/math/vector2.hpp> +#include <asura-utils/math/rect.hpp> #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<ImageData> + : public Scripting::Portable<ImageData> + , 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<ImageDecodeTask> - , public AEThreading::Task + : public AEScripting::Portable<ImageDecodeTask, AEThreading::Task> { 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<Window> + : public AEScripting::Portable<Window, AEGraphics::RenderTarget> , public Singleton<Window> { 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<cc8*>(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<cc8*>(1); std::vector<std::string> 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 <cstdlib> + #include <asura-utils/threading/thread.h> #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); /// /// 첽дļдļtaskthreadĶС /// - 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 bufferfiledataʱ٣luaüΪ0ʱluaGC١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<std::string>& items) { return false; }; + bool GetDirectoryItems(const std::string& path, ASURA_OUT std::vector<std::string>& 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.Ӧýֹڹ캯еvirtualUpdate - /// ӹ캯г룬Ҫֶ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; /// - /// ҪעluanativeҪ̳дģ塣 + /// ҪעluanativeҪ̳дģ塣BASEָ࣬ĬLuaxObjectָ + /// LuaxObjectࡢ /// template<typename TYPE, typename BASE = Luax::LuaxObject> using Portable = Luax::LuaxNativeClass<TYPE, BASE>; 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 |