Add initial support for shader binding sets (WIP)
This commit is contained in:
@@ -19,19 +19,23 @@ namespace Nz
|
||||
m_pipelineInfo(std::move(pipelineInfo)),
|
||||
m_isViewportFlipped(false)
|
||||
{
|
||||
OpenGLRenderPipelineLayout& pipelineLayout = static_cast<OpenGLRenderPipelineLayout&>(*m_pipelineInfo.pipelineLayout);
|
||||
|
||||
if (!m_program.Create(device))
|
||||
throw std::runtime_error("failed to create program");
|
||||
|
||||
const GL::Context* activeContext = GL::Context::GetCurrentContext();
|
||||
assert(activeContext);
|
||||
|
||||
// Enable pipeline states before compiling and linking the program, for drivers which embed some pipeline states into the shader binary (to avoid recompilation later)
|
||||
activeContext->UpdateStates(m_pipelineInfo, false);
|
||||
|
||||
ShaderStageTypeFlags stageFlags;
|
||||
|
||||
for (const auto& shaderModulePtr : m_pipelineInfo.shaderModules)
|
||||
{
|
||||
OpenGLShaderModule& shaderModule = static_cast<OpenGLShaderModule&>(*shaderModulePtr);
|
||||
for (const auto& shaderEntry : shaderModule.GetShaders())
|
||||
{
|
||||
m_program.AttachShader(shaderEntry.shader.GetObjectId());
|
||||
stageFlags |= shaderEntry.stage;
|
||||
}
|
||||
stageFlags |= shaderModule.Attach(m_program, pipelineLayout.GetBindingMapping());
|
||||
}
|
||||
|
||||
// OpenGL ES programs must have both vertex and fragment shaders or a compute shader or a mesh and fragment shader.
|
||||
@@ -42,12 +46,8 @@ namespace Nz
|
||||
if (!stageFlags.Test(stage))
|
||||
{
|
||||
ShaderAst::StatementPtr dummyAst = ShaderBuilder::DeclareFunction(stage, "main", {}, {});
|
||||
OpenGLShaderModule shaderModule(device, stage, dummyAst);
|
||||
for (const auto& shaderEntry : shaderModule.GetShaders())
|
||||
{
|
||||
m_program.AttachShader(shaderEntry.shader.GetObjectId());
|
||||
stageFlags |= shaderEntry.stage;
|
||||
}
|
||||
OpenGLShaderModule shaderModule(device, stage, *dummyAst);
|
||||
stageFlags |= shaderModule.Attach(m_program, pipelineLayout.GetBindingMapping());
|
||||
}
|
||||
};
|
||||
|
||||
@@ -70,7 +70,7 @@ namespace Nz
|
||||
{
|
||||
context.UpdateStates(m_pipelineInfo, flipViewport);
|
||||
context.BindProgram(m_program.GetObjectId()); //< Bind program after states (for shader caching)
|
||||
if (m_isViewportFlipped != flipViewport)
|
||||
if (m_flipYUniformLocation != -1 && m_isViewportFlipped != flipViewport)
|
||||
{
|
||||
m_program.Uniform(m_flipYUniformLocation, (flipViewport) ? -1.f : 1.f);
|
||||
m_isViewportFlipped = flipViewport;
|
||||
|
||||
Reference in New Issue
Block a user