+ WPF Support

This commit is contained in:
Michel Fedde 2021-01-31 12:54:50 +01:00
parent 6f23a80f7f
commit 41421b1df9
12 changed files with 94 additions and 14 deletions

View file

@ -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)

View file

@ -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 *

View file

@ -64,6 +64,7 @@ namespace SM.OGL
/// </summary>
public virtual void Dispose()
{
}
/// <summary>

View file

@ -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>

View file

@ -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()));
}
}

View file

@ -62,7 +62,7 @@ namespace SM.OGL.Shaders
foreach (var kvp in StringOverrides)
_data = _data.Replace("//!" + kvp.Key, kvp.Value);
}
internal void Compile(GenericShader shader, ShaderType type)
{
if (_id < 0)

View file

@ -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);
}
}
}

View file

@ -26,7 +26,7 @@ namespace SM2D
SMRenderer.DefaultMaterialShader = Default2DShader.MaterialShader;
SetRenderPipeline(Default2DPipeline.Pipeline);
//SetRenderPipeline(Default2DPipeline.Pipeline);
}
protected override void Rendering(TimeSpan delta)