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"
39 #include "transformfeedback.h"
40 #include "shaderapi.h"
41 #include "shaderobj.h"
42 #include "main/dispatch.h"
44 #include "program/prog_parameter.h"
48 * Do reference counting of transform feedback buffers.
51 reference_transform_feedback_object(struct gl_transform_feedback_object
**ptr
,
52 struct gl_transform_feedback_object
*obj
)
58 /* Unreference the old object */
59 struct gl_transform_feedback_object
*oldObj
= *ptr
;
61 ASSERT(oldObj
->RefCount
> 0);
64 if (oldObj
->RefCount
== 0) {
65 GET_CURRENT_CONTEXT(ctx
);
67 ctx
->Driver
.DeleteTransformFeedback(ctx
, oldObj
);
75 /* reference new object */
76 if (obj
->RefCount
== 0) {
77 _mesa_problem(NULL
, "referencing deleted transform feedback object");
82 obj
->EverBound
= GL_TRUE
;
90 * Check that all the buffer objects currently bound for transform
91 * feedback actually exist. Raise a GL_INVALID_OPERATION error if
92 * any buffers are missing.
93 * \return GL_TRUE for success, GL_FALSE if error
96 _mesa_validate_transform_feedback_buffers(struct gl_context
*ctx
)
105 * Per-context init for transform feedback.
108 _mesa_init_transform_feedback(struct gl_context
*ctx
)
110 /* core mesa expects this, even a dummy one, to be available */
111 ASSERT(ctx
->Driver
.NewTransformFeedback
);
113 ctx
->TransformFeedback
.DefaultObject
=
114 ctx
->Driver
.NewTransformFeedback(ctx
, 0);
116 assert(ctx
->TransformFeedback
.DefaultObject
->RefCount
== 1);
118 reference_transform_feedback_object(&ctx
->TransformFeedback
.CurrentObject
,
119 ctx
->TransformFeedback
.DefaultObject
);
121 assert(ctx
->TransformFeedback
.DefaultObject
->RefCount
== 2);
123 ctx
->TransformFeedback
.Objects
= _mesa_NewHashTable();
125 _mesa_reference_buffer_object(ctx
,
126 &ctx
->TransformFeedback
.CurrentBuffer
,
127 ctx
->Shared
->NullBufferObj
);
133 * Callback for _mesa_HashDeleteAll().
136 delete_cb(GLuint key
, void *data
, void *userData
)
138 struct gl_context
*ctx
= (struct gl_context
*) userData
;
139 struct gl_transform_feedback_object
*obj
=
140 (struct gl_transform_feedback_object
*) data
;
142 ctx
->Driver
.DeleteTransformFeedback(ctx
, obj
);
147 * Per-context free/clean-up for transform feedback.
150 _mesa_free_transform_feedback(struct gl_context
*ctx
)
152 /* core mesa expects this, even a dummy one, to be available */
153 ASSERT(ctx
->Driver
.NewTransformFeedback
);
155 _mesa_reference_buffer_object(ctx
,
156 &ctx
->TransformFeedback
.CurrentBuffer
,
159 /* Delete all feedback objects */
160 _mesa_HashDeleteAll(ctx
->TransformFeedback
.Objects
, delete_cb
, ctx
);
161 _mesa_DeleteHashTable(ctx
->TransformFeedback
.Objects
);
163 /* Delete the default feedback object */
164 assert(ctx
->Driver
.DeleteTransformFeedback
);
165 ctx
->Driver
.DeleteTransformFeedback(ctx
,
166 ctx
->TransformFeedback
.DefaultObject
);
168 ctx
->TransformFeedback
.CurrentObject
= NULL
;
172 /** Default fallback for ctx->Driver.NewTransformFeedback() */
173 static struct gl_transform_feedback_object
*
174 new_transform_feedback(struct gl_context
*ctx
, GLuint name
)
176 struct gl_transform_feedback_object
*obj
;
177 obj
= CALLOC_STRUCT(gl_transform_feedback_object
);
181 obj
->EverBound
= GL_FALSE
;
186 /** Default fallback for ctx->Driver.DeleteTransformFeedback() */
188 delete_transform_feedback(struct gl_context
*ctx
,
189 struct gl_transform_feedback_object
*obj
)
193 for (i
= 0; i
< Elements(obj
->Buffers
); i
++) {
194 _mesa_reference_buffer_object(ctx
, &obj
->Buffers
[i
], NULL
);
201 /** Default fallback for ctx->Driver.BeginTransformFeedback() */
203 begin_transform_feedback(struct gl_context
*ctx
, GLenum mode
,
204 struct gl_transform_feedback_object
*obj
)
209 /** Default fallback for ctx->Driver.EndTransformFeedback() */
211 end_transform_feedback(struct gl_context
*ctx
,
212 struct gl_transform_feedback_object
*obj
)
217 /** Default fallback for ctx->Driver.PauseTransformFeedback() */
219 pause_transform_feedback(struct gl_context
*ctx
,
220 struct gl_transform_feedback_object
*obj
)
225 /** Default fallback for ctx->Driver.ResumeTransformFeedback() */
227 resume_transform_feedback(struct gl_context
*ctx
,
228 struct gl_transform_feedback_object
*obj
)
235 * Plug in default device driver functions for transform feedback.
236 * Most drivers will override some/all of these.
239 _mesa_init_transform_feedback_functions(struct dd_function_table
*driver
)
241 driver
->NewTransformFeedback
= new_transform_feedback
;
242 driver
->DeleteTransformFeedback
= delete_transform_feedback
;
243 driver
->BeginTransformFeedback
= begin_transform_feedback
;
244 driver
->EndTransformFeedback
= end_transform_feedback
;
245 driver
->PauseTransformFeedback
= pause_transform_feedback
;
246 driver
->ResumeTransformFeedback
= resume_transform_feedback
;
251 * Fill in the correct Size value for each buffer in \c obj.
253 * From the GL 4.3 spec, section 6.1.1 ("Binding Buffer Objects to Indexed
256 * BindBufferBase binds the entire buffer, even when the size of the buffer
257 * is changed after the binding is established. It is equivalent to calling
258 * BindBufferRange with offset zero, while size is determined by the size of
259 * the bound buffer at the time the binding is used.
261 * Regardless of the size specified with BindBufferRange, or indirectly with
262 * BindBufferBase, the GL will never read or write beyond the end of a bound
263 * buffer. In some cases this constraint may result in visibly different
264 * behavior when a buffer overflow would otherwise result, such as described
265 * for transform feedback operations in section 13.2.2.
268 compute_transform_feedback_buffer_sizes(
269 struct gl_transform_feedback_object
*obj
)
272 for (i
= 0; i
< MAX_FEEDBACK_BUFFERS
; ++i
) {
273 GLintptr offset
= obj
->Offset
[i
];
274 GLsizeiptr buffer_size
275 = obj
->Buffers
[i
] == NULL
? 0 : obj
->Buffers
[i
]->Size
;
276 GLsizeiptr available_space
277 = buffer_size
<= offset
? 0 : buffer_size
- offset
;
278 GLsizeiptr computed_size
;
279 if (obj
->RequestedSize
[i
] == 0) {
280 /* No size was specified at the time the buffer was bound, so allow
281 * writing to all available space in the buffer.
283 computed_size
= available_space
;
285 /* A size was specified at the time the buffer was bound, however
286 * it's possible that the buffer has shrunk since then. So only
287 * allow writing to the minimum of the specified size and the space
290 computed_size
= MIN2(available_space
, obj
->RequestedSize
[i
]);
293 /* Legal sizes must be multiples of four, so round down if necessary. */
294 obj
->Size
[i
] = computed_size
& ~0x3;
300 * Compute the maximum number of vertices that can be written to the currently
301 * enabled transform feedback buffers without overflowing any of them.
304 _mesa_compute_max_transform_feedback_vertices(
305 const struct gl_transform_feedback_object
*obj
,
306 const struct gl_transform_feedback_info
*info
)
308 unsigned max_index
= 0xffffffff;
311 for (i
= 0; i
< info
->NumBuffers
; ++i
) {
312 unsigned stride
= info
->BufferStride
[i
];
313 unsigned max_for_this_buffer
;
315 /* Skip any inactive buffers, which have a stride of 0. */
319 max_for_this_buffer
= obj
->Size
[i
] / (4 * stride
);
320 max_index
= MIN2(max_index
, max_for_this_buffer
);
328 ** Begin API functions
333 _mesa_BeginTransformFeedback(GLenum mode
)
335 struct gl_transform_feedback_object
*obj
;
336 struct gl_transform_feedback_info
*info
;
338 unsigned vertices_per_prim
;
339 GET_CURRENT_CONTEXT(ctx
);
341 obj
= ctx
->TransformFeedback
.CurrentObject
;
343 if (ctx
->Shader
.CurrentVertexProgram
== NULL
) {
344 _mesa_error(ctx
, GL_INVALID_OPERATION
,
345 "glBeginTransformFeedback(no program active)");
349 info
= &ctx
->Shader
.CurrentVertexProgram
->LinkedTransformFeedback
;
351 if (info
->NumOutputs
== 0) {
352 _mesa_error(ctx
, GL_INVALID_OPERATION
,
353 "glBeginTransformFeedback(no varyings to record)");
359 vertices_per_prim
= 1;
362 vertices_per_prim
= 2;
365 vertices_per_prim
= 3;
368 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBeginTransformFeedback(mode)");
373 _mesa_error(ctx
, GL_INVALID_OPERATION
,
374 "glBeginTransformFeedback(already active)");
378 for (i
= 0; i
< info
->NumBuffers
; ++i
) {
379 if (obj
->BufferNames
[i
] == 0) {
380 _mesa_error(ctx
, GL_INVALID_OPERATION
,
381 "glBeginTransformFeedback(binding point %d does not have "
382 "a buffer object bound)", i
);
387 FLUSH_VERTICES(ctx
, 0);
388 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewTransformFeedback
;
390 obj
->Active
= GL_TRUE
;
391 ctx
->TransformFeedback
.Mode
= mode
;
393 compute_transform_feedback_buffer_sizes(obj
);
395 if (_mesa_is_gles3(ctx
)) {
396 /* In GLES3, we are required to track the usage of the transform
397 * feedback buffer and report INVALID_OPERATION if a draw call tries to
398 * exceed it. So compute the maximum number of vertices that we can
399 * write without overflowing any of the buffers currently being used for
402 unsigned max_vertices
403 = _mesa_compute_max_transform_feedback_vertices(obj
, info
);
404 obj
->GlesRemainingPrims
= max_vertices
/ vertices_per_prim
;
407 assert(ctx
->Driver
.BeginTransformFeedback
);
408 ctx
->Driver
.BeginTransformFeedback(ctx
, mode
, obj
);
413 _mesa_EndTransformFeedback(void)
415 struct gl_transform_feedback_object
*obj
;
416 GET_CURRENT_CONTEXT(ctx
);
418 obj
= ctx
->TransformFeedback
.CurrentObject
;
421 _mesa_error(ctx
, GL_INVALID_OPERATION
,
422 "glEndTransformFeedback(not active)");
426 FLUSH_VERTICES(ctx
, 0);
427 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewTransformFeedback
;
429 ctx
->TransformFeedback
.CurrentObject
->Active
= GL_FALSE
;
430 ctx
->TransformFeedback
.CurrentObject
->Paused
= GL_FALSE
;
431 ctx
->TransformFeedback
.CurrentObject
->EndedAnytime
= GL_TRUE
;
433 assert(ctx
->Driver
.EndTransformFeedback
);
434 ctx
->Driver
.EndTransformFeedback(ctx
, obj
);
439 * Helper used by BindBufferRange() and BindBufferBase().
442 bind_buffer_range(struct gl_context
*ctx
, GLuint index
,
443 struct gl_buffer_object
*bufObj
,
444 GLintptr offset
, GLsizeiptr size
)
446 struct gl_transform_feedback_object
*obj
=
447 ctx
->TransformFeedback
.CurrentObject
;
449 /* Note: no need to FLUSH_VERTICES or flag NewTransformFeedback, because
450 * transform feedback buffers can't be changed while transform feedback is
454 /* The general binding point */
455 _mesa_reference_buffer_object(ctx
,
456 &ctx
->TransformFeedback
.CurrentBuffer
,
459 /* The per-attribute binding point */
460 _mesa_reference_buffer_object(ctx
,
461 &obj
->Buffers
[index
],
464 obj
->BufferNames
[index
] = bufObj
->Name
;
466 obj
->Offset
[index
] = offset
;
467 obj
->RequestedSize
[index
] = size
;
472 * Specify a buffer object to receive vertex shader results. Plus,
473 * specify the starting offset to place the results, and max size.
474 * Called from the glBindBufferRange() function.
477 _mesa_bind_buffer_range_transform_feedback(struct gl_context
*ctx
,
479 struct gl_buffer_object
*bufObj
,
483 struct gl_transform_feedback_object
*obj
;
485 obj
= ctx
->TransformFeedback
.CurrentObject
;
488 _mesa_error(ctx
, GL_INVALID_OPERATION
,
489 "glBindBufferRange(transform feedback active)");
493 if (index
>= ctx
->Const
.MaxTransformFeedbackBuffers
) {
494 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBindBufferRange(index=%d)", index
);
499 /* must a multiple of four */
500 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBindBufferRange(size=%d)", (int) size
);
505 /* must be multiple of four */
506 _mesa_error(ctx
, GL_INVALID_VALUE
,
507 "glBindBufferRange(offset=%d)", (int) offset
);
511 bind_buffer_range(ctx
, index
, bufObj
, offset
, size
);
516 * Specify a buffer object to receive vertex shader results.
517 * As above, but start at offset = 0.
518 * Called from the glBindBufferBase() function.
521 _mesa_bind_buffer_base_transform_feedback(struct gl_context
*ctx
,
523 struct gl_buffer_object
*bufObj
)
525 struct gl_transform_feedback_object
*obj
;
527 obj
= ctx
->TransformFeedback
.CurrentObject
;
530 _mesa_error(ctx
, GL_INVALID_OPERATION
,
531 "glBindBufferBase(transform feedback active)");
535 if (index
>= ctx
->Const
.MaxTransformFeedbackBuffers
) {
536 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBindBufferBase(index=%d)", index
);
540 bind_buffer_range(ctx
, index
, bufObj
, 0, 0);
545 * Specify a buffer object to receive vertex shader results, plus the
546 * offset in the buffer to start placing results.
547 * This function is part of GL_EXT_transform_feedback, but not GL3.
550 _mesa_BindBufferOffsetEXT(GLenum target
, GLuint index
, GLuint buffer
,
553 struct gl_transform_feedback_object
*obj
;
554 struct gl_buffer_object
*bufObj
;
555 GET_CURRENT_CONTEXT(ctx
);
557 if (target
!= GL_TRANSFORM_FEEDBACK_BUFFER
) {
558 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindBufferOffsetEXT(target)");
562 obj
= ctx
->TransformFeedback
.CurrentObject
;
565 _mesa_error(ctx
, GL_INVALID_OPERATION
,
566 "glBindBufferOffsetEXT(transform feedback active)");
570 if (index
>= ctx
->Const
.MaxTransformFeedbackBuffers
) {
571 _mesa_error(ctx
, GL_INVALID_VALUE
,
572 "glBindBufferOffsetEXT(index=%d)", index
);
577 /* must be multiple of four */
578 _mesa_error(ctx
, GL_INVALID_VALUE
,
579 "glBindBufferOffsetEXT(offset=%d)", (int) offset
);
584 bufObj
= ctx
->Shared
->NullBufferObj
;
586 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
590 _mesa_error(ctx
, GL_INVALID_OPERATION
,
591 "glBindBufferOffsetEXT(invalid buffer=%u)", buffer
);
595 bind_buffer_range(ctx
, index
, bufObj
, offset
, 0);
600 * This function specifies the vertex shader outputs to be written
601 * to the feedback buffer(s), and in what order.
604 _mesa_TransformFeedbackVaryings(GLuint program
, GLsizei count
,
605 const GLchar
* const *varyings
,
608 struct gl_shader_program
*shProg
;
610 GET_CURRENT_CONTEXT(ctx
);
612 switch (bufferMode
) {
613 case GL_INTERLEAVED_ATTRIBS
:
615 case GL_SEPARATE_ATTRIBS
:
618 _mesa_error(ctx
, GL_INVALID_ENUM
,
619 "glTransformFeedbackVaryings(bufferMode)");
624 (bufferMode
== GL_SEPARATE_ATTRIBS
&&
625 (GLuint
) count
> ctx
->Const
.MaxTransformFeedbackBuffers
)) {
626 _mesa_error(ctx
, GL_INVALID_VALUE
,
627 "glTransformFeedbackVaryings(count=%d)", count
);
631 shProg
= _mesa_lookup_shader_program(ctx
, program
);
633 _mesa_error(ctx
, GL_INVALID_VALUE
,
634 "glTransformFeedbackVaryings(program=%u)", program
);
638 if (ctx
->Extensions
.ARB_transform_feedback3
) {
639 if (bufferMode
== GL_INTERLEAVED_ATTRIBS
) {
640 unsigned buffers
= 1;
642 for (i
= 0; i
< count
; i
++) {
643 if (strcmp(varyings
[i
], "gl_NextBuffer") == 0)
647 if (buffers
> ctx
->Const
.MaxTransformFeedbackBuffers
) {
648 _mesa_error(ctx
, GL_INVALID_OPERATION
,
649 "glTransformFeedbackVaryings(too many gl_NextBuffer "
654 for (i
= 0; i
< count
; i
++) {
655 if (strcmp(varyings
[i
], "gl_NextBuffer") == 0 ||
656 strcmp(varyings
[i
], "gl_SkipComponents1") == 0 ||
657 strcmp(varyings
[i
], "gl_SkipComponents2") == 0 ||
658 strcmp(varyings
[i
], "gl_SkipComponents3") == 0 ||
659 strcmp(varyings
[i
], "gl_SkipComponents4") == 0) {
660 _mesa_error(ctx
, GL_INVALID_OPERATION
,
661 "glTransformFeedbackVaryings(SEPARATE_ATTRIBS,"
670 /* free existing varyings, if any */
671 for (i
= 0; i
< (GLint
) shProg
->TransformFeedback
.NumVarying
; i
++) {
672 free(shProg
->TransformFeedback
.VaryingNames
[i
]);
674 free(shProg
->TransformFeedback
.VaryingNames
);
676 /* allocate new memory for varying names */
677 shProg
->TransformFeedback
.VaryingNames
=
678 malloc(count
* sizeof(GLchar
*));
680 if (!shProg
->TransformFeedback
.VaryingNames
) {
681 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTransformFeedbackVaryings()");
685 /* Save the new names and the count */
686 for (i
= 0; i
< count
; i
++) {
687 shProg
->TransformFeedback
.VaryingNames
[i
] = _mesa_strdup(varyings
[i
]);
689 shProg
->TransformFeedback
.NumVarying
= count
;
691 shProg
->TransformFeedback
.BufferMode
= bufferMode
;
693 /* No need to invoke FLUSH_VERTICES or flag NewTransformFeedback since
694 * the varyings won't be used until shader link time.
700 * Get info about the vertex shader's outputs which are to be written
701 * to the feedback buffer(s).
704 _mesa_GetTransformFeedbackVarying(GLuint program
, GLuint index
,
705 GLsizei bufSize
, GLsizei
*length
,
706 GLsizei
*size
, GLenum
*type
, GLchar
*name
)
708 const struct gl_shader_program
*shProg
;
709 const struct gl_transform_feedback_info
*linked_xfb_info
;
710 GET_CURRENT_CONTEXT(ctx
);
712 shProg
= _mesa_lookup_shader_program(ctx
, program
);
714 _mesa_error(ctx
, GL_INVALID_VALUE
,
715 "glGetTransformFeedbackVarying(program=%u)", program
);
719 linked_xfb_info
= &shProg
->LinkedTransformFeedback
;
720 if (index
>= (GLuint
) linked_xfb_info
->NumVarying
) {
721 _mesa_error(ctx
, GL_INVALID_VALUE
,
722 "glGetTransformFeedbackVarying(index=%u)", index
);
726 /* return the varying's name and length */
727 _mesa_copy_string(name
, bufSize
, length
,
728 linked_xfb_info
->Varyings
[index
].Name
);
730 /* return the datatype and value's size (in datatype units) */
732 *type
= linked_xfb_info
->Varyings
[index
].Type
;
734 *size
= linked_xfb_info
->Varyings
[index
].Size
;
739 struct gl_transform_feedback_object
*
740 _mesa_lookup_transform_feedback_object(struct gl_context
*ctx
, GLuint name
)
743 return ctx
->TransformFeedback
.DefaultObject
;
746 return (struct gl_transform_feedback_object
*)
747 _mesa_HashLookup(ctx
->TransformFeedback
.Objects
, name
);
752 * Create new transform feedback objects. Transform feedback objects
753 * encapsulate the state related to transform feedback to allow quickly
754 * switching state (and drawing the results, below).
755 * Part of GL_ARB_transform_feedback2.
758 _mesa_GenTransformFeedbacks(GLsizei n
, GLuint
*names
)
761 GET_CURRENT_CONTEXT(ctx
);
764 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGenTransformFeedbacks(n < 0)");
771 /* we don't need contiguous IDs, but this might be faster */
772 first
= _mesa_HashFindFreeKeyBlock(ctx
->TransformFeedback
.Objects
, n
);
775 for (i
= 0; i
< n
; i
++) {
776 struct gl_transform_feedback_object
*obj
777 = ctx
->Driver
.NewTransformFeedback(ctx
, first
+ i
);
779 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glGenTransformFeedbacks");
782 names
[i
] = first
+ i
;
783 _mesa_HashInsert(ctx
->TransformFeedback
.Objects
, first
+ i
, obj
);
787 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glGenTransformFeedbacks");
793 * Is the given ID a transform feedback object?
794 * Part of GL_ARB_transform_feedback2.
797 _mesa_IsTransformFeedback(GLuint name
)
799 struct gl_transform_feedback_object
*obj
;
800 GET_CURRENT_CONTEXT(ctx
);
802 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
807 obj
= _mesa_lookup_transform_feedback_object(ctx
, name
);
811 return obj
->EverBound
;
816 * Bind the given transform feedback object.
817 * Part of GL_ARB_transform_feedback2.
820 _mesa_BindTransformFeedback(GLenum target
, GLuint name
)
822 struct gl_transform_feedback_object
*obj
;
823 GET_CURRENT_CONTEXT(ctx
);
825 if (target
!= GL_TRANSFORM_FEEDBACK
) {
826 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindTransformFeedback(target)");
830 if (_mesa_is_xfb_active_and_unpaused(ctx
)) {
831 _mesa_error(ctx
, GL_INVALID_OPERATION
,
832 "glBindTransformFeedback(transform is active, or not paused)");
836 obj
= _mesa_lookup_transform_feedback_object(ctx
, name
);
838 _mesa_error(ctx
, GL_INVALID_OPERATION
,
839 "glBindTransformFeedback(name=%u)", name
);
843 reference_transform_feedback_object(&ctx
->TransformFeedback
.CurrentObject
,
849 * Delete the given transform feedback objects.
850 * Part of GL_ARB_transform_feedback2.
853 _mesa_DeleteTransformFeedbacks(GLsizei n
, const GLuint
*names
)
856 GET_CURRENT_CONTEXT(ctx
);
859 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDeleteTransformFeedbacks(n < 0)");
866 for (i
= 0; i
< n
; i
++) {
868 struct gl_transform_feedback_object
*obj
869 = _mesa_lookup_transform_feedback_object(ctx
, names
[i
]);
872 _mesa_error(ctx
, GL_INVALID_OPERATION
,
873 "glDeleteTransformFeedbacks(object %u is active)",
877 _mesa_HashRemove(ctx
->TransformFeedback
.Objects
, names
[i
]);
878 /* unref, but object may not be deleted until later */
879 reference_transform_feedback_object(&obj
, NULL
);
887 * Pause transform feedback.
888 * Part of GL_ARB_transform_feedback2.
891 _mesa_PauseTransformFeedback(void)
893 struct gl_transform_feedback_object
*obj
;
894 GET_CURRENT_CONTEXT(ctx
);
896 obj
= ctx
->TransformFeedback
.CurrentObject
;
898 if (!_mesa_is_xfb_active_and_unpaused(ctx
)) {
899 _mesa_error(ctx
, GL_INVALID_OPERATION
,
900 "glPauseTransformFeedback(feedback not active or already paused)");
904 FLUSH_VERTICES(ctx
, 0);
905 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewTransformFeedback
;
907 obj
->Paused
= GL_TRUE
;
909 assert(ctx
->Driver
.PauseTransformFeedback
);
910 ctx
->Driver
.PauseTransformFeedback(ctx
, obj
);
915 * Resume transform feedback.
916 * Part of GL_ARB_transform_feedback2.
919 _mesa_ResumeTransformFeedback(void)
921 struct gl_transform_feedback_object
*obj
;
922 GET_CURRENT_CONTEXT(ctx
);
924 obj
= ctx
->TransformFeedback
.CurrentObject
;
926 if (!obj
->Active
|| !obj
->Paused
) {
927 _mesa_error(ctx
, GL_INVALID_OPERATION
,
928 "glResumeTransformFeedback(feedback not active or not paused)");
932 FLUSH_VERTICES(ctx
, 0);
933 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewTransformFeedback
;
935 obj
->Paused
= GL_FALSE
;
937 assert(ctx
->Driver
.ResumeTransformFeedback
);
938 ctx
->Driver
.ResumeTransformFeedback(ctx
, obj
);