Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

when i load a pak file with mesh and texture(runtime),the texture lost mipmap

i baked asstes in editor,after i Released the game i discover when i load pak file the mipmap was lost。it only load one level of mipmap and not the hight res one。so i change my way,before i bake asstes i change the texture seting to nomipmap and bake again。this time it does load right but only the high res level in there。the result with nomipmap is not well too,a lot moire phenomenon on the texture。so i try to fix this and i find a way,use a function to creat mipmap for the texture。

 UTexture* Calculate_Mipmap(UTexture* texture)
     int mipsToAdd = 3;
     TArray<uint8> _mipRGBAs;
     UTexture2D* texture2d = Cast<UTexture2D>(texture);
     if (texture2d->PlatformData->Mips.Num() > 1)
         return texture;
     GEngine->AddOnScreenDebugMessage(0, 1, FColor::Blue, FString::FromInt(texture2d->PlatformData->Mips[0].BulkData.GetBulkDataSize()));
     const uint8 *priorData = (const uint8 *)texture2d->PlatformData->Mips[0].BulkData.Lock(LOCK_READ_WRITE);
     int priorwidth = texture2d->PlatformData->Mips[0].SizeX;
     int priorheight = texture2d->PlatformData->Mips[0].SizeY;
     while (mipsToAdd > 0)
         TArray<uint8> *mipRGBAs = &_mipRGBAs;
         int mipwidth = priorwidth >> 1;
         int mipheight = priorheight >> 1;
         if ((mipwidth == 0) || (mipheight == 0))
         mipRGBAs->AddUninitialized(mipwidth * mipheight * BYTES_PER_PIXEL);
         int dataPerRow = priorwidth * BYTES_PER_PIXEL;
         uint8 *dataOut = mipRGBAs->GetData();
         for (int y = 0; y < mipheight; y++)
             const uint8 *dataInRow0 = priorData + (dataPerRow * y /** 2*/);
             const uint8 *dataInRow1 = dataInRow0 + dataPerRow;
             for (int x = 0; x < mipwidth; x++)
                 int totalB = *dataInRow0++;
                 int totalG = *dataInRow0++;
                 int totalR = *dataInRow0++;
                 //int totalA = *dataInRow0++;
                 totalB += *dataInRow0++;
                 totalG += *dataInRow0++;
                 totalR += *dataInRow0++;
                 //totalA += *dataInRow0++;
                 totalB += *dataInRow1++;
                 totalG += *dataInRow1++;
                 totalR += *dataInRow1++;
                 //totalA += *dataInRow1++;
                 totalB += *dataInRow1++;
                 totalG += *dataInRow1++;
                 totalR += *dataInRow1++;
                 //totalA += *dataInRow1++;
                 totalB >>= 2;
                 totalG >>= 2;
                 totalR >>= 2;
                 //totalA >>= 2;
                 *dataOut++ = (uint8)totalB;
                 *dataOut++ = (uint8)totalG;
                 *dataOut++ = (uint8)totalR;
                 //*dataOut++ = (uint8)totalA;
             //dataInRow0 += dataPerRow * 2;
             //dataInRow1 += dataPerRow * 2;
         FTexture2DMipMap* Mip = new(texture2d->PlatformData->Mips) FTexture2DMipMap();
         Mip->SizeX = mipwidth;
         Mip->SizeY = mipheight;
         void* mipData = Mip->BulkData.Realloc(mipRGBAs->Num());
         FMemory::Memcpy(mipData, mipRGBAs->GetData(), mipRGBAs->Num());
         priorData = mipRGBAs->GetData();
         priorwidth = mipwidth;
         priorheight = mipheight;
     return texture;

this is the C++ code,it crash everytime when the texture->UpdateResourceW() function excused。sometime it crash when get next RGBA value the pointer out of bounds。 so dose any have a solution how to load mipmap right or help me fix the code issue。 one more thing,my English not so well,so if you find some grammatical mistakes in this describe please don't mind。if you don't understand what i am take about please let me know i will describe more carefuly。

Product Version: UE 4.14
more ▼

asked Feb 28 '18 at 02:41 AM in C++ Programming

avatar image


(comments are locked)
10|2000 characters needed characters left
Viewable by all users

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question