Skip to content

Commit

Permalink
Miscellaneous windowing fixes (#27)
Browse files Browse the repository at this point in the history
* Start experimenting with a basic triangle program.

* Some more work

* Include error code in exception message

* Remove MakeCurrent

* Add a WindowBuilder

* Implement the dispatcher ourselves for Update and Render only

* Fix the current context bug

* Allow invocation on the main thread from the main thread

* Invoke within VSync setter

* Fix a NRE, assign everything, and remove initialOptions

* Fix an InvalidOperationException

* Actually fix it :P

* Remove the double assignment of UseSingleThreadedWindow

* Continue with triangle example

* Delete WindowBuilder.cs

* Run a Using cleanup on the entire project
  • Loading branch information
Perksey authored Jul 31, 2019
1 parent 9107c96 commit eef0280
Show file tree
Hide file tree
Showing 20 changed files with 6,456 additions and 6,309 deletions.
15 changes: 15 additions & 0 deletions Silk.NET.sln
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Silk.NET.OpenGLES.Extension
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Core", "Core", "{0651C5EF-50AA-4598-8D9C-8F210ADD8490}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Triangle", "examples\Triangle\Triangle.csproj", "{3478F392-7055-4ECC-B388-7F115AA7EA5A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -1030,6 +1032,18 @@ Global
{8D534FE1-6113-457A-97DD-FD42782580A5}.Release|x64.Build.0 = Release|Any CPU
{8D534FE1-6113-457A-97DD-FD42782580A5}.Release|x86.ActiveCfg = Release|Any CPU
{8D534FE1-6113-457A-97DD-FD42782580A5}.Release|x86.Build.0 = Release|Any CPU
{3478F392-7055-4ECC-B388-7F115AA7EA5A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3478F392-7055-4ECC-B388-7F115AA7EA5A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3478F392-7055-4ECC-B388-7F115AA7EA5A}.Debug|x64.ActiveCfg = Debug|Any CPU
{3478F392-7055-4ECC-B388-7F115AA7EA5A}.Debug|x64.Build.0 = Debug|Any CPU
{3478F392-7055-4ECC-B388-7F115AA7EA5A}.Debug|x86.ActiveCfg = Debug|Any CPU
{3478F392-7055-4ECC-B388-7F115AA7EA5A}.Debug|x86.Build.0 = Debug|Any CPU
{3478F392-7055-4ECC-B388-7F115AA7EA5A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3478F392-7055-4ECC-B388-7F115AA7EA5A}.Release|Any CPU.Build.0 = Release|Any CPU
{3478F392-7055-4ECC-B388-7F115AA7EA5A}.Release|x64.ActiveCfg = Release|Any CPU
{3478F392-7055-4ECC-B388-7F115AA7EA5A}.Release|x64.Build.0 = Release|Any CPU
{3478F392-7055-4ECC-B388-7F115AA7EA5A}.Release|x86.ActiveCfg = Release|Any CPU
{3478F392-7055-4ECC-B388-7F115AA7EA5A}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{BFE429EB-4C2E-4BF3-A302-C9C5A2FDA6D7} = {23324041-2076-477C-A4BF-B385B8066C6C}
Expand Down Expand Up @@ -1104,5 +1118,6 @@ Global
{8D534FE1-6113-457A-97DD-FD42782580A5} = {CF69D5C3-4ACE-4458-BA5A-0E9A3B294CDC}
{FD24E9FF-1097-4777-A418-F2D88C558665} = {0651C5EF-50AA-4598-8D9C-8F210ADD8490}
{136C6154-D300-4B82-80D3-17B637841A2B} = {0651C5EF-50AA-4598-8D9C-8F210ADD8490}
{3478F392-7055-4ECC-B388-7F115AA7EA5A} = {E1F91563-7277-4E9B-A3B7-8D5FD9802A4A}
EndGlobalSection
EndGlobal
1,790 changes: 895 additions & 895 deletions build/binder_specifications/GLES.json

Large diffs are not rendered by default.

7,046 changes: 3,523 additions & 3,523 deletions build/binder_specifications/OpenGL (Compatibility Profile).json

Large diffs are not rendered by default.

3,650 changes: 1,825 additions & 1,825 deletions build/binder_specifications/OpenGL.json

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions examples/BlankWindow/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ private static void Main()

window = Window.Create(options);

window.MakeCurrent();

window.OnFileDrop += OnFileDrop;
window.OnMove += OnMove;
window.OnResize += OnResize;
Expand Down
70 changes: 70 additions & 0 deletions examples/Triangle/Game.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// This file is part of Silk.NET.
//
// You may modify and distribute Silk.NET under the terms
// of the MIT license. See the LICENSE file for details.

using System.Drawing;
using Silk.NET.OpenGL;
using Silk.NET.Windowing;
using Silk.NET.Windowing.Common;

namespace Triangle
{
public unsafe class Game
{
private IWindow window;
private GL gl;

private uint vbo;
private uint vao;

private float[] vertices = {
-0.5f, -0.5f, 0.0f, //Bottom-left vertex
0.5f, -0.5f, 0.0f, //Bottom-right vertex
0.0f, 0.5f, 0.0f //Top vertex
};

public Game()
{
var options = WindowOptions.Default;

options.UseSingleThreadedWindow = false;

window = Window.Create(options);

window.OnLoad += OnLoad;
window.OnRender += OnRender;
window.OnResize += OnResize;

gl = GL.GetApi();
}

public void Run()
{
window.Run();
}

public void OnLoad()
{
gl.ClearColor(1.0f, 0.4f, 0.3f, 1.0f);

vbo = gl.GenBuffer(1);
gl.BindBuffer((int)GLEnum.ArrayBuffer, vbo);

//var size = (uint)vertices.Length * sizeof(float);
//gl.BufferData((int)GLEnum.ArrayBuffer, new UIntPtr(size), vertices, (int)GLEnum.StaticDraw);
}

public void OnRender(double delta)
{
gl.Clear((uint)GLEnum.ColorBufferBit);

window.SwapBuffers();
}

public void OnResize(Size size)
{
gl.Viewport(0, 0, (uint)size.Width, (uint)size.Height);
}
}
}
11 changes: 11 additions & 0 deletions examples/Triangle/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace Triangle
{
internal class Program
{
private static void Main()
{
var game = new Game();
game.Run();
}
}
}
14 changes: 14 additions & 0 deletions examples/Triangle/Triangle.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\OpenGL\Silk.NET.OpenGL\Silk.NET.OpenGL.csproj" />
<ProjectReference Include="..\..\src\Windowing\Silk.NET.Windowing\Silk.NET.Windowing.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// You may modify and distribute Silk.NET under the terms
// of the MIT license. See the LICENSE file for details.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// You may modify and distribute Silk.NET under the terms
// of the MIT license. See the LICENSE file for details.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// You may modify and distribute Silk.NET under the terms
// of the MIT license. See the LICENSE file for details.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand Down
3 changes: 0 additions & 3 deletions src/Core/BuildTools/Bind/ProfileWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,9 @@
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Xml.Linq;
using MoreLinq.Extensions;
using Silk.NET.BuildTools.Bind.Overloading;
using Silk.NET.BuildTools.Common;
using Silk.NET.BuildTools.Common.Functions;
using Silk.NET.BuildTools.Convert.XML;
using Enum = Silk.NET.BuildTools.Common.Enums.Enum;

namespace Silk.NET.BuildTools.Bind
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
using System.Linq;
using System.Xml.Linq;
using JetBrains.Annotations;
using Newtonsoft.Json;
using Silk.NET.BuildTools.Common;
using Silk.NET.BuildTools.Common.Enums;
using Silk.NET.BuildTools.Common.Functions;
Expand Down
1 change: 0 additions & 1 deletion src/OpenGL/Silk.NET.OpenGL.Legacy/GL.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Drawing;
using System.Numerics;
using System.Runtime.InteropServices;
using Silk.NET.Core.Loader;
using Silk.NET.Core.Native;

Expand Down
2 changes: 1 addition & 1 deletion src/Windowing/Silk.NET.GLFW/Glfw.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ protected Glfw(string path, ImplementationOptions options)
/// </summary>
/// <seealso cref="SetErrorCallback" />
public static GlfwCallbacks.ErrorCallback ErrorCallback { get; } = (errorCode, description) =>
throw new GlfwException(description) {ErrorCode = errorCode};
throw new GlfwException($"{errorCode}: {description}") {ErrorCode = errorCode};

public override SearchPathContainer SearchPaths { get; } = new GlfwLibraryNameContainer();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,6 @@ public interface IWindowFunctions
/// </summary>
void SwapBuffers();

/// <summary>
/// Makes this window's rendering API current for the calling thread.
/// </summary>
void MakeCurrent();

/// <summary>
/// Converts this point to client coordinates.
/// </summary>
Expand Down
22 changes: 22 additions & 0 deletions src/Windowing/Silk.NET.Windowing.Common/WindowExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// This file is part of Silk.NET.
//
// You may modify and distribute Silk.NET under the terms
// of the MIT license. See the LICENSE file for details.

using System;

namespace Silk.NET.Windowing.Common
{
public static class WindowExtensions
{
public static T Invoke<T>(this IWindow window, Func<T> t)
{
return (T) window.Invoke(t);
}

public static void Invoke(this IWindow window, Action t)
{
window.Invoke(t);
}
}
}
2 changes: 1 addition & 1 deletion src/Windowing/Silk.NET.Windowing.Common/WindowOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public WindowOptions(bool isVisible, bool useSingleThreadedWindow, Point positio
/// <summary>
/// Convinience wrapper around creating a new WindowProperties with the default values.
/// </summary>
public static WindowOptions Default { get; } = new WindowOptions(true, true, new Point(-1, -1),
public static WindowOptions Default { get; } = new WindowOptions(true, true, new Point(50, 50),
new Size(1280, 720), 0.0, 0.0, GraphicsAPI.Default,
"Silk.NET Window", WindowState.Normal, WindowBorder.Resizable, VSyncMode.On, 5);
}
Expand Down
3 changes: 1 addition & 2 deletions src/Windowing/Silk.NET.Windowing.Desktop/GlfwPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// You may modify and distribute Silk.NET under the terms
// of the MIT license. See the LICENSE file for details.

using System.IO;
using Silk.NET.GLFW;
using Silk.NET.Windowing.Common;

Expand All @@ -22,7 +21,7 @@ public bool IsApplicable
try {
Glfw.GetAPI(); // activate the class so we can determine if we can activate the class
}
catch (FileNotFoundException) {
catch {
return false;
}

Expand Down
Loading

0 comments on commit eef0280

Please sign in to comment.