File Coverage

File:config/auto/opengl.pm
Coverage:92.5%

linestmtbrancondsubcode
1# Copyright (C) 2008, Parrot Foundation.
2# $Id: opengl.pm 37202 2009-03-08 12:18:47Z rurban $
3
4
5 - 132
=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 2.1, 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 three different compiler environments, each of
which has different requirements for OpenGL support:


=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 a X server and F<libglut-devel>, F<libGL-devel>, F<libGLU-devel>,
F<freeglut> and its dependencies.

This is tried first.

=head3 Cygwin/w32api

The Cygwin/w32api for native opengl support
is only tried if F</usr/include/GL> does not exist.

The problem is that the L<NCI|pdds/draft/pdd16_native_call.pod>
tries the header files to create the imports and not the libraries,
and if the F</usr/include/GL> headers are found these are used, despite
the w32api GLUT libraries are defined.

F<opengl>, F<w32api>

=cut
133
134
135package auto::opengl;
136
137
39
39
39
use strict;
138
39
39
39
use warnings;
139
39
39
39
use File::Spec;
140
141
39
39
39
use base qw(Parrot::Configure::Step);
142
143
39
39
39
use Parrot::Configure::Utils ':auto';
144
145sub _init {
146
41
    my $self = shift;
147
41
    my %data;
148
41
    $data{description} = q{Does your platform support OpenGL};
149
41
    $data{result} = q{};
150
41
    return \%data;
151}
152
153sub runstep {
154
39
    my ( $self, $conf ) = @_;
155
156
39
    my ( $verbose, $without ) = $conf->options->get(
157        qw|
158            verbose
159            without-opengl
160        |
161    );
162
163
39
    return $self->_handle_no_opengl($conf) if $without;
164
165
38
    my $osname = $conf->data->get_p5('OSNAME');
166
167
38
    my $extra_libs = $self->_select_lib( {
168            conf => $conf,
169            osname => $osname,
170            cc => $conf->data->get('cc'),
171            ($^O eq 'cygwin') ? # Cygwin/X is used when /usr/include/GL is found
172             (-d '/usr/include/GL'
173                ? (cygwin => '-lglut -L/usr/X11R6/lib -lGLU -lGL')
174                : (cygwin => '-lglut32 -lglu32 -lopengl32'))
175             : (),
176            win32_gcc => '-lglut32 -lglu32 -lopengl32',
177            win32_nongcc => 'opengl32.lib glu32.lib glut32.lib',
178            darwin => '-framework OpenGL -framework GLUT',
179            default => '-lglut -lGLU -lGL',
180    } );
181
182    # On OS X check the presence of the OpenGL headers in the standard
183    # Fink/macports locations.
184    # Mindlessly morphed from readline ... may need to be fixed
185
38
    $self->_handle_darwin_for_fink ($conf, $osname, 'GL/glut.h');
186
38
    $self->_handle_darwin_for_macports($conf, $osname, 'GL/glut.h');
187
188
38
    $conf->cc_gen('config/auto/opengl/opengl_c.in');
189
38
    my $has_glut = 0;
190
38
38
    eval { $conf->cc_build( q{}, $extra_libs ) };
191
38
    if ( $@ ) {
192
0
        return $self->_handle_no_opengl($conf);
193    }
194    else {
195
38
        my $test = $conf->cc_run();
196
38
        return _handle_glut($conf, $extra_libs, $self->_evaluate_cc_run($test, $verbose));
197    }
198}
199
200sub _evaluate_cc_run {
201
40
    my ($self, $test, $verbose) = @_;
202
40
    my ($glut_api_version, $glut_brand) = split ' ', $test;
203
204
40
    print " (yes, $glut_brand API version $glut_api_version) " if $verbose;
205
40
    $self->set_result("yes, $glut_brand $glut_api_version");
206
207
40
    return ($glut_api_version, $glut_brand);
208}
209
210sub _handle_glut {
211
39
    my ($conf, $libs, $glut_api_version, $glut_brand) = @_;
212
213
39
    $conf->data->set(
214        # Completely cargo culted
215        opengl => 'define',
216        has_opengl => 1,
217        HAS_OPENGL => 1,
218        opengl_lib => $libs,
219
220        glut => 'define',
221        glut_brand => $glut_brand,
222        has_glut => $glut_api_version,
223        HAS_GLUT => $glut_api_version,
224    );
225
226
39
    return 1;
227}
228
229sub _handle_no_opengl {
230
1
    my ($self, $conf) = @_;
231
232
1
    $conf->data->set(
233        has_opengl => 0,
234        HAS_OPENGL => 0,
235        opengl_lib => '',
236
237        has_glut => 0,
238        HAS_GLUT => 0,
239    );
240
241
1
    $self->set_result('no');
242
243
1
    return 1;
244}
245
246
2471;
248
249# Local Variables:
250# mode: cperl
251# cperl-indent-level: 4
252# fill-column: 100
253# End:
254# vim: expandtab shiftwidth=4: