Adds usage flags to backend textures.

This was SVN commit r27152.
This commit is contained in:
vladislavbelov
2022-10-12 23:19:27 +00:00
parent d3f0395d2a
commit 64bd81ae6b
24 changed files with 123 additions and 40 deletions
+8 -2
View File
@@ -260,6 +260,8 @@ void CLOSTexture::ConstructTexture(Renderer::Backend::IDeviceCommandContext* dev
} }
m_Texture = backendDevice->CreateTexture2D("LOSTexture", m_Texture = backendDevice->CreateTexture2D("LOSTexture",
Renderer::Backend::ITexture::Usage::TRANSFER_DST |
Renderer::Backend::ITexture::Usage::SAMPLED,
m_TextureFormat, textureSize, textureSize, defaultSamplerDesc); m_TextureFormat, textureSize, textureSize, defaultSamplerDesc);
// Initialise texture with SoD color, for the areas we don't // Initialise texture with SoD color, for the areas we don't
@@ -270,10 +272,14 @@ void CLOSTexture::ConstructTexture(Renderer::Backend::IDeviceCommandContext* dev
if (CRenderer::IsInitialised() && g_RenderingOptions.GetSmoothLOS()) if (CRenderer::IsInitialised() && g_RenderingOptions.GetSmoothLOS())
{ {
const uint32_t usage =
Renderer::Backend::ITexture::Usage::TRANSFER_DST |
Renderer::Backend::ITexture::Usage::SAMPLED |
Renderer::Backend::ITexture::Usage::COLOR_ATTACHMENT;
m_SmoothTextures[0] = backendDevice->CreateTexture2D("LOSSmoothTexture0", m_SmoothTextures[0] = backendDevice->CreateTexture2D("LOSSmoothTexture0",
m_TextureFormat, textureSize, textureSize, defaultSamplerDesc); usage, m_TextureFormat, textureSize, textureSize, defaultSamplerDesc);
m_SmoothTextures[1] = backendDevice->CreateTexture2D("LOSSmoothTexture1", m_SmoothTextures[1] = backendDevice->CreateTexture2D("LOSSmoothTexture1",
m_TextureFormat, textureSize, textureSize, defaultSamplerDesc); usage, m_TextureFormat, textureSize, textureSize, defaultSamplerDesc);
m_SmoothFramebuffers[0] = backendDevice->CreateFramebuffer( m_SmoothFramebuffers[0] = backendDevice->CreateFramebuffer(
"LOSSmoothFramebuffer0", m_SmoothTextures[0].get(), nullptr); "LOSSmoothFramebuffer0", m_SmoothTextures[0].get(), nullptr);
+4
View File
@@ -332,6 +332,8 @@ void CMiniMapTexture::CreateTextures(
// Create terrain texture // Create terrain texture
m_TerrainTexture = backendDevice->CreateTexture2D("MiniMapTerrainTexture", m_TerrainTexture = backendDevice->CreateTexture2D("MiniMapTerrainTexture",
Renderer::Backend::ITexture::Usage::TRANSFER_DST |
Renderer::Backend::ITexture::Usage::SAMPLED,
Renderer::Backend::Format::R8G8B8A8_UNORM, textureSize, textureSize, defaultSamplerDesc); Renderer::Backend::Format::R8G8B8A8_UNORM, textureSize, textureSize, defaultSamplerDesc);
// Initialise texture with solid black, for the areas we don't // Initialise texture with solid black, for the areas we don't
@@ -348,6 +350,8 @@ void CMiniMapTexture::CreateTextures(
m_FinalTexture = g_Renderer.GetTextureManager().WrapBackendTexture( m_FinalTexture = g_Renderer.GetTextureManager().WrapBackendTexture(
backendDevice->CreateTexture2D("MiniMapFinalTexture", backendDevice->CreateTexture2D("MiniMapFinalTexture",
Renderer::Backend::ITexture::Usage::SAMPLED |
Renderer::Backend::ITexture::Usage::COLOR_ATTACHMENT,
Renderer::Backend::Format::R8G8B8A8_UNORM, Renderer::Backend::Format::R8G8B8A8_UNORM,
FINAL_TEXTURE_SIZE, FINAL_TEXTURE_SIZE, defaultSamplerDesc)); FINAL_TEXTURE_SIZE, FINAL_TEXTURE_SIZE, defaultSamplerDesc));
@@ -293,6 +293,8 @@ CTerrainTextureManager::LoadAlphaMap(const VfsPath& alphaMapType)
#endif #endif
result.m_CompositeAlphaMap = g_VideoMode.GetBackendDevice()->CreateTexture2D("CompositeAlphaMap", result.m_CompositeAlphaMap = g_VideoMode.GetBackendDevice()->CreateTexture2D("CompositeAlphaMap",
Renderer::Backend::ITexture::Usage::TRANSFER_DST |
Renderer::Backend::ITexture::Usage::SAMPLED,
Renderer::Backend::Format::A8_UNORM, totalWidth, totalHeight, Renderer::Backend::Format::A8_UNORM, totalWidth, totalHeight,
Renderer::Backend::Sampler::MakeDefaultSampler( Renderer::Backend::Sampler::MakeDefaultSampler(
Renderer::Backend::Sampler::Filter::LINEAR, Renderer::Backend::Sampler::Filter::LINEAR,
+2
View File
@@ -87,6 +87,8 @@ void CTerritoryTexture::ConstructTexture(Renderer::Backend::IDeviceCommandContex
const uint32_t textureSize = round_up_to_pow2(static_cast<uint32_t>(m_MapSize)); const uint32_t textureSize = round_up_to_pow2(static_cast<uint32_t>(m_MapSize));
m_Texture = deviceCommandContext->GetDevice()->CreateTexture2D("TerritoryTexture", m_Texture = deviceCommandContext->GetDevice()->CreateTexture2D("TerritoryTexture",
Renderer::Backend::ITexture::Usage::TRANSFER_DST |
Renderer::Backend::ITexture::Usage::SAMPLED,
Renderer::Backend::Format::R8G8B8A8_UNORM, textureSize, textureSize, Renderer::Backend::Format::R8G8B8A8_UNORM, textureSize, textureSize,
Renderer::Backend::Sampler::MakeDefaultSampler( Renderer::Backend::Sampler::MakeDefaultSampler(
Renderer::Backend::Sampler::Filter::LINEAR, Renderer::Backend::Sampler::Filter::LINEAR,
+8
View File
@@ -146,6 +146,8 @@ public:
std::unique_ptr<Renderer::Backend::ITexture> backendTexture = std::unique_ptr<Renderer::Backend::ITexture> backendTexture =
device->CreateTexture2D( device->CreateTexture2D(
textureName.str().c_str(), textureName.str().c_str(),
Renderer::Backend::ITexture::Usage::TRANSFER_DST |
Renderer::Backend::ITexture::Usage::SAMPLED,
Renderer::Backend::Format::R8G8B8A8_UNORM, Renderer::Backend::Format::R8G8B8A8_UNORM,
1, 1, Renderer::Backend::Sampler::MakeDefaultSampler( 1, 1, Renderer::Backend::Sampler::MakeDefaultSampler(
Renderer::Backend::Sampler::Filter::LINEAR, Renderer::Backend::Sampler::Filter::LINEAR,
@@ -192,6 +194,8 @@ public:
std::unique_ptr<Renderer::Backend::ITexture> backendTexture = std::unique_ptr<Renderer::Backend::ITexture> backendTexture =
device->CreateTexture( device->CreateTexture(
textureName.str().c_str(), Renderer::Backend::ITexture::Type::TEXTURE_CUBE, textureName.str().c_str(), Renderer::Backend::ITexture::Type::TEXTURE_CUBE,
Renderer::Backend::ITexture::Usage::TRANSFER_DST |
Renderer::Backend::ITexture::Usage::SAMPLED,
Renderer::Backend::Format::R8G8B8A8_UNORM, Renderer::Backend::Format::R8G8B8A8_UNORM,
1, 1, Renderer::Backend::Sampler::MakeDefaultSampler( 1, 1, Renderer::Backend::Sampler::MakeDefaultSampler(
Renderer::Backend::Sampler::Filter::LINEAR, Renderer::Backend::Sampler::Filter::LINEAR,
@@ -252,6 +256,8 @@ public:
std::unique_ptr<Renderer::Backend::ITexture> backendTexture = std::unique_ptr<Renderer::Backend::ITexture> backendTexture =
device->CreateTexture2D( device->CreateTexture2D(
textureName.str().c_str(), textureName.str().c_str(),
Renderer::Backend::ITexture::Usage::TRANSFER_DST |
Renderer::Backend::ITexture::Usage::SAMPLED,
Renderer::Backend::Format::R8G8B8A8_UNORM, Renderer::Backend::Format::R8G8B8A8_UNORM,
WIDTH, 1, Renderer::Backend::Sampler::MakeDefaultSampler( WIDTH, 1, Renderer::Backend::Sampler::MakeDefaultSampler(
Renderer::Backend::Sampler::Filter::LINEAR, Renderer::Backend::Sampler::Filter::LINEAR,
@@ -562,6 +568,8 @@ public:
texture->m_BackendTexture = m_Device->CreateTexture2D( texture->m_BackendTexture = m_Device->CreateTexture2D(
texture->m_Properties.m_Path.string8().c_str(), texture->m_Properties.m_Path.string8().c_str(),
Renderer::Backend::ITexture::Usage::TRANSFER_DST |
Renderer::Backend::ITexture::Usage::SAMPLED,
format, (width >> texture->m_BaseLevelOffset), (height >> texture->m_BaseLevelOffset), format, (width >> texture->m_BaseLevelOffset), (height >> texture->m_BaseLevelOffset),
defaultSamplerDesc, MIPLevelCount - texture->m_BaseLevelOffset); defaultSamplerDesc, MIPLevelCount - texture->m_BaseLevelOffset);
} }
+9 -2
View File
@@ -126,7 +126,10 @@ void CPostprocManager::RecreateBuffers()
#define GEN_BUFFER_RGBA(name, w, h) \ #define GEN_BUFFER_RGBA(name, w, h) \
name = backendDevice->CreateTexture2D( \ name = backendDevice->CreateTexture2D( \
"PostProc" #name, Renderer::Backend::Format::R8G8B8A8_UNORM, w, h, \ "PostProc" #name, \
Renderer::Backend::ITexture::Usage::SAMPLED | \
Renderer::Backend::ITexture::Usage::COLOR_ATTACHMENT, \
Renderer::Backend::Format::R8G8B8A8_UNORM, w, h, \
Renderer::Backend::Sampler::MakeDefaultSampler( \ Renderer::Backend::Sampler::MakeDefaultSampler( \
Renderer::Backend::Sampler::Filter::LINEAR, \ Renderer::Backend::Sampler::Filter::LINEAR, \
Renderer::Backend::Sampler::AddressMode::CLAMP_TO_EDGE)); Renderer::Backend::Sampler::AddressMode::CLAMP_TO_EDGE));
@@ -155,7 +158,9 @@ void CPostprocManager::RecreateBuffers()
#undef GEN_BUFFER_RGBA #undef GEN_BUFFER_RGBA
// Allocate the Depth/Stencil texture. // Allocate the Depth/Stencil texture.
m_DepthTex = backendDevice->CreateTexture2D("PostPRocDepthTexture", m_DepthTex = backendDevice->CreateTexture2D("PostProcDepthTexture",
Renderer::Backend::ITexture::Usage::SAMPLED |
Renderer::Backend::ITexture::Usage::DEPTH_STENCIL_ATTACHMENT,
Renderer::Backend::Format::D24_S8, m_Width, m_Height, Renderer::Backend::Format::D24_S8, m_Width, m_Height,
Renderer::Backend::Sampler::MakeDefaultSampler( Renderer::Backend::Sampler::MakeDefaultSampler(
Renderer::Backend::Sampler::Filter::LINEAR, Renderer::Backend::Sampler::Filter::LINEAR,
@@ -654,6 +659,7 @@ void CPostprocManager::CreateMultisampleBuffer()
m_MultisampleColorTex = backendDevice->CreateTexture("PostProcColorMS", m_MultisampleColorTex = backendDevice->CreateTexture("PostProcColorMS",
Renderer::Backend::ITexture::Type::TEXTURE_2D_MULTISAMPLE, Renderer::Backend::ITexture::Type::TEXTURE_2D_MULTISAMPLE,
Renderer::Backend::ITexture::Usage::COLOR_ATTACHMENT,
Renderer::Backend::Format::R8G8B8A8_UNORM, m_Width, m_Height, Renderer::Backend::Format::R8G8B8A8_UNORM, m_Width, m_Height,
Renderer::Backend::Sampler::MakeDefaultSampler( Renderer::Backend::Sampler::MakeDefaultSampler(
Renderer::Backend::Sampler::Filter::LINEAR, Renderer::Backend::Sampler::Filter::LINEAR,
@@ -662,6 +668,7 @@ void CPostprocManager::CreateMultisampleBuffer()
// Allocate the Depth/Stencil texture. // Allocate the Depth/Stencil texture.
m_MultisampleDepthTex = backendDevice->CreateTexture("PostProcDepthMS", m_MultisampleDepthTex = backendDevice->CreateTexture("PostProcDepthMS",
Renderer::Backend::ITexture::Type::TEXTURE_2D_MULTISAMPLE, Renderer::Backend::ITexture::Type::TEXTURE_2D_MULTISAMPLE,
Renderer::Backend::ITexture::Usage::DEPTH_STENCIL_ATTACHMENT,
Renderer::Backend::Format::D24_S8, m_Width, m_Height, Renderer::Backend::Format::D24_S8, m_Width, m_Height,
Renderer::Backend::Sampler::MakeDefaultSampler( Renderer::Backend::Sampler::MakeDefaultSampler(
Renderer::Backend::Sampler::Filter::LINEAR, Renderer::Backend::Sampler::Filter::LINEAR,
+3
View File
@@ -529,6 +529,7 @@ void ShadowMapInternals::CreateTexture()
if (g_RenderingOptions.GetShadowAlphaFix()) if (g_RenderingOptions.GetShadowAlphaFix())
{ {
DummyTexture = backendDevice->CreateTexture2D("ShadowMapDummy", DummyTexture = backendDevice->CreateTexture2D("ShadowMapDummy",
Renderer::Backend::ITexture::Usage::COLOR_ATTACHMENT,
Renderer::Backend::Format::R8G8B8A8_UNORM, Width, Height, Renderer::Backend::Format::R8G8B8A8_UNORM, Width, Height,
Renderer::Backend::Sampler::MakeDefaultSampler( Renderer::Backend::Sampler::MakeDefaultSampler(
Renderer::Backend::Sampler::Filter::NEAREST, Renderer::Backend::Sampler::Filter::NEAREST,
@@ -551,6 +552,8 @@ void ShadowMapInternals::CreateTexture()
samplerDesc.compareOp = Renderer::Backend::CompareOp::LESS_OR_EQUAL; samplerDesc.compareOp = Renderer::Backend::CompareOp::LESS_OR_EQUAL;
Texture = backendDevice->CreateTexture2D("ShadowMapDepth", Texture = backendDevice->CreateTexture2D("ShadowMapDepth",
Renderer::Backend::ITexture::Usage::SAMPLED |
Renderer::Backend::ITexture::Usage::DEPTH_STENCIL_ATTACHMENT,
backendFormat, Width, Height, samplerDesc); backendFormat, Width, Height, samplerDesc);
Framebuffer = backendDevice->CreateFramebuffer("ShadowMapFramebuffer", Framebuffer = backendDevice->CreateFramebuffer("ShadowMapFramebuffer",
+2
View File
@@ -120,6 +120,8 @@ void SkyManager::LoadAndUploadSkyTexturesIfNeeded(
std::unique_ptr<Renderer::Backend::ITexture> skyCubeMap = std::unique_ptr<Renderer::Backend::ITexture> skyCubeMap =
g_VideoMode.GetBackendDevice()->CreateTexture("SkyCubeMap", g_VideoMode.GetBackendDevice()->CreateTexture("SkyCubeMap",
Renderer::Backend::ITexture::Type::TEXTURE_CUBE, Renderer::Backend::ITexture::Type::TEXTURE_CUBE,
Renderer::Backend::ITexture::Usage::TRANSFER_DST |
Renderer::Backend::ITexture::Usage::SAMPLED,
Renderer::Backend::Format::R8G8B8A8_UNORM, textures[0].m_Width, textures[0].m_Height, Renderer::Backend::Format::R8G8B8A8_UNORM, textures[0].m_Width, textures[0].m_Height,
Renderer::Backend::Sampler::MakeDefaultSampler( Renderer::Backend::Sampler::MakeDefaultSampler(
Renderer::Backend::Sampler::Filter::LINEAR, Renderer::Backend::Sampler::Filter::LINEAR,
+2
View File
@@ -323,6 +323,8 @@ void TerrainTextureOverlay::RenderAfterWater(
if (!m_Texture || m_Texture->GetWidth() != requiredWidth || m_Texture->GetHeight() != requiredHeight) if (!m_Texture || m_Texture->GetWidth() != requiredWidth || m_Texture->GetHeight() != requiredHeight)
{ {
m_Texture = deviceCommandContext->GetDevice()->CreateTexture2D("TerrainOverlayTexture", m_Texture = deviceCommandContext->GetDevice()->CreateTexture2D("TerrainOverlayTexture",
Renderer::Backend::ITexture::Usage::TRANSFER_DST |
Renderer::Backend::ITexture::Usage::SAMPLED,
Renderer::Backend::Format::R8G8B8A8_UNORM, requiredWidth, requiredHeight, Renderer::Backend::Format::R8G8B8A8_UNORM, requiredWidth, requiredHeight,
Renderer::Backend::Sampler::MakeDefaultSampler( Renderer::Backend::Sampler::MakeDefaultSampler(
Renderer::Backend::Sampler::Filter::NEAREST, Renderer::Backend::Sampler::Filter::NEAREST,
+11
View File
@@ -208,12 +208,16 @@ void WaterManager::RecreateOrLoadTexturesIfNeeded()
if (needsReflectionTextures && !m_ReflectionTexture) if (needsReflectionTextures && !m_ReflectionTexture)
{ {
m_ReflectionTexture = backendDevice->CreateTexture2D("WaterReflectionTexture", m_ReflectionTexture = backendDevice->CreateTexture2D("WaterReflectionTexture",
Renderer::Backend::ITexture::Usage::SAMPLED |
Renderer::Backend::ITexture::Usage::COLOR_ATTACHMENT,
Renderer::Backend::Format::R8G8B8A8_UNORM, m_RefTextureSize, m_RefTextureSize, Renderer::Backend::Format::R8G8B8A8_UNORM, m_RefTextureSize, m_RefTextureSize,
Renderer::Backend::Sampler::MakeDefaultSampler( Renderer::Backend::Sampler::MakeDefaultSampler(
Renderer::Backend::Sampler::Filter::LINEAR, Renderer::Backend::Sampler::Filter::LINEAR,
Renderer::Backend::Sampler::AddressMode::MIRRORED_REPEAT)); Renderer::Backend::Sampler::AddressMode::MIRRORED_REPEAT));
m_ReflFboDepthTexture = backendDevice->CreateTexture2D("WaterReflectionDepthTexture", m_ReflFboDepthTexture = backendDevice->CreateTexture2D("WaterReflectionDepthTexture",
Renderer::Backend::ITexture::Usage::SAMPLED |
Renderer::Backend::ITexture::Usage::DEPTH_STENCIL_ATTACHMENT,
Renderer::Backend::Format::D32, m_RefTextureSize, m_RefTextureSize, Renderer::Backend::Format::D32, m_RefTextureSize, m_RefTextureSize,
Renderer::Backend::Sampler::MakeDefaultSampler( Renderer::Backend::Sampler::MakeDefaultSampler(
Renderer::Backend::Sampler::Filter::NEAREST, Renderer::Backend::Sampler::Filter::NEAREST,
@@ -235,12 +239,16 @@ void WaterManager::RecreateOrLoadTexturesIfNeeded()
if (needsRefractionTextures && !m_RefractionTexture) if (needsRefractionTextures && !m_RefractionTexture)
{ {
m_RefractionTexture = backendDevice->CreateTexture2D("WaterRefractionTexture", m_RefractionTexture = backendDevice->CreateTexture2D("WaterRefractionTexture",
Renderer::Backend::ITexture::Usage::SAMPLED |
Renderer::Backend::ITexture::Usage::COLOR_ATTACHMENT,
Renderer::Backend::Format::R8G8B8A8_UNORM, m_RefTextureSize, m_RefTextureSize, Renderer::Backend::Format::R8G8B8A8_UNORM, m_RefTextureSize, m_RefTextureSize,
Renderer::Backend::Sampler::MakeDefaultSampler( Renderer::Backend::Sampler::MakeDefaultSampler(
Renderer::Backend::Sampler::Filter::LINEAR, Renderer::Backend::Sampler::Filter::LINEAR,
Renderer::Backend::Sampler::AddressMode::MIRRORED_REPEAT)); Renderer::Backend::Sampler::AddressMode::MIRRORED_REPEAT));
m_RefrFboDepthTexture = backendDevice->CreateTexture2D("WaterRefractionDepthTexture", m_RefrFboDepthTexture = backendDevice->CreateTexture2D("WaterRefractionDepthTexture",
Renderer::Backend::ITexture::Usage::SAMPLED |
Renderer::Backend::ITexture::Usage::DEPTH_STENCIL_ATTACHMENT,
Renderer::Backend::Format::D32, m_RefTextureSize, m_RefTextureSize, Renderer::Backend::Format::D32, m_RefTextureSize, m_RefTextureSize,
Renderer::Backend::Sampler::MakeDefaultSampler( Renderer::Backend::Sampler::MakeDefaultSampler(
Renderer::Backend::Sampler::Filter::NEAREST, Renderer::Backend::Sampler::Filter::NEAREST,
@@ -271,12 +279,15 @@ void WaterManager::RecreateOrLoadTexturesIfNeeded()
if (needsFancyTextures && !m_FancyTexture) if (needsFancyTextures && !m_FancyTexture)
{ {
m_FancyTexture = backendDevice->CreateTexture2D("WaterFancyTexture", m_FancyTexture = backendDevice->CreateTexture2D("WaterFancyTexture",
Renderer::Backend::ITexture::Usage::SAMPLED |
Renderer::Backend::ITexture::Usage::COLOR_ATTACHMENT,
Renderer::Backend::Format::R8G8B8A8_UNORM, g_Renderer.GetWidth(), g_Renderer.GetHeight(), Renderer::Backend::Format::R8G8B8A8_UNORM, g_Renderer.GetWidth(), g_Renderer.GetHeight(),
Renderer::Backend::Sampler::MakeDefaultSampler( Renderer::Backend::Sampler::MakeDefaultSampler(
Renderer::Backend::Sampler::Filter::LINEAR, Renderer::Backend::Sampler::Filter::LINEAR,
Renderer::Backend::Sampler::AddressMode::REPEAT)); Renderer::Backend::Sampler::AddressMode::REPEAT));
m_FancyTextureDepth = backendDevice->CreateTexture2D("WaterFancyDepthTexture", m_FancyTextureDepth = backendDevice->CreateTexture2D("WaterFancyDepthTexture",
Renderer::Backend::ITexture::Usage::DEPTH_STENCIL_ATTACHMENT,
Renderer::Backend::Format::D32, g_Renderer.GetWidth(), g_Renderer.GetHeight(), Renderer::Backend::Format::D32, g_Renderer.GetWidth(), g_Renderer.GetHeight(),
Renderer::Backend::Sampler::MakeDefaultSampler( Renderer::Backend::Sampler::MakeDefaultSampler(
Renderer::Backend::Sampler::Filter::LINEAR, Renderer::Backend::Sampler::Filter::LINEAR,
+4 -2
View File
@@ -73,11 +73,13 @@ public:
virtual std::unique_ptr<IDeviceCommandContext> CreateCommandContext() = 0; virtual std::unique_ptr<IDeviceCommandContext> CreateCommandContext() = 0;
virtual std::unique_ptr<ITexture> CreateTexture(const char* name, const ITexture::Type type, virtual std::unique_ptr<ITexture> CreateTexture(
const char* name, const ITexture::Type type, const uint32_t usage,
const Format format, const uint32_t width, const uint32_t height, const Format format, const uint32_t width, const uint32_t height,
const Sampler::Desc& defaultSamplerDesc, const uint32_t MIPLevelCount, const uint32_t sampleCount) = 0; const Sampler::Desc& defaultSamplerDesc, const uint32_t MIPLevelCount, const uint32_t sampleCount) = 0;
virtual std::unique_ptr<ITexture> CreateTexture2D(const char* name, virtual std::unique_ptr<ITexture> CreateTexture2D(
const char* name, const uint32_t usage,
const Format format, const uint32_t width, const uint32_t height, const Format format, const uint32_t width, const uint32_t height,
const Sampler::Desc& defaultSamplerDesc, const uint32_t MIPLevelCount = 1, const uint32_t sampleCount = 1) = 0; const Sampler::Desc& defaultSamplerDesc, const uint32_t MIPLevelCount = 1, const uint32_t sampleCount = 1) = 0;
+12
View File
@@ -40,7 +40,19 @@ public:
TEXTURE_CUBE TEXTURE_CUBE
}; };
// Using a struct instead of a enum allows using the same syntax while
// avoiding adding operator overrides and additional checks on casts.
struct Usage
{
static constexpr uint32_t TRANSFER_SRC = 1u << 0u;
static constexpr uint32_t TRANSFER_DST = 1u << 1u;
static constexpr uint32_t SAMPLED = 1u << 2u;
static constexpr uint32_t COLOR_ATTACHMENT = 1u << 3u;
static constexpr uint32_t DEPTH_STENCIL_ATTACHMENT = 1u << 4u;
};
virtual Type GetType() const = 0; virtual Type GetType() const = 0;
virtual uint32_t GetUsage() const = 0;
virtual Format GetFormat() const = 0; virtual Format GetFormat() const = 0;
virtual uint32_t GetWidth() const = 0; virtual uint32_t GetWidth() const = 0;
+6 -4
View File
@@ -73,18 +73,20 @@ std::unique_ptr<IDeviceCommandContext> CDevice::CreateCommandContext()
return CDeviceCommandContext::Create(this); return CDeviceCommandContext::Create(this);
} }
std::unique_ptr<ITexture> CDevice::CreateTexture(const char* UNUSED(name), const CTexture::Type type, std::unique_ptr<ITexture> CDevice::CreateTexture(
const char* UNUSED(name), const CTexture::Type type, const uint32_t usage,
const Format format, const uint32_t width, const uint32_t height, const Format format, const uint32_t width, const uint32_t height,
const Sampler::Desc& UNUSED(defaultSamplerDesc), const uint32_t MIPLevelCount, const uint32_t UNUSED(sampleCount)) const Sampler::Desc& UNUSED(defaultSamplerDesc), const uint32_t MIPLevelCount, const uint32_t UNUSED(sampleCount))
{ {
return CTexture::Create(this, type, format, width, height, MIPLevelCount); return CTexture::Create(this, type, usage, format, width, height, MIPLevelCount);
} }
std::unique_ptr<ITexture> CDevice::CreateTexture2D(const char* name, std::unique_ptr<ITexture> CDevice::CreateTexture2D(
const char* name, const uint32_t usage,
const Format format, const uint32_t width, const uint32_t height, const Format format, const uint32_t width, const uint32_t height,
const Sampler::Desc& defaultSamplerDesc, const uint32_t MIPLevelCount, const uint32_t sampleCount) const Sampler::Desc& defaultSamplerDesc, const uint32_t MIPLevelCount, const uint32_t sampleCount)
{ {
return CreateTexture(name, ITexture::Type::TEXTURE_2D, return CreateTexture(name, ITexture::Type::TEXTURE_2D, usage,
format, width, height, defaultSamplerDesc, MIPLevelCount, sampleCount); format, width, height, defaultSamplerDesc, MIPLevelCount, sampleCount);
} }
+4 -2
View File
@@ -50,11 +50,13 @@ public:
std::unique_ptr<IDeviceCommandContext> CreateCommandContext() override; std::unique_ptr<IDeviceCommandContext> CreateCommandContext() override;
std::unique_ptr<ITexture> CreateTexture(const char* name, const ITexture::Type type, std::unique_ptr<ITexture> CreateTexture(
const char* name, const ITexture::Type type, const uint32_t usage,
const Format format, const uint32_t width, const uint32_t height, const Format format, const uint32_t width, const uint32_t height,
const Sampler::Desc& defaultSamplerDesc, const uint32_t MIPLevelCount, const uint32_t sampleCount) override; const Sampler::Desc& defaultSamplerDesc, const uint32_t MIPLevelCount, const uint32_t sampleCount) override;
std::unique_ptr<ITexture> CreateTexture2D(const char* name, std::unique_ptr<ITexture> CreateTexture2D(
const char* name, const uint32_t usage,
const Format format, const uint32_t width, const uint32_t height, const Format format, const uint32_t width, const uint32_t height,
const Sampler::Desc& defaultSamplerDesc, const uint32_t MIPLevelCount = 1, const uint32_t sampleCount = 1) override; const Sampler::Desc& defaultSamplerDesc, const uint32_t MIPLevelCount = 1, const uint32_t sampleCount = 1) override;
+3 -2
View File
@@ -32,15 +32,16 @@ namespace Dummy
// static // static
std::unique_ptr<ITexture> CTexture::Create( std::unique_ptr<ITexture> CTexture::Create(
CDevice* device, const Type type, const Format format, CDevice* device, const Type type, const uint32_t usage, const Format format,
const uint32_t width, const uint32_t height, const uint32_t width, const uint32_t height,
const uint32_t MIPLevelCount) const uint32_t MIPLevelCount)
{ {
std::unique_ptr<CTexture> texture(new CTexture()); std::unique_ptr<CTexture> texture(new CTexture());
texture->m_Device = device; texture->m_Device = device;
texture->m_Format = format;
texture->m_Type = type; texture->m_Type = type;
texture->m_Usage = usage;
texture->m_Format = format;
texture->m_Width = width; texture->m_Width = width;
texture->m_Height = height; texture->m_Height = height;
texture->m_MIPLevelCount = MIPLevelCount; texture->m_MIPLevelCount = MIPLevelCount;
+4 -2
View File
@@ -41,6 +41,7 @@ public:
IDevice* GetDevice() override; IDevice* GetDevice() override;
Type GetType() const override { return m_Type; } Type GetType() const override { return m_Type; }
uint32_t GetUsage() const override { return m_Usage; }
Format GetFormat() const override { return m_Format; } Format GetFormat() const override { return m_Format; }
uint32_t GetWidth() const override { return m_Width; } uint32_t GetWidth() const override { return m_Width; }
@@ -53,12 +54,13 @@ private:
CTexture(); CTexture();
static std::unique_ptr<ITexture> Create( static std::unique_ptr<ITexture> Create(
CDevice* device, const Type type, const Format format, CDevice* device, const Type type, const uint32_t usage,
const uint32_t width, const uint32_t height, const Format format, const uint32_t width, const uint32_t height,
const uint32_t MIPLevelCount); const uint32_t MIPLevelCount);
CDevice* m_Device = nullptr; CDevice* m_Device = nullptr;
Type m_Type = Type::TEXTURE_2D; Type m_Type = Type::TEXTURE_2D;
uint32_t m_Usage = 0;
Format m_Format = Format::UNDEFINED; Format m_Format = Format::UNDEFINED;
uint32_t m_Width = 0; uint32_t m_Width = 0;
uint32_t m_Height = 0; uint32_t m_Height = 0;
+6 -4
View File
@@ -861,19 +861,21 @@ std::unique_ptr<IDeviceCommandContext> CDevice::CreateCommandContext()
return commandContet; return commandContet;
} }
std::unique_ptr<ITexture> CDevice::CreateTexture(const char* name, const ITexture::Type type, std::unique_ptr<ITexture> CDevice::CreateTexture(
const char* name, const ITexture::Type type, const uint32_t usage,
const Format format, const uint32_t width, const uint32_t height, const Format format, const uint32_t width, const uint32_t height,
const Sampler::Desc& defaultSamplerDesc, const uint32_t MIPLevelCount, const uint32_t sampleCount) const Sampler::Desc& defaultSamplerDesc, const uint32_t MIPLevelCount, const uint32_t sampleCount)
{ {
return CTexture::Create(this, name, type, return CTexture::Create(this, name, type, usage,
format, width, height, defaultSamplerDesc, MIPLevelCount, sampleCount); format, width, height, defaultSamplerDesc, MIPLevelCount, sampleCount);
} }
std::unique_ptr<ITexture> CDevice::CreateTexture2D(const char* name, std::unique_ptr<ITexture> CDevice::CreateTexture2D(
const char* name, const uint32_t usage,
const Format format, const uint32_t width, const uint32_t height, const Format format, const uint32_t width, const uint32_t height,
const Sampler::Desc& defaultSamplerDesc, const uint32_t MIPLevelCount, const uint32_t sampleCount) const Sampler::Desc& defaultSamplerDesc, const uint32_t MIPLevelCount, const uint32_t sampleCount)
{ {
return CreateTexture(name, CTexture::Type::TEXTURE_2D, return CreateTexture(name, CTexture::Type::TEXTURE_2D, usage,
format, width, height, defaultSamplerDesc, MIPLevelCount, sampleCount); format, width, height, defaultSamplerDesc, MIPLevelCount, sampleCount);
} }
+4 -2
View File
@@ -67,11 +67,13 @@ public:
CDeviceCommandContext* GetActiveCommandContext() { return m_ActiveCommandContext; } CDeviceCommandContext* GetActiveCommandContext() { return m_ActiveCommandContext; }
std::unique_ptr<ITexture> CreateTexture(const char* name, const ITexture::Type type, std::unique_ptr<ITexture> CreateTexture(
const char* name, const ITexture::Type type, const uint32_t usage,
const Format format, const uint32_t width, const uint32_t height, const Format format, const uint32_t width, const uint32_t height,
const Sampler::Desc& defaultSamplerDesc, const uint32_t MIPLevelCount, const uint32_t sampleCount) override; const Sampler::Desc& defaultSamplerDesc, const uint32_t MIPLevelCount, const uint32_t sampleCount) override;
std::unique_ptr<ITexture> CreateTexture2D(const char* name, std::unique_ptr<ITexture> CreateTexture2D(
const char* name, const uint32_t usage,
const Format format, const uint32_t width, const uint32_t height, const Format format, const uint32_t width, const uint32_t height,
const Sampler::Desc& defaultSamplerDesc, const uint32_t MIPLevelCount = 1, const uint32_t sampleCount = 1) override; const Sampler::Desc& defaultSamplerDesc, const uint32_t MIPLevelCount = 1, const uint32_t sampleCount = 1) override;
@@ -222,6 +222,7 @@ void CDeviceCommandContext::UploadTextureRegion(
{ {
ENSURE(destinationTexture); ENSURE(destinationTexture);
CTexture* texture = destinationTexture->As<CTexture>(); CTexture* texture = destinationTexture->As<CTexture>();
ENSURE(texture->GetUsage() & Renderer::Backend::ITexture::Usage::TRANSFER_DST);
ENSURE(width > 0 && height > 0); ENSURE(width > 0 && height > 0);
if (texture->GetType() == CTexture::Type::TEXTURE_2D) if (texture->GetType() == CTexture::Type::TEXTURE_2D)
{ {
@@ -1075,6 +1076,8 @@ void CDeviceCommandContext::SetTexture(const int32_t bindingSlot, ITexture* text
{ {
ENSURE(m_ShaderProgram); ENSURE(m_ShaderProgram);
ENSURE(texture); ENSURE(texture);
ENSURE(texture->GetUsage() & Renderer::Backend::ITexture::Usage::SAMPLED);
const CShaderProgram::TextureUnit textureUnit = const CShaderProgram::TextureUnit textureUnit =
m_ShaderProgram->GetTextureUnit(bindingSlot); m_ShaderProgram->GetTextureUnit(bindingSlot);
if (!textureUnit.type) if (!textureUnit.type)
@@ -58,6 +58,7 @@ std::unique_ptr<CFramebuffer> CFramebuffer::Create(
if (colorAttachment) if (colorAttachment)
{ {
ENSURE(device->IsFramebufferFormatSupported(colorAttachment->GetFormat())); ENSURE(device->IsFramebufferFormatSupported(colorAttachment->GetFormat()));
ENSURE(colorAttachment->GetUsage() & Renderer::Backend::ITexture::Usage::COLOR_ATTACHMENT);
framebuffer->m_AttachmentMask |= GL_COLOR_BUFFER_BIT; framebuffer->m_AttachmentMask |= GL_COLOR_BUFFER_BIT;
@@ -73,6 +74,8 @@ std::unique_ptr<CFramebuffer> CFramebuffer::Create(
} }
if (depthStencilAttachment) if (depthStencilAttachment)
{ {
ENSURE(depthStencilAttachment->GetUsage() & Renderer::Backend::ITexture::Usage::DEPTH_STENCIL_ATTACHMENT);
framebuffer->m_Width = depthStencilAttachment->GetWidth(); framebuffer->m_Width = depthStencilAttachment->GetWidth();
framebuffer->m_Height = depthStencilAttachment->GetHeight(); framebuffer->m_Height = depthStencilAttachment->GetHeight();
framebuffer->m_AttachmentMask |= GL_DEPTH_BUFFER_BIT; framebuffer->m_AttachmentMask |= GL_DEPTH_BUFFER_BIT;
+6 -4
View File
@@ -87,19 +87,21 @@ GLenum TypeToGLEnum(CTexture::Type type)
} // anonymous namespace } // anonymous namespace
// static // static
std::unique_ptr<CTexture> CTexture::Create(CDevice* device, const char* name, std::unique_ptr<CTexture> CTexture::Create(
const Type type, const Format format, const uint32_t width, const uint32_t height, CDevice* device, const char* name, const Type type, const uint32_t usage,
const Format format, const uint32_t width, const uint32_t height,
const Sampler::Desc& defaultSamplerDesc, const uint32_t MIPLevelCount, const uint32_t sampleCount) const Sampler::Desc& defaultSamplerDesc, const uint32_t MIPLevelCount, const uint32_t sampleCount)
{ {
std::unique_ptr<CTexture> texture(new CTexture()); std::unique_ptr<CTexture> texture(new CTexture());
ENSURE(format != Format::UNDEFINED); ENSURE(format != Format::UNDEFINED);
ENSURE(width > 0 && height > 0 && MIPLevelCount > 0); ENSURE(width > 0 && height > 0 && MIPLevelCount > 0);
ENSURE((type == Type::TEXTURE_2D_MULTISAMPLE && sampleCount > 1) || sampleCount == 1); ENSURE((type == Type::TEXTURE_2D_MULTISAMPLE && sampleCount > 1 && !(usage & ITexture::Usage::SAMPLED)) || sampleCount == 1);
texture->m_Device = device; texture->m_Device = device;
texture->m_Format = format;
texture->m_Type = type; texture->m_Type = type;
texture->m_Usage = usage;
texture->m_Format = format;
texture->m_Width = width; texture->m_Width = width;
texture->m_Height = height; texture->m_Height = height;
texture->m_MIPLevelCount = MIPLevelCount; texture->m_MIPLevelCount = MIPLevelCount;
+5 -2
View File
@@ -47,6 +47,7 @@ public:
IDevice* GetDevice() override; IDevice* GetDevice() override;
Type GetType() const override { return m_Type; } Type GetType() const override { return m_Type; }
uint32_t GetUsage() const override { return m_Usage; }
Format GetFormat() const override { return m_Format; } Format GetFormat() const override { return m_Format; }
uint32_t GetWidth() const override { return m_Width; } uint32_t GetWidth() const override { return m_Width; }
@@ -64,13 +65,15 @@ private:
// GL before 3.3 doesn't support sampler objects, so each texture should have // GL before 3.3 doesn't support sampler objects, so each texture should have
// an own default sampler. // an own default sampler.
static std::unique_ptr<CTexture> Create(CDevice* device, const char* name, static std::unique_ptr<CTexture> Create(
const Type type, const Format format, const uint32_t width, const uint32_t height, CDevice* device, const char* name, const Type type, const uint32_t usage,
const Format format, const uint32_t width, const uint32_t height,
const Sampler::Desc& defaultSamplerDesc, const uint32_t MIPLevelCount, const uint32_t sampleCount); const Sampler::Desc& defaultSamplerDesc, const uint32_t MIPLevelCount, const uint32_t sampleCount);
GLuint m_Handle = 0; GLuint m_Handle = 0;
Type m_Type = Type::TEXTURE_2D; Type m_Type = Type::TEXTURE_2D;
uint32_t m_Usage = 0;
Format m_Format = Format::UNDEFINED; Format m_Format = Format::UNDEFINED;
uint32_t m_Width = 0; uint32_t m_Width = 0;
uint32_t m_Height = 0; uint32_t m_Height = 0;
+8 -10
View File
@@ -84,12 +84,14 @@ std::unique_ptr<IDeviceCommandContext> CDevice::CreateCommandContext()
return nullptr; return nullptr;
} }
std::unique_ptr<ITexture> CDevice::CreateTexture(const char* name, const ITexture::Type type, std::unique_ptr<ITexture> CDevice::CreateTexture(
const char* name, const ITexture::Type type, const uint32_t usage,
const Format format, const uint32_t width, const uint32_t height, const Format format, const uint32_t width, const uint32_t height,
const Sampler::Desc& defaultSamplerDesc, const uint32_t MIPLevelCount, const uint32_t sampleCount) const Sampler::Desc& defaultSamplerDesc, const uint32_t MIPLevelCount, const uint32_t sampleCount)
{ {
UNUSED2(name); UNUSED2(name);
UNUSED2(type); UNUSED2(type);
UNUSED2(usage);
UNUSED2(format); UNUSED2(format);
UNUSED2(width); UNUSED2(width);
UNUSED2(height); UNUSED2(height);
@@ -99,18 +101,14 @@ std::unique_ptr<ITexture> CDevice::CreateTexture(const char* name, const ITextur
return nullptr; return nullptr;
} }
std::unique_ptr<ITexture> CDevice::CreateTexture2D(const char* name, std::unique_ptr<ITexture> CDevice::CreateTexture2D(
const char* name, const uint32_t usage,
const Format format, const uint32_t width, const uint32_t height, const Format format, const uint32_t width, const uint32_t height,
const Sampler::Desc& defaultSamplerDesc, const uint32_t MIPLevelCount, const uint32_t sampleCount) const Sampler::Desc& defaultSamplerDesc, const uint32_t MIPLevelCount, const uint32_t sampleCount)
{ {
UNUSED2(name); return CreateTexture(
UNUSED2(format); name, ITexture::Type::TEXTURE_2D, usage, format,
UNUSED2(width); width, height, defaultSamplerDesc, MIPLevelCount, sampleCount);
UNUSED2(height);
UNUSED2(defaultSamplerDesc);
UNUSED2(MIPLevelCount);
UNUSED2(sampleCount);
return nullptr;
} }
std::unique_ptr<IFramebuffer> CDevice::CreateFramebuffer( std::unique_ptr<IFramebuffer> CDevice::CreateFramebuffer(
+4 -2
View File
@@ -55,11 +55,13 @@ public:
std::unique_ptr<IDeviceCommandContext> CreateCommandContext() override; std::unique_ptr<IDeviceCommandContext> CreateCommandContext() override;
std::unique_ptr<ITexture> CreateTexture(const char* name, const ITexture::Type type, std::unique_ptr<ITexture> CreateTexture(
const char* name, const ITexture::Type type, const uint32_t usage,
const Format format, const uint32_t width, const uint32_t height, const Format format, const uint32_t width, const uint32_t height,
const Sampler::Desc& defaultSamplerDesc, const uint32_t MIPLevelCount, const uint32_t sampleCount) override; const Sampler::Desc& defaultSamplerDesc, const uint32_t MIPLevelCount, const uint32_t sampleCount) override;
std::unique_ptr<ITexture> CreateTexture2D(const char* name, std::unique_ptr<ITexture> CreateTexture2D(
const char* name, const uint32_t usage,
const Format format, const uint32_t width, const uint32_t height, const Format format, const uint32_t width, const uint32_t height,
const Sampler::Desc& defaultSamplerDesc, const uint32_t MIPLevelCount = 1, const uint32_t sampleCount = 1) override; const Sampler::Desc& defaultSamplerDesc, const uint32_t MIPLevelCount = 1, const uint32_t sampleCount = 1) override;