Adds usage flags to backend textures.

This was SVN commit r27152.
This commit is contained in:
Vladislav Belov 2022-10-12 23:19:27 +00:00
parent d3f0395d2a
commit 64bd81ae6b
24 changed files with 123 additions and 40 deletions

View File

@ -260,6 +260,8 @@ void CLOSTexture::ConstructTexture(Renderer::Backend::IDeviceCommandContext* dev
}
m_Texture = backendDevice->CreateTexture2D("LOSTexture",
Renderer::Backend::ITexture::Usage::TRANSFER_DST |
Renderer::Backend::ITexture::Usage::SAMPLED,
m_TextureFormat, textureSize, textureSize, defaultSamplerDesc);
// 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())
{
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_TextureFormat, textureSize, textureSize, defaultSamplerDesc);
usage, m_TextureFormat, textureSize, textureSize, defaultSamplerDesc);
m_SmoothTextures[1] = backendDevice->CreateTexture2D("LOSSmoothTexture1",
m_TextureFormat, textureSize, textureSize, defaultSamplerDesc);
usage, m_TextureFormat, textureSize, textureSize, defaultSamplerDesc);
m_SmoothFramebuffers[0] = backendDevice->CreateFramebuffer(
"LOSSmoothFramebuffer0", m_SmoothTextures[0].get(), nullptr);

View File

