コード例 #1
0
ファイル: GorgonBuffers.cs プロジェクト: tmp7701/Gorgon
        /// <summary>
        /// Function to create a index buffer.
        /// </summary>
        /// <param name="name">The name of the buffer.</param>
        /// <param name="settings">The settings for the buffer.</param>
        /// <param name="initialData">[Optional] Initial data to populate the index buffer with.</param>
        /// <returns>A new index buffer.</returns>
        /// <remarks>This method should only be called from an immediate graphics context, if it is called from a deferred context an exception will be thrown.</remarks>
        /// <exception cref="System.ArgumentNullException">Thrown when the <paramref name="name"/> parameter is NULL (Nothing in VB.Net).
        /// <para>-or-</para>
        /// <para>Thrown when the <paramref name="settings"/> parameter is NULL.</para>
        /// </exception>
        /// <exception cref="System.ArgumentException">Thrown when the <paramref name="name"/> parameter is empty.</exception>
        /// <exception cref="GorgonLibrary.GorgonException">Thrown when the <see cref="GorgonLibrary.Graphics.GorgonIndexBufferSettings.IsOutput">IsOutput</see> property is TRUE and has a usage that is not Default.
        /// <para>-or-</para>
        /// <para>Thrown when the <see cref="GorgonLibrary.Graphics.GorgonIndexBufferSettings.SizeInBytes">SizeInBytes</see> property of the <paramref name="settings"/> parameter is less than 1.</para>
        /// <para>-or-</para>
        /// <para>Thrown when the usage is set to immutable and the <paramref name="initialData"/> parameter is NULL (Nothing in VB.Net) or has no data.</para>
        /// </exception>
        public GorgonIndexBuffer CreateIndexBuffer(string name, GorgonIndexBufferSettings settings, GorgonDataStream initialData = null)
        {
            if (_graphics.IsDeferred)
            {
                throw new GorgonException(GorgonResult.CannotCreate, Resources.GORGFX_CANNOT_USE_DEFERRED_CONTEXT);
            }

            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            if (settings.SizeInBytes < 1)
            {
                throw new GorgonException(GorgonResult.CannotCreate, string.Format(Resources.GORGFX_BUFFER_SIZE_TOO_SMALL, 1));
            }

            if ((settings.Usage == BufferUsage.Immutable) && ((initialData == null) || (initialData.Length == 0)))
            {
                throw new GorgonException(GorgonResult.CannotCreate, Resources.GORGFX_BUFFER_IMMUTABLE_REQUIRES_DATA);
            }

            ValidateGenericBufferSettings(settings);

            var buffer = new GorgonIndexBuffer(_graphics, name, settings);

            buffer.Initialize(initialData);

            _graphics.AddTrackedObject(buffer);
            return(buffer);
        }
コード例 #2
0
ファイル: GorgonInputGeometry.cs プロジェクト: tmp7701/Gorgon
        /// <summary>
        /// Function to set the current index buffer, with an offset inside the buffer.
        /// </summary>
        /// <param name="buffer">Buffer to set.</param>
        /// <param name="offset">Offset into the buffer to use, in bytes.</param>
        public void SetIndexBuffer(GorgonIndexBuffer buffer, int offset)
        {
            if (_indexBuffer == buffer)
            {
                return;
            }

#if DEBUG
            if ((buffer != null) && ((offset >= buffer.SizeInBytes) || (offset < 0)))
            {
                throw new ArgumentOutOfRangeException("offset", string.Format(Resources.GORGFX_VALUE_OUT_OF_RANGE, offset, buffer.SizeInBytes));
            }
#endif

            if (buffer != null)
            {
                _graphics.Context.InputAssembler.SetIndexBuffer((D3D.Buffer)buffer.D3DResource,
                                                                buffer.Settings.Use32BitIndices ? GI.Format.R32_UInt : GI.Format.R16_UInt, offset);
            }
            else
            {
                _graphics.Context.InputAssembler.SetIndexBuffer(null, GI.Format.Unknown, 0);
            }

            _indexBuffer = buffer;
        }
コード例 #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GorgonBufferUnorderedAccessView"/> class.
        /// </summary>
        /// <param name="resource">The buffer to bind to the view.</param>
        /// <param name="format">The format of the view.</param>
        /// <param name="firstElement">The first element in the buffer.</param>
        /// <param name="elementCount">The number of elements to view.</param>
        /// <param name="isRaw">TRUE if the view should be a raw view, FALSE if not.</param>
        internal GorgonBufferUnorderedAccessView(GorgonResource resource, BufferFormat format, int firstElement, int elementCount, bool isRaw)
            : base(resource, format)
        {
            IsRaw        = isRaw;
            ElementStart = firstElement;
            ElementCount = elementCount;

            _buffer       = resource as GorgonBuffer;
            _indexBuffer  = resource as GorgonIndexBuffer;
            _vertexBuffer = resource as GorgonVertexBuffer;
        }
コード例 #4
0
ファイル: GorgonInputGeometry.cs プロジェクト: tmp7701/Gorgon
        /// <summary>
        /// Function to reset the states for the input assembler.
        /// </summary>
        internal void Reset()
        {
            _graphics.Context.InputAssembler.SetIndexBuffer(null, GI.Format.Unknown, 0);
            VertexBuffers.Reset();
            _graphics.Context.InputAssembler.PrimitiveTopology = (PrimitiveTopology.TriangleList);
            _graphics.Context.InputAssembler.InputLayout       = null;

            _indexBuffer   = null;
            _inputLayout   = null;
            _primitiveType = PrimitiveType.TriangleList;
        }
コード例 #5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GorgonBufferShaderView"/> class.
        /// </summary>
        /// <param name="buffer">The buffer to bind to the view.</param>
        /// <param name="format">Format of the view.</param>
        /// <param name="elementStart">The starting element for the view.</param>
        /// <param name="elementCount">The number of elements in the view.</param>
        /// <param name="isRaw">TRUE to use a raw view, FALSE to use a normal view.</param>
        internal GorgonBufferShaderView(GorgonResource buffer, BufferFormat format, int elementStart, int elementCount, bool isRaw)
            : base(buffer, format)
        {
            IsRaw        = isRaw;
            ElementStart = elementStart;
            ElementCount = elementCount;

            _buffer           = buffer as GorgonBuffer;
            _structuredBuffer = buffer as GorgonStructuredBuffer;
            _indexBuffer      = buffer as GorgonIndexBuffer;
            _vertexBuffer     = buffer as GorgonVertexBuffer;
        }