Fix OpenGL version check

This commit is contained in:
Jérôme Leclercq 2021-10-24 15:25:17 +02:00
parent 6162a805e4
commit cb716e5da5
2 changed files with 18 additions and 18 deletions

View File

@ -350,6 +350,8 @@ namespace Nz::GL
m_params.glMajorVersion = majorVersion; m_params.glMajorVersion = majorVersion;
m_params.glMinorVersion = minorVersion; m_params.glMinorVersion = minorVersion;
unsigned int glVersion = majorVersion * 100 + minorVersion * 10;
// Load extensions // Load extensions
GLint extensionCount = 0; GLint extensionCount = 0;
glGetIntegerv(GL_NUM_EXTENSIONS, &extensionCount); glGetIntegerv(GL_NUM_EXTENSIONS, &extensionCount);
@ -360,7 +362,7 @@ namespace Nz::GL
m_extensionStatus.fill(ExtensionStatus::NotSupported); m_extensionStatus.fill(ExtensionStatus::NotSupported);
// Depth clamp // Depth clamp
if (m_params.type == ContextType::OpenGL && m_params.glMajorVersion >= 3 && m_params.glMajorVersion >= 2) if (m_params.type == ContextType::OpenGL && glVersion >= 320)
m_extensionStatus[UnderlyingCast(Extension::DepthClamp)] = ExtensionStatus::Core; m_extensionStatus[UnderlyingCast(Extension::DepthClamp)] = ExtensionStatus::Core;
else if (m_supportedExtensions.count("GL_ARB_depth_clamp")) else if (m_supportedExtensions.count("GL_ARB_depth_clamp"))
m_extensionStatus[UnderlyingCast(Extension::DepthClamp)] = ExtensionStatus::ARB; m_extensionStatus[UnderlyingCast(Extension::DepthClamp)] = ExtensionStatus::ARB;
@ -370,7 +372,7 @@ namespace Nz::GL
m_extensionStatus[UnderlyingCast(Extension::DepthClamp)] = ExtensionStatus::Vendor; m_extensionStatus[UnderlyingCast(Extension::DepthClamp)] = ExtensionStatus::Vendor;
// SpirV // SpirV
if (m_params.type == ContextType::OpenGL && m_params.glMajorVersion >= 4 && m_params.glMajorVersion >= 6) if (m_params.type == ContextType::OpenGL && glVersion >= 460)
m_extensionStatus[UnderlyingCast(Extension::SpirV)] = ExtensionStatus::Core; m_extensionStatus[UnderlyingCast(Extension::SpirV)] = ExtensionStatus::Core;
else if (m_supportedExtensions.count("GL_ARB_gl_spirv")) else if (m_supportedExtensions.count("GL_ARB_gl_spirv"))
m_extensionStatus[UnderlyingCast(Extension::SpirV)] = ExtensionStatus::ARB; m_extensionStatus[UnderlyingCast(Extension::SpirV)] = ExtensionStatus::ARB;
@ -380,7 +382,7 @@ namespace Nz::GL
m_extensionStatus[UnderlyingCast(Extension::TextureCompressionS3tc)] = ExtensionStatus::EXT; m_extensionStatus[UnderlyingCast(Extension::TextureCompressionS3tc)] = ExtensionStatus::EXT;
// Texture anisotropic filter // Texture anisotropic filter
if (m_params.type == ContextType::OpenGL && m_params.glMajorVersion >= 4 && m_params.glMajorVersion >= 6) if (m_params.type == ContextType::OpenGL && glVersion >= 460)
m_extensionStatus[UnderlyingCast(Extension::TextureFilterAnisotropic)] = ExtensionStatus::Core; m_extensionStatus[UnderlyingCast(Extension::TextureFilterAnisotropic)] = ExtensionStatus::Core;
else if (m_supportedExtensions.count("GL_ARB_texture_filter_anisotropic")) else if (m_supportedExtensions.count("GL_ARB_texture_filter_anisotropic"))
m_extensionStatus[UnderlyingCast(Extension::TextureFilterAnisotropic)] = ExtensionStatus::ARB; m_extensionStatus[UnderlyingCast(Extension::TextureFilterAnisotropic)] = ExtensionStatus::ARB;
@ -393,7 +395,7 @@ namespace Nz::GL
#undef NAZARA_OPENGLRENDERER_EXT_FUNC #undef NAZARA_OPENGLRENDERER_EXT_FUNC
#undef NAZARA_OPENGLRENDERER_FUNC #undef NAZARA_OPENGLRENDERER_FUNC
// If we requested an OpenGL ES context but cannot create one, check for some compatibility extensions // If we requested an OpenGL ES context but couldn't create one, check for some compatibility extensions
if (params.type == ContextType::OpenGL_ES && m_params.type != params.type) if (params.type == ContextType::OpenGL_ES && m_params.type != params.type)
{ {
if (m_supportedExtensions.count("GL_ARB_ES3_2_compatibility")) if (m_supportedExtensions.count("GL_ARB_ES3_2_compatibility"))

View File

@ -420,14 +420,11 @@ namespace Nz
void GlslWriter::AppendHeader() void GlslWriter::AppendHeader()
{ {
unsigned int glslVersion; unsigned int glslVersion;
unsigned int glVersion = m_environment.glMajorVersion * 100 + m_environment.glMinorVersion * 10;
if (m_environment.glES) if (m_environment.glES)
{ {
if (m_environment.glMajorVersion >= 3 && m_environment.glMinorVersion >= 2) if (glVersion >= 300)
glslVersion = 320; glslVersion = glVersion;
else if (m_environment.glMajorVersion >= 3 && m_environment.glMinorVersion >= 1)
glslVersion = 310;
else if (m_environment.glMajorVersion >= 3)
glslVersion = 300;
else if (m_environment.glMajorVersion >= 2) else if (m_environment.glMajorVersion >= 2)
glslVersion = 100; glslVersion = 100;
else else
@ -435,17 +432,17 @@ namespace Nz
} }
else else
{ {
if (m_environment.glMajorVersion >= 3 && m_environment.glMinorVersion >= 3) if (glVersion >= 330)
glslVersion = m_environment.glMajorVersion * 100 + m_environment.glMinorVersion * 10; glslVersion = glVersion;
else if (m_environment.glMajorVersion >= 3 && m_environment.glMinorVersion >= 2) else if (glVersion >= 320)
glslVersion = 150; glslVersion = 150;
else if (m_environment.glMajorVersion >= 3 && m_environment.glMinorVersion >= 1) else if (glVersion >= 310)
glslVersion = 140; glslVersion = 140;
else if (m_environment.glMajorVersion >= 3) else if (glVersion >= 300)
glslVersion = 130; glslVersion = 130;
else if (m_environment.glMajorVersion >= 2 && m_environment.glMinorVersion >= 1) else if (glVersion >= 210)
glslVersion = 120; glslVersion = 120;
else if (m_environment.glMajorVersion >= 2) else if (glVersion >= 200)
glslVersion = 110; glslVersion = 110;
else else
throw std::runtime_error("This version of OpenGL does not support shaders"); throw std::runtime_error("This version of OpenGL does not support shaders");
@ -553,7 +550,8 @@ namespace Nz
{ {
if (node.entryStage.GetResultingValue() == ShaderStageType::Fragment && node.earlyFragmentTests.HasValue() && node.earlyFragmentTests.GetResultingValue()) if (node.entryStage.GetResultingValue() == ShaderStageType::Fragment && node.earlyFragmentTests.HasValue() && node.earlyFragmentTests.GetResultingValue())
{ {
if ((m_environment.glES && m_environment.glMajorVersion >= 3 && m_environment.glMinorVersion >= 1) || (!m_environment.glES && m_environment.glMajorVersion >= 4 && m_environment.glMinorVersion >= 2) || (m_environment.extCallback && m_environment.extCallback("GL_ARB_shader_image_load_store"))) unsigned int glVersion = m_environment.glMajorVersion * 100 + m_environment.glMinorVersion * 10;
if ((m_environment.glES && glVersion >= 310) || (!m_environment.glES && glVersion >= 420) || (m_environment.extCallback && m_environment.extCallback("GL_ARB_shader_image_load_store")))
{ {
AppendLine("layout(early_fragment_tests) in;"); AppendLine("layout(early_fragment_tests) in;");
AppendLine(); AppendLine();