예제 #1
0
 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);
 }
예제 #2
0
        /// <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++;
        }
예제 #3
0
 /// <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);
 }
예제 #4
0
        /// <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++;
        }
예제 #5
0
        /// <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;
        }
예제 #6
0
        /// <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);
        }
예제 #7
0
        /// <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]);
        }
예제 #8
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);
        }
예제 #9
0
        /// <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();
        }
예제 #10
0
        /// <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);
        }
예제 #11
0
 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);
 }
예제 #12
0
 /// <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);
 }
예제 #13
0
        /// <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);
        }
예제 #14
0
        /// <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);
        }
예제 #15
0
        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;
            }
        }
예제 #16
0
        public void Dispose()
        {
            Canvas.Dispose();

            rasterizerState.Dispose();
            blendState.Dispose();
            depthStencilState.Dispose();
            samplerState.Dispose();

            backBufferView.Dispose();
            depthStencilView.Dispose();
            swapChain.Dispose();
            NativeDeviceContext.Dispose();
            NativeDevice.Dispose();
        }
예제 #17
0
        /// <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));
        }
예제 #18
0
        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));
        }
예제 #19
0
        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);
        }
예제 #20
0
        /// <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);
        }
예제 #21
0
 public void UnmapSubresource(MappedResource unmapped)
 {
     NativeDeviceContext.UnmapSubresource(unmapped.Resource.NativeResource, unmapped.SubResourceIndex);
 }
예제 #22
0
 /// <summary>
 /// Finishes a deffered command list.
 /// </summary>
 /// <returns>A deferred command list.</returns>
 public ICommandList FinishCommandList()
 {
     return(new CommandList(NativeDeviceContext.FinishCommandList(false)));
 }
예제 #23
0
 /// <summary>
 /// Begin a 2D drawing session
 /// </summary>
 public void Begin()
 {
     NativeDeviceContext.BeginDraw();
 }
예제 #24
0
 /// <summary>
 /// End drawing session
 /// </summary>
 public void End()
 {
     NativeDeviceContext.EndDraw();
 }
예제 #25
0
        /// <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);
        }
예제 #26
0
        /// <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);
        }
예제 #27
0
 /// <inheritdoc />
 public void Dispatch(int threadCountX, int threadCountY, int threadCountZ)
 {
     NativeDeviceContext.Dispatch(threadCountX, threadCountY, threadCountZ);
 }
예제 #28
0
        /// <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);
        }
예제 #29
0
        /// <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();
 }