cube maps and avi textures in bam files

This commit is contained in:
David Rose 2005-09-23 21:31:31 +00:00
parent d8d1a0a561
commit 5b17fbd0d9
9 changed files with 72 additions and 62 deletions

View File

@ -498,6 +498,9 @@ read_pages(Filename fullpath_pattern, int z_size) {
} }
} }
set_fullpath(fullpath_pattern);
clear_alpha_fullpath();
return true; return true;
} }
@ -1614,16 +1617,16 @@ consider_downgrade(PNMImage &pnmimage, int num_channels) {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
void Texture:: void Texture::
register_with_read_factory() { 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 // Function: Texture::make_from_bam
// Access: Protected // Access: Protected, Static
// Description: Factory method to generate a Texture object // Description: Factory method to generate a Texture object
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
TypedWritable *Texture:: TypedWritable *Texture::
make_Texture(const FactoryParams &params) { make_from_bam(const FactoryParams &params) {
// The process of making a texture is slightly different than making // The process of making a texture is slightly different than making
// other TypedWritable objects. That is because all creation of // other TypedWritable objects. That is because all creation of
// Textures should be done through calls to TexturePool, which // Textures should be done through calls to TexturePool, which
@ -1634,7 +1637,8 @@ make_Texture(const FactoryParams &params) {
parse_params(params, scan, manager); 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(); string name = scan.get_string();
Filename filename = scan.get_string(); Filename filename = scan.get_string();
Filename alpha_filename = scan.get_string(); Filename alpha_filename = scan.get_string();
@ -1642,6 +1646,7 @@ make_Texture(const FactoryParams &params) {
int primary_file_num_channels = scan.get_uint8(); int primary_file_num_channels = scan.get_uint8();
int alpha_file_channel = scan.get_uint8(); int alpha_file_channel = scan.get_uint8();
bool has_rawdata = scan.get_bool(); bool has_rawdata = scan.get_bool();
TextureType texture_type = (TextureType)scan.get_uint8();
Texture *me = NULL; Texture *me = NULL;
if (has_rawdata) { if (has_rawdata) {
@ -1659,15 +1664,34 @@ make_Texture(const FactoryParams &params) {
} else { } else {
// This texture does have a filename, so try to load it from disk. // This texture does have a filename, so try to load it from disk.
VirtualFileSystem *vfs = VirtualFileSystem::get_global_ptr(); VirtualFileSystem *vfs = VirtualFileSystem::get_global_ptr();
if (!manager->get_filename().empty()) if (!manager->get_filename().empty()) {
vfs->resolve_filename(filename,manager->get_filename().get_dirname()); // If texture filename was given relative to the bam filename,
if (alpha_filename.empty()) { // expand it now.
me = TexturePool::load_texture(filename, primary_file_num_channels); DSearchPath bam_dir = manager->get_filename().get_dirname();
} else { vfs->resolve_filename(filename, bam_dir);
if (!manager->get_filename().empty()) if (!alpha_filename.empty()) {
vfs->resolve_filename(alpha_filename, manager->get_filename().get_dirname()); vfs->resolve_filename(alpha_filename, bam_dir);
me = TexturePool::load_texture(filename, alpha_filename, }
primary_file_num_channels, alpha_file_channel); }
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 &params) {
void Texture:: void Texture::
fillin(DatagramIterator &scan, BamReader *manager, bool has_rawdata) { fillin(DatagramIterator &scan, BamReader *manager, bool has_rawdata) {
// We have already read in the filenames; don't read them again. // 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_u = (WrapMode)scan.get_uint8();
_wrap_v = (WrapMode)scan.get_uint8(); _wrap_v = (WrapMode)scan.get_uint8();
_wrap_w = (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(_primary_file_num_channels);
me.add_uint8(_alpha_file_channel); me.add_uint8(_alpha_file_channel);
me.add_bool(has_rawdata); me.add_bool(has_rawdata);
me.add_uint8(_texture_type);
// The data beginning at this point is handled by fillin(). // The data beginning at this point is handled by fillin().
me.add_uint8(_texture_type);
me.add_uint8(_wrap_u); me.add_uint8(_wrap_u);
me.add_uint8(_wrap_v); me.add_uint8(_wrap_v);
me.add_uint8(_wrap_w); me.add_uint8(_wrap_w);

View File

@ -356,12 +356,11 @@ protected:
// Datagram stuff // Datagram stuff
public: public:
static void register_with_read_factory(); static void register_with_read_factory();
virtual void write_datagram(BamWriter* manager, Datagram &me); virtual void write_datagram(BamWriter *manager, Datagram &me);
static TypedWritable *make_Texture(const FactoryParams &params);
protected: protected:
void fillin(DatagramIterator& scan, BamReader* manager, bool has_rawdata = false); static TypedWritable *make_from_bam(const FactoryParams &params);
void fillin(DatagramIterator &scan, BamReader *manager, bool has_rawdata);
public: public:
static TypeHandle get_class_type() { static TypeHandle get_class_type() {

View File

@ -298,6 +298,7 @@ ns_load_texture(const Filename &orig_filename,
Texture *TexturePool:: Texture *TexturePool::
ns_load_3d_texture(const Filename &filename_pattern) { ns_load_3d_texture(const Filename &filename_pattern) {
Filename filename(filename_pattern); Filename filename(filename_pattern);
filename.set_pattern(true);
VirtualFileSystem *vfs = VirtualFileSystem::get_global_ptr(); VirtualFileSystem *vfs = VirtualFileSystem::get_global_ptr();
vfs->resolve_filename(filename, get_texture_path()) || vfs->resolve_filename(filename, get_texture_path()) ||
@ -317,6 +318,7 @@ ns_load_3d_texture(const Filename &filename_pattern) {
if (!tex->read_pages(filename)) { if (!tex->read_pages(filename)) {
// This texture was not found or could not be read. // This texture was not found or could not be read.
report_texture_unreadable(filename); report_texture_unreadable(filename);
return NULL;
} }
// Set the original filename, before we searched along the path. // Set the original filename, before we searched along the path.
@ -334,6 +336,7 @@ ns_load_3d_texture(const Filename &filename_pattern) {
Texture *TexturePool:: Texture *TexturePool::
ns_load_cube_map(const Filename &filename_pattern) { ns_load_cube_map(const Filename &filename_pattern) {
Filename filename(filename_pattern); Filename filename(filename_pattern);
filename.set_pattern(true);
VirtualFileSystem *vfs = VirtualFileSystem::get_global_ptr(); VirtualFileSystem *vfs = VirtualFileSystem::get_global_ptr();
vfs->resolve_filename(filename, get_texture_path()) || vfs->resolve_filename(filename, get_texture_path()) ||
@ -353,6 +356,7 @@ ns_load_cube_map(const Filename &filename_pattern) {
if (!tex->read_pages(filename)) { if (!tex->read_pages(filename)) {
// This texture was not found or could not be read. // This texture was not found or could not be read.
report_texture_unreadable(filename); report_texture_unreadable(filename);
return NULL;
} }
// Set the original filename, before we searched along the path. // Set the original filename, before we searched along the path.

View File

@ -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 // Function: VideoTexture::get_video_width
// Access: Published // Access: Published

View File

@ -33,7 +33,6 @@ VideoTexture::
VideoTexture(const string &name) : VideoTexture(const string &name) :
Texture(name) Texture(name)
{ {
_power_2 = (textures_power_2 != ATS_none);
_video_width = 0; _video_width = 0;
_video_height = 0; _video_height = 0;
@ -50,7 +49,6 @@ VideoTexture::
VideoTexture(const VideoTexture &copy) : VideoTexture(const VideoTexture &copy) :
Texture(copy), Texture(copy),
AnimInterface(copy), AnimInterface(copy),
_power_2(copy._power_2),
_video_width(copy._video_width), _video_width(copy._video_width),
_video_height(copy._video_height), _video_height(copy._video_height),
_last_frame_update(copy._last_frame_update), _last_frame_update(copy._last_frame_update),

View File

@ -37,9 +37,6 @@ protected:
VideoTexture(const VideoTexture &copy); VideoTexture(const VideoTexture &copy);
PUBLISHED: PUBLISHED:
INLINE void set_power_2(bool power_2);
INLINE bool get_power_2() const;
virtual bool has_ram_image() const; virtual bool has_ram_image() const;
virtual bool get_keep_ram_image() const; virtual bool get_keep_ram_image() const;
@ -62,7 +59,6 @@ protected:
virtual void update_frame(int frame)=0; virtual void update_frame(int frame)=0;
private: private:
bool _power_2;
int _video_width; int _video_width;
int _video_height; int _video_height;
int _last_frame_update; int _last_frame_update;

View File

@ -67,6 +67,7 @@ init_libgrutil() {
#ifdef HAVE_OPENCV #ifdef HAVE_OPENCV
OpenCVTexture::init_type(); OpenCVTexture::init_type();
OpenCVTexture::register_with_read_factory();
PandaSystem *ps = PandaSystem::get_global_ptr(); PandaSystem *ps = PandaSystem::get_global_ptr();
ps->add_system("OpenCV"); ps->add_system("OpenCV");

View File

@ -278,7 +278,7 @@ reconsider_video_properties(const OpenCVTexture::VideoStream &stream,
int x_size = width; int x_size = width;
int y_size = height; int y_size = height;
if (get_power_2()) { if (textures_power_2 != ATS_none) {
x_size = up_to_power_2(width); x_size = up_to_power_2(width);
y_size = up_to_power_2(height); 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 // Function: OpenCVTexture::VideoStream::Constructor
// Access: Public // Access: Public

View File

@ -100,6 +100,9 @@ private:
typedef pvector<VideoPage> Pages; typedef pvector<VideoPage> Pages;
Pages _pages; Pages _pages;
public:
static void register_with_read_factory();
public: public:
static TypeHandle get_class_type() { static TypeHandle get_class_type() {
return _type_handle; return _type_handle;