diff options
Diffstat (limited to 'source/modules/asura-core')
23 files changed, 461 insertions, 65 deletions
diff --git a/source/modules/asura-core/graphics/binding/_gl.cpp b/source/modules/asura-core/graphics/binding/_gl.cpp index 4c0605f..0c3a18f 100644 --- a/source/modules/asura-core/graphics/binding/_gl.cpp +++ b/source/modules/asura-core/graphics/binding/_gl.cpp @@ -28,8 +28,9 @@ namespace AsuraEngine LUAX_POSTPROCESS(OpenGL) { LUAX_REGISTER_ENUM(state, "EMatrixMode", - { "PROJECTION", MATRIX_PROJECTION }, - { "MODELVIEW", MATRIX_MODELVIEW } + { "PROJECTION", MATRIX_MODE_PROJECTION }, + { "MODEL", MATRIX_MODE_MODEL }, + { "VIEW", MATRIX_MODE_VIEW } ); } diff --git a/source/modules/asura-core/graphics/color.h b/source/modules/asura-core/graphics/color.h index e875846..197921f 100644 --- a/source/modules/asura-core/graphics/color.h +++ b/source/modules/asura-core/graphics/color.h @@ -66,4 +66,6 @@ namespace AsuraEngine } } +namespace AEGraphics = AsuraEngine::Graphics; + #endif
\ No newline at end of file diff --git a/source/modules/asura-core/graphics/gl.cpp b/source/modules/asura-core/graphics/gl.cpp index 54fadb7..537d40d 100644 --- a/source/modules/asura-core/graphics/gl.cpp +++ b/source/modules/asura-core/graphics/gl.cpp @@ -4,6 +4,7 @@ #include "gl.h" #include "shader.h" +#include "matrix_stack.h" using namespace AEMath; @@ -30,6 +31,8 @@ namespace AsuraEngine { } + static bool inited = false; + bool OpenGL::Init(const AEMath::Recti& view) { bool loaded = false; @@ -39,10 +42,17 @@ namespace AsuraEngine #endif if (!loaded) return false; - state.viewport = view; + SetViewport(view); + + inited = true; return true; } + bool OpenGL::Inited() + { + return inited; + } + void OpenGL::WipeError() { while (glGetError() != GL_NO_ERROR); @@ -60,8 +70,8 @@ namespace AsuraEngine void OpenGL::SetViewport(const Recti v) { + state.viewport = v; glViewport(v.x, v.y, v.w, v.h); - state.viewport = v; } const Recti& OpenGL::GetViewport() @@ -71,12 +81,15 @@ namespace AsuraEngine void OpenGL::UseShader(Shader* shader) { - glUseProgram(shader->GetGLProgramHandle()); + glUseProgram(shader->GetGLProgram()); + int err = gl.HasError(); state.shader = shader; + shader->OnUse(); } void OpenGL::UnuseShader() { + state.shader->OnUnuse(); state.shader = nullptr; } @@ -112,9 +125,9 @@ namespace AsuraEngine state.matrix[state.matrixMode].Rotate(angle, x, y, z); } - void OpenGL::Translate(float x, float y, float z) + void OpenGL::Translate(float x, float y) { - state.matrix[state.matrixMode].Translate(x, y, z); + state.matrix[state.matrixMode].Translate(x, y); } void OpenGL::Scale(float x, float y, float z) @@ -129,7 +142,7 @@ namespace AsuraEngine AEMath::Matrix44& OpenGL::GetMatrix(MatrixMode mode) { - return state.matrix[state.matrixMode].GetTop(); + return state.matrix[mode].GetTop(); } uint OpenGL::GetMatrixDepth() diff --git a/source/modules/asura-core/graphics/gl.h b/source/modules/asura-core/graphics/gl.h index e3c2ffc..82b9821 100644 --- a/source/modules/asura-core/graphics/gl.h +++ b/source/modules/asura-core/graphics/gl.h @@ -22,8 +22,14 @@ namespace AsuraEngine enum MatrixMode { - MATRIX_PROJECTION = 0, - MATRIX_MODELVIEW = 1, + MATRIX_MODE_PROJECTION = 0, + MATRIX_MODE_MODEL = 1, + MATRIX_MODE_VIEW = 2, + }; + + enum GLPrams + { + GL_PARAM_MAX_TEXTURE_UNIT = 1, }; /// @@ -40,15 +46,23 @@ namespace AsuraEngine ~OpenGL(); /// + /// óֵ + /// + int GetParam(GLPrams param); + + /// /// ʼOpenGLIJڴOpenGL֮˺עOpenGLĵַ /// bool Init(const AEMath::Recti& viewport); + bool Inited(); void SetViewport(const AEMath::Recti viewport); const AEMath::Recti& GetViewport(); void UseShader(Shader* shader); void UnuseShader(); + + void Draw(); /// /// Matrix stackز @@ -58,9 +72,9 @@ namespace AsuraEngine void PushMatrix(); void PopMatrix(); void LoadIdentity(); - void Rotate(float angle, float x, float y, float z); - void Translate(float x, float y, float z); - void Scale(float x, float y, float z); + void Rotate(float angle); + void Translate(float x, float y); + void Scale(float x, float y); void Ortho(float l, float r, float b, float t, float n, float f); AEMath::Matrix44& GetMatrix(MatrixMode mode); uint GetMatrixDepth(); @@ -84,7 +98,7 @@ namespace AsuraEngine { Shader* shader; ///< ǰʹõshader AEMath::Recti viewport; ///< ǰлHDC߱ڴСı߲ˢʱ䶯 - MatrixStack matrix[2]; ///< 任 + MatrixStack matrix[3]; ///< model, view, projection MatrixMode matrixMode; ///< ǰľ } state; @@ -96,7 +110,8 @@ namespace AsuraEngine //----------------------------------------------------------------------------// - LUAX_DECL_ENUM(MatrixMode, 0); + LUAX_DECL_ENUM(MatrixMode, 1); + LUAX_DECL_ENUM(GLPrams, 1); LUAX_DECL_METHOD(_SetMatrixMode); LUAX_DECL_METHOD(_GetMatrixMode); diff --git a/source/modules/asura-core/graphics/gpu_buffer.cpp b/source/modules/asura-core/graphics/gpu_buffer.cpp index c796bb0..6e6aead 100644 --- a/source/modules/asura-core/graphics/gpu_buffer.cpp +++ b/source/modules/asura-core/graphics/gpu_buffer.cpp @@ -34,19 +34,6 @@ namespace AsuraEngine 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; } @@ -63,10 +50,33 @@ namespace AsuraEngine { if (data == nullptr) return false; - glBindBuffer(mTarget, mBuffer); + if (mBuffer == 0) + { + // ʼ + gl.WipeError(); + glGenBuffers(1, &mBuffer); + if (mBuffer == 0) + throw Exception("OpenGL glGenBuffers failed."); + glBindBuffer(mTarget, mBuffer); + glBufferData(mTarget, mSize, NULL, mUsage); // ʼСΪsizeĻ + if (gl.HasError()) + { + glBindBuffer(mTarget, 0); + throw Exception("OpenGL glBufferData failed. Errorcode=%d.", gl.GetError()); + } +#if ASURA_DEBUG + mData = (byte*)malloc(size); + memset(mData, 0, size); +#endif + } + else + glBindBuffer(mTarget, mBuffer); glBufferSubData(mTarget, offset, size, data); if (gl.HasError()) + { + glBindBuffer(mTarget, 0); throw Exception("OpenGL glBufferSubData failed. Errorcode=%d.", gl.GetError()); + } glBindBuffer(mTarget, 0); #if ASURA_DEBUG // һݣ diff --git a/source/modules/asura-core/graphics/gpu_buffer.h b/source/modules/asura-core/graphics/gpu_buffer.h index aba1157..c79ed4b 100644 --- a/source/modules/asura-core/graphics/gpu_buffer.h +++ b/source/modules/asura-core/graphics/gpu_buffer.h @@ -1,6 +1,7 @@ #ifndef __ASURA_GPU_BUFFER_H__ #define __ASURA_GPU_BUFFER_H__ +#include <asura-utils/scripting/portable.hpp> #include <asura-utils/exceptions/exception.h> #include <asura-utils/type.h> @@ -27,11 +28,12 @@ namespace AsuraEngine /// /// GPU壬ֶ㻺֣ÿζڴԴϴݡ /// - class GPUBuffer + class GPUBuffer + : AEScripting::Portable<GPUBuffer> { public: - GPUBuffer(BufferType type, BufferUsage usage, size_t size) ASURA_THROW(Exception); + GPUBuffer(BufferType type, BufferUsage usage, size_t size); ~GPUBuffer(); /// @@ -47,7 +49,20 @@ namespace AsuraEngine uint GetBufferSize(); - private: + private: + + //----------------------------------------------------------------------------// + + LUAX_DECL_FACTORY(GPUBuffer); + + LUAX_DECL_ENUM(BufferType, 1); + LUAX_DECL_ENUM(BufferUsage, 1); + + LUAX_DECL_METHOD(_New); + LUAX_DECL_METHOD(_Fill); + LUAX_DECL_METHOD(_GetSize); + + //----------------------------------------------------------------------------// GLenum mTarget; GLuint mBuffer; diff --git a/source/modules/asura-core/graphics/image.cpp b/source/modules/asura-core/graphics/image.cpp index d4c4cdd..cb5b573 100644 --- a/source/modules/asura-core/graphics/image.cpp +++ b/source/modules/asura-core/graphics/image.cpp @@ -13,11 +13,16 @@ namespace AsuraEngine { Image::Image() + : mVBO(nullptr) + , mWidth(0) + , mHeight(0) { } Image::~Image() { + if (mVBO) + delete mVBO; } bool Image::Load(ImageData* imgData) @@ -46,6 +51,24 @@ namespace AsuraEngine , tf.type , imgData->pixels ); + + // ʼbuffer + if (!mVBO) + mVBO = new GPUBuffer(BUFFER_TYPE_VERTEX, BUFFER_USAGE_STATIC, 16*sizeof(float)); // positionuv + + if (mWidth != imgData->width || mHeight != imgData->height) + { + float w = imgData->width, + h = imgData->height; + float buffer[] = { + 0, 0, 0, 0, + 0, h, 0, 1, + w, h, 1, 1, + w, 0, 1, 0 + }; + mVBO->Fill(buffer, sizeof(buffer)); + } + mWidth = imgData->width; mHeight = imgData->height; imgData->Unlock(); @@ -86,5 +109,30 @@ namespace AsuraEngine return true; } + uint32 Image::GetWidth() + { + return mWidth; + } + + uint32 Image::GetHeight() + { + return mHeight; + } + + void Image::UpdateBuffer() + { + if (!mVBO) + return; + float w = mWidth, + h = mHeight; + float buffer[] = { + 0, 0, 0, 0, + 0, h, 0, 1, + w, h, 1, 1, + w, 0, 1, 0 + }; + mVBO->Fill(buffer, sizeof(buffer)); + } + } }
\ No newline at end of file diff --git a/source/modules/asura-core/graphics/image.h b/source/modules/asura-core/graphics/image.h index d3cca4b..abb8a1a 100644 --- a/source/modules/asura-core/graphics/image.h +++ b/source/modules/asura-core/graphics/image.h @@ -14,6 +14,7 @@ #include "color.h" #include "color32.h" #include "render_state.h" +#include "gpu_buffer.h" namespace AsuraEngine { @@ -43,9 +44,11 @@ namespace AsuraEngine uint GetWidth(); uint GetHeight(); - - void Render(const RenderTarget* rt, const RenderState& state) override {}; - void Render(const RenderTarget* rt, const AEMath::Rectf& quad, const RenderState& state) override {}; +/* + void Render(const RenderTarget* rt, const RenderState& state) {}; + void Render(const RenderTarget* rt, const AEMath::Rectf& quad, const RenderState& state) {}; +*/ + void UpdateBuffer(); private: @@ -65,6 +68,11 @@ namespace AsuraEngine uint32 mWidth, mHeight; + /// + /// 壬positionUV + /// + GPUBuffer* mVBO; + }; } diff --git a/source/modules/asura-core/graphics/matrix_stack.cpp b/source/modules/asura-core/graphics/matrix_stack.cpp index 72ffb7d..920dded 100644 --- a/source/modules/asura-core/graphics/matrix_stack.cpp +++ b/source/modules/asura-core/graphics/matrix_stack.cpp @@ -55,6 +55,22 @@ namespace AsuraEngine void MatrixStack::Ortho(float left, float right, float bottom, float top, float near, float far) { + mStack[this->top].Ortho(left, right, bottom, top, near, far); + } + + void MatrixStack::Rotate(float angle, float x, float y, float z) + { + mStack[top].Rotate(angle); + } + + void MatrixStack::Translate(float x, float y) + { + mStack[top].Translate(x, y); + } + + void MatrixStack::Scale(float x, float y, float z) + { + mStack[top].Scale(x, y); } } diff --git a/source/modules/asura-core/graphics/matrix_stack.h b/source/modules/asura-core/graphics/matrix_stack.h index db7248b..c8ab3d6 100644 --- a/source/modules/asura-core/graphics/matrix_stack.h +++ b/source/modules/asura-core/graphics/matrix_stack.h @@ -44,7 +44,7 @@ namespace AsuraEngine /// 任 /// void Rotate(float angle, float x, float y, float z); - void Translate(float x, float y, float z); + void Translate(float x, float y); void Scale(float x, float y, float z); /// diff --git a/source/modules/asura-core/graphics/mesh2d.h b/source/modules/asura-core/graphics/mesh2d.h index 226b9f6..87f0d4b 100644 --- a/source/modules/asura-core/graphics/mesh2d.h +++ b/source/modules/asura-core/graphics/mesh2d.h @@ -1,13 +1,19 @@ #ifndef __ASURA_ENGINE_MESH2D_H__ #define __ASURA_ENGINE_MESH2D_H__ +#include <vector> + #include <asura-utils/scripting/portable.hpp> +#include <asura-utils/math/vector2.hpp> + +#include "color.h" +#include "gpu_buffer.h" namespace AsuraEngine { namespace Graphics { - + /// /// 2D meshһЩ㶯 /// @@ -16,12 +22,24 @@ namespace AsuraEngine { public: - LUAX_DECL_FACTORY(Mesh2D); - Mesh2D(); ~Mesh2D(); + private: + + //----------------------------------------------------------------------------// + + LUAX_DECL_FACTORY(Mesh2D); + + //----------------------------------------------------------------------------// + + /// + /// mesh2d dataйvbo ebo + /// + GPUBuffer* mVBO; + GPUBuffer* mEBO; + }; } diff --git a/source/modules/asura-core/graphics/shader.cpp b/source/modules/asura-core/graphics/shader.cpp index e6779df..662ce5e 100644 --- a/source/modules/asura-core/graphics/shader.cpp +++ b/source/modules/asura-core/graphics/shader.cpp @@ -1,5 +1,6 @@ #include <asura-utils/exceptions/exception.h> +#include "gl.h" #include "shader.h" using namespace std; @@ -9,6 +10,17 @@ namespace AsuraEngine namespace Graphics { + /// + /// texture unit + /// + static int _texture_unit = 0; + + const char* Shader::ASLSemantics[] = { + "asura_model_matrix", // BUILTIN_UNIFORM_MODEL_MATRIX + "asura_view_matrix", // BUILTIN_UNIFORM_VIEW_MATRIX + "asura_projection_matrix", // BUILTIN_UNIFORM_PROJECTION_MATRIX + }; + Shader::Shader() { } @@ -85,13 +97,33 @@ namespace AsuraEngine throw Exception("Link shader program failed:\n%s", warnning.c_str()); } + // mvplocation + mMVP[MATRIX_MODE_MODEL] = glGetUniformLocation(mProgram, ASLSemantics[BUILTIN_UNIFORM_MODEL_MATRIX]); + mMVP[MATRIX_MODE_VIEW] = glGetUniformLocation(mProgram, ASLSemantics[BUILTIN_UNIFORM_VIEW_MATRIX]); + mMVP[MATRIX_MODE_PROJECTION] = glGetUniformLocation(mProgram, ASLSemantics[BUILTIN_UNIFORM_PROJECTION_MATRIX]); + return true; } + void Shader::OnUse() + { + _texture_unit = 0; + SetBuiltInUniforms(); + } + + void Shader::OnUnuse() + { + _texture_unit = 0; + } + + int Shader::GetAttributeLocation(const std::string& name) + { + GLint loc = glGetAttribLocation(mProgram, name.c_str()); + return loc; + } + uint Shader::GetUniformLocation(const std::string& uniform) { - // 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; } @@ -102,7 +134,7 @@ namespace AsuraEngine return loc != -1; } - GLuint Shader::GetGLProgramHandle() + GLuint Shader::GetGLProgram() { return mProgram; } @@ -113,10 +145,23 @@ namespace AsuraEngine glUniform1f(loc, value); } - void Shader::SetUniformTexture(uint loc, const Texture& texture) + bool Shader::SetUniformTexture(uint loc, const Texture& texture) { - if (gl.state.shader == this) - glUniform1i(loc, texture.GetGLTextureHandle()); + if (gl.state.shader != this) + return false; + + gl.WipeError(); + glActiveTexture(GL_TEXTURE0 + _texture_unit); + if (gl.HasError()) + return false; + GLint tex = texture.GetGLTexture(); + glBindTexture(GL_TEXTURE_2D, tex); + if (gl.HasError()) + return false; + glUniform1i(loc, _texture_unit); + if (gl.HasError()) + return false; + ++_texture_unit; } void Shader::SetUniformVector2(uint loc, const Math::Vector2f& vec2) @@ -143,6 +188,14 @@ namespace AsuraEngine glUniformMatrix4fv(loc, 1, GL_FALSE, mat.GetElements()); } + void Shader::SetBuiltInUniforms() + { + // model\view\projection matrix + SetUniformMatrix44(mMVP[MATRIX_MODE_MODEL], gl.GetMatrix(MATRIX_MODE_MODEL)); + SetUniformMatrix44(mMVP[MATRIX_MODE_VIEW], gl.GetMatrix(MATRIX_MODE_VIEW)); + SetUniformMatrix44(mMVP[MATRIX_MODE_PROJECTION], gl.GetMatrix(MATRIX_MODE_PROJECTION)); + } + //void Shader::GetUniform() //{ // //if(gl.state.shader == this) diff --git a/source/modules/asura-core/graphics/shader.h b/source/modules/asura-core/graphics/shader.h index 9cf9653..12d2f59 100644 --- a/source/modules/asura-core/graphics/shader.h +++ b/source/modules/asura-core/graphics/shader.h @@ -14,15 +14,25 @@ #include <asura-utils/stringmap.hpp> #include <asura-utils/manager.hpp> +#include "gl.h" #include "color.h" #include "texture.h" -#include "gl.h" +#include "gpu_buffer.h" namespace AsuraEngine { namespace Graphics { + enum BuiltInUniforms + { + BUILTIN_UNIFORM_MODEL_MATRIX = 0, + BUILTIN_UNIFORM_VIEW_MATRIX, + BUILTIN_UNIFORM_PROJECTION_MATRIX, + + BUILTIN_UNIFORM_COUNT + }; + /// /// һshaderһڲʼ乲ijShaderuniformsͶݣֻṩ /// uniformsuseɫķ༭ÿshaderͨshaderҵuniforms @@ -40,15 +50,33 @@ namespace AsuraEngine bool Load(const std::string& vert, const std::string& frag); - uint GetAttributeLocation(const std::string& name); + void OnUse(); + void OnUnuse(); + + /// + /// öԣAsuraֻ֧2ά + /// + int GetAttributeLocation(const std::string& name); + void SetAttribute(int loc, void* data, uint offset = 0, uint stride = 0); + void SetAttribute(int loc, GPUBuffer* vbo, uint offset = 0, uint stride = 0); + /// + /// uniform + /// + bool HasUniform(const std::string& uniform); + uint GetUniformLocation(const std::string& uniform); void SetUniformFloat(uint loc, float value); - void SetUniformTexture(uint loc, const Texture& texture); void SetUniformVector2(uint loc, const Math::Vector2f& vec2); void SetUniformVector3(uint loc, const Math::Vector3f& vec3); void SetUniformVector4(uint loc, const Math::Vector4f& vec4); void SetUniformColor(uint loc, const Color& color); void SetUniformMatrix44(uint loc, const Math::Matrix44& mat44); + bool SetUniformTexture(uint loc, const Texture& texture); + + /// + /// \uniform + /// + void SetBuiltInUniforms(); float GetUniformFloat(uint loc); AEMath::Vector2f GetUniformVector2(uint loc); @@ -56,22 +84,12 @@ namespace AsuraEngine AEMath::Vector4f GetUniformVector4s(uint loc); AEMath::Matrix44 GetUniformMatrix44(uint loc); - uint GetUniformLocation(const std::string& uniform); - - bool HasUniform(const std::string& uniform); - - GLuint GetGLProgramHandle(); + GLuint GetGLProgram(); static uint GetGLTextureUnitCount(); private: - GLuint mProgram; - GLuint mVertShader; - GLuint mFragShader; - - private: - //----------------------------------------------------------------------------// LUAX_DECL_FACTORY(Shader); @@ -95,6 +113,25 @@ namespace AsuraEngine std::string GetProgramWarnings(); std::string GetShaderWarnings(GLuint shader); + + /// + /// Asura shader ַͳһ + /// + static const char* ASLSemantics[BUILTIN_UNIFORM_COUNT]; + + GLuint mProgram; + GLuint mVertShader; + GLuint mFragShader; + + /// + /// Model\View\Projection matrix uniformlocationAsuraҪshader + /// 壺 + /// 1: asura_model_matrix ģ; + /// 2: asura_view_matrix ۲߾ + /// 3: asura_projection_matrix ͶӰ + /// frameworkø壬ֵϷͱ༭еġ + /// + GLint mMVP[3]; }; diff --git a/source/modules/asura-core/graphics/texture.cpp b/source/modules/asura-core/graphics/texture.cpp index 38a75d7..522ba95 100644 --- a/source/modules/asura-core/graphics/texture.cpp +++ b/source/modules/asura-core/graphics/texture.cpp @@ -23,7 +23,7 @@ namespace AsuraEngine glDeleteTextures(1, &mTex); } - GLuint Texture::GetGLTextureHandle() const + GLuint Texture::GetGLTexture() const { return mTex; } diff --git a/source/modules/asura-core/graphics/texture.h b/source/modules/asura-core/graphics/texture.h index 4a414b4..333a8c6 100644 --- a/source/modules/asura-core/graphics/texture.h +++ b/source/modules/asura-core/graphics/texture.h @@ -66,7 +66,7 @@ namespace AsuraEngine Texture(); virtual ~Texture(); - GLuint GetGLTextureHandle() const; + GLuint GetGLTexture() const; void SetFilterMode(FilterMode min, FilterMode mag); void SetWrapMode(WrapMode wrapMode); @@ -82,12 +82,12 @@ namespace AsuraEngine /// /// ȾtexturertϣԭϽǣң /// - virtual void Render(const RenderTarget* rt, const RenderState& state) = 0; + //virtual void Render(const RenderTarget* rt, const RenderState& state) = 0; /// /// ȾtextureһֵrtϣԭϽǣң졣 /// - virtual void Render(const RenderTarget* rt, const AEMath::Rectf& quad, const RenderState& state) = 0; + //virtual void Render(const RenderTarget* rt, const AEMath::Rectf& quad, const RenderState& state) = 0; protected: diff --git a/source/modules/asura-core/image/image_decoder.h b/source/modules/asura-core/image/image_decoder.h index 8b82d2b..f752826 100644 --- a/source/modules/asura-core/image/image_decoder.h +++ b/source/modules/asura-core/image/image_decoder.h @@ -20,12 +20,12 @@ namespace AsuraEngine /// /// жڴǷñdecoderѹ /// - virtual bool CanDecode(AEIO::DataBuffer& buffer) = 0; + virtual bool CanDecode(AEIO::DataBuffer& input) = 0; /// /// һڴ棬һѹImage dataѹʧܷnullptr /// - virtual void Decode(AEIO::DataBuffer& buffer, ImageData& data) = 0; + virtual void Decode(AEIO::DataBuffer& input, ImageData& target) = 0; }; diff --git a/source/modules/asura-core/mesh/am2_handler.cpp b/source/modules/asura-core/mesh/am2_handler.cpp new file mode 100644 index 0000000..fce7817 --- /dev/null +++ b/source/modules/asura-core/mesh/am2_handler.cpp @@ -0,0 +1,36 @@ +#include "am2_handler.h" + +namespace AsuraEngine +{ + namespace Mesh + { +/* +Asuramesh2DʽΪ.am2ʽ¡ +ͷ11ֽڱһAsuraMesh2Dļ +ASURAMESH2D +v position +t tangent +n normal +[c color] +[u texcoord0] +[u texcoord1] +[u texcoord2] +[u texcoord3] + +f surface + + +ASURAMESH2D +p0 +v 0, 0 +t -0.2, 0.45 +n -0.3, 0.6 +p1 + + +*/ + + + + } +} diff --git a/source/modules/asura-core/mesh/am2_handler.h b/source/modules/asura-core/mesh/am2_handler.h new file mode 100644 index 0000000..de93be9 --- /dev/null +++ b/source/modules/asura-core/mesh/am2_handler.h @@ -0,0 +1,32 @@ +#ifndef __ASURA_MESH2D_AM2_HANDLER_H__ +#define __ASURA_MESH2D_AM2_HANDLER_H__ + +#include "mesh2d_handler.h" + +namespace AsuraEngine +{ + namespace Mesh + { + + /// + /// Asura Mesh Format handlerAsura.am2ʽmeshļ + /// + class AM2Handler ASURA_FINAL : public Mesh2DHandler + { + public: + + AM2Handler(); + ~AM2Handler(); + + bool CanDecode(AEIO::DataBuffer& input) override; + + void Decode(AEIO::DataBuffer& input, Mesh2DData& target) override; + + void Encode(Mesh2DData& input, AEIO::DataBuffer& target) override; + + }; + + } +} + +#endif
\ No newline at end of file diff --git a/source/modules/asura-core/mesh/mesh2d_data.h b/source/modules/asura-core/mesh/mesh2d_data.h index e69de29..ad4b6c8 100644 --- a/source/modules/asura-core/mesh/mesh2d_data.h +++ b/source/modules/asura-core/mesh/mesh2d_data.h @@ -0,0 +1,58 @@ +#ifndef __ASURA_MESH2D_DATA_H__ +#define __ASURA_MESH2D_DATA_H__ + +#include <asura-utils/scripting/portable.hpp> +#include <asura-utils/math/vector2.hpp> +#include <asura-utils/io/decoded_data.h> + +#include <vector> + +#include "../graphics/color.h" +#include "../graphics/gpu_buffer.h" + +namespace AsuraEngine +{ + namespace Mesh + { + + /// + /// Mesh2DĶݣindexʹáAsura 2D mesh֧4UVһϡ + /// + struct Vertex + { + AEMath::Vector2f position; ///< + AEMath::Vector2f tangent; ///< + AEMath::Vector2f normal; ///< + AEGraphics::Color color; ///< ɫ + AEMath::Vector2f texCoord[4]; ///< UVs + }; + + /// + /// meshĶݺ + /// + class Mesh2DData + : AEIO::DecodedData + , AEScripting::Portable<Mesh2DData> + { + public: + + void Decode(AEIO::DataBuffer& buffer) override; + + private: + + /// + /// meshж㡣 + /// + std::vector<Vertex*> mVertices; + + /// + /// ebo + /// + std::vector<float> mIndices; + + }; + + } +} + +#endif
\ No newline at end of file diff --git a/source/modules/asura-core/mesh/mesh2d_handler.cpp b/source/modules/asura-core/mesh/mesh2d_handler.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/modules/asura-core/mesh/mesh2d_handler.cpp diff --git a/source/modules/asura-core/mesh/mesh2d_handler.h b/source/modules/asura-core/mesh/mesh2d_handler.h new file mode 100644 index 0000000..05e12f0 --- /dev/null +++ b/source/modules/asura-core/mesh/mesh2d_handler.h @@ -0,0 +1,34 @@ +#ifndef __ASURA_MESH2D_HANDLER_H__ +#define __ASURA_MESH2D_HANDLER_H__ + +#include <asura-utils/io/data_buffer.h> +#include <asura-utils/type.h> + +#include "mesh2d_data.h" + +namespace AsuraEngine +{ + namespace Mesh + { + + /// + /// ͱmesh + /// + ASURA_ABSTRACT class Mesh2DHandler + { + public: + Mesh2DHandler() {}; + virtual ~Mesh2DHandler() {}; + + virtual bool CanDecode(AEIO::DataBuffer& input) = 0; + + virtual void Decode(AEIO::DataBuffer& input, Mesh2DData& target) = 0; + + virtual void Encode(Mesh2DData& input, AEIO::DataBuffer& target) = 0; + + }; + + } +} + +#endif
\ No newline at end of file diff --git a/source/modules/asura-core/mesh/obj_handler.cpp b/source/modules/asura-core/mesh/obj_handler.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/modules/asura-core/mesh/obj_handler.cpp diff --git a/source/modules/asura-core/mesh/obj_handler.h b/source/modules/asura-core/mesh/obj_handler.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/modules/asura-core/mesh/obj_handler.h |