mesa/es: Enable GL_EXT_map_buffer_range
[mesa.git] / src / mesa / main / tests / dispatch_sanity.cpp
1 /*
2 * Copyright © 2012 Intel Corporation
3 *
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:
10 *
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.
14 *
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.
22 */
23
24 /**
25 * \name dispatch_sanity.cpp
26 *
27 * Verify that only set of functions that should be available in a particular
28 * API are available in that API.
29 *
30 * The list of expected functions originally came from the functions set by
31 * api_exec_es2.c. This file no longer exists in Mesa (but api_exec_es1.c was
32 * still generated at the time this test was written). It was the generated
33 * file that configured the dispatch table for ES2 contexts. This test
34 * verifies that all of the functions set by the old api_exec_es2.c (with the
35 * recent addition of VAO functions) are set in the dispatch table and
36 * everything else is a NOP.
37 *
38 * When adding extensions that add new functions, this test will need to be
39 * modified to expect dispatch functions for the new extension functions.
40 */
41
42 extern "C" {
43 #include "main/mfeatures.h"
44 }
45
46 #if FEATURE_ES2
47
48 #include <gtest/gtest.h>
49
50 extern "C" {
51 #include "GL/gl.h"
52 #include "GL/glext.h"
53 #include "main/compiler.h"
54 #include "main/api_exec.h"
55 #include "main/context.h"
56 #include "main/remap.h"
57 #include "glapi/glapi.h"
58 #include "drivers/common/driverfuncs.h"
59
60 #include "swrast/swrast.h"
61 #include "vbo/vbo.h"
62 #include "tnl/tnl.h"
63 #include "swrast_setup/swrast_setup.h"
64
65 #ifndef GLAPIENTRYP
66 #define GLAPIENTRYP GL_APIENTRYP
67 #endif
68
69 #include "main/dispatch.h"
70 }
71
72 struct function {
73 const char *name;
74 int offset;
75 };
76
77 extern const struct function gles2_functions_possible[];
78
79 class DispatchSanity_test : public ::testing::Test {
80 public:
81 virtual void SetUp();
82
83 struct gl_config visual;
84 struct dd_function_table driver_functions;
85 struct gl_context share_list;
86 struct gl_context ctx;
87 };
88
89 void
90 DispatchSanity_test::SetUp()
91 {
92 memset(&visual, 0, sizeof(visual));
93 memset(&driver_functions, 0, sizeof(driver_functions));
94 memset(&share_list, 0, sizeof(share_list));
95 memset(&ctx, 0, sizeof(ctx));
96
97 _mesa_init_driver_functions(&driver_functions);
98 }
99
100 static void
101 validate_functions(_glapi_proc *table, const struct function *function_table)
102 {
103 for (unsigned i = 0; function_table[i].name != NULL; i++) {
104 const int offset = (function_table[i].offset != -1)
105 ? function_table[i].offset
106 : _glapi_get_proc_offset(function_table[i].name);
107
108 ASSERT_NE(-1, offset)
109 << "Function: " << function_table[i].name;
110 ASSERT_EQ(offset,
111 _glapi_get_proc_offset(function_table[i].name))
112 << "Function: " << function_table[i].name;
113 EXPECT_NE((_glapi_proc) _mesa_generic_nop, table[offset])
114 << "Function: " << function_table[i].name
115 << " at offset " << offset;
116
117 table[offset] = (_glapi_proc) _mesa_generic_nop;
118 }
119
120 const unsigned size = _glapi_get_dispatch_table_size();
121 for (unsigned i = 0; i < size; i++) {
122 EXPECT_EQ((_glapi_proc) _mesa_generic_nop, table[i]) << "i = " << i;
123 }
124 }
125
126 TEST_F(DispatchSanity_test, GLES2)
127 {
128 ctx.Version = 20;
129 _mesa_initialize_context(&ctx,
130 API_OPENGLES2, //api,
131 &visual,
132 NULL, //&share_list,
133 &driver_functions);
134
135 _swrast_CreateContext(&ctx);
136 _vbo_CreateContext(&ctx);
137 _tnl_CreateContext(&ctx);
138 _swsetup_CreateContext(&ctx);
139
140 validate_functions((_glapi_proc *) ctx.Exec, gles2_functions_possible);
141 }
142
143 const struct function gles2_functions_possible[] = {
144 { "glActiveTexture", _gloffset_ActiveTextureARB },
145 { "glAttachShader", -1 },
146 { "glBindAttribLocation", -1 },
147 { "glBindBuffer", -1 },
148 { "glBindFramebuffer", -1 },
149 { "glBindRenderbuffer", -1 },
150 { "glBindTexture", _gloffset_BindTexture },
151 { "glBindVertexArrayOES", -1 },
152 { "glBlendColor", _gloffset_BlendColor },
153 { "glBlendEquation", _gloffset_BlendEquation },
154 { "glBlendEquationSeparate", -1 },
155 { "glBlendFunc", _gloffset_BlendFunc },
156 { "glBlendFuncSeparate", -1 },
157 { "glBufferData", -1 },
158 { "glBufferSubData", -1 },
159 { "glCheckFramebufferStatus", -1 },
160 { "glClear", _gloffset_Clear },
161 { "glClearColor", _gloffset_ClearColor },
162 { "glClearDepthf", -1 },
163 { "glClearStencil", _gloffset_ClearStencil },
164 { "glColorMask", _gloffset_ColorMask },
165 { "glCompileShader", -1 },
166 { "glCompressedTexImage2D", -1 },
167 { "glCompressedTexImage3DOES", -1 },
168 { "glCompressedTexSubImage2D", -1 },
169 { "glCompressedTexSubImage3DOES", -1 },
170 { "glCopyTexImage2D", _gloffset_CopyTexImage2D },
171 { "glCopyTexSubImage2D", _gloffset_CopyTexSubImage2D },
172 { "glCopyTexSubImage3DOES", _gloffset_CopyTexSubImage3D },
173 { "glCreateProgram", -1 },
174 { "glCreateShader", -1 },
175 { "glCullFace", _gloffset_CullFace },
176 { "glDeleteBuffers", -1 },
177 { "glDeleteFramebuffers", -1 },
178 { "glDeleteProgram", -1 },
179 { "glDeleteRenderbuffers", -1 },
180 { "glDeleteShader", -1 },
181 { "glDeleteTextures", _gloffset_DeleteTextures },
182 { "glDeleteVertexArraysOES", -1 },
183 { "glDepthFunc", _gloffset_DepthFunc },
184 { "glDepthMask", _gloffset_DepthMask },
185 { "glDepthRangef", -1 },
186 { "glDetachShader", -1 },
187 { "glDisable", _gloffset_Disable },
188 { "glDisableVertexAttribArray", -1 },
189 { "glDrawArrays", _gloffset_DrawArrays },
190 { "glDrawBuffersNV", -1 },
191 { "glDrawElements", _gloffset_DrawElements },
192 { "glEGLImageTargetRenderbufferStorageOES", -1 },
193 { "glEGLImageTargetTexture2DOES", -1 },
194 { "glEnable", _gloffset_Enable },
195 { "glEnableVertexAttribArray", -1 },
196 { "glFinish", _gloffset_Finish },
197 { "glFlush", _gloffset_Flush },
198 { "glFlushMappedBufferRangeEXT", -1 },
199 { "glFramebufferRenderbuffer", -1 },
200 { "glFramebufferTexture2D", -1 },
201 { "glFramebufferTexture3DOES", -1 },
202 { "glFrontFace", _gloffset_FrontFace },
203 { "glGenBuffers", -1 },
204 { "glGenFramebuffers", -1 },
205 { "glGenRenderbuffers", -1 },
206 { "glGenTextures", _gloffset_GenTextures },
207 { "glGenVertexArraysOES", -1 },
208 { "glGenerateMipmap", -1 },
209 { "glGetActiveAttrib", -1 },
210 { "glGetActiveUniform", -1 },
211 { "glGetAttachedShaders", -1 },
212 { "glGetAttribLocation", -1 },
213 { "glGetBooleanv", _gloffset_GetBooleanv },
214 { "glGetBufferParameteriv", -1 },
215 { "glGetBufferPointervOES", -1 },
216 { "glGetError", _gloffset_GetError },
217 { "glGetFloatv", _gloffset_GetFloatv },
218 { "glGetFramebufferAttachmentParameteriv", -1 },
219 { "glGetIntegerv", _gloffset_GetIntegerv },
220 { "glGetProgramInfoLog", -1 },
221 { "glGetProgramiv", -1 },
222 { "glGetRenderbufferParameteriv", -1 },
223 { "glGetShaderInfoLog", -1 },
224 { "glGetShaderPrecisionFormat", -1 },
225 { "glGetShaderSource", -1 },
226 { "glGetShaderiv", -1 },
227 { "glGetString", _gloffset_GetString },
228 { "glGetTexParameterfv", _gloffset_GetTexParameterfv },
229 { "glGetTexParameteriv", _gloffset_GetTexParameteriv },
230 { "glGetUniformLocation", -1 },
231 { "glGetUniformfv", -1 },
232 { "glGetUniformiv", -1 },
233 { "glGetVertexAttribPointerv", -1 },
234 { "glGetVertexAttribfv", -1 },
235 { "glGetVertexAttribiv", -1 },
236 { "glHint", _gloffset_Hint },
237 { "glIsBuffer", -1 },
238 { "glIsEnabled", _gloffset_IsEnabled },
239 { "glIsFramebuffer", -1 },
240 { "glIsProgram", -1 },
241 { "glIsRenderbuffer", -1 },
242 { "glIsShader", -1 },
243 { "glIsTexture", _gloffset_IsTexture },
244 { "glIsVertexArrayOES", -1 },
245 { "glLineWidth", _gloffset_LineWidth },
246 { "glLinkProgram", -1 },
247 { "glMapBufferOES", -1 },
248 { "glMapBufferRangeEXT", -1 },
249 { "glMultiDrawArraysEXT", -1 },
250 { "glMultiDrawElementsEXT", -1 },
251 { "glPixelStorei", _gloffset_PixelStorei },
252 { "glPolygonOffset", _gloffset_PolygonOffset },
253 { "glReadBufferNV", _gloffset_ReadBuffer },
254 { "glReadPixels", _gloffset_ReadPixels },
255 { "glReleaseShaderCompiler", -1 },
256 { "glRenderbufferStorage", -1 },
257 { "glSampleCoverage", -1 },
258 { "glScissor", _gloffset_Scissor },
259 { "glShaderBinary", -1 },
260 { "glShaderSource", -1 },
261 { "glStencilFunc", _gloffset_StencilFunc },
262 { "glStencilFuncSeparate", -1 },
263 { "glStencilMask", _gloffset_StencilMask },
264 { "glStencilMaskSeparate", -1 },
265 { "glStencilOp", _gloffset_StencilOp },
266 { "glStencilOpSeparate", -1 },
267 { "glTexImage2D", _gloffset_TexImage2D },
268 { "glTexImage3DOES", _gloffset_TexImage3D },
269 { "glTexParameterf", _gloffset_TexParameterf },
270 { "glTexParameterfv", _gloffset_TexParameterfv },
271 { "glTexParameteri", _gloffset_TexParameteri },
272 { "glTexParameteriv", _gloffset_TexParameteriv },
273 { "glTexSubImage2D", _gloffset_TexSubImage2D },
274 { "glTexSubImage3DOES", _gloffset_TexSubImage3D },
275 { "glUniform1f", -1 },
276 { "glUniform1fv", -1 },
277 { "glUniform1i", -1 },
278 { "glUniform1iv", -1 },
279 { "glUniform2f", -1 },
280 { "glUniform2fv", -1 },
281 { "glUniform2i", -1 },
282 { "glUniform2iv", -1 },
283 { "glUniform3f", -1 },
284 { "glUniform3fv", -1 },
285 { "glUniform3i", -1 },
286 { "glUniform3iv", -1 },
287 { "glUniform4f", -1 },
288 { "glUniform4fv", -1 },
289 { "glUniform4i", -1 },
290 { "glUniform4iv", -1 },
291 { "glUniformMatrix2fv", -1 },
292 { "glUniformMatrix3fv", -1 },
293 { "glUniformMatrix4fv", -1 },
294 { "glUnmapBufferOES", -1 },
295 { "glUseProgram", -1 },
296 { "glValidateProgram", -1 },
297 { "glVertexAttrib1f", -1 },
298 { "glVertexAttrib1fv", -1 },
299 { "glVertexAttrib2f", -1 },
300 { "glVertexAttrib2fv", -1 },
301 { "glVertexAttrib3f", -1 },
302 { "glVertexAttrib3fv", -1 },
303 { "glVertexAttrib4f", -1 },
304 { "glVertexAttrib4fv", -1 },
305 { "glVertexAttribPointer", -1 },
306 { "glViewport", _gloffset_Viewport },
307 { NULL, -1 }
308 };
309
310 #endif /* FEATURE_ES2 */