Пример #1
0
        /// <summary>
        /// Create and compile this shader.
        /// </summary>
        /// <param name="shaderType"></param>
        /// <param name="source"></param>
        public void Create(uint shaderType, string source)
        {
            if (glCreateShader == null)
            {
                glCreateShader     = OpenGL.GetDelegateFor <OpenGL.glCreateShader>();
                glShaderSource     = OpenGL.GetDelegateFor <OpenGL.glShaderSource>();
                glCompileShader    = OpenGL.GetDelegateFor <OpenGL.glCompileShader>();
                glDeleteShader     = OpenGL.GetDelegateFor <OpenGL.glDeleteShader>();
                glGetShaderiv      = OpenGL.GetDelegateFor <OpenGL.glGetShaderiv>();
                glGetShaderInfoLog = OpenGL.GetDelegateFor <OpenGL.glGetShaderInfoLog>();
            }

            //  Create the OpenGL shader object.
            uint shaderId = glCreateShader(shaderType);

            //  Set the shader source.
            glShaderSource(shaderId, 1, new[] { source }, new[] { source.Length });
            //  Compile the shader object.
            glCompileShader(shaderId);

            //  Now that we've compiled the shader, check it's compilation status. If it's not compiled properly, we're
            //  going to throw an exception.
            if (GetCompileStatus(shaderId) == false)
            {
                string log = this.GetInfoLog(shaderId);
                throw new Exception(
                          string.Format("Failed to compile shader with ID {0}: {1}", shaderId.ToString(), log));
            }

            this.ShaderId = shaderId;
        }
Пример #2
0
        /// <summary>
        /// Create and compile this shader.
        /// </summary>
        /// <param name="shaderType"></param>
        /// <param name="source"></param>
        public void Create(uint shaderType, string source)
        {
            if (glCreateShader == null)
            {
                glCreateShader = OpenGL.GetDelegateFor<OpenGL.glCreateShader>();
                glShaderSource = OpenGL.GetDelegateFor<OpenGL.glShaderSource>();
                glCompileShader = OpenGL.GetDelegateFor<OpenGL.glCompileShader>();
                glDeleteShader = OpenGL.GetDelegateFor<OpenGL.glDeleteShader>();
                glGetShaderiv = OpenGL.GetDelegateFor<OpenGL.glGetShaderiv>();
                glGetShaderInfoLog = OpenGL.GetDelegateFor<OpenGL.glGetShaderInfoLog>();
            }

            //  Create the OpenGL shader object.
            uint shaderId = glCreateShader(shaderType);

            //  Set the shader source.
            glShaderSource(shaderId, 1, new[] { source }, new[] { source.Length });
            //  Compile the shader object.
            glCompileShader(shaderId);

            //  Now that we've compiled the shader, check it's compilation status. If it's not compiled properly, we're
            //  going to throw an exception.
            if (GetCompileStatus(shaderId) == false)
            {
                string log = this.GetInfoLog(shaderId);
                throw new Exception(
                    string.Format("Failed to compile shader with ID {0}: {1}", shaderId.ToString(), log));
            }

            this.ShaderId = shaderId;
        }
Пример #3
0
 internal Shader()
 {
     if (glCreateShader == null)
     {
         glCreateShader  = OpenGL.GetDelegateFor <OpenGL.glCreateShader>();
         glShaderSource  = OpenGL.GetDelegateFor <OpenGL.glShaderSource>();
         glCompileShader = OpenGL.GetDelegateFor <OpenGL.glCompileShader>();
         glDeleteShader  = OpenGL.GetDelegateFor <OpenGL.glDeleteShader>();
         glGetShaderiv   = OpenGL.GetDelegateFor <OpenGL.glGetShaderiv>();
     }
 }
Пример #4
0
 internal Shader()
 {
     if (glCreateShader == null)
     {
         glCreateShader = OpenGL.GetDelegateFor<OpenGL.glCreateShader>();
         glShaderSource = OpenGL.GetDelegateFor<OpenGL.glShaderSource>();
         glCompileShader = OpenGL.GetDelegateFor<OpenGL.glCompileShader>();
         glDeleteShader = OpenGL.GetDelegateFor<OpenGL.glDeleteShader>();
         glGetShaderiv = OpenGL.GetDelegateFor<OpenGL.glGetShaderiv>();
     }
 }