void Texture::setFilter(GLenum target) { const TXI::Features &features = getTXI().getFeatures(); if (features.filter) { glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); } else { glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST); } }
void Texture::doRebuild() { if (!_image) // No image return; // Generate the texture ID if (_textureID == 0) glGenTextures(1, &_textureID); // Bind the texture glBindTexture(GL_TEXTURE_2D, _textureID); // Texture wrapping glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); // Filter? const TXI::Features &features = getTXI().getFeatures(); if (features.filter) { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); } else { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); } if (_image->getMipMapCount() == 1) { // Texture doesn't specify any mip maps, generate our own glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 9); } else { // Texture does specify mip maps, use these glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_FALSE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, _image->getMipMapCount() - 1); } // Texture image data if (_image->isCompressed()) { // Compressed texture data for (uint32 i = 0; i < _image->getMipMapCount(); i++) { const ImageDecoder::MipMap &mipMap = _image->getMipMap(i); glCompressedTexImage2D(GL_TEXTURE_2D, i, _image->getFormatRaw(), mipMap.width, mipMap.height, 0, mipMap.size, mipMap.data); } } else { // Uncompressed texture data for (uint32 i = 0; i < _image->getMipMapCount(); i++) { const ImageDecoder::MipMap &mipMap = _image->getMipMap(i); glTexImage2D(GL_TEXTURE_2D, i, _image->getFormatRaw(), mipMap.width, mipMap.height, 0, _image->getFormat(), _image->getDataType(), mipMap.data); } } }