Esempio n. 1
0
        public static Shader FromFile(ShaderType type, string fileName)
        {
            Shader shader = new Shader(type, string.Empty);
            shader.LoadSource(fileName);

            return shader;
        }
Esempio n. 2
0
        public void Initialize(Shader vertexShader, Shader fragmentShader)
        {
            if (!Initialized)
            {
                this.vertexShader = vertexShader;
                this.fragmentShader = fragmentShader;

                if (!vertexShader.Initialized)
                {
                    vertexShader.Initialize();
                }

                if (!fragmentShader.Initialized)
                {
                    fragmentShader.Initialize();
                }

                Handle = GL.CreateProgram();

                GL.AttachShader(Handle, vertexShader.Handle);
                GL.AttachShader(Handle, fragmentShader.Handle);

                GL.LinkProgram(Handle);

                int status;
                GL.GetProgram(Handle, ProgramParameter.LinkStatus, out status);

                string info;
                GL.GetProgramInfoLog(Handle, out info);

                string message = string.IsNullOrEmpty(info) ? "Program linked succesfully"
                                                            : string.Format("Program link result:{0}{1}",
                                                                            Environment.NewLine, info);

                System.Diagnostics.Debug.WriteLine(message);

                if (status == 0)
                {
                    throw new GraphicsException(message);
                }

                Initialized = true;
            }
        }
Esempio n. 3
0
        protected override void Dispose(bool nongc)
        {
            if (nongc && Initialized)
            {
                    GL.DetachShader(Handle, vertexShader.Handle);
                    GL.DetachShader(Handle, fragmentShader.Handle);

                    vertexShader.Dispose();
                    fragmentShader.Dispose();

                    vertexShader = null;
                    fragmentShader = null;

                    GL.DeleteProgram(Handle);

                    Handle = 0;
                    Initialized = false;
            }
        }