• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 2018 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 // validationES2.h:
7 //  Inlined validation functions for OpenGL ES 2.0 entry points.
8 
9 #ifndef LIBANGLE_VALIDATION_ES2_H_
10 #define LIBANGLE_VALIDATION_ES2_H_
11 
12 #include "libANGLE/ErrorStrings.h"
13 #include "libANGLE/validationES.h"
14 #include "libANGLE/validationES2_autogen.h"
15 
16 namespace gl
17 {
ValidateDrawArrays(const Context * context,angle::EntryPoint entryPoint,PrimitiveMode mode,GLint first,GLsizei count)18 ANGLE_INLINE bool ValidateDrawArrays(const Context *context,
19                                      angle::EntryPoint entryPoint,
20                                      PrimitiveMode mode,
21                                      GLint first,
22                                      GLsizei count)
23 {
24     return ValidateDrawArraysCommon(context, entryPoint, mode, first, count, 1);
25 }
26 
ValidateUniform1f(const Context * context,angle::EntryPoint entryPoint,UniformLocation location,GLfloat x)27 ANGLE_INLINE bool ValidateUniform1f(const Context *context,
28                                     angle::EntryPoint entryPoint,
29                                     UniformLocation location,
30                                     GLfloat x)
31 {
32     return ValidateUniform(context, entryPoint, GL_FLOAT, location, 1);
33 }
34 
ValidateUniform1fv(const Context * context,angle::EntryPoint entryPoint,UniformLocation location,GLsizei count,const GLfloat * v)35 ANGLE_INLINE bool ValidateUniform1fv(const Context *context,
36                                      angle::EntryPoint entryPoint,
37                                      UniformLocation location,
38                                      GLsizei count,
39                                      const GLfloat *v)
40 {
41     return ValidateUniform(context, entryPoint, GL_FLOAT, location, count);
42 }
43 
ValidateUniform1i(const Context * context,angle::EntryPoint entryPoint,UniformLocation location,GLint x)44 ANGLE_INLINE bool ValidateUniform1i(const Context *context,
45                                     angle::EntryPoint entryPoint,
46                                     UniformLocation location,
47                                     GLint x)
48 {
49     return ValidateUniform1iv(context, entryPoint, location, 1, &x);
50 }
51 
ValidateUniform2f(const Context * context,angle::EntryPoint entryPoint,UniformLocation location,GLfloat x,GLfloat y)52 ANGLE_INLINE bool ValidateUniform2f(const Context *context,
53                                     angle::EntryPoint entryPoint,
54                                     UniformLocation location,
55                                     GLfloat x,
56                                     GLfloat y)
57 {
58     return ValidateUniform(context, entryPoint, GL_FLOAT_VEC2, location, 1);
59 }
60 
ValidateUniform2fv(const Context * context,angle::EntryPoint entryPoint,UniformLocation location,GLsizei count,const GLfloat * v)61 ANGLE_INLINE bool ValidateUniform2fv(const Context *context,
62                                      angle::EntryPoint entryPoint,
63                                      UniformLocation location,
64                                      GLsizei count,
65                                      const GLfloat *v)
66 {
67     return ValidateUniform(context, entryPoint, GL_FLOAT_VEC2, location, count);
68 }
69 
ValidateUniform2i(const Context * context,angle::EntryPoint entryPoint,UniformLocation location,GLint x,GLint y)70 ANGLE_INLINE bool ValidateUniform2i(const Context *context,
71                                     angle::EntryPoint entryPoint,
72                                     UniformLocation location,
73                                     GLint x,
74                                     GLint y)
75 {
76     return ValidateUniform(context, entryPoint, GL_INT_VEC2, location, 1);
77 }
78 
ValidateUniform2iv(const Context * context,angle::EntryPoint entryPoint,UniformLocation location,GLsizei count,const GLint * v)79 ANGLE_INLINE bool ValidateUniform2iv(const Context *context,
80                                      angle::EntryPoint entryPoint,
81                                      UniformLocation location,
82                                      GLsizei count,
83                                      const GLint *v)
84 {
85     return ValidateUniform(context, entryPoint, GL_INT_VEC2, location, count);
86 }
87 
ValidateUniform3f(const Context * context,angle::EntryPoint entryPoint,UniformLocation location,GLfloat x,GLfloat y,GLfloat z)88 ANGLE_INLINE bool ValidateUniform3f(const Context *context,
89                                     angle::EntryPoint entryPoint,
90                                     UniformLocation location,
91                                     GLfloat x,
92                                     GLfloat y,
93                                     GLfloat z)
94 {
95     return ValidateUniform(context, entryPoint, GL_FLOAT_VEC3, location, 1);
96 }
97 
ValidateUniform3fv(const Context * context,angle::EntryPoint entryPoint,UniformLocation location,GLsizei count,const GLfloat * v)98 ANGLE_INLINE bool ValidateUniform3fv(const Context *context,
99                                      angle::EntryPoint entryPoint,
100                                      UniformLocation location,
101                                      GLsizei count,
102                                      const GLfloat *v)
103 {
104     return ValidateUniform(context, entryPoint, GL_FLOAT_VEC3, location, count);
105 }
106 
ValidateUniform3i(const Context * context,angle::EntryPoint entryPoint,UniformLocation location,GLint x,GLint y,GLint z)107 ANGLE_INLINE bool ValidateUniform3i(const Context *context,
108                                     angle::EntryPoint entryPoint,
109                                     UniformLocation location,
110                                     GLint x,
111                                     GLint y,
112                                     GLint z)
113 {
114     return ValidateUniform(context, entryPoint, GL_INT_VEC3, location, 1);
115 }
116 
ValidateUniform3iv(const Context * context,angle::EntryPoint entryPoint,UniformLocation location,GLsizei count,const GLint * v)117 ANGLE_INLINE bool ValidateUniform3iv(const Context *context,
118                                      angle::EntryPoint entryPoint,
119                                      UniformLocation location,
120                                      GLsizei count,
121                                      const GLint *v)
122 {
123     return ValidateUniform(context, entryPoint, GL_INT_VEC3, location, count);
124 }
125 
ValidateUniform4f(const Context * context,angle::EntryPoint entryPoint,UniformLocation location,GLfloat x,GLfloat y,GLfloat z,GLfloat w)126 ANGLE_INLINE bool ValidateUniform4f(const Context *context,
127                                     angle::EntryPoint entryPoint,
128                                     UniformLocation location,
129                                     GLfloat x,
130                                     GLfloat y,
131                                     GLfloat z,
132                                     GLfloat w)
133 {
134     return ValidateUniform(context, entryPoint, GL_FLOAT_VEC4, location, 1);
135 }
136 
ValidateUniform4fv(const Context * context,angle::EntryPoint entryPoint,UniformLocation location,GLsizei count,const GLfloat * v)137 ANGLE_INLINE bool ValidateUniform4fv(const Context *context,
138                                      angle::EntryPoint entryPoint,
139                                      UniformLocation location,
140                                      GLsizei count,
141                                      const GLfloat *v)
142 {
143     return ValidateUniform(context, entryPoint, GL_FLOAT_VEC4, location, count);
144 }
145 
ValidateUniform4i(const Context * context,angle::EntryPoint entryPoint,UniformLocation location,GLint x,GLint y,GLint z,GLint w)146 ANGLE_INLINE bool ValidateUniform4i(const Context *context,
147                                     angle::EntryPoint entryPoint,
148                                     UniformLocation location,
149                                     GLint x,
150                                     GLint y,
151                                     GLint z,
152                                     GLint w)
153 {
154     return ValidateUniform(context, entryPoint, GL_INT_VEC4, location, 1);
155 }
156 
ValidateUniform4iv(const Context * context,angle::EntryPoint entryPoint,UniformLocation location,GLsizei count,const GLint * v)157 ANGLE_INLINE bool ValidateUniform4iv(const Context *context,
158                                      angle::EntryPoint entryPoint,
159                                      UniformLocation location,
160                                      GLsizei count,
161                                      const GLint *v)
162 {
163     return ValidateUniform(context, entryPoint, GL_INT_VEC4, location, count);
164 }
165 
ValidateUniformMatrix2fv(const Context * context,angle::EntryPoint entryPoint,UniformLocation location,GLsizei count,GLboolean transpose,const GLfloat * value)166 ANGLE_INLINE bool ValidateUniformMatrix2fv(const Context *context,
167                                            angle::EntryPoint entryPoint,
168                                            UniformLocation location,
169                                            GLsizei count,
170                                            GLboolean transpose,
171                                            const GLfloat *value)
172 {
173     return ValidateUniformMatrix(context, entryPoint, GL_FLOAT_MAT2, location, count, transpose);
174 }
175 
ValidateUniformMatrix3fv(const Context * context,angle::EntryPoint entryPoint,UniformLocation location,GLsizei count,GLboolean transpose,const GLfloat * value)176 ANGLE_INLINE bool ValidateUniformMatrix3fv(const Context *context,
177                                            angle::EntryPoint entryPoint,
178                                            UniformLocation location,
179                                            GLsizei count,
180                                            GLboolean transpose,
181                                            const GLfloat *value)
182 {
183     return ValidateUniformMatrix(context, entryPoint, GL_FLOAT_MAT3, location, count, transpose);
184 }
185 
ValidateUniformMatrix4fv(const Context * context,angle::EntryPoint entryPoint,UniformLocation location,GLsizei count,GLboolean transpose,const GLfloat * value)186 ANGLE_INLINE bool ValidateUniformMatrix4fv(const Context *context,
187                                            angle::EntryPoint entryPoint,
188                                            UniformLocation location,
189                                            GLsizei count,
190                                            GLboolean transpose,
191                                            const GLfloat *value)
192 {
193     return ValidateUniformMatrix(context, entryPoint, GL_FLOAT_MAT4, location, count, transpose);
194 }
195 
ValidateVertexAttrib1f(const PrivateState & state,ErrorSet * errors,angle::EntryPoint entryPoint,GLuint index,GLfloat x)196 ANGLE_INLINE bool ValidateVertexAttrib1f(const PrivateState &state,
197                                          ErrorSet *errors,
198                                          angle::EntryPoint entryPoint,
199                                          GLuint index,
200                                          GLfloat x)
201 {
202     return ValidateVertexAttribIndex(state, errors, entryPoint, index);
203 }
204 
ValidateVertexAttrib1fv(const PrivateState & state,ErrorSet * errors,angle::EntryPoint entryPoint,GLuint index,const GLfloat * values)205 ANGLE_INLINE bool ValidateVertexAttrib1fv(const PrivateState &state,
206                                           ErrorSet *errors,
207                                           angle::EntryPoint entryPoint,
208                                           GLuint index,
209                                           const GLfloat *values)
210 {
211     if (values == nullptr)
212     {
213         errors->validationError(entryPoint, GL_INVALID_VALUE, err::kVertexAttributeValueNULL);
214         return false;
215     }
216 
217     return ValidateVertexAttribIndex(state, errors, entryPoint, index);
218 }
219 
ValidateVertexAttrib2f(const PrivateState & state,ErrorSet * errors,angle::EntryPoint entryPoint,GLuint index,GLfloat x,GLfloat y)220 ANGLE_INLINE bool ValidateVertexAttrib2f(const PrivateState &state,
221                                          ErrorSet *errors,
222                                          angle::EntryPoint entryPoint,
223                                          GLuint index,
224                                          GLfloat x,
225                                          GLfloat y)
226 {
227     return ValidateVertexAttribIndex(state, errors, entryPoint, index);
228 }
229 
ValidateVertexAttrib2fv(const PrivateState & state,ErrorSet * errors,angle::EntryPoint entryPoint,GLuint index,const GLfloat * values)230 ANGLE_INLINE bool ValidateVertexAttrib2fv(const PrivateState &state,
231                                           ErrorSet *errors,
232                                           angle::EntryPoint entryPoint,
233                                           GLuint index,
234                                           const GLfloat *values)
235 {
236     if (values == nullptr)
237     {
238         errors->validationError(entryPoint, GL_INVALID_VALUE, err::kVertexAttributeValueNULL);
239         return false;
240     }
241 
242     return ValidateVertexAttribIndex(state, errors, entryPoint, index);
243 }
244 
ValidateVertexAttrib3f(const PrivateState & state,ErrorSet * errors,angle::EntryPoint entryPoint,GLuint index,GLfloat x,GLfloat y,GLfloat z)245 ANGLE_INLINE bool ValidateVertexAttrib3f(const PrivateState &state,
246                                          ErrorSet *errors,
247                                          angle::EntryPoint entryPoint,
248                                          GLuint index,
249                                          GLfloat x,
250                                          GLfloat y,
251                                          GLfloat z)
252 {
253     return ValidateVertexAttribIndex(state, errors, entryPoint, index);
254 }
255 
ValidateVertexAttrib3fv(const PrivateState & state,ErrorSet * errors,angle::EntryPoint entryPoint,GLuint index,const GLfloat * values)256 ANGLE_INLINE bool ValidateVertexAttrib3fv(const PrivateState &state,
257                                           ErrorSet *errors,
258                                           angle::EntryPoint entryPoint,
259                                           GLuint index,
260                                           const GLfloat *values)
261 {
262     if (values == nullptr)
263     {
264         errors->validationError(entryPoint, GL_INVALID_VALUE, err::kVertexAttributeValueNULL);
265         return false;
266     }
267 
268     return ValidateVertexAttribIndex(state, errors, entryPoint, index);
269 }
270 
ValidateVertexAttrib4f(const PrivateState & state,ErrorSet * errors,angle::EntryPoint entryPoint,GLuint index,GLfloat x,GLfloat y,GLfloat z,GLfloat w)271 ANGLE_INLINE bool ValidateVertexAttrib4f(const PrivateState &state,
272                                          ErrorSet *errors,
273                                          angle::EntryPoint entryPoint,
274                                          GLuint index,
275                                          GLfloat x,
276                                          GLfloat y,
277                                          GLfloat z,
278                                          GLfloat w)
279 {
280     return ValidateVertexAttribIndex(state, errors, entryPoint, index);
281 }
282 
ValidateVertexAttrib4fv(const PrivateState & state,ErrorSet * errors,angle::EntryPoint entryPoint,GLuint index,const GLfloat * values)283 ANGLE_INLINE bool ValidateVertexAttrib4fv(const PrivateState &state,
284                                           ErrorSet *errors,
285                                           angle::EntryPoint entryPoint,
286                                           GLuint index,
287                                           const GLfloat *values)
288 {
289     if (values == nullptr)
290     {
291         errors->validationError(entryPoint, GL_INVALID_VALUE, err::kVertexAttributeValueNULL);
292         return false;
293     }
294 
295     return ValidateVertexAttribIndex(state, errors, entryPoint, index);
296 }
297 
ValidateGenBuffers(const Context * context,angle::EntryPoint entryPoint,GLint n,const BufferID * buffers)298 ANGLE_INLINE bool ValidateGenBuffers(const Context *context,
299                                      angle::EntryPoint entryPoint,
300                                      GLint n,
301                                      const BufferID *buffers)
302 {
303     return ValidateGenOrDelete(context, entryPoint, n, buffers);
304 }
305 
ValidateGenFramebuffers(const Context * context,angle::EntryPoint entryPoint,GLint n,const FramebufferID * framebuffers)306 ANGLE_INLINE bool ValidateGenFramebuffers(const Context *context,
307                                           angle::EntryPoint entryPoint,
308                                           GLint n,
309                                           const FramebufferID *framebuffers)
310 {
311     return ValidateGenOrDelete(context, entryPoint, n, framebuffers);
312 }
313 
ValidateGenRenderbuffers(const Context * context,angle::EntryPoint entryPoint,GLint n,const RenderbufferID * renderbuffers)314 ANGLE_INLINE bool ValidateGenRenderbuffers(const Context *context,
315                                            angle::EntryPoint entryPoint,
316                                            GLint n,
317                                            const RenderbufferID *renderbuffers)
318 {
319     return ValidateGenOrDelete(context, entryPoint, n, renderbuffers);
320 }
321 
ValidateGenTextures(const Context * context,angle::EntryPoint entryPoint,GLint n,const TextureID * textures)322 ANGLE_INLINE bool ValidateGenTextures(const Context *context,
323                                       angle::EntryPoint entryPoint,
324                                       GLint n,
325                                       const TextureID *textures)
326 {
327     return ValidateGenOrDelete(context, entryPoint, n, textures);
328 }
329 
ValidateGenerateMipmap(const Context * context,angle::EntryPoint entryPoint,TextureType target)330 ANGLE_INLINE bool ValidateGenerateMipmap(const Context *context,
331                                          angle::EntryPoint entryPoint,
332                                          TextureType target)
333 {
334     return ValidateGenerateMipmapBase(context, entryPoint, target);
335 }
336 
ValidateGetBufferParameteriv(const Context * context,angle::EntryPoint entryPoint,BufferBinding target,GLenum pname,const GLint * params)337 ANGLE_INLINE bool ValidateGetBufferParameteriv(const Context *context,
338                                                angle::EntryPoint entryPoint,
339                                                BufferBinding target,
340                                                GLenum pname,
341                                                const GLint *params)
342 {
343     return ValidateGetBufferParameterBase(context, entryPoint, target, pname, false, nullptr);
344 }
345 
ValidateGetRenderbufferParameteriv(const Context * context,angle::EntryPoint entryPoint,GLenum target,GLenum pname,const GLint * params)346 ANGLE_INLINE bool ValidateGetRenderbufferParameteriv(const Context *context,
347                                                      angle::EntryPoint entryPoint,
348                                                      GLenum target,
349                                                      GLenum pname,
350                                                      const GLint *params)
351 {
352     return ValidateGetRenderbufferParameterivBase(context, entryPoint, target, pname, nullptr);
353 }
354 
ValidateGetShaderiv(const Context * context,angle::EntryPoint entryPoint,ShaderProgramID shader,GLenum pname,const GLint * params)355 ANGLE_INLINE bool ValidateGetShaderiv(const Context *context,
356                                       angle::EntryPoint entryPoint,
357                                       ShaderProgramID shader,
358                                       GLenum pname,
359                                       const GLint *params)
360 {
361     if (params == nullptr)
362     {
363         ANGLE_VALIDATION_ERROR(GL_INVALID_VALUE, err::kPLSParamsNULL);
364         return false;
365     }
366 
367     return ValidateGetShaderivBase(context, entryPoint, shader, pname, nullptr);
368 }
369 
ValidateGetTexParameterfv(const Context * context,angle::EntryPoint entryPoint,TextureType target,GLenum pname,const GLfloat * params)370 ANGLE_INLINE bool ValidateGetTexParameterfv(const Context *context,
371                                             angle::EntryPoint entryPoint,
372                                             TextureType target,
373                                             GLenum pname,
374                                             const GLfloat *params)
375 {
376     return ValidateGetTexParameterBase(context, entryPoint, target, pname, nullptr);
377 }
378 
ValidateGetTexParameteriv(const Context * context,angle::EntryPoint entryPoint,TextureType target,GLenum pname,const GLint * params)379 ANGLE_INLINE bool ValidateGetTexParameteriv(const Context *context,
380                                             angle::EntryPoint entryPoint,
381                                             TextureType target,
382                                             GLenum pname,
383                                             const GLint *params)
384 {
385     return ValidateGetTexParameterBase(context, entryPoint, target, pname, nullptr);
386 }
387 
ValidateGetUniformfv(const Context * context,angle::EntryPoint entryPoint,ShaderProgramID program,UniformLocation location,const GLfloat * params)388 ANGLE_INLINE bool ValidateGetUniformfv(const Context *context,
389                                        angle::EntryPoint entryPoint,
390                                        ShaderProgramID program,
391                                        UniformLocation location,
392                                        const GLfloat *params)
393 {
394     return ValidateGetUniformBase(context, entryPoint, program, location);
395 }
396 
ValidateGetUniformiv(const Context * context,angle::EntryPoint entryPoint,ShaderProgramID program,UniformLocation location,const GLint * params)397 ANGLE_INLINE bool ValidateGetUniformiv(const Context *context,
398                                        angle::EntryPoint entryPoint,
399                                        ShaderProgramID program,
400                                        UniformLocation location,
401                                        const GLint *params)
402 {
403     return ValidateGetUniformBase(context, entryPoint, program, location);
404 }
405 
ValidateGetVertexAttribfv(const Context * context,angle::EntryPoint entryPoint,GLuint index,GLenum pname,const GLfloat * params)406 ANGLE_INLINE bool ValidateGetVertexAttribfv(const Context *context,
407                                             angle::EntryPoint entryPoint,
408                                             GLuint index,
409                                             GLenum pname,
410                                             const GLfloat *params)
411 {
412     return ValidateGetVertexAttribBase(context, entryPoint, index, pname, nullptr, false, false);
413 }
414 
ValidateGetVertexAttribiv(const Context * context,angle::EntryPoint entryPoint,GLuint index,GLenum pname,const GLint * params)415 ANGLE_INLINE bool ValidateGetVertexAttribiv(const Context *context,
416                                             angle::EntryPoint entryPoint,
417                                             GLuint index,
418                                             GLenum pname,
419                                             const GLint *params)
420 {
421     return ValidateGetVertexAttribBase(context, entryPoint, index, pname, nullptr, false, false);
422 }
423 
ValidateGetVertexAttribPointerv(const Context * context,angle::EntryPoint entryPoint,GLuint index,GLenum pname,void * const * pointer)424 ANGLE_INLINE bool ValidateGetVertexAttribPointerv(const Context *context,
425                                                   angle::EntryPoint entryPoint,
426                                                   GLuint index,
427                                                   GLenum pname,
428                                                   void *const *pointer)
429 {
430     return ValidateGetVertexAttribBase(context, entryPoint, index, pname, nullptr, true, false);
431 }
432 
ValidateReadPixels(const Context * context,angle::EntryPoint entryPoint,GLint x,GLint y,GLsizei width,GLsizei height,GLenum format,GLenum type,const void * pixels)433 ANGLE_INLINE bool ValidateReadPixels(const Context *context,
434                                      angle::EntryPoint entryPoint,
435                                      GLint x,
436                                      GLint y,
437                                      GLsizei width,
438                                      GLsizei height,
439                                      GLenum format,
440                                      GLenum type,
441                                      const void *pixels)
442 {
443     return ValidateReadPixelsBase(context, entryPoint, x, y, width, height, format, type, -1,
444                                   nullptr, nullptr, nullptr, pixels);
445 }
446 
ValidateTexParameterf(const Context * context,angle::EntryPoint entryPoint,TextureType target,GLenum pname,GLfloat param)447 ANGLE_INLINE bool ValidateTexParameterf(const Context *context,
448                                         angle::EntryPoint entryPoint,
449                                         TextureType target,
450                                         GLenum pname,
451                                         GLfloat param)
452 {
453     return ValidateTexParameterBase(context, entryPoint, target, pname, -1, false, &param);
454 }
455 
ValidateTexParameterfv(const Context * context,angle::EntryPoint entryPoint,TextureType target,GLenum pname,const GLfloat * params)456 ANGLE_INLINE bool ValidateTexParameterfv(const Context *context,
457                                          angle::EntryPoint entryPoint,
458                                          TextureType target,
459                                          GLenum pname,
460                                          const GLfloat *params)
461 {
462     return ValidateTexParameterBase(context, entryPoint, target, pname, -1, true, params);
463 }
464 
ValidateTexParameteri(const Context * context,angle::EntryPoint entryPoint,TextureType target,GLenum pname,GLint param)465 ANGLE_INLINE bool ValidateTexParameteri(const Context *context,
466                                         angle::EntryPoint entryPoint,
467                                         TextureType target,
468                                         GLenum pname,
469                                         GLint param)
470 {
471     return ValidateTexParameterBase(context, entryPoint, target, pname, -1, false, &param);
472 }
473 
ValidateTexParameteriv(const Context * context,angle::EntryPoint entryPoint,TextureType target,GLenum pname,const GLint * params)474 ANGLE_INLINE bool ValidateTexParameteriv(const Context *context,
475                                          angle::EntryPoint entryPoint,
476                                          TextureType target,
477                                          GLenum pname,
478                                          const GLint *params)
479 {
480     return ValidateTexParameterBase(context, entryPoint, target, pname, -1, true, params);
481 }
482 
ValidateBindBuffer(const Context * context,angle::EntryPoint entryPoint,BufferBinding target,BufferID buffer)483 ANGLE_INLINE bool ValidateBindBuffer(const Context *context,
484                                      angle::EntryPoint entryPoint,
485                                      BufferBinding target,
486                                      BufferID buffer)
487 {
488     if (!context->isValidBufferBinding(target))
489     {
490         ANGLE_VALIDATION_ERROR(GL_INVALID_ENUM, err::kInvalidBufferTypes);
491         return false;
492     }
493 
494     if (!context->getState().isBindGeneratesResourceEnabled() &&
495         !context->isBufferGenerated(buffer))
496     {
497         ANGLE_VALIDATION_ERROR(GL_INVALID_OPERATION, err::kObjectNotGenerated);
498         return false;
499     }
500 
501     return true;
502 }
503 
ValidateDrawElements(const Context * context,angle::EntryPoint entryPoint,PrimitiveMode mode,GLsizei count,DrawElementsType type,const void * indices)504 ANGLE_INLINE bool ValidateDrawElements(const Context *context,
505                                        angle::EntryPoint entryPoint,
506                                        PrimitiveMode mode,
507                                        GLsizei count,
508                                        DrawElementsType type,
509                                        const void *indices)
510 {
511     return ValidateDrawElementsCommon(context, entryPoint, mode, count, type, indices, 1);
512 }
513 
ValidateVertexAttribPointer(const Context * context,angle::EntryPoint entryPoint,GLuint index,GLint size,VertexAttribType type,GLboolean normalized,GLsizei stride,const void * ptr)514 ANGLE_INLINE bool ValidateVertexAttribPointer(const Context *context,
515                                               angle::EntryPoint entryPoint,
516                                               GLuint index,
517                                               GLint size,
518                                               VertexAttribType type,
519                                               GLboolean normalized,
520                                               GLsizei stride,
521                                               const void *ptr)
522 {
523     if (!ValidateFloatVertexFormat(context, entryPoint, index, size, type))
524     {
525         return false;
526     }
527 
528     if (stride < 0)
529     {
530         ANGLE_VALIDATION_ERROR(GL_INVALID_VALUE, err::kNegativeStride);
531         return false;
532     }
533 
534     if (context->getClientVersion() >= ES_3_1)
535     {
536         const Caps &caps = context->getCaps();
537         if (stride > caps.maxVertexAttribStride)
538         {
539             ANGLE_VALIDATION_ERROR(GL_INVALID_VALUE, err::kExceedsMaxVertexAttribStride);
540             return false;
541         }
542 
543         if (index >= static_cast<GLuint>(caps.maxVertexAttribBindings))
544         {
545             ANGLE_VALIDATION_ERROR(GL_INVALID_VALUE, err::kExceedsMaxVertexAttribBindings);
546             return false;
547         }
548     }
549 
550     // [OpenGL ES 3.0.2] Section 2.8 page 24:
551     // An INVALID_OPERATION error is generated when a non-zero vertex array object
552     // is bound, zero is bound to the ARRAY_BUFFER buffer object binding point,
553     // and the pointer argument is not NULL.
554     bool nullBufferAllowed = context->getState().areClientArraysEnabled() &&
555                              context->getState().getVertexArray()->id().value == 0;
556     if (!nullBufferAllowed && context->getState().getTargetBuffer(BufferBinding::Array) == 0 &&
557         ptr != nullptr)
558     {
559         ANGLE_VALIDATION_ERROR(GL_INVALID_OPERATION, err::kClientDataInVertexArray);
560         return false;
561     }
562 
563     if (context->isWebGL())
564     {
565         // WebGL 1.0 [Section 6.14] Fixed point support
566         // The WebGL API does not support the GL_FIXED data type.
567         if (type == VertexAttribType::Fixed)
568         {
569             ANGLE_VALIDATION_ERROR(GL_INVALID_ENUM, err::kFixedNotInWebGL);
570             return false;
571         }
572 
573         if (!ValidateWebGLVertexAttribPointer(context, entryPoint, type, normalized, stride, ptr,
574                                               false))
575         {
576             return false;
577         }
578     }
579 
580     return true;
581 }
582 
583 void RecordBindTextureTypeError(const Context *context,
584                                 angle::EntryPoint entryPoint,
585                                 TextureType target);
586 
ValidateBindTexture(const Context * context,angle::EntryPoint entryPoint,TextureType target,TextureID texture)587 ANGLE_INLINE bool ValidateBindTexture(const Context *context,
588                                       angle::EntryPoint entryPoint,
589                                       TextureType target,
590                                       TextureID texture)
591 {
592     if (!context->getStateCache().isValidBindTextureType(target))
593     {
594         RecordBindTextureTypeError(context, entryPoint, target);
595         return false;
596     }
597 
598     if (texture.value == 0)
599     {
600         return true;
601     }
602 
603     Texture *textureObject = context->getTexture(texture);
604     if (textureObject && textureObject->getType() != target)
605     {
606         ANGLE_VALIDATION_ERRORF(GL_INVALID_OPERATION, err::kTextureTargetMismatchWithLabel,
607                                 static_cast<uint8_t>(target),
608                                 static_cast<uint8_t>(textureObject->getType()),
609                                 textureObject->getLabel().c_str());
610         return false;
611     }
612 
613     if (!context->getState().isBindGeneratesResourceEnabled() &&
614         !context->isTextureGenerated(texture))
615     {
616         ANGLE_VALIDATION_ERROR(GL_INVALID_OPERATION, err::kObjectNotGenerated);
617         return false;
618     }
619 
620     return true;
621 }
622 
623 // Validation of all Tex[Sub]Image2D parameters except TextureTarget.
624 bool ValidateES2TexImageParametersBase(const Context *context,
625                                        angle::EntryPoint entryPoint,
626                                        TextureTarget target,
627                                        GLint level,
628                                        GLenum internalformat,
629                                        bool isCompressed,
630                                        bool isSubImage,
631                                        GLint xoffset,
632                                        GLint yoffset,
633                                        GLsizei width,
634                                        GLsizei height,
635                                        GLint border,
636                                        GLenum format,
637                                        GLenum type,
638                                        GLsizei imageSize,
639                                        const void *pixels);
640 
641 // Validation of TexStorage*2DEXT
642 bool ValidateES2TexStorageParametersBase(const Context *context,
643                                          angle::EntryPoint entryPoint,
644                                          TextureType target,
645                                          GLsizei levels,
646                                          GLenum internalformat,
647                                          GLsizei width,
648                                          GLsizei height);
649 
650 // Validation of [Push,Pop]DebugGroup
651 bool ValidatePushDebugGroupBase(const Context *context,
652                                 angle::EntryPoint entryPoint,
653                                 GLenum source,
654                                 GLuint id,
655                                 GLsizei length,
656                                 const GLchar *message);
657 bool ValidatePopDebugGroupBase(const Context *context, angle::EntryPoint entryPoint);
658 
659 bool ValidateDebugMessageControlBase(const Context *context,
660                                      angle::EntryPoint entryPoint,
661                                      GLenum source,
662                                      GLenum type,
663                                      GLenum severity,
664                                      GLsizei count,
665                                      const GLuint *ids);
666 
667 bool ValidateDebugMessageInsertBase(const Context *context,
668                                     angle::EntryPoint entryPoint,
669                                     GLenum source,
670                                     GLenum type,
671                                     GLuint id,
672                                     GLenum severity,
673                                     GLsizei length,
674                                     const GLchar *buf);
675 
676 // Validation of ObjectLabel
677 bool ValidateObjectLabelBase(const Context *context,
678                              angle::EntryPoint entryPoint,
679                              GLenum identifier,
680                              GLuint name,
681                              GLsizei length,
682                              const GLchar *label);
683 
684 // Validation of GetObjectLabel
685 bool ValidateGetObjectLabelBase(const Context *context,
686                                 angle::EntryPoint entryPoint,
687                                 GLenum identifier,
688                                 GLuint name,
689                                 GLsizei bufSize,
690                                 const GLsizei *length,
691                                 const GLchar *label);
692 
693 // Validation of ObjectPtrLabel
694 bool ValidateObjectPtrLabelBase(const Context *context,
695                                 angle::EntryPoint entryPoint,
696                                 const void *ptr,
697                                 GLsizei length,
698                                 const GLchar *label);
699 
700 // Validation of GetObjectPtrLabel
701 bool ValidateGetObjectPtrLabelBase(const Context *context,
702                                    angle::EntryPoint entryPoint,
703                                    const void *ptr,
704                                    GLsizei bufSize,
705                                    const GLsizei *length,
706                                    const GLchar *label);
707 
708 }  // namespace gl
709 
710 #endif  // LIBANGLE_VALIDATION_ES2_H_
711