summaryrefslogtreecommitdiff
path: root/source/modules/asura-core/graphics
diff options
context:
space:
mode:
Diffstat (limited to 'source/modules/asura-core/graphics')
-rw-r--r--source/modules/asura-core/graphics/binding/_image.cpp42
-rw-r--r--source/modules/asura-core/graphics/binding/_image_data.cpp43
-rw-r--r--source/modules/asura-core/graphics/canvas.cpp4
-rw-r--r--source/modules/asura-core/graphics/canvas.h4
-rw-r--r--source/modules/asura-core/graphics/color.h18
-rw-r--r--source/modules/asura-core/graphics/color32.h7
-rw-r--r--source/modules/asura-core/graphics/gl.cpp2
-rw-r--r--source/modules/asura-core/graphics/image.cpp31
-rw-r--r--source/modules/asura-core/graphics/image.h29
-rw-r--r--source/modules/asura-core/graphics/image_data.cpp28
-rw-r--r--source/modules/asura-core/graphics/image_data.h45
-rw-r--r--source/modules/asura-core/graphics/image_decoder.h4
-rw-r--r--source/modules/asura-core/graphics/pixel_format.h91
-rw-r--r--source/modules/asura-core/graphics/png_decoder.cpp6
-rw-r--r--source/modules/asura-core/graphics/png_decoder.h4
-rw-r--r--source/modules/asura-core/graphics/render_state.h3
-rw-r--r--source/modules/asura-core/graphics/shader.h2
-rw-r--r--source/modules/asura-core/graphics/stb_decoder.cpp23
-rw-r--r--source/modules/asura-core/graphics/stb_decoder.h4
-rw-r--r--source/modules/asura-core/graphics/texture.cpp8
-rw-r--r--source/modules/asura-core/graphics/texture.h74
21 files changed, 256 insertions, 216 deletions
diff --git a/source/modules/asura-core/graphics/binding/_image.cpp b/source/modules/asura-core/graphics/binding/_image.cpp
index cb008d3..1d43067 100644
--- a/source/modules/asura-core/graphics/binding/_image.cpp
+++ b/source/modules/asura-core/graphics/binding/_image.cpp
@@ -11,7 +11,7 @@ namespace AsuraEngine
{
LUAX_REGISTER_METHODS(state,
{ "New", _New },
- { "Load", _Load },
+ { "Refresh", _Refresh },
{ "GetWidth", _GetWidth },
{ "GetHeight", _GetHeight },
{ "GetSize", _GetSize },
@@ -25,66 +25,52 @@ namespace AsuraEngine
}
- // image = Image.New()
+ // Image.New()
LUAX_IMPL_METHOD(Image, _New)
{
LUAX_STATE(L);
- Image* image = new Image();
- image->PushLuaxUserdata(state);
return 0;
}
- // successed = image:Load(image_data)
- LUAX_IMPL_METHOD(Image, _Load)
+ // image:Refresh()
+ LUAX_IMPL_METHOD(Image, _Refresh)
{
LUAX_PREPARE(L, Image);
- ImageData* imgdata = state.CheckUserdata<ImageData>(2);
- bool loaded = self->Load(imgdata);
- state.Push(loaded);
- return 1;
+ return 0;
}
- // width = image:GetWidth()
+ // image:GetWidth()
LUAX_IMPL_METHOD(Image, _GetWidth)
{
LUAX_PREPARE(L, Image);
- state.Push(self->GetWidth());
- return 1;
+ return 0;
}
- // height = image:GetHeight()
+ // image:GetHeight()
LUAX_IMPL_METHOD(Image, _GetHeight)
{
LUAX_PREPARE(L, Image);
- state.Push(self->GetHeight());
- return 1;
+ return 0;
}
- // w, h = image:GetSize()
+ // image:GetSize()
LUAX_IMPL_METHOD(Image, _GetSize)
{
LUAX_PREPARE(L, Image);
- Math::Vector2u size = self->GetSize();
- state.Push(size.x);
- state.Push(size.y);
- return 2;
+ return 0;
}
- // color32 = image:GetPixel(x, y)
+ // image:GetPixel()
LUAX_IMPL_METHOD(Image, _GetPixel)
{
LUAX_PREPARE(L, Image);
- uint x = state.CheckValue<uint>(2);
- uint y = state.CheckValue<uint>(3);
- Color32* c32 = new Color32(self->GetPixel(x, y));
- c32->PushLuaxUserdata(state);
- return 1;
+ return 0;
}
// image:Render()
@@ -96,4 +82,4 @@ namespace AsuraEngine
}
}
-} \ No newline at end of file
+}
diff --git a/source/modules/asura-core/graphics/binding/_image_data.cpp b/source/modules/asura-core/graphics/binding/_image_data.cpp
index 3ff38f9..ac9473b 100644
--- a/source/modules/asura-core/graphics/binding/_image_data.cpp
+++ b/source/modules/asura-core/graphics/binding/_image_data.cpp
@@ -1,6 +1,11 @@
+#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
{
@@ -15,7 +20,10 @@ namespace AsuraEngine
{ "GetSize", _GetSize },
{ "GetWidth", _GetWidth },
{ "GetHeight", _GetHeight },
- { "GetPixelFormat", _GetPixelFormat }
+ { "GetPixelFormat", _GetPixelFormat },
+ { "Decode", _Decode },
+ { "DecodeAsync", _DecodeAsync },
+ { "IsAvailable", _IsAvailable }
);
}
@@ -29,6 +37,7 @@ namespace AsuraEngine
{
LUAX_STATE(L);
+ return 0;
}
// imagedata:GetPixel()
@@ -36,6 +45,7 @@ namespace AsuraEngine
{
LUAX_PREPARE(L, ImageData);
+ return 0;
}
// imagedata:GetSize()
@@ -43,6 +53,7 @@ namespace AsuraEngine
{
LUAX_PREPARE(L, ImageData);
+ return 0;
}
// imagedata:GetWidth()
@@ -50,6 +61,7 @@ namespace AsuraEngine
{
LUAX_PREPARE(L, ImageData);
+ return 0;
}
// imagedata:GetHeight()
@@ -57,6 +69,7 @@ namespace AsuraEngine
{
LUAX_PREPARE(L, ImageData);
+ return 0;
}
// imagedata:GetPixelFormat()
@@ -64,6 +77,34 @@ namespace AsuraEngine
{
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/canvas.cpp b/source/modules/asura-core/graphics/canvas.cpp
index 61787b6..e54ba1f 100644
--- a/source/modules/asura-core/graphics/canvas.cpp
+++ b/source/modules/asura-core/graphics/canvas.cpp
@@ -14,7 +14,7 @@ namespace AsuraEngine
GLint current_fbo;
glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &current_fbo);
glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
- glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextureHandle, 0);
+ glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTexHandle, 0);
glBindFramebuffer(GL_FRAMEBUFFER, current_fbo);
}
@@ -22,7 +22,7 @@ namespace AsuraEngine
{
GLint current_tex;
glGetIntegerv(GL_TEXTURE_BINDING_2D, &current_tex);
- glBindTexture(GL_TEXTURE_2D, mTextureHandle);
+ glBindTexture(GL_TEXTURE_2D, mTexHandle);
glBindTexture(GL_TEXTURE_2D, current_tex);
}
diff --git a/source/modules/asura-core/graphics/canvas.h b/source/modules/asura-core/graphics/canvas.h
index 7e7b2fd..d1412da 100644
--- a/source/modules/asura-core/graphics/canvas.h
+++ b/source/modules/asura-core/graphics/canvas.h
@@ -60,7 +60,7 @@ namespace AsuraEngine
public:
- //----------------------------------------------------------------------------------------------------------
+ //----------------------------------------------------------------------------//
LUAX_DECL_FACTORY(SimCanvas);
@@ -68,7 +68,7 @@ namespace AsuraEngine
LUAX_DECL_METHOD(_Bind);
LUAX_DECL_METHOD(_Unbind);
- //----------------------------------------------------------------------------------------------------------
+ //----------------------------------------------------------------------------//
};
diff --git a/source/modules/asura-core/graphics/color.h b/source/modules/asura-core/graphics/color.h
index d0d0751..c4945ca 100644
--- a/source/modules/asura-core/graphics/color.h
+++ b/source/modules/asura-core/graphics/color.h
@@ -13,7 +13,7 @@ namespace AsuraEngine
class Color32;
///
- /// 淶ɫ
+ /// 淶ɫColor32иIJԡ
///
class Color ASURA_FINAL
: public Scripting::Portable<Color>
@@ -26,7 +26,7 @@ namespace AsuraEngine
static Color Green;
static Color Blue;
- Color();
+ Color();
Color(const Color& c);
@@ -40,12 +40,24 @@ namespace AsuraEngine
float r, g, b, a;
+ //----------------------------------------------------------------------------//
+
LUAX_DECL_FACTORY(Color);
LUAX_DECL_METHOD(_ToColor32);
LUAX_DECL_METHOD(_SetColor);
LUAX_DECL_METHOD(_GetColor);
- LUAX_DECL_METHOD(_Multiply); // ɫ˷
+ LUAX_DECL_METHOD(_GetR);
+ LUAX_DECL_METHOD(_GetG);
+ LUAX_DECL_METHOD(_GetB);
+ LUAX_DECL_METHOD(_GetA);
+
+ // Ԫ
+ LUAX_DECL_METHOD(__eq); // __eq
+ LUAX_DECL_METHOD(__add); // __add
+ LUAX_DECL_METHOD(__sub); // __sub
+ LUAX_DECL_METHOD(__mul); // __mul
+ LUAX_DECL_METHOD(__div); // __div
};
diff --git a/source/modules/asura-core/graphics/color32.h b/source/modules/asura-core/graphics/color32.h
index b18f66c..2b13d1a 100644
--- a/source/modules/asura-core/graphics/color32.h
+++ b/source/modules/asura-core/graphics/color32.h
@@ -35,13 +35,14 @@ namespace AsuraEngine
byte r, g, b, a;
LUAX_DECL_METHOD(_ToColor);
+
+ LUAX_DECL_METHOD(_SetColor);
+
+ LUAX_DECL_METHOD(_GetColor);
LUAX_DECL_METHOD(_GetRed);
LUAX_DECL_METHOD(_GetGreen);
LUAX_DECL_METHOD(_GetBlue);
LUAX_DECL_METHOD(_GetAlpha);
- LUAX_DECL_METHOD(_Multiply);
- LUAX_DECL_METHOD(_Index); //r,g,b,a
- LUAX_DECL_METHOD(_NewIndex); //޸r,g,b,a
};
diff --git a/source/modules/asura-core/graphics/gl.cpp b/source/modules/asura-core/graphics/gl.cpp
index 7c68c8f..41d43a3 100644
--- a/source/modules/asura-core/graphics/gl.cpp
+++ b/source/modules/asura-core/graphics/gl.cpp
@@ -1,3 +1,5 @@
+#include <asura-utils/type.h>
+
#include "../core_config.h"
#include "gl.h"
diff --git a/source/modules/asura-core/graphics/image.cpp b/source/modules/asura-core/graphics/image.cpp
index e704945..e0528eb 100644
--- a/source/modules/asura-core/graphics/image.cpp
+++ b/source/modules/asura-core/graphics/image.cpp
@@ -1,6 +1,9 @@
-#include "Config.h"
-#include "Image.h"
-#include "GL.h"
+#include "../core_config.h"
+
+#include "image.h"
+#include "gl.h"
+
+using namespace AEIO;
namespace AsuraEngine
{
@@ -16,16 +19,28 @@ namespace AsuraEngine
}
//\Ϣ
- bool Image::Load(ImageData* data)
+ bool Image::Refresh(DecodedData* data)
{
ASSERT(data);
- glBindTexture(GL_TEXTURE_2D, mTextureHandle);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, data->width, data->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data->pixels);
+ ImageData* imgData = static_cast<ImageData*>(data);
+ ASSERT(imgData);
+
+ glBindTexture(GL_TEXTURE_2D, mTexHandle);
+
+ 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);
+ mImageData = imgData;
+
+ imgData->Unlock();
+
glBindTexture(GL_TEXTURE_2D, 0);
- return true;
- RRA(data, mImageData);
+ return true;
}
}
diff --git a/source/modules/asura-core/graphics/image.h b/source/modules/asura-core/graphics/image.h
index 29fd97c..377e002 100644
--- a/source/modules/asura-core/graphics/image.h
+++ b/source/modules/asura-core/graphics/image.h
@@ -27,9 +27,9 @@ namespace AsuraEngine
/// һֻࡣҪǿǵeditorengineʹòͬķװ
///
class Image ASURA_FINAL
- : public Drawable
+ : public Texture
, public Scripting::Portable<Image>
- , public AEIO::Reloadable
+ , public AEIO::Renewable
{
public:
@@ -40,19 +40,17 @@ namespace AsuraEngine
~Image();
///
- /// bufferimageϢmPixelsΪգݡ¹image
- /// ʹglTexImage2Dύimageݡ
+ /// ͼύGPUϢ¹imageʹglTexImage2D
+ /// ύimageݡ
///
- bool Load(ImageData* data);
+ bool Refresh(AEIO::DecodedData* decodeData) override;
+ bool Refresh(AEIO::DecodedData* decodeData, const AEMath::Recti& rect);
- uint GetWidth();
- uint GetHeight();
- Math::Vector2u GetSize();
- ///
- /// ijһλõ
- ///
- Color32 GetPixel(uint x, uint y);
+ uint GetWidth();
+ uint GetHeight();
+ Math::Vector2u GetSize();
+ Color32 GetPixel(uint x, uint y);
void Render(const RenderTarget* rt, const RenderState& state) override;
@@ -60,13 +58,14 @@ namespace AsuraEngine
private:
+ ///
+ /// һͼƬһݵá
+ ///
ImageData* mImageData;
Luax::LuaxMemberRef mImageDataRef;
- Math::Vector2u mSize;
-
LUAX_DECL_METHOD(_New);
- LUAX_DECL_METHOD(_Load);
+ LUAX_DECL_METHOD(_Refresh);
LUAX_DECL_METHOD(_GetWidth);
LUAX_DECL_METHOD(_GetHeight);
LUAX_DECL_METHOD(_GetSize);
diff --git a/source/modules/asura-core/graphics/image_data.cpp b/source/modules/asura-core/graphics/image_data.cpp
index b79dfab..64f83a8 100644
--- a/source/modules/asura-core/graphics/image_data.cpp
+++ b/source/modules/asura-core/graphics/image_data.cpp
@@ -16,8 +16,12 @@ namespace AsuraEngine
new STBDecoder() // jpeg, tga, bmp
};
- ImageData::ImageData(const IO::DataBuffer& buffer)
- : DecodedData(buffer)
+ ImageData::ImageData()
+ : pixels(nullptr)
+ , size(0)
+ , width(0)
+ , height(0)
+ , format(COLOR_FORMAT_UNKNOWN)
{
}
@@ -27,10 +31,12 @@ namespace AsuraEngine
delete[] pixels;
}
- ///
- /// ޷ɹ׳쳣
- ///
- void ImageData::Decode(const IO::DataBuffer& buffer)
+ ImageData::operator bool()
+ {
+ return size > 0;
+ }
+
+ void ImageData::Decode(IO::DataBuffer& buffer)
{
for (ImageDecoder* decoder : ImageDecoders)
{
@@ -46,6 +52,16 @@ namespace AsuraEngine
{
}
+
+ 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
index ea1d53a..b9d656c 100644
--- a/source/modules/asura-core/graphics/image_data.h
+++ b/source/modules/asura-core/graphics/image_data.h
@@ -7,8 +7,9 @@
#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 "pixel_format.h"
+#include "texture.h"
#include "color.h"
namespace AsuraEngine
@@ -29,27 +30,28 @@ namespace AsuraEngine
///
/// ͼƬļϢʧܣ׳쳣
///
- ImageData(const AEIO::DataBuffer& buffer);
+ ImageData();
~ImageData();
- void Load(const AEIO::DataBuffer& buffer);
- void LoadAsync(const AEIO::DataBuffer& buffer, AEThreading::Thread* thread);
+ void Decode(AEIO::DataBuffer& buffer) override;
+
+ void Lock();
+ void Unlock();
Color GetPixel(uint x, uint y);
- uint width, height;
- PixelFormat format;
- std::size_t size;
- byte* pixels;
+ //----------------------------------------------------------------------------//
- private:
+ uint width, height; // سߴ
+ ColorFormat format; // ʽ
+ byte* pixels; //
+ std::size_t size; // ݳ
- void Decode(const AEIO::DataBuffer& buffer) override;
+ //----------------------------------------------------------------------------//
- ///
- /// ڵһ׼image dataʱṩdecoderڼdecodersмѡԡ
- ///
- static std::list<ImageDecoder*> ImageDecoders;
+ private:
+
+ //----------------------------------------------------------------------------//
LUAX_DECL_METHOD(_New);
LUAX_DECL_METHOD(_GetPixel);
@@ -57,6 +59,21 @@ namespace AsuraEngine
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;
};
diff --git a/source/modules/asura-core/graphics/image_decoder.h b/source/modules/asura-core/graphics/image_decoder.h
index 263c694..869c82a 100644
--- a/source/modules/asura-core/graphics/image_decoder.h
+++ b/source/modules/asura-core/graphics/image_decoder.h
@@ -20,12 +20,12 @@ namespace AsuraEngine
///
/// жڴǷñdecoderѹ
///
- virtual bool CanDecode(const AEIO::DataBuffer& buffer) = 0;
+ virtual bool CanDecode(AEIO::DataBuffer& buffer) = 0;
///
/// һڴ棬һѹImage dataѹʧܷnullptr
///
- virtual void Decode(const AEIO::DataBuffer& buffer, ImageData& data) = 0;
+ virtual void Decode(AEIO::DataBuffer& buffer, ImageData& data) = 0;
};
diff --git a/source/modules/asura-core/graphics/pixel_format.h b/source/modules/asura-core/graphics/pixel_format.h
deleted file mode 100644
index 8df07d5..0000000
--- a/source/modules/asura-core/graphics/pixel_format.h
+++ /dev/null
@@ -1,91 +0,0 @@
-namespace AsuraEngine
-{
- namespace Graphics
- {
-
- ///
- /// ظʽ
- ///
- enum PixelFormat
- {
- PIXELFORMAT_UNKNOWN,
-
- // these are converted to an actual format by love
- PIXELFORMAT_NORMAL,
- PIXELFORMAT_HDR,
-
- // "regular" formats
- PIXELFORMAT_R8,
- PIXELFORMAT_RG8,
- PIXELFORMAT_RGBA8,
- PIXELFORMAT_sRGBA8,
- PIXELFORMAT_R16,
- PIXELFORMAT_RG16,
- PIXELFORMAT_RGBA16,
- PIXELFORMAT_R16F,
- PIXELFORMAT_RG16F,
- PIXELFORMAT_RGBA16F,
- PIXELFORMAT_R32F,
- PIXELFORMAT_RG32F,
- PIXELFORMAT_RGBA32F,
-
- PIXELFORMAT_LA8, // Same as RG8, but accessed as (L, L, L, A)
-
- // packed formats
- PIXELFORMAT_RGBA4,
- PIXELFORMAT_RGB5A1,
- PIXELFORMAT_RGB565,
- PIXELFORMAT_RGB10A2,
- PIXELFORMAT_RG11B10F,
-
- // depth/stencil formats
- PIXELFORMAT_STENCIL8,
- PIXELFORMAT_DEPTH16,
- PIXELFORMAT_DEPTH24,
- PIXELFORMAT_DEPTH32F,
- PIXELFORMAT_DEPTH24_STENCIL8,
- PIXELFORMAT_DEPTH32F_STENCIL8,
-
- // compressed formats
- PIXELFORMAT_DXT1,
- PIXELFORMAT_DXT3,
- PIXELFORMAT_DXT5,
- PIXELFORMAT_BC4,
- PIXELFORMAT_BC4s,
- PIXELFORMAT_BC5,
- PIXELFORMAT_BC5s,
- PIXELFORMAT_BC6H,
- PIXELFORMAT_BC6Hs,
- PIXELFORMAT_BC7,
- PIXELFORMAT_PVR1_RGB2,
- PIXELFORMAT_PVR1_RGB4,
- PIXELFORMAT_PVR1_RGBA2,
- PIXELFORMAT_PVR1_RGBA4,
- PIXELFORMAT_ETC1,
- PIXELFORMAT_ETC2_RGB,
- PIXELFORMAT_ETC2_RGBA,
- PIXELFORMAT_ETC2_RGBA1,
- PIXELFORMAT_EAC_R,
- PIXELFORMAT_EAC_Rs,
- PIXELFORMAT_EAC_RG,
- PIXELFORMAT_EAC_RGs,
- PIXELFORMAT_ASTC_4x4,
- PIXELFORMAT_ASTC_5x4,
- PIXELFORMAT_ASTC_5x5,
- PIXELFORMAT_ASTC_6x5,
- PIXELFORMAT_ASTC_6x6,
- PIXELFORMAT_ASTC_8x5,
- PIXELFORMAT_ASTC_8x6,
- PIXELFORMAT_ASTC_8x8,
- PIXELFORMAT_ASTC_10x5,
- PIXELFORMAT_ASTC_10x6,
- PIXELFORMAT_ASTC_10x8,
- PIXELFORMAT_ASTC_10x10,
- PIXELFORMAT_ASTC_12x10,
- PIXELFORMAT_ASTC_12x12,
-
- PIXELFORMAT_MAX_ENUM
- };
-
- }
-}
diff --git a/source/modules/asura-core/graphics/png_decoder.cpp b/source/modules/asura-core/graphics/png_decoder.cpp
index f919090..80463d5 100644
--- a/source/modules/asura-core/graphics/png_decoder.cpp
+++ b/source/modules/asura-core/graphics/png_decoder.cpp
@@ -1,16 +1,16 @@
-#include "PNGDecoder.h"
+#include "png_decoder.h"
namespace AsuraEngine
{
namespace Graphics
{
- bool PNGDecoder::CanDecode(const Filesystem::DataBuffer& buffer)
+ bool PNGDecoder::CanDecode(AEIO::DataBuffer& buffer)
{
return false;
}
- void PNGDecoder::Decode(const Filesystem::DataBuffer& buffer, ImageData& data)
+ 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
index bc871fa..6377940 100644
--- a/source/modules/asura-core/graphics/png_decoder.h
+++ b/source/modules/asura-core/graphics/png_decoder.h
@@ -15,9 +15,9 @@ namespace AsuraEngine
{
public:
- bool CanDecode(const AEIO::DataBuffer& buffer) override;
+ bool CanDecode(AEIO::DataBuffer& buffer) override;
- void Decode(const AEIO::DataBuffer& buffer, ImageData& data) override;
+ void Decode(AEIO::DataBuffer& buffer, ImageData& data) override;
};
diff --git a/source/modules/asura-core/graphics/render_state.h b/source/modules/asura-core/graphics/render_state.h
index 2b1dd7f..4c3491c 100644
--- a/source/modules/asura-core/graphics/render_state.h
+++ b/source/modules/asura-core/graphics/render_state.h
@@ -4,7 +4,6 @@
#include <asura-utils/math/vector2.hpp>
#include <asura-utils/math/transform.h>
-#include "Shader.h"
#include "blend_mode.h"
namespace AsuraEngine
@@ -12,6 +11,8 @@ namespace AsuraEngine
namespace Graphics
{
+ class Shader;
+
///
/// Ⱦǰķʽ
///
diff --git a/source/modules/asura-core/graphics/shader.h b/source/modules/asura-core/graphics/shader.h
index 97e2c15..8c21ab2 100644
--- a/source/modules/asura-core/graphics/shader.h
+++ b/source/modules/asura-core/graphics/shader.h
@@ -28,7 +28,7 @@ namespace AsuraEngine
///
class Shader ASURA_FINAL
: public Scripting::Portable<Shader>
- , public AEIO::Reloadable
+ , public AEIO::Renewable
{
public:
diff --git a/source/modules/asura-core/graphics/stb_decoder.cpp b/source/modules/asura-core/graphics/stb_decoder.cpp
index eff2e65..9a14141 100644
--- a/source/modules/asura-core/graphics/stb_decoder.cpp
+++ b/source/modules/asura-core/graphics/stb_decoder.cpp
@@ -8,49 +8,54 @@ namespace AsuraEngine
namespace Graphics
{
- bool STBDecoder::CanDecode(const Filesystem::DataBuffer& buffer)
+ 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.data, buffer.size, &w, &h, &comp);
+ 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(const Filesystem::DataBuffer& db, ImageData& imageData)
+ void STBDecoder::Decode(IO::DataBuffer& db, ImageData& imageData)
{
- const stbi_uc *buffer = (const stbi_uc *)db.data;
- int bufferlen = db.size;
+ const stbi_uc *buffer = (const stbi_uc *)db.GetData();
+ // databufferݳ
+ int bufferlen = db.GetSize();
+
int width, height;
int comp = 0;
byte* data = nullptr;
- PixelFormat format = PIXELFORMAT_UNKNOWN;
+ 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 = PIXELFORMAT_RGBA32F;
+ 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 = PIXELFORMAT_ASTC_8x5;
+ format = COLOR_FORMAT_RGBA8;
size = width * height * 4;
}
if (data)
{
- // ֤ڴ汻ͷţһϲûͷŵΪimage dataһԵģimageǶεġ
+ imageData.Lock();
+
if (imageData.pixels)
delete[] imageData.pixels;
imageData.pixels = (byte*)data;
imageData.format = format;
imageData.width = width;
imageData.height = height;
+
+ imageData.Unlock();
}
else
{
diff --git a/source/modules/asura-core/graphics/stb_decoder.h b/source/modules/asura-core/graphics/stb_decoder.h
index 85bad21..76e70c3 100644
--- a/source/modules/asura-core/graphics/stb_decoder.h
+++ b/source/modules/asura-core/graphics/stb_decoder.h
@@ -16,9 +16,9 @@ namespace AsuraEngine
{
public:
- bool CanDecode(const AEIO::DataBuffer& buffer) override;
+ bool CanDecode(AEIO::DataBuffer& buffer) override;
- void Decode(const AEIO::DataBuffer& buffer, ImageData& data) override;
+ void Decode(AEIO::DataBuffer& buffer, ImageData& data) override;
};
diff --git a/source/modules/asura-core/graphics/texture.cpp b/source/modules/asura-core/graphics/texture.cpp
index 6cb6497..0897702 100644
--- a/source/modules/asura-core/graphics/texture.cpp
+++ b/source/modules/asura-core/graphics/texture.cpp
@@ -6,20 +6,20 @@ namespace AsuraEngine
{
Texture::Texture()
- : mTextureHandle(0)
+ : mTexHandle(0)
{
// GL texture
- glGenTextures(1, &mTextureHandle);
+ glGenTextures(1, &mTexHandle);
}
Texture::~Texture()
{
- glDeleteTextures(1, &mTextureHandle);
+ glDeleteTextures(1, &mTexHandle);
}
GLuint Texture::GetGLTextureHandle() const
{
- return mTextureHandle;
+ return mTexHandle;
}
}
diff --git a/source/modules/asura-core/graphics/texture.h b/source/modules/asura-core/graphics/texture.h
index 81ced9f..a76e1d4 100644
--- a/source/modules/asura-core/graphics/texture.h
+++ b/source/modules/asura-core/graphics/texture.h
@@ -1,9 +1,8 @@
-#ifndef __ASURA_ENGINE_TEXTURE_H__
-#define __ASURA_ENGINE_TEXTURE_H__
+#ifndef __ASURA_TEXTURE_H__
+#define __ASURA_TEXTURE_H__
#include <asura-utils/math/rect.hpp>
#include <asura-utils/math/vector2.hpp>
-#include <asura-utils/scripting/portable.hpp>
#include "../core_config.h"
@@ -17,20 +16,59 @@ namespace AsuraEngine
class RenderTarget;
+ enum WrapMode
+ {
+ WRAP_MODE_REPEAT,
+ WRAP_MODE_MIRROR,
+ WRAP_MODE_CLAMPTOEDGE,
+ WRAP_MODE_CLAMPTOBORDER,
+ //WRAP_MODE_PERAXIS, // UVвͬ4ֵ
+ };
+
+ enum FilterMode
+ {
+ FILTER_MODE_NEAREST,
+ FILTER_MODE_LINEAR,
+ };
+
///
- /// 2D࣬2d meshrender targetбʹáTextureȾԭϽǣϷϲԵѿϵΪ׼
- /// EditorҲϽΪԭ㣬Ϊ˷㡣
+ /// ͼݵɫʽ
+ ///
+ enum ColorFormat
+ {
+ COLOR_FORMAT_UNKNOWN,
+
+ COLOR_FORMAT_RGBA8, ///< RGBA8bits int
+ COLOR_FORMAT_RGBA32F, ///< RGBA32bits float
+ };
+
+ ///
+ /// 2D࣬2d meshrender targetбʹáTextureȾԭϽǣϷ
+ /// ϲԵѿϵΪ׼EditorҲϽΪԭ㣬Ϊ
+ /// 㡣
///
ASURA_ABSTRACT class Texture
{
public:
- Texture();
+ LUAX_DECL_ABSTRACT_FACTORY();
+ Texture();
virtual ~Texture();
GLuint GetGLTextureHandle() const;
+ void SetFilterMode(FilterMode min, FilterMode mag);
+ void SetWrapMode(WrapMode wrapMode);
+
+ void GetFilterMode();
+ void GetWrapMode();
+
+ ///
+ /// UVfilterΪ
+ ///
+ void IsGenMipmap();
+
///
/// ȾtexturertϣԭϽǣң
///
@@ -41,22 +79,20 @@ namespace AsuraEngine
///
virtual void Render(const RenderTarget* rt, const Math::Rectf& quad, const RenderState& state) = 0;
- ///
- /// ù˷ʽ
- ///
- void SetSmooth(bool smooth);
+ protected:
- ///
- /// ظʽ
- ///
- void SetRepeated();
+ LUAX_DECL_ENUM(ColorFormat);
+ LUAX_DECL_ENUM(FilterMode);
+ LUAX_DECL_ENUM(WrapMode);
- protected:
+ GLuint mTexHandle;
- ///
- /// OpenGL texture handle
- ///
- GLuint mTextureHandle;
+ FilterMode mMinFilter;
+ FilterMode mMagFilter;
+
+ WrapMode mWrapMode;
+
+ bool mIsGenMipmap;
};