4 #include "opengl/texture-gl.h"
9 target = GL_TEXTURE_2D;
12 TextureGL::~TextureGL()
14 glDeleteTextures(1, &tex);
17 void TextureGL::update()
23 target = is_cubemap() ? GL_TEXTURE_CUBE_MAP : GL_TEXTURE_2D;
25 glGenTextures(1, &tex);
26 glBindTexture(target, tex);
27 glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
28 glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
31 glBindTexture(target, tex);
34 static const unsigned int faces[] = {
35 GL_TEXTURE_CUBE_MAP_POSITIVE_X, GL_TEXTURE_CUBE_MAP_POSITIVE_Y, GL_TEXTURE_CUBE_MAP_POSITIVE_Z,
36 GL_TEXTURE_CUBE_MAP_NEGATIVE_X, GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
39 for(size_t i=0; i<images.size(); i++) {
43 unsigned char *pixels = images[i].pixels;
44 unsigned int t = is_cubemap() ? faces[i] : GL_TEXTURE_2D;
45 glTexImage2D(t, 0, GL_SRGB_ALPHA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
48 glGenerateMipmap(target);
51 void TextureGL::bind()
53 glBindTexture(GL_TEXTURE_2D, tex);