#include "stdafx.h"
#include "ogColor.h"
#include "ogTexture.h"
#include "gtasaQueue.h"
#include "ogEngine.h"

CTexture::CTexture () {
	texture = NULL;
}

CTexture::~CTexture () {
	clean ();
}

RwTexture * CTexture::read (char * name, char * maskName) {
	texture = RwReadTexture (name, maskName);
	return texture;
}

void CTexture::clean() {
	if (texture) {
		RwTextureDestroy (texture);
		texture = NULL;
	}
}

RwTexture * CTexture::reload (char * name) {
	clean ();
	return read (name, NULL);
}

RwTexture * CTexture::setAddressing(BYTE addressing) {
	texture->filterAddressing &= ~0x0000FF00;	// rwTEXTUREADDRESSINGMASK
	addressing &= 0x0F;
	texture->filterAddressing |= ((addressing << 4)|addressing) << 8;
	return texture;
}

void CTexture::drawTexturedRect(float *coords, RGBA *color) {
	_727420 (coords, color, color, color, color);
	RENDERSTATESET (rwRENDERSTATETEXTURERASTER, (DWORD)texture);
	RENDERPRIMITIVE (rwPRIMTYPETRIFAN, vertices, 4);
	RENDERSTATESET (rwRENDERSTATETEXTURERASTER, 0);
}