From dab7c43f7c81b20a5fec877f09f570ac1fb5c731 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 18 Oct 2019 19:06:57 +0200 Subject: [PATCH] - fixed all compiler errors. It mostly works again, but still has a few glitches. --- source/build/include/mdsprite.h | 37 +++++++++++++------------ source/build/src/mdsprite.cpp | 6 ++-- source/build/src/polymost.cpp | 11 ++++---- source/build/src/texcache.cpp | 15 +++++----- source/build/src/voxmodel.cpp | 10 +++---- source/common/textures/bitmap.cpp | 4 +-- source/common/textures/bitmap.h | 2 +- source/common/textures/buildtiles.cpp | 6 ++-- source/common/textures/image.h | 2 +- source/common/textures/imagetexture.cpp | 2 +- source/common/textures/skyboxtexture.h | 2 +- source/common/textures/texture.cpp | 4 +-- source/common/textures/textures.h | 12 ++++---- source/glbackend/glbackend.cpp | 8 +++--- source/glbackend/glbackend.h | 4 +-- 15 files changed, 60 insertions(+), 65 deletions(-) diff --git a/source/build/include/mdsprite.h b/source/build/include/mdsprite.h index 8718efa2b..1fb347cd3 100644 --- a/source/build/include/mdsprite.h +++ b/source/build/include/mdsprite.h @@ -15,11 +15,27 @@ struct mdmodel_t { int32_t mdnum, shadeoff; float scale, bscale, zadd, yoffset; - FTexture **textures; + FTexture *texture; int32_t flags; }; +struct mdanim_t +{ + int32_t startframe, endframe; + int32_t fpssc, flags; + mdanim_t* next; +}; + +struct mdskinmap_t +{ + uint8_t palette, flags, filler[2]; // Build palette number, flags the same as hightiles + int32_t skinnum, surfnum; // Skin identifier, surface number + FTexture* texture; + mdskinmap_t* next; + float param, specpower, specfactor; +}; + struct idmodel_t : public mdmodel_t { int32_t numframes, cframe, nframe, fpssc, usesalpha; @@ -29,24 +45,9 @@ struct idmodel_t : public mdmodel_t int32_t numskins, skinloaded; }; -typedef struct _mdanim_t -{ - int32_t startframe, endframe; - int32_t fpssc, flags; - struct _mdanim_t *next; -} mdanim_t; - #define MDANIM_LOOP 0 #define MDANIM_ONESHOT 1 -typedef struct _mdskinmap_t -{ - uint8_t palette, flags, filler[2]; // Build palette number, flags the same as hightiles - int32_t skinnum, surfnum; // Skin identifier, surface number - FTexture *texture; - struct _mdskinmap_t *next; - float param, specpower, specfactor; -} mdskinmap_t; //This MD2 code is based on the source code from David Henry (tfc_duke(at)hotmail.com) @@ -189,12 +190,12 @@ struct voxmodel_t : public mdmodel_t vec3f_t piv; int32_t is8bit; -} voxmodel_t; +}; EXTERN mdmodel_t **models; void updateanimation(md2model_t *m, tspriteptr_t tspr, uint8_t lpal); -FTexture *mdloadskin(idmodel_t *m, int32_t number, int32_t pal, int32_t surf, bool *exact) +FTexture* mdloadskin(idmodel_t* m, int32_t number, int32_t pal, int32_t surf, bool* exact); void mdinit(void); void freeallmodels(void); int32_t polymost_mddraw(tspriteptr_t tspr); diff --git a/source/build/src/mdsprite.cpp b/source/build/src/mdsprite.cpp index 051890421..1e906c523 100644 --- a/source/build/src/mdsprite.cpp +++ b/source/build/src/mdsprite.cpp @@ -805,7 +805,7 @@ static md2model_t *md2load(buildvfs_kfd fil, const char *filnam) // the MD2 is now loaded internally - let's begin the MD3 conversion process //OSD_Printf("Beginning md3 conversion.\n"); m3 = (md3model_t *)Xcalloc(1, sizeof(md3model_t)); - m3->mdnum = 3; m3->texture = nullptr m3->scale = m->scale; + m3->mdnum = 3; m3->texture = nullptr; m3->scale = m->scale; m3->head.id = IDP3_MAGIC; m3->head.vers = 15; m3->head.flags = 0; @@ -911,7 +911,7 @@ static md2model_t *md2load(buildvfs_kfd fil, const char *filnam) sk->texture = TileFiles.GetTexture(fn); if (!sk->texture) { - initprintf("Unable to load %s as model skin\n", skinfn); + initprintf("Unable to load %s as model skin\n", m->skinfn); } } m3->skinmap = sk; @@ -1743,7 +1743,7 @@ static int32_t polymost_md3draw(md3model_t *m, tspriteptr_t tspr) det = tex = r_detailmapping ? mdloadskin((md2model_t *) m, tile2model[Ptile2tile(tspr->picnum, lpal)].skinnum, DETAILPAL, surfi, nullptr) : nullptr; if (det) { - for (sk = m->skinmap; sk; sk = sk->next) + for (auto sk = m->skinmap; sk; sk = sk->next) if ((int32_t) sk->palette == DETAILPAL && sk->skinnum == tile2model[Ptile2tile(tspr->picnum, lpal)].skinnum && sk->surfnum == surfi) detscale = sk->param; } diff --git a/source/build/src/polymost.cpp b/source/build/src/polymost.cpp index 234d0a0da..0cd5d2a9f 100644 --- a/source/build/src/polymost.cpp +++ b/source/build/src/polymost.cpp @@ -267,8 +267,7 @@ void polymost_glreset() } else { - TileFiles.CleatTextureCache(); - clearskins(INVALIDATE_ALL); + TileFiles.ClearTextureCache(); } if (polymosttext) @@ -5255,7 +5254,7 @@ void polymost_fillpolygon(int32_t npoints) if (gloy1 != -1) polymostSet2dView(); //disables blending, texturing, and depth testing GLInterface.EnableAlphaTest(true); - GLInterface.SetTexture(TileFiles.tiles[globalpicnum], globalpal, DAMETH_NOMASK); + GLInterface.SetTexture(TileFiles.tiles[globalpicnum], globalpal, DAMETH_NOMASK, -1); uint8_t const maskprops = (globalorientation>>7)&DAMETH_MASKPROPS; handle_blend(maskprops > DAMETH_MASK, 0, maskprops == DAMETH_TRANS2); @@ -5587,7 +5586,7 @@ void polymost_precache(int32_t dapicnum, int32_t dapalnum, int32_t datype) //OSD_Printf("precached %d %d type %d\n", dapicnum, dapalnum, datype); hicprecaching = 1; - GLInterface.SetTexture(TileFiles.tiles[dapicnum], dapalnum, 0); + GLInterface.SetTexture(TileFiles.tiles[dapicnum], dapalnum, 0, -1); hicprecaching = 0; if (datype == 0 || !usemodels) return; @@ -5600,8 +5599,8 @@ void polymost_precache(int32_t dapicnum, int32_t dapalnum, int32_t datype) for (int i = 0; i <= surfaces; i++) { - auto tex = mdloadskin((md2model_t *)models[mid], 0, dapalnum, i); - if (tex) GLInterface.SetTexture(tex, dapalnum, 0); + auto tex = mdloadskin((md2model_t *)models[mid], 0, dapalnum, i, nullptr); + if (tex) GLInterface.SetTexture(tex, dapalnum, 0, -1); } } diff --git a/source/build/src/texcache.cpp b/source/build/src/texcache.cpp index 01e46a29c..84d08aae7 100644 --- a/source/build/src/texcache.cpp +++ b/source/build/src/texcache.cpp @@ -4,7 +4,6 @@ #include "lz4.h" #include "hightile.h" #include "polymost.h" -#include "texcache.h" #include "scriptfile.h" #include "xxhash.h" #include "kplib.h" @@ -109,9 +108,9 @@ FHardwareTexture* GLInstance::LoadTexture(FTexture* tex, int textype, int palid) FHardwareTexture *hwtex; if (textype == TT_INDEXED) - auto hwtex = CreateIndexedTexture(tex); + hwtex = CreateIndexedTexture(tex); else - auto hwtex = CreateTrueColorTexture(tex, textype == TT_HICREPLACE? -1 : palid, textype == TT_BRIGHTMAP); + hwtex = CreateTrueColorTexture(tex, textype == TT_HICREPLACE? -1 : palid, textype == TT_BRIGHTMAP); tex->SetHardwareTexture(palid, hwtex); return hwtex; @@ -135,7 +134,7 @@ bool GLInstance::SetTextureInternal(FTexture* tex, int palette, int method, int int lookuppal = 0; VSMatrix texmat; - auto rep = usehightile? currentTexture->FindReplacement(palette) : nullptr; + auto rep = usehightile? tex->FindReplacement(palette) : nullptr; if (rep) { // Hightile replacements have only one texture representation and it is always the base. @@ -170,7 +169,7 @@ bool GLInstance::SetTextureInternal(FTexture* tex, int palette, int method, int float detscalex = detscale, detscaley = detscale; if (!(method & DAMETH_MODEL)) { - auto drep = currentTexture->FindReplacement(DETAILPAL); + auto drep = tex->FindReplacement(DETAILPAL); if (drep) { det = drep->faces[0]; @@ -200,7 +199,7 @@ bool GLInstance::SetTextureInternal(FTexture* tex, int palette, int method, int { if (!(method & DAMETH_MODEL)) { - auto drep = currentTexture->FindReplacement(DETAILPAL); + auto drep = tex->FindReplacement(DETAILPAL); if (drep) { glow = drep->faces[0]; @@ -217,7 +216,7 @@ bool GLInstance::SetTextureInternal(FTexture* tex, int palette, int method, int { if (TextureType == TT_HICREPLACE) { - auto brep = currentTexture->FindReplacement(BRIGHTPAL); + auto brep = tex->FindReplacement(BRIGHTPAL); if (brep) { auto htex = LoadTexture(brep->faces[0], TT_HICREPLACE, 0); @@ -237,6 +236,7 @@ bool GLInstance::SetTextureInternal(FTexture* tex, int palette, int method, int } } } + else return false; float al = 0; if (TextureType == TT_HICREPLACE) @@ -245,6 +245,7 @@ bool GLInstance::SetTextureInternal(FTexture* tex, int palette, int method, int (tex->alphaThreshold >= 0.f ? tex->alphaThreshold : 0.f); } GLInterface.SetAlphaThreshold(al); + return true; } diff --git a/source/build/src/voxmodel.cpp b/source/build/src/voxmodel.cpp index 19b51fc30..d8bfc6b4a 100644 --- a/source/build/src/voxmodel.cpp +++ b/source/build/src/voxmodel.cpp @@ -849,7 +849,6 @@ void voxfree(voxmodel_t *m) DO_FREE_AND_NULL(m->mytex); DO_FREE_AND_NULL(m->quad); - DO_FREE_AND_NULL(m->texid); Xfree(m); } @@ -877,8 +876,7 @@ voxmodel_t *voxload(const char *filnam) vm->siz.x = voxsiz.x; vm->siz.y = voxsiz.y; vm->siz.z = voxsiz.z; vm->piv.x = voxpiv.x; vm->piv.y = voxpiv.y; vm->piv.z = voxpiv.z; vm->is8bit = is8bit; - - vm->texid = (FHardwareTexture * *)Xcalloc(MAXPALOOKUPS, sizeof(FHardwareTexture*)); + vm->texture = nullptr; } DO_FREE_AND_NULL(shcntmal); @@ -990,8 +988,6 @@ voxmodel_t *loadkvxfrombuf(const char *kvxbuffer, int32_t length) vm->siz.x = voxsiz.x; vm->siz.y = voxsiz.y; vm->siz.z = voxsiz.z; vm->piv.x = voxpiv.x; vm->piv.y = voxpiv.y; vm->piv.z = voxpiv.z; vm->is8bit = 1; - - vm->texid = (FHardwareTexture **)Xcalloc(MAXPALOOKUPS, sizeof(FHardwareTexture *)); } DO_FREE_AND_NULL(shcntmal); @@ -1132,10 +1128,12 @@ int32_t polymost_voxdraw(voxmodel_t *m, tspriteptr_t const tspr) int prevClamp = GLInterface.GetClamp(); GLInterface.SetClamp(0); +#if 0 if (!m->texid[globalpal]) m->texid[globalpal] = gloadtex(m->mytex, m->mytexx, m->mytexy, m->is8bit, globalpal); - GLInterface.BindTexture(0, m->texid[globalpal]); + GLInterface.BindTexture(0, m->texid[globalpal], -1); +#endif auto data = GLInterface.AllocVertices(m->qcnt * 4); auto vt = data.second; diff --git a/source/common/textures/bitmap.cpp b/source/common/textures/bitmap.cpp index 3f79318de..dfeed247d 100644 --- a/source/common/textures/bitmap.cpp +++ b/source/common/textures/bitmap.cpp @@ -100,7 +100,7 @@ void FBitmap::CopyPixelDataRGB(int originx, int originy, const uint8_t *patch, i template void iCopyPaletted(uint8_t *buffer, const uint8_t * patch, int srcwidth, int srcheight, int Pitch, - int step_x, int step_y, int rotate, PalEntry * palette) + int step_x, int step_y, int rotate, const PalEntry * palette) { int x,y,pos; @@ -133,7 +133,7 @@ typedef void (*CopyPalettedFunc)(uint8_t *buffer, const uint8_t * patch, int src // //=========================================================================== void FBitmap::CopyPixelData(int originx, int originy, const uint8_t * patch, int srcwidth, int srcheight, - int step_x, int step_y, int rotate, PalEntry * palette) + int step_x, int step_y, int rotate, const PalEntry * palette) { uint8_t *buffer = data + 4*originx + Pitch*originy; iCopyPaletted(buffer, patch, srcwidth, srcheight, Pitch, diff --git a/source/common/textures/bitmap.h b/source/common/textures/bitmap.h index e20b64b5d..2a69c6701 100644 --- a/source/common/textures/bitmap.h +++ b/source/common/textures/bitmap.h @@ -204,7 +204,7 @@ public: int srcheight, int step_x, int step_y, int rotate, int ct, /* for PNG tRNS */ int r=0, int g=0, int b=0); void CopyPixelData(int originx, int originy, const uint8_t * patch, int srcwidth, int srcheight, - int step_x, int step_y, int rotate, PalEntry * palette); + int step_x, int step_y, int rotate, const PalEntry * palette); void Blit(int originx, int originy, const FBitmap &src) diff --git a/source/common/textures/buildtiles.cpp b/source/common/textures/buildtiles.cpp index 1420e8dd2..800f34f01 100644 --- a/source/common/textures/buildtiles.cpp +++ b/source/common/textures/buildtiles.cpp @@ -79,7 +79,7 @@ picanm_t tileConvertAnimFormat(int32_t const picanimraw) // //========================================================================== -FBitmap FTileTexture::GetBgraBitmap(PalEntry* remap, int* ptrans) +FBitmap FTileTexture::GetBgraBitmap(const PalEntry* remap, int* ptrans) { FBitmap bmp; TArray buffer; @@ -232,7 +232,7 @@ void BuildFiles::CloseAllMapArt() // //=========================================================================== -void BuildFiles::CleatTextureCache(bool artonly) +void BuildFiles::ClearTextureCache(bool artonly) { for (auto tex : AllTiles) { @@ -262,7 +262,7 @@ void BuildFiles::InvalidateTile(int num) tex->DeleteHardwareTextures(); for (auto &rep : tex->Hightiles) { - for (auto &reptex : rep.Faces) + for (auto &reptex : rep.faces) { if (reptex) reptex->DeleteHardwareTextures(); } diff --git a/source/common/textures/image.h b/source/common/textures/image.h index 3659bc4be..d6bbfffda 100644 --- a/source/common/textures/image.h +++ b/source/common/textures/image.h @@ -131,7 +131,7 @@ public: } FImageSource *GetImage() const override { return mImage; } - FBitmap GetBgraBitmap(PalEntry *p, int *trans) override; + FBitmap GetBgraBitmap(const PalEntry *p, int *trans) override; }; diff --git a/source/common/textures/imagetexture.cpp b/source/common/textures/imagetexture.cpp index 03f1655ca..64570775c 100644 --- a/source/common/textures/imagetexture.cpp +++ b/source/common/textures/imagetexture.cpp @@ -69,7 +69,7 @@ FImageTexture::FImageTexture(FImageSource *img, const char *name) // //=========================================================================== -FBitmap FImageTexture::GetBgraBitmap(PalEntry *p, int *trans) +FBitmap FImageTexture::GetBgraBitmap(const PalEntry *p, int *trans) { FBitmap bmp; bmp.Create(Size.x, Size.y); diff --git a/source/common/textures/skyboxtexture.h b/source/common/textures/skyboxtexture.h index 51350a067..7651dc0c8 100644 --- a/source/common/textures/skyboxtexture.h +++ b/source/common/textures/skyboxtexture.h @@ -16,7 +16,7 @@ public: bool fliptop; FSkyBox(const char *name); - FBitmap GetBgraBitmap(PalEntry *, int *trans) override; + FBitmap GetBgraBitmap(const PalEntry *, int *trans) override; FImageSource *GetImage() const override; diff --git a/source/common/textures/texture.cpp b/source/common/textures/texture.cpp index 904aa41f9..f968d6f2c 100644 --- a/source/common/textures/texture.cpp +++ b/source/common/textures/texture.cpp @@ -90,7 +90,7 @@ FTexture::~FTexture () // //=========================================================================== -FBitmap FTexture::GetBgraBitmap(PalEntry *remap, int *ptrans) +FBitmap FTexture::GetBgraBitmap(const PalEntry *remap, int *ptrans) { FBitmap bmp; bmp.Create(Size.x, Size.y); @@ -288,7 +288,7 @@ bool FTexture::ProcessData(unsigned char * buffer, int w, int h, bool ispatch) // //=========================================================================== -FTextureBuffer FTexture::CreateTexBuffer(PalEntry * remap, int flags) +FTextureBuffer FTexture::CreateTexBuffer(const PalEntry * remap, int flags) { FTextureBuffer result; diff --git a/source/common/textures/textures.h b/source/common/textures/textures.h index 3a0bf086a..0e5f5543b 100644 --- a/source/common/textures/textures.h +++ b/source/common/textures/textures.h @@ -176,7 +176,6 @@ struct FTextureBuffer mBuffer = other.mBuffer; mWidth = other.mWidth; mHeight = other.mHeight; - mContentId = other.mContentId; other.mBuffer = nullptr; } @@ -185,7 +184,6 @@ struct FTextureBuffer mBuffer = other.mBuffer; mWidth = other.mWidth; mHeight = other.mHeight; - mContentId = other.mContentId; other.mBuffer = nullptr; return *this; } @@ -223,7 +221,7 @@ public: virtual void Create8BitPixels(uint8_t* buffer); virtual const uint8_t* Get8BitPixels(); virtual uint8_t* GetWritableBuffer() { return nullptr; } // For dynamic tiles. Requesting this must also invalidate the texture. - virtual FBitmap GetBgraBitmap(PalEntry *remap, int *trans = nullptr); + virtual FBitmap GetBgraBitmap(const PalEntry *remap, int *trans = nullptr); static int SmoothEdges(unsigned char * buffer,int w, int h); static PalEntry averageColor(const uint32_t *data, int size, int maxout); @@ -236,7 +234,7 @@ public: int GetTopOffset() const { return PicAnim.yofs; } picanm_t& GetAnim() { return PicAnim; } // This must be modifiable. There's quite a bit of code messing around with the flags in here. rottile_t& GetRotTile() { return RotTile; } - FTextureBuffer CreateTexBuffer(PalEntry *palette, int flags = 0); + FTextureBuffer CreateTexBuffer(const PalEntry *palette, int flags = 0); bool GetTranslucency(); void CheckTrans(unsigned char * buffer, int size, int trans); bool ProcessData(unsigned char * buffer, int w, int h, bool ispatch); @@ -313,7 +311,7 @@ protected: TMap HardwareTextures; // Note: These must be deleted by the backend. When the texture manager is taken down it may already be too late to delete them. FTexture (const char *name = NULL); - friend class BuildFiles; + friend struct BuildFiles; }; class FTileTexture : public FTexture @@ -324,7 +322,7 @@ public: useType = Art; } void SetName(const char* name) { Name = name; } - FBitmap GetBgraBitmap(PalEntry* remap, int* ptrans) override; + FBitmap GetBgraBitmap(const PalEntry* remap, int* ptrans) override; void Create8BitPixels(uint8_t* buffer) override; }; @@ -548,7 +546,7 @@ struct BuildFiles void tileSetExternal(int tilenum, int width, int height, uint8_t* data); int findUnusedTile(void); int tileCreateRotated(int owner); - void CleatTextureCache(bool artonly = false); + void ClearTextureCache(bool artonly = false); void InvalidateTile(int num); }; diff --git a/source/glbackend/glbackend.cpp b/source/glbackend/glbackend.cpp index ce81b80af..efc2ac10e 100644 --- a/source/glbackend/glbackend.cpp +++ b/source/glbackend/glbackend.cpp @@ -207,8 +207,9 @@ void GLInstance::RestoreTextureProps() { // todo: reset everything that's needed to ensure proper functionality VSMatrix identity(0); - GLInterface.SetMatrix(Matrix_Texture, &identity); - GLInterface.SetMatrix(Matrix_Detail, &identity); + if (MatrixChange & 1) GLInterface.SetMatrix(Matrix_Texture, &identity); + if (MatrixChange & 2) GLInterface.SetMatrix(Matrix_Detail, &identity); + MatrixChange = 0; } @@ -228,7 +229,6 @@ void GLInstance::Draw(EDrawType type, size_t start, size_t count) if (activeShader == polymostShader) { - applied = ApplyTextureProps(); renderState.UsePalette = texv && texv->isIndexed(); renderState.Apply(polymostShader); } @@ -240,7 +240,7 @@ void GLInstance::Draw(EDrawType type, size_t start, size_t count) glVertexAttrib3f(0, p->x, p->y, p->z); } glEnd(); - if (applied) RestoreTextureProps(); + if (MatrixChange) RestoreTextureProps(); } int GLInstance::GetTextureID() diff --git a/source/glbackend/glbackend.h b/source/glbackend/glbackend.h index f1e91c87d..7532a75ab 100644 --- a/source/glbackend/glbackend.h +++ b/source/glbackend/glbackend.h @@ -391,10 +391,8 @@ public: bool SetModelTexture(FTexture *tex, int palette, float xpanning, float ypanning, FTexture *det, float detscale, FTexture *glow) { - return SetTextureInternal(tex, palette, DAMETH_MODEL, -1, xpanning, ypanning, det, detscale, glow); + return SetTextureInternal(tex, palette, 8/*DAMETH_MODEL*/, -1, xpanning, ypanning, det, detscale, glow); } - -) }; extern GLInstance GLInterface;