예제 #1
0
        private void Bind(OGLShaderStage Stage)
        {
            if (Stage.Type == GalShaderType.Geometry)
            {
                //Enhanced layouts are required for Geometry shaders
                //skip this stage if current driver has no ARB_enhanced_layouts
                if (!OGLExtension.HasEnhancedLayouts())
                {
                    return;
                }
            }

            switch (Stage.Type)
            {
            case GalShaderType.Vertex:         Current.Vertex = Stage; break;

            case GalShaderType.TessControl:    Current.TessControl = Stage; break;

            case GalShaderType.TessEvaluation: Current.TessEvaluation = Stage; break;

            case GalShaderType.Geometry:       Current.Geometry = Stage; break;

            case GalShaderType.Fragment:       Current.Fragment = Stage; break;
            }
        }
예제 #2
0
        private void AttachIfNotNull(int ProgramHandle, OGLShaderStage Stage)
        {
            if (Stage != null)
            {
                Stage.Compile();

                GL.AttachShader(ProgramHandle, Stage.Handle);
            }
        }
예제 #3
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;
        }