1
0
mirror of https://github.com/borgesdan/xn65 synced 2024-12-29 21:54:47 +01:00
xn65/includes/xna/graphics/texture.hpp

71 lines
2.5 KiB
C++
Raw Normal View History

2024-03-18 15:41:46 -03:00
#ifndef XNA_GRAPHICS_TEXTURE_HPP
#define XNA_GRAPHICS_TEXTURE_HPP
2024-05-04 21:07:39 -03:00
#include "../default.hpp"
2024-05-23 14:38:16 -03:00
#include "gresource.hpp"
2024-03-18 15:41:46 -03:00
namespace xna {
//Represents a texture resource.
class Texture : public GraphicsResource {
2024-05-23 14:38:16 -03:00
public:
Texture(P_GraphicsDevice const& graphicsDevice) : GraphicsResource(graphicsDevice) {}
//Gets the format of the texture data.
virtual SurfaceFormat Format() const = 0;
//Gets the number of texture levels in a multilevel texture.
virtual Int LevelCount() const = 0;
2024-03-18 15:41:46 -03:00
};
//Represents a 2D grid of texels.
class Texture2D : public Texture {
2024-05-23 14:38:16 -03:00
public:
Texture2D();
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);
//Gets the width of this texture resource, in pixels.
constexpr Int Width() const { return width; }
//Gets the height of this texture resource, in pixels.
constexpr Int Height() const { return height; }
//Gets the size of this resource.
constexpr Rectangle Bounds() const { return { 0, 0, width, height }; }
//Gets the format of the texture data.
constexpr SurfaceFormat Format() const override { return surfaceFormat; }
//Gets the number of texture levels in a multilevel texture.
constexpr Int LevelCount() const { return levelCount; }
//Sets data to the texture.
void SetData(std::vector<Color> const& data, size_t startIndex = 0, size_t elementCount = 0);
//Sets data to the texture.
void SetData(std::vector<Uint> const& data, size_t startIndex = 0, size_t elementCount = 0);
//Sets data to the texture.
void SetData(std::vector<Byte> const& data, size_t startIndex = 0, size_t elementCount = 0);
//Sets data to the texture.
void SetData(Int level, Rectangle* rect, std::vector<Byte> const& data, size_t startIndex, size_t elementCount);
//Loads texture data from a stream.
static P_Texture2D FromStream(GraphicsDevice& device, P_Stream const& stream);
//Loads texture data from a file.
static P_Texture2D FromStream(GraphicsDevice& device, String const& fileName);
//Loads texture data from a data.
static P_Texture2D FromStream(GraphicsDevice& device, std::vector<Byte> const& data);
void Initialize();
protected:
SurfaceFormat surfaceFormat{ SurfaceFormat::Color };
Int levelCount{ 0 };
int width{ 0 };
int height{ 0 };
2024-05-23 14:38:16 -03:00
2024-03-18 15:41:46 -03:00
public:
2024-05-23 14:38:16 -03:00
struct PlatformImplementation;
uptr<PlatformImplementation> impl = nullptr;
2024-03-18 15:41:46 -03:00
};
2024-05-25 11:39:32 -03:00
using PTexture2D = P_Texture2D;
2024-03-18 15:41:46 -03:00
}
#endif