ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/OpenGL.pm
Revision: 1.8
Committed: Sun Aug 12 01:49:09 2007 UTC (16 years, 9 months ago) by root
Branch: MAIN
Changes since 1.7: +8 -5 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
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    
13     our $DEBUG = 1;
14     our %INIT_HOOK;
15 root 1.3 our %SHUTDOWN_HOOK;
16 root 1.1
17     sub import {
18     my $caller = caller;
19    
20     no strict;
21    
22 root 1.4 my $symtab = *{"main::CFPlus::OpenGL::"}{HASH};
23 root 1.1
24     for (keys %$symtab) {
25 root 1.2 *{"$caller\::$_"} = *$_
26     if /^(?:gl[A-Z_]|GL_)/;
27 root 1.1 }
28     }
29    
30 root 1.2 sub init {
31 root 1.8 if ($::CFG->{opengl11}) {
32     $GL_VERSION = 1.1;
33     %GL_EXT = ();
34     } else {
35     $GL_VERSION = gl_version * 1;
36     %GL_EXT = map +($_ => 1), split /\s+/, gl_extensions;
37     }
38 root 1.2
39 root 1.8 $GL_NPOT = $GL_EXT{GL_ARB_texture_non_power_of_two} || $GL_VERSION >= 2;
40 root 1.2
41     glDisable GL_COLOR_MATERIAL;
42     glShadeModel GL_FLAT;
43     glDisable GL_DITHER;
44     glDisable GL_DEPTH_TEST;
45     glDepthMask 0;
46 root 1.5
47     my $hint = $::FAST ? GL_FASTEST : GL_NICEST;
48     glHint GL_PERSPECTIVE_CORRECTION_HINT, $hint;
49 root 1.6 glHint GL_POINT_SMOOTH_HINT , $hint;
50 root 1.5 glHint GL_LINE_SMOOTH_HINT , $hint;
51     glHint GL_POLYGON_SMOOTH_HINT , $hint;
52     glHint GL_GENERATE_MIPMAP_HINT , $hint;
53     #glDrawBuffer GL_BACK;
54     #glReadBuffer GL_BACK;
55 root 1.2
56     $_->() for values %INIT_HOOK;
57     }
58    
59 root 1.3 sub shutdown {
60     $_->() for values %SHUTDOWN_HOOK;
61     }
62    
63 root 1.2 sub gl_check {
64     return unless $DEBUG;
65    
66     if (my $error = glGetError) {
67     my ($format, @args) = @_;
68     Carp::cluck sprintf "opengl error %x while $format", $error, @args;
69     }
70     }
71    
72     1;
73