3#include "Services/Variables.h"
6#include "Foundation/BitTwiddling/PowerOfTwo.h"
7#include "Foundation/Logging/Logger.h"
23 assert(!allocationSize &&
"Texture memory leaked.");
27 void *
allocate(
size_t size,
size_t alignment = 0, MemBlockType type = MemBlockType::Block)
override
29 allocationSize += size;
34 void deallocate(
void * ptr,
size_t size, MemBlockType type = MemBlockType::Block)
override
36 allocationSize -= size;
42 Atomic<size_t> allocationSize{ 0 };
49 if (ownsExternalTexture.value) {
50 assert(externalHandle == 0);
54void Cogs::Core::Texture::setData(ResourceDimensions target,
const void * data,
size_t size,
int width,
int height, TextureFormat format,
bool generateMipMap)
56 setData(target, data, size, width, height, 1, format, generateMipMap);
59void Cogs::Core::Texture::setData(ResourceDimensions target,
const void * data,
size_t size,
int width,
int height,
int levels, TextureFormat format,
bool generateMipMap)
61 setData(target, data, size, width, height, 1, 1, 1, levels, format, generateMipMap);
76 debug_assert(layers >= 1 &&
"Invalid number of layers.");
77 debug_assert(faces == 1 || faces == 6 &&
"Invalid number of faces.");
78 debug_assert(levels >= 1 &&
"Invalid number of levels.");
80 description.target = target;
81 description.width = width;
82 description.height = height;
83 description.depth = depth;
84 description.layers = layers;
85 description.faces = faces;
86 description.levels = levels;
87 description.format = format;
97 storage.init({ width, height, depth }, layers, faces, levels, format, &textureAllocator);
99 auto textureData = storage.getData();
101 std::memcpy(textureData, data, size);
104 if (!isSet(ResourceFlags::Loading)) {
109void * Cogs::Core::Texture::mapInternal(uint16_t width, uint16_t height, TextureFormat format,
bool generateMipMap)
111 description.width = width;
112 description.height = height;
113 description.format = format;
115 if (generateMipMap) {
119 storage.init({ width, height, 1 }, 1, 1, 1, format, &textureAllocator);
121 std::memset(storage.getData(), 0, storage.getSize());
123 return storage.getData();
126void Cogs::Core::Texture::clearData(){
127 if (!keepStorage()) {
void * allocate(size_t size, size_t alignment=0, MemBlockType type=MemBlockType::Block) override
Allocate raw memory.
void deallocate(void *ptr, size_t size, MemBlockType type=MemBlockType::Block) override
Deallocate the memory block at the given pointer, with the given size.
Log implementation class.
Base allocator implementation.
virtual void deallocate(void *ptr, size_t size, MemBlockType type=MemBlockType::Block)
Deallocate the memory block at the given pointer, with the given size.
virtual void * allocate(size_t size, size_t alignment=0, MemBlockType type=MemBlockType::Block)
Allocate raw memory.
constexpr Log getLogger(const char(&name)[LEN]) noexcept
Contains all Cogs related functionality.
void setChanged(Cogs::Core::Context *context, Cogs::ComponentModel::Component *component, Reflection::FieldId fieldId)
Must be Called after changing a Component field. Mark field changed. Request engine update.
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.
@ GenerateMipMaps
The texture supports automatic mipmap generation performed by the graphics device.
@ Texture
Texture usage, see Default.
@ CubeMap
The texture can be used as a cube map.
@ Default
Default usage, the texture can be loaded once and bound and sampled in shaders.