diff options
Diffstat (limited to 'source/modules/asura-core')
23 files changed, 127 insertions, 94 deletions
diff --git a/source/modules/asura-core/core_module.cpp b/source/modules/asura-core/core_module.cpp index 989ec3e..e91dd8f 100644 --- a/source/modules/asura-core/core_module.cpp +++ b/source/modules/asura-core/core_module.cpp @@ -10,7 +10,7 @@ namespace AsuraEngine { // Graphics LUAX_REGISTER_ABSTRACT_FACTORY(state, Texture); - LUAX_REGISTER_FACTORY(state, Image); + LUAX_REGISTER_FACTORY(state, AEGraphics::Image); // Wnd LUAX_REGISTER_SINGLETON(state, AEWindow::Window); // Threading diff --git a/source/modules/asura-core/graphics/canvas.h b/source/modules/asura-core/graphics/canvas.h index 49096c7..4175561 100644 --- a/source/modules/asura-core/graphics/canvas.h +++ b/source/modules/asura-core/graphics/canvas.h @@ -47,19 +47,10 @@ namespace AsuraEngine private: - /// - /// Frame buffer object id. - /// GLuint mFBO; - /// - /// tex - /// GLuint mTex; - /// - /// canvasĴС - /// uint mWidth, mHeight; public: diff --git a/source/modules/asura-core/graphics/gfx_device.h b/source/modules/asura-core/graphics/gfx_device.h index 5bb8c6a..c93717f 100644 --- a/source/modules/asura-core/graphics/gfx_device.h +++ b/source/modules/asura-core/graphics/gfx_device.h @@ -46,14 +46,8 @@ namespace AsuraEngine GfxDevice(); ~GfxDevice(); - /// - /// óֵ - /// int GetParam(GLParams param); - /// - /// ʼOpenGLIJڴOpenGL֮˺עOpenGLĵַ - /// bool Init(const AEMath::Recti& viewport); bool Inited(); @@ -64,12 +58,8 @@ namespace AsuraEngine void UnuseShader(); Shader* GetShader(); - // Draw call. void DrawArrays(GLenum mode, GLint first, GLsizei count); - /// - /// Matrix stackز - /// void SetMatrixMode(MatrixMode mode); MatrixMode GetMatrixMode(); void PushMatrix(); @@ -87,20 +77,10 @@ namespace AsuraEngine void SetDrawColor(float r, float g, float b, float a); Color& GetDrawColor(); - /// - /// ʾ - /// void WipeError(); bool HasError(); GLenum GetError(); - /// - /// OpenGL3.0Ժû任ӿڡshaderȲﱣһЩOpenGL״̬ע - /// ƺȫ̵ģҲ˵Asuraֶ֧߳ȾOpenGLĵĴʹһ - /// İһHDC\ϣڴض̴߳ģOpenGLҲһ - /// ض̡߳ͬһ̵߳IJͬHDC\ڿԹͬһOpenGLġΪ - /// дtextuer\shaderhandle - /// struct { Shader* shader; ///< ǰʹõshader @@ -113,9 +93,9 @@ namespace AsuraEngine #if ASURA_GL_PROFILE struct { - uint drawCall; ///< ͳdrawcall - uint canvasSwitch; ///< лtextureĴ - uint shaderSwitch; ///< лshaderĴ + uint drawCall; ///< ͳdrawcall + uint canvasSwitch; ///< лtextureĴ + uint shaderSwitch; ///< лshaderĴ } stats; #endif diff --git a/source/modules/asura-core/graphics/image.cpp b/source/modules/asura-core/graphics/image.cpp index d2f1d7b..42fc2ab 100644 --- a/source/modules/asura-core/graphics/image.cpp +++ b/source/modules/asura-core/graphics/image.cpp @@ -7,6 +7,7 @@ #include "gfx_device.h" using namespace AEIO; +using namespace AEImage; namespace AsuraEngine { diff --git a/source/modules/asura-core/graphics/image.h b/source/modules/asura-core/graphics/image.h index 932ca65..8e3e7d3 100644 --- a/source/modules/asura-core/graphics/image.h +++ b/source/modules/asura-core/graphics/image.h @@ -44,8 +44,8 @@ namespace AsuraEngine /// ͼύGPUϢ¹imageʹglTexImage2D /// ύimageݡ /// - bool Load(ImageData* decodeData); - bool Load(ImageData* decodeData, const AEMath::Vector2i& pos); + bool Load(AEImage::ImageData* decodeData); + bool Load(AEImage::ImageData* decodeData, const AEMath::Vector2i& pos); uint GetWidth(); uint GetHeight(); diff --git a/source/modules/asura-core/graphics/shader.cpp b/source/modules/asura-core/graphics/shader.cpp index 866c4da..afd10b0 100644 --- a/source/modules/asura-core/graphics/shader.cpp +++ b/source/modules/asura-core/graphics/shader.cpp @@ -21,74 +21,97 @@ namespace AsuraEngine Shader::~Shader() { - if(mVertShader != 0) - glDeleteShader(mVertShader); - if(mFragShader != 0) - glDeleteShader(mFragShader); - if(mProgram != 0) - glDeleteProgram(mProgram); + if(mVertShader) glDeleteShader(mVertShader); + if(mFragShader) glDeleteShader(mFragShader); + if(mProgram) glDeleteProgram(mProgram); } bool Shader::Load(const string& vert, const string& frag) { - GLenum err = GL_NO_ERROR; - GLint success; string warnning = ""; - if (mProgram == 0) + if (!mProgram) { mProgram = glCreateProgram(); - if (mProgram == 0) + if (!mProgram) throw Exception("Cannot create OpenGL shader program."); } - if (mVertShader == 0) + if (!CompileVertexShader(vert, warnning)) { - mVertShader = glCreateShader(GL_VERTEX_SHADER); - if (mVertShader == 0) - throw Exception("Cannot create OpenGL vertex shader."); + throw Exception("Compile vertex shader failed:%s", warnning); } - if (mFragShader == 0) + if (!CompileFragementShader(frag, warnning)) { - mFragShader = glCreateShader(GL_FRAGMENT_SHADER); - if(mFragShader == 0) - throw Exception("Cannot create OpenGL fragment shader."); + throw Exception("Compile fragment shader failed:%s", warnning); } - const GLchar* source; + glAttachShader(mProgram, mVertShader); + glAttachShader(mProgram, mFragShader); + + glLinkProgram(mProgram); + GLint success; + glGetProgramiv(mProgram, GL_LINK_STATUS, &success); + if (success == GL_FALSE) + { + warnning = GetProgramWarnings(); + throw Exception("Link shader program failed:\n%s", warnning.c_str()); + } + + return true; + } + + bool Shader::CompileVertexShader(const string& vert, string& outError) + { + if (!mVertShader) + { + mVertShader = glCreateShader(GL_VERTEX_SHADER); + if (!mVertShader) + { + outError = "Cannot create OpenGL Vertex shader."; + return false; + } + } + + const GLchar* source = vert.c_str(); + GLint success; - // Compile vertex shader. - source = vert.c_str(); glShaderSource(mVertShader, 1, &source, NULL); glCompileShader(mVertShader); glGetShaderiv(mVertShader, GL_COMPILE_STATUS, &success); if (success == GL_FALSE) { - warnning = GetShaderWarnings(mVertShader); - throw Exception("Compile vertex shader failed:\n%s", warnning.c_str()); + outError = GetShaderWarnings(mVertShader); + return false; } - // Compile fragment shader. + return true; + } + + bool Shader::CompileFragementShader(const string& frag, string& outError) + { + if (!mFragShader) + { + mFragShader = glCreateShader(GL_FRAGMENT_SHADER); + if (!mFragShader) + { + outError = "Cannot create OpenGL fragment shader."; + return false; + } + } + + const GLchar* source = frag.c_str(); + GLint success; + source = frag.c_str(); glShaderSource(mFragShader, 1, &source, NULL); glCompileShader(mFragShader); glGetShaderiv(mFragShader, GL_COMPILE_STATUS, &success); if (success == GL_FALSE) { - warnning = GetShaderWarnings(mFragShader); - throw Exception("Compile fragment shader failed:\n%s", warnning.c_str()); - } - - // Link program. - glAttachShader(mProgram, mVertShader); - glAttachShader(mProgram, mFragShader); - glLinkProgram(mProgram); - glGetProgramiv(mProgram, GL_LINK_STATUS, &success); - if (success == GL_FALSE) - { - warnning = GetProgramWarnings(); - throw Exception("Link shader program failed:\n%s", warnning.c_str()); + outError = GetShaderWarnings(mFragShader); + return false; } return true; diff --git a/source/modules/asura-core/graphics/shader.h b/source/modules/asura-core/graphics/shader.h index b5d866e..f4553ec 100644 --- a/source/modules/asura-core/graphics/shader.h +++ b/source/modules/asura-core/graphics/shader.h @@ -45,12 +45,10 @@ namespace AsuraEngine void OnUse(); void OnUnuse(); - /// void SetAttribute(int loc, VertexBuffer* vbo, uint offseti = 0, uint stridei = 0, bool normalized = false); int GetAttributeLocation(const std::string& attribute); void DisableAttribute(int loc); - /// Uniform bool HasUniform(const std::string& uniform); uint GetUniformLocation(const std::string& uniform); void SetUniformFloat(uint loc, float value); @@ -88,15 +86,18 @@ namespace AsuraEngine LUAX_DECL_METHOD(_SetUniformVector3); LUAX_DECL_METHOD(_SetUniformVector4); LUAX_DECL_METHOD(_SetUniformColor); - /// vertex attributes + LUAX_DECL_METHOD(_GetAttributeLocation); LUAX_DECL_METHOD(_SetAttribute); LUAX_DECL_METHOD(_DisableAttribute); - /// uniform + LUAX_DECL_METHOD(_SetBuiltInUniforms); //----------------------------------------------------------------------------// + bool CompileVertexShader(const std::string& vert, std::string& outError); + bool CompileFragementShader(const std::string& frag, std::string& outError); + std::string GetProgramWarnings(); std::string GetShaderWarnings(GLuint shader); diff --git a/source/modules/asura-core/image/binding/_image_data.cpp b/source/modules/asura-core/image/binding/_image_data.cpp index ac9473b..1030e93 100644 --- a/source/modules/asura-core/image/binding/_image_data.cpp +++ b/source/modules/asura-core/image/binding/_image_data.cpp @@ -9,7 +9,7 @@ using namespace AEIO; namespace AsuraEngine { - namespace Graphics + namespace Image { LUAX_REGISTRY(ImageData) diff --git a/source/modules/asura-core/image/binding/_image_decode_task.cpp b/source/modules/asura-core/image/binding/_image_decode_task.cpp index 76b544b..a0caddf 100644 --- a/source/modules/asura-core/image/binding/_image_decode_task.cpp +++ b/source/modules/asura-core/image/binding/_image_decode_task.cpp @@ -4,7 +4,7 @@ using namespace std; namespace AsuraEngine { - namespace Graphics + namespace Image { LUAX_REGISTRY(ImageDecodeTask) diff --git a/source/modules/asura-core/image/image_data.cpp b/source/modules/asura-core/image/image_data.cpp index 1a6d3a2..b35c4b2 100644 --- a/source/modules/asura-core/image/image_data.cpp +++ b/source/modules/asura-core/image/image_data.cpp @@ -3,13 +3,15 @@ #include "stb_decoder.h" #include "image_decoder.h" +using namespace std; + +using namespace AEGraphics; + namespace AsuraEngine { - namespace Graphics + namespace Image { - using namespace std; - // imagedecoderΪԡ list<ImageDecoder*> ImageData::ImageDecoders = { new PNGDecoder(), // png diff --git a/source/modules/asura-core/image/image_data.h b/source/modules/asura-core/image/image_data.h index b05507a..c377407 100644 --- a/source/modules/asura-core/image/image_data.h +++ b/source/modules/asura-core/image/image_data.h @@ -14,7 +14,7 @@ namespace AsuraEngine { - namespace Graphics + namespace Image { class ImageDecoder; @@ -36,12 +36,12 @@ namespace AsuraEngine void Lock(); void Unlock(); - Color GetPixel(uint x, uint y); + AEGraphics::Color GetPixel(uint x, uint y); //----------------------------------------------------------------------------// uint width, height; // سߴ - ColorFormat format; // ʽ + AEGraphics::ColorFormat format; // ʽ byte* pixels; // std::size_t size; // ݳ @@ -80,6 +80,6 @@ namespace AsuraEngine } } -namespace AEGraphics = AsuraEngine::Graphics; +namespace AEImage = AsuraEngine::Image; #endif
\ No newline at end of file diff --git a/source/modules/asura-core/image/image_decode_task.cpp b/source/modules/asura-core/image/image_decode_task.cpp index e69de29..954749a 100644 --- a/source/modules/asura-core/image/image_decode_task.cpp +++ b/source/modules/asura-core/image/image_decode_task.cpp @@ -0,0 +1,19 @@ +#include "image_decode_task.h" + +namespace AsuraEngine +{ + namespace Image + { + + bool ImageDecodeTask::Execute() + { + return false; + } + + void ImageDecodeTask::Invoke(lua_State* invokeThreaad) + { + + } + + } +}
\ No newline at end of file diff --git a/source/modules/asura-core/image/image_decode_task.h b/source/modules/asura-core/image/image_decode_task.h index 666d00f..fc695fa 100644 --- a/source/modules/asura-core/image/image_decode_task.h +++ b/source/modules/asura-core/image/image_decode_task.h @@ -6,7 +6,7 @@ namespace AsuraEngine { - namespace Graphics + namespace Image { class ImageDecodeTask @@ -14,7 +14,19 @@ namespace AsuraEngine { public: - LUAX_DECL_FACTORY(ImageDecodeTask); + /// + /// ִɺtrueûص + /// + bool Execute() override; + + /// + /// ûصinvoke threadص + /// + void Invoke(lua_State* invokeThreaad) override; + + private: + + LUAX_DECL_FACTORY(ImageDecodeTask, AEThreading::Task); }; diff --git a/source/modules/asura-core/image/image_decoder.h b/source/modules/asura-core/image/image_decoder.h index f752826..15efff7 100644 --- a/source/modules/asura-core/image/image_decoder.h +++ b/source/modules/asura-core/image/image_decoder.h @@ -7,7 +7,7 @@ namespace AsuraEngine { - namespace Graphics + namespace Image { ASURA_ABSTRACT class ImageDecoder diff --git a/source/modules/asura-core/image/png_decoder.cpp b/source/modules/asura-core/image/png_decoder.cpp index 80463d5..a76af80 100644 --- a/source/modules/asura-core/image/png_decoder.cpp +++ b/source/modules/asura-core/image/png_decoder.cpp @@ -2,7 +2,7 @@ namespace AsuraEngine { - namespace Graphics + namespace Image { bool PNGDecoder::CanDecode(AEIO::DataBuffer& buffer) diff --git a/source/modules/asura-core/image/png_decoder.h b/source/modules/asura-core/image/png_decoder.h index 6377940..24e40c5 100644 --- a/source/modules/asura-core/image/png_decoder.h +++ b/source/modules/asura-core/image/png_decoder.h @@ -5,7 +5,7 @@ namespace AsuraEngine { - namespace Graphics + namespace Image { /// diff --git a/source/modules/asura-core/image/stb_decoder.cpp b/source/modules/asura-core/image/stb_decoder.cpp index b19f28b..add1c13 100644 --- a/source/modules/asura-core/image/stb_decoder.cpp +++ b/source/modules/asura-core/image/stb_decoder.cpp @@ -5,9 +5,11 @@ #define STB_IMAGE_IMPLEMENTATION #include <stb/stb_image.h> +using namespace AEGraphics; + namespace AsuraEngine { - namespace Graphics + namespace Image { bool STBDecoder::CanDecode(IO::DataBuffer& buffer) diff --git a/source/modules/asura-core/image/stb_decoder.h b/source/modules/asura-core/image/stb_decoder.h index 76e70c3..ad89214 100644 --- a/source/modules/asura-core/image/stb_decoder.h +++ b/source/modules/asura-core/image/stb_decoder.h @@ -5,7 +5,7 @@ namespace AsuraEngine { - namespace Graphics + namespace Image { /// diff --git a/source/modules/asura-core/profiler/gpu_profiler.cpp b/source/modules/asura-core/profiler/gpu_profiler.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/modules/asura-core/profiler/gpu_profiler.cpp diff --git a/source/modules/asura-core/profiler/gpu_profiler.h b/source/modules/asura-core/profiler/gpu_profiler.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/modules/asura-core/profiler/gpu_profiler.h diff --git a/source/modules/asura-core/window/binding/_window.cpp b/source/modules/asura-core/window/binding/_window.cpp index e477408..cff1dd3 100644 --- a/source/modules/asura-core/window/binding/_window.cpp +++ b/source/modules/asura-core/window/binding/_window.cpp @@ -4,6 +4,7 @@ using namespace std; using namespace AEGraphics; +using namespace AEImage; namespace AsuraEngine { diff --git a/source/modules/asura-core/window/window.h b/source/modules/asura-core/window/window.h index 61adae1..d0f62c1 100644 --- a/source/modules/asura-core/window/window.h +++ b/source/modules/asura-core/window/window.h @@ -48,7 +48,7 @@ namespace AsuraEngine int x, y; ///< ڳʼ std::string title; ///< bool vsync; ///< ֱͬ - AEGraphics::ImageData* icon; ///< ͼ + AEImage::ImageData* icon; ///< ͼ bool show; ///< Ƿʾ int flag; ///< ڱ }; @@ -80,7 +80,7 @@ namespace AsuraEngine void SetSize(uint width, uint height); void SetPosition(int x, int y); void SetTitle(const std::string& title); - void SetIcon(AEGraphics::ImageData* imgData); + void SetIcon(AEImage::ImageData* imgData); void Show(); void Hide(); diff --git a/source/modules/asura-core/window/window_impl_sdl.cpp b/source/modules/asura-core/window/window_impl_sdl.cpp index 9554e37..2679bc1 100644 --- a/source/modules/asura-core/window/window_impl_sdl.cpp +++ b/source/modules/asura-core/window/window_impl_sdl.cpp @@ -9,6 +9,7 @@ #include "window_impl_sdl.h" using namespace AEGraphics; +using namespace AEImage; namespace AsuraEngine { |