mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 10:22:45 -04:00
simple dds fixes (still inverted)
This commit is contained in:
parent
c76a53486f
commit
6b15f348b3
@ -91,62 +91,6 @@ AutoTextureScale Texture::_textures_power_2 = ATS_UNSPECIFIED;
|
|||||||
#define DDSCAPS2_CUBEMAP_NEGATIVEZ 0x00008000
|
#define DDSCAPS2_CUBEMAP_NEGATIVEZ 0x00008000
|
||||||
#define DDSCAPS2_VOLUME 0x00200000
|
#define DDSCAPS2_VOLUME 0x00200000
|
||||||
|
|
||||||
#define D3DFMT_DXT1 '1TXD' // DXT1 compression texture format
|
|
||||||
#define D3DFMT_DXT2 '2TXD' // DXT2 compression texture format
|
|
||||||
#define D3DFMT_DXT3 '3TXD' // DXT3 compression texture format
|
|
||||||
#define D3DFMT_DXT4 '4TXD' // DXT4 compression texture format
|
|
||||||
#define D3DFMT_DXT5 '5TXD' // DXT5 compression texture format
|
|
||||||
|
|
||||||
#define PF_IS_DXT1(pf) \
|
|
||||||
((pf.dwFlags & DDPF_FOURCC) && \
|
|
||||||
(pf.dwFourCC == D3DFMT_DXT1))
|
|
||||||
|
|
||||||
#define PF_IS_DXT3(pf) \
|
|
||||||
((pf.dwFlags & DDPF_FOURCC) && \
|
|
||||||
(pf.dwFourCC == D3DFMT_DXT3))
|
|
||||||
|
|
||||||
#define PF_IS_DXT5(pf) \
|
|
||||||
((pf.dwFlags & DDPF_FOURCC) && \
|
|
||||||
(pf.dwFourCC == D3DFMT_DXT5))
|
|
||||||
|
|
||||||
#define PF_IS_BGRA8(pf) \
|
|
||||||
((pf.dwFlags & DDPF_RGB) && \
|
|
||||||
(pf.dwFlags & DDPF_ALPHAPIXELS) && \
|
|
||||||
(pf.dwRGBBitCount == 32) && \
|
|
||||||
(pf.dwRBitMask == 0xff0000) && \
|
|
||||||
(pf.dwGBitMask == 0xff00) && \
|
|
||||||
(pf.dwBBitMask == 0xff) && \
|
|
||||||
(pf.dwAlphaBitMask == 0xff000000U))
|
|
||||||
|
|
||||||
#define PF_IS_BGR8(pf) \
|
|
||||||
((pf.dwFlags & DDPF_ALPHAPIXELS) && \
|
|
||||||
!(pf.dwFlags & DDPF_ALPHAPIXELS) && \
|
|
||||||
(pf.dwRGBBitCount == 24) && \
|
|
||||||
(pf.dwRBitMask == 0xff0000) && \
|
|
||||||
(pf.dwGBitMask == 0xff00) && \
|
|
||||||
(pf.dwBBitMask == 0xff))
|
|
||||||
|
|
||||||
#define PF_IS_BGR5A1(pf) \
|
|
||||||
((pf.dwFlags & DDPF_RGB) && \
|
|
||||||
(pf.dwFlags & DDPF_ALPHAPIXELS) && \
|
|
||||||
(pf.dwRGBBitCount == 16) && \
|
|
||||||
(pf.dwRBitMask == 0x00007c00) && \
|
|
||||||
(pf.dwGBitMask == 0x000003e0) && \
|
|
||||||
(pf.dwBBitMask == 0x0000001f) && \
|
|
||||||
(pf.dwAlphaBitMask == 0x00008000))
|
|
||||||
|
|
||||||
#define PF_IS_BGR565(pf) \
|
|
||||||
((pf.dwFlags & DDPF_RGB) && \
|
|
||||||
!(pf.dwFlags & DDPF_ALPHAPIXELS) && \
|
|
||||||
(pf.dwRGBBitCount == 16) && \
|
|
||||||
(pf.dwRBitMask == 0x0000f800) && \
|
|
||||||
(pf.dwGBitMask == 0x000007e0) && \
|
|
||||||
(pf.dwBBitMask == 0x0000001f))
|
|
||||||
|
|
||||||
#define PF_IS_INDEX8(pf) \
|
|
||||||
((pf.dwFlags & DDPF_INDEXED) && \
|
|
||||||
(pf.dwRGBBitCount == 8))
|
|
||||||
|
|
||||||
struct DDSPixelFormat {
|
struct DDSPixelFormat {
|
||||||
unsigned int pf_size;
|
unsigned int pf_size;
|
||||||
unsigned int pf_flags;
|
unsigned int pf_flags;
|
||||||
@ -178,44 +122,6 @@ struct DDSHeader {
|
|||||||
DDSCaps2 caps;
|
DDSCaps2 caps;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct DdsLoadInfo {
|
|
||||||
bool compressed;
|
|
||||||
bool swap;
|
|
||||||
bool palette;
|
|
||||||
unsigned int divSize;
|
|
||||||
unsigned int blockBytes;
|
|
||||||
/*
|
|
||||||
GLenum internalFormat;
|
|
||||||
GLenum externalFormat;
|
|
||||||
GLenum type;
|
|
||||||
*/
|
|
||||||
};
|
|
||||||
|
|
||||||
DdsLoadInfo loadInfoDXT1 = {
|
|
||||||
true, false, false, 4, 8, // GL_COMPRESSED_RGBA_S3TC_DXT1
|
|
||||||
};
|
|
||||||
DdsLoadInfo loadInfoDXT3 = {
|
|
||||||
true, false, false, 4, 16, // GL_COMPRESSED_RGBA_S3TC_DXT3
|
|
||||||
};
|
|
||||||
DdsLoadInfo loadInfoDXT5 = {
|
|
||||||
true, false, false, 4, 16, // GL_COMPRESSED_RGBA_S3TC_DXT5
|
|
||||||
};
|
|
||||||
DdsLoadInfo loadInfoBGRA8 = {
|
|
||||||
false, false, false, 1, 4, // GL_RGBA8, GL_BGRA, GL_UNSIGNED_BYTE
|
|
||||||
};
|
|
||||||
DdsLoadInfo loadInfoBGR8 = {
|
|
||||||
false, false, false, 1, 3, // GL_RGB8, GL_BGR, GL_UNSIGNED_BYTE
|
|
||||||
};
|
|
||||||
DdsLoadInfo loadInfoBGR5A1 = {
|
|
||||||
false, true, false, 1, 2, // GL_RGB5_A1, GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5_REV
|
|
||||||
};
|
|
||||||
DdsLoadInfo loadInfoBGR565 = {
|
|
||||||
false, true, false, 1, 2, // GL_RGB5, GL_RGB, GL_UNSIGNED_SHORT_5_6_5
|
|
||||||
};
|
|
||||||
DdsLoadInfo loadInfoIndex8 = {
|
|
||||||
false, false, true, 1, 1, // GL_RGB8, GL_BGRA, GL_UNSIGNED_BYTE
|
|
||||||
};
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: Texture::Constructor
|
// Function: Texture::Constructor
|
||||||
// Access: Published
|
// Access: Published
|
||||||
@ -967,7 +873,7 @@ read_dds(istream &in, const string &filename, bool header_only) {
|
|||||||
|
|
||||||
StreamReader dds(in);
|
StreamReader dds(in);
|
||||||
|
|
||||||
// DDS header
|
// DDS header (19 words)
|
||||||
DDSHeader header;
|
DDSHeader header;
|
||||||
header.dds_magic = dds.get_uint32();
|
header.dds_magic = dds.get_uint32();
|
||||||
header.dds_size = dds.get_uint32();
|
header.dds_size = dds.get_uint32();
|
||||||
@ -979,7 +885,7 @@ read_dds(istream &in, const string &filename, bool header_only) {
|
|||||||
header.num_levels = dds.get_uint32();
|
header.num_levels = dds.get_uint32();
|
||||||
dds.skip_bytes(44);
|
dds.skip_bytes(44);
|
||||||
|
|
||||||
// Pixelformat
|
// Pixelformat (8 words)
|
||||||
header.pf.pf_size = dds.get_uint32();
|
header.pf.pf_size = dds.get_uint32();
|
||||||
header.pf.pf_flags = dds.get_uint32();
|
header.pf.pf_flags = dds.get_uint32();
|
||||||
header.pf.four_cc = dds.get_uint32();
|
header.pf.four_cc = dds.get_uint32();
|
||||||
@ -989,12 +895,15 @@ read_dds(istream &in, const string &filename, bool header_only) {
|
|||||||
header.pf.b_mask = dds.get_uint32();
|
header.pf.b_mask = dds.get_uint32();
|
||||||
header.pf.a_mask = dds.get_uint32();
|
header.pf.a_mask = dds.get_uint32();
|
||||||
|
|
||||||
// Caps
|
// Caps (4 words)
|
||||||
header.caps.caps1 = dds.get_uint32();
|
header.caps.caps1 = dds.get_uint32();
|
||||||
header.caps.caps2 = dds.get_uint32();
|
header.caps.caps2 = dds.get_uint32();
|
||||||
header.caps.ddsx = dds.get_uint32();
|
header.caps.ddsx = dds.get_uint32();
|
||||||
dds.skip_bytes(4);
|
dds.skip_bytes(4);
|
||||||
|
|
||||||
|
// Pad out to 32 words
|
||||||
|
dds.skip_bytes(4);
|
||||||
|
|
||||||
if (header.dds_magic != DDS_MAGIC || (in.fail() || in.eof())) {
|
if (header.dds_magic != DDS_MAGIC || (in.fail() || in.eof())) {
|
||||||
gobj_cat.error()
|
gobj_cat.error()
|
||||||
<< filename << " is not a DDS file.\n";
|
<< filename << " is not a DDS file.\n";
|
||||||
@ -3723,7 +3632,7 @@ convert_to_pnmimage(PNMImage &pnmimage, int x_size, int y_size,
|
|||||||
bool Texture::
|
bool Texture::
|
||||||
read_dds_level_bgr8(Texture *tex, const DDSHeader &header,
|
read_dds_level_bgr8(Texture *tex, const DDSHeader &header,
|
||||||
int n, istream &in) {
|
int n, istream &in) {
|
||||||
// This is laid out in order B, G, R.
|
// This appears to be laid out in order R, G, B (?)
|
||||||
int x_size = tex->get_expected_mipmap_x_size(n);
|
int x_size = tex->get_expected_mipmap_x_size(n);
|
||||||
int y_size = tex->get_expected_mipmap_y_size(n);
|
int y_size = tex->get_expected_mipmap_y_size(n);
|
||||||
|
|
||||||
@ -3733,9 +3642,9 @@ read_dds_level_bgr8(Texture *tex, const DDSHeader &header,
|
|||||||
for (int y = y_size - 1; y >= 0; --y) {
|
for (int y = y_size - 1; y >= 0; --y) {
|
||||||
unsigned char *p = image.p() + y * row_bytes;
|
unsigned char *p = image.p() + y * row_bytes;
|
||||||
for (int x = 0; x < x_size; ++x) {
|
for (int x = 0; x < x_size; ++x) {
|
||||||
unsigned int b = (unsigned char)in.get();
|
|
||||||
unsigned int g = (unsigned char)in.get();
|
|
||||||
unsigned int r = (unsigned char)in.get();
|
unsigned int r = (unsigned char)in.get();
|
||||||
|
unsigned int g = (unsigned char)in.get();
|
||||||
|
unsigned int b = (unsigned char)in.get();
|
||||||
|
|
||||||
store_unscaled_byte(p, b);
|
store_unscaled_byte(p, b);
|
||||||
store_unscaled_byte(p, g);
|
store_unscaled_byte(p, g);
|
||||||
@ -3757,7 +3666,7 @@ read_dds_level_bgr8(Texture *tex, const DDSHeader &header,
|
|||||||
bool Texture::
|
bool Texture::
|
||||||
read_dds_level_rgb8(Texture *tex, const DDSHeader &header,
|
read_dds_level_rgb8(Texture *tex, const DDSHeader &header,
|
||||||
int n, istream &in) {
|
int n, istream &in) {
|
||||||
// This is laid out in order R, G, B.
|
// This appears to be laid out in order B, G, R (?)
|
||||||
int x_size = tex->get_expected_mipmap_x_size(n);
|
int x_size = tex->get_expected_mipmap_x_size(n);
|
||||||
int y_size = tex->get_expected_mipmap_y_size(n);
|
int y_size = tex->get_expected_mipmap_y_size(n);
|
||||||
|
|
||||||
@ -3767,9 +3676,9 @@ read_dds_level_rgb8(Texture *tex, const DDSHeader &header,
|
|||||||
for (int y = y_size - 1; y >= 0; --y) {
|
for (int y = y_size - 1; y >= 0; --y) {
|
||||||
unsigned char *p = image.p() + y * row_bytes;
|
unsigned char *p = image.p() + y * row_bytes;
|
||||||
for (int x = 0; x < x_size; ++x) {
|
for (int x = 0; x < x_size; ++x) {
|
||||||
unsigned int r = (unsigned char)in.get();
|
|
||||||
unsigned int g = (unsigned char)in.get();
|
|
||||||
unsigned int b = (unsigned char)in.get();
|
unsigned int b = (unsigned char)in.get();
|
||||||
|
unsigned int g = (unsigned char)in.get();
|
||||||
|
unsigned int r = (unsigned char)in.get();
|
||||||
|
|
||||||
store_unscaled_byte(p, b);
|
store_unscaled_byte(p, b);
|
||||||
store_unscaled_byte(p, g);
|
store_unscaled_byte(p, g);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user