├── SilkRenderer.WinUI
├── Assets
│ ├── StoreLogo.png
│ ├── LockScreenLogo.scale-200.png
│ ├── SplashScreen.scale-200.png
│ ├── Square44x44Logo.scale-200.png
│ ├── Wide310x150Logo.scale-200.png
│ ├── Square150x150Logo.scale-200.png
│ └── Square44x44Logo.targetsize-24_altform-unplated.png
├── OpenGL
│ ├── Sample
│ │ ├── Shaders
│ │ │ ├── shader.frag
│ │ │ ├── shader.vert
│ │ │ └── lighting.frag
│ │ ├── Materials.xaml
│ │ ├── ExampleScene.xaml
│ │ ├── ExampleScene.xaml.cs
│ │ └── Materials.xaml.cs
│ ├── Settings.cs
│ ├── GameControl.cs
│ ├── RenderContext.cs
│ ├── Common
│ │ ├── Camera.cs
│ │ └── Shader.cs
│ └── Framebuffer.cs
├── Properties
│ └── launchSettings.json
├── AssemblyInfo.cs
├── Common
│ ├── FramebufferBase.cs
│ ├── ISwapChainPanelNative.cs
│ ├── GameBase.cs
│ └── SilkColor.cs
├── App.xaml.cs
├── App.xaml
├── MainWindow.xaml.cs
├── app.manifest
├── Package.appxmanifest
├── MainWindow.xaml
└── SilkRenderer.WinUI.csproj
├── SilkRenderer.WPF
├── OpenGL
│ ├── Sample
│ │ ├── Shaders
│ │ │ ├── shader.frag
│ │ │ ├── shader.vert
│ │ │ └── lighting.frag
│ │ ├── Materials.xaml
│ │ ├── ExampleScene.xaml
│ │ ├── ExampleScene.xaml.cs
│ │ └── Materials.xaml.cs
│ ├── Settings.cs
│ ├── GameControl.cs
│ ├── RenderContext.cs
│ ├── Framebuffer.cs
│ └── Common
│ │ ├── Camera.cs
│ │ └── Shader.cs
├── App.xaml.cs
├── MainWindow.xaml.cs
├── Common
│ ├── FramebufferBase.cs
│ ├── DesignTimeHelper.cs
│ ├── GameBase.cs
│ └── SilkColor.cs
├── App.xaml
├── AssemblyInfo.cs
├── Direct3D9
│ ├── Sample
│ │ ├── MiniTri.xaml
│ │ └── MiniTri.xaml.cs
│ ├── Framebuffer.cs
│ ├── RenderContext.cs
│ └── GameControl.cs
├── SilkRenderer.WPF.csproj
└── MainWindow.xaml
├── README.md
├── SilkRenderer.sln
├── .gitattributes
└── .gitignore
/SilkRenderer.WinUI/Assets/StoreLogo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/qian-o/SilkRenderer/HEAD/SilkRenderer.WinUI/Assets/StoreLogo.png
--------------------------------------------------------------------------------
/SilkRenderer.WinUI/Assets/LockScreenLogo.scale-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/qian-o/SilkRenderer/HEAD/SilkRenderer.WinUI/Assets/LockScreenLogo.scale-200.png
--------------------------------------------------------------------------------
/SilkRenderer.WinUI/Assets/SplashScreen.scale-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/qian-o/SilkRenderer/HEAD/SilkRenderer.WinUI/Assets/SplashScreen.scale-200.png
--------------------------------------------------------------------------------
/SilkRenderer.WinUI/Assets/Square44x44Logo.scale-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/qian-o/SilkRenderer/HEAD/SilkRenderer.WinUI/Assets/Square44x44Logo.scale-200.png
--------------------------------------------------------------------------------
/SilkRenderer.WinUI/Assets/Wide310x150Logo.scale-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/qian-o/SilkRenderer/HEAD/SilkRenderer.WinUI/Assets/Wide310x150Logo.scale-200.png
--------------------------------------------------------------------------------
/SilkRenderer.WinUI/Assets/Square150x150Logo.scale-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/qian-o/SilkRenderer/HEAD/SilkRenderer.WinUI/Assets/Square150x150Logo.scale-200.png
--------------------------------------------------------------------------------
/SilkRenderer.WPF/OpenGL/Sample/Shaders/shader.frag:
--------------------------------------------------------------------------------
1 | #version 330 core
2 | out vec4 FragColor;
3 |
4 | void main()
5 | {
6 | FragColor = vec4(1.0); // set all 4 vector values to 1.0
7 | }
--------------------------------------------------------------------------------
/SilkRenderer.WinUI/OpenGL/Sample/Shaders/shader.frag:
--------------------------------------------------------------------------------
1 | #version 330 core
2 | out vec4 FragColor;
3 |
4 | void main()
5 | {
6 | FragColor = vec4(1.0); // set all 4 vector values to 1.0
7 | }
--------------------------------------------------------------------------------
/SilkRenderer.WinUI/Assets/Square44x44Logo.targetsize-24_altform-unplated.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/qian-o/SilkRenderer/HEAD/SilkRenderer.WinUI/Assets/Square44x44Logo.targetsize-24_altform-unplated.png
--------------------------------------------------------------------------------
/SilkRenderer.WPF/App.xaml.cs:
--------------------------------------------------------------------------------
1 | using System.Windows;
2 |
3 | namespace SilkRenderer.WPF;
4 | ///
5 | /// Interaction logic for App.xaml
6 | ///
7 | public partial class App : Application
8 | {
9 | }
10 |
--------------------------------------------------------------------------------
/SilkRenderer.WinUI/Properties/launchSettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "profiles": {
3 | "SilkRenderer.WinUI (Package)": {
4 | "commandName": "MsixPackage"
5 | },
6 | "SilkRenderer.WinUI (Unpackaged)": {
7 | "commandName": "Project"
8 | }
9 | }
10 | }
--------------------------------------------------------------------------------
/SilkRenderer.WinUI/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Runtime.CompilerServices;
2 | using System.Runtime.InteropServices;
3 |
4 | [assembly: ComVisible(false)]
5 |
6 |
7 | [assembly: Guid("fedef0b9-929a-41c0-a468-d990f94c9155")]
8 |
9 | [assembly: DisableRuntimeMarshalling]
10 |
--------------------------------------------------------------------------------
/SilkRenderer.WPF/MainWindow.xaml.cs:
--------------------------------------------------------------------------------
1 | using System.Windows;
2 |
3 | namespace SilkRenderer.WPF;
4 |
5 | ///
6 | /// Interaction logic for MainWindow.xaml
7 | ///
8 | public partial class MainWindow : Window
9 | {
10 | public MainWindow()
11 | {
12 | InitializeComponent();
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/SilkRenderer.WPF/Common/FramebufferBase.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Windows.Interop;
3 |
4 | namespace SilkRenderer.WPF.Common;
5 | public abstract class FramebufferBase : IDisposable
6 | {
7 | public abstract int FramebufferWidth { get; }
8 |
9 | public abstract int FramebufferHeight { get; }
10 |
11 | public abstract D3DImage D3dImage { get; }
12 |
13 | public abstract void Dispose();
14 | }
15 |
--------------------------------------------------------------------------------
/SilkRenderer.WPF/App.xaml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/SilkRenderer.WinUI/Common/FramebufferBase.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace SilkRenderer.WinUI.Common;
4 | public abstract class FramebufferBase : IDisposable
5 | {
6 | public abstract int FramebufferWidth { get; protected set; }
7 |
8 | public abstract int FramebufferHeight { get; protected set; }
9 |
10 | public abstract IntPtr SwapChainHandle { get; protected set; }
11 |
12 | public abstract void Dispose();
13 | }
14 |
--------------------------------------------------------------------------------
/SilkRenderer.WinUI/App.xaml.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.UI.Xaml;
2 |
3 | namespace SilkRenderer.WinUI;
4 |
5 | public partial class App : Application
6 | {
7 | public static Window MainWindow { get; set; }
8 |
9 | public App()
10 | {
11 | InitializeComponent();
12 | }
13 |
14 | protected override void OnLaunched(LaunchActivatedEventArgs args)
15 | {
16 | MainWindow = new MainWindow();
17 | MainWindow.Activate();
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/SilkRenderer.WinUI/Common/ISwapChainPanelNative.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Runtime.InteropServices;
3 | using Silk.NET.Core.Native;
4 |
5 | namespace SilkRenderer.WinUI.Common;
6 |
7 | [ComImport]
8 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
9 | [Guid("63aad0b8-7c24-40ff-85a8-640d944cc325")]
10 | public interface ISwapChainPanelNative
11 | {
12 | [PreserveSig] HResult SetSwapChain([In] IntPtr swapChain);
13 | [PreserveSig] ulong Release();
14 | }
15 |
--------------------------------------------------------------------------------
/SilkRenderer.WPF/OpenGL/Sample/Shaders/shader.vert:
--------------------------------------------------------------------------------
1 | #version 330 core
2 | layout (location = 0) in vec3 aPos;
3 | layout (location = 1) in vec3 aNormal;
4 |
5 | uniform mat4 model;
6 | uniform mat4 view;
7 | uniform mat4 projection;
8 |
9 | out vec3 Normal;
10 | out vec3 FragPos;
11 |
12 | void main()
13 | {
14 | gl_Position = vec4(aPos, 1.0) * model * view * projection;
15 | FragPos = vec3(vec4(aPos, 1.0) * model);
16 | Normal = aNormal * mat3(transpose(inverse(model)));
17 | }
--------------------------------------------------------------------------------
/SilkRenderer.WinUI/OpenGL/Sample/Shaders/shader.vert:
--------------------------------------------------------------------------------
1 | #version 330 core
2 | layout (location = 0) in vec3 aPos;
3 | layout (location = 1) in vec3 aNormal;
4 |
5 | uniform mat4 model;
6 | uniform mat4 view;
7 | uniform mat4 projection;
8 |
9 | out vec3 Normal;
10 | out vec3 FragPos;
11 |
12 | void main()
13 | {
14 | gl_Position = vec4(aPos, 1.0) * model * view * projection;
15 | FragPos = vec3(vec4(aPos, 1.0) * model);
16 | Normal = aNormal * mat3(transpose(inverse(model)));
17 | }
--------------------------------------------------------------------------------
/SilkRenderer.WPF/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Windows;
2 |
3 | [assembly: ThemeInfo(
4 | ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
5 | //(used if a resource is not found in the page,
6 | // or application resource dictionaries)
7 | ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
8 | //(used if a resource is not found in the page,
9 | // app, or any theme specific resource dictionaries)
10 | )]
11 |
--------------------------------------------------------------------------------
/SilkRenderer.WinUI/App.xaml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/SilkRenderer.WinUI/OpenGL/Sample/Materials.xaml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
10 |
11 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/SilkRenderer.WinUI/OpenGL/Sample/ExampleScene.xaml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
10 |
11 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/SilkRenderer.WPF/OpenGL/Sample/Materials.xaml:
--------------------------------------------------------------------------------
1 |
10 |
11 |
12 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/SilkRenderer.WPF/OpenGL/Sample/ExampleScene.xaml:
--------------------------------------------------------------------------------
1 |
10 |
11 |
12 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/SilkRenderer.WPF/Direct3D9/Sample/MiniTri.xaml:
--------------------------------------------------------------------------------
1 |
10 |
11 |
12 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/SilkRenderer.WinUI/MainWindow.xaml.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.UI.Xaml;
2 | using Microsoft.UI.Xaml.Controls;
3 | using Microsoft.UI.Xaml.Input;
4 | using SilkRenderer.WinUI.OpenGL.Sample;
5 |
6 | namespace SilkRenderer.WinUI;
7 |
8 | public sealed partial class MainWindow : Window
9 | {
10 | public MainWindow()
11 | {
12 | InitializeComponent();
13 | }
14 |
15 | private void Materials_DoubleTapped(object sender, DoubleTappedRoutedEventArgs e)
16 | {
17 | Materials materials = (Materials)sender;
18 |
19 | if (Grid.GetColumn(materials) == 1)
20 | {
21 | Grid.SetColumn(materials, 0);
22 | Grid.SetRow(materials, 0);
23 |
24 | Grid.SetColumnSpan(materials, 2);
25 | Grid.SetRowSpan(materials, 2);
26 | }
27 | else
28 | {
29 | Grid.SetColumn(materials, 1);
30 | Grid.SetRow(materials, 1);
31 |
32 | Grid.SetColumnSpan(materials, 1);
33 | Grid.SetRowSpan(materials, 1);
34 | }
35 | }
36 | }
--------------------------------------------------------------------------------
/SilkRenderer.WPF/Common/DesignTimeHelper.cs:
--------------------------------------------------------------------------------
1 | using System.Windows;
2 | using System.Windows.Controls;
3 | using System.Windows.Media;
4 |
5 | namespace SilkRenderer.WPF.Common;
6 |
7 | public static class DesignTimeHelper
8 | {
9 | public static void DrawDesign(Control control, DrawingContext drawingContext)
10 | {
11 | if (control.Visibility == Visibility.Visible && control.ActualWidth > 0 && control.ActualHeight > 0)
12 | {
13 | drawingContext.DrawRectangle(Brushes.Black,
14 | new Pen(Brushes.DarkBlue, 2.0),
15 | new Rect(0, 0, control.ActualWidth, control.ActualHeight));
16 |
17 | drawingContext.DrawLine(new Pen(Brushes.DarkBlue, 2.0),
18 | new Point(0.0, 0.0),
19 | new Point(control.ActualWidth, control.ActualHeight));
20 | drawingContext.DrawLine(new Pen(Brushes.DarkBlue, 2.0),
21 | new Point(control.ActualWidth, 0.0),
22 | new Point(0.0, control.ActualHeight));
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/SilkRenderer.WPF/OpenGL/Settings.cs:
--------------------------------------------------------------------------------
1 | using System.Diagnostics.CodeAnalysis;
2 | using Silk.NET.GLFW;
3 | using Silk.NET.Windowing;
4 |
5 | namespace SilkRenderer.WPF.OpenGL;
6 |
7 | public class Settings
8 | {
9 | public int MajorVersion { get; set; } = 3;
10 |
11 | public int MinorVersion { get; set; } = 3;
12 |
13 | public ContextFlags GraphicsContextFlags { get; set; } = ContextFlags.Default;
14 |
15 | public ContextProfile GraphicsProfile { get; set; } = ContextProfile.Core;
16 |
17 | public OpenGlProfile OpenGlProfile { get; set; } = OpenGlProfile.Core;
18 |
19 | public static bool WouldResultInSameContext([NotNull] Settings a, [NotNull] Settings b)
20 | {
21 | if (a.MajorVersion != b.MajorVersion)
22 | {
23 | return false;
24 | }
25 |
26 | if (a.MinorVersion != b.MinorVersion)
27 | {
28 | return false;
29 | }
30 |
31 | if (a.GraphicsProfile != b.GraphicsProfile)
32 | {
33 | return false;
34 | }
35 |
36 | if (a.GraphicsContextFlags != b.GraphicsContextFlags)
37 | {
38 | return false;
39 | }
40 |
41 | return true;
42 |
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/SilkRenderer.WinUI/OpenGL/Settings.cs:
--------------------------------------------------------------------------------
1 | using System.Diagnostics.CodeAnalysis;
2 | using Silk.NET.GLFW;
3 | using Silk.NET.Windowing;
4 |
5 | namespace SilkRenderer.WinUI.OpenGL;
6 |
7 | public class Settings
8 | {
9 | public int MajorVersion { get; set; } = 3;
10 |
11 | public int MinorVersion { get; set; } = 3;
12 |
13 | public ContextFlags GraphicsContextFlags { get; set; } = ContextFlags.Default;
14 |
15 | public ContextProfile GraphicsProfile { get; set; } = ContextProfile.Core;
16 |
17 | public OpenGlProfile OpenGlProfile { get; set; } = OpenGlProfile.Core;
18 |
19 | public static bool WouldResultInSameContext([NotNull] Settings a, [NotNull] Settings b)
20 | {
21 | if (a.MajorVersion != b.MajorVersion)
22 | {
23 | return false;
24 | }
25 |
26 | if (a.MinorVersion != b.MinorVersion)
27 | {
28 | return false;
29 | }
30 |
31 | if (a.GraphicsProfile != b.GraphicsProfile)
32 | {
33 | return false;
34 | }
35 |
36 | if (a.GraphicsContextFlags != b.GraphicsContextFlags)
37 | {
38 | return false;
39 | }
40 |
41 | return true;
42 |
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/SilkRenderer.WPF/SilkRenderer.WPF.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | WinExe
5 | net7.0-windows
6 | disable
7 | true
8 | x64
9 | True
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 | PreserveNewest
23 |
24 |
25 | PreserveNewest
26 |
27 |
28 | PreserveNewest
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/SilkRenderer.WPF/Direct3D9/Framebuffer.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Windows.Interop;
3 | using Silk.NET.Direct3D9;
4 | using SilkRenderer.WPF.Common;
5 |
6 | namespace SilkRenderer.WPF.Direct3D9;
7 |
8 | public unsafe class Framebuffer : FramebufferBase
9 | {
10 | public RenderContext Context { get; }
11 |
12 | public override int FramebufferWidth { get; }
13 |
14 | public override int FramebufferHeight { get; }
15 |
16 | public override D3DImage D3dImage { get; }
17 |
18 | public Framebuffer(RenderContext context, int framebufferWidth, int framebufferHeight)
19 | {
20 | Context = context;
21 | FramebufferWidth = framebufferWidth;
22 | FramebufferHeight = framebufferHeight;
23 |
24 | IDirect3DSurface9* surface;
25 | context.Device->CreateRenderTarget((uint)FramebufferWidth, (uint)FramebufferHeight, context.Format, MultisampleType.MultisampleNone, 0, 0, &surface, null);
26 | context.Device->SetRenderTarget(0, surface);
27 |
28 | D3dImage = new D3DImage();
29 | D3dImage.Lock();
30 | D3dImage.SetBackBuffer(D3DResourceType.IDirect3DSurface9, (IntPtr)surface);
31 | D3dImage.Unlock();
32 | }
33 |
34 | public override void Dispose()
35 | {
36 | GC.SuppressFinalize(this);
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/SilkRenderer.WinUI/app.manifest:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
21 | true/PM
22 | PerMonitorV2, PerMonitor
23 |
24 |
25 |
--------------------------------------------------------------------------------
/SilkRenderer.WPF/MainWindow.xaml:
--------------------------------------------------------------------------------
1 |
13 |
14 |
15 |
16 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
36 |
37 |
38 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # SilkRenderer
2 | ## WPF、WinUI3 使用 Silk.NET 绘制示例(OpenGL、DirectX)
3 |
4 | ## WPF、WinUI3 Use Silk.NET to draw examples (OpenGL, DirectX)
5 |
6 | ### 注意事项
7 | 该项目代码结构较为复杂、混乱,仅供参考学习。
8 |
9 | ### Precautions
10 | The project code structure is rather complex, messy, and is only for reference and learning purposes.
11 |
12 | ### 项目说明
13 | - 本项目是一个使用 Silk.NET 绘制图形的示例项目,包含了 WPF 和 WinUI3 两个项目,分别使用 OpenGL 和 DirectX 两种渲染方式。
14 | - 渲染模式依靠 OpenTK 提供的渲染思路,使用 NV_DX_Interop 扩展实现 DirectX 与 OpenGL 之间的交互。
15 | - 使用该方式进行渲染,能够极大提高 WPF 和 WinUI3 的图形性能,同时也能够接入不同的图形库。
16 |
17 | ### Project Description
18 | - This project is an example project that uses Silk.NET to draw graphics. It contains two projects, WPF and WinUI3, which use OpenGL and DirectX rendering respectively.
19 | - The rendering mode relies on the rendering ideas provided by OpenTK and uses the NV_DX_Interop extension to implement interaction between DirectX and OpenGL.
20 | - Using this rendering method can greatly improve the graphics performance of WPF and WinUI3, and can also access different graphics libraries.
21 |
22 | ### 项目结构
23 | - RenderContext:渲染上下文,用户管理 OpenGL 和 DirectX 的渲染环境。
24 | - Framebuffer:帧缓冲,用户管理 OpenGL 和 DirectX 的帧缓冲。
25 | - GameControl:渲染控件,管理上下文和渲染。
26 |
27 | ### Project Structure
28 | - RenderContext: Rendering context, user management OpenGL and DirectX rendering environment.
29 | - Framebuffer: Frame buffer, user management OpenGL and DirectX frame buffer.
30 | - GameControl: Rendering control, management context and rendering.
31 |
32 | 
33 |
34 | 
35 |
--------------------------------------------------------------------------------
/SilkRenderer.WPF/Direct3D9/RenderContext.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Silk.NET.Direct3D9;
3 |
4 | namespace SilkRenderer.WPF.Direct3D9;
5 |
6 | public unsafe class RenderContext
7 | {
8 | public IDirect3DDevice9Ex* Device { get; }
9 |
10 | public Format Format { get; }
11 |
12 | public RenderContext()
13 | {
14 | IDirect3D9Ex* direct3D9;
15 | IDirect3DDevice9Ex* device;
16 | D3D9.GetApi(null).Direct3DCreate9Ex(D3D9.SdkVersion, &direct3D9);
17 |
18 | Displaymodeex pMode = new((uint)sizeof(Displaymodeex));
19 | direct3D9->GetAdapterDisplayModeEx(D3D9.AdapterDefault, ref pMode, null);
20 |
21 | PresentParameters presentParameters = new()
22 | {
23 | Windowed = 1,
24 | SwapEffect = Swapeffect.Discard,
25 | HDeviceWindow = 0,
26 | PresentationInterval = 0,
27 | BackBufferFormat = pMode.Format,
28 | BackBufferWidth = 1,
29 | BackBufferHeight = 1,
30 | AutoDepthStencilFormat = Format.Unknown,
31 | BackBufferCount = 1,
32 | EnableAutoDepthStencil = 0,
33 | Flags = 0,
34 | FullScreenRefreshRateInHz = 0,
35 | MultiSampleQuality = 0,
36 | MultiSampleType = MultisampleType.MultisampleNone
37 | };
38 | direct3D9->CreateDeviceEx(D3D9.AdapterDefault, Devtype.Hal, 0, D3D9.CreateHardwareVertexprocessing | D3D9.CreateMultithreaded | D3D9.CreatePuredevice, ref presentParameters, (Displaymodeex*)IntPtr.Zero, &device);
39 |
40 | Device = device;
41 | Format = pMode.Format;
42 | }
43 |
44 | public static Format MakeFourCC(byte c1, byte c2, byte c3, byte c4)
45 | {
46 | return (Format)((((((c4 << 8) | c3) << 8) | c2) << 8) | c1);
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/SilkRenderer.WinUI/Package.appxmanifest:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
9 |
13 |
14 |
15 | SilkRenderer.WinUI
16 | 13247
17 | Assets\StoreLogo.png
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
33 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
--------------------------------------------------------------------------------
/SilkRenderer.WinUI/MainWindow.xaml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
20 |
22 |
24 |
27 |
28 |
29 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/SilkRenderer.WPF/Direct3D9/GameControl.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Windows;
3 | using System.Windows.Media;
4 | using Silk.NET.Direct3D9;
5 | using SilkRenderer.WPF.Common;
6 | using Rect = System.Windows.Rect;
7 |
8 | namespace SilkRenderer.WPF.Direct3D9;
9 |
10 | public unsafe class GameControl : GameBase
11 | {
12 | private RenderContext _context;
13 |
14 | public IDirect3DDevice9Ex* Device { get; private set; }
15 | public Format Format { get; private set; }
16 |
17 | public override event Action Ready;
18 | public override event Action Render;
19 | public override event Action