ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/OpenGL.pm
(Generate patch)

Comparing deliantra/Deliantra-Client/DC/OpenGL.pm (file contents):
Revision 1.1 by root, Wed Apr 19 23:37:49 2006 UTC vs.
Revision 1.13 by root, Wed Dec 26 20:46:39 2007 UTC

1package CFClient::OpenGL; 1package dc::OpenGL;
2 2
3use strict; 3use strict;
4 4
5#use CFClient; 5use Carp ();
6use dc;
7
8our %GL_EXT;
9our $GL_VERSION;
10
11our $GL_NPOT;
12our $GL_COMPRESS;
13our $GL_BFSEP; # blendfuncseparate
14
15our $DEBUG = 1;
16our %INIT_HOOK;
17our %SHUTDOWN_HOOK;
6 18
7sub import { 19sub import {
8 my $caller = caller; 20 my $caller = caller;
9 21
10 no strict; 22 no strict;
11 23
12 my $symtab = *{"main::CFClient::OpenGL::"}{HASH}; 24 my $symtab = *{"main::dc::OpenGL::"}{HASH};
13 25
14 for (keys %$symtab) { 26 for (keys %$symtab) {
15 *{"$caller\::$_"} = \&$_ 27 *{"$caller\::$_"} = *$_
16 if /^(?:gl|GL_)/; 28 if /^(?:gl[A-Z_]|GL_)/;
17 } 29 }
18} 30}
19 31
201 32sub 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
58 disable_GL_EXT_blend_func_separate
59 unless $GL_BFSEP;
60
61 glDisable GL_COLOR_MATERIAL;
62 glShadeModel GL_FLAT;
63 glDisable GL_DITHER;
64 glDisable GL_DEPTH_TEST;
65 glDepthMask 0;
66
67 my $hint = $::FAST ? GL_FASTEST : GL_NICEST;
68 glHint GL_PERSPECTIVE_CORRECTION_HINT, $hint;
69 glHint GL_POINT_SMOOTH_HINT , $hint;
70 glHint GL_LINE_SMOOTH_HINT , $hint;
71 glHint GL_POLYGON_SMOOTH_HINT , $hint;
72 glHint GL_GENERATE_MIPMAP_HINT , $hint;
73 glHint GL_TEXTURE_COMPRESSION_HINT , $hint;
74 #glDrawBuffer GL_BACK;
75 #glReadBuffer GL_BACK;
76
77 $_->() for values %INIT_HOOK;
78}
79
80sub quit {
81 undef $GL_VERSION;
82 undef %GL_EXT;
83}
84
85sub shutdown {
86 $_->() for values %SHUTDOWN_HOOK;
87
88 quit;
89}
90
91sub gl_check {
92 return unless $DEBUG;
93
94 if (my $error = glGetError) {
95 my ($format, @args) = @_;
96 Carp::cluck sprintf "opengl error %x while $format", $error, @args;
97 }
98}
99
1001;
101

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines