Code samplesCreate GLI texture views and copies:- #include <gli/gli.hpp>
- gli::texture2DArray TextureArray(gli::load_dds("texture.dds"));
- gli::texture2DArray TextureViewA(TextureArray,
- TextureArray.baseLayer(), TextureArray.maxLayer(),
- TextureArray.baseLevel() + 1, TextureArray.maxLevel());
- gli::texture2D TextureViewB(TextureArray,
- TextureArray.baseLayer(),
- TextureArray.baseLevel(), TextureArray.maxLevel());
- gli::texture2D TextureViewC(gli::view(TextureArray,
- TextureArray.baseLayer(),
- TextureArray.baseLevel(), TextureArray.maxLevel());
- gli::texture2D TextureCopyC(gli::copy(TextureViewC);
- gli::texture2DArray TextureCopyA(gli::copy(TextureArray,
- TextureArray.baseLayer(), TextureArray.maxLayer(),
- TextureArray.baseLevel() + 1, TextureArray.maxLevel());
Loading an OpenGL texture:- #include <gli/gli.hpp>
- gli::storage Storage(gli::load_dds("texture.dds"));
- assert(!Storage.empty())
- GLenum Target = Storage.layers() > 1 ? GL_TEXTURE_2D_ARRAY : GL_TEXTURE_2D;
- glGenTextures(1, &TextureName);
- glBindTexture(Target, TextureName);
- glTexParameteri(Target, GL_TEXTURE_BASE_LEVEL, 0);
- glTexParameteri(Target, GL_TEXTURE_MAX_LEVEL, static_cast<GLint>(Texture.levels() - 1));
- glTexParameteri(Target, GL_TEXTURE_MIN_FILTER, Texture.levels() > 1 ? GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR);
- glTexParameteri(Target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- if(Storage.layers() > 1)
- {
- gli::texture2DArray Texture(Storage);
- glTexStorage3D(Target, static_cast<GLint>(Texture.levels()),
- static_cast<GLenum>(gli::internal_format(Texture.format())),
- static_cast<GLsizei>(Texture.dimensions().x),
- static_cast<GLsizei>(Texture.dimensions().y),
- static_cast<GLsizei>(Texture.layers()));
- if(gli::is_compressed(Texture.format()))
- {
- for(gli::texture2DArray::size_type Layer = 0; Layer < Texture.layers(); ++Layer)
- for(gli::texture2DArray::size_type Level = 0; Level < Texture.levels(); ++Level)
- {
- glCompressedTexSubImage3D(Target,
- static_cast<GLint>(Level),
- 0, 0, static_cast<GLint>(Layer),
- static_cast<GLsizei>(Texture[Layer][Level].dimensions().x),
- static_cast<GLsizei>(Texture[Layer][Level].dimensions().y),
- static_cast<GLsizei>(1),
- static_cast<GLenum>(gli::external_format(Texture.format())),
- static_cast<GLsizei>(Texture[Layer][Level].size()),
- Texture[Layer][Level].data());
- }
- }
- else
- {
- for(gli::texture2DArray::size_type Layer = 0; Layer < Texture.layers(); ++Layer)
- for(gli::texture2DArray::size_type Level = 0; Level < Texture.levels(); ++Level)
- {
- glTexSubImage3D(Target,
- static_cast<GLint>(Level),
- 0, 0, static_cast<GLint>(Layer),
- static_cast<GLsizei>(Texture[Layer][Level].dimensions().x),
- static_cast<GLsizei>(Texture[Layer][Level].dimensions().y),
- static_cast<GLsizei>(1),
- static_cast<GLenum>(gli::external_format(Texture.format())),
- static_cast<GLenum>(gli::type_format(Texture.format())),
- Texture[Layer][Level].data());
- }
- }
- }
- else
- {
- gli::texture2D Texture(Storage);
- glTexStorage2D(Target, static_cast<GLint>(Texture.levels()),
- static_cast<GLenum>(gli::internal_format(Texture.format())),
- static_cast<GLsizei>(Texture.dimensions().x), static_cast<GLsizei>(Texture.dimensions().y));
- if(gli::is_compressed(Texture.format()))
- {
- for(gli::texture2D::size_type Level = 0; Level < Texture.levels(); ++Level)
- {
- glCompressedTexSubImage2D(Target,
- static_cast<GLint>(Level), 0, 0,
- static_cast<GLsizei>(Texture[Level].dimensions().x),
- static_cast<GLsizei>(Texture[Level].dimensions().y),
- static_cast<GLenum>(gli::external_format(Texture.format())),
- static_cast<GLsizei>(Texture[Level].size()),
- Texture[Level].data());
- }
- }
- else
- {
- for(gli::texture2D::size_type Level = 0; Level < Texture.levels(); ++Level)
- {
- glTexSubImage2D(Target,
- static_cast<GLint>(Level), 0, 0,
- static_cast<GLsizei>(Texture[Level].dimensions().x),
- static_cast<GLsizei>(Texture[Level].dimensions().y),
- static_cast<GLenum>(gli::external_format(Texture.format())),
- static_cast<GLenum>(gli::type_format(Texture.format())),
- Texture[Level].data());
- }
- }
- }
Create a texture with GLI 0.5 and save it to a DDS file:- #include <glm/glm.hpp>
- #include <gli/gli.hpp>
- gli::texture2D Texture(3, gli::RGBA8_UNORM, gli::texture2D::dimensions_type(256, 256));
- Texture[0].clear(glm::u8vec4(255, 0, 0, 255)));
- Texture[1].clear(glm::u8vec4(255, 128, 0, 255)));
- Texture[2].clear(glm::u8vec4(255, 255, 0, 255)));
- glm::u8vec4 * LinearAddress0 = Texture[0].data<glm::u8vec4>();
- glm::u8vec4 * LinearAddress1 = Texture[1].data<glm::u8vec4>();
- glm::u8vec4 * LinearAddress2 = Texture[2].data<glm::u8vec4>();
- ...
- ...
- gli::save_dds(Texture, "texture.dds");
|