OpenGL-Sandbox

 view release on metacpan or  search on metacpan

lib/OpenGL/Sandbox/VertexArray.pm  view on Meta::CPAN

Human-readable name of this Vertex Array (not GL's integer "name")

=head2 attributes

This is a hashref of the metadata for each attribute.  You can specify it without knowing the
index of an array, and that will be filled in later when it is applied to a program.

Each attribute is a hashref of:

  {
    name       => $text,   # should match the named attribute of the Program
    index      => $n,      # vertex attribute index; use undef to lookup by name
    buffer     => $buffer, # buffer this attribute comes from. Leave undef to use current buffer.
                           # This can also be a buffer ID integer.
    size       => $n,      # number of components per vertex attribute
    type       => $type,   # GL_FLOAT, GL_INT, etc.
    normalized => $bool,   # perl boolean, whether to remap ints to float [0..1)
    stride     => $ofs,    # number of bytes between stored attributes, or 0 for "tightly packed"
    pointer    => $ofs,    # byte offset into $buffer of first element, defaults to 0
  }

=head2 buffer

You can specify a buffer on each attribute, or specify it in the call to C<bind>, or you can
supply a default buffer here that will be used for all the attributes.  If given a hashref,
it will be inflated to a buffer object.  If you give an integer, it will be used directly.

This is most useful for the following:

  my $vao= $res->new_vao({
    buffer => { data => pack('f*', @coordinates) },
    attributes => {
      position => { size => 3, type => GL_FLOAT, stride => 32 },
      normal   => { size => 3, type => GL_FLOAT, stride => 32 },
      texcoord => { size => 2, type => GL_FLOAT, stride => 32 },
    }
  });

=head2 id

For OpenGL 3.0+, this will be allocated upon demand.  For earlier OpenGL, this remains undef.

=over

=item has_id

Whether the ID (or lack of one) has been resolved yet.

=back

=head2 prepared

Whether the L</prepare> step has happened.

=head1 METHODS

=head2 bind

  $vertex_array->bind($program, $buffer);

Make the configuration of this vertex array active for drawing.  This might cause a cascade of
effects, like binding buffers, loading buffers, binding the vertex array object, looking up
program attributes, and enabling and configuring the attributes.  Steps which don't need
repeated won't be.

If C<$program> is not given, the current one will be used for any attribute-index lookups.
If C<$buffer> is not given, the current GL_VERTEX_ARRAY buffer will be used (unless an
attribute configuration specifies otherwise).

=head2 prepare

For OpenGL 3+ this creates a Vertex Array Object (VAO) and initializes it.  For earlier OpenGL,
this is a no-op.

=head1 AUTHOR

Michael Conrad <mike@nrdvana.net>

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2019 by Michael Conrad.

This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.

=cut



( run in 1.820 second using v1.01-cache-2.11-cpan-39bf76dae61 )