cl: Don't use device_infos if num_device_infos == 0
[piglit.git] / tests / shaders / shader_runner_gles_workarounds.h
blobbbcdc9b4ad774f2f97d7cf3b19dd3752ae097925
1 /*
2 * Copyright © 2012 Intel Corporation
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
21 * DEALINGS IN THE SOFTWARE.
24 /**
25 * \file
26 * \brief Workarounds for building with GLES2 and GLES3.
28 * When building shader_runner against GLESX and libpiglitutil_glesX, there
29 * are many macros and symbols that are not defined. This header defines such
30 * macros to have the same value found in <GL/gl*.h>, and defines such
31 * functions to print an error message and then report PIGLIT_SKIP, just as
32 * piglit-dispatch does for unsupported extension functions.
35 #include <stdio.h>
36 #include "piglit-util.h"
38 static void
39 #if defined(__GNUC__)
40 __attribute__((unused))
41 #endif
42 unsupported_function(const char *name, ...)
44 printf("Function \"%s\" not supported on this implementation\n", name);
45 piglit_report_result(PIGLIT_SKIP);
48 /**
49 * This macro should be sufficient for most functions. If one of the actual
50 * function's parameters causes an unused-variable warning, you must
51 * special-case the function. See glBindProgramARB for example.
53 * GLES doesn't exist on Windows. So we're free to use the GCC/Clang extension
54 * for statement expressions.
56 #define UNSUPPORTED_FUNCTION(name, return_value, ...) \
57 ({ \
58 unsupported_function(#name, __VA_ARGS__); \
59 return_value; \
62 #if defined(PIGLIT_USE_OPENGL_ES3) || defined(PIGLIT_USE_OPENGL_ES2)
64 #define piglit_frustum_projection(...) UNSUPPORTED_FUNCTION(piglit_frustum_projection, 0, __VA_ARGS__)
65 #define piglit_gen_ortho_projection(...) UNSUPPORTED_FUNCTION(piglit_gen_ortho_projection, 0, __VA_ARGS__)
66 #define piglit_miptree_texture() UNSUPPORTED_FUNCTION(piglit_miptree_texture, 0, 0)
67 #define piglit_depth_texture(...) UNSUPPORTED_FUNCTION(piglit_depth_texture, 0, __VA_ARGS__)
68 #define piglit_ortho_projection(...) UNSUPPORTED_FUNCTION(piglit_ortho_projection, 0, __VA_ARGS__)
69 #define piglit_compile_program(...) UNSUPPORTED_FUNCTION(piglit_compile_program, 0, __VA_ARGS__)
71 #if defined(PIGLIT_USE_OPENGL_ES3)
72 #undef glMapBuffer
74 static GLvoid*
75 glMapBuffer(GLenum target, GLbitfield map_buffer_access)
77 /* Emulate with glMapBufferRange. */
79 GLsizeiptr length = 0;
80 GLbitfield map_buffer_range_access;
82 glGetBufferParameteri64v(target, GL_BUFFER_SIZE, (GLint64*) &length);
83 if (!piglit_check_gl_error(GL_NO_ERROR))
84 piglit_report_result(PIGLIT_FAIL);
86 switch (map_buffer_access) {
87 case GL_READ_ONLY:
88 map_buffer_range_access = GL_MAP_READ_BIT;
89 break;
90 case GL_WRITE_ONLY:
91 map_buffer_range_access = GL_MAP_WRITE_BIT;
92 break;
93 case GL_READ_WRITE:
94 map_buffer_range_access = GL_MAP_READ_BIT | GL_MAP_WRITE_BIT;
95 break;
96 default:
97 map_buffer_range_access = 0;
98 break;
100 return glMapBufferRange(target, 0, length, map_buffer_range_access);
102 #endif /* PIGLIT_USE_OPENGL_ES3 */
104 #endif /* PIGLIT_USE_OPENGL_ES3 || PIGLIT_USE_OPENGL_ES2 */