mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 02:15:43 -04:00
cube maps and avi textures in bam files
This commit is contained in:
parent
d8d1a0a561
commit
5b17fbd0d9
@ -498,6 +498,9 @@ read_pages(Filename fullpath_pattern, int z_size) {
|
||||
}
|
||||
}
|
||||
|
||||
set_fullpath(fullpath_pattern);
|
||||
clear_alpha_fullpath();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -1614,16 +1617,16 @@ consider_downgrade(PNMImage &pnmimage, int num_channels) {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void Texture::
|
||||
register_with_read_factory() {
|
||||
BamReader::get_factory()->register_factory(get_class_type(), make_Texture);
|
||||
BamReader::get_factory()->register_factory(get_class_type(), make_from_bam);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Texture::make_Texture
|
||||
// Access: Protected
|
||||
// Function: Texture::make_from_bam
|
||||
// Access: Protected, Static
|
||||
// Description: Factory method to generate a Texture object
|
||||
////////////////////////////////////////////////////////////////////
|
||||
TypedWritable *Texture::
|
||||
make_Texture(const FactoryParams ¶ms) {
|
||||
make_from_bam(const FactoryParams ¶ms) {
|
||||
// The process of making a texture is slightly different than making
|
||||
// other TypedWritable objects. That is because all creation of
|
||||
// Textures should be done through calls to TexturePool, which
|
||||
@ -1634,7 +1637,8 @@ make_Texture(const FactoryParams ¶ms) {
|
||||
|
||||
parse_params(params, scan, manager);
|
||||
|
||||
// Get the filenames so we can look up the file on disk first.
|
||||
// Get the filenames and texture type so we can look up the file on
|
||||
// disk first.
|
||||
string name = scan.get_string();
|
||||
Filename filename = scan.get_string();
|
||||
Filename alpha_filename = scan.get_string();
|
||||
@ -1642,6 +1646,7 @@ make_Texture(const FactoryParams ¶ms) {
|
||||
int primary_file_num_channels = scan.get_uint8();
|
||||
int alpha_file_channel = scan.get_uint8();
|
||||
bool has_rawdata = scan.get_bool();
|
||||
TextureType texture_type = (TextureType)scan.get_uint8();
|
||||
|
||||
Texture *me = NULL;
|
||||
if (has_rawdata) {
|
||||
@ -1659,15 +1664,34 @@ make_Texture(const FactoryParams ¶ms) {
|
||||
} else {
|
||||
// This texture does have a filename, so try to load it from disk.
|
||||
VirtualFileSystem *vfs = VirtualFileSystem::get_global_ptr();
|
||||
if (!manager->get_filename().empty())
|
||||
vfs->resolve_filename(filename,manager->get_filename().get_dirname());
|
||||
if (alpha_filename.empty()) {
|
||||
me = TexturePool::load_texture(filename, primary_file_num_channels);
|
||||
} else {
|
||||
if (!manager->get_filename().empty())
|
||||
vfs->resolve_filename(alpha_filename, manager->get_filename().get_dirname());
|
||||
me = TexturePool::load_texture(filename, alpha_filename,
|
||||
primary_file_num_channels, alpha_file_channel);
|
||||
if (!manager->get_filename().empty()) {
|
||||
// If texture filename was given relative to the bam filename,
|
||||
// expand it now.
|
||||
DSearchPath bam_dir = manager->get_filename().get_dirname();
|
||||
vfs->resolve_filename(filename, bam_dir);
|
||||
if (!alpha_filename.empty()) {
|
||||
vfs->resolve_filename(alpha_filename, bam_dir);
|
||||
}
|
||||
}
|
||||
|
||||
switch (texture_type) {
|
||||
case TT_1d_texture:
|
||||
case TT_2d_texture:
|
||||
if (alpha_filename.empty()) {
|
||||
me = TexturePool::load_texture(filename, primary_file_num_channels);
|
||||
} else {
|
||||
me = TexturePool::load_texture(filename, alpha_filename,
|
||||
primary_file_num_channels, alpha_file_channel);
|
||||
}
|
||||
break;
|
||||
|
||||
case TT_3d_texture:
|
||||
me = TexturePool::load_3d_texture(filename);
|
||||
break;
|
||||
|
||||
case TT_cube_map:
|
||||
me = TexturePool::load_cube_map(filename);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1697,8 +1721,6 @@ make_Texture(const FactoryParams ¶ms) {
|
||||
void Texture::
|
||||
fillin(DatagramIterator &scan, BamReader *manager, bool has_rawdata) {
|
||||
// We have already read in the filenames; don't read them again.
|
||||
|
||||
_texture_type = (TextureType)scan.get_uint8();
|
||||
_wrap_u = (WrapMode)scan.get_uint8();
|
||||
_wrap_v = (WrapMode)scan.get_uint8();
|
||||
_wrap_w = (WrapMode)scan.get_uint8();
|
||||
@ -1804,9 +1826,9 @@ write_datagram(BamWriter *manager, Datagram &me) {
|
||||
me.add_uint8(_primary_file_num_channels);
|
||||
me.add_uint8(_alpha_file_channel);
|
||||
me.add_bool(has_rawdata);
|
||||
me.add_uint8(_texture_type);
|
||||
|
||||
// The data beginning at this point is handled by fillin().
|
||||
me.add_uint8(_texture_type);
|
||||
me.add_uint8(_wrap_u);
|
||||
me.add_uint8(_wrap_v);
|
||||
me.add_uint8(_wrap_w);
|
||||
|
@ -356,12 +356,11 @@ protected:
|
||||
// Datagram stuff
|
||||
public:
|
||||
static void register_with_read_factory();
|
||||
virtual void write_datagram(BamWriter* manager, Datagram &me);
|
||||
|
||||
static TypedWritable *make_Texture(const FactoryParams ¶ms);
|
||||
virtual void write_datagram(BamWriter *manager, Datagram &me);
|
||||
|
||||
protected:
|
||||
void fillin(DatagramIterator& scan, BamReader* manager, bool has_rawdata = false);
|
||||
static TypedWritable *make_from_bam(const FactoryParams ¶ms);
|
||||
void fillin(DatagramIterator &scan, BamReader *manager, bool has_rawdata);
|
||||
|
||||
public:
|
||||
static TypeHandle get_class_type() {
|
||||
|
@ -298,6 +298,7 @@ ns_load_texture(const Filename &orig_filename,
|
||||
Texture *TexturePool::
|
||||
ns_load_3d_texture(const Filename &filename_pattern) {
|
||||
Filename filename(filename_pattern);
|
||||
filename.set_pattern(true);
|
||||
|
||||
VirtualFileSystem *vfs = VirtualFileSystem::get_global_ptr();
|
||||
vfs->resolve_filename(filename, get_texture_path()) ||
|
||||
@ -317,6 +318,7 @@ ns_load_3d_texture(const Filename &filename_pattern) {
|
||||
if (!tex->read_pages(filename)) {
|
||||
// This texture was not found or could not be read.
|
||||
report_texture_unreadable(filename);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Set the original filename, before we searched along the path.
|
||||
@ -334,6 +336,7 @@ ns_load_3d_texture(const Filename &filename_pattern) {
|
||||
Texture *TexturePool::
|
||||
ns_load_cube_map(const Filename &filename_pattern) {
|
||||
Filename filename(filename_pattern);
|
||||
filename.set_pattern(true);
|
||||
|
||||
VirtualFileSystem *vfs = VirtualFileSystem::get_global_ptr();
|
||||
vfs->resolve_filename(filename, get_texture_path()) ||
|
||||
@ -353,6 +356,7 @@ ns_load_cube_map(const Filename &filename_pattern) {
|
||||
if (!tex->read_pages(filename)) {
|
||||
// This texture was not found or could not be read.
|
||||
report_texture_unreadable(filename);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Set the original filename, before we searched along the path.
|
||||
|
@ -17,40 +17,6 @@
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: VideoTexture::set_power_2
|
||||
// Access: Published
|
||||
// Description: Sets the flag that indicates whether a newly-loaded
|
||||
// VideoTexture will be constrained to dimensions that are
|
||||
// a power of 2 or not. If true, then a newly-loaded
|
||||
// video stream will be set within the smallest power of
|
||||
// 2 texture that will fit it; if false, a newly-loaded
|
||||
// video stream will be set within a texture that
|
||||
// exactly fits it, even if that means creating a
|
||||
// texture whose dimensions are not a power of 2.
|
||||
//
|
||||
// This must be set before the first call to read().
|
||||
// The default value is false if the Config.prc variable
|
||||
// textures-power-2 is "none", true otherwise.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void VideoTexture::
|
||||
set_power_2(bool power_2) {
|
||||
_power_2 = power_2;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: VideoTexture::get_power_2
|
||||
// Access: Published
|
||||
// Description: Returns the flag that indicates whether a
|
||||
// newly-loaded VideoTexture will be constrained to
|
||||
// dimensions that are a power of 2 or not. See
|
||||
// set_power_2().
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE bool VideoTexture::
|
||||
get_power_2() const {
|
||||
return _power_2;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: VideoTexture::get_video_width
|
||||
// Access: Published
|
||||
|
@ -33,7 +33,6 @@ VideoTexture::
|
||||
VideoTexture(const string &name) :
|
||||
Texture(name)
|
||||
{
|
||||
_power_2 = (textures_power_2 != ATS_none);
|
||||
_video_width = 0;
|
||||
_video_height = 0;
|
||||
|
||||
@ -50,7 +49,6 @@ VideoTexture::
|
||||
VideoTexture(const VideoTexture ©) :
|
||||
Texture(copy),
|
||||
AnimInterface(copy),
|
||||
_power_2(copy._power_2),
|
||||
_video_width(copy._video_width),
|
||||
_video_height(copy._video_height),
|
||||
_last_frame_update(copy._last_frame_update),
|
||||
|
@ -37,9 +37,6 @@ protected:
|
||||
VideoTexture(const VideoTexture ©);
|
||||
|
||||
PUBLISHED:
|
||||
INLINE void set_power_2(bool power_2);
|
||||
INLINE bool get_power_2() const;
|
||||
|
||||
virtual bool has_ram_image() const;
|
||||
virtual bool get_keep_ram_image() const;
|
||||
|
||||
@ -62,7 +59,6 @@ protected:
|
||||
virtual void update_frame(int frame)=0;
|
||||
|
||||
private:
|
||||
bool _power_2;
|
||||
int _video_width;
|
||||
int _video_height;
|
||||
int _last_frame_update;
|
||||
|
@ -67,6 +67,7 @@ init_libgrutil() {
|
||||
|
||||
#ifdef HAVE_OPENCV
|
||||
OpenCVTexture::init_type();
|
||||
OpenCVTexture::register_with_read_factory();
|
||||
|
||||
PandaSystem *ps = PandaSystem::get_global_ptr();
|
||||
ps->add_system("OpenCV");
|
||||
|
@ -278,7 +278,7 @@ reconsider_video_properties(const OpenCVTexture::VideoStream &stream,
|
||||
int x_size = width;
|
||||
int y_size = height;
|
||||
|
||||
if (get_power_2()) {
|
||||
if (textures_power_2 != ATS_none) {
|
||||
x_size = up_to_power_2(width);
|
||||
y_size = up_to_power_2(height);
|
||||
}
|
||||
@ -409,6 +409,27 @@ update_frame(int frame) {
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: OpenCVTexture::register_with_read_factory
|
||||
// Access: Public, Static
|
||||
// Description: Factory method to generate a Texture object
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void OpenCVTexture::
|
||||
register_with_read_factory() {
|
||||
// Since Texture is such a funny object that is reloaded from the
|
||||
// TexturePool each time, instead of actually being read fully from
|
||||
// the bam file, and since the VideoTexture and OpenCVTexture
|
||||
// classes don't really add any useful data to the bam record, we
|
||||
// don't need to define make_from_bam(), fillin(), or
|
||||
// write_datagram() in this class--we just inherit the same
|
||||
// functions from Texture.
|
||||
|
||||
// We do, however, have to register this class with the BamReader,
|
||||
// to avoid warnings about creating the wrong kind of object from
|
||||
// the bam file.
|
||||
BamReader::get_factory()->register_factory(get_class_type(), make_from_bam);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: OpenCVTexture::VideoStream::Constructor
|
||||
// Access: Public
|
||||
|
@ -100,6 +100,9 @@ private:
|
||||
typedef pvector<VideoPage> Pages;
|
||||
Pages _pages;
|
||||
|
||||
public:
|
||||
static void register_with_read_factory();
|
||||
|
||||
public:
|
||||
static TypeHandle get_class_type() {
|
||||
return _type_handle;
|
||||
|
Loading…
x
Reference in New Issue
Block a user