Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(26)

Side by Side Diff: client/deps/glbench/src/textureupdatetest.cc

Issue 2115012: Added texture update test. (Closed) Base URL: ssh://git@chromiumos-git//autotest.git
Patch Set: C++ enum Created 10 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « client/deps/glbench/src/testbase.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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 #include "base/logging.h"
6 #include "base/scoped_ptr.h"
7 #include "base/string_util.h"
8
9 #include "main.h"
10 #include "testbase.h"
11 #include "utils.h"
12
13 namespace glbench {
14
15 static const int kNumberOfTextures = 8;
16
17 class TextureUpdateTest : public TestBase {
18 public:
19 TextureUpdateTest() {}
20 virtual ~TextureUpdateTest() {}
21 bool TestFunc(int iter);
22 virtual bool Run();
23
24 enum UpdateFlavor {
25 TEX_IMAGE,
26 TEX_SUBIMAGE
27 };
28
29 private:
30 GLuint width_;
31 GLuint height_;
32 GLuint program_;
33 int texsize_;
34 scoped_array<char> pixels_[kNumberOfTextures];
35 UpdateFlavor flavor_;
36 DISALLOW_COPY_AND_ASSIGN(TextureUpdateTest);
37 };
38
39 #if I915_WORKAROUND
40 #define V1 "gl_TexCoord[0]"
41 #else
42 #define V1 "v1"
43 #endif
44
45 static const char* kVertexShader =
46 "attribute vec4 c1;"
47 "attribute vec4 c2;"
48 "varying vec4 v1;"
49 "void main() {"
50 " gl_Position = c1;"
51 V1 "= c2;"
52 "}";
53
54 static const char* kFragmentShader =
55 "varying vec4 v1;"
56 "uniform sampler2D texture;"
57 "void main() {"
58 " gl_FragColor = texture2D(texture, " V1 ".xy);"
59 "}";
60
61 bool TextureUpdateTest::TestFunc(int iter) {
62 glGetError();
63 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, width_, height_,
64 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, NULL);
65 if (glGetError() != 0) {
66 printf("# Failed to allocate %dx%d texture.\n", width_, height_);
67 return false;
68 }
69
70 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
71 glFlush();
72 for (int i = 0; i < iter-1; ++i) {
73 switch (flavor_) {
74 case TEX_IMAGE:
75 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, width_, height_,
76 0, GL_LUMINANCE, GL_UNSIGNED_BYTE,
77 pixels_[i % kNumberOfTextures].get());
78 break;
79 case TEX_SUBIMAGE:
80 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width_, height_,
81 GL_LUMINANCE, GL_UNSIGNED_BYTE,
82 pixels_[i % kNumberOfTextures].get());
83 break;
84 }
85 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
86 }
87 return true;
88 }
89
90 bool TextureUpdateTest::Run() {
91 // Two triangles that form one pixel at 0, 0.
92 GLfloat vertices[8] = {
93 0.f, 0.f,
94 2.f / g_width, 0.f,
95 0.f, 2.f / g_height,
96 2.f / g_width, 2.f / g_height,
97 };
98 GLfloat texcoords[8] = {
99 0.f, 0.f, 0.f, 0.f,
100 0.f, 0.f, 0.f, 0.f,
101 };
102
103 program_ = InitShaderProgram(kVertexShader, kFragmentShader);
104
105 int attr1 = glGetAttribLocation(program_, "c1");
106 glVertexAttribPointer(attr1, 2, GL_FLOAT, GL_FALSE, 0, vertices);
107 glEnableVertexAttribArray(attr1);
108
109 int attr2 = glGetAttribLocation(program_, "c2");
110 glVertexAttribPointer(attr2, 2, GL_FLOAT, GL_FALSE, 0, texcoords);
111 glEnableVertexAttribArray(attr2);
112
113 int texture_sampler = glGetUniformLocation(program_, "texture");
114 glUniform1i(texture_sampler, 0);
115 glActiveTexture(GL_TEXTURE0);
116
117 GLuint texname;
118 glGenTextures(1, &texname);
119 glBindTexture(GL_TEXTURE_2D, texname);
120 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
121 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
122
123
124 UpdateFlavor flavors[] = {TEX_IMAGE, TEX_SUBIMAGE};
125 const std::string flavor_names[] = {"teximage2d", "texsubimage2d"};
126 for (unsigned int f = 0; f < arraysize(flavors); f++) {
127 flavor_ = flavors[f];
128 int sizes[] = {32, 128, 256, 512, 768, 1024, 1536, 2048};
129 for (unsigned int i = 0; i < arraysize(sizes); i++) {
130 std::string name = "mtexel_sec_" + flavor_names[f] + "_" +
131 IntToString(sizes[i]);
132 width_ = height_ = sizes[i];
133 for (int i = 0; i < kNumberOfTextures; ++i)
134 pixels_[i].reset(new char[width_ * height_]);
135 RunTest(this, name.c_str(), width_ * height_, true);
136 }
137 }
138
139 glDeleteTextures(1, &texname);
140 glDeleteProgram(program_);
141 return true;
142 }
143
144 TestBase* GetTextureUpdateTest() {
145 return new TextureUpdateTest;
146 }
147
148 } // namespace glbench
OLDNEW
« no previous file with comments | « client/deps/glbench/src/testbase.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698