Skip to content
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

Remove legacy OpenGL support. #21143

Merged
merged 1 commit into from
Oct 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 2 additions & 3 deletions OpenRA.Game/Graphics/PlatformInterfaces.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@ public enum GLProfile
Automatic,
ANGLE,
Modern,
Embedded,
Legacy
Embedded
}

public interface IPlatform
{
IPlatformWindow CreateWindow(Size size, WindowMode windowMode, float scaleModifier, int vertexBatchSize, int indexBatchSize, int videoDisplay, GLProfile profile, bool enableLegacyGL);
IPlatformWindow CreateWindow(Size size, WindowMode windowMode, float scaleModifier, int vertexBatchSize, int indexBatchSize, int videoDisplay, GLProfile profile);
ISoundEngine CreateSound(string device);
IFont CreateFont(byte[] data);
}
Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Game/Renderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public Renderer(IPlatform platform, GraphicSettings graphicSettings)

Window = platform.CreateWindow(new Size(resolution.Width, resolution.Height),
graphicSettings.Mode, graphicSettings.UIScale, TempVertexBufferSize, TempIndexBufferSize,
graphicSettings.VideoDisplay, graphicSettings.GLProfile, !graphicSettings.DisableLegacyGL);
graphicSettings.VideoDisplay, graphicSettings.GLProfile);

Context = Window.Context;

Expand Down
3 changes: 0 additions & 3 deletions OpenRA.Game/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,6 @@ public class GraphicSettings
[Desc("Disable operating-system provided cursor rendering.")]
public bool DisableHardwareCursors = false;

[Desc("Disable legacy OpenGL 2.1 support.")]
public bool DisableLegacyGL = true;

[Desc("Display index to use in a multi-monitor fullscreen setup.")]
public int VideoDisplay = 0;

