5Texture_1d_Array::Texture_1d_Array() :
Texture() {
6 target = GL_TEXTURE_1D_ARRAY;
9Texture_1d_Array::Texture_1d_Array(
unsigned int res,
11 GLenum internal_format,
13 GLenum format) : Texture() {
15 target = GL_TEXTURE_1D_ARRAY;
19Texture_1d_Array::Texture_1d_Array(
const std::vector<Image>& images) :
Texture() {
20 target = GL_TEXTURE_1D_ARRAY;
24Texture_1d_Array::Texture_1d_Array(
const std::vector<std::string>& paths) : Texture() {
25 target = GL_TEXTURE_1D_ARRAY;
29Texture_1d_Array::~Texture_1d_Array() {
34 GLenum internal_format,
35 GLenum type, GLenum format) {
42 glTexImage2D(GL_TEXTURE_1D_ARRAY, 0, internal_format,
44 glTexParameteri(GL_TEXTURE_1D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
45 glTexParameteri(GL_TEXTURE_1D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
46 glTexParameteri(GL_TEXTURE_1D_ARRAY, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
51 std::vector<Image> images(paths.size());
52 for(
unsigned int i = 0; i < paths.size(); i++) {
53 if(!images[i].
load(paths[i]))
64 std::vector<SDL_Surface *> images_tmp(images.size());
66 for(
unsigned int i = 0; i < images.size(); i++) {
71 width = images[i].width;
76 images_tmp[i] = SDL_ConvertSurfaceFormat(images[i].image,
77 SDL_PIXELFORMAT_RGBA8888, 0);
84 glTexParameteri(GL_TEXTURE_1D_ARRAY, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
85 glTexParameteri(GL_TEXTURE_1D_ARRAY, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
86 glTexParameteri(GL_TEXTURE_1D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
87 glTexParameteri(GL_TEXTURE_1D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
88 glTexImage2D(GL_TEXTURE_1D_ARRAY, 0, GL_RGBA,
89 width, images.size(), 0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8,
nullptr);
91 glTexSubImage2D(GL_TEXTURE_1D_ARRAY, 0, 0, i,
width, 1,
92 GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, images_tmp[i]->pixels);
94 glGenerateMipmap(GL_TEXTURE_1D_ARRAY);
97 for(SDL_Surface *image : images_tmp) {
98 SDL_FreeSurface(image);
105 glActiveTexture(GL_TEXTURE0 + texture_unit);
106 glBindTexture(GL_TEXTURE_1D_ARRAY,
texture);
110 glActiveTexture(GL_TEXTURE0 + texture_unit);
111 glBindTexture(GL_TEXTURE_1D_ARRAY, 0);
void unbind(unsigned int texture_unit=0)
Unbind the texture.
void create_empty(unsigned int res, unsigned int num_layers, GLenum internal_format, GLenum type, GLenum format)
Creates an empty 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.