4 /// Filename can be KTX or DDS files
5 GLuint create_texture(char const* Filename)
7 gli::texture Texture = gli::load(Filename);
11 gli::gl GL(gli::gl::PROFILE_GL33);
12 gli::gl::format const Format = GL.translate(Texture.format(), Texture.swizzles());
13 GLenum Target = GL.translate(Texture.target());
15 GLuint TextureName = 0;
16 glGenTextures(1, &TextureName);
17 glBindTexture(Target, TextureName);
18 glTexParameteri(Target, GL_TEXTURE_BASE_LEVEL, 0);
19 glTexParameteri(Target, GL_TEXTURE_MAX_LEVEL, static_cast<GLint>(Texture.levels() - 1));
20 glTexParameteri(Target, GL_TEXTURE_SWIZZLE_R, Format.Swizzles[0]);
21 glTexParameteri(Target, GL_TEXTURE_SWIZZLE_G, Format.Swizzles[1]);
22 glTexParameteri(Target, GL_TEXTURE_SWIZZLE_B, Format.Swizzles[2]);
23 glTexParameteri(Target, GL_TEXTURE_SWIZZLE_A, Format.Swizzles[3]);
25 glm::tvec3<GLsizei> const Extent(Texture.extent());
26 GLsizei const FaceTotal = static_cast<GLsizei>(Texture.layers() * Texture.faces());
28 switch(Texture.target())
32 Target, static_cast<GLint>(Texture.levels()), Format.Internal, Extent.x);
34 case gli::TARGET_1D_ARRAY:
36 case gli::TARGET_CUBE:
38 Target, static_cast<GLint>(Texture.levels()), Format.Internal,
39 Extent.x, Texture.target() == gli::TARGET_2D ? Extent.y : FaceTotal);
41 case gli::TARGET_2D_ARRAY:
43 case gli::TARGET_CUBE_ARRAY:
45 Target, static_cast<GLint>(Texture.levels()), Format.Internal,
47 Texture.target() == gli::TARGET_3D ? Extent.z : FaceTotal);
54 for(std::size_t Layer = 0; Layer < Texture.layers(); ++Layer)
55 for(std::size_t Face = 0; Face < Texture.faces(); ++Face)
56 for(std::size_t Level = 0; Level < Texture.levels(); ++Level)
58 GLsizei const LayerGL = static_cast<GLsizei>(Layer);
59 glm::tvec3<GLsizei> Extent(Texture.extent(Level));
60 Target = gli::is_target_cube(Texture.target())
61 ? static_cast<GLenum>(GL_TEXTURE_CUBE_MAP_POSITIVE_X + Face)
64 switch(Texture.target())
67 if(gli::is_compressed(Texture.format()))
68 glCompressedTexSubImage1D(
69 Target, static_cast<GLint>(Level), 0, Extent.x,
70 Format.Internal, static_cast<GLsizei>(Texture.size(Level)),
71 Texture.data(Layer, Face, Level));
74 Target, static_cast<GLint>(Level), 0, Extent.x,
75 Format.External, Format.Type,
76 Texture.data(Layer, Face, Level));
78 case gli::TARGET_1D_ARRAY:
80 case gli::TARGET_CUBE:
81 if(gli::is_compressed(Texture.format()))
82 glCompressedTexSubImage2D(
83 Target, static_cast<GLint>(Level),
86 Texture.target() == gli::TARGET_1D_ARRAY ? LayerGL : Extent.y,
87 Format.Internal, static_cast<GLsizei>(Texture.size(Level)),
88 Texture.data(Layer, Face, Level));
91 Target, static_cast<GLint>(Level),
94 Texture.target() == gli::TARGET_1D_ARRAY ? LayerGL : Extent.y,
95 Format.External, Format.Type,
96 Texture.data(Layer, Face, Level));
98 case gli::TARGET_2D_ARRAY:
100 case gli::TARGET_CUBE_ARRAY:
101 if(gli::is_compressed(Texture.format()))
102 glCompressedTexSubImage3D(
103 Target, static_cast<GLint>(Level),
106 Texture.target() == gli::TARGET_3D ? Extent.z : LayerGL,
107 Format.Internal, static_cast<GLsizei>(Texture.size(Level)),
108 Texture.data(Layer, Face, Level));
111 Target, static_cast<GLint>(Level),
114 Texture.target() == gli::TARGET_3D ? Extent.z : LayerGL,
115 Format.External, Format.Type,
116 Texture.data(Layer, Face, Level));
118 default: assert(0); break;