internal unsafe void UpdateSubresource(GraphicsResource resource, int subResourceIndex, DataBox databox) { if (resource == null) { throw new ArgumentNullException("resource"); } NativeDeviceContext.UpdateSubresource(*(SharpDX.DataBox *)Interop.Cast(ref databox), resource.NativeResource, subResourceIndex); }
/// <summary> /// Draw geometry of an unknown size. /// </summary> /// <param name="primitiveType">Type of the primitive to draw.</param> public void DrawAuto(PrimitiveType primitiveType) { PrepareDraw(primitiveType); NativeDeviceContext.DrawAuto(); FrameDrawCalls++; }
/// <summary> /// Dispatches the specified indirect buffer. /// </summary> /// <param name="indirectBuffer">The indirect buffer.</param> /// <param name="offsetInBytes">The offset information bytes.</param> public void Dispatch(Buffer indirectBuffer, int offsetInBytes) { if (indirectBuffer == null) { throw new ArgumentNullException("indirectBuffer"); } NativeDeviceContext.DispatchIndirect(indirectBuffer.NativeBuffer, offsetInBytes); }
/// <summary> /// Draw non-indexed, non-instanced primitives. /// </summary> /// <param name="primitiveType">Type of the primitive to draw.</param> /// <param name="vertexCount">Number of vertices to draw.</param> /// <param name="startVertexLocation">Index of the first vertex, which is usually an offset in a vertex buffer; it could also be used as the first vertex id generated for a shader parameter marked with the <strong>SV_TargetId</strong> system-value semantic.</param> public void Draw(PrimitiveType primitiveType, int vertexCount, int startVertexLocation = 0) { PrepareDraw(primitiveType); NativeDeviceContext.Draw(vertexCount, startVertexLocation); FrameTriangleCount += (uint)vertexCount; FrameDrawCalls++; }
/// <summary> /// Draw indexed, non-instanced primitives. /// </summary> /// <param name="primitiveType">Type of the primitive to draw.</param> /// <param name="indexCount">Number of indices to draw.</param> /// <param name="startIndexLocation">The location of the first index read by the GPU from the index buffer.</param> /// <param name="baseVertexLocation">A value added to each index before reading a vertex from the vertex buffer.</param> public void DrawIndexed(PrimitiveType primitiveType, int indexCount, int startIndexLocation = 0, int baseVertexLocation = 0) { PrepareDraw(primitiveType); NativeDeviceContext.DrawIndexed(indexCount, startIndexLocation, baseVertexLocation); FrameDrawCalls++; FrameTriangleCount += (uint)indexCount; }
/// <summary> /// Draw non-indexed, instanced primitives. /// </summary> /// <param name="primitiveType">Type of the primitive to draw.</param> /// <param name="vertexCountPerInstance">Number of vertices to draw.</param> /// <param name="instanceCount">Number of instances to draw.</param> /// <param name="startVertexLocation">Index of the first vertex.</param> /// <param name="startInstanceLocation">A value added to each index before reading per-instance data from a vertex buffer.</param> public void DrawInstanced(PrimitiveType primitiveType, int vertexCountPerInstance, int instanceCount, int startVertexLocation = 0, int startInstanceLocation = 0) { PrepareDraw(primitiveType); NativeDeviceContext.DrawInstanced(vertexCountPerInstance, instanceCount, startVertexLocation, startInstanceLocation); FrameDrawCalls++; FrameTriangleCount += (uint)(vertexCountPerInstance * instanceCount); }
/// <summary> /// Set the pixel format on EGL platform. /// </summary> private void SetPixelFormatEgl() { NativeDeviceContext eglDeviceContext = (NativeDeviceContext)_DeviceContext; // Require the pixel formats DevicePixelFormatCollection pixelFormats = eglDeviceContext.PixelsFormats; eglDeviceContext.SetPixelFormat(pixelFormats[0]); }
/// <summary> /// Clears the specified render target. See <see cref="Textures+and+render+targets"/> to learn how to use it. /// </summary> /// <param name="renderTarget">The render target.</param> /// <param name="color">The color.</param> /// <exception cref="System.ArgumentNullException">renderTarget</exception> public unsafe void Clear(Texture renderTarget, Color4 color) { if (renderTarget == null) { throw new ArgumentNullException("renderTarget"); } NativeDeviceContext.ClearRenderTargetView(renderTarget.NativeRenderTargetView, *(RawColor4 *)&color); }
/// <summary> /// Executes a deferred command list. /// </summary> /// <param name="commandList">The deferred command list.</param> public void ExecuteCommandList(ICommandList commandList) { if (commandList == null) { throw new ArgumentNullException("commandList"); } NativeDeviceContext.ExecuteCommandList(((CommandList)commandList).NativeCommandList, false); commandList.Release(); }
/// <summary> /// Draw instanced, GPU-generated primitives. /// </summary> /// <param name="primitiveType">Type of the primitive to draw.</param> /// <param name="argumentsBuffer">An arguments buffer</param> /// <param name="alignedByteOffsetForArgs">Offset in <em>pBufferForArgs</em> to the start of the GPU generated primitives.</param> public void DrawInstanced(PrimitiveType primitiveType, Buffer argumentsBuffer, int alignedByteOffsetForArgs = 0) { if (argumentsBuffer == null) { throw new ArgumentNullException("argumentsBuffer"); } PrepareDraw(primitiveType); NativeDeviceContext.DrawIndexedInstancedIndirect(argumentsBuffer.NativeBuffer, alignedByteOffsetForArgs); }
public void Copy(GraphicsResource source, GraphicsResource destination) { if (source == null) { throw new ArgumentNullException("source"); } if (destination == null) { throw new ArgumentNullException("destination"); } NativeDeviceContext.CopyResource(source.NativeResource, destination.NativeResource); }
/// <inheritdoc /> public void CopyCount(Buffer sourceBuffer, Buffer destBuffer, int offsetInBytes) { if (sourceBuffer == null) { throw new ArgumentNullException("sourceBuffer"); } if (destBuffer == null) { throw new ArgumentNullException("destBuffer"); } NativeDeviceContext.CopyStructureCount(destBuffer.NativeBuffer, offsetInBytes, sourceBuffer.NativeUnorderedAccessView); }
/// <summary> /// Clears a read-write Texture. This texture must have been created with read-write/unordered access. /// </summary> /// <param name="texture">The texture.</param> /// <param name="value">The value.</param> /// <exception cref="System.ArgumentNullException">texture</exception> /// <exception cref="System.ArgumentException">Expecting buffer supporting UAV;texture</exception> public unsafe void ClearReadWrite(Texture texture, UInt4 value) { if (texture == null) { throw new ArgumentNullException("texture"); } if (texture.NativeUnorderedAccessView == null) { throw new ArgumentException("Expecting buffer supporting UAV", "texture"); } NativeDeviceContext.ClearUnorderedAccessView(texture.NativeUnorderedAccessView, *(RawInt4 *)&value); }
/// <summary> /// Clears a read-write Buffer. This buffer must have been created with read-write/unordered access. /// </summary> /// <param name="buffer">The buffer.</param> /// <param name="value">The value.</param> /// <exception cref="System.ArgumentNullException">buffer</exception> /// <exception cref="System.ArgumentException">Expecting buffer supporting UAV;buffer</exception> public unsafe void ClearReadWrite(Buffer buffer, Int4 value) { if (buffer == null) { throw new ArgumentNullException("buffer"); } if (buffer.NativeUnorderedAccessView == null) { throw new ArgumentException("Expecting buffer supporting UAV", "buffer"); } NativeDeviceContext.ClearUnorderedAccessView(buffer.NativeUnorderedAccessView, *(RawInt4 *)&value); }
public new void FixtureSetUp() { try { // Create compatibility profile context if ((_Context = _DeviceContext.CreateContext(IntPtr.Zero)) == IntPtr.Zero) { throw new InvalidOperationException("unable to create compatibility profile OpenGL context"); } // Make OpenGL context current if (_DeviceContext.MakeCurrent(_Context) == false) { throw new InvalidOperationException("unable to make current the OpenGL context"); } // Get OpenGL version if ((_VersionString = Gl.GetString(StringName.Version)) == null) { throw new InvalidOperationException("unable to get the OpenGL version"); } // Extract OpenGL version numbers _Version = KhronosVersion.Parse(_VersionString); // Get OpenGL extensions _GlExtensions.Query(); // Get OpenGL window system extensions // Windows OpenGL extensions WindowsDeviceContext windowsDeviceContext = _DeviceContext as WindowsDeviceContext; if (windowsDeviceContext != null) { _WglExtensions.Query(windowsDeviceContext); } // GLX OpenGL extensions XServerDeviceContext xserverDeviceContext = _DeviceContext as XServerDeviceContext; if (xserverDeviceContext != null) { _GlxExtensions.Query(xserverDeviceContext); } // EGL OpenGL extensions NativeDeviceContext nativeDeviceContext = _DeviceContext as NativeDeviceContext; if (nativeDeviceContext != null) { _EglExtensions.Query(nativeDeviceContext); } } catch { // Release resources manually FixtureTearDown(); throw; } }
public void Dispose() { Canvas.Dispose(); rasterizerState.Dispose(); blendState.Dispose(); depthStencilState.Dispose(); samplerState.Dispose(); backBufferView.Dispose(); depthStencilView.Dispose(); swapChain.Dispose(); NativeDeviceContext.Dispose(); NativeDevice.Dispose(); }
/// <summary> /// Maps a subresource. /// </summary> /// <param name="resource">The resource.</param> /// <param name="subResourceIndex">Index of the sub resource.</param> /// <param name="mapMode">The map mode.</param> /// <param name="doNotWait">if set to <c>true</c> this method will return immediately if the resource is still being used by the GPU for writing. Default is false</param> /// <param name="offsetInBytes">The offset information in bytes.</param> /// <param name="lengthInBytes">The length information in bytes.</param> /// <returns>Pointer to the sub resource to map.</returns> public unsafe MappedResource MapSubresource(GraphicsResource resource, int subResourceIndex, MapMode mapMode, bool doNotWait = false, int offsetInBytes = 0, int lengthInBytes = 0) { if (resource == null) { throw new ArgumentNullException("resource"); } SharpDX.DataBox dataBox = NativeDeviceContext.MapSubresource(resource.NativeResource, subResourceIndex, (SharpDX.Direct3D11.MapMode)mapMode, doNotWait ? SharpDX.Direct3D11.MapFlags.DoNotWait : SharpDX.Direct3D11.MapFlags.None); var databox = *(DataBox *)Interop.Cast(ref dataBox); if (!dataBox.IsEmpty) { databox.DataPointer = (IntPtr)((byte *)databox.DataPointer + offsetInBytes); } return(new MappedResource(resource, subResourceIndex, databox)); }
public void CopyMultiSample(Texture sourceMsaaTexture, int sourceSubResource, Texture destTexture, int destSubResource, PixelFormat format = PixelFormat.None) { if (sourceMsaaTexture == null) { throw new ArgumentNullException("sourceMsaaTexture"); } if (destTexture == null) { throw new ArgumentNullException("destTexture"); } if (!sourceMsaaTexture.IsMultiSample) { throw new ArgumentOutOfRangeException("sourceMsaaTexture", "Source texture is not a MSAA texture"); } NativeDeviceContext.ResolveSubresource(sourceMsaaTexture.NativeResource, sourceSubResource, destTexture.NativeResource, destSubResource, (Format)(format == PixelFormat.None ? destTexture.Format : format)); }
public void CopyRegion(GraphicsResource source, int sourceSubresource, ResourceRegion?sourecRegion, GraphicsResource destination, int destinationSubResource, int dstX = 0, int dstY = 0, int dstZ = 0) { if (source == null) { throw new ArgumentNullException("source"); } if (destination == null) { throw new ArgumentNullException("destination"); } var nullableSharpDxRegion = new SharpDX.Direct3D11.ResourceRegion?(); if (sourecRegion.HasValue) { var value = sourecRegion.Value; nullableSharpDxRegion = new SharpDX.Direct3D11.ResourceRegion(value.Left, value.Top, value.Front, value.Right, value.Bottom, value.Back); } NativeDeviceContext.CopySubresourceRegion(source.NativeResource, sourceSubresource, nullableSharpDxRegion, destination.NativeResource, destinationSubResource, dstX, dstY, dstZ); }
/// <summary> /// Clears the specified depth stencil buffer. See <see cref="Textures+and+render+targets"/> to learn how to use it. /// </summary> /// <param name="depthStencilBuffer">The depth stencil buffer.</param> /// <param name="options">The options.</param> /// <param name="depth">The depth.</param> /// <param name="stencil">The stencil.</param> /// <exception cref="System.InvalidOperationException"></exception> public void Clear(Texture depthStencilBuffer, DepthStencilClearOptions options, float depth = 1, byte stencil = 0) { if (depthStencilBuffer == null) { throw new ArgumentNullException("depthStencilBuffer"); } var flags = ((options & DepthStencilClearOptions.DepthBuffer) != 0) ? SharpDX.Direct3D11.DepthStencilClearFlags.Depth : 0; // Check that the DepthStencilBuffer has a Stencil if Clear Stencil is requested if ((options & DepthStencilClearOptions.Stencil) != 0) { if (!depthStencilBuffer.HasStencil) { throw new InvalidOperationException(string.Format(FrameworkResources.NoStencilBufferForDepthFormat, depthStencilBuffer.ViewFormat)); } flags |= SharpDX.Direct3D11.DepthStencilClearFlags.Stencil; } NativeDeviceContext.ClearDepthStencilView(depthStencilBuffer.NativeDepthStencilView, flags, depth, stencil); }
public void UnmapSubresource(MappedResource unmapped) { NativeDeviceContext.UnmapSubresource(unmapped.Resource.NativeResource, unmapped.SubResourceIndex); }
/// <summary> /// Finishes a deffered command list. /// </summary> /// <returns>A deferred command list.</returns> public ICommandList FinishCommandList() { return(new CommandList(NativeDeviceContext.FinishCommandList(false))); }
/// <summary> /// Begin a 2D drawing session /// </summary> public void Begin() { NativeDeviceContext.BeginDraw(); }
/// <summary> /// End drawing session /// </summary> public void End() { NativeDeviceContext.EndDraw(); }
/// <summary> /// Draw text /// </summary> /// <param name="text">Text</param> /// <param name="x">Left position</param> /// <param name="y">Top position</param> /// <param name="width">Max width</param> /// <param name="height">Max heigh</param> public void DrawString(string text, float x, float y, float width = 800, float height = 600) { var brush = GetBrush(Color.White); NativeDeviceContext.DrawText(text, TextFormat, new RawRectangleF(x, y, width, height), brush); }
/// <summary> /// Draw non-indexed, non-instanced primitives. /// </summary> /// <param name="primitiveType">Type of the primitive to draw.</param> /// <param name="vertexCount">Number of vertices to draw.</param> /// <param name="startVertexLocation">Index of the first vertex, which is usually an offset in a vertex buffer; it could also be used as the first vertex id generated for a shader parameter marked with the <strong>SV_TargetId</strong> system-value semantic.</param> public void Draw(PrimitiveType primitiveType, int vertexCount, int startVertexLocation = 0) { PrepareDraw(primitiveType); NativeDeviceContext.Draw(vertexCount, startVertexLocation); }
/// <inheritdoc /> public void Dispatch(int threadCountX, int threadCountY, int threadCountZ) { NativeDeviceContext.Dispatch(threadCountX, threadCountY, threadCountZ); }
/// <summary> /// Draw indexed, non-instanced primitives. /// </summary> /// <param name="primitiveType">Type of the primitive to draw.</param> /// <param name="indexCount">Number of indices to draw.</param> /// <param name="startIndexLocation">The location of the first index read by the GPU from the index buffer.</param> /// <param name="baseVertexLocation">A value added to each index before reading a vertex from the vertex buffer.</param> public void DrawIndexed(PrimitiveType primitiveType, int indexCount, int startIndexLocation = 0, int baseVertexLocation = 0) { PrepareDraw(primitiveType); NativeDeviceContext.DrawIndexed(indexCount, startIndexLocation, baseVertexLocation); }
/// <summary> /// Draw non-indexed, instanced primitives. /// </summary> /// <param name="primitiveType">Type of the primitive to draw.</param> /// <param name="vertexCountPerInstance">Number of vertices to draw.</param> /// <param name="instanceCount">Number of instances to draw.</param> /// <param name="startVertexLocation">Index of the first vertex.</param> /// <param name="startInstanceLocation">A value added to each index before reading per-instance data from a vertex buffer.</param> public void DrawInstanced(PrimitiveType primitiveType, int vertexCountPerInstance, int instanceCount, int startVertexLocation = 0, int startInstanceLocation = 0) { PrepareDraw(primitiveType); NativeDeviceContext.DrawInstanced(vertexCountPerInstance, instanceCount, startVertexLocation, startInstanceLocation); }
public void Reset() { NativeDeviceContext.ClearState(); }