extensions: Add ES3-only extension support
[mesa.git] / src / mesa / main / api_validate.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 7.1
4 *
5 * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25 #include <stdbool.h>
26 #include "glheader.h"
27 #include "api_validate.h"
28 #include "bufferobj.h"
29 #include "context.h"
30 #include "imports.h"
31 #include "mfeatures.h"
32 #include "mtypes.h"
33 #include "enums.h"
34 #include "vbo/vbo.h"
35 #include "transformfeedback.h"
36 #include <stdbool.h>
37
38
39 /**
40 * \return number of bytes in array [count] of type.
41 */
42 static GLsizei
43 index_bytes(GLenum type, GLsizei count)
44 {
45 if (type == GL_UNSIGNED_INT) {
46 return count * sizeof(GLuint);
47 }
48 else if (type == GL_UNSIGNED_BYTE) {
49 return count * sizeof(GLubyte);
50 }
51 else {
52 ASSERT(type == GL_UNSIGNED_SHORT);
53 return count * sizeof(GLushort);
54 }
55 }
56
57
58 /**
59 * Find the max index in the given element/index buffer
60 */
61 GLuint
62 _mesa_max_buffer_index(struct gl_context *ctx, GLuint count, GLenum type,
63 const void *indices,
64 struct gl_buffer_object *elementBuf)
65 {
66 const GLubyte *map = NULL;
67 GLuint max = 0;
68 GLuint i;
69
70 if (_mesa_is_bufferobj(elementBuf)) {
71 /* elements are in a user-defined buffer object. need to map it */
72 map = ctx->Driver.MapBufferRange(ctx, 0, elementBuf->Size,
73 GL_MAP_READ_BIT, elementBuf);
74 /* Actual address is the sum of pointers */
75 indices = (const GLvoid *) ADD_POINTERS(map, (const GLubyte *) indices);
76 }
77
78 if (type == GL_UNSIGNED_INT) {
79 for (i = 0; i < count; i++)
80 if (((GLuint *) indices)[i] > max)
81 max = ((GLuint *) indices)[i];
82 }
83 else if (type == GL_UNSIGNED_SHORT) {
84 for (i = 0; i < count; i++)
85 if (((GLushort *) indices)[i] > max)
86 max = ((GLushort *) indices)[i];
87 }
88 else {
89 ASSERT(type == GL_UNSIGNED_BYTE);
90 for (i = 0; i < count; i++)
91 if (((GLubyte *) indices)[i] > max)
92 max = ((GLubyte *) indices)[i];
93 }
94
95 if (map) {
96 ctx->Driver.UnmapBuffer(ctx, elementBuf);
97 }
98
99 return max;
100 }
101
102
103 /**
104 * Check if OK to draw arrays/elements.
105 */
106 static GLboolean
107 check_valid_to_render(struct gl_context *ctx, const char *function)
108 {
109 if (!_mesa_valid_to_render(ctx, function)) {
110 return GL_FALSE;
111 }
112
113 switch (ctx->API) {
114 case API_OPENGLES2:
115 /* For ES2, we can draw if any vertex array is enabled (and we
116 * should always have a vertex program/shader). */
117 if (ctx->Array.ArrayObj->_Enabled == 0x0 || !ctx->VertexProgram._Current)
118 return GL_FALSE;
119 break;
120
121 case API_OPENGLES:
122 /* For OpenGL ES, only draw if we have vertex positions
123 */
124 if (!ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_POS].Enabled)
125 return GL_FALSE;
126 break;
127
128 case API_OPENGL_COMPAT:
129 case API_OPENGL_CORE:
130 {
131 const struct gl_shader_program *vsProg =
132 ctx->Shader.CurrentVertexProgram;
133 GLboolean haveVertexShader = (vsProg && vsProg->LinkStatus);
134 GLboolean haveVertexProgram = ctx->VertexProgram._Enabled;
135 if (haveVertexShader || haveVertexProgram) {
136 /* Draw regardless of whether or not we have any vertex arrays.
137 * (Ex: could draw a point using a constant vertex pos)
138 */
139 return GL_TRUE;
140 }
141 else {
142 /* Draw if we have vertex positions (GL_VERTEX_ARRAY or generic
143 * array [0]).
144 */
145 return (ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_POS].Enabled ||
146 ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_GENERIC0].Enabled);
147 }
148 }
149 break;
150
151 default:
152 assert(!"Invalid API value in check_valid_to_render()");
153 }
154
155 return GL_TRUE;
156 }
157
158
159 /**
160 * Do bounds checking on array element indexes. Check that the vertices
161 * pointed to by the indices don't lie outside buffer object bounds.
162 * \return GL_TRUE if OK, GL_FALSE if any indexed vertex goes is out of bounds
163 */
164 static GLboolean
165 check_index_bounds(struct gl_context *ctx, GLsizei count, GLenum type,
166 const GLvoid *indices, GLint basevertex)
167 {
168 struct _mesa_prim prim;
169 struct _mesa_index_buffer ib;
170 GLuint min, max;
171
172 /* Only the X Server needs to do this -- otherwise, accessing outside
173 * array/BO bounds allows application termination.
174 */
175 if (!ctx->Const.CheckArrayBounds)
176 return GL_TRUE;
177
178 memset(&prim, 0, sizeof(prim));
179 prim.count = count;
180
181 memset(&ib, 0, sizeof(ib));
182 ib.type = type;
183 ib.ptr = indices;
184 ib.obj = ctx->Array.ArrayObj->ElementArrayBufferObj;
185
186 vbo_get_minmax_indices(ctx, &prim, &ib, &min, &max, 1);
187
188 if ((int)(min + basevertex) < 0 ||
189 max + basevertex >= ctx->Array.ArrayObj->_MaxElement) {
190 /* the max element is out of bounds of one or more enabled arrays */
191 _mesa_warning(ctx, "glDrawElements() index=%u is out of bounds (max=%u)",
192 max, ctx->Array.ArrayObj->_MaxElement);
193 return GL_FALSE;
194 }
195
196 return GL_TRUE;
197 }
198
199
200 /**
201 * Is 'mode' a valid value for glBegin(), glDrawArrays(), glDrawElements(),
202 * etc? The set of legal values depends on whether geometry shaders/programs
203 * are supported.
204 */
205 GLboolean
206 _mesa_valid_prim_mode(struct gl_context *ctx, GLenum mode, const char *name)
207 {
208 bool valid_enum;
209
210 switch (mode) {
211 case GL_POINTS:
212 case GL_LINES:
213 case GL_LINE_LOOP:
214 case GL_LINE_STRIP:
215 case GL_TRIANGLES:
216 case GL_TRIANGLE_STRIP:
217 case GL_TRIANGLE_FAN:
218 valid_enum = true;
219 break;
220 case GL_QUADS:
221 case GL_QUAD_STRIP:
222 case GL_POLYGON:
223 valid_enum = (ctx->API == API_OPENGL_COMPAT);
224 break;
225 case GL_LINES_ADJACENCY:
226 case GL_LINE_STRIP_ADJACENCY:
227 case GL_TRIANGLES_ADJACENCY:
228 case GL_TRIANGLE_STRIP_ADJACENCY:
229 valid_enum = _mesa_is_desktop_gl(ctx)
230 && ctx->Extensions.ARB_geometry_shader4;
231 break;
232 default:
233 valid_enum = false;
234 break;
235 }
236
237 if (!valid_enum) {
238 _mesa_error(ctx, GL_INVALID_ENUM, "%s(mode=%x)", name, mode);
239 return GL_FALSE;
240 }
241
242 /* From the GL_EXT_transform_feedback spec:
243 *
244 * "The error INVALID_OPERATION is generated if Begin, or any command
245 * that performs an explicit Begin, is called when:
246 *
247 * * a geometry shader is not active and <mode> does not match the
248 * allowed begin modes for the current transform feedback state as
249 * given by table X.1.
250 *
251 * * a geometry shader is active and the output primitive type of the
252 * geometry shader does not match the allowed begin modes for the
253 * current transform feedback state as given by table X.1.
254 *
255 */
256 if (_mesa_is_xfb_active_and_unpaused(ctx)) {
257 GLboolean pass = GL_TRUE;
258
259 switch (mode) {
260 case GL_POINTS:
261 pass = ctx->TransformFeedback.Mode == GL_POINTS;
262 break;
263 case GL_LINES:
264 case GL_LINE_STRIP:
265 case GL_LINE_LOOP:
266 pass = ctx->TransformFeedback.Mode == GL_LINES;
267 break;
268 default:
269 pass = ctx->TransformFeedback.Mode == GL_TRIANGLES;
270 break;
271 }
272 if (!pass) {
273 _mesa_error(ctx, GL_INVALID_OPERATION,
274 "%s(mode=%s vs transform feedback %s)",
275 name,
276 _mesa_lookup_prim_by_nr(mode),
277 _mesa_lookup_prim_by_nr(ctx->TransformFeedback.Mode));
278 return GL_FALSE;
279 }
280 }
281
282 return GL_TRUE;
283 }
284
285 /**
286 * Verify that the element type is valid.
287 *
288 * Generates \c GL_INVALID_ENUM and returns \c false if it is not.
289 */
290 static bool
291 valid_elements_type(struct gl_context *ctx, GLenum type, const char *name)
292 {
293 switch (type) {
294 case GL_UNSIGNED_BYTE:
295 case GL_UNSIGNED_SHORT:
296 case GL_UNSIGNED_INT:
297 return true;
298
299 default:
300 _mesa_error(ctx, GL_INVALID_ENUM, "%s(type = %s)", name,
301 _mesa_lookup_enum_by_nr(type));
302 return false;
303 }
304 }
305
306 /**
307 * Error checking for glDrawElements(). Includes parameter checking
308 * and VBO bounds checking.
309 * \return GL_TRUE if OK to render, GL_FALSE if error found
310 */
311 GLboolean
312 _mesa_validate_DrawElements(struct gl_context *ctx,
313 GLenum mode, GLsizei count, GLenum type,
314 const GLvoid *indices, GLint basevertex)
315 {
316 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE);
317 FLUSH_CURRENT(ctx, 0);
318
319 /* From the GLES3 specification, section 2.14.2 (Transform Feedback
320 * Primitive Capture):
321 *
322 * The error INVALID_OPERATION is also generated by DrawElements,
323 * DrawElementsInstanced, and DrawRangeElements while transform feedback
324 * is active and not paused, regardless of mode.
325 */
326 if (_mesa_is_gles3(ctx) && _mesa_is_xfb_active_and_unpaused(ctx)) {
327 _mesa_error(ctx, GL_INVALID_OPERATION,
328 "glDrawElements(transform feedback active)");
329 return GL_FALSE;
330 }
331
332 if (count <= 0) {
333 if (count < 0)
334 _mesa_error(ctx, GL_INVALID_VALUE, "glDrawElements(count)" );
335 return GL_FALSE;
336 }
337
338 if (!_mesa_valid_prim_mode(ctx, mode, "glDrawElements")) {
339 return GL_FALSE;
340 }
341
342 if (!valid_elements_type(ctx, type, "glDrawElements"))
343 return GL_FALSE;
344
345 if (!check_valid_to_render(ctx, "glDrawElements"))
346 return GL_FALSE;
347
348 /* Vertex buffer object tests */
349 if (_mesa_is_bufferobj(ctx->Array.ArrayObj->ElementArrayBufferObj)) {
350 /* use indices in the buffer object */
351 /* make sure count doesn't go outside buffer bounds */
352 if (index_bytes(type, count) > ctx->Array.ArrayObj->ElementArrayBufferObj->Size) {
353 _mesa_warning(ctx, "glDrawElements index out of buffer bounds");
354 return GL_FALSE;
355 }
356 }
357 else {
358 /* not using a VBO */
359 if (!indices)
360 return GL_FALSE;
361 }
362
363 if (!check_index_bounds(ctx, count, type, indices, basevertex))
364 return GL_FALSE;
365
366 return GL_TRUE;
367 }
368
369
370 /**
371 * Error checking for glMultiDrawElements(). Includes parameter checking
372 * and VBO bounds checking.
373 * \return GL_TRUE if OK to render, GL_FALSE if error found
374 */
375 GLboolean
376 _mesa_validate_MultiDrawElements(struct gl_context *ctx,
377 GLenum mode, const GLsizei *count,
378 GLenum type, const GLvoid * const *indices,
379 GLuint primcount, const GLint *basevertex)
380 {
381 unsigned i;
382
383 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE);
384 FLUSH_CURRENT(ctx, 0);
385
386 for (i = 0; i < primcount; i++) {
387 if (count[i] <= 0) {
388 if (count[i] < 0)
389 _mesa_error(ctx, GL_INVALID_VALUE,
390 "glMultiDrawElements(count)" );
391 return GL_FALSE;
392 }
393 }
394
395 if (!_mesa_valid_prim_mode(ctx, mode, "glMultiDrawElements")) {
396 return GL_FALSE;
397 }
398
399 if (!valid_elements_type(ctx, type, "glMultiDrawElements"))
400 return GL_FALSE;
401
402 if (!check_valid_to_render(ctx, "glMultiDrawElements"))
403 return GL_FALSE;
404
405 /* Vertex buffer object tests */
406 if (_mesa_is_bufferobj(ctx->Array.ArrayObj->ElementArrayBufferObj)) {
407 /* use indices in the buffer object */
408 /* make sure count doesn't go outside buffer bounds */
409 for (i = 0; i < primcount; i++) {
410 if (index_bytes(type, count[i]) >
411 ctx->Array.ArrayObj->ElementArrayBufferObj->Size) {
412 _mesa_warning(ctx,
413 "glMultiDrawElements index out of buffer bounds");
414 return GL_FALSE;
415 }
416 }
417 }
418 else {
419 /* not using a VBO */
420 for (i = 0; i < primcount; i++) {
421 if (!indices[i])
422 return GL_FALSE;
423 }
424 }
425
426 for (i = 0; i < primcount; i++) {
427 if (!check_index_bounds(ctx, count[i], type, indices[i],
428 basevertex ? basevertex[i] : 0))
429 return GL_FALSE;
430 }
431
432 return GL_TRUE;
433 }
434
435
436 /**
437 * Error checking for glDrawRangeElements(). Includes parameter checking
438 * and VBO bounds checking.
439 * \return GL_TRUE if OK to render, GL_FALSE if error found
440 */
441 GLboolean
442 _mesa_validate_DrawRangeElements(struct gl_context *ctx, GLenum mode,
443 GLuint start, GLuint end,
444 GLsizei count, GLenum type,
445 const GLvoid *indices, GLint basevertex)
446 {
447 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE);
448 FLUSH_CURRENT(ctx, 0);
449
450 /* From the GLES3 specification, section 2.14.2 (Transform Feedback
451 * Primitive Capture):
452 *
453 * The error INVALID_OPERATION is also generated by DrawElements,
454 * DrawElementsInstanced, and DrawRangeElements while transform feedback
455 * is active and not paused, regardless of mode.
456 */
457 if (_mesa_is_gles3(ctx) && _mesa_is_xfb_active_and_unpaused(ctx)) {
458 _mesa_error(ctx, GL_INVALID_OPERATION,
459 "glDrawElements(transform feedback active)");
460 return GL_FALSE;
461 }
462
463 if (count <= 0) {
464 if (count < 0)
465 _mesa_error(ctx, GL_INVALID_VALUE, "glDrawRangeElements(count)" );
466 return GL_FALSE;
467 }
468
469 if (!_mesa_valid_prim_mode(ctx, mode, "glDrawRangeElements")) {
470 return GL_FALSE;
471 }
472
473 if (end < start) {
474 _mesa_error(ctx, GL_INVALID_VALUE, "glDrawRangeElements(end<start)");
475 return GL_FALSE;
476 }
477
478 if (!valid_elements_type(ctx, type, "glDrawRangeElements"))
479 return GL_FALSE;
480
481 if (!check_valid_to_render(ctx, "glDrawRangeElements"))
482 return GL_FALSE;
483
484 /* Vertex buffer object tests */
485 if (_mesa_is_bufferobj(ctx->Array.ArrayObj->ElementArrayBufferObj)) {
486 /* use indices in the buffer object */
487 /* make sure count doesn't go outside buffer bounds */
488 if (index_bytes(type, count) > ctx->Array.ArrayObj->ElementArrayBufferObj->Size) {
489 _mesa_warning(ctx, "glDrawRangeElements index out of buffer bounds");
490 return GL_FALSE;
491 }
492 }
493 else {
494 /* not using a VBO */
495 if (!indices)
496 return GL_FALSE;
497 }
498
499 if (!check_index_bounds(ctx, count, type, indices, basevertex))
500 return GL_FALSE;
501
502 return GL_TRUE;
503 }
504
505
506 /**
507 * Called from the tnl module to error check the function parameters and
508 * verify that we really can draw something.
509 * \return GL_TRUE if OK to render, GL_FALSE if error found
510 */
511 GLboolean
512 _mesa_validate_DrawArrays(struct gl_context *ctx,
513 GLenum mode, GLint start, GLsizei count)
514 {
515 struct gl_transform_feedback_object *xfb_obj
516 = ctx->TransformFeedback.CurrentObject;
517 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE);
518 FLUSH_CURRENT(ctx, 0);
519
520 if (count <= 0) {
521 if (count < 0)
522 _mesa_error(ctx, GL_INVALID_VALUE, "glDrawArrays(count)" );
523 return GL_FALSE;
524 }
525
526 if (!_mesa_valid_prim_mode(ctx, mode, "glDrawArrays")) {
527 return GL_FALSE;
528 }
529
530 if (!check_valid_to_render(ctx, "glDrawArrays"))
531 return GL_FALSE;
532
533 if (ctx->Const.CheckArrayBounds) {
534 if (start + count > (GLint) ctx->Array.ArrayObj->_MaxElement)
535 return GL_FALSE;
536 }
537
538 /* From the GLES3 specification, section 2.14.2 (Transform Feedback
539 * Primitive Capture):
540 *
541 * The error INVALID_OPERATION is generated by DrawArrays and
542 * DrawArraysInstanced if recording the vertices of a primitive to the
543 * buffer objects being used for transform feedback purposes would result
544 * in either exceeding the limits of any buffer object’s size, or in
545 * exceeding the end position offset + size − 1, as set by
546 * BindBufferRange.
547 *
548 * This is in contrast to the behaviour of desktop GL, where the extra
549 * primitives are silently dropped from the transform feedback buffer.
550 */
551 if (_mesa_is_gles3(ctx) && _mesa_is_xfb_active_and_unpaused(ctx)) {
552 size_t prim_count = vbo_count_tessellated_primitives(mode, count, 1);
553 if (xfb_obj->GlesRemainingPrims < prim_count) {
554 _mesa_error(ctx, GL_INVALID_OPERATION,
555 "glDrawArrays(exceeds transform feedback size)");
556 return GL_FALSE;
557 }
558 xfb_obj->GlesRemainingPrims -= prim_count;
559 }
560
561 return GL_TRUE;
562 }
563
564
565 GLboolean
566 _mesa_validate_DrawArraysInstanced(struct gl_context *ctx, GLenum mode, GLint first,
567 GLsizei count, GLsizei numInstances)
568 {
569 struct gl_transform_feedback_object *xfb_obj
570 = ctx->TransformFeedback.CurrentObject;
571 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE);
572 FLUSH_CURRENT(ctx, 0);
573
574 if (count <= 0) {
575 if (count < 0)
576 _mesa_error(ctx, GL_INVALID_VALUE,
577 "glDrawArraysInstanced(count=%d)", count);
578 return GL_FALSE;
579 }
580
581 if (first < 0) {
582 _mesa_error(ctx, GL_INVALID_VALUE,
583 "glDrawArraysInstanced(start=%d)", first);
584 return GL_FALSE;
585 }
586
587 if (!_mesa_valid_prim_mode(ctx, mode, "glDrawArraysInstanced")) {
588 return GL_FALSE;
589 }
590
591 if (numInstances <= 0) {
592 if (numInstances < 0)
593 _mesa_error(ctx, GL_INVALID_VALUE,
594 "glDrawArraysInstanced(numInstances=%d)", numInstances);
595 return GL_FALSE;
596 }
597
598 if (!check_valid_to_render(ctx, "glDrawArraysInstanced(invalid to render)"))
599 return GL_FALSE;
600
601 if (ctx->Const.CheckArrayBounds) {
602 if (first + count > (GLint) ctx->Array.ArrayObj->_MaxElement)
603 return GL_FALSE;
604 }
605
606 /* From the GLES3 specification, section 2.14.2 (Transform Feedback
607 * Primitive Capture):
608 *
609 * The error INVALID_OPERATION is generated by DrawArrays and
610 * DrawArraysInstanced if recording the vertices of a primitive to the
611 * buffer objects being used for transform feedback purposes would result
612 * in either exceeding the limits of any buffer object’s size, or in
613 * exceeding the end position offset + size − 1, as set by
614 * BindBufferRange.
615 *
616 * This is in contrast to the behaviour of desktop GL, where the extra
617 * primitives are silently dropped from the transform feedback buffer.
618 */
619 if (_mesa_is_gles3(ctx) && _mesa_is_xfb_active_and_unpaused(ctx)) {
620 size_t prim_count
621 = vbo_count_tessellated_primitives(mode, count, numInstances);
622 if (xfb_obj->GlesRemainingPrims < prim_count) {
623 _mesa_error(ctx, GL_INVALID_OPERATION,
624 "glDrawArraysInstanced(exceeds transform feedback size)");
625 return GL_FALSE;
626 }
627 xfb_obj->GlesRemainingPrims -= prim_count;
628 }
629
630 return GL_TRUE;
631 }
632
633
634 GLboolean
635 _mesa_validate_DrawElementsInstanced(struct gl_context *ctx,
636 GLenum mode, GLsizei count, GLenum type,
637 const GLvoid *indices, GLsizei numInstances,
638 GLint basevertex)
639 {
640 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE);
641 FLUSH_CURRENT(ctx, 0);
642
643 /* From the GLES3 specification, section 2.14.2 (Transform Feedback
644 * Primitive Capture):
645 *
646 * The error INVALID_OPERATION is also generated by DrawElements,
647 * DrawElementsInstanced, and DrawRangeElements while transform feedback
648 * is active and not paused, regardless of mode.
649 */
650 if (_mesa_is_gles3(ctx) && _mesa_is_xfb_active_and_unpaused(ctx)) {
651 _mesa_error(ctx, GL_INVALID_OPERATION,
652 "glDrawElements(transform feedback active)");
653 return GL_FALSE;
654 }
655
656 if (count <= 0) {
657 if (count < 0)
658 _mesa_error(ctx, GL_INVALID_VALUE,
659 "glDrawElementsInstanced(count=%d)", count);
660 return GL_FALSE;
661 }
662
663 if (!_mesa_valid_prim_mode(ctx, mode, "glDrawElementsInstanced")) {
664 return GL_FALSE;
665 }
666
667 if (!valid_elements_type(ctx, type, "glDrawElementsInstanced"))
668 return GL_FALSE;
669
670 if (numInstances <= 0) {
671 if (numInstances < 0)
672 _mesa_error(ctx, GL_INVALID_VALUE,
673 "glDrawElementsInstanced(numInstances=%d)", numInstances);
674 return GL_FALSE;
675 }
676
677 if (!check_valid_to_render(ctx, "glDrawElementsInstanced"))
678 return GL_FALSE;
679
680 /* Vertex buffer object tests */
681 if (_mesa_is_bufferobj(ctx->Array.ArrayObj->ElementArrayBufferObj)) {
682 /* use indices in the buffer object */
683 /* make sure count doesn't go outside buffer bounds */
684 if (index_bytes(type, count) > ctx->Array.ArrayObj->ElementArrayBufferObj->Size) {
685 _mesa_warning(ctx,
686 "glDrawElementsInstanced index out of buffer bounds");
687 return GL_FALSE;
688 }
689 }
690 else {
691 /* not using a VBO */
692 if (!indices)
693 return GL_FALSE;
694 }
695
696 if (!check_index_bounds(ctx, count, type, indices, basevertex))
697 return GL_FALSE;
698
699 return GL_TRUE;
700 }
701
702
703 GLboolean
704 _mesa_validate_DrawTransformFeedback(struct gl_context *ctx,
705 GLenum mode,
706 struct gl_transform_feedback_object *obj,
707 GLuint stream,
708 GLsizei numInstances)
709 {
710 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE);
711 FLUSH_CURRENT(ctx, 0);
712
713 if (!_mesa_valid_prim_mode(ctx, mode, "glDrawTransformFeedback*(mode)")) {
714 return GL_FALSE;
715 }
716
717 if (!obj) {
718 _mesa_error(ctx, GL_INVALID_VALUE, "glDrawTransformFeedback*(name)");
719 return GL_FALSE;
720 }
721
722 if (!obj->EndedAnytime) {
723 _mesa_error(ctx, GL_INVALID_OPERATION, "glDrawTransformFeedback*");
724 return GL_FALSE;
725 }
726
727 if (stream >= ctx->Const.MaxVertexStreams) {
728 _mesa_error(ctx, GL_INVALID_VALUE,
729 "glDrawTransformFeedbackStream*(index>=MaxVertexStream)");
730 return GL_FALSE;
731 }
732
733 if (numInstances <= 0) {
734 if (numInstances < 0)
735 _mesa_error(ctx, GL_INVALID_VALUE,
736 "glDrawTransformFeedback*Instanced(numInstances=%d)",
737 numInstances);
738 return GL_FALSE;
739 }
740
741 if (!check_valid_to_render(ctx, "glDrawTransformFeedback*")) {
742 return GL_FALSE;
743 }
744
745 return GL_TRUE;
746 }