Cubemap class
This commit is contained in:
@@ -4,16 +4,19 @@
|
||||
#include <memory>
|
||||
|
||||
#include "ImageData.h"
|
||||
#include "gl_util.h"
|
||||
|
||||
Texture::Texture(uint id, uint width, uint height)
|
||||
: id(id), width(width), height(height) {
|
||||
}
|
||||
|
||||
Texture::Texture(ubyte* data, uint width, uint height, uint format)
|
||||
Texture::Texture(ubyte* data, uint width, uint height, ImageFormat imageFormat)
|
||||
: width(width), height(height) {
|
||||
glGenTextures(1, &id);
|
||||
glBindTexture(GL_TEXTURE_2D, id);
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
|
||||
GLenum format = gl::to_gl_format(imageFormat);
|
||||
glTexImage2D(
|
||||
GL_TEXTURE_2D, 0, format, width, height, 0,
|
||||
format, GL_UNSIGNED_BYTE, (GLvoid *) data
|
||||
@@ -33,6 +36,10 @@ void Texture::bind(){
|
||||
glBindTexture(GL_TEXTURE_2D, id);
|
||||
}
|
||||
|
||||
void Texture::unbind() {
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
}
|
||||
|
||||
void Texture::reload(ubyte* data){
|
||||
glBindTexture(GL_TEXTURE_2D, id);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0,
|
||||
@@ -58,15 +65,8 @@ void Texture::setNearestFilter() {
|
||||
Texture* Texture::from(const ImageData* image) {
|
||||
uint width = image->getWidth();
|
||||
uint height = image->getHeight();
|
||||
uint format;
|
||||
const void* data = image->getData();
|
||||
switch (image->getFormat()) {
|
||||
case ImageFormat::rgb888: format = GL_RGB; break;
|
||||
case ImageFormat::rgba8888: format = GL_RGBA; break;
|
||||
default:
|
||||
throw std::runtime_error("unsupported image data format");
|
||||
}
|
||||
return new Texture((ubyte*)data, width, height, format);
|
||||
return new Texture((ubyte*)data, width, height, image->getFormat());
|
||||
}
|
||||
|
||||
uint Texture::getWidth() const {
|
||||
|
||||
Reference in New Issue
Block a user