diff options
Diffstat (limited to 'Source/Asura.Engine/graphics')
44 files changed, 1629 insertions, 0 deletions
diff --git a/Source/Asura.Engine/graphics/application.graphics.cpp b/Source/Asura.Engine/graphics/application.graphics.cpp new file mode 100644 index 0000000..4d3102f --- /dev/null +++ b/Source/Asura.Engine/graphics/application.graphics.cpp @@ -0,0 +1,19 @@ +#include "Application.h" +#include "Sdl2/SDL.h" +#include "Exceptions/Exception.h" + +namespace AsuraEngine +{ + + /// + /// ʼgraphicsģ + /// + bool Application::InitGraphics() + { + + if (SDL_Init(SDL_INIT_VIDEO) < 0) + return false; + + } + +}
\ No newline at end of file diff --git a/Source/Asura.Engine/graphics/binding/canvas.cpp b/Source/Asura.Engine/graphics/binding/canvas.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Source/Asura.Engine/graphics/binding/canvas.cpp diff --git a/Source/Asura.Engine/graphics/binding/color.cpp b/Source/Asura.Engine/graphics/binding/color.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Source/Asura.Engine/graphics/binding/color.cpp diff --git a/Source/Asura.Engine/graphics/binding/image.cpp b/Source/Asura.Engine/graphics/binding/image.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Source/Asura.Engine/graphics/binding/image.cpp diff --git a/Source/Asura.Engine/graphics/binding/image_data.cpp b/Source/Asura.Engine/graphics/binding/image_data.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Source/Asura.Engine/graphics/binding/image_data.cpp diff --git a/Source/Asura.Engine/graphics/binding/mesh2d.cpp b/Source/Asura.Engine/graphics/binding/mesh2d.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Source/Asura.Engine/graphics/binding/mesh2d.cpp diff --git a/Source/Asura.Engine/graphics/binding/mesh2d_data.cpp b/Source/Asura.Engine/graphics/binding/mesh2d_data.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Source/Asura.Engine/graphics/binding/mesh2d_data.cpp diff --git a/Source/Asura.Engine/graphics/binding/shader.cpp b/Source/Asura.Engine/graphics/binding/shader.cpp new file mode 100644 index 0000000..27ed856 --- /dev/null +++ b/Source/Asura.Engine/graphics/binding/shader.cpp @@ -0,0 +1,119 @@ +#include "../Shader.h" + +using namespace Luax; + +namespace AsuraEngine +{ + namespace Graphics + { + + /// + /// shaderΪ + /// + int Shader::l_Use(lua_State* L) + { + LUAX_STATE(L); + + } + + /// + /// shaderΪǻ + /// + int Shader::l_Unuse(lua_State* L) + { + LUAX_STATE(L); + + } + + /// + /// ɫйshaderɹtrueʧܷfalse + /// + int Shader::l_Load(lua_State* L) + { + LUAX_STATE(L); + + } + + /// + /// жshaderǷuniformзtrue,false + /// + int Shader::l_HasUniform(lua_State* L) + { + LUAX_STATE(L); + + } + + /// + /// uniformslocationûuniformnilضӦloc + /// + int Shader::l_GetUniformLocation(lua_State* L) + { + LUAX_STATE(L); + + } + + int Shader::l_SetBuiltInUniforms(lua_State* L) + { + LUAX_STATE(L); + + } + + int Shader::l_SetUniformFloat(lua_State* L) + { + LUAX_STATE(L); + + } + + int Shader::l_SetUniformTexture(lua_State* L) + { + LUAX_STATE(L); + + } + + int Shader::l_SetUniformVector2(lua_State* L) + { + LUAX_STATE(L); + + } + + int Shader::l_SetUniformVector3(lua_State* L) + { + LUAX_STATE(L); + + } + + int Shader::l_SetUniformVector4(lua_State* L) + { + LUAX_STATE(L); + + } + + int Shader::l_SetUniformColor(lua_State* L) + { + LUAX_STATE(L); + + } + + void Shader::RegisterLuaxClass(LuaxState& state) + { + + } + + void Shader::RegisterLuaxInterface(LuaxState& state) + { + + } + + void Shader::RegisterLuaxClass(LuaxState& state) + { + + LuaxEnum EBuiltIn[] = { + {0, 0} + }; + + state.RegisterEnum("EBuiltIn", EBuiltIn); + + } + + } +}
\ No newline at end of file diff --git a/Source/Asura.Engine/graphics/binding/sprite_batch.cpp b/Source/Asura.Engine/graphics/binding/sprite_batch.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Source/Asura.Engine/graphics/binding/sprite_batch.cpp diff --git a/Source/Asura.Engine/graphics/binding/window.cpp b/Source/Asura.Engine/graphics/binding/window.cpp new file mode 100644 index 0000000..3befc8c --- /dev/null +++ b/Source/Asura.Engine/graphics/binding/window.cpp @@ -0,0 +1,11 @@ +#include "../Window.h" + +namespace AsuraEngine +{ + namespace Graphics + { + + + + } +} diff --git a/Source/Asura.Engine/graphics/blend_mode.h b/Source/Asura.Engine/graphics/blend_mode.h new file mode 100644 index 0000000..775cc45 --- /dev/null +++ b/Source/Asura.Engine/graphics/blend_mode.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 new file mode 100644 index 0000000..61787b6 --- /dev/null +++ b/Source/Asura.Engine/graphics/canvas.cpp @@ -0,0 +1,41 @@ +#include "Canvas.h" + +namespace AsuraEngine +{ + namespace Graphics + { + + Canvas::Canvas() + : Texture() + , mWidth(0) + , mHeight(0) + { + glGenFramebuffers(1, &mFBO); + GLint current_fbo; + glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, ¤t_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, ¤t_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 new file mode 100644 index 0000000..c4e0f65 --- /dev/null +++ b/Source/Asura.Engine/graphics/canvas.h @@ -0,0 +1,81 @@ +#ifndef __ASURA_ENGINE_CANVAS_H__ +#define __ASURA_ENGINE_CANVAS_H__ + +#include <Scripting/Luax.hpp> + +#include "Math/Rect.hpp" +#include "GL.h" +#include "Texture.h" +#include "RenderTarget.h" + +namespace AsuraEngine +{ + namespace Graphics + { + + /// + /// CanvasҲԳΪrender textureҲΪtextureȾ + /// + class Canvas ASURA_FINAL + : public Drawable + , public RenderTarget + , public Scripting::Portable + { + public: + + Canvas(); + + ~Canvas(); + + /// + /// render textureĴС + /// + void SetSize(uint w, uint h); + + void Clear(const Color& col = Color::Black) override; + + void Clear(const Math::Recti& quad, const Color& col = Color::Black) override; + + void Render(const RenderTarget* rt, const Math::Vector2i& pos, const Math::Vector2i& scale, const Math::Vector2i& center, float rot); + + void Render(const RenderTarget* rt, const Math::Rectf& quad, const Math::Vector2i& pos, const Math::Vector2i& scale, const Math::Vector2i& center, float rot); + + void Draw(const Drawable* texture, const RenderState& state); + + void Draw(const Drawable* texture, const Math::Recti& quad, const RenderState& state); + + private: + + /// + /// Frame buffer object id. + /// + GLuint mFBO; + + /// + /// canvasĴС + /// + uint mWidth, mHeight; + + public: + + //---------------------------------------------------------------------------------------------------------- + + LUAX_DECL_FACTORY(SimCanvas); + + LUAX_DECL_METHOD(l_SetSize); + LUAX_DECL_METHOD(l_Bind); + LUAX_DECL_METHOD(l_Unbind); + + //---------------------------------------------------------------------------------------------------------- + + }; + + /// + /// CanvasΪRenderTexture + /// + using RenderTexture = Canvas; + + } +} + +#endif
\ No newline at end of file diff --git a/Source/Asura.Engine/graphics/color.cpp b/Source/Asura.Engine/graphics/color.cpp new file mode 100644 index 0000000..106493d --- /dev/null +++ b/Source/Asura.Engine/graphics/color.cpp @@ -0,0 +1,132 @@ +#include "Color.h" + +namespace AsuraEngine +{ + namespace Graphics + { + + Color32::Color32() + { + r = g = b = a = 0; + } + + Color32::Color32(const Color32& c) + { + r = c.r; + g = c.g; + b = c.b; + a = c.a; + } + + Color32::Color32(const Color& c) + { + r = 255.f * c.r; + g = 255.f * c.g; + b = 255.f * c.b; + a = 255.f * c.a; + } + + Color32::Color32(byte r, byte g, byte b, byte a) + { + this->r = r; + this->g = g; + this->b = b; + this->a = a; + } + + int Color32::l_GetRed(lua_State* L) + { + + } + + int Color32::l_GetGreen(lua_State* L) + { + + } + + int Color32::l_GetBlue(lua_State* L) + { + + } + + int Color32::l_GetAlpha(lua_State* L) + { + + } + + //------------------------------------------------------------------------------------------------------------ + + Color::Color() + { + r = g = b = a = 0; + } + + Color::Color(const Color& c) + { + r = c.r; + g = c.g; + b = c.b; + a = c.a; + } + + Color::Color(float r, float g, float b, float a) + { + this->r = r; + this->g = g; + this->b = b; + this->a = a; + } + + Color::Color(const Color32& c) + { + r = c.r / 255.f; + g = c.g / 255.f; + b = c.b / 255.f; + a = c.a / 255.f; + } + + Color Color::operator *(const Color& c) + { + r *= c.r; + g *= c.g; + b *= c.b; + a *= c.a; + } + + int Color::l_GetRed(lua_State* L) + { + + } + + int Color::l_GetGreen(lua_State* L) + { + + } + + int Color::l_GetBlue(lua_State* L) + { + + } + + int Color::l_GetAlpha(lua_State* L) + { + + } + + int Color::l_Add(lua_State* L) + { + + } + + int Color::l_Minus(lua_State* L) + { + + } + + int Color::l_Multiply(lua_State* L) + { + + } + + } +}
\ No newline at end of file diff --git a/Source/Asura.Engine/graphics/color.h b/Source/Asura.Engine/graphics/color.h new file mode 100644 index 0000000..0d65cb1 --- /dev/null +++ b/Source/Asura.Engine/graphics/color.h @@ -0,0 +1,94 @@ +#ifndef __ASURA_ENGINE_COLOR_H__ +#define __ASURA_ENGINE_COLOR_H__ + +#include "Scripting/Luax.hpp" +#include "Scripting/Portable.h" +#include "Config.h" + +namespace AsuraEngine +{ + namespace Graphics + { + + class Color; + + /// + /// 32bitsɫ + /// + class Color32 ASURA_FINAL: public Scripting::Portable + { + public: + + Color32(); + + ~Color32(); + + Color32(const Color32& c); + + Color32(const Color& c); + + Color32(byte r, byte g, byte b, byte a); + + byte r, g, b, a; + + //---------------------------------------------------------------------------------------------------------- + + LUAX_DECL_FACTORY(Color32); + + LUAX_DECL_METHOD(l_ToColor); + LUAX_DECL_METHOD(l_GetRed); + LUAX_DECL_METHOD(l_GetGreen); + LUAX_DECL_METHOD(l_GetBlue); + LUAX_DECL_METHOD(l_GetAlpha); + LUAX_DECL_METHOD(l_Multiply); + LUAX_DECL_METHOD(l_Index); //r,g,b,a + LUAX_DECL_METHOD(l_NewIndex); //r,g,b,a + + //---------------------------------------------------------------------------------------------------------- + + }; + + /// + /// 淶ɫ + /// + class Color ASURA_FINAL: public Scripting::Portable + { + public: + + static Color Black; + static Color White; + static Color Red; + static Color Green; + static Color Blue; + + Color(); + + Color(const Color& c); + + Color(float r, float g, float b, float a); + + Color(const Color32& c); + + ~Color(); + + Color operator *(const Color& c); + + float r, g, b, a; + + //---------------------------------------------------------------------------------------------------------- + + LUAX_DECL_FACTORY(Color); + + LUAX_DECL_METHOD(l_ToColor32); + LUAX_DECL_METHOD(l_SetColor); + LUAX_DECL_METHOD(l_GetColor); + LUAX_DECL_METHOD(l_Multiply); // ɫ˷ + + //---------------------------------------------------------------------------------------------------------- + + }; + + } +} + +#endif
\ No newline at end of file diff --git a/Source/Asura.Engine/graphics/gl.cpp b/Source/Asura.Engine/graphics/gl.cpp new file mode 100644 index 0000000..dac2ea4 --- /dev/null +++ b/Source/Asura.Engine/graphics/gl.cpp @@ -0,0 +1,11 @@ +#include "OpenGL.h" + +namespace AsuraEngine +{ + namespace Graphics + { + + + + } +}
\ No newline at end of file diff --git a/Source/Asura.Engine/graphics/gl.h b/Source/Asura.Engine/graphics/gl.h new file mode 100644 index 0000000..0661e17 --- /dev/null +++ b/Source/Asura.Engine/graphics/gl.h @@ -0,0 +1,19 @@ +#ifndef __ASURA_ENGINE_OPENGL_H__ +#define __ASURA_ENGINE_OPENGL_H__ + +#include "glad/glad.h" + +namespace AsuraEngine +{ + namespace Graphics + { + + class OpenGL + { + + }; + + } +} + +#endif
\ No newline at end of file diff --git a/Source/Asura.Engine/graphics/image.cpp b/Source/Asura.Engine/graphics/image.cpp new file mode 100644 index 0000000..e704945 --- /dev/null +++ b/Source/Asura.Engine/graphics/image.cpp @@ -0,0 +1,32 @@ +#include "Config.h" +#include "Image.h" +#include "GL.h" + +namespace AsuraEngine +{ + namespace Graphics + { + + Image::Image() + { + } + + Image::~Image() + { + } + + //\Ϣ + bool Image::Load(ImageData* 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); + glBindTexture(GL_TEXTURE_2D, 0); + return true; + + RRA(data, mImageData); + } + + } +}
\ No newline at end of file diff --git a/Source/Asura.Engine/graphics/image.h b/Source/Asura.Engine/graphics/image.h new file mode 100644 index 0000000..66c7ae1 --- /dev/null +++ b/Source/Asura.Engine/graphics/image.h @@ -0,0 +1,78 @@ +#ifndef __ASURA_ENGINE_IMAGE_H__ +#define __ASURA_ENGINE_IMAGE_H__ + +#include "Math/Vector2.hpp" +#include "Scripting/Portable.h" +#include "FileSystem/Reloadable.h" +#include "StringMap.hpp" +#include "Manager.hpp" +#include "Texture.h" +#include "Color.h" +#include "ImageData.h" + +namespace AsuraEngine +{ + namespace Graphics + { + + class ImageFactory; + + /// + /// ImageͼƬڴȡϷĽһImageڴ桢ԴֻᱣһݣҪ + /// imageêλãźתǶȣʹspriteһֻࡣҪǿǵeditorengineʹòͬķװ + /// + class Image ASURA_FINAL + : public Drawable + , public Scripting::Portable + , public Filesystem::Reloadable + { + public: + + Image(); + + ~Image(); + + /// + /// bufferimageϢmPixelsΪգݡ¹imageʹglTexImage2Dύimage + /// ݡ + /// + bool Load(ImageData* data); + + uint GetWidth(); + uint GetHeight(); + Math::Vector2u GetSize(); + + /// + /// ijһλõ + /// + 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; + + private: + + ImageData* mImageData; + + Math::Vector2u mSize; + + public: + + //---------------------------------------------------------------------------------------------------------- + + LUAX_DECL_FACTORY(SimImage); + + LUAX_DECL_METHOD(l_Load); + LUAX_DECL_METHOD(l_GetWidth); + LUAX_DECL_METHOD(l_GetHeight); + LUAX_DECL_METHOD(l_GetSize); + + //---------------------------------------------------------------------------------------------------------- + + }; + + } +} + +#endif
\ No newline at end of file diff --git a/Source/Asura.Engine/graphics/image_data.cpp b/Source/Asura.Engine/graphics/image_data.cpp new file mode 100644 index 0000000..68781a1 --- /dev/null +++ b/Source/Asura.Engine/graphics/image_data.cpp @@ -0,0 +1,50 @@ +#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 + }; + + 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/image_data.h b/Source/Asura.Engine/graphics/image_data.h new file mode 100644 index 0000000..931eaa3 --- /dev/null +++ b/Source/Asura.Engine/graphics/image_data.h @@ -0,0 +1,62 @@ +#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 ASURA_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; + + private: + + void Decode(const Filesystem::DataBuffer& buffer) override; + + /// + /// ڵһimage dataʱṩdecoderڼdecodersмѡԡ + /// + static std::list<ImageDecoder*> ImageDecoders; + + public: + + //---------------------------------------------------------------------------------------------------------- + + LUAX_DECL_FACTORY(ImageData); + + LUAX_DECL_METHOD(l_GetPixel); + LUAX_DECL_METHOD(l_GetSize); + + //---------------------------------------------------------------------------------------------------------- + + }; + + } +} + +#endif
\ No newline at end of file diff --git a/Source/Asura.Engine/graphics/image_decoder.h b/Source/Asura.Engine/graphics/image_decoder.h new file mode 100644 index 0000000..2c73fd1 --- /dev/null +++ b/Source/Asura.Engine/graphics/image_decoder.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 + { + 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.cpp b/Source/Asura.Engine/graphics/mesh2d.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Source/Asura.Engine/graphics/mesh2d.cpp diff --git a/Source/Asura.Engine/graphics/mesh2d.h b/Source/Asura.Engine/graphics/mesh2d.h new file mode 100644 index 0000000..de4a0c8 --- /dev/null +++ b/Source/Asura.Engine/graphics/mesh2d.h @@ -0,0 +1,29 @@ +#ifndef __ASURA_ENGINE_MESH2D_H__ +#define __ASURA_ENGINE_MESH2D_H__ + +#include "Scripting/Luax.hpp" + +#include "Scripting/Portable.h" + +namespace AsuraEngine +{ + namespace Graphics + { + + /// + /// 2D meshһЩ㶯 + /// + class Mesh2D ASURA_FINAL: public Scripting::Portable + { + public: + + Mesh2D(); + + ~Mesh2D(); + + }; + + } +} + +#endif
\ No newline at end of file diff --git a/Source/Asura.Engine/graphics/pixel_format.h b/Source/Asura.Engine/graphics/pixel_format.h new file mode 100644 index 0000000..8df07d5 --- /dev/null +++ b/Source/Asura.Engine/graphics/pixel_format.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/png_decoder.cpp b/Source/Asura.Engine/graphics/png_decoder.cpp new file mode 100644 index 0000000..f919090 --- /dev/null +++ b/Source/Asura.Engine/graphics/png_decoder.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/png_decoder.h b/Source/Asura.Engine/graphics/png_decoder.h new file mode 100644 index 0000000..980753f --- /dev/null +++ b/Source/Asura.Engine/graphics/png_decoder.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 ASURA_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/quad.cpp b/Source/Asura.Engine/graphics/quad.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Source/Asura.Engine/graphics/quad.cpp diff --git a/Source/Asura.Engine/graphics/quad.h b/Source/Asura.Engine/graphics/quad.h new file mode 100644 index 0000000..b7dd3d9 --- /dev/null +++ b/Source/Asura.Engine/graphics/quad.h @@ -0,0 +1 @@ +// Quadrectڣrectǵıƫᣬquadһ diff --git a/Source/Asura.Engine/graphics/render_state.h b/Source/Asura.Engine/graphics/render_state.h new file mode 100644 index 0000000..f313296 --- /dev/null +++ b/Source/Asura.Engine/graphics/render_state.h @@ -0,0 +1,50 @@ +#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 + { + + /// + /// Ⱦǰķʽ + /// + struct RenderState ASURA_FINAL + { + /// + /// Ĭϵ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/render_target.cpp b/Source/Asura.Engine/graphics/render_target.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Source/Asura.Engine/graphics/render_target.cpp diff --git a/Source/Asura.Engine/graphics/render_target.h b/Source/Asura.Engine/graphics/render_target.h new file mode 100644 index 0000000..d6de164 --- /dev/null +++ b/Source/Asura.Engine/graphics/render_target.h @@ -0,0 +1,54 @@ +#ifndef __ASURA_ENGINE_RENDERTARGET_H__ +#define __ASURA_ENGINE_RENDERTARGET_H__ + +#include "Math/Rect.hpp" +#include "Texture.h" +#include "Scripting/Portable.h" +#include "Color.h" + +namespace AsuraEngine +{ + namespace Graphics + { + + class Drawable; + + /// + /// ɱΪȾĿ࣬ + /// Canvas(RenderTexture) + /// Window(RenderWindow) + /// + class RenderTarget + { + public: + + RenderTarget() {}; + + 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; + + }; + + } +} + +#endif
\ No newline at end of file diff --git a/Source/Asura.Engine/graphics/shader.cpp b/Source/Asura.Engine/graphics/shader.cpp new file mode 100644 index 0000000..1a85866 --- /dev/null +++ b/Source/Asura.Engine/graphics/shader.cpp @@ -0,0 +1,81 @@ +#include "Shader.h" + +namespace AsuraEngine +{ + namespace Graphics + { + + Shader::Shader() + { + + } + + Shader::~Shader() + { + + } + + bool Shader::Load(const std::string& vertexShader, const std::string& fragmentShader) + { + + } + + uint Shader::GetUniformLocation(const std::string& uniform) + { + + } + + GLuint Shader::GetGLProgramHandle() + { + return mProgramHandle; + } + + void Shader::Use() + { + + } + + void Shader::Unuse() + { + + } + + void Shader::SetUniformFloat(uint loc, float value) + { + + } + + void Shader::SetUniformFloat(uint loc, float value) + { + + } + + void Shader::SetUniformTexture(uint loc, const Texture& texture) + { + + } + + void Shader::SetUniformVector2(uint loc, const Math::Vector2f& vec2) + { + + } + + void Shader::SetUniformVector3(uint loc, const Math::Vector3f& vec3) + { + + } + + void Shader::SetUniformVector4(uint loc, const Math::Vector4f& vec4) + { + + } + + uint Shader::GetGLTextureUnitCount() + { + GLint maxTextureUnits = 0; + glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &maxTextureUnits); + return (uint)maxTextureUnits; + } + + } +}
\ No newline at end of file diff --git a/Source/Asura.Engine/graphics/shader.h b/Source/Asura.Engine/graphics/shader.h new file mode 100644 index 0000000..103c7b7 --- /dev/null +++ b/Source/Asura.Engine/graphics/shader.h @@ -0,0 +1,123 @@ +#ifndef __ASURA_ENGINE_SHADER_H__ +#define __ASURA_ENGINE_SHADER_H__ + +#include <map> +#include <string> + +#include "FileSystem/Reloadable.h" +#include "Scripting/Luax.hpp" +#include "Math/Vector2.hpp" +#include "Math/Vector3.hpp" +#include "Math/Vector4.h" +#include "Math/Matrix44.h" +#include "StringMap.hpp" +#include "scripting/portable.h" +#include "Color.h" +#include "Manager.hpp" +#include "Texture.h" +#include "GL.h" + +namespace AsuraEngine +{ + namespace Graphics + { + + /// + /// һshaderһڲʼ乲ijShaderuniformsͶݣֻṩuniformsuseɫķ༭ + /// ÿshaderͨshaderҵuniforms¶frameworkmaterialá + /// + class Shader ASURA_FINAL + : public Scripting::Portable<Shader> + , public Filesystem::Reloadable + { + public: + + Shader(); + + ~Shader(); + + /// + /// ӴshaderʱȼǷϴλuniforms location mapʹglAttachShader±ɫ + /// ɫ + /// + bool Load(const std::string& vertexShader, const std::string& fragmentShader); + + /// + /// shaderΪ + /// + void Use(); + + /// + /// shaderΪǻ + /// + void Unuse(); + + /// + /// Ѿ֪uniform location£ֵ + /// + void SetUniformFloat(uint loc, float value); + void SetUniformTexture(uint loc, const Texture& texture); + 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); + + uint GetUniformLocation(const std::string& uniform); + + bool HasUniform(const std::string& uniform); + + GLuint GetGLProgramHandle(); + + /// + /// texture unitһΪ16 + /// + static uint GetGLTextureUnitCount(); + + private: + + /// + /// ǰshader + /// + static Shader* mCurrentShader; + + /// + /// ñ + /// vec2 Asura_Time xֵΪ뵱ǰʼʱ䣬yֵΪһ֡ʱ + /// vec2 Asura_RenderTargetSize RTĴСΪλ + /// Texture Asura_MainTexture + /// + void SetBuiltInUniforms(); + + /// + /// OpenGL shader program handle. + /// + GLuint mProgramHandle; + + public: + + //---------------------------------------------------------------------------------------------------------- + + LUAX_DECL_FACTORY(SimShader); + + LUAX_DECL_METHOD(l_Use); + LUAX_DECL_METHOD(l_Unuse); + LUAX_DECL_METHOD(l_Load); + LUAX_DECL_METHOD(l_HasUniform); + LUAX_DECL_METHOD(l_GetUniformLocation); + LUAX_DECL_METHOD(l_SetBuiltInUniforms); + LUAX_DECL_METHOD(l_SetUniformFloat); + LUAX_DECL_METHOD(l_SetUniformTexture); + LUAX_DECL_METHOD(l_SetUniformVector2); + LUAX_DECL_METHOD(l_SetUniformVector3); + LUAX_DECL_METHOD(l_SetUniformVector4); + LUAX_DECL_METHOD(l_SetUniformColor); + + //---------------------------------------------------------------------------------------------------------- + + }; + + } +} + +#endif
\ No newline at end of file diff --git a/Source/Asura.Engine/graphics/shape.cpp b/Source/Asura.Engine/graphics/shape.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Source/Asura.Engine/graphics/shape.cpp diff --git a/Source/Asura.Engine/graphics/shape.h b/Source/Asura.Engine/graphics/shape.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Source/Asura.Engine/graphics/shape.h diff --git a/Source/Asura.Engine/graphics/sprite_batch.cpp b/Source/Asura.Engine/graphics/sprite_batch.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Source/Asura.Engine/graphics/sprite_batch.cpp diff --git a/Source/Asura.Engine/graphics/sprite_batch.h b/Source/Asura.Engine/graphics/sprite_batch.h new file mode 100644 index 0000000..7909519 --- /dev/null +++ b/Source/Asura.Engine/graphics/sprite_batch.h @@ -0,0 +1,28 @@ +#ifndef __ASURA_ENGINE_SPRITE_BATCH_H__ +#define __ASURA_ENGINE_SPRITE_BATCH_H__ + +#include "Scripting/Portable.h" + +namespace AsuraEngine +{ + namespace Graphics + { + + /// + /// Sprite batchȾͼƬĵطϵͳ + /// + class SpriteBatch ASURA_FINAL + : public Scripting::Portable<SpriteBatch> + { + public: + + SpriteBatch(); + + ~SpriteBatch(); + + }; + + } +} + +#endif
\ No newline at end of file diff --git a/Source/Asura.Engine/graphics/stb_decoder.cpp b/Source/Asura.Engine/graphics/stb_decoder.cpp new file mode 100644 index 0000000..b14d0f3 --- /dev/null +++ b/Source/Asura.Engine/graphics/stb_decoder.cpp @@ -0,0 +1,65 @@ +#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) + { + 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/stb_decoder.h b/Source/Asura.Engine/graphics/stb_decoder.h new file mode 100644 index 0000000..b8fb83c --- /dev/null +++ b/Source/Asura.Engine/graphics/stb_decoder.h @@ -0,0 +1,27 @@ +#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(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/texture.cpp b/Source/Asura.Engine/graphics/texture.cpp new file mode 100644 index 0000000..6cb6497 --- /dev/null +++ b/Source/Asura.Engine/graphics/texture.cpp @@ -0,0 +1,26 @@ +#include "Texture.h" + +namespace AsuraEngine +{ + namespace Graphics + { + + Texture::Texture() + : mTextureHandle(0) + { + // GL texture + glGenTextures(1, &mTextureHandle); + } + + Texture::~Texture() + { + glDeleteTextures(1, &mTextureHandle); + } + + GLuint Texture::GetGLTextureHandle() const + { + return mTextureHandle; + } + + } +}
\ No newline at end of file diff --git a/Source/Asura.Engine/graphics/texture.h b/Source/Asura.Engine/graphics/texture.h new file mode 100644 index 0000000..81aa469 --- /dev/null +++ b/Source/Asura.Engine/graphics/texture.h @@ -0,0 +1,66 @@ +#ifndef __ASURA_ENGINE_TEXTURE_H__ +#define __ASURA_ENGINE_TEXTURE_H__ + +#include "Config.h" +#include "Math/Rect.hpp" +#include "Math/Vector2.hpp" +#include "Scripting/Luax.hpp" +#include "RenderState.h" +#include "GL.h" + +namespace AsuraEngine +{ + namespace Graphics + { + + class RenderTarget; + + /// + /// 2D࣬2d meshrender targetбʹáTextureȾԭϽǣϷϲԵѿϵΪ + /// EditorҲϽΪԭ㣬Ϊ˷㡣 + /// + ASURA_ABSTRACT class Texture + { + public: + + Texture(); + + virtual ~Texture(); + + GLuint GetGLTextureHandle() const; + + /// + /// ȾtexturertϣԭϽǣң + /// + virtual void Render(const RenderTarget* rt, const RenderState& state) = 0; + + /// + /// ȾtextureһֵrtϣԭϽǣң졣 + /// + virtual void Render(const RenderTarget* rt, const Math::Rectf& quad, const RenderState& state) = 0; + + /// + /// ù˷ʽ + /// + void SetSmooth(bool smooth); + + /// + /// ظʽ + /// + void SetRepeated(); + + protected: + + /// + /// OpenGL texture handle + /// + GLuint mTextureHandle; + + }; + + using Drawable = Texture; + + } +} + +#endif
\ No newline at end of file diff --git a/Source/Asura.Engine/graphics/window.cpp b/Source/Asura.Engine/graphics/window.cpp new file mode 100644 index 0000000..bb941e1 --- /dev/null +++ b/Source/Asura.Engine/graphics/window.cpp @@ -0,0 +1,56 @@ +#include "Config.h" +#include "Window.h" + +namespace AsuraEngine +{ + namespace Graphics + { + + Window::Window(WindowStyle style) + { + //mWindowHandle = SDL_CreateWindow(); + } + + Window::~Window() + { + + } + + SDL_Window* Window::GetSDLWindowHandle() + { + return mWindowHandle; + } + + void Window::SetPosition(int x, int y) + { + ASSERT(mWindowHandle); + SDL_SetWindowPosition(mWindowHandle, x, y); + } + + void Window::SetTitle(const std::string& title) + { + + } + + void Window::Show() + { + + } + + void Window::Hide() + { + + } + + void Window::SetWindowStyle(WindowStyle style) + { + + } + + void Window::SwapRenderBuffer() + { + + } + + } +} diff --git a/Source/Asura.Engine/graphics/window.h b/Source/Asura.Engine/graphics/window.h new file mode 100644 index 0000000..973fd98 --- /dev/null +++ b/Source/Asura.Engine/graphics/window.h @@ -0,0 +1,85 @@ +#ifndef __ASURA_ENGINE_WINDOW_H__ +#define __ASURA_ENGINE_WINDOW_H__ + +#include "SDL2/Sdl.h" +#include "Graphics/RenderTarget.h" +#include "Math/Vector2.hpp" +#include "Scripting/Portable.h" + +namespace AsuraEngine +{ + namespace Graphics + { + + enum WindowStyle + { + WINDOW_STYLE_FULLSCREEN = 1 << 1, + }; + + /// + /// ڣֶ֧രڡڱ༭Ҫ֧֣runnerֻҪһڡ + /// + class Window ASURA_FINAL + : public RenderTarget + , public Scripting::Portable + { + public: + + Window(WindowStyle style); + + ~Window(); + + SDL_Window* GetSDLWindowHandle(); + + void SetSize(uint width, uint height); + + void SetPosition(int x, int y); + + void SetTitle(const std::string& title); + + void SetWindowStyle(WindowStyle style); + + void Show(); + + void Hide(); + + /// + /// ǿ˫ĴڣҪչʾǰ̨ + /// + void SwapRenderBuffer(); + + void Clear(const Color& col = Color::Black) override; + + void Clear(const Math::Recti& quad, const Color& col = Color::Black) override; + + void Draw(const Drawable* texture, const RenderState& state) override; + + void Draw(const Drawable* texture, const Math::Recti& quad, const RenderState& state) override; + + private: + + /// + /// SDL window handle. + /// + SDL_Window* mWindowHandle; + + Math::Vector2i mPosition; + + Math::Vector2i mSize; + + public: + + //---------------------------------------------------------------------------------------------------------- + + LUAX_DECL_FACTORY(Window); + + //---------------------------------------------------------------------------------------------------------- + + }; + + using RenderWindow = Window; + + } +} + +#endif
\ No newline at end of file |