-
-
Notifications
You must be signed in to change notification settings - Fork 10.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Get better OpenGL version than 2.1 on macOS #3895
Get better OpenGL version than 2.1 on macOS #3895
Conversation
Normally macOS gives us only OpenGL 2.1, but if we request 3.3 and create a new context, we get the best OpenGL version it has to offer. Before: INFO: Renderer: opengl INFO: OpenGL version: 2.1 NVIDIA-14.0.32 355.11.11.10.10.143 WARN: Trilinear filtering disabled (OpenGL 3.0+ or ES 2.0+ required) After: INFO: Renderer: opengl DEBUG: Creating GL Context INFO: OpenGL version: 4.1 NVIDIA-14.0.32 355.11.11.10.10.143 INFO: Trilinear filtering enabled when running with --verbosity=verbose --render-driver=opengl Note: Since SDL_CreateRenderer causes a fallback to OpenGL 2.1, the profile and version attributes have to be set and the context created _after_. This took a while to figure out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your contribution.
Since SDL_CreateRenderer causes a fallback to OpenGL 2.1
Do you know where (in the SDL codebase)?
if we request 3.3 and create a new context, we get the best OpenGL version it has to offer.
What if the latest version available is <3.3? It will fail in that case.
I'm a bit afraid that this change is specific to your machine/drivers, and that it may fail otherwise.
If OpenGL 3 or 4 can be available on macOS, IMO it should even be changed on SDL directly (we can still try to make it work better on scrcpy temporarily).
app/src/screen.c
Outdated
// Persuade macOS to give us something better than OpenGL 2.1 | ||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); | ||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); | ||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if OpenGL 3.3 is not available? Is there a way to know which version is available?
Why SDL does not use the latest version availabe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a macOS OpenGL strangeness that SDL seems to have left up to us to solve.
More explained in #3895 (comment) below.
app/src/screen.c
Outdated
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3); | ||
LOGD("Creating GL Context"); | ||
SDL_GLContext *gl_context; | ||
gl_context = SDL_GL_CreateContext(screen->window); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably needs a matching SDL_GL_DestroyContext()
somewhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. Added SDL_GL_DeleteContext()
.
This way we get the best available OpenGL version on macOS. Explanation at Genymobile#3895
EDIT: Please ignore this - I found a better solution, which I'll push shortly.
Found it mentioned at Also discussed at
Changed to select OpenGL 3.2. According to page 24 of Also, when choosing 3.2, I actually get 4.1, which is the highest that my computer supports under macOS:
Apparently that is how Apple chose to handle it: A more thorough explanation of macOS OpenGL peculiarities:
It seems like it's specific to OpenGL under macOS in general.
The option to use higher OpenGL versions under macOS has been available for a long time, and SDL supports using them, but not automagically. A solution in Lisp, for example, which starts with the highest version and keeps decreasing it until a context is created: |
By only setting the Core Profile for the context, without specifying the OpenGL version, macOS seems to choose the highest available OpenGL version. I've modified the PR accordingly. The reason why SDL doesn't do this automagically:
From https://www.khronos.org/opengl/wiki/OpenGL_Context#OpenGL_3.2_and_Profiles |
Thank you for the details 👍 I had a refactor commit related to screen/display on a local branch that I just pushed to I rebased/reapplied your work above. Please check and review branch |
Looks good and works now. |
You should not have closed it, it's not merged yet, and I cannot reopen since your branch has been deleted :/ I would like other people to test branch |
Oh, sorry. |
I thought that it's fine to delete, since it's in |
Should I do something about the "This branch has conflicts that must be resolved" that's being shown at the end of this thread? |
By default, SDL creates an OpenGL 2.1 context on macOS for an OpenGL renderer. As a consequence, mipmapping is not supported. Force to use a core profile context, to get a higher version. Before: INFO: Renderer: opengl INFO: OpenGL version: 2.1 NVIDIA-14.0.32 355.11.11.10.10.143 WARN: Trilinear filtering disabled (OpenGL 3.0+ or ES 2.0+ required) After: INFO: Renderer: opengl DEBUG: Creating OpenGL Core Profile context INFO: OpenGL version: 4.1 NVIDIA-14.0.32 355.11.11.10.10.143 INFO: Trilinear filtering enabled when running with: scrcpy --verbosity=debug --render-driver=opengl Note: Since SDL_CreateRenderer() causes a fallback to OpenGL 2.1, the profile and version attributes have to be set and the context created _after_. PR #3895 <#3895> Signed-off-by: Romain Vimont <rom@rom1v.com>
Merged 👍 Thank you.
I've got a confirmation that it works as expected. 👍 |
Normally macOS gives us only OpenGL 2.1, but if we request 3.3 and create a new context, we get the best OpenGL version it has to offer.
Before:
INFO: Renderer: opengl
INFO: OpenGL version: 2.1 NVIDIA-14.0.32 355.11.11.10.10.143
WARN: Trilinear filtering disabled (OpenGL 3.0+ or ES 2.0+ required)
After:
INFO: Renderer: opengl
DEBUG: Creating GL Context
INFO: OpenGL version: 4.1 NVIDIA-14.0.32 355.11.11.10.10.143
INFO: Trilinear filtering enabled
when running with
--verbosity=verbose --render-driver=opengl
Note:
Since SDL_CreateRenderer causes a fallback to OpenGL 2.1, the profile and version attributes have to be set and the context created after.
This took a while to figure out.