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

Comparing deliantra/Deliantra-Client/DC/Texture.pm (file contents):
Revision 1.8 by root, Sat Jun 17 15:07:53 2006 UTC vs.
Revision 1.12 by root, Sun Aug 13 16:29:36 2006 UTC

1=head1 NAME 1=head1 NAME
2 2
3CFClient::Texture - tetxure class for CFClient 3CFPlus::Texture - tetxure class for CFPlus
4 4
5=head1 SYNOPSIS 5=head1 SYNOPSIS
6 6
7 use CFClient::Texture; 7 use CFPlus::Texture;
8 8
9=head1 DESCRIPTION 9=head1 DESCRIPTION
10 10
11=over 4 11=over 4
12 12
13=cut 13=cut
14 14
15package CFClient::Texture; 15package CFPlus::Texture;
16 16
17use strict; 17use strict;
18 18
19use Scalar::Util; 19use Scalar::Util;
20 20
21use CFClient::OpenGL; 21use CFPlus::OpenGL;
22 22
23my %TEXTURES; 23my %TEXTURES;
24 24
25sub new { 25sub new {
26 my ($class, %data) = @_; 26 my ($class, %data) = @_;
65# w => $surface->width, 65# w => $surface->width,
66# h => $surface->height, 66# h => $surface->height,
67# ) 67# )
68#} 68#}
69 69
70sub new_from_layout { 70#sub new_from_layout {
71 my ($class, $layout, %arg) = @_; 71# my ($class, $layout, %arg) = @_;
72 72#
73 my ($w, $h, $data, $format, $internalformat) = $layout->render; 73# my ($w, $h, $data, $format, $internalformat) = $layout->render;
74 74#
75 $class->new ( 75# $class->new (
76 w => $w, 76# w => $w,
77 h => $h, 77# h => $h,
78 data => $data, 78# data => $data,
79 format => $format, 79# format => $format,
80 internalformat => $format, 80# internalformat => $format,
81 type => GL_UNSIGNED_BYTE, 81# type => GL_UNSIGNED_BYTE,
82 %arg, 82# %arg,
83 ) 83# )
84} 84#}
85 85
86sub new_from_opengl { 86sub new_from_opengl {
87 my ($class, $w, $h, $cb) = @_; 87 my ($class, $w, $h, $cb) = @_;
88 88
89 $class->new (w => $w || 1, h => $h || 1, render_cb => $cb) 89 $class->new (w => $w || 1, h => $h || 1, render_cb => $cb, nearest => 1)
90} 90}
91 91
92sub upload { 92sub upload {
93 my ($self) = @_; 93 my ($self) = @_;
94 94
108 glLoadIdentity; 108 glLoadIdentity;
109 $self->{render_cb}->($self, $self->{w}, $self->{h}); 109 $self->{render_cb}->($self, $self->{w}, $self->{h});
110 110
111 } else { 111 } else {
112 ($self->{w}, $self->{h}, $data, my $internalformat, $self->{format}, $self->{type}) 112 ($self->{w}, $self->{h}, $data, my $internalformat, $self->{format}, $self->{type})
113 = CFClient::load_image_inline $self->{image}; 113 = CFPlus::load_image_inline $self->{image};
114 114
115 $self->{internalformat} ||= $internalformat; 115 $self->{internalformat} ||= $internalformat;
116 } 116 }
117 117
118 my ($tw, $th) = @$self{qw(w h)}; 118 my ($tw, $th) = @$self{qw(w h)};
119 119
120 $self->{minified} ||= [CFClient::average $tw, $th, $data] 120 $self->{minified} ||= [CFPlus::average $tw, $th, $data]
121 if $self->{minify}; 121 if $self->{minify};
122 122
123 pad2pot $data, $tw, $th unless $GL_NPOT; 123 pad2pot $data, $tw, $th unless $GL_NPOT;
124 124
125 $self->{s} = $self->{w} / $tw; 125 $self->{s} = $self->{w} / $tw;
135 } else { 135 } else {
136 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, $GL_VERSION >= 1.2 ? GL_CLAMP_TO_EDGE : GL_CLAMP; 136 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, $GL_VERSION >= 1.2 ? GL_CLAMP_TO_EDGE : GL_CLAMP;
137 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, $GL_VERSION >= 1.2 ? GL_CLAMP_TO_EDGE : GL_CLAMP; 137 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, $GL_VERSION >= 1.2 ? GL_CLAMP_TO_EDGE : GL_CLAMP;
138 } 138 }
139 139
140 if ($::FAST) { 140 if ($::FAST || $self->{nearest}) {
141 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST; 141 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST;
142 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST; 142 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST;
143 } elsif ($self->{mipmap} && $GL_VERSION >= 1.4) { 143 } elsif ($self->{mipmap} && $GL_VERSION >= 1.4) {
144 glTexParameter GL_TEXTURE_2D, GL_GENERATE_MIPMAP, 1; 144 glTexParameter GL_TEXTURE_2D, GL_GENERATE_MIPMAP, 1;
145 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR; 145 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR;
161 $self->{type}, 161 $self->{type},
162 $data; 162 $data;
163 gl_check "uploading texture %dx%d if=%x f=%x t=%x", 163 gl_check "uploading texture %dx%d if=%x f=%x t=%x",
164 $tw, $th, $self->{internalformat}, $self->{format}, $self->{type}; 164 $tw, $th, $self->{internalformat}, $self->{format}, $self->{type};
165 } else { 165 } else {
166 exists $self->{render_cb} or die;
166 glCopyTexImage2D GL_TEXTURE_2D, 0, 167 glCopyTexImage2D GL_TEXTURE_2D, 0,
167 $self->{internalformat}, 168 $self->{internalformat},
168 0, 0, 169 0, 0,
169 $tw, $th, 170 $tw, $th,
170 0; 171 0;
174} 175}
175 176
176sub shutdown { 177sub shutdown {
177 my ($self) = @_; 178 my ($self) = @_;
178 179
179 glDeleteTexture delete $self->{name} 180 glDeleteTexture $self->{name}
180 if $self->{name}; 181 if $self->{name};
181} 182}
182 183
183sub DESTROY { 184sub DESTROY {
184 my ($self) = @_; 185 my ($self) = @_;
186 delete $TEXTURES{$self+0}; 187 delete $TEXTURES{$self+0};
187 188
188 $self->shutdown; 189 $self->shutdown;
189} 190}
190 191
191$CFClient::OpenGL::INIT_HOOK{"CFClient::Texture"} = sub { 192$CFPlus::OpenGL::INIT_HOOK{"CFPlus::Texture"} = sub {
193 # first mark all existing texture names as in-use, in case the context lost textures
194 glBindTexture GL_TEXTURE_2D, $_->{name}
195 for values %TEXTURES;
192 $_->upload 196 $_->upload
193 for values %TEXTURES; 197 for values %TEXTURES;
194}; 198};
195 199
196$CFClient::OpenGL::SHUTDOWN_HOOK{"CFClient::Texture"} = sub { 200$CFPlus::OpenGL::SHUTDOWN_HOOK{"CFPlus::Texture"} = sub {
197 $_->shutdown 201 $_->shutdown
198 for values %TEXTURES; 202 for values %TEXTURES;
199}; 203};
200 204
2011; 2051;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines