1 // Copyright (c) 2010 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 updating a single texture and using it to
6 // draw after each upload.
7
8 #include "base/logging.h"
9
10 #include "texturetest.h"
11 #include "main.h"
12
13 namespace glbench {
14
15 class TextureUpdateTest : public TextureTest {
16 public:
TextureUpdateTest()17 TextureUpdateTest() {}
~TextureUpdateTest()18 virtual ~TextureUpdateTest() {}
19 virtual bool TestFunc(uint64_t iterations);
Name() const20 virtual const char* Name() const { return "texture_update"; }
IsDrawTest() const21 virtual bool IsDrawTest() const { return true; }
22 };
23
TestFunc(uint64_t iterations)24 bool TextureUpdateTest::TestFunc(uint64_t iterations) {
25 glGetError();
26
27 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
28 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
29 glFlush();
30 for (uint64_t i = 0; i < iterations; ++i) {
31 switch (flavor_) {
32 case TEX_IMAGE:
33 glTexImage2D(GL_TEXTURE_2D, 0, texel_gl_format_, width_, height_,
34 0, 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 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
44 }
45 return true;
46 }
47
GetTextureUpdateTest()48 TestBase* GetTextureUpdateTest() {
49 return new TextureUpdateTest;
50 }
51
52 } // namespace glbench
53