Texture.readData
This commit is contained in:
parent
6430121cf2
commit
714a49685f
@ -1,6 +1,7 @@
|
|||||||
#include "Texture.h"
|
#include "Texture.h"
|
||||||
#include <GL/glew.h>
|
#include <GL/glew.h>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include "ImageData.h"
|
#include "ImageData.h"
|
||||||
|
|
||||||
@ -37,6 +38,14 @@ void Texture::reload(ubyte* data){
|
|||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ImageData* Texture::readData() {
|
||||||
|
std::unique_ptr<ubyte[]> data (new ubyte[width * height * 4]);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, id);
|
||||||
|
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, data.get());
|
||||||
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
|
return new ImageData(ImageFormat::rgba8888, width, height, data.release());
|
||||||
|
}
|
||||||
|
|
||||||
Texture* Texture::from(const ImageData* image) {
|
Texture* Texture::from(const ImageData* image) {
|
||||||
uint width = image->getWidth();
|
uint width = image->getWidth();
|
||||||
uint height = image->getHeight();
|
uint height = image->getHeight();
|
||||||
|
|||||||
@ -18,6 +18,8 @@ public:
|
|||||||
void bind();
|
void bind();
|
||||||
void reload(ubyte* data);
|
void reload(ubyte* data);
|
||||||
|
|
||||||
|
ImageData* readData();
|
||||||
|
|
||||||
static Texture* from(const ImageData* image);
|
static Texture* from(const ImageData* image);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user