Skip to content

Commit

Permalink
Less MenuLayer lag
Browse files Browse the repository at this point in the history
  • Loading branch information
Alphalaneous committed Mar 8, 2024
1 parent bf51a84 commit 3b54fd5
Showing 1 changed file with 37 additions and 8 deletions.
45 changes: 37 additions & 8 deletions src/utils/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,54 @@

using namespace geode::prelude;

struct ImageCache{
std::string filePath;
CCImage* img;
CCTexture2D* texture;
};

class Utils {

public:

inline static std::vector<ImageCache> imageCache;

static void generateTexture(std::string filePath, GLenum target){

CCImage img;
img.initWithImageFile(filePath.c_str());
ImageCache imgCache;

bool found = false;

for(ImageCache i : imageCache){
if(i.filePath == filePath){
imgCache = i;
found = true;
break;
}
}

if(!found){
CCImage* img = new CCImage;
img->initWithImageFile(filePath.c_str());
img->retain();

CCTexture2D* texture = new CCTexture2D;
texture->initWithImage(img);
texture->retain();

CCTexture2D texture;
texture.initWithImage(&img);
imgCache.filePath = filePath;
imgCache.img = img;
imgCache.texture = texture;

imageCache.push_back(imgCache);
}

int pixelsWide = texture.getPixelsWide();
int pixelsHigh = texture.getPixelsHigh();
int pixelsWide = imgCache.texture->getPixelsWide();
int pixelsHigh = imgCache.texture->getPixelsHigh();

CCTexture2DPixelFormat pixelFormat = texture.getPixelFormat();
CCTexture2DPixelFormat pixelFormat = imgCache.texture->getPixelFormat();

auto data = img.getData();
auto data = imgCache.img->getData();

switch(pixelFormat)
{
Expand Down

0 comments on commit 3b54fd5

Please sign in to comment.