Some FreeSO Stuff

- HashSet for resource references to speed up dispose
- InheritDepthStencil for sharing stencil between FBs
- Use GLES 3.0 on iOS (does pre iphone 5s even exist at this point)
- Thirdparty submodule updates because they were screwed for some reason.
This commit is contained in:
riperiperi 2018-06-09 17:00:00 +01:00
parent d1cfbd162b
commit 1eaeeb10d7
13 changed files with 74 additions and 25 deletions

View file

@ -298,7 +298,7 @@
<Compile Include="Rectangle.cs" />
<Compile Include="ReusableItemList.cs" />
<Compile Include="TextInputEventArgs.cs">
<Platforms>Angle,Linux,MacOS,Windows,WindowsGL,WindowsUniversal</Platforms>
<Platforms>Android,Angle,iOS,Linux,MacOS,Windows,WindowsGL,WindowsUniversal</Platforms>
</Compile>
<Compile Include="Threading.cs">
<Platforms>Android,Angle,iOS,Linux,MacOS,WindowsGL,tvOS</Platforms>

View file

@ -45,10 +45,10 @@ namespace Microsoft.Xna.Framework.Graphics
SupportsTextureFilterAnisotropic = GL.Extensions.Contains("GL_EXT_texture_filter_anisotropic");
#if GLES
SupportsDepth24 = GL.Extensions.Contains("GL_OES_depth24");
SupportsPackedDepthStencil = GL.Extensions.Contains("GL_OES_packed_depth_stencil");
SupportsDepth24 = device.glMajorVersion >= 3 || GL.Extensions.Contains("GL_OES_depth24");
SupportsPackedDepthStencil = device.glMajorVersion >= 3 || GL.Extensions.Contains("GL_OES_packed_depth_stencil");
SupportsDepthNonLinear = GL.Extensions.Contains("GL_NV_depth_nonlinear");
SupportsTextureMaxLevel = GL.Extensions.Contains("GL_APPLE_texture_max_level");
SupportsTextureMaxLevel = device.glMajorVersion >= 3 || GL.Extensions.Contains("GL_APPLE_texture_max_level");
#else
SupportsDepth24 = true;
SupportsPackedDepthStencil = true;

View file

@ -656,7 +656,7 @@ namespace Microsoft.Xna.Framework.Graphics
#if GLES
case DepthFormat.Depth24:
if (GraphicsCapabilities.SupportsDepth24)
depthInternalFormat = RenderbufferStorage.DepthComponent24Oes;
depthInternalFormat = RenderbufferStorage.DepthComponent24;
else if (GraphicsCapabilities.SupportsDepthNonLinear)
depthInternalFormat = (RenderbufferStorage)0x8E2C;
else
@ -664,11 +664,11 @@ namespace Microsoft.Xna.Framework.Graphics
break;
case DepthFormat.Depth24Stencil8:
if (GraphicsCapabilities.SupportsPackedDepthStencil)
depthInternalFormat = RenderbufferStorage.Depth24Stencil8Oes;
depthInternalFormat = RenderbufferStorage.Depth24Stencil8;
else
{
if (GraphicsCapabilities.SupportsDepth24)
depthInternalFormat = RenderbufferStorage.DepthComponent24Oes;
depthInternalFormat = RenderbufferStorage.DepthComponent24;
else if (GraphicsCapabilities.SupportsDepthNonLinear)
depthInternalFormat = (RenderbufferStorage)0x8E2C;
else

View file

@ -114,10 +114,10 @@ namespace Microsoft.Xna.Framework.Graphics
// Use WeakReference for the global resources list as we do not know when a resource
// may be disposed and collected. We do not want to prevent a resource from being
// collected by holding a strong reference to it in this list.
private readonly List<WeakReference> _resources = new List<WeakReference>();
private readonly HashSet<WeakReference> _resources = new HashSet<WeakReference>();
// TODO Graphics Device events need implementing
public event EventHandler<EventArgs> DeviceLost;
// TODO Graphics Device events need implementing
public event EventHandler<EventArgs> DeviceLost;
public event EventHandler<EventArgs> DeviceReset;
public event EventHandler<EventArgs> DeviceResetting;
public event EventHandler<ResourceCreatedEventArgs> ResourceCreated;
@ -535,7 +535,7 @@ namespace Microsoft.Xna.Framework.Graphics
// Dispose of all remaining graphics resources before disposing of the graphics device
lock (_resourcesLock)
{
foreach (var resource in _resources.ToArray())
foreach (var resource in (new List<WeakReference>(_resources)).ToArray())
{
var target = resource.Target as IDisposable;
if (target != null)
@ -586,7 +586,7 @@ namespace Microsoft.Xna.Framework.Graphics
{
lock (_resourcesLock)
{
_resources.Remove(resourceReference);
_resources.RemoveWhere(wr => !wr.IsAlive);
}
}
@ -649,7 +649,7 @@ namespace Microsoft.Xna.Framework.Graphics
}
// Remove references to resources that have been garbage collected.
_resources.RemoveAll(wr => !wr.IsAlive);
_resources.RemoveWhere(wr => !wr.IsAlive);
}
}

