2020-09-21 17:17:34 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2020-06-21 12:25:28 +00:00
|
|
|
//
|
2020-09-21 17:17:34 +00:00
|
|
|
// EmulationStation Desktop Edition
|
2020-06-21 12:25:28 +00:00
|
|
|
// TextureData.h
|
|
|
|
//
|
|
|
|
// Low-level texture data functions.
|
|
|
|
//
|
|
|
|
|
2017-10-31 17:12:50 +00:00
|
|
|
#ifndef ES_CORE_RESOURCES_TEXTURE_DATA_H
|
|
|
|
#define ES_CORE_RESOURCES_TEXTURE_DATA_H
|
2017-01-22 23:28:06 +00:00
|
|
|
|
2020-12-28 22:49:34 +00:00
|
|
|
#include <cmath>
|
2017-11-01 22:21:10 +00:00
|
|
|
#include <mutex>
|
|
|
|
#include <string>
|
2020-10-11 16:46:06 +00:00
|
|
|
#include <vector>
|
2017-01-22 23:28:06 +00:00
|
|
|
|
|
|
|
class TextureResource;
|
|
|
|
|
|
|
|
class TextureData
|
|
|
|
{
|
|
|
|
public:
|
2020-06-21 12:25:28 +00:00
|
|
|
TextureData(bool tile);
|
|
|
|
~TextureData();
|
2017-01-22 23:28:06 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
// These functions populate mDataRGBA but do not upload the texture to VRAM.
|
2017-01-22 23:28:06 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
//!!!! Needs to be canonical path. Caller should check for duplicates before calling this.
|
|
|
|
void initFromPath(const std::string& path);
|
2020-10-11 16:46:06 +00:00
|
|
|
bool initSVGFromMemory(const std::string& fileData);
|
2020-06-21 12:25:28 +00:00
|
|
|
bool initImageFromMemory(const unsigned char* fileData, size_t length);
|
|
|
|
bool initFromRGBA(const unsigned char* dataRGBA, size_t width, size_t height);
|
2017-01-22 23:28:06 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
// Read the data into memory if necessary.
|
|
|
|
bool load();
|
2017-01-22 23:28:06 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
bool isLoaded();
|
2017-01-22 23:28:06 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
// Upload the texture to VRAM if necessary and bind.
|
2020-10-11 16:46:06 +00:00
|
|
|
// Returns true if bound correctly.
|
2020-06-21 12:25:28 +00:00
|
|
|
bool uploadAndBind();
|
2017-01-22 23:28:06 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
// Release the texture from VRAM.
|
|
|
|
void releaseVRAM();
|
2017-01-22 23:28:06 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
// Release the texture from conventional RAM.
|
|
|
|
void releaseRAM();
|
2017-01-22 23:28:06 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
// Get the amount of VRAM currenty used by this texture.
|
|
|
|
size_t getVRAMUsage();
|
2017-01-22 23:28:06 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
size_t width();
|
|
|
|
size_t height();
|
|
|
|
float sourceWidth();
|
|
|
|
float sourceHeight();
|
|
|
|
void setSourceSize(float width, float height);
|
2017-01-22 23:28:06 +00:00
|
|
|
|
2021-01-14 21:25:44 +00:00
|
|
|
// Define a factor for scaling the SVG graphics when loading it (1.0f = no scaling).
|
|
|
|
void setScaleSVGDuringLoad(float scale) { mScaleSVG = scale; }
|
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
bool tiled() { return mTile; }
|
2017-01-22 23:28:06 +00:00
|
|
|
|
|
|
|
private:
|
2020-06-21 12:25:28 +00:00
|
|
|
std::mutex mMutex;
|
|
|
|
bool mTile;
|
|
|
|
std::string mPath;
|
|
|
|
unsigned int mTextureID;
|
2020-10-11 16:46:06 +00:00
|
|
|
std::vector<unsigned char> mDataRGBA;
|
2020-06-21 12:25:28 +00:00
|
|
|
size_t mWidth;
|
|
|
|
size_t mHeight;
|
|
|
|
float mSourceWidth;
|
|
|
|
float mSourceHeight;
|
2021-01-14 21:25:44 +00:00
|
|
|
float mScaleSVG;
|
2020-06-21 12:25:28 +00:00
|
|
|
bool mScalable;
|
|
|
|
bool mReloadable;
|
2017-01-22 23:28:06 +00:00
|
|
|
};
|
2017-10-31 17:12:50 +00:00
|
|
|
|
|
|
|
#endif // ES_CORE_RESOURCES_TEXTURE_DATA_H
|