Commit current work
Reworked conditions, added uber-shaders, comparison nodes, fixed Discard
This commit is contained in:
@@ -93,6 +93,7 @@ namespace Nz
|
||||
command.framebuffer->Activate();
|
||||
|
||||
context = GL::Context::GetCurrentContext();
|
||||
context->glClearColor(0.5, 0.5, 0.5, 1.0);
|
||||
context->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
}
|
||||
else
|
||||
|
||||
@@ -68,6 +68,11 @@ namespace Nz
|
||||
return std::make_shared<OpenGLRenderPipelineLayout>(std::move(pipelineLayoutInfo));
|
||||
}
|
||||
|
||||
std::shared_ptr<ShaderStage> OpenGLDevice::InstantiateShaderStage(const ShaderAst& shaderAst, const ShaderWriter::States& states)
|
||||
{
|
||||
return std::make_shared<OpenGLShaderStage>(*this, shaderAst, states);
|
||||
}
|
||||
|
||||
std::shared_ptr<ShaderStage> OpenGLDevice::InstantiateShaderStage(ShaderStageType type, ShaderLanguage lang, const void* source, std::size_t sourceSize)
|
||||
{
|
||||
return std::make_shared<OpenGLShaderStage>(*this, type, lang, source, sourceSize);
|
||||
|
||||
@@ -20,6 +20,8 @@ namespace Nz
|
||||
const auto& textureDescriptor = m_owner.GetTextureDescriptor(m_poolIndex, m_bindingIndex, i);
|
||||
|
||||
UInt32 textureIndex = textureDescriptor.bindingIndex;
|
||||
if (textureIndex == OpenGLRenderPipelineLayout::InvalidIndex)
|
||||
continue;
|
||||
|
||||
context.BindSampler(textureIndex, textureDescriptor.sampler);
|
||||
context.BindTexture(textureIndex, textureDescriptor.textureTarget, textureDescriptor.texture);
|
||||
@@ -29,6 +31,10 @@ namespace Nz
|
||||
{
|
||||
const auto& uboDescriptor = m_owner.GetUniformBufferDescriptor(m_poolIndex, m_bindingIndex, i);
|
||||
|
||||
UInt32 uboIndex = uboDescriptor.bindingIndex;
|
||||
if (uboIndex == OpenGLRenderPipelineLayout::InvalidIndex)
|
||||
continue;
|
||||
|
||||
context.BindUniformBuffer(uboDescriptor.bindingIndex, uboDescriptor.buffer, uboDescriptor.offset, uboDescriptor.size);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,15 @@
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
OpenGLShaderStage::OpenGLShaderStage(OpenGLDevice& device, const ShaderAst& shaderAst, const ShaderWriter::States& states)
|
||||
{
|
||||
if (!m_shader.Create(device, ToOpenGL(shaderAst.GetStage())))
|
||||
throw std::runtime_error("failed to create shader"); //< TODO: Handle error message
|
||||
|
||||
Create(device, shaderAst, states);
|
||||
CheckCompilationStatus();
|
||||
}
|
||||
|
||||
OpenGLShaderStage::OpenGLShaderStage(OpenGLDevice& device, ShaderStageType type, ShaderLanguage lang, const void* source, std::size_t sourceSize)
|
||||
{
|
||||
if (!m_shader.Create(device, ToOpenGL(type)))
|
||||
@@ -28,32 +37,11 @@ namespace Nz
|
||||
|
||||
case ShaderLanguage::NazaraBinary:
|
||||
{
|
||||
ByteStream byteStream(source, sourceSize);
|
||||
auto shader = Nz::UnserializeShader(byteStream);
|
||||
|
||||
auto shader = UnserializeShader(source, sourceSize);
|
||||
if (shader.GetStage() != type)
|
||||
throw std::runtime_error("incompatible shader stage");
|
||||
|
||||
const auto& context = device.GetReferenceContext();
|
||||
const auto& contextParams = context.GetParams();
|
||||
|
||||
GlslWriter::Environment env;
|
||||
env.glES = (contextParams.type == GL::ContextType::OpenGL_ES);
|
||||
env.glMajorVersion = contextParams.glMajorVersion;
|
||||
env.glMinorVersion = contextParams.glMinorVersion;
|
||||
env.extCallback = [&](const std::string_view& ext)
|
||||
{
|
||||
return context.IsExtensionSupported(std::string(ext));
|
||||
};
|
||||
env.flipYPosition = true;
|
||||
|
||||
GlslWriter writer;
|
||||
writer.SetEnv(env);
|
||||
|
||||
std::string code = writer.Generate(shader);
|
||||
|
||||
m_shader.SetSource(code.data(), code.size());
|
||||
m_shader.Compile();
|
||||
Create(device, shader, {});
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -71,8 +59,39 @@ namespace Nz
|
||||
throw std::runtime_error("Unsupported shader language");
|
||||
}
|
||||
|
||||
CheckCompilationStatus();
|
||||
}
|
||||
|
||||
void OpenGLShaderStage::CheckCompilationStatus()
|
||||
{
|
||||
std::string errorLog;
|
||||
if (!m_shader.GetCompilationStatus(&errorLog))
|
||||
throw std::runtime_error("Failed to compile shader: " + errorLog);
|
||||
}
|
||||
|
||||
void OpenGLShaderStage::Create(OpenGLDevice& device, const ShaderAst& shaderAst, const ShaderWriter::States& states)
|
||||
{
|
||||
const auto& context = device.GetReferenceContext();
|
||||
const auto& contextParams = context.GetParams();
|
||||
|
||||
GlslWriter::Environment env;
|
||||
env.glES = (contextParams.type == GL::ContextType::OpenGL_ES);
|
||||
env.glMajorVersion = contextParams.glMajorVersion;
|
||||
env.glMinorVersion = contextParams.glMinorVersion;
|
||||
env.extCallback = [&](const std::string_view& ext)
|
||||
{
|
||||
return context.IsExtensionSupported(std::string(ext));
|
||||
};
|
||||
env.flipYPosition = true;
|
||||
|
||||
GlslWriter writer;
|
||||
writer.SetEnv(env);
|
||||
|
||||
std::string code = writer.Generate(shaderAst, states);
|
||||
|
||||
NazaraError(code);
|
||||
|
||||
m_shader.SetSource(code.data(), code.size());
|
||||
m_shader.Compile();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -174,7 +174,7 @@ namespace Nz::GL
|
||||
WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB
|
||||
};
|
||||
|
||||
m_handle = baseContext->wglCreateContextAttribsARB(m_deviceContext, nullptr, attributes.data());
|
||||
m_handle = baseContext->wglCreateContextAttribsARB(m_deviceContext, (shareContext) ? shareContext->m_handle : nullptr, attributes.data());
|
||||
if (m_handle)
|
||||
{
|
||||
m_params.type = ContextType::OpenGL;
|
||||
@@ -198,16 +198,16 @@ namespace Nz::GL
|
||||
return false;
|
||||
}
|
||||
|
||||
m_params.type = ContextType::OpenGL;
|
||||
}
|
||||
|
||||
if (shareContext)
|
||||
{
|
||||
if (!m_loader.wglShareLists(shareContext->m_handle, m_handle))
|
||||
if (shareContext)
|
||||
{
|
||||
NazaraError("failed to share context objects: " + Error::GetLastSystemError());
|
||||
return false;
|
||||
if (!m_loader.wglShareLists(shareContext->m_handle, m_handle))
|
||||
{
|
||||
NazaraError("failed to share context objects: " + Error::GetLastSystemError());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
m_params.type = ContextType::OpenGL;
|
||||
}
|
||||
|
||||
LoadWGLExt();
|
||||
|
||||
Reference in New Issue
Block a user