WIP
This commit is contained in:
committed by
Jérôme Leclercq
parent
4a10c1f8fe
commit
e990a320cc
@@ -21,10 +21,14 @@ namespace Nz
|
||||
unsigned int bindingIndex = 0;
|
||||
for (const auto& binding : m_layoutInfo.bindings)
|
||||
{
|
||||
UInt64 bindingKey = UInt64(binding.setIndex) << 32 | UInt64(binding.bindingIndex);
|
||||
for (UInt32 i = 0; i < binding.arraySize; ++i)
|
||||
{
|
||||
UInt64 bindingKey = UInt64(binding.setIndex) << 32 | UInt64(binding.bindingIndex + i);
|
||||
|
||||
m_bindingMapping[bindingKey] = bindingIndex++;
|
||||
m_maxDescriptorCount = std::max<std::size_t>(m_maxDescriptorCount, binding.bindingIndex + 1);
|
||||
m_bindingMapping[bindingKey] = bindingIndex++;
|
||||
}
|
||||
|
||||
m_maxDescriptorCount = std::max<std::size_t>(m_maxDescriptorCount, binding.bindingIndex + binding.arraySize);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,18 @@ namespace Nz
|
||||
{
|
||||
using DescriptorType = std::decay_t<decltype(descriptor)>;
|
||||
|
||||
auto bindingIt = std::find_if(layoutInfo.bindings.begin(), layoutInfo.bindings.end(), [&](const auto& binding) { return binding.setIndex == setIndex && binding.bindingIndex == bindingIndex; });
|
||||
auto bindingIt = std::find_if(layoutInfo.bindings.begin(), layoutInfo.bindings.end(), [&](const auto& binding)
|
||||
{
|
||||
if (binding.setIndex != setIndex)
|
||||
return false;
|
||||
|
||||
assert(binding.arraySize > 0);
|
||||
if (bindingIndex < binding.bindingIndex || bindingIndex >= binding.bindingIndex + binding.arraySize)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
if (bindingIt == layoutInfo.bindings.end())
|
||||
throw std::runtime_error("invalid binding index");
|
||||
|
||||
@@ -88,26 +99,11 @@ namespace Nz
|
||||
storageDescriptor.buffer = 0;
|
||||
}
|
||||
else if constexpr (std::is_same_v<T, TextureBinding>)
|
||||
HandleTextureBinding(binding.bindingIndex, arg);
|
||||
else if constexpr (std::is_same_v<T, TextureBindings>)
|
||||
{
|
||||
auto& textureDescriptor = m_owner.GetTextureDescriptor(m_poolIndex, m_bindingIndex, binding.bindingIndex);
|
||||
|
||||
if (const OpenGLTexture* glTexture = static_cast<const OpenGLTexture*>(arg.texture))
|
||||
{
|
||||
textureDescriptor.texture = glTexture->GetTexture().GetObjectId();
|
||||
|
||||
if (const OpenGLTextureSampler* glSampler = static_cast<const OpenGLTextureSampler*>(arg.sampler))
|
||||
textureDescriptor.sampler = glSampler->GetSampler(glTexture->GetLevelCount() > 1).GetObjectId();
|
||||
else
|
||||
textureDescriptor.sampler = 0;
|
||||
|
||||
textureDescriptor.textureTarget = OpenGLTexture::ToTextureTarget(glTexture->GetType());
|
||||
}
|
||||
else
|
||||
{
|
||||
textureDescriptor.sampler = 0;
|
||||
textureDescriptor.texture = 0;
|
||||
textureDescriptor.textureTarget = GL::TextureTarget::Target2D;
|
||||
}
|
||||
for (UInt32 i = 0; i < arg.arraySize; ++i)
|
||||
HandleTextureBinding(binding.bindingIndex + i, arg.textureBindings[i]);
|
||||
}
|
||||
else if constexpr (std::is_same_v<T, UniformBufferBinding>)
|
||||
{
|
||||
@@ -137,6 +133,29 @@ namespace Nz
|
||||
// No OpenGL object to name
|
||||
}
|
||||
|
||||
void OpenGLShaderBinding::HandleTextureBinding(UInt32 bindingIndex, const TextureBinding& textureBinding)
|
||||
{
|
||||
auto& textureDescriptor = m_owner.GetTextureDescriptor(m_poolIndex, m_bindingIndex, bindingIndex);
|
||||
|
||||
if (const OpenGLTexture* glTexture = static_cast<const OpenGLTexture*>(textureBinding.texture))
|
||||
{
|
||||
textureDescriptor.texture = glTexture->GetTexture().GetObjectId();
|
||||
|
||||
if (const OpenGLTextureSampler* glSampler = static_cast<const OpenGLTextureSampler*>(textureBinding.sampler))
|
||||
textureDescriptor.sampler = glSampler->GetSampler(glTexture->GetLevelCount() > 1).GetObjectId();
|
||||
else
|
||||
textureDescriptor.sampler = 0;
|
||||
|
||||
textureDescriptor.textureTarget = OpenGLTexture::ToTextureTarget(glTexture->GetType());
|
||||
}
|
||||
else
|
||||
{
|
||||
textureDescriptor.sampler = 0;
|
||||
textureDescriptor.texture = 0;
|
||||
textureDescriptor.textureTarget = GL::TextureTarget::Target2D;
|
||||
}
|
||||
}
|
||||
|
||||
void OpenGLShaderBinding::Release()
|
||||
{
|
||||
m_owner.Release(*this);
|
||||
|
||||
@@ -36,6 +36,12 @@ namespace Nz
|
||||
|
||||
if (samplerInfo.anisotropyLevel > 1.f)
|
||||
sampler.SetParameterf(GL_TEXTURE_MAX_ANISOTROPY_EXT, samplerInfo.anisotropyLevel);
|
||||
|
||||
if (samplerInfo.depthCompare)
|
||||
{
|
||||
sampler.SetParameteri(GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
|
||||
sampler.SetParameteri(GL_TEXTURE_COMPARE_FUNC, ToOpenGL(samplerInfo.depthComparison));
|
||||
}
|
||||
}
|
||||
|
||||
void OpenGLTextureSampler::UpdateDebugName(std::string_view name)
|
||||
|
||||
@@ -565,8 +565,13 @@ namespace Nz::GL
|
||||
glGetIntegerv(GL_VIEWPORT, res.data());
|
||||
m_state.viewport = { res[0], res[1], res[2], res[3] };
|
||||
|
||||
m_state.renderStates.depthCompare = RendererComparison::Less; //< OpenGL default depth mode is GL_LESS
|
||||
m_state.renderStates.frontFace = FrontFace::CounterClockwise; //< OpenGL default front face is GL_CCW
|
||||
// Set default OpenGL states
|
||||
m_state.renderStates.depthBuffer = false;
|
||||
m_state.renderStates.depthCompare = RendererComparison::Less;
|
||||
m_state.renderStates.faceCulling = FaceCulling::None;
|
||||
m_state.renderStates.frontFace = FrontFace::CounterClockwise;
|
||||
m_state.renderStates.scissorTest = false;
|
||||
m_state.renderStates.stencilTest = false;
|
||||
|
||||
EnableVerticalSync(false);
|
||||
|
||||
@@ -671,6 +676,18 @@ namespace Nz::GL
|
||||
if (!SetCurrentContext(this))
|
||||
throw std::runtime_error("failed to activate context");
|
||||
|
||||
// Depth bias
|
||||
if (renderStates.depthBias)
|
||||
{
|
||||
if (!NumberEquals(m_state.renderStates.depthBiasConstantFactor, renderStates.depthBiasConstantFactor) ||
|
||||
!NumberEquals(m_state.renderStates.depthBiasSlopeFactor, renderStates.depthBiasSlopeFactor))
|
||||
{
|
||||
glPolygonOffset(renderStates.depthBiasConstantFactor, renderStates.depthBiasSlopeFactor);
|
||||
m_state.renderStates.depthBiasConstantFactor = renderStates.depthBiasConstantFactor;
|
||||
m_state.renderStates.depthBiasSlopeFactor = renderStates.depthBiasSlopeFactor;
|
||||
}
|
||||
}
|
||||
|
||||
// Depth compare and depth write
|
||||
if (renderStates.depthBuffer)
|
||||
{
|
||||
@@ -687,14 +704,23 @@ namespace Nz::GL
|
||||
}
|
||||
}
|
||||
|
||||
// Face culling side
|
||||
if (renderStates.faceCulling)
|
||||
// Face culling
|
||||
if (m_state.renderStates.faceCulling != renderStates.faceCulling)
|
||||
{
|
||||
if (m_state.renderStates.cullingSide != renderStates.cullingSide)
|
||||
bool wasEnabled = (m_state.renderStates.faceCulling != FaceCulling::None);
|
||||
bool isEnabled = (renderStates.faceCulling != FaceCulling::None);
|
||||
|
||||
if (isEnabled)
|
||||
{
|
||||
glCullFace(ToOpenGL(renderStates.cullingSide));
|
||||
m_state.renderStates.cullingSide = renderStates.cullingSide;
|
||||
if (!wasEnabled)
|
||||
glEnable(GL_CULL_FACE);
|
||||
|
||||
glCullFace(ToOpenGL(renderStates.faceCulling));
|
||||
}
|
||||
else if (wasEnabled)
|
||||
glDisable(GL_CULL_FACE);
|
||||
|
||||
m_state.renderStates.faceCulling = renderStates.faceCulling;
|
||||
}
|
||||
|
||||
// Front face
|
||||
@@ -811,6 +837,18 @@ namespace Nz::GL
|
||||
m_state.renderStates.colorWriteMask = renderStates.colorWriteMask;
|
||||
}
|
||||
|
||||
// Depth bias
|
||||
if (m_state.renderStates.depthBias != renderStates.depthBias)
|
||||
{
|
||||
// TODO: Handle line and points
|
||||
if (renderStates.depthBias)
|
||||
glEnable(GL_POLYGON_OFFSET_FILL);
|
||||
else
|
||||
glDisable(GL_POLYGON_OFFSET_FILL);
|
||||
|
||||
m_state.renderStates.depthBias = renderStates.depthBias;
|
||||
}
|
||||
|
||||
// Depth buffer
|
||||
if (m_state.renderStates.depthBuffer != renderStates.depthBuffer)
|
||||
{
|
||||
@@ -835,17 +873,6 @@ namespace Nz::GL
|
||||
m_state.renderStates.depthClamp = renderStates.depthClamp;
|
||||
}
|
||||
|
||||
// Face culling
|
||||
if (m_state.renderStates.faceCulling != renderStates.faceCulling)
|
||||
{
|
||||
if (renderStates.faceCulling)
|
||||
glEnable(GL_CULL_FACE);
|
||||
else
|
||||
glDisable(GL_CULL_FACE);
|
||||
|
||||
m_state.renderStates.faceCulling = renderStates.faceCulling;
|
||||
}
|
||||
|
||||
// Scissor test
|
||||
if (m_state.renderStates.scissorTest != renderStates.scissorTest)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user