… | |
… | |
28 | |
28 | |
29 | our %GL_EXT; |
29 | our %GL_EXT; |
30 | our $GL_VERSION; |
30 | our $GL_VERSION; |
31 | |
31 | |
32 | our $GL_NPOT; |
32 | our $GL_NPOT; |
|
|
33 | our $GL_DEBUG = 1; |
33 | |
34 | |
34 | sub gl_init { |
35 | sub gl_init { |
35 | $GL_VERSION = gl_version * 1; |
36 | $GL_VERSION = gl_version * 1; |
36 | %GL_EXT = map +($_ => 1), split /\s+/, gl_extensions; |
37 | %GL_EXT = map +($_ => 1), split /\s+/, gl_extensions; |
37 | |
38 | |
38 | $GL_NPOT = $GL_EXT{GL_ARB_texture_non_power_of_two} || $GL_VERSION >= 2; |
39 | $GL_NPOT = $GL_EXT{GL_ARB_texture_non_power_of_two} || $GL_VERSION >= 2; |
39 | |
40 | |
40 | glEnable GL_TEXTURE_2D; |
|
|
41 | glEnable GL_COLOR_MATERIAL; |
41 | glDisable GL_COLOR_MATERIAL; |
42 | glShadeModel GL_FLAT; |
42 | glShadeModel GL_FLAT; |
|
|
43 | glDisable GL_DITHER; |
43 | glDisable GL_DEPTH_TEST; |
44 | glDisable GL_DEPTH_TEST; |
44 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
45 | |
|
|
46 | glHint GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST; |
45 | glHint GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST; |
47 | |
46 | |
48 | CFClient::Texture::restore_state (); |
47 | CFClient::Texture::restore_state (); |
|
|
48 | } |
|
|
49 | |
|
|
50 | sub gl_check { |
|
|
51 | return unless $GL_DEBUG; |
|
|
52 | |
|
|
53 | if (my $error = glGetError) { |
|
|
54 | Carp::cluck sprintf "opengl error %x while %s", $error, sprintf @_; |
|
|
55 | } |
49 | } |
56 | } |
50 | |
57 | |
51 | sub find_rcfile($) { |
58 | sub find_rcfile($) { |
52 | my $path; |
59 | my $path; |
53 | |
60 | |
… | |
… | |
298 | $tw, $th, # need to pad texture first |
305 | $tw, $th, # need to pad texture first |
299 | 0, |
306 | 0, |
300 | $self->{format}, |
307 | $self->{format}, |
301 | $self->{type}, |
308 | $self->{type}, |
302 | $data; |
309 | $data; |
303 | if (my $error = glGetError) { |
310 | CFClient::gl_check "uploading texture %dx%d if=%x f=%x t=%x", |
304 | Carp::cluck sprintf "texture upload error: %x %dx%d i=%x f=%x t=%x", |
|
|
305 | $error, $tw, $th, $self->{internalformat}, $self->{format}, $self->{type}; |
311 | $tw, $th, $self->{internalformat}, $self->{format}, $self->{type}; |
306 | } |
|
|
307 | } else { |
312 | } else { |
308 | glCopyTexImage2D GL_TEXTURE_2D, 0, |
313 | glCopyTexImage2D GL_TEXTURE_2D, 0, |
309 | $self->{internalformat}, |
314 | $self->{internalformat}, |
310 | 0, 0, |
315 | 0, 0, |
311 | $tw, $th, |
316 | $tw, $th, |
312 | 0; |
317 | 0; |
313 | if (my $error = glGetError) { |
318 | CFClient::gl_check "copying to texture %dx%d if=%x", |
314 | Carp::cluck sprintf "texture upload error: %x %dx%d i=%x", |
|
|
315 | $error, $tw, $th, $self->{internalformat}; |
319 | $tw, $th, $self->{internalformat}; |
316 | } |
|
|
317 | } |
320 | } |
318 | } |
321 | } |
319 | |
322 | |
320 | sub DESTROY { |
323 | sub DESTROY { |
321 | my ($self) = @_; |
324 | my ($self) = @_; |