2 * Mesa 3-D graphics library
4 * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * OTHER DEALINGS IN THE SOFTWARE.
27 #include "api_validate.h"
28 #include "bufferobj.h"
34 #include "transformfeedback.h"
39 * \return number of bytes in array [count] of type.
42 index_bytes(GLenum type
, GLsizei count
)
44 if (type
== GL_UNSIGNED_INT
) {
45 return count
* sizeof(GLuint
);
47 else if (type
== GL_UNSIGNED_BYTE
) {
48 return count
* sizeof(GLubyte
);
51 ASSERT(type
== GL_UNSIGNED_SHORT
);
52 return count
* sizeof(GLushort
);
58 * Find the max index in the given element/index buffer
61 _mesa_max_buffer_index(struct gl_context
*ctx
, GLuint count
, GLenum type
,
63 struct gl_buffer_object
*elementBuf
)
65 const GLubyte
*map
= NULL
;
69 if (_mesa_is_bufferobj(elementBuf
)) {
70 /* elements are in a user-defined buffer object. need to map it */
71 map
= ctx
->Driver
.MapBufferRange(ctx
, 0, elementBuf
->Size
,
72 GL_MAP_READ_BIT
, elementBuf
,
74 /* Actual address is the sum of pointers */
75 indices
= (const GLvoid
*) ADD_POINTERS(map
, (const GLubyte
*) indices
);
78 if (type
== GL_UNSIGNED_INT
) {
79 for (i
= 0; i
< count
; i
++)
80 if (((GLuint
*) indices
)[i
] > max
)
81 max
= ((GLuint
*) indices
)[i
];
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
];
89 ASSERT(type
== GL_UNSIGNED_BYTE
);
90 for (i
= 0; i
< count
; i
++)
91 if (((GLubyte
*) indices
)[i
] > max
)
92 max
= ((GLubyte
*) indices
)[i
];
96 ctx
->Driver
.UnmapBuffer(ctx
, elementBuf
, MAP_INTERNAL
);
104 * Check if OK to draw arrays/elements.
107 check_valid_to_render(struct gl_context
*ctx
, const char *function
)
109 if (!_mesa_valid_to_render(ctx
, function
)) {
115 /* For ES2, we can draw if we have a vertex program/shader). */
116 if (!ctx
->VertexProgram
._Current
)
121 /* For OpenGL ES, only draw if we have vertex positions
123 if (!ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_POS
].Enabled
)
127 case API_OPENGL_CORE
:
128 if (ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
)
131 case API_OPENGL_COMPAT
:
133 const struct gl_shader_program
*vsProg
=
134 ctx
->_Shader
->CurrentProgram
[MESA_SHADER_VERTEX
];
135 GLboolean haveVertexShader
= (vsProg
&& vsProg
->LinkStatus
);
136 GLboolean haveVertexProgram
= ctx
->VertexProgram
._Enabled
;
137 if (haveVertexShader
|| haveVertexProgram
) {
138 /* Draw regardless of whether or not we have any vertex arrays.
139 * (Ex: could draw a point using a constant vertex pos)
144 /* Draw if we have vertex positions (GL_VERTEX_ARRAY or generic
147 return (ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_POS
].Enabled
||
148 ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_GENERIC0
].Enabled
);
154 assert(!"Invalid API value in check_valid_to_render()");
162 * Is 'mode' a valid value for glBegin(), glDrawArrays(), glDrawElements(),
163 * etc? The set of legal values depends on whether geometry shaders/programs
165 * Note: This may be called during display list compilation.
168 _mesa_is_valid_prim_mode(struct gl_context
*ctx
, GLenum mode
)
176 case GL_TRIANGLE_STRIP
:
177 case GL_TRIANGLE_FAN
:
182 return (ctx
->API
== API_OPENGL_COMPAT
);
183 case GL_LINES_ADJACENCY
:
184 case GL_LINE_STRIP_ADJACENCY
:
185 case GL_TRIANGLES_ADJACENCY
:
186 case GL_TRIANGLE_STRIP_ADJACENCY
:
187 return _mesa_has_geometry_shaders(ctx
);
195 * Is 'mode' a valid value for glBegin(), glDrawArrays(), glDrawElements(),
196 * etc? Also, do additional checking related to transformation feedback.
197 * Note: this function cannot be called during glNewList(GL_COMPILE) because
198 * this code depends on current transform feedback state.
201 _mesa_valid_prim_mode(struct gl_context
*ctx
, GLenum mode
, const char *name
)
203 bool valid_enum
= _mesa_is_valid_prim_mode(ctx
, mode
);
206 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(mode=%x)", name
, mode
);
210 /* From the ARB_geometry_shader4 spec:
212 * The error INVALID_OPERATION is generated if Begin, or any command that
213 * implicitly calls Begin, is called when a geometry shader is active and:
215 * * the input primitive type of the current geometry shader is
216 * POINTS and <mode> is not POINTS,
218 * * the input primitive type of the current geometry shader is
219 * LINES and <mode> is not LINES, LINE_STRIP, or LINE_LOOP,
221 * * the input primitive type of the current geometry shader is
222 * TRIANGLES and <mode> is not TRIANGLES, TRIANGLE_STRIP or
225 * * the input primitive type of the current geometry shader is
226 * LINES_ADJACENCY_ARB and <mode> is not LINES_ADJACENCY_ARB or
227 * LINE_STRIP_ADJACENCY_ARB, or
229 * * the input primitive type of the current geometry shader is
230 * TRIANGLES_ADJACENCY_ARB and <mode> is not
231 * TRIANGLES_ADJACENCY_ARB or TRIANGLE_STRIP_ADJACENCY_ARB.
234 if (ctx
->_Shader
->CurrentProgram
[MESA_SHADER_GEOMETRY
]) {
235 const GLenum geom_mode
=
236 ctx
->_Shader
->CurrentProgram
[MESA_SHADER_GEOMETRY
]->Geom
.InputType
;
239 valid_enum
= (geom_mode
== GL_POINTS
);
244 valid_enum
= (geom_mode
== GL_LINES
);
247 case GL_TRIANGLE_STRIP
:
248 case GL_TRIANGLE_FAN
:
249 valid_enum
= (geom_mode
== GL_TRIANGLES
);
256 case GL_LINES_ADJACENCY
:
257 case GL_LINE_STRIP_ADJACENCY
:
258 valid_enum
= (geom_mode
== GL_LINES_ADJACENCY
);
260 case GL_TRIANGLES_ADJACENCY
:
261 case GL_TRIANGLE_STRIP_ADJACENCY
:
262 valid_enum
= (geom_mode
== GL_TRIANGLES_ADJACENCY
);
269 _mesa_error(ctx
, GL_INVALID_OPERATION
,
270 "%s(mode=%s vs geometry shader input %s)",
272 _mesa_lookup_prim_by_nr(mode
),
273 _mesa_lookup_prim_by_nr(geom_mode
));
278 /* From the GL_EXT_transform_feedback spec:
280 * "The error INVALID_OPERATION is generated if Begin, or any command
281 * that performs an explicit Begin, is called when:
283 * * a geometry shader is not active and <mode> does not match the
284 * allowed begin modes for the current transform feedback state as
285 * given by table X.1.
287 * * a geometry shader is active and the output primitive type of the
288 * geometry shader does not match the allowed begin modes for the
289 * current transform feedback state as given by table X.1.
292 if (_mesa_is_xfb_active_and_unpaused(ctx
)) {
293 GLboolean pass
= GL_TRUE
;
295 if(ctx
->_Shader
->CurrentProgram
[MESA_SHADER_GEOMETRY
]) {
296 switch (ctx
->_Shader
->CurrentProgram
[MESA_SHADER_GEOMETRY
]->Geom
.OutputType
) {
298 pass
= ctx
->TransformFeedback
.Mode
== GL_POINTS
;
301 pass
= ctx
->TransformFeedback
.Mode
== GL_LINES
;
303 case GL_TRIANGLE_STRIP
:
304 pass
= ctx
->TransformFeedback
.Mode
== GL_TRIANGLES
;
313 pass
= ctx
->TransformFeedback
.Mode
== GL_POINTS
;
318 pass
= ctx
->TransformFeedback
.Mode
== GL_LINES
;
321 pass
= ctx
->TransformFeedback
.Mode
== GL_TRIANGLES
;
326 _mesa_error(ctx
, GL_INVALID_OPERATION
,
327 "%s(mode=%s vs transform feedback %s)",
329 _mesa_lookup_prim_by_nr(mode
),
330 _mesa_lookup_prim_by_nr(ctx
->TransformFeedback
.Mode
));
339 * Verify that the element type is valid.
341 * Generates \c GL_INVALID_ENUM and returns \c false if it is not.
344 valid_elements_type(struct gl_context
*ctx
, GLenum type
, const char *name
)
347 case GL_UNSIGNED_BYTE
:
348 case GL_UNSIGNED_SHORT
:
349 case GL_UNSIGNED_INT
:
353 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(type = %s)", name
,
354 _mesa_lookup_enum_by_nr(type
));
360 * Error checking for glDrawElements(). Includes parameter checking
361 * and VBO bounds checking.
362 * \return GL_TRUE if OK to render, GL_FALSE if error found
365 _mesa_validate_DrawElements(struct gl_context
*ctx
,
366 GLenum mode
, GLsizei count
, GLenum type
,
367 const GLvoid
*indices
, GLint basevertex
)
369 FLUSH_CURRENT(ctx
, 0);
371 /* From the GLES3 specification, section 2.14.2 (Transform Feedback
372 * Primitive Capture):
374 * The error INVALID_OPERATION is also generated by DrawElements,
375 * DrawElementsInstanced, and DrawRangeElements while transform feedback
376 * is active and not paused, regardless of mode.
378 if (_mesa_is_gles3(ctx
) && _mesa_is_xfb_active_and_unpaused(ctx
)) {
379 _mesa_error(ctx
, GL_INVALID_OPERATION
,
380 "glDrawElements(transform feedback active)");
385 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDrawElements(count)" );
389 if (!_mesa_valid_prim_mode(ctx
, mode
, "glDrawElements")) {
393 if (!valid_elements_type(ctx
, type
, "glDrawElements"))
396 if (!check_valid_to_render(ctx
, "glDrawElements"))
399 /* Vertex buffer object tests */
400 if (_mesa_is_bufferobj(ctx
->Array
.VAO
->IndexBufferObj
)) {
401 /* use indices in the buffer object */
402 /* make sure count doesn't go outside buffer bounds */
403 if (index_bytes(type
, count
) > ctx
->Array
.VAO
->IndexBufferObj
->Size
) {
404 _mesa_warning(ctx
, "glDrawElements index out of buffer bounds");
409 /* not using a VBO */
422 * Error checking for glMultiDrawElements(). Includes parameter checking
423 * and VBO bounds checking.
424 * \return GL_TRUE if OK to render, GL_FALSE if error found
427 _mesa_validate_MultiDrawElements(struct gl_context
*ctx
,
428 GLenum mode
, const GLsizei
*count
,
429 GLenum type
, const GLvoid
* const *indices
,
430 GLuint primcount
, const GLint
*basevertex
)
434 FLUSH_CURRENT(ctx
, 0);
436 for (i
= 0; i
< primcount
; i
++) {
438 _mesa_error(ctx
, GL_INVALID_VALUE
,
439 "glMultiDrawElements(count)" );
444 if (!_mesa_valid_prim_mode(ctx
, mode
, "glMultiDrawElements")) {
448 if (!valid_elements_type(ctx
, type
, "glMultiDrawElements"))
451 if (!check_valid_to_render(ctx
, "glMultiDrawElements"))
454 /* Vertex buffer object tests */
455 if (_mesa_is_bufferobj(ctx
->Array
.VAO
->IndexBufferObj
)) {
456 /* use indices in the buffer object */
457 /* make sure count doesn't go outside buffer bounds */
458 for (i
= 0; i
< primcount
; i
++) {
459 if (index_bytes(type
, count
[i
]) >
460 ctx
->Array
.VAO
->IndexBufferObj
->Size
) {
462 "glMultiDrawElements index out of buffer bounds");
468 /* not using a VBO */
469 for (i
= 0; i
< primcount
; i
++) {
480 * Error checking for glDrawRangeElements(). Includes parameter checking
481 * and VBO bounds checking.
482 * \return GL_TRUE if OK to render, GL_FALSE if error found
485 _mesa_validate_DrawRangeElements(struct gl_context
*ctx
, GLenum mode
,
486 GLuint start
, GLuint end
,
487 GLsizei count
, GLenum type
,
488 const GLvoid
*indices
, GLint basevertex
)
490 FLUSH_CURRENT(ctx
, 0);
492 /* From the GLES3 specification, section 2.14.2 (Transform Feedback
493 * Primitive Capture):
495 * The error INVALID_OPERATION is also generated by DrawElements,
496 * DrawElementsInstanced, and DrawRangeElements while transform feedback
497 * is active and not paused, regardless of mode.
499 if (_mesa_is_gles3(ctx
) && _mesa_is_xfb_active_and_unpaused(ctx
)) {
500 _mesa_error(ctx
, GL_INVALID_OPERATION
,
501 "glDrawElements(transform feedback active)");
506 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDrawRangeElements(count)" );
510 if (!_mesa_valid_prim_mode(ctx
, mode
, "glDrawRangeElements")) {
515 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDrawRangeElements(end<start)");
519 if (!valid_elements_type(ctx
, type
, "glDrawRangeElements"))
522 if (!check_valid_to_render(ctx
, "glDrawRangeElements"))
525 /* Vertex buffer object tests */
526 if (_mesa_is_bufferobj(ctx
->Array
.VAO
->IndexBufferObj
)) {
527 /* use indices in the buffer object */
528 /* make sure count doesn't go outside buffer bounds */
529 if (index_bytes(type
, count
) > ctx
->Array
.VAO
->IndexBufferObj
->Size
) {
530 _mesa_warning(ctx
, "glDrawRangeElements index out of buffer bounds");
535 /* not using a VBO */
548 * Called from the tnl module to error check the function parameters and
549 * verify that we really can draw something.
550 * \return GL_TRUE if OK to render, GL_FALSE if error found
553 _mesa_validate_DrawArrays(struct gl_context
*ctx
,
554 GLenum mode
, GLint start
, GLsizei count
)
556 struct gl_transform_feedback_object
*xfb_obj
557 = ctx
->TransformFeedback
.CurrentObject
;
558 FLUSH_CURRENT(ctx
, 0);
561 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDrawArrays(count)" );
565 if (!_mesa_valid_prim_mode(ctx
, mode
, "glDrawArrays")) {
569 if (!check_valid_to_render(ctx
, "glDrawArrays"))
572 /* From the GLES3 specification, section 2.14.2 (Transform Feedback
573 * Primitive Capture):
575 * The error INVALID_OPERATION is generated by DrawArrays and
576 * DrawArraysInstanced if recording the vertices of a primitive to the
577 * buffer objects being used for transform feedback purposes would result
578 * in either exceeding the limits of any buffer object’s size, or in
579 * exceeding the end position offset + size − 1, as set by
582 * This is in contrast to the behaviour of desktop GL, where the extra
583 * primitives are silently dropped from the transform feedback buffer.
585 if (_mesa_is_gles3(ctx
) && _mesa_is_xfb_active_and_unpaused(ctx
)) {
586 size_t prim_count
= vbo_count_tessellated_primitives(mode
, count
, 1);
587 if (xfb_obj
->GlesRemainingPrims
< prim_count
) {
588 _mesa_error(ctx
, GL_INVALID_OPERATION
,
589 "glDrawArrays(exceeds transform feedback size)");
592 xfb_obj
->GlesRemainingPrims
-= prim_count
;
603 _mesa_validate_DrawArraysInstanced(struct gl_context
*ctx
, GLenum mode
, GLint first
,
604 GLsizei count
, GLsizei numInstances
)
606 struct gl_transform_feedback_object
*xfb_obj
607 = ctx
->TransformFeedback
.CurrentObject
;
608 FLUSH_CURRENT(ctx
, 0);
611 _mesa_error(ctx
, GL_INVALID_VALUE
,
612 "glDrawArraysInstanced(count=%d)", count
);
617 _mesa_error(ctx
, GL_INVALID_VALUE
,
618 "glDrawArraysInstanced(start=%d)", first
);
622 if (!_mesa_valid_prim_mode(ctx
, mode
, "glDrawArraysInstanced")) {
626 if (numInstances
<= 0) {
627 if (numInstances
< 0)
628 _mesa_error(ctx
, GL_INVALID_VALUE
,
629 "glDrawArraysInstanced(numInstances=%d)", numInstances
);
633 if (!check_valid_to_render(ctx
, "glDrawArraysInstanced(invalid to render)"))
636 /* From the GLES3 specification, section 2.14.2 (Transform Feedback
637 * Primitive Capture):
639 * The error INVALID_OPERATION is generated by DrawArrays and
640 * DrawArraysInstanced if recording the vertices of a primitive to the
641 * buffer objects being used for transform feedback purposes would result
642 * in either exceeding the limits of any buffer object’s size, or in
643 * exceeding the end position offset + size − 1, as set by
646 * This is in contrast to the behaviour of desktop GL, where the extra
647 * primitives are silently dropped from the transform feedback buffer.
649 if (_mesa_is_gles3(ctx
) && _mesa_is_xfb_active_and_unpaused(ctx
)) {
651 = vbo_count_tessellated_primitives(mode
, count
, numInstances
);
652 if (xfb_obj
->GlesRemainingPrims
< prim_count
) {
653 _mesa_error(ctx
, GL_INVALID_OPERATION
,
654 "glDrawArraysInstanced(exceeds transform feedback size)");
657 xfb_obj
->GlesRemainingPrims
-= prim_count
;
668 _mesa_validate_DrawElementsInstanced(struct gl_context
*ctx
,
669 GLenum mode
, GLsizei count
, GLenum type
,
670 const GLvoid
*indices
, GLsizei numInstances
,
673 FLUSH_CURRENT(ctx
, 0);
675 /* From the GLES3 specification, section 2.14.2 (Transform Feedback
676 * Primitive Capture):
678 * The error INVALID_OPERATION is also generated by DrawElements,
679 * DrawElementsInstanced, and DrawRangeElements while transform feedback
680 * is active and not paused, regardless of mode.
682 if (_mesa_is_gles3(ctx
) && _mesa_is_xfb_active_and_unpaused(ctx
)) {
683 _mesa_error(ctx
, GL_INVALID_OPERATION
,
684 "glDrawElements(transform feedback active)");
689 _mesa_error(ctx
, GL_INVALID_VALUE
,
690 "glDrawElementsInstanced(count=%d)", count
);
694 if (!_mesa_valid_prim_mode(ctx
, mode
, "glDrawElementsInstanced")) {
698 if (!valid_elements_type(ctx
, type
, "glDrawElementsInstanced"))
701 if (numInstances
<= 0) {
702 if (numInstances
< 0)
703 _mesa_error(ctx
, GL_INVALID_VALUE
,
704 "glDrawElementsInstanced(numInstances=%d)", numInstances
);
708 if (!check_valid_to_render(ctx
, "glDrawElementsInstanced"))
711 /* Vertex buffer object tests */
712 if (_mesa_is_bufferobj(ctx
->Array
.VAO
->IndexBufferObj
)) {
713 /* use indices in the buffer object */
714 /* make sure count doesn't go outside buffer bounds */
715 if (index_bytes(type
, count
) > ctx
->Array
.VAO
->IndexBufferObj
->Size
) {
717 "glDrawElementsInstanced index out of buffer bounds");
722 /* not using a VBO */
735 _mesa_validate_DrawTransformFeedback(struct gl_context
*ctx
,
737 struct gl_transform_feedback_object
*obj
,
739 GLsizei numInstances
)
741 FLUSH_CURRENT(ctx
, 0);
743 if (!_mesa_valid_prim_mode(ctx
, mode
, "glDrawTransformFeedback*(mode)")) {
748 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDrawTransformFeedback*(name)");
752 if (!obj
->EndedAnytime
) {
753 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glDrawTransformFeedback*");
757 if (stream
>= ctx
->Const
.MaxVertexStreams
) {
758 _mesa_error(ctx
, GL_INVALID_VALUE
,
759 "glDrawTransformFeedbackStream*(index>=MaxVertexStream)");
763 if (numInstances
<= 0) {
764 if (numInstances
< 0)
765 _mesa_error(ctx
, GL_INVALID_VALUE
,
766 "glDrawTransformFeedback*Instanced(numInstances=%d)",
771 if (!check_valid_to_render(ctx
, "glDrawTransformFeedback*")) {
779 valid_draw_indirect(struct gl_context
*ctx
,
780 GLenum mode
, const GLvoid
*indirect
,
781 GLsizei size
, const char *name
)
783 const GLsizeiptr end
= (GLsizeiptr
)indirect
+ size
;
785 if (!_mesa_valid_prim_mode(ctx
, mode
, name
))
789 /* From the ARB_draw_indirect specification:
790 * "An INVALID_OPERATION error is generated [...] if <indirect> is no
793 if ((GLsizeiptr
)indirect
& (sizeof(GLuint
) - 1)) {
794 _mesa_error(ctx
, GL_INVALID_OPERATION
,
795 "%s(indirect is not aligned)", name
);
799 if (!_mesa_is_bufferobj(ctx
->DrawIndirectBuffer
)) {
800 _mesa_error(ctx
, GL_INVALID_OPERATION
,
801 "%s: no buffer bound to DRAW_INDIRECT_BUFFER", name
);
805 if (_mesa_check_disallowed_mapping(ctx
->DrawIndirectBuffer
)) {
806 _mesa_error(ctx
, GL_INVALID_OPERATION
,
807 "%s(DRAW_INDIRECT_BUFFER is mapped)", name
);
811 /* From the ARB_draw_indirect specification:
812 * "An INVALID_OPERATION error is generated if the commands source data
813 * beyond the end of the buffer object [...]"
815 if (ctx
->DrawIndirectBuffer
->Size
< end
) {
816 _mesa_error(ctx
, GL_INVALID_OPERATION
,
817 "%s(DRAW_INDIRECT_BUFFER too small)", name
);
821 if (!check_valid_to_render(ctx
, name
))
827 static inline GLboolean
828 valid_draw_indirect_elements(struct gl_context
*ctx
,
829 GLenum mode
, GLenum type
, const GLvoid
*indirect
,
830 GLsizeiptr size
, const char *name
)
832 if (!valid_elements_type(ctx
, type
, name
))
836 * Unlike regular DrawElementsInstancedBaseVertex commands, the indices
837 * may not come from a client array and must come from an index buffer.
838 * If no element array buffer is bound, an INVALID_OPERATION error is
841 if (!_mesa_is_bufferobj(ctx
->Array
.VAO
->IndexBufferObj
)) {
842 _mesa_error(ctx
, GL_INVALID_OPERATION
,
843 "%s(no buffer bound to GL_ELEMENT_ARRAY_BUFFER)", name
);
847 return valid_draw_indirect(ctx
, mode
, indirect
, size
, name
);
850 static inline GLboolean
851 valid_draw_indirect_multi(struct gl_context
*ctx
,
852 GLsizei primcount
, GLsizei stride
,
856 /* From the ARB_multi_draw_indirect specification:
857 * "INVALID_VALUE is generated by MultiDrawArraysIndirect or
858 * MultiDrawElementsIndirect if <primcount> is negative."
860 * "<primcount> must be positive, otherwise an INVALID_VALUE error will
864 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(primcount < 0)", name
);
869 /* From the ARB_multi_draw_indirect specification:
870 * "<stride> must be a multiple of four, otherwise an INVALID_VALUE
871 * error is generated."
874 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(stride %% 4)", name
);
882 _mesa_validate_DrawArraysIndirect(struct gl_context
*ctx
,
884 const GLvoid
*indirect
)
886 const unsigned drawArraysNumParams
= 4;
888 FLUSH_CURRENT(ctx
, 0);
890 return valid_draw_indirect(ctx
, mode
,
891 indirect
, drawArraysNumParams
* sizeof(GLuint
),
892 "glDrawArraysIndirect");
896 _mesa_validate_DrawElementsIndirect(struct gl_context
*ctx
,
897 GLenum mode
, GLenum type
,
898 const GLvoid
*indirect
)
900 const unsigned drawElementsNumParams
= 5;
902 FLUSH_CURRENT(ctx
, 0);
904 return valid_draw_indirect_elements(ctx
, mode
, type
,
905 indirect
, drawElementsNumParams
* sizeof(GLuint
),
906 "glDrawElementsIndirect");
910 _mesa_validate_MultiDrawArraysIndirect(struct gl_context
*ctx
,
912 const GLvoid
*indirect
,
913 GLsizei primcount
, GLsizei stride
)
916 const unsigned drawArraysNumParams
= 4;
918 FLUSH_CURRENT(ctx
, 0);
920 /* caller has converted stride==0 to drawArraysNumParams * sizeof(GLuint) */
923 if (!valid_draw_indirect_multi(ctx
, primcount
, stride
,
924 "glMultiDrawArraysIndirect"))
927 /* number of bytes of the indirect buffer which will be read */
929 ? (primcount
- 1) * stride
+ drawArraysNumParams
* sizeof(GLuint
)
932 if (!valid_draw_indirect(ctx
, mode
, indirect
, size
,
933 "glMultiDrawArraysIndirect"))
940 _mesa_validate_MultiDrawElementsIndirect(struct gl_context
*ctx
,
941 GLenum mode
, GLenum type
,
942 const GLvoid
*indirect
,
943 GLsizei primcount
, GLsizei stride
)
946 const unsigned drawElementsNumParams
= 5;
948 FLUSH_CURRENT(ctx
, 0);
950 /* caller has converted stride==0 to drawElementsNumParams * sizeof(GLuint) */
953 if (!valid_draw_indirect_multi(ctx
, primcount
, stride
,
954 "glMultiDrawElementsIndirect"))
957 /* number of bytes of the indirect buffer which will be read */
959 ? (primcount
- 1) * stride
+ drawElementsNumParams
* sizeof(GLuint
)
962 if (!valid_draw_indirect_elements(ctx
, mode
, type
,
964 "glMultiDrawElementsIndirect"))