forked from 0ad/0ad
Moves GL depth comparison function to SamplerDesc.
This was SVN commit r26485.
This commit is contained in:
parent
0d2faa1cab
commit
a87cb6c94d
@ -161,10 +161,6 @@ void CPostprocManager::RecreateBuffers()
|
||||
Renderer::Backend::Sampler::Filter::LINEAR,
|
||||
Renderer::Backend::Sampler::AddressMode::CLAMP_TO_EDGE));
|
||||
|
||||
g_Renderer.GetDeviceCommandContext()->BindTexture(0, GL_TEXTURE_2D, m_DepthTex->GetHandle());
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_NONE);
|
||||
g_Renderer.GetDeviceCommandContext()->BindTexture(0, GL_TEXTURE_2D, 0);
|
||||
|
||||
// Set up the framebuffers with some initial textures.
|
||||
m_CaptureFramebuffer = backendDevice->CreateFramebuffer("PostprocCaptureFramebuffer",
|
||||
m_ColorTex1.get(), m_DepthTex.get(),
|
||||
|
@ -537,8 +537,7 @@ void ShadowMapInternals::CreateTexture()
|
||||
Renderer::Backend::Sampler::AddressMode::CLAMP_TO_EDGE));
|
||||
}
|
||||
|
||||
Texture = backendDevice->CreateTexture2D("ShadowMapDepth",
|
||||
backendFormat, Width, Height,
|
||||
Renderer::Backend::Sampler::Desc samplerDesc =
|
||||
Renderer::Backend::Sampler::MakeDefaultSampler(
|
||||
#if CONFIG2_GLES
|
||||
// GLES doesn't do depth comparisons, so treat it as a
|
||||
@ -548,19 +547,13 @@ void ShadowMapInternals::CreateTexture()
|
||||
// Use GL_LINEAR to trigger automatic PCF on some devices
|
||||
Renderer::Backend::Sampler::Filter::LINEAR,
|
||||
#endif
|
||||
Renderer::Backend::Sampler::AddressMode::CLAMP_TO_EDGE));
|
||||
|
||||
|
||||
#if !CONFIG2_GLES
|
||||
g_Renderer.GetDeviceCommandContext()->BindTexture(0, GL_TEXTURE_2D, Texture->GetHandle());
|
||||
Renderer::Backend::Sampler::AddressMode::CLAMP_TO_EDGE);
|
||||
// Enable automatic depth comparisons
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE, GL_INTENSITY);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
|
||||
g_Renderer.GetDeviceCommandContext()->BindTexture(0, GL_TEXTURE_2D, 0);
|
||||
#endif
|
||||
samplerDesc.compareEnabled = true;
|
||||
samplerDesc.compareOp = Renderer::Backend::CompareOp::LESS_OR_EQUAL;
|
||||
|
||||
ogl_WarnIfError();
|
||||
Texture = backendDevice->CreateTexture2D("ShadowMapDepth",
|
||||
backendFormat, Width, Height, samplerDesc);
|
||||
|
||||
Framebuffer = backendDevice->CreateFramebuffer("ShadowMapFramebuffer",
|
||||
g_RenderingOptions.GetShadowAlphaFix() ? DummyTexture.get() : nullptr, Texture.get());
|
||||
|
47
source/renderer/backend/CompareOp.cpp
Normal file
47
source/renderer/backend/CompareOp.cpp
Normal file
@ -0,0 +1,47 @@
|
||||
/* Copyright (C) 2022 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 0 A.D. is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "precompiled.h"
|
||||
|
||||
#include "CompareOp.h"
|
||||
|
||||
namespace Renderer
|
||||
{
|
||||
|
||||
namespace Backend
|
||||
{
|
||||
|
||||
CompareOp ParseCompareOp(const CStr& str)
|
||||
{
|
||||
// TODO: it might make sense to use upper case in XML for consistency.
|
||||
#define CASE(NAME, VALUE) if (str == NAME) return CompareOp::VALUE
|
||||
CASE("never", NEVER);
|
||||
CASE("less", LESS);
|
||||
CASE("equal", EQUAL);
|
||||
CASE("lequal", LESS_OR_EQUAL);
|
||||
CASE("greater", GREATER);
|
||||
CASE("notequal", NOT_EQUAL);
|
||||
CASE("gequal", GREATER_OR_EQUAL);
|
||||
CASE("always", ALWAYS);
|
||||
#undef CASE
|
||||
debug_warn("Invalid compare op");
|
||||
return CompareOp::NEVER;
|
||||
}
|
||||
|
||||
} // namespace Backend
|
||||
|
||||
} // namespace Renderer
|
57
source/renderer/backend/CompareOp.h
Normal file
57
source/renderer/backend/CompareOp.h
Normal file
@ -0,0 +1,57 @@
|
||||
/* Copyright (C) 2022 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 0 A.D. is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef INCLUDED_RENDERER_BACKEND_COMPAREOP
|
||||
#define INCLUDED_RENDERER_BACKEND_COMPAREOP
|
||||
|
||||
#include "graphics/Color.h"
|
||||
|
||||
class CStr;
|
||||
|
||||
namespace Renderer
|
||||
{
|
||||
|
||||
namespace Backend
|
||||
{
|
||||
|
||||
enum class CompareOp
|
||||
{
|
||||
// Never passes the comparison.
|
||||
NEVER,
|
||||
// Passes if the source value is less than the destination value.
|
||||
LESS,
|
||||
// Passes if the source depth value is equal to the destination value.
|
||||
EQUAL,
|
||||
// Passes if the source depth value is less than or equal to the destination value.
|
||||
LESS_OR_EQUAL,
|
||||
// Passes if the source depth value is greater than the destination value.
|
||||
GREATER,
|
||||
// Passes if the source depth value is not equal to the destination value.
|
||||
NOT_EQUAL,
|
||||
// Passes if the source depth value is greater than or equal to the destination value.
|
||||
GREATER_OR_EQUAL,
|
||||
// Always passes the comparison.
|
||||
ALWAYS
|
||||
};
|
||||
|
||||
CompareOp ParseCompareOp(const CStr& str);
|
||||
|
||||
} // namespace Backend
|
||||
|
||||
} // namespace Renderer
|
||||
|
||||
#endif // INCLUDED_RENDERER_BACKEND_COMPAREOP
|
@ -59,23 +59,6 @@ GraphicsPipelineStateDesc MakeDefaultGraphicsPipelineStateDesc()
|
||||
return desc;
|
||||
}
|
||||
|
||||
CompareOp ParseCompareOp(const CStr& str)
|
||||
{
|
||||
// TODO: it might make sense to use upper case in XML for consistency.
|
||||
#define CASE(NAME, VALUE) if (str == NAME) return CompareOp::VALUE
|
||||
CASE("never", NEVER);
|
||||
CASE("less", LESS);
|
||||
CASE("equal", EQUAL);
|
||||
CASE("lequal", LESS_OR_EQUAL);
|
||||
CASE("greater", GREATER);
|
||||
CASE("notequal", NOT_EQUAL);
|
||||
CASE("gequal", GREATER_OR_EQUAL);
|
||||
CASE("always", ALWAYS);
|
||||
#undef CASE
|
||||
debug_warn("Invalid compare op");
|
||||
return CompareOp::NEVER;
|
||||
}
|
||||
|
||||
StencilOp ParseStencilOp(const CStr& str)
|
||||
{
|
||||
#define CASE(NAME) if (str == #NAME) return StencilOp::NAME
|
||||
|
@ -19,6 +19,7 @@
|
||||
#define INCLUDED_RENDERER_BACKEND_PIPELINESTATE
|
||||
|
||||
#include "graphics/Color.h"
|
||||
#include "renderer/backend/CompareOp.h"
|
||||
|
||||
class CStr;
|
||||
|
||||
@ -28,26 +29,6 @@ namespace Renderer
|
||||
namespace Backend
|
||||
{
|
||||
|
||||
enum class CompareOp
|
||||
{
|
||||
// Never passes the comparison.
|
||||
NEVER,
|
||||
// Passes if the source value is less than the destination value.
|
||||
LESS,
|
||||
// Passes if the source depth value is equal to the destination value.
|
||||
EQUAL,
|
||||
// Passes if the source depth value is less than or equal to the destination value.
|
||||
LESS_OR_EQUAL,
|
||||
// Passes if the source depth value is greater than the destination value.
|
||||
GREATER,
|
||||
// Passes if the source depth value is not equal to the destination value.
|
||||
NOT_EQUAL,
|
||||
// Passes if the source depth value is greater than or equal to the destination value.
|
||||
GREATER_OR_EQUAL,
|
||||
// Always passes the comparison.
|
||||
ALWAYS
|
||||
};
|
||||
|
||||
enum class StencilOp
|
||||
{
|
||||
// Keeps the current value.
|
||||
@ -180,8 +161,6 @@ struct GraphicsPipelineStateDesc
|
||||
// should be described with a related shader and should be switched together.
|
||||
GraphicsPipelineStateDesc MakeDefaultGraphicsPipelineStateDesc();
|
||||
|
||||
CompareOp ParseCompareOp(const CStr& str);
|
||||
|
||||
StencilOp ParseStencilOp(const CStr& str);
|
||||
|
||||
BlendFactor ParseBlendFactor(const CStr& str);
|
||||
|
@ -40,6 +40,7 @@ Desc MakeDefaultSampler(Filter filter, AddressMode addressMode)
|
||||
desc.anisotropyEnabled = false;
|
||||
desc.mipLODBias = 0.0f;
|
||||
desc.borderColor = CColor(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
desc.compareEnabled = false;
|
||||
return desc;
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2021 Wildfire Games.
|
||||
/* Copyright (C) 2022 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -19,6 +19,7 @@
|
||||
#define INCLUDED_RENDERER_BACKEND_SAMPLER
|
||||
|
||||
#include "graphics/Color.h"
|
||||
#include "renderer/backend/CompareOp.h"
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
@ -58,6 +59,8 @@ struct Desc
|
||||
float maxAnisotropy;
|
||||
// When some filter is CLAMP_TO_BORDER.
|
||||
CColor borderColor;
|
||||
bool compareEnabled;
|
||||
CompareOp compareOp;
|
||||
};
|
||||
|
||||
Desc MakeDefaultSampler(Filter filter, AddressMode addressMode);
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include "lib/config2.h"
|
||||
#include "renderer/backend/gl/Device.h"
|
||||
#include "renderer/backend/gl/DeviceCommandContext.h"
|
||||
#include "renderer/backend/gl/Mapping.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
@ -257,6 +258,23 @@ std::unique_ptr<CTexture> CTexture::Create(CDevice* device, const char* name,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#if !CONFIG2_GLES
|
||||
if (format == Format::D16 || format == Format::D24 || format == Format::D32 ||
|
||||
format == Format::D24_S8)
|
||||
{
|
||||
if (defaultSamplerDesc.compareEnabled)
|
||||
{
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE);
|
||||
glTexParameteri(
|
||||
GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC,
|
||||
Mapping::FromCompareOp(defaultSamplerDesc.compareOp));
|
||||
}
|
||||
else
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_NONE);
|
||||
}
|
||||
#endif
|
||||
|
||||
ogl_WarnIfError();
|
||||
|
||||
if (texture->m_Device->GetCapabilities().debugLabels)
|
||||
|
Loading…
Reference in New Issue
Block a user