3#include "ResourceBase.h"
5#include "Rendering/TextureData.h"
7#include "Foundation/UniqueValue.h"
15 template<
typename Element>
16 inline TextureFormat getFormat() {
return TextureFormat::Unknown; }
19 inline TextureFormat getFormat<glm::u8vec4>() {
return TextureFormat::R8G8B8A8_UNORM; }
22 inline TextureFormat getFormat<glm::vec3>() {
return TextureFormat::R32G32B32_FLOAT; }
25 inline TextureFormat getFormat<glm::vec4>() {
return TextureFormat::R32G32B32A32_FLOAT; }
32 template<
typename Element>
63 explicit operator Element *() {
return data; }
131 return MappedTexture<uint8_t>(
this,
static_cast<uint8_t *
>(mapInternal(width, height, format, generateMipMap)));
144 template<
typename Element>
147 auto format = getFormat<Element>();
149 assert(Cogs::getBlockSize(format) ==
sizeof(Element) &&
"Compatible format not found for element type.");
151 return MappedTexture<Element>(
this,
static_cast<Element *
>(mapInternal(width, height, format, generateMipMap)));
166 template<
typename Element>
169 assert(Cogs::getBlockSize(format) ==
sizeof(Element) &&
"Format not size compatible with element type.");
171 return MappedTexture<Element>(
this,
static_cast<Element *
>(mapInternal(width, height, format, generateMipMap)));
185 void setData(ResourceDimensions target,
const void * data,
size_t size,
int width,
int height, TextureFormat format,
bool generateMipMap);
187 void setData(ResourceDimensions target,
const void * data,
size_t size,
int width,
int height,
int levels, TextureFormat format,
bool generateMipMap);
189 void COGSCORE_DLL_API
setData(ResourceDimensions target,
const void * data,
size_t size, uint32_t width, uint32_t height, uint32_t depth, uint32_t layers, uint32_t faces, uint32_t levels, TextureFormat format,
bool generateMipMap);
193 bool empty() {
return storage.data.size() == 0; }
195 void * mapInternal(uint16_t width, uint16_t height, TextureFormat format,
bool mipMap);
199 intptr_t externalHandle = 0;
201 bool hasAlpha =
false;
204 template<
typename Element>
Wrapper for mapped texture data, ensuring RAII behavior of stream map/unmap operations.
~MappedTexture()
Destructs the texture wrapper.
MappedTexture(MappedTexture &other)=delete
Deleted copy constructor.
Element * elements
Pointer to the mapped data.
MappedTexture(Texture *texture, Element *data)
Constructs a texture data wrapper.
Element & operator[](const size_t index)
Access the element at offset index.
MappedTexture(MappedTexture &&other)=default
Move construct the wrapper from other.
Element * data()
Get the pointer to the mapped data.
Texture * texture
Pointer to the texture the data was mapped from.
Contains all Cogs related functionality.
Base class for engine resources.
Texture resources contain raster bitmap data to use for texturing.
MappedTexture< Element > map(uint16_t width, uint16_t height, TextureFormat format, bool generateMipMap)
Map the texture data, ensuring the data is sized to hold width * height * sizeof(Element) bytes.
Texture()=default
Construct a texture resource.
MappedTexture< Element > map(uint16_t width, uint16_t height, bool generateMipMap)
Map the texture data, ensuring the data is sized to hold width * height * sizeof(Element) bytes.
Texture(Texture &&other)=default
Move construct a texture from the given texture other.
MappedTexture< uint8_t > map(uint16_t width, uint16_t height, TextureFormat format, bool generateMipMap)
Map the texture data, ensuring the data is sized to hold width * height * bpp of the format bytes.
void unmap()
Unmap the currently mapped texture data.
Texture & operator=(Texture &&other)=default
Move assign a texture from the given texture other.
void setData(ResourceDimensions target, const void *data, size_t size, int width, int height, TextureFormat format, bool generateMipMap)
Set the texture data.
~Texture()
Destroy a texture.
Texture(const Texture &other)=delete
Copying disabled since copying a texture resource might be a resource-intensive operation.
A value that is cleared when it is moved from.