コード例 #1
0
 public Uniforms(GLProgram program)
 {
     foreach (var field in GetType().GetUniforms())
     {
         field.SetValue(this, Activator.CreateInstance(field.FieldType, program, field));
     }
 }
コード例 #2
0
        private static int GetUniformLocation(GLProgram program, string name)
        {
            var loc = GL.GetUniformLocation(program._glProgram, name);

            if (loc < 0)
            {
                Trace.TraceWarning(string.Format("Creating uniform '{0}' which is not found in program. " +
                                                 " Probably optimized away by OpenGL.", name));
            }
            return(loc);
        }
コード例 #3
0
 private void CreateUniform(GLProgram program, string name, Type type)
 {
     if (type.IsGLStruct())
     {
         _mappings = (from field in type.GetGLStructFields(name + ".")
                      select Tuple.Create(field, GetUniformLocation(program, field.Name)))
                     .ToArray();
     }
     else
     {
         _glUniform = GetUniformLocation(program, name);
     }
     _name = name;
 }
コード例 #4
0
        public Uniform(GLProgram program, FieldInfo field)
        {
            if (field.FieldType.GetGenericTypeDefinition() != typeof(Uniform <>))
            {
                throw new ArgumentException("Field must be of Uniform<> generic type.");
            }
            var type = field.FieldType.GetGenericArguments() [0];

            if (type != typeof(T))
            {
                throw new ArgumentException("Field type is different from uniform type.");
            }
            if (type.IsArray)
            {
                _mappings = (from elem in type.GetGLArrayElements(field.Name, field.ExpectFixedArrayAttribute().Length)
                             select Tuple.Create(elem, GetUniformLocation(program, elem.Name)))
                            .ToArray();
            }
            else
            {
                CreateUniform(program, field.Name, type);
            }
        }
コード例 #5
0
 public Uniform(GLProgram program, string name)
 {
     CreateUniform(program, name, typeof(T));
 }