/// <summary> /// Constructor of IndexBufferObject class /// </summary> /// <param name="device">Graphics device</param> /// <param name="type">Type of buffer to use</param> /// <param name="buffer">Underlying index buffer</param> internal IndexBufferObject(GraphicsDevice device, BufferType type, IndexBuffer buffer) { _device = device; _bufferType = type; _elementSize = buffer.IndexElementSize; CreateWrapper(buffer); }
/// <summary> /// Constructor of IndexBufferObject class /// </summary> /// <param name="device">Graphics device</param> /// <param name="type">Type of buffer to use</param> /// <param name="elementSize">Size of one element stored in the buffer</param> /// <param name="indexCount">Initial size of the buffer</param> internal IndexBufferObject(GraphicsDevice device, BufferType type, IndexElementSize elementSize, int indexCount) { _device = device; _bufferType = type; _elementSize = elementSize; CreateBuffer(indexCount); }
#pragma warning restore 0067 #endregion #region Public Constructors public DynamicIndexBuffer( IndexElementSize indexElementSize, int indexCount, BufferUsage usage ) : base( indexElementSize, indexCount, usage, true ) { }
public static extern void FNA3D_DrawInstancedPrimitives( IntPtr device, PrimitiveType primitiveType, int baseVertex, int minVertexIndex, int numVertices, int startIndex, int primitiveCount, int instanceCount, IntPtr indices, /* FNA3D_Buffer* */ IndexElementSize indexElementSize );
public IndexBuffer( GraphicsDevice graphicsDevice, IndexElementSize indexElementSize, int indexCount, BufferUsage bufferUsage ) : this( graphicsDevice, indexElementSize, indexCount, bufferUsage, false ) { }
private static int GetElementSizeInBytes(IndexElementSize size) { switch (size) { case IndexElementSize.EightBits: return 1; case IndexElementSize.SixteenBits: return 2; case IndexElementSize.ThirtyTwoBits: return 4; default: throw new NotSupportedException(); } }
#pragma warning restore 0067 #endregion #region Public Constructors public DynamicIndexBuffer( GraphicsDevice graphicsDevice, IndexElementSize indexElementSize, int indexCount, BufferUsage usage ) : base( graphicsDevice, indexElementSize, indexCount, usage, true ) { }
protected IndexBuffer(GraphicsDevice graphicsDevice, IndexElementSize indexElementSize, int indexCount, BufferUsage usage, bool dynamic) { GraphicsDevice = graphicsDevice ?? throw new ArgumentNullException(nameof(graphicsDevice), "The GraphicsDevice must not be null when creating new resources."); IndexElementSize = indexElementSize; IndexCount = indexCount; BufferUsage = usage; _isDynamic = dynamic; }
public RenderBatch(GraphicsDevice graphicsDevice, VertexDeclaration vertexDeclaration, TVertex[] vertices, bool isVertexBufferDynamic, TIndex[] indices, bool isIndexBufferDynamic) { if (graphicsDevice == null) throw new ArgumentNullException("graphicsDevice"); if (vertices == null) throw new ArgumentNullException("vertices"); if (indices == null) throw new ArgumentNullException("indices"); _vertexDeclaration = vertexDeclaration; _isVertexBufferDynamic = isVertexBufferDynamic; _isIndexBufferDynamic = isIndexBufferDynamic; Vertices = vertices; Indices = indices; if (isVertexBufferDynamic) { _vertexBuffer = new DynamicVertexBuffer(graphicsDevice, _vertexDeclaration, Vertices.Length, BufferUsage.WriteOnly); } else { _vertexBuffer = new VertexBuffer(graphicsDevice, _vertexDeclaration, Vertices.Length, BufferUsage.WriteOnly); _vertexBuffer.SetData(vertices); } if (indices is ushort[]) { _indexElementSize = IndexElementSize.SixteenBits; } else if (indices is int[]) { _indexElementSize = IndexElementSize.ThirtyTwoBits; } else { throw new NotSupportedException("indices array must be of type ushort[] or int[]"); } if (isIndexBufferDynamic) { _indexBuffer = new DynamicIndexBuffer(graphicsDevice, _indexElementSize, indices.Length, BufferUsage.WriteOnly); } else { _indexBuffer = new IndexBuffer(graphicsDevice, _indexElementSize, indices.Length, BufferUsage.None); _indexBuffer.SetData(indices); } }
protected IndexBuffer(GraphicsDevice graphicsDevice, IndexElementSize indexElementSize, int indexCount, BufferUsage usage, bool dynamic) { if (graphicsDevice == null) { throw new ArgumentNullException("GraphicsDevice is null"); } this.GraphicsDevice = graphicsDevice; this.IndexElementSize = indexElementSize; this.IndexCount = indexCount; this.BufferUsage = usage; int num = (int)this.IndexElementSize; this._isDynamic = dynamic; Threading.BlockOnUIThread(new Action(this.GenerateIfRequired)); }
protected IndexBuffer(GraphicsDevice graphicsDevice, IndexElementSize indexElementSize, int indexCount, BufferUsage usage, bool dynamic) { if (graphicsDevice == null) { throw new ArgumentNullException("GraphicsDevice is null"); } this.GraphicsDevice = graphicsDevice; this.IndexElementSize = indexElementSize; this.IndexCount = indexCount; this.BufferUsage = usage; _isDynamic = dynamic; PlatformConstruct(indexElementSize, indexCount); }
protected IndexBuffer(GraphicsDevice graphicsDevice, IndexElementSize indexElementSize, int indexCount, BufferUsage usage, bool dynamic) { if (graphicsDevice == null) { throw new ArgumentNullException("graphicsDevice", FrameworkResources.ResourceCreationWhenDeviceIsNull); } this.GraphicsDevice = graphicsDevice; this.IndexElementSize = indexElementSize; this.IndexCount = indexCount; this.BufferUsage = usage; _isDynamic = dynamic; PlatformConstruct(indexElementSize, indexCount); }
/// <summary> /// Creates a Render Pass based on the given mesh and material /// </summary> public RenderPass(RenderTarget target, Mesh mesh, Material material) { Target = target; Viewport = null; Mesh = mesh; Material = material; MeshIndexStart = 0; MeshIndexCount = mesh.IndexCount; MeshInstanceCount = mesh.InstanceCount; Scissor = null; BlendMode = BlendMode.Normal; DepthFunction = Compare.None; CullMode = CullMode.None; IndexElementSize = IndexElementSize.ThirtyTwoBits; // Default to 32 bits. }
protected IndexBuffer(GraphicsDevice graphicsDevice, IndexElementSize indexElementSize, int indexCount, BufferUsage usage, bool dynamic) { if (graphicsDevice == null) { throw new ArgumentNullException("GraphicsDevice is null"); } this.GraphicsDevice = graphicsDevice; this.IndexElementSize = indexElementSize; this.IndexCount = indexCount; this.BufferUsage = usage; var sizeInBytes = indexCount * (this.IndexElementSize == IndexElementSize.SixteenBits ? 2 : 4); _isDynamic = dynamic; #if DIRECTX // TODO: To use true Immutable resources we would need to delay creation of // the Buffer until SetData() and recreate them if set more than once. var accessflags = SharpDX.Direct3D11.CpuAccessFlags.None; var resUsage = SharpDX.Direct3D11.ResourceUsage.Default; if (dynamic) { accessflags |= SharpDX.Direct3D11.CpuAccessFlags.Write; resUsage = SharpDX.Direct3D11.ResourceUsage.Dynamic; } _buffer = new SharpDX.Direct3D11.Buffer(graphicsDevice._d3dDevice, sizeInBytes, resUsage, SharpDX.Direct3D11.BindFlags.IndexBuffer, accessflags, SharpDX.Direct3D11.ResourceOptionFlags.None, 0 // StructureSizeInBytes ); #elif PSM if (indexElementSize != IndexElementSize.SixteenBits) { throw new NotImplementedException("PSS Currently only supports ushort (SixteenBits) index elements"); } _buffer = new ushort[indexCount]; #else Threading.BlockOnUIThread(GenerateIfRequired); #endif }
public IndexBuffer(GraphicsDevice graphicsDevice, IndexElementSize indexElementSize, int indexCount, BufferUsage usage) : base(graphicsDevice, BufferTarget.ElementArrayBuffer, GetElementSizeInBytes(indexElementSize), indexCount, usage) { IndexElementSize = indexElementSize; switch (indexElementSize) { case IndexElementSize.EightBits: DrawElementsType = DrawElementsType.UnsignedByte; break; case IndexElementSize.SixteenBits: DrawElementsType = DrawElementsType.UnsignedShort; break; case IndexElementSize.ThirtyTwoBits: DrawElementsType = DrawElementsType.UnsignedInt; break; } }
public IGLBuffer GenIndexBuffer( bool dynamic, int indexCount, IndexElementSize indexElementSize ) { IGLBuffer result = null; ForceToMainThread(() => { result = GLDevice.GenIndexBuffer( dynamic, indexCount, indexElementSize ); }); // End ForceToMainThread return(result); }
protected IndexBuffer( IndexElementSize indexElementSize, int indexCount, BufferUsage usage, bool dynamic ) { GraphicsDevice = GraphicsDeviceManager.Instance.GraphicsDevice; IndexElementSize = indexElementSize; IndexCount = indexCount; BufferUsage = usage; int stride = (indexElementSize == IndexElementSize.ThirtyTwoBits) ? 4 : 2; buffer = FNA3D.FNA3D_GenIndexBuffer( GraphicsDevice.GLDevice, (byte)(dynamic ? 1 : 0), usage, IndexCount * stride ); }
protected IndexBuffer(GraphicsDevice graphicsDevice, IndexElementSize indexElementSize, int indexCount, BufferUsage bufferUsage, bool dynamic) { IndexBuffer indexBuffer = this; if (graphicsDevice == null) { throw new ArgumentNullException("Graphics Device Cannot Be Null"); } this.GraphicsDevice = graphicsDevice; this.IndexElementSize = indexElementSize; this.IndexCount = indexCount; this.BufferUsage = bufferUsage; int sizeInBytes = indexCount * (this.IndexElementSize == IndexElementSize.SixteenBits ? 2 : 4); this._isDynamic = dynamic; Threading.BlockOnUIThread((Action)(() => { GL.GenBuffers(1, out indexBuffer.ibo); GL.BindBuffer(BufferTarget.ElementArrayBuffer, indexBuffer.ibo); GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)sizeInBytes, IntPtr.Zero, dynamic ? BufferUsageHint.StreamDraw : BufferUsageHint.StaticDraw); })); }
public IndexBuffer(GraphicsDevice graphicsDevice, Type indexType, int elementCount, BufferUsage usage) : this(graphicsDevice, usage) { int size = Marshal.SizeOf(indexType); if (size == 16) { indexElementSize = IndexElementSize.SixteenBits; } else if (size == 32) { indexElementSize = IndexElementSize.ThirtyTwoBits; } else { throw new ArgumentOutOfRangeException("The indexType must be either 16 or 32 bit"); } this.sizeInBytes = Marshal.SizeOf(indexType) * elementCount; createHostBuffer(); }
protected IndexBuffer( GraphicsDevice graphicsDevice, IndexElementSize indexElementSize, int indexCount, BufferUsage usage, bool dynamic ) { if (graphicsDevice == null) { throw new ArgumentNullException("graphicsDevice"); } GraphicsDevice = graphicsDevice; IndexElementSize = indexElementSize; IndexCount = indexCount; BufferUsage = usage; buffer = GraphicsDevice.GLDevice.GenIndexBuffer( dynamic, IndexCount, IndexElementSize ); }
public static IndexBuffer ReadIndexBuffer(TWXmlNode node, XNAGame game) { if (node.Value == "NULL") { return(null); } BufferUsage bufferUsage = (BufferUsage)Enum.Parse(typeof(BufferUsage), node.ReadChildNodeValue("BufferUsage")); IndexElementSize elementSize = (IndexElementSize)Enum.Parse(typeof(IndexElementSize), node.ReadChildNodeValue("IndexElementSize")); TWXmlNode dataNode = node.FindChildNode("Data"); int length = dataNode.GetAttributeInt("length"); byte[] data;// = new byte[ length ]; data = Convert.FromBase64String(dataNode.ReadCData()); IndexBuffer ib = new IndexBuffer(game.GraphicsDevice, length, bufferUsage, elementSize); ib.SetData <byte>(data); return(ib); }
// // FNA3D_DrawIndexedPrimitives // public static void FNA3D_DrawIndexedPrimitives(IntPtr device, PrimitiveType primitiveType, int baseVertex, int minVertexIndex, int numVertices, int startIndex, int primitiveCount, IntPtr indices, IndexElementSize indexElementSize) { int elementSize, elementType; if (indexElementSize == IndexElementSize.SixteenBits) { elementSize = 2; elementType = GLES20.GL_UNSIGNED_SHORT; } else if (indexElementSize == IndexElementSize.ThirtyTwoBits) { elementSize = 4; elementType = GLES20.GL_UNSIGNED_INT; } else { throw new ArgumentException("invalid IndexElementSize"); } int drawMode = PrimitiveTypeToDrawMode[(int)primitiveType]; int maxVertexIndex = minVertexIndex + numVertices - 1; int indexOffset = startIndex * elementSize; primitiveCount = PrimitiveCount(primitiveType, primitiveCount); Renderer.Get(device).Send(false, () => { GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, (int)indices); GLES30.glDrawRangeElements(drawMode, minVertexIndex, maxVertexIndex, primitiveCount, elementType, indexOffset); }); }
public XnaHardwareIndexBuffer( HardwareBufferManagerBase manager, IndexType type, int numIndices, BufferUsage usage, GraphicsDevice device, bool useSystemMemory, bool useShadowBuffer ) : base(manager, Validate(type), numIndices, usage, useSystemMemory, useShadowBuffer) { if (this.type == IndexType.Size16) _bufferType = IndexElementSize.SixteenBits; #if !SILVERLIGHT else _bufferType = IndexElementSize.ThirtyTwoBits; #endif // create the buffer if ( usage == BufferUsage.Dynamic || usage == BufferUsage.DynamicWriteOnly ) { _xnaBuffer = new IndexBuffer( device, _bufferType, numIndices, XnaHelper.Convert( usage ) ); } else { _xnaBuffer = new IndexBuffer( device, _bufferType, numIndices, Microsoft.Xna.Framework.Graphics.BufferUsage.None ); } _bufferBytes = new byte[sizeInBytes]; _bufferBytes.Initialize(); }
private void PlatformConstruct(IndexElementSize indexElementSize, int indexCount) { Threading.BlockOnUIThread(GenerateIfRequired); }
public IndexBuffer(GraphicsDevice graphicsDevice, IndexElementSize sixteenBits, int maxIndices, BufferUsage writeOnly) : base(graphicsDevice) { }
/// <summary> /// Merges some indexedbatchinformation objects. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="GraphicFactory">The graphic factory.</param> /// <param name="IndexElementSize">Size of the index element.</param> /// <param name="ExtraBatchInformation">The extra batch information.</param> public static void MergeIndexedBatchInformation <T>(GraphicFactory GraphicFactory, IndexElementSize IndexElementSize, params BatchInformation[] ExtraBatchInformation) where T : struct, IVertexType { CheckBatchInformationsConsistency <T>(ExtraBatchInformation); int NumVerts = 0; int NumIndexes = 0; for (int i = 0; i < ExtraBatchInformation.Count(); i++) { NumVerts += ExtraBatchInformation[i].VertexBuffer.VertexCount; NumIndexes += ExtraBatchInformation[i].IndexBuffer.IndexCount; } //complete int[] completeindex = new int[NumVerts]; T[] completevertex = new T[NumIndexes]; VertexDeclaration VertexDeclaration = ExtraBatchInformation[0].VertexDeclaration; //mandatory int[] indexbuffer = new int[ExtraBatchInformation[0].IndexBuffer.IndexCount]; switch (IndexElementSize) { case IndexElementSize.SixteenBits: short[] tempindex = new short[ExtraBatchInformation[0].IndexBuffer.IndexCount]; ExtraBatchInformation[0].IndexBuffer.GetData <short>(tempindex); for (int i = 0; i < tempindex.Count(); i++) { indexbuffer[i] = tempindex[i]; } break; case IndexElementSize.ThirtyTwoBits: ExtraBatchInformation[0].IndexBuffer.GetData <int>(indexbuffer); break; default: break; } //mandatory T[] vertexBuffer = new T[ExtraBatchInformation[0].VertexBuffer.VertexCount]; ExtraBatchInformation[0].VertexBuffer.GetData <T>(vertexBuffer); ExtraBatchInformation[0].VertexBuffer.Dispose(); ExtraBatchInformation[0].IndexBuffer.Dispose(); int VertexOffset = 0; int IndexOffset = 0; for (int i = 1; i < ExtraBatchInformation.Count(); i++) { //extra vertex T[] ExtravertexBuffer = new T[ExtraBatchInformation[i].VertexBuffer.VertexCount]; ExtraBatchInformation[i].VertexBuffer.GetData <T>(vertexBuffer); //extra index int[] ExtraindexBuffer = new int[ExtraBatchInformation[i].IndexBuffer.IndexCount]; switch (IndexElementSize) { case IndexElementSize.SixteenBits: short[] tempindex = new short[ExtraBatchInformation[0].IndexBuffer.IndexCount]; ExtraBatchInformation[0].IndexBuffer.GetData <short>(tempindex); for (int q = 0; q < ExtraindexBuffer.Count(); q++) { ExtraindexBuffer[q] = tempindex[q]; } break; case IndexElementSize.ThirtyTwoBits: ExtraBatchInformation[i].IndexBuffer.GetData <int>(ExtraindexBuffer); break; default: break; } for (int v = 0; v < ExtraBatchInformation[i].VertexBuffer.VertexCount; v++) { completevertex[VertexOffset + v] = ExtravertexBuffer[v]; } for (int j = 0; j < ExtraBatchInformation[i].IndexBuffer.IndexCount; j++) { completeindex[IndexOffset + i] = ExtraindexBuffer[j] + VertexOffset; } ExtraBatchInformation[i].VertexBuffer.Dispose(); ExtraBatchInformation[i].IndexBuffer.Dispose(); ExtraBatchInformation[i].StartIndex = IndexOffset; ExtraBatchInformation[i].StartVertex = VertexOffset; VertexOffset += ExtravertexBuffer.Count(); IndexOffset += ExtraindexBuffer.Count(); } IndexBuffer IndexBuffer = GraphicFactory.CreateIndexBuffer(IndexElementSize.ThirtyTwoBits, NumIndexes, BufferUsage.None); VertexBuffer VertexBuffer = GraphicFactory.CreateVertexBuffer(VertexDeclaration, NumIndexes, BufferUsage.None); for (int i = 0; i < ExtraBatchInformation.Count(); i++) { ExtraBatchInformation[i].IndexBuffer = IndexBuffer; ExtraBatchInformation[i].VertexBuffer = VertexBuffer; } }
/// <summary> /// Creates a new IndexBufferObject /// </summary> /// <param name="bufferType">Type of buffer to create</param> /// <param name="elementSize">Size of index stored in the buffer</param> /// <param name="indexCount">Number of indices in the buffer</param> /// <returns>Returns an IndexBufferObject</returns> public IndexBufferObject CreateIndexBuffer(BufferType bufferType, IndexElementSize elementSize, int indexCount) { return new IndexBufferObject(_deviceManager.GraphicsDevice, bufferType, elementSize, indexCount); }
private void PlatformConstruct(IndexElementSize indexElementSize, int indexCount) { GenerateIfRequired(); }
protected IndexBuffer(GraphicsDevice graphicsDevice, IndexElementSize indexElementSize, int indexCount, BufferUsage usage, bool dynamic) { }
public DynamicIndexBuffer(GraphicsDevice graphicsDevice, int sizeInBytes, BufferUsage usage, IndexElementSize elementSize) : base(graphicsDevice, sizeInBytes, usage, elementSize) { throw new NotImplementedException(); }
public PooledIndexBuffer(GpuResourceManager parent, long id, object owner, GraphicsDevice graphicsDevice, IndexElementSize indexElementSize, int indexCount, BufferUsage bufferUsage) : base(graphicsDevice, indexElementSize, indexCount, bufferUsage) { Parent = parent; PoolId = id; CreatedTime = DateTime.UtcNow; Owner = owner; }
private void PlatformConstruct(IndexElementSize indexElementSize, int indexCount) { throw new NotImplementedException(); }
protected IndexBuffer(IGraphicsDevice graphicsDevice, IndexElementSize indexElementSize, int indexCount, BufferUsage usage, bool dynamic) { throw new NotImplementedException(); }
public DynamicIndexBuffer(GraphicsDevice graphicsDevice, IndexElementSize indexElementSize, int indexCount, BufferUsage bufferUsage) : base(graphicsDevice, indexElementSize, indexCount, bufferUsage) { }
public void DrawUserIndexedPrimitives( PrimitiveType primitiveType, IntPtr vertexData, int vertexOffset, int numVertices, IntPtr indexData, int indexOffset, IndexElementSize indexElementSize, int primitiveCount ) { // Unbind current index buffer. BindIndexBuffer(OpenGLBuffer.NullBuffer); // Draw! glDrawRangeElements( XNAToGL.Primitive[(int) primitiveType], 0, numVertices - 1, XNAToGL.PrimitiveVerts(primitiveType, primitiveCount), XNAToGL.IndexType[(int) indexElementSize], (IntPtr) ( indexData.ToInt64() + (indexOffset * XNAToGL.IndexSize[(int) indexElementSize]) ) ); }
public IndexBuffer(GraphicsDevice graphicsDevice, int sizeInBytes, BufferUsage usage, IndexElementSize elementSize) : this(graphicsDevice, usage) { this.sizeInBytes = sizeInBytes; this.indexElementSize = elementSize; createHostBuffer(); }
public IGLBuffer GenIndexBuffer( bool dynamic, int indexCount, IndexElementSize indexElementSize ) { OpenGLBuffer result = null; #if !DISABLE_THREADING ForceToMainThread(() => { #endif uint handle; glGenBuffers(1, out handle); result = new OpenGLBuffer( handle, (IntPtr) (indexCount * XNAToGL.IndexSize[(int) indexElementSize]), dynamic ? GLenum.GL_STREAM_DRAW : GLenum.GL_STATIC_DRAW ); BindIndexBuffer(result); glBufferData( GLenum.GL_ELEMENT_ARRAY_BUFFER, result.BufferSize, IntPtr.Zero, result.Dynamic ); #if !DISABLE_THREADING }); #endif return result; }
protected InstancedIndexBuffer( GraphicsDevice graphicsDeivce, int sizeInBytes, IndexElementSize indexElementSize) : base(graphicsDeivce, sizeInBytes, BufferUsage.None, indexElementSize) { }
public IndexBuffer CreateIndexBuffer(IndexElementSize id, int s, BufferUsage usage = BufferUsage.WriteOnly) { IndexBuffer ib = new IndexBuffer(G, id, s, usage); toDispose.Add(ib); return ib; }
public IndexBuffer(IGraphicsDevice graphicsDevice, IndexElementSize indexElementSize, int indexCount, BufferUsage bufferUsage) { throw new NotImplementedException(); }
public DynamicIndexBuffer(GraphicsDevice graphicsDevice, IndexElementSize indexElementSize, int maxIndices, BufferUsage writeOnly) : base(graphicsDevice) { }