public void UpdateImage(DX11RenderContext context, DX11Resource <DX11DynamicTexture2D> texture, byte[] data) { if (FInvalidate || !texture.Contains(context)) { var fmt = SlimDX.DXGI.Format.R8_UNorm; if (texture.Contains(context)) { var imgdesc = texture[context].Resource.Description; if (imgdesc.Width != ValidImage.Width || imgdesc.Height != ValidImage.Height || imgdesc.Format != fmt) { texture.Dispose(context); texture[context] = new DX11DynamicTexture2D(context, ValidImage.Width, ValidImage.Height, fmt); } } else { texture[context] = new DX11DynamicTexture2D(context, ValidImage.Width, ValidImage.Height, fmt); #if DEBUG texture[context].Resource.DebugName = "DynamicTexture"; #endif } texture[context].WriteData(data); } }
public void UpdateDistMap(DX11RenderContext context, DX11Resource <DX11DynamicTexture2D> texture, Image.CameraType side) { if (FInvalidate || !texture.Contains(context)) { var fmt = SlimDX.DXGI.Format.R32G32_Float; if (texture.Contains(context)) { var imgdesc = texture[context].Resource.Description; if (imgdesc.Width != ValidImage.DistortionWidth / 2 || imgdesc.Height != ValidImage.DistortionHeight || imgdesc.Format != fmt) { texture.Dispose(context); texture[context] = new DX11DynamicTexture2D(context, ValidImage.DistortionWidth / 2, ValidImage.DistortionHeight, fmt); } } else { texture[context] = new DX11DynamicTexture2D(context, ValidImage.DistortionWidth / 2, ValidImage.DistortionHeight, fmt); #if DEBUG texture[context].Resource.DebugName = "DynamicTexture"; #endif } texture[context].WriteData(ValidImage.Distortion(side), 2); } }
private static void CheckBufferDispose <T>(DX11RenderContext context, DX11Resource <IDX11ReadableStructureBuffer> bufferResource, int bufferCount, bool bufferTypeChanged) where T : struct { if (bufferResource.Contains(context)) { if (bufferResource[context].ElementCount < bufferCount || bufferTypeChanged || bufferResource[context] is DX11ImmutableStructuredBuffer <T> ) { bufferResource.Dispose(context); } } }
public void Update(DX11Resource <DX11DynamicTexture2D> textureSlice, DX11RenderContext context) { if (!this.Running || !FDataNewForTexture) { return; } FDataNewForTexture = false; DX11DynamicTexture2D tex; //create texture if necessary //should also check if properties (width,height) changed if (!textureSlice.Contains(context)) { tex = new DX11DynamicTexture2D(context, FFrameWidth, FFrameHeight, SlimDX.DXGI.Format.R8_UNorm); textureSlice[context] = tex; } else if (textureSlice[context].Width != this.FFrameWidth || textureSlice[context].Height != this.FFrameHeight) { textureSlice[context].Dispose(); tex = new DX11DynamicTexture2D(context, FFrameWidth, FFrameHeight, SlimDX.DXGI.Format.R8_UNorm); textureSlice[context] = tex; } else { tex = textureSlice[context]; } FDoubleBuffer.LockFront.AcquireReaderLock(100); try { //write data to surface if (FFrameWidth == tex.GetRowPitch()) { tex.WriteData(FDoubleBuffer.Front); } else { GCHandle pinnedArray = GCHandle.Alloc(FDoubleBuffer.Front, GCHandleType.Pinned); tex.WriteDataPitch(pinnedArray.AddrOfPinnedObject(), FDoubleBuffer.Front.Length); pinnedArray.Free(); } } catch { } finally { FDoubleBuffer.LockFront.ReleaseReaderLock(); } }
public void Update(DX11RenderContext context) { if (!shaderData.Contains(context)) { shaderData[context] = new ShaderDeviceData(context); } if (this.spmax > 0) { if (!this.FOutLayer[0].Contains(context)) { this.FOutLayer[0][context] = new DX11Layer(); this.FOutLayer[0][context].Render = this.Render; } } }
/// <summary> /// Creates a buffer. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="bufferResource">The buffer resource</param> /// <param name="context">The DX11 context.</param> /// <param name="count">The required count. Gets blown up to the next power of 2.</param> /// <param name="bufferToCopy">The buffer to copy in case of immutable buffer type</param> private void CreateBuffer <T>(DX11Resource <IDX11ReadableStructureBuffer> bufferResource, DX11RenderContext context, int count, T[] bufferToCopy) where T : struct { if (!bufferResource.Contains(context)) { count = NextUpperPow2(count); if (this.FBufferType[0] == DX11BufferUploadType.Dynamic) { bufferResource[context] = new DX11DynamicStructuredBuffer <T>(context, count); } else if (this.FBufferType[0] == DX11BufferUploadType.Default) { bufferResource[context] = new DX11CopyDestStructuredBuffer <T>(context, count); } else { bufferResource[context] = new DX11ImmutableStructuredBuffer <T>(context.Device, bufferToCopy, count); } } }
public void Update(DX11RenderContext context) { if (this.dispatchBuffer == null) { this.dispatchBuffer = new DispatchIndirectBuffer(context); } if (!indirectGeom.Contains(context)) { indirectDispatch = new DX11NullIndirectDispatcher(); indirectDispatch.IndirectArgs = dispatchBuffer; DX11NullGeometry nullgeom = new DX11NullGeometry(context); nullgeom.AssignDrawer(this.indirectDispatch); indirectGeom[context] = nullgeom; } if (!this.FOutLayer[0].Contains(context)) { this.FOutLayer[0][context] = new DX11Layer(); this.FOutLayer[0][context].Render = this.Render; } }
public void Update(DX11Resource<DX11DynamicTexture2D> textureSlice, DX11RenderContext context) { if (!this.Running || !FDataNewForTexture) { return; } FDataNewForTexture = false; DX11DynamicTexture2D tex; //create texture if necessary //should also check if properties (width,height) changed if (!textureSlice.Contains(context)) { tex = new DX11DynamicTexture2D(context, FFrameWidth, FFrameHeight, SlimDX.DXGI.Format.R8_UNorm); textureSlice[context] = tex; } else if (textureSlice[context].Width != this.FFrameWidth || textureSlice[context].Height != this.FFrameHeight) { textureSlice[context].Dispose(); tex = new DX11DynamicTexture2D(context, FFrameWidth, FFrameHeight, SlimDX.DXGI.Format.R8_UNorm); textureSlice[context] = tex; } else { tex = textureSlice[context]; } FDoubleBuffer.LockFront.AcquireReaderLock(100); try { //write data to surface if (FFrameWidth == tex.GetRowPitch()) { tex.WriteData(FDoubleBuffer.Front); } else { GCHandle pinnedArray = GCHandle.Alloc(FDoubleBuffer.Front, GCHandleType.Pinned); tex.WriteDataPitch(pinnedArray.AddrOfPinnedObject(), FDoubleBuffer.Front.Length); pinnedArray.Free(); } } catch { } finally { FDoubleBuffer.LockFront.ReleaseReaderLock(); } }