My Project
TextureEntityDirectX.h
1 #pragma once
2 #include "TextureEntity.h"
3 
4 namespace ParaEngine
5 {
6  //--------------------------------------------------------
9  //--------------------------------------------------------
11  {
12  public:
13  union
14  {
16  LPDIRECT3DTEXTURE9 m_pTexture;
18  LPDIRECT3DCUBETEXTURE9 m_pCubeTexture;
20  LPDIRECT3DSURFACE9 m_pSurface;
22  LPDIRECT3DTEXTURE9* m_pTextureSequence;
23  };
24 
25  public:
26  virtual AssetEntity::AssetType GetType(){ return AssetEntity::texture; };
27  public:
28 
29 
30  TextureEntityDirectX(const AssetKey& key);
32  virtual ~TextureEntityDirectX();
33 
34  virtual HRESULT InitDeviceObjects();
35  virtual HRESULT RestoreDeviceObjects();
36  virtual HRESULT InvalidateDeviceObjects();
37  virtual HRESULT DeleteDeviceObjects();
38  virtual bool SetRenderTarget(int nIndex = 0);
42  virtual HRESULT LoadFromMemory(const char* buffer, DWORD nFileSize, UINT nMipLevels, D3DFORMAT dwTextureFormat = D3DFMT_UNKNOWN, void** ppTexture = NULL);
43 
48  virtual bool IsLoaded();
49 
54  int GetFrameCount();
55 
59  virtual const TextureInfo* GetTextureInfo();
60 
62  virtual DeviceTexturePtr_type GetTexture();
63 
65  void SetTexture(LPDIRECT3DTEXTURE9 pSrcTexture);
66 
73  void CreateTexture(LPDIRECT3DTEXTURE9 pSrcTexture, D3DFORMAT dwFormat = D3DFMT_DXT3, int width = 256, int height = 256, UINT MipLevels = 0);
74 
84  HRESULT CreateTextureFromFile_Serial(RenderDevicePtr pDev = NULL, const char* sFileName = NULL, IDirect3DTexture9** ppTexture = NULL, D3DFORMAT dwTextureFormat = D3DFMT_UNKNOWN, UINT nMipLevels = D3DX_DEFAULT, Color dwColorKey = 0);
85 
89  virtual bool SaveToFile(const char* filename, D3DFORMAT dwFormat, int width, int height, UINT MipLevels = 1, DWORD Filter = D3DX_DEFAULT, Color ColorKey = 0);
90 
100  static void GetFormatAndMipLevelFromFileName(const string& filename, D3DFORMAT* pdwTextureFormat, UINT* pnMipLevels);
101 
110  static void GetFormatAndMipLevelFromFileNameEx(const string& filename, D3DFORMAT* pdwTextureFormat, UINT* pnMipLevels);
111 
113  void SetSurface(LPDIRECT3DSURFACE9 pSurface);
114 
116  LPDIRECT3DSURFACE9 GetSurface();
117 
119  D3DFORMAT GetD3DFormat();
120 
129  static void LoadImage(char *sBufMemFile, int sizeBuf, int &width, int &height, byte ** ppBuffer, bool bAlpha);
134  static bool LoadImageOfFormat(const std::string& sTextureFileName, char *sBufMemFile, int sizeBuf, int &width, int &height, byte ** ppBuffer, int* pBytesPerPixel = NULL, int nFormat = -1);
135  static bool LoadImageOfFormatEx(const std::string& sTextureFileName, char *sBufMemFile, int sizeBuf, int &width, int &height, byte ** ppBuffer, int* pBytesPerPixel = NULL, int nFormat = -1, ImageExtendInfo *info = nullptr);
136 
138  static bool StretchRect(TextureEntityDirectX * pSrcTexture, TextureEntityDirectX * pDestTexture);
139 
141  static TextureEntity* CreateTexture(const uint8 * pTexels, int width, int height, int rowLength, int bytesPerPixel, uint32 nMipLevels = 0, D3DPOOL dwCreatePool = D3DPOOL_MANAGED, DWORD nFormat = 0);
142  static TextureEntity* CreateTexture(const char* pFileName, uint32 nMipLevels = 0, D3DPOOL dwCreatePool = D3DPOOL_MANAGED);
143  };
144 
145  // the manager class
147 }
void CreateTexture(LPDIRECT3DTEXTURE9 pSrcTexture, D3DFORMAT dwFormat=D3DFMT_DXT3, int width=256, int height=256, UINT MipLevels=0)
Copy pSrcTexture's surface to the current texture.
Which DXT Compression to Use? Obviously, there are some trade-offs between the different formats whic...
Definition: TextureEntity.h:29
LPDIRECT3DTEXTURE9 m_pTexture
static texture
Definition: TextureEntityDirectX.h:16
virtual bool IsLoaded()
most assets are loaded asynchronously.
Texture Entity distinguish one template from other The following type are all supported by texture en...
Definition: TextureEntityDirectX.h:10
void SetSurface(LPDIRECT3DSURFACE9 pSurface)
secretly, change the m_pSurface
AssetType
each asset type has a unique asset type number
Definition: AssetEntity.h:82
basic texture information
Definition: TextureEntity.h:83
different physics engine has different winding order.
Definition: EventBinding.h:32
LPDIRECT3DSURFACE9 GetSurface()
Get the surface.
a very thin wrapper to DirectX device with a portable version of openGL implementation.
Definition: RenderDeviceDirectX.h:10
virtual bool SaveToFile(const char *filename, D3DFORMAT dwFormat, int width, int height, UINT MipLevels=1, DWORD Filter=D3DX_DEFAULT, Color ColorKey=0)
save any texture to a different texture file format and save with full mipmapping to disk...
int GetFrameCount()
For animated textures.
static void GetFormatAndMipLevelFromFileNameEx(const string &filename, D3DFORMAT *pdwTextureFormat, UINT *pnMipLevels)
determine the texture format and mip level from file name.
HRESULT CreateTextureFromFile_Serial(RenderDevicePtr pDev=NULL, const char *sFileName=NULL, IDirect3DTexture9 **ppTexture=NULL, D3DFORMAT dwTextureFormat=D3DFMT_UNKNOWN, UINT nMipLevels=D3DX_DEFAULT, Color dwColorKey=0)
this function is mostly used internally.
AssetManager manages a set of asset entities of a certain type.
Definition: AssetManager.h:13
virtual HRESULT LoadFromMemory(const char *buffer, DWORD nFileSize, UINT nMipLevels, D3DFORMAT dwTextureFormat=D3DFMT_UNKNOWN, void **ppTexture=NULL)
load from memory buffer.
Definition: TextureEntity.h:8
virtual DeviceTexturePtr_type GetTexture()
Get the texture for rendering.
D3DFORMAT GetD3DFormat()
get d3d format
LPDIRECT3DCUBETEXTURE9 m_pCubeTexture
cube texture
Definition: TextureEntityDirectX.h:18
LPDIRECT3DTEXTURE9 * m_pTextureSequence
animated texture sequence
Definition: TextureEntityDirectX.h:22
static bool StretchRect(TextureEntityDirectX *pSrcTexture, TextureEntityDirectX *pDestTexture)
Copy render target content from one surface to another.
std::string AssetKey
the unique key object for asset entity.
Definition: AssetEntity.h:13
void SetTexture(LPDIRECT3DTEXTURE9 pSrcTexture)
the internal texture managed.
Definition: ParaColor.h:275
static bool LoadImageOfFormat(const std::string &sTextureFileName, char *sBufMemFile, int sizeBuf, int &width, int &height, byte **ppBuffer, int *pBytesPerPixel=NULL, int nFormat=-1)
this function uses FreeImage lib and support more formats.
virtual const TextureInfo * GetTextureInfo()
get texture info.
static void GetFormatAndMipLevelFromFileName(const string &filename, D3DFORMAT *pdwTextureFormat, UINT *pnMipLevels)
determine the texture format and mip level from file name.
LPDIRECT3DSURFACE9 m_pSurface
RenderTarget.
Definition: TextureEntityDirectX.h:20
static void LoadImage(char *sBufMemFile, int sizeBuf, int &width, int &height, byte **ppBuffer, bool bAlpha)
load image of any format to buffer.