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"
|
|
|
|
|
|
|
|
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;
|
|
|
|
fixed_t mScaleX;
|
|
|
|
fixed_t mScaleY;
|
|
|
|
fixed_t mTempScaleX;
|
|
|
|
fixed_t mTempScaleY;
|
|
|
|
bool mWorldPanning;
|
|
|
|
|
|
|
|
float FloatToTexU(float v) const { return v / mRenderWidth; }
|
|
|
|
float FloatToTexV(float v) const { return v / mRenderHeight; }
|
|
|
|
fixed_t RowOffset(fixed_t ofs) const;
|
|
|
|
fixed_t TextureOffset(fixed_t ofs) const;
|
|
|
|
fixed_t TextureAdjustWidth() const;
|
|
|
|
};
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
// 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
|
|
|
|
bool bExpand;
|
|
|
|
|
2014-05-11 17:44:19 +00:00
|
|
|
unsigned char * LoadHiresTexture(FTexture *hirescheck, int *width, int *height, bool alphatexture);
|
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-08-22 21:50:38 +00:00
|
|
|
const FHardwareTexture *Bind(int texunit, int clamp, int translation, bool alphatexture, FTexture *hirescheck);
|
2014-06-21 13:50:32 +00:00
|
|
|
const FHardwareTexture *BindPatch(int texunit, int translation, bool alphatexture);
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
FGLTexture(FTexture * tx, bool expandpatches);
|
|
|
|
~FGLTexture();
|
|
|
|
|
2014-08-22 21:50:38 +00:00
|
|
|
unsigned char * CreateTexBuffer(int translation, int & w, int & h, FTexture *hirescheck, bool alphatexture);
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
|
|
void Clean(bool all);
|
|
|
|
int Dump(int i);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
// this is the material class for OpenGL.
|
|
|
|
//
|
|
|
|
//===========================================================================
|
|
|
|
|
|
|
|
class FMaterial
|
|
|
|
{
|
|
|
|
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();
|
|
|
|
bool isMasked() const
|
|
|
|
{
|
|
|
|
return !!mBaseLayer->tex->bMasked;
|
|
|
|
}
|
|
|
|
|
2014-08-22 21:50:38 +00:00
|
|
|
int GetLayers() const
|
|
|
|
{
|
|
|
|
return mTextureLayers.Size() + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
//void Bind(int clamp = 0, int translation = 0, int overrideshader = 0, bool alphatexture = false);
|
|
|
|
void Bind(int clamp, int translation, int overrideshader, bool alphatexture);
|
2013-06-23 07:49:34 +00:00
|
|
|
|
2014-08-22 21:50:38 +00:00
|
|
|
unsigned char * CreateTexBuffer(int translation, int & w, int & h, bool allowhires=true) const
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
2014-08-22 21:50:38 +00:00
|
|
|
return mBaseLayer->CreateTexBuffer(translation, w, h, allowhires? tex:NULL, 0);
|
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;
|
|
|
|
}
|
|
|
|
|
2013-06-23 07:49:34 +00:00
|
|
|
void GetTexCoordInfo(FTexCoordInfo *tci, fixed_t x, fixed_t y) const;
|
|
|
|
|
|
|
|
// 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
|
|
|
{
|
2014-08-22 21:50:38 +00:00
|
|
|
return DivScale16(mLeftOffset, tex->xScale);
|
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
|
|
|
{
|
2014-08-22 21:50:38 +00:00
|
|
|
return DivScale16(mTopOffset, tex->yScale);
|
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
|
|
|
{
|
2014-08-22 21:50:38 +00:00
|
|
|
return mLeftOffset / FIXED2FLOAT(tex->xScale);
|
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
|
|
|
{
|
2014-08-22 21:50:38 +00:00
|
|
|
return mTopOffset/ FIXED2FLOAT(tex->yScale);
|
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
|
|
|
{
|
2014-08-22 21:50:38 +00:00
|
|
|
return mWidth / FIXED2FLOAT(tex->xScale);
|
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
|
|
|
{
|
2014-08-22 21:50:38 +00:00
|
|
|
return mHeight / FIXED2FLOAT(tex->yScale);
|
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);
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|