ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cf.schmorp.de/Deliantra-Client/DC/OpenGL.pm
Revision: 1.21
Committed: Sat Apr 3 02:58:25 2010 UTC (14 years, 3 months ago) by root
Branch: MAIN
CVS Tags: rel-2_11, HEAD
Changes since 1.20: +1 -3 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 package DC::OpenGL;
2
3 use common::sense;
4
5 use Carp ();
6 use DC;
7
8 our %GL_EXT;
9 our $GL_VERSION;
10
11 our $GL_NPOT;
12 our $GL_COMPRESS;
13 our $GL_BFSEP; # blendfuncseparate
14 our $GL_MULTITEX;
15 our $APPLE_NVIDIA_BUG;
16
17 our $DEBUG = 1;
18 our %INIT_HOOK;
19 our %SHUTDOWN_HOOK;
20
21 sub import {
22 my $caller = caller;
23
24 my $symtab = *{"main::DC::OpenGL::"}{HASH};
25
26 for (keys %$symtab) {
27 *{"$caller\::$_"} = *$_
28 if /^(?:gl[A-Z_]|GL_)/;
29 }
30 }
31
32 sub init {
33 $GL_VERSION = gl_version * 1;
34 %GL_EXT = map +($_ => 1), split /\s+/, gl_extensions;
35
36 unless (defined $::CFG->{force_opengl11}) {
37 # try to find a suitable default
38 if (
39 $GL_VERSION >= 2.0
40 && (!$GL_EXT{GL_ARB_texture_non_power_of_two}
41 || !$GL_EXT{GL_EXT_blend_func_separate})
42 ) {
43 $::CFG->{force_opengl11} = 1;
44 } else {
45 $::CFG->{force_opengl11} = 0;
46 }
47 }
48
49 if ($::CFG->{force_opengl11}) {
50 $GL_VERSION = 1.1;
51 %GL_EXT = ();
52 }
53
54 $GL_BFSEP = $GL_EXT{GL_EXT_blend_func_separate} || $GL_VERSION >= 2.0;
55 $GL_NPOT = $GL_EXT{GL_ARB_texture_non_power_of_two} || $GL_VERSION >= 2.0;
56 $GL_COMPRESS = $GL_EXT{GL_ARB_texture_compression} || $GL_VERSION >= 1.3;
57 $GL_MULTITEX = $GL_EXT{GL_ARB_multitexture} || $GL_VERSION >= 1.3;
58 $GL_MULTITEX &&= 2 <= glGetInteger GL_MAX_TEXTURE_UNITS;
59
60 $GL_COMPRESS = 0 if DC::OpenGL::gl_vendor eq "Apple Computer, Inc."; # there is no end to their suckage
61
62 $APPLE_NVIDIA_BUG = DC::OpenGL::gl_vendor eq "NVIDIA Corporation" && $^O eq "darwin";
63 apple_nvidia_bug $APPLE_NVIDIA_BUG;
64
65 disable_GL_EXT_blend_func_separate
66 unless $GL_BFSEP;
67
68 glDisable GL_COLOR_MATERIAL;
69 glShadeModel GL_FLAT;
70 glDisable GL_DITHER;
71 glDisable GL_DEPTH_TEST;
72 glDepthMask 0;
73
74 my $hint = $::FAST ? GL_FASTEST : GL_NICEST;
75 glHint GL_PERSPECTIVE_CORRECTION_HINT, $hint;
76 glHint GL_POINT_SMOOTH_HINT , $hint;
77 glHint GL_LINE_SMOOTH_HINT , $hint;
78 glHint GL_POLYGON_SMOOTH_HINT , $hint;
79 glHint GL_GENERATE_MIPMAP_HINT , $hint;
80 glHint GL_TEXTURE_COMPRESSION_HINT , $hint;
81 #glDrawBuffer GL_BACK;
82 #glReadBuffer GL_BACK;
83
84 c_init;
85 $_->() for values %INIT_HOOK;
86 }
87
88 sub quit {
89 undef $GL_VERSION;
90 undef %GL_EXT;
91 }
92
93 sub shutdown {
94 $_->() for values %SHUTDOWN_HOOK;
95
96 quit;
97 }
98
99 sub gl_check {
100 return unless $DEBUG;
101
102 if (my $error = glGetError) {
103 my ($format, @args) = @_;
104 Carp::cluck sprintf "opengl error %x while $format", $error, @args;
105 }
106 }
107
108 1;
109