Skip to content

Commit

Permalink
updated iOS to GLES 3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jnoyola committed Oct 27, 2017
1 parent 40bf85d commit 4d97d3a
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 25 deletions.
15 changes: 10 additions & 5 deletions MonoGame.Framework/Graphics/GraphicsCapabilities.OpenGL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ private void PlatformInitialize(GraphicsDevice device)
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 = (GL.BoundApi == GL.RenderApi.ES && device.glMajorVersion >= 3) ||
GL.Extensions.Contains("GL_OES_depth24");
SupportsPackedDepthStencil = (GL.BoundApi == GL.RenderApi.ES && 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");
#else
Expand All @@ -70,7 +72,8 @@ private void PlatformInitialize(GraphicsDevice device)
#if GLES
SupportsFramebufferObjectARB = GL.BoundApi == GL.RenderApi.ES && (device.glMajorVersion >= 2 || GL.Extensions.Contains("GL_ARB_framebuffer_object")); // always supported on GLES 2.0+
SupportsFramebufferObjectEXT = GL.Extensions.Contains("GL_EXT_framebuffer_object");;
SupportsFramebufferObjectIMG = GL.Extensions.Contains("GL_IMG_multisampled_render_to_texture") |
SupportsFramebufferObjectIMG = (GL.BoundApi == GL.RenderApi.ES && device.glMajorVersion >= 3) |
GL.Extensions.Contains("GL_IMG_multisampled_render_to_texture") |
GL.Extensions.Contains("GL_APPLE_framebuffer_multisample") |
GL.Extensions.Contains("GL_EXT_multisampled_render_to_texture") |
GL.Extensions.Contains("GL_NV_framebuffer_multisample");
Expand All @@ -91,9 +94,11 @@ private void PlatformInitialize(GraphicsDevice device)

// sRGB
#if GLES
SupportsSRgb = GL.Extensions.Contains("GL_EXT_sRGB");
SupportsSRgb = (GL.BoundApi == GL.RenderApi.ES && device.glMajorVersion >= 3) ||
GL.Extensions.Contains("GL_EXT_sRGB");
#else
SupportsSRgb = GL.Extensions.Contains("GL_EXT_texture_sRGB") && GL.Extensions.Contains("GL_EXT_framebuffer_sRGB");
SupportsSRgb = (GL.BoundApi == GL.RenderApi.ES && device.glMajorVersion >= 3) ||
(GL.Extensions.Contains("GL_EXT_texture_sRGB") && GL.Extensions.Contains("GL_EXT_framebuffer_sRGB"));
#endif

// TODO: Implement OpenGL support for texture arrays
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ internal virtual void CheckFramebufferStatus()
case FramebufferErrorCode.FramebufferIncompleteMissingAttachment: message = "No images are attached to the framebuffer."; break;
case FramebufferErrorCode.FramebufferUnsupported: message = "The combination of internal formats of the attached images violates an implementation-dependent set of restrictions."; break;
case FramebufferErrorCode.FramebufferIncompleteMultisample: message = "Not all attached images have the same number of samples."; break;
default: message += $" ({status.ToString()})"; break;
}
throw new InvalidOperationException(message);
}
Expand Down
33 changes: 21 additions & 12 deletions MonoGame.Framework/Graphics/GraphicsDevice.OpenGL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ public partial class GraphicsDevice
internal IGraphicsContext Context { get; private set; }
#endif

#if !GLES
private DrawBuffersEnum[] _drawBuffers;
#endif

enum ResourceType
{
Expand Down Expand Up @@ -323,14 +321,19 @@ private void PlatformSetup()
}
#endif

