public void UpdateResource(IPluginOut ForPin, Device OnDevice) { if (this.FInvalidate || !this.FMeshes.ContainsKey(OnDevice)) { //Destroy old mesh DestroyResource(ForPin, OnDevice, false); if (this.FInput[0] == null) { return; } List <Mesh> meshes = new List <Mesh>(); Frame frame = FInput[0]; if (frame.Loaded) { Mesh mesh = new Mesh(OnDevice, frame.Indices.Length / 3, frame.Vertices.Length, MeshFlags.Dynamic | MeshFlags.Use32Bit, Frame.VertexDeclaration); DataStream vS = mesh.LockVertexBuffer(LockFlags.Discard); DataStream iS = mesh.LockIndexBuffer(LockFlags.Discard); vS.WriteRange(frame.FormattedVertices); iS.WriteRange(frame.Indices); mesh.UnlockIndexBuffer(); mesh.UnlockVertexBuffer(); this.FMeshes.Add(OnDevice, mesh); } } }
public void UpdateResource(IPluginOut ForPin, Device OnDevice) { if (this.runtime != null) { if (!this.FColorTex.ContainsKey(OnDevice)) { Texture t; if (OnDevice is DeviceEx) { t = new Texture(OnDevice, 320, 240, 1, Usage.Dynamic, Format.G32R32F, Pool.Default); } else { t = new Texture(OnDevice, 320, 240, 1, Usage.None, Format.G32R32F, Pool.Managed); } this.FColorTex.Add(OnDevice, t); } if (this.FInvalidate) { Texture tx = this.FColorTex[OnDevice]; Surface srf = tx.GetSurfaceLevel(0); DataRectangle rect = srf.LockRectangle(LockFlags.Discard); lock (this.m_colorlock) { rect.Data.WriteRange <float>(this.colorimage, 0, 320 * 240 * 2); } srf.UnlockRectangle(); this.FInvalidate = false; } } }
void IPluginDXResource.DestroyResource(IPluginOut pin, EX9.Device device, bool onlyUnmanaged) { foreach (var renderer in FWebRenderers) { renderer.DestroyResources(device); } }
void IPluginDXResource.UpdateResource(IPluginOut pin, EX9.Device device) { foreach (var renderer in FWebRenderers) { renderer.UpdateResources(device); } }
public void UpdateResource(IPluginOut ForPin, Device OnDevice) { if (this.FMeshes.ContainsKey(OnDevice)) { this.FMeshes[OnDevice].Dispose(); this.FMeshes.Remove(OnDevice); // = null; } List <Mesh> meshes = new List <Mesh>(); if (this.FBodies.SliceCount > 0) { int cnt = this.FBodies.SliceCount; for (int i = 0; i < cnt; i++) { RigidBody body = this.FBodies[i]; CollisionShape shape = body.CollisionShape; ShapeCustomData sd = (ShapeCustomData)shape.UserObject; BulletMesh m = sd.ShapeDef.GetMesh(OnDevice); meshes.AddRange(m.Meshes); } this.FMeshes.Add(OnDevice, Mesh.Concatenate(OnDevice, meshes.ToArray(), MeshFlags.Use32Bit | MeshFlags.Managed)); } }
public void UpdateResource(IPluginOut ForPin, Device OnDevice) { if (this.FMeshes.ContainsKey(OnDevice)) { this.FMeshes[OnDevice].Dispose(); this.FMeshes.Remove(OnDevice);// = null; } List<Mesh> meshes = new List<Mesh>(); if (this.FBodies.SliceCount > 0) { int cnt = this.FBodies.SliceCount; for (int i = 0; i < cnt; i++) { RigidBody body = this.FBodies[i]; CollisionShape shape = body.CollisionShape; ShapeCustomData sd = (ShapeCustomData)shape.UserObject; BulletMesh m = sd.ShapeDef.GetMesh(OnDevice); meshes.AddRange(m.Meshes); } this.FMeshes.Add(OnDevice,Mesh.Concatenate(OnDevice, meshes.ToArray(), MeshFlags.Use32Bit | MeshFlags.Managed)); } }
public void UpdateResource(IPluginOut ForPin, Device OnDevice) { //Called by the PluginHost every frame for every device. Therefore a plugin should only do //device specific operations here and still keep node specific calculations in the Evaluate call. if (FColladaModel != null) { Mesh m; if (!FDeviceMeshes.TryGetValue(OnDevice, out m)) { //if resource is not yet created on given Device, create it now if (FSelectedInstanceMeshes.Count > 0) { FLogger.Log(LogType.Debug, "Creating Resource..."); try { m = CreateUnion3D9Mesh(OnDevice, FSelectedInstanceMeshes); FDeviceMeshes.Add(OnDevice, m); } catch (Exception e) { FLogger.Log(LogType.Error, e.Message); } } } } }
public void UpdateResource(IPluginOut ForPin, Device OnDevice) { try { if (FLoadSWF.IsChanged) { if (FLoadSWF[0]) { //Debug.WriteLine("FLoadSWF.PinIsChanged"); _NeedsUpdate = true; } } if (FBufferMode.IsChanged) { //Debug.WriteLine("FBufferMode.PinIsChanged"); switch (FBufferMode[0]) { case BufferMode.Single: _BufferMode = 0; break; case BufferMode.Double: _BufferMode = 1; break; } _NeedsUpdate = true; } } catch (Exception ex) { FLogger.Log(LogType.Debug, "Exception in UpdateResource: " + ex.Message); if (ex.InnerException != null) { FLogger.Log(LogType.Debug, "inner: " + ex.InnerException.Message); } //if resource is not yet created on given Device, create it now _NeedsUpdate = true; } if (_NeedsUpdate) { RemoveResource(OnDevice); Sprite tSprite = new Sprite(OnDevice); FSprites.Add(OnDevice, tSprite); LoadSWF(OnDevice); _FNUIFlashPlayer.SetQualityString(FQuality[0].ToString()); _NeedsUpdate = false; } }
public void UpdateResource(IPluginOut ForPin, Device OnDevice) { try { Mesh mtry = FDeviceMeshes[OnDevice]; if (update) { RemoveResource(OnDevice); } } //if resource is not yet created on given Device, create it now catch { update = true; } if (update) { try { // create new Mesh Mesh NewMesh = new Mesh(OnDevice, NumIndices / 3, NumVertices, MeshFlags.Dynamic | MeshFlags.WriteOnly, VertexFormat.PositionNormal); // lock buffers sVx = NewMesh.LockVertexBuffer(LockFlags.Discard); sIx = NewMesh.LockIndexBuffer(LockFlags.Discard); // write buffers unsafe { fixed(sVxBuffer *FixTemp = &VxBuffer[0]) { IntPtr VxPointer = new IntPtr(FixTemp); sVx.WriteRange(VxPointer, sizeof(sVxBuffer) * NumVertices); } fixed(short *FixTemp = &IxBuffer[0]) { IntPtr IxPointer = new IntPtr(FixTemp); sIx.WriteRange(IxPointer, sizeof(short) * NumIndices); } } // unlock buffers NewMesh.UnlockIndexBuffer(); NewMesh.UnlockVertexBuffer(); FDeviceMeshes.Add(OnDevice, NewMesh); } finally { update = false; } } }
public void DestroyResource(IPluginOut ForPin, Device OnDevice, bool OnlyUnManaged) { if (this.FMesh != null) { this.FMesh.Dispose(); this.FMesh = null; } }
public void DestroyResource(IPluginOut ForPin, Device OnDevice, bool OnlyUnManaged) { if (this.FMeshes.ContainsKey(OnDevice)) { this.FMeshes[OnDevice].Dispose(); this.FMeshes.Remove(OnDevice);// = null; } }
public void DestroyResource(IPluginOut ForPin, Device OnDevice, bool OnlyUnManaged) { if (this.FDepthTex.ContainsKey(OnDevice)) { this.FDepthTex[OnDevice].Dispose(); this.FDepthTex.Remove(OnDevice); } }
public void DestroyResource(IPluginOut ForPin, Device OnDevice, bool OnlyUnManaged) { //Debug.WriteLine("DestroyResource"); //Called by the PluginHost whenever a resource for a specific pin needs to be destroyed on a specific device. //This is also called when the plugin is destroyed, so don't dispose dxresources in the plugins destructor/Dispose() RemoveResource(OnDevice); }
public void UpdateResource(IPluginOut ForPin, Device OnDevice) { /*try * { * Mesh mtry = FDeviceMeshes[OnDevice]; * if (update) * RemoveResource(OnDevice); * } * * //if resource is not yet created on given Device, create it now * catch * { * update = true; * } * * if (update) * { * try * { * // create new Mesh * Mesh NewMesh = new Mesh(OnDevice, NumIndices / 3, NumVertices, * MeshFlags.Dynamic | MeshFlags.WriteOnly, * VertexFormat.PositionNormal); * * // lock buffers * sVx = NewMesh.LockVertexBuffer(LockFlags.Discard); * sIx = NewMesh.LockIndexBuffer(LockFlags.Discard); * * // write buffers * unsafe * { * fixed (sVxBuffer* FixTemp = &VxBuffer[0]) * { * IntPtr VxPointer = new IntPtr(FixTemp); * sVx.WriteRange(VxPointer, sizeof(sVxBuffer) * NumVertices); * * } * fixed (short* FixTemp = &IxBuffer[0]) * { * IntPtr IxPointer = new IntPtr(FixTemp); * sIx.WriteRange(IxPointer, sizeof(short) * NumIndices); * } * } * * // unlock buffers * NewMesh.UnlockIndexBuffer(); * NewMesh.UnlockVertexBuffer(); * * FDeviceMeshes.Add(OnDevice, NewMesh); * } * finally * { * update = false; * } * }*/ }
private void CreateResource(IPluginOut ForPin, Device OnDevice) { //destroy resource if it exists if (FDeviceData.ContainsKey(OnDevice)) { DestroyResource(ForPin, OnDevice, false); } //call user create method to set the new device data FDeviceData.Add(OnDevice, CreateDeviceData(OnDevice)); }
public void DestroyResource(IPluginOut ForPin, Device OnDevice, bool OnlyUnManaged) { //dispose resources that were created on given OnDevice try { RemoveResource(OnDevice); } catch { //resource is not available for this device. good. nothing to do then. } }
public void UpdateResource(IPluginOut ForPin, Device OnDevice) { if (ForPin == this.FPinOutMesh) { bool update = this.FMeshes.ContainsKey(OnDevice); if (update && this.FInvalidate) { RemoveResource(OnDevice); } if (!update) { this.FInvalidate = true; } if (this.FInvalidate) { List <Mesh> meshes = new List <Mesh>(); for (int i = 0; i < this.FVertex.Count; i++) { Mesh mesh = new Mesh(OnDevice, this.FIndices[i].Length / 3, this.FVertex[i].Length, MeshFlags.Dynamic | MeshFlags.WriteOnly, Vertex.Format); DataStream vS = mesh.LockVertexBuffer(LockFlags.Discard); DataStream iS = mesh.LockIndexBuffer(LockFlags.Discard); vS.WriteRange(this.FVertex[i]); iS.WriteRange(this.FIndices[i]); mesh.UnlockVertexBuffer(); mesh.UnlockIndexBuffer(); meshes.Add(mesh); } Mesh merge = null; if (OnDevice is DeviceEx) { merge = Mesh.Concatenate(OnDevice, meshes.ToArray(), MeshFlags.Use32Bit); } else { merge = Mesh.Concatenate(OnDevice, meshes.ToArray(), MeshFlags.Use32Bit | MeshFlags.Managed); } this.FMeshes.Add(OnDevice, merge); foreach (Mesh m in meshes) { m.Dispose(); } } } }
public void UpdateResource(IPluginOut ForPin, Device OnDevice) { if (this.FInvalidate || !this.FMeshes.ContainsKey(OnDevice)) { //Destroy old mesh DestroyResource(ForPin, OnDevice, false); if (this.FInScene[0] == null) { return; } List <Mesh> meshes = new List <Mesh>(); for (int i = 0; i < this.FInScene[0].MeshCount; i++) { AssimpMesh assimpmesh = this.FInScene[0].Meshes[i]; Mesh mesh = new Mesh(OnDevice, assimpmesh.Indices.Count / 3, assimpmesh.VerticesCount, MeshFlags.Dynamic | MeshFlags.Use32Bit, assimpmesh.GetVertexBinding().ToArray()); DataStream vS = mesh.LockVertexBuffer(LockFlags.Discard); DataStream iS = mesh.LockIndexBuffer(LockFlags.Discard); assimpmesh.Write(vS); iS.WriteRange(assimpmesh.Indices.ToArray()); mesh.UnlockVertexBuffer(); mesh.UnlockIndexBuffer(); meshes.Add(mesh); } try { Mesh merge = null; if (OnDevice is DeviceEx) { merge = Mesh.Concatenate(OnDevice, meshes.ToArray(), MeshFlags.Use32Bit); } else { merge = Mesh.Concatenate(OnDevice, meshes.ToArray(), MeshFlags.Use32Bit | MeshFlags.Managed); } this.FMeshes.Add(OnDevice, merge); } catch (Exception ex) { } foreach (Mesh m in meshes) { m.Dispose(); } } }
public void UpdateResource(IPluginOut ForPin, Device OnDevice) { if (this.runtime != null) { if (!this.FDepthTex.ContainsKey(OnDevice)) { Texture t = null; if (OnDevice is DeviceEx) { t = new Texture(OnDevice, 320, 240, 1, Usage.Dynamic, Format.L16, Pool.Default); } else { t = new Texture(OnDevice, 320, 240, 1, Usage.None, Format.L16, Pool.Managed); } this.FDepthTex.Add(OnDevice, t); } if (this.FInvalidate) { Texture tx = this.FDepthTex[OnDevice]; Surface srf = tx.GetSurfaceLevel(0); DataRectangle rect = srf.LockRectangle(LockFlags.Discard); int pos = 0; lock (this.m_lock) { fixed(short *b = &this.rawdepth[0]) { short *ptr = b; for (int i = 0; i < 240; i++) { rect.Data.WriteRange((IntPtr)ptr, 320); pos += rect.Pitch; rect.Data.Position = pos; ptr += 320; } } } //rect.Data.WriteRange(this.depthimage); srf.UnlockRectangle(); this.FInvalidate = false; } } }
public void DestroyResource(IPluginOut ForPin, Device OnDevice, bool OnlyUnManaged) { if (FDeviceData.ContainsKey(OnDevice)) { try { DestroyDeviceData(FDeviceData[OnDevice], OnlyUnManaged); } finally { FDeviceData.Remove(OnDevice); } } }
public void DestroyResource(IPluginOut ForPin, Device OnDevice, bool OnlyUnManaged) { //called when a resource needs to be disposed on a given device //this is also called when the plugin is destroyed, //so don't dispose dxresources in the plugins destructor/Dispose() try { RemoveResource(OnDevice); } catch { //nothing to do } }
public void DestroyResource(IPluginOut ForPin, Device OnDevice, bool OnlyUnManaged) { //Called by the PluginHost whenever a resource for a specific pin needs to be destroyed on a specific device. //This is also called when the plugin is destroyed, so don't dispose dxresources in the plugins destructor/Dispose() Mesh m = FDeviceMeshes[OnDevice]; if (m != null) { FLogger.Log(LogType.Debug, "Destroying Resource..."); FDeviceMeshes.Remove(OnDevice); //dispose mesh m.Dispose(); } }
public void DestroyResource(IPluginOut ForPin, int OnDevice, bool OnlyUnManaged) { try { if (this.FMeshes.ContainsKey(OnDevice)) { Mesh m = this.FMeshes[OnDevice]; this.FMeshes.Remove(OnDevice); m.Dispose(); } } catch { } }
public void UpdateResource(IPluginOut ForPin, Device OnDevice) { //Called by the PluginHost every frame for every device. Therefore a plugin should only do //device specific operations here and still keep node specific calculations in the Evaluate call. try { Mesh m = FDeviceMeshes[OnDevice]; } catch { //if resource is not yet created on given Device, create it now //FHost.Log(TLogType.Debug, "Creating Resource..."); FDeviceMeshes.Add(OnDevice, createMesh(OnDevice)); } }
public void UpdateResource(IPluginOut ForPin, Device OnDevice) { //create device specific helpers on given device if not already present if (!FDeviceHelpers.ContainsKey(OnDevice)) { var dh = new DeviceHelpers( new Sprite(OnDevice), new Texture(OnDevice, 1, 1, 1, Usage.Dynamic, Format.L8, Pool.Default)); // Format.A8R8G8B8, Pool.Default) //need to fill texture white to be able to set color on sprite later DataRectangle tex = dh.Texture.LockRectangle(0, LockFlags.None); tex.Data.WriteByte(255); dh.Texture.UnlockRectangle(0); FDeviceHelpers.Add(OnDevice, dh); } }
public void UpdateResource(IPluginOut ForPin, Device OnDevice) { bool needsupdate = false; try { DeviceFont df = FDeviceFonts[OnDevice]; if (FFontInput.IsChanged || FSizeInput.IsChanged || FBoldInput.IsChanged || FItalicInput.IsChanged) { RemoveResource(OnDevice); needsupdate = true; } } catch { //if resource is not yet created on given Device, create it now needsupdate = true; } if (needsupdate) { //FHost.Log(TLogType.Debug, "Creating Resource..."); DeviceFont df = new DeviceFont(); FontWeight weight; if (FBoldInput[0]) { weight = FontWeight.Bold; } else { weight = FontWeight.Light; } df.Font = new SlimDX.Direct3D9.Font(OnDevice, FSizeInput[0], 0, weight, 0, FItalicInput[0], CharacterSet.Default, Precision.Default, FontQuality.Default, PitchAndFamily.Default, FFontInput[0].Name); df.Sprite = new Sprite(OnDevice); df.Texture = new Texture(OnDevice, 1, 1, 1, Usage.Dynamic, Format.L8, Pool.Default); // Format.A8R8G8B8, Pool.Default); //need to fill texture white to be able to set color on sprite later DataRectangle tex = df.Texture.LockRectangle(0, LockFlags.None); tex.Data.WriteByte(255); df.Texture.UnlockRectangle(0); FDeviceFonts.Add(OnDevice, df); } }
public void DestroyResource(IPluginOut ForPin, Device OnDevice, bool OnlyUnManaged) { //dispose resources that were created on given device DeviceHelpers dh = null; if (FDeviceHelpers.TryGetValue(OnDevice, out dh)) { dh.Dispose(); var ids = FFonts.Where(kv => kv.Value.Tag == OnDevice).Select(kv => kv.Key).ToArray(); foreach (var id in ids) { RemoveFont(id); } FDeviceHelpers.Remove(OnDevice); } }
public void DestroyResource(IPluginOut ForPin, Device OnDevice, bool OnlyUnManaged) { //Called by the PluginHost whenever a resource for a specific pin needs to be destroyed on a specific device. //This is also called when the plugin is destroyed, so don't dispose dxresources in the plugins destructor/Dispose() try { Mesh m = FDeviceMeshes[OnDevice]; //FHost.Log(TLogType.Debug, "Destroying Resource..."); FDeviceMeshes.Remove(OnDevice); //dispose mesh m.Dispose(); } catch { //resource is not available for this device. good. nothing to do then. } }
public void UpdateResource(IPluginOut ForPin, Device OnDevice) { if (this.runtime != null) { if (!this.FDepthTex.ContainsKey(OnDevice)) { Texture t = null; if (OnDevice is DeviceEx) { t = new Texture(OnDevice, 320, 240, 1, Usage.Dynamic, Format.L16, Pool.Default); } else { t = new Texture(OnDevice, 320, 240, 1, Usage.None, Format.L16, Pool.Managed); } this.FDepthTex.Add(OnDevice, t); } if (this.FInvalidate) { Texture tx = this.FDepthTex[OnDevice]; Surface srf = tx.GetSurfaceLevel(0); DataRectangle rect = srf.LockRectangle(LockFlags.Discard); int pos = 0; lock (this.m_lock) { rect.Data.WriteRange(this.rawdepth); } //rect.Data.WriteRange(this.depthimage); srf.UnlockRectangle(); this.FInvalidate = false; } } }
public void UpdateResource(IPluginOut ForPin, Device OnDevice) { if (this.runtime != null) { if (!this.FDepthTex.ContainsKey(OnDevice)) { Texture t = null; if (OnDevice is DeviceEx) { t = new Texture(OnDevice, 640, 480, 1, Usage.Dynamic, Format.A32B32G32R32F, Pool.Default); } else { t = new Texture(OnDevice, 640, 480, 1, Usage.None, Format.A32B32G32R32F, Pool.Managed); } this.FDepthTex.Add(OnDevice, t); } if (this.FInvalidate) { Texture tx = this.FDepthTex[OnDevice]; Surface srf = tx.GetSurfaceLevel(0); DataRectangle rect = srf.LockRectangle(LockFlags.Discard); lock (this.m_lock) { fixed(SkeletonPoint *f = &this.skelpoints[0]) { IntPtr ptr = new IntPtr(f); rect.Data.WriteRange(ptr, 640 * 480 * 16); } } srf.UnlockRectangle(); this.FInvalidate = false; } } }
public void UpdateResource(IPluginOut ForPin, Device OnDevice) { if (!FDeviceData.ContainsKey(OnDevice)) { //create resource for this device CreateResource(ForPin, OnDevice); } else { //recreate data? if (FDeviceData[OnDevice].Reinitialize) { CreateResource(ForPin, OnDevice); } //update data? var dd = FDeviceData[OnDevice]; if (dd.Update) { UpdateDeviceData(dd); dd.Update = false; } } }
public void UpdateResource(IPluginOut ForPin, Device OnDevice) { if (this.FInvalidate || !this.FMeshes.ContainsKey(OnDevice)) { //Destroy old mesh DestroyResource(ForPin, OnDevice, false); if (this.FInput[0] == null) { return; } List<Mesh> meshes = new List<Mesh>(); Frame frame = FInput[0]; if (frame.Loaded) { Mesh mesh = new Mesh(OnDevice, frame.Indices.Length / 3, frame.Vertices.Length, MeshFlags.Dynamic | MeshFlags.Use32Bit, Frame.VertexDeclaration); DataStream vS = mesh.LockVertexBuffer(LockFlags.Discard); DataStream iS = mesh.LockIndexBuffer(LockFlags.Discard); vS.WriteRange(frame.FormattedVertices); iS.WriteRange(frame.Indices); mesh.UnlockIndexBuffer(); mesh.UnlockVertexBuffer(); this.FMeshes.Add(OnDevice, mesh); } } }
public void UpdateResource(IPluginOut ForPin, Device OnDevice) { if (this.runtime != null && this.worldImage != null) { var width = runtime.Runtime.DepthStream.FrameWidth; var height = runtime.Runtime.DepthStream.FrameHeight; if (!this.FDepthTex.ContainsKey(OnDevice)) { Texture t = null; if (OnDevice is DeviceEx) { t = new Texture(OnDevice, width, height, 1, Usage.None, Format.A32B32G32R32F, Pool.Default); } else { t = new Texture(OnDevice, width, height, 1, Usage.None, Format.A32B32G32R32F, Pool.Managed); } this.FDepthTex.Add(OnDevice, t); } if (this.FInvalidate) { Texture tx = this.FDepthTex[OnDevice]; Surface srf = tx.GetSurfaceLevel(0); DataRectangle rect = srf.LockRectangle(LockFlags.Discard); lock (this.m_lock) { rect.Data.WriteRange(this.worldImage); } srf.UnlockRectangle(); this.FInvalidate = false; } } }
public void UpdateResource(IPluginOut ForPin, Device OnDevice) { if (this.FSensor != null) { //color if (FOutColor.IsConnected) { var width = this.FSensor.ColorStream.FrameWidth; var height = this.FSensor.ColorStream.FrameHeight; //create if necessary if (!FColorTexture.ContainsKey(OnDevice)) { var texture = new Texture(OnDevice, width, height, 1, Usage.None, Format.X8R8G8B8, (OnDevice is DeviceEx) ? Pool.Default : Pool.Managed); FColorTexture.Add(OnDevice, texture); } //fill if (FColorInvalidate) { var texture = FColorTexture[OnDevice]; var surface = texture.GetSurfaceLevel(0); var rectangle = surface.LockRectangle(LockFlags.Discard); lock (ColorLock) { rectangle.Data.WriteRange(ColorData); } surface.UnlockRectangle(); FColorInvalidate = false; } } //world if (FOutWorld.IsConnected) { var width = FSensor.DepthStream.FrameWidth; var height = FSensor.DepthStream.FrameHeight; //create if necessary if (!FWorldTexture.ContainsKey(OnDevice)) { var texture = new Texture(OnDevice, width, height, 1, Usage.None, Format.A32B32G32R32F, (OnDevice is DeviceEx) ? Pool.Default : Pool.Managed); FWorldTexture.Add(OnDevice, texture); } //fill if (FWorldOutInvalidate) { var texture = FWorldTexture[OnDevice]; var surface = texture.GetSurfaceLevel(0); var rectangle = surface.LockRectangle(LockFlags.Discard); var worldData = FWorldDataPointer ? FWorldData2 : FWorldData1; var worldLock = FWorldDataPointer ? FWorldLock2 : FWorldLock1; worldLock.AcquireReaderLock(100); try { rectangle.Data.WriteRange(worldData); } catch { } finally { worldLock.ReleaseReaderLock(); } surface.UnlockRectangle(); FWorldOutInvalidate = false; } } //depth if (FOutDepth.IsConnected) { var width = FSensor.DepthStream.FrameWidth; var height = FSensor.DepthStream.FrameHeight; //create if necessary if (!FDepthTexture.ContainsKey(OnDevice)) { var texture = new Texture(OnDevice, width, height, 1, Usage.None, Format.L16, (OnDevice is DeviceEx) ? Pool.Default : Pool.Managed); FDepthTexture.Add(OnDevice, texture); } //fill if (FDepthInvalidate) { var texture = FDepthTexture[OnDevice]; var surface = texture.GetSurfaceLevel(0); var rectangle = surface.LockRectangle(LockFlags.Discard); lock (DepthLock) { rectangle.Data.WriteRange(DepthData); } surface.UnlockRectangle(); FDepthInvalidate = false; } } } }
public void DestroyResource(IPluginOut ForPin, Device OnDevice, bool OnlyUnManaged) { if (ForPin == FOutColor) DestroyTexture(FColorTexture, OnDevice); if (ForPin == FOutDepth) DestroyTexture(FDepthTexture, OnDevice); if (ForPin == FOutWorld) DestroyTexture(FWorldTexture, OnDevice); }
public void UpdateResource(IPluginOut ForPin, Device OnDevice) { /*try { Mesh mtry = FDeviceMeshes[OnDevice]; if (update) RemoveResource(OnDevice); } //if resource is not yet created on given Device, create it now catch { update = true; } if (update) { try { // create new Mesh Mesh NewMesh = new Mesh(OnDevice, NumIndices / 3, NumVertices, MeshFlags.Dynamic | MeshFlags.WriteOnly, VertexFormat.PositionNormal); // lock buffers sVx = NewMesh.LockVertexBuffer(LockFlags.Discard); sIx = NewMesh.LockIndexBuffer(LockFlags.Discard); // write buffers unsafe { fixed (sVxBuffer* FixTemp = &VxBuffer[0]) { IntPtr VxPointer = new IntPtr(FixTemp); sVx.WriteRange(VxPointer, sizeof(sVxBuffer) * NumVertices); } fixed (short* FixTemp = &IxBuffer[0]) { IntPtr IxPointer = new IntPtr(FixTemp); sIx.WriteRange(IxPointer, sizeof(short) * NumIndices); } } // unlock buffers NewMesh.UnlockIndexBuffer(); NewMesh.UnlockVertexBuffer(); FDeviceMeshes.Add(OnDevice, NewMesh); } finally { update = false; } }*/ }
public void DestroyResource(IPluginOut ForPin, int OnDevice, bool OnlyUnManaged) { if (this.FTextures.ContainsKey(OnDevice)) { this.FTextures[OnDevice].Dispose(); this.FTextures.Remove(OnDevice); } }
public void DestroyResource(IPluginOut ForPin, int OnDevice, bool OnlyUnManaged) { //Called by the PluginHost whenever a resource for a specific pin needs to be destroyed on a specific device. //This is also called when the plugin is destroyed, so don't dispose dxresources in the plugins destructor/Dispose() try { RemoveResource(OnDevice); } catch { //resource is not available for this device. good. nothing to do then. } }
public void UpdateResource(IPluginOut ForPin, int OnDevice) { Device dev = Device.FromPointer(new IntPtr(OnDevice)); if (isValidIamge && idx < count-1) { if (!this.FTextures.ContainsKey(OnDevice)) { Texture txt = new Texture(dev, FWidth, FHeight, 1, Usage.None, Format.A8R8G8B8, Pool.Managed); this.FTextures.Add(OnDevice, txt); } Texture tx = this.FTextures[OnDevice]; Surface srf = tx.GetSurfaceLevel(0); DataRectangle rect = srf.LockRectangle(LockFlags.Discard); rect.Data.WriteRange(this.FData[idx], FWidth*FHeight*4); srf.UnlockRectangle(); } }
public void UpdateResource(IPluginOut ForPin, int OnDevice) { //Called by the PluginHost every frame for every device. Therefore a plugin should only do //device specific operations here and still keep node specific calculations in the Evaluate call. try { Mesh mrty = FDeviceMeshes[OnDevice]; if (update) RemoveResource(OnDevice); } catch { update = true; } if (update) { Device dev = Device.FromPointer(new IntPtr(OnDevice)); try { Mesh nuMesh = new Mesh(dev, numIndices / 3, numVertsOut, MeshFlags.Dynamic | MeshFlags.WriteOnly, VertexFormat.PositionNormal); sVx = nuMesh.LockVertexBuffer(LockFlags.Discard); sIx = nuMesh.LockIndexBuffer(LockFlags.Discard); unsafe { fixed (sVxBuffer* FixTemp = &VxBuffer[0]) { IntPtr VxPointer = new IntPtr(FixTemp); sVx.WriteRange(VxPointer, sizeof(sVxBuffer) * numVertsOut); } fixed (short* FixTemp = &IxBuffer[0]) { IntPtr IxPointer = new IntPtr(FixTemp); sIx.WriteRange(IxPointer, sizeof(short) * numIndices); } } nuMesh.UnlockVertexBuffer(); nuMesh.UnlockIndexBuffer(); FDeviceMeshes.Add(OnDevice, nuMesh); } finally { dev.Dispose(); update = false; } } }
public void UpdateResource(IPluginOut ForPin, int OnDevice) { if (ForPin == this.FPinOutMesh) { bool update = this.FMeshes.ContainsKey(OnDevice); if (this.FInvalidate) { RemoveResource(OnDevice); } if (!update) { this.FInvalidate = true; } if (this.FInvalidate) { Device dev = Device.FromPointer(new IntPtr(OnDevice)); List<Mesh> meshes = new List<Mesh>(); //Mesh. for (int i = 0; i < this.FVertexList.Count; i++) { Mesh mesh = new Mesh(dev, this.FIndexList[i].Length / 3, this.FVertexList[i].Length, MeshFlags.Dynamic, VertexNormT2.Format); DataStream vS = mesh.LockVertexBuffer(LockFlags.Discard); DataStream iS = mesh.LockIndexBuffer(LockFlags.Discard); FLogger.Log(LogType.Debug,this.FVertexList[i].Length.ToString()); FLogger.Log(LogType.Debug,this.FIndexList[i].Length.ToString()); vS.WriteRange(this.FVertexList[i]); iS.WriteRange(this.FIndexList[i]); mesh.UnlockVertexBuffer(); mesh.UnlockIndexBuffer(); meshes.Add(mesh); FLogger.Log(LogType.Debug,meshes.Count.ToString()); } try { Mesh merge = Mesh.Concatenate(dev, meshes.ToArray(), MeshFlags.Use32Bit | MeshFlags.Managed); this.FMeshes.Add(OnDevice, merge); //FLogger.Log(LogType.Debug,meshes.Count.ToString()); } catch (Exception ex) { //FLogger.Log(LogType.Error,ex.Message); } foreach (Mesh m in meshes) { m.Dispose(); } dev.Dispose(); this.FInvalidate = false; } } }