Skip to content

Commit

Permalink
version upgrade.
Browse files Browse the repository at this point in the history
  • Loading branch information
zhujie authored and zhujie committed Jun 13, 2023
1 parent 4138d70 commit 28d07be
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 37 deletions.
72 changes: 38 additions & 34 deletions OpenTkWPFHost/Control/BitmapOpenTkControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public Brush FpsBrush

public BitmapOpenTkControl() : base()
{
this.SizeChanged += ThreadOpenTkControl_SizeChanged;
}

protected override void OnLoaded(object sender, RoutedEventArgs args)
Expand Down Expand Up @@ -99,6 +100,7 @@ private void CompositionTarget_Rendering(object sender, EventArgs e)
this.InvalidateVisual();
}


private void ThreadOpenTkControl_SizeChanged(object sender, SizeChangedEventArgs e)
{
_recentTarget = this.RenderSetting.CreateRenderTarget(this);
Expand Down Expand Up @@ -240,7 +242,6 @@ private Pipeline<BitmapRenderArgs> BuildPipeline(TaskScheduler glContextTaskSche
return new Pipeline<BitmapRenderArgs>(renderBlock, canvasBlock);
}

private RenderSetting _workingRenderSetting;

private MultiBitmapCanvas _renderCanvas;

Expand All @@ -251,9 +252,43 @@ protected override void StartRender()
_renderTokenSource = new CancellationTokenSource();
var renderer = this.Renderer;
var glSettings = this.GlSettings;
_workingRenderSetting = this.RenderSetting;
var workingRenderSetting = this.RenderSetting;
Initialize(workingRenderSetting);
_recentTarget = workingRenderSetting.CreateRenderTarget(this);
_renderCanvas = new MultiBitmapCanvas((int)(_maxParallelism * 3));
_multiStoragePixelBuffer = new MultiPixelBuffer(_maxParallelism * 3);
var scheduler = TaskScheduler.FromCurrentSynchronizationContext();
_mainContextWrapper = glSettings.NewContext();
_mainContextWrapper.MakeCurrent();
var samples = glSettings.MSAASamples;
if (samples > 1)
{
this._frameBuffer = new OffScreenMSAAFrameBuffer(samples);
GL.Enable(EnableCap.Multisample);
}
else
{
this._frameBuffer = new SimpleFrameBuffer();
}

GL.Enable(EnableCap.DebugOutput);
GL.DebugMessageCallback(DebugProc, IntPtr.Zero);
_taskScheduler = new GLTaskScheduler(_mainContextWrapper, DebugProc);
var pipeline = BuildPipeline(_taskScheduler, scheduler);
_renderTask = Task.Run(async () =>
{
using (_renderTokenSource)
{
await RenderThread(_renderTokenSource.Token, _mainContextWrapper, pipeline, renderer,
_renderSemaphoreEnable);
}
});
}

private void Initialize(RenderSetting workingRenderSetting)
{
var parallelismMax = (uint)Environment.ProcessorCount / 2; //hyper threading or P-E cores?
switch (_workingRenderSetting.RenderTactic)
switch (workingRenderSetting.RenderTactic)
{
case RenderTactic.Default:
_isInternalTrigger = false;
Expand Down Expand Up @@ -294,37 +329,6 @@ protected override void StartRender()
default:
throw new ArgumentOutOfRangeException();
}

_recentTarget = _workingRenderSetting.CreateRenderTarget(this);
_renderCanvas = new MultiBitmapCanvas((int)(_maxParallelism * 3));
_multiStoragePixelBuffer = new MultiPixelBuffer(_maxParallelism * 3);
this.SizeChanged += ThreadOpenTkControl_SizeChanged;
var scheduler = TaskScheduler.FromCurrentSynchronizationContext();
_mainContextWrapper = glSettings.NewContext();
_mainContextWrapper.MakeCurrent();
var samples = glSettings.MSAASamples;
if (samples > 1)
{
this._frameBuffer = new OffScreenMSAAFrameBuffer(samples);
GL.Enable(EnableCap.Multisample);
}
else
{
this._frameBuffer = new SimpleFrameBuffer();
}

GL.Enable(EnableCap.DebugOutput);
GL.DebugMessageCallback(DebugProc, IntPtr.Zero);
_taskScheduler = new GLTaskScheduler(_mainContextWrapper, DebugProc);
var pipeline = BuildPipeline(_taskScheduler, scheduler);
_renderTask = Task.Run(async () =>
{
using (_renderTokenSource)
{
await RenderThread(_renderTokenSource.Token, _mainContextWrapper, pipeline, renderer,
_renderSemaphoreEnable);
}
});
}

private GLTaskScheduler _taskScheduler;
Expand Down
6 changes: 3 additions & 3 deletions OpenTkWPFHost/OpenTkWPFHost.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
<Description>OpenTK WPF host control</Description>
<Copyright>Copyright © 2021</Copyright>
<UseWPF>true</UseWPF>
<Version>4.0.0.1</Version>
<AssemblyVersion>4.0.0.1</AssemblyVersion>
<FileVersion>4.0.0.1</FileVersion>
<Version>4.1.0.0</Version>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<FileVersion>4.1.0.0</FileVersion>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<OutputPath>bin\$(Configuration)\</OutputPath>
<Authors>Karl Zhu</Authors>
Expand Down

0 comments on commit 28d07be

Please sign in to comment.