Expand Down
4 changes: 2 additions & 2 deletions OpenRA.Platforms.Default/DefaultPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ namespace OpenRA.Platforms.Default
{
public class DefaultPlatform : IPlatform
{
public IPlatformWindow CreateWindow(Size size, WindowMode windowMode, float scaleModifier, int vertexBatchSize, int indexBatchSize, int videoDisplay, GLProfile profile, bool enableLegacyGL)
public IPlatformWindow CreateWindow(Size size, WindowMode windowMode, float scaleModifier, int vertexBatchSize, int indexBatchSize, int videoDisplay, GLProfile profile)
{
return new Sdl2PlatformWindow(size, windowMode, scaleModifier, vertexBatchSize, indexBatchSize, videoDisplay, profile, enableLegacyGL);
return new Sdl2PlatformWindow(size, windowMode, scaleModifier, vertexBatchSize, indexBatchSize, videoDisplay, profile);
}

public ISoundEngine CreateSound(string device)
Expand Down
80 changes: 23 additions & 57 deletions OpenRA.Platforms.Default/OpenGL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ public static string glGetStringi(int name, uint index)

#endregion

public static void Initialize(bool preferLegacyProfile)
public static void Initialize()
{
try
{
Expand All @@ -508,7 +508,7 @@ public static void Initialize(bool preferLegacyProfile)
throw new InvalidProgramException("Failed to initialize low-level OpenGL bindings. GPU information is not available.", e);
}

if (!DetectGLFeatures(preferLegacyProfile))
if (!DetectGLFeatures())
{
WriteGraphicsLog("Unsupported OpenGL version: " + glGetString(GL_VERSION));
throw new InvalidProgramException("OpenGL Version Error: See graphics.log for details.");
Expand Down Expand Up @@ -615,49 +615,29 @@ public static void Initialize(bool preferLegacyProfile)
glTexParameteri = Bind<TexParameteri>("glTexParameteri");
glTexParameterf = Bind<TexParameterf>("glTexParameterf");

if (Profile != GLProfile.Legacy)
if (Profile != GLProfile.Embedded)
{
if (Profile != GLProfile.Embedded)
{
glGetTexImage = Bind<GetTexImage>("glGetTexImage");
glBindFragDataLocation = Bind<BindFragDataLocation>("glBindFragDataLocation");
}
else
{
glGetTexImage = null;
glBindFragDataLocation = null;
}

glGenVertexArrays = Bind<GenVertexArrays>("glGenVertexArrays");
glBindVertexArray = Bind<BindVertexArray>("glBindVertexArray");
glGenFramebuffers = Bind<GenFramebuffers>("glGenFramebuffers");
glBindFramebuffer = Bind<BindFramebuffer>("glBindFramebuffer");
glFramebufferTexture2D = Bind<FramebufferTexture2D>("glFramebufferTexture2D");
glDeleteFramebuffers = Bind<DeleteFramebuffers>("glDeleteFramebuffers");
glGenRenderbuffers = Bind<GenRenderbuffers>("glGenRenderbuffers");
glBindRenderbuffer = Bind<BindRenderbuffer>("glBindRenderbuffer");
glRenderbufferStorage = Bind<RenderbufferStorage>("glRenderbufferStorage");
glDeleteRenderbuffers = Bind<DeleteRenderbuffers>("glDeleteRenderbuffers");
glFramebufferRenderbuffer = Bind<FramebufferRenderbuffer>("glFramebufferRenderbuffer");
glCheckFramebufferStatus = Bind<CheckFramebufferStatus>("glCheckFramebufferStatus");
glGetTexImage = Bind<GetTexImage>("glGetTexImage");
glBindFragDataLocation = Bind<BindFragDataLocation>("glBindFragDataLocation");
}
else
{
glGenVertexArrays = null;
glBindVertexArray = null;
glGetTexImage = null;
glBindFragDataLocation = null;
glGetTexImage = Bind<GetTexImage>("glGetTexImage");
glGenFramebuffers = Bind<GenFramebuffers>("glGenFramebuffersEXT");
glBindFramebuffer = Bind<BindFramebuffer>("glBindFramebufferEXT");
glFramebufferTexture2D = Bind<FramebufferTexture2D>("glFramebufferTexture2DEXT");
glDeleteFramebuffers = Bind<DeleteFramebuffers>("glDeleteFramebuffersEXT");
glGenRenderbuffers = Bind<GenRenderbuffers>("glGenRenderbuffersEXT");
glBindRenderbuffer = Bind<BindRenderbuffer>("glBindRenderbufferEXT");
glRenderbufferStorage = Bind<RenderbufferStorage>("glRenderbufferStorageEXT");
glDeleteRenderbuffers = Bind<DeleteRenderbuffers>("glDeleteRenderbuffersEXT");
glFramebufferRenderbuffer = Bind<FramebufferRenderbuffer>("glFramebufferRenderbufferEXT");
glCheckFramebufferStatus = Bind<CheckFramebufferStatus>("glCheckFramebufferStatusEXT");
}

glGenVertexArrays = Bind<GenVertexArrays>("glGenVertexArrays");
glBindVertexArray = Bind<BindVertexArray>("glBindVertexArray");
glGenFramebuffers = Bind<GenFramebuffers>("glGenFramebuffers");
glBindFramebuffer = Bind<BindFramebuffer>("glBindFramebuffer");
glFramebufferTexture2D = Bind<FramebufferTexture2D>("glFramebufferTexture2D");
glDeleteFramebuffers = Bind<DeleteFramebuffers>("glDeleteFramebuffers");
glGenRenderbuffers = Bind<GenRenderbuffers>("glGenRenderbuffers");
glBindRenderbuffer = Bind<BindRenderbuffer>("glBindRenderbuffer");
glRenderbufferStorage = Bind<RenderbufferStorage>("glRenderbufferStorage");
glDeleteRenderbuffers = Bind<DeleteRenderbuffers>("glDeleteRenderbuffers");
glFramebufferRenderbuffer = Bind<FramebufferRenderbuffer>("glFramebufferRenderbuffer");
glCheckFramebufferStatus = Bind<CheckFramebufferStatus>("glCheckFramebufferStatus");
}
catch (Exception e)
{
Expand All @@ -671,7 +651,7 @@ static T Bind<T>(string name)
return (T)(object)Marshal.GetDelegateForFunctionPointer(SDL.SDL_GL_GetProcAddress(name), typeof(T));
}

public static bool DetectGLFeatures(bool preferLegacyProfile)
public static bool DetectGLFeatures()
{
var hasValidConfiguration = false;
try
Expand Down Expand Up @@ -708,15 +688,6 @@ public static bool DetectGLFeatures(bool preferLegacyProfile)
var hasDebugMessagesCallback = SDL.SDL_GL_ExtensionSupported("GL_KHR_debug") == SDL.SDL_bool.SDL_TRUE;
if (hasDebugMessagesCallback)
Features |= GLFeatures.DebugMessagesCallback;

if (preferLegacyProfile || (major == 2 && minor == 1) || (major == 3 && minor < 2))
{
if (SDL.SDL_GL_ExtensionSupported("GL_EXT_framebuffer_object") == SDL.SDL_bool.SDL_TRUE)
{
hasValidConfiguration = true;
Profile = GLProfile.Legacy;
}
}
}
catch (Exception) { }

Expand All @@ -743,14 +714,9 @@ public static void WriteGraphicsLog(string message)
Log.Write("graphics", $"Shader Version: {glGetString(GL_SHADING_LANGUAGE_VERSION)}");
Log.Write("graphics", "Available extensions:");

if (Profile != GLProfile.Legacy)
{
glGetIntegerv(GL_NUM_EXTENSIONS, out var extensionCount);
for (var i = 0; i < extensionCount; i++)
Log.Write("graphics", glGetStringi(GL_EXTENSIONS, (uint)i));
}
else
Log.Write("graphics", glGetString(GL_EXTENSIONS));
glGetIntegerv(GL_NUM_EXTENSIONS, out var extensionCount);
for (var i = 0; i < extensionCount; i++)
Log.Write("graphics", glGetStringi(GL_EXTENSIONS, (uint)i));
}

public static void CheckGLError()
Expand Down
13 changes: 5 additions & 8 deletions OpenRA.Platforms.Default/Sdl2GraphicsContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,13 @@ internal void InitializeOpenGL()
if (SDL.SDL_GL_MakeCurrent(window.Window, context) < 0)
throw new InvalidOperationException($"Can not bind OpenGL context. (Error: {SDL.SDL_GetError()})");

OpenGL.Initialize(window.GLProfile == GLProfile.Legacy);
OpenGL.Initialize();
OpenGL.CheckGLError();

if (OpenGL.Profile != GLProfile.Legacy)
{
OpenGL.glGenVertexArrays(1, out var vao);
OpenGL.CheckGLError();
OpenGL.glBindVertexArray(vao);
OpenGL.CheckGLError();
}
OpenGL.glGenVertexArrays(1, out var vao);
OpenGL.CheckGLError();
OpenGL.glBindVertexArray(vao);
OpenGL.CheckGLError();
}

public IVertexBuffer<T> CreateVertexBuffer<T>(int size) where T : struct
Expand Down
9 changes: 1 addition & 8 deletions OpenRA.Platforms.Default/Sdl2PlatformWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public GLProfile[] SupportedGLProfiles
static extern IntPtr XFlush(IntPtr display);

public Sdl2PlatformWindow(Size requestEffectiveWindowSize, WindowMode windowMode,
float scaleModifier, int vertexBatchSize, int indexBatchSize, int videoDisplay, GLProfile requestProfile, bool enableLegacyGL)
float scaleModifier, int vertexBatchSize, int indexBatchSize, int videoDisplay, GLProfile requestProfile)
{
// Lock the Window/Surface properties until initialization is complete
lock (syncObject)
Expand All @@ -147,9 +147,6 @@ public GLProfile[] SupportedGLProfiles
// Decide which OpenGL profile to use.
// Prefer standard GL over GLES provided by the native driver
var testProfiles = new List<GLProfile> { GLProfile.ANGLE, GLProfile.Modern, GLProfile.Embedded };
if (enableLegacyGL)
testProfiles.Add(GLProfile.Legacy);

var errorLog = new List<string>();
supportedProfiles = testProfiles
.Where(profile => CanCreateGLWindow(profile, errorLog))
Expand Down Expand Up @@ -537,10 +534,6 @@ static void SetSDLAttributes(GLProfile profile)
SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_CONTEXT_MINOR_VERSION, 0);
SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_CONTEXT_PROFILE_MASK, (int)SDL.SDL_GLprofile.SDL_GL_CONTEXT_PROFILE_ES);
break;
case GLProfile.Legacy:
SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_CONTEXT_MAJOR_VERSION, 2);
SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_CONTEXT_MINOR_VERSION, 1);
break;
}
}

