+ 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
|
||||
{
|
||||
private bool _renderContinuesly;
|
||||
|
||||
protected GenericCamera _viewportCamera;
|
||||
|
||||
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 Vector2 WorldScale { get; set; }
|
||||
|
||||
public GenericWPFWindow(bool renderContinuesly = false)
|
||||
public GenericWPFWindow()
|
||||
{
|
||||
_renderContinuesly = renderContinuesly;
|
||||
|
||||
Ready += Init;
|
||||
Render += Rendering;
|
||||
|
|
@ -49,13 +46,13 @@ namespace SM.Base
|
|||
GenericWindowCode.Resize(this);
|
||||
}
|
||||
|
||||
public void Start()
|
||||
public void Start(bool renderContinuesly = false)
|
||||
{
|
||||
GLWpfControlSettings settings = new GLWpfControlSettings()
|
||||
{
|
||||
MajorVersion = GLSettings.ForcedVersion.MajorVersion,
|
||||
MinorVersion = GLSettings.ForcedVersion.MinorVersion,
|
||||
RenderContinuously = _renderContinuesly
|
||||
RenderContinuously = renderContinuesly
|
||||
};
|
||||
base.Start(settings);
|
||||
}
|
||||
|
|
@ -74,7 +71,7 @@ namespace SM.Base
|
|||
public TScene CurrentScene => _scene;
|
||||
public RenderPipeline<TScene> RenderPipeline => _renderPipeline;
|
||||
|
||||
public GenericWPFWindow(bool renderContinuesly = false) : base(renderContinuesly)
|
||||
public GenericWPFWindow() : base()
|
||||
{
|
||||
_viewportCamera = new TCamera();
|
||||
}
|
||||
|
|
@ -97,7 +94,7 @@ namespace SM.Base
|
|||
{
|
||||
_scene = scene;
|
||||
scene.Activate();
|
||||
RenderPipeline.SceneChanged(scene);
|
||||
RenderPipeline?.SceneChanged(scene);
|
||||
}
|
||||
|
||||
public void SetRenderPipeline(RenderPipeline<TScene> renderPipeline)
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ namespace SM.Base
|
|||
where TCamera : GenericCamera, new()
|
||||
{
|
||||
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.Mvp = PostProcessEffect.Model *
|
||||
|
|
|
|||
|
|
@ -64,6 +64,7 @@ namespace SM.OGL
|
|||
/// </summary>
|
||||
public virtual void Dispose()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -82,6 +82,12 @@ namespace SM.OGL.Shaders
|
|||
/// <inheritdoc />
|
||||
public override ObjectLabelIdentifier TypeIdentifier { get; } = ObjectLabelIdentifier.Program;
|
||||
|
||||
public void Update(ShaderFileCollection newShaderFiles)
|
||||
{
|
||||
ShaderFileFiles = newShaderFiles;
|
||||
Recompile();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads the shader to the GPU.
|
||||
/// </summary>
|
||||
|
|
@ -106,6 +112,11 @@ namespace SM.OGL.Shaders
|
|||
Load();
|
||||
}
|
||||
|
||||
public override void Dispose()
|
||||
{
|
||||
GL.DeleteShader(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draws the mesh.
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -47,6 +47,9 @@ namespace SM.OGL.Shaders
|
|||
{
|
||||
var name =
|
||||
$"{prefix}{Path.GetFileNameWithoutExtension(filePath.Substring(path.Length)).Replace('.', '_')}";
|
||||
|
||||
if (Extensions.ContainsKey(name)) continue;
|
||||
|
||||
Extensions.Add(name, new ShaderFile(reader.ReadToEnd()));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,9 +20,7 @@ namespace SM2D.Pipelines
|
|||
|
||||
protected override void RenderProcess(ref DrawContext context, Scene.Scene scene)
|
||||
{
|
||||
|
||||
Framebuffer.Screen.Activate(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
|
||||
if (scene != null) scene.Draw(context);
|
||||
scene?.Draw(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -26,7 +26,7 @@ namespace SM2D
|
|||
|
||||
SMRenderer.DefaultMaterialShader = Default2DShader.MaterialShader;
|
||||
|
||||
SetRenderPipeline(Default2DPipeline.Pipeline);
|
||||
//SetRenderPipeline(Default2DPipeline.Pipeline);
|
||||
}
|
||||
|
||||
protected override void Rendering(TimeSpan delta)
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ using System.Windows.Shapes;
|
|||
using OpenTK.Graphics;
|
||||
using SM2D;
|
||||
using SM2D.Drawing;
|
||||
using SM2D.Pipelines;
|
||||
using SM2D.Scene;
|
||||
|
||||
namespace SM_WPF_TEST
|
||||
|
|
@ -37,10 +38,13 @@ namespace SM_WPF_TEST
|
|||
gl.Start();
|
||||
|
||||
gl.SetScene(scene = new Scene());
|
||||
gl.SetRenderPipeline(Default2DPipeline.Pipeline);
|
||||
|
||||
DrawObject2D cube = new DrawObject2D();
|
||||
cube.Color = Color4.Blue;
|
||||
scene.Objects.Add(cube);
|
||||
|
||||
new Window1().Show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -61,6 +61,9 @@
|
|||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
</ApplicationDefinition>
|
||||
<Compile Include="Window1.xaml.cs">
|
||||
<DependentUpon>Window1.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Page Include="MainWindow.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
|
|
@ -73,6 +76,10 @@
|
|||
<DependentUpon>MainWindow.xaml</DependentUpon>
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Page Include="Window1.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<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