summaryrefslogtreecommitdiff
path: root/layoutgl/texturemanager.cpp
blob: 896c40fd453f52a53a3bfe9b02ed5685d1ef675b (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
#include "texturemanager.h"
#include "ctr/image.h"

LGLTextureManager::LGLTextureManager() {
}

void LGLTextureManager::setup(QGLWidget *gl, const LYTLayout *layout) {
	// TODO: code to cleanup previous stuff

	//m_gl = gl;
	m_layout = layout;
	m_package = &layout->package();

	QStringList textures = layout->generateTextureRefs();

	foreach (const QString &texName, textures) {
		qDebug() << texName;

		QByteArray tplData = m_package->getTexture(texName);
		if (tplData.isEmpty()) {
			qDebug() << "[[[ NON-EXISTENT TEXTURE! ]]]";
			continue;
		}

		QDataStream tplStream(tplData);
		CTRImageCollection tpl(tplStream);

		const QImage &image = tpl.images.first().image;
		image.save(QString("tpl/%2__%1.png").arg(texName).arg((int)tpl.images.first().format));
		// dirty, dirty hack, TODO: FIXME
		GLuint tex = gl->bindTexture(image, GL_TEXTURE_2D);

		m_textures.insert(texName, tex);
		m_images.insert(texName, image);
	}
}