示例#1
0
        /// <summary>
        /// Function to return an interpolated point from the spline.
        /// </summary>
        /// <param name="startPointIndex">Index in the point list to start from.</param>
        /// <param name="delta">Delta value to interpolate.</param>
        /// <returns>The interpolated value at <paramref name="delta"/>.</returns>
        /// <exception cref="System.ArgumentOutOfRangeException">Thrown when the <paramref name="startPointIndex"/> parameter is less than 0, or greater than/equal to the number of points in the spline minus 1.</exception>
        /// <remarks>The delta parameter is a unit value where 0 is the first point in the spline (referenced by startPointIndex) and 1 is the next point from the startPointIndex in the spline.</remarks>
        public Vector4 GetInterpolatedValue(int startPointIndex, float delta)
        {
            Matrix calculations = Matrix.Identity;

            GorgonDebug.AssertParamRange(startPointIndex, 0, Points.Count - 1, "startPointIndex");

            if (delta.EqualsEpsilon(0.0f))
            {
                return(Points[startPointIndex]);
            }

            if (delta.EqualsEpsilon(1.0f))
            {
                return(Points[startPointIndex + 1]);
            }

            var result = new Vector4(delta * delta * delta, delta * delta, delta * delta, 1.0f);

            calculations.Row1 = Points[startPointIndex];
            calculations.Row2 = Points[startPointIndex + 1];
            calculations.Row3 = _tangents[startPointIndex];
            calculations.Row4 = _tangents[startPointIndex + 1];

            Matrix.Multiply(ref _coefficients, ref calculations, out calculations);
            Vector4.Transform(ref result, ref calculations, out result);

            return(result);
        }
示例#2
0
        /// <summary>
        /// Function to copy the contents of the specified buffer to this buffer.
        /// </summary>
        /// <param name="buffer">Buffer to copy.</param>
        /// <param name="sourceOffset">Starting byte index to start copying from.</param>
        /// <param name="byteCount">The number of bytes to copy.</param>
        /// <param name="destOffset">The offset within the destination buffer.</param>
        /// <remarks>This is used to copy data from one GPU buffer to another.</remarks>
        /// <exception cref="System.ArgumentOutOfRangeException">Thrown when the <paramref name="sourceOffset"/> is less than 0 or larger than the size of the source <paramref name="buffer"/>.
        /// <para>-or-</para>
        /// <para>Thrown when the <paramref name="byteCount"/> + sourceStartIndex is greater than the size of the source buffer, or less than 0.</para>
        /// <para>-or-</para>
        /// <para>Thrown when the <paramref name="destOffset"/> + byteCount is greater than the size of this buffer, or less than 0.</para>
        /// </exception>
        /// <exception cref="GorgonLibrary.GorgonException">Thrown when this buffer has a usage of Immutable.</exception>
        public void Copy(GorgonBaseBuffer buffer, int sourceOffset, int byteCount, int destOffset)
        {
            int sourceByteIndex = sourceOffset + byteCount;
            int destByteIndex   = destOffset + byteCount;

            GorgonDebug.AssertNull(buffer, "buffer");
            GorgonDebug.AssertParamRange(sourceOffset, 0, buffer.SizeInBytes, "sourceOffset");
            GorgonDebug.AssertParamRange(sourceByteIndex, 0, buffer.SizeInBytes, "sourceOffset");
            GorgonDebug.AssertParamRange(destOffset, 0, SizeInBytes, "destOffset");
            GorgonDebug.AssertParamRange(destByteIndex, 0, buffer.SizeInBytes, "destOffset");

#if DEBUG
            if (Settings.Usage == BufferUsage.Immutable)
            {
                throw new GorgonException(GorgonResult.AccessDenied, Resources.GORGFX_BUFFER_IMMUTABLE);
            }
#endif
            Graphics.Context.CopySubresourceRegion(buffer.D3DResource, 0, new D3D.ResourceRegion
            {
                Top    = 0,
                Bottom = 1,
                Left   = sourceOffset,
                Right  = sourceByteIndex,
                Front  = 0,
                Back   = 1
            }, D3DResource, 0, destOffset);
        }
        /// <summary>
        /// Function to execute the current compute shader.
        /// </summary>
        /// <param name="threadCountX">Number of threads on the X group.</param>
        /// <param name="threadCountY">Number of threads on the Y group.</param>
        /// <param name="threadCountZ">Number of threads on the Z group.</param>
        /// <exception cref="System.ArgumentOutOfRangeException">Thrown when the <paramref name="threadCountX"/>, <paramref name="threadCountY"/> or the <paramref name="threadCountZ"/> parameters are less than
        /// 0 or greater than 65535.</exception>
        /// <remarks>Call dispatch to execute the commands in the compute shader.  A compute shader can be run on multiple threads in parallel within a threading group.  Use a particular threading group
        /// within the shader by using a 3D vector (float3).</remarks>
        public void Dispatch(int threadCountX, int threadCountY, int threadCountZ)
        {
            GorgonDebug.AssertParamRange(threadCountX, 0, 65535, "threadCountX");
            GorgonDebug.AssertParamRange(threadCountY, 0, 65535, "threadCountY");
            GorgonDebug.AssertParamRange(threadCountZ, 0, 65535, "threadCountZ");

            Graphics.Context.Dispatch(threadCountX, threadCountY, threadCountZ);
        }
