Exemplo n.º 1
0
void MipMapReplacer::ReplaceMipMapFromMemory(Texture * texture, int32 level)
{
    uint32 mipMapSize = texture->width / (1 << level);
    if(mipMapSize < 2)  //don't replace mipmaps less than 2x2
        return;

    uint32 dataSize = 0;
    uint8 * data = 0;

    if(texture->format == FORMAT_RGB888)
    {
        uint32 pixelsCount = mipMapSize * mipMapSize;
        dataSize = pixelsCount * 3;
        data = new uint8[dataSize];

        for(uint32 i = 0; i < pixelsCount; i++)
        {
            data[i * 3] = 0xff;
            data[i * 3 + 1] = 0;
            data[i * 3 + 2] = 0;
        }
    }
    else
    {
        int32 elementBytesCount = Texture::GetPixelFormatSizeInBytes(texture->format);
        uint32 elementValue = GetReplaceValue(texture->format);

        uint32 pixelsCount = mipMapSize * mipMapSize;
        dataSize = pixelsCount * elementBytesCount;
        data = new uint8[dataSize];

        uint32 * dataPt = (uint32 *)data;
        uint32 intCount = dataSize / 4;

        while(intCount)
        {
            *dataPt++ = elementValue;
            intCount--;
        }
    }

    RenderManager::Instance()->LockNonMain();
    texture->TexImage(level, mipMapSize, mipMapSize, data, dataSize);
    RenderManager::Instance()->UnlockNonMain();

    SafeDeleteArray(data);
}
Exemplo n.º 2
0
void MipMapReplacer::ReplaceMipMapFromMemory(Texture * texture, int32 level)
{
    uint32 mipMapSize = texture->width / (1 << level);
    if(mipMapSize < 2)  //don't replace mipmaps less than 2x2
        return;

    uint32 dataSize = 0;
    uint8 * data = 0;

	PixelFormat format = texture->GetFormat();
    if(format == FORMAT_RGB888)
    {
        uint32 pixelsCount = mipMapSize * mipMapSize;
        dataSize = pixelsCount * 3;
        data = new uint8[dataSize];

        for(uint32 i = 0; i < pixelsCount; i++)
        {
            data[i * 3] = 0xff;
            data[i * 3 + 1] = 0;
            data[i * 3 + 2] = 0;
        }
    }
    else
    {
        int32 elementBytesCount = PixelFormatDescriptor::GetPixelFormatSizeInBytes(format);
        uint32 elementValue = GetReplaceValue(format);

        uint32 pixelsCount = mipMapSize * mipMapSize;
        dataSize = pixelsCount * elementBytesCount;
        data = new uint8[dataSize];

        uint32 * dataPt = (uint32 *)data;
        uint32 intCount = dataSize / 4;

        while(intCount)
        {
            *dataPt++ = elementValue;
            intCount--;
        }
    }

    texture->TexImage(level, mipMapSize, mipMapSize, data, dataSize, Texture::CUBE_FACE_INVALID);

    SafeDeleteArray(data);
}