Cogs.Core
TexturesD3D11.h
1#pragma once
2#include <unordered_map>
3#include "../Base/TexturesCommon.h"
4
5#include "CommonD3D11.h"
6
7namespace Cogs
8{
10 {
12
13 uint32_t width = 0;
14 uint32_t height = 0;
15 uint32_t depth = 0;
16
17 TextureFormat format = TextureFormat::Unknown;
18
19 inline ID3D11Resource* resource() { return texture2D ? (ID3D11Resource*)texture2D : (ID3D11Resource*)texture3D; }
20
25 };
26
28 {
29 TextureHandle texture;
30
32 };
33
35
37 {
38 TexturesD3D11(struct GraphicsDeviceD3D11 * device);
39
40 void initialize(struct ContextD3D11 * context_set)
41 {
42 this->context = context_set;
43 }
44
45 void annotate(TextureHandle handle, const StringView& name) override;
46
47 using TexturesCommon::loadTexture;
48 TextureHandle loadTexture(const TextureDescription & desc, const TextureData * data) override;
49 void releaseTexture(TextureHandle textureHandle) override;
50
52 void releaseTextureView(const TextureViewHandle & handle) override;
53
54 SamplerStateHandle loadSamplerState(const SamplerState & state) override;
55 void releaseSamplerState(SamplerStateHandle handle) override;
56
57 void generateMipmaps(TextureHandle texureHandle) override;
58
59 void * getNativeHandle(TextureHandle textureHandle) override;
60
61 void releaseResources() override;
62
63 ID3D11Resource * getTexture(TextureHandle textureHandle) {
64 return this->textures[textureHandle].resource();
65 }
66
67 ID3D11Texture2D * getTexture2D(TextureHandle textureHandle) {
68 return this->textures[textureHandle].texture2D;
69 }
70
71 size_t textureMemoryConsumption = 0;
75
76 private:
77 struct GraphicsDeviceD3D11 * graphicsDevice = nullptr;
78 ContextD3D11 * context = nullptr;
80
81 ResourcePointer<ID3D11ShaderResourceView> createShaderResourceView(ID3D11Resource * resource, uint32_t flags = 0, uint32_t mostDetailedMip = 0, uint32_t mipLevels=~0);
82 };
83}
Provides a weakly referenced view over the contents of a string.
Definition: StringView.h:24
Contains all Cogs related functionality.
Definition: FieldSetter.h:23
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
void releaseResources() override
Release all allocated texture resources.
SamplerStateHandle loadSamplerState(const SamplerState &state) override
Load a sampler state object.
void releaseTextureView(const TextureViewHandle &handle) override
Release the given texture view.
TextureHandle loadTexture(const TextureDescription &desc, const TextureData *data) override
Load a texture from the given description.
void generateMipmaps(TextureHandle texureHandle) override
Use the graphics device to generate mipmaps for the texture with the given texture handle.
void * getNativeHandle(TextureHandle textureHandle) override
Get the device-specific handle (D3D texture pointer, OpenGL texture ID etc) associated with the given...
void releaseSamplerState(SamplerStateHandle handle) override
Release the sampler state with the given handle.
void releaseTexture(TextureHandle textureHandle) override
Release the texture with the given textureHandle.
TextureViewHandle createTextureView(TextureViewDescription &view) override
Create a texture view used to bind a limited view of the texture data to the rendering pipeline.
void annotate(TextureHandle handle, const StringView &name) override
Associate a name with an object for use in graphics debugging.