-
Notifications
You must be signed in to change notification settings - Fork 0
/
oga.pl
187 lines (143 loc) · 3.23 KB
/
oga.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#!/usr/bin/perl -w
use strict;
# Sample/Test app for OpenGL::Array functions
# by Bob "grafman" Free <[email protected]>
# http://graphcomp.com/opengl
use OpenGL qw/ :all /;
#use OpenGL::Image;
#use OpenGL::Shader;
use Time::HiRes qw( gettimeofday );
use constant PROGRAM_TITLE => "OpenGL::ARRAY Test App";
# Window vars
my $Window_ID;
# Vertex Buffer Object data
my($VertexObjID);
my @verts =
(
-1.0, -1.3, -1.0,
1.0, -1.3, -1.0,
1.0, -1.3, 1.0,
-1.0, -1.3, 1.0,
-1.0, 1.3, -1.0,
-1.0, 1.3, 1.0,
1.0, 1.3, 1.0,
1.0, 1.3, -1.0,
-1.0, -1.0, -1.3,
-1.0, 1.0, -1.3,
1.0, 1.0, -1.3,
1.0, -1.0, -1.3,
1.3, -1.0, -1.0,
1.3, 1.0, -1.0,
1.3, 1.0, 1.0,
1.3, -1.0, 1.0,
-1.0, -1.0, 1.3,
1.0, -1.0, 1.3,
1.0, 1.0, 1.3,
-1.0, 1.0, 1.3,
-1.3, -1.0, -1.0,
-1.3, -1.0, 1.0,
-1.3, 1.0, 1.0,
-1.3, 1.0, -1.0
);
@verts =
(
0.0, 0.1, 0.2,
1.0, 1.1, 1.2,
2.0, 2.1, 2.2,
3.0, 3.1, 3.2,
10.0, 10.1, 10.2,
11.0, 11.1, 11.2,
12.0, 12.1, 12.2,
13.0, 13.1, 13.2,
20.0, 20.1, 20.2,
21.0, 21.1, 21.2,
22.0, 22.1, 22.2,
13.0, 23.1, 23.2,
30.0, 30.1, 30.2,
31.0, 31.1, 31.2,
32.0, 32.1, 32.2,
33.0, 33.1, 33.2,
40.0, 40.1, 40.2,
41.0, 41.1, 41.2,
42.0, 42.1, 42.2,
43.0, 43.1, 43.2,
50.0, 50.1, 50.2,
51.0, 51.1, 51.2,
52.0, 52.1, 52.2,
53.0, 53.1, 53.2
);
my @xform =
(
1.0, 0.0, 0.0, 1.0,
0.0, 3.0, 0.0, 0.0,
0.0, 0.0, 2.0, 1.0,
0.0, 0.0, 0.0, 1.0
);
my $xform = OpenGL::Array->new_list(GL_FLOAT,@xform);
# ------
# The main() function. Inits OpenGL. Calls our own init function,
# then passes control onto OpenGL.
glutInit();
# To see OpenGL drawing, take out the GLUT_DOUBLE request.
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH | GLUT_ALPHA);
glutInitWindowSize(1,1);
# Open a window
$Window_ID = glutCreateWindow( PROGRAM_TITLE );
glutHideWindow();
# Test for GPGPU support
print "Has GPGPU Support: ".OpenGL::glpHasGPGPU()."\n";
# Tests
my $loops = 2;
my $vertices = 4;
my $print_verts = $vertices < 5;
my($i,$start,$secs);
print "Initial data:\n";
print "Loops: $loops, Vertices: $vertices\n";
my $verts = init_verts($vertices);
print_verts($verts,$vertices) if ($print_verts);
$start = gettimeofday();
for ($i=0;$i<$loops;$i++)
{
$verts->calc('1,+','3,*','2,*,1,+');
}
$secs = (gettimeofday()-$start)/$loops;
my $vps_calc = int($vertices/$secs);
print "Calc VPS: $vps_calc\n";
print_verts($verts,$vertices) if ($print_verts);
$verts = init_verts($vertices);
$start = gettimeofday();
for ($i=0;$i<$loops;$i++)
{
$verts->affine($xform);
}
$secs = (gettimeofday()-$start)/$loops;
my $vps_gpu = int($vertices/$secs);
print "Affine VPS: $vps_gpu\n";
print_verts($verts,$vertices) if ($print_verts);
# Destroy window
glutDestroyWindow($Window_ID);
exit 0;
sub init_verts
{
my($count) = @_;
my @verts = ();
for (my $i=0;$i<$count;$i++)
{
push(@verts,"$i.0","$i.1","$i.2");
}
my $verts = OpenGL::Array->new_list(GL_FLOAT,@verts);
die "new_list failed to return an OGA\n" if (!$verts);
return $verts;
}
sub print_verts
{
my($verts,$vertices) = @_;
my $len = $vertices * 3;
for(my $i=0;$i<$len;$i+=3)
{
my($x,$y,$z) = $verts->retrieve($i,3);
printf("%8.3f,%8.3f,%8.3f\n",$x,$y,$z);
}
print "\n";
}
__END__