2013-06-23 07:49:34 +00:00
|
|
|
|
|
|
|
#ifndef __GL_TEXTURE_H
|
|
|
|
#define __GL_TEXTURE_H
|
|
|
|
|
|
|
|
#include "m_fixed.h"
|
|
|
|
#include "textures/textures.h"
|
|
|
|
#include "gl/textures/gl_hwtexture.h"
|
|
|
|
#include "gl/renderer/gl_colormap.h"
|
|
|
|
#include "i_system.h"
|
2016-04-07 23:42:43 +00:00
|
|
|
#include "r_defs.h"
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
|
|
EXTERN_CVAR(Bool, gl_precache)
|
|
|
|
|
|
|
|
struct FRemapTable;
|
|
|
|
class FTextureShader;
|
|
|
|
|
2014-08-22 21:50:38 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
CLAMP_NONE = 0,
|
|
|
|
CLAMP_X = 1,
|
|
|
|
CLAMP_Y = 2,
|
|
|
|
CLAMP_XY = 3,
|
|
|
|
CLAMP_XY_NOMIP = 4,
|
|
|
|
CLAMP_NOFILTER = 5,
|
|
|
|
CLAMP_CAMTEX = 6,
|
|
|
|
};
|
|
|
|
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
struct FTexCoordInfo
|
|
|
|
{
|
|
|
|
int mRenderWidth;
|
|
|
|
int mRenderHeight;
|
|
|
|
int mWidth;
|
2016-04-07 23:42:43 +00:00
|
|
|
FVector2 mScale;
|
|
|
|
FVector2 mTempScale;
|
2013-06-23 07:49:34 +00:00
|
|
|
bool mWorldPanning;
|
|
|
|
|
|
|
|
float FloatToTexU(float v) const { return v / mRenderWidth; }
|
|
|
|
float FloatToTexV(float v) const { return v / mRenderHeight; }
|
2016-04-07 22:19:51 +00:00
|
|
|
float RowOffset(float ofs) const;
|
|
|
|
float TextureOffset(float ofs) const;
|
2016-04-07 23:42:43 +00:00
|
|
|
float TextureAdjustWidth() const;
|
2013-06-23 07:49:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
// this is the texture maintenance class for OpenGL.
|
|
|
|
//
|
|
|
|
//===========================================================================
|
|
|
|
class FMaterial;
|
|
|
|
|
|
|
|
|
2014-05-11 17:44:19 +00:00
|
|
|
class FGLTexture
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
|
|
|
friend class FMaterial;
|
|
|
|
public:
|
|
|
|
FTexture * tex;
|
|
|
|
FTexture * hirestexture;
|
|
|
|
char bIsTransparent;
|
|
|
|
int HiresLump;
|
|
|
|
|
|
|
|
private:
|
2014-08-22 21:50:38 +00:00
|
|
|
FHardwareTexture *mHwTexture;
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
|
|
bool bHasColorkey; // only for hires
|
2015-04-04 11:37:55 +00:00
|
|
|
bool bExpandFlag;
|
2016-04-22 17:54:51 +00:00
|
|
|
BYTE lastSampler;
|
2016-05-02 23:00:52 +00:00
|
|
|
int lastTranslation;
|
2013-06-23 07:49:34 +00:00
|
|
|
|
2014-09-09 11:21:36 +00:00
|
|
|
unsigned char * LoadHiresTexture(FTexture *hirescheck, int *width, int *height);
|
2013-06-23 07:49:34 +00:00
|
|
|
|
2014-08-22 21:50:38 +00:00
|
|
|
FHardwareTexture *CreateHwTexture();
|
2013-06-23 07:49:34 +00:00
|
|
|
|
2014-09-09 11:21:36 +00:00
|
|
|
const FHardwareTexture *Bind(int texunit, int clamp, int translation, FTexture *hirescheck);
|
|
|
|
|
2013-06-23 07:49:34 +00:00
|
|
|
public:
|
|
|
|
FGLTexture(FTexture * tx, bool expandpatches);
|
|
|
|
~FGLTexture();
|
|
|
|
|
2016-04-26 17:11:32 +00:00
|
|
|
unsigned char * CreateTexBuffer(int translation, int & w, int & h, FTexture *hirescheck, bool createexpanded = true, bool alphatrans = false);
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
|
|
void Clean(bool all);
|
2016-05-02 23:00:52 +00:00
|
|
|
void CleanUnused(SpriteHits &usedtranslations);
|
2013-06-23 07:49:34 +00:00
|
|
|
int Dump(int i);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
// this is the material class for OpenGL.
|
|
|
|
//
|
|
|
|
//===========================================================================
|
|
|
|
|
|
|
|
class FMaterial
|
|
|
|
{
|
2014-09-09 10:00:42 +00:00
|
|
|
friend class FRenderState;
|
|
|
|
|
2013-06-23 07:49:34 +00:00
|
|
|
struct FTextureLayer
|
|
|
|
{
|
|
|
|
FTexture *texture;
|
|
|
|
bool animated;
|
|
|
|
};
|
|
|
|
|
|
|
|
static TArray<FMaterial *> mMaterials;
|
|
|
|
static int mMaxBound;
|
|
|
|
|
|
|
|
FGLTexture *mBaseLayer;
|
|
|
|
TArray<FTextureLayer> mTextureLayers;
|
|
|
|
int mShaderIndex;
|
|
|
|
|
2014-08-22 21:50:38 +00:00
|
|
|
short mLeftOffset;
|
|
|
|
short mTopOffset;
|
|
|
|
short mWidth;
|
|
|
|
short mHeight;
|
|
|
|
short mRenderWidth;
|
|
|
|
short mRenderHeight;
|
|
|
|
bool mExpanded;
|
2013-06-23 07:49:34 +00:00
|
|
|
|
2014-08-22 21:50:38 +00:00
|
|
|
float mSpriteU[2], mSpriteV[2];
|
|
|
|
FloatRect mSpriteRect;
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
|
|
FGLTexture * ValidateSysTexture(FTexture * tex, bool expand);
|
|
|
|
bool TrimBorders(int *rect);
|
|
|
|
|
|
|
|
public:
|
|
|
|
FTexture *tex;
|
|
|
|
|
|
|
|
FMaterial(FTexture *tex, bool forceexpand);
|
|
|
|
~FMaterial();
|
|
|
|
void Precache();
|
2016-05-02 23:00:52 +00:00
|
|
|
void PrecacheList(SpriteHits &translations);
|
2013-06-23 07:49:34 +00:00
|
|
|
bool isMasked() const
|
|
|
|
{
|
|
|
|
return !!mBaseLayer->tex->bMasked;
|
|
|
|
}
|
|
|
|
|
2014-08-22 21:50:38 +00:00
|
|
|
int GetLayers() const
|
|
|
|
{
|
|
|
|
return mTextureLayers.Size() + 1;
|
|
|
|
}
|
|
|
|
|
2014-09-09 11:21:36 +00:00
|
|
|
void Bind(int clamp, int translation);
|
2013-06-23 07:49:34 +00:00
|
|
|
|
2015-04-04 11:37:55 +00:00
|
|
|
unsigned char * CreateTexBuffer(int translation, int & w, int & h, bool allowhires=true, bool createexpanded = true) const
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
2015-04-04 11:37:55 +00:00
|
|
|
return mBaseLayer->CreateTexBuffer(translation, w, h, allowhires? tex : NULL, createexpanded);
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Clean(bool f)
|
|
|
|
{
|
|
|
|
mBaseLayer->Clean(f);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BindToFrameBuffer();
|
|
|
|
// Patch drawing utilities
|
|
|
|
|
2014-08-22 21:50:38 +00:00
|
|
|
void GetSpriteRect(FloatRect * r) const
|
|
|
|
{
|
|
|
|
*r = mSpriteRect;
|
|
|
|
}
|
|
|
|
|
2016-04-07 23:42:43 +00:00
|
|
|
void GetTexCoordInfo(FTexCoordInfo *tci, float x, float y) const;
|
|
|
|
|
|
|
|
void GetTexCoordInfo(FTexCoordInfo *tci, side_t *side, int texpos) const
|
|
|
|
{
|
2016-04-23 09:38:33 +00:00
|
|
|
GetTexCoordInfo(tci, (float)side->GetTextureXScale(texpos), (float)side->GetTextureYScale(texpos));
|
2016-04-07 23:42:43 +00:00
|
|
|
}
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
|
|
// This is scaled size in integer units as needed by walls and flats
|
2014-08-22 21:50:38 +00:00
|
|
|
int TextureHeight() const { return mRenderHeight; }
|
|
|
|
int TextureWidth() const { return mRenderWidth; }
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
|
|
int GetAreas(FloatRect **pAreas) const;
|
|
|
|
|
2014-08-22 21:50:38 +00:00
|
|
|
int GetWidth() const
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
2014-08-22 21:50:38 +00:00
|
|
|
return mWidth;
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
|
|
|
|
2014-08-22 21:50:38 +00:00
|
|
|
int GetHeight() const
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
2014-08-22 21:50:38 +00:00
|
|
|
return mHeight;
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
|
|
|
|
2014-08-22 21:50:38 +00:00
|
|
|
int GetLeftOffset() const
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
2014-08-22 21:50:38 +00:00
|
|
|
return mLeftOffset;
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
|
|
|
|
2014-08-22 21:50:38 +00:00
|
|
|
int GetTopOffset() const
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
2014-08-22 21:50:38 +00:00
|
|
|
return mTopOffset;
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
|
|
|
|
2014-08-22 21:50:38 +00:00
|
|
|
int GetScaledLeftOffset() const
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
2016-03-29 09:26:33 +00:00
|
|
|
return int(mLeftOffset / tex->Scale.X);
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
|
|
|
|
2014-08-22 21:50:38 +00:00
|
|
|
int GetScaledTopOffset() const
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
2016-03-29 09:26:33 +00:00
|
|
|
return int(mTopOffset / tex->Scale.Y);
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
|
|
|
|
2014-08-22 21:50:38 +00:00
|
|
|
float GetScaledLeftOffsetFloat() const
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
2016-03-29 09:26:33 +00:00
|
|
|
return float(mLeftOffset / tex->Scale.X);
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
|
|
|
|
2014-08-22 21:50:38 +00:00
|
|
|
float GetScaledTopOffsetFloat() const
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
2016-03-29 09:26:33 +00:00
|
|
|
return float(mTopOffset/ tex->Scale.Y);
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// This is scaled size in floating point as needed by sprites
|
2014-08-22 21:50:38 +00:00
|
|
|
float GetScaledWidthFloat() const
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
2016-03-29 09:26:33 +00:00
|
|
|
return float(mWidth / tex->Scale.X);
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
|
|
|
|
2014-08-22 21:50:38 +00:00
|
|
|
float GetScaledHeightFloat() const
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
2016-03-29 09:26:33 +00:00
|
|
|
return float(mHeight / tex->Scale.Y);
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Get right/bottom UV coordinates for patch drawing
|
|
|
|
float GetUL() const { return 0; }
|
|
|
|
float GetVT() const { return 0; }
|
2014-08-22 21:50:38 +00:00
|
|
|
float GetUR() const { return 1; }
|
|
|
|
float GetVB() const { return 1; }
|
|
|
|
float GetU(float upix) const { return upix/(float)mWidth; }
|
|
|
|
float GetV(float vpix) const { return vpix/(float)mHeight; }
|
2013-06-23 07:49:34 +00:00
|
|
|
|
2014-08-22 21:50:38 +00:00
|
|
|
float GetSpriteUL() const { return mSpriteU[0]; }
|
|
|
|
float GetSpriteVT() const { return mSpriteV[0]; }
|
|
|
|
float GetSpriteUR() const { return mSpriteU[1]; }
|
|
|
|
float GetSpriteVB() const { return mSpriteV[1]; }
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool GetTransparent() const
|
|
|
|
{
|
|
|
|
if (mBaseLayer->bIsTransparent == -1)
|
|
|
|
{
|
|
|
|
if (!mBaseLayer->tex->bHasCanvas)
|
|
|
|
{
|
|
|
|
int w, h;
|
2014-05-11 17:44:19 +00:00
|
|
|
unsigned char *buffer = CreateTexBuffer(0, w, h);
|
2013-06-23 07:49:34 +00:00
|
|
|
delete [] buffer;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mBaseLayer->bIsTransparent = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return !!mBaseLayer->bIsTransparent;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void DeleteAll();
|
|
|
|
static void FlushAll();
|
2014-08-22 21:50:38 +00:00
|
|
|
static FMaterial *ValidateTexture(FTexture * tex, bool expand);
|
|
|
|
static FMaterial *ValidateTexture(FTextureID no, bool expand, bool trans);
|
2014-08-31 17:00:17 +00:00
|
|
|
static void ClearLastTexture();
|
2013-06-23 07:49:34 +00:00
|
|
|
|
2016-08-25 23:36:21 +00:00
|
|
|
static void InitGlobalState();
|
2013-06-23 07:49:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
2016-09-06 09:58:22 +00:00
|
|
|
|
|
|
|
|