Mercurial > mm7
diff Engine/Graphics/Texture.h @ 2572:d87bfbd3bb3b
Step towards unification of Texture and RGBTexture (class Image)
author | a.parshin |
---|---|
date | Sat, 05 Mar 2016 01:51:54 +0200 |
parents | c674d547cc7c |
children | 0c67be4ec900 |
line wrap: on
line diff
--- a/Engine/Graphics/Texture.h Mon Oct 05 00:19:13 2015 +0200 +++ b/Engine/Graphics/Texture.h Sat Mar 05 01:51:54 2016 +0200 @@ -1,7 +1,83 @@ #pragma once +#include "Engine/Engine.h" + #include <stdio.h> #include <array> +enum IMAGE_FORMAT +{ + IMAGE_FORMAT_R5G6B5 = 0, + IMAGE_FORMAT_A1R5G5B5, + IMAGE_FORMAT_A8R8G8B8, + + IMAGE_NUM_FORMATS, + IMAGE_INVALID_FORMAT = -1, +}; + + +inline unsigned int IMAGE_FORMAT_BytesPerPixel(IMAGE_FORMAT format) +{ + switch (format) + { + case IMAGE_FORMAT_R5G6B5: return 2; + case IMAGE_FORMAT_A1R5G5B5: return 2; + case IMAGE_FORMAT_A8R8G8B8: return 4; + + default: + Error("Invalid format: %d", format); + return 0; + } +} + + +struct ImageLoader +{ + virtual bool Load(unsigned int *width, unsigned int *height, void **pixels, IMAGE_FORMAT *format) = 0; +}; + + + +struct Image +{ + inline Image(bool lazy_initialization = true): + lazy_initialization(lazy_initialization), initialized(false), + width(0), height(0), native_format(IMAGE_INVALID_FORMAT), + loader(nullptr) + { + for (unsigned int i = 0; i < IMAGE_NUM_FORMATS; ++i) + pixels[i] = 0; + } + + + bool Image_From_LOD(const wchar_t *name); + bool ColorKey_From_LOD(const wchar_t *name, unsigned __int16 colorkey); + bool Alpha_From_LOD(const wchar_t *name); + + bool PCX_From_IconsLOD(const wchar_t *name); + bool PCX_From_NewLOD(const wchar_t *name); + bool PCX_From_File(const wchar_t *filename); + + + unsigned int GetWidth(); + unsigned int GetHeight(); + const void *GetPixels(IMAGE_FORMAT format); + + bool Release(); + + + protected: + bool lazy_initialization; + bool initialized; + ImageLoader *loader; + + unsigned int width; + unsigned int height; + IMAGE_FORMAT native_format; + void *pixels[IMAGE_NUM_FORMATS]; + + bool LoadImageData(); +}; + /* 194 */ @@ -53,8 +129,9 @@ short palette_id1; short palette_id2; unsigned int uDecompressedSize; - int pBits; - unsigned __int8 *pLevelOfDetail0_prolly_alpha_mask; + int pBits; // 0x0002 - generate mipmaps + // 0x0200 - 0th palette entry is transparent, else colorkey (7FF) + unsigned __int8 *paletted_pixels; unsigned __int8 *pLevelOfDetail1; /*unsigned __int8 *pLevelOfDetail2;*/ struct ID3D11ShaderResourceView *d3d11_srv; // replace ol SW stuff with new fields to keep data integrity /*unsigned __int8 *pLevelOfDetail3;*/ struct D3D11_TEXTURE2D_DESC *d3d11_desc; @@ -127,7 +204,7 @@ -extern std::array<struct RGBTexture, 45> pSavegameThumbnails; +extern std::array<struct Image *, 45> pSavegameThumbnails; extern std::array<struct Texture *, 2> pTexture_LloydBeacons; extern struct Texture *pTexture_50635C; extern struct Texture *pTex_book_button8_off; @@ -171,9 +248,11 @@ extern struct Texture *pTex_moon_2_2; extern struct Texture *pTex_moon_ful; - - -extern RGBTexture stru_506E40; // weak +extern struct Texture *minimap_loop; // 5079D8 +extern struct Texture *_5079B4_compass; // 5079B4 +extern struct Texture *_5079C8_init_y; // 5079C8 +extern struct Texture *_5079CC_init_r; // 5079CC +extern struct Texture *_5079D0_init_g; // 5079D0 extern int uTextureID_RestUI_restb4; // weak @@ -189,15 +268,6 @@ extern int uTextureID_ar_up_up; // weak -extern int uTextureID_507698; // weak -extern int uTextureID_50769C; // weak -extern int uTextureID_5076A0; // weak -extern int uTextureID_5076A4; // weak -extern int uTextureID_5076A8; // weak -extern int uTextureID_5076AC; // weak -extern int uTextureID_5076B0; // weak -extern int uTextureID_5076B4; // weak -extern int uTextureID_Parchment; // weak extern unsigned int uTextureID_mhp_yel; extern unsigned int uTextureID_mhp_red; extern unsigned int uTextureID_mhp_grn; @@ -257,17 +327,8 @@ extern unsigned int uTextureID_BarBlue; -extern unsigned int uTextureID_right_panel; // weak - - -extern struct RGBTexture *pTexture_StatusBar; -extern struct RGBTexture *pTexture_LeftFrame; -extern struct RGBTexture *pTexture_TopFrame; -extern struct RGBTexture *pTexture_BottomFrame; -extern struct RGBTexture *pTexture_RightFrame; - - -extern unsigned int uTextureID_right_panel_loop; // weak +extern Texture *right_panel; +extern Texture *right_panel_loop; extern struct Texture *pTexture_Leather; @@ -318,9 +379,6 @@ extern struct Texture pTex_F7CE30; - -extern struct RGBTexture stru_5773C4; // idb - extern struct stru355 stru_4E82A4;// = {0x20, 0x41, 0, 0x20, 0xFF0000, 0xFF00, 0xFF, 0xFF000000}; moved to texture.h extern struct stru355 stru_4EFCBC;// = {0x20, 0x41, 0, 0x10, 0x7C00, 0x3E0, 0x1F, 0x8000}; moved to texture.h