コード例 #1
0
ファイル: Shader.cs プロジェクト: MetalYos/OpenGlNet
        uint compileShader(OpenGL.ShaderType type, string source)
        {
            uint id = Gl.CreateShader(type);

            Gl.ShaderSource(id, new string[] { source });
            Gl.CompileShader(id);

            // Check for compilation errors
            int result;

            Gl.GetShader(id, ShaderParameterName.CompileStatus, out result);
            if (result == 0)
            {
                int length;
                Gl.GetShader(id, ShaderParameterName.InfoLogLength, out length);

                StringBuilder infoLog = new StringBuilder(length);
                Gl.GetShaderInfoLog(id, length, out length, infoLog);

                string shaderType = "Vertex";
                if (type == OpenGL.ShaderType.GeometryShader)
                {
                    shaderType = "Geometry";
                }
                if (type == OpenGL.ShaderType.FragmentShader)
                {
                    shaderType = "Fragment";
                }
                Debug.WriteLine("ERROR: " + shaderType + " shader: " + infoLog.ToString());
            }

            return(id);
        }
コード例 #2
0
        private uint Compile(OpenGL.ShaderType shaderType, string source)
        {
            uint shader = Gl.CreateShader(shaderType);

            Gl.ShaderSource(shader, new string[] { source });
            Gl.CompileShader(shader);
            Gl.GetShader(shader, ShaderParameterName.CompileStatus, out int success);
            if (success == Gl.FALSE)
            {
                // compile error
                Gl.GetShader(shader, ShaderParameterName.InfoLogLength, out int length);
                StringBuilder logBuilder = new StringBuilder();
                Gl.GetShaderInfoLog(shader, length, out int _, logBuilder);
                Debug.LogWarning(string.Format("Shader compilation failed:\n{0}\n{1}", source, logBuilder.ToString()));
            }
            return(shader);
        }