Home | History | Annotate | Download | only in src
      1 // Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 // This test evaluates the speed of using the same textures to draw repeatedly.
      6 // It uploads a series of textures initially.  On subsequent iterations, it uses
      7 // those uploaded textures to draw.
      8 
      9 #include "base/logging.h"
     10 
     11 #include "texturetest.h"
     12 #include "main.h"
     13 
     14 namespace glbench {
     15 
     16 class TextureReuseTest : public TextureTest {
     17  public:
     18   TextureReuseTest() {}
     19   virtual ~TextureReuseTest() {}
     20   virtual bool TestFunc(uint64_t iterations);
     21   virtual const char* Name() const { return "texture_reuse"; }
     22   virtual bool IsDrawTest() const { return true; }
     23 };
     24 
     25 bool TextureReuseTest::TestFunc(uint64_t iterations) {
     26   glGetError();
     27 
     28   glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
     29   glFlush();
     30 
     31   for (uint64_t i = 0; i < iterations; ++i) {
     32     glBindTexture(GL_TEXTURE_2D, textures_[i % kNumberOfTextures]);
     33     switch (flavor_) {
     34       case TEX_IMAGE:
     35         glTexImage2D(GL_TEXTURE_2D, 0, texel_gl_format_, width_, height_,
     36                      0, texel_gl_format_, GL_UNSIGNED_BYTE,
     37                      pixels_[i % kNumberOfTextures].get());
     38         break;
     39       case TEX_SUBIMAGE:
     40         glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width_, height_,
     41                         texel_gl_format_, GL_UNSIGNED_BYTE,
     42                         pixels_[i % kNumberOfTextures].get());
     43         break;
     44     }
     45 
     46     // After having uploaded |kNumberOfTextures| textures, use each of them to
     47     // draw once before uploading new textures.
     48     if ((i % kNumberOfTextures) == (kNumberOfTextures - 1)) {
     49       for (int j = 0; j < kNumberOfTextures; ++j) {
     50         glBindTexture(GL_TEXTURE_2D, textures_[j]);
     51         glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
     52       }
     53     }
     54   }
     55 
     56   return true;
     57 }
     58 
     59 TestBase* GetTextureReuseTest() {
     60   return new TextureReuseTest;
     61 }
     62 
     63 } // namespace glbench
     64