Deliantra-Client

 view release on metacpan or  search on metacpan

DC/Texture.pm  view on Meta::CPAN

=head1 NAME

DC::Texture - tetxure class for Deliantra-Client

=head1 SYNOPSIS

 use DC::Texture;

=head1 DESCRIPTION

=over 4

=cut

package DC::Texture;

use common::sense;

use List::Util qw(max min);
use DC::OpenGL;

my %TEXTURES;
my ($MAX_W, $MAX_H) = (4096, 4096); # maximum texture size attempted by this module

sub new {
   my ($class, %data) = @_;

   my $self = bless {
      internalformat => GL_RGBA,
      format         => GL_RGBA,
      type           => GL_UNSIGNED_BYTE,
      %data,
   }, $class;

   DC::weaken ($TEXTURES{$self+0} = $self);

   $self->upload
      unless delete $self->{delay};

   $self
}

sub new_from_image {
   my ($class, $image, %arg) = @_;

   Carp::confess "tried to create texture from undefined image"
      unless defined $image;

   $class->new (image => $image, internalformat => undef, %arg)
}

sub new_from_resource {
   my ($class, $path, %arg) = @_;

   $class->new (resource_path => $path, internalformat => undef, %arg)
}

#sub new_from_surface {
#   my ($class, $surface) = @_;
#
#   $surface->rgba;
#
#   $class->new (
#      data   => $surface->pixels,
#      w      => $surface->width,
#      h      => $surface->height,
#   )
#}

#sub new_from_layout {
#   my ($class, $layout, %arg) = @_;
#
#   my ($w, $h, $data, $format, $internalformat) = $layout->render;
#
#   $class->new (
#      w              => $w,
#      h              => $h,
#      data           => $data,
#      format         => $format,
#      internalformat => $format,
#      type           => GL_UNSIGNED_BYTE,
#      %arg,
#   )
#}

sub new_from_opengl {
   my ($class, $w, $h, $cb) = @_;

   $class->new (w => $w || 1, h => $h || 1, render_cb => $cb, nearest => 1)
}

sub loading_done($$) {
   my ($self, $data) = @_;

   delete $self->{loading};



( run in 3.058 seconds using v1.01-cache-2.11-cpan-5837b0d9d2c )