Remove legacy OpenGL support.
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -491,7 +491,7 @@ namespace OpenRA.Platforms.Default
|
||||
|
||||
#endregion
|
||||
|
||||
public static void Initialize(bool preferLegacyProfile)
|
||||
public static void Initialize()
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -508,7 +508,7 @@ namespace OpenRA.Platforms.Default
|
||||
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.");
|
||||
@@ -615,49 +615,29 @@ namespace OpenRA.Platforms.Default
|
||||
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)
|
||||
{
|
||||
@@ -671,7 +651,7 @@ namespace OpenRA.Platforms.Default
|
||||
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
|
||||
@@ -708,15 +688,6 @@ namespace OpenRA.Platforms.Default
|
||||
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) { }
|
||||
|
||||
@@ -743,14 +714,9 @@ namespace OpenRA.Platforms.Default
|
||||
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()
|
||||
|
||||
@@ -40,16 +40,13 @@ namespace OpenRA.Platforms.Default
|
||||
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
|
||||
|
||||
@@ -133,7 +133,7 @@ namespace OpenRA.Platforms.Default
|
||||
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)
|
||||
@@ -147,9 +147,6 @@ namespace OpenRA.Platforms.Default
|
||||
// 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))
|
||||
@@ -537,10 +534,6 @@ namespace OpenRA.Platforms.Default
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
@@ -28,8 +27,7 @@ namespace OpenRA.Platforms.Default
|
||||
|
||||
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);
|
||||
|
||||
@@ -127,14 +125,6 @@ namespace OpenRA.Platforms.Default
|
||||
|
||||
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++;
|
||||
}
|
||||
}
|
||||
@@ -166,13 +156,6 @@ namespace OpenRA.Platforms.Default
|
||||
{
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user