Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gtk: GLArea tweaks #23

Merged
merged 5 commits into from
Jun 18, 2024
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
17 changes: 7 additions & 10 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ jobs:
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 3.1.101

- name: Setup msbuild
uses: microsoft/setup-msbuild@v1
dotnet-version: '5.0.x'

- uses: actions/cache@v1
with:
Expand All @@ -40,10 +37,10 @@ jobs:
${{ runner.os }}-nuget-

- name: Build
run: msbuild /restore ${{ env.PlatformBuildParameters }} ${{ env.BuildParameters }}
run: dotnet build ${{ env.PlatformBuildParameters }} ${{ env.BuildParameters }}

- name: Pack
run: msbuild /t:Pack ${{ env.PlatformBuildParameters }} ${{ env.BuildParameters }}
run: dotnet pack ${{ env.PlatformBuildParameters }} ${{ env.BuildParameters }}

- name: Upload artifacts
uses: actions/upload-artifact@v2
Expand All @@ -64,10 +61,10 @@ jobs:
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 3.1.101
dotnet-version: '5.0.x'

- name: setup-xamarin
uses: maxim-lobanov/setup-xamarin@v1.1
uses: maxim-lobanov/setup-xamarin@v1
with:
mono-version: latest
xamarin-mac-version: latest
Expand All @@ -81,10 +78,10 @@ jobs:
${{ runner.os }}-nuget-

- name: Build
run: msbuild /restore ${{ env.PlatformBuildParameters }} ${{ env.BuildParameters }}
run: dotnet build ${{ env.PlatformBuildParameters }} ${{ env.BuildParameters }}

- name: Pack
run: msbuild /t:Pack ${{ env.PlatformBuildParameters }} ${{ env.BuildParameters }}
run: dotnet pack ${{ env.PlatformBuildParameters }} ${{ env.BuildParameters }}

