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 evalutes the speed of uploading textures without actually drawing.
      6 
      7 #include "main.h"
      8 #include "texturetest.h"
      9 
     10 namespace glbench {
     11 
     12 class TextureUploadTest : public TextureTest {
     13  public:
     14   TextureUploadTest() {}
     15   virtual ~TextureUploadTest() {}
     16   virtual bool TestFunc(uint64_t iterations);
     17   virtual const char* Name() const { return "texture_upload"; }
     18   virtual bool IsDrawTest() const { return false; }
     19 };
     20 
     21 bool TextureUploadTest::TestFunc(uint64_t iterations) {
     22   glGetError();
     23 
     24   for (uint64_t i = 0; i < iterations; ++i) {
     25     glBindTexture(GL_TEXTURE_2D, textures_[i % kNumberOfTextures]);
     26     switch (flavor_) {
     27       case TEX_IMAGE:
     28         glTexImage2D(GL_TEXTURE_2D, 0, texel_gl_format_, width_, height_, 0,
     29                      texel_gl_format_, GL_UNSIGNED_BYTE,
     30                      pixels_[i % kNumberOfTextures].get());
     31         break;
     32       case TEX_SUBIMAGE:
     33         glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width_, height_,
     34                         texel_gl_format_, GL_UNSIGNED_BYTE,
     35                         pixels_[i % kNumberOfTextures].get());
     36         break;
     37     }
     38   }
     39 
     40   return true;
     41 }
     42 
     43 TestBase* GetTextureUploadTest() {
     44   return new TextureUploadTest;
     45 }
     46 
     47 }  // namespace glbench
     48