private void SetTextureInSeperateThread(SlimDX.Direct3D10.Device device, ShaderHelper helper) { updateRequired = false; if (this.TextureMipMaps == null || this.TextureMipMaps.Length < 1) { return; } Image[] clones = new Image[this.mipmaps.Length]; for (int i = 0; i < mipmaps.Length; i++) { clones[i] = mipmaps[i].Clone() as Image; } BackgroundWorker worker = new BackgroundWorker(); worker.DoWork += (o, e) => { Image [] img = e.Argument as Image[]; try { if (TextureIndex >= 0 && img != null) { byte[] bytes = ImageConverter.ConvertImageToBytes(img[0]); SlimDX.Direct3D10.Texture2D tex = ImageConverter.ConvertBytesToTexture2D(device, bytes); helper.TextureSet[TextureIndex].TextureImage = tex; foreach(Image i in img) i.Dispose(); img = null; } } catch (SlimDX.Direct3D10.Direct3D10Exception) { } }; worker.RunWorkerCompleted += (o, e) => { worker.Dispose(); }; worker.RunWorkerAsync(clones); }
public virtual void Render(Device device, ShaderHelper shaderHelper) { if (vertexBuffer != null && Topology != PrimitiveTopology.Undefined) { device.InputAssembler.SetInputLayout(vertexLayout); device.InputAssembler.SetPrimitiveTopology(Topology); device.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(vertexBuffer, Marshal.SizeOf(typeof(Vertex)), 0)); if (indexBuffer != null) device.InputAssembler.SetIndexBuffer(indexBuffer, Format.R32_UInt, 0); shaderHelper.ConstantBufferSet.World = World; shaderHelper.ConstantBufferSet.LocalRotation = RotationMatrix; shaderHelper.ConstantBufferSet.TextureIndex = TextureIndex; shaderHelper.ApplyEffects(); if (indexBuffer != null) device.DrawIndexed(Vertices.NumElements, 0, 0); else { device.Draw(Vertices.NumElements, 0); } } }
public override void Render(SlimDX.Direct3D10.Device device, ShaderHelper shaderHelper) { if (updateRequired) { SetTextureInSeperateThread(device, shaderHelper); } base.Render(device, shaderHelper); }