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