Example #1
0
        internal void Compile()
        {
            parts.RemoveAll(p => p == null);
            uniforms.Clear();
            uniformsArray = null;
            Log.Clear();

            if (programID != -1)
            {
                Dispose(true);
            }

            if (parts.Count == 0)
            {
                return;
            }

            programID = GL.CreateProgram();
            foreach (ShaderPart p in parts)
            {
                if (!p.Compiled)
                {
                    p.Compile();
                }
                GL.AttachShader(this, p);
            }

            GL.BindAttribLocation(this, 0, "m_Position");
            GL.BindAttribLocation(this, 1, "m_Colour");
            GL.BindAttribLocation(this, 2, "m_TexCoord");
            GL.BindAttribLocation(this, 3, "m_Time");
            GL.BindAttribLocation(this, 4, "m_Direction");

            GL.LinkProgram(this);

            int linkResult;

            GL.GetProgram(this, GetProgramParameterName.LinkStatus, out linkResult);
            string linkLog = GL.GetProgramInfoLog(this);

            Log.AppendLine(string.Format(ShaderPart.BOUNDARY, name));
            Log.AppendLine(string.Format("Linked: {0}", linkResult == 1));
            if (linkResult == 0)
            {
                Log.AppendLine("Log:");
                Log.AppendLine(linkLog);
            }

            foreach (var part in parts)
            {
                GL.DetachShader(this, part);
            }

            Loaded = linkResult == 1;

            if (Loaded)
            {
                //Obtain all the shader uniforms
                int uniformCount;
                GL.GetProgram(this, GetProgramParameterName.ActiveUniforms, out uniformCount);
                uniformsArray = new UniformBase[uniformCount];

                for (int i = 0; i < uniformCount; i++)
                {
                    int size;
                    int length;
                    ActiveUniformType type;
                    StringBuilder     uniformName = new StringBuilder(100);
                    GL.GetActiveUniform(this, i, 100, out length, out size, out type, uniformName);

                    string strName = uniformName.ToString();

                    uniformsArray[i] = new UniformBase(this, strName, GL.GetUniformLocation(this, strName), type);
                    uniforms.Add(strName, uniformsArray[i]);
                }

                foreach (KeyValuePair <string, object> kvp in globalProperties)
                {
                    if (!uniforms.ContainsKey(kvp.Key))
                    {
                        continue;
                    }
                    uniforms[kvp.Key].Value = kvp.Value;
                }

                allShaders.Add(this);
            }
        }
Example #2
0
        internal void Compile()
        {
            parts.RemoveAll(p => p == null);
            uniforms.Clear();
            uniformsArray = null;
            Log.Clear();

            if (programID != -1)
            {
                Dispose(true);
            }

            if (parts.Count == 0)
            {
                return;
            }

            programID = GL.CreateProgram();
            foreach (ShaderPart p in parts)
            {
                if (!p.Compiled)
                {
                    p.Compile();
                }
                GL.AttachShader(this, p);

                foreach (AttributeInfo attribute in p.Attributes)
                {
                    GL.BindAttribLocation(this, attribute.Location, attribute.Name);
                }
            }

            GL.LinkProgram(this);

            int linkResult;

            GL.GetProgram(this, GetProgramParameterName.LinkStatus, out linkResult);
            string linkLog = GL.GetProgramInfoLog(this);

            Log.AppendLine(string.Format(ShaderPart.BOUNDARY, name));
            Log.AppendLine($"Linked: {linkResult == 1}");
            if (linkResult == 0)
            {
                Log.AppendLine("Log:");
                Log.AppendLine(linkLog);
            }

            foreach (var part in parts)
            {
                GL.DetachShader(this, part);
            }

            Loaded = linkResult == 1;

            if (Loaded)
            {
                //Obtain all the shader uniforms
                int uniformCount;
                GL.GetProgram(this, GetProgramParameterName.ActiveUniforms, out uniformCount);
                uniformsArray = new UniformBase[uniformCount];

                for (int i = 0; i < uniformCount; i++)
                {
                    ActiveUniformType type;
                    string            uniformName;
                    GL.GetActiveUniform(this, i, 100, out _, out _, out type, out uniformName);

                    uniformsArray[i] = new UniformBase(this, uniformName, GL.GetUniformLocation(this, uniformName), type);
                    uniforms.Add(uniformName, uniformsArray[i]);
                }

                foreach (KeyValuePair <string, object> kvp in global_properties)
                {
                    if (!uniforms.ContainsKey(kvp.Key))
                    {
                        continue;
                    }
                    uniforms[kvp.Key].Value = kvp.Value;
                }

                all_shaders.Add(this);
            }
        }
Example #3
0
 internal Uniform(UniformBase uniformBase)
 {
     this.uniformBase = uniformBase;
 }