DXT5 support in NemesisCore

Posted 2010-05-08

With few neat tricks adding DXT5 support (and importing dds) to UEngine can be quite easy thing (although it took me some time to figure things out). Easiest way to take is make UTexture subclass and import raw data directly into some variable, then just save it.

class NEMESISNATIVE_API UNMTextureDDS : public UTexture
{
	DECLARE_CLASS(UNMTextureDDS,UTexture,CLASS_SafeReplace,NemesisNative)
public:
	unsigned char* m_pPixels;
	int	m_iComponents;
	int	m_Format;
	int	m_iNumMipMaps;
	int m_iBuffer;
	int m_iHeight;
	int m_iWidth;

	void Serialize( FArchive& Ar )
	{
		Super::Serialize(Ar);

		Ar<<m_iComponents<<m_Format<<m_iNumMipMaps<<m_iBuffer;
		Ar<<m_iHeight<<m_iWidth;
		Ar<<Scale<<Friction<<Specular<<Diffuse<<DetailTexture
		Ar<<MacroTexture<<BumpMap<<Alpha<<USize<<VSize;
		Ar<<UClamp<<VClamp;
	
		if( Ar.IsLoading() )
			m_pPixels = new unsigned char[m_iBuffer];

		Ar.Serialize( m_pPixels, m_iBuffer );
	}
}

Of course rendering it is another case. Easiest way is to make check in SetTExtureNoCheck after:

Tex.pBind = pBind;
glBindTexture(GL_TEXTURE_2D, pBind->Id);

and using Cast(Info.Texture)->m_pPixels generate texture.