Example #1
0
        private void BindUniformBuffers(int ProgramHandle)
        {
            int FreeBinding = 0;

            int BindUniformBuffersIfNotNull(ShaderStage Stage)
            {
                if (Stage != null)
                {
                    foreach (ShaderDeclInfo DeclInfo in Stage.UniformUsage)
                    {
                        OGLStreamBuffer Buffer = GetConstBuffer(Stage.Type, DeclInfo.Cbuf);

                        GL.BindBufferBase(BufferRangeTarget.UniformBuffer, FreeBinding, Buffer.Handle);

                        FreeBinding++;
                    }
                }

                return(FreeBinding);
            }

            BindUniformBuffersIfNotNull(Current.Vertex);
            BindUniformBuffersIfNotNull(Current.TessControl);
            BindUniformBuffersIfNotNull(Current.TessEvaluation);
            BindUniformBuffersIfNotNull(Current.Geometry);
            BindUniformBuffersIfNotNull(Current.Fragment);
        }
Example #2
0
        public OGLShader()
        {
            Stages = new ConcurrentDictionary <long, ShaderStage>();

            Programs = new Dictionary <ShaderProgram, int>();

            ConstBuffers = new OGLStreamBuffer[5][];

            for (int i = 0; i < 5; i++)
            {
                ConstBuffers[i] = new OGLStreamBuffer[ConstBuffersPerStage];
            }
        }
Example #3
0
        public void SetConstBuffer(long Key, int Cbuf, int DataSize, IntPtr HostAddress)
        {
            if (Stages.TryGetValue(Key, out ShaderStage Stage))
            {
                foreach (ShaderDeclInfo DeclInfo in Stage.UniformUsage.Where(x => x.Cbuf == Cbuf))
                {
                    OGLStreamBuffer Buffer = GetConstBuffer(Stage.Type, Cbuf);

                    int Size = Math.Min(DataSize, Buffer.Size);

                    Buffer.SetData(Size, HostAddress);
                }
            }
        }
Example #4
0
        private OGLStreamBuffer GetConstBuffer(GalShaderType StageType, int Cbuf)
        {
            int StageIndex = (int)StageType;

            OGLStreamBuffer Buffer = ConstBuffers[StageIndex][Cbuf];

            if (Buffer == null)
            {
                //Allocate a maximum of 64 KiB
                int Size = Math.Min(GL.GetInteger(GetPName.MaxUniformBlockSize), 64 * 1024);

                Buffer = OGLStreamBuffer.Create(BufferTarget.UniformBuffer, Size);

                ConstBuffers[StageIndex][Cbuf] = Buffer;
            }

            return(Buffer);
        }
Example #5
0
        public void SetConstBuffer(long Key, int Cbuf, byte[] Data)
        {
            if (Stages.TryGetValue(Key, out ShaderStage Stage))
            {
                foreach (ShaderDeclInfo DeclInfo in Stage.UniformUsage.Where(x => x.Cbuf == Cbuf))
                {
                    OGLStreamBuffer Buffer = GetConstBuffer(Stage.Type, Cbuf);

                    int Size = Math.Min(Data.Length, Buffer.Size);

                    byte[] Destiny = Buffer.Map(Size);

                    Array.Copy(Data, Destiny, Size);

                    Buffer.Unmap(Size);
                }
            }
        }
Example #6
0
 private static void DeleteBuffer(OGLStreamBuffer Buffer)
 {
     Buffer.Dispose();
 }
Example #7
0
        public void Create(long Key, long Size)
        {
            OGLStreamBuffer Buffer = new OGLStreamBuffer(BufferTarget.UniformBuffer, Size);

            Cache.AddOrUpdate(Key, Buffer, Size);
        }