A game framework written with osu! in mind.
fork

Configure Feed

Select the types of activity you want to include in your feed.

at master 53 lines 1.9 kB view raw
1// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. 2// See the LICENCE file in the repository root for full licence text. 3 4using System; 5using SDL2; 6 7namespace osu.Framework.Platform.SDL2 8{ 9 /// <summary> 10 /// Implementation of <see cref="PassthroughGraphicsBackend"/> that uses SDL's OpenGL bindings. 11 /// </summary> 12 public class SDL2GraphicsBackend : PassthroughGraphicsBackend 13 { 14 private IntPtr sdlWindowHandle; 15 16 public override bool VerticalSync 17 { 18 get => SDL.SDL_GL_GetSwapInterval() != 0; 19 set => SDL.SDL_GL_SetSwapInterval(value ? 1 : 0); 20 } 21 22 protected override IntPtr CreateContext() 23 { 24 SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_CONTEXT_PROFILE_MASK, SDL.SDL_GLprofile.SDL_GL_CONTEXT_PROFILE_COMPATIBILITY); 25 26 IntPtr context = SDL.SDL_GL_CreateContext(sdlWindowHandle); 27 if (context == IntPtr.Zero) 28 throw new InvalidOperationException($"Failed to create an SDL2 GL context ({SDL.SDL_GetError()})"); 29 30 return context; 31 } 32 33 protected override void MakeCurrent(IntPtr context) 34 { 35 int result = SDL.SDL_GL_MakeCurrent(sdlWindowHandle, context); 36 if (result < 0) 37 throw new InvalidOperationException($"Failed to acquire GL context ({SDL.SDL_GetError()})"); 38 } 39 40 public override void SwapBuffers() => SDL.SDL_GL_SwapWindow(sdlWindowHandle); 41 42 protected override IntPtr GetProcAddress(string symbol) => SDL.SDL_GL_GetProcAddress(symbol); 43 44 public override void Initialise(IWindow window) 45 { 46 if (!(window is SDL2DesktopWindow sdlWindow)) 47 throw new ArgumentException("Unsupported window backend.", nameof(window)); 48 49 sdlWindowHandle = sdlWindow.SDLWindowHandle; 50 base.Initialise(window); 51 } 52 } 53}