From 250e30d73f09e9da2b5a81d0fbae63744ae12a73 Mon Sep 17 00:00:00 2001 From: chai Date: Tue, 2 Apr 2019 08:47:15 +0800 Subject: *misc --- .../asura-core/graphics/binding/_canvas.cpp | 3 + .../asura-core/graphics/binding/_color32.cpp | 6 +- .../asura-core/graphics/binding/_image_data.cpp | 111 --------------------- .../graphics/binding/_image_decode_task.cpp | 21 ---- .../asura-core/graphics/binding/_shader.cpp | 18 +++- source/modules/asura-core/graphics/canvas.cpp | 13 +-- source/modules/asura-core/graphics/color.cpp | 15 ++- source/modules/asura-core/graphics/gl.cpp | 17 ++++ source/modules/asura-core/graphics/gl.h | 19 +++- source/modules/asura-core/graphics/image.cpp | 15 ++- source/modules/asura-core/graphics/image.h | 8 +- source/modules/asura-core/graphics/image_data.cpp | 67 ------------- source/modules/asura-core/graphics/image_data.h | 85 ---------------- .../asura-core/graphics/image_decode_task.cpp | 0 .../asura-core/graphics/image_decode_task.h | 25 ----- source/modules/asura-core/graphics/image_decoder.h | 35 ------- source/modules/asura-core/graphics/mesh2d.h | 2 + source/modules/asura-core/graphics/mesh2d_data.cpp | 0 source/modules/asura-core/graphics/mesh2d_data.h | 0 source/modules/asura-core/graphics/png_decoder.cpp | 19 ---- source/modules/asura-core/graphics/png_decoder.h | 27 ----- source/modules/asura-core/graphics/render_target.h | 2 - source/modules/asura-core/graphics/shader.cpp | 11 +- source/modules/asura-core/graphics/sprite_batch.h | 2 + source/modules/asura-core/graphics/stb_decoder.cpp | 70 ------------- source/modules/asura-core/graphics/stb_decoder.h | 28 ------ source/modules/asura-core/graphics/texture.cpp | 19 ++++ source/modules/asura-core/graphics/texture.h | 18 ++++ 28 files changed, 125 insertions(+), 531 deletions(-) delete mode 100644 source/modules/asura-core/graphics/binding/_image_data.cpp delete mode 100644 source/modules/asura-core/graphics/binding/_image_decode_task.cpp delete mode 100644 source/modules/asura-core/graphics/image_data.cpp delete mode 100644 source/modules/asura-core/graphics/image_data.h delete mode 100644 source/modules/asura-core/graphics/image_decode_task.cpp delete mode 100644 source/modules/asura-core/graphics/image_decode_task.h delete mode 100644 source/modules/asura-core/graphics/image_decoder.h delete mode 100644 source/modules/asura-core/graphics/mesh2d_data.cpp delete mode 100644 source/modules/asura-core/graphics/mesh2d_data.h delete mode 100644 source/modules/asura-core/graphics/png_decoder.cpp delete mode 100644 source/modules/asura-core/graphics/png_decoder.h delete mode 100644 source/modules/asura-core/graphics/stb_decoder.cpp delete mode 100644 source/modules/asura-core/graphics/stb_decoder.h (limited to 'source/modules/asura-core/graphics') diff --git a/source/modules/asura-core/graphics/binding/_canvas.cpp b/source/modules/asura-core/graphics/binding/_canvas.cpp index 7927995..6728ff3 100644 --- a/source/modules/asura-core/graphics/binding/_canvas.cpp +++ b/source/modules/asura-core/graphics/binding/_canvas.cpp @@ -25,6 +25,7 @@ namespace AsuraEngine LUAX_IMPL_METHOD(Canvas, _SetSize) { LUAX_PREPARE(L, Canvas); + return 0; } @@ -33,12 +34,14 @@ namespace AsuraEngine { LUAX_PREPARE(L, Canvas); + return 0; } // canvas:Unbind() LUAX_IMPL_METHOD(Canvas, _Unbind) { LUAX_PREPARE(L, Canvas); + return 0; } diff --git a/source/modules/asura-core/graphics/binding/_color32.cpp b/source/modules/asura-core/graphics/binding/_color32.cpp index ad7dad5..f2f716a 100644 --- a/source/modules/asura-core/graphics/binding/_color32.cpp +++ b/source/modules/asura-core/graphics/binding/_color32.cpp @@ -27,6 +27,7 @@ namespace AsuraEngine LUAX_IMPL_METHOD(Color32, _ToColor) { LUAX_PREPARE(L, Color32); + return 0; } @@ -34,7 +35,7 @@ namespace AsuraEngine LUAX_IMPL_METHOD(Color32, _GetRed) { LUAX_PREPARE(L, Color32); - + return 0; } // color32:GetGreen() @@ -42,6 +43,7 @@ namespace AsuraEngine { LUAX_PREPARE(L, Color32); + return 0; } // color32:GetBlue() @@ -49,6 +51,7 @@ namespace AsuraEngine { LUAX_PREPARE(L, Color32); + return 0; } // color32:GetAlpha() @@ -56,6 +59,7 @@ namespace AsuraEngine { LUAX_PREPARE(L, Color32); + return 0; } } diff --git a/source/modules/asura-core/graphics/binding/_image_data.cpp b/source/modules/asura-core/graphics/binding/_image_data.cpp deleted file mode 100644 index ac9473b..0000000 --- a/source/modules/asura-core/graphics/binding/_image_data.cpp +++ /dev/null @@ -1,111 +0,0 @@ -#include -#include - -#include "../image_data.h" - -using namespace std; -using namespace AEThreading; -using namespace AEIO; - -namespace AsuraEngine -{ - namespace Graphics - { - - LUAX_REGISTRY(ImageData) - { - LUAX_REGISTER_METHODS(state, - { "New", _New }, - { "GetPixel", _GetPixel }, - { "GetSize", _GetSize }, - { "GetWidth", _GetWidth }, - { "GetHeight", _GetHeight }, - { "GetPixelFormat", _GetPixelFormat }, - { "Decode", _Decode }, - { "DecodeAsync", _DecodeAsync }, - { "IsAvailable", _IsAvailable } - ); - } - - LUAX_POSTPROCESS(ImageData) - { - - } - - // ImageData.New() - LUAX_IMPL_METHOD(ImageData, _New) - { - LUAX_STATE(L); - - return 0; - } - - // imagedata:GetPixel() - LUAX_IMPL_METHOD(ImageData, _GetPixel) - { - LUAX_PREPARE(L, ImageData); - - return 0; - } - - // imagedata:GetSize() - LUAX_IMPL_METHOD(ImageData, _GetSize) - { - LUAX_PREPARE(L, ImageData); - - return 0; - } - - // imagedata:GetWidth() - LUAX_IMPL_METHOD(ImageData, _GetWidth) - { - LUAX_PREPARE(L, ImageData); - - return 0; - } - - // imagedata:GetHeight() - LUAX_IMPL_METHOD(ImageData, _GetHeight) - { - LUAX_PREPARE(L, ImageData); - - return 0; - } - - // imagedata:GetPixelFormat() - LUAX_IMPL_METHOD(ImageData, _GetPixelFormat) - { - LUAX_PREPARE(L, ImageData); - - return 0; - } - - // imagedata:Decode() - LUAX_IMPL_METHOD(ImageData, _Decode) - { - LUAX_PREPARE(L, ImageData); - - return 0; - } - - // imagedata:DecodeAsync(thread, databuffer, callback) - LUAX_IMPL_METHOD(ImageData, _DecodeAsync) - { - LUAX_PREPARE(L, ImageData); - - Thread* thread = state.CheckUserdata(2); - DataBuffer* buffer = state.CheckUserdata(3); - - return 0; - } - - // imagedata:IsAvailable() - LUAX_IMPL_METHOD(ImageData, _IsAvailable) - { - LUAX_PREPARE(L, ImageData); - - return 0; - } - - } -} diff --git a/source/modules/asura-core/graphics/binding/_image_decode_task.cpp b/source/modules/asura-core/graphics/binding/_image_decode_task.cpp deleted file mode 100644 index 76b544b..0000000 --- a/source/modules/asura-core/graphics/binding/_image_decode_task.cpp +++ /dev/null @@ -1,21 +0,0 @@ -#include "../image_decode_task.h" - -using namespace std; - -namespace AsuraEngine -{ - namespace Graphics - { - - LUAX_REGISTRY(ImageDecodeTask) - { - - } - - LUAX_POSTPROCESS(ImageDecodeTask) - { - - } - - } -} diff --git a/source/modules/asura-core/graphics/binding/_shader.cpp b/source/modules/asura-core/graphics/binding/_shader.cpp index a06e54b..af6e981 100644 --- a/source/modules/asura-core/graphics/binding/_shader.cpp +++ b/source/modules/asura-core/graphics/binding/_shader.cpp @@ -36,12 +36,14 @@ namespace AsuraEngine { LUAX_STATE(L); + return 0; } // shader:Use() LUAX_IMPL_METHOD(Shader, _Use) { LUAX_PREPARE(L, Shader); + return 0; } @@ -49,6 +51,7 @@ namespace AsuraEngine LUAX_IMPL_METHOD(Shader, _Unuse) { LUAX_PREPARE(L, Shader); + return 0; } @@ -57,6 +60,7 @@ namespace AsuraEngine { LUAX_PREPARE(L, Shader); + return 0; } // shader:HasUniform() @@ -64,6 +68,7 @@ namespace AsuraEngine { LUAX_PREPARE(L, Shader); + return 0; } // shader:GetUniformLocation() @@ -71,6 +76,7 @@ namespace AsuraEngine { LUAX_PREPARE(L, Shader); + return 0; } // shader:SetBuiltInUniforms() @@ -78,6 +84,7 @@ namespace AsuraEngine { LUAX_PREPARE(L, Shader); + return 0; } // shader:SetUniformFloat() @@ -85,41 +92,42 @@ namespace AsuraEngine { LUAX_PREPARE(L, Shader); + return 0; } // shader:SetUniformTexture() LUAX_IMPL_METHOD(Shader, _SetUniformTexture) { LUAX_PREPARE(L, Shader); - + return 0; } // shader:SetUniformVector2() LUAX_IMPL_METHOD(Shader, _SetUniformVector2) { LUAX_PREPARE(L, Shader); - + return 0; } // shader:SetUniformVector3() LUAX_IMPL_METHOD(Shader, _SetUniformVector3) { LUAX_PREPARE(L, Shader); - + return 0; } // shader:SetUniformVector4() LUAX_IMPL_METHOD(Shader, _SetUniformVector4) { LUAX_PREPARE(L, Shader); - + return 0; } // shader:SetUniformColor() LUAX_IMPL_METHOD(Shader, _SetUniformColor) { LUAX_PREPARE(L, Shader); - + return 0; } } diff --git a/source/modules/asura-core/graphics/canvas.cpp b/source/modules/asura-core/graphics/canvas.cpp index 8b556d9..89be45c 100644 --- a/source/modules/asura-core/graphics/canvas.cpp +++ b/source/modules/asura-core/graphics/canvas.cpp @@ -6,8 +6,7 @@ namespace AsuraEngine { Canvas::Canvas() - : Texture() - , mWidth(0) + : mWidth(0) , mHeight(0) { glGenFramebuffers(1, &mFBO); @@ -27,15 +26,5 @@ namespace AsuraEngine glBindTexture(GL_TEXTURE_2D, current_tex); } - void Canvas::Bind() - { - - } - - void Canvas::Unbind() - { - - } - } } \ No newline at end of file diff --git a/source/modules/asura-core/graphics/color.cpp b/source/modules/asura-core/graphics/color.cpp index 4d3691e..9343939 100644 --- a/source/modules/asura-core/graphics/color.cpp +++ b/source/modules/asura-core/graphics/color.cpp @@ -35,13 +35,18 @@ namespace AsuraEngine a = c.a / 255.f; } - Color Color::operator *(const Color& c) + Color::~Color() { - r *= c.r; - g *= c.g; - b *= c.b; - a *= c.a; } + //Color Color::operator *(const Color& c) + //{ + // r *= c.r; + // g *= c.g; + // b *= c.b; + // a *= c.a; + + //} + } } \ 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 41d43a3..9ffe010 100644 --- a/source/modules/asura-core/graphics/gl.cpp +++ b/source/modules/asura-core/graphics/gl.cpp @@ -3,6 +3,8 @@ #include "../core_config.h" #include "gl.h" +using namespace AEMath; + namespace AsuraEngine { namespace Graphics @@ -23,5 +25,20 @@ namespace AsuraEngine { } + //------------------------------------------------------------------------------// + + void OpenGL::SetViewport(const Recti v) + { + glViewport(v.x, v.y, v.w, v.h); + state.viewport = v; + } + + Recti OpenGL::GetViewport() + { + return state.viewport; + } + + + } } \ No newline at end of file diff --git a/source/modules/asura-core/graphics/gl.h b/source/modules/asura-core/graphics/gl.h index bfc60ea..4d21a5a 100644 --- a/source/modules/asura-core/graphics/gl.h +++ b/source/modules/asura-core/graphics/gl.h @@ -1,7 +1,9 @@ #ifndef __ASURA_ENGINE_OPENGL_H__ #define __ASURA_ENGINE_OPENGL_H__ -#include "glad/glad.h" +#include + +#include namespace AsuraEngine { @@ -11,7 +13,9 @@ namespace AsuraEngine class Profiler; /// - /// 用来做一些opengl状态的追踪。 + /// 用来做一些opengl状态的追踪。在编辑器多窗口环境下,一个窗口对应一个hwnd,一个hdc,以及 + /// 数个opengl context,如果使用wglMakeCurrent(hdc, glc)指定当前线程耳朵渲染窗口hdc和 + /// opengl上下文glc,gl中记录的就是任意一个线程的任意一个窗口的任意一个opengl上下文的状态, /// class OpenGL { @@ -19,6 +23,9 @@ namespace AsuraEngine OpenGL(); ~OpenGL(); + void SetViewport(const AEMath::Recti viewport); + AEMath::Recti GetViewport(); + private: friend class Profiler; @@ -28,6 +35,14 @@ namespace AsuraEngine /// static bool instantiated; + /// + /// 记录opengl状态。 + /// + struct + { + AEMath::Recti viewport; + } state; + }; /// diff --git a/source/modules/asura-core/graphics/image.cpp b/source/modules/asura-core/graphics/image.cpp index bdd8c3d..2b274c2 100644 --- a/source/modules/asura-core/graphics/image.cpp +++ b/source/modules/asura-core/graphics/image.cpp @@ -18,7 +18,6 @@ namespace AsuraEngine { } - //创建\更新纹理像素信息 bool Image::Refresh(DecodedData* data) { ASSERT(data); @@ -27,14 +26,22 @@ namespace AsuraEngine ASSERT(imgData); glBindTexture(GL_TEXTURE_2D, mTex); - imgData->Lock(); int width = imgData->width; int height = imgData->height; - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, imgData->pixels); + TextureFormat tf = ConvertColorFormat(imgData->format); + glTexImage2D( + GL_TEXTURE_2D + , 0 + , tf.internalformat + , width, height + , 0 + , tf.externalformat + , tf.type + , imgData->pixels + ); mImageData = imgData; imgData->Unlock(); - glBindTexture(GL_TEXTURE_2D, 0); return true; diff --git a/source/modules/asura-core/graphics/image.h b/source/modules/asura-core/graphics/image.h index 30df8c0..7795c08 100644 --- a/source/modules/asura-core/graphics/image.h +++ b/source/modules/asura-core/graphics/image.h @@ -8,10 +8,11 @@ #include #include +#include "../image/image_data.h" + #include "texture.h" #include "color.h" #include "color32.h" -#include "image_data.h" #include "render_state.h" namespace AsuraEngine @@ -50,9 +51,8 @@ namespace AsuraEngine uint GetHeight(); Color32 GetPixel(uint x, uint y); - 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 RenderState& state) override {}; + void Render(const RenderTarget* rt, const Math::Rectf& quad, const RenderState& state) override {}; private: diff --git a/source/modules/asura-core/graphics/image_data.cpp b/source/modules/asura-core/graphics/image_data.cpp deleted file mode 100644 index 64f83a8..0000000 --- a/source/modules/asura-core/graphics/image_data.cpp +++ /dev/null @@ -1,67 +0,0 @@ -#include "image_data.h" -#include "png_decoder.h" -#include "stb_decoder.h" -#include "image_decoder.h" - -namespace AsuraEngine -{ - namespace Graphics - { - - using namespace std; - - // 解析image的decoder,用来作为解析策略。 - list ImageData::ImageDecoders = { - new PNGDecoder(), // png - new STBDecoder() // jpeg, tga, bmp - }; - - ImageData::ImageData() - : pixels(nullptr) - , size(0) - , width(0) - , height(0) - , format(COLOR_FORMAT_UNKNOWN) - { - } - - ImageData::~ImageData() - { - if (pixels) - delete[] pixels; - } - - ImageData::operator bool() - { - return size > 0; - } - - void ImageData::Decode(IO::DataBuffer& buffer) - { - for (ImageDecoder* decoder : ImageDecoders) - { - if (decoder->CanDecode(buffer)) - { - decoder->Decode(buffer, *this); - return; - } - } - } - - Color ImageData::GetPixel(uint x, uint y) - { - - } - - void ImageData::Lock() - { - mMutex.Lock(); - } - - void ImageData::Unlock() - { - mMutex.Unlock(); - } - - } -} \ No newline at end of file diff --git a/source/modules/asura-core/graphics/image_data.h b/source/modules/asura-core/graphics/image_data.h deleted file mode 100644 index b9d656c..0000000 --- a/source/modules/asura-core/graphics/image_data.h +++ /dev/null @@ -1,85 +0,0 @@ -#ifndef __ASURA_ENGINE_IMAGEDATA_H__ -#define __ASURA_ENGINE_IMAGEDATA_H__ - -#include - -#include -#include -#include -#include -#include - -#include "texture.h" -#include "color.h" - -namespace AsuraEngine -{ - namespace Graphics - { - - class ImageDecoder; - - class ImageData ASURA_FINAL - : public AEIO::DecodedData - , public Scripting::Portable - { - public: - - LUAX_DECL_FACTORY(ImageData); - - /// - /// 解析图片数据文件,并构建像素信息,如果解析失败,抛出异常 - /// - ImageData(); - ~ImageData(); - - void Decode(AEIO::DataBuffer& buffer) override; - - void Lock(); - void Unlock(); - - Color GetPixel(uint x, uint y); - - //----------------------------------------------------------------------------// - - uint width, height; // 像素尺寸 - ColorFormat format; // 格式 - byte* pixels; // 像素数据 - std::size_t size; // 数据长度 - - //----------------------------------------------------------------------------// - - private: - - //----------------------------------------------------------------------------// - - LUAX_DECL_METHOD(_New); - LUAX_DECL_METHOD(_GetPixel); - LUAX_DECL_METHOD(_GetSize); - LUAX_DECL_METHOD(_GetWidth); - LUAX_DECL_METHOD(_GetHeight); - LUAX_DECL_METHOD(_GetPixelFormat); - LUAX_DECL_METHOD(_Decode); - LUAX_DECL_METHOD(_DecodeAsync); - LUAX_DECL_METHOD(_IsAvailable); - - //----------------------------------------------------------------------------// - - /// - /// 在第一次准备image data时构建所有提供的decoder。在几个decoders中间选择解析策略。 - /// - static std::list ImageDecoders; - - /// - /// 写数据的锁。 - /// - AEThreading::Mutex mMutex; - - }; - - } -} - -namespace AEGraphics = AsuraEngine::Graphics; - -#endif \ No newline at end of file diff --git a/source/modules/asura-core/graphics/image_decode_task.cpp b/source/modules/asura-core/graphics/image_decode_task.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/source/modules/asura-core/graphics/image_decode_task.h b/source/modules/asura-core/graphics/image_decode_task.h deleted file mode 100644 index ec5ed49..0000000 --- a/source/modules/asura-core/graphics/image_decode_task.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef __ASURA_IMAGE_DECODE_TASK_H__ -#define __ASURA_IMAGE_DECODE_TASK_H__ - -#include -#include - -namespace AsuraEngine -{ - namespace Graphics - { - - class ImageDecodeTask - : public AEScripting::Portable - , public AEThreading::ThreadTask - { - public: - - LUAX_DECL_FACTORY(ImageDecodeTask); - - }; - - } -} - -#endif \ No newline at end of file diff --git a/source/modules/asura-core/graphics/image_decoder.h b/source/modules/asura-core/graphics/image_decoder.h deleted file mode 100644 index 869c82a..0000000 --- a/source/modules/asura-core/graphics/image_decoder.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef __ASURA_ENGINE_IMAGE_DECODER_H__ -#define __ASURA_ENGINE_IMAGE_DECODER_H__ - -#include - -#include "image_data.h" - -namespace AsuraEngine -{ - namespace Graphics - { - - class ImageDecoder - { - public: - - ImageDecoder(); - virtual ~ImageDecoder(); - - /// - /// 判断内存是否能用本decoder解压 - /// - virtual bool CanDecode(AEIO::DataBuffer& buffer) = 0; - - /// - /// 输入一个编码后的内存,输出一个解压后的Image data,如果解压失败返回nullptr - /// - virtual void Decode(AEIO::DataBuffer& buffer, ImageData& data) = 0; - - }; - - } -} - -#endif \ No newline at end of file diff --git a/source/modules/asura-core/graphics/mesh2d.h b/source/modules/asura-core/graphics/mesh2d.h index 31d3629..226b9f6 100644 --- a/source/modules/asura-core/graphics/mesh2d.h +++ b/source/modules/asura-core/graphics/mesh2d.h @@ -16,6 +16,8 @@ namespace AsuraEngine { public: + LUAX_DECL_FACTORY(Mesh2D); + Mesh2D(); ~Mesh2D(); diff --git a/source/modules/asura-core/graphics/mesh2d_data.cpp b/source/modules/asura-core/graphics/mesh2d_data.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/source/modules/asura-core/graphics/mesh2d_data.h b/source/modules/asura-core/graphics/mesh2d_data.h deleted file mode 100644 index e69de29..0000000 diff --git a/source/modules/asura-core/graphics/png_decoder.cpp b/source/modules/asura-core/graphics/png_decoder.cpp deleted file mode 100644 index 80463d5..0000000 --- a/source/modules/asura-core/graphics/png_decoder.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include "png_decoder.h" - -namespace AsuraEngine -{ - namespace Graphics - { - - bool PNGDecoder::CanDecode(AEIO::DataBuffer& buffer) - { - return false; - } - - void PNGDecoder::Decode(AEIO::DataBuffer& buffer, ImageData& data) - { - - } - - } -} diff --git a/source/modules/asura-core/graphics/png_decoder.h b/source/modules/asura-core/graphics/png_decoder.h deleted file mode 100644 index 6377940..0000000 --- a/source/modules/asura-core/graphics/png_decoder.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef __ASURA_ENGINE_PNGDECODER_H__ -#define __ASURA_ENGINE_PNGDECODER_H__ - -#include "image_decoder.h" - -namespace AsuraEngine -{ - namespace Graphics - { - - /// - /// 使用lodepng解压png文件 - /// - class PNGDecoder ASURA_FINAL: public ImageDecoder - { - public: - - bool CanDecode(AEIO::DataBuffer& buffer) override; - - void Decode(AEIO::DataBuffer& buffer, ImageData& data) override; - - }; - - } -} - -#endif \ No newline at end of file diff --git a/source/modules/asura-core/graphics/render_target.h b/source/modules/asura-core/graphics/render_target.h index b1a695a..0749cab 100644 --- a/source/modules/asura-core/graphics/render_target.h +++ b/source/modules/asura-core/graphics/render_target.h @@ -13,8 +13,6 @@ namespace AsuraEngine namespace Graphics { - class Drawable; - /// /// 可被作为渲染目标的类,派生类有 /// Canvas(RenderTexture) diff --git a/source/modules/asura-core/graphics/shader.cpp b/source/modules/asura-core/graphics/shader.cpp index c0c6f75..f33fd1a 100644 --- a/source/modules/asura-core/graphics/shader.cpp +++ b/source/modules/asura-core/graphics/shader.cpp @@ -15,14 +15,14 @@ namespace AsuraEngine } - bool Shader::Load(const std::string& vertexShader, const std::string& fragmentShader) + bool Shader::Refresh(AEIO::DecodedData* db) { - + return false; } uint Shader::GetUniformLocation(const std::string& uniform) { - + return 0; } GLuint Shader::GetGLProgramHandle() @@ -45,11 +45,6 @@ namespace AsuraEngine } - void Shader::SetUniformFloat(uint loc, float value) - { - - } - void Shader::SetUniformTexture(uint loc, const Texture& texture) { diff --git a/source/modules/asura-core/graphics/sprite_batch.h b/source/modules/asura-core/graphics/sprite_batch.h index 3143f73..eb1c89c 100644 --- a/source/modules/asura-core/graphics/sprite_batch.h +++ b/source/modules/asura-core/graphics/sprite_batch.h @@ -16,6 +16,8 @@ namespace AsuraEngine { public: + LUAX_DECL_FACTORY(SpriteBatch); + SpriteBatch(); ~SpriteBatch(); diff --git a/source/modules/asura-core/graphics/stb_decoder.cpp b/source/modules/asura-core/graphics/stb_decoder.cpp deleted file mode 100644 index 9a14141..0000000 --- a/source/modules/asura-core/graphics/stb_decoder.cpp +++ /dev/null @@ -1,70 +0,0 @@ -#include - -#include "stb_decoder.h" -#include "stb/stb_image.h" - -namespace AsuraEngine -{ - namespace Graphics - { - - bool STBDecoder::CanDecode(IO::DataBuffer& buffer) - { - int w = 0; - int h = 0; - int comp = 0; - - int status = stbi_info_from_memory((const stbi_uc*)buffer.GetData(), buffer.GetSize(), &w, &h, &comp); - - return status == 1 && w > 0 && h > 0; - } - - void STBDecoder::Decode(IO::DataBuffer& db, ImageData& imageData) - { - const stbi_uc *buffer = (const stbi_uc *)db.GetData(); - // databuffer数据长 - int bufferlen = db.GetSize(); - - int width, height; - int comp = 0; - byte* data = nullptr; - ColorFormat format = COLOR_FORMAT_UNKNOWN; - std::size_t size = 0; - - if (stbi_is_hdr_from_memory(buffer, bufferlen)) - { - // 4个channel都是float - data = (byte*)stbi_loadf_from_memory(buffer, bufferlen, &width, &height, &comp, STBI_rgb_alpha); - format = COLOR_FORMAT_RGBA32F; - size = width * height * 4 * sizeof(float); - } - else - { - data = (byte*)stbi_load_from_memory(buffer, bufferlen, &width, &height, &comp, STBI_rgb_alpha); - format = COLOR_FORMAT_RGBA8; - size = width * height * 4; - } - if (data) - { - imageData.Lock(); - - if (imageData.pixels) - delete[] imageData.pixels; - imageData.pixels = (byte*)data; - imageData.format = format; - imageData.width = width; - imageData.height = height; - - imageData.Unlock(); - } - else - { - const char *err = stbi_failure_reason(); - if (err == nullptr) - err = "unknown error"; - throw Exception("Could not decode image with stb_image (%s).", err); - } - } - - } -} \ No newline at end of file diff --git a/source/modules/asura-core/graphics/stb_decoder.h b/source/modules/asura-core/graphics/stb_decoder.h deleted file mode 100644 index 76e70c3..0000000 --- a/source/modules/asura-core/graphics/stb_decoder.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef __ASURA_ENGINE_STBDECODER_H__ -#define __ASURA_ENGINE_STBDECODER_H__ - -#include "image_decoder.h" - -namespace AsuraEngine -{ - namespace Graphics - { - - /// - /// 使用stb_image解压JPEG、TGA、BMP文件 - /// - class STBDecoder ASURA_FINAL - : public ImageDecoder - { - public: - - bool CanDecode(AEIO::DataBuffer& buffer) override; - - void Decode(AEIO::DataBuffer& buffer, ImageData& data) override; - - }; - - } -} - -#endif \ No newline at end of file diff --git a/source/modules/asura-core/graphics/texture.cpp b/source/modules/asura-core/graphics/texture.cpp index c260ce9..4db6ad3 100644 --- a/source/modules/asura-core/graphics/texture.cpp +++ b/source/modules/asura-core/graphics/texture.cpp @@ -22,5 +22,24 @@ namespace AsuraEngine return mTex; } + TextureFormat Texture::ConvertColorFormat(const ColorFormat& colorformat) + { + TextureFormat t; + switch (colorformat) + { + case COLOR_FORMAT_RGBA8: + t.internalformat = GL_RGBA8; + t.externalformat = GL_RGBA; + t.type = GL_UNSIGNED_BYTE; + break; + case COLOR_FORMAT_RGBA32F: + t.internalformat = GL_RGBA32F; + t.externalformat = GL_RGBA; + t.type = GL_FLOAT; + break; + } + return t; + } + } } \ No newline at end of file diff --git a/source/modules/asura-core/graphics/texture.h b/source/modules/asura-core/graphics/texture.h index 02d3407..f19f3a7 100644 --- a/source/modules/asura-core/graphics/texture.h +++ b/source/modules/asura-core/graphics/texture.h @@ -41,6 +41,17 @@ namespace AsuraEngine COLOR_FORMAT_RGBA32F, ///< RGBA都是32bits float }; + /// + /// 纹理格式,GPU内部和CPU外部格式 + /// + struct TextureFormat + { + GLenum internalformat; // GPU内部格式 + + GLenum externalformat; // CPU外部格式 + GLenum type; // 外部格式每个channel数值类型 + }; + /// /// 2D纹理抽象类,在2d mesh和render target中被使用。Texture的渲染原点在左上角,游戏里 /// 面的上层会以笛卡尔坐标系为标准。在Editor里面界面和组件也是以左上角为原点,这样是为了 @@ -94,6 +105,13 @@ namespace AsuraEngine //----------------------------------------------------------------------------// + /// + /// 转换color format为texture format。 + /// + TextureFormat ConvertColorFormat(const ColorFormat& colorformat); + + //----------------------------------------------------------------------------// + GLuint mTex; FilterMode mMinFilter; -- cgit v1.1-26-g67d0