Refactor material system (#382)

This commit is contained in:
Jérôme Leclercq
2022-10-31 19:53:41 +01:00
committed by GitHub
parent 0a8048809c
commit dc6ce8427c
156 changed files with 3633 additions and 4569 deletions

View File

@@ -251,7 +251,7 @@ namespace Nz
{
context->ResetColorWriteMasks();
Color color = command.clearValues[colorAttachmentIndex].color;
const Color& color = command.clearValues[colorAttachmentIndex].color;
context->glClearColor(color.r, color.g, color.b, color.a);
clearFields |= GL_COLOR_BUFFER_BIT;
@@ -286,7 +286,12 @@ namespace Nz
}
if (clearFields)
{
const Vector2ui& size = command.framebuffer->GetSize();
context->SetScissorBox(0, 0, size.x, size.y);
context->SetViewport(0, 0, size.x, size.y);
context->glClear(clearFields);
}
}
if (!invalidateAttachments.empty())

View File

@@ -86,6 +86,12 @@ namespace Nz
if (m_deviceInfo.features.storageBuffers)
{
GLint minStorageOffsetAlignment;
m_referenceContext->glGetIntegerv(GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT, &minStorageOffsetAlignment);
assert(minStorageOffsetAlignment >= 1);
m_deviceInfo.limits.minStorageBufferOffsetAlignment = static_cast<UInt64>(minStorageOffsetAlignment);
GLint maxStorageBlockSize;
m_referenceContext->glGetIntegerv(GL_MAX_SHADER_STORAGE_BLOCK_SIZE, &maxStorageBlockSize);

View File

@@ -17,7 +17,7 @@ namespace Nz
throw std::runtime_error("failed to create framebuffer object");
std::size_t colorAttachmentCount = 0;
bool hasDepth = false;
bool hasDepth = false;
bool hasStencil = false;
for (std::size_t i = 0; i < attachments.size(); ++i)
@@ -25,6 +25,13 @@ namespace Nz
assert(attachments[i]);
const OpenGLTexture& glTexture = static_cast<const OpenGLTexture&>(*attachments[i]);
Vector2ui textureSize = Vector2ui(glTexture.GetSize());
if (i == 0)
m_size = textureSize;
else
m_size.Minimize(textureSize);
PixelFormat textureFormat = glTexture.GetFormat();
GLenum attachment;
@@ -89,4 +96,9 @@ namespace Nz
{
return m_colorAttachmentCount;
}
const Vector2ui& OpenGLFboFramebuffer::GetSize() const
{
return m_size;
}
}

View File

@@ -22,4 +22,9 @@ namespace Nz
{
return 1;
}
const Vector2ui& OpenGLWindowFramebuffer::GetSize() const
{
return m_renderWindow.GetSize();
}
}

View File

@@ -394,9 +394,9 @@ namespace Nz::GL
if ((m_params.type == ContextType::OpenGL && glVersion >= 430) || (m_params.type == ContextType::OpenGL_ES && glVersion >= 320))
m_extensionStatus[UnderlyingCast(Extension::DebugOutput)] = ExtensionStatus::Core;
else if (m_supportedExtensions.count("GL_KHR_debug"))
m_extensionStatus[UnderlyingCast(Extension::DepthClamp)] = ExtensionStatus::KHR;
m_extensionStatus[UnderlyingCast(Extension::DebugOutput)] = ExtensionStatus::KHR;
else if (m_supportedExtensions.count("GL_ARB_debug_output"))
m_extensionStatus[UnderlyingCast(Extension::DepthClamp)] = ExtensionStatus::ARB;
m_extensionStatus[UnderlyingCast(Extension::DebugOutput)] = ExtensionStatus::ARB;
// Depth clamp
if (m_params.type == ContextType::OpenGL && glVersion >= 320)
@@ -558,7 +558,7 @@ namespace Nz::GL
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 counter-clockwise
m_state.renderStates.frontFace = FrontFace::CounterClockwise; //< OpenGL default front face is GL_CCW
EnableVerticalSync(false);
@@ -774,12 +774,10 @@ namespace Nz::GL
}
// Color write
if (m_state.renderStates.colorWrite != renderStates.colorWrite)
if (m_state.renderStates.colorWriteMask != renderStates.colorWriteMask)
{
GLboolean param = (renderStates.colorWrite) ? GL_TRUE : GL_FALSE;
glColorMask(param, param, param, param);
m_state.renderStates.colorWrite = renderStates.colorWrite;
glColorMask(renderStates.colorWriteMask.Test(ColorComponent::Red), renderStates.colorWriteMask.Test(ColorComponent::Green), renderStates.colorWriteMask.Test(ColorComponent::Blue), renderStates.colorWriteMask.Test(ColorComponent::Alpha));
m_state.renderStates.colorWriteMask = renderStates.colorWriteMask;
}
// Depth buffer
@@ -799,9 +797,9 @@ namespace Nz::GL
assert(IsExtensionSupported(Extension::DepthClamp));
if (renderStates.depthClamp)
glEnable(GL_DEPTH_CLAMP_EXT);
glEnable(GL_DEPTH_CLAMP);
else
glDisable(GL_DEPTH_CLAMP_EXT);
glDisable(GL_DEPTH_CLAMP);
m_state.renderStates.depthClamp = renderStates.depthClamp;
}