On Sun, 20 Apr 2008 00:02:18 -0700 Geoffrey Broadwell <[EMAIL PROTECTED]> wrote:
> OK, I've done some more research on differences between various GLUT > libraries; please try the attached patch rather than the one from > tentra (mine includes his with a couple changes and several > additions). I ran into a few minor problems testing this: 1. Some trailing whitespace was flagging a couple of codingstd failures. 2. fperrad's r27055 checkin (a mingw header name fix) conflicted and needed to be merged. 3. kid51's tests were breaking because the internals of your opengl configuration modules changed, and the expected return values didn't match. r27058 disabled those tests for now, so they're not an issue. (Thanks, Jim.) I fixed the trailing whitespace, and reverted r27055. The attached patch detects successfully, example runs, and passes all tests for me on linux/amd64. I applied it to r27058. fperrad, I believe this patch will cover the issue you patched in r27055, but in a different way. Can you please verify that this works for you on mingw32? Thanks, Mark
Index: runtime/parrot/library/OpenGL.pir =================================================================== --- runtime/parrot/library/OpenGL.pir (revision 27058) +++ runtime/parrot/library/OpenGL.pir (working copy) @@ -56,16 +56,19 @@ libnames = new 'ResizableStringArray' push libnames, 'libGL' + push libnames, '/System/Library/Frameworks/OpenGL.framework/OpenGL' libgl = load_lib_with_fallbacks('GL', libnames) set_global 'libgl', libgl libnames = new 'ResizableStringArray' push libnames, 'libGLU' + push libnames, '/System/Library/Frameworks/OpenGL.framework/OpenGL' libglu = load_lib_with_fallbacks('GLU', libnames) set_global 'libglu', libglu libnames = new 'ResizableStringArray' push libnames, 'libglut' + push libnames, '/System/Library/Frameworks/GLUT.framework/GLUT' libglut = load_lib_with_fallbacks('GLUT', libnames) set_global 'libglut', libglut Index: config/auto/opengl.pm =================================================================== --- config/auto/opengl.pm (revision 27058) +++ config/auto/opengl.pm (working copy) @@ -66,8 +66,7 @@ eval { $conf->cc_build() }; if ( !$@ ) { my $test = $conf->cc_run(); - $has_glut = $self->_evaluate_cc_run($test, $verbose); - _handle_glut($conf, $has_glut); + $has_glut = _handle_glut($conf, $self->_evaluate_cc_run($test, $verbose)); } unless ($has_glut) { # The Parrot::Configure settings might have changed while class ran @@ -88,6 +87,9 @@ $conf->data->add( ' ', libs => 'glut.lib glu.lib gl.lib' ); } } + elsif ( $osname =~ /darwin/i ) { + $conf->data->add( ' ', libs => '-framework OpenGL -framework GLUT' ); + } else { $conf->data->add( ' ', libs => '-lglut -lGLU -lGL' ); } @@ -96,25 +98,29 @@ sub _evaluate_cc_run { my ($self, $test, $verbose) = @_; - chomp $test; - my $has_glut = $test; - print " (yes, GLUT API $has_glut) " if $verbose; - $self->set_result("yes, GLUT $has_glut"); - return $has_glut; + my ($glut_api_version, $glut_brand) = split ' ', $test; + + print " (yes, $glut_brand API version $glut_api_version) " if $verbose; + $self->set_result("yes, $glut_brand $glut_api_version"); + + return ($glut_api_version, $glut_brand); } sub _handle_glut { - my ($conf, $has_glut) = @_; + my ($conf, $glut_api_version, $glut_brand) = @_; + $conf->data->set( # Completely cargo culted opengl => 'define', - has_opengl => $has_glut, - HAS_OPENGL => $has_glut, + has_opengl => 1, + HAS_OPENGL => 1, glut => 'define', - has_glut => $has_glut, - HAS_GLUT => $has_glut, + glut_brand => $glut_brand, + has_glut => $glut_api_version, + HAS_GLUT => $glut_api_version, ); + return 1; } Index: config/auto/opengl/opengl.in =================================================================== --- config/auto/opengl/opengl.in (revision 27058) +++ config/auto/opengl/opengl.in (working copy) @@ -4,9 +4,11 @@ #include <stdio.h> #include <stdlib.h> -/* XXXX: This location is platform dependent. What's the preferred - way to find headers that move? */ +#ifdef __APPLE_CC__ +#include <GLUT/glut.h> +#else #include <GL/glut.h> +#endif int main(int argc, char *argv[]) @@ -15,6 +17,16 @@ printf("glutInit is NULL\n"); return EXIT_FAILURE; } - printf("%d\n", GLUT_API_VERSION); + +#ifdef OPENGLUT + printf("%d OpenGLUT\n", GLUT_API_VERSION); +#elif FREEGLUT + printf("%d freeglut\n", GLUT_API_VERSION); +#elif GLUT_MACOSX_IMPLEMENTATION + printf("%d MacOSX_GLUT\n", GLUT_API_VERSION); +#else + printf("%d GLUT\n", GLUT_API_VERSION); +#endif + return EXIT_SUCCESS; } Index: config/gen/opengl.pm =================================================================== --- config/gen/opengl.pm (revision 27058) +++ config/gen/opengl.pm (working copy) @@ -60,18 +60,25 @@ ); my @GLUT_4_CALLBACKS = ( - [ 'Close', 'void' ], - [ 'Menu Destroy', 'void' ], - [ 'WM Close', 'void' ], [ 'Window Status', 'int state' ], [ 'Keyboard Up', 'unsigned char key, int x, int y' ], [ 'Special Up', 'int key, int x, int y' ], - [ 'Mouse Wheel', 'int wheel, int direction, int x, int y' ], # NOTE: Hardcoded because of special arguments # [ 'Joystick', 'int buttons, int xaxis, int yaxis, int zaxis' ], ); +my @MACOSXGLUT_CALLBACKS = ( + # Also works in freeglut + [ 'WM Close', 'void' ], +); + +my @FREEGLUT_CALLBACKS = ( + [ 'Close', 'void' ], + [ 'Menu Destroy', 'void' ], + [ 'Mouse Wheel', 'int wheel, int direction, int x, int y' ], +); + my $MACRO_FILE = 'runtime/parrot/include/opengl_defines.pasm'; my $C_FILE = 'src/glut_callbacks.c'; @@ -93,23 +100,29 @@ return 1; } - $self->gen_opengl_defines($conf); + my @header_globs = ( + '/usr/include/GL/*.h', + '/System/Library/Frameworks/OpenGL.framework/Headers/*.h', + '/System/Library/Frameworks/GLUT.framework/Headers/*.h', + ); + + my @header_files = sort map {glob} @header_globs; + + $self->gen_opengl_defines($conf, [EMAIL PROTECTED]); $self->gen_glut_callbacks($conf); return 1; } sub gen_opengl_defines { - my ( $self, $conf ) = @_; + my ( $self, $conf, $header_files ) = @_; my $verbose = $conf->options->get('verbose'); - my @header_files = glob '/usr/include/GL/*.h'; - my (%defs, @macros); my $max_len = 0; - foreach my $file (@header_files) { + foreach my $file (@$header_files) { open my $header, '<', $file or die "Could not open header '$file': $!"; @@ -157,7 +170,7 @@ # HEADER - print $macros "# $_\n" foreach sort @header_files; + print $macros "# $_\n" foreach @$header_files; print $macros "\n\n"; foreach my $api (sort keys %defs) { @@ -177,12 +190,22 @@ sub gen_glut_callbacks { my ( $self, $conf ) = @_; - my $glut_api = $conf->data->get('has_glut'); + my $glut_api = $conf->data->get('has_glut'); + my $glut_brand = $conf->data->get('glut_brand'); + my @glut_callbacks = @GLUT_1_CALLBACKS; - push @glut_callbacks, @GLUT_2_CALLBACKS if $glut_api >= 2; - push @glut_callbacks, @GLUT_3_CALLBACKS if $glut_api >= 3; - push @glut_callbacks, @GLUT_4_CALLBACKS if $glut_api >= 4; + push @glut_callbacks, @GLUT_2_CALLBACKS if $glut_api >= 2; + push @glut_callbacks, @GLUT_3_CALLBACKS if $glut_api >= 3; + push @glut_callbacks, @GLUT_4_CALLBACKS if $glut_api >= 4; + push @glut_callbacks, @FREEGLUT_CALLBACKS if $glut_brand eq 'freeglut'; + push @glut_callbacks, @MACOSXGLUT_CALLBACKS if $glut_brand eq 'freeglut' + or $glut_brand eq 'MacOSX_GLUT'; + my $glut_header = $glut_brand eq 'MacOSX_GLUT' ? 'GLUT/glut.h' : + $glut_brand eq 'OpenGLUT' ? 'GL/openglut.h' : + $glut_brand eq 'freeglut' ? 'GL/freeglut.h' : + 'GL/glut.h' ; + my @callbacks; foreach my $raw (@glut_callbacks) { my ($friendly, $params) = @$raw; @@ -260,11 +283,7 @@ */ -#ifdef WIN32 -#include <GL/glut.h> -#else -#include <GL/freeglut.h> -#endif +#include <$glut_header> #include "parrot/parrot.h"