Cogs.Core
ITextures.h
1#pragma once
2
3#include "Common.h"
4#include "TextureData.h"
5#include "SamplerState.h"
6
7namespace Cogs
8{
13 {
17 uint32_t layerIndex;
19 uint32_t numLayers;
21 uint32_t levelIndex;
23 uint32_t numLevels;
24
25 size_t hash(size_t hashValue = Cogs::hash()) const {
26 hashValue = Cogs::hash(texture.handle, hashValue);
27 hashValue = Cogs::hash(layerIndex, hashValue);
28 hashValue = Cogs::hash(numLayers, hashValue);
29 hashValue = Cogs::hash(levelIndex, hashValue);
30 hashValue = Cogs::hash(numLevels, hashValue);
31
32 return hashValue;
33 }
34 };
35
39 struct ITextures
40 {
44 virtual void annotate(TextureHandle handle, const StringView& name) { (void)handle; (void)name; }
45
56 virtual TextureHandle loadTexture(const unsigned char * bytes, unsigned int width, unsigned int height, TextureFormat format, unsigned int flags = 0) = 0;
57
69 virtual TextureHandle loadTexture(const unsigned char * bytes, unsigned int width, unsigned int height, TextureFormat format, unsigned int numSamples, unsigned int flags) = 0;
70
82 virtual TextureHandle loadTextureMipMaps(const unsigned char ** bytes, size_t numLevels, const unsigned int * widths, const unsigned int * heights, TextureFormat format, unsigned int flags = 0) = 0;
83
97 virtual TextureHandle loadTextureArray(const unsigned char ** bytes, const size_t arraySize, const size_t numLevels, const unsigned int * widths, const unsigned int * heights, TextureFormat format, unsigned int flags = 0) = 0;
98
112 virtual TextureHandle loadCubeMap(const unsigned char ** bytes, const size_t arraySize, const size_t numLevels, const unsigned int * widths, const unsigned int * heights, TextureFormat format, unsigned int flags = 0) = 0;
113
120 virtual TextureHandle loadTexture(const TextureDescription & desc, const TextureData * data) = 0;
121
128 virtual void uploadTextureData(TextureHandle textureHandle,
129 const TextureData &data,
130 uint32_t layer_offset = 0,
131 uint32_t face_offset = 0,
132 uint32_t level_offset = 0) { (void)textureHandle; (void)data; (void)layer_offset; (void)face_offset; (void)level_offset; }
133
139 virtual void releaseTexture(TextureHandle textureHandle) = 0;
140
146 virtual void releaseNativeTexture(TextureNativeHandle nativeHandle) { (void)nativeHandle; assert(false); }
147
156
162 virtual void releaseTextureView(const TextureViewHandle & handle) = 0;
163
171
177 virtual void releaseSamplerState(SamplerStateHandle handle) = 0;
178
185 virtual void generateMipmaps(TextureHandle textureHandle) = 0;
186
193 virtual void * getNativeHandle(TextureHandle textureHandle) = 0;
194
198 virtual void releaseResources() = 0;
199 };
200}
Provides a weakly referenced view over the contents of a string.
Definition: StringView.h:24
Contains all Cogs related functionality.
Definition: FieldSetter.h:23
constexpr size_t hash() noexcept
Simple getter function that returns the initial value for fnv1a hashing.
Definition: HashFunctions.h:62
handle_type handle
Internal resource handle.
Definition: Common.h:74
Provides texture management functionality.
Definition: ITextures.h:40
virtual SamplerStateHandle loadSamplerState(const SamplerState &state)=0
Load a sampler state object.
virtual void uploadTextureData(TextureHandle textureHandle, const TextureData &data, uint32_t layer_offset=0, uint32_t face_offset=0, uint32_t level_offset=0)
Upload a texture from the given description.
Definition: ITextures.h:128
virtual void releaseResources()=0
Release all allocated texture resources.
virtual void releaseNativeTexture(TextureNativeHandle nativeHandle)
Release a native texture handle.
Definition: ITextures.h:146
virtual TextureViewHandle createTextureView(TextureViewDescription &viewDescription)=0
Create a texture view used to bind a limited view of the texture data to the rendering pipeline.
virtual void * getNativeHandle(TextureHandle textureHandle)=0
Get the device-specific handle (D3D texture pointer, OpenGL texture ID etc) associated with the given...
virtual void generateMipmaps(TextureHandle textureHandle)=0
Use the graphics device to generate mipmaps for the texture with the given texture handle.
virtual void annotate(TextureHandle handle, const StringView &name)
Associate a name with an object for use in graphics debugging.
Definition: ITextures.h:44
virtual TextureHandle loadTexture(const unsigned char *bytes, unsigned int width, unsigned int height, TextureFormat format, unsigned int numSamples, unsigned int flags)=0
Load a texture using the given data to populate the texture contents.
virtual void releaseTexture(TextureHandle textureHandle)=0
Release the texture with the given textureHandle.
virtual TextureHandle loadTextureMipMaps(const unsigned char **bytes, size_t numLevels, const unsigned int *widths, const unsigned int *heights, TextureFormat format, unsigned int flags=0)=0
Load a texture with multiple mipmap levels using the given data to populate the texture contents.
virtual void releaseSamplerState(SamplerStateHandle handle)=0
Release the sampler state with the given handle.
virtual TextureHandle loadTexture(const TextureDescription &desc, const TextureData *data)=0
Load a texture from the given description.
virtual TextureHandle loadTexture(const unsigned char *bytes, unsigned int width, unsigned int height, TextureFormat format, unsigned int flags=0)=0
Load a texture using the given data to populate the texture contents.
virtual TextureHandle loadTextureArray(const unsigned char **bytes, const size_t arraySize, const size_t numLevels, const unsigned int *widths, const unsigned int *heights, TextureFormat format, unsigned int flags=0)=0
Load an array texture with mipmaps using the given data to populate the texture contents.
virtual void releaseTextureView(const TextureViewHandle &handle)=0
Release the given texture view.
virtual TextureHandle loadCubeMap(const unsigned char **bytes, const size_t arraySize, const size_t numLevels, const unsigned int *widths, const unsigned int *heights, TextureFormat format, unsigned int flags=0)=0
Load a cube map texture with mipmaps using the given data to populate the texture contents.
Encapsulates state for texture sampling in a state object.
Definition: SamplerState.h:12
Describes how to fetch data from a texture in shaders.
Definition: ITextures.h:13
uint32_t layerIndex
Index of the first layer (if array) to fetch from.
Definition: ITextures.h:17
uint32_t numLayers
Number of array layers available.
Definition: ITextures.h:19
uint32_t numLevels
Number of mipmap levels available.
Definition: ITextures.h:23
uint32_t levelIndex
First mipmap level to fetch data from.
Definition: ITextures.h:21
TextureHandle texture
Texture.
Definition: ITextures.h:15