diff --git a/framework/platform-dx/texture.cpp b/framework/platform-dx/texture.cpp index 3f54d5a..2d74881 100644 --- a/framework/platform-dx/texture.cpp +++ b/framework/platform-dx/texture.cpp @@ -37,7 +37,7 @@ namespace xna { return texture2d; } - bool Texture2D::Initialize() + void Texture2D::Initialize() { if (!m_device || !m_device->impl->_device) { Exception::Throw(Exception::UNABLE_TO_INITIALIZE); @@ -62,7 +62,8 @@ namespace xna { Exception::Throw(Exception::FAILED_TO_CREATE); } - return true; + surfaceFormat = DxHelpers::SurfaceFormatToXna(impl->dxDescription.Format); + levelCount = static_cast(impl->dxShaderDescription.Texture2D.MipLevels); } void setDefaultDesc(Texture2D::PlatformImplementation& impl) { @@ -79,24 +80,24 @@ namespace xna { impl.dxShaderDescription.Texture2D.MostDetailedMip = 0; } - Texture2D::Texture2D() : GraphicsResource(nullptr) { + Texture2D::Texture2D() : Texture(nullptr) { impl = unew(); setDefaultDesc(*impl); } - Texture2D::Texture2D(sptr const& device, size_t width, size_t height) : GraphicsResource(device) { + Texture2D::Texture2D(sptr const& device, size_t width, size_t height) : Texture(device) { impl = unew(); setDefaultDesc(*impl); impl->dxDescription.Width = static_cast(width); impl->dxDescription.Height = static_cast(height); } - Texture2D::Texture2D(sptr const& device) : GraphicsResource(device) { + Texture2D::Texture2D(sptr const& device) : Texture(device) { impl = unew(); setDefaultDesc(*impl); } - Texture2D::Texture2D(sptr const& device, size_t width, size_t height, size_t mipMap, SurfaceFormat format) : GraphicsResource(device) + Texture2D::Texture2D(sptr const& device, size_t width, size_t height, size_t mipMap, SurfaceFormat format) : Texture(device) { impl = unew(); setDefaultDesc(*impl); diff --git a/inc/xna/default.hpp b/inc/xna/default.hpp index 4725e7a..9d2c563 100644 --- a/inc/xna/default.hpp +++ b/inc/xna/default.hpp @@ -202,6 +202,8 @@ namespace xna { using P_RasterizerState = sptr; using P_PresentationParameters = sptr; using P_SamplerStateCollection = sptr; + using P_Texture = sptr; + using P_Texture2D = sptr; } diff --git a/inc/xna/graphics/texture.hpp b/inc/xna/graphics/texture.hpp index e5afae4..6d6a00c 100644 --- a/inc/xna/graphics/texture.hpp +++ b/inc/xna/graphics/texture.hpp @@ -5,28 +5,41 @@ #include "gresource.hpp" namespace xna { - class Texture { + //Represents a texture resource. + class Texture : public GraphicsResource { public: - ~Texture() {} + Texture(P_GraphicsDevice const& graphicsDevice) : GraphicsResource(graphicsDevice) {} + + virtual ~Texture() {} + + //Gets the format of the texture data. + constexpr SurfaceFormat Format() const { return surfaceFormat; } + //Gets the number of texture levels in a multilevel texture. + constexpr Int LevelCount() const { return levelCount; } + + protected: + SurfaceFormat surfaceFormat{SurfaceFormat::Color}; + Int levelCount{ 0 }; }; - class Texture2D : public Texture, public GraphicsResource { + class Texture2D : public Texture { public: Texture2D(); - Texture2D(sptr const& device); - Texture2D(sptr const& device, size_t width, size_t height); - Texture2D(sptr const& device, size_t width, size_t height, size_t mipMap, SurfaceFormat format); + Texture2D(P_GraphicsDevice const& device); + Texture2D(P_GraphicsDevice const& device, size_t width, size_t height); + Texture2D(P_GraphicsDevice const& device, size_t width, size_t height, size_t mipMap, SurfaceFormat format); ~Texture2D() override; Int Width() const; Int Height() const; Rectangle Bounds() const; - bool Initialize(); void SetData(std::vector const& data, size_t startIndex = 0, size_t elementCount = 0); void SetData(std::vector const& data, size_t startIndex = 0, size_t elementCount = 0); void SetData(std::vector const& data, size_t startIndex = 0, size_t elementCount = 0); void SetData(Int level, Rectangle* rect, std::vector const& data, size_t startIndex, size_t elementCount); - static sptr FromStream(GraphicsDevice& device, String const& fileName); - static sptr FromMemory(GraphicsDevice& device, std::vector const& data); + static P_Texture2D FromStream(GraphicsDevice& device, String const& fileName); + static P_Texture2D FromMemory(GraphicsDevice& device, std::vector const& data); + + void Initialize(); public: struct PlatformImplementation; @@ -34,7 +47,7 @@ namespace xna { }; - using PTexture2D = sptr; + using PTexture2D = P_Texture2D; } #endif \ No newline at end of file