Example #1
0
        public void Create(
            long KeyA,
            long KeyB,
            byte[]        BinaryA,
            byte[]        BinaryB,
            GalShaderType Type)
        {
            long Key = KeyB;

            if (Stages.TryGetValue(Key, out List <OGLShaderStage> Cache))
            {
                OGLShaderStage CachedStage = Cache.Find((OGLShaderStage Stage) => Stage.EqualsBinary(BinaryA, BinaryB));

                if (CachedStage != null)
                {
                    TopStages[Key] = CachedStage;

                    return;
                }
            }
            else
            {
                Cache = new List <OGLShaderStage>();

                Stages.Add(Key, Cache);
            }

            GlslProgram Program;

            GlslDecompiler Decompiler = new GlslDecompiler();

            if (BinaryA != null)
            {
                ShaderHelper.Dump(BinaryA, Type, "a");
                ShaderHelper.Dump(BinaryB, Type, "b");

                Program = Decompiler.Decompile(BinaryA, BinaryB, Type);
            }
            else
            {
                ShaderHelper.Dump(BinaryB, Type);

                Program = Decompiler.Decompile(BinaryB, Type);
            }

            OGLShaderStage NewStage = new OGLShaderStage(
                Type,
                BinaryA,
                BinaryB,
                Program.Code,
                Program.Uniforms,
                Program.Textures);

            Cache.Add(NewStage);

            TopStages[Key] = NewStage;

            if (BinaryA != null)
            {
                TopStageSizes[KeyA] = BinaryA.Length;
            }

            TopStageSizes[KeyB] = BinaryB.Length;
        }