private static Format MakeSRGB(Format format) { switch (format) { case Format.R8G8B8A8_UNorm: return(Format.R8G8B8A8_UNorm_SRgb); case Format.BC1_UNorm: return(Format.BC1_UNorm_SRgb); case Format.BC2_UNorm: return(Format.BC2_UNorm_SRgb); case Format.BC3_UNorm: return(Format.BC3_UNorm_SRgb); case Format.B8G8R8A8_UNorm: return(Format.B8G8R8A8_UNorm_SRgb); case Format.B8G8R8X8_UNorm: return(Format.B8G8R8X8_UNorm_SRgb); case Format.BC7_UNorm: return(Format.BC7_UNorm_SRgb); default: return(format); } }
public static bool IsSupportFormat(this GraphicsDevice device, SharpDX.DXGI.Format format) { var d3dDevice = device._d3dDevice(); var fmtSupport = d3dDevice.CheckFormatSupport(format); return((fmtSupport & SharpDX.Direct3D11.FormatSupport.Texture2D) != 0); }
public ShaderResourceViewProxy Get(Format format) { if (IsDisposed) { return(null); } ConcurrentBag <ShaderResourceViewProxy> bag; ShaderResourceViewProxy proxy; if (pool.TryGetValue(format, out bag) && bag.TryTake(out proxy)) { return(proxy); } else { description.Format = format; var texture = Collect(new ShaderResourceViewProxy(deviceResourse.Device, description)); if ((description.BindFlags & BindFlags.RenderTarget) != 0) { texture.CreateRenderTargetView(); } if ((description.BindFlags & BindFlags.ShaderResource) != 0) { texture.CreateTextureView(); } if ((description.BindFlags & BindFlags.DepthStencil) != 0) { texture.CreateDepthStencilView(); } return(texture); } }
public D3DTexture2D( Device device, BindFlags bindFlags, ResourceUsage usage, CpuAccessFlags cpuAccessFlags, SharpDX.DXGI.Format format, IntPtr pixelPtr, int width, int height, int stride) { _device = device; Texture2DDescription desc = CreateDescription(width, height, bindFlags, usage, cpuAccessFlags, format); if (pixelPtr != IntPtr.Zero) { DataRectangle dataRectangle = new DataRectangle(pixelPtr, stride); DeviceTexture = new Texture2D(device, desc, dataRectangle); } else { DeviceTexture = new Texture2D(device, desc); } }
static SharpDX.DXGI.Format promoteFormatToSRGB(SharpDX.DXGI.Format format) { switch (format) { case SharpDX.DXGI.Format.R8G8B8A8_UNorm: return(SharpDX.DXGI.Format.R8G8B8A8_UNorm_SRgb); case SharpDX.DXGI.Format.B8G8R8A8_UNorm: return(SharpDX.DXGI.Format.B8G8R8A8_UNorm_SRgb); case SharpDX.DXGI.Format.B8G8R8X8_UNorm: return(SharpDX.DXGI.Format.B8G8R8X8_UNorm_SRgb); case SharpDX.DXGI.Format.BC1_UNorm: return(SharpDX.DXGI.Format.BC1_UNorm_SRgb); case SharpDX.DXGI.Format.BC2_UNorm: return(SharpDX.DXGI.Format.BC2_UNorm_SRgb); case SharpDX.DXGI.Format.BC3_UNorm: return(SharpDX.DXGI.Format.BC3_UNorm_SRgb); case SharpDX.DXGI.Format.BC7_UNorm: return(SharpDX.DXGI.Format.BC7_UNorm_SRgb); default: return(format); } }
public Texture2D(int width, int height, SharpDX.DXGI.Format format, bool autoMipmapped) { this.Width = width; this.Height = height; this.Format = format; this.AutoMipmapped = autoMipmapped; }
public void SetIndices <T>(T[] indices, IndexFormat format, int stride, int elementOffset) where T : struct { _format = D3DFormats.ConvertIndexFormat(format); int elementSizeInBytes = Unsafe.SizeOf <T>(); SetData(indices, elementSizeInBytes * indices.Length, elementOffset * elementSizeInBytes); }
protected DX11IndexBuffer(DxDevice device, int indicescount, SharpDX.Direct3D11.Buffer buffer) { this.format = SharpDX.DXGI.Format.R32_UInt; this.device = device; this.IndicesCount = indicescount; this.Buffer = buffer; }
public static ColorFormat Convert(Format format) { switch (format) { case Format.R32_Typeless: case Format.R32_Float: return(ColorFormat.R32F); case Format.R16_Typeless: case Format.R16_Float: return(ColorFormat.R16F); case Format.R16G16_Typeless: case Format.R16G16_Float: return(ColorFormat.Rg16F); case Format.R8G8B8A8_Typeless: case Format.R8G8B8A8_UNorm: case Format.R8G8B8A8_UNorm_SRgb: return(ColorFormat.Rgba8); case Format.B8G8R8A8_UNorm: case Format.B8G8R8A8_Typeless: case Format.B8G8R8A8_UNorm_SRgb: return(ColorFormat.Bgra8); case Format.R10G10B10A2_Typeless: case Format.R10G10B10A2_UNorm: return(ColorFormat.Rgb10A2); case Format.R16G16B16A16_Typeless: case Format.R16G16B16A16_Float: return(ColorFormat.Rgba16F); case Format.R32G32B32A32_Typeless: case Format.R32G32B32A32_Float: return(ColorFormat.Rgba32F); case Format.R32G32B32_Typeless: case Format.R32G32B32_Float: return(ColorFormat.Rgb32F); case Format.BC1_Typeless: case Format.BC1_UNorm: case Format.BC1_UNorm_SRgb: return(ColorFormat.Dxt1); case Format.BC2_Typeless: case Format.BC2_UNorm: case Format.BC2_UNorm_SRgb: return(ColorFormat.Dxt3); case Format.BC3_Typeless: case Format.BC3_UNorm: case Format.BC3_UNorm_SRgb: return(ColorFormat.Dxt5); } return(ColorFormat.Unknown); }
/// <summary> /// Converts the DXGI formats (Direct3D 10/Direct3D 11) to Direct3D 9 formats. /// </summary> /// <param name="format">The DXGI format.</param> /// <returns>The Direct3D 9 format.</returns> /// <exception cref="ArgumentException"> /// The DXGI format is not supported. /// </exception> private static Format ToD3D9(SharpDX.DXGI.Format format) { switch (format) { case SharpDX.DXGI.Format.B8G8R8A8_UNorm: // MonoGame: SurfaceFormat.Bgra32 return(Format.A8R8G8B8); case SharpDX.DXGI.Format.B8G8R8A8_UNorm_SRgb: return(Format.A8R8G8B8); case SharpDX.DXGI.Format.B8G8R8X8_UNorm: // MonoGame: SurfaceFormat.Bgr32 return(Format.X8R8G8B8); case SharpDX.DXGI.Format.R8G8B8A8_UNorm: return(Format.A8B8G8R8); case SharpDX.DXGI.Format.R8G8B8A8_UNorm_SRgb: return(Format.A8B8G8R8); case SharpDX.DXGI.Format.R10G10B10A2_UNorm: return(Format.A2B10G10R10); case SharpDX.DXGI.Format.R16G16B16A16_Float: return(Format.A16B16G16R16F); default: throw new ArgumentException("The specified surface format is not supported."); } }
private Texture2DDescription CreateDescription( int mipLevels, int width, int height, BindFlags bindFlags, ResourceUsage usage, CpuAccessFlags cpuAccessFlags, SharpDX.DXGI.Format format) { Texture2DDescription desc; desc.Width = width; desc.Height = height; desc.ArraySize = 1; desc.BindFlags = bindFlags; desc.Usage = usage; desc.CpuAccessFlags = cpuAccessFlags; desc.Format = format; desc.MipLevels = mipLevels; desc.OptionFlags = ResourceOptionFlags.None; desc.SampleDescription.Count = 1; desc.SampleDescription.Quality = 0; return(desc); }
public SharpDX.Direct2D1.Bitmap1 RenderLabel( float imageWidth, float imageHeight, Color4 foregroundColor, Vector2 origin, TextLayout textLayout, float dpi = DEFAULT_DPI, SharpDX.DXGI.Format format = SharpDX.DXGI.Format.B8G8R8A8_UNorm, SharpDX.Direct2D1.AlphaMode alpha = AlphaMode.Premultiplied) { var renderTarget = CreateRenderTarget(imageWidth, imageHeight, dpi, format, alpha); using (var drawingContext = CreateDrawingContext(renderTarget)) { // Begin our drawing drawingContext.BeginDraw(); // Clear to transparent drawingContext.Clear(TransparentColor); // Create our brush to actually draw with var solidBrush = new SolidColorBrush(drawingContext, foregroundColor); // Draw the text to the bitmap drawingContext.DrawTextLayout(origin, textLayout, solidBrush); // End our drawing drawingContext.EndDraw(); } return(renderTarget); }
protected DX11IndexBuffer(DxDevice device, int indicescount, BufferDescription desc, IntPtr ptr, bool largeformat = true) { this.device = device; this.IndicesCount = indicescount; this.format = largeformat ? SharpDX.DXGI.Format.R32_UInt : SharpDX.DXGI.Format.R16_UInt; this.Buffer = new SharpDX.Direct3D11.Buffer(device.Device, ptr, desc); }
public void SetIndices(IntPtr indices, IndexFormat format, int count, int elementOffset) { int elementSizeInBytes = format == IndexFormat.UInt16 ? sizeof(ushort) : sizeof(uint); SetData(indices, elementSizeInBytes * count, elementSizeInBytes * elementOffset); SharpDX.DXGI.Format dxgiFormat = D3DFormats.VeldridToD3DIndexFormat(format); _format = dxgiFormat; }
public static SharpDX.Direct3D9.Format ToD3D9(this SharpDX.DXGI.Format dxgiformat) { switch (dxgiformat) { case SharpDX.DXGI.Format.R10G10B10A2_UNorm: return(SharpDX.Direct3D9.Format.A2B10G10R10); case SharpDX.DXGI.Format.B8G8R8A8_UNorm: return(SharpDX.Direct3D9.Format.A8R8G8B8); case SharpDX.DXGI.Format.R16G16B16A16_Float: return(SharpDX.Direct3D9.Format.A16B16G16R16F); // not sure those one below will work... case SharpDX.DXGI.Format.R32G32B32A32_Float: return(SharpDX.Direct3D9.Format.A32B32G32R32F); case SharpDX.DXGI.Format.R16G16B16A16_UNorm: return(SharpDX.Direct3D9.Format.A16B16G16R16); case SharpDX.DXGI.Format.R32G32_Float: return(SharpDX.Direct3D9.Format.G32R32F); case SharpDX.DXGI.Format.R8G8B8A8_UNorm: return(SharpDX.Direct3D9.Format.A8R8G8B8); case SharpDX.DXGI.Format.R16G16_UNorm: return(SharpDX.Direct3D9.Format.G16R16); case SharpDX.DXGI.Format.R16G16_Float: return(SharpDX.Direct3D9.Format.G16R16F); case SharpDX.DXGI.Format.R32_Float: return(SharpDX.Direct3D9.Format.R32F); case SharpDX.DXGI.Format.R16_Float: return(SharpDX.Direct3D9.Format.R16F); case SharpDX.DXGI.Format.A8_UNorm: return(SharpDX.Direct3D9.Format.A8); case SharpDX.DXGI.Format.R8_UNorm: return(SharpDX.Direct3D9.Format.L8); case SharpDX.DXGI.Format.BC1_UNorm: return(SharpDX.Direct3D9.Format.Dxt1); case SharpDX.DXGI.Format.BC2_UNorm: return(SharpDX.Direct3D9.Format.Dxt3); case SharpDX.DXGI.Format.BC3_UNorm: return(SharpDX.Direct3D9.Format.Dxt5); default: return(SharpDX.Direct3D9.Format.Unknown); } }
/// <summary> /// Updates resources associated with a holographic camera's swap chain. /// The app does not access the swap chain directly, but it does create /// resource views for the back buffer. /// </summary> public void CreateResourcesForBackBuffer( DeviceResources deviceResources, HolographicCameraRenderingParameters cameraParameters) { var device = deviceResources.D3DDevice; // Get the WinRT object representing the holographic camera's back buffer. IDirect3DSurface surface = cameraParameters.Direct3D11BackBuffer; // Get a DXGI interface for the holographic camera's back buffer. // Holographic cameras do not provide the DXGI swap chain, which is owned // by the system. The Direct3D back buffer resource is provided using WinRT // interop APIs. InteropStatics.IDirect3DDxgiInterfaceAccess surfaceDxgiInterfaceAccess = surface as InteropStatics.IDirect3DDxgiInterfaceAccess; IntPtr pResource = surfaceDxgiInterfaceAccess.GetInterface(InteropStatics.ID3D11Resource); Resource resource = SharpDX.CppObject.FromPointer <Resource>(pResource); Marshal.Release(pResource); // Get a Direct3D interface for the holographic camera's back buffer. Texture2D cameraBackBuffer = resource.QueryInterface <Texture2D>(); // Determine if the back buffer has changed. If so, ensure that the render target view // is for the current back buffer. if ((this.d3dBackBuffer == null) || (this.d3dBackBuffer.NativePointer != cameraBackBuffer.NativePointer)) { // This can change every frame as the system moves to the next buffer in the // swap chain. This mode of operation will occur when certain rendering modes // are activated. this.d3dBackBuffer = cameraBackBuffer; // Get the DXGI format for the back buffer. // This information can be accessed by the app using CameraResources::GetBackBufferDXGIFormat(). Texture2DDescription backBufferDesc = this.BackBufferTexture2D.Description; // backBufferDesc.SampleDescription = new SharpDX.DXGI.SampleDescription(8, 8); this.dxgiFormat = backBufferDesc.Format; // Check for render target size changes. Size currentSize = this.holographicCamera.RenderTargetSize; if (this.d3dRenderTargetSize != currentSize) { // Set render target size. this.d3dRenderTargetSize = this.HolographicCamera.RenderTargetSize; } } // Create the constant buffer, if needed. if (this.viewProjectionConstantBuffer == null) { // Create a constant buffer to store view and projection matrices for the camera. ViewProjectionConstantBuffer viewProjectionConstantBufferData = new ViewProjectionConstantBuffer(); this.viewProjectionConstantBuffer = this.ToDispose(SharpDX.Direct3D11.Buffer.Create( device, BindFlags.ConstantBuffer, ref viewProjectionConstantBufferData)); } }
public SpriteTexture(Texture2D texture, SharpDX.DXGI.Format customFormat) { if (texture == null) { throw new ArgumentNullException("texture"); } CreateResource(texture.Device, texture, Vector2I.Zero, customFormat); }
public D3DIndexBuffer(Device device, int sizeInBytes, bool isDynamic, SharpDX.DXGI.Format format = SharpDX.DXGI.Format.Unknown) : base(device, sizeInBytes, BindFlags.IndexBuffer, isDynamic ? ResourceUsage.Dynamic : ResourceUsage.Default, isDynamic ? CpuAccessFlags.Write : CpuAccessFlags.None) { _device = device; _format = format; }
public void Put(Format format, ShaderResourceViewProxy proxy) { if (IsDisposed) { return; } ConcurrentBag <ShaderResourceViewProxy> bag = pool.GetOrAdd(format, new System.Func <Format, ConcurrentBag <ShaderResourceViewProxy> >((d) => { return(new ConcurrentBag <ShaderResourceViewProxy>()); })); bag.Add(proxy); }
public D3D11Texture(Device device, ref TextureDescription description) { Width = description.Width; Height = description.Height; Depth = description.Depth; MipLevels = description.MipLevels; ArrayLayers = description.ArrayLayers; Format = description.Format; Usage = description.Usage; SharpDX.DXGI.Format dxgiFormat = D3D11Formats.ToDxgiFormat( description.Format, (description.Usage & TextureUsage.DepthStencil) == TextureUsage.DepthStencil); BindFlags bindFlags = BindFlags.None; if ((description.Usage & TextureUsage.RenderTarget) == TextureUsage.RenderTarget) { bindFlags |= BindFlags.RenderTarget; } if ((description.Usage & TextureUsage.DepthStencil) == TextureUsage.DepthStencil) { bindFlags |= BindFlags.DepthStencil; } if ((description.Usage & TextureUsage.Sampled) == TextureUsage.Sampled) { bindFlags |= BindFlags.ShaderResource; } ResourceOptionFlags optionFlags = ResourceOptionFlags.None; int arraySize = (int)description.ArrayLayers; if ((description.Usage & TextureUsage.Cubemap) == TextureUsage.Cubemap) { optionFlags = ResourceOptionFlags.TextureCube; arraySize *= 6; } Texture2DDescription deviceDescription = new Texture2DDescription() { Width = (int)description.Width, Height = (int)description.Height, MipLevels = (int)description.MipLevels, ArraySize = arraySize, Format = dxgiFormat, BindFlags = bindFlags, CpuAccessFlags = CpuAccessFlags.None, Usage = ResourceUsage.Default, SampleDescription = new SharpDX.DXGI.SampleDescription(1, 0), OptionFlags = optionFlags, }; DeviceTexture = new Texture2D(device, deviceDescription); }
private Size2 AlignImage(int w, int h, SharpDX.DXGI.Format format) { int fs = SharpDX.DXGI.FormatHelper.SizeOfInBits(format); /* BC1_Typeless = 70, * BC1_UNorm = 71, * BC1_UNorm_SRgb = 72, * BC2_Typeless = 73, * BC2_UNorm = 74, * BC2_UNorm_SRgb = 75, * BC3_Typeless = 76, * BC3_UNorm = 77, * BC3_UNorm_SRgb = 78, * BC4_Typeless = 79, * BC4_UNorm = 80, * BC4_SNorm = 81,*/ //Those formats are : 512*256 //other bc formats are 256*256 Size2 tileSizeForFormat; switch (fs) { case 8: tileSizeForFormat = new Size2(256, 256); break; case 16: tileSizeForFormat = new Size2(256, 128); break; case 32: tileSizeForFormat = new Size2(128, 128); break; case 64: tileSizeForFormat = new Size2(128, 64); break; case 128: tileSizeForFormat = new Size2(64, 64); break; default: throw new Exception("Unknown tile size for this format"); } int alignedTileWidth = ((w + tileSizeForFormat.Width - 1) / tileSizeForFormat.Width) * tileSizeForFormat.Width; int alignedTileHeight = ((h + tileSizeForFormat.Height - 1) / tileSizeForFormat.Height) * tileSizeForFormat.Height; return(new Size2(alignedTileWidth, alignedTileHeight)); }
private void PushElement(string name, SharpDX.DXGI.Format type, int typeSize, int count) { m_Elements.Add(new Element { Name = name, Type = type, TypeSize = typeSize, Offset = m_Size, Count = count }); m_Size += typeSize * count; }
public TextureColorBuffer(SharpDX.DXGI.Format format, int width, int height, int samplesPerPixel, bool mipMapped) { _textureDesc = new Texture2DDescription(); _textureDesc.Height = height; _textureDesc.Width = width; _textureDesc.Usage = ResourceUsage.Default; _textureDesc.BindFlags = BindFlags.ShaderResource | BindFlags.RenderTarget; _textureDesc.Format = format; _textureDesc.CpuAccessFlags = CpuAccessFlags.None; _textureDesc.MipLevels = mipMapped ? 0 : 1; _textureDesc.ArraySize = 1; _textureDesc.SampleDescription = new SharpDX.DXGI.SampleDescription(samplesPerPixel, 0); _textureDesc.OptionFlags = mipMapped ? ResourceOptionFlags.GenerateMipMaps : ResourceOptionFlags.None; }
public Vector3VertexAttribute(XElement element, string name, SharpDX.DXGI.Format type) : base(name, type) { var attributes = element.Value.Replace('\n', ' ').Split(new char[] { ',' }); data = new Vector3[attributes.Length]; for (int i = 0; i < attributes.Length; ++i) { var attributeValues = attributes[i].Trim().Split(new char[] { ' ' }); data[i] = new Vector3(float.Parse(attributeValues[0], CultureInfo.InvariantCulture.NumberFormat), float.Parse(attributeValues[1], CultureInfo.InvariantCulture.NumberFormat), float.Parse(attributeValues[2], CultureInfo.InvariantCulture.NumberFormat)); // System.Diagnostics.Debug.WriteLine(value); } }
public ColorVertexAttribute(XElement element, string name, SharpDX.DXGI.Format type) : base(name, SharpDX.DXGI.Format.R32G32B32A32_Float) { var attributes = element.Value.Replace('\n', ' ').Split(new char[] { ',' }); data = new Vector4[attributes.Length]; for (int i = 0; i < attributes.Length; ++i) { var attributeValues = attributes[i].Trim().Split(new char[] { ' ' }); data[i] = new Vector4(float.Parse(attributeValues[0]) / 255.0f, float.Parse(attributeValues[1]) / 255.0f, float.Parse(attributeValues[2]) / 255.0f, float.Parse(attributeValues[3]) / 255.0f); // System.Diagnostics.Debug.WriteLine(value); } }
public static DX11Texture1D CreateDynamic(DxDevice device, int width, SharpDX.DXGI.Format format) { Texture1DDescription desc = new Texture1DDescription() { ArraySize = 1, BindFlags = BindFlags.ShaderResource, CpuAccessFlags = CpuAccessFlags.Write, OptionFlags = ResourceOptionFlags.None, Width = width, Format = format, MipLevels = 1, Usage = ResourceUsage.Dynamic }; return(new DX11Texture1D(device, desc)); }
protected DX11IndexBuffer(DxDevice device, int indicescount, BufferDescription desc, DataStream initial = null, bool largeformat = true) { this.device = device; this.IndicesCount = indicescount; this.format = largeformat ? SharpDX.DXGI.Format.R32_UInt : SharpDX.DXGI.Format.R16_UInt; if (initial != null) { initial.Position = 0; this.Buffer = new SharpDX.Direct3D11.Buffer(device.Device, initial, desc); } else { this.Buffer = new SharpDX.Direct3D11.Buffer(device.Device, desc); } }
static bool isSRGBFormat(SharpDX.DXGI.Format format) { switch (format) { case SharpDX.DXGI.Format.R8G8B8A8_UNorm_SRgb: case SharpDX.DXGI.Format.B8G8R8A8_UNorm_SRgb: case SharpDX.DXGI.Format.B8G8R8X8_UNorm_SRgb: case SharpDX.DXGI.Format.BC1_UNorm_SRgb: case SharpDX.DXGI.Format.BC2_UNorm_SRgb: case SharpDX.DXGI.Format.BC3_UNorm_SRgb: case SharpDX.DXGI.Format.BC7_UNorm_SRgb: return(true);; default: return(false); } }
public D3DTexture2D( Device device, BindFlags bindFlags, ResourceUsage usage, CpuAccessFlags cpuAccessFlags, SharpDX.DXGI.Format format, int mipLevels, int width, int height, int stride) { _device = device; MipLevels = mipLevels; Texture2DDescription desc = CreateDescription(mipLevels, width, height, bindFlags, usage, cpuAccessFlags, format); DeviceTexture = new Texture2D(device, desc); }
static SharpDX.DXGI.SampleDescription DetectSampleDescription(Device device, SharpDX.DXGI.Format format) { var desc = new SharpDX.DXGI.SampleDescription(); for (int multisample_count = Device.MultisampleCountMaximum; multisample_count > 0; --multisample_count) { int quality_levels = device.CheckMultisampleQualityLevels(format, multisample_count); if (quality_levels > 0) { desc.Count = multisample_count; desc.Quality = quality_levels - 1; break; } } Console.WriteLine("sample count {0} quality {1}", desc.Count, desc.Quality); return(desc); }
private VertexArrayObject(GraphicsDevice graphicsDevice, EffectInputSignature shaderSignature, IndexBufferBinding indexBufferBinding, VertexBufferBinding[] vertexBufferBindings) : base(graphicsDevice) { this.vertexBufferBindings = vertexBufferBindings; this.indexBufferBinding = indexBufferBinding; this.EffectInputSignature = shaderSignature; // Calculate Direct3D11 InputElement int inputElementCount = vertexBufferBindings.Sum(t => t.Declaration.VertexElements.Length); var inputElements = new InputElement[inputElementCount]; int j = 0; for (int i = 0; i < vertexBufferBindings.Length; i++) { var declaration = vertexBufferBindings[i].Declaration; vertexBufferBindings[i].Buffer.AddReferenceInternal(); foreach (var vertexElementWithOffset in declaration.EnumerateWithOffsets()) { var vertexElement = vertexElementWithOffset.VertexElement; inputElements[j++] = new InputElement { Slot = i, SemanticName = vertexElement.SemanticName, SemanticIndex = vertexElement.SemanticIndex, AlignedByteOffset = vertexElementWithOffset.Offset, Format = (SharpDX.DXGI.Format)vertexElement.Format, }; } } Layout = VertexArrayLayout.GetOrCreateLayout(new VertexArrayLayout(inputElements)); if (indexBufferBinding != null) { indexBufferBinding.Buffer.AddReferenceInternal(); indexBufferOffset = indexBufferBinding.Offset; indexFormat = (indexBufferBinding.Is32Bit ? SharpDX.DXGI.Format.R32_UInt : SharpDX.DXGI.Format.R16_UInt); } CreateResources(); }
public static ColorFormat Convert ( Format format ) { switch ( format ) { case Format.R32_Typeless : case Format.R32_Float : return ColorFormat.R32F; case Format.R16_Typeless : case Format.R16_Float : return ColorFormat.R16F; case Format.R16G16_Typeless : case Format.R16G16_Float : return ColorFormat.Rg16F; case Format.R8G8B8A8_Typeless : case Format.R8G8B8A8_UNorm : case Format.R8G8B8A8_UNorm_SRgb : return ColorFormat.Rgba8; case Format.R10G10B10A2_Typeless : case Format.R10G10B10A2_UNorm : return ColorFormat.Rgb10A2; case Format.R16G16B16A16_Typeless : case Format.R16G16B16A16_Float : return ColorFormat.Rgba16F; case Format.R32G32B32A32_Typeless : case Format.R32G32B32A32_Float : return ColorFormat.Rgba32F; case Format.R32G32B32_Typeless : case Format.R32G32B32_Float : return ColorFormat.Rgb32F; case Format.BC1_Typeless : case Format.BC1_UNorm : case Format.BC1_UNorm_SRgb : return ColorFormat.Dxt1; case Format.BC2_Typeless : case Format.BC2_UNorm : case Format.BC2_UNorm_SRgb : return ColorFormat.Dxt3; case Format.BC3_Typeless : case Format.BC3_UNorm : case Format.BC3_UNorm_SRgb : return ColorFormat.Dxt5; } return ColorFormat.Unknown; }
// Method to marshal from native to managed struct internal unsafe void __MarshalFrom(ref __Native @ref) { this.SemanticName = ( @ref.SemanticName == IntPtr.Zero )?null:Marshal.PtrToStringAnsi(@ref.SemanticName); this.SemanticIndex = @ref.SemanticIndex; this.Format = @ref.Format; this.Slot = @ref.Slot; this.AlignedByteOffset = @ref.AlignedByteOffset; this.Classification = @ref.Classification; this.InstanceDataStepRate = @ref.InstanceDataStepRate; }
/// <summary> /// Updates resources associated with a holographic camera's swap chain. /// The app does not access the swap chain directly, but it does create /// resource views for the back buffer. /// </summary> public void CreateResourcesForBackBuffer( DeviceResources deviceResources, HolographicCameraRenderingParameters cameraParameters ) { var device = deviceResources.D3DDevice; // Get the WinRT object representing the holographic camera's back buffer. IDirect3DSurface surface = cameraParameters.Direct3D11BackBuffer; // Get a DXGI interface for the holographic camera's back buffer. // Holographic cameras do not provide the DXGI swap chain, which is owned // by the system. The Direct3D back buffer resource is provided using WinRT // interop APIs. InteropStatics.IDirect3DDxgiInterfaceAccess surfaceDxgiInterfaceAccess = surface as InteropStatics.IDirect3DDxgiInterfaceAccess; IntPtr pResource = surfaceDxgiInterfaceAccess.GetInterface(InteropStatics.ID3D11Resource); Resource resource = SharpDX.CppObject.FromPointer<Resource>(pResource); Marshal.Release(pResource); // Get a Direct3D interface for the holographic camera's back buffer. Texture2D cameraBackBuffer = resource.QueryInterface<Texture2D>(); // Determine if the back buffer has changed. If so, ensure that the render target view // is for the current back buffer. if ((null == d3dBackBuffer) || (d3dBackBuffer.NativePointer != cameraBackBuffer.NativePointer)) { // This can change every frame as the system moves to the next buffer in the // swap chain. This mode of operation will occur when certain rendering modes // are activated. d3dBackBuffer = cameraBackBuffer; // Get the DXGI format for the back buffer. // This information can be accessed by the app using CameraResources::GetBackBufferDXGIFormat(). Texture2DDescription backBufferDesc = BackBufferTexture2D.Description; dxgiFormat = backBufferDesc.Format; // Check for render target size changes. Size currentSize = holographicCamera.RenderTargetSize; if (d3dRenderTargetSize != currentSize) { // Set render target size. d3dRenderTargetSize = HolographicCamera.RenderTargetSize; } } // Create the constant buffer, if needed. if (null == viewProjectionConstantBuffer) { // Create a constant buffer to store view and projection matrices for the camera. ViewProjectionConstantBuffer viewProjectionConstantBufferData = new ViewProjectionConstantBuffer(); viewProjectionConstantBuffer = this.ToDispose(SharpDX.Direct3D11.Buffer.Create( device, BindFlags.ConstantBuffer, ref viewProjectionConstantBufferData)); } }
public static IBorrowedRtvTexture DrawSpritesOffscreen(string textureName, int widht, int height, Format format = Format.B8G8R8A8_UNorm, Color? clearColor = null) { if (String.IsNullOrEmpty(textureName)) textureName = DEFAULT_TEXTURE_TARGET; if (widht == -1) widht = MyRender11.ViewportResolution.X; if (height == -1) height = MyRender11.ViewportResolution.Y; var texture = MyManagers.RwTexturesPool.BorrowRtv(textureName, widht, height, format); MyImmediateRC.RC.ClearRtv(texture, clearColor == null ? Color.Zero : clearColor.Value); DispatchDrawQueue(true); MySpritesRenderer.PushState(new Vector2(widht, height)); bool processed = ProcessDrawSpritesQueue(textureName); if (!processed) { MySpritesRenderer.PopState(); return texture; } DrawSprites(texture, new MyViewport(widht, height)); MySpritesRenderer.PopState(); return texture; }