Force OpenGL Core Profile context on macOS
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 <https://github.com/Genymobile/scrcpy/pull/3895> Signed-off-by: Romain Vimont <rom@rom1v.com>
This commit is contained in:
parent
9eb6591913
commit
c083a7cc90
2 changed files with 27 additions and 0 deletions
|
@ -23,6 +23,22 @@ sc_display_init(struct sc_display *display, SDL_Window *window, bool mipmaps) {
|
||||||
// starts with "opengl"
|
// starts with "opengl"
|
||||||
bool use_opengl = renderer_name && !strncmp(renderer_name, "opengl", 6);
|
bool use_opengl = renderer_name && !strncmp(renderer_name, "opengl", 6);
|
||||||
if (use_opengl) {
|
if (use_opengl) {
|
||||||
|
|
||||||
|
#ifdef SC_DISPLAY_FORCE_OPENGL_CORE_PROFILE
|
||||||
|
// Persuade macOS to give us something better than OpenGL 2.1.
|
||||||
|
// If we create a Core Profile context, we get the best OpenGL version.
|
||||||
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK,
|
||||||
|
SDL_GL_CONTEXT_PROFILE_CORE);
|
||||||
|
|
||||||
|
LOGD("Creating OpenGL Core Profile context");
|
||||||
|
display->gl_context = SDL_GL_CreateContext(window);
|
||||||
|
if (!display->gl_context) {
|
||||||
|
LOGE("Could not create OpenGL context: %s", SDL_GetError());
|
||||||
|
SDL_DestroyRenderer(display->renderer);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
struct sc_opengl *gl = &display->gl;
|
struct sc_opengl *gl = &display->gl;
|
||||||
sc_opengl_init(gl);
|
sc_opengl_init(gl);
|
||||||
|
|
||||||
|
@ -51,6 +67,9 @@ sc_display_init(struct sc_display *display, SDL_Window *window, bool mipmaps) {
|
||||||
|
|
||||||
void
|
void
|
||||||
sc_display_destroy(struct sc_display *display) {
|
sc_display_destroy(struct sc_display *display) {
|
||||||
|
#ifdef SC_DISPLAY_FORCE_OPENGL_CORE_PROFILE
|
||||||
|
SDL_GL_DeleteContext(display->gl_context);
|
||||||
|
#endif
|
||||||
if (display->texture) {
|
if (display->texture) {
|
||||||
SDL_DestroyTexture(display->texture);
|
SDL_DestroyTexture(display->texture);
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,11 +10,19 @@
|
||||||
#include "coords.h"
|
#include "coords.h"
|
||||||
#include "opengl.h"
|
#include "opengl.h"
|
||||||
|
|
||||||
|
#ifdef __APPLE__
|
||||||
|
# define SC_DISPLAY_FORCE_OPENGL_CORE_PROFILE
|
||||||
|
#endif
|
||||||
|
|
||||||
struct sc_display {
|
struct sc_display {
|
||||||
SDL_Renderer *renderer;
|
SDL_Renderer *renderer;
|
||||||
SDL_Texture *texture;
|
SDL_Texture *texture;
|
||||||
|
|
||||||
struct sc_opengl gl;
|
struct sc_opengl gl;
|
||||||
|
#ifdef SC_DISPLAY_FORCE_OPENGL_CORE_PROFILE
|
||||||
|
SDL_GLContext *gl_context;
|
||||||
|
#endif
|
||||||
|
|
||||||
bool mipmaps;
|
bool mipmaps;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue