Convert Google Now's Authentication Manager to use Promises
[chromium-blink-merge.git] / gpu / command_buffer / tests / occlusion_query_unittest.cc
blob7cbb1a8e4eb418139009a69e076ca9c746dee996
1 // Copyright 2014 The Chromium 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.
5 #include <GLES2/gl2.h>
6 #include <GLES2/gl2ext.h>
8 #include "gpu/command_buffer/tests/gl_manager.h"
9 #include "gpu/command_buffer/tests/gl_test_utils.h"
10 #include "testing/gmock/include/gmock/gmock.h"
11 #include "testing/gtest/include/gtest/gtest.h"
13 namespace gpu {
15 class OcclusionQueryTest : public testing::Test {
16 protected:
17 virtual void SetUp() {
18 GLManager::Options options;
19 options.size = gfx::Size(512, 512);
20 gl_.Initialize(options);
23 virtual void TearDown() {
24 gl_.Destroy();
27 void DrawRect(float x, float z, float scale, float* color);
29 GLManager gl_;
31 GLint position_loc_;
32 GLint matrix_loc_;
33 GLint color_loc_;
36 static void SetMatrix(float x, float z, float scale, float* matrix) {
37 matrix[0] = scale;
38 matrix[1] = 0.0f;
39 matrix[2] = 0.0f;
40 matrix[3] = 0.0f;
42 matrix[4] = 0.0f;
43 matrix[5] = scale;
44 matrix[6] = 0.0f;
45 matrix[7] = 0.0f;
47 matrix[8] = 0.0f;
48 matrix[9] = 0.0f;
49 matrix[10] = scale;
50 matrix[11] = 0.0f;
52 matrix[12] = x;
53 matrix[13] = 0.0f;
54 matrix[14] = z;
55 matrix[15] = 1.0f;
58 void OcclusionQueryTest::DrawRect(float x, float z, float scale, float* color) {
59 GLfloat matrix[16];
61 SetMatrix(x, z, scale, matrix);
63 // Set up the model matrix
64 glUniformMatrix4fv(matrix_loc_, 1, GL_FALSE, matrix);
65 glUniform4fv(color_loc_, 1, color);
67 glDrawArrays(GL_TRIANGLES, 0, 6);
70 TEST_F(OcclusionQueryTest, Occlusion) {
71 #if defined(OS_MACOSX)
72 EXPECT_TRUE(GLTestHelper::HasExtension("GL_EXT_occlusion_query_boolean"))
73 << "GL_EXT_occlusion_query_boolean is required on OSX";
74 #endif
76 if (!GLTestHelper::HasExtension("GL_EXT_occlusion_query_boolean")) {
77 return;
80 static const char* v_shader_str =
81 "uniform mat4 worldMatrix;\n"
82 "attribute vec3 g_Position;\n"
83 "void main()\n"
84 "{\n"
85 " gl_Position = worldMatrix *\n"
86 " vec4(g_Position.x, g_Position.y, g_Position.z, 1.0);\n"
87 "}\n";
88 static const char* f_shader_str =
89 "precision mediump float;"
90 "uniform vec4 color;\n"
91 "void main()\n"
92 "{\n"
93 " gl_FragColor = color;\n"
94 "}\n";
96 GLuint program = GLTestHelper::LoadProgram(v_shader_str, f_shader_str);
98 position_loc_ = glGetAttribLocation(program, "g_Position");
99 matrix_loc_ = glGetUniformLocation(program, "worldMatrix");
100 color_loc_ = glGetUniformLocation(program, "color");
102 GLTestHelper::SetupUnitQuad(position_loc_);
104 GLuint query = 0;
105 glGenQueriesEXT(1, &query);
107 glEnable(GL_DEPTH_TEST);
108 glClearColor(0.0f, 0.1f, 0.2f, 1.0f);
110 // Use the program object
111 glUseProgram(program);
113 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
114 static float red[] = { 1.0f, 0.0f, 0.0f, 1.0f };
115 DrawRect(0, 0.0f, 0.50f, red);
117 glBeginQueryEXT(GL_ANY_SAMPLES_PASSED_EXT, query);
118 static float blue[] = { 0.0f, 0.0f, 1.0f, 1.0f };
119 DrawRect(-0.125f, 0.1f, 0.25f, blue);
120 glEndQueryEXT(GL_ANY_SAMPLES_PASSED_EXT);
122 glFinish();
124 GLuint query_status = 0;
125 GLuint result = 0;
126 glGetQueryObjectuivEXT(query, GL_QUERY_RESULT_AVAILABLE_EXT, &result);
127 EXPECT_TRUE(result);
128 glGetQueryObjectuivEXT(query, GL_QUERY_RESULT_EXT, &query_status);
129 EXPECT_FALSE(query_status);
131 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
132 DrawRect(1, 0.0f, 0.50f, red);
134 glBeginQueryEXT(GL_ANY_SAMPLES_PASSED_EXT, query);
135 DrawRect(-0.125f, 0.1f, 0.25f, blue);
136 glEndQueryEXT(GL_ANY_SAMPLES_PASSED_EXT);
138 glFinish();
140 query_status = 0;
141 result = 0;
142 glGetQueryObjectuivEXT(query, GL_QUERY_RESULT_AVAILABLE_EXT, &result);
143 EXPECT_TRUE(result);
144 glGetQueryObjectuivEXT(query, GL_QUERY_RESULT_EXT, &query_status);
145 EXPECT_TRUE(query_status);
146 GLTestHelper::CheckGLError("no errors", __LINE__);
149 } // namespace gpu