tests/benchmarks/opengl/main.cpp
changeset 33 3e2da88830cd
parent 18 2f34d5167611
equal deleted inserted replaced
30:5dc02b23752f 33:3e2da88830cd
    72     void clippedPainting_data();
    72     void clippedPainting_data();
    73     void clippedPainting();
    73     void clippedPainting();
    74 
    74 
    75     void gradients_data();
    75     void gradients_data();
    76     void gradients();
    76     void gradients();
       
    77 
       
    78     void textureUpload_data();
       
    79     void textureUpload();
       
    80 
    77 
    81 
    78 private:
    82 private:
    79     QGLPixelBuffer *pb;
    83     QGLPixelBuffer *pb;
    80 };
    84 };
    81 
    85 
   372         p.fillRect(0, 0, pb->width(), pb->height(), gradient);
   376         p.fillRect(0, 0, pb->width(), pb->height(), gradient);
   373         glFinish();
   377         glFinish();
   374     }
   378     }
   375 }
   379 }
   376 
   380 
       
   381 void OpenGLBench::textureUpload_data()
       
   382 {
       
   383     QTest::addColumn<int>("size");
       
   384     QTest::addColumn<int>("flags");
       
   385     QTest::addColumn<int>("format");
       
   386 
       
   387     int sizes[] = { 8, 10, 16, 20, 32, 50, 64, 100, 128, 200, 256, 500, 512, 1000, 1024, 2000, 2048, -1 };
       
   388     int flags[] = { QGLContext::InternalBindOption,
       
   389                   QGLContext::DefaultBindOption,
       
   390                   -1 };
       
   391     int formats[] = { GL_RGB, GL_RGBA, -1 };
       
   392 
       
   393     for (int s = 0; sizes[s] != -1; ++s) {
       
   394         for (int f = 0; flags[f] != -1; ++f) {
       
   395             for (int a = 0; formats[a] != -1; ++a) {
       
   396                 QByteArray name;
       
   397                 name.append("size=").append(QByteArray::number(sizes[s]));
       
   398                 name.append(", flags=").append(f == 0 ? "internal" : "default");
       
   399                 name.append(", format=").append(a == 0 ? "RGB" : "RGBA");
       
   400                 QTest::newRow(name.constData()) << sizes[s] << flags[f] << formats[a];
       
   401             }
       
   402         }
       
   403     }
       
   404 }
       
   405 
       
   406 void OpenGLBench::textureUpload()
       
   407 {
       
   408     QFETCH(int, size);
       
   409     QFETCH(int, flags);
       
   410     QFETCH(int, format);
       
   411 
       
   412     QPixmap pixmap(size, size);
       
   413 
       
   414     if (format == GL_RGB)
       
   415         pixmap.fill(Qt::red);
       
   416     else
       
   417         pixmap.fill(Qt::transparent);
       
   418 
       
   419     pb->makeCurrent();
       
   420     QGLContext *context = const_cast<QGLContext *>(QGLContext::currentContext());
       
   421     QTime time;
       
   422 
       
   423     time.start();
       
   424     context->bindTexture(pixmap, GL_TEXTURE_2D, format, (QGLContext::BindOptions) flags);
       
   425     QTest::setBenchmarkResult(time.elapsed(), QTest::WalltimeMilliseconds);
       
   426 }
       
   427 
   377 QTEST_MAIN(OpenGLBench)
   428 QTEST_MAIN(OpenGLBench)
   378 
   429 
   379 #include "main.moc"
   430 #include "main.moc"