1
1
using System ;
2
+ using System . Collections . Concurrent ;
2
3
using System . Collections . Generic ;
3
4
using System . Diagnostics ;
4
5
using System . IO ;
@@ -76,6 +77,8 @@ public abstract class BaseRenderer
76
77
/// <summary>The track follower for the main camera</summary>
77
78
public TrackFollower CameraTrackFollower ;
78
79
80
+ public bool RenderThreadJobWaiting ;
81
+
79
82
/// <summary>Holds a reference to the current interface type of the game (Used by the renderer)</summary>
80
83
public InterfaceType CurrentInterface
81
84
{
@@ -315,6 +318,7 @@ protected BaseRenderer(HostInterface CurrentHost, BaseOptions CurrentOptions, Fi
315
318
Fonts = new Fonts ( currentHost , currentOptions . Font ) ;
316
319
VisibilityThread = new Thread ( vt ) ;
317
320
VisibilityThread . Start ( ) ;
321
+ RenderThreadJobs = new ConcurrentQueue < ThreadStart > ( ) ;
318
322
}
319
323
320
324
~ BaseRenderer ( )
@@ -687,15 +691,15 @@ public void InitializeVisibility()
687
691
{
688
692
for ( int i = 0 ; i < StaticObjectStates . Count ; i ++ )
689
693
{
690
- VAOExtensions . CreateVAO ( ref StaticObjectStates [ i ] . Prototype . Mesh , false , DefaultShader . VertexLayout , this ) ;
694
+ VAOExtensions . CreateVAO ( StaticObjectStates [ i ] . Prototype . Mesh , false , DefaultShader . VertexLayout , this ) ;
691
695
if ( StaticObjectStates [ i ] . Matricies != null )
692
696
{
693
697
GL . CreateBuffers ( 1 , out StaticObjectStates [ i ] . MatrixBufferIndex ) ;
694
698
}
695
699
}
696
700
for ( int i = 0 ; i < DynamicObjectStates . Count ; i ++ )
697
701
{
698
- VAOExtensions . CreateVAO ( ref DynamicObjectStates [ i ] . Prototype . Mesh , false , DefaultShader . VertexLayout , this ) ;
702
+ VAOExtensions . CreateVAO ( DynamicObjectStates [ i ] . Prototype . Mesh , false , DefaultShader . VertexLayout , this ) ;
699
703
if ( DynamicObjectStates [ i ] . Matricies != null )
700
704
{
701
705
GL . CreateBuffers ( 1 , out DynamicObjectStates [ i ] . MatrixBufferIndex ) ;
@@ -1051,7 +1055,7 @@ public void ResetShader(Shader Shader)
1051
1055
1052
1056
if ( lastError != ErrorCode . NoError )
1053
1057
{
1054
- throw new InvalidOperationException ( $ "OpenGL Error: { lastError } ") ;
1058
+ // throw new InvalidOperationException($"OpenGL Error: {lastError}");
1055
1059
}
1056
1060
}
1057
1061
#endif
@@ -1736,7 +1740,7 @@ public void SetCursor(OpenTK.MouseCursor newCursor)
1736
1740
1737
1741
/// <summary>Sets the window state</summary>
1738
1742
/// <param name="windowState">The new window state</param>
1739
- public void SetWindowState ( OpenTK . WindowState windowState )
1743
+ public void SetWindowState ( WindowState windowState )
1740
1744
{
1741
1745
GameWindow . WindowState = windowState ;
1742
1746
if ( windowState == WindowState . Fullscreen )
@@ -1762,5 +1766,23 @@ public void SetWindowSize(int width, int height)
1762
1766
SetWindowState ( WindowState . Maximized ) ;
1763
1767
}
1764
1768
}
1769
+
1770
+ public ConcurrentQueue < ThreadStart > RenderThreadJobs ;
1771
+
1772
+ /// <summary>This method is used during loading to run commands requiring an OpenGL context in the main render loop</summary>
1773
+ /// <param name="job">The OpenGL command</param>
1774
+ /// <param name="timeout">The timeout</param>
1775
+ public void RunInRenderThread ( ThreadStart job , int timeout )
1776
+ {
1777
+ RenderThreadJobs . Enqueue ( job ) ;
1778
+ //Don't set the job to available until after it's been loaded into the queue
1779
+ RenderThreadJobWaiting = true ;
1780
+ //Failsafe: If our job has taken more than the timeout, stop waiting for it
1781
+ //A missing texture is probably better than an infinite loadscreen
1782
+ lock ( job )
1783
+ {
1784
+ Monitor . Wait ( job , timeout ) ;
1785
+ }
1786
+ }
1765
1787
}
1766
1788
}
0 commit comments