1967 QVERIFY(guard3.context() == 0); |
1941 QVERIFY(guard3.context() == 0); |
1968 QVERIFY(guard3.id() == 0); |
1942 QVERIFY(guard3.id() == 0); |
1969 #endif |
1943 #endif |
1970 } |
1944 } |
1971 |
1945 |
|
1946 // Tests QGLContext::bindTexture with default options |
|
1947 void tst_QGL::qglContextDefaultBindTexture() |
|
1948 { |
|
1949 #ifdef QT_BUILD_INTERNAL |
|
1950 QGLWidget w; |
|
1951 w.makeCurrent(); |
|
1952 QGLContext *ctx = const_cast<QGLContext*>(w.context()); |
|
1953 |
|
1954 QImage *boundImage = new QImage(256, 256, QImage::Format_RGB32); |
|
1955 boundImage->fill(0xFFFFFFFF); |
|
1956 QPixmap *boundPixmap = new QPixmap(256, 256); |
|
1957 boundPixmap->fill(Qt::red); |
|
1958 |
|
1959 int startCacheItemCount = QGLTextureCache::instance()->size(); |
|
1960 |
|
1961 GLuint boundImageTextureId = ctx->bindTexture(*boundImage); |
|
1962 GLuint boundPixmapTextureId = ctx->bindTexture(*boundPixmap); |
|
1963 |
|
1964 // Make sure the image & pixmap have been added to the cache: |
|
1965 QCOMPARE(QGLTextureCache::instance()->size(), startCacheItemCount+2); |
|
1966 |
|
1967 // Make sure the image & pixmap have the is_cached flag set: |
|
1968 QVERIFY(QImagePixmapCleanupHooks::isImageCached(*boundImage)); |
|
1969 QVERIFY(QImagePixmapCleanupHooks::isPixmapCached(*boundPixmap)); |
|
1970 |
|
1971 // Make sure the texture IDs returned are valid: |
|
1972 QCOMPARE((bool)glIsTexture(boundImageTextureId), GL_TRUE); |
|
1973 QCOMPARE((bool)glIsTexture(boundPixmapTextureId), GL_TRUE); |
|
1974 |
|
1975 // Make sure the textures are still valid after we delete the image/pixmap: |
|
1976 // Also check that although the textures are left intact, the cache entries are removed: |
|
1977 delete boundImage; |
|
1978 boundImage = 0; |
|
1979 QCOMPARE((bool)glIsTexture(boundImageTextureId), GL_TRUE); |
|
1980 QCOMPARE(QGLTextureCache::instance()->size(), startCacheItemCount+1); |
|
1981 delete boundPixmap; |
|
1982 boundPixmap = 0; |
|
1983 QCOMPARE((bool)glIsTexture(boundPixmapTextureId), GL_TRUE); |
|
1984 QCOMPARE(QGLTextureCache::instance()->size(), startCacheItemCount); |
|
1985 |
|
1986 // Finally, make sure QGLContext::deleteTexture deletes the texture IDs: |
|
1987 ctx->deleteTexture(boundImageTextureId); |
|
1988 ctx->deleteTexture(boundPixmapTextureId); |
|
1989 QCOMPARE((bool)glIsTexture(boundImageTextureId), GL_FALSE); |
|
1990 QCOMPARE((bool)glIsTexture(boundPixmapTextureId), GL_FALSE); |
|
1991 #endif |
|
1992 } |
|
1993 |
|
1994 void tst_QGL::textureCleanup() |
|
1995 { |
|
1996 #ifdef QT_BUILD_INTERNAL |
|
1997 QGLWidget w; |
|
1998 w.resize(200,200); |
|
1999 w.show(); |
|
2000 w.makeCurrent(); |
|
2001 |
|
2002 // Test pixmaps which have been loaded via QPixmapCache are removed from the texture cache |
|
2003 // when the pixmap cache is cleared |
|
2004 { |
|
2005 int startCacheItemCount = QGLTextureCache::instance()->size(); |
|
2006 QPainter p(&w); |
|
2007 |
|
2008 QPixmap boundPixmap(":designer.png"); |
|
2009 |
|
2010 QCOMPARE(QGLTextureCache::instance()->size(), startCacheItemCount); |
|
2011 |
|
2012 p.drawPixmap(0, 0, boundPixmap); |
|
2013 QCOMPARE(QGLTextureCache::instance()->size(), startCacheItemCount+1); |
|
2014 |
|
2015 // Need to call end for the GL2 paint engine to release references to pixmap if using tfp |
|
2016 p.end(); |
|
2017 |
|
2018 QCOMPARE(QGLTextureCache::instance()->size(), startCacheItemCount+1); |
|
2019 |
|
2020 // Check that the texture doesn't get removed from the cache when the pixmap is cleared |
|
2021 // as it should still be in the cache: |
|
2022 boundPixmap = QPixmap(); |
|
2023 QCOMPARE(QGLTextureCache::instance()->size(), startCacheItemCount+1); |
|
2024 |
|
2025 QPixmapCache::clear(); |
|
2026 QCOMPARE(QGLTextureCache::instance()->size(), startCacheItemCount); |
|
2027 } |
|
2028 |
|
2029 // Test pixmaps which have been loaded via QPixmapCache are removed from the texture cache |
|
2030 // when they are explicitly removed from the pixmap cache |
|
2031 { |
|
2032 int startCacheItemCount = QGLTextureCache::instance()->size(); |
|
2033 QPainter p(&w); |
|
2034 |
|
2035 QPixmap boundPixmap(128, 128); |
|
2036 QString cacheKey = QString::fromLatin1("myPixmap"); |
|
2037 QPixmapCache::insert(cacheKey, boundPixmap); |
|
2038 |
|
2039 QCOMPARE(QGLTextureCache::instance()->size(), startCacheItemCount); |
|
2040 |
|
2041 p.drawPixmap(0, 0, boundPixmap); |
|
2042 QCOMPARE(QGLTextureCache::instance()->size(), startCacheItemCount+1); |
|
2043 |
|
2044 // Need to call end for the GL2 paint engine to release references to pixmap if using tfp |
|
2045 p.end(); |
|
2046 |
|
2047 QCOMPARE(QGLTextureCache::instance()->size(), startCacheItemCount+1); |
|
2048 |
|
2049 // Check that the texture doesn't get removed from the cache when the pixmap is cleared |
|
2050 // as it should still be in the cache: |
|
2051 boundPixmap = QPixmap(); |
|
2052 QCOMPARE(QGLTextureCache::instance()->size(), startCacheItemCount+1); |
|
2053 |
|
2054 // Finally, we check that the texture cache entry is removed when we remove the |
|
2055 // pixmap cache entry, which should hold the last reference: |
|
2056 QPixmapCache::remove(cacheKey); |
|
2057 QCOMPARE(QGLTextureCache::instance()->size(), startCacheItemCount); |
|
2058 } |
|
2059 |
|
2060 // Check images & pixmaps are removed from the cache when they are deleted |
|
2061 { |
|
2062 int startCacheItemCount = QGLTextureCache::instance()->size(); |
|
2063 QPainter p(&w); |
|
2064 |
|
2065 QImage *boundImage = new QImage(256, 256, QImage::Format_RGB32); |
|
2066 boundImage->fill(0xFFFFFFFF); |
|
2067 QPixmap *boundPixmap = new QPixmap(256, 256); |
|
2068 boundPixmap->fill(Qt::red); |
|
2069 |
|
2070 QCOMPARE(QGLTextureCache::instance()->size(), startCacheItemCount); |
|
2071 |
|
2072 p.drawImage(0, 0, *boundImage); |
|
2073 QCOMPARE(QGLTextureCache::instance()->size(), startCacheItemCount+1); |
|
2074 |
|
2075 p.drawPixmap(0, 0, *boundPixmap); |
|
2076 QCOMPARE(QGLTextureCache::instance()->size(), startCacheItemCount+2); |
|
2077 |
|
2078 // Need to call end for the GL2 paint engine to release references to pixmap if using tfp |
|
2079 p.end(); |
|
2080 |
|
2081 QCOMPARE(QGLTextureCache::instance()->size(), startCacheItemCount+2); |
|
2082 |
|
2083 delete boundImage; |
|
2084 boundImage = 0; |
|
2085 QCOMPARE(QGLTextureCache::instance()->size(), startCacheItemCount+1); |
|
2086 |
|
2087 delete boundPixmap; |
|
2088 boundPixmap = 0; |
|
2089 QCOMPARE(QGLTextureCache::instance()->size(), startCacheItemCount); |
|
2090 } |
|
2091 |
|
2092 // Check images & pixmaps are removed from the cache when they are assigned to |
|
2093 { |
|
2094 int startCacheItemCount = QGLTextureCache::instance()->size(); |
|
2095 QPainter p(&w); |
|
2096 |
|
2097 QImage boundImage(256, 256, QImage::Format_RGB32); |
|
2098 boundImage.fill(0xFFFFFFFF); |
|
2099 QPixmap boundPixmap(256, 256); |
|
2100 boundPixmap.fill(Qt::red); |
|
2101 |
|
2102 QCOMPARE(QGLTextureCache::instance()->size(), startCacheItemCount); |
|
2103 |
|
2104 p.drawImage(0, 0, boundImage); |
|
2105 QCOMPARE(QGLTextureCache::instance()->size(), startCacheItemCount+1); |
|
2106 |
|
2107 p.drawPixmap(0, 0, boundPixmap); |
|
2108 QCOMPARE(QGLTextureCache::instance()->size(), startCacheItemCount+2); |
|
2109 |
|
2110 // Need to call end for the GL2 paint engine to release references to pixmap if using tfp |
|
2111 p.end(); |
|
2112 |
|
2113 QCOMPARE(QGLTextureCache::instance()->size(), startCacheItemCount+2); |
|
2114 |
|
2115 boundImage = QImage(64, 64, QImage::Format_RGB32); |
|
2116 QCOMPARE(QGLTextureCache::instance()->size(), startCacheItemCount+1); |
|
2117 |
|
2118 boundPixmap = QPixmap(64, 64); |
|
2119 QCOMPARE(QGLTextureCache::instance()->size(), startCacheItemCount); |
|
2120 } |
|
2121 |
|
2122 // Check images & pixmaps are removed from the cache when they are modified (detached) |
|
2123 { |
|
2124 int startCacheItemCount = QGLTextureCache::instance()->size(); |
|
2125 QPainter p(&w); |
|
2126 |
|
2127 QImage boundImage(256, 256, QImage::Format_RGB32); |
|
2128 boundImage.fill(0xFFFFFFFF); |
|
2129 QPixmap boundPixmap(256, 256); |
|
2130 boundPixmap.fill(Qt::red); |
|
2131 |
|
2132 QCOMPARE(QGLTextureCache::instance()->size(), startCacheItemCount); |
|
2133 |
|
2134 p.drawImage(0, 0, boundImage); |
|
2135 QCOMPARE(QGLTextureCache::instance()->size(), startCacheItemCount+1); |
|
2136 |
|
2137 p.drawPixmap(0, 0, boundPixmap); |
|
2138 QCOMPARE(QGLTextureCache::instance()->size(), startCacheItemCount+2); |
|
2139 |
|
2140 // Need to call end for the GL2 paint engine to release references to pixmap if using tfp |
|
2141 p.end(); |
|
2142 |
|
2143 QCOMPARE(QGLTextureCache::instance()->size(), startCacheItemCount+2); |
|
2144 |
|
2145 boundImage.fill(0x00000000); |
|
2146 QCOMPARE(QGLTextureCache::instance()->size(), startCacheItemCount+1); |
|
2147 |
|
2148 boundPixmap.fill(Qt::blue); |
|
2149 QCOMPARE(QGLTextureCache::instance()->size(), startCacheItemCount); |
|
2150 } |
|
2151 |
|
2152 // Check that images/pixmaps aren't removed from the cache if a shallow copy has been made |
|
2153 QImage copyOfImage; |
|
2154 QPixmap copyOfPixmap; |
|
2155 int startCacheItemCount = QGLTextureCache::instance()->size(); |
|
2156 { |
|
2157 QPainter p(&w); |
|
2158 |
|
2159 QImage boundImage(256, 256, QImage::Format_RGB32); |
|
2160 boundImage.fill(0xFFFFFFFF); |
|
2161 QPixmap boundPixmap(256, 256); |
|
2162 boundPixmap.fill(Qt::red); |
|
2163 |
|
2164 QCOMPARE(QGLTextureCache::instance()->size(), startCacheItemCount); |
|
2165 |
|
2166 p.drawImage(0, 0, boundImage); |
|
2167 QCOMPARE(QGLTextureCache::instance()->size(), startCacheItemCount+1); |
|
2168 |
|
2169 p.drawPixmap(0, 0, boundPixmap); |
|
2170 QCOMPARE(QGLTextureCache::instance()->size(), startCacheItemCount+2); |
|
2171 |
|
2172 // Need to call end for the GL2 paint engine to release references to pixmap if using tfp |
|
2173 p.end(); |
|
2174 |
|
2175 copyOfImage = boundImage; |
|
2176 copyOfPixmap = boundPixmap; |
|
2177 QCOMPARE(QGLTextureCache::instance()->size(), startCacheItemCount+2); |
|
2178 } // boundImage & boundPixmap would have been deleted when they went out of scope |
|
2179 QCOMPARE(QGLTextureCache::instance()->size(), startCacheItemCount+2); |
|
2180 |
|
2181 copyOfImage = QImage(); |
|
2182 QCOMPARE(QGLTextureCache::instance()->size(), startCacheItemCount+1); |
|
2183 |
|
2184 copyOfPixmap = QPixmap(); |
|
2185 QCOMPARE(QGLTextureCache::instance()->size(), startCacheItemCount); |
|
2186 #endif |
|
2187 } |
|
2188 |
1972 QTEST_MAIN(tst_QGL) |
2189 QTEST_MAIN(tst_QGL) |
1973 #include "tst_qgl.moc" |
2190 #include "tst_qgl.moc" |