Example #1
0
        protected uint CompileShaderObject(int type, string name)
        {
            var ext      = type == OpenGL.GL_VERTEX_SHADER ? "vert" : "frag";
            var filename = Path.Combine(Platform.GameDir, "glsl", name + "." + ext);
            var code     = File.ReadAllText(filename);

            var version = OpenGL.Profile == GLProfile.Embedded ? "300 es" :
                          OpenGL.Profile == GLProfile.Legacy ? "120" : "140";

            code = code.Replace("{VERSION}", version);

            var shader = OpenGL.glCreateShader(type);

            OpenGL.CheckGLError();
            unsafe
            {
                var length = code.Length;
                OpenGL.glShaderSource(shader, 1, new string[] { code }, new IntPtr(&length));
            }

            OpenGL.CheckGLError();
            OpenGL.glCompileShader(shader);
            OpenGL.CheckGLError();
            int success;

            OpenGL.glGetShaderiv(shader, OpenGL.GL_COMPILE_STATUS, out success);
            OpenGL.CheckGLError();
            if (success == OpenGL.GL_FALSE)
            {
                int len;
                OpenGL.glGetShaderiv(shader, OpenGL.GL_INFO_LOG_LENGTH, out len);
                var log = new StringBuilder(len);
                int length;
                OpenGL.glGetShaderInfoLog(shader, len, out length, log);

                Log.Write("graphics", "GL Info Log:\n{0}", log.ToString());
                throw new InvalidProgramException("Compile error in shader object '{0}'".F(filename));
            }

            return(shader);
        }
Example #2
0
        protected uint CompileShaderObject(int type, string name)
        {
            var ext      = ShaderTypeToFileExt(type);
            var filename = Path.Combine(Platform.GameDir, "glsl", name + "." + ext);
            var code     = File.ReadAllText(filename);

            var shader = OpenGL.glCreateShader(type);

            if (shader == 0)
            {
            }
            unsafe
            {
                var length = code.Length;
                OpenGL.glShaderSource(shader, 1, new string[] { code }, new IntPtr(&length));
            }

            OpenGL.glCompileShader(shader);


            int success;

            OpenGL.glGetShaderiv(shader, OpenGL.GL_COMPILE_STATUS, out success);
            if (success == OpenGL.GL_FALSE)
            {
                int len;
                OpenGL.glGetShaderiv(shader, OpenGL.GL_INFO_LOG_LENGTH, out len);
                var log = new StringBuilder(len);
                int length;
                OpenGL.glGetShaderInfoLog(shader, len, out length, log);

                Log.Write("graphics", "GL Info Log:\n{0}", log.ToString());
                throw new InvalidProgramException("Compile error in shader object '{0}'".F(filename));
            }

            return(shader);
        }