Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Veldrid/OpenGL/EGL/EGLNative.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ internal static unsafe class EglNative
public const int EGL_BLUE_SIZE = 0x3022;
public const int EGL_ALPHA_SIZE = 0x3021;
public const int EGL_DEPTH_SIZE = 0x3025;
public const int EGL_STENCIL_SIZE = 0x3026;
public const int EGL_SURFACE_TYPE = 0x3033;
public const int EGL_WINDOW_BIT = 0x0004;
public const int EGL_OPENGL_ES_BIT = 0x0001;
Expand Down Expand Up @@ -45,7 +46,7 @@ internal static unsafe class EglNative
public static extern IntPtr eglGetCurrentDisplay();

[DllImport(lib_name)]
public static extern IntPtr eglGetDisplay(int nativeDisplay);
public static extern IntPtr eglGetDisplay(IntPtr nativeDisplay);

[DllImport(lib_name)]
public static extern IntPtr eglGetCurrentSurface(int readdraw);
Expand Down
8 changes: 8 additions & 0 deletions src/Veldrid/OpenGL/OpenGLExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ internal class OpenGLExtensions : IReadOnlyCollection<string>
public readonly bool MultiDrawIndirect;
public readonly bool StorageBuffers;
public readonly bool AnisotropicFilter;
public readonly bool OesPackedDepthStencil;
private readonly HashSet<string> extensions;
private readonly GraphicsBackend backend;
private readonly int major;
Expand Down Expand Up @@ -90,6 +91,13 @@ internal OpenGLExtensions(HashSet<string> extensions, GraphicsBackend backend, i
ArbUniformBufferObject = IsExtensionSupported("GL_ARB_uniform_buffer_object");

AnisotropicFilter = IsExtensionSupported("GL_EXT_texture_filter_anisotropic") || IsExtensionSupported("GL_ARB_texture_filter_anisotropic");

// D24_UNorm_S8_UInt (GL_DEPTH24_STENCIL8) is core in GL 3.0+ and GLES 3.0+.
// On desktop GL 2.x, GL_ARB_framebuffer_object provides it.
// On GLES 2.x, it requires the GL_OES_packed_depth_stencil extension.
OesPackedDepthStencil = GLVersion(3, 0) || GLESVersion(3, 0)
|| IsExtensionSupported("GL_ARB_framebuffer_object")
|| IsExtensionSupported("GL_OES_packed_depth_stencil");
}

/// <summary>
Expand Down
5 changes: 5 additions & 0 deletions src/Veldrid/OpenGL/OpenGLFormats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,11 @@ internal static bool IsFormatSupported(OpenGLExtensions extensions, PixelFormat
case PixelFormat.R10G10B10A2UNorm:
return backend == GraphicsBackend.OpenGL;

case PixelFormat.D24UNormS8UInt:
return extensions.GLVersion(3, 0) || extensions.GLESVersion(3, 0)
|| extensions.IsExtensionSupported("GL_OES_packed_depth_stencil")
|| extensions.IsExtensionSupported("GL_ARB_framebuffer_object");

default:
return true;
}
Expand Down
29 changes: 28 additions & 1 deletion src/Veldrid/OpenGL/OpenGLGraphicsDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,29 @@ private static int getDepthBits(PixelFormat value)
case PixelFormat.R32Float:
return 32;

case PixelFormat.D24UNormS8UInt:
return 24;

case PixelFormat.D32FloatS8UInt:
return 32;

default:
throw new VeldridException($"Unsupported depth format: {value}");
}
}

private static int getStencilBits(PixelFormat value)
{
switch (value)
{
case PixelFormat.D24UNormS8UInt:
case PixelFormat.D32FloatS8UInt:
return 8;

case PixelFormat.R16UNorm:
case PixelFormat.R32Float:
return 0;

default:
throw new VeldridException($"Unsupported depth format: {value}");
}
Expand Down Expand Up @@ -750,7 +773,7 @@ private void initializeANativeWindow(
IntPtr aNativeWindow,
SwapchainDescription swapchainDescription)
{
IntPtr display = eglGetDisplay(0);
IntPtr display = eglGetDisplay(IntPtr.Zero);
if (display == IntPtr.Zero) throw new VeldridException($"Failed to get the default Android EGLDisplay: {eglGetError()}");

int major, minor;
Expand All @@ -766,6 +789,10 @@ private void initializeANativeWindow(
swapchainDescription.DepthFormat != null
? getDepthBits(swapchainDescription.DepthFormat.Value)
: 0,
EGL_STENCIL_SIZE,
swapchainDescription.DepthFormat != null
? getStencilBits(swapchainDescription.DepthFormat.Value)
: 0,
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES3_BIT,
EGL_NONE
Expand Down
20 changes: 18 additions & 2 deletions src/Veldrid/OpenGL/OpenGLTexture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,15 @@ public OpenGLTexture(OpenGLGraphicsDevice gd, ref TextureDescription description
Width = description.Width;
Height = description.Height;
Depth = description.Depth;
Format = description.Format;

if (description.Format == PixelFormat.D24UNormS8UInt && !gd.Extensions.OesPackedDepthStencil) {
Console.WriteLine(
"[Veldrid] GL_OES_packed_depth_stencil not available — downgrading D24_UNorm_S8_UInt to D32_Float_S8_UInt");
Format = PixelFormat.D32FloatS8UInt;
}
else {
Format = description.Format;
}
MipLevels = description.MipLevels;
ArrayLayers = description.ArrayLayers;
Usage = description.Usage;
Expand Down Expand Up @@ -115,7 +123,15 @@ public OpenGLTexture(OpenGLGraphicsDevice gd, uint nativeTexture, ref TextureDes
Width = description.Width;
Height = description.Height;
Depth = description.Depth;
Format = description.Format;

if (description.Format == PixelFormat.D24UNormS8UInt && !gd.Extensions.OesPackedDepthStencil) {
Console.WriteLine(
"[Veldrid] GL_OES_packed_depth_stencil not available — downgrading D24_UNorm_S8_UInt to D32_Float_S8_UInt");
Format = PixelFormat.D32FloatS8UInt;
}
else {
Format = description.Format;
}
MipLevels = description.MipLevels;
ArrayLayers = description.ArrayLayers;
Usage = description.Usage;
Expand Down
Loading