View file

@ -320,6 +320,7 @@ namespace MonoGame.OpenGL
TextureBinding2D = 0x8069,
MaxTextureMaxAnisotropyExt = 0x84FF,
MaxSamples = 0x8D57,
NumExtensions = 0x821D
}
internal enum StringName
@ -650,6 +651,11 @@ namespace MonoGame.OpenGL
internal delegate IntPtr GetStringDelegate (StringName param);
internal static GetStringDelegate GetStringInternal;
[System.Security.SuppressUnmanagedCodeSecurity()]
[MonoNativeFunctionWrapper]
internal delegate IntPtr GetStringiDelegate(StringName param, int i);
internal static GetStringiDelegate GetStringiInternal;
[System.Security.SuppressUnmanagedCodeSecurity ()]
[MonoNativeFunctionWrapper]
internal delegate void ClearDepthDelegate (float depth);
@ -1215,6 +1221,7 @@ namespace MonoGame.OpenGL
DisableVertexAttribArray = LoadEntryPoint<DisableVertexAttribArrayDelegate> ("glDisableVertexAttribArray");
GetIntegerv = LoadEntryPoint<GetIntegerDelegate> ("glGetIntegerv");
GetStringInternal = LoadEntryPoint<GetStringDelegate> ("glGetString");
GetStringiInternal = LoadEntryPoint<GetStringiDelegate>("glGetStringi");
ClearDepth = LoadEntryPoint<ClearDepthDelegate> ("glClearDepth");
if (ClearDepth == null)
ClearDepth = LoadEntryPoint<ClearDepthDelegate> ("glClearDepthf");
@ -1352,7 +1359,9 @@ namespace MonoGame.OpenGL
}
#endif
if (BoundApi == RenderApi.ES) {
InvalidateFramebuffer = LoadEntryPoint<InvalidateFramebufferDelegate> ("glDiscardFramebufferEXT");
InvalidateFramebuffer = LoadEntryPoint<InvalidateFramebufferDelegate>("glInvalidateFramebufer");
if (InvalidateFramebuffer == null)
InvalidateFramebuffer = LoadEntryPoint<InvalidateFramebufferDelegate> ("glDiscardFramebufferEXT");
}
LoadExtensions ();
@ -1369,14 +1378,28 @@ namespace MonoGame.OpenGL
foreach (var ext in Extensions)
Android.Util.Log.Verbose("GL", " " + ext);
#endif
foreach (var ext in Extensions)
Console.WriteLine("GL " + ext);
}
internal static void LoadExtensions()
{
string extstring = GL.GetString(StringName.Extensions);
var error = GL.GetError();
if (!string.IsNullOrEmpty(extstring) && error == ErrorCode.NoError)
Extensions.AddRange(extstring.Split(' '));
if (GetStringiInternal != null)
{
int numExtensions = 0;
GL.GetInteger(GetPName.NumExtensions, out numExtensions);
for (int i = 0; i < numExtensions; ++i)
{
Extensions.Add(GL.GetStringi(StringName.Extensions, i));
}
}
else
{
string extstring = GL.GetString(StringName.Extensions);
var error = GL.GetError();
if (!string.IsNullOrEmpty(extstring) && error == ErrorCode.NoError)
Extensions.AddRange(extstring.Split(' '));
}
LogExtensions();
// now load Extensions :)
@ -1408,6 +1431,8 @@ namespace MonoGame.OpenGL
GL.BlitFramebuffer = GL.LoadEntryPoint<GL.BlitFramebufferDelegate>("glBlitFramebufferNV");
}
}
if (GL.BlitFramebuffer == null) GL.LoadEntryPoint<GL.BlitFramebufferDelegate>("glResolveMultisampleFramebufferAPPLE"); //ios doesnt have the extension, but does need you to do this
}
internal static void LoadFrameBufferObjectARBEntryPoints()
@ -1489,6 +1514,11 @@ namespace MonoGame.OpenGL
return Marshal.PtrToStringAnsi (GetStringInternal (name));
}
internal unsafe static string GetStringi(StringName name, int i)
{
return Marshal.PtrToStringAnsi(GetStringiInternal(name, i));
}
protected static IntPtr MarshalStringArrayToPtr (string[] strings)
{
IntPtr intPtr = IntPtr.Zero;

View file

@ -50,7 +50,7 @@ namespace MonoGame.OpenGL
{
public GraphicsContext ()
{
Context = new EAGLContext (EAGLRenderingAPI.OpenGLES2);
Context = new EAGLContext (EAGLRenderingAPI.OpenGLES3);
}
public bool IsCurrent {

View file

@ -199,5 +199,11 @@ namespace Microsoft.Xna.Framework.Graphics
return desc;
}
public void InheritDepthStencil(RenderTarget2D from)
{
if (from == null) _depthStencilView = GraphicsDevice._depthStencilView;
else _depthStencilView = from._depthStencilView;
}
}
}

