Skip to content

Commit

Permalink
Enable all tests for OpenGL ES.
Browse files Browse the repository at this point in the history
  • Loading branch information
mellinoe committed Apr 6, 2018
1 parent 2889a11 commit 2edc075
Show file tree
Hide file tree
Showing 9 changed files with 102 additions and 7 deletions.
5 changes: 5 additions & 0 deletions src/Veldrid.Tests/BufferTests.cs
Expand Up @@ -450,7 +450,12 @@ private DeviceBuffer GetReadback(DeviceBuffer buffer)
}
}

#if TEST_OPENGL
public class OpenGLBufferTests : BufferTestBase<OpenGLDeviceCreator> { }
#endif
#if TEST_OPENGLES
public class OpenGLESBufferTests : BufferTestBase<OpenGLESDeviceCreator> { }
#endif
#if TEST_VULKAN
public class VulkanBufferTests : BufferTestBase<VulkanDeviceCreator> { }
#endif
Expand Down
6 changes: 6 additions & 0 deletions src/Veldrid.Tests/FramebufferTests.cs
Expand Up @@ -98,8 +98,14 @@ public void ClearSwapchainFramebuffer_Succeeds()
}
}

#if TEST_OPENGL
public class OpenGLFramebufferTests : FramebufferTests<OpenGLDeviceCreator> { }
public class OpenGLSwapchainFramebufferTests : SwapchainFramebufferTests<OpenGLDeviceCreator> { }
#endif
#if TEST_OPENGLES
public class OpenGLESFramebufferTests : FramebufferTests<OpenGLESDeviceCreator> { }
public class OpenGLESSwapchainFramebufferTests : SwapchainFramebufferTests<OpenGLESDeviceCreator> { }
#endif
#if TEST_VULKAN
public class VulkanFramebufferTests : FramebufferTests<VulkanDeviceCreator> { }
public class VulkanSwapchainFramebufferTests : SwapchainFramebufferTests<VulkanDeviceCreatorWithMainSwapchain> { }
Expand Down
18 changes: 14 additions & 4 deletions src/Veldrid.Tests/RenderTests.cs
Expand Up @@ -133,7 +133,7 @@ public void Points_WithUIntColor()
{
uint x = (uint)vertex.Position.X;
uint y = (uint)vertex.Position.Y;
if (GD.BackendType == GraphicsBackend.OpenGL)
if (HasInvertedY(GD.BackendType))
{
y = framebuffer.Height - y - 1;
}
Expand Down Expand Up @@ -255,7 +255,7 @@ public void Points_WithUShortNormColor()
{
uint x = (uint)vertex.Position.X;
uint y = (uint)vertex.Position.Y;
if (GD.BackendType == GraphicsBackend.OpenGL)
if (HasInvertedY(GD.BackendType))
{
y = framebuffer.Height - y - 1;
}
Expand Down Expand Up @@ -406,7 +406,7 @@ public void Points_WithUShortColor()
{
uint x = (uint)vertex.Position.X;
uint y = (uint)vertex.Position.Y;
if (GD.BackendType == GraphicsBackend.OpenGL)
if (HasInvertedY(GD.BackendType))
{
y = framebuffer.Height - y - 1;
}
Expand Down Expand Up @@ -535,7 +535,7 @@ public unsafe void Points_WithTexture_UpdateUnrelated()
{
uint x = (uint)vertex.X;
uint y = (uint)vertex.Y;
if (GD.BackendType == GraphicsBackend.OpenGL)
if (HasInvertedY(GD.BackendType))
{
y = framebuffer.Height - y - 1;
}
Expand All @@ -544,9 +544,19 @@ public unsafe void Points_WithTexture_UpdateUnrelated()
}
GD.Unmap(staging);
}

private bool HasInvertedY(GraphicsBackend backendType)
{
return backendType == GraphicsBackend.OpenGL || backendType == GraphicsBackend.OpenGLES;
}
}

#if TEST_OPENGL
public class OpenGLRenderTests : RenderTests<OpenGLDeviceCreator> { }
#endif
#if TEST_OPENGLES
public class OpenGLESRenderTests : RenderTests<OpenGLESDeviceCreator> { }
#endif
#if TEST_VULKAN
public class VulkanRenderTests : RenderTests<VulkanDeviceCreator> { }
#endif
Expand Down
5 changes: 5 additions & 0 deletions src/Veldrid.Tests/ResourceSetTests.cs
Expand Up @@ -80,7 +80,12 @@ public void ResourceSet_TooFewOrTooManyElements_Fails()
}
}

