private void Bw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { if (Vertices == null) { return; } //Globals.GUIThreadOwner.Invoke((MethodInvoker)delegate // { int MSize = TexturedVertex.Size; GL.GenVertexArrays(1, out VAO); GL.GenBuffers(1, out VBO); GL.GenBuffers(1, out EBO); GL.BindVertexArray(VAO); GL.BindBuffer(BufferTarget.ArrayBuffer, VBO); GL.BufferData(BufferTarget.ArrayBuffer, Vertices.Length * MSize, Vertices, BufferUsageHint.DynamicDraw); GL.BindBuffer(BufferTarget.ElementArrayBuffer, EBO); GL.BufferData(BufferTarget.ElementArrayBuffer, Indices.Length * sizeof(int), Indices, BufferUsageHint.StaticDraw); // vertex positions GL.EnableVertexAttribArray(0); GL.VertexAttribPointer(0, 3, VertexAttribPointerType.Float, false, MSize, 0); // vertex normals GL.EnableVertexAttribArray(1); GL.VertexAttribPointer(1, 3, VertexAttribPointerType.Float, false, MSize, sizeof(float) * 3); // vertex texture coords GL.EnableVertexAttribArray(2); GL.VertexAttribPointer(2, 2, VertexAttribPointerType.Float, false, MSize, sizeof(float) * 6); // }); _backgroundWorker.Dispose(); _backgroundWorker = null; VerticesLength = Vertices.Length; IndicesLength = Indices.Length; //Indices = null; // Vertices = null; IsSetup = true; if (Settings.TerrainPhysics == true) { MMessageBus.LoadingStatus(this, "Preparing:" + TileX + "," + TileY); SetupPhysics(); //must run on main thread } }
public void Setup(MAstroBody body) { string sText = string.Format("Earth\\{0}\\biome\\{1}_{2}.png", ZoomLevel, TileX, TileY); sText = Path.Combine(Settings.TileDataPath, sText); if (!File.Exists(sText)) { return; } CurrentBody = body; if (_backgroundWorker != null) { _backgroundWorker.CancelAsync(); } ; Console.WriteLine("Memory:" + GC.GetTotalMemory(false)); MMessageBus.LoadingStatus(this, "Loading:" + TileX + "," + TileY); _backgroundWorker = new BackgroundWorker(); _backgroundWorker.DoWork += Bw_DoWork; _backgroundWorker.RunWorkerCompleted += Bw_RunWorkerCompleted; _backgroundWorker.WorkerSupportsCancellation = true; _backgroundWorker.RunWorkerAsync(body); }