Exemple #1
0
 public void Render()
 {
     if (Disposed)
     {
         return;
     }
     if (_needUpdate)
     {
         lock (_updateLock)
         {
             _vertex?.DisposeAll();
             _vertex = _chunkVertexArrayProvider.ToElementArray().GetHandle();
             _chunkVertexArrayProvider = null;
             _needUpdate = false;
         }
     }
     lock (_renderLock)
     {
         if (_vertex == null || _shader == null)
         {
             return;
         }
         _textureDictionary.Bind();
         _shader.Use();
         _shader.Model      = Matrix4.Identity;
         _shader.Projection = _projectionMatrix.GetMatrix();
         _shader.View       = _viewMatrix.GetMatrix();
         _vertex.Bind();
         _vertex.Render();
     }
 }
Exemple #2
0
 public void Initialize()
 {
     Disposed                  = false;
     _shader                   = new BlockShader();
     _shader.Model             = Matrix4.Identity;
     _textureDictionary        = _textureAtlasProvider();
     _chunkVertexArrayProvider = new ChunkVertexArrayProvider(_chunk, _textureAtlasProvider);
     Logger.GetLogger <ChunkRenderer>().Info($"Initalized {_chunk.X}, {_chunk.Z}");
     GenerateMeshes();
 }
Exemple #3
0
 internal void InitializeWithShader(BlockShader shader)
 {
     Disposed     = false;
     _shaderOwner = false;
     _shader      = shader;
     /*_shader.Model = Matrix4.Identity;*/
     _textureDictionary        = _textureAtlasProvider();
     _chunkVertexArrayProvider = new ChunkVertexArrayProvider(_chunk, _textureAtlasProvider);
     //Logger.GetLogger<ChunkRenderer>().Info($"Initalized {_chunk.X}, {_chunk.Z}");
 }
Exemple #4
0
 public void Dispose()
 {
     if (Disposed)
     {
         return;
     }
     lock (_renderLock)
     {
         Disposed = true;
         if (_shaderOwner)
         {
             (_shader as IDisposable)?.Dispose();
         }
         _shader = null;
         _chunkVertexArrayProvider.StopCalculation();
         _chunkVertexArrayProvider = null;
     }
 }
Exemple #5
0
        public void GenerateMeshes()
        {
            if (Disposed)
            {
                return;
            }
#if SyncCalculateChunk
            ChunkCalculatorThread.Invoke(() =>
#else
            ThreadHelper.StartThread(() =>
#endif
            {
                lock (_updateLock)
                {
                    _chunkVertexArrayProvider = new ChunkVertexArrayProvider(_chunk, _textureAtlasProvider);
                    _needUpdate = _chunkVertexArrayProvider.Calculate();
                }
#if SyncCalculateChunk
            }, true);
#else
            }, "ChunkCalculatorThread", true);