mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 02:42:49 -04:00
fix a few texture issues
This commit is contained in:
parent
d7ec4a0fce
commit
eb4baf3e4d
@ -938,6 +938,9 @@ load_texture(TextureDef &def, EggTexture *egg_tex) {
|
||||
switch (egg_tex->get_texture_type()) {
|
||||
case EggTexture::TT_unspecified:
|
||||
case EggTexture::TT_1d_texture:
|
||||
options.set_texture_flags(options.get_texture_flags() | LoaderOptions::TF_allow_1d);
|
||||
// Fall through.
|
||||
|
||||
case EggTexture::TT_2d_texture:
|
||||
if (egg_tex->has_alpha_filename() && wanted_alpha) {
|
||||
tex = TexturePool::load_texture(egg_tex->get_fullpath(),
|
||||
|
@ -248,12 +248,12 @@ write(const Filename &fullpath, int z, int n,
|
||||
// Description: Replaces the texture with the indicated image.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE bool Texture::
|
||||
load(const PNMImage &pnmimage) {
|
||||
load(const PNMImage &pnmimage, const LoaderOptions &options) {
|
||||
MutexHolder holder(_lock);
|
||||
do_clear();
|
||||
++_properties_modified;
|
||||
++_image_modified;
|
||||
return do_load_one(pnmimage, get_name(), 0, 0);
|
||||
return do_load_one(pnmimage, get_name(), 0, 0, options);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
@ -263,11 +263,11 @@ load(const PNMImage &pnmimage) {
|
||||
// mipmap level. See read().
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE bool Texture::
|
||||
load(const PNMImage &pnmimage, int z, int n) {
|
||||
load(const PNMImage &pnmimage, int z, int n, const LoaderOptions &options) {
|
||||
MutexHolder holder(_lock);
|
||||
++_properties_modified;
|
||||
++_image_modified;
|
||||
return do_load_one(pnmimage, get_name(), z, n);
|
||||
return do_load_one(pnmimage, get_name(), z, n, options);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
@ -249,6 +249,9 @@ generate_normalization_cube_map(int size) {
|
||||
PTA_uchar image = do_make_ram_image();
|
||||
_keep_ram_image = true;
|
||||
|
||||
++_image_modified;
|
||||
++_properties_modified;
|
||||
|
||||
float half_size = (float)size * 0.5f;
|
||||
float center = half_size - 0.5f;
|
||||
|
||||
@ -353,6 +356,7 @@ generate_alpha_scale_map() {
|
||||
_magfilter = FT_nearest;
|
||||
_compression = CM_off;
|
||||
|
||||
++_image_modified;
|
||||
++_properties_modified;
|
||||
|
||||
PTA_uchar image = do_make_ram_image();
|
||||
@ -375,9 +379,8 @@ read(const Filename &fullpath, const LoaderOptions &options) {
|
||||
do_clear();
|
||||
++_properties_modified;
|
||||
++_image_modified;
|
||||
bool header_only = ((options.get_texture_flags() & (LoaderOptions::TF_preload | LoaderOptions::TF_preload_simple)) == 0);
|
||||
return do_read(fullpath, Filename(), 0, 0, 0, 0, false, false,
|
||||
header_only, NULL);
|
||||
options, NULL);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
@ -399,11 +402,9 @@ read(const Filename &fullpath, const Filename &alpha_fullpath,
|
||||
do_clear();
|
||||
++_properties_modified;
|
||||
++_image_modified;
|
||||
bool header_only = ((options.get_texture_flags() & (LoaderOptions::TF_preload | LoaderOptions::TF_preload_simple)) == 0);
|
||||
return do_read(fullpath, alpha_fullpath, primary_file_num_channels,
|
||||
alpha_file_channel, 0, 0, false, false,
|
||||
header_only,
|
||||
NULL);
|
||||
options, NULL);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
@ -423,9 +424,8 @@ read(const Filename &fullpath, int z, int n,
|
||||
MutexHolder holder(_lock);
|
||||
++_properties_modified;
|
||||
++_image_modified;
|
||||
bool header_only = ((options.get_texture_flags() & (LoaderOptions::TF_preload | LoaderOptions::TF_preload_simple)) == 0);
|
||||
return do_read(fullpath, Filename(), 0, 0, z, n, read_pages, read_mipmaps,
|
||||
header_only, NULL);
|
||||
options, NULL);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
@ -506,10 +506,9 @@ read(const Filename &fullpath, const Filename &alpha_fullpath,
|
||||
MutexHolder holder(_lock);
|
||||
++_properties_modified;
|
||||
++_image_modified;
|
||||
bool header_only = ((options.get_texture_flags() & (LoaderOptions::TF_preload | LoaderOptions::TF_preload_simple)) == 0);
|
||||
return do_read(fullpath, alpha_fullpath, primary_file_num_channels,
|
||||
alpha_file_channel, z, n, read_pages, read_mipmaps,
|
||||
header_only, record);
|
||||
options, record);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
@ -2061,9 +2060,10 @@ bool Texture::
|
||||
do_read(const Filename &fullpath, const Filename &alpha_fullpath,
|
||||
int primary_file_num_channels, int alpha_file_channel,
|
||||
int z, int n, bool read_pages, bool read_mipmaps,
|
||||
bool header_only, BamCacheRecord *record) {
|
||||
const LoaderOptions &options, BamCacheRecord *record) {
|
||||
PStatTimer timer(_texture_read_pcollector);
|
||||
|
||||
bool header_only = ((options.get_texture_flags() & (LoaderOptions::TF_preload | LoaderOptions::TF_preload_simple)) == 0);
|
||||
if (record != (BamCacheRecord *)NULL) {
|
||||
header_only = false;
|
||||
}
|
||||
@ -2156,7 +2156,7 @@ do_read(const Filename &fullpath, const Filename &alpha_fullpath,
|
||||
while ((z_size == 0 && (vfs->exists(file) || z == 0)) ||
|
||||
(z_size != 0 && z < z_size)) {
|
||||
if (!do_read_one(file, alpha_file, z, n, primary_file_num_channels,
|
||||
alpha_file_channel, header_only, record)) {
|
||||
alpha_file_channel, options, header_only, record)) {
|
||||
return false;
|
||||
}
|
||||
++z;
|
||||
@ -2193,7 +2193,7 @@ do_read(const Filename &fullpath, const Filename &alpha_fullpath,
|
||||
while ((z_size == 0 && (vfs->exists(file) || z == 0)) ||
|
||||
(z_size != 0 && z < z_size)) {
|
||||
if (!do_read_one(file, alpha_file, z, 0, primary_file_num_channels,
|
||||
alpha_file_channel, header_only, record)) {
|
||||
alpha_file_channel, options, header_only, record)) {
|
||||
return false;
|
||||
}
|
||||
++z;
|
||||
@ -2221,7 +2221,7 @@ do_read(const Filename &fullpath, const Filename &alpha_fullpath,
|
||||
(n_size != 0 && n < n_size)) {
|
||||
if (!do_read_one(file, alpha_file, z, n,
|
||||
primary_file_num_channels, alpha_file_channel,
|
||||
header_only, record)) {
|
||||
options, header_only, record)) {
|
||||
return false;
|
||||
}
|
||||
++n;
|
||||
@ -2240,7 +2240,7 @@ do_read(const Filename &fullpath, const Filename &alpha_fullpath,
|
||||
// Just an ordinary read of one file.
|
||||
if (!do_read_one(fullpath, alpha_fullpath, z, n,
|
||||
primary_file_num_channels, alpha_file_channel,
|
||||
header_only, record)) {
|
||||
options, header_only, record)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -2269,7 +2269,7 @@ do_read(const Filename &fullpath, const Filename &alpha_fullpath,
|
||||
bool Texture::
|
||||
do_read_one(const Filename &fullpath, const Filename &alpha_fullpath,
|
||||
int z, int n, int primary_file_num_channels, int alpha_file_channel,
|
||||
bool header_only, BamCacheRecord *record) {
|
||||
const LoaderOptions &options, bool header_only, BamCacheRecord *record) {
|
||||
if (record != (BamCacheRecord *)NULL) {
|
||||
nassertr(!header_only, false);
|
||||
record->add_dependent_file(fullpath);
|
||||
@ -2469,7 +2469,7 @@ do_read_one(const Filename &fullpath, const Filename &alpha_fullpath,
|
||||
}
|
||||
}
|
||||
|
||||
return do_load_one(image, fullpath.get_basename(), z, n);
|
||||
return do_load_one(image, fullpath.get_basename(), z, n, options);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
@ -2479,7 +2479,8 @@ do_read_one(const Filename &fullpath, const Filename &alpha_fullpath,
|
||||
// level.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool Texture::
|
||||
do_load_one(const PNMImage &pnmimage, const string &name, int z, int n) {
|
||||
do_load_one(const PNMImage &pnmimage, const string &name, int z, int n,
|
||||
const LoaderOptions &options) {
|
||||
if (_ram_images.size() <= 1 && n == 0) {
|
||||
// A special case for mipmap level 0. When we load mipmap level
|
||||
// 0, unless we already have mipmap levels, it determines the
|
||||
@ -2498,7 +2499,7 @@ do_load_one(const PNMImage &pnmimage, const string &name, int z, int n) {
|
||||
|
||||
if (!do_reconsider_image_properties(pnmimage.get_x_size(), pnmimage.get_y_size(),
|
||||
pnmimage.get_num_channels(), component_type,
|
||||
z)) {
|
||||
z, options)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -3159,10 +3160,10 @@ do_reload_ram_image(bool allow_compression) {
|
||||
// instance, we don't want to change the filter type or the
|
||||
// border color or anything--we just want to get the image and
|
||||
// necessary associated parameters.
|
||||
_loaded_from_image = false;
|
||||
do_reconsider_image_properties(tex->get_x_size(), tex->get_y_size(),
|
||||
tex->get_num_components(),
|
||||
tex->get_component_type(), 0);
|
||||
tex->get_component_type(), 0,
|
||||
LoaderOptions());
|
||||
_compression = tex->get_compression();
|
||||
_ram_image_compression = tex->_ram_image_compression;
|
||||
_ram_images = tex->_ram_images;
|
||||
@ -3185,11 +3186,12 @@ do_reload_ram_image(bool allow_compression) {
|
||||
if (_has_read_mipmaps) {
|
||||
n = _num_mipmap_levels_read;
|
||||
}
|
||||
_loaded_from_image = false;
|
||||
|
||||
LoaderOptions options;
|
||||
options.set_texture_flags(LoaderOptions::TF_preload);
|
||||
do_read(_fullpath, _alpha_fullpath,
|
||||
_primary_file_num_channels, _alpha_file_channel,
|
||||
z, n, _has_read_pages, _has_read_mipmaps, false, NULL);
|
||||
z, n, _has_read_pages, _has_read_mipmaps, options, NULL);
|
||||
|
||||
if (do_has_ram_image() && record != (BamCacheRecord *)NULL) {
|
||||
if (cache->get_cache_textures() || (_ram_image_compression != CM_off && cache->get_cache_compressed_textures())) {
|
||||
@ -3313,7 +3315,8 @@ do_reconsider_z_size(int z) {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool Texture::
|
||||
do_reconsider_image_properties(int x_size, int y_size, int num_components,
|
||||
Texture::ComponentType component_type, int z) {
|
||||
Texture::ComponentType component_type, int z,
|
||||
const LoaderOptions &options) {
|
||||
if (!_loaded_from_image || num_components != _num_components) {
|
||||
// Come up with a default format based on the number of channels.
|
||||
// But only do this the first time the file is loaded, or if the
|
||||
@ -3344,6 +3347,12 @@ do_reconsider_image_properties(int x_size, int y_size, int num_components,
|
||||
}
|
||||
|
||||
if (!_loaded_from_image) {
|
||||
if ((options.get_texture_flags() & LoaderOptions::TF_allow_1d) &&
|
||||
_texture_type == TT_2d_texture && x_size != 1 && y_size == 1) {
|
||||
// If we're loading an Nx1 size texture, infer a 1-d texture type.
|
||||
_texture_type = TT_1d_texture;
|
||||
}
|
||||
|
||||
#ifndef NDEBUG
|
||||
if (_texture_type == TT_1d_texture) {
|
||||
nassertr(y_size == 1, false);
|
||||
|
@ -237,8 +237,8 @@ PUBLISHED:
|
||||
bool write_txo(ostream &out, const string &filename = "stream") const;
|
||||
bool read_dds(istream &in, const string &filename = "stream", bool header_only = false);
|
||||
|
||||
INLINE bool load(const PNMImage &pnmimage);
|
||||
INLINE bool load(const PNMImage &pnmimage, int z, int n);
|
||||
INLINE bool load(const PNMImage &pnmimage, const LoaderOptions &options = LoaderOptions());
|
||||
INLINE bool load(const PNMImage &pnmimage, int z, int n, const LoaderOptions &options = LoaderOptions());
|
||||
INLINE bool store(PNMImage &pnmimage) const;
|
||||
INLINE bool store(PNMImage &pnmimage, int z, int n) const;
|
||||
|
||||
@ -448,12 +448,13 @@ protected:
|
||||
virtual bool do_read(const Filename &fullpath, const Filename &alpha_fullpath,
|
||||
int primary_file_num_channels, int alpha_file_channel,
|
||||
int z, int n, bool read_pages, bool read_mipmaps,
|
||||
bool header_only, BamCacheRecord *record);
|
||||
const LoaderOptions &options, BamCacheRecord *record);
|
||||
virtual bool do_read_one(const Filename &fullpath, const Filename &alpha_fullpath,
|
||||
int z, int n, int primary_file_num_channels, int alpha_file_channel,
|
||||
const LoaderOptions &options,
|
||||
bool header_only, BamCacheRecord *record);
|
||||
virtual bool do_load_one(const PNMImage &pnmimage, const string &name,
|
||||
int z, int n);
|
||||
int z, int n, const LoaderOptions &options);
|
||||
bool do_read_txo_file(const Filename &fullpath);
|
||||
bool do_read_txo(istream &in, const string &filename);
|
||||
bool do_read_dds_file(const Filename &fullpath, bool header_only);
|
||||
@ -475,7 +476,8 @@ protected:
|
||||
|
||||
bool do_reconsider_z_size(int z);
|
||||
bool do_reconsider_image_properties(int x_size, int y_size, int num_components,
|
||||
ComponentType component_type, int z);
|
||||
ComponentType component_type, int z,
|
||||
const LoaderOptions &options);
|
||||
|
||||
virtual PT(Texture) do_make_copy();
|
||||
void do_assign(const Texture ©);
|
||||
|
@ -195,7 +195,8 @@ do_recalculate_image_properties(CDWriter &cdata) {
|
||||
}
|
||||
|
||||
do_reconsider_image_properties(x_max, y_max, alpha?4:3,
|
||||
T_unsigned_byte, cdata->_pages.size());
|
||||
T_unsigned_byte, cdata->_pages.size(),
|
||||
LoaderOptions());
|
||||
do_set_pad_size(x_max - x_size, y_max - y_size, 0);
|
||||
}
|
||||
|
||||
|
@ -42,6 +42,7 @@ PUBLISHED:
|
||||
enum TextureFlags {
|
||||
TF_preload = 0x0004, // Texture will have RAM image
|
||||
TF_preload_simple = 0x0008, // Texture will have simple RAM image
|
||||
TF_allow_1d = 0x0010, // If texture is Nx1, make a 1-d texture
|
||||
};
|
||||
|
||||
LoaderOptions(int flags = LF_search | LF_report_errors);
|
||||
|
@ -1453,12 +1453,20 @@ set_state_and_transform(const RenderState *target,
|
||||
////////////////////////////////////////////////////////////////////
|
||||
TextureContext *TinyGraphicsStateGuardian::
|
||||
prepare_texture(Texture *tex) {
|
||||
if (tex->get_texture_type() != Texture::TT_2d_texture) {
|
||||
switch (tex->get_texture_type()) {
|
||||
case Texture::TT_1d_texture:
|
||||
case Texture::TT_2d_texture:
|
||||
// These are supported.
|
||||
break;
|
||||
|
||||
default:
|
||||
// Anything else is not supported.
|
||||
tinydisplay_cat.info()
|
||||
<< "not loading texture " << tex->get_name() << ": "
|
||||
<< tex->get_texture_type() << "\n";
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (tex->get_ram_image_compression() != Texture::CM_off) {
|
||||
tinydisplay_cat.info()
|
||||
<< "not loading texture " << tex->get_name() << ": "
|
||||
|
Loading…
x
Reference in New Issue
Block a user