+ WPF Support
This commit is contained in:
parent
6f23a80f7f
commit
41421b1df9
12 changed files with 94 additions and 14 deletions
|
|
@ -11,8 +11,6 @@ namespace SM.Base
|
||||||
{
|
{
|
||||||
public class GenericWPFWindow : OpenTK.Wpf.GLWpfControl, IGenericWindow
|
public class GenericWPFWindow : OpenTK.Wpf.GLWpfControl, IGenericWindow
|
||||||
{
|
{
|
||||||
private bool _renderContinuesly;
|
|
||||||
|
|
||||||
protected GenericCamera _viewportCamera;
|
protected GenericCamera _viewportCamera;
|
||||||
|
|
||||||
public bool Loading => !base.IsInitialized;
|
public bool Loading => !base.IsInitialized;
|
||||||
|
|
@ -24,9 +22,8 @@ namespace SM.Base
|
||||||
public Rectangle ClientRectangle => new Rectangle((int)base.RenderTransformOrigin.X, (int)RenderTransformOrigin.Y, Width, Height);
|
public Rectangle ClientRectangle => new Rectangle((int)base.RenderTransformOrigin.X, (int)RenderTransformOrigin.Y, Width, Height);
|
||||||
public Vector2 WorldScale { get; set; }
|
public Vector2 WorldScale { get; set; }
|
||||||
|
|
||||||
public GenericWPFWindow(bool renderContinuesly = false)
|
public GenericWPFWindow()
|
||||||
{
|
{
|
||||||
_renderContinuesly = renderContinuesly;
|
|
||||||
|
|
||||||
Ready += Init;
|
Ready += Init;
|
||||||
Render += Rendering;
|
Render += Rendering;
|
||||||
|
|
@ -49,13 +46,13 @@ namespace SM.Base
|
||||||
GenericWindowCode.Resize(this);
|
GenericWindowCode.Resize(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Start()
|
public void Start(bool renderContinuesly = false)
|
||||||
{
|
{
|
||||||
GLWpfControlSettings settings = new GLWpfControlSettings()
|
GLWpfControlSettings settings = new GLWpfControlSettings()
|
||||||
{
|
{
|
||||||
MajorVersion = GLSettings.ForcedVersion.MajorVersion,
|
MajorVersion = GLSettings.ForcedVersion.MajorVersion,
|
||||||
MinorVersion = GLSettings.ForcedVersion.MinorVersion,
|
MinorVersion = GLSettings.ForcedVersion.MinorVersion,
|
||||||
RenderContinuously = _renderContinuesly
|
RenderContinuously = renderContinuesly
|
||||||
};
|
};
|
||||||
base.Start(settings);
|
base.Start(settings);
|
||||||
}
|
}
|
||||||
|
|
@ -74,7 +71,7 @@ namespace SM.Base
|
||||||
public TScene CurrentScene => _scene;
|
public TScene CurrentScene => _scene;
|
||||||
public RenderPipeline<TScene> RenderPipeline => _renderPipeline;
|
public RenderPipeline<TScene> RenderPipeline => _renderPipeline;
|
||||||
|
|
||||||
public GenericWPFWindow(bool renderContinuesly = false) : base(renderContinuesly)
|
public GenericWPFWindow() : base()
|
||||||
{
|
{
|
||||||
_viewportCamera = new TCamera();
|
_viewportCamera = new TCamera();
|
||||||
}
|
}
|
||||||
|
|
@ -97,7 +94,7 @@ namespace SM.Base
|
||||||
{
|
{
|
||||||
_scene = scene;
|
_scene = scene;
|
||||||
scene.Activate();
|
scene.Activate();
|
||||||
RenderPipeline.SceneChanged(scene);
|
RenderPipeline?.SceneChanged(scene);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetRenderPipeline(RenderPipeline<TScene> renderPipeline)
|
public void SetRenderPipeline(RenderPipeline<TScene> renderPipeline)
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,7 @@ namespace SM.Base
|
||||||
where TCamera : GenericCamera, new()
|
where TCamera : GenericCamera, new()
|
||||||
{
|
{
|
||||||
window.ViewportCamera.RecalculateWorld(window.WorldScale, window.Aspect);
|
window.ViewportCamera.RecalculateWorld(window.WorldScale, window.Aspect);
|
||||||
window.RenderPipeline.Resize();
|
window.RenderPipeline?.Resize();
|
||||||
|
|
||||||
PostProcessEffect.Model = Matrix4.CreateScale(window.WorldScale.X, -window.WorldScale.Y, 1);
|
PostProcessEffect.Model = Matrix4.CreateScale(window.WorldScale.X, -window.WorldScale.Y, 1);
|
||||||
PostProcessEffect.Mvp = PostProcessEffect.Model *
|
PostProcessEffect.Mvp = PostProcessEffect.Model *
|
||||||
|
|
|
||||||
|
|
@ -64,6 +64,7 @@ namespace SM.OGL
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public virtual void Dispose()
|
public virtual void Dispose()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
||||||
|
|
@ -82,6 +82,12 @@ namespace SM.OGL.Shaders
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override ObjectLabelIdentifier TypeIdentifier { get; } = ObjectLabelIdentifier.Program;
|
public override ObjectLabelIdentifier TypeIdentifier { get; } = ObjectLabelIdentifier.Program;
|
||||||
|
|
||||||
|
public void Update(ShaderFileCollection newShaderFiles)
|
||||||
|
{
|
||||||
|
ShaderFileFiles = newShaderFiles;
|
||||||
|
Recompile();
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Loads the shader to the GPU.
|
/// Loads the shader to the GPU.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -106,6 +112,11 @@ namespace SM.OGL.Shaders
|
||||||
Load();
|
Load();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void Dispose()
|
||||||
|
{
|
||||||
|
GL.DeleteShader(this);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Draws the mesh.
|
/// Draws the mesh.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
||||||
|
|
@ -47,6 +47,9 @@ namespace SM.OGL.Shaders
|
||||||
{
|
{
|
||||||
var name =
|
var name =
|
||||||
$"{prefix}{Path.GetFileNameWithoutExtension(filePath.Substring(path.Length)).Replace('.', '_')}";
|
$"{prefix}{Path.GetFileNameWithoutExtension(filePath.Substring(path.Length)).Replace('.', '_')}";
|
||||||
|
|
||||||
|
if (Extensions.ContainsKey(name)) continue;
|
||||||
|
|
||||||
Extensions.Add(name, new ShaderFile(reader.ReadToEnd()));
|
Extensions.Add(name, new ShaderFile(reader.ReadToEnd()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,7 @@ namespace SM.OGL.Shaders
|
||||||
foreach (var kvp in StringOverrides)
|
foreach (var kvp in StringOverrides)
|
||||||
_data = _data.Replace("//!" + kvp.Key, kvp.Value);
|
_data = _data.Replace("//!" + kvp.Key, kvp.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void Compile(GenericShader shader, ShaderType type)
|
internal void Compile(GenericShader shader, ShaderType type)
|
||||||
{
|
{
|
||||||
if (_id < 0)
|
if (_id < 0)
|
||||||
|
|
|
||||||
|
|
@ -20,9 +20,7 @@ namespace SM2D.Pipelines
|
||||||
|
|
||||||
protected override void RenderProcess(ref DrawContext context, Scene.Scene scene)
|
protected override void RenderProcess(ref DrawContext context, Scene.Scene scene)
|
||||||
{
|
{
|
||||||
|
scene?.Draw(context);
|
||||||
Framebuffer.Screen.Activate(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
|
|
||||||
if (scene != null) scene.Draw(context);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -26,7 +26,7 @@ namespace SM2D
|
||||||
|
|
||||||
SMRenderer.DefaultMaterialShader = Default2DShader.MaterialShader;
|
SMRenderer.DefaultMaterialShader = Default2DShader.MaterialShader;
|
||||||
|
|
||||||
SetRenderPipeline(Default2DPipeline.Pipeline);
|
//SetRenderPipeline(Default2DPipeline.Pipeline);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Rendering(TimeSpan delta)
|
protected override void Rendering(TimeSpan delta)
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ using System.Windows.Shapes;
|
||||||
using OpenTK.Graphics;
|
using OpenTK.Graphics;
|
||||||
using SM2D;
|
using SM2D;
|
||||||
using SM2D.Drawing;
|
using SM2D.Drawing;
|
||||||
|
using SM2D.Pipelines;
|
||||||
using SM2D.Scene;
|
using SM2D.Scene;
|
||||||
|
|
||||||
namespace SM_WPF_TEST
|
namespace SM_WPF_TEST
|
||||||
|
|
@ -37,10 +38,13 @@ namespace SM_WPF_TEST
|
||||||
gl.Start();
|
gl.Start();
|
||||||
|
|
||||||
gl.SetScene(scene = new Scene());
|
gl.SetScene(scene = new Scene());
|
||||||
|
gl.SetRenderPipeline(Default2DPipeline.Pipeline);
|
||||||
|
|
||||||
DrawObject2D cube = new DrawObject2D();
|
DrawObject2D cube = new DrawObject2D();
|
||||||
cube.Color = Color4.Blue;
|
cube.Color = Color4.Blue;
|
||||||
scene.Objects.Add(cube);
|
scene.Objects.Add(cube);
|
||||||
|
|
||||||
|
new Window1().Show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -61,6 +61,9 @@
|
||||||
<Generator>MSBuild:Compile</Generator>
|
<Generator>MSBuild:Compile</Generator>
|
||||||
<SubType>Designer</SubType>
|
<SubType>Designer</SubType>
|
||||||
</ApplicationDefinition>
|
</ApplicationDefinition>
|
||||||
|
<Compile Include="Window1.xaml.cs">
|
||||||
|
<DependentUpon>Window1.xaml</DependentUpon>
|
||||||
|
</Compile>
|
||||||
<Page Include="MainWindow.xaml">
|
<Page Include="MainWindow.xaml">
|
||||||
<Generator>MSBuild:Compile</Generator>
|
<Generator>MSBuild:Compile</Generator>
|
||||||
<SubType>Designer</SubType>
|
<SubType>Designer</SubType>
|
||||||
|
|
@ -73,6 +76,10 @@
|
||||||
<DependentUpon>MainWindow.xaml</DependentUpon>
|
<DependentUpon>MainWindow.xaml</DependentUpon>
|
||||||
<SubType>Code</SubType>
|
<SubType>Code</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Page Include="Window1.xaml">
|
||||||
|
<SubType>Designer</SubType>
|
||||||
|
<Generator>MSBuild:Compile</Generator>
|
||||||
|
</Page>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Properties\AssemblyInfo.cs">
|
<Compile Include="Properties\AssemblyInfo.cs">
|
||||||
|
|
|
||||||
12
SM_WPF_TEST/Window1.xaml
Normal file
12
SM_WPF_TEST/Window1.xaml
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
<Window x:Class="SM_WPF_TEST.Window1"
|
||||||
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
xmlns:local="clr-namespace:SM_WPF_TEST"
|
||||||
|
mc:Ignorable="d"
|
||||||
|
Title="Window1" Height="450" Width="800">
|
||||||
|
<Grid>
|
||||||
|
|
||||||
|
</Grid>
|
||||||
|
</Window>
|
||||||
47
SM_WPF_TEST/Window1.xaml.cs
Normal file
47
SM_WPF_TEST/Window1.xaml.cs
Normal file
|
|
@ -0,0 +1,47 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows;
|
||||||
|
using System.Windows.Controls;
|
||||||
|
using System.Windows.Data;
|
||||||
|
using System.Windows.Documents;
|
||||||
|
using System.Windows.Input;
|
||||||
|
using System.Windows.Media;
|
||||||
|
using System.Windows.Media.Imaging;
|
||||||
|
using System.Windows.Shapes;
|
||||||
|
using OpenTK.Graphics;
|
||||||
|
using SM2D;
|
||||||
|
using SM2D.Drawing;
|
||||||
|
using SM2D.Pipelines;
|
||||||
|
using SM2D.Scene;
|
||||||
|
|
||||||
|
namespace SM_WPF_TEST
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Interaction logic for Window1.xaml
|
||||||
|
/// </summary>
|
||||||
|
public partial class Window1 : Window
|
||||||
|
{
|
||||||
|
public Window1()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
|
||||||
|
GLWPFWindow2D gl;
|
||||||
|
Scene scene;
|
||||||
|
Content = gl = new GLWPFWindow2D();
|
||||||
|
gl.Start();
|
||||||
|
|
||||||
|
gl.SetScene(scene = new Scene());
|
||||||
|
gl.SetRenderPipeline(Basic2DPipeline.Pipeline);
|
||||||
|
|
||||||
|
DrawObject2D obj = new DrawObject2D()
|
||||||
|
{
|
||||||
|
Color = Color4.Red
|
||||||
|
};
|
||||||
|
obj.ApplyCircle();
|
||||||
|
scene.Objects.Add(obj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue