diff options
Diffstat (limited to 'source/modules/asura-core/graphics')
28 files changed, 125 insertions, 531 deletions
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 <asura-utils/threading/thread.h> -#include <asura-utils/io/data_buffer.h> - -#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<Thread>(2); - DataBuffer* buffer = state.CheckUserdata<DataBuffer>(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 <asura-utils/math/rect.hpp> + +#include <glad/glad.h> namespace AsuraEngine { @@ -11,7 +13,9 @@ namespace AsuraEngine class Profiler; /// - /// һЩopengl״̬١ + /// һЩopengl״̬١ڱ༭രڻ£һڶӦһhwndһhdcԼ + /// opengl contextʹwglMakeCurrent(hdc, glc)ָǰ̶߳Ⱦhdc + /// openglglcglм¼ľһ̵߳һڵһ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 <asura-utils/stringmap.hpp> #include <asura-utils/manager.hpp> +#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; - - // imagedecoderΪԡ - list<ImageDecoder*> 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 <list> - -#include <asura-utils/scripting/portable.hpp> -#include <asura-utils/io/decoded_data.h> -#include <asura-utils/io/data_buffer.h> -#include <asura-utils/threading/thread.h> -#include <asura-utils/threading/mutex.h> - -#include "texture.h" -#include "color.h" - -namespace AsuraEngine -{ - namespace Graphics - { - - class ImageDecoder; - - class ImageData ASURA_FINAL - : public AEIO::DecodedData - , public Scripting::Portable<ImageData> - { - 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<ImageDecoder*> 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 --- a/source/modules/asura-core/graphics/image_decode_task.cpp +++ /dev/null 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 <asura-utils/threading/thread_task.h> -#include <asura-utils/scripting/portable.hpp> - -namespace AsuraEngine -{ - namespace Graphics - { - - class ImageDecodeTask - : public AEScripting::Portable<ImageDecodeTask> - , 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 <asura-utils/io/data_buffer.h> - -#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 --- a/source/modules/asura-core/graphics/mesh2d_data.cpp +++ /dev/null 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 --- a/source/modules/asura-core/graphics/mesh2d_data.h +++ /dev/null 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 <asura-utils/exceptions/exception.h> - -#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)) - { - // 4channelfloat - 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ѹJPEGTGABMPļ - /// - 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 @@ -42,6 +42,17 @@ namespace AsuraEngine }; /// + /// ʽGPUڲCPUⲿʽ + /// + struct TextureFormat + { + GLenum internalformat; // GPUڲʽ + + GLenum externalformat; // CPUⲿʽ + GLenum type; // ⲿʽÿchannelֵ + }; + + /// /// 2D࣬2d meshrender targetбʹáTextureȾԭϽǣϷ /// ϲԵѿϵΪEditorҲϽΪԭ㣬Ϊ /// 㡣 @@ -94,6 +105,13 @@ namespace AsuraEngine //----------------------------------------------------------------------------// + /// + /// תcolor formatΪtexture format + /// + TextureFormat ConvertColorFormat(const ColorFormat& colorformat); + + //----------------------------------------------------------------------------// + GLuint mTex; FilterMode mMinFilter; |