blob: b5acdfa361a64557366a2ab9d3ad7e479021e58a [file] [log] [blame]
Alexey Marinichev9f9b8732010-05-20 19:33:44 -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
5#include "base/logging.h"
6#include "base/scoped_ptr.h"
7
8#include "main.h"
9#include "testbase.h"
10
11
12namespace glbench {
13
14
15class ReadPixelTest : public TestBase {
16 public:
17 ReadPixelTest() : pixels_(NULL) {}
18 virtual ~ReadPixelTest() {}
19 virtual bool TestFunc(int iter);
20 virtual bool Run();
Alexey Marinichevf50ecb12010-06-14 15:21:41 -070021 virtual const char* Name() const { return "pixel_read"; }
Alexey Marinichev9f9b8732010-05-20 19:33:44 -070022
23 private:
24 void* pixels_;
25 DISALLOW_COPY_AND_ASSIGN(ReadPixelTest);
26};
27
28
29bool ReadPixelTest::TestFunc(int iter) {
30 glReadPixels(0, 0, g_width, g_height, GL_RGBA, GL_UNSIGNED_BYTE, pixels_);
31 CHECK(glGetError() == 0);
32 for (int i = 0; i < iter; i++)
33 glReadPixels(0, 0, g_width, g_height, GL_RGBA, GL_UNSIGNED_BYTE, pixels_);
34 return true;
35}
36
37
38bool ReadPixelTest::Run() {
39 // One GL_RGBA pixel takes 4 bytes.
40 const int row_size = g_width * 4;
41 // Default GL_PACK_ALIGNMENT is 4, round up pixel row size to multiple of 4.
42 // This is a no-op because row_size is already divisible by 4.
43 // One is added so that we can test reads into unaligned location.
44 scoped_array<char> buf(new char[((row_size + 3) & ~3) * g_height + 1]);
45 pixels_ = buf.get();
46 RunTest(this, "mpixels_sec_pixel_read", g_width * g_height, true);
47
48 // Reducing GL_PACK_ALIGNMENT can only make rows smaller. No need to
49 // reallocate the buffer.
50 glPixelStorei(GL_PACK_ALIGNMENT, 1);
51 RunTest(this, "mpixels_sec_pixel_read_2", g_width * g_height, true);
52
53 pixels_ = static_cast<void*>(buf.get() + 1);
54 RunTest(this, "mpixels_sec_pixel_read_3", g_width * g_height, true);
55
56 return true;
57}
58
59
60TestBase* GetReadPixelTest() {
61 return new ReadPixelTest;
62}
63
64
65} // namespace glbench