5Texture_3d::Texture_3d() :
Texture() {
6 target = GL_TEXTURE_3D;
9Texture_3d::Texture_3d(
unsigned int res_x,
12 GLenum internal_format,
14 GLenum format) : Texture() {
17 create_empty(res_x, res_y, res_z, internal_format, type, format);
20Texture_3d::Texture_3d(
const std::vector<Image>& images) :
Texture() {
25Texture_3d::Texture_3d(
const std::vector<std::string>& paths) : Texture() {
30Texture_3d::~Texture_3d() {
36 GLenum internal_format,
45 glTexImage3D(GL_TEXTURE_3D, 0, internal_format,
46 res_x, res_y, res_z, 0, format, type,
nullptr);
47 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
48 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
49 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
50 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
51 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
56 std::vector<Image> images(paths.size());
57 for(
unsigned int i = 0; i < paths.size(); i++) {
58 if(!images[i].
load(paths[i]))
69 std::vector<SDL_Surface *> images_tmp(images.size());
71 for(
unsigned int i = 0; i < images.size(); i++) {
76 width = images[i].width;
82 images_tmp[i] = SDL_ConvertSurfaceFormat(images[i].image,
83 SDL_PIXELFORMAT_RGBA8888, 0);
90 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
91 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
92 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
93 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
94 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
95 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA,
97 GL_RGBA, GL_UNSIGNED_INT_8_8_8_8,
nullptr);
99 glTexSubImage3D(GL_TEXTURE_3D, 0, 0, 0, i,
101 GL_UNSIGNED_INT_8_8_8_8, images_tmp[i]->pixels);
103 glGenerateMipmap(GL_TEXTURE_3D);
106 for(SDL_Surface *image : images_tmp) {
107 SDL_FreeSurface(image);
114 glActiveTexture(GL_TEXTURE0 + texture_unit);
115 glBindTexture(GL_TEXTURE_3D,
texture);
119 glActiveTexture(GL_TEXTURE0 + texture_unit);
120 glBindTexture(GL_TEXTURE_3D, 0);
void create_empty(unsigned int res_x, unsigned int res_y, unsigned int res_z, GLenum internal_format, GLenum type, GLenum format)
Creates an empty texture.
void unbind(unsigned int texture_unit=0)
Unbind the texture.
bool load(const std::vector< sgltk::Image > &images)
Load a new image as texture.
void bind(unsigned int texture_unit=0)
Bind the texture to be used by the shader.
unsigned int num_layers
The number of layers.
unsigned int width
The width of the texture.
GLenum target
The texture target.
GLuint texture
The texture name.
unsigned int height
The height of the texture.