示例#1
0
        /// <summary>
        /// Creates a VertexArrayObject from a mesh expecting the MeshAttribute names as shader variable names for the attributes
        /// </summary>
        /// <param name="mesh">From which to load positions, indices, normals, texture coordinates</param>
        /// <param name="shaderProgram">Used for the attribute location bindings</param>
        /// <returns>A vertex array object</returns>
        public static VAO FromMesh(Mesh mesh, IShaderProgram shaderProgram)
        {
            var vao = new VAO(PrimitiveType.Triangles);

            foreach (var attributeName in mesh.AttributeNames)
            {
                var loc       = shaderProgram.GetResourceLocation(ShaderResourceType.Attribute, attributeName);
                var attribute = mesh.GetAttribute(attributeName);
                var array     = attribute.ToArray();             // copy
                vao.SetAttribute(loc, array, attribute.BaseType, attribute.BaseTypeCount);
            }
            vao.SetIndex(mesh.IDs.ToArray());
            return(vao);
        }
示例#2
0
        /// <summary>
        /// Creates a VertexArrayObject from a mesh expecting the MeshAttribute names as shader variable names for the attributes
        /// </summary>
        /// <param name="mesh">From which to load positions, indices, normals, texture coordinates</param>
        /// <param name="shaderProgram">Used for the attribute location bindings</param>
        /// <returns>A vertex array object</returns>
        public static VAO FromMesh(DefaultMesh mesh, IShaderProgram shaderProgram)
        {
            var vao = new VAO(PrimitiveType.Triangles);

            if (mesh.Position.Count > 0)
            {
                var loc = shaderProgram.GetResourceLocation(ShaderResourceType.Attribute, DefaultMesh.PositionName);
                vao.SetAttribute(loc, mesh.Position.ToArray(), VertexAttribPointerType.Float, 3);
            }
            if (mesh.Normal.Count > 0)
            {
                var loc = shaderProgram.GetResourceLocation(ShaderResourceType.Attribute, DefaultMesh.NormalName);
                vao.SetAttribute(loc, mesh.Normal.ToArray(), VertexAttribPointerType.Float, 3);
            }
            if (mesh.TexCoord.Count > 0)
            {
                var loc = shaderProgram.GetResourceLocation(ShaderResourceType.Attribute, DefaultMesh.TexCoordName);
                vao.SetAttribute(loc, mesh.TexCoord.ToArray(), VertexAttribPointerType.Float, 2);
            }
            vao.SetIndex(mesh.IDs.ToArray());
            return(vao);
        }
示例#3
0
        /// <summary>
        /// Creates the indexed draw call gl.
        /// </summary>
        /// <param name="primitiveType">Type of the primitive.</param>
        /// <param name="drawElementsType">Type of the draw elements.</param>
        /// <param name="idCount">The identifier count.</param>
        /// <param name="instanceCount">The instance count.</param>
        /// <param name="vao">The vao.</param>
        /// <returns></returns>
        public static Action CreateIndexedDrawCallGL(PrimitiveType primitiveType, DrawElementsType drawElementsType, int idCount, int instanceCount, VAO vao)
        {
            if (vao is null)
            {
                void Draw()
                {
                    GL.DrawElementsInstanced(primitiveType, idCount, drawElementsType, (IntPtr)0, instanceCount);
                }

                return(Draw);
            }
            else
            {
                void Draw()
                {
                    vao.Activate();
                    GL.DrawElementsInstanced(primitiveType, idCount, drawElementsType, (IntPtr)0, instanceCount);
                    vao.Deactivate();
                }

                return(Draw);
            }
        }
示例#4
0
        /// <summary>
        /// Creates the draw call gl.
        /// </summary>
        /// <param name="primitiveType">Type of the primitive.</param>
        /// <param name="elementCount">The element count.</param>
        /// <param name="instanceCount">The instance count.</param>
        /// <param name="vao">The vao.</param>
        /// <returns></returns>
        public static Action CreateDrawCallGL(PrimitiveType primitiveType, int elementCount, int instanceCount, VAO vao)
        {
            if (vao is null)
            {
                void Draw()
                {
                    GL.DrawArraysInstanced(primitiveType, 0, elementCount, instanceCount);
                }

                return(Draw);
            }
            else
            {
                void Draw()
                {
                    vao.Activate();
                    GL.DrawArraysInstanced(primitiveType, 0, elementCount, instanceCount);
                    vao.Deactivate();
                }

                return(Draw);
            }
        }