1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
|
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
/*
* Copyright (C) 2006-2010 - Frictional Games
*
* This file is part of HPL1 Engine.
*/
#ifndef HPL_TEXTURE_H
#define HPL_TEXTURE_H
#include "common/array.h"
#include "graphics/pixelformat.h"
#include "hpl1/engine/graphics/GraphicsTypes.h"
#include "hpl1/engine/graphics/LowLevelPicture.h"
#include "hpl1/engine/graphics/bitmap2D.h"
#include "hpl1/engine/resources/ResourceBase.h"
namespace hpl {
enum eTextureType {
eTextureType_Normal,
eTextureType_RenderTarget,
eTextureType_LastEnum
};
//-----------------------------------------
enum eTextureTarget {
eTextureTarget_1D,
eTextureTarget_2D,
eTextureTarget_Rect,
eTextureTarget_CubeMap,
eTextureTarget_3D,
eTextureTarget_LastEnum
};
//-----------------------------------------
enum eTextureWrap {
eTextureWrap_Repeat,
eTextureWrap_Clamp,
eTextureWrap_ClampToEdge,
eTextureWrap_ClampToBorder,
eTextureWrap_LastEnum
};
//-----------------------------------------
enum eTextureFilter {
eTextureFilter_Bilinear,
eTextureFilter_Trilinear,
eTextureFilter_LastEnum
};
//-----------------------------------------
enum eTextureAnimMode {
eTextureAnimMode_None,
eTextureAnimMode_Loop,
eTextureAnimMode_Oscillate,
eTextureAnimMode_LastEnum
};
//-----------------------------------------
class iLowLevelGraphics;
class iTexture : public LowLevelPicture, public iResourceBase {
public:
iTexture(tString asName, tString asType, Graphics::PixelFormat *apPxlFmt, iLowLevelGraphics *apLowLevelGraphics,
eTextureType aType, bool abUseMipMaps, eTextureTarget aTarget,
bool abCompress = false)
: LowLevelPicture(asType), iResourceBase(asName, 0),
mType(aType), mbUseMipMaps(abUseMipMaps),
mpLowLevelGraphics(apLowLevelGraphics), mbCompress(abCompress),
mTarget(aTarget),
mWrapS(eTextureWrap_Repeat), mWrapT(eTextureWrap_Repeat), mWrapR(eTextureWrap_Repeat),
mfFrameTime(1), mAnimMode(eTextureAnimMode_Loop), mlSizeLevel(0), mvMinLevelSize(16, 16),
mfAnisotropyDegree(1.0f), mFilter(eTextureFilter_Bilinear), _bpp(apPxlFmt->bpp()) {}
virtual ~iTexture() {}
void SetSizeLevel(unsigned int alLevel) { mlSizeLevel = alLevel; }
void SetMinLevelSize(const cVector2l &avSize) { mvMinLevelSize = avSize; }
bool reload() override { return false; }
void unload() override {}
void destroy() override {}
/**
* Create a texture from a bitmap, work only for 1D, 2D and Rect targets. Doesn't work with render targets.
* \param pBmp
* \return
*/
virtual bool CreateFromBitmap(Bitmap2D *pBmp) = 0;
/**
* Create a cube map texture from a vector of bitmaps. Doesn't work with render targets.
* All bitmaps most be square, a power of 2 and the same same. The order must be: posX, negX, posY, negY, posZ and negZ.
* \param *avBitmaps a vector with at least 6 bitmaps
* \return
*/
virtual bool CreateCubeFromBitmapVec(tBitmap2DVec *avBitmaps) = 0;
/**
* Create a texture with color, works with all target types. Works with render targets.
* \param alWidth
* \param alHeight
* \param aCol
* \return
*/
virtual bool Create(unsigned int alWidth, unsigned int alHeight, cColor aCol) = 0;
virtual bool CreateAnimFromBitmapVec(tBitmap2DVec *avBitmaps) = 0;
virtual bool CreateFromArray(unsigned char *apPixelData, int alChannels, const cVector3l &avSize) = 0;
virtual void Update(float afTimeStep) = 0;
virtual void SetPixels2D(int alLevel, const cVector2l &avOffset, const cVector2l &avSize,
eColorDataFormat aDataFormat, void *apPixelData) = 0;
virtual void SetFilter(eTextureFilter aFilter) = 0;
virtual void SetAnisotropyDegree(float afX) = 0;
eTextureFilter GetFilter() { return mFilter; }
float GetAnisotropyDegree(float afX) { return mfAnisotropyDegree; }
virtual float GetGamma() = 0;
virtual void SetGamma(float afGamma) = 0;
virtual int GetHandle() = 0;
virtual bool hasAlpha() override { return false; }
uint32 getBpp() const override { return _bpp; }
virtual void SetWrapS(eTextureWrap aMode) = 0;
virtual void SetWrapT(eTextureWrap aMode) = 0;
virtual void SetWrapR(eTextureWrap aMode) = 0;
eTextureWrap GetWrapS() { return mWrapS; }
eTextureWrap GetWrapT() { return mWrapT; }
eTextureWrap GetWrapR() { return mWrapR; }
void SetFrameTime(float afX) { mfFrameTime = afX; }
float GetFrameTime() { return mfFrameTime; }
eTextureAnimMode GetAnimMode() { return mAnimMode; }
void SetAnimMode(eTextureAnimMode aMode) { mAnimMode = aMode; };
eTextureType GetTextureType() { return mType; }
bool UsesMipMaps() { return mbUseMipMaps; }
void SetMipMapUse(bool abX) { mbUseMipMaps = abX; }
eTextureTarget GetTarget() { return mTarget; }
virtual bool HasAnimation() = 0;
virtual void NextFrame() = 0;
virtual void PrevFrame() = 0;
virtual float GetT() = 0;
virtual float GetTimeCount() = 0;
virtual void SetTimeCount(float afX) = 0;
virtual int GetCurrentLowlevelHandle() = 0;
protected:
eTextureType mType;
eTextureTarget mTarget;
eTextureWrap mWrapS;
eTextureWrap mWrapT;
eTextureWrap mWrapR;
eTextureFilter mFilter;
float mfAnisotropyDegree;
bool mbUseMipMaps;
bool mbCompress;
iLowLevelGraphics *mpLowLevelGraphics;
float mfFrameTime;
eTextureAnimMode mAnimMode;
unsigned int mlSizeLevel;
uint32 _bpp;
cVector2l mvMinLevelSize;
};
typedef Common::Array<iTexture *> tTextureVec;
typedef tTextureVec::iterator tTextureVecIt;
} // namespace hpl
#endif // HPL_TEXTURE_H
|