@ -332,6 +332,8 @@ void CMiniMapTexture::CreateTextures(
// Create terrain texture
m_TerrainTexture = backendDevice->CreateTexture2D("MiniMapTerrainTexture",
Renderer::Backend::ITexture::Usage::TRANSFER_DST |
Renderer::Backend::ITexture::Usage::SAMPLED,
Renderer::Backend::Format::R8G8B8A8_UNORM, textureSize, textureSize, defaultSamplerDesc);
// Initialise texture with solid black, for the areas we don't
@ -348,6 +350,8 @@ void CMiniMapTexture::CreateTextures(
m_FinalTexture = g_Renderer.GetTextureManager().WrapBackendTexture(
backendDevice->CreateTexture2D("MiniMapFinalTexture",
Renderer::Backend::ITexture::Usage::SAMPLED |
Renderer::Backend::ITexture::Usage::COLOR_ATTACHMENT,
Renderer::Backend::Format::R8G8B8A8_UNORM,
FINAL_TEXTURE_SIZE, FINAL_TEXTURE_SIZE, defaultSamplerDesc));

View File

@ -293,6 +293,8 @@ CTerrainTextureManager::LoadAlphaMap(const VfsPath& alphaMapType)
#endif
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::Sampler::MakeDefaultSampler(
Renderer::Backend::Sampler::Filter::LINEAR,

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));
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::Sampler::MakeDefaultSampler(
Renderer::Backend::Sampler::Filter::LINEAR,

View File

@ -146,6 +146,8 @@ public:
std::unique_ptr<Renderer::Backend::ITexture> backendTexture =
device->CreateTexture2D(
textureName.str().c_str(),
Renderer::Backend::ITexture::Usage::TRANSFER_DST |
Renderer::Backend::ITexture::Usage::SAMPLED,
Renderer::Backend::Format::R8G8B8A8_UNORM,
1, 1, Renderer::Backend::Sampler::MakeDefaultSampler(
Renderer::Backend::Sampler::Filter::LINEAR,
@ -192,6 +194,8 @@ public:
std::unique_ptr<Renderer::Backend::ITexture> backendTexture =
device->CreateTexture(
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,
1, 1, Renderer::Backend::Sampler::MakeDefaultSampler(
Renderer::Backend::Sampler::Filter::LINEAR,
@ -252,6 +256,8 @@ public:
std::unique_ptr<Renderer::Backend::ITexture> backendTexture =
device->CreateTexture2D(
textureName.str().c_str(),
Renderer::Backend::ITexture::Usage::TRANSFER_DST |
Renderer::Backend::ITexture::Usage::SAMPLED,
Renderer::Backend::Format::R8G8B8A8_UNORM,
WIDTH, 1, Renderer::Backend::Sampler::MakeDefaultSampler(
Renderer::Backend::Sampler::Filter::LINEAR,
@ -562,6 +568,8 @@ public:
texture->m_BackendTexture = m_Device->CreateTexture2D(
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),
defaultSamplerDesc, MIPLevelCount - texture->m_BaseLevelOffset);
}

View File

@ -126,7 +126,10 @@ void CPostprocManager::RecreateBuffers()
#define GEN_BUFFER_RGBA(name, w, h) \
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::Filter::LINEAR, \
Renderer::Backend::Sampler::AddressMode::CLAMP_TO_EDGE));
@ -155,7 +158,9 @@ void CPostprocManager::RecreateBuffers()
#undef GEN_BUFFER_RGBA
// 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::Sampler::MakeDefaultSampler(
Renderer::Backend::Sampler::Filter::LINEAR,
@ -654,6 +659,7 @@ void CPostprocManager::CreateMultisampleBuffer()
m_MultisampleColorTex = backendDevice->CreateTexture("PostProcColorMS",
Renderer::Backend::ITexture::Type::TEXTURE_2D_MULTISAMPLE,
Renderer::Backend::ITexture::Usage::COLOR_ATTACHMENT,
Renderer::Backend::Format::R8G8B8A8_UNORM, m_Width, m_Height,
Renderer::Backend::Sampler::MakeDefaultSampler(
Renderer::Backend::Sampler::Filter::LINEAR,
@ -662,6 +668,7 @@ void CPostprocManager::CreateMultisampleBuffer()
// Allocate the Depth/Stencil texture.
m_MultisampleDepthTex = backendDevice->CreateTexture("PostProcDepthMS",
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::Sampler::MakeDefaultSampler(
Renderer::Backend::Sampler::Filter::LINEAR,

View File

@ -529,6 +529,7 @@ void ShadowMapInternals::CreateTexture()
if (g_RenderingOptions.GetShadowAlphaFix())
{
DummyTexture = backendDevice->CreateTexture2D("ShadowMapDummy",
Renderer::Backend::ITexture::Usage::COLOR_ATTACHMENT,
Renderer::Backend::Format::R8G8B8A8_UNORM, Width, Height,
Renderer::Backend::Sampler::MakeDefaultSampler(
Renderer::Backend::Sampler::Filter::NEAREST,
@ -551,6 +552,8 @@ void ShadowMapInternals::CreateTexture()
samplerDesc.compareOp = Renderer::Backend::CompareOp::LESS_OR_EQUAL;
Texture = backendDevice->CreateTexture2D("ShadowMapDepth",
Renderer::Backend::ITexture::Usage::SAMPLED |
Renderer::Backend::ITexture::Usage::DEPTH_STENCIL_ATTACHMENT,
backendFormat, Width, Height, samplerDesc);
Framebuffer = backendDevice->CreateFramebuffer("ShadowMapFramebuffer",

View File

@ -120,6 +120,8 @@ void SkyManager::LoadAndUploadSkyTexturesIfNeeded(
std::unique_ptr<Renderer::Backend::ITexture> skyCubeMap =
g_VideoMode.GetBackendDevice()->CreateTexture("SkyCubeMap",
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::Sampler::MakeDefaultSampler(
Renderer::Backend::Sampler::Filter::LINEAR,

View File

@ -323,6 +323,8 @@ void TerrainTextureOverlay::RenderAfterWater(
if (!m_Texture || m_Texture->GetWidth() != requiredWidth || m_Texture->GetHeight() != requiredHeight)
{
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::Sampler::MakeDefaultSampler(
Renderer::Backend::Sampler::Filter::NEAREST,

View File

@ -208,12 +208,16 @@ void WaterManager::RecreateOrLoadTexturesIfNeeded()
if (needsReflectionTextures && !m_ReflectionTexture)
{
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::Sampler::MakeDefaultSampler(
Renderer::Backend::Sampler::Filter::LINEAR,
Renderer::Backend::Sampler::AddressMode::MIRRORED_REPEAT));
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::Sampler::MakeDefaultSampler(
Renderer::Backend::Sampler::Filter::NEAREST,
@ -235,12 +239,16 @@ void WaterManager::RecreateOrLoadTexturesIfNeeded()
if (needsRefractionTextures && !m_RefractionTexture)
{
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::Sampler::MakeDefaultSampler(
Renderer::Backend::Sampler::Filter::LINEAR,
Renderer::Backend::Sampler::AddressMode::MIRRORED_REPEAT));
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::Sampler::MakeDefaultSampler(
Renderer::Backend::Sampler::Filter::NEAREST,
@ -271,12 +279,15 @@ void WaterManager::RecreateOrLoadTexturesIfNeeded()
if (needsFancyTextures && !m_FancyTexture)
{
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::Sampler::MakeDefaultSampler(
Renderer::Backend::Sampler::Filter::LINEAR,
Renderer::Backend::Sampler::AddressMode::REPEAT));
m_FancyTextureDepth = backendDevice->CreateTexture2D("WaterFancyDepthTexture",
Renderer::Backend::ITexture::Usage::DEPTH_STENCIL_ATTACHMENT,
Renderer::Backend::Format::D32, g_Renderer.GetWidth(), g_Renderer.GetHeight(),
Renderer::Backend::Sampler::MakeDefaultSampler(
Renderer::Backend::Sampler::Filter::LINEAR,

View File

@ -73,11 +73,13 @@ public:
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 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 Sampler::Desc& defaultSamplerDesc, const uint32_t MIPLevelCount = 1, const uint32_t sampleCount = 1) = 0;

View File

@ -40,7 +40,19 @@ public:
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 uint32_t GetUsage() const = 0;
virtual Format GetFormat() const = 0;
virtual uint32_t GetWidth() const = 0;

View File

@ -73,18 +73,20 @@ std::unique_ptr<IDeviceCommandContext> CDevice::CreateCommandContext()
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 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 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);
}

View File

@ -50,11 +50,13 @@ public:
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 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 Sampler::Desc& defaultSamplerDesc, const uint32_t MIPLevelCount = 1, const uint32_t sampleCount = 1) override;

View File

@ -32,15 +32,16 @@ namespace Dummy
// static
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 MIPLevelCount)
{
std::unique_ptr<CTexture> texture(new CTexture());
texture->m_Device = device;
texture->m_Format = format;
texture->m_Type = type;
texture->m_Usage = usage;
texture->m_Format = format;
texture->m_Width = width;
texture->m_Height = height;
texture->m_MIPLevelCount = MIPLevelCount;

View File

@ -41,6 +41,7 @@ public:
IDevice* GetDevice() override;
Type GetType() const override { return m_Type; }
uint32_t GetUsage() const override { return m_Usage; }
Format GetFormat() const override { return m_Format; }
uint32_t GetWidth() const override { return m_Width; }
@ -53,12 +54,13 @@ private:
CTexture();
static std::unique_ptr<ITexture> Create(
CDevice* device, const Type type, const Format format,
const uint32_t width, const uint32_t height,
CDevice* device, const Type type, const uint32_t usage,
const Format format, const uint32_t width, const uint32_t height,
const uint32_t MIPLevelCount);
CDevice* m_Device = nullptr;
Type m_Type = Type::TEXTURE_2D;
uint32_t m_Usage = 0;
Format m_Format = Format::UNDEFINED;
uint32_t m_Width = 0;
uint32_t m_Height = 0;

View File

@ -861,19 +861,21 @@ std::unique_ptr<IDeviceCommandContext> CDevice::CreateCommandContext()
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 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);
}
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 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);
}

View File

@ -67,11 +67,13 @@ public:
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 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 Sampler::Desc& defaultSamplerDesc, const uint32_t MIPLevelCount = 1, const uint32_t sampleCount = 1) override;

View File

@ -222,6 +222,7 @@ void CDeviceCommandContext::UploadTextureRegion(
{
ENSURE(destinationTexture);
CTexture* texture = destinationTexture->As<CTexture>();
ENSURE(texture->GetUsage() & Renderer::Backend::ITexture::Usage::TRANSFER_DST);
ENSURE(width > 0 && height > 0);
if (texture->GetType() == CTexture::Type::TEXTURE_2D)
{
@ -1075,6 +1076,8 @@ void CDeviceCommandContext::SetTexture(const int32_t bindingSlot, ITexture* text
{
ENSURE(m_ShaderProgram);
ENSURE(texture);
ENSURE(texture->GetUsage() & Renderer::Backend::ITexture::Usage::SAMPLED);
const CShaderProgram::TextureUnit textureUnit =
m_ShaderProgram->GetTextureUnit(bindingSlot);
if (!textureUnit.type)

View File

@ -58,6 +58,7 @@ std::unique_ptr<CFramebuffer> CFramebuffer::Create(
if (colorAttachment)
{
ENSURE(device->IsFramebufferFormatSupported(colorAttachment->GetFormat()));
ENSURE(colorAttachment->GetUsage() & Renderer::Backend::ITexture::Usage::COLOR_ATTACHMENT);
framebuffer->m_AttachmentMask |= GL_COLOR_BUFFER_BIT;
@ -73,6 +74,8 @@ std::unique_ptr<CFramebuffer> CFramebuffer::Create(
}
if (depthStencilAttachment)
{
ENSURE(depthStencilAttachment->GetUsage() & Renderer::Backend::ITexture::Usage::DEPTH_STENCIL_ATTACHMENT);
framebuffer->m_Width = depthStencilAttachment->GetWidth();
framebuffer->m_Height = depthStencilAttachment->GetHeight();
framebuffer->m_AttachmentMask |= GL_DEPTH_BUFFER_BIT;

View File

@ -87,19 +87,21 @@ GLenum TypeToGLEnum(CTexture::Type type)
} // anonymous namespace
// static
std::unique_ptr<CTexture> CTexture::Create(CDevice* device, const char* name,
const Type type, const Format format, const uint32_t width, const uint32_t height,
std::unique_ptr<CTexture> CTexture::Create(
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)
{
std::unique_ptr<CTexture> texture(new CTexture());
ENSURE(format != Format::UNDEFINED);
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_Format = format;
texture->m_Type = type;
texture->m_Usage = usage;
texture->m_Format = format;
texture->m_Width = width;
texture->m_Height = height;
texture->m_MIPLevelCount = MIPLevelCount;

View File

@ -47,6 +47,7 @@ public:
IDevice* GetDevice() override;
Type GetType() const override { return m_Type; }
uint32_t GetUsage() const override { return m_Usage; }
Format GetFormat() const override { return m_Format; }
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
// an own default sampler.
static std::unique_ptr<CTexture> Create(CDevice* device, const char* name,
const Type type, const Format format, const uint32_t width, const uint32_t height,
static std::unique_ptr<CTexture> Create(
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);
GLuint m_Handle = 0;
Type m_Type = Type::TEXTURE_2D;
uint32_t m_Usage = 0;
Format m_Format = Format::UNDEFINED;
uint32_t m_Width = 0;
uint32_t m_Height = 0;

View File

@ -84,12 +84,14 @@ std::unique_ptr<IDeviceCommandContext> CDevice::CreateCommandContext()
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 Sampler::Desc& defaultSamplerDesc, const uint32_t MIPLevelCount, const uint32_t sampleCount)
{
UNUSED2(name);
UNUSED2(type);
UNUSED2(usage);
UNUSED2(format);
UNUSED2(width);
UNUSED2(height);
@ -99,18 +101,14 @@ std::unique_ptr<ITexture> CDevice::CreateTexture(const char* name, const ITextur
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 Sampler::Desc& defaultSamplerDesc, const uint32_t MIPLevelCount, const uint32_t sampleCount)
{
UNUSED2(name);
UNUSED2(format);
UNUSED2(width);
UNUSED2(height);
UNUSED2(defaultSamplerDesc);
UNUSED2(MIPLevelCount);
UNUSED2(sampleCount);
return nullptr;
return CreateTexture(
name, ITexture::Type::TEXTURE_2D, usage, format,
width, height, defaultSamplerDesc, MIPLevelCount, sampleCount);
}
std::unique_ptr<IFramebuffer> CDevice::CreateFramebuffer(

View File

@ -55,11 +55,13 @@ public:
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 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 Sampler::Desc& defaultSamplerDesc, const uint32_t MIPLevelCount = 1, const uint32_t sampleCount = 1) override;