3DWorld/Mesh/VBA.pm untested

filter: Statementstmt 0.0% 0 / 46 Branchbran 0.0% 0 / 18 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 79 CC 10 SCAR 37.9
CC
10
Cov
0%
display
90.0
new
6.0
vertex
2.0
CRAP 44.1
1 package SDL::Tutorial::3DWorld::Mesh::VBA;
2  
3 # A compiled/optimised ::Mesh using Vertex Buffer Arrays, which are
4 # optimised in terms calls to GL but hold the data client side.
5  
6 use 5.008;
7 use strict;
8 use warnings;
9 use OpenGL ();
10 use SDL::Tutorial::3DWorld::OpenGL ();
11  
12 our $VERSION = '0.33';
13  
14  
15  
16  
17  
18 ######################################################################
19 # Constructor
20  
21 sub new {
22 my $class = shift;
23 my $self = bless { @_ }, $class;
24  
25 # We require at the very least a vertex array
26 unless ( defined $self->{vertex} ) {
27 die "Did not provide a vertex buffer array";
28 }
29  
30 return $self;
31 }
32  
33 sub vertex {
34 $_[0]->{vertex};
35 }
36  
37 sub normal {
38 $_[0]->{normal};
39 }
40  
41  
42  
43  
44  
45 ######################################################################
46 # Engine Methods
47  
48 sub init {
49 return 1;
50 }
51  
52 sub display {
53 my $self = shift;
54  
55 # Assume all the client list pointers are disable by default
56 # and enable just the ones we need.
57 if ( $self->{vertex} ) {
58 OpenGL::glEnableClientState( OpenGL::GL_VERTEX_ARRAY );
59 }
60 if ( $self->{normal} ) {
61 OpenGL::glEnableClientState( OpenGL::GL_NORMAL_ARRAY );
62 }
63 if ( $self->{color} ) {
64 OpenGL::glEnableClientState( OpenGL::GL_COLOR_ARRAY );
65 }
66 if ( $self->{texture_coord} ) {
67 OpenGL::glEnableClientState( OpenGL::GL_TEXTURE_COORD_ARRAY );
68 }
69  
70 # Draw by index
71 my $draw_arrays = $self->{draw_arrays};
72 foreach ( @$draw_arrays ) {
73 OpenGL::glDrawArrays( $_->[0], $_->[1] );
74 }
75  
76 # Disable the client state params we use
77 if ( $self->{vertex} ) {
78 OpenGL::glDisableClientState( OpenGL::GL_VERTEX_ARRAY );
79 }
80 if ( $self->{normal} ) {
81 OpenGL::glDisableClientState( OpenGL::GL_NORMAL_ARRAY );
82 }
83 if ( $self->{color} ) {
84 OpenGL::glDisableClientState( OpenGL::GL_COLOR_ARRAY );
85 }
86 if ( $self->{texture_coord} ) {
87 OpenGL::glDisableClientState( OpenGL::GL_TEXTURE_COORD_ARRAY );
88 }
89  
90 return 1;
91 }
92  
93 1;