コード例 #1
0
        ///// <summary>
        /////
        ///// </summary>
        ///// <typeparam name="T"></typeparam>
        ///// <param name="blockName"></param>
        ///// <param name="value"></param>
        ///// <returns></returns>
        //public bool SetUniformBlock<T>(string blockName, T value) where T : struct,IEquatable<T>
        //{
        //    //if ((!this.Initialized) && (!this.Initializing)) { this.Initialize(); }

        //    bool gotUniform = false;
        //    bool updated = false;
        //    foreach (UniformVariable item in this.uniformVariables)
        //    {
        //        if (item.VarName == blockName)
        //        {
        //            var variable = item as UniformBlock<T>;
        //            if (variable == null)
        //            { throw new ArgumentException(string.Format("Wrong type[{0}] for uniform block [{1}] [{2}];", typeof(T), item.GetType().Name, item.VarName)); }

        //            variable.Value = value;
        //            updated = variable.Updated;
        //            gotUniform = true;
        //            break;
        //        }
        //    }

        //    if (!gotUniform)
        //    {
        //        //if (ShaderProgram == null)
        //        //{ throw new Exception(string.Format("{0} is not initialized!", this.GetType().Name)); }

        //        //int location = ShaderProgram.GetUniformLocation(varNameInShader);
        //        //if (location < 0)
        //        //{
        //        //    throw new Exception(string.Format(
        //        //        "niform variable [{0}] not exists! Remember to invoke RendererBase.Initialize(); before this method.", varNameInShader));
        //        //}

        //        var variable = new UniformBlock<T>(blockName);
        //        variable.Value = value;
        //        this.uniformVariables.Add(variable);
        //        updated = true;
        //    }

        //    return updated;
        //}

        /// <summary>
        /// Sets up a new value to specified uniform variable and mark it as updated so that the new value will be sent to shader before rendering.
        /// </summary>
        /// <param name="varNameInShader"></param>
        /// <param name="texture"></param>
        /// <returns></returns>
        public bool SetUniform(string varNameInShader, Texture texture)
        {
            var value = new samplerValue(
                texture.Target,
                texture.Id,
                texture.TextureUnitIndex);

            return(this.SetUniform(varNameInShader, value));
        }
コード例 #2
0
ファイル: UniformSampler2D.cs プロジェクト: wsf1990/CSharpGL
        internal override bool SetValue(ValueType value)
        {
            if (value.GetType() != typeof(samplerValue))
            {
                throw new ArgumentException(string.Format("[{0}] not match [{1}]'s value.",
                                                          value.GetType().Name, this.GetType().Name));
            }

            var v = (samplerValue)value;

            if (v != this.value)
            {
                this.value   = v;
                this.Updated = true;
                return(true);
            }
            else
            {
                return(false);
            }
        }