Cogs.Core
TexturesD3D11.cpp
1#include "TexturesD3D11.h"
2
3#include "FormatsD3D11.h"
4#include "GraphicsDeviceD3D11.h"
5
6#include "Foundation/Logging/Logger.h"
7
8#include <OsoMemoryProfiler/CogsMemoryProfile.h>
9
10#include <algorithm>
11
12namespace
13{
14 Cogs::Logging::Log logger = Cogs::Logging::getLogger("TexturesD3D11");
15}
16
17Cogs::TexturesD3D11::TexturesD3D11(GraphicsDeviceD3D11 * device) :
18 textures(256, 128, device->getResourceAllocator()),
19 samplerStates(128, 128, device->getResourceAllocator()),
20 graphicsDevice(device)
21{
22}
23
25{
26#if defined(OSOMP_EnableProfiler) || defined(COGSRENDERING_GFX_ANNOTATE)
27 TextureD3D11& t = textures[handle];
28#else
29 (void)handle;
30 (void)name;
31#endif
32
33#if defined( OSOMP_EnableProfiler )
34 OsoMPAttribute attribute = { COGSMEM_NameAttribute, ATTRIBUTETYPE_String };
35
36 std::string nameStr(name);
37 attribute.mData.mText = nameStr.c_str();
38
39 if (t.texture2D) {
40 RegisterGPUResourceAttributes(textures[handle].texture2D.get<void>(), &attribute, 1);
41 }
42 else if (t.texture3D) {
43 RegisterGPUResourceAttributes(textures[handle].texture3D.get<void>(), &attribute, 1);
44 }
45#endif
46
47#ifdef COGSRENDERING_GFX_ANNOTATE
48 if (name.empty() || !handle) {
49 return;
50 }
51
52 if (t.texture2D) {
53 t.texture2D->SetPrivateData(WKPDID_D3DDebugObjectName, static_cast<UINT>(name.length()), name.data());
54 }
55 if (t.texture3D) {
56 t.texture3D->SetPrivateData(WKPDID_D3DDebugObjectName, static_cast<UINT>(name.length()), name.data());
57 }
58 if (t.unorderedAccessView) {
59 const std::string m = std::string(name) + "_UAV";
60 t.unorderedAccessView->SetPrivateData(WKPDID_D3DDebugObjectName, static_cast<UINT>(m.length()), m.c_str());
61 }
62 if (t.shaderResourceView) {
63 const std::string m = std::string(name) + "_SRV";
64 t.shaderResourceView->SetPrivateData(WKPDID_D3DDebugObjectName, static_cast<UINT>(m.length()), m.c_str());
65 }
66#endif
67}
68
70{
71 HRESULT hr;
72 TextureD3D11 texture = { desc, desc.width, desc.height, desc.depth, desc.format, nullptr, nullptr, nullptr };
73
74#if defined(OSOMP_EnableProfiler)
75 OsoMPAttribute profilerAttributes[7] = {
76 { COGSMEM_WidthAttribute, ATTRIBUTETYPE_Integer32, static_cast<int32_t>(desc.width) },
77 { COGSMEM_HeightAttribute, ATTRIBUTETYPE_Integer32, static_cast<int32_t>(desc.height) },
78 { COGSMEM_DepthAttribute, ATTRIBUTETYPE_Integer32, static_cast<int32_t>(desc.depth) },
79 { COGSMEM_LayersAttribute, ATTRIBUTETYPE_Integer32, static_cast<int32_t>(desc.layers) },
80 { COGSMEM_FacesAttribute, ATTRIBUTETYPE_Integer32, static_cast<int32_t>(desc.faces) },
81 { COGSMEM_LevelsAttribute, ATTRIBUTETYPE_Integer32, static_cast<int32_t>(desc.levels) },
82 { COGSMEM_FormatAttribute, ATTRIBUTETYPE_String },
83 };
84
85 profilerAttributes[6].mData.mText = getFormatInfo(desc.format)->name;
86#endif
87
88 const auto flags = desc.flags;
89 const auto format = desc.format;
90 const auto bytes = data ? data->offsets.data() : (const void **)nullptr;
91
92 DXGI_FORMAT formatD3D = Direct3D11::Formats[(int)format];
93 const bool generateMipmaps = (flags & TextureFlags::GenerateMipMaps) != 0;
94
96 if (desc.target == ResourceDimensions::Texture3D) {
97 texture.texture3D = (ID3D11Texture3D *)data->externalHandle;
98 }
99 else {
100 texture.texture2D = (ID3D11Texture2D *)data->externalHandle;
101 }
102 }
103 else {
104 UINT bindFlags = (flags & TextureFlags::DepthBuffer) ? 0 : D3D11_BIND_SHADER_RESOURCE;
105
106 const UINT mipLevels = generateMipmaps ? Cogs::getMipLevels(desc.width, desc.height) : static_cast<UINT>(desc.levels);
107
108 if (flags & TextureFlags::RenderTarget || generateMipmaps) {
109 bindFlags |= D3D11_BIND_RENDER_TARGET;
110 }
111
112 if (flags & TextureFlags::DepthBuffer) {
113 bindFlags |= D3D11_BIND_DEPTH_STENCIL;
114 }
115
116 if (flags & TextureFlags::Texture) {
117 bindFlags |= D3D11_BIND_SHADER_RESOURCE;
118 }
119
120 if (flags & TextureFlags::ReadWriteTexture) {
121 bindFlags |= D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_UNORDERED_ACCESS;
122 }
123
124 D3D11_USAGE usage = D3D11_USAGE_DEFAULT;
125 UINT CPUAccessFlag = 0;
126 if (flags & TextureFlags::UsageWriteStaging) {
127 bindFlags = 0;
128 usage = D3D11_USAGE_STAGING;
129 CPUAccessFlag = D3D11_CPU_ACCESS_WRITE;
130 }
131 else if (flags & TextureFlags::UsageReadStaging) {
132 bindFlags = 0;
133 usage = D3D11_USAGE_STAGING;
134 CPUAccessFlag = D3D11_CPU_ACCESS_READ;
135 }
136
137 if (desc.target == ResourceDimensions::Texture3D) {
138 D3D11_TEXTURE3D_DESC textureDesc = {};
139 textureDesc.Width = desc.width;
140 textureDesc.Height = desc.height;
141 textureDesc.Depth = desc.depth;
142 textureDesc.MipLevels = mipLevels;
143 textureDesc.Format = formatD3D;
144 textureDesc.Usage = usage;
145 textureDesc.BindFlags = bindFlags;
146 textureDesc.CPUAccessFlags = CPUAccessFlag;
147 textureDesc.MiscFlags |= (flags & TextureFlags::GenerateMipMaps) ? D3D11_RESOURCE_MISC_GENERATE_MIPS : 0;
148
149 ResourcePointer<ID3D11Texture3D> textureResource;
150 if (FAILED(hr = graphicsDevice->getDevice()->CreateTexture3D(&textureDesc, nullptr, textureResource.internalPointer()))) {
151 LOG_ERROR(logger, "Failed to create resource (%s): %s", getString(textureDesc), direct3D11ReturnCodeAsString(hr));
153 }
154 else if ((graphicsDevice->getSettings().flags & GraphicsDeviceFlags::EnableTraceLogging) == GraphicsDeviceFlags::EnableTraceLogging) {
155 LOG_TRACE(logger, "Created resource %p: %s", textureResource.get<void>(), getString(textureDesc));
156 }
157
158#if defined(OSOMP_EnableProfiler)
159 RegisterGPUResource(textureResource.get<void>(), desc.estimateMemorySize(), MemBlockType::GPUTexture, profilerAttributes, 7);
160#endif
161
162 texture.texture3D = textureResource;
163
164 if (bytes) {
166 graphicsDevice->getDevice()->GetImmediateContext(context.internalPointer());
167
168 D3D11_BOX rectangle;
169 rectangle.left = 0;
170 rectangle.right = desc.width;
171 rectangle.top = 0;
172 rectangle.bottom = desc.height;
173 rectangle.front = 0;
174 rectangle.back = desc.depth;
175 context->UpdateSubresource(textureResource,
176 static_cast<UINT>(0) * mipLevels,
177 &rectangle,
178 bytes[0],
179 static_cast<uint32_t>(data->getPitch(0)),
180 static_cast<uint32_t>(data->getPitch(0))*desc.height);
181 if(this->context->uploadStatisticsEnabled) this->context->uploadStatisticsTextureUpload(data->getSize());
182 }
183 }
184 else {
185 D3D11_TEXTURE2D_DESC textureDesc = {};
186 textureDesc.Width = desc.width;
187 textureDesc.Height = desc.height;
188 textureDesc.ArraySize = desc.layers * desc.faces;
189 textureDesc.MipLevels = mipLevels;
190 textureDesc.Format = formatD3D;
191 textureDesc.SampleDesc.Count = desc.samples;
192 textureDesc.SampleDesc.Quality = 0;
193 textureDesc.Usage = usage;
194 textureDesc.BindFlags = bindFlags;
195 textureDesc.CPUAccessFlags = CPUAccessFlag;
196 textureDesc.MiscFlags |= (flags & TextureFlags::GenerateMipMaps) ? D3D11_RESOURCE_MISC_GENERATE_MIPS : 0;
197 textureDesc.MiscFlags |= (flags & TextureFlags::CubeMap) ? D3D11_RESOURCE_MISC_TEXTURECUBE : 0;
198
199 ResourcePointer<ID3D11Texture2D> textureResource;
200
201 if (bytes) {
202 if (desc.levels == 1 && generateMipmaps) {
203 if (FAILED(hr = graphicsDevice->getDevice()->CreateTexture2D(&textureDesc, nullptr, textureResource.internalPointer()))) {
204 LOG_ERROR(logger, "Failed to create resource (%s): %s", getString(textureDesc), direct3D11ReturnCodeAsString(hr));
206 }
207 else if ((graphicsDevice->getSettings().flags & GraphicsDeviceFlags::EnableTraceLogging) == GraphicsDeviceFlags::EnableTraceLogging) {
208 LOG_TRACE(logger, "Created resource %p: %s", textureResource.get<void>(), getString(textureDesc));
209 }
210
211#if defined(OSOMP_EnableProfiler)
212 RegisterGPUResource(textureResource.get<void>(), desc.estimateMemorySize(), MemBlockType::GPUTexture, profilerAttributes, 7);
213#endif
214
216 graphicsDevice->getDevice()->GetImmediateContext(context.internalPointer());
217
218 for (size_t i = 0; i < desc.layers; ++i) {
219 for (size_t f = 0; f < desc.faces; f++) {
220
221 D3D11_BOX rectangle;
222 rectangle.left = 0;
223 rectangle.right = desc.width;
224 rectangle.top = 0;
225 rectangle.bottom = desc.height;
226 rectangle.front = 0;
227 rectangle.back = 1;
228
229 // Copy the image into the 0th mipmap level in the texture.
230 context->UpdateSubresource(textureResource,
231 static_cast<UINT>(f + i*desc.faces) * mipLevels,
232 &rectangle,
233 data->getData(i, f, 0),
234 static_cast<uint32_t>(data->getPitch(0)), 1);
235 }
236 }
237 if(this->context->uploadStatisticsEnabled) this->context->uploadStatisticsTextureUpload(data->getSize());
238 }
239 else {
240 textureDesc.MipLevels = desc.levels;
241
242 std::vector<D3D11_SUBRESOURCE_DATA> subresourceData(desc.layers * desc.faces * desc.levels);
243 auto pData = subresourceData.data();
244
245 for (size_t i = 0; i < desc.layers; ++i) {
246 for (size_t j = 0; j < desc.faces; ++j) {
247 for (size_t k = 0; k < desc.levels; ++k) {
248 (*pData).pSysMem = data->getData(i, j, k);
249 (*pData).SysMemPitch = static_cast<uint32_t>(data->getPitch(k));
250 (*pData).SysMemSlicePitch = 0;
251
252 ++pData;
253 }
254 }
255 }
256
257 if (FAILED(hr = graphicsDevice->getDevice()->CreateTexture2D(&textureDesc, subresourceData.data(), textureResource.internalPointer()))) {
258 LOG_ERROR(logger, "Failed to create resource (%s): %s", getString(textureDesc), direct3D11ReturnCodeAsString(hr));
260 }
261 else if ((graphicsDevice->getSettings().flags & GraphicsDeviceFlags::EnableTraceLogging) == GraphicsDeviceFlags::EnableTraceLogging) {
262 LOG_TRACE(logger, "Created resource %p: %s", textureResource.get<void>(), getString(textureDesc));
263 }
264#if defined(OSOMP_EnableProfiler)
265 RegisterGPUResource(textureResource.get<void>(), desc.estimateMemorySize(), MemBlockType::GPUTexture, profilerAttributes, 7);
266#endif
267 }
268 }
269 else {
270 if (FAILED(hr = graphicsDevice->getDevice()->CreateTexture2D(&textureDesc, nullptr, textureResource.internalPointer()))) {
271 LOG_ERROR(logger, "Failed to create resource (%s): %s", getString(textureDesc), direct3D11ReturnCodeAsString(hr));
273 }
274 else if ((graphicsDevice->getSettings().flags & GraphicsDeviceFlags::EnableTraceLogging) == GraphicsDeviceFlags::EnableTraceLogging) {
275 LOG_DEBUG(logger, "Created resource %p: %s", textureResource.get<void>(), getString(textureDesc));
276 }
277#if defined(OSOMP_EnableProfiler)
278 RegisterGPUResource(textureResource.get<void>(), desc.estimateMemorySize(), MemBlockType::GPUTexture, profilerAttributes, 7);
279#endif
280 }
281 texture.texture2D = textureResource;
282 }
283 }
284
285 if (((flags & (TextureFlags::UsageReadStaging | TextureFlags::UsageWriteStaging)) == 0) && (flags ^ TextureFlags::DepthBuffer) || (flags & TextureFlags::Texture)) {
286 texture.shaderResourceView = createShaderResourceView(texture.resource(), flags);
287
288 if (flags & TextureFlags::ReadWriteTexture) {
289 D3D11_UNORDERED_ACCESS_VIEW_DESC uavDesc;
290
291 uavDesc.Format = formatD3D;
292 uavDesc.ViewDimension = D3D11_UAV_DIMENSION_TEXTURE2D;
293 uavDesc.Texture2D.MipSlice = 0;
294
295 hr = graphicsDevice->getDevice()->CreateUnorderedAccessView(texture.resource(), &uavDesc, texture.unorderedAccessView.internalPointer());
296 if (FAILED(hr)) {
297 LOG_ERROR(logger, "Failed to create unordered access view: %s", direct3D11ReturnCodeAsString(hr));
299 }
300 }
301
303 graphicsDevice->getDevice()->GetImmediateContext(context.internalPointer());
304
305 if (generateMipmaps) {
306 context->GenerateMips(texture.shaderResourceView);
307 }
308 }
309
310 textureMemoryConsumption += desc.estimateMemorySize();
311 return textures.addResource(std::move(texture));
312}
313
315{
316 if (!HandleIsValid(textureHandle)) { return; }
317
318 TextureD3D11& texture = textures[textureHandle];
319
320 if ((graphicsDevice->getSettings().flags & GraphicsDeviceFlags::EnableTraceLogging) == GraphicsDeviceFlags::EnableTraceLogging) {
321 LOG_TRACE(logger, "Releasing resource %p", (void*)(&texture));
322 }
323
324 textureMemoryConsumption -= texture.desc.estimateMemorySize();
325 textures.removeResource(textureHandle);
326}
327
329{
330 if (!HandleIsValid(view.texture)) {
331 LOG_ERROR(logger, "Cannot create texture view: Invalid texture");
333 }
334 auto resource = createShaderResourceView(textures[view.texture].resource(), 0, view.levelIndex, view.numLevels);
335 if (!resource) {
336 LOG_ERROR(logger, "Failed to create texture view.");
338 }
339
340 return textureViews.addResource(TextureViewD3D11{ view.texture, std::move(resource) });
341}
342
344{
345 textureViews.removeResource(handle);
346}
347
348Cogs::ResourcePointer<ID3D11ShaderResourceView> Cogs::TexturesD3D11::createShaderResourceView(ID3D11Resource * resource, uint32_t flags, uint32_t mostDetailedMip, uint32_t mipLevels)
349{
350 D3D11_RESOURCE_DIMENSION dimension;
351 resource->GetType(&dimension);
352
353 D3D11_SHADER_RESOURCE_VIEW_DESC resourceViewDesc = {};
354
355 switch (dimension)
356 {
357 case D3D11_RESOURCE_DIMENSION_TEXTURE2D:
358 {
359 D3D11_TEXTURE2D_DESC textureDesc;
360
361 ((ID3D11Texture2D *)resource)->GetDesc(&textureDesc);
362
363 auto MostDetailedMip = std::min(mostDetailedMip, std::max(1u, textureDesc.MipLevels) - 1u);
364 auto MipLevels = std::min(mipLevels, std::max(mostDetailedMip, textureDesc.MipLevels) - mostDetailedMip);
365
366 resourceViewDesc.Format = textureDesc.Format;
367
368 if (textureDesc.Format == DXGI_FORMAT_R32_TYPELESS) {
369 resourceViewDesc.Format = DXGI_FORMAT_R32_FLOAT;
370 }
371 else if (textureDesc.Format == DXGI_FORMAT_R16_TYPELESS) {
372 resourceViewDesc.Format = DXGI_FORMAT_R16_UNORM;
373 }
374 else if (textureDesc.Format == DXGI_FORMAT_R8G8B8A8_TYPELESS) {
375 resourceViewDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
376 }
377
378 if (textureDesc.ArraySize == 1) {
379 if (textureDesc.SampleDesc.Count == 1) {
380 resourceViewDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
381 resourceViewDesc.Texture2D.MipLevels = MipLevels;
382 resourceViewDesc.Texture2D.MostDetailedMip = MostDetailedMip;
383 }
384 else {
385 resourceViewDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2DMS;
386 }
387 }
388 else {
389 if ((flags & TextureFlags::CubeMap) != 0) {
390 if (textureDesc.ArraySize == 6) {
391 resourceViewDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURECUBE;
392 resourceViewDesc.TextureCube.MipLevels = MipLevels;
393 resourceViewDesc.TextureCube.MostDetailedMip = MostDetailedMip;
394 }
395 else {
396 resourceViewDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURECUBEARRAY;
397 resourceViewDesc.TextureCubeArray.MipLevels = MipLevels;
398 resourceViewDesc.TextureCubeArray.MostDetailedMip = MostDetailedMip;
399 resourceViewDesc.TextureCubeArray.NumCubes = textureDesc.ArraySize / 6;
400 resourceViewDesc.TextureCubeArray.First2DArrayFace = 0;
401 }
402 }
403 else {
404 resourceViewDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2DARRAY;
405 resourceViewDesc.Texture2DArray.MipLevels = MipLevels;
406 resourceViewDesc.Texture2DArray.MostDetailedMip = MostDetailedMip;
407 resourceViewDesc.Texture2DArray.ArraySize = textureDesc.ArraySize;
408 resourceViewDesc.Texture2DArray.FirstArraySlice = 0;
409 }
410 }
411
412 break;
413 }
414 case D3D11_RESOURCE_DIMENSION_TEXTURE3D:
415 {
416 D3D11_TEXTURE3D_DESC textureDesc;
417 ((ID3D11Texture3D *)resource)->GetDesc(&textureDesc);
418
419 auto MostDetailedMip = std::min(mostDetailedMip, std::max(1u, textureDesc.MipLevels) - 1u);
420 auto MipLevels = std::min(mipLevels, std::max(mostDetailedMip, textureDesc.MipLevels) - mostDetailedMip);
421
422 resourceViewDesc.Format = textureDesc.Format;
423
424 if (textureDesc.Format == DXGI_FORMAT_R32_TYPELESS) {
425 resourceViewDesc.Format = DXGI_FORMAT_R32_FLOAT;
426 }
427 else if (textureDesc.Format == DXGI_FORMAT_R16_TYPELESS) {
428 resourceViewDesc.Format = DXGI_FORMAT_R16_UNORM;
429 }
430 else if (textureDesc.Format == DXGI_FORMAT_R8G8B8A8_TYPELESS) {
431 resourceViewDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
432 }
433 resourceViewDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE3D;
434 resourceViewDesc.Texture3D.MipLevels = MipLevels;
435 resourceViewDesc.Texture3D.MostDetailedMip = MostDetailedMip;
436 break;
437 }
438 default:
439 LOG_ERROR(logger, "Unsupported resource format for shader view.");
440 return nullptr;
441 }
442
443 ResourcePointer<ID3D11ShaderResourceView> texture;
444 HRESULT hr = graphicsDevice->getDevice()->CreateShaderResourceView(resource, &resourceViewDesc, texture.internalPointer());
445
446 if (FAILED(hr)) {
447 LOG_ERROR(logger, "Failed to create shader resource view: %s", direct3D11ReturnCodeAsString(hr));
448 return nullptr;
449 }
450
451 return texture;
452}
453
455{
456 D3D11_SAMPLER_DESC samplerDesc = {};
457
458 samplerDesc.AddressU = Direct3D11::AddressModes[state.addressModeS];
459 samplerDesc.AddressV = Direct3D11::AddressModes[state.addressModeT];
460 samplerDesc.AddressW = Direct3D11::AddressModes[state.addressModeW];
461
462 if (state.maxAnisotropy > 1) {
463 samplerDesc.Filter = D3D11_FILTER_ANISOTROPIC;
464 samplerDesc.MaxAnisotropy = state.maxAnisotropy;
465 }
466 else{
467 samplerDesc.Filter = Direct3D11::FilterModes[state.filter];
468 }
469
470 samplerDesc.ComparisonFunc = Direct3D11::ComparisonFunctions[state.comparisonFunction];
471
472 samplerDesc.MinLOD = std::numeric_limits<float>::lowest();
473 samplerDesc.MaxLOD = std::numeric_limits<float>::max();
474
475 for (int i = 0; i < 4; ++i) {
476 samplerDesc.BorderColor[i] = state.borderColor[i];
477 }
478
480 HRESULT hr = graphicsDevice->getDevice()->CreateSamplerState(&samplerDesc, samplerState.internalPointer());
481
482 if (FAILED(hr)) {
483 LOG_ERROR(logger, "Failed to load sampler state: %s", direct3D11ReturnCodeAsString(hr));
485 }
486
487 return samplerStates.addResource(std::move(samplerState));
488}
489
491{
492 samplerStates.removeResource(handle);
493}
494
496{
497 return (void*)(this->textures[textureHandle].resource());
498 //return texPtr.get<void>();
499}
500
502{
504 graphicsDevice->getDevice()->GetImmediateContext(context.internalPointer());
505
506 context->GenerateMips(textures[textureHandle].shaderResourceView);
507}
508
510{
511 samplerStates.clear();
512
513 textures.clear();
514}
Log implementation class.
Definition: LogManager.h:139
Provides a weakly referenced view over the contents of a string.
Definition: StringView.h:24
constexpr const char * data() const noexcept
Get the sequence of characters referenced by the string view.
Definition: StringView.h:171
constexpr size_t length() const noexcept
Get the length of the string.
Definition: StringView.h:185
constexpr bool empty() const noexcept
Check if the string is empty.
Definition: StringView.h:122
const DXGI_FORMAT Formats[]
Must match up to Format definition.
Definition: FormatsD3D11.cpp:6
constexpr Log getLogger(const char(&name)[LEN]) noexcept
Definition: LogManager.h:180
@ EnableTraceLogging
Enables trace logging.
const char * name
Name as a color format (using RGBA as channels).
Definition: DataFormat.h:260
static const Handle_t InvalidHandle
Represents an invalid handle.
Definition: Common.h:80
Encapsulates state for texture sampling in a state object.
Definition: SamplerState.h:12
ComparisonFunction comparisonFunction
Specifies the comparison function to use when applying a comparison sampler.
Definition: SamplerState.h:73
unsigned int maxAnisotropy
Specifies the maximum number of anisotropic samples to use when sampling a texture.
Definition: SamplerState.h:76
AddressMode addressModeW
Specifies the addressing mode along the W axis in texture coordinate space.
Definition: SamplerState.h:67
AddressMode addressModeS
Specifies the addressing mode along the S axis in texture coordinate space.
Definition: SamplerState.h:63
float borderColor[4]
Definition: SamplerState.h:80
FilterMode filter
Specifies the filter to use for texture sampling.
Definition: SamplerState.h:70
AddressMode addressModeT
Specifies the addressing mode along the T axis in texture coordinate space.
Definition: SamplerState.h:65
COGSRENDERING_DLL_API size_t estimateMemorySize() const
Attempts to estimate the amount of memory a texture with these attributes will require.
Definition: TextureData.cpp:57
@ DepthBuffer
The texture can be used as a depth target and have depth buffer values written into.
Definition: Flags.h:122
@ RenderTarget
The texture can be used as a render target and drawn into.
Definition: Flags.h:120
@ GenerateMipMaps
The texture supports automatic mipmap generation performed by the graphics device.
Definition: Flags.h:124
@ Texture
Texture usage, see Default.
Definition: Flags.h:118
@ ReadWriteTexture
The texture can be used as a read/write texture. Can be used to output data from compute shaders.
Definition: Flags.h:128
@ UsageReadStaging
The texture is intended to be used as a staging texture.
Definition: Flags.h:133
@ CubeMap
The texture can be used as a cube map.
Definition: Flags.h:126
Describes how to fetch data from a texture in shaders.
Definition: ITextures.h:13
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
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.