/// <summary> /// 用GL.DrawElements()执行一个索引buffer的渲染操作。 /// </summary> /// <param name="bufferID">用GL.GenBuffers()得到的VBO的ID。</param> /// <param name="mode">用哪种方式渲染各个顶点?(OpenGL.GL_TRIANGLES etc.)</param> /// <param name="elementCount">索引数组中有多少个元素。</param> /// <param name="type">type in GL.DrawElements(uint mode, int count, uint type, IntPtr indices); /// <para>表示第3个参数,表示索引元素的类型。</para></param> /// <param name="length">此VBO含有多个个元素?</param> internal OneIndexBufferPtr(uint bufferID, DrawMode mode, int elementCount, IndexElementType type, int length, int byteLength) : base(mode, bufferID, length, byteLength) { this.ElementCount = elementCount; this.Type = type; }
protected IndexBuffer( GraphicsDevice graphicsDevice, IndexElementType elementType, int capacity, BufferUsage bufferUsage, bool isDynamic) : base(graphicsDevice, capacity, bufferUsage, isDynamic) { if (elementType == IndexElementType.Int32) { if (graphicsDevice.GraphicsProfile == GraphicsProfile.Reach) { throw new NotSupportedException( $"The current graphics profile does not support an element type of " + $"{elementType}; use {IndexElementType.Int16} instead."); } } else if (elementType != IndexElementType.Int16) { throw new ArgumentOutOfRangeException(nameof(elementType)); } ElementType = elementType; if (IsValidThreadContext) { PlatformConstruct(); } else { Threading.BlockOnMainThread(PlatformConstruct); } }
public DynamicIndexBuffer( GraphicsDevice graphicsDevice, IndexElementType elementType, int capacity, BufferUsage bufferUsage) : base(graphicsDevice, elementType, capacity, bufferUsage, true) { }
public IndexBuffer( GraphicsDevice graphicsDevice, IndexElementType elementType, int capacity, BufferUsage bufferUsage) : this(graphicsDevice, elementType, capacity, bufferUsage, false) { }
/// <summary> /// Wraps glDrawElements(uint mode, int count, uint type, IntPtr indices). /// </summary> /// <param name="bufferId">用glGenBuffers()得到的VBO的Id。<para>Id got from glGenBuffers();</para></param> /// <param name="mode">用哪种方式渲染各个顶点?(OpenGL.GL_TRIANGLES etc.)</param> /// <param name="firstIndex">要渲染的第一个索引的位置。<para>First index to be rendered.</para></param> /// <param name="elementCount">索引数组中有多少个元素。<para>How many indexes to be rendered?</para></param> /// <param name="type">type in glDrawElements(uint mode, int count, uint type, IntPtr indices); /// <para>表示第3个参数,表示索引元素的类型。</para></param> /// <param name="length">此VBO含有多个个元素?<para>How many elements?</para></param> /// <param name="byteLength">此VBO中的数据在内存中占用多少个字节?<para>How many bytes in this buffer?</para></param> internal OneIndexBufferPtr(uint bufferId, DrawMode mode, int firstIndex, int elementCount, IndexElementType type, int length, int byteLength) : base(mode, bufferId, length, byteLength) { this.FirstIndex = firstIndex; this.ElementCount = elementCount; this.OriginalElementCount = elementCount; this.Type = type; }
/// <summary> /// Wraps glDrawElements(uint mode, int count, uint type, IntPtr indices). /// </summary> /// <param name="bufferId">用glGenBuffers()得到的VBO的Id。<para>Id got from glGenBuffers();</para></param> /// <param name="mode">用哪种方式渲染各个顶点?(OpenGL.GL_TRIANGLES etc.)</param> /// <param name="type">type in glDrawElements(uint mode, int count, uint type, IntPtr indices); /// <para>表示第3个参数,表示索引元素的类型。</para></param> /// <param name="length">此VBO含有多个个元素?<para>How many elements?</para></param> /// <param name="byteLength">此VBO中的数据在内存中占用多少个字节?<para>How many bytes in this buffer?</para></param> /// <param name="primCount">primCount in instanced rendering.</param> internal OneIndexBufferPtr(uint bufferId, DrawMode mode, IndexElementType type, int length, int byteLength, int primCount = 1) : base(mode, bufferId, length, byteLength, primCount) { if (glDrawElementsInstanced == null) { glDrawElementsInstanced = OpenGL.GetDelegateFor <OpenGL.glDrawElementsInstanced>(); } this.ElementCount = length; this.Type = type; }
public static SharpDX.DXGI.Format ToDXElementType(this IndexElementType elementType) { switch (elementType) { case IndexElementType.Int16: return(SharpDX.DXGI.Format.R16_UInt); case IndexElementType.Int32: return(SharpDX.DXGI.Format.R32_UInt); default: throw new ArgumentOutOfRangeException(nameof(elementType)); } }
/// <summary> /// Gets the size of the element type in bytes. /// </summary> /// <param name="elementType"></param> /// <returns></returns> public static int TypeSize(this IndexElementType elementType) { switch (elementType) { case IndexElementType.Int16: return(2); case IndexElementType.Int32: return(4); default: throw new ArgumentOutOfRangeException(nameof(elementType)); } }
/// <summary> /// Invokes the GetCount delegate. /// </summary> /// <param name="element">The element type.</param> /// <returns>The element count.</returns> public int GetCount(IndexElementType element) { return(getCount(element)); }
/// <summary> /// Creates a new index buffer to hold the given index type. /// </summary> /// <param name="type">The type of the index elements.</param> /// <param name="count">The number of indices for this buffer to hold.</param> public IndexBuffer(IndexElementType type, uint count) : base(count * ((type == IndexElementType.U16) ? 2u : 4u), BufferType.Index, Vk.BufferUsages.IndexBuffer) { ElementType = type; IndexCount = count; }
/// <summary> /// Gets the number of elements in the index. /// </summary> /// <param name="element">The type of elements.</param> /// <returns>The number of elements.</returns> private int GetCount(IndexElementType element) { ICommandBuilder builder = GetCommandBuilder(); DbConnection connection = builder.GetConnection(connString); QueryBuilder queryBuilder = new QueryBuilder(builder); int count = 0; string elemName = ""; if(element == IndexElementType.Documents) elemName = "IndexDocument"; else if(element == IndexElementType.Words) elemName = "IndexWord"; else if(element == IndexElementType.Occurrences) elemName = "IndexWordMapping"; else throw new NotSupportedException("Unsupported element type"); string query = queryBuilder.SelectCountFrom(elemName); DbCommand command = builder.GetCommand(connection, query, new List<Parameter>()); count = ExecuteScalar<int>(command, -1, true); return count; }
/// <summary> /// Gets a free element ID from the database. /// </summary> /// <param name="element">The element type.</param> /// <param name="transaction">The current database transaction.</param> /// <returns>The free element ID.</returns> private uint GetFreeElementId(IndexElementType element, DbTransaction transaction) { if(element == IndexElementType.Occurrences) throw new ArgumentException("Element cannot be Occurrences", "element"); string table = element == IndexElementType.Documents ? "IndexDocument" : "IndexWord"; ICommandBuilder builder = GetCommandBuilder(); QueryBuilder queryBuilder = new QueryBuilder(builder); string query = queryBuilder.SelectFrom(table, new string[] { "Id" }); query = queryBuilder.OrderBy(query, new string[] { "Id" }, new Ordering[] { Ordering.Desc }); DbCommand command = builder.GetCommand(transaction, query, new List<Parameter>()); int id = ExecuteScalar<int>(command, -1, false); if(id == -1) return 0; else return (uint)id + 1; }
/// <summary> /// 用于存储索引的VBO。索引指定了<see cref="VertexAttributeBuffer<T>"/>里各个顶点的渲染顺序。 /// Vertex Buffer Object storing vertex' indexes, which indicate the rendering order of each vertex. /// </summary> /// <param name="elementType">element type.</param> /// <param name="mode">用哪种方式渲染各个顶点?(OpenGL.GL_TRIANGLES etc.)</param> /// <param name="usage"></param> /// <param name="primCount">primCount in instanced rendering.</param> public OneIndexBuffer(IndexElementType elementType, DrawMode mode, BufferUsage usage, int primCount = 1) : base(mode, usage, primCount) { this.Type = elementType; }
/// <summary> /// 用GL.DrawElements()执行一个索引buffer的渲染操作。 /// </summary> /// <param name="bufferID">用GL.GenBuffers()得到的VBO的ID。</param> /// <param name="mode">用哪种方式渲染各个顶点?(OpenGL.GL_TRIANGLES etc.)</param> /// <param name="elementCount">索引数组中有多少个元素。</param> /// <param name="type">type in GL.DrawElements(uint mode, int count, uint type, IntPtr indices); /// <para>表示第3个参数,表示索引元素的类型。</para></param> internal IndexBufferRenderer(uint bufferID, DrawMode mode, int elementCount, IndexElementType type) : base(mode, bufferID) { this.ElementCount = elementCount; this.Type = type; }
/// <summary> /// Invokes the GetCount delegate. /// </summary> /// <param name="element">The element type.</param> /// <returns>The element count.</returns> public int GetCount(IndexElementType element) { return getCount(element); }
/// <summary> /// 用于存储索引的VBO。 /// </summary> /// <param name="mode">用哪种方式渲染各个顶点?(OpenGL.GL_TRIANGLES etc.)</param> /// <param name="type">type in GL.DrawElements(uint mode, int count, uint type, IntPtr indices); /// <para>表示第3个参数,表示索引元素的类型。</para></param> /// <param name="usage"></param> public IndexBuffer(DrawMode mode, IndexElementType type, BufferUsage usage) : base(mode, usage) { this.Type = type; }