blob: 8592465c17a5dc6f04d01f9f0f65eae9cf53b7d4 [file] [log] [blame]
Alexey Marinichev9c891ef2010-05-21 15:28:59 -07001// 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 Quec6ae4d52012-12-26 16:41:24 -08005// This test evaluates the speed of updating a single texture and using it to
6// draw after each upload.
Alexey Marinichev9c891ef2010-05-21 15:28:59 -07007
Simon Quec6ae4d52012-12-26 16:41:24 -08008#include "base/logging.h"
9
10#include "texturetest.h"
Alexey Marinichev9c891ef2010-05-21 15:28:59 -070011#include "main.h"
Alexey Marinichev9c891ef2010-05-21 15:28:59 -070012
13namespace glbench {
14
Simon Quec6ae4d52012-12-26 16:41:24 -080015class TextureUpdateTest : public TextureTest {
Alexey Marinichev9c891ef2010-05-21 15:28:59 -070016 public:
17 TextureUpdateTest() {}
18 virtual ~TextureUpdateTest() {}
Ilja H. Friedel439ea142014-02-21 20:29:10 -080019 virtual bool TestFunc(uint64_t iterations);
Alexey Marinichevf50ecb12010-06-14 15:21:41 -070020 virtual const char* Name() const { return "texture_update"; }
Daniel Kurtzbcad4fb2014-06-18 12:31:03 +080021 virtual bool IsDrawTest() const { return true; }
Alexey Marinichev9c891ef2010-05-21 15:28:59 -070022};
23
Ilja H. Friedel439ea142014-02-21 20:29:10 -080024bool TextureUpdateTest::TestFunc(uint64_t iterations) {
Alexey Marinichev9c891ef2010-05-21 15:28:59 -070025 glGetError();
Alexey Marinichev9c891ef2010-05-21 15:28:59 -070026
Frank Henigman819a7fc2015-03-18 14:12:03 -040027 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
Alexey Marinichev9c891ef2010-05-21 15:28:59 -070028 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
29 glFlush();
Daniel Kurtz0f359492014-05-30 10:28:19 +080030 for (uint64_t i = 0; i < iterations; ++i) {
Alexey Marinichev9c891ef2010-05-21 15:28:59 -070031 switch (flavor_) {
32 case TEX_IMAGE:
Daniel Kurtzfe871ec2014-06-06 13:02:10 +080033 glTexImage2D(GL_TEXTURE_2D, 0, texel_gl_format_, width_, height_,
34 0, texel_gl_format_, GL_UNSIGNED_BYTE,
Alexey Marinichev9c891ef2010-05-21 15:28:59 -070035 pixels_[i % kNumberOfTextures].get());
36 break;
37 case TEX_SUBIMAGE:
38 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width_, height_,
Daniel Kurtzfe871ec2014-06-06 13:02:10 +080039 texel_gl_format_, GL_UNSIGNED_BYTE,
Alexey Marinichev9c891ef2010-05-21 15:28:59 -070040 pixels_[i % kNumberOfTextures].get());
41 break;
42 }
43 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
44 }
45 return true;
46}
47
Alexey Marinichev9c891ef2010-05-21 15:28:59 -070048TestBase* GetTextureUpdateTest() {
49 return new TextureUpdateTest;
50}
51
52} // namespace glbench