示例#1
0
        private void BindUniformBlock(OpenGLESShaderSet shaderSet, int slot, int blockLocation, OpenGLESConstantBuffer cb)
        {
            if (slot > _maxConstantBufferSlots)
            {
                throw new VeldridException($"Too many constant buffers used. Limit is {_maxConstantBufferSlots}.");
            }

            // Bind Constant Buffer to slot
            if (_constantBuffersBySlot[slot] == cb)
            {
                if (_newConstantBuffersBySlot[slot] != null)
                {
                    _newConstantBuffersCount -= 1;
                }
                _newConstantBuffersBySlot[slot] = null;
            }
            else
            {
                if (_newConstantBuffersBySlot[slot] == null)
                {
                    _newConstantBuffersCount += 1;
                }

                _newConstantBuffersBySlot[slot] = cb;
            }

            // Bind slot to uniform block location. Performs internal caching to avoid GL calls.
            shaderSet.BindConstantBuffer(slot, blockLocation, cb);
        }
示例#2
0
        private unsafe void SetUniformLocationDataSlow(OpenGLESConstantBuffer cb, OpenGLESUniformStorageAdapter storageAdapter)
        {
            // NOTE: This is slow -- avoid using uniform locations in shader code. Prefer uniform blocks.
            int   dataSizeInBytes = cb.BufferSize;
            byte *data            = stackalloc byte[dataSizeInBytes];

            cb.GetData((IntPtr)data, dataSizeInBytes);
            storageAdapter.SetData((IntPtr)data, dataSizeInBytes);
        }
        public bool BindConstantBuffer(int slot, int blockLocation, OpenGLESConstantBuffer cb)
        {
            // NOTE: slot == uniformBlockIndex

            if (_boundConstantBuffers.TryGetValue(slot, out OpenGLESConstantBuffer boundCB) && boundCB == cb)
            {
                return(false);
            }

            GL.UniformBlockBinding(ProgramID, blockLocation, slot);
            Utilities.CheckLastGLES3Error();
            _boundConstantBuffers[slot] = cb;
            return(true);
        }
示例#4
0
        private void CommitNewConstantBufferBindings_SingleBind()
        {
            int remainingBindings = _newConstantBuffersCount;

            for (int slot = 0; slot < _maxConstantBufferSlots; slot++)
            {
                if (remainingBindings == 0)
                {
                    return;
                }

                OpenGLESConstantBuffer cb = _newConstantBuffersBySlot[slot];
                if (cb != null)
                {
                    GL.BindBufferRange(BufferRangeTarget.UniformBuffer, slot, cb.BufferID, IntPtr.Zero, cb.BufferSize);
                    Utilities.CheckLastGLES3Error();
                    remainingBindings -= 1;
                }
            }
        }
 public abstract void Bind(OpenGLESConstantBuffer cb);
 public override void Bind(OpenGLESConstantBuffer cb)
 {
     throw new NotImplementedException();
 }
 public override void Bind(OpenGLESConstantBuffer cb)
 {
     cb.BindToBlock(ProgramID, BlockIndex, _dataSizeInBytes, BindingIndex);
 }