Exemple #1
0
        /// <summary>
        /// Upload a floatingpoint texture from the graphics hardware.
        /// This method is only valid for resources of type R32_Floatfloat.
        /// </summary>
        public unsafe MemoryMappedTextureFloat UploadToFloatBuffer()
        {
            MemoryMappedTextureFloat result = new MemoryMappedTextureFloat(
                new Size2(m_width, m_height));

            UploadToFloatBuffer(result);
            return(result);
        }
Exemple #2
0
        /// <summary>
        /// Upload a floatingpoint texture from the graphics hardware.
        /// This method is only valid for resources of type R32_Floatfloat.
        /// </summary>
        /// <param name="floatBuffer">The target float buffer to which to copy all ObjectIDs.</param>
        public unsafe void UploadToFloatBuffer(MemoryMappedTextureFloat floatBuffer)
        {
            // Check current format
            if (m_format != GraphicsHelper.DEFAULT_TEXTURE_FORMAT_OBJECT_ID)
            {
                throw new SeeingSharpGraphicsException("Invalid format for texture uploading to gdi bitmap (" + m_format + ")!");
            }
            if (floatBuffer.Width != m_width)
            {
                throw new SeeingSharpGraphicsException("The width of the textures during texture upload does not match!");
            }
            if (floatBuffer.Height != m_height)
            {
                throw new SeeingSharpGraphicsException("The height of the textures during texture upload does not match!");
            }

            // Upload the texture
            CopyTextureToStagingResource();

            // Read the data into the .Net data block
            SharpDX.DataBox dataBox = m_device.DeviceImmediateContextD3D11.MapSubresource(
                m_copyHelperTextureStaging, 0, D3D11.MapMode.Read, D3D11.MapFlags.None);
            try
            {
                int rowPitchSource      = dataBox.RowPitch;
                int rowPitchDestination = floatBuffer.Width * 4;
                if ((rowPitchSource > 0) && (rowPitchSource < 20000) &&
                    (rowPitchDestination > 0) && (rowPitchDestination < 20000))
                {
                    for (int loopY = 0; loopY < m_height; loopY++)
                    {
                        CommonTools.CopyMemory(
                            dataBox.DataPointer + loopY * rowPitchSource,
                            floatBuffer.Pointer + loopY * rowPitchDestination,
                            (ulong)rowPitchDestination);
                    }
                }
            }
            finally
            {
                m_device.DeviceImmediateContextD3D11.UnmapSubresource(m_copyHelperTextureStaging, 0);
            }
        }