コード例 #1
0
ファイル: Images.cs プロジェクト: microdee/leappack
        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);
            }
        }
コード例 #2
0
ファイル: Images.cs プロジェクト: microdee/leappack
        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);
            }
        }
コード例 #3
0
 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);
         }
     }
 }
コード例 #4
0
        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();
            }
        }
コード例 #5
0
        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;
                }
            }
        }
コード例 #6
0
 /// <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);
         }
     }
 }
コード例 #7
0
        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;
            }
        }
コード例 #8
0
		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();
			}
		}