Utilities | Arrays | Imaging | Shaders | POGL | GLUT | OpenGL | GLU |

OpenGL::Array (OGA) objects provide Perl Array handling and conversion between Perl arrays and C array pointers.

Due to the difference between how Perl and C handle pointers, all POGL APIs that require pointers are suffixed with _c. OGAs provide a means to convert Perl arrays into C pointers that can be passed into these APIs.

Many POGL _c APIs also have a _s version to support SDL's packed string APIs; OGA provides APIs to convert between C arrays and packed strings.

POGL also provides many _p APIs that accept native Perl arrays, or in some cases OGAs directly. In the case of VBOs, OGAs may be bound to GPU buffers, automatically switching buffers at render time.

Note: Since OGAs are stored as typed C arrays, there is no conversion/copy/casting when passing them to POGL APIs, resulting in significant performance improvements over other non-compiled bindings (SDL, PyOpenGL, etc).

Google Bookmarks Google
  
Stumble Upon It! Stumbled on It!
  
del.icio.us del.icio.us
  


Creating OpenGL::Array Objects

my $array = OpenGL::Array->new($count,@types);

    Creates an empty array object of $count rows made up data types @types.

my $array = OpenGL::Array->new_list($type,@data);

    Creates and populates a uniform array object made up @data of type $type.

my $array = OpenGL::Array->new_pointer($type,ptr,$elements);

    Creates an array object wrapper around a C pointer ptr of type $type and array length $elements. Caches C pointer directly; does not copy data.



Using OpenGL::Array Object's C pointers

OpenGL::Array objects are Perl references; in order to use them in OpenGL APIs that expect C pointers, you need to use the native pointer:

    my $array = OpenGL::Array->new(4,GL_INT);
    glGetIntegerv_c(GL_VIEWPORT,$array->ptr());
    my @viewport = $array->retrieve(0,4);



OpenGL::Array Accessors

$array->assign($pos,@data);

    Sets array data starting at element position $pos using @data.

$array->assign_data($pos,$data);

    Sets array data element position $pos using packed string $data.

my @data = $array->retrieve($pos,$len);

    Returns an array of $len elements from an array object.

my $data = $array->retrieve_data($pos,$len);

    Returns a packed string of length $len bytes from an array object.

my $count = $array->elements();

    Returns the element count from an array object.

ptr = $array->ptr();

    Returns a C pointer to an array object.

ptr = $array->offset($pos);

    Returns a C pointer to the $pos element of an array object.



Binding to VBOs

Helps abstract Vertex Array and VBO rendering.

  • Requires GL_ARB_vertex_buffer_object extension and POGL 0.55_01 or newer

    $array->bind($id);

      Binds a GPU buffer to an array object.

      If bound, glXxxPointer_p APIs will call glBindBufferARB.

    my $id = $array->bound();

      Return bound buffer ID, or 0 if not bound.



    Affine: Perfoms Affine Transforms on OpenGL::Array Objects

    Eventually, this API will abstract CPU vs GPU-based affine transforms for the best performance.

    $array->affine($xform);

      $xform is an NxN OpenGL::Array object used to transform $array.

      N must be one element wider than the width of the array.



    Calc: Populating and Manipulating OpenGL::Array Objects

    Used to populate or mathematically modify an POGL array. Uses Reverse Polish Notation (RPN) for mathematical operations.

    $array->calc($value);

      Populates the array with $value.

    $array->calc(@values);

      Populates each row of the array with @values, assuming rows have the same width as the length of @values.

    $array->calc(1.0, '3,*', '2,*,rand,+', '');

      Resets the first column of each row to 1.0; multiplies the values in the second column by 3; multiplies the third column by 2, then adds a random number between 0 and 1; leaves the fourth column alone.

    calc maintains a push/pop stack and a "register" for each column.

    calc currently suports the following primitives:

      ! - Logical "Not" for End of Stack (S0) for the current column; becomes 1.0 if empty or 0. otherwise 1.0

      - - Arithmetic Negation of S0

      + - Add S0 and Next on Stack (S1), pop operands and push result (Result)

      * - Multiply S0 and S1; Result

      / - Divide S1 by S0; Result

      % - S1 Modulus S0; Result

      = - Test S0 equality to S1; pop operands and push non-zero (1.0) for true, otherwise 0.0 (Boolean)

      > - Test if S0 Greater than S1; Boolean

      < - Test if S0 Lesser than S1; Boolean

      ? - If S0 is true (non-zero), pop S0 and S1; otherwise pop s0-3, push s1

      pop - Pop s0

      rand - Push a random number from 0.0 to 1.0

      dup - Push a copy of S0

      swap - Swap values of S0 and S1

      set - Pop S0 and store it's value in the column's Register

      get - Push the column's Register onto the column's Stack

      store - Pop S0, and copy the values of row S0 of the array into their respective column Registers

      load - Pop S0, and copy the values in the current registers into row S0 of the array

      end - End processing; column unchanged

      endif - Pop S0, End if true; column unchanged

      endrow - End processing of current row; column unchanged

      endrowif - Pop S0, End processing of current row if true; column unchanged

      return - End processing; column value set to s0

      returnif - Pop S0, End if true; column value set to s0

      returnrow - End processing of current row; column value set to s0

      returnrowif - Pop S0, End processing of current row if true; column value set to s0

      if - alias to ?

      or - alias to +

      and - alias to *

      inc - Add 1 to S0

      dec - Subtract 1 from S0

      sum - Add and pop everything in stack; push result

      avg - Average and pop everything in stack; push result

      abs - Replace S0 with its absolute value

      power - Raise S1 to the power of S0; Result

      min - The lower of S0 and S1; Result

      max - The higher of S0 and S1; Result

      sin - Sine of S0 in Radians; Result

      cos - Cosine of S0; Result

      tan - Tangent of S0; Result

      atan2 - ArcTangent of S1 over s0; Result

      count - Push the number of elements in the array

      index - Push the current element index (zero-based)

      columns - Push the number of columns in the array

      column - Push the current column index

      rows - Push the number of rows in the array

      row - Push the current row index

      pi - Push the the value of PI