Jump to content

[SOLVED] Load RAW DXT1 texture


photo

Recommended Posts

Posted (edited)

Hello,

I try to load a RAW texture that I have in DTX1 format. I don't found a way to load a RAW texture. I try to load as image but log an error loading

int format = ::Unigine::Image::FORMAT_DXT1;
	
::Unigine::ImagePtr image = ::Unigine::Image::create();
image->create2D(textureSize, textureSize, format);
const ::Unigine::Ptr<::Unigine::Blob> stream = ::Unigine::Blob::create();
stream->write(textureData, textureLen);        // textureData=RAW DTX1 Buffer, textureLen=size
image->load(stream->getStream());   
  

/roberto

Edited by roberto.voxelfarm
Posted (edited)

Thank you Silent,

The error is

   "ImageFileDDS::read_header(): wrong magic 0x0"

I know that the texture not is a DDS image file, is just a RAW DXT1 buffer,  and for that is the error. 

For sample Unity have this function that allow to load Raw texture

Texture2D texture = new Texture2D(textureSize, textureSize, format, hasMipmaps, linear);
texture.LoadRawTextureData(textureData);

Is any possibility to load a RAW texture here like unity do?. or convert this to DDS format directly from the buffer or the streaming. 

best regards

/roberto

 

 

 

6.rawTex

Edited by roberto.voxelfarm
Posted

Hello Roberto,

There is no built-in serialization/deserialization of raw formats in the engine. Consider using DDS.

To work with a raw format you could allocate image of certain size and format with create2D and then put data directly to allocated memory with memcpy(image.getPixels(), data, size).

Also to read from blob after write it should be reset to the beginning with blob->seekSet(0).

  • Like 1
Posted

Thank you andrey,

This solution work perfect.

/Roberto 

  • silent changed the title to [SOLVED] Load RAW DXT1 texture
  • 2 months later...
Posted

Hi Roberto, 

For what purpose you need such a texture? Is it CPU only or GPU might be useful too?
Image class is used for CPU representation of texture data, while Texture class is used to represent GPU side texture data.

Thanks!
 

×
×
  • Create New...