2 * Mesa 3-D graphics library
4 * Copyright (C) 2010 VMware, Inc. 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 BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
20 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 * Vertex transform feedback support.
34 #include "bufferobj.h"
38 #include "mfeatures.h"
40 #include "transformfeedback.h"
41 #include "shaderapi.h"
42 #include "shaderobj.h"
43 #include "main/dispatch.h"
45 #include "program/prog_parameter.h"
49 * Do reference counting of transform feedback buffers.
52 reference_transform_feedback_object(struct gl_transform_feedback_object
**ptr
,
53 struct gl_transform_feedback_object
*obj
)
59 /* Unreference the old object */
60 struct gl_transform_feedback_object
*oldObj
= *ptr
;
62 ASSERT(oldObj
->RefCount
> 0);
65 if (oldObj
->RefCount
== 0) {
66 GET_CURRENT_CONTEXT(ctx
);
68 ctx
->Driver
.DeleteTransformFeedback(ctx
, oldObj
);
76 /* reference new object */
77 if (obj
->RefCount
== 0) {
78 _mesa_problem(NULL
, "referencing deleted transform feedback object");
83 obj
->EverBound
= GL_TRUE
;
91 * Check that all the buffer objects currently bound for transform
92 * feedback actually exist. Raise a GL_INVALID_OPERATION error if
93 * any buffers are missing.
94 * \return GL_TRUE for success, GL_FALSE if error
97 _mesa_validate_transform_feedback_buffers(struct gl_context
*ctx
)
106 * Per-context init for transform feedback.
109 _mesa_init_transform_feedback(struct gl_context
*ctx
)
111 /* core mesa expects this, even a dummy one, to be available */
112 ASSERT(ctx
->Driver
.NewTransformFeedback
);
114 ctx
->TransformFeedback
.DefaultObject
=
115 ctx
->Driver
.NewTransformFeedback(ctx
, 0);
117 assert(ctx
->TransformFeedback
.DefaultObject
->RefCount
== 1);
119 reference_transform_feedback_object(&ctx
->TransformFeedback
.CurrentObject
,
120 ctx
->TransformFeedback
.DefaultObject
);
122 assert(ctx
->TransformFeedback
.DefaultObject
->RefCount
== 2);
124 ctx
->TransformFeedback
.Objects
= _mesa_NewHashTable();
126 _mesa_reference_buffer_object(ctx
,
127 &ctx
->TransformFeedback
.CurrentBuffer
,
128 ctx
->Shared
->NullBufferObj
);
134 * Callback for _mesa_HashDeleteAll().
137 delete_cb(GLuint key
, void *data
, void *userData
)
139 struct gl_context
*ctx
= (struct gl_context
*) userData
;
140 struct gl_transform_feedback_object
*obj
=
141 (struct gl_transform_feedback_object
*) data
;
143 ctx
->Driver
.DeleteTransformFeedback(ctx
, obj
);
148 * Per-context free/clean-up for transform feedback.
151 _mesa_free_transform_feedback(struct gl_context
*ctx
)
153 /* core mesa expects this, even a dummy one, to be available */
154 ASSERT(ctx
->Driver
.NewTransformFeedback
);
156 _mesa_reference_buffer_object(ctx
,
157 &ctx
->TransformFeedback
.CurrentBuffer
,
160 /* Delete all feedback objects */
161 _mesa_HashDeleteAll(ctx
->TransformFeedback
.Objects
, delete_cb
, ctx
);
162 _mesa_DeleteHashTable(ctx
->TransformFeedback
.Objects
);
164 /* Delete the default feedback object */
165 assert(ctx
->Driver
.DeleteTransformFeedback
);
166 ctx
->Driver
.DeleteTransformFeedback(ctx
,
167 ctx
->TransformFeedback
.DefaultObject
);
169 ctx
->TransformFeedback
.CurrentObject
= NULL
;
173 /** Default fallback for ctx->Driver.NewTransformFeedback() */
174 static struct gl_transform_feedback_object
*
175 new_transform_feedback(struct gl_context
*ctx
, GLuint name
)
177 struct gl_transform_feedback_object
*obj
;
178 obj
= CALLOC_STRUCT(gl_transform_feedback_object
);
182 obj
->EverBound
= GL_FALSE
;
187 /** Default fallback for ctx->Driver.DeleteTransformFeedback() */
189 delete_transform_feedback(struct gl_context
*ctx
,
190 struct gl_transform_feedback_object
*obj
)
194 for (i
= 0; i
< Elements(obj
->Buffers
); i
++) {
195 _mesa_reference_buffer_object(ctx
, &obj
->Buffers
[i
], NULL
);
202 /** Default fallback for ctx->Driver.BeginTransformFeedback() */
204 begin_transform_feedback(struct gl_context
*ctx
, GLenum mode
,
205 struct gl_transform_feedback_object
*obj
)
210 /** Default fallback for ctx->Driver.EndTransformFeedback() */
212 end_transform_feedback(struct gl_context
*ctx
,
213 struct gl_transform_feedback_object
*obj
)
218 /** Default fallback for ctx->Driver.PauseTransformFeedback() */
220 pause_transform_feedback(struct gl_context
*ctx
,
221 struct gl_transform_feedback_object
*obj
)
226 /** Default fallback for ctx->Driver.ResumeTransformFeedback() */
228 resume_transform_feedback(struct gl_context
*ctx
,
229 struct gl_transform_feedback_object
*obj
)
236 * Plug in default device driver functions for transform feedback.
237 * Most drivers will override some/all of these.
240 _mesa_init_transform_feedback_functions(struct dd_function_table
*driver
)
242 driver
->NewTransformFeedback
= new_transform_feedback
;
243 driver
->DeleteTransformFeedback
= delete_transform_feedback
;
244 driver
->BeginTransformFeedback
= begin_transform_feedback
;
245 driver
->EndTransformFeedback
= end_transform_feedback
;
246 driver
->PauseTransformFeedback
= pause_transform_feedback
;
247 driver
->ResumeTransformFeedback
= resume_transform_feedback
;
252 * Fill in the correct Size value for each buffer in \c obj.
254 * From the GL 4.3 spec, section 6.1.1 ("Binding Buffer Objects to Indexed
257 * BindBufferBase binds the entire buffer, even when the size of the buffer
258 * is changed after the binding is established. It is equivalent to calling
259 * BindBufferRange with offset zero, while size is determined by the size of
260 * the bound buffer at the time the binding is used.
262 * Regardless of the size specified with BindBufferRange, or indirectly with
263 * BindBufferBase, the GL will never read or write beyond the end of a bound
264 * buffer. In some cases this constraint may result in visibly different
265 * behavior when a buffer overflow would otherwise result, such as described
266 * for transform feedback operations in section 13.2.2.
269 compute_transform_feedback_buffer_sizes(
270 struct gl_transform_feedback_object
*obj
)
273 for (i
= 0; i
< MAX_FEEDBACK_BUFFERS
; ++i
) {
274 GLintptr offset
= obj
->Offset
[i
];
275 GLsizeiptr buffer_size
276 = obj
->Buffers
[i
] == NULL
? 0 : obj
->Buffers
[i
]->Size
;
277 GLsizeiptr available_space
278 = buffer_size
<= offset
? 0 : buffer_size
- offset
;
279 GLsizeiptr computed_size
;
280 if (obj
->RequestedSize
[i
] == 0) {
281 /* No size was specified at the time the buffer was bound, so allow
282 * writing to all available space in the buffer.
284 computed_size
= available_space
;
286 /* A size was specified at the time the buffer was bound, however
287 * it's possible that the buffer has shrunk since then. So only
288 * allow writing to the minimum of the specified size and the space
291 computed_size
= MIN2(available_space
, obj
->RequestedSize
[i
]);
294 /* Legal sizes must be multiples of four, so round down if necessary. */
295 obj
->Size
[i
] = computed_size
& ~0x3;
301 * Compute the maximum number of vertices that can be written to the currently
302 * enabled transform feedback buffers without overflowing any of them.
305 _mesa_compute_max_transform_feedback_vertices(
306 const struct gl_transform_feedback_object
*obj
,
307 const struct gl_transform_feedback_info
*info
)
309 unsigned max_index
= 0xffffffff;
312 for (i
= 0; i
< info
->NumBuffers
; ++i
) {
313 unsigned stride
= info
->BufferStride
[i
];
314 unsigned max_for_this_buffer
;
316 /* Skip any inactive buffers, which have a stride of 0. */
320 max_for_this_buffer
= obj
->Size
[i
] / (4 * stride
);
321 max_index
= MIN2(max_index
, max_for_this_buffer
);
329 ** Begin API functions
334 _mesa_BeginTransformFeedback(GLenum mode
)
336 struct gl_transform_feedback_object
*obj
;
337 struct gl_transform_feedback_info
*info
;
339 unsigned vertices_per_prim
;
340 GET_CURRENT_CONTEXT(ctx
);
342 obj
= ctx
->TransformFeedback
.CurrentObject
;
344 if (ctx
->Shader
.CurrentVertexProgram
== NULL
) {
345 _mesa_error(ctx
, GL_INVALID_OPERATION
,
346 "glBeginTransformFeedback(no program active)");
350 info
= &ctx
->Shader
.CurrentVertexProgram
->LinkedTransformFeedback
;
352 if (info
->NumOutputs
== 0) {
353 _mesa_error(ctx
, GL_INVALID_OPERATION
,
354 "glBeginTransformFeedback(no varyings to record)");
360 vertices_per_prim
= 1;
363 vertices_per_prim
= 2;
366 vertices_per_prim
= 3;
369 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBeginTransformFeedback(mode)");
374 _mesa_error(ctx
, GL_INVALID_OPERATION
,
375 "glBeginTransformFeedback(already active)");
379 for (i
= 0; i
< info
->NumBuffers
; ++i
) {
380 if (obj
->BufferNames
[i
] == 0) {
381 _mesa_error(ctx
, GL_INVALID_OPERATION
,
382 "glBeginTransformFeedback(binding point %d does not have "
383 "a buffer object bound)", i
);
388 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM_FEEDBACK
);
389 obj
->Active
= GL_TRUE
;
390 ctx
->TransformFeedback
.Mode
= mode
;
392 compute_transform_feedback_buffer_sizes(obj
);
394 if (_mesa_is_gles3(ctx
)) {
395 /* In GLES3, we are required to track the usage of the transform
396 * feedback buffer and report INVALID_OPERATION if a draw call tries to
397 * exceed it. So compute the maximum number of vertices that we can
398 * write without overflowing any of the buffers currently being used for
401 unsigned max_vertices
402 = _mesa_compute_max_transform_feedback_vertices(obj
, info
);
403 obj
->GlesRemainingPrims
= max_vertices
/ vertices_per_prim
;
406 assert(ctx
->Driver
.BeginTransformFeedback
);
407 ctx
->Driver
.BeginTransformFeedback(ctx
, mode
, obj
);
412 _mesa_EndTransformFeedback(void)
414 struct gl_transform_feedback_object
*obj
;
415 GET_CURRENT_CONTEXT(ctx
);
417 obj
= ctx
->TransformFeedback
.CurrentObject
;
420 _mesa_error(ctx
, GL_INVALID_OPERATION
,
421 "glEndTransformFeedback(not active)");
425 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM_FEEDBACK
);
426 ctx
->TransformFeedback
.CurrentObject
->Active
= GL_FALSE
;
427 ctx
->TransformFeedback
.CurrentObject
->Paused
= GL_FALSE
;
428 ctx
->TransformFeedback
.CurrentObject
->EndedAnytime
= GL_TRUE
;
430 assert(ctx
->Driver
.EndTransformFeedback
);
431 ctx
->Driver
.EndTransformFeedback(ctx
, obj
);
436 * Helper used by BindBufferRange() and BindBufferBase().
439 bind_buffer_range(struct gl_context
*ctx
, GLuint index
,
440 struct gl_buffer_object
*bufObj
,
441 GLintptr offset
, GLsizeiptr size
)
443 struct gl_transform_feedback_object
*obj
=
444 ctx
->TransformFeedback
.CurrentObject
;
446 /* Note: no need to FLUSH_VERTICES or flag _NEW_TRANSFORM_FEEDBACK, because
447 * transform feedback buffers can't be changed while transform feedback is
451 /* The general binding point */
452 _mesa_reference_buffer_object(ctx
,
453 &ctx
->TransformFeedback
.CurrentBuffer
,
456 /* The per-attribute binding point */
457 _mesa_reference_buffer_object(ctx
,
458 &obj
->Buffers
[index
],
461 obj
->BufferNames
[index
] = bufObj
->Name
;
463 obj
->Offset
[index
] = offset
;
464 obj
->RequestedSize
[index
] = size
;
469 * Specify a buffer object to receive vertex shader results. Plus,
470 * specify the starting offset to place the results, and max size.
471 * Called from the glBindBufferRange() function.
474 _mesa_bind_buffer_range_transform_feedback(struct gl_context
*ctx
,
476 struct gl_buffer_object
*bufObj
,
480 struct gl_transform_feedback_object
*obj
;
482 obj
= ctx
->TransformFeedback
.CurrentObject
;
485 _mesa_error(ctx
, GL_INVALID_OPERATION
,
486 "glBindBufferRange(transform feedback active)");
490 if (index
>= ctx
->Const
.MaxTransformFeedbackBuffers
) {
491 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBindBufferRange(index=%d)", index
);
496 /* must a multiple of four */
497 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBindBufferRange(size=%d)", (int) size
);
502 /* must be multiple of four */
503 _mesa_error(ctx
, GL_INVALID_VALUE
,
504 "glBindBufferRange(offset=%d)", (int) offset
);
508 bind_buffer_range(ctx
, index
, bufObj
, offset
, size
);
513 * Specify a buffer object to receive vertex shader results.
514 * As above, but start at offset = 0.
515 * Called from the glBindBufferBase() function.
518 _mesa_bind_buffer_base_transform_feedback(struct gl_context
*ctx
,
520 struct gl_buffer_object
*bufObj
)
522 struct gl_transform_feedback_object
*obj
;
524 obj
= ctx
->TransformFeedback
.CurrentObject
;
527 _mesa_error(ctx
, GL_INVALID_OPERATION
,
528 "glBindBufferBase(transform feedback active)");
532 if (index
>= ctx
->Const
.MaxTransformFeedbackBuffers
) {
533 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBindBufferBase(index=%d)", index
);
537 bind_buffer_range(ctx
, index
, bufObj
, 0, 0);
542 * Specify a buffer object to receive vertex shader results, plus the
543 * offset in the buffer to start placing results.
544 * This function is part of GL_EXT_transform_feedback, but not GL3.
547 _mesa_BindBufferOffsetEXT(GLenum target
, GLuint index
, GLuint buffer
,
550 struct gl_transform_feedback_object
*obj
;
551 struct gl_buffer_object
*bufObj
;
552 GET_CURRENT_CONTEXT(ctx
);
554 if (target
!= GL_TRANSFORM_FEEDBACK_BUFFER
) {
555 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindBufferOffsetEXT(target)");
559 obj
= ctx
->TransformFeedback
.CurrentObject
;
562 _mesa_error(ctx
, GL_INVALID_OPERATION
,
563 "glBindBufferOffsetEXT(transform feedback active)");
567 if (index
>= ctx
->Const
.MaxTransformFeedbackBuffers
) {
568 _mesa_error(ctx
, GL_INVALID_VALUE
,
569 "glBindBufferOffsetEXT(index=%d)", index
);
574 /* must be multiple of four */
575 _mesa_error(ctx
, GL_INVALID_VALUE
,
576 "glBindBufferOffsetEXT(offset=%d)", (int) offset
);
581 bufObj
= ctx
->Shared
->NullBufferObj
;
583 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
587 _mesa_error(ctx
, GL_INVALID_OPERATION
,
588 "glBindBufferOffsetEXT(invalid buffer=%u)", buffer
);
592 bind_buffer_range(ctx
, index
, bufObj
, offset
, 0);
597 * This function specifies the vertex shader outputs to be written
598 * to the feedback buffer(s), and in what order.
601 _mesa_TransformFeedbackVaryings(GLuint program
, GLsizei count
,
602 const GLchar
* const *varyings
,
605 struct gl_shader_program
*shProg
;
607 GET_CURRENT_CONTEXT(ctx
);
609 switch (bufferMode
) {
610 case GL_INTERLEAVED_ATTRIBS
:
612 case GL_SEPARATE_ATTRIBS
:
615 _mesa_error(ctx
, GL_INVALID_ENUM
,
616 "glTransformFeedbackVaryings(bufferMode)");
621 (bufferMode
== GL_SEPARATE_ATTRIBS
&&
622 (GLuint
) count
> ctx
->Const
.MaxTransformFeedbackBuffers
)) {
623 _mesa_error(ctx
, GL_INVALID_VALUE
,
624 "glTransformFeedbackVaryings(count=%d)", count
);
628 shProg
= _mesa_lookup_shader_program(ctx
, program
);
630 _mesa_error(ctx
, GL_INVALID_VALUE
,
631 "glTransformFeedbackVaryings(program=%u)", program
);
635 if (ctx
->Extensions
.ARB_transform_feedback3
) {
636 if (bufferMode
== GL_INTERLEAVED_ATTRIBS
) {
637 unsigned buffers
= 1;
639 for (i
= 0; i
< count
; i
++) {
640 if (strcmp(varyings
[i
], "gl_NextBuffer") == 0)
644 if (buffers
> ctx
->Const
.MaxTransformFeedbackBuffers
) {
645 _mesa_error(ctx
, GL_INVALID_OPERATION
,
646 "glTransformFeedbackVaryings(too many gl_NextBuffer "
651 for (i
= 0; i
< count
; i
++) {
652 if (strcmp(varyings
[i
], "gl_NextBuffer") == 0 ||
653 strcmp(varyings
[i
], "gl_SkipComponents1") == 0 ||
654 strcmp(varyings
[i
], "gl_SkipComponents2") == 0 ||
655 strcmp(varyings
[i
], "gl_SkipComponents3") == 0 ||
656 strcmp(varyings
[i
], "gl_SkipComponents4") == 0) {
657 _mesa_error(ctx
, GL_INVALID_OPERATION
,
658 "glTransformFeedbackVaryings(SEPARATE_ATTRIBS,"
667 /* free existing varyings, if any */
668 for (i
= 0; i
< (GLint
) shProg
->TransformFeedback
.NumVarying
; i
++) {
669 free(shProg
->TransformFeedback
.VaryingNames
[i
]);
671 free(shProg
->TransformFeedback
.VaryingNames
);
673 /* allocate new memory for varying names */
674 shProg
->TransformFeedback
.VaryingNames
=
675 malloc(count
* sizeof(GLchar
*));
677 if (!shProg
->TransformFeedback
.VaryingNames
) {
678 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTransformFeedbackVaryings()");
682 /* Save the new names and the count */
683 for (i
= 0; i
< count
; i
++) {
684 shProg
->TransformFeedback
.VaryingNames
[i
] = _mesa_strdup(varyings
[i
]);
686 shProg
->TransformFeedback
.NumVarying
= count
;
688 shProg
->TransformFeedback
.BufferMode
= bufferMode
;
690 /* No need to set _NEW_TRANSFORM_FEEDBACK (or invoke FLUSH_VERTICES) since
691 * the varyings won't be used until shader link time.
697 * Get info about the vertex shader's outputs which are to be written
698 * to the feedback buffer(s).
701 _mesa_GetTransformFeedbackVarying(GLuint program
, GLuint index
,
702 GLsizei bufSize
, GLsizei
*length
,
703 GLsizei
*size
, GLenum
*type
, GLchar
*name
)
705 const struct gl_shader_program
*shProg
;
706 const struct gl_transform_feedback_info
*linked_xfb_info
;
707 GET_CURRENT_CONTEXT(ctx
);
709 shProg
= _mesa_lookup_shader_program(ctx
, program
);
711 _mesa_error(ctx
, GL_INVALID_VALUE
,
712 "glGetTransformFeedbackVarying(program=%u)", program
);
716 linked_xfb_info
= &shProg
->LinkedTransformFeedback
;
717 if (index
>= (GLuint
) linked_xfb_info
->NumVarying
) {
718 _mesa_error(ctx
, GL_INVALID_VALUE
,
719 "glGetTransformFeedbackVarying(index=%u)", index
);
723 /* return the varying's name and length */
724 _mesa_copy_string(name
, bufSize
, length
,
725 linked_xfb_info
->Varyings
[index
].Name
);
727 /* return the datatype and value's size (in datatype units) */
729 *type
= linked_xfb_info
->Varyings
[index
].Type
;
731 *size
= linked_xfb_info
->Varyings
[index
].Size
;
736 struct gl_transform_feedback_object
*
737 _mesa_lookup_transform_feedback_object(struct gl_context
*ctx
, GLuint name
)
740 return ctx
->TransformFeedback
.DefaultObject
;
743 return (struct gl_transform_feedback_object
*)
744 _mesa_HashLookup(ctx
->TransformFeedback
.Objects
, name
);
749 * Create new transform feedback objects. Transform feedback objects
750 * encapsulate the state related to transform feedback to allow quickly
751 * switching state (and drawing the results, below).
752 * Part of GL_ARB_transform_feedback2.
755 _mesa_GenTransformFeedbacks(GLsizei n
, GLuint
*names
)
758 GET_CURRENT_CONTEXT(ctx
);
761 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGenTransformFeedbacks(n < 0)");
768 /* we don't need contiguous IDs, but this might be faster */
769 first
= _mesa_HashFindFreeKeyBlock(ctx
->TransformFeedback
.Objects
, n
);
772 for (i
= 0; i
< n
; i
++) {
773 struct gl_transform_feedback_object
*obj
774 = ctx
->Driver
.NewTransformFeedback(ctx
, first
+ i
);
776 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glGenTransformFeedbacks");
779 names
[i
] = first
+ i
;
780 _mesa_HashInsert(ctx
->TransformFeedback
.Objects
, first
+ i
, obj
);
784 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glGenTransformFeedbacks");
790 * Is the given ID a transform feedback object?
791 * Part of GL_ARB_transform_feedback2.
794 _mesa_IsTransformFeedback(GLuint name
)
796 struct gl_transform_feedback_object
*obj
;
797 GET_CURRENT_CONTEXT(ctx
);
799 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
804 obj
= _mesa_lookup_transform_feedback_object(ctx
, name
);
808 return obj
->EverBound
;
813 * Bind the given transform feedback object.
814 * Part of GL_ARB_transform_feedback2.
817 _mesa_BindTransformFeedback(GLenum target
, GLuint name
)
819 struct gl_transform_feedback_object
*obj
;
820 GET_CURRENT_CONTEXT(ctx
);
822 if (target
!= GL_TRANSFORM_FEEDBACK
) {
823 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindTransformFeedback(target)");
827 if (_mesa_is_xfb_active_and_unpaused(ctx
)) {
828 _mesa_error(ctx
, GL_INVALID_OPERATION
,
829 "glBindTransformFeedback(transform is active, or not paused)");
833 obj
= _mesa_lookup_transform_feedback_object(ctx
, name
);
835 _mesa_error(ctx
, GL_INVALID_OPERATION
,
836 "glBindTransformFeedback(name=%u)", name
);
840 reference_transform_feedback_object(&ctx
->TransformFeedback
.CurrentObject
,
846 * Delete the given transform feedback objects.
847 * Part of GL_ARB_transform_feedback2.
850 _mesa_DeleteTransformFeedbacks(GLsizei n
, const GLuint
*names
)
853 GET_CURRENT_CONTEXT(ctx
);
856 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDeleteTransformFeedbacks(n < 0)");
863 for (i
= 0; i
< n
; i
++) {
865 struct gl_transform_feedback_object
*obj
866 = _mesa_lookup_transform_feedback_object(ctx
, names
[i
]);
869 _mesa_error(ctx
, GL_INVALID_OPERATION
,
870 "glDeleteTransformFeedbacks(object %u is active)",
874 _mesa_HashRemove(ctx
->TransformFeedback
.Objects
, names
[i
]);
875 /* unref, but object may not be deleted until later */
876 reference_transform_feedback_object(&obj
, NULL
);
884 * Pause transform feedback.
885 * Part of GL_ARB_transform_feedback2.
888 _mesa_PauseTransformFeedback(void)
890 struct gl_transform_feedback_object
*obj
;
891 GET_CURRENT_CONTEXT(ctx
);
893 obj
= ctx
->TransformFeedback
.CurrentObject
;
895 if (!_mesa_is_xfb_active_and_unpaused(ctx
)) {
896 _mesa_error(ctx
, GL_INVALID_OPERATION
,
897 "glPauseTransformFeedback(feedback not active or already paused)");
901 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM_FEEDBACK
);
902 obj
->Paused
= GL_TRUE
;
904 assert(ctx
->Driver
.PauseTransformFeedback
);
905 ctx
->Driver
.PauseTransformFeedback(ctx
, obj
);
910 * Resume transform feedback.
911 * Part of GL_ARB_transform_feedback2.
914 _mesa_ResumeTransformFeedback(void)
916 struct gl_transform_feedback_object
*obj
;
917 GET_CURRENT_CONTEXT(ctx
);
919 obj
= ctx
->TransformFeedback
.CurrentObject
;
921 if (!obj
->Active
|| !obj
->Paused
) {
922 _mesa_error(ctx
, GL_INVALID_OPERATION
,
923 "glResumeTransformFeedback(feedback not active or not paused)");
927 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM_FEEDBACK
);
928 obj
->Paused
= GL_FALSE
;
930 assert(ctx
->Driver
.ResumeTransformFeedback
);
931 ctx
->Driver
.ResumeTransformFeedback(ctx
, obj
);