5 #include "opengl/texture-gl.h"
10 target = GL_TEXTURE_2D;
13 TextureGL::~TextureGL()
15 glDeleteTextures(1, &tex);
18 void TextureGL::update()
24 target = is_cubemap() ? GL_TEXTURE_CUBE_MAP : GL_TEXTURE_2D;
26 glGenTextures(1, &tex);
27 glBindTexture(target, tex);
28 glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
29 glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
32 glBindTexture(target, tex);
35 static const unsigned int faces[] = {
36 GL_TEXTURE_CUBE_MAP_POSITIVE_X, GL_TEXTURE_CUBE_MAP_POSITIVE_Y, GL_TEXTURE_CUBE_MAP_POSITIVE_Z,
37 GL_TEXTURE_CUBE_MAP_NEGATIVE_X, GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
40 for(size_t i=0; i<images.size(); i++) {
45 unsigned int t = is_cubemap() ? faces[i] : GL_TEXTURE_2D;
48 unsigned int ifmt = images[i].is_float ? GL_RGBA16F : GL_SRGB_ALPHA;
50 /* data type of pixel data */
51 unsigned int type = images[i].is_float ? GL_FLOAT : GL_UNSIGNED_BYTE;
53 glTexImage2D(t, 0, ifmt, w, h, 0, GL_RGBA, type, images[i].pixels);
56 glGenerateMipmap(target);
59 void TextureGL::bind()
61 unsigned int target = is_cubemap() ? GL_TEXTURE_CUBE_MAP : GL_TEXTURE_2D;
62 glBindTexture(target, tex);
65 void TextureGL::unbind()
67 unsigned int target = is_cubemap() ? GL_TEXTURE_CUBE_MAP : GL_TEXTURE_2D;
68 glBindTexture(target, 0);