View file

@ -56,5 +56,18 @@ namespace Microsoft.Xna.Framework.Graphics
base.Dispose(disposing);
}
public void InheritDepthStencil(RenderTarget2D from)
{
if (from == null)
{
//must use other method
}
else
{
((IRenderTarget)this).GLDepthBuffer = ((IRenderTarget)from).GLDepthBuffer;
((IRenderTarget)this).GLStencilBuffer = ((IRenderTarget)from).GLStencilBuffer;
}
}
}
}

View file

@ -230,9 +230,9 @@ namespace Microsoft.Xna.Framework {
GL.BindRenderbuffer(RenderbufferTarget.Renderbuffer, _depthbuffer);
var internalFormat = RenderbufferStorage.DepthComponent16;
if (preferredDepthFormat == DepthFormat.Depth24)
internalFormat = RenderbufferStorage.DepthComponent24Oes;
internalFormat = RenderbufferStorage.DepthComponent24;
else if (preferredDepthFormat == DepthFormat.Depth24Stencil8)
internalFormat = RenderbufferStorage.Depth24Stencil8Oes;
internalFormat = RenderbufferStorage.Depth24Stencil8;
GL.RenderbufferStorage(RenderbufferTarget.Renderbuffer, internalFormat, viewportWidth, viewportHeight);
GL.FramebufferRenderbuffer(FramebufferTarget.Framebuffer, FramebufferAttachment.DepthAttachment, RenderbufferTarget.Renderbuffer, _depthbuffer);
if (preferredDepthFormat == DepthFormat.Depth24Stencil8)

@ -1 +1 @@
Subproject commit 15e2213c1fac21e448d83963cf382d1cdaf95bb4
Subproject commit 27948adc77b87e3bd85ba5e73af8f4151b2797d7

2
ThirdParty/NVorbis vendored

@ -1 +1 @@
Subproject commit c84c6aced83e3fd801bdac237268a51e098ace2a
Subproject commit 478eb45c3996e45a6bd19777c0549b85a7bb6851

@ -1 +1 @@
Subproject commit 4c86539a1b1420d072c4d370f6ef47797db7f3db
Subproject commit d797cd5ea477695e2a34f77a1823eafca66f773f

View file

@ -171,7 +171,7 @@ namespace TwoMGFX
// Add the required precision specifiers for GLES.
var floatPrecision = dxshader.IsVertexShader ? "precision highp float;\r\n" : "precision mediump float;\r\n";
var floatPrecision = dxshader.IsVertexShader ? "precision highp float;\r\n" : "precision highp float;\r\n";
glslCode = "#ifdef GL_ES\r\n" +
floatPrecision +