Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
28c8e60
Started cleanup effort
NogginBops Jul 21, 2022
1631d01
Updated to .net 5.0. Added error checking for d3d9 calls. Slowly remo…
NogginBops Aug 1, 2022
513f980
Moved design time and unstarted rendering helpers into GLWpfControl.cs
NogginBops Aug 1, 2022
8e9d4f7
Whitespace cleanup
NogginBops Aug 1, 2022
d12260f
Merge branch 'master' of github.com:opentk/GLWpfControl into cleanup
NogginBops Feb 15, 2023
57e58df
Implemented proper COM interop. Switched back to .net core 3.1.
NogginBops Mar 13, 2023
e70ea99
Fixed some style issues and made COM error checking part of DxInterop.
NogginBops Mar 13, 2023
82ad452
Merge branch 'master' of github.com:opentk/GLWpfControl into cleanup
NogginBops Mar 13, 2023
bb42362
Move comments
NogginBops Mar 13, 2023
84f0b73
Added code to check if DX rendertarget is created with multisamples
NogginBops May 1, 2023
c07acf1
Fixed compile error after rename
NogginBops May 1, 2023
920cefd
Bunch of cleaup. Enabled MSAA framebuffer sharing. Removed the one sh…
NogginBops May 29, 2024
db7bb33
Merge branch 'master' of github.com:opentk/GLWpfControl into cleanup
NogginBops May 29, 2024
9c51f6f
Fixed paket file. Cleaned csproj. Other cleanup.
NogginBops May 29, 2024
3bb8d1e
Fixed nullability issue.
NogginBops May 29, 2024
4b0913f
Implemented IDisposable.
NogginBops May 29, 2024
8a539b2
Added context sharing setting.
NogginBops May 30, 2024
ec9d51b
Merge branch 'master' of github.com:opentk/GLWpfControl into cleanup
NogginBops May 30, 2024
8edd8b1
Set Focusable=true by default. Deprecate direct event registering.
NogginBops May 30, 2024
20cecb2
Updated readme to reflect changes to keyboard event handling.
NogginBops May 30, 2024
85cc8ca
Fixed warnings
NogginBops May 30, 2024
3551c5e
Small style cleanup
NogginBops May 30, 2024
d619ff4
Fix Example function order.
NogginBops May 30, 2024
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
2 changes: 1 addition & 1 deletion src/Example/Example.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>netcoreapp3.1-windows</TargetFramework>
<TargetFramework>netcoreapp5.0-windows</TargetFramework>
<UseWPF>true</UseWPF>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<StartupObject>Example.App</StartupObject>
Expand Down
59 changes: 29 additions & 30 deletions src/GLWpfControl/DXGLContext.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System;
using System.Runtime.InteropServices;
using System.Threading;
using System.Windows;
using System.Windows.Interop;
using JetBrains.Annotations;
using OpenTK.Graphics.Wgl;
using OpenTK.Windowing.Common;
using OpenTK.Windowing.Desktop;
Expand Down Expand Up @@ -31,14 +31,16 @@ internal sealed class DxGlContext : IDisposable {
/// The shared context we (may) want to lazily create/use.
private static IGraphicsContext _sharedContext;
private static GLWpfControlSettings _sharedContextSettings;
/// List of extra resources to dispose along with the shared context.
private static IDisposable[] _sharedContextResources;

private static NativeWindow GlfwWindow;
private static HwndSource HwndSource;

/// The number of active controls using the shared context.
private static int _sharedContextReferenceCount;

public DxGlContext(GLWpfControlSettings settings) {

public DxGlContext([NotNull] GLWpfControlSettings settings) {
DXInterop.Direct3DCreate9Ex(DXInterop.DefaultSdkVersion, out var dxContextHandle);
DXInterop.CheckHResult(DXInterop.Direct3DCreate9Ex(DXInterop.DefaultSdkVersion, out var dxContextHandle));
DxContextHandle = dxContextHandle;

var deviceParameters = new PresentationParameters
Expand All @@ -59,17 +61,18 @@ public DxGlContext([NotNull] GLWpfControlSettings settings) {
MultiSampleType = MultisampleType.None
};

DXInterop.CreateDeviceEx(
dxContextHandle,
0,
DeviceType.HAL, // use hardware rasterization
IntPtr.Zero,
CreateFlags.HardwareVertexProcessing |
CreateFlags.Multithreaded |
CreateFlags.PureDevice,
ref deviceParameters,
IntPtr.Zero,
out var dxDeviceHandle);
DXInterop.CheckHResult(
DXInterop.CreateDeviceEx(
dxContextHandle,
0,
DeviceType.HAL, // use hardware rasterization
IntPtr.Zero,
CreateFlags.HardwareVertexProcessing |
CreateFlags.Multithreaded |
CreateFlags.PureDevice,
ref deviceParameters,
IntPtr.Zero,
out var dxDeviceHandle));
DxDeviceHandle = dxDeviceHandle;

// if the graphics context is null, we use the shared context.
Expand All @@ -92,8 +95,7 @@ private static IGraphicsContext GetOrCreateSharedOpenGLContext(GLWpfControlSetti
$" either ensure all of your context settings are identical, or provide an " +
$"external context via the '{nameof(GLWpfControlSettings.ContextToUse)}' field.");
}
}

}
else {
var nws = NativeWindowSettings.Default;
nws.StartFocused = false;
Expand All @@ -106,26 +108,24 @@ private static IGraphicsContext GetOrCreateSharedOpenGLContext(GLWpfControlSetti
nws.Profile = settings.GraphicsProfile;
nws.WindowBorder = WindowBorder.Hidden;
nws.WindowState = WindowState.Minimized;
var glfwWindow = new NativeWindow(nws);
GlfwWindow = new NativeWindow(nws);
var provider = settings.BindingsContext ?? new GLFWBindingsContext();
Wgl.LoadBindings(provider);
// we're already in a window context, so we can just cheat by creating a new dependency object here rather than passing any around.
var depObject = new DependencyObject();
// retrieve window handle/info
var window = Window.GetWindow(depObject);
var baseHandle = window is null ? IntPtr.Zero : new WindowInteropHelper(window).Handle;
var hwndSource = new HwndSource(0, 0, 0, 0, 0, "GLWpfControl", baseHandle);
HwndSource = new HwndSource(0, 0, 0, 0, 0, "GLWpfControl", baseHandle);

_sharedContext = glfwWindow.Context;
_sharedContext = GlfwWindow.Context;
_sharedContextSettings = settings;
_sharedContextResources = new IDisposable[] {hwndSource, glfwWindow};
// GL init
// var mode = new GraphicsMode(ColorFormat.Empty, 0, 0, 0, 0, 0, false);
// _commonContext = new GraphicsContext(mode, _windowInfo, _settings.MajorVersion, _settings.MinorVersion,
// _settings.GraphicsContextFlags);
// _commonContext.LoadAll();
_sharedContext.MakeCurrent();
}

// FIXME:
// This has a race condition where we think we still have the
// shared context available but it's been deleted when we get here.
Interlocked.Increment(ref _sharedContextReferenceCount);
return _sharedContext;
}
Expand All @@ -134,9 +134,8 @@ public void Dispose() {
// we only dispose of the graphics context if we're using the shared one.
if (ReferenceEquals(_sharedContext, GraphicsContext)) {
if (Interlocked.Decrement(ref _sharedContextReferenceCount) == 0) {
foreach (var resource in _sharedContextResources) {
resource.Dispose();
}
GlfwWindow.Dispose();
HwndSource.Dispose();
}
}
}
Expand Down
35 changes: 0 additions & 35 deletions src/GLWpfControl/DesignTimeHelper.cs

This file was deleted.

131 changes: 0 additions & 131 deletions src/GLWpfControl/DxGLFramebuffer.cs

This file was deleted.

Loading