Skip to content

Commit

Permalink
Merge pull request #619 from FUSEEProjectTeam/feature/618-cannot-set-…
Browse files Browse the repository at this point in the history
…minwidth-and-minheight-for-imguirendercanvasimp

Feature/618 cannot set minwidth and minheight for imguirendercanvasimp
  • Loading branch information
wrestledBearOnce authored Sep 8, 2022
2 parents 2ca2091 + cf586a4 commit bdeaa0f
Show file tree
Hide file tree
Showing 18 changed files with 332 additions and 680 deletions.
1 change: 0 additions & 1 deletion Examples/Complete/PointCloudPotree2/Core/PtRenderParams.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Fusee.Engine.Core.Effects;
using Fusee.Engine.Core.ShaderShards;
using Fusee.PointCloud.Common;
using System;
using System.IO;

namespace Fusee.Examples.PointCloudPotree2.Core
Expand Down
10 changes: 5 additions & 5 deletions Examples/Complete/PointCloudPotree2/ImGui/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ public class PointCloudPotree2ImGui
public static void Main()
{
// Inject Fusee.Engine.Base InjectMe dependencies
IO.IOImp = new Fusee.Base.Imp.Desktop.IOImp();
IO.IOImp = new IOImp();

var fap = new Fusee.Base.Imp.Desktop.FileAssetProvider("Assets");
var fap = new FileAssetProvider("Assets");
fap.RegisterTypeHandler(
new AssetHandler
{
Expand Down Expand Up @@ -59,9 +59,9 @@ public static void Main()
var app = new ImGuiApp();

var icon = AssetStorage.Get<ImageData>("FuseeIconTop32.png");
app.CanvasImplementor = new Fusee.ImGuiImp.Desktop.ImGuiRenderCanvasImp(icon);
app.ContextImplementor = new Fusee.Engine.Imp.Graphics.Desktop.RenderContextImp(app.CanvasImplementor);
Input.AddDriverImp(new Fusee.ImGuiImp.Desktop.ImGuiInputImp(app.CanvasImplementor));
app.CanvasImplementor = new ImGuiImp.Desktop.ImGuiRenderCanvasImp(icon);
app.ContextImplementor = new Engine.Imp.Graphics.Desktop.RenderContextImp(app.CanvasImplementor);
Input.AddDriverImp(new ImGuiImp.Desktop.ImGuiInputImp(app.CanvasImplementor));

app.InitApp();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Fusee.Engine.Core.Effects;
using Fusee.Engine.Core.ShaderShards;
using Fusee.PointCloud.Common;
using System;
using System.IO;

namespace Fusee.Examples.PointCloudPotree2.Gui
Expand Down
25 changes: 25 additions & 0 deletions src/Engine/Common/IRenderCanvasImp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,31 @@ public interface IRenderCanvasImp
/// <param name="borderHidden">Show the window border or not.</param>
void SetWindowSize(int width, int height, int posx = -1, int posy = -1, bool borderHidden = false);

/// <summary>
/// Does the initialize of this instance.
/// </summary>
public void DoInit();

/// <summary>
/// Does the unload of this instance.
/// </summary>
public void DoUnLoad();

/// <summary>
/// Does the update of this instance.
/// </summary>
public void DoUpdate();

/// <summary>
/// Does the render of this instance.
/// </summary>
public void DoRender();

/// <summary>
/// Does the resize on this instance.
/// </summary>
public void DoResize(int width, int height);

/// <summary>
/// Closes the GameWindow with a call to opentk.
/// </summary>
Expand Down
3 changes: 1 addition & 2 deletions src/Engine/Core/Effects/ComputeEffect.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;

namespace Fusee.Engine.Core.Effects
{
Expand Down
3 changes: 1 addition & 2 deletions src/Engine/Core/Effects/ShaderEffect.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;

namespace Fusee.Engine.Core.Effects
{
Expand Down
1 change: 0 additions & 1 deletion src/Engine/Core/ModuleExtensionPoint.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Fusee.Engine.Common;
using System;

namespace Fusee.Engine.Core
{
Expand Down
10 changes: 6 additions & 4 deletions src/Engine/Core/RenderCanvas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,12 +231,14 @@ public void InitApp()
RC.CleanupResourceManagers();
};

CanvasImplementor.Resize += delegate
CanvasImplementor.Resize += (s, e) =>
{
if (IsShuttingDown) return;
Width = e.Width;
Height = e.Height;
RC.DefaultState.CanvasWidth = Width;
RC.DefaultState.CanvasHeight = Height;
Resize(new ResizeEventArgs(Width, Height));
Resize(e);
};
}

Expand Down Expand Up @@ -387,7 +389,7 @@ public void CloseGameWindow()
public int Width
{
get { return CanvasImplementor.Width; }
set { CanvasImplementor.Width = value; }
private set { CanvasImplementor.Width = value; }
}

/// <summary>
Expand All @@ -399,7 +401,7 @@ public int Width
public int Height
{
get { return CanvasImplementor.Height; }
set { CanvasImplementor.Height = value; }
private set { CanvasImplementor.Height = value; }
}

/// <summary>
Expand Down
1 change: 0 additions & 1 deletion src/Engine/Core/ScenePicker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using Fusee.Xene;
using System;
using System.Collections.Generic;
using System.Linq;

namespace Fusee.Engine.Core
{
Expand Down
1 change: 0 additions & 1 deletion src/Engine/Core/TextureManager.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Fusee.Engine.Common;
using System;
using System.Collections.Generic;
using System.Linq;

namespace Fusee.Engine.Core
{
Expand Down
13 changes: 5 additions & 8 deletions src/Engine/Imp/Graphics/Android/RenderCanvasImp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -310,49 +310,46 @@ public void Run()

#endregion Events

#region Internal Members

/// <summary>
/// Does the initialize of this instance.
/// </summary>
protected internal void DoInit()
public void DoInit()
{
Init?.Invoke(this, new InitEventArgs());
}

/// <summary>
/// Does the unload of this instance.
/// </summary>
protected internal void DoUnLoad()
public void DoUnLoad()
{
UnLoad?.Invoke(this, new InitEventArgs());
}

/// <summary>
/// Does the update of this instance.
/// </summary>
protected internal void DoUpdate()
public void DoUpdate()
{
Update?.Invoke(this, new RenderEventArgs());
}

/// <summary>
/// Does the render of this instance.
/// </summary>
protected internal void DoRender()
public void DoRender()
{
Render?.Invoke(this, new RenderEventArgs());
}

/// <summary>
/// Does the resize on this instance.
/// </summary>
protected internal void DoResize(int width, int height)
public void DoResize(int width, int height)
{
Resize?.Invoke(this, new ResizeEventArgs(width, height));
}

#endregion Internal Members
}

internal class RenderCanvasGameView : AndroidGameView
Expand Down
8 changes: 8 additions & 0 deletions src/Engine/Imp/Graphics/Blazor/RenderCanvasImp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,14 @@ public void DoInit()
Init?.Invoke(this, new InitEventArgs());
}

/// <summary>
/// Does the unload of this instance.
/// </summary>
public void DoUnLoad()
{
UnLoad?.Invoke(this, new InitEventArgs());
}

/// <summary>
/// Does perform the update of this instance
/// </summary>
Expand Down
157 changes: 157 additions & 0 deletions src/Engine/Imp/Graphics/Desktop/RenderCanvasGameWindow.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
using Fusee.Engine.Common;
using OpenTK.Graphics.OpenGL;
using OpenTK.Windowing.Desktop;
using OpenTK.Windowing.GraphicsLibraryFramework;
using System;

namespace Fusee.Engine.Imp.Graphics.Desktop
{
internal class RenderCanvasGameWindow : GameWindow
{
#region Fields

private readonly RenderCanvasImp _renderCanvasImp;

/// <summary>
/// True if the GameWindow/ the application uses multiple threads.
/// With OpenTK 4.7 we need to use the "new" modifier to hide the GameWindow.IsMultithreaded property, which became obsolete in this version.
/// </summary>
public new bool IsMultiThreaded { get; private set; } = false;

/// <summary>
/// Gets the delta time.
/// The delta time is the time that was required to render the last frame in milliseconds.
/// This value can be used to determine the frames per second of the application.
/// </summary>
/// <value>
/// The delta time in milliseconds.
/// </value>
public float DeltaTime { get; private set; }

/// <summary>
/// Gets the delta time.
/// The delta time is the time that was required to update the last frame in milliseconds.
/// </summary>
/// <value>
/// The delta time in milliseconds.
/// </value>
public float DeltaTimeUpdate { get; private set; }

/// <summary>
/// Gets and sets a value indicating whether [blending].
/// Blending is used to render transparent objects.
/// </summary>
/// <value>
/// <c>true</c> if [blending]; otherwise, <c>false</c>.
/// </value>
public bool Blending
{
get => GL.IsEnabled(EnableCap.Blend);
set
{
if (value)
{
GL.Enable(EnableCap.Blend);
GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha);
}
else
{
GL.Disable(EnableCap.Blend);
}
}
}

#endregion

#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="RenderCanvasGameWindow"/> class.
/// </summary>
/// <param name="renderCanvasImp">The render canvas implementation.</param>
/// <param name="width">The width.</param>
/// <param name="height">The height.</param>
/// <param name="antiAliasing">if set to <c>true</c> [anti aliasing] is on.</param>
/// <param name="minimumWidth">The minimum width of the game window.</param>
/// <param name="minimumHeight">The minimum height of the game window</param>
/// <param name="isMultithreaded">If true OpenTk will call run() in a new Thread. The default value is false.</param>
/// <param name="startVisible">Should the window be visible from the start, default: true.</param>
public RenderCanvasGameWindow(RenderCanvasImp renderCanvasImp, int width, int height, bool antiAliasing, bool isMultithreaded = false, bool startVisible = true, int minimumWidth = 1280, int minimumHeight = 720)
: base(new GameWindowSettings(), new NativeWindowSettings
{
Size = new OpenTK.Mathematics.Vector2i(width, height),
Profile = OpenTK.Windowing.Common.ContextProfile.Core,
Flags = OpenTK.Windowing.Common.ContextFlags.ForwardCompatible,
StartVisible = startVisible,
MinimumSize = new OpenTK.Mathematics.Vector2i(minimumWidth, minimumHeight)
})
{
IsMultiThreaded = isMultithreaded;
_renderCanvasImp = renderCanvasImp;
_renderCanvasImp.Width = width;
_renderCanvasImp.Height = height;
}

#endregion

#region Overrides

protected override void OnLoad()
{
// Check for necessary capabilities
string version = GL.GetString(StringName.Version);

int major = version[0];
// int minor = (int)version[2];

if (major < 2)
{
throw new InvalidOperationException("You need at least OpenGL 2.0 to run this example. GLSL not supported.");
}

// Use VSync!
VSync = OpenTK.Windowing.Common.VSyncMode.On;

_renderCanvasImp.DoInit();
}

protected override void OnUnload()
{
_renderCanvasImp.DoUnLoad();
}

protected override void OnResize(OpenTK.Windowing.Common.ResizeEventArgs e)
{
base.OnResize(e);

if (_renderCanvasImp != null)
{
_renderCanvasImp.Width = e.Width;
_renderCanvasImp.Height = e.Height;
_renderCanvasImp.DoResize(e.Width, e.Height);
}
}

protected override void OnUpdateFrame(OpenTK.Windowing.Common.FrameEventArgs args)
{
base.OnUpdateFrame(args);

DeltaTimeUpdate = (float)args.Time;

if (KeyboardState.IsKeyPressed(OpenTK.Windowing.GraphicsLibraryFramework.Keys.F11))
WindowState = (WindowState != OpenTK.Windowing.Common.WindowState.Fullscreen) ? OpenTK.Windowing.Common.WindowState.Fullscreen : OpenTK.Windowing.Common.WindowState.Normal;

_renderCanvasImp?.DoUpdate();
}

protected override void OnRenderFrame(OpenTK.Windowing.Common.FrameEventArgs args)
{
base.OnRenderFrame(args);

DeltaTime = (float)args.Time;

_renderCanvasImp?.DoRender();
}

#endregion
}
}
Loading

0 comments on commit bdeaa0f

Please sign in to comment.