diff --git a/src/r_data.cpp b/src/r_data.cpp index 98eedff4ee..d9edfc11ca 100644 --- a/src/r_data.cpp +++ b/src/r_data.cpp @@ -1,4 +1,3 @@ - // Emacs style mode select -*- C++ -*- //----------------------------------------------------------------------------- // @@ -207,17 +206,21 @@ int FTextureManager::AddTexture (FTexture *texture) return trans; } -// Calls DoCreateTexture and adds the texture to the manager. +// Calls FTexture::CreateTexture and adds the texture to the manager. int FTextureManager::CreateTexture (int lumpnum, int usetype) { - FTexture *out = FTexture::CreateTexture(lumpnum, usetype); - - if (out != NULL) return AddTexture (out); - else + if (lumpnum != -1) { - Printf (TEXTCOLOR_ORANGE "Invalid data encountered for texture %s\n", Wads.GetLumpFullName(lumpnum)); - return -1; + FTexture *out = FTexture::CreateTexture(lumpnum, usetype); + + if (out != NULL) return AddTexture (out); + else + { + Printf (TEXTCOLOR_ORANGE "Invalid data encountered for texture %s\n", Wads.GetLumpFullName(lumpnum)); + return -1; + } } + return -1; } void FTextureManager::ReplaceTexture (int picnum, FTexture *newtexture, bool free) diff --git a/src/r_data.h b/src/r_data.h index e18ea1fbf6..d64a9f1810 100644 --- a/src/r_data.h +++ b/src/r_data.h @@ -287,7 +287,9 @@ protected: friend class FTexture; }; -// A texture that is just a single patch +// A TGA texture +struct TGAHeader; + class FTGATexture : public FTexture { public: @@ -304,7 +306,7 @@ protected: static bool Check(FileReader & file); static FTexture *Create(FileReader & file, int lumpnum); - FTGATexture (int lumpnum, int width, int height); + FTGATexture (int lumpnum, TGAHeader *); void ReadCompressed(FileReader &lump, BYTE * buffer, int bytesperpixel); virtual void MakeTexture (); diff --git a/src/textures/tgatexture.cpp b/src/textures/tgatexture.cpp index e563e5449f..19f349d9f1 100644 --- a/src/textures/tgatexture.cpp +++ b/src/textures/tgatexture.cpp @@ -97,13 +97,15 @@ FTexture *FTGATexture::Create(FileReader & file, int lumpnum) } -FTGATexture::FTGATexture (int lumpnum, int w, int h) +FTGATexture::FTGATexture (int lumpnum, TGAHeader * hdr) : SourceLump(lumpnum), Pixels(0), Spans(0) { Wads.GetLumpName (Name, lumpnum); Name[8] = 0; - Width = w; - Height = h; + Width = hdr->width; + Height = hdr->height; + // Alpha channel is used only for 32 bit RGBA and paletted images with RGBA palettes. + bMasked = (hdr->img_desc&15)==8 && (hdr->bpp==32 || (hdr->img_type==1 && hdr->cm_size==32)); CalcBitSize(); } @@ -211,7 +213,6 @@ void FTGATexture::MakeTexture () hdr.cm_length = LittleShort(hdr.cm_length); #endif - bMasked = false; if (hdr.has_cm) { memset(PaletteMap, 0, 256); @@ -236,7 +237,6 @@ void FTGATexture::MakeTexture () case 32: lump >> b >> g >> r >> a; if ((hdr.img_desc&15)!=8) a=255; - else if (a<128) bMasked=true; break; default: // should never happen @@ -333,8 +333,6 @@ void FTGATexture::MakeTexture () } else { - bMasked=true; - for(int y=0;y