private unsafe void CommitNewConstantBufferBindings_MultiBind()
        {
            Debug.Assert(_extensions.ARB_MultiBind);
            int *   buffers          = stackalloc int[_maxConstantBufferSlots];
            IntPtr *sizes            = stackalloc IntPtr[_maxConstantBufferSlots];
            IntPtr *offsets          = stackalloc IntPtr[_maxConstantBufferSlots];
            int     currentIndex     = 0; // Index into stack allocated buffers.
            int     currentBaseSlot  = -1;
            int     remainingBuffers = _newConstantBuffersCount;

            void AddBinding(OpenGLConstantBuffer cb)
            {
                buffers[currentIndex] = cb.BufferID;
                sizes[currentIndex]   = new IntPtr(cb.BufferSize);

                currentIndex += 1;
            }

            void EmitBindings()
            {
                int count = currentIndex;

                GL.BindBuffersRange(BufferRangeTarget.UniformBuffer, currentBaseSlot, count, buffers, offsets, sizes);
                Utilities.CheckLastGLError();
                currentIndex      = 0;
                currentBaseSlot   = -1;
                remainingBuffers -= count;
                Debug.Assert(remainingBuffers >= 0);
            }

            for (int slot = 0; slot < _maxConstantBufferSlots; slot++)
            {
                OpenGLConstantBuffer cb = _newConstantBuffersBySlot[slot];
                if (cb != null)
                {
                    AddBinding(cb);
                    if (currentBaseSlot == -1)
                    {
                        currentBaseSlot = slot;
                    }
                    _constantBuffersBySlot[slot] = cb;
                }
                else if (currentIndex != 0)
                {
                    EmitBindings();
                    if (remainingBuffers == 0)
                    {
                        return;
                    }
                }
            }

            if (currentIndex != 0)
            {
                EmitBindings();
            }
        }
Ejemplo n.º 2
0
 public void BindUniformBuffers(int count, uint[] buffers, IntPtr[] offsets, IntPtr[] sizes)
 {
     GL.BindBuffersRange(BufferRangeTarget.UniformBuffer, 0, count, buffers, offsets, sizes);
 }