示例#4
0
            /// <summary>
            /// Function to set a series of bindings at once.
            /// </summary>
            /// <param name="binding">Bindings to set.</param>
            /// <param name="slot">Index to start writing at.</param>
            /// <remarks>Passing NULL (Nothing in VB.Net) to the <paramref name="binding"/> parameter will set the bindings to empty (starting at <paramref name="slot"/>).</remarks>
            /// <exception cref="System.ArgumentOutOfRangeException">Thrown when the startIndex parameter is less than 0 or greater than the number of available bindings - 1.</exception>
            /// <exception cref="GorgonLibrary.GorgonException">Thrown when an the vertex buffer is already bound to another slot.</exception>
            public void SetRange(int slot, GorgonVertexBufferBinding[] binding)
            {
                int count = _bindings.Length - slot;

                GorgonDebug.AssertParamRange(slot, 0, _bindings.Length, true, false, "startIndex");

                if (binding != null)
                {
                    count = binding.Length.Min(_bindings.Length);
                }

                if ((_D3DBindings == null) || (_D3DBindings.Length != count))
                {
                    _D3DBindings = new D3D.VertexBufferBinding[count];
                }

                for (int i = 0; i < count; i++)
                {
                    int slotIndex = i + slot;
                    GorgonVertexBufferBinding currentBinding = GorgonVertexBufferBinding.Empty;

                    if (binding != null)
                    {
                        currentBinding = binding[i];
                    }

                    // If we've already set the binding, then don't bother.
                    if (_bindings[slotIndex].Equals(currentBinding))
                    {
                        continue;
                    }

#if DEBUG
                    if (!currentBinding.Equals(GorgonVertexBufferBinding.Empty))
                    {
                        var oldIndex = IndexOf(currentBinding);
                        if (oldIndex != -1)
                        {
                            throw new GorgonException(GorgonResult.CannotBind,
                                                      string.Format(Resources.GORGFX_VERTEXBUFFER_ALREADY_BOUND,
                                                                    currentBinding.VertexBuffer != null
                                                                                                        ? currentBinding.VertexBuffer.Name
                                                                                                        : "NULL", oldIndex));
                        }
                    }
#endif

                    _bindings[slotIndex] = currentBinding;
                    _D3DBindings[i]      = currentBinding.Convert();
                }

                _graphics.Context.InputAssembler.SetVertexBuffers(slot, _D3DBindings);
            }
        /// <summary>
        /// Function to copy data from this view into a buffer.
        /// </summary>
        /// <param name="buffer">Buffer that will receive the data.</param>
        /// <param name="offset">DWORD aligned offset within the buffer to start writing at.</param>
        /// <exception cref="System.ArgumentNullException">Thrown when the <paramref name="buffer"/> parameter is NULL (Nothing in VB.Net).</exception>
        /// <exception cref="System.ArgumentOutOfRangeException">Thrown when the <paramref name="offset"/> parameter is less than 0, or larger than the size of the buffer minus 4 bytes.</exception>
        /// <remarks>This will copy the contents of a structured buffer into any other type of buffer.  The view must have been created using a ViewType of Counter or Append, otherwise an exception will be thrown.</remarks>
        public void CopyTo(GorgonBaseBuffer buffer, int offset)
        {
            GorgonDebug.AssertNull(buffer, "buffer");
            GorgonDebug.AssertParamRange(offset, 0, buffer.SizeInBytes - 4, "index");

#if DEBUG
            if (ViewType == UnorderedAccessViewType.Standard)
            {
                throw new GorgonException(GorgonResult.CannotRead, Resources.GORGFX_VIEW_UNORDERED_TYPE_NOT_VALID_FOR_COPY);
            }
#endif
            Resource.Graphics.Context.CopyStructureCount(buffer.D3DBuffer, offset, D3DView);
        }
        /// <summary>
        /// Function to execute the current compute shader using an indirect argument buffer.
        /// </summary>
        /// <param name="indirectArgsBuffer">The indirect argument buffer to use.</param>
        /// <param name="alignedOffset">The byte aligned offset into the buffer to start at.</param>
        /// <remarks>Call dispatch to execute the commands in the compute shader.  A compute shader can be run on multiple threads in parallel within a threading group.  Use a particular threading group
        /// within the shader by using a 3D vector (float3).
        /// <para>The <paramref name="indirectArgsBuffer"/> must be loaded with data that matches the argument list of <see cref="Dispatch(int, int, int)"/>.</para></remarks>
        /// <exception cref="System.ArgumentNullException">Thrown when the <paramref name="indirectArgsBuffer"/> was NULL (Nothing in VB.Net).</exception>
        /// <exception cref="System.ArgumentOutOfRangeException">Thrown when the <paramref name="alignedOffset"/> parameter is less than 0 or not less than the number of bytes in the buffer.</exception>
        /// <exception cref="System.ArgumentException">Thrown when the buffer passed in through <paramref name="indirectArgsBuffer"/> was not created as an indirect argument buffer.</exception>
        public void Dispatch(GorgonBuffer indirectArgsBuffer, int alignedOffset)
        {
            GorgonDebug.AssertNull(indirectArgsBuffer, "indirectArgsBuffer");
            GorgonDebug.AssertParamRange(alignedOffset, 0, indirectArgsBuffer.SizeInBytes, "alignedOffset");

#if DEBUG
            if (!indirectArgsBuffer.Settings.AllowIndirectArguments)
            {
                throw new ArgumentException(Properties.Resources.GORGFX_BUFFER_NOT_INDIRECT, "indirectArgsBuffer");
            }
#endif
            Graphics.Context.DispatchIndirect(indirectArgsBuffer.D3DBuffer, alignedOffset);
        }
            /// <summary>
            /// Function to set a range of unordered access views all at once.
            /// </summary>
            /// <param name="slot">Starting slot for the buffer.</param>
            /// <param name="views">Buffers to set.</param>
            /// <remarks>This will bind unordered access views at the same time.  An unordered access view or its resource must not already be bound to the shader at another index, or an exception will be thrown.
            /// <para>Passing NULL (Nothing in VB.Net) to the <paramref name="views"/> parameter will set the bindings to empty (starting at <paramref name="slot"/>).</para>
            /// </remarks>
            /// <exception cref="System.ArgumentOutOfRangeException">Thrown when the <paramref name="slot"/> is less than 0, or greater than the available number of resource view slots.</exception>
            /// <exception cref="GorgonLibrary.GorgonException">Thrown when one of the views in the <paramref name="views"/> parameter is already bound to another slot or has a resource bound to another slot.</exception>
            public void SetRange(int slot, GorgonUnorderedAccessView[] views)
            {
                int count = _unorderedViews.Length - slot;

                GorgonDebug.AssertParamRange(slot, 0, _unorderedViews.Length, "slot");

                if (views != null)
                {
                    count = views.Length.Min(_unorderedViews.Length);
                }

                var D3DViews      = new D3D.UnorderedAccessView[count];
                var initialCounts = new int[count];

                for (int i = 0; i < count; i++)
                {
                    GorgonUnorderedAccessView buffer = null;
                    var bufferIndex = i + slot;

                    if (views != null)
                    {
                        buffer = views[i];
                    }

#if DEBUG
                    ValidateBinding(buffer);
#endif

                    _unorderedViews[bufferIndex] = buffer;
                    D3DViews[i]      = buffer != null ? buffer.D3DView : null;
                    initialCounts[i] = -1;

                    if (buffer == null)
                    {
                        continue;
                    }

                    var structView = buffer as GorgonStructuredBufferUnorderedAccessView;

                    if (structView != null)
                    {
                        initialCounts[i] = structView.InitialCount;
                    }
                }

                _shader.Graphics.Context.ComputeShader.SetUnorderedAccessViews(slot, D3DViews, initialCounts);
            }
