예제 #1
0
        /// <summary>
        /// Writes attribute data from specified vertex into a float buffer. This method can be called only
        /// if the type of attribute is float-based.
        /// </summary>
        /// <param name="vertex">Vertex to load the data from.</param>
        /// <param name="buffer">Buffer to write data to.</param>
        /// <param name="where">Where in buffer to write the data.</param>
        public void WriteToFloatBuffer(Vertex vertex, float[] buffer, int where)
        {
            if (Type.BaseType != GLBaseType.Float)
            {
                throw new Exception("This attribute is not float based!");
            }

            GLVariable vertexVar = vertex.Attributes[Id];

            switch (Type.ComponentCount)
            {
            case GLComponentCount.One:
            {
                Float variable = (Float)vertexVar;
                buffer[where] = variable.Value;
            } break;

            case GLComponentCount.Two:
            {
                Vec2f variable = (Vec2f)vertexVar;
                buffer[where]     = variable.X;
                buffer[where + 1] = variable.Y;
            } break;

            case GLComponentCount.Three:
            {
                Vec3f variable = (Vec3f)vertexVar;
                buffer[where]     = variable.X;
                buffer[where + 1] = variable.Y;
                buffer[where + 2] = variable.Z;
            } break;

            case GLComponentCount.Four:
            {
                Vec4f variable = (Vec4f)vertexVar;
                buffer[where]     = variable.X;
                buffer[where + 1] = variable.Y;
                buffer[where + 2] = variable.Z;
                buffer[where + 3] = variable.W;
            } break;

            default:
                throw new Exception("This code should be unreachable!");
            }
        }
예제 #2
0
        /// <summary>
        /// Makes Uniform from a specified GLSL type.
        /// </summary>
        /// <param name="type">GLSL type of the uniform. It should be one of the supported ones.</param>
        /// <param name="name">Name of the new uniform.</param>
        /// <returns>The newly created uniform.</returns>
        public static Uniform Make(GLType type, string name)
        {
            GLVariable variable = VariableMaker.Make(type);

            return(new Uniform(name, variable));
        }
예제 #3
0
 public Uniform(string name, GLVariable variable)
 {
     Name     = name;
     Variable = variable;
 }