Jump to content
  • Advertisement
Sign in to follow this  

OpenGL Loading S3 compressed textures from memory (DXT1- DXT5)

This topic is 2999 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts


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:


(*currentTextureReference)->LockRect(0U,&rect,0, 0)));

switch(format) {
// 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;


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?


[Edited by - treeway on September 2, 2010 3:38:23 AM]

Share this post

Link to post
Share on other sites
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.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!