示例#8
0
        /// <summary>
        /// Property to return the buffer for the given mip map level and depth slice.
        /// </summary>
        /// <exception cref="System.ArgumentOutOfRangeException">Thrown when the array index or the depth slice parameters are larger than their respective boundaries, or less than 0.</exception>
        /// <remarks>To get the array length, or the mip map count, use the <see cref="P:GorgonLibrary.Graphics.GorgonImageData.Settings">Settings</see> property.
        /// <para>To get the depth slice count, use the <see cref="GorgonLibrary.Graphics.GorgonImageData.GetDepthCount">GetDepthCount</see> method.</para>
        /// <para>The <paramref name="arrayIndexDepthSlice"/> parameter is used as an array index if the image is 1D or 2D.  If it is a 3D image, then the value indicates a depth slice.</para>
        /// </remarks>
        public GorgonImageBuffer this[int mipLevel, int arrayIndexDepthSlice = 0]
        {
            get
            {
                Tuple <int, int> offsetSize;

                GorgonDebug.AssertParamRange(mipLevel, 0, _image.Settings.MipCount, "mipLevel");

                if (_image.Settings.ImageType == ImageType.Image3D)
                {
                    GorgonDebug.AssertParamRange(arrayIndexDepthSlice, 0, _image.Settings.Depth, "arrayIndexDepthSlice");
                    offsetSize = MipOffsetSize[mipLevel];
                    return(_buffers[offsetSize.Item1 + arrayIndexDepthSlice]);
                }

                GorgonDebug.AssertParamRange(arrayIndexDepthSlice, 0, _image.Settings.ArrayCount, "arrayIndexDepthSlice");
                offsetSize = MipOffsetSize[mipLevel + (arrayIndexDepthSlice * _image.Settings.MipCount)];
                return(_buffers[offsetSize.Item1]);
            }
        }
            /// <summary>
            /// Function to return the resource assigned to a view at the specified index.
            /// </summary>
            /// <typeparam name="TR">Type of resource.</typeparam>
            /// <param name="index">Index of the resource to look up.</param>
            /// <exception cref="System.ArgumentOutOfRangeException">Thrown when the <paramref name="index"/> parameter is outside of the available resource view slots.</exception>
            /// <exception cref="System.InvalidCastException">Thrown when the type of resource at the specified index is not the requested type.</exception>
            /// <returns>The resource assigned to the view at the specified index, or NULL if nothing is assigned to the specified index.</returns>
            public TR GetResource <TR>(int index)
                where TR : GorgonResource
            {
                GorgonDebug.AssertParamRange(index, 0, _unorderedViews.Length, "index");

                var resourceView = _unorderedViews[index];

#if DEBUG
                if ((resourceView != null) && (resourceView.Resource != null) && (!(resourceView.Resource is TR)))
                {
                    throw new InvalidCastException(string.Format(Properties.Resources.GORGFX_VIEW_RESOURCE_NOT_TYPE, index,
                                                                 typeof(TR).FullName));
                }
#endif

                if (resourceView == null)
                {
                    return(null);
                }

                return((TR)resourceView.Resource);
            }
        /// <summary>
        /// Function to insert a list of key frames into the collection.
        /// </summary>
        /// <param name="index">The zero-based index at which <paramref name="keyFrames" /> should be inserted.</param>
        /// <param name="keyFrames">The key frames that should be inserted.</param>
        /// <exception cref="System.ArgumentOutOfRangeException">Thrown when the <paramref name="index"/> parameter is less than 0, or greater than the number of elements in the collection.</exception>
        public void InsertRange(int index, IEnumerable <IKeyFrame> keyFrames)
        {
            IKeyFrame[] frames = keyFrames.ToArray();

            GorgonDebug.AssertParamRange(index, 0, Count, "index");

            foreach (var key in frames)
            {
                if (Contains(key.Time))
                {
                    throw new ArgumentException(string.Format(Resources.GORANM_KEY_EXISTS_AT_TIME, key.Time));
                }

                Times.Add(key.Time, key);
            }

            _keyFrames.InsertRange(index, frames);
            if (_track != null)
            {
                _track.SetupSpline();
            }
        }
