| 730 | |
| 731 | |
| 732 | void CachedTexture::transfer() |
| 733 | // ---------------------------------------------------------------------------- |
| 734 | // Copy image to GL memory and update cached sizes |
| 735 | // ---------------------------------------------------------------------------- |
| 736 | { |
| 737 | #define ADJUST_FOR_MIPMAP_OVERHEAD(sz) \ |
| 738 | do { if (mipmap) { sz *= 1.33; } } while(0) |
| 739 | |
| 740 | if (networked && !loaded()) |
| 741 | return; |
| 742 | |
| 743 | Q_ASSERT(loaded()); |
| 744 | Q_ASSERT(!transferred()); |
| 745 | Q_ASSERT(id); |
| 746 | |
| 747 | int before = image.byteCount(); |
| 748 | |
| 749 | bool copiedCompressed = false, didNotCompress = false; |
| 750 | int copiedSize = 0; |
| 751 | |
| 752 | if (compress) |
| 753 | { |
| 754 | // Want compressed texture |
| 755 | |
| 756 | if (image.compressed) |
| 757 | { |
| 758 | // Already have compressed texture data |
| 759 | |
| 760 | GL.BindTexture(GL_TEXTURE_2D, id); |
| 761 | if (mipmap) |
| 762 | GL.TexParameter(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE); |
| 763 | TextureCache::instance()->setMinMagFilters(id); |
| 764 | GL.CompressedTexImage2D(GL_TEXTURE_2D, 0, image.fmt, width, height, |
| 765 | 0, image.byteCount(), image.compressed); |
| 766 | copiedSize = GLsize = image.byteCount(); |
| 767 | copiedCompressed = true; |
| 768 | ADJUST_FOR_MIPMAP_OVERHEAD(GLsize); |
| 769 | } |
| 770 | else |
| 771 | { |
| 772 | // Transfer uncompressed image data and request compression. |
| 773 | |
| 774 | QImage texture = QGLWidget::convertToGLFormat(image.raw); |
| 775 | bool hasAlpha = image.raw.hasAlphaChannel(); |
| 776 | GLenum internalFmt = hasAlpha?GL_COMPRESSED_RGBA:GL_COMPRESSED_RGB; |
| 777 | GL.BindTexture(GL_TEXTURE_2D, id); |
| 778 | if (mipmap) |
| 779 | GL.TexParameter(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE); |
| 780 | TextureCache::instance()->setMinMagFilters(id); |
| 781 | GL.TexImage2D(GL_TEXTURE_2D, 0, internalFmt, |
| 782 | width, height, 0, GL_RGBA, |
| 783 | GL_UNSIGNED_BYTE, texture.bits()); |
| 784 | copiedSize = width * height * 4; |
| 785 | |
| 786 | GLint cmp = GL_FALSE, cmpsz = copiedSize; |
| 787 | glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_COMPRESSED, |
| 788 | &cmp); |
| 789 | if (cmp) |
no test coverage detected