Split GLProfile from GLFeatures.

This commit is contained in:
Paul Chote
2020-04-21 10:23:57 +01:00
committed by abcdefg30
parent a4b427bfac
commit 91c4179f05
5 changed files with 29 additions and 20 deletions

View File

@@ -15,6 +15,12 @@ using OpenRA.Primitives;
namespace OpenRA namespace OpenRA
{ {
public enum GLProfile
{
Modern,
Embedded,
}
public interface IPlatform public interface IPlatform
{ {
IPlatformWindow CreateWindow(Size size, WindowMode windowMode, float scaleModifier, int batchSize, int videoDisplay); IPlatformWindow CreateWindow(Size size, WindowMode windowMode, float scaleModifier, int batchSize, int videoDisplay);

View File

@@ -50,7 +50,7 @@ namespace OpenRA.Platforms.Default
OpenGL.glBindRenderbuffer(OpenGL.GL_RENDERBUFFER, depth); OpenGL.glBindRenderbuffer(OpenGL.GL_RENDERBUFFER, depth);
OpenGL.CheckGLError(); OpenGL.CheckGLError();
var glDepth = OpenGL.Features.HasFlag(OpenGL.GLFeatures.GLES) ? OpenGL.GL_DEPTH_COMPONENT16 : OpenGL.GL_DEPTH_COMPONENT; var glDepth = OpenGL.Profile == GLProfile.Embedded ? OpenGL.GL_DEPTH_COMPONENT16 : OpenGL.GL_DEPTH_COMPONENT;
OpenGL.glRenderbufferStorage(OpenGL.GL_RENDERBUFFER, glDepth, size.Width, size.Height); OpenGL.glRenderbufferStorage(OpenGL.GL_RENDERBUFFER, glDepth, size.Width, size.Height);
OpenGL.CheckGLError(); OpenGL.CheckGLError();

View File

@@ -29,12 +29,11 @@ namespace OpenRA.Platforms.Default
public enum GLFeatures public enum GLFeatures
{ {
None = 0, None = 0,
Core = 1, DebugMessagesCallback = 1,
GLES = 2, ESReadFormatBGRA = 2,
DebugMessagesCallback = 4,
ESReadFormatBGRA = 8
} }
public static GLProfile Profile { get; private set; }
public static GLFeatures Features { get; private set; } public static GLFeatures Features { get; private set; }
public static string Version { get; private set; } public static string Version { get; private set; }
@@ -495,7 +494,11 @@ namespace OpenRA.Platforms.Default
throw new InvalidProgramException("Failed to initialize low-level OpenGL bindings. GPU information is not available.", e); throw new InvalidProgramException("Failed to initialize low-level OpenGL bindings. GPU information is not available.", e);
} }
DetectGLFeatures(); if (!DetectGLFeatures())
{
WriteGraphicsLog("Unsupported OpenGL version: " + glGetString(GL_VERSION));
throw new InvalidProgramException("OpenGL Version Error: See graphics.log for details.");
}
// Allow users to force-disable the debug message callback feature to work around driver bugs // Allow users to force-disable the debug message callback feature to work around driver bugs
if (Features.HasFlag(GLFeatures.DebugMessagesCallback) && Game.Settings.Graphics.DisableGLDebugMessageCallback) if (Features.HasFlag(GLFeatures.DebugMessagesCallback) && Game.Settings.Graphics.DisableGLDebugMessageCallback)
@@ -509,18 +512,12 @@ namespace OpenRA.Platforms.Default
Features ^= GLFeatures.DebugMessagesCallback; Features ^= GLFeatures.DebugMessagesCallback;
} }
if (!Features.HasFlag(GLFeatures.Core))
{
WriteGraphicsLog("Unsupported OpenGL version: " + glGetString(GL_VERSION));
throw new InvalidProgramException("OpenGL Version Error: See graphics.log for details.");
}
// Setup the debug message callback handler // Setup the debug message callback handler
if (Features.HasFlag(GLFeatures.DebugMessagesCallback)) if (Features.HasFlag(GLFeatures.DebugMessagesCallback))
{ {
try try
{ {
var suffix = Features.HasFlag(GLFeatures.GLES) ? "KHR" : ""; var suffix = Profile == GLProfile.Embedded ? "KHR" : "";
glDebugMessageCallback = Bind<DebugMessageCallback>("glDebugMessageCallback" + suffix); glDebugMessageCallback = Bind<DebugMessageCallback>("glDebugMessageCallback" + suffix);
glDebugMessageInsert = Bind<DebugMessageInsert>("glDebugMessageInsert" + suffix); glDebugMessageInsert = Bind<DebugMessageInsert>("glDebugMessageInsert" + suffix);
@@ -620,8 +617,9 @@ namespace OpenRA.Platforms.Default
return (T)(object)Marshal.GetDelegateForFunctionPointer(SDL.SDL_GL_GetProcAddress(name), typeof(T)); return (T)(object)Marshal.GetDelegateForFunctionPointer(SDL.SDL_GL_GetProcAddress(name), typeof(T));
} }
public static void DetectGLFeatures() public static bool DetectGLFeatures()
{ {
var hasValidConfiguration = false;
try try
{ {
Version = glGetString(GL_VERSION); Version = glGetString(GL_VERSION);
@@ -641,13 +639,16 @@ namespace OpenRA.Platforms.Default
var hasBGRA = SDL.SDL_GL_ExtensionSupported("GL_EXT_texture_format_BGRA8888") == SDL.SDL_bool.SDL_TRUE; var hasBGRA = SDL.SDL_GL_ExtensionSupported("GL_EXT_texture_format_BGRA8888") == SDL.SDL_bool.SDL_TRUE;
if (Version.Contains(" ES") && hasBGRA && major >= 3) if (Version.Contains(" ES") && hasBGRA && major >= 3)
{ {
Features = GLFeatures.Core | GLFeatures.GLES; hasValidConfiguration = true;
Profile = GLProfile.Embedded;
if (SDL.SDL_GL_ExtensionSupported("GL_EXT_read_format_bgra") == SDL.SDL_bool.SDL_TRUE) if (SDL.SDL_GL_ExtensionSupported("GL_EXT_read_format_bgra") == SDL.SDL_bool.SDL_TRUE)
Features |= GLFeatures.ESReadFormatBGRA; Features |= GLFeatures.ESReadFormatBGRA;
} }
else if (major > 3 || (major == 3 && minor >= 2)) else if (major > 3 || (major == 3 && minor >= 2))
Features = GLFeatures.Core; {
hasValidConfiguration = true;
Profile = GLProfile.Modern;
}
// Debug callbacks were introduced in GL 4.3 // Debug callbacks were introduced in GL 4.3
var hasDebugMessagesCallback = SDL.SDL_GL_ExtensionSupported("GL_KHR_debug") == SDL.SDL_bool.SDL_TRUE; var hasDebugMessagesCallback = SDL.SDL_GL_ExtensionSupported("GL_KHR_debug") == SDL.SDL_bool.SDL_TRUE;
@@ -655,6 +656,8 @@ namespace OpenRA.Platforms.Default
Features |= GLFeatures.DebugMessagesCallback; Features |= GLFeatures.DebugMessagesCallback;
} }
catch (Exception) { } catch (Exception) { }
return hasValidConfiguration;
} }
public static void WriteGraphicsLog(string message) public static void WriteGraphicsLog(string message)

View File

@@ -33,7 +33,7 @@ namespace OpenRA.Platforms.Default
var filename = Path.Combine(Platform.GameDir, "glsl", name + "." + ext); var filename = Path.Combine(Platform.GameDir, "glsl", name + "." + ext);
var code = File.ReadAllText(filename); var code = File.ReadAllText(filename);
var version = OpenGL.Features.HasFlag(OpenGL.GLFeatures.GLES) ? "300 es" : "140"; var version = OpenGL.Profile == GLProfile.Embedded ? "300 es" : "140";
code = code.Replace("{VERSION}", version); code = code.Replace("{VERSION}", version);
var shader = OpenGL.glCreateShader(type); var shader = OpenGL.glCreateShader(type);

View File

@@ -75,7 +75,7 @@ namespace OpenRA.Platforms.Default
void SetData(IntPtr data, int width, int height) void SetData(IntPtr data, int width, int height)
{ {
PrepareTexture(); PrepareTexture();
var glInternalFormat = OpenGL.Features.HasFlag(OpenGL.GLFeatures.GLES) ? OpenGL.GL_BGRA : OpenGL.GL_RGBA8; var glInternalFormat = OpenGL.Profile == GLProfile.Embedded ? OpenGL.GL_BGRA : OpenGL.GL_RGBA8;
OpenGL.glTexImage2D(OpenGL.GL_TEXTURE_2D, 0, glInternalFormat, width, height, OpenGL.glTexImage2D(OpenGL.GL_TEXTURE_2D, 0, glInternalFormat, width, height,
0, OpenGL.GL_BGRA, OpenGL.GL_UNSIGNED_BYTE, data); 0, OpenGL.GL_BGRA, OpenGL.GL_UNSIGNED_BYTE, data);
OpenGL.CheckGLError(); OpenGL.CheckGLError();
@@ -119,7 +119,7 @@ namespace OpenRA.Platforms.Default
var data = new byte[4 * Size.Width * Size.Height]; var data = new byte[4 * Size.Width * Size.Height];
// GLES doesn't support glGetTexImage so data must be read back via a frame buffer // GLES doesn't support glGetTexImage so data must be read back via a frame buffer
if (OpenGL.Features.HasFlag(OpenGL.GLFeatures.GLES)) if (OpenGL.Profile == GLProfile.Embedded)
{ {
// Query the active framebuffer so we can restore it afterwards // Query the active framebuffer so we can restore it afterwards
int lastFramebuffer; int lastFramebuffer;