Backends: Opengl3: Support GLSL 410 shader when GLSL version is auto-detected.#9427
Backends: Opengl3: Support GLSL 410 shader when GLSL version is auto-detected.#9427perminovVS wants to merge 1 commit into
Conversation
…detected. Add the GLSL 410 shader and ensure it is selected when the GLSL version is auto-detected (i.e. when glsl_version is nullptr). Previously the GLSL 410 shader was only used if a GLSL version string was passed manually to ImGui_ImplOpenGL3_Init. Now the backend detects the GL/GLSL version at runtime and will pick the GLSL 410 shader when the context supports it. ocornut@fc737d2
|
Thank you very much Vladimir. Can you suggest how to amend your examples/xxxx_opengl3/main.cpp file? As current code is the example does: #elif defined(__APPLE__)
// GL 3.2 + GLSL 150
const char* glsl_version = "#version 150";
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // 3.2+ only
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // Required on Mac
#else
// GL 3.0 + GLSL 130
const char* glsl_version = "#version 130";
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
//glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // 3.2+ only
//glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // 3.0+ only
#endifTherefore your code path won't run. Can you report the detected GlVersion
Thank you. |
Thank you — glad to see the change merged (7950c96). A bit of context about my environment and how I initialize GL in production:
What I do in production (relevant snippet) // For cocos2d-x: GLViewImpl::initWithRect used to create the highest available GL context on macOS/Wine
if (IsRunWine())
{
// Minimum target is OpenGL 4.1
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
Configuration::getInstance()->setCoreProfile(true);
}
_mainWindow = glfwCreateWindow(neededWidth, neededHeight, _viewName.c_str(), _monitor, nullptr);
if (_mainWindow == nullptr && IsRunWine())
{
Configuration::getInstance()->setCoreProfile(false);
// Create default fallback
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 1);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_ANY_PROFILE);
_mainWindow = glfwCreateWindow(neededWidth, neededHeight, _viewName.c_str(), _monitor, nullptr);
}Why this: on macOS (Intel or Apple Silicon) the system GL implementation exposes up to GL 4.1. When running under Wine I try to request the highest desktop profile available (4.1 core) so the runtime and drivers give me the best feature set possible. If that fails I fall back to a very conservative context for auto select max in driver. As far as I recall, I experienced initialization issues on Apple Silicon, so I explicitly request an OpenGL 4.1 core context; if that fails, I fall back to the default (more conservative) context. |
|
I tested my app by requesting a GL 3.0 context (the branch shown in the example). The problem remained and several of my 3D shaders would not compile under that context, which indicates the runtime/driver on macOS (under Wine on macOS) does not provide the features I need when only GL 3.0 is requested. For that reason GLViewImpl::initWithRect first requests an OpenGL 4.1 core context (the maximum desktop GL Apple exposes); the driver/runtime ultimately decides the exact version returned. If creating a 4.1 context fails, the code falls back to a conservative default context. |
|
If your app explicitly try to request varying GL context version, then surely you can select a GLSL version manually too? So to clarify, this fix doesn't strictly fix #6577 because the example have explicit GL version. |






Add the GLSL 410 shader and ensure it is selected when the GLSL version is auto-detected (i.e. when glsl_version is nullptr). Previously the GLSL 410 shader was only used if a GLSL version string was passed manually to ImGui_ImplOpenGL3_Init. Now the backend detects the GL/GLSL version at runtime and will pick the GLSL 410 shader when the context supports it.
fc737d2