mesa: handle missing read buffer in _mesa_get_color_read_format/type()
[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 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
24 */
25
26 #include <stdbool.h>
27 #include "glheader.h"
28 #include "api_validate.h"
29 #include "bufferobj.h"
30 #include "context.h"
31 #include "imports.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 * Note: This may be called during display list compilation.
205 */
206 bool
207 _mesa_is_valid_prim_mode(struct gl_context *ctx, GLenum mode)
208 {
209 switch (mode) {
210 case GL_POINTS:
211 case GL_LINES:
212 case GL_LINE_LOOP:
213 case GL_LINE_STRIP:
214 case GL_TRIANGLES:
215 case GL_TRIANGLE_STRIP:
216 case GL_TRIANGLE_FAN:
217 return true;
218 case GL_QUADS:
219 case GL_QUAD_STRIP:
220 case GL_POLYGON:
221 return (ctx->API == API_OPENGL_COMPAT);
222 case GL_LINES_ADJACENCY:
223 case GL_LINE_STRIP_ADJACENCY:
224 case GL_TRIANGLES_ADJACENCY:
225 case GL_TRIANGLE_STRIP_ADJACENCY:
226 return _mesa_is_desktop_gl(ctx) && ctx->Extensions.ARB_geometry_shader4;
227 default:
228 return false;
229 }
230 }
231
232
233 /**
234 * Is 'mode' a valid value for glBegin(), glDrawArrays(), glDrawElements(),
235 * etc? Also, do additional checking related to transformation feedback.
236 * Note: this function cannot be called during glNewList(GL_COMPILE) because
237 * this code depends on current transform feedback state.
238 */
239 GLboolean
240 _mesa_valid_prim_mode(struct gl_context *ctx, GLenum mode, const char *name)
241 {
242 bool valid_enum = _mesa_is_valid_prim_mode(ctx, mode);
243
244 if (!valid_enum) {
245 _mesa_error(ctx, GL_INVALID_ENUM, "%s(mode=%x)", name, mode);
246 return GL_FALSE;
247 }
248
249 /* From the GL_EXT_transform_feedback spec:
250 *
251 * "The error INVALID_OPERATION is generated if Begin, or any command
252 * that performs an explicit Begin, is called when:
253 *
254 * * a geometry shader is not active and <mode> does not match the
255 * allowed begin modes for the current transform feedback state as
256 * given by table X.1.
257 *
258 * * a geometry shader is active and the output primitive type of the
259 * geometry shader does not match the allowed begin modes for the
260 * current transform feedback state as given by table X.1.
261 *
262 */
263 if (_mesa_is_xfb_active_and_unpaused(ctx)) {
264 GLboolean pass = GL_TRUE;
265
266 switch (mode) {
267 case GL_POINTS:
268 pass = ctx->TransformFeedback.Mode == GL_POINTS;
269 break;
270 case GL_LINES:
271 case GL_LINE_STRIP:
272 case GL_LINE_LOOP:
273 pass = ctx->TransformFeedback.Mode == GL_LINES;
274 break;
275 default:
276 pass = ctx->TransformFeedback.Mode == GL_TRIANGLES;
277 break;
278 }
279 if (!pass) {
280 _mesa_error(ctx, GL_INVALID_OPERATION,
281 "%s(mode=%s vs transform feedback %s)",
282 name,
283 _mesa_lookup_prim_by_nr(mode),
284 _mesa_lookup_prim_by_nr(ctx->TransformFeedback.Mode));
285 return GL_FALSE;
286 }
287 }
288
289 return GL_TRUE;
290 }
291
292 /**
293 * Verify that the element type is valid.
294 *
295 * Generates \c GL_INVALID_ENUM and returns \c false if it is not.
296 */
297 static bool
298 valid_elements_type(struct gl_context *ctx, GLenum type, const char *name)
299 {
300 switch (type) {
301 case GL_UNSIGNED_BYTE:
302 case GL_UNSIGNED_SHORT:
303 case GL_UNSIGNED_INT:
304 return true;
305
306 default:
307 _mesa_error(ctx, GL_INVALID_ENUM, "%s(type = %s)", name,
308 _mesa_lookup_enum_by_nr(type));
309 return false;
310 }
311 }
312
313 /**
314 * Error checking for glDrawElements(). Includes parameter checking
315 * and VBO bounds checking.
316 * \return GL_TRUE if OK to render, GL_FALSE if error found
317 */
318 GLboolean
319 _mesa_validate_DrawElements(struct gl_context *ctx,
320 GLenum mode, GLsizei count, GLenum type,
321 const GLvoid *indices, GLint basevertex)
322 {
323 FLUSH_CURRENT(ctx, 0);
324
325 /* From the GLES3 specification, section 2.14.2 (Transform Feedback
326 * Primitive Capture):
327 *
328 * The error INVALID_OPERATION is also generated by DrawElements,
329 * DrawElementsInstanced, and DrawRangeElements while transform feedback
330 * is active and not paused, regardless of mode.
331 */
332 if (_mesa_is_gles3(ctx) && _mesa_is_xfb_active_and_unpaused(ctx)) {
333 _mesa_error(ctx, GL_INVALID_OPERATION,
334 "glDrawElements(transform feedback active)");
335 return GL_FALSE;
336 }
337
338 if (count <= 0) {
339 if (count < 0)
340 _mesa_error(ctx, GL_INVALID_VALUE, "glDrawElements(count)" );
341 return GL_FALSE;
342 }
343
344 if (!_mesa_valid_prim_mode(ctx, mode, "glDrawElements")) {
345 return GL_FALSE;
346 }
347
348 if (!valid_elements_type(ctx, type, "glDrawElements"))
349 return GL_FALSE;
350
351 if (!check_valid_to_render(ctx, "glDrawElements"))
352 return GL_FALSE;
353
354 /* Vertex buffer object tests */
355 if (_mesa_is_bufferobj(ctx->Array.ArrayObj->ElementArrayBufferObj)) {
356 /* use indices in the buffer object */
357 /* make sure count doesn't go outside buffer bounds */
358 if (index_bytes(type, count) > ctx->Array.ArrayObj->ElementArrayBufferObj->Size) {
359 _mesa_warning(ctx, "glDrawElements index out of buffer bounds");
360 return GL_FALSE;
361 }
362 }
363 else {
364 /* not using a VBO */
365 if (!indices)
366 return GL_FALSE;
367 }
368
369 if (!check_index_bounds(ctx, count, type, indices, basevertex))
370 return GL_FALSE;
371
372 return GL_TRUE;
373 }
374
375
376 /**
377 * Error checking for glMultiDrawElements(). Includes parameter checking
378 * and VBO bounds checking.
379 * \return GL_TRUE if OK to render, GL_FALSE if error found
380 */
381 GLboolean
382 _mesa_validate_MultiDrawElements(struct gl_context *ctx,
383 GLenum mode, const GLsizei *count,
384 GLenum type, const GLvoid * const *indices,
385 GLuint primcount, const GLint *basevertex)
386 {
387 unsigned i;
388
389 FLUSH_CURRENT(ctx, 0);
390
391 for (i = 0; i < primcount; i++) {
392 if (count[i] <= 0) {
393 if (count[i] < 0)
394 _mesa_error(ctx, GL_INVALID_VALUE,
395 "glMultiDrawElements(count)" );
396 return GL_FALSE;
397 }
398 }
399
400 if (!_mesa_valid_prim_mode(ctx, mode, "glMultiDrawElements")) {
401 return GL_FALSE;
402 }
403
404 if (!valid_elements_type(ctx, type, "glMultiDrawElements"))
405 return GL_FALSE;
406
407 if (!check_valid_to_render(ctx, "glMultiDrawElements"))
408 return GL_FALSE;
409
410 /* Vertex buffer object tests */
411 if (_mesa_is_bufferobj(ctx->Array.ArrayObj->ElementArrayBufferObj)) {
412 /* use indices in the buffer object */
413 /* make sure count doesn't go outside buffer bounds */
414 for (i = 0; i < primcount; i++) {
415 if (index_bytes(type, count[i]) >
416 ctx->Array.ArrayObj->ElementArrayBufferObj->Size) {
417 _mesa_warning(ctx,
418 "glMultiDrawElements index out of buffer bounds");
419 return GL_FALSE;
420 }
421 }
422 }
423 else {
424 /* not using a VBO */
425 for (i = 0; i < primcount; i++) {
426 if (!indices[i])
427 return GL_FALSE;
428 }
429 }
430
431 for (i = 0; i < primcount; i++) {
432 if (!check_index_bounds(ctx, count[i], type, indices[i],
433 basevertex ? basevertex[i] : 0))
434 return GL_FALSE;
435 }
436
437 return GL_TRUE;
438 }
439
440
441 /**
442 * Error checking for glDrawRangeElements(). Includes parameter checking
443 * and VBO bounds checking.
444 * \return GL_TRUE if OK to render, GL_FALSE if error found
445 */
446 GLboolean
447 _mesa_validate_DrawRangeElements(struct gl_context *ctx, GLenum mode,
448 GLuint start, GLuint end,
449 GLsizei count, GLenum type,
450 const GLvoid *indices, GLint basevertex)
451 {
452 FLUSH_CURRENT(ctx, 0);
453
454 /* From the GLES3 specification, section 2.14.2 (Transform Feedback
455 * Primitive Capture):
456 *
457 * The error INVALID_OPERATION is also generated by DrawElements,
458 * DrawElementsInstanced, and DrawRangeElements while transform feedback
459 * is active and not paused, regardless of mode.
460 */
461 if (_mesa_is_gles3(ctx) && _mesa_is_xfb_active_and_unpaused(ctx)) {
462 _mesa_error(ctx, GL_INVALID_OPERATION,
463 "glDrawElements(transform feedback active)");
464 return GL_FALSE;
465 }
466
467 if (count <= 0) {
468 if (count < 0)
469 _mesa_error(ctx, GL_INVALID_VALUE, "glDrawRangeElements(count)" );
470 return GL_FALSE;
471 }
472
473 if (!_mesa_valid_prim_mode(ctx, mode, "glDrawRangeElements")) {
474 return GL_FALSE;
475 }
476
477 if (end < start) {
478 _mesa_error(ctx, GL_INVALID_VALUE, "glDrawRangeElements(end<start)");
479 return GL_FALSE;
480 }
481
482 if (!valid_elements_type(ctx, type, "glDrawRangeElements"))
483 return GL_FALSE;
484
485 if (!check_valid_to_render(ctx, "glDrawRangeElements"))
486 return GL_FALSE;
487
488 /* Vertex buffer object tests */
489 if (_mesa_is_bufferobj(ctx->Array.ArrayObj->ElementArrayBufferObj)) {
490 /* use indices in the buffer object */
491 /* make sure count doesn't go outside buffer bounds */
492 if (index_bytes(type, count) > ctx->Array.ArrayObj->ElementArrayBufferObj->Size) {
493 _mesa_warning(ctx, "glDrawRangeElements index out of buffer bounds");
494 return GL_FALSE;
495 }
496 }
497 else {
498 /* not using a VBO */
499 if (!indices)
500 return GL_FALSE;
501 }
502
503 if (!check_index_bounds(ctx, count, type, indices, basevertex))
504 return GL_FALSE;
505
506 return GL_TRUE;
507 }
508
509
510 /**
511 * Called from the tnl module to error check the function parameters and
512 * verify that we really can draw something.
513 * \return GL_TRUE if OK to render, GL_FALSE if error found
514 */
515 GLboolean
516 _mesa_validate_DrawArrays(struct gl_context *ctx,
517 GLenum mode, GLint start, GLsizei count)
518 {
519 struct gl_transform_feedback_object *xfb_obj
520 = ctx->TransformFeedback.CurrentObject;
521 FLUSH_CURRENT(ctx, 0);
522
523 if (count <= 0) {
524 if (count < 0)
525 _mesa_error(ctx, GL_INVALID_VALUE, "glDrawArrays(count)" );
526 return GL_FALSE;
527 }
528
529 if (!_mesa_valid_prim_mode(ctx, mode, "glDrawArrays")) {
530 return GL_FALSE;
531 }
532
533 if (!check_valid_to_render(ctx, "glDrawArrays"))
534 return GL_FALSE;
535
536 if (ctx->Const.CheckArrayBounds) {
537 if (start + count > (GLint) ctx->Array.ArrayObj->_MaxElement)
538 return GL_FALSE;
539 }
540
541 /* From the GLES3 specification, section 2.14.2 (Transform Feedback
542 * Primitive Capture):
543 *
544 * The error INVALID_OPERATION is generated by DrawArrays and
545 * DrawArraysInstanced if recording the vertices of a primitive to the
546 * buffer objects being used for transform feedback purposes would result
547 * in either exceeding the limits of any buffer object’s size, or in
548 * exceeding the end position offset + size − 1, as set by
549 * BindBufferRange.
550 *
551 * This is in contrast to the behaviour of desktop GL, where the extra
552 * primitives are silently dropped from the transform feedback buffer.
553 */
554 if (_mesa_is_gles3(ctx) && _mesa_is_xfb_active_and_unpaused(ctx)) {
555 size_t prim_count = vbo_count_tessellated_primitives(mode, count, 1);
556 if (xfb_obj->GlesRemainingPrims < prim_count) {
557 _mesa_error(ctx, GL_INVALID_OPERATION,
558 "glDrawArrays(exceeds transform feedback size)");
559 return GL_FALSE;
560 }
561 xfb_obj->GlesRemainingPrims -= prim_count;
562 }
563
564 return GL_TRUE;
565 }
566
567
568 GLboolean
569 _mesa_validate_DrawArraysInstanced(struct gl_context *ctx, GLenum mode, GLint first,
570 GLsizei count, GLsizei numInstances)
571 {
572 struct gl_transform_feedback_object *xfb_obj
573 = ctx->TransformFeedback.CurrentObject;
574 FLUSH_CURRENT(ctx, 0);
575
576 if (count <= 0) {
577 if (count < 0)
578 _mesa_error(ctx, GL_INVALID_VALUE,
579 "glDrawArraysInstanced(count=%d)", count);
580 return GL_FALSE;
581 }
582
583 if (first < 0) {
584 _mesa_error(ctx, GL_INVALID_VALUE,
585 "glDrawArraysInstanced(start=%d)", first);
586 return GL_FALSE;
587 }
588
589 if (!_mesa_valid_prim_mode(ctx, mode, "glDrawArraysInstanced")) {
590 return GL_FALSE;
591 }
592
593 if (numInstances <= 0) {
594 if (numInstances < 0)
595 _mesa_error(ctx, GL_INVALID_VALUE,
596 "glDrawArraysInstanced(numInstances=%d)", numInstances);
597 return GL_FALSE;
598 }
599
600 if (!check_valid_to_render(ctx, "glDrawArraysInstanced(invalid to render)"))
601 return GL_FALSE;
602
603 if (ctx->Const.CheckArrayBounds) {
604 if (first + count > (GLint) ctx->Array.ArrayObj->_MaxElement)
605 return GL_FALSE;
606 }
607
608 /* From the GLES3 specification, section 2.14.2 (Transform Feedback
609 * Primitive Capture):
610 *
611 * The error INVALID_OPERATION is generated by DrawArrays and
612 * DrawArraysInstanced if recording the vertices of a primitive to the
613 * buffer objects being used for transform feedback purposes would result
614 * in either exceeding the limits of any buffer object’s size, or in
615 * exceeding the end position offset + size − 1, as set by
616 * BindBufferRange.
617 *
618 * This is in contrast to the behaviour of desktop GL, where the extra
619 * primitives are silently dropped from the transform feedback buffer.
620 */
621 if (_mesa_is_gles3(ctx) && _mesa_is_xfb_active_and_unpaused(ctx)) {
622 size_t prim_count
623 = vbo_count_tessellated_primitives(mode, count, numInstances);
624 if (xfb_obj->GlesRemainingPrims < prim_count) {
625 _mesa_error(ctx, GL_INVALID_OPERATION,
626 "glDrawArraysInstanced(exceeds transform feedback size)");
627 return GL_FALSE;
628 }
629 xfb_obj->GlesRemainingPrims -= prim_count;
630 }
631
632 return GL_TRUE;
633 }
634
635
636 GLboolean
637 _mesa_validate_DrawElementsInstanced(struct gl_context *ctx,
638 GLenum mode, GLsizei count, GLenum type,
639 const GLvoid *indices, GLsizei numInstances,
640 GLint basevertex)
641 {
642 FLUSH_CURRENT(ctx, 0);
643
644 /* From the GLES3 specification, section 2.14.2 (Transform Feedback
645 * Primitive Capture):
646 *
647 * The error INVALID_OPERATION is also generated by DrawElements,
648 * DrawElementsInstanced, and DrawRangeElements while transform feedback
649 * is active and not paused, regardless of mode.
650 */
651 if (_mesa_is_gles3(ctx) && _mesa_is_xfb_active_and_unpaused(ctx)) {
652 _mesa_error(ctx, GL_INVALID_OPERATION,
653 "glDrawElements(transform feedback active)");
654 return GL_FALSE;
655 }
656
657 if (count <= 0) {
658 if (count < 0)
659 _mesa_error(ctx, GL_INVALID_VALUE,
660 "glDrawElementsInstanced(count=%d)", count);
661 return GL_FALSE;
662 }
663
664 if (!_mesa_valid_prim_mode(ctx, mode, "glDrawElementsInstanced")) {
665 return GL_FALSE;
666 }
667
668 if (!valid_elements_type(ctx, type, "glDrawElementsInstanced"))
669 return GL_FALSE;
670
671 if (numInstances <= 0) {
672 if (numInstances < 0)
673 _mesa_error(ctx, GL_INVALID_VALUE,
674 "glDrawElementsInstanced(numInstances=%d)", numInstances);
675 return GL_FALSE;
676 }
677
678 if (!check_valid_to_render(ctx, "glDrawElementsInstanced"))
679 return GL_FALSE;
680
681 /* Vertex buffer object tests */
682 if (_mesa_is_bufferobj(ctx->Array.ArrayObj->ElementArrayBufferObj)) {
683 /* use indices in the buffer object */
684 /* make sure count doesn't go outside buffer bounds */
685 if (index_bytes(type, count) > ctx->Array.ArrayObj->ElementArrayBufferObj->Size) {
686 _mesa_warning(ctx,
687 "glDrawElementsInstanced index out of buffer bounds");
688 return GL_FALSE;
689 }
690 }
691 else {
692 /* not using a VBO */
693 if (!indices)
694 return GL_FALSE;
695 }
696
697 if (!check_index_bounds(ctx, count, type, indices, basevertex))
698 return GL_FALSE;
699
700 return GL_TRUE;
701 }
702
703
704 GLboolean
705 _mesa_validate_DrawTransformFeedback(struct gl_context *ctx,
706 GLenum mode,
707 struct gl_transform_feedback_object *obj,
708 GLuint stream,
709 GLsizei numInstances)
710 {
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 }