#if TEST_OPENGL
public class OpenGLResourceSetTests : ResourceSetTests<OpenGLDeviceCreator> { }
#endif
#if TEST_OPENGLES
public class OpenGLESResourceSetTests : ResourceSetTests<OpenGLESDeviceCreator> { }
#endif
#if TEST_VULKAN
public class VulkanResourceSetTests : ResourceSetTests<VulkanDeviceCreator> { }
#endif
Expand Down
1 change: 1 addition & 0 deletions src/Veldrid.Tests/TestShaders.cs
Expand Up @@ -22,6 +22,7 @@ private static string GetShaderExtension(GraphicsBackend backend)
case GraphicsBackend.Direct3D11: return "hlsl.bytes";
case GraphicsBackend.Vulkan: return "450.glsl.spv";
case GraphicsBackend.OpenGL: return "330.glsl";
case GraphicsBackend.OpenGLES: return "300.glsles";
case GraphicsBackend.Metal: return "metallib";
default: throw new InvalidOperationException();
}
Expand Down
29 changes: 29 additions & 0 deletions src/Veldrid.Tests/TestUtils.cs
Expand Up @@ -98,6 +98,27 @@ internal static void CreateOpenGLDevice(out Sdl2Window window, out GraphicsDevic
VeldridStartup.CreateWindowAndGraphicsDevice(wci, options, GraphicsBackend.OpenGL, out window, out gd);
}

internal static void CreateOpenGLESDevice(out Sdl2Window window, out GraphicsDevice gd)
{
if (!InitializedSdl2)
{
window = null;
gd = null;
return;
}

WindowCreateInfo wci = new WindowCreateInfo
{
WindowWidth = 200,
WindowHeight = 200,
WindowInitialState = WindowState.Hidden,
};

GraphicsDeviceOptions options = new GraphicsDeviceOptions(true, PixelFormat.R16_UNorm, false);

VeldridStartup.CreateWindowAndGraphicsDevice(wci, options, GraphicsBackend.OpenGLES, out window, out gd);
}

public static GraphicsDevice CreateMetalDevice()
{
return GraphicsDevice.CreateMetal(new GraphicsDeviceOptions(true));
Expand Down Expand Up @@ -208,6 +229,14 @@ public unsafe void CreateGraphicsDevice(out Sdl2Window window, out GraphicsDevic
}
}

public class OpenGLESDeviceCreator : GraphicsDeviceCreator
{
public unsafe void CreateGraphicsDevice(out Sdl2Window window, out GraphicsDevice gd)
{
TestUtils.CreateOpenGLESDevice(out window, out gd);
}
}

