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"

Is there a faster alternative to FImageUtils::CreateTexture2D?

Dear Friends at Epic,

I am using FImageUtils::CreateTexture2D to make a T2D from a color buffer obtained from ReadPixels using custom viewportclient class.

 UTexture2D* MyScreenshot;

     MyScreenshot = FImageUtils::CreateTexture2D(

I have verified that the only thing that is causing my game to hang during this process is the call to FImageUtils::CreateTexture2D

I have looked at the code for this function and I cannot see an easy way to break it up over multiple ticks.

I also cannot use Task Graph System because this is a modification / creation of a UObject

The Question

Is there an alternative to FImageUtils::CreateTexture2D that will not cause the system to hang for a brief time?

The hang averages about 2 seconds.

Loading from Binary Array

I will be loading images from compressed binary arrays and will need to turn them into T2Ds, so I really do need a way to make a T2D from color buffer that does not cause a hang :)



Product Version: Not Selected
more ▼

asked Apr 23 '14 at 12:39 AM in C++ Programming

avatar image

10.6k 446 346 1088

avatar image emandrawkcab Apr 23 '14 at 01:09 AM

How many textures are there and how big are they? I would consider just doing all your CreateTexture2D calls ahead of time. You could basically write your own simple memory manager for textures and recycle these UTexture2D objects that way. Creating such a manager would be easiest if you restrict the size of the allowed textures, a problem you don't usually get to ignore in that problem space.

avatar image Rama Apr 23 '14 at 02:31 AM

thanks for the idea!

I ended up writing my own version which works almost instantly :)

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

1 answer: sort voted first

Very Fast Version of CreateTexture2D

I wrote my own version which is basically instant

One notable feature is I made the SrcPtr const.

 void AYourClass::TextureFromImage_Internal(const int32 SrcWidth, const int32 SrcHeight, const TArray<FColor> &SrcData, const bool UseAlpha)
     // Create the texture
     MyScreenshot = UTexture2D::CreateTransient(
     // Lock the texture so it can be modified
     uint8* MipData = static_cast<uint8*>(MyScreenshot->PlatformData->Mips[0].BulkData.Lock(LOCK_READ_WRITE));
     // Create base mip.
     uint8* DestPtr = NULL;
     const FColor* SrcPtr = NULL;
     for( int32 y=0; y<SrcHeight; y++ )
         DestPtr = &MipData[(SrcHeight - 1 - y) * SrcWidth * sizeof(FColor)];
         SrcPtr = const_cast<FColor*>(&SrcData[(SrcHeight - 1 - y) * SrcWidth]);
         for( int32 x=0; x<SrcWidth; x++ )
             *DestPtr++ = SrcPtr->B;
             *DestPtr++ = SrcPtr->G;
             *DestPtr++ = SrcPtr->R;
             if( UseAlpha )
                 *DestPtr++ = SrcPtr->A;
                 *DestPtr++ = 0xFF;
     // Unlock the texture
more ▼

answered Apr 23 '14 at 02:33 AM

avatar image

10.6k 446 346 1088

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
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