Alexey Marinichev | 9c891ef | 2010-05-21 15:28:59 -0700 | [diff] [blame] | 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 | |
Simon Que | c6ae4d5 | 2012-12-26 16:41:24 -0800 | [diff] [blame] | 5 | // This test evaluates the speed of updating a single texture and using it to |
| 6 | // draw after each upload. |
Alexey Marinichev | 9c891ef | 2010-05-21 15:28:59 -0700 | [diff] [blame] | 7 | |
Simon Que | c6ae4d5 | 2012-12-26 16:41:24 -0800 | [diff] [blame] | 8 | #include "base/logging.h" |
| 9 | |
| 10 | #include "texturetest.h" |
Alexey Marinichev | 9c891ef | 2010-05-21 15:28:59 -0700 | [diff] [blame] | 11 | #include "main.h" |
Alexey Marinichev | 9c891ef | 2010-05-21 15:28:59 -0700 | [diff] [blame] | 12 | |
| 13 | namespace glbench { |
| 14 | |
Simon Que | c6ae4d5 | 2012-12-26 16:41:24 -0800 | [diff] [blame] | 15 | class TextureUpdateTest : public TextureTest { |
Alexey Marinichev | 9c891ef | 2010-05-21 15:28:59 -0700 | [diff] [blame] | 16 | public: |
| 17 | TextureUpdateTest() {} |
| 18 | virtual ~TextureUpdateTest() {} |
Ilja H. Friedel | 439ea14 | 2014-02-21 20:29:10 -0800 | [diff] [blame] | 19 | virtual bool TestFunc(uint64_t iterations); |
Alexey Marinichev | f50ecb1 | 2010-06-14 15:21:41 -0700 | [diff] [blame] | 20 | virtual const char* Name() const { return "texture_update"; } |
Daniel Kurtz | bcad4fb | 2014-06-18 12:31:03 +0800 | [diff] [blame] | 21 | virtual bool IsDrawTest() const { return true; } |
Alexey Marinichev | 9c891ef | 2010-05-21 15:28:59 -0700 | [diff] [blame] | 22 | }; |
| 23 | |
Ilja H. Friedel | 439ea14 | 2014-02-21 20:29:10 -0800 | [diff] [blame] | 24 | bool TextureUpdateTest::TestFunc(uint64_t iterations) { |
Alexey Marinichev | 9c891ef | 2010-05-21 15:28:59 -0700 | [diff] [blame] | 25 | glGetError(); |
Alexey Marinichev | 9c891ef | 2010-05-21 15:28:59 -0700 | [diff] [blame] | 26 | |
Frank Henigman | 819a7fc | 2015-03-18 14:12:03 -0400 | [diff] [blame] | 27 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
Alexey Marinichev | 9c891ef | 2010-05-21 15:28:59 -0700 | [diff] [blame] | 28 | glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); |
| 29 | glFlush(); |
Daniel Kurtz | 0f35949 | 2014-05-30 10:28:19 +0800 | [diff] [blame] | 30 | for (uint64_t i = 0; i < iterations; ++i) { |
Alexey Marinichev | 9c891ef | 2010-05-21 15:28:59 -0700 | [diff] [blame] | 31 | switch (flavor_) { |
| 32 | case TEX_IMAGE: |
Daniel Kurtz | fe871ec | 2014-06-06 13:02:10 +0800 | [diff] [blame] | 33 | glTexImage2D(GL_TEXTURE_2D, 0, texel_gl_format_, width_, height_, |
| 34 | 0, texel_gl_format_, GL_UNSIGNED_BYTE, |
Alexey Marinichev | 9c891ef | 2010-05-21 15:28:59 -0700 | [diff] [blame] | 35 | pixels_[i % kNumberOfTextures].get()); |
| 36 | break; |
| 37 | case TEX_SUBIMAGE: |
| 38 | glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width_, height_, |
Daniel Kurtz | fe871ec | 2014-06-06 13:02:10 +0800 | [diff] [blame] | 39 | texel_gl_format_, GL_UNSIGNED_BYTE, |
Alexey Marinichev | 9c891ef | 2010-05-21 15:28:59 -0700 | [diff] [blame] | 40 | pixels_[i % kNumberOfTextures].get()); |
| 41 | break; |
| 42 | } |
| 43 | glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); |
| 44 | } |
| 45 | return true; |
| 46 | } |
| 47 | |
Alexey Marinichev | 9c891ef | 2010-05-21 15:28:59 -0700 | [diff] [blame] | 48 | TestBase* GetTextureUpdateTest() { |
| 49 | return new TextureUpdateTest; |
| 50 | } |
| 51 | |
| 52 | } // namespace glbench |