hi, i’m using a texture2Darray for model texturing
the upsides are clear: i can access at least 2048 (openGL 4.5) different layers (each a separate image)
that allows me to just bind that array once to a certain texture unit
struct Vertex {
vec3 position;
vec2 texcoords;
vec3 normal;
int materialindex;
};
struct Material
{
vec4 Kd, Ks;
float Ns{ 0.0f };
int Index_Kd;
int Index_Ks;
int Index_Ns;
//float _PADDING_[...]; not necessary
};
using that vertex layout, and a uniform block (materials) with many materials, i plan to use Index_Kd in the fragmentshader to sample from a certain image / layer of the texture2D array
my problem:
i get a “GL_INVALID_VALUE” when the image dimensions exceeds the (fixed) size of each layer (1024 x 1024)
(for example if image = 1150 x 700, an gl error occurs, because 1150 > 1024)
whats the “best” solution / method to resize an 2D image W x H into MAXWIDTH x MAXHEIGHT ?
another question:
how should i generate mipmaps for that texture2D array ? where should i call glGenerateMipMaps(…) ?
// textures
unsigned int mipmapcount = 1, width = 1024, height = 1024, layers = texturediffusearray.size() + 1;
glBindTexture(GL_TEXTURE_2D_ARRAY, texturearray);
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexStorage3D(GL_TEXTURE_2D_ARRAY, mipmapcount, GL_RGBA8, width, height, layers);
for (unsigned int i = 0; i < texturediffusearray.size(); i++)
{
int w, h, c;
unsigned char* data = SOIL_load_image(texturediffusearray[i].c_str(), &w, &h, &c, 4);
if (data)
glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, i, w, h, 1, GL_RGBA, GL_UNSIGNED_BYTE, data);
else
std::cout << "ERROR: cant load texture: " << texturediffusearray[i] << std::endl;
SOIL_free_image_data(data);
}
glBindTexture(GL_TEXTURE_2D_ARRAY, 0);