Beispiel #1
0
        public VertexArray(VertexLocations vertexLocations, ShaderBlobType type, RawVertexData vertexInformation)
        {
            if (vertexLocations == null)
            {
                throw new ArgumentNullException(nameof(vertexLocations));
            }

            // Allocate buffers referenced by this vertex array
            _BufferPosition = new GlBuffer <float>(vertexInformation.positions, BufferTarget.ArrayBuffer);

            // Generate VAO name
            ArrayName = Gl.GenVertexArray();
            // First bind create the VAO
            Gl.BindVertexArray(ArrayName);

            // Select the buffer object
            Gl.BindBuffer(BufferTarget.ArrayBuffer, _BufferPosition.BufferName);
            // Format the vertex information: 2 floats from the current buffer
            Gl.VertexAttribPointer((uint)vertexLocations.Location_Position, floats_per_position, VertexAttribType.Float, false, stride, startingLocation);
            // Enable attribute
            Gl.EnableVertexAttribArray((uint)vertexLocations.Location_Position);

            if (type.UseIndexing)
            {
                _BufferIndex = new GlBuffer <uint>(vertexInformation.indexes, BufferTarget.ElementArrayBuffer);
                Gl.BindBuffer(BufferTarget.ElementArrayBuffer, _BufferIndex.BufferName);

                Count = vertexInformation.indexes.Length;
            }
            else
            {
                Count = (vertexInformation.positions.Length / floats_per_position);
            }

            if (type.VertexFormat == VertexFormat.WithColor || type.VertexFormat == VertexFormat.WithColorAndTexture)
            {
                _BufferColor = new GlBuffer <float>(vertexInformation.colors, BufferTarget.ArrayBuffer);

                Gl.BindBuffer(BufferTarget.ArrayBuffer, _BufferColor.BufferName);
                // Format the vertex information: 3 floats from the current buffer
                Gl.VertexAttribPointer((uint)vertexLocations.Location_Color, floats_per_color, VertexAttribType.Float, false, stride, startingLocation);
                // Enable attribute
                Gl.EnableVertexAttribArray((uint)vertexLocations.Location_Color);
            }

            if (type.VertexFormat == VertexFormat.WithTexture || type.VertexFormat == VertexFormat.WithColorAndTexture)
            {
                _BufferTex = new GlBuffer <float>(vertexInformation.textures, BufferTarget.ArrayBuffer);

                Gl.BindBuffer(BufferTarget.ArrayBuffer, _BufferTex.BufferName);
                // Format the vertex information: 2 floats from the current buffer
                Gl.VertexAttribPointer((uint)vertexLocations.Location_Texture, floats_per_textureCoordinate, VertexAttribType.Float, false, stride, startingLocation);
                // Enable attribute
                Gl.EnableVertexAttribArray((uint)vertexLocations.Location_Texture);
            }
        }
Beispiel #2
0
 private IVertexArray BuildVertexArray(VertexLocations vertexLocations, ShaderCreationArguments args)
 {
     if (!args.Type.UseIndexing)
     {
         return(new VertexArray(vertexLocations, args.Type, RawVertexData.NonIndexed));
     }
     else
     {
         return(new VertexArray(vertexLocations, args.Type, RawVertexData.Indexed));
     }
 }