summaryrefslogtreecommitdiff
path: root/Source/Asura.Engine/Graphics
diff options
context:
space:
mode:
Diffstat (limited to 'Source/Asura.Engine/Graphics')
-rw-r--r--Source/Asura.Engine/Graphics/BlendMode.h17
-rw-r--r--Source/Asura.Engine/Graphics/Canvas.cpp32
-rw-r--r--Source/Asura.Engine/Graphics/Canvas.h30
-rw-r--r--Source/Asura.Engine/Graphics/Color.h13
-rw-r--r--Source/Asura.Engine/Graphics/Image.cpp28
-rw-r--r--Source/Asura.Engine/Graphics/Image.h24
-rw-r--r--Source/Asura.Engine/Graphics/ImageData.cpp56
-rw-r--r--Source/Asura.Engine/Graphics/ImageData.h58
-rw-r--r--Source/Asura.Engine/Graphics/ImageDecoder.h35
-rw-r--r--Source/Asura.Engine/Graphics/Mesh2D.h5
-rw-r--r--Source/Asura.Engine/Graphics/PNGDecoder.cpp19
-rw-r--r--Source/Asura.Engine/Graphics/PNGDecoder.h27
-rw-r--r--Source/Asura.Engine/Graphics/PixelFormat.h91
-rw-r--r--Source/Asura.Engine/Graphics/Port/ImageData.cpp0
-rw-r--r--Source/Asura.Engine/Graphics/Port/Mesh2DData.cpp0
-rw-r--r--Source/Asura.Engine/Graphics/Port/Shader.cpp26
-rw-r--r--Source/Asura.Engine/Graphics/RenderState.h52
-rw-r--r--Source/Asura.Engine/Graphics/RenderTarget.h26
-rw-r--r--Source/Asura.Engine/Graphics/STBDecoder.cpp69
-rw-r--r--Source/Asura.Engine/Graphics/STBDecoder.h27
-rw-r--r--Source/Asura.Engine/Graphics/Shader.cpp6
-rw-r--r--Source/Asura.Engine/Graphics/Shader.h13
-rw-r--r--Source/Asura.Engine/Graphics/Texture.h23
23 files changed, 596 insertions, 81 deletions
diff --git a/Source/Asura.Engine/Graphics/BlendMode.h b/Source/Asura.Engine/Graphics/BlendMode.h
new file mode 100644
index 0000000..775cc45
--- /dev/null
+++ b/Source/Asura.Engine/Graphics/BlendMode.h
@@ -0,0 +1,17 @@
+#ifndef __ASURA_ENGINE_BLEND_MODE_H__
+#define __ASURA_ENGINE_BLEND_MODE_H__
+
+namespace AsuraEngine
+{
+ namespace Graphics
+ {
+
+ enum BlendMode
+ {
+
+ };
+
+ }
+}
+
+#endif \ No newline at end of file
diff --git a/Source/Asura.Engine/Graphics/Canvas.cpp b/Source/Asura.Engine/Graphics/Canvas.cpp
index 8ca6fb2..61787b6 100644
--- a/Source/Asura.Engine/Graphics/Canvas.cpp
+++ b/Source/Asura.Engine/Graphics/Canvas.cpp
@@ -5,7 +5,37 @@ namespace AsuraEngine
namespace Graphics
{
-
+ Canvas::Canvas()
+ : Texture()
+ , mWidth(0)
+ , mHeight(0)
+ {
+ glGenFramebuffers(1, &mFBO);
+ 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);
+ glBindFramebuffer(GL_FRAMEBUFFER, current_fbo);
+ }
+
+ void Canvas::SetSize(uint w, uint h)
+ {
+ GLint current_tex;
+ glGetIntegerv(GL_TEXTURE_BINDING_2D, &current_tex);
+ glBindTexture(GL_TEXTURE_2D, mTextureHandle);
+
+ glBindTexture(GL_TEXTURE_2D, current_tex);
+ }
+
+ void Canvas::Bind()
+ {
+
+ }
+
+ void Canvas::Unbind()
+ {
+
+ }
}
} \ No newline at end of file
diff --git a/Source/Asura.Engine/Graphics/Canvas.h b/Source/Asura.Engine/Graphics/Canvas.h
index c8faacf..c258793 100644
--- a/Source/Asura.Engine/Graphics/Canvas.h
+++ b/Source/Asura.Engine/Graphics/Canvas.h
@@ -3,8 +3,8 @@
#include <Scripting/Luax.hpp>
+#include "Math/Rect.hpp"
#include "GL.h"
-#include "SimClass.h"
#include "Texture.h"
#include "RenderTarget.h"
@@ -16,35 +16,34 @@ namespace AsuraEngine
///
/// CanvasҲԳΪrender textureҲΪtextureȾ
///
- class Canvas final : public Texture, public RenderTarget, public SimClass
+ class Canvas final : public Drawable, public RenderTarget, public Scripting::Portable
{
public:
Canvas();
- ///
- /// render textureĴС
- ///
- void Init(uint w, uint h);
+ ~Canvas();
///
- /// 󶨴canvasΪ
+ /// render textureĴС
///
- void Bind();
+ void SetSize(uint w, uint h);
///
- /// Ϊǻ󶨻screen
+ /// ȾtexturertϣԭϽǣң
///
- void Unbind();
+ void Render(const RenderTarget* rt, const Math::Vector2i& pos, const Math::Vector2i& scale, const Math::Vector2i& center, float rot);
- void Render(int x, int y, int sx, int sy, int ox, int oy, int r) override;
-
- void Render(const Math::Rect& quad, int x, int y, int sx, int sy, int ox, int oy, int r) override;
+ ///
+ /// ȾtextureһֵrtϣԭϽǣң졣
+ ///
+ void Render(const RenderTarget* rt, const Math::Rectf& quad, const Math::Vector2i& pos, const Math::Vector2i& scale, const Math::Vector2i& center, float rot);
//----------------------------------------------------------------------------------------------------------
LUAX_DECL_FACTORY(SimCanvas);
+ LUAX_DECL_METHOD(l_SetSize);
LUAX_DECL_METHOD(l_Bind);
LUAX_DECL_METHOD(l_Unbind);
@@ -57,6 +56,11 @@ namespace AsuraEngine
///
GLuint mFBO;
+ ///
+ /// canvasĴС
+ ///
+ uint mWidth, mHeight;
+
};
///
diff --git a/Source/Asura.Engine/Graphics/Color.h b/Source/Asura.Engine/Graphics/Color.h
index 6383602..d8f39a0 100644
--- a/Source/Asura.Engine/Graphics/Color.h
+++ b/Source/Asura.Engine/Graphics/Color.h
@@ -52,6 +52,12 @@ namespace AsuraEngine
{
public:
+ static Color Black;
+ static Color White;
+ static Color Red;
+ static Color Green;
+ static Color Blue;
+
Color();
Color(const Color& c);
@@ -68,12 +74,9 @@ namespace AsuraEngine
LUAX_DECL_FACTORY(Color);
- LUAX_DECL_METHOD(l_GetRed); // color.r
- LUAX_DECL_METHOD(l_GetGreen); // color.g
- LUAX_DECL_METHOD(l_GetBlue); // color.b
- LUAX_DECL_METHOD(l_GetAlpha); // color.a
+ LUAX_DECL_METHOD(l_SetColor);
+ LUAX_DECL_METHOD(l_GetColor);
LUAX_DECL_METHOD(l_Multiply); // ɫ˷
- LUAX_DECL_METHOD(l_NewIndex); // ޸r,g,b,a
//----------------------------------------------------------------------------------------------------------
diff --git a/Source/Asura.Engine/Graphics/Image.cpp b/Source/Asura.Engine/Graphics/Image.cpp
index e19d57f..8287d76 100644
--- a/Source/Asura.Engine/Graphics/Image.cpp
+++ b/Source/Asura.Engine/Graphics/Image.cpp
@@ -1,4 +1,5 @@
#include "Image.h"
+#include "GL.h"
namespace AsuraEngine
{
@@ -7,30 +8,25 @@ namespace AsuraEngine
Image::Image()
: Texture()
- , mPixels(nullptr)
- , mWidth(0)
- , mHeight(0)
{
}
Image::~Image()
{
- delete mPixels;
}
- bool Image::Load(const void* data, size_t size)
+ //\Ϣ
+ bool Image::Load(const ImageData* data)
{
-
- }
-
- void Image::Render(int x, int y, int sx, int sy, int ox, int oy, int r)
- {
-
- }
-
- void Image::Render(const Math::Rect& quad, int x, int y, int sx, int sy, int ox, int oy, int r)
- {
-
+ if (!data)
+ return false;
+ if (mImageData)
+ delete mImageData;
+ mImageData = 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);
+ glBindTexture(GL_TEXTURE_2D, 0);
+ return true;
}
}
diff --git a/Source/Asura.Engine/Graphics/Image.h b/Source/Asura.Engine/Graphics/Image.h
index 391d1c4..da881aa 100644
--- a/Source/Asura.Engine/Graphics/Image.h
+++ b/Source/Asura.Engine/Graphics/Image.h
@@ -1,13 +1,12 @@
#ifndef __ASURA_ENGINE_IMAGE_H__
#define __ASURA_ENGINE_IMAGE_H__
-#include "Math/Vector2.h"
#include "StringMap.hpp"
#include "Manager.hpp"
#include "Texture.h"
#include "Color.h"
#include "Factory.h"
-#include "SimClass.h"
+#include "ImageData.h"
namespace AsuraEngine
{
@@ -20,7 +19,7 @@ namespace AsuraEngine
/// ImageͼƬڴ󣬶ȡϷ󱣴ĽһImageڴ桢ԴֻᱣһݣҪ
/// imageêλãźתǶȣʹspriteһֻࡣҪǿǵeditorengineʹòͬķװ
///
- class Image final : public Texture, public SimClass
+ class Image final : public Drawable, public Scripting::Portable
{
public:
@@ -28,10 +27,10 @@ namespace AsuraEngine
~Image();
///
- /// bufferimagemPixelsΪգݡ¹imageʹglTexImage2Dύimage
- /// ݡ
+ /// bufferimageϢmPixelsΪգݡ¹imageʹglTexImage2Dύimage
+ /// ݡ
///
- bool Load(const void* data, size_t size);
+ bool Load(const ImageData* data);
uint GetWidth();
uint GetHeight();
@@ -39,11 +38,11 @@ namespace AsuraEngine
///
/// ijһλõ
///
- Color GetPixel(uint x, uint y);
+ Color32 GetPixel(uint x, uint y);
- void Render(int x, int y, int sx, int sy, int ox, int oy, int r) override;
+ virtual void Render(const RenderTarget* rt, const RenderState& state) override;
- void Render(const Math::Rect& quad, int x, int y, int sx, int sy, int ox, int oy, int r) override;
+ virtual void Render(const RenderTarget* rt, const Math::Rectf& quad, const RenderState& state) override;
//----------------------------------------------------------------------------------------------------------
@@ -58,12 +57,7 @@ namespace AsuraEngine
private:
- ///
- /// СΪλ
- ///
- uint mWidth, mHeight;
-
- Color* mPixels;
+ const ImageData* mImageData;
};
diff --git a/Source/Asura.Engine/Graphics/ImageData.cpp b/Source/Asura.Engine/Graphics/ImageData.cpp
new file mode 100644
index 0000000..af448bd
--- /dev/null
+++ b/Source/Asura.Engine/Graphics/ImageData.cpp
@@ -0,0 +1,56 @@
+#include "ImageData.h"
+#include "PNGDecoder.h"
+#include "STBDecoder.h"
+
+namespace AsuraEngine
+{
+ namespace Graphics
+ {
+
+ using namespace std;
+
+ // imagedecoderΪԡ
+ list<ImageDecoder*> ImageData::ImageDecoders = {
+ new PNGDecoder(), // png
+ new STBDecoder() // jpeg, tga, bmp
+ };
+
+ void ImageData::ReleaseAllDecoders()
+ {
+ for (ImageDecoder* decoder : ImageDecoders)
+ decoder->Release();
+ }
+
+ ImageData::ImageData(const Filesystem::DataBuffer* buffer)
+ : DecodedData(buffer)
+ {
+ }
+
+ ImageData::~ImageData()
+ {
+ if (pixels)
+ delete[] pixels;
+ }
+
+ ///
+ /// ޷ɹ׳쳣
+ ///
+ void ImageData::Decode(const Filesystem::DataBuffer* buffer)
+ {
+ for (ImageDecoder* decoder : ImageDecoders)
+ {
+ if (decoder->CanDecode(buffer))
+ {
+ decoder->Decode(buffer, this);
+ return;
+ }
+ }
+ }
+
+ Color ImageData::GetPixel(uint x, uint y)
+ {
+
+ }
+
+ }
+} \ No newline at end of file
diff --git a/Source/Asura.Engine/Graphics/ImageData.h b/Source/Asura.Engine/Graphics/ImageData.h
new file mode 100644
index 0000000..925a5a0
--- /dev/null
+++ b/Source/Asura.Engine/Graphics/ImageData.h
@@ -0,0 +1,58 @@
+#ifndef __ASURA_ENGINE_IMAGEDATA_H__
+#define __ASURA_ENGINE_IMAGEDATA_H__
+
+#include <list>
+
+#include "Scripting/Luax.hpp"
+#include "Filesystem/DecodedData.h"
+#include "ImageDecoder.h"
+#include "PixelFormat.h"
+#include "Color.h"
+
+namespace AsuraEngine
+{
+ namespace Graphics
+ {
+
+ class ImageData final : public Filesystem::DecodedData, public Scripting::Portable
+ {
+ public:
+
+ ///
+ /// ͼƬļϢʧܣ׳쳣
+ ///
+ ImageData(const Filesystem::DataBuffer* buffer);
+ ~ImageData();
+
+ Color GetPixel(uint x, uint y);
+
+ uint width, height;
+ PixelFormat format;
+ std::size_t size;
+ byte* pixels;
+
+ //----------------------------------------------------------------------------------------------------------
+
+ LUAX_DECL_FACTORY(ImageData);
+
+ LUAX_DECL_METHOD(l_GetPixel);
+ LUAX_DECL_METHOD(l_GetSize);
+
+ //----------------------------------------------------------------------------------------------------------
+
+ private:
+
+ // stbJPEGTGABMP,lodePNGpngͼƬ
+ void Decode(const Filesystem::DataBuffer* buffer) override;
+
+ ///
+ /// ڵһ׼image dataʱṩdecoderڼdecodersмѡԡ
+ ///
+ static std::list<ImageDecoder*> ImageDecoders;
+
+ };
+
+ }
+}
+
+#endif \ No newline at end of file
diff --git a/Source/Asura.Engine/Graphics/ImageDecoder.h b/Source/Asura.Engine/Graphics/ImageDecoder.h
new file mode 100644
index 0000000..9dc2188
--- /dev/null
+++ b/Source/Asura.Engine/Graphics/ImageDecoder.h
@@ -0,0 +1,35 @@
+#ifndef __ASURA_ENGINE_IMAGE_DECODER_H__
+#define __ASURA_ENGINE_IMAGE_DECODER_H__
+
+#include "FileSystem/DataBuffer.h"
+
+#include "ImageData.h"
+
+namespace AsuraEngine
+{
+ namespace Graphics
+ {
+
+ class ImageDecoder : virtual public Object
+ {
+ public:
+
+ ImageDecoder();
+ virtual ~ImageDecoder();
+
+ ///
+ /// жڴǷñdecoderѹ
+ ///
+ virtual bool CanDecode(const Filesystem::DataBuffer* buffer) = 0;
+
+ ///
+ /// һڴ棬һѹImage dataѹʧܷnullptr
+ ///
+ virtual void Decode(const Filesystem::DataBuffer* buffer, ImageData* data) = 0;
+
+ };
+
+ }
+}
+
+#endif \ No newline at end of file
diff --git a/Source/Asura.Engine/Graphics/Mesh2D.h b/Source/Asura.Engine/Graphics/Mesh2D.h
index 921ae80..cadbec1 100644
--- a/Source/Asura.Engine/Graphics/Mesh2D.h
+++ b/Source/Asura.Engine/Graphics/Mesh2D.h
@@ -1,8 +1,9 @@
#ifndef __ASURA_ENGINE_MESH2D_H__
#define __ASURA_ENGINE_MESH2D_H__
+#include "Scripting/Luax.hpp"
+
#include "Object.h"
-#include "SimClass.h"
namespace AsuraEngine
{
@@ -12,7 +13,7 @@ namespace AsuraEngine
///
/// 2D meshһЩ㶯
///
- class Mesh2D : virtual public Object, public SimClass
+ class Mesh2D : virtual public Object, public Scripting::Portable
{
};
diff --git a/Source/Asura.Engine/Graphics/PNGDecoder.cpp b/Source/Asura.Engine/Graphics/PNGDecoder.cpp
new file mode 100644
index 0000000..363d478
--- /dev/null
+++ b/Source/Asura.Engine/Graphics/PNGDecoder.cpp
@@ -0,0 +1,19 @@
+#include "PNGDecoder.h"
+
+namespace AsuraEngine
+{
+ namespace Graphics
+ {
+
+ bool PNGDecoder::CanDecode(const Filesystem::DataBuffer* buffer)
+ {
+ return false;
+ }
+
+ void PNGDecoder::Decode(const Filesystem::DataBuffer* buffer, ImageData* data)
+ {
+
+ }
+
+ }
+}
diff --git a/Source/Asura.Engine/Graphics/PNGDecoder.h b/Source/Asura.Engine/Graphics/PNGDecoder.h
new file mode 100644
index 0000000..dc5bb60
--- /dev/null
+++ b/Source/Asura.Engine/Graphics/PNGDecoder.h
@@ -0,0 +1,27 @@
+#ifndef __ASURA_ENGINE_PNGDECODER_H__
+#define __ASURA_ENGINE_PNGDECODER_H__
+
+#include "ImageDecoder.h"
+
+namespace AsuraEngine
+{
+ namespace Graphics
+ {
+
+ ///
+ /// ʹlodepngѹpngļ
+ ///
+ class PNGDecoder final : public ImageDecoder
+ {
+ public:
+
+ bool CanDecode(const Filesystem::DataBuffer* buffer) override;
+
+ void Decode(const Filesystem::DataBuffer* buffer, ImageData* data) override;
+
+ };
+
+ }
+}
+
+#endif \ No newline at end of file
diff --git a/Source/Asura.Engine/Graphics/PixelFormat.h b/Source/Asura.Engine/Graphics/PixelFormat.h
new file mode 100644
index 0000000..8df07d5
--- /dev/null
+++ b/Source/Asura.Engine/Graphics/PixelFormat.h
@@ -0,0 +1,91 @@
+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/Asura.Engine/Graphics/Port/ImageData.cpp b/Source/Asura.Engine/Graphics/Port/ImageData.cpp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Source/Asura.Engine/Graphics/Port/ImageData.cpp
diff --git a/Source/Asura.Engine/Graphics/Port/Mesh2DData.cpp b/Source/Asura.Engine/Graphics/Port/Mesh2DData.cpp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Source/Asura.Engine/Graphics/Port/Mesh2DData.cpp
diff --git a/Source/Asura.Engine/Graphics/Port/Shader.cpp b/Source/Asura.Engine/Graphics/Port/Shader.cpp
index 887cfae..2253a56 100644
--- a/Source/Asura.Engine/Graphics/Port/Shader.cpp
+++ b/Source/Asura.Engine/Graphics/Port/Shader.cpp
@@ -12,7 +12,7 @@ namespace AsuraEngine
///
int Shader::l_Use(lua_State* L)
{
- LuaxState state = LuaxState(L);
+ LuaxState state(L);
}
@@ -21,7 +21,7 @@ namespace AsuraEngine
///
int Shader::l_Unuse(lua_State* L)
{
- LuaxState state = LuaxState(L);
+ LuaxState state(L);
}
@@ -30,7 +30,7 @@ namespace AsuraEngine
///
int Shader::l_Load(lua_State* L)
{
- LuaxState state = LuaxState(L);
+ LuaxState state(L);
}
@@ -39,7 +39,7 @@ namespace AsuraEngine
///
int Shader::l_HasUniform(lua_State* L)
{
- LuaxState state = LuaxState(L);
+ LuaxState state(L);
}
@@ -48,56 +48,56 @@ namespace AsuraEngine
///
int Shader::l_GetUniformLocation(lua_State* L)
{
- LuaxState state = LuaxState(L);
+ LuaxState state(L);
}
int Shader::l_SetBuiltInUniforms(lua_State* L)
{
- LuaxState state = LuaxState(L);
+ LuaxState state(L);
}
int Shader::l_SetUniformFloat(lua_State* L)
{
- LuaxState state = LuaxState(L);
+ LuaxState state(L);
}
int Shader::l_SetUniformTexture(lua_State* L)
{
- LuaxState state = LuaxState(L);
+ LuaxState state(L);
}
int Shader::l_SetUniformVector2(lua_State* L)
{
- LuaxState state = LuaxState(L);
+ LuaxState state(L);
}
int Shader::l_SetUniformVector3(lua_State* L)
{
- LuaxState state = LuaxState(L);
+ LuaxState state(L);
}
int Shader::l_SetUniformVector4(lua_State* L)
{
- LuaxState state = LuaxState(L);
+ LuaxState state(L);
}
int Shader::l_SetUniformColor(lua_State* L)
{
- LuaxState state = LuaxState(L);
+ LuaxState state(L);
}
//עluaijԱ
int Shader::RegisterLuaClass(lua_State* L)
{
- LuaxState state = LuaxState(L);
+ LuaxState state(L);
}
diff --git a/Source/Asura.Engine/Graphics/RenderState.h b/Source/Asura.Engine/Graphics/RenderState.h
new file mode 100644
index 0000000..9524ef6
--- /dev/null
+++ b/Source/Asura.Engine/Graphics/RenderState.h
@@ -0,0 +1,52 @@
+#ifndef __ASURA_ENGINE_RENDER_STATE_H__
+#define __ASURA_ENGINE_RENDER_STATE_H__
+
+#include "Math/Vector2.hpp"
+#include "Math/Rect.hpp"
+#include "Math/Transform.h"
+
+#include "Shader.h"
+#include "BlendMode.h"
+
+namespace AsuraEngine
+{
+ namespace Graphics
+ {
+
+ ///
+ /// Ⱦǰķʽ
+ ///
+ class RenderState final : virtual public Object
+ {
+ public:
+
+ ///
+ /// Ĭϵrender state
+ ///
+ static RenderState Default;
+
+ RenderState();
+ ~RenderState();
+
+ ///
+ /// λášλúת
+ ///
+
+ Math::Transform transform;
+
+ ///
+ /// ɫ
+ ///
+ Shader* shader;
+
+ ///
+ /// Ϸʽ
+ ///
+ BlendMode blendMode;
+
+ };
+
+ }
+}
+
+#endif \ No newline at end of file
diff --git a/Source/Asura.Engine/Graphics/RenderTarget.h b/Source/Asura.Engine/Graphics/RenderTarget.h
index 05d7068..afa8967 100644
--- a/Source/Asura.Engine/Graphics/RenderTarget.h
+++ b/Source/Asura.Engine/Graphics/RenderTarget.h
@@ -1,20 +1,24 @@
#ifndef __ASURA_ENGINE_RENDERTARGET_H__
#define __ASURA_ENGINE_RENDERTARGET_H__
+#include "Math/Rect.hpp"
#include "Texture.h"
#include "Object.h"
+#include "Color.h"
namespace AsuraEngine
{
namespace Graphics
{
+ class Drawable;
+
///
/// ɱΪȾĿ࣬
/// Canvas(RenderTexture)
/// Window(RenderWindow)
///
- class RenderTarget : virtual public Object
+ class RenderTarget : virtual public Object
{
public:
@@ -22,6 +26,26 @@ namespace AsuraEngine
virtual ~RenderTarget() {};
+ ///
+ /// ɫcolRT
+ ///
+ virtual void Clear(const Color& col = Color::Black) = 0;
+
+ ///
+ /// ɫcolղRT
+ ///
+ virtual void Clear(const Math::Recti& quad, const Color& col = Color::Black) = 0;
+
+ ///
+ /// textureRT
+ ///
+ virtual void Draw(const Drawable* texture, const RenderState& state) = 0;
+
+ ///
+ /// һtextureRT
+ ///
+ virtual void Draw(const Drawable* texture, const Math::Recti& quad, const RenderState& state) = 0;
+
};
}
diff --git a/Source/Asura.Engine/Graphics/STBDecoder.cpp b/Source/Asura.Engine/Graphics/STBDecoder.cpp
new file mode 100644
index 0000000..d4d578f
--- /dev/null
+++ b/Source/Asura.Engine/Graphics/STBDecoder.cpp
@@ -0,0 +1,69 @@
+#include "STBDecoder.h"
+
+#include "Exceptions/Exception.h"
+#include "stb/stb_image.h"
+
+namespace AsuraEngine
+{
+ namespace Graphics
+ {
+
+ bool STBDecoder::CanDecode(const Filesystem::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);
+
+ return status == 1 && w > 0 && h > 0;
+ }
+
+ void STBDecoder::Decode(const Filesystem::DataBuffer* db, ImageData* imageData)
+ {
+ if (!db)
+ throw Exception("Could not decode image with stb decoder because of null databuffer.");
+ if (!imageData)
+ throw Exception("Could not decode image with stb decoder because of null output image data.");
+ const stbi_uc *buffer = (const stbi_uc *)db->data;
+ int bufferlen = db->size;
+ int width, height;
+ int comp = 0;
+ byte* data = nullptr;
+ PixelFormat format = PIXELFORMAT_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;
+ 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;
+ size = width * height * 4;
+ }
+ if (data)
+ {
+ // ֤ڴ汻ͷţһϲûͷŵΪimage dataһԵģimageǶεġ
+ if (imageData->pixels)
+ delete[] imageData->pixels;
+ imageData->pixels = (byte*)data;
+ imageData->format = format;
+ imageData->width = width;
+ imageData->height = height;
+ }
+ 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/Asura.Engine/Graphics/STBDecoder.h b/Source/Asura.Engine/Graphics/STBDecoder.h
new file mode 100644
index 0000000..d89042e
--- /dev/null
+++ b/Source/Asura.Engine/Graphics/STBDecoder.h
@@ -0,0 +1,27 @@
+#ifndef __ASURA_ENGINE_STBDECODER_H__
+#define __ASURA_ENGINE_STBDECODER_H__
+
+#include "ImageDecoder.h"
+
+namespace AsuraEngine
+{
+ namespace Graphics
+ {
+
+ ///
+ /// ʹstb_imageѹJPEGTGABMPļ
+ ///
+ class STBDecoder final : public ImageDecoder
+ {
+ public:
+
+ bool CanDecode(const Filesystem::DataBuffer* buffer) override;
+
+ void Decode(const Filesystem::DataBuffer* buffer, ImageData* data) override;
+
+ };
+
+ }
+}
+
+#endif \ No newline at end of file
diff --git a/Source/Asura.Engine/Graphics/Shader.cpp b/Source/Asura.Engine/Graphics/Shader.cpp
index 6cf65e0..1a85866 100644
--- a/Source/Asura.Engine/Graphics/Shader.cpp
+++ b/Source/Asura.Engine/Graphics/Shader.cpp
@@ -55,17 +55,17 @@ namespace AsuraEngine
}
- void Shader::SetUniformVector2(uint loc, const Math::Vector2& vec2)
+ void Shader::SetUniformVector2(uint loc, const Math::Vector2f& vec2)
{
}
- void Shader::SetUniformVector3(uint loc, const Math::Vector3& vec3)
+ void Shader::SetUniformVector3(uint loc, const Math::Vector3f& vec3)
{
}
- void Shader::SetUniformVector4(uint loc, const Math::Vector4& vec4)
+ void Shader::SetUniformVector4(uint loc, const Math::Vector4f& vec4)
{
}
diff --git a/Source/Asura.Engine/Graphics/Shader.h b/Source/Asura.Engine/Graphics/Shader.h
index 2cc482b..831f5c3 100644
--- a/Source/Asura.Engine/Graphics/Shader.h
+++ b/Source/Asura.Engine/Graphics/Shader.h
@@ -5,8 +5,8 @@
#include <string>
#include "Scripting/Luax.hpp"
-#include "Math/Vector2.h"
-#include "Math/Vector3.h"
+#include "Math/Vector2.hpp"
+#include "Math/Vector3.hpp"
#include "Math/Vector4.h"
#include "Math/Matrix44.h"
#include "StringMap.hpp"
@@ -15,7 +15,6 @@
#include "Manager.hpp"
#include "Texture.h"
#include "GL.h"
-#include "SimClass.h"
namespace AsuraEngine
{
@@ -26,7 +25,7 @@ namespace AsuraEngine
/// һshaderһڲʼ乲ijShaderuniformsͶݣֻṩuniformsuseɫķ༭
/// ÿshaderͨshaderҵuniforms¶frameworkmaterialá
///
- class Shader final : virtual public Object, public SimClass
+ class Shader final : virtual public Object
{
public:
@@ -54,9 +53,9 @@ namespace AsuraEngine
///
void SetUniformFloat(uint loc, float value);
void SetUniformTexture(uint loc, const Texture& texture);
- void SetUniformVector2(uint loc, const Math::Vector2& vec2);
- void SetUniformVector3(uint loc, const Math::Vector3& vec3);
- void SetUniformVector4(uint loc, const Math::Vector4& vec4);
+ 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);
diff --git a/Source/Asura.Engine/Graphics/Texture.h b/Source/Asura.Engine/Graphics/Texture.h
index e5b713c..c1411fc 100644
--- a/Source/Asura.Engine/Graphics/Texture.h
+++ b/Source/Asura.Engine/Graphics/Texture.h
@@ -1,9 +1,10 @@
#ifndef __ASURA_ENGINE_TEXTURE_H__
#define __ASURA_ENGINE_TEXTURE_H__
-#include "Math/Rect.h"
+#include "Math/Rect.hpp"
+#include "Math/Vector2.hpp"
#include "Scripting/Luax.hpp"
-#include "Object.h"
+#include "RenderState.h"
#include "GL.h"
namespace AsuraEngine
@@ -11,6 +12,8 @@ namespace AsuraEngine
namespace Graphics
{
+ class RenderTarget;
+
///
/// 2D࣬2d meshrender targetбʹáTextureȾԭϽǣϷϲԵѿϵΪ׼
/// EditorҲϽΪԭ㣬Ϊ˷㡣
@@ -28,12 +31,22 @@ namespace AsuraEngine
///
/// ȾtexturertϣԭϽǣң
///
- virtual void Render(int x, int y, int sx, int sy, int ox, int oy, int r) = 0;
+ virtual void Render(const RenderTarget* rt, const RenderState& state) = 0;
///
/// ȾtextureһֵrtϣԭϽǣң졣
///
- virtual void Render(const Math::Rect& quad, int x, int y, int sx, int sy, int ox, int oy, int r) = 0;
+ virtual void Render(const RenderTarget* rt, const Math::Rectf& quad, const RenderState& state) = 0;
+
+ ///
+ /// ù˷ʽ
+ ///
+ void SetSmooth(bool smooth);
+
+ ///
+ /// ظʽ
+ ///
+ void SetRepeated();
protected:
@@ -44,7 +57,7 @@ namespace AsuraEngine
};
- using Renderable = Texture;
+ using Drawable = Texture;
}
}