2024-03-18 15:41:46 -03:00
|
|
|
#ifndef XNA_GRAPHICS_TEXTURE_HPP
|
|
|
|
#define XNA_GRAPHICS_TEXTURE_HPP
|
|
|
|
|
2024-12-13 17:28:46 -03:00
|
|
|
#include "csharp/io/stream.hpp"
|
2024-05-23 14:38:16 -03:00
|
|
|
#include "gresource.hpp"
|
2024-11-15 12:33:06 -03:00
|
|
|
#include "shared.hpp"
|
2024-11-16 12:15:40 -03:00
|
|
|
#include <cstdint>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2024-03-18 15:41:46 -03:00
|
|
|
|
|
|
|
namespace xna {
|
2024-08-02 22:10:40 -03:00
|
|
|
//Represents a texture resource.
|
|
|
|
class Texture : public GraphicsResource {
|
2024-05-23 14:38:16 -03:00
|
|
|
public:
|
2024-11-16 12:15:40 -03:00
|
|
|
Texture(std::shared_ptr<GraphicsDevice> const& graphicsDevice) : GraphicsResource(graphicsDevice) {}
|
2024-08-02 22:10:40 -03:00
|
|
|
|
|
|
|
//Gets the format of the texture data.
|
2024-08-03 12:32:30 -03:00
|
|
|
virtual SurfaceFormat Format() const = 0;
|
2024-08-02 22:10:40 -03:00
|
|
|
//Gets the number of texture levels in a multilevel texture.
|
2024-11-16 12:15:40 -03:00
|
|
|
virtual int32_t LevelCount() const = 0;
|
2024-03-18 15:41:46 -03:00
|
|
|
};
|
|
|
|
|
2024-11-16 12:15:40 -03:00
|
|
|
struct Texture2DImplementation;
|
|
|
|
|
2024-08-03 12:32:30 -03:00
|
|
|
//Represents a 2D grid of texels.
|
2024-11-16 14:21:06 -03:00
|
|
|
class Texture2D : public Texture {
|
2024-05-23 14:38:16 -03:00
|
|
|
public:
|
|
|
|
Texture2D();
|
2024-11-16 12:15:40 -03:00
|
|
|
Texture2D(std::shared_ptr<GraphicsDevice> const& device);
|
|
|
|
Texture2D(std::shared_ptr<GraphicsDevice> const& device, size_t width, size_t height);
|
|
|
|
Texture2D(std::shared_ptr<GraphicsDevice> const& device, size_t width, size_t height, size_t mipMap, SurfaceFormat format);
|
2024-08-03 12:32:30 -03:00
|
|
|
|
|
|
|
//Gets the width of this texture resource, in pixels.
|
2024-11-16 12:15:40 -03:00
|
|
|
constexpr int32_t Width() const { return width; }
|
2024-08-03 12:32:30 -03:00
|
|
|
//Gets the height of this texture resource, in pixels.
|
2024-11-16 12:15:40 -03:00
|
|
|
constexpr int32_t Height() const { return height; }
|
2024-08-03 12:32:30 -03:00
|
|
|
//Gets the size of this resource.
|
2024-08-03 22:45:19 -03:00
|
|
|
constexpr Rectangle Bounds() const { return { 0, 0, width, height }; }
|
2024-08-03 12:32:30 -03:00
|
|
|
//Gets the format of the texture data.
|
|
|
|
constexpr SurfaceFormat Format() const override { return surfaceFormat; }
|
|
|
|
//Gets the number of texture levels in a multilevel texture.
|
2024-11-16 12:15:40 -03:00
|
|
|
constexpr int32_t LevelCount() const { return levelCount; }
|
2024-08-03 12:32:30 -03:00
|
|
|
|
|
|
|
//Sets data to the texture.
|
2024-06-22 11:02:01 -03:00
|
|
|
void SetData(std::vector<Color> const& data, size_t startIndex = 0, size_t elementCount = 0);
|
2024-08-03 12:32:30 -03:00
|
|
|
//Sets data to the texture.
|
2024-11-16 12:15:40 -03:00
|
|
|
void SetData(std::vector<uint32_t> const& data, size_t startIndex = 0, size_t elementCount = 0);
|
2024-08-03 12:32:30 -03:00
|
|
|
//Sets data to the texture.
|
2024-11-16 12:15:40 -03:00
|
|
|
void SetData(std::vector<uint8_t> const& data, size_t startIndex = 0, size_t elementCount = 0);
|
2024-08-03 12:32:30 -03:00
|
|
|
//Sets data to the texture.
|
2024-11-16 12:15:40 -03:00
|
|
|
void SetData(int32_t level, Rectangle* rect, std::vector<uint8_t> const& data, size_t startIndex, size_t elementCount);
|
2024-08-03 12:32:30 -03:00
|
|
|
|
|
|
|
//Loads texture data from a stream.
|
2024-12-13 17:28:46 -03:00
|
|
|
static std::shared_ptr<Texture2D> FromStream(GraphicsDevice& device, csharp::Stream& stream);
|
2024-08-03 12:32:30 -03:00
|
|
|
//Loads texture data from a file.
|
2024-12-02 14:42:09 -03:00
|
|
|
static std::shared_ptr<Texture2D> FromStream(GraphicsDevice& device, std::string const& fileName);
|
2024-08-03 12:32:30 -03:00
|
|
|
//Loads texture data from a data.
|
2024-12-02 14:42:09 -03:00
|
|
|
static std::shared_ptr<Texture2D> FromStream(GraphicsDevice& device, std::vector<uint8_t> const& data);
|
2024-08-02 22:10:40 -03:00
|
|
|
|
2024-08-03 12:32:30 -03:00
|
|
|
void Initialize();
|
|
|
|
|
2024-11-16 14:21:06 -03:00
|
|
|
std::unique_ptr<Texture2DImplementation> Implementation;
|
|
|
|
|
2024-08-03 22:45:19 -03:00
|
|
|
protected:
|
2024-08-03 12:32:30 -03:00
|
|
|
SurfaceFormat surfaceFormat{ SurfaceFormat::Color };
|
2024-11-16 12:15:40 -03:00
|
|
|
int32_t levelCount{ 0 };
|
2024-08-03 22:45:19 -03:00
|
|
|
int width{ 0 };
|
2024-11-16 12:15:40 -03:00
|
|
|
int height{ 0 };
|
2024-03-18 15:41:46 -03:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|