first few elements

This commit is contained in:
samcake 2016-03-22 19:18:46 -07:00
parent 34633c2f19
commit 24b26e3097
2 changed files with 53 additions and 3 deletions

View file

@ -17,6 +17,30 @@
using namespace gpu; using namespace gpu;
std::atomic<uint32_t> Texture::_textureSystemMemoryUsage;
std::atomic<uint32_t> Texture::_textureVideoMemoryUsage;
uint32_t Texture::getCurrentSystemMemoryUsage() {
return _textureSystemMemoryUsage.load();
}
uint32_t Texture::getCurrentVideoMemoryUsage() {
return _textureVideoMemoryUsage.load();
}
void Texture::addSystemMemoryUsage(uint32_t memorySize) {
_textureSystemMemoryUsage.fetch_add(memorySize);
}
void Texture::subSystemMemoryUsage(uint32_t memorySize) {
_textureSystemMemoryUsage.fetch_sub(memorySize);
}
void Texture::addVideoMemoryUsage(uint32_t memorySize) {
_textureVideoMemoryUsage.fetch_add(memorySize);
}
void Texture::subVideoMemoryUsage(uint32_t memorySize) {
_textureVideoMemoryUsage.fetch_sub(memorySize);
}
uint8 Texture::NUM_FACES_PER_TYPE[NUM_TYPES] = {1, 1, 1, 6}; uint8 Texture::NUM_FACES_PER_TYPE[NUM_TYPES] = {1, 1, 1, 6};
Texture::Pixels::Pixels(const Element& format, Size size, const Byte* bytes) : Texture::Pixels::Pixels(const Element& format, Size size, const Byte* bytes) :
@ -28,6 +52,15 @@ Texture::Pixels::Pixels(const Element& format, Size size, const Byte* bytes) :
Texture::Pixels::~Pixels() { Texture::Pixels::~Pixels() {
} }
Texture::Size Texture::Pixels::resize(Size pSize) {
return _sysmem.resize(pSize);
}
void Texture::Pixels::notifyGPULoaded() {
_isGPULoaded = true;
_sysmem.resize(0);
}
void Texture::Storage::assignTexture(Texture* texture) { void Texture::Storage::assignTexture(Texture* texture) {
_texture = texture; _texture = texture;
if (_texture) { if (_texture) {
@ -60,8 +93,7 @@ const Texture::PixelsPointer Texture::Storage::getMipFace(uint16 level, uint8 fa
void Texture::Storage::notifyMipFaceGPULoaded(uint16 level, uint8 face) const { void Texture::Storage::notifyMipFaceGPULoaded(uint16 level, uint8 face) const {
PixelsPointer mipFace = getMipFace(level, face); PixelsPointer mipFace = getMipFace(level, face);
if (mipFace && (_type != TEX_CUBE)) { if (mipFace && (_type != TEX_CUBE)) {
mipFace->_isGPULoaded = true; mipFace->notifyGPULoaded();
mipFace->_sysmem.resize(0);
} }
} }

View file

@ -15,6 +15,7 @@
#include <algorithm> //min max and more #include <algorithm> //min max and more
#include <bitset> #include <bitset>
#include <atomic>
#include <QUrl> #include <QUrl>
@ -138,8 +139,20 @@ protected:
}; };
class Texture : public Resource { class Texture : public Resource {
static std::atomic<uint32_t> _textureSystemMemoryUsage;
static std::atomic<uint32_t> _textureVideoMemoryUsage;
void addSystemMemoryUsage(uint32_t memorySize);
void subSystemMemoryUsage(uint32_t memorySize);
void addVideoMemoryUsage(uint32_t memorySize);
void subVideoMemoryUsage(uint32_t memorySize);
public: public:
uint32_t getCurrentSystemMemoryUsage();
uint32_t getCurrentVideoMemoryUsage();
class Usage { class Usage {
public: public:
enum FlagBit { enum FlagBit {
@ -194,8 +207,13 @@ public:
Pixels(const Element& format, Size size, const Byte* bytes); Pixels(const Element& format, Size size, const Byte* bytes);
~Pixels(); ~Pixels();
Sysmem _sysmem; Size getSize() const { return _sysmem.getSize(); }
Size resize(Size pSize);
void notifyGPULoaded();
protected:
Element _format; Element _format;
Sysmem _sysmem;
bool _isGPULoaded; bool _isGPULoaded;
}; };
typedef std::shared_ptr< Pixels > PixelsPointer; typedef std::shared_ptr< Pixels > PixelsPointer;