4jcraft/targets/minecraft/client/renderer/texture/Stitcher.h

70 lines
1.9 KiB
C++

#pragma once
#include <format>
#include <set>
#include <string>
#include <vector>
#include "TextureHolder.h"
class StitchSlot;
class Texture;
class Stitcher {
public:
static const int STITCH_SUCCESS = 0;
static const int STITCH_RETRY = 1;
static const int STITCH_ABORT = 2;
static const int MAX_MIPLEVEL =
0; // This should be 4 again later when we *ACTUALLY* mipmap
static const int MIN_TEXEL = 1 << MAX_MIPLEVEL;
private:
std::set<TextureHolder*, TextureHolderLessThan>
texturesToBeStitched; // = new HashSet<TextureHolder>(256);
std::vector<StitchSlot*> storage; // = new ArrayList<StitchSlot>(256);
int storageX;
int storageY;
int maxWidth;
int maxHeight;
bool forcePowerOfTwo;
int forcedScale;
Texture* stitchedTexture;
std::string name;
void _init(const std::string& name, int maxWidth, int maxHeight,
bool forcePowerOfTwo, int forcedScale);
public:
Stitcher(const std::string& name, int maxWidth, int maxHeight,
bool forcePowerOfTwo);
Stitcher(const std::string& name, int maxWidth, int maxHeight,
bool forcePowerOfTwo, int forcedScale);
int getWidth();
int getHeight();
void addTexture(TextureHolder* textureHolder);
Texture* constructTexture(bool mipmap = true); // 4J Added mipmap param
void stitch();
std::vector<StitchSlot*>* gatherAreas();
private:
// Based on:
// http://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2
int smallestEncompassingPowerOfTwo(int input);
bool addToStorage(TextureHolder* textureHolder);
/**
* Expand the current storage to take in account the new texture.
* This should only be called if it didn't fit anywhere.
*
* @param textureHolder
* @return Boolean indicating if it could accommodate for the growth
*/
bool expand(TextureHolder* textureHolder);
};