Loading S3 compressed textures from memory (DXT1- DXT5)

Started by
2 comments, last by 21st Century Moose 13 years, 7 months ago
Hi

In the OpenGL side of my engine i load in bianry blocks containing S3 Compressed textures in the folloding way:

    glCompressedTexImage2D(GL_TEXTURE_2D, currentMipMapLevel, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, width, height, 0, compressedWidth * compressedHeight * 8, data);		


on the directx side for non-compressed textures i do this:

d3DDevice->CreateTexture(width,height,numLevels,usage,format,D3DPOOL_MANAGED,currentTextureReference,NULL)(*currentTextureReference)->LockRect(0U,&rect,0, 0)));  			switch(format) {				case(D3DFMT_A8R8G8B8):				case(D3DFMT_A8B8G8R8):				case(D3DFMT_R8G8B8):				{					// Change the pointer received from LockRect into a 32bit pointer					DWORD* pData=(DWORD*)(rect.pBits);					Uint pixelIndex(0U);					if(width >= height) {						for(int x=0; x < width; ++x) {							for(int y=0; y < height; ++y) {								// Get Pixel data							Byte red(*(data + pixelIndex));								Byte green(*(data + pixelIndex + (sizeof(cyan::Byte))));								Byte blue(*(data + pixelIndex + (sizeof(cyan::Byte)*2U)));																if(D3DFMT_R8G8B8 == format) { // 24 bit textures									pData[(((rect.Pitch/bytesPerPixel) * (y)) + x)] = D3DCOLOR_XRGB(red,green,blue);																	}								else{	 // 32 bit textures									cyan::Byte alpha(*(data + pixelIndex + (sizeof(cyan::Byte)*3U)));									pData[(((rect.Pitch/bytesPerPixel) * (y)) + x)] = D3DCOLOR_ARGB(alpha,red,green,blue);									}								pixelIndex += bytesPerPixel;							}						}					}....(*currentTextureReference)->UnlockRect(0U)			


This loads uncompressed textures from binary but i have to manually fill each pixel of the texture to avoid problems with pitch. What would be the equivalent for loading dxt1-5 compressed textures? i know that each dxt format has a pitch so cant do a memcpy directly from the binary into the texture. Does anyone know how i can load dxt1=5 textures in from memory?

thanks.

[Edited by - treeway on September 2, 2010 3:38:23 AM]
Advertisement
D3D is capable of loading DXT texture data directly without needing to decode the format, so just use D3DXCreateTextureFromFileInMemory (or D3DXCreateTextureFromFileInMemoryEx) or memcpy the full thing into your locked rect.

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

fantastic, this is the answer I was looking for.
Glad to help. :)

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

This topic is closed to new replies.

Advertisement