Repository: libsdl-org/SDL
File: src/video/uikit/SDL_uikitopengles.m (Objective-C)

Code before:

        if (_this->gl_config.share_with_current_context) {
            EAGLContext *currContext = (__bridge EAGLContext *)SDL_GL_GetCurrentContext();
            sharegroup = currContext.sharegroup;
        }

        if (window->flags & SDL_WINDOW_HIGH_PIXEL_DENSITY) {
            /* Set the scale to the natural scale factor of the screen - the
             * backing dimensions of the OpenGL view will match the pixel
             * dimensions of the screen rather than the dimensions in points. */
            scale = data.uiwindow.screen.nativeScale;
        }

        context = [[SDLEAGLContext alloc] initWithAPI:api sharegroup:sharegroup];
        if (!context) {
            SDL_SetError("OpenGL ES %d context could not be created", _this->gl_config.major_version);
            return NULL;
        }

        int srgb = _this->gl_config.framebuffer_srgb_capable;
        const char *srgbhint = SDL_GetHint(SDL_HINT_OPENGL_FORCE_SRGB_CAPABLE);
        if (srgbhint) {
            srgb = SDL_GetStringBoolean(srgbhint, false) ? 1 : 0;  // there is no "avoid" here, since initWithFrame expects it, so we'll treat it as false.
        }

         // construct our view, passing in SDL's OpenGL configuration data
        view = [[SDL_uikitopenglview alloc] initWithFrame:frame
                                                    scale:scale
                                            retainBacking:_this->gl_config.retained_backing
                                                    rBits:_this->gl_config.red_size
                                                    gBits:_this->gl_config.green_size
                                                    bBits:_this->gl_config.blue_size
                                                    aBits:_this->gl_config.alpha_size
                                                depthBits:_this->gl_config.depth_size
                                              stencilBits:_this->gl_config.stencil_size
                                                     sRGB:srgb
                                             multisamples:samples
                                                  context:context];

        if (!view) {
            return NULL;
        }

        SDL_PropertiesID props = SDL_GetWindowProperties(window);
        SDL_SetNumberProperty(props, SDL_PROP_WINDOW_UIKIT_OPENGL_FRAMEBUFFER_NUMBER, view.drawableFramebuffer);
        SDL_SetNumberProperty(props, SDL_PROP_WINDOW_UIKIT_OPENGL_RENDERBUFFER_NUMBER, view.drawableRenderbuffer);
        SDL_SetNumberProperty(props, SDL_PROP_WINDOW_UIKIT_OPENGL_RESOLVE_FRAMEBUFFER_NUMBER, view.msaaResolveFramebuffer);

        // The context owns the view / drawable.
        context.sdlView = view;


Review comment (suggestion):
```suggestion
        // construct our view, passing in SDL's OpenGL configuration data
```

Code after:
        }

        if (_this->gl_config.share_with_current_context) {
            EAGLContext *currContext = (__bridge EAGLContext *)SDL_GL_GetCurrentContext();
            sharegroup = currContext.sharegroup;
        }

        if (window->flags & SDL_WINDOW_HIGH_PIXEL_DENSITY) {
            /* Set the scale to the natural scale factor of the screen - the
             * backing dimensions of the OpenGL view will match the pixel
             * dimensions of the screen rather than the dimensions in points. */
            scale = data.uiwindow.screen.nativeScale;
        }

        context = [[SDLEAGLContext alloc] initWithAPI:api sharegroup:sharegroup];
        if (!context) {
            SDL_SetError("OpenGL ES %d context could not be created", _this->gl_config.major_version);
            return NULL;
        }

        int srgb = _this->gl_config.framebuffer_srgb_capable;
        const char *srgbhint = SDL_GetHint(SDL_HINT_OPENGL_FORCE_SRGB_CAPABLE);
        if (srgbhint && *srgbhint) {
            srgb = SDL_GetStringBoolean(srgbhint, false) ? 1 : 0;  // there is no "skip" here, since initWithFrame expects it, so we'll treat it as false.
        }

        // construct our view, passing in SDL's OpenGL configuration data
        view = [[SDL_uikitopenglview alloc] initWithFrame:frame
                                                    scale:scale
                                            retainBacking:_this->gl_config.retained_backing
                                                    rBits:_this->gl_config.red_size
                                                    gBits:_this->gl_config.green_size
                                                    bBits:_this->gl_config.blue_size
                                                    aBits:_this->gl_config.alpha_size
                                                depthBits:_this->gl_config.depth_size
                                              stencilBits:_this->gl_config.stencil_size
                                                     sRGB:srgb
                                             multisamples:samples
                                                  context:context];

        if (!view) {
            return NULL;
        }

        SDL_PropertiesID props = SDL_GetWindowProperties(window);
        SDL_SetNumberProperty(props, SDL_PROP_WINDOW_UIKIT_OPENGL_FRAMEBUFFER_NUMBER, view.drawableFramebuffer);
        SDL_SetNumberProperty(props, SDL_PROP_WINDOW_UIKIT_OPENGL_RENDERBUFFER_NUMBER, view.drawableRenderbuffer);
        SDL_SetNumberProperty(props, SDL_PROP_WINDOW_UIKIT_OPENGL_RESOLVE_FRAMEBUFFER_NUMBER, view.msaaResolveFramebuffer);

        // The context owns the view / drawable.
        context.sdlView = view;