ruby-opengl 0.60.0-i386-mswin32
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +18 -0
- data/README.txt +47 -0
- data/doc/build_install.txt +122 -0
- data/doc/history.txt +66 -0
- data/doc/requirements_and_design.txt +117 -0
- data/doc/roadmap.txt +28 -0
- data/doc/scientific_use.txt +35 -0
- data/doc/thanks.txt +29 -0
- data/doc/tutorial.txt +469 -0
- data/examples/NeHe/nehe_lesson02.rb +117 -0
- data/examples/NeHe/nehe_lesson03.rb +122 -0
- data/examples/NeHe/nehe_lesson04.rb +133 -0
- data/examples/NeHe/nehe_lesson05.rb +186 -0
- data/examples/NeHe/nehe_lesson36.rb +303 -0
- data/examples/OrangeBook/3Dlabs-License.txt +33 -0
- data/examples/OrangeBook/brick.frag +36 -0
- data/examples/OrangeBook/brick.rb +376 -0
- data/examples/OrangeBook/brick.vert +41 -0
- data/examples/OrangeBook/particle.frag +17 -0
- data/examples/OrangeBook/particle.rb +406 -0
- data/examples/OrangeBook/particle.vert +38 -0
- data/examples/README +16 -0
- data/examples/RedBook/aapoly.rb +142 -0
- data/examples/RedBook/aargb.rb +119 -0
- data/examples/RedBook/accanti.rb +162 -0
- data/examples/RedBook/accpersp.rb +215 -0
- data/examples/RedBook/alpha.rb +123 -0
- data/examples/RedBook/alpha3D.rb +158 -0
- data/examples/RedBook/bezcurve.rb +105 -0
- data/examples/RedBook/bezmesh.rb +137 -0
- data/examples/RedBook/checker.rb +124 -0
- data/examples/RedBook/clip.rb +95 -0
- data/examples/RedBook/colormat.rb +135 -0
- data/examples/RedBook/cube.rb +69 -0
- data/examples/RedBook/depthcue.rb +99 -0
- data/examples/RedBook/dof.rb +205 -0
- data/examples/RedBook/double.rb +105 -0
- data/examples/RedBook/drawf.rb +91 -0
- data/examples/RedBook/feedback.rb +145 -0
- data/examples/RedBook/fog.rb +167 -0
- data/examples/RedBook/font.rb +151 -0
- data/examples/RedBook/hello.rb +79 -0
- data/examples/RedBook/image.rb +137 -0
- data/examples/RedBook/jitter.rb +207 -0
- data/examples/RedBook/lines.rb +128 -0
- data/examples/RedBook/list.rb +111 -0
- data/examples/RedBook/material.rb +275 -0
- data/examples/RedBook/mipmap.rb +156 -0
- data/examples/RedBook/model.rb +113 -0
- data/examples/RedBook/movelight.rb +132 -0
- data/examples/RedBook/pickdepth.rb +179 -0
- data/examples/RedBook/planet.rb +108 -0
- data/examples/RedBook/quadric.rb +158 -0
- data/examples/RedBook/robot.rb +115 -0
- data/examples/RedBook/select.rb +196 -0
- data/examples/RedBook/smooth.rb +95 -0
- data/examples/RedBook/stencil.rb +163 -0
- data/examples/RedBook/stroke.rb +167 -0
- data/examples/RedBook/surface.rb +166 -0
- data/examples/RedBook/teaambient.rb +132 -0
- data/examples/RedBook/teapots.rb +182 -0
- data/examples/RedBook/tess.rb +183 -0
- data/examples/RedBook/texbind.rb +147 -0
- data/examples/RedBook/texgen.rb +169 -0
- data/examples/RedBook/texturesurf.rb +128 -0
- data/examples/RedBook/varray.rb +159 -0
- data/examples/RedBook/wrap.rb +148 -0
- data/examples/misc/OGLBench.rb +337 -0
- data/examples/misc/anisotropic.rb +194 -0
- data/examples/misc/fbo_test.rb +356 -0
- data/examples/misc/font-glut.rb +46 -0
- data/examples/misc/glfwtest.rb +30 -0
- data/examples/misc/plane.rb +161 -0
- data/examples/misc/readpixel.rb +65 -0
- data/examples/misc/sdltest.rb +34 -0
- data/examples/misc/trislam.rb +828 -0
- data/lib/gl.so +0 -0
- data/lib/glu.so +0 -0
- data/lib/glut.so +0 -0
- data/lib/opengl.rb +84 -0
- metadata +132 -0
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'opengl'
|
2
|
+
include Gl,Glu,Glut
|
3
|
+
|
4
|
+
display = Proc.new do
|
5
|
+
glClear(GL_COLOR_BUFFER_BIT)
|
6
|
+
GL.LoadIdentity
|
7
|
+
|
8
|
+
glRasterPos2d(100,100)
|
9
|
+
"Hello Bitmap".each_byte { |x| glutBitmapCharacter(GLUT_BITMAP_9_BY_15, x) }
|
10
|
+
|
11
|
+
GL.Translate(100, 250, 0)
|
12
|
+
GL.Scale(0.5, 0.5, 1)
|
13
|
+
"Hello Stroke".each_byte { |x| glutStrokeCharacter(GLUT_STROKE_ROMAN, x) }
|
14
|
+
|
15
|
+
glutSwapBuffers()
|
16
|
+
end
|
17
|
+
|
18
|
+
reshape = Proc.new do |w, h|
|
19
|
+
glViewport(0, 0, w, h)
|
20
|
+
glMatrixMode(GL_PROJECTION)
|
21
|
+
glLoadIdentity()
|
22
|
+
glOrtho(0.0, w, 0.0, h, -1.0, 1.0)
|
23
|
+
glMatrixMode(GL_MODELVIEW)
|
24
|
+
end
|
25
|
+
|
26
|
+
keyboard = Proc.new do |key, x, y|
|
27
|
+
case (key)
|
28
|
+
when ?\e
|
29
|
+
exit(0)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# Main Loop
|
34
|
+
# Open window with initial window size, title bar,
|
35
|
+
# color index display mode, and handle input events.
|
36
|
+
#
|
37
|
+
glutInit
|
38
|
+
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB)
|
39
|
+
glutInitWindowSize(500, 500)
|
40
|
+
glutInitWindowPosition(100, 100)
|
41
|
+
glutCreateWindow($0)
|
42
|
+
|
43
|
+
glutReshapeFunc(reshape)
|
44
|
+
glutDisplayFunc(display)
|
45
|
+
glutKeyboardFunc(keyboard)
|
46
|
+
glutMainLoop
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'opengl'
|
2
|
+
require 'glfw'
|
3
|
+
|
4
|
+
#init
|
5
|
+
Glfw.glfwOpenWindow( 500,500, 0,0,0,0, 32,0, Glfw::GLFW_WINDOW )
|
6
|
+
|
7
|
+
# main loop
|
8
|
+
while true
|
9
|
+
if( Glfw.glfwGetWindowParam( Glfw::GLFW_OPENED ) == false ||
|
10
|
+
Glfw.glfwGetKey(Glfw::GLFW_KEY_ESC) == Glfw::GLFW_PRESS )
|
11
|
+
break
|
12
|
+
end
|
13
|
+
|
14
|
+
Gl.glClear( Gl::GL_COLOR_BUFFER_BIT | Gl::GL_DEPTH_BUFFER_BIT )
|
15
|
+
|
16
|
+
Gl.glBegin( Gl::GL_POLYGON )
|
17
|
+
Gl.glColor3f( 1.0, 0.0, 0.0 )
|
18
|
+
Gl.glVertex2f( -0.5, -0.5 )
|
19
|
+
Gl.glColor3f( 0.0, 1.0, 0.0 )
|
20
|
+
Gl.glVertex2f( -0.5, 0.5 )
|
21
|
+
Gl.glColor3f( 0.0, 0.0, 1.0 )
|
22
|
+
Gl.glVertex2f( 0.5, 0.5 )
|
23
|
+
Gl.glColor3f( 1.0, 0.0, 1.0 )
|
24
|
+
Gl.glVertex2f( 0.5, -0.5 )
|
25
|
+
Gl.glEnd
|
26
|
+
|
27
|
+
Glfw.glfwSwapBuffers()
|
28
|
+
|
29
|
+
sleep 0.01 # to avoid consuming all CPU power
|
30
|
+
end
|
@@ -0,0 +1,161 @@
|
|
1
|
+
#!/usr/bin/env ruby -rubygems
|
2
|
+
#/* Copyright (c) Mark J. Kilgard, 1994. */
|
3
|
+
#
|
4
|
+
#/*
|
5
|
+
# * (c) Copyright 1993, Silicon Graphics, Inc.
|
6
|
+
# * ALL RIGHTS RESERVED
|
7
|
+
# * Permission to use, copy, modify, and distribute this software for
|
8
|
+
# * any purpose and without fee is hereby granted, provided that the above
|
9
|
+
# * copyright notice appear in all copies and that both the copyright notice
|
10
|
+
# * and this permission notice appear in supporting documentation, and that
|
11
|
+
# * the name of Silicon Graphics, Inc. not be used in advertising
|
12
|
+
# * or publicity pertaining to distribution of the software without specific,
|
13
|
+
# * written prior permission.
|
14
|
+
# *
|
15
|
+
# * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
|
16
|
+
# * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
|
17
|
+
# * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
|
18
|
+
# * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
|
19
|
+
# * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
|
20
|
+
# * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
|
21
|
+
# * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
|
22
|
+
# * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
|
23
|
+
# * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN
|
24
|
+
# * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
|
25
|
+
# * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
|
26
|
+
# * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
|
27
|
+
# *
|
28
|
+
# * US Government Users Restricted Rights
|
29
|
+
# * Use, duplication, or disclosure by the Government is subject to
|
30
|
+
# * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
|
31
|
+
# * (c)(1)(ii) of the Rights in Technical Data and Computer Software
|
32
|
+
# * clause at DFARS 252.227-7013 and/or in similar or successor
|
33
|
+
# * clauses in the FAR or the DOD or NASA FAR Supplement.
|
34
|
+
# * Unpublished-- rights reserved under the copyright laws of the
|
35
|
+
# * United States. Contractor/manufacturer is Silicon Graphics,
|
36
|
+
# * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
|
37
|
+
# *
|
38
|
+
# * OpenGL(TM) is a trademark of Silicon Graphics, Inc.
|
39
|
+
# */
|
40
|
+
#/*
|
41
|
+
# * plane.c
|
42
|
+
# * This program demonstrates the use of local versus
|
43
|
+
# * infinite lighting on a flat plane.
|
44
|
+
# */
|
45
|
+
|
46
|
+
require "gl"
|
47
|
+
require "glut"
|
48
|
+
require "mathn"
|
49
|
+
|
50
|
+
# /* Initialize material property, light source, and lighting model.
|
51
|
+
# */
|
52
|
+
def myinit
|
53
|
+
mat_ambient = [ 0.0, 0.0, 0.0, 1.0 ];
|
54
|
+
#/* mat_specular and mat_shininess are NOT default values */
|
55
|
+
mat_diffuse = [ 0.4, 0.4, 0.4, 1.0 ];
|
56
|
+
mat_specular = [ 1.0, 1.0, 1.0, 1.0 ];
|
57
|
+
mat_shininess = [ 15.0 ];
|
58
|
+
|
59
|
+
light_ambient = [ 0.0, 0.0, 0.0, 1.0 ];
|
60
|
+
light_diffuse = [ 1.0, 1.0, 1.0, 1.0 ];
|
61
|
+
light_specular = [ 1.0, 1.0, 1.0, 1.0 ];
|
62
|
+
lmodel_ambient = [ 0.2, 0.2, 0.2, 1.0 ];
|
63
|
+
|
64
|
+
Gl.glMaterial(Gl::GL_FRONT, Gl::GL_AMBIENT, mat_ambient);
|
65
|
+
Gl.glMaterial(Gl::GL_FRONT, Gl::GL_DIFFUSE, mat_diffuse);
|
66
|
+
Gl.glMaterial(Gl::GL_FRONT, Gl::GL_SPECULAR, mat_specular);
|
67
|
+
Gl.glMaterial(Gl::GL_FRONT, Gl::GL_SHININESS, *mat_shininess);
|
68
|
+
Gl.glLight(Gl::GL_LIGHT0, Gl::GL_AMBIENT, light_ambient);
|
69
|
+
Gl.glLight(Gl::GL_LIGHT0, Gl::GL_DIFFUSE, light_diffuse);
|
70
|
+
Gl.glLight(Gl::GL_LIGHT0, Gl::GL_SPECULAR, light_specular);
|
71
|
+
Gl.glLightModel(Gl::GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
|
72
|
+
|
73
|
+
Gl.glEnable(Gl::GL_LIGHTING);
|
74
|
+
Gl.glEnable(Gl::GL_LIGHT0);
|
75
|
+
Gl.glDepthFunc(Gl::GL_LESS);
|
76
|
+
Gl.glEnable(Gl::GL_DEPTH_TEST);
|
77
|
+
end
|
78
|
+
|
79
|
+
def drawPlane
|
80
|
+
Gl.glBegin(Gl::GL_QUADS);
|
81
|
+
Gl.glNormal(0.0, 0.0, 1.0);
|
82
|
+
Gl.glVertex(-1.0, -1.0, 0.0);
|
83
|
+
Gl.glVertex(0.0, -1.0, 0.0);
|
84
|
+
Gl.glVertex(0.0, 0.0, 0.0);
|
85
|
+
Gl.glVertex(-1.0, 0.0, 0.0);
|
86
|
+
|
87
|
+
Gl.glNormal(0.0, 0.0, 1.0);
|
88
|
+
Gl.glVertex(0.0, -1.0, 0.0);
|
89
|
+
Gl.glVertex(1.0, -1.0, 0.0);
|
90
|
+
Gl.glVertex(1.0, 0.0, 0.0);
|
91
|
+
Gl.glVertex(0.0, 0.0, 0.0);
|
92
|
+
|
93
|
+
Gl.glNormal(0.0, 0.0, 1.0);
|
94
|
+
Gl.glVertex(0.0, 0.0, 0.0);
|
95
|
+
Gl.glVertex(1.0, 0.0, 0.0);
|
96
|
+
Gl.glVertex(1.0, 1.0, 0.0);
|
97
|
+
Gl.glVertex(0.0, 1.0, 0.0);
|
98
|
+
|
99
|
+
Gl.glNormal(0.0, 0.0, 1.0);
|
100
|
+
Gl.glVertex(0.0, 0.0, 0.0);
|
101
|
+
Gl.glVertex(0.0, 1.0, 0.0);
|
102
|
+
Gl.glVertex(-1.0, 1.0, 0.0);
|
103
|
+
Gl.glVertex(-1.0, 0.0, 0.0);
|
104
|
+
Gl.glEnd();
|
105
|
+
end
|
106
|
+
|
107
|
+
display = Proc.new {
|
108
|
+
infinite_light = [ 1.0, 1.0, 1.0, 0.0 ];
|
109
|
+
local_light = [ 1.0, 1.0, 1.0, 1.0 ];
|
110
|
+
|
111
|
+
Gl.glClear(Gl::GL_COLOR_BUFFER_BIT | Gl::GL_DEPTH_BUFFER_BIT);
|
112
|
+
|
113
|
+
Gl.glPushMatrix();
|
114
|
+
Gl.glTranslate(-1.5, 0.0, 0.0);
|
115
|
+
Gl.glLight(Gl::GL_LIGHT0, Gl::GL_POSITION, infinite_light);
|
116
|
+
drawPlane();
|
117
|
+
Gl.glPopMatrix();
|
118
|
+
|
119
|
+
Gl.glPushMatrix();
|
120
|
+
Gl.glTranslate(1.5, 0.0, 0.0);
|
121
|
+
Gl.glLight(Gl::GL_LIGHT0, Gl::GL_POSITION, local_light);
|
122
|
+
drawPlane();
|
123
|
+
Gl.glPopMatrix();
|
124
|
+
Gl.glFlush();
|
125
|
+
}
|
126
|
+
|
127
|
+
myReshape = Proc.new {|w, h|
|
128
|
+
Gl.glViewport(0, 0, w, h);
|
129
|
+
Gl.glMatrixMode(Gl::GL_PROJECTION);
|
130
|
+
Gl.glLoadIdentity();
|
131
|
+
if (w <= h)
|
132
|
+
Gl.glOrtho(-1.5, 1.5, -1.5*h/w, 1.5*h/w, -10.0, 10.0);
|
133
|
+
else
|
134
|
+
Gl.glOrtho(-1.5*w/h, 1.5*w/h, -1.5, 1.5, -10.0, 10.0);
|
135
|
+
end
|
136
|
+
Gl.glMatrixMode(Gl::GL_MODELVIEW);
|
137
|
+
}
|
138
|
+
|
139
|
+
# Keyboard handler to exit when ESC is typed
|
140
|
+
keyboard = lambda do |key, x, y|
|
141
|
+
case(key)
|
142
|
+
when ?\e
|
143
|
+
exit(0)
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
#/* Main Loop
|
148
|
+
# * Open window with initial window size, title bar,
|
149
|
+
# * RGBA display mode, and handle input events.
|
150
|
+
# */
|
151
|
+
#int main(int argc, char** argv)
|
152
|
+
#{
|
153
|
+
Glut.glutInit
|
154
|
+
Glut.glutInitDisplayMode(Glut::GLUT_SINGLE | Glut::GLUT_RGB | Glut::GLUT_DEPTH);
|
155
|
+
Glut.glutInitWindowSize(500, 200);
|
156
|
+
Glut.glutCreateWindow($0);
|
157
|
+
myinit();
|
158
|
+
Glut.glutReshapeFunc(myReshape);
|
159
|
+
Glut.glutDisplayFunc(display);
|
160
|
+
Glut.glutKeyboardFunc(keyboard);
|
161
|
+
Glut.glutMainLoop();
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'opengl'
|
2
|
+
include Gl,Glu,Glut
|
3
|
+
|
4
|
+
begin
|
5
|
+
require "RMagick"
|
6
|
+
rescue Exception
|
7
|
+
print "This sample needs RMagick Module.\n"
|
8
|
+
exit
|
9
|
+
end
|
10
|
+
|
11
|
+
WIDTH = 500
|
12
|
+
HEIGHT = 500
|
13
|
+
|
14
|
+
display = Proc.new do
|
15
|
+
glClear(GL_COLOR_BUFFER_BIT)
|
16
|
+
|
17
|
+
glBegin(GL_LINES)
|
18
|
+
glVertex(0.5, 0.5)
|
19
|
+
glVertex(-0.5, -0.5)
|
20
|
+
glEnd
|
21
|
+
|
22
|
+
glFlush()
|
23
|
+
|
24
|
+
pixels = glReadPixels(0, 0, WIDTH, HEIGHT, GL_RGBA, GL_UNSIGNED_SHORT)
|
25
|
+
|
26
|
+
image = Magick::Image.new(WIDTH, HEIGHT)
|
27
|
+
image.import_pixels(0, 0, WIDTH, HEIGHT, "RGBA", pixels,Magick::ShortPixel)
|
28
|
+
image.flip!
|
29
|
+
image.write("opengl_window.gif")
|
30
|
+
end
|
31
|
+
|
32
|
+
reshape = Proc.new do |w, h|
|
33
|
+
glViewport(0, 0, w, h)
|
34
|
+
glMatrixMode(GL_PROJECTION)
|
35
|
+
glLoadIdentity()
|
36
|
+
if (w <= h)
|
37
|
+
gluOrtho2D(-1.0, 1.0, -h.to_f/w.to_f, h.to_f/w.to_f)
|
38
|
+
else
|
39
|
+
gluOrtho2D(w.to_f/h.to_f, w.to_f/h.to_f, -1.0, 1.0)
|
40
|
+
end
|
41
|
+
glMatrixMode(GL_MODELVIEW)
|
42
|
+
glLoadIdentity()
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
keyboard = Proc.new do |key, x, y|
|
47
|
+
case (key)
|
48
|
+
when ?\e
|
49
|
+
exit(0);
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# Main Loop
|
54
|
+
# Open window with initial window size, title bar,
|
55
|
+
# color index display mode, and handle input events.
|
56
|
+
glutInit
|
57
|
+
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_ALPHA)
|
58
|
+
glutInitWindowSize(WIDTH, HEIGHT)
|
59
|
+
glutInitWindowPosition(100, 100)
|
60
|
+
glutCreateWindow($0)
|
61
|
+
glutReshapeFunc(reshape)
|
62
|
+
glutDisplayFunc(display)
|
63
|
+
glutKeyboardFunc(keyboard)
|
64
|
+
glutMainLoop
|
65
|
+
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'opengl'
|
2
|
+
require 'sdl'
|
3
|
+
|
4
|
+
#init
|
5
|
+
SDL.init(SDL::INIT_VIDEO)
|
6
|
+
SDL.setGLAttr(SDL::GL_DOUBLEBUFFER,1)
|
7
|
+
SDL.setVideoMode(512,512,32,SDL::OPENGL)
|
8
|
+
|
9
|
+
# main loop
|
10
|
+
while true
|
11
|
+
while event = SDL::Event2.poll
|
12
|
+
case event
|
13
|
+
when SDL::Event2::KeyDown, SDL::Event2::Quit
|
14
|
+
exit
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
Gl.glClear( Gl::GL_COLOR_BUFFER_BIT | Gl::GL_DEPTH_BUFFER_BIT )
|
19
|
+
|
20
|
+
Gl.glBegin( Gl::GL_POLYGON )
|
21
|
+
Gl.glColor3f( 1.0, 0.0, 0.0 )
|
22
|
+
Gl.glVertex2f( -0.5, -0.5 )
|
23
|
+
Gl.glColor3f( 0.0, 1.0, 0.0 )
|
24
|
+
Gl.glVertex2f( -0.5, 0.5 )
|
25
|
+
Gl.glColor3f( 0.0, 0.0, 1.0 )
|
26
|
+
Gl.glVertex2f( 0.5, 0.5 )
|
27
|
+
Gl.glColor3f( 1.0, 0.0, 1.0 )
|
28
|
+
Gl.glVertex2f( 0.5, -0.5 )
|
29
|
+
Gl.glEnd
|
30
|
+
|
31
|
+
SDL.GLSwapBuffers()
|
32
|
+
|
33
|
+
sleep 0.01 # to avoid consuming all CPU power
|
34
|
+
end
|
@@ -0,0 +1,828 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# Purpose: Determine performance curves for various methods of pushing
|
4
|
+
# triangles and quads through the OpenGL pipeline
|
5
|
+
|
6
|
+
# Copyright (c) 2004-2006, Geoff Broadwell; this script is released
|
7
|
+
# as open source and may be distributed and modified under the terms
|
8
|
+
# of either the Artistic License or the GNU General Public License,
|
9
|
+
# in the same manner as Perl itself. These licenses should have been
|
10
|
+
# distributed to you as part of your Perl distribution, and can be
|
11
|
+
# read using `perldoc perlartistic` and `perldoc perlgpl` respectively.
|
12
|
+
|
13
|
+
# Conversion to ruby by Jan Dvorak <jan.dvorak@kraxnet.cz>
|
14
|
+
|
15
|
+
require 'opengl'
|
16
|
+
include Gl,Glu,Glut
|
17
|
+
|
18
|
+
require 'mathn'
|
19
|
+
|
20
|
+
require 'OGLBench'
|
21
|
+
|
22
|
+
$VERSION = '0.1.24-ruby-p1'
|
23
|
+
|
24
|
+
$test = 0
|
25
|
+
$run = 0
|
26
|
+
$done = false
|
27
|
+
$ready = false
|
28
|
+
|
29
|
+
### USER CONFIG
|
30
|
+
|
31
|
+
# Primitive sizes (and therefore counts) are integer divisors of
|
32
|
+
# (A^i * B^j * C^k ...) where good A, B, C, ... are relatively prime;
|
33
|
+
# this number is used for the draw area height and width and defaults to:
|
34
|
+
# 2^4 * 3^2 * 5 = 720
|
35
|
+
# You may also want to get fewer data points across the same range by
|
36
|
+
# directly using higher powers; for example:
|
37
|
+
# 16 * 9 * 5 = 720
|
38
|
+
#
|
39
|
+
# my @max_powers = (16 => 1, 9 => 1, 5 => 1);
|
40
|
+
$max_powers = { 2 => 4, 3 => 2, 5 => 1 }.to_a.flatten
|
41
|
+
|
42
|
+
# Maximum quads along each axis for known slow versus usually fast tests;
|
43
|
+
# chosen to be somewhat reasonable for most common settings of @max_powers
|
44
|
+
# my $max_count_slow = 60;
|
45
|
+
$max_count_slow = 154
|
46
|
+
$max_count_fast = 154
|
47
|
+
|
48
|
+
# Font to use to label graphs
|
49
|
+
$font_style = GLUT_BITMAP_HELVETICA_10
|
50
|
+
|
51
|
+
### MISC GLOBALS
|
52
|
+
|
53
|
+
$conf = $app = $gl_info = nil
|
54
|
+
$MIN_FRAMES = $MIN_SECONDS = 0
|
55
|
+
$w = $h = 0
|
56
|
+
$dls = {}
|
57
|
+
$vas = {}
|
58
|
+
$combos = $slow = $fast = 0
|
59
|
+
$showing_graph = false
|
60
|
+
$empty_time = $empty_frames = $total = 0
|
61
|
+
$max = []
|
62
|
+
$stats = []
|
63
|
+
$stats_fixed = []
|
64
|
+
|
65
|
+
### CODE
|
66
|
+
|
67
|
+
def main
|
68
|
+
init()
|
69
|
+
print "Benchmarks:"
|
70
|
+
|
71
|
+
glutDisplayFunc(method(:cbDraw).to_proc)
|
72
|
+
glutIdleFunc(method(:cbDraw).to_proc)
|
73
|
+
glutKeyboardFunc(method(:cbKeyPressed).to_proc)
|
74
|
+
glutMainLoop()
|
75
|
+
end
|
76
|
+
|
77
|
+
def init
|
78
|
+
$stdout.sync = true
|
79
|
+
|
80
|
+
$combos = recurse_combos($max_powers)
|
81
|
+
$combos.sort!
|
82
|
+
$slow = $combos.select { |a| a <= $max_count_slow }
|
83
|
+
$fast = $combos.select { |a| a > $max_count_slow &&
|
84
|
+
a <= $max_count_slow }
|
85
|
+
|
86
|
+
# Choose drawing area size to match counts
|
87
|
+
$h = $w = $combos.last
|
88
|
+
|
89
|
+
default_conf = {
|
90
|
+
:title => 'Triangle Slammer OpenGL Benchmark',
|
91
|
+
:geometry => "#{$w}x#{$h}",
|
92
|
+
:frames => 10,
|
93
|
+
:seconds => 1,
|
94
|
+
}
|
95
|
+
$conf, $app, $gl_info = OGLBench.basic_init(default_conf)
|
96
|
+
|
97
|
+
|
98
|
+
# Reduce indirections in inner loops
|
99
|
+
$MIN_FRAMES, $MIN_SECONDS = $conf[:frames], $conf[:seconds]
|
100
|
+
|
101
|
+
# Let user know what's going on
|
102
|
+
show_user_message()
|
103
|
+
|
104
|
+
# Change projection to integer-pixel ortho
|
105
|
+
glMatrixMode(GL_PROJECTION)
|
106
|
+
glOrtho(0, $w, 0, $h, -1, 1)
|
107
|
+
glMatrixMode(GL_MODELVIEW)
|
108
|
+
|
109
|
+
# Make sure GL state is consistent for VA and DL creation
|
110
|
+
start_frame()
|
111
|
+
|
112
|
+
# Create vertex arrays and display lists outside timing loop
|
113
|
+
init_vertex_arrays()
|
114
|
+
init_display_lists()
|
115
|
+
|
116
|
+
# Clean up GL state
|
117
|
+
end_frame()
|
118
|
+
end
|
119
|
+
|
120
|
+
def recurse_combos(powers)
|
121
|
+
base, max_power, *rest = powers
|
122
|
+
|
123
|
+
return [1] if powers.size<1
|
124
|
+
|
125
|
+
combos = []
|
126
|
+
(0..max_power).each do |power|
|
127
|
+
multiplier = base ** power
|
128
|
+
recurse_combos(rest).each do |item|
|
129
|
+
combos << (item*multiplier)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
combos
|
133
|
+
end
|
134
|
+
|
135
|
+
def show_user_message
|
136
|
+
print <<"EOM";
|
137
|
+
TRISLAM benchmarks several methods of pushing OpenGL primitives,
|
138
|
+
testing each method with various primitive counts and sizes.
|
139
|
+
During the benchmark, the test window will start out black, slowly
|
140
|
+
brightening to white as testing progresses. Once benchmarking is
|
141
|
+
complete, the collected data will be dumped in tabular form.
|
142
|
+
|
143
|
+
The configuration for this series of tests will be as follows:
|
144
|
+
|
145
|
+
EOM
|
146
|
+
|
147
|
+
OGLBench.show_basic_config($conf, $gl_info, $VERSION)
|
148
|
+
|
149
|
+
puts "standard runs: #{$slow.join(' ')}"
|
150
|
+
puts "extra fast runs: #{$fast.join(' ')}"
|
151
|
+
puts '-' * 79
|
152
|
+
end
|
153
|
+
|
154
|
+
|
155
|
+
def init_vertex_arrays
|
156
|
+
print "Init vertex arrays:"
|
157
|
+
|
158
|
+
$va_types.keys.sort.each do |type|
|
159
|
+
print " #{type}"
|
160
|
+
($slow + $fast).each do |count|
|
161
|
+
data = $va_types[type].call(count, $w / count.to_f)
|
162
|
+
va = data.pack("f*")
|
163
|
+
$vas["#{type}_#{count}"] = va
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
print ".\n";
|
168
|
+
end
|
169
|
+
|
170
|
+
def init_display_lists
|
171
|
+
print "Init display lists:"
|
172
|
+
|
173
|
+
num_lists = $dl_types.size * ($slow + $fast).size
|
174
|
+
current = glGenLists(num_lists)
|
175
|
+
|
176
|
+
$dl_types.keys.sort.each do |type|
|
177
|
+
print " #{type}"
|
178
|
+
($slow + $fast).each do |count|
|
179
|
+
$dls["#{type}_#{count}"] = current
|
180
|
+
glNewList(current, GL_COMPILE)
|
181
|
+
$dl_types[type].call(count, $w / count.to_f)
|
182
|
+
glEndList()
|
183
|
+
current += 1
|
184
|
+
end
|
185
|
+
end
|
186
|
+
puts "."
|
187
|
+
end
|
188
|
+
|
189
|
+
def benchmark
|
190
|
+
if ($test >= $tests.size)
|
191
|
+
print ".\n" if (!$done)
|
192
|
+
$done = true
|
193
|
+
return
|
194
|
+
end
|
195
|
+
name,draw,stats,class_ = $tests[$test]
|
196
|
+
|
197
|
+
counts = class_ == 'single' ? [1] : (class_ == 'slow' ? $slow : $slow + $fast)
|
198
|
+
|
199
|
+
if ($run == 0)
|
200
|
+
print " #{name}";
|
201
|
+
|
202
|
+
# After printing current test name, busy wait for a second
|
203
|
+
# so that the terminal can catch up and not do work while
|
204
|
+
# the GL timing is in progress
|
205
|
+
a = Time.now
|
206
|
+
while 1 > (Time.now - a) do end
|
207
|
+
end
|
208
|
+
|
209
|
+
count = counts[$run]
|
210
|
+
size = $w / count
|
211
|
+
|
212
|
+
OGLBench.fade_to_white(($test + ($run.to_f / counts.size)) / $tests.size)
|
213
|
+
|
214
|
+
run_done = 0
|
215
|
+
frames = 0
|
216
|
+
start = Time.now
|
217
|
+
|
218
|
+
while (run_done==0)
|
219
|
+
start_frame()
|
220
|
+
draw.call(count, size.to_f)
|
221
|
+
end_frame()
|
222
|
+
|
223
|
+
frames += 1
|
224
|
+
run_done = 1 if ($MIN_FRAMES <= frames &&
|
225
|
+
$MIN_SECONDS <= Time.now - start)
|
226
|
+
end
|
227
|
+
glFinish()
|
228
|
+
end_ = Time.now
|
229
|
+
time = end_ - start
|
230
|
+
|
231
|
+
$stats << [name,count,time,frames] + stats.call(count,size.to_f)
|
232
|
+
|
233
|
+
$run += 1
|
234
|
+
if ($run >= counts.size)
|
235
|
+
$test += 1
|
236
|
+
$run = 0
|
237
|
+
end
|
238
|
+
end
|
239
|
+
|
240
|
+
def cleanup
|
241
|
+
fixup_stats()
|
242
|
+
show_stats()
|
243
|
+
draw_stats()
|
244
|
+
end
|
245
|
+
|
246
|
+
def start_frame
|
247
|
+
glClear(GL_COLOR_BUFFER_BIT |
|
248
|
+
GL_DEPTH_BUFFER_BIT)
|
249
|
+
end
|
250
|
+
|
251
|
+
def end_frame
|
252
|
+
glFinish()
|
253
|
+
end
|
254
|
+
|
255
|
+
def fixup_stats
|
256
|
+
empty = $stats.shift
|
257
|
+
|
258
|
+
$empty_time = empty[2]
|
259
|
+
$empty_frames = empty[3]
|
260
|
+
empty_tpf = $empty_time.to_f / $empty_frames
|
261
|
+
|
262
|
+
$total = ['totl,','avg'] + [0] * 12
|
263
|
+
$max = ['max','max'] + [0] * 12
|
264
|
+
|
265
|
+
$stats.each do |stat|
|
266
|
+
name, count, time, frames, pixpf, prmpf, tpf, vpf = stat
|
267
|
+
|
268
|
+
# Subtract out empty loop time, and loop if negative result
|
269
|
+
# $time -= $empty_tpf * $frames;
|
270
|
+
if (time <= 0)
|
271
|
+
stat += [0] * 5
|
272
|
+
next
|
273
|
+
end
|
274
|
+
|
275
|
+
# Calc "work", the geometric mean of pixels and vertices
|
276
|
+
workpf = Math::sqrt(pixpf * vpf)
|
277
|
+
|
278
|
+
# Calc fps
|
279
|
+
fps = frames / time
|
280
|
+
|
281
|
+
# Calc other perf stats
|
282
|
+
pixps = pixpf * fps
|
283
|
+
prmps = prmpf * fps
|
284
|
+
tps = tpf * fps
|
285
|
+
vps = vpf * fps
|
286
|
+
wps = workpf * fps
|
287
|
+
|
288
|
+
# Add them to stat row
|
289
|
+
stat += [fps, pixps, prmps, tps, vps, wps]
|
290
|
+
|
291
|
+
# Convert per frame counts to totals
|
292
|
+
(4..7).each { |i| stat[i] *= frames }
|
293
|
+
|
294
|
+
# Update running totals
|
295
|
+
(2..7).each { |i| $total[i] += stat[i] }
|
296
|
+
|
297
|
+
# Update running maximums
|
298
|
+
(2..13).each do |i|
|
299
|
+
$max[i] = stat[i] if $max[i] < stat[i]
|
300
|
+
end
|
301
|
+
|
302
|
+
$stats_fixed << stat
|
303
|
+
end
|
304
|
+
|
305
|
+
# Calc averages for totals line
|
306
|
+
(8..13).each { |i| $total[i] = $total[i-5] / $total[2].to_f }
|
307
|
+
|
308
|
+
$ready = true
|
309
|
+
$stats = $stats_fixed
|
310
|
+
end
|
311
|
+
|
312
|
+
|
313
|
+
def show_stats
|
314
|
+
basic = ["Name","Cnt","Time"]
|
315
|
+
raw = ["Frms","Mpix","Kprim","Ktri","Kvert"]
|
316
|
+
calc = raw
|
317
|
+
scale = [ 0, 6, 3, 3, 3, ] * 2
|
318
|
+
header = basic + raw + calc
|
319
|
+
scale.map! {|n| 10 ** n }
|
320
|
+
|
321
|
+
g_form = "%9s%-*s %s\n"
|
322
|
+
h_form = '%-5s%3s %6s' + ' %5s' * raw.size + ' ' + ' %5s' * calc.size + "\n"
|
323
|
+
format = '%-5s%3s %6.3f' + ' %5d' * raw.size + ' ' + ' %5d' * calc.size + "\n"
|
324
|
+
|
325
|
+
printf(g_form, '', 6 * 5 + 8, 'MEASURED', 'PER SECOND')
|
326
|
+
printf(h_form, *header)
|
327
|
+
printf(format, "empty", 1, $empty_time, $empty_frames, *([0] * 9))
|
328
|
+
#
|
329
|
+
|
330
|
+
($stats + [$total]).each do |stat|
|
331
|
+
st = stat.clone()
|
332
|
+
(0..scale.size-1).each do |i|
|
333
|
+
st[i + 3] /= scale[i]
|
334
|
+
end
|
335
|
+
printf(format,*st)
|
336
|
+
end
|
337
|
+
end
|
338
|
+
|
339
|
+
|
340
|
+
def make_quads_va(count,size)
|
341
|
+
data = []
|
342
|
+
(0 .. count-1).each do |y|
|
343
|
+
(0 .. count-1).each do |x|
|
344
|
+
data << x * size << y * size + size
|
345
|
+
data << x * size << y * size
|
346
|
+
data << x * size + size << y * size
|
347
|
+
data << x * size + size << y * size + size
|
348
|
+
end
|
349
|
+
end
|
350
|
+
data
|
351
|
+
end
|
352
|
+
|
353
|
+
def make_tris_va(count,size)
|
354
|
+
data = []
|
355
|
+
(0 .. count-1).each do |y|
|
356
|
+
(0 .. count-1).each do |x|
|
357
|
+
data << x * size << y * size + size
|
358
|
+
data << x * size << y * size
|
359
|
+
data << x * size + size << y * size + size
|
360
|
+
|
361
|
+
data << x * size + size << y * size + size
|
362
|
+
data << x * size << y * size
|
363
|
+
data << x * size + size << y * size
|
364
|
+
end
|
365
|
+
end
|
366
|
+
data
|
367
|
+
end
|
368
|
+
|
369
|
+
def make_qs_va(count,size)
|
370
|
+
data = []
|
371
|
+
(0 .. count-1).each do |y|
|
372
|
+
(0 .. count).each do |x|
|
373
|
+
data << x * size << y * size + size
|
374
|
+
data << x * size << y * size
|
375
|
+
end
|
376
|
+
end
|
377
|
+
data
|
378
|
+
end
|
379
|
+
|
380
|
+
def make_ts_va(count,size)
|
381
|
+
data = []
|
382
|
+
(0 .. count-1).each do |y|
|
383
|
+
(0 .. count).each do |x|
|
384
|
+
data << x * size << y * size + size
|
385
|
+
data << x * size << y * size
|
386
|
+
end
|
387
|
+
end
|
388
|
+
data
|
389
|
+
end
|
390
|
+
|
391
|
+
def draw_qs(count,size)
|
392
|
+
(0 .. count-1).each do |y|
|
393
|
+
glBegin(GL_QUAD_STRIP)
|
394
|
+
(0 .. count).each do |x|
|
395
|
+
glVertex2f(x * size, y * size + size)
|
396
|
+
glVertex2f(x * size, y * size )
|
397
|
+
end
|
398
|
+
glEnd()
|
399
|
+
end
|
400
|
+
end
|
401
|
+
|
402
|
+
def draw_ts(count,size)
|
403
|
+
(0 .. count-1).each do |y|
|
404
|
+
glBegin(GL_TRIANGLE_STRIP)
|
405
|
+
(0 .. count).each do |x|
|
406
|
+
glVertex2f(x * size, y * size + size)
|
407
|
+
glVertex2f(x * size, y * size )
|
408
|
+
end
|
409
|
+
glEnd()
|
410
|
+
end
|
411
|
+
end
|
412
|
+
|
413
|
+
def draw_qs_va(count,size)
|
414
|
+
va = $vas["qs_#{count}"]
|
415
|
+
row = 2 * (count + 1)
|
416
|
+
|
417
|
+
glEnableClientState(GL_VERTEX_ARRAY)
|
418
|
+
glVertexPointer(2, GL_FLOAT, 0, va)
|
419
|
+
(0 .. count-1).each do |y|
|
420
|
+
glDrawArrays(GL_QUAD_STRIP, y * row, row)
|
421
|
+
end
|
422
|
+
glDisableClientState(GL_VERTEX_ARRAY)
|
423
|
+
end
|
424
|
+
|
425
|
+
def draw_ts_va(count,size)
|
426
|
+
va = $vas["ts_#{count}"]
|
427
|
+
row = 2 * (count + 1)
|
428
|
+
|
429
|
+
glEnableClientState(GL_VERTEX_ARRAY)
|
430
|
+
glVertexPointer(2, GL_FLOAT, 0, va)
|
431
|
+
(0 .. count-1).each do |y|
|
432
|
+
glDrawArrays(GL_TRIANGLE_STRIP, y * row, row)
|
433
|
+
end
|
434
|
+
glDisableClientState(GL_VERTEX_ARRAY)
|
435
|
+
end
|
436
|
+
|
437
|
+
def draw_tris(count,size)
|
438
|
+
glBegin(GL_TRIANGLES)
|
439
|
+
(0 .. count-1).each do |y|
|
440
|
+
(0 .. count-1).each do |x|
|
441
|
+
glVertex2f(x * size , y * size + size)
|
442
|
+
glVertex2f(x * size , y * size )
|
443
|
+
glVertex2f(x * size + size, y * size + size)
|
444
|
+
|
445
|
+
glVertex2f(x * size + size, y * size + size)
|
446
|
+
glVertex2f(x * size , y * size )
|
447
|
+
glVertex2f(x * size + size, y * size )
|
448
|
+
end
|
449
|
+
end
|
450
|
+
glEnd
|
451
|
+
end
|
452
|
+
|
453
|
+
def stats_tris(count,size)
|
454
|
+
length = size * count
|
455
|
+
area = length * length
|
456
|
+
prims = 2 * count * count
|
457
|
+
tris = prims
|
458
|
+
verts = 3 * prims
|
459
|
+
|
460
|
+
[area, prims, tris, verts]
|
461
|
+
end
|
462
|
+
|
463
|
+
def draw_empty(count,size)
|
464
|
+
end
|
465
|
+
|
466
|
+
def stats_empty(count,size)
|
467
|
+
[0,0,0,0]
|
468
|
+
end
|
469
|
+
|
470
|
+
def draw_quads(count,size)
|
471
|
+
glBegin(GL_QUADS)
|
472
|
+
(0 .. count-1).each do |y|
|
473
|
+
(0 .. count-1).each do |x|
|
474
|
+
glVertex2f(x * size , y * size + size)
|
475
|
+
glVertex2f(x * size , y * size )
|
476
|
+
glVertex2f(x * size + size, y * size )
|
477
|
+
glVertex2f(x * size + size, y * size + size)
|
478
|
+
end
|
479
|
+
end
|
480
|
+
glEnd
|
481
|
+
end
|
482
|
+
|
483
|
+
def stats_quads(count,size)
|
484
|
+
length = size * count
|
485
|
+
area = length * length
|
486
|
+
prims = count * count
|
487
|
+
tris = 2 * prims
|
488
|
+
verts = 4 * prims
|
489
|
+
|
490
|
+
[area, prims, tris, verts]
|
491
|
+
end
|
492
|
+
|
493
|
+
def stats_ts(count,size)
|
494
|
+
length = size * count
|
495
|
+
area = length * length
|
496
|
+
prims = count
|
497
|
+
tris = 2 * count * prims
|
498
|
+
verts = 2 * (count + 1) * prims
|
499
|
+
|
500
|
+
[area, prims, tris, verts]
|
501
|
+
end
|
502
|
+
|
503
|
+
def stats_qs(count,size)
|
504
|
+
length = size * count
|
505
|
+
area = length * length
|
506
|
+
prims = count
|
507
|
+
tris = 2 * count * prims
|
508
|
+
verts = 2 * (count + 1) * prims
|
509
|
+
|
510
|
+
[area, prims, tris, verts]
|
511
|
+
end
|
512
|
+
|
513
|
+
def draw_ts_dl(count,size)
|
514
|
+
glCallList($dls["ts_#{count}"]);
|
515
|
+
end
|
516
|
+
|
517
|
+
def draw_qs_dl(count,size)
|
518
|
+
glCallList($dls["qs_#{count}"]);
|
519
|
+
end
|
520
|
+
|
521
|
+
def draw_tris_va(count,size)
|
522
|
+
va = $vas["t_#{count}"]
|
523
|
+
|
524
|
+
glVertexPointer(2, GL_FLOAT, 0, va)
|
525
|
+
|
526
|
+
glEnableClientState(GL_VERTEX_ARRAY)
|
527
|
+
glDrawArrays(GL_TRIANGLES, 0, 6 * count * count)
|
528
|
+
glDisableClientState(GL_VERTEX_ARRAY)
|
529
|
+
end
|
530
|
+
|
531
|
+
def draw_quads_va(count,size)
|
532
|
+
va = $vas["q_#{count}"]
|
533
|
+
|
534
|
+
glVertexPointer(2, GL_FLOAT, 0, va)
|
535
|
+
|
536
|
+
glEnableClientState(GL_VERTEX_ARRAY)
|
537
|
+
glDrawArrays(GL_QUADS, 0, 4 * count * count)
|
538
|
+
glDisableClientState(GL_VERTEX_ARRAY)
|
539
|
+
end
|
540
|
+
|
541
|
+
|
542
|
+
def draw_ts_va_dl(count,size)
|
543
|
+
va = $vas["ts_#{count}"]
|
544
|
+
|
545
|
+
glVertexPointer(2, GL_FLOAT, 0, va)
|
546
|
+
|
547
|
+
glEnableClientState(GL_VERTEX_ARRAY)
|
548
|
+
glCallList($dls["tsv_#{count}"])
|
549
|
+
glDisableClientState(GL_VERTEX_ARRAY)
|
550
|
+
end
|
551
|
+
|
552
|
+
def draw_qs_va_dl(count,size)
|
553
|
+
va = $vas["qs_#{count}"]
|
554
|
+
|
555
|
+
glVertexPointer(2, GL_FLOAT, 0, va)
|
556
|
+
|
557
|
+
glEnableClientState(GL_VERTEX_ARRAY)
|
558
|
+
glCallList($dls["qsv_#{count}"])
|
559
|
+
glDisableClientState(GL_VERTEX_ARRAY)
|
560
|
+
end
|
561
|
+
|
562
|
+
|
563
|
+
def draw_stats
|
564
|
+
return if (!$ready)
|
565
|
+
|
566
|
+
# Graph config
|
567
|
+
x_off = 10
|
568
|
+
y_off = 10
|
569
|
+
tick_size = 3
|
570
|
+
val_space = 50
|
571
|
+
key_size = 20
|
572
|
+
x_scale = ($w - 4 * x_off) / (2 * ($fast.last || $slow.last))
|
573
|
+
key_scale = ($h - 4 * y_off) / (2 * $tests.size)
|
574
|
+
|
575
|
+
# Get a fresh black frame for graphing
|
576
|
+
glClearColor(0, 0, 0, 1)
|
577
|
+
start_frame()
|
578
|
+
|
579
|
+
# Use antialiased lines
|
580
|
+
glEnable(GL_BLEND)
|
581
|
+
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
|
582
|
+
glEnable(GL_LINE_SMOOTH)
|
583
|
+
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST)
|
584
|
+
|
585
|
+
# Draw axis ticks
|
586
|
+
glColor3f(1, 1, 1);
|
587
|
+
glBegin(GL_LINES);
|
588
|
+
|
589
|
+
([0] + $slow + $fast).each do |count|
|
590
|
+
x_tick = count * x_scale + x_off
|
591
|
+
glVertex2f(x_tick, y_off)
|
592
|
+
glVertex2f(x_tick, y_off - tick_size)
|
593
|
+
glVertex2f(x_tick, y_off + $h / 2)
|
594
|
+
glVertex2f(x_tick, y_off + $h / 2 - tick_size)
|
595
|
+
glVertex2f(x_tick + $w / 2, y_off + $h / 2)
|
596
|
+
glVertex2f(x_tick + $w / 2, y_off + $h / 2 - tick_size)
|
597
|
+
end
|
598
|
+
glEnd
|
599
|
+
|
600
|
+
x_tick = x_off + 3
|
601
|
+
val_max = (($h / 2 - 2 * y_off) / val_space).to_i
|
602
|
+
|
603
|
+
# Work
|
604
|
+
(0..val_max).each do |value|
|
605
|
+
y_tick = value * val_space + y_off
|
606
|
+
|
607
|
+
glBegin(GL_LINES)
|
608
|
+
glVertex2f(x_off, y_tick)
|
609
|
+
glVertex2f(x_off - tick_size, y_tick)
|
610
|
+
glEnd
|
611
|
+
end
|
612
|
+
|
613
|
+
# Pixels
|
614
|
+
value = 0
|
615
|
+
val_max = $max[9] / mag_scale($max[9])
|
616
|
+
y_scale = ($h - 4 * y_off) / (2 * val_max)
|
617
|
+
val_inc = tick_inc(val_max,5)
|
618
|
+
|
619
|
+
while (value < val_max)
|
620
|
+
y_tick = (value * y_scale) + y_off
|
621
|
+
|
622
|
+
glBegin(GL_LINES)
|
623
|
+
glVertex2f(x_off, y_tick + $h / 2)
|
624
|
+
glVertex2f(x_off - tick_size, y_tick + $h / 2)
|
625
|
+
glEnd
|
626
|
+
OGLBench.draw_string($font_style, value.to_s, x_tick, y_tick + $h / 2) if (value!=0)
|
627
|
+
value += val_inc
|
628
|
+
end
|
629
|
+
|
630
|
+
# Vertices
|
631
|
+
value = 0
|
632
|
+
val_max = $max[12] / mag_scale($max[12])
|
633
|
+
y_scale = ($h - 4 * y_off) / (2 * val_max)
|
634
|
+
val_inc = tick_inc(val_max,5)
|
635
|
+
while (value < val_max)
|
636
|
+
y_tick = (value * y_scale) + y_off
|
637
|
+
|
638
|
+
glBegin(GL_LINES)
|
639
|
+
glVertex2f(x_off + $w / 2, y_tick + $h / 2)
|
640
|
+
glVertex2f(x_off + $w / 2 - tick_size, y_tick + $h / 2)
|
641
|
+
glEnd
|
642
|
+
|
643
|
+
OGLBench.draw_string($font_style, value.to_s, x_tick + $w / 2, y_tick + $h / 2) if (value!=0)
|
644
|
+
value += val_inc
|
645
|
+
end
|
646
|
+
|
647
|
+
# Draw axes
|
648
|
+
glBegin(GL_LINE_STRIP)
|
649
|
+
glVertex2f(x_off, $h / 2 - y_off)
|
650
|
+
glVertex2f(x_off, y_off)
|
651
|
+
glVertex2f($w / 2 - x_off, y_off)
|
652
|
+
glEnd
|
653
|
+
glBegin(GL_LINE_STRIP)
|
654
|
+
glVertex2f(x_off, $h - y_off)
|
655
|
+
glVertex2f(x_off, $h / 2 + y_off)
|
656
|
+
glVertex2f($w / 2 - x_off, $h / 2 + y_off)
|
657
|
+
glEnd
|
658
|
+
glBegin(GL_LINE_STRIP)
|
659
|
+
glVertex2f($w / 2 + x_off, $h - y_off)
|
660
|
+
glVertex2f($w / 2 + x_off, $h / 2 + y_off)
|
661
|
+
glVertex2f($w - x_off, $h / 2 + y_off)
|
662
|
+
glEnd
|
663
|
+
|
664
|
+
# Draw color key
|
665
|
+
(0..$tests.size - 1).each do |num|
|
666
|
+
test = $tests[num]
|
667
|
+
name,color,stipple = [test[0]] + test[-2,2]
|
668
|
+
glEnable(GL_LINE_STIPPLE)
|
669
|
+
glLineStipple(3, stipple)
|
670
|
+
|
671
|
+
glBegin(GL_LINES)
|
672
|
+
glColor3fv(color)
|
673
|
+
glVertex2f(x_off + $w / 2, y_off + num * key_scale)
|
674
|
+
glVertex2f(x_off + $w / 2 + key_size, y_off + num * key_scale)
|
675
|
+
glEnd()
|
676
|
+
|
677
|
+
glDisable(GL_LINE_STIPPLE)
|
678
|
+
|
679
|
+
OGLBench.draw_string($font_style, name, x_off + $w / 2 + key_size * 2, y_off + num * key_scale)
|
680
|
+
end
|
681
|
+
|
682
|
+
# Draw performance graph lines
|
683
|
+
|
684
|
+
# Pixels per second
|
685
|
+
draw_one_stat(x_off, y_off + $h / 2, y_off, x_scale, 9)
|
686
|
+
glColor3f(1, 1, 1)
|
687
|
+
|
688
|
+
OGLBench.draw_string($font_style, mag_char($max[9]) + " Pixels/Sec", $w / 4, $h - 2 * y_off)
|
689
|
+
|
690
|
+
# Vertices per second
|
691
|
+
draw_one_stat(x_off + $w / 2, y_off + $h / 2, y_off, x_scale, 12)
|
692
|
+
glColor3f(1, 1, 1)
|
693
|
+
OGLBench.draw_string($font_style, mag_char($max[12]) + " Vertices/Sec", 3 * $w / 4, $h - 2 * y_off)
|
694
|
+
|
695
|
+
# "Work" per second, the geometric mean of pixels and vertices
|
696
|
+
draw_one_stat(x_off, y_off, y_off, x_scale, 13)
|
697
|
+
glColor3f(1, 1, 1)
|
698
|
+
|
699
|
+
OGLBench.draw_string($font_style, "Work/Sec", $w / 4, $h / 2 - 2 * y_off)
|
700
|
+
|
701
|
+
# Show our graph
|
702
|
+
end_frame();
|
703
|
+
$showing_graph = true
|
704
|
+
end
|
705
|
+
|
706
|
+
def draw_one_stat(x_loc,y_loc,y_off,x_scale,num)
|
707
|
+
max = $max[num]
|
708
|
+
y_scale = ($h - 4 * y_off) / (2 * max)
|
709
|
+
colors = {}
|
710
|
+
$tests.each do |test| colors[test[0]] = test[-2] end
|
711
|
+
|
712
|
+
stipple = {}
|
713
|
+
$tests.each do |test| stipple[test[0]] = test[-1] end
|
714
|
+
|
715
|
+
last = ''
|
716
|
+
|
717
|
+
glEnable(GL_LINE_STIPPLE)
|
718
|
+
glBegin(GL_LINE_STRIP)
|
719
|
+
$stats.each_with_index do |stat,run|
|
720
|
+
name,count, st = stat[0,2] + [stat[num]]
|
721
|
+
|
722
|
+
if name != last
|
723
|
+
glEnd
|
724
|
+
glLineStipple(3, stipple[name])
|
725
|
+
glBegin(GL_LINE_STRIP)
|
726
|
+
last = name
|
727
|
+
end
|
728
|
+
|
729
|
+
glColor3fv(colors[name])
|
730
|
+
glVertex2f(count * x_scale + x_loc, st * y_scale + y_loc)
|
731
|
+
end
|
732
|
+
glEnd
|
733
|
+
glDisable(GL_LINE_STIPPLE)
|
734
|
+
end
|
735
|
+
|
736
|
+
|
737
|
+
def kilo_mag(num)
|
738
|
+
mag = (Math::log(num) / Math::log(10)).to_i
|
739
|
+
(mag / 3)
|
740
|
+
end
|
741
|
+
|
742
|
+
def mag_char(num)
|
743
|
+
['','K','M','G','T','P','E','Z','Y'][kilo_mag(num)]
|
744
|
+
end
|
745
|
+
|
746
|
+
def mag_scale(num)
|
747
|
+
10 ** (3*kilo_mag(num))
|
748
|
+
end
|
749
|
+
|
750
|
+
def tick_inc(max,parts = 5)
|
751
|
+
return (max / parts.to_f) if (max < 1)
|
752
|
+
|
753
|
+
mag = (Math::log(max) / Math::log(10)).to_i
|
754
|
+
scl = (10 ** (mag - 1))
|
755
|
+
inc = max / (scl * parts)
|
756
|
+
|
757
|
+
if (inc > 7.5)
|
758
|
+
inc = 10
|
759
|
+
elsif (inc > 3.5)
|
760
|
+
inc = 5
|
761
|
+
elsif (inc > 1.5)
|
762
|
+
inc = 2
|
763
|
+
else
|
764
|
+
inc = 1
|
765
|
+
end
|
766
|
+
(inc * scl.to_f)
|
767
|
+
end
|
768
|
+
|
769
|
+
# State engine
|
770
|
+
def cbDraw
|
771
|
+
if (!$done)
|
772
|
+
benchmark()
|
773
|
+
elsif (!$ready)
|
774
|
+
cleanup()
|
775
|
+
else
|
776
|
+
sleep(1)
|
777
|
+
draw_stats()
|
778
|
+
end
|
779
|
+
end
|
780
|
+
|
781
|
+
# Keyboard handler
|
782
|
+
def cbKeyPressed(key,x,y)
|
783
|
+
if (key == ?\e or key == ?q)
|
784
|
+
glutDestroyWindow($app)
|
785
|
+
exit(0)
|
786
|
+
end
|
787
|
+
if ($done && key == ?r)
|
788
|
+
draw_stats()
|
789
|
+
end
|
790
|
+
end
|
791
|
+
|
792
|
+
|
793
|
+
### METHODS TO BENCHMARK
|
794
|
+
|
795
|
+
$va_types = {
|
796
|
+
"q" => method(:make_quads_va),
|
797
|
+
"t" => method(:make_tris_va),
|
798
|
+
"qs" => method(:make_qs_va),
|
799
|
+
"ts" => method(:make_ts_va),
|
800
|
+
}
|
801
|
+
|
802
|
+
$dl_types = {
|
803
|
+
"qs" => method(:draw_qs),
|
804
|
+
"ts" => method(:draw_ts),
|
805
|
+
"qsv" => method(:draw_qs_va),
|
806
|
+
"tsv" => method(:draw_ts_va),
|
807
|
+
}
|
808
|
+
|
809
|
+
$tests = [
|
810
|
+
# Nick Draw Routine Stats Calc Type Graph Color
|
811
|
+
# ["empty",method(:draw_empty), method(:stats_empty),'single',[1 , 1, 1], 0xFFFF],
|
812
|
+
["t" ,method(:draw_tris), method(:stats_tris) ,'slow', [1 , 0, 0], 0xAAAA],
|
813
|
+
["q" ,method(:draw_quads), method(:stats_quads),'slow', [1 ,0.5, 0], 0xAAAA],
|
814
|
+
["ts" ,method(:draw_ts), method(:stats_ts), 'slow', [1 , 1, 0], 0xAAAA],
|
815
|
+
["qs" ,method(:draw_qs), method(:stats_qs), 'slow', [0 , 1, 0], 0xAAAA],
|
816
|
+
["tsd" ,method(:draw_ts_dl), method(:stats_ts), 'fast', [0 , 1, 1], 0xAAAA],
|
817
|
+
["qsd" ,method(:draw_qs_dl), method(:stats_qs), 'fast', [0 , 0, 1], 0xAAAA],
|
818
|
+
["tv" ,method(:draw_tris_va), method(:stats_tris), 'fast', [0.8, 0, 0], 0xFFFF],
|
819
|
+
["qv" ,method(:draw_quads_va),method(:stats_quads),'fast', [0.8,0.4, 0], 0xFFFF],
|
820
|
+
["tsv" ,method(:draw_ts_va), method(:stats_ts), 'fast', [0.8,0.8, 0], 0xFFFF],
|
821
|
+
["qsv" ,method(:draw_qs_va), method(:stats_qs), 'fast', [0 ,0.8, 0], 0xFFFF],
|
822
|
+
["tsvd" ,method(:draw_ts_va_dl),method(:stats_ts), 'fast', [0 ,0.8,0.8], 0xFFFF],
|
823
|
+
["qsvd" ,method(:draw_qs_va_dl),method(:stats_qs), 'fast', [0 , 0,0.8], 0xFFFF],
|
824
|
+
]
|
825
|
+
|
826
|
+
# Start from main function ()
|
827
|
+
main()
|
828
|
+
|