| File: | config/auto/opengl.pm |
| Coverage: | 92.3% |
| line | stmt | bran | cond | sub | code |
|---|---|---|---|---|---|
| 1 | # Copyright (C) 2008, Parrot Foundation. | ||||
| 2 | # $Id: opengl.pm 42341 2009-11-07 23:48:27Z jkeenan $ | ||||
| 3 | |||||
| 4 | |||||
| 5 - 137 | =head1 NAME
config/auto/opengl.pm - Probe for OpenGL, GLU, and GLUT libraries
=head1 DESCRIPTION
Determines whether the platform supports OpenGL, GLU and GLUT. The optimal
result at this time is to find OpenGL 3.2, GLU 1.3, and GLUT API version 4.
You will typically need to install the headers and libraries required for
compiling OpenGL/GLU/GLUT applications as a separate step in addition to
the base development tools for your platform. The following sections detail
the steps needed to add OpenGL support for each platform for which we have
received this information -- details for additional platforms are welcome!
=head2 Mac OS X
You will need to install the F<OpenGL Framework> and the F<GLUT Framework>.
With these in place, everything else should be autodetected. Mac OS X uses
a proprietary GLUT variant that supports more functions than standard
GLUT 3.7, but fewer than F<freeglut>.
=head2 Linux
Linux distributions typically use F<freeglut>
(L<http://freeglut.sourceforge.net/>) for GLUT support, and F<Mesa>
(L<http://www.mesa3d.org/>) for GLU support. Either the Mesa headers
(for open source drivers) or the vendor headers (for closed source drivers)
can be used for core OpenGL/GLX support. Here are the package names for
various distributions; installing each of these will typically pull in a
number of prerequisites as well:
=head3 Debian/Ubuntu/etc.
=over 4
=item GLUT
F<freeglut3-dev>
=item GLU
F<libglu1-mesa-dev>
=item OpenGL/GLX (open source drivers)
F<libgl1-mesa-dev>
=item OpenGL/GLX (NVIDIA drivers)
F<nvidia-glx-dev>
=back
=head3 Fedora/RedHat/CentOS/etc.
=over 4
=item GLUT
F<freeglut-devel>
=item GLU
F<mesa-libGLU-devel>
=item OpenGL/GLX (open source drivers)
F<mesa-libGL-devel>
=item OpenGL/GLX (NVIDIA drivers)
F<nvidia-devel> (?)
=back
=head2 Windows
On Windows, Parrot supports four different compiler environments, each of
which has different requirements for OpenGL support. Generally you should not
attempt to mix the Cygwin variants (installing some X OpenGL libs and some
w32api OpenGL libs) as this will almost certainly result in runtime errors
like this one:
freeglut ERROR: Function <glutDisplayFunc> called without first calling 'glutInit'.
=head3 MSVC
=over 4
=item OpenGL/GLU/WGL
F<Windows SDK for Windows Server 2008 and .NET Framework 3.5>
=item GLUT
F<GLUT for Win32> (L<http://www.xmission.com/~nate/glut.html>)
=back
=head3 MinGW
GLUT 3.7.6,
see L<http://www.transmissionzero.co.uk/computing/using-glut-with-mingw/>.
=head3 Cygwin/X
Requires an X server and F<libglut-devel>, F<libGL-devel>, F<libGLU-devel>,
F<freeglut> and its dependencies.
This is tried first.
=head3 Cygwin/w32api
Requires the F<opengl> and F<w32api> packages.
Cygwin/w32api for native opengl support is only tried if
F</usr/include/GL> does not exist. The problem is that the OpenGL header files
are used to create the OpenGL function list, and not the libraries themselves.
If the F</usr/include/GL> headers are found these are used, even if the w32api
GLUT libraries are defined.
=cut | ||||
| 138 | |||||
| 139 | |||||
| 140 | package auto::opengl; | ||||
| 141 | |||||
| 142 | 81 81 81 | use strict; | |||
| 143 | 81 81 81 | use warnings; | |||
| 144 | 81 81 81 | use File::Spec; | |||
| 145 | |||||
| 146 | 81 81 81 | use base qw(Parrot::Configure::Step); | |||
| 147 | |||||
| 148 | 81 81 81 | use Parrot::Configure::Utils ':auto'; | |||
| 149 | |||||
| 150 | sub _init { | ||||
| 151 | 83 | my $self = shift; | |||
| 152 | 83 | my %data; | |||
| 153 | 83 | $data{description} = q{Does your platform support OpenGL}; | |||
| 154 | 83 | $data{result} = q{}; | |||
| 155 | 83 | return \%data; | |||
| 156 | } | ||||
| 157 | |||||
| 158 | sub runstep { | ||||
| 159 | 81 | my ( $self, $conf ) = @_; | |||
| 160 | |||||
| 161 | 81 | my ( $verbose, $without ) = $conf->options->get( | |||
| 162 | qw| | ||||
| 163 | verbose | ||||
| 164 | without-opengl | ||||
| 165 | | | ||||
| 166 | ); | ||||
| 167 | |||||
| 168 | 81 | return $self->_handle_no_opengl($conf) if $without; | |||
| 169 | |||||
| 170 | 80 | my $osname = $conf->data->get('osname'); | |||
| 171 | |||||
| 172 | 80 | my $extra_libs = $self->_select_lib( { | |||
| 173 | conf => $conf, | ||||
| 174 | osname => $osname, | ||||
| 175 | cc => $conf->data->get('cc'), | ||||
| 176 | ($^O eq 'cygwin') ? # Cygwin/X is used when /usr/include/GL is found | ||||
| 177 | (-d '/usr/include/GL' | ||||
| 178 | ? (cygwin => '-lglut -L/usr/X11R6/lib -lGLU -lGL') | ||||
| 179 | : (cygwin => '-lglut32 -lglu32 -lopengl32')) | ||||
| 180 | : (), | ||||
| 181 | win32_gcc => '-lglut32 -lglu32 -lopengl32', | ||||
| 182 | win32_nongcc => 'opengl32.lib glu32.lib glut32.lib', | ||||
| 183 | darwin => '-framework OpenGL -framework GLUT', | ||||
| 184 | default => '-lglut -lGLU -lGL', | ||||
| 185 | } ); | ||||
| 186 | |||||
| 187 | 80 | $conf->cc_gen('config/auto/opengl/opengl_c.in'); | |||
| 188 | 80 | my $has_glut = 0; | |||
| 189 | 80 80 | eval { $conf->cc_build( q{}, $extra_libs ) }; | |||
| 190 | 80 | if ( $@ ) { | |||
| 191 | 0 | return $self->_handle_no_opengl($conf); | |||
| 192 | } | ||||
| 193 | else { | ||||
| 194 | 80 | my $test = $conf->cc_run(); | |||
| 195 | 80 | return _handle_glut($conf, $extra_libs, $self->_evaluate_cc_run($test, $verbose)); | |||
| 196 | } | ||||
| 197 | } | ||||
| 198 | |||||
| 199 | sub _evaluate_cc_run { | ||||
| 200 | 82 | my ($self, $test, $verbose) = @_; | |||
| 201 | 82 | my ($glut_api_version, $glut_brand) = split ' ', $test; | |||
| 202 | |||||
| 203 | 82 | print " (yes, $glut_brand API version $glut_api_version) " if $verbose; | |||
| 204 | 82 | $self->set_result("yes, $glut_brand $glut_api_version"); | |||
| 205 | |||||
| 206 | 82 | return ($glut_api_version, $glut_brand); | |||
| 207 | } | ||||
| 208 | |||||
| 209 | sub _handle_glut { | ||||
| 210 | 81 | my ($conf, $libs, $glut_api_version, $glut_brand) = @_; | |||
| 211 | |||||
| 212 | 81 | $conf->data->set( | |||
| 213 | # Completely cargo culted | ||||
| 214 | opengl => 'define', | ||||
| 215 | has_opengl => 1, | ||||
| 216 | HAS_OPENGL => 1, | ||||
| 217 | opengl_lib => $libs, | ||||
| 218 | |||||
| 219 | glut => 'define', | ||||
| 220 | glut_brand => $glut_brand, | ||||
| 221 | has_glut => $glut_api_version, | ||||
| 222 | HAS_GLUT => $glut_api_version, | ||||
| 223 | ); | ||||
| 224 | |||||
| 225 | 81 | return 1; | |||
| 226 | } | ||||
| 227 | |||||
| 228 | sub _handle_no_opengl { | ||||
| 229 | 1 | my ($self, $conf) = @_; | |||
| 230 | |||||
| 231 | 1 | $conf->data->set( | |||
| 232 | has_opengl => 0, | ||||
| 233 | HAS_OPENGL => 0, | ||||
| 234 | opengl_lib => '', | ||||
| 235 | |||||
| 236 | has_glut => 0, | ||||
| 237 | HAS_GLUT => 0, | ||||
| 238 | ); | ||||
| 239 | |||||
| 240 | 1 | $self->set_result('no'); | |||
| 241 | |||||
| 242 | 1 | return 1; | |||
| 243 | } | ||||
| 244 | |||||
| 245 | |||||
| 246 | 1; | ||||
| 247 | |||||
| 248 | # Local Variables: | ||||
| 249 | # mode: cperl | ||||
| 250 | # cperl-indent-level: 4 | ||||
| 251 | # fill-column: 100 | ||||
| 252 | # End: | ||||
| 253 | # vim: expandtab shiftwidth=4: | ||||