# - name: Upload artifacts
# uses: actions/upload-artifact@v2
Expand Down
14 changes: 7 additions & 7 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
"preLaunchTask": "build",
"program": "",
"osx": {
"program": "${workspaceFolder}/artifacts/bin/TestEtoVeldrid.Mac64/Debug/netcoreapp3.1/osx-x64/TestEtoVeldrid.Mac64.app/Contents/MacOS/TestEtoVeldrid.Mac64"
"program": "${workspaceFolder}/artifacts/bin/TestEtoVeldrid.Mac64/Debug/net5.0/osx-x64/TestEtoVeldrid.Mac64.app/Contents/MacOS/TestEtoVeldrid.Mac64"
},
"linux": {
"program": "${workspaceFolder}/artifacts/bin/TestEtoVeldrid.Gtk/Debug/netcoreapp3.1/linux-x64/TestEtoVeldrid.Gtk.dll"
"program": "${workspaceFolder}/artifacts/bin/TestEtoVeldrid.Gtk/Debug/net5.0/linux-x64/TestEtoVeldrid.Gtk.dll"
},
"windows": {
"program": "${workspaceFolder}/artifacts/bin/TestEtoVeldrid.Wpf/Debug/netcoreapp3.1/win-x64/TestEtoVeldrid.Wpf.dll"
"program": "${workspaceFolder}/artifacts/bin/TestEtoVeldrid.Wpf/Debug/net5.0-windows/win-x64/TestEtoVeldrid.Wpf.dll"
},
"console": "internalConsole",
"stopAtEntry": false
Expand All @@ -29,11 +29,11 @@
"preLaunchTask": "build",
"program": "",
"osx": {
"program": "${workspaceFolder}/artifacts/bin/TestEtoVeldrid.Mac64/Debug/net472/osx-x64/TestEtoVeldrid.Mac64.app/Contents/MacOS/TestEtoVeldrid.Mac64",
"program": "${workspaceFolder}/artifacts/bin/TestEtoVeldrid.Mac64/Debug/net48/osx-x64/TestEtoVeldrid.Mac64.app/Contents/MacOS/TestEtoVeldrid.Mac64",
"useRuntime": false
},
"linux": {
"program": "${workspaceFolder}/artifacts/bin/TestEtoVeldrid.Gtk/Debug/net472/linux-x64/TestEtoVeldrid.Gtk.exe"
"program": "${workspaceFolder}/artifacts/bin/TestEtoVeldrid.Gtk/Debug/net48/linux-x64/TestEtoVeldrid.Gtk.exe"
},
"console": "internalConsole"
},
Expand All @@ -44,7 +44,7 @@
"preLaunchTask": "build",
"program": "",
"windows": {
"program": "${workspaceFolder}/artifacts/bin/TestEtoVeldrid.Wpf/Debug/net472/win-x64/TestEtoVeldrid.Wpf.exe"
"program": "${workspaceFolder}/artifacts/bin/TestEtoVeldrid.Wpf/Debug/net48/win-x64/TestEtoVeldrid.Wpf.exe"
},
"console": "internalConsole"
},
Expand All @@ -55,7 +55,7 @@
"preLaunchTask": "build",
"program": "",
"windows": {
"program": "${workspaceFolder}/artifacts/bin/TestEtoVeldrid.WinForms/Debug/net472/win-x64/TestEtoVeldrid.WinForms.exe"
"program": "${workspaceFolder}/artifacts/bin/TestEtoVeldrid.WinForms/Debug/net48/win-x64/TestEtoVeldrid.WinForms.exe"
},
"console": "internalConsole"
},
Expand Down
2 changes: 1 addition & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{
"label": "build",
"command": "dotnet",
"type": "process",
"type": "shell",
"osx": {
"args": [
"build",
Expand Down
5 changes: 2 additions & 3 deletions src/Eto.Veldrid.Gtk/Eto.Veldrid.Gtk.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net461;netcoreapp3.1</TargetFrameworks>
<TargetFrameworks>netcoreapp3.1;net461</TargetFrameworks>
<DefineConstants>GTK3</DefineConstants>
<Title>Veldrid Gtk implementation for Eto.Forms</Title>
<Description>This provides the Gtk implementation of Eto.Veldrid for Eto.Forms</Description>
Expand All @@ -13,8 +13,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Eto.Platform.Gtk" Version="2.5.1" />
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.0" PrivateAssets="all" />
<PackageReference Include="Eto.Platform.Gtk" Version="2.5.9" />
</ItemGroup>

<ItemGroup>
Expand Down
19 changes: 0 additions & 19 deletions src/Eto.Veldrid.Gtk/GtkVeldridDrawingArea.cs

This file was deleted.

92 changes: 78 additions & 14 deletions src/Eto.Veldrid.Gtk/GtkVeldridSurfaceHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,18 @@

namespace Eto.Veldrid.Gtk
{
public class GtkVeldridSurfaceHandler : GtkControl<GtkVeldridDrawingArea, VeldridSurface, VeldridSurface.ICallback>, VeldridSurface.IHandler, VeldridSurface.IOpenGL
public class GtkVeldridSurfaceHandler : GtkControl<EtoEventBox, VeldridSurface, VeldridSurface.ICallback>, VeldridSurface.IHandler, VeldridSurface.IOpenGL
{
GLArea glArea;
public Size RenderSize => Size.Round((SizeF)Widget.Size * Scale);

float Scale => Widget.ParentWindow?.LogicalPixelSize ?? 1;
float Scale => Widget.ParentWindow?.Screen?.LogicalPixelSize ?? 1;

public override global::Gtk.Widget ContainerContentControl => glArea ?? base.ContainerContentControl;

public GtkVeldridSurfaceHandler()
{
Control = new GtkVeldridDrawingArea();

Control.Render += Control_InitializeGraphicsBackend;
Control = new EtoEventBox { Handler = this };
}

public Swapchain CreateSwapchain()
Expand Down Expand Up @@ -56,25 +57,44 @@ public Swapchain CreateSwapchain()
return swapchain;
}

void Control_InitializeGraphicsBackend(object o, RenderArgs args)
void glArea_InitializeGraphicsBackend(object sender, EventArgs e)
{
glArea.Context.MakeCurrent();
Callback.OnInitializeBackend(Widget, new InitializeEventArgs(RenderSize));

Control.Render -= Control_InitializeGraphicsBackend;
Control.Render += Control_Render;
Widget.SizeChanged += Widget_SizeChanged;
glArea.Render += glArea_Render;
glArea.Resize += glArea_Resize;
}

private void Widget_SizeChanged(object sender, EventArgs e) => Callback.OnResize(Widget, new ResizeEventArgs(RenderSize));
void Control_InitializeGraphicsBackend(object sender, EventArgs e)
{
Callback.OnInitializeBackend(Widget, new InitializeEventArgs(RenderSize));
}

void Control_Render(object o, RenderArgs args) => Callback.OnDraw(Widget, args);
bool skipDraw;

private void glArea_Resize(object o, ResizeArgs args)
{
skipDraw = false;
Callback.OnResize(Widget, new ResizeEventArgs(RenderSize));
}

void glArea_Render(object o, RenderArgs args)
{
if (!skipDraw)
{
skipDraw = true;
Callback.OnDraw(Widget, EventArgs.Empty);
}
skipDraw = false;
}

// TODO: Figure this one out! The docstring for this property in Veldrid's OpenGLPlatformInfo is ambiguous.
IntPtr VeldridSurface.IOpenGL.OpenGLContextHandle => ((VeldridSurface.IOpenGL)this).GetCurrentContext();
IntPtr VeldridSurface.IOpenGL.OpenGLContextHandle => glArea?.Context.Handle ?? IntPtr.Zero;

IntPtr VeldridSurface.IOpenGL.GetProcAddress(string name) => X11Interop.glXGetProcAddress(name);

void VeldridSurface.IOpenGL.MakeCurrent(IntPtr context) => Control.MakeCurrent();
void VeldridSurface.IOpenGL.MakeCurrent(IntPtr context) => glArea?.MakeCurrent();

IntPtr VeldridSurface.IOpenGL.GetCurrentContext() => Gdk.GLContext.Current.Handle;

Expand All @@ -86,7 +106,12 @@ void VeldridSurface.IOpenGL.DeleteContext(IntPtr context)

void VeldridSurface.IOpenGL.SwapBuffers()
{
// This happens automatically in GLArea, so no need to do anything.
// GLArea doesn't support drawing directly, so we queue a render but don't actually call OnDraw
if (skipDraw)
return;

skipDraw = true;
glArea?.QueueRender();
}

void VeldridSurface.IOpenGL.SetSyncToVerticalBlank(bool on)
Expand All @@ -100,5 +125,44 @@ void VeldridSurface.IOpenGL.SetSwapchainFramebuffer()
void VeldridSurface.IOpenGL.ResizeSwapchain(uint width, uint height)
{
}

void Eto.Forms.Control.IHandler.Invalidate(Rectangle rect, bool invalidateChildren)
{
skipDraw = false;
glArea?.QueueRender();
}

void Eto.Forms.Control.IHandler.Invalidate(bool invalidateChildren)
{
skipDraw = false;
glArea?.QueueRender();
}


protected override void Initialize()
{
base.Initialize();

if (Widget.Backend == GraphicsBackend.OpenGL)
{
glArea = new GLArea();
glArea.CanFocus = true;

// Veldrid technically supports as low as OpenGL 3.0, but the full
// complement of features is only available with 3.3 and higher.
glArea.SetRequiredVersion(3, 3);

glArea.HasDepthBuffer = true;
glArea.HasStencilBuffer = true;
Control.Child = glArea;
glArea.Realized += glArea_InitializeGraphicsBackend;
}
else
{
Control.CanFocus = true;
Control.Realized += Control_InitializeGraphicsBackend;
}

}
}
}
4 changes: 2 additions & 2 deletions src/Eto.Veldrid.Mac/Eto.Veldrid.Mac64.csproj
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net461;netcoreapp3.1</TargetFrameworks>
<TargetFrameworks>netcoreapp3.1;net461</TargetFrameworks>
<DefineConstants>MONOMAC</DefineConstants>
<MacBuildBundle>false</MacBuildBundle>
<Title>Veldrid Mac implementation for Eto.Forms</Title>
<Description>This provides the Mac64 implementation of Eto.Veldrid for Eto.Forms</Description>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Eto.Platform.Mac64" Version="2.5.1" />
<PackageReference Include="Eto.Platform.Mac64" Version="2.5.9" />
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.0" PrivateAssets="all" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion src/Eto.Veldrid.WinForms/Eto.Veldrid.WinForms.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Eto.Platform.Windows" Version="2.5.1" />
<PackageReference Include="Eto.Platform.Windows" Version="2.5.9" />
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.0" PrivateAssets="all" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion src/Eto.Veldrid.Wpf/Eto.Veldrid.Wpf.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Eto.Platform.Wpf" Version="2.5.1" />
<PackageReference Include="Eto.Platform.Wpf" Version="2.5.9" />

<!-- Please note that version 3.6.0 is the newest version of this toolkit
that has licensing terms permitting use in commercial projects.
Expand Down
2 changes: 1 addition & 1 deletion src/Eto.Veldrid/Eto.Veldrid.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Eto.Forms" Version="2.5.1" />
<PackageReference Include="Eto.Forms" Version="2.5.9" />
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="3.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
7 changes: 5 additions & 2 deletions src/Eto.Veldrid/VeldridSurface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace Eto.Veldrid
[Handler(typeof(VeldridSurface.IHandler))]
public class VeldridSurface : Control
{
[AutoInitialize(false)]
public new interface IHandler : Control.IHandler
{
Size RenderSize { get; }
Expand Down Expand Up @@ -72,7 +73,7 @@ public interface IOpenGL

public GraphicsBackend Backend { get; private set; }
public GraphicsDevice GraphicsDevice { get; private set; }
public GraphicsDeviceOptions GraphicsDeviceOptions { get; private set; } = new GraphicsDeviceOptions();
public GraphicsDeviceOptions GraphicsDeviceOptions { get; private set; }
public Swapchain Swapchain { get; private set; }

public const string VeldridInitializedEvent = "VeldridSurface.VeldridInitialized";
Expand Down Expand Up @@ -100,13 +101,15 @@ public VeldridSurface()
{
}
public VeldridSurface(GraphicsBackend backend)
: this(backend, new GraphicsDeviceOptions())
{
Backend = backend;
}

public VeldridSurface(GraphicsBackend backend, GraphicsDeviceOptions gdOptions)
{
Backend = backend;
GraphicsDeviceOptions = gdOptions;
Initialize();
}

private static GraphicsBackend GetPreferredBackend()
Expand Down
8 changes: 4 additions & 4 deletions test/TestEtoVeldrid.Gtk/TestEtoVeldrid.Gtk.csproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFrameworks>net472;netcoreapp3.1</TargetFrameworks>
<TargetFrameworks>net5.0;net48</TargetFrameworks>
<RuntimeIdentifier>linux-x64</RuntimeIdentifier>
</PropertyGroup>

Expand All @@ -12,13 +12,13 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Eto.Platform.Gtk" Version="2.5.1" />
<PackageReference Include="Eto.Platform.Gtk" Version="2.5.9" />
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.0" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\TestEtoVeldrid\TestEtoVeldrid.csproj" />
<ProjectReference Include="..\..\src\Eto.Veldrid.Gtk\Eto.Veldrid.Gtk.csproj" />
</ItemGroup>

</Project>
Loading