aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.Client/Stitcher.h
blob: 1e5b28c14752788a84e1992e199c338fee786e14 (plain)
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
#pragma once
using namespace std;

class StitchSlot;
class Texture;
#include "TextureHolder.h"

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:
	set<TextureHolder *, TextureHolderLessThan> texturesToBeStitched; // = new HashSet<TextureHolder>(256);
	vector<StitchSlot *> storage; // = new ArrayList<StitchSlot>(256);
	int storageX;
	int storageY;

	int maxWidth;
	int maxHeight;
	bool forcePowerOfTwo;
	int forcedScale;

	Texture *stitchedTexture;

	wstring name;

	void _init(const wstring &name, int maxWidth, int maxHeight, bool forcePowerOfTwo, int forcedScale);

public:
	Stitcher(const wstring &name, int maxWidth, int maxHeight, bool forcePowerOfTwo);
	Stitcher(const wstring &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();
	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);
};