Expand Down
19 changes: 1 addition & 18 deletions OpenRA.Platforms.Default/Shader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ namespace OpenRA.Platforms.Default
sealed class Shader : ThreadAffine, IShader
{
readonly Dictionary<string, int> samplers = new();
readonly Dictionary<int, int> legacySizeUniforms = new();
readonly Dictionary<string, int> uniformCache = new();
readonly Dictionary<int, ITexture> textures = new();
readonly Queue<int> unbindTextures = new();
Expand All @@ -28,8 +27,7 @@ sealed class Shader : ThreadAffine, IShader

static uint CompileShaderObject(int type, string code, string name)
{
var version = OpenGL.Profile == GLProfile.Embedded ? "300 es" :
OpenGL.Profile == GLProfile.Legacy ? "120" : "140";
var version = OpenGL.Profile == GLProfile.Embedded ? "300 es" : "140";

code = code.Replace("{VERSION}", version);

Expand Down Expand Up @@ -127,14 +125,6 @@ public Shader(IShaderBindings bindings)

OpenGL.glUniform1i(loc, nextTexUnit);
OpenGL.CheckGLError();

if (OpenGL.Profile == GLProfile.Legacy)
{
var sizeLoc = OpenGL.glGetUniformLocation(program, sampler + "Size");
if (sizeLoc >= 0)
legacySizeUniforms.Add(nextTexUnit, sizeLoc);
}

nextTexUnit++;
}
}
Expand Down Expand Up @@ -166,13 +156,6 @@ public void PrepareRender()
{
OpenGL.glActiveTexture(OpenGL.GL_TEXTURE0 + kv.Key);
OpenGL.glBindTexture(OpenGL.GL_TEXTURE_2D, texture.ID);

// Work around missing textureSize GLSL function by explicitly tracking sizes in a uniform
if (OpenGL.Profile == GLProfile.Legacy && legacySizeUniforms.TryGetValue(kv.Key, out var param))
{
OpenGL.glUniform2f(param, texture.Size.Width, texture.Size.Height);
OpenGL.CheckGLError();
}
}
else
unbindTextures.Enqueue(kv.Key);
Expand Down