public static void SetShaderStorageBufferBinding(StorageBuffer buf, int index)
 {
     if (buf == null)
     {
         return;
     }
     GL.BindBufferBase(BufferRangeTarget.ShaderStorageBuffer, index, (int)buf);
 }
 public void Build(StorageBuffer buf)
 {
     if (!locked)
     {
         GL.CreateTextures(OpenTK.Graphics.OpenGL4.TextureTarget.TextureBuffer, 1, out id);
         GL.TextureBuffer(id, (SizedInternalFormat)Format, (GpuBuffer)buf);
         locked = true;
     }
 }
        public RenderQueue(int MaxDrawCount, IndexType t, bool transient)
        {
            this.transient = transient;
            this.idxType   = t;
            MeshGroups     = new List <MeshData>();

            if (MaxDrawCount < 4096)
            {
                MaxDrawCount = 4096;
            }

            this.MaxDrawCount = MaxDrawCount;
            MultidrawParams   = new StorageBuffer(MaxDrawCount * Stride + InfoOffset, transient);
        }
        public static void SetRenderState(RenderState state)
        {
            GraphicsDevice.CullMode          = state.CullMode;
            GraphicsDevice.ClearColor        = state.ClearColor;
            GraphicsDevice.DepthTest         = state.DepthTest;
            GraphicsDevice.DepthWriteEnabled = state.DepthWrite;
            GraphicsDevice.ColorWriteEnabled = state.ColorWrite;
            GraphicsDevice.ClearDepth        = state.ClearDepth;
            GraphicsDevice.AlphaSrc          = state.Src;
            GraphicsDevice.AlphaDst          = state.Dst;
            if (state.Framebuffer != null)
            {
                GraphicsDevice.Framebuffer = state.Framebuffer;
            }
            GraphicsDevice.SetDepthRange(state.NearPlane, state.FarPlane);


            if (state.IndexBuffer != null)
            {
                SetVertexArray(state.IndexBuffer.varray);
            }
            for (int i = 0; i < state.Viewports.Length; i++)
            {
                GraphicsDevice.SetViewport(i, state.Viewports[i].X, state.Viewports[i].Y, state.Viewports[i].Z, state.Viewports[i].W);
            }

            if (state.ShaderStorageBufferBindings != null)
            {
                StorageBuffer[] pendingBindings = new StorageBuffer[state.ShaderStorageBufferBindings.Length];
                Array.Copy(state.ShaderStorageBufferBindings, pendingBindings, pendingBindings.Length);
                int pendingCnt = pendingBindings.Length;
                while (pendingCnt > 0)
                {
                    for (int i = 0; i < pendingBindings.Length; i++)
                    {
                        if (pendingBindings[i] != null && pendingBindings[i].IsReady)
                        {
                            GraphicsDevice.SetShaderStorageBufferBinding(pendingBindings[i], i);
                            pendingBindings[i] = null;
                            pendingCnt--;
                        }
                    }
                }
            }

            if (state.UniformBufferBindings != null)
            {
                UniformBuffer[] pendingBindings = new UniformBuffer[state.UniformBufferBindings.Length];
                Array.Copy(state.UniformBufferBindings, pendingBindings, pendingBindings.Length);
                int pendingCnt = pendingBindings.Length;
                while (pendingCnt > 0)
                {
                    for (int i = 0; i < pendingBindings.Length; i++)
                    {
                        if (pendingBindings[i] != null && pendingBindings[i].IsReady)
                        {
                            GraphicsDevice.SetUniformBufferBinding(pendingBindings[i], i);
                            pendingBindings[i] = null;
                            pendingCnt--;
                        }
                    }
                }
            }

            if (state.ShaderProgram != null)
            {
                GraphicsDevice.ShaderProgram = state.ShaderProgram;
            }
        }