An uniform variable in shader.
Beispiel #1
0
        public bool SetUniform(string varNameInShader, ValueType value)
        {
            bool gotUniform = false;
            bool updated    = false;

            foreach (var item in this.uniformVariables)
            {
                if (item.VarName == varNameInShader)
                {
                    updated    = item.SetValue(value);
                    gotUniform = true;
                    break;
                }
            }

            if (!gotUniform)
            {
                int location = shaderProgram.GetUniformLocation(varNameInShader);
                if (location < 0)
                {
                    throw new Exception(string.Format(
                                            "uniform variable [{0}] not exists!", varNameInShader));
                }

                UniformVariable variable = GetVariable(value, varNameInShader);
                variable.SetValue(value);
                this.uniformVariables.Add(variable);
                updated = true;
            }

            return(updated);
        }
        /// <summary>
        /// Initialize this shader program object.
        /// </summary>
        /// <param name="shaders"></param>
        public void Initialize(params Shader[] shaders)
        {
            foreach (var item in shaders)
            {
                item.Initialize();
            }

            //if (shaders.Length < 1) { throw new ArgumentException(); }
            uint programId = this.ProgramId;

            foreach (Shader item in shaders)
            {
                glAttachShader(programId, item.ShaderId);
            }

            glLinkProgram(programId);

            this.CheckLinkStatus(programId);

            UniformVarInShader[] variables = LoadAllUniformsInShader();
            foreach (var item in variables)
            {
                UniformVariable variable = item.GetUniformVariable(programId);
                if (variable != null)
                {
                    this.uniformVariables.Add(variable.VarName, variable);
                }
            }
        }
Beispiel #3
0
        private void ResetUniformValues(ShaderProgram program)
        {
            //while (uniformArrayVariableStack.Count > 0)
            //{
            //    UniformArrayVariable item = uniformArrayVariableStack.Pop();
            //    item.ResetUniform(program);
            //}

            while (uniformVariableStack.Count > 0)
            {
                UniformVariable item = uniformVariableStack.Pop();
                item.ResetUniform(program);
            }
        }
        private void btnMoveDown_Click(object sender, EventArgs e)
        {
            int index = this.lstMember.SelectedIndex;

            if (0 <= index && index + 1 < this.lstMember.Items.Count)
            {
                object item = this.lstMember.Items[index];
                this.lstMember.Items.RemoveAt(index);
                UniformVariable obj = this.list[index];
                this.list.RemoveAt(index);

                this.lstMember.Items.Insert(index + 1, item);
                this.list.Insert(index + 1, obj);

                this.lstMember.SelectedIndex = index + 1;
            }
        }