34#define DEBUG_TEXTURE 0
46 static auto baseidx = 0;
54 img.
savePNG(
"./ComposedTexture" + std::to_string(baseidx) +
"_" + std::to_string(cmpidx++) +
".png");
59 glBindTexture(GL_TEXTURE_2D, texID);
60 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, img.
width(), img.
height(), 0, GL_BGRA, GL_UNSIGNED_BYTE, img.
data());
61 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
62 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
67 const DB2Table* layoutsTbl =
WOWDB.getTable(
"CharComponentTextureLayouts");
70 LOG_ERROR <<
"Fail to retrieve Texture Layout information from game database";
74 const DB2Table* sectionsTbl =
WOWDB.getTable(
"CharComponentTextureSections");
75 if (!sectionsTbl || sectionsTbl->
getRowCount() == 0)
77 LOG_ERROR <<
"Fail to retrieve Section Layout information from game database";
82 for (
const auto& layoutRow : *layoutsTbl)
84 const int curLayout =
static_cast<int>(layoutRow.recordID());
85 LayoutSize texLayout = {
static_cast<int>(layoutRow.getUInt(
"Width")),
86 static_cast<int>(layoutRow.getUInt(
"Height"))};
88 std::map<int, CharRegionCoords> regionCoords;
94 for (
const auto& secRow : *sectionsTbl)
96 if (
static_cast<int>(secRow.getUInt(
"CharComponentTextureLayoutID")) != curLayout)
101 static_cast<int>(secRow.getUInt(
"X")),
102 static_cast<int>(secRow.getUInt(
"Y")),
103 static_cast<int>(secRow.getUInt(
"Width")),
104 static_cast<int>(secRow.getUInt(
"Height"))
106 regionCoords[
static_cast<int>(secRow.getUInt(
"SectionType"))] = coords;
111 LOG_ERROR <<
"Fail to retrieve Section Layout information from game database for layout" << curLayout;
115 LOG_INFO <<
"Found" << regionCoords.size() <<
"regions for layout" << curLayout;
124 const auto& coords = layoutInfos.second[ct.
region];
131 const auto newImage = tmp->scaled(coords.width, coords.height);
135 const auto region = ct.
region;
136 const auto layer = ct.
layer;
137 const auto x = coords.xpos;
138 const auto y = coords.ypos;
139 const auto width = coords.width;
140 const auto height = coords.height;
141 LOG_INFO << __FUNCTION__ << ct.
file->
fullname() << region << layer << x << y << width << height;
145 newImage.savePNG(
"./tex__" + std::to_string(region) +
"_" + std::to_string(x) +
"_" + std::to_string(y) +
"_" + std::to_string(width) +
"_" + std::to_string(height) +
".png");
152 destImage.
assign(newImage);
169 if (!tex || tex->w == 0 || tex->h == 0)
175 auto* tempbuf =
static_cast<unsigned char*
>(malloc(tex->w * tex->h * 4));
177 tex->getPixels(tempbuf, GL_BGRA);
constexpr int LAYOUT_BASE_REGION
TextureManager TEXTUREMANAGER
void reset(unsigned int _layoutSizeId)
std::vector< CharTextureComponent > m_components
unsigned int layoutSizeId
void compose(GLuint texID)
void burnComponent(SoftwareImage &destImage, CharTextureComponent &) const
static SoftwareImage * gameFileToQImage(GameFile *file)
static std::map< int, std::pair< LayoutSize, std::map< int, CharRegionCoords > > > LAYOUTS
static void initRegions()
void addLayer(GameFile *file, int region, int layer, int blendMode=1)
Provides typed, field-name-based access to records in a WDC DB2 file.
size_t getRowCount() const
Abstract base class representing a file within the game data archive.
const std::string & fullname() const
virtual void del(IDTYPE id)
std::map< IDTYPE, ManagedItem * > items
CPU-side image buffer storing BGRA pixel data.
void composite(const SoftwareImage &src, int destX, int destY, int blendMode=1)
Composite a source image onto this image at the given position.
bool savePNG(const std::string &path) const
Save as PNG to the given file path.
void assign(const SoftwareImage &src)
Replace contents entirely with a copy of src.
int height() const
Image height in pixels.
uint8_t * data()
Mutable pointer to the raw BGRA pixel buffer.
int width() const
Image width in pixels.
virtual GLuint add(GameFile *)
Coordinates of a region within the character texture atlas.
A single texture layer to be composited onto the character skin.
Dimensions of a character texture layout.