public VertexArrayObject(GL gl) : base(gl)
        {
            _VertexAttributes           = new NonAllocatingList <IVertexAttribute>();
            _VertexBufferObjectBindings = new Dictionary <uint, VertexBufferObjectBinding>();

            Handle = GL.CreateVertexArray();

            Log.Verbose(string.Format(FormatHelper.DEFAULT_LOGGING, $"{nameof(VertexArrayObject)} 0x{Handle}", "Allocated new VAO."));
        }
        private bool TryGetAggregateAllocationTasks(EntityManager entityManager, [NotNullWhen(true)] out NonAllocatingList <Task>?tasks)
        {
            nint allocatedMeshDataCount = entityManager.GetComponentCount <AllocatedMeshData <TIndex, TVertex> >();

            if (allocatedMeshDataCount is 0)
            {
                tasks = null;
                return(false);
            }

            tasks = new NonAllocatingList <Task>((int)allocatedMeshDataCount);
            bool recreateCommandBuffer = false;

            foreach ((Entity entity, AllocatedMeshData <TIndex, TVertex> mesh) in
                     entityManager.GetEntitiesWithComponents <AllocatedMeshData <TIndex, TVertex> >())
            {
                unsafe Task CreateDrawIndirectAllocationAllocationImpl(DrawElementsIndirectAllocation <TIndex, TVertex> pendingAllocation)
                {
                    pendingAllocation.Allocation?.Dispose();

                    BufferMemory <TIndex> indexArrayMemory = _MultiDrawIndirectMesh.RentBufferMemory <TIndex>((nuint)sizeof(TIndex),
                                                                                                              MemoryMarshal.Cast <QuadIndexes <TIndex>, TIndex>(mesh.Data.Indexes.Segment));

                    BufferMemory <TVertex> vertexArrayMemory = _MultiDrawIndirectMesh.RentBufferMemory <TVertex>((nuint)sizeof(TVertex),
                                                                                                                 MemoryMarshal.Cast <QuadVertexes <TVertex>, TVertex>(mesh.Data.Vertexes.Segment));

                    pendingAllocation.Allocation = new MeshMemory <TIndex, TVertex>(indexArrayMemory, vertexArrayMemory);

                    return(Task.CompletedTask);
                }

                if (!mesh.Data.IsEmpty)
                {
                    if (!entity.TryComponent(out DrawElementsIndirectAllocation <TIndex, TVertex>?allocation))
                    {
                        allocation = entityManager.RegisterComponent <DrawElementsIndirectAllocation <TIndex, TVertex> >(entity);
                    }

                    tasks.Add(CreateDrawIndirectAllocationAllocationImpl(allocation));
                    ConfigureMaterial(entityManager, entity);
                    recreateCommandBuffer = true;
                }

                entityManager.RemoveComponent <AllocatedMeshData <TIndex, TVertex> >(entity);
            }

            return(recreateCommandBuffer);
        }
Exemple #3
0
 internal Enumerator(NonAllocatingList <T> list)
 {
     _List    = list;
     _Index   = 0u;
     _Current = default !;