public class MetalDeviceCreator : GraphicsDeviceCreator
{
public unsafe void CreateGraphicsDevice(out Sdl2Window window, out GraphicsDevice gd)
Expand Down
33 changes: 33 additions & 0 deletions src/Veldrid.Tests/TextureTests.cs
Expand Up @@ -313,6 +313,10 @@ public unsafe void MapWrite_ThenMapRead_3D()
[Fact]
public unsafe void Update_ThenMapRead_1D()
{
// 1D textures not supported in OpenGLES.
// TODO: Capability API for this.
if (GD.BackendType == GraphicsBackend.OpenGLES) { return; }

Texture tex1D = RF.CreateTexture(
TextureDescription.Texture1D(100, 1, 1, PixelFormat.R16_UNorm, TextureUsage.Staging));
ushort[] data = Enumerable.Range(0, (int)tex1D.Width).Select(i => (ushort)(i * 2)).ToArray();
Expand All @@ -332,6 +336,10 @@ public unsafe void Update_ThenMapRead_1D()
[Fact]
public unsafe void MapWrite_ThenMapRead_1D()
{
// 1D textures not supported in OpenGLES.
// TODO: Capability API for this.
if (GD.BackendType == GraphicsBackend.OpenGLES) { return; }

Texture tex1D = RF.CreateTexture(
TextureDescription.Texture1D(100, 1, 1, PixelFormat.R16_UNorm, TextureUsage.Staging));

Expand All @@ -354,6 +362,10 @@ public unsafe void MapWrite_ThenMapRead_1D()
[Fact]
public unsafe void Copy_1DTo2D()
{
// 1D textures not supported in OpenGLES.
// TODO: Capability API for this.
if (GD.BackendType == GraphicsBackend.OpenGLES) { return; }

Texture tex1D = RF.CreateTexture(
TextureDescription.Texture1D(100, 1, 1, PixelFormat.R16_UNorm, TextureUsage.Staging));
Texture tex2D = RF.CreateTexture(
Expand Down Expand Up @@ -389,6 +401,10 @@ public unsafe void Copy_1DTo2D()
[Fact]
public void Update_MultipleMips_1D()
{
// 1D textures not supported in OpenGLES.
// TODO: Capability API for this.
if (GD.BackendType == GraphicsBackend.OpenGLES) { return; }

Texture tex1D = RF.CreateTexture(TextureDescription.Texture1D(
100, 5, 1, PixelFormat.R8_G8_B8_A8_UNorm, TextureUsage.Staging));

Expand Down Expand Up @@ -416,6 +432,10 @@ public void Update_MultipleMips_1D()
[Fact]
public void Copy_DifferentMip_1DTo2D()
{
// 1D textures not supported in OpenGLES.
// TODO: Capability API for this.
if (GD.BackendType == GraphicsBackend.OpenGLES) { return; }

Texture tex1D = RF.CreateTexture(
TextureDescription.Texture1D(200, 2, 1, PixelFormat.R16_UNorm, TextureUsage.Staging));
Texture tex2D = RF.CreateTexture(
Expand Down Expand Up @@ -702,6 +722,14 @@ public unsafe void Copy_NonSquareTexture()
uint dstX, uint dstY, uint dstZ,
uint dstMipLevel, uint dstArrayLayer)
{

// TODO: There should be a capability API that describes the support level for a PixelFormat.
if (GD.BackendType == GraphicsBackend.OpenGLES
&& (format == PixelFormat.R10_G10_B10_A2_UInt || format == PixelFormat.R10_G10_B10_A2_UNorm))
{
return;
}

Texture srcTex = RF.CreateTexture(new TextureDescription(
srcWidth, srcHeight, srcDepth, srcMipLevels, srcArrayLayers,
format, TextureUsage.Staging, srcType));
Expand Down Expand Up @@ -867,5 +895,10 @@ public class D3D11TextureTests : TextureTestBase<D3D11DeviceCreator> { }
#if TEST_METAL
public class MetalTextureTests : TextureTestBase<MetalDeviceCreator> { }
#endif
#if TEST_OPENGL
public class OpenGLTextureTests : TextureTestBase<OpenGLDeviceCreator> { }
#endif
#if TEST_OPENGLES
public class OpenGLESTextureTests : TextureTestBase<OpenGLESDeviceCreator> { }
#endif
}
6 changes: 3 additions & 3 deletions src/Veldrid.Tests/Veldrid.Tests.csproj
Expand Up @@ -5,9 +5,9 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<IsPackable>false</IsPackable>
<OutputType>exe</OutputType>
<DefineConstants Condition="'$(IsWindows)' == 'true'">$(DefineConstants);TEST_D3D11;TEST_VULKAN</DefineConstants>
<DefineConstants Condition="'$(IsLinux)' == 'true'">$(DefineConstants);TEST_VULKAN</DefineConstants>
<DefineConstants Condition="'$(IsMacOS)' == 'true'">$(DefineConstants);TEST_METAL</DefineConstants>
<DefineConstants Condition="'$(IsWindows)' == 'true'">$(DefineConstants);TEST_D3D11;TEST_VULKAN;TEST_OPENGL;TEST_OPENGLES</DefineConstants>
<DefineConstants Condition="'$(IsLinux)' == 'true'">$(DefineConstants);TEST_VULKAN;TEST_OPENGL;TEST_OPENGLES</DefineConstants>
<DefineConstants Condition="'$(IsMacOS)' == 'true'">$(DefineConstants);TEST_METAL;TEST_OPENGL</DefineConstants>
<StartupObject>Program</StartupObject>
<ShaderOutputPath>$(BaseIntermediateOutputPath)Shaders</ShaderOutputPath>
<ShaderContentIncludePath>Shaders</ShaderContentIncludePath>
Expand Down
6 changes: 6 additions & 0 deletions src/Veldrid/OpenGL/OpenGLTexture.cs
Expand Up @@ -23,6 +23,12 @@ internal unsafe class OpenGLTexture : Texture, OpenGLDeferredResource

public OpenGLTexture(OpenGLGraphicsDevice gd, ref TextureDescription description)
{
// TODO CAPABILITY
if (description.Type == TextureType.Texture1D && gd.BackendType == GraphicsBackend.OpenGLES)
{
throw new VeldridException($"1D Textures are not supported by OpenGL ES.");
}

_gd = gd;

Width = description.Width;
Expand Down

0 comments on commit 2edc075

Please sign in to comment.