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 "main.h"
9 #include "texturetest.h"
10
11 namespace glbench {
12
13 class TextureUpdateTest : public TextureTest {
14 public:
TextureUpdateTest()15 TextureUpdateTest() {}
~TextureUpdateTest()16 virtual ~TextureUpdateTest() {}
17 virtual bool TestFunc(uint64_t iterations);
Name() const18 virtual const char* Name() const { return "texture_update"; }
IsDrawTest() const19 virtual bool IsDrawTest() const { return true; }
20 };
21
TestFunc(uint64_t iterations)22 bool TextureUpdateTest::TestFunc(uint64_t iterations) {
23 glGetError();
24
25 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
26 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
27 glFlush();
28 for (uint64_t i = 0; i < iterations; ++i) {
29 switch (flavor_) {
30 case TEX_IMAGE:
31 glTexImage2D(GL_TEXTURE_2D, 0, texel_gl_format_, width_, height_, 0,
32 texel_gl_format_, GL_UNSIGNED_BYTE,
33 pixels_[i % kNumberOfTextures].get());
34 break;
35 case TEX_SUBIMAGE:
36 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width_, height_,
37 texel_gl_format_, GL_UNSIGNED_BYTE,
38 pixels_[i % kNumberOfTextures].get());
39 break;
40 }
41 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
42 }
43 return true;
44 }
45
GetTextureUpdateTest()46 TestBase* GetTextureUpdateTest() {
47 return new TextureUpdateTest;
48 }
49
50 } // namespace glbench
51