#if !GLES
// Initialize draw buffer attachment array
int maxDrawBuffers;
GL.GetInteger(GetPName.MaxDrawBuffers, out maxDrawBuffers);
GraphicsExtensions.CheckGLError ();
_drawBuffers = new DrawBuffersEnum[maxDrawBuffers];
for (int i = 0; i < maxDrawBuffers; i++)
_drawBuffers[i] = (DrawBuffersEnum)(FramebufferAttachment.ColorAttachment0Ext + i);
#if GLES
if (glMajorVersion >= 3)
{
#endif
// Initialize draw buffer attachment array
int maxDrawBuffers;
GL.GetInteger(GetPName.MaxDrawBuffers, out maxDrawBuffers);
GraphicsExtensions.CheckGLError();
_drawBuffers = new DrawBuffersEnum[maxDrawBuffers];
for (int i = 0; i < maxDrawBuffers; i++)
_drawBuffers[i] = (DrawBuffersEnum)(FramebufferAttachment.ColorAttachment0Ext + i);
#if GLES
}
#endif
}

Expand Down Expand Up @@ -856,8 +859,14 @@ private IRenderTarget PlatformApplyRenderTargets()
{
this.framebufferHelper.BindFramebuffer(glFramebuffer);
}
#if !GLES
GL.DrawBuffers(this._currentRenderTargetCount, this._drawBuffers);

#if GLES
if (glMajorVersion >= 3)
{
#endif
GL.DrawBuffers(this._currentRenderTargetCount, this._drawBuffers);
#if GLES
}
#endif

// Reset the raster state because we flip vertices
Expand Down
36 changes: 31 additions & 5 deletions MonoGame.Framework/Graphics/OpenGL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ internal enum GetPName : int
TextureBinding2D = 0x8069,
MaxTextureMaxAnisotropyExt = 0x84FF,
MaxSamples = 0x8D57,
NumExtensions = 0x821D,
}

internal enum StringName
Expand Down Expand Up @@ -647,6 +648,11 @@ internal delegate void BlitFramebufferDelegate (int srcX0,
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);
Expand Down Expand Up @@ -1214,6 +1220,7 @@ internal static void LoadEntryPoints ()
DisableVertexAttribArray = (DisableVertexAttribArrayDelegate)LoadEntryPoint<DisableVertexAttribArrayDelegate> ("glDisableVertexAttribArray");
GetIntegerv = (GetIntegerDelegate)LoadEntryPoint<GetIntegerDelegate> ("glGetIntegerv");
GetStringInternal = (GetStringDelegate)LoadEntryPoint<GetStringDelegate> ("glGetString");
GetStringiInternal = (GetStringiDelegate)LoadEntryPoint<GetStringiDelegate>("glGetStringi");
ClearDepth = (ClearDepthDelegate)LoadEntryPoint<ClearDepthDelegate> ("glClearDepth");
if (ClearDepth == null)
ClearDepth = (ClearDepthDelegate)LoadEntryPoint<ClearDepthDelegate> ("glClearDepthf");
Expand Down Expand Up @@ -1351,7 +1358,9 @@ internal static void LoadEntryPoints ()
}
#endif
if (BoundApi == RenderApi.ES) {
InvalidateFramebuffer = (InvalidateFramebufferDelegate)LoadEntryPoint<InvalidateFramebufferDelegate> ("glDiscardFramebufferEXT");
InvalidateFramebuffer = (InvalidateFramebufferDelegate)LoadEntryPoint<InvalidateFramebufferDelegate>("glInvalidateFramebuffer");
if (InvalidateFramebuffer == null)
InvalidateFramebuffer = (InvalidateFramebufferDelegate)LoadEntryPoint<InvalidateFramebufferDelegate>("glDiscardFramebufferEXT");
}

LoadExtensions ();
Expand All @@ -1372,10 +1381,22 @@ static void LogExtensions()

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 :)
Expand Down Expand Up @@ -1488,6 +1509,11 @@ internal unsafe static string GetString (StringName name)
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;
Expand Down
2 changes: 1 addition & 1 deletion MonoGame.Framework/Graphics/OpenGL.iOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class GraphicsContext : IGraphicsContext
{
public GraphicsContext ()
{
Context = new EAGLContext (EAGLRenderingAPI.OpenGLES2);
Context = new EAGLContext (EAGLRenderingAPI.OpenGLES3);
}

public bool IsCurrent {
Expand Down
4 changes: 2 additions & 2 deletions MonoGame.Framework/iOS/iOSGameView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,9 @@ private void CreateFramebuffer ()
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)
Expand Down

0 comments on commit 4d97d3a

Please sign in to comment.