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 "main.h"
10 #include "texturetest.h"
11
12 namespace glbench {
13
14 class TextureReuseTest : public TextureTest {
15 public:
TextureReuseTest()16 TextureReuseTest() {}
~TextureReuseTest()17 virtual ~TextureReuseTest() {}
18 virtual bool TestFunc(uint64_t iterations);
Name() const19 virtual const char* Name() const { return "texture_reuse"; }
IsDrawTest() const20 virtual bool IsDrawTest() const { return true; }
21 };
22
TestFunc(uint64_t iterations)23 bool TextureReuseTest::TestFunc(uint64_t iterations) {
24 glGetError();
25
26 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
27 glFlush();
28
29 for (uint64_t i = 0; i < iterations; ++i) {
30 glBindTexture(GL_TEXTURE_2D, textures_[i % kNumberOfTextures]);
31 switch (flavor_) {
32 case TEX_IMAGE:
33 glTexImage2D(GL_TEXTURE_2D, 0, texel_gl_format_, width_, height_, 0,
34 texel_gl_format_, GL_UNSIGNED_BYTE,
35 pixels_[i % kNumberOfTextures].get());
36 break;
37 case TEX_SUBIMAGE:
38 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width_, height_,
39 texel_gl_format_, GL_UNSIGNED_BYTE,
40 pixels_[i % kNumberOfTextures].get());
41 break;
42 }
43
44 // After having uploaded |kNumberOfTextures| textures, use each of them to
45 // draw once before uploading new textures.
46 if ((i % kNumberOfTextures) == (kNumberOfTextures - 1)) {
47 for (int j = 0; j < kNumberOfTextures; ++j) {
48 glBindTexture(GL_TEXTURE_2D, textures_[j]);
49 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
50 }
51 }
52 }
53
54 return true;
55 }
56
GetTextureReuseTest()57 TestBase* GetTextureReuseTest() {
58 return new TextureReuseTest;
59 }
60
61 } // namespace glbench
62