framework/replay: recently introduced HTML tags should be in innerHTML
[piglit.git] / tests / llvmpipe / llvmpipe.cpp
blobaea92234d1ee32fee9052d970f6b8641c7f52af8
1 /*
2 * Copyright © 2012-2021 VMware, Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
25 * Tests for exercising llvmpipe linear optimizations.
27 * Authors:
28 * James Benton
31 #include "piglit-util-gl.h"
33 #include "utils/framebuffer.h"
34 #include "utils/glenum.h"
36 #include "glsl/shader.h"
37 #include "tests/random.h"
39 #include "version.h"
41 #include <time.h>
42 #include <iostream>
44 PIGLIT_GL_TEST_CONFIG_BEGIN
46 config.supports_gl_compat_version = 10;
48 config.window_width = 256;
49 config.window_height = 256;
50 config.window_visual = PIGLIT_GL_VISUAL_RGBA | PIGLIT_GL_VISUAL_DOUBLE;
52 PIGLIT_GL_TEST_CONFIG_END
54 Random gRandom;
55 FrameBuffer gFrameBuffer;
57 bool RandomTest::enabled = true;
59 int random_test_count = 10000;
61 bool test_perform_next = false;
62 std::vector<Test*> tests;
63 std::vector<Test*>::iterator test_current;
65 enum piglit_result
66 piglit_display(void)
68 bool pass = true;
70 gFrameBuffer.bind();
71 gFrameBuffer.tolerance(piglit_tolerance);
72 piglit_ortho_projection(gFrameBuffer.width(), gFrameBuffer.height(), GL_FALSE);
74 if (piglit_automatic) {
75 for (std::vector<Test*>::iterator itr = tests.begin(); itr != tests.end(); ++itr) {
76 Test* test = *itr;
77 pass &= test->run();
80 RandomTest rnd;
81 for (int i = 0; i < random_test_count; ++i)
82 pass &= rnd.run();
83 } else {
84 if (test_perform_next) {
85 test_current++;
87 if (test_current == tests.end())
88 test_current = tests.begin();
91 Test* test = *test_current;
92 pass = test->run();
94 gFrameBuffer.unbind();
96 glUseProgram(0);
97 glDisable(GL_BLEND);
98 glDisable(GL_ALPHA_TEST);
99 glViewport(0, 0, piglit_width, piglit_height);
101 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
102 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_REPLACE);
103 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_REPLACE);
105 glColor4f(1, 1, 1, 1);
106 glEnable(GL_TEXTURE_2D);
107 glBindTexture(GL_TEXTURE_2D, gFrameBuffer.texture());
109 piglit_draw_rect_tex(0, 0, piglit_width, piglit_height, 0, 0, 1, 1);
111 glDisable(GL_TEXTURE_2D);
112 piglit_swap_buffers();
114 test_perform_next = false;
117 fflush(stdout);
118 fflush(stderr);
120 return pass ? PIGLIT_PASS : PIGLIT_FAIL;
123 void fbo_formats_key_func(unsigned char key, int x, int y)
125 if (key == 'n') {
126 test_perform_next = true;
129 piglit_escape_exit_key(key, x, y);
132 void piglit_init(int argc, char** argv)
134 std::cout.precision(9);
135 std::cout << "git head: " << GIT_HEAD << std::endl;
137 gFrameBuffer.setSize(piglit_width, piglit_height);
138 gRandom.setImplementation(new Mersenne(0xbeefface));
140 for (int i = 1; i < argc; ++i) {
141 if (strcmp(argv[i], "-rgba32f") == 0) {
142 gFrameBuffer.setFormat(GL_RGBA);
143 gFrameBuffer.setInternalFormat(GL_RGBA32F);
144 gFrameBuffer.setType(GL_FLOAT);
145 } else if (strcmp(argv[i], "-clamped") == 0) {
146 gFrameBuffer.setClamped(true);
147 } else if (strcmp(argv[i], "-unclamped") == 0) {
148 gFrameBuffer.setClamped(false);
149 } else if (i + 1 < argc) {
150 if (strcmp(argv[i], "-test") == 0) {
151 tests.push_back(new RandomTest(argv[++i]));
152 } else if (strcmp(argv[i], "-count") == 0) {
153 random_test_count = atoi(argv[++i]);
154 } else if (strcmp(argv[i], "-type") == 0) {
155 gFrameBuffer.setType(glStringToEnum(argv[++i]));
156 } else if (strcmp(argv[i], "-internalformat") == 0) {
157 gFrameBuffer.setInternalFormat(glStringToEnum(argv[++i]));
158 } else if (strcmp(argv[i], "-format") == 0) {
159 gFrameBuffer.setFormat(glStringToEnum(argv[++i]));
164 if (gFrameBuffer.type() != GL_FLOAT && gFrameBuffer.type() != GL_HALF_FLOAT && !gFrameBuffer.clamped()) {
165 gFrameBuffer.setClamped(true);
168 piglit_require_extension("GL_EXT_framebuffer_object");
169 piglit_require_extension("GL_ARB_texture_env_combine");
171 piglit_require_vertex_shader();
172 piglit_require_fragment_shader();
174 piglit_set_keyboard_func(fbo_formats_key_func);
176 glDisable(GL_DITHER);
178 if (RandomTest::enabled) {
179 if (!piglit_automatic)
180 tests.push_back(new RandomTest());
183 test_current = tests.begin();