示例#11
0
        /// <summary>
        /// Function to flip the buffers to the front buffer.
        /// </summary>
        /// <param name="interval">Vertical blank interval.</param>
        /// <remarks>If <paramref name="interval"/> parameter is greater than 0, then this method will synchronize to the vertical blank count specified by interval  Passing 0 will display immediately.
        /// <para>If the window that the swap chain is bound with is occluded and/or the swap chain is in between a mode switch, then this method will place the swap chain into stand by mode, and will recover (i.e. turn off stand by) once the device is ready for rendering again.</para>
        /// </remarks>
        /// <exception cref="System.ArgumentOutOfRangeException">Thrown when the interval parameter is less than 0 or greater than 4.</exception>
        /// <exception cref="GorgonLibrary.GorgonException">Thrown when the method encounters an unrecoverable error.</exception>
        public void Flip(int interval)
        {
            var    flags  = GI.PresentFlags.None;
            Result result = Result.Ok;

            GorgonDebug.AssertParamRange(interval, 0, 4, true, true, "interval");

            if (GISwapChain == null)
            {
                return;
            }

            if (IsInStandBy)
            {
                flags = GI.PresentFlags.Test;
            }

            try
            {
                IsInStandBy = false;
                GISwapChain.Present(interval, flags);
            }
            catch (SharpDXException sdex)
            {
                if (sdex.ResultCode == Result.Ok)
                {
                    return;
                }

                if (!result.Success)
                {
                    throw new GorgonException(GorgonResult.CannotWrite, Resources.GORGFX_CATASTROPHIC_ERROR);
                }

                IsInStandBy = true;
            }
        }
示例#12
0
        /// <summary>
        /// Function to remove an animation from the collection.
        /// </summary>
        /// <param name="index">Index of the animation to remove.</param>
        /// <exception cref="System.IndexOutOfRangeException">Thrown when the <paramref name="index"/> parameter is less than 0 or greater than (or equal to) the number of items in the collection.</exception>
        public void Remove(int index)
        {
            GorgonDebug.AssertParamRange(index, 0, Count, "index");

            RemoveItem(this[index]);
        }
示例#13
0
 /// <summary>
 /// Function to set an animation playing.
 /// </summary>
 /// <param name="animatedObject">The object to apply the animation onto.</param>
 /// <param name="index">Index of the animation to start playing.</param>
 /// <exception cref="System.ArgumentNullException">Thrown when the <paramref name="animatedObject"/> parameter is NULL (Nothing in VB.Net).</exception>
 /// <exception cref="System.IndexOutOfRangeException">Thrown when the <paramref name="index"/> parameter is less than 0 or greater than (or equal to) the number of animations.</exception>
 public void Play(T animatedObject, int index)
 {
     GorgonDebug.AssertParamRange(index, 0, Count, "index");
     Play(animatedObject, this[index]);
 }