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 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 * Vertex transform feedback support.
35 #include "bufferobj.h"
40 #include "transformfeedback.h"
41 #include "shaderapi.h"
42 #include "shaderobj.h"
43 #include "main/dispatch.h"
45 #include "program/prog_parameter.h"
47 struct using_program_tuple
49 struct gl_shader_program
*shProg
;
54 active_xfb_object_references_program(GLuint key
, void *data
, void *user_data
)
56 struct using_program_tuple
*callback_data
= user_data
;
57 struct gl_transform_feedback_object
*obj
= data
;
58 if (obj
->Active
&& obj
->shader_program
== callback_data
->shProg
)
59 callback_data
->found
= true;
63 * Return true if any active transform feedback object is using a program.
66 _mesa_transform_feedback_is_using_program(struct gl_context
*ctx
,
67 struct gl_shader_program
*shProg
)
69 struct using_program_tuple callback_data
;
70 callback_data
.shProg
= shProg
;
71 callback_data
.found
= false;
73 _mesa_HashWalk(ctx
->TransformFeedback
.Objects
,
74 active_xfb_object_references_program
, &callback_data
);
76 /* Also check DefaultObject, as it's not in the Objects hash table. */
77 active_xfb_object_references_program(0, ctx
->TransformFeedback
.DefaultObject
,
80 return callback_data
.found
;
84 * Do reference counting of transform feedback buffers.
87 reference_transform_feedback_object(struct gl_transform_feedback_object
**ptr
,
88 struct gl_transform_feedback_object
*obj
)
94 /* Unreference the old object */
95 struct gl_transform_feedback_object
*oldObj
= *ptr
;
97 ASSERT(oldObj
->RefCount
> 0);
100 if (oldObj
->RefCount
== 0) {
101 GET_CURRENT_CONTEXT(ctx
);
103 ctx
->Driver
.DeleteTransformFeedback(ctx
, oldObj
);
111 /* reference new object */
112 if (obj
->RefCount
== 0) {
113 _mesa_problem(NULL
, "referencing deleted transform feedback object");
118 obj
->EverBound
= GL_TRUE
;
126 * Check that all the buffer objects currently bound for transform
127 * feedback actually exist. Raise a GL_INVALID_OPERATION error if
128 * any buffers are missing.
129 * \return GL_TRUE for success, GL_FALSE if error
132 _mesa_validate_transform_feedback_buffers(struct gl_context
*ctx
)
141 * Per-context init for transform feedback.
144 _mesa_init_transform_feedback(struct gl_context
*ctx
)
146 /* core mesa expects this, even a dummy one, to be available */
147 ASSERT(ctx
->Driver
.NewTransformFeedback
);
149 ctx
->TransformFeedback
.DefaultObject
=
150 ctx
->Driver
.NewTransformFeedback(ctx
, 0);
152 assert(ctx
->TransformFeedback
.DefaultObject
->RefCount
== 1);
154 reference_transform_feedback_object(&ctx
->TransformFeedback
.CurrentObject
,
155 ctx
->TransformFeedback
.DefaultObject
);
157 assert(ctx
->TransformFeedback
.DefaultObject
->RefCount
== 2);
159 ctx
->TransformFeedback
.Objects
= _mesa_NewHashTable();
161 _mesa_reference_buffer_object(ctx
,
162 &ctx
->TransformFeedback
.CurrentBuffer
,
163 ctx
->Shared
->NullBufferObj
);
169 * Callback for _mesa_HashDeleteAll().
172 delete_cb(GLuint key
, void *data
, void *userData
)
174 struct gl_context
*ctx
= (struct gl_context
*) userData
;
175 struct gl_transform_feedback_object
*obj
=
176 (struct gl_transform_feedback_object
*) data
;
178 ctx
->Driver
.DeleteTransformFeedback(ctx
, obj
);
183 * Per-context free/clean-up for transform feedback.
186 _mesa_free_transform_feedback(struct gl_context
*ctx
)
188 /* core mesa expects this, even a dummy one, to be available */
189 ASSERT(ctx
->Driver
.NewTransformFeedback
);
191 _mesa_reference_buffer_object(ctx
,
192 &ctx
->TransformFeedback
.CurrentBuffer
,
195 /* Delete all feedback objects */
196 _mesa_HashDeleteAll(ctx
->TransformFeedback
.Objects
, delete_cb
, ctx
);
197 _mesa_DeleteHashTable(ctx
->TransformFeedback
.Objects
);
199 /* Delete the default feedback object */
200 assert(ctx
->Driver
.DeleteTransformFeedback
);
201 ctx
->Driver
.DeleteTransformFeedback(ctx
,
202 ctx
->TransformFeedback
.DefaultObject
);
204 ctx
->TransformFeedback
.CurrentObject
= NULL
;
208 /** Initialize the fields of a gl_transform_feedback_object. */
210 _mesa_init_transform_feedback_object(struct gl_transform_feedback_object
*obj
,
218 obj
->EverBound
= GL_FALSE
;
222 /** Default fallback for ctx->Driver.NewTransformFeedback() */
223 static struct gl_transform_feedback_object
*
224 new_transform_feedback(struct gl_context
*ctx
, GLuint name
)
226 struct gl_transform_feedback_object
*obj
;
227 obj
= CALLOC_STRUCT(gl_transform_feedback_object
);
228 _mesa_init_transform_feedback_object(obj
, name
);
232 /** Default fallback for ctx->Driver.DeleteTransformFeedback() */
234 delete_transform_feedback(struct gl_context
*ctx
,
235 struct gl_transform_feedback_object
*obj
)
239 for (i
= 0; i
< Elements(obj
->Buffers
); i
++) {
240 _mesa_reference_buffer_object(ctx
, &obj
->Buffers
[i
], NULL
);
248 /** Default fallback for ctx->Driver.BeginTransformFeedback() */
250 begin_transform_feedback(struct gl_context
*ctx
, GLenum mode
,
251 struct gl_transform_feedback_object
*obj
)
256 /** Default fallback for ctx->Driver.EndTransformFeedback() */
258 end_transform_feedback(struct gl_context
*ctx
,
259 struct gl_transform_feedback_object
*obj
)
264 /** Default fallback for ctx->Driver.PauseTransformFeedback() */
266 pause_transform_feedback(struct gl_context
*ctx
,
267 struct gl_transform_feedback_object
*obj
)
272 /** Default fallback for ctx->Driver.ResumeTransformFeedback() */
274 resume_transform_feedback(struct gl_context
*ctx
,
275 struct gl_transform_feedback_object
*obj
)
282 * Plug in default device driver functions for transform feedback.
283 * Most drivers will override some/all of these.
286 _mesa_init_transform_feedback_functions(struct dd_function_table
*driver
)
288 driver
->NewTransformFeedback
= new_transform_feedback
;
289 driver
->DeleteTransformFeedback
= delete_transform_feedback
;
290 driver
->BeginTransformFeedback
= begin_transform_feedback
;
291 driver
->EndTransformFeedback
= end_transform_feedback
;
292 driver
->PauseTransformFeedback
= pause_transform_feedback
;
293 driver
->ResumeTransformFeedback
= resume_transform_feedback
;
298 * Fill in the correct Size value for each buffer in \c obj.
300 * From the GL 4.3 spec, section 6.1.1 ("Binding Buffer Objects to Indexed
303 * BindBufferBase binds the entire buffer, even when the size of the buffer
304 * is changed after the binding is established. It is equivalent to calling
305 * BindBufferRange with offset zero, while size is determined by the size of
306 * the bound buffer at the time the binding is used.
308 * Regardless of the size specified with BindBufferRange, or indirectly with
309 * BindBufferBase, the GL will never read or write beyond the end of a bound
310 * buffer. In some cases this constraint may result in visibly different
311 * behavior when a buffer overflow would otherwise result, such as described
312 * for transform feedback operations in section 13.2.2.
315 compute_transform_feedback_buffer_sizes(
316 struct gl_transform_feedback_object
*obj
)
319 for (i
= 0; i
< MAX_FEEDBACK_BUFFERS
; ++i
) {
320 GLintptr offset
= obj
->Offset
[i
];
321 GLsizeiptr buffer_size
322 = obj
->Buffers
[i
] == NULL
? 0 : obj
->Buffers
[i
]->Size
;
323 GLsizeiptr available_space
324 = buffer_size
<= offset
? 0 : buffer_size
- offset
;
325 GLsizeiptr computed_size
;
326 if (obj
->RequestedSize
[i
] == 0) {
327 /* No size was specified at the time the buffer was bound, so allow
328 * writing to all available space in the buffer.
330 computed_size
= available_space
;
332 /* A size was specified at the time the buffer was bound, however
333 * it's possible that the buffer has shrunk since then. So only
334 * allow writing to the minimum of the specified size and the space
337 computed_size
= MIN2(available_space
, obj
->RequestedSize
[i
]);
340 /* Legal sizes must be multiples of four, so round down if necessary. */
341 obj
->Size
[i
] = computed_size
& ~0x3;
347 * Compute the maximum number of vertices that can be written to the currently
348 * enabled transform feedback buffers without overflowing any of them.
351 _mesa_compute_max_transform_feedback_vertices(
352 const struct gl_transform_feedback_object
*obj
,
353 const struct gl_transform_feedback_info
*info
)
355 unsigned max_index
= 0xffffffff;
358 for (i
= 0; i
< info
->NumBuffers
; ++i
) {
359 unsigned stride
= info
->BufferStride
[i
];
360 unsigned max_for_this_buffer
;
362 /* Skip any inactive buffers, which have a stride of 0. */
366 max_for_this_buffer
= obj
->Size
[i
] / (4 * stride
);
367 max_index
= MIN2(max_index
, max_for_this_buffer
);
375 ** Begin API functions
380 _mesa_BeginTransformFeedback(GLenum mode
)
382 struct gl_transform_feedback_object
*obj
;
383 struct gl_transform_feedback_info
*info
;
385 unsigned vertices_per_prim
;
386 GET_CURRENT_CONTEXT(ctx
);
388 obj
= ctx
->TransformFeedback
.CurrentObject
;
390 if (ctx
->Shader
.CurrentProgram
[MESA_SHADER_VERTEX
] == NULL
) {
391 _mesa_error(ctx
, GL_INVALID_OPERATION
,
392 "glBeginTransformFeedback(no program active)");
396 info
= &ctx
->Shader
.CurrentProgram
[MESA_SHADER_VERTEX
]->LinkedTransformFeedback
;
398 if (info
->NumOutputs
== 0) {
399 _mesa_error(ctx
, GL_INVALID_OPERATION
,
400 "glBeginTransformFeedback(no varyings to record)");
406 vertices_per_prim
= 1;
409 vertices_per_prim
= 2;
412 vertices_per_prim
= 3;
415 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBeginTransformFeedback(mode)");
420 _mesa_error(ctx
, GL_INVALID_OPERATION
,
421 "glBeginTransformFeedback(already active)");
425 for (i
= 0; i
< info
->NumBuffers
; ++i
) {
426 if (obj
->BufferNames
[i
] == 0) {
427 _mesa_error(ctx
, GL_INVALID_OPERATION
,
428 "glBeginTransformFeedback(binding point %d does not have "
429 "a buffer object bound)", i
);
434 FLUSH_VERTICES(ctx
, 0);
435 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewTransformFeedback
;
437 obj
->Active
= GL_TRUE
;
438 ctx
->TransformFeedback
.Mode
= mode
;
440 compute_transform_feedback_buffer_sizes(obj
);
442 if (_mesa_is_gles3(ctx
)) {
443 /* In GLES3, we are required to track the usage of the transform
444 * feedback buffer and report INVALID_OPERATION if a draw call tries to
445 * exceed it. So compute the maximum number of vertices that we can
446 * write without overflowing any of the buffers currently being used for
449 unsigned max_vertices
450 = _mesa_compute_max_transform_feedback_vertices(obj
, info
);
451 obj
->GlesRemainingPrims
= max_vertices
/ vertices_per_prim
;
454 obj
->shader_program
= ctx
->Shader
.CurrentProgram
[MESA_SHADER_VERTEX
];
456 assert(ctx
->Driver
.BeginTransformFeedback
);
457 ctx
->Driver
.BeginTransformFeedback(ctx
, mode
, obj
);
462 _mesa_EndTransformFeedback(void)
464 struct gl_transform_feedback_object
*obj
;
465 GET_CURRENT_CONTEXT(ctx
);
467 obj
= ctx
->TransformFeedback
.CurrentObject
;
470 _mesa_error(ctx
, GL_INVALID_OPERATION
,
471 "glEndTransformFeedback(not active)");
475 FLUSH_VERTICES(ctx
, 0);
476 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewTransformFeedback
;
478 ctx
->TransformFeedback
.CurrentObject
->Active
= GL_FALSE
;
479 ctx
->TransformFeedback
.CurrentObject
->Paused
= GL_FALSE
;
480 ctx
->TransformFeedback
.CurrentObject
->EndedAnytime
= GL_TRUE
;
482 assert(ctx
->Driver
.EndTransformFeedback
);
483 ctx
->Driver
.EndTransformFeedback(ctx
, obj
);
488 * Helper used by BindBufferRange() and BindBufferBase().
491 bind_buffer_range(struct gl_context
*ctx
, GLuint index
,
492 struct gl_buffer_object
*bufObj
,
493 GLintptr offset
, GLsizeiptr size
)
495 struct gl_transform_feedback_object
*obj
=
496 ctx
->TransformFeedback
.CurrentObject
;
498 /* Note: no need to FLUSH_VERTICES or flag NewTransformFeedback, because
499 * transform feedback buffers can't be changed while transform feedback is
503 /* The general binding point */
504 _mesa_reference_buffer_object(ctx
,
505 &ctx
->TransformFeedback
.CurrentBuffer
,
508 /* The per-attribute binding point */
509 _mesa_reference_buffer_object(ctx
,
510 &obj
->Buffers
[index
],
513 obj
->BufferNames
[index
] = bufObj
->Name
;
515 obj
->Offset
[index
] = offset
;
516 obj
->RequestedSize
[index
] = size
;
521 * Specify a buffer object to receive vertex shader results. Plus,
522 * specify the starting offset to place the results, and max size.
523 * Called from the glBindBufferRange() function.
526 _mesa_bind_buffer_range_transform_feedback(struct gl_context
*ctx
,
528 struct gl_buffer_object
*bufObj
,
532 struct gl_transform_feedback_object
*obj
;
534 obj
= ctx
->TransformFeedback
.CurrentObject
;
537 _mesa_error(ctx
, GL_INVALID_OPERATION
,
538 "glBindBufferRange(transform feedback active)");
542 if (index
>= ctx
->Const
.MaxTransformFeedbackBuffers
) {
543 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBindBufferRange(index=%d)", index
);
548 /* must a multiple of four */
549 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBindBufferRange(size=%d)", (int) size
);
554 /* must be multiple of four */
555 _mesa_error(ctx
, GL_INVALID_VALUE
,
556 "glBindBufferRange(offset=%d)", (int) offset
);
560 bind_buffer_range(ctx
, index
, bufObj
, offset
, size
);
565 * Specify a buffer object to receive vertex shader results.
566 * As above, but start at offset = 0.
567 * Called from the glBindBufferBase() function.
570 _mesa_bind_buffer_base_transform_feedback(struct gl_context
*ctx
,
572 struct gl_buffer_object
*bufObj
)
574 struct gl_transform_feedback_object
*obj
;
576 obj
= ctx
->TransformFeedback
.CurrentObject
;
579 _mesa_error(ctx
, GL_INVALID_OPERATION
,
580 "glBindBufferBase(transform feedback active)");
584 if (index
>= ctx
->Const
.MaxTransformFeedbackBuffers
) {
585 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBindBufferBase(index=%d)", index
);
589 bind_buffer_range(ctx
, index
, bufObj
, 0, 0);
594 * Specify a buffer object to receive vertex shader results, plus the
595 * offset in the buffer to start placing results.
596 * This function is part of GL_EXT_transform_feedback, but not GL3.
599 _mesa_BindBufferOffsetEXT(GLenum target
, GLuint index
, GLuint buffer
,
602 struct gl_transform_feedback_object
*obj
;
603 struct gl_buffer_object
*bufObj
;
604 GET_CURRENT_CONTEXT(ctx
);
606 if (target
!= GL_TRANSFORM_FEEDBACK_BUFFER
) {
607 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindBufferOffsetEXT(target)");
611 obj
= ctx
->TransformFeedback
.CurrentObject
;
614 _mesa_error(ctx
, GL_INVALID_OPERATION
,
615 "glBindBufferOffsetEXT(transform feedback active)");
619 if (index
>= ctx
->Const
.MaxTransformFeedbackBuffers
) {
620 _mesa_error(ctx
, GL_INVALID_VALUE
,
621 "glBindBufferOffsetEXT(index=%d)", index
);
626 /* must be multiple of four */
627 _mesa_error(ctx
, GL_INVALID_VALUE
,
628 "glBindBufferOffsetEXT(offset=%d)", (int) offset
);
633 bufObj
= ctx
->Shared
->NullBufferObj
;
635 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
639 _mesa_error(ctx
, GL_INVALID_OPERATION
,
640 "glBindBufferOffsetEXT(invalid buffer=%u)", buffer
);
644 bind_buffer_range(ctx
, index
, bufObj
, offset
, 0);
649 * This function specifies the vertex shader outputs to be written
650 * to the feedback buffer(s), and in what order.
653 _mesa_TransformFeedbackVaryings(GLuint program
, GLsizei count
,
654 const GLchar
* const *varyings
,
657 struct gl_shader_program
*shProg
;
659 GET_CURRENT_CONTEXT(ctx
);
661 /* From the ARB_transform_feedback2 specification:
662 * "The error INVALID_OPERATION is generated by TransformFeedbackVaryings
663 * if the current transform feedback object is active, even if paused."
665 if (ctx
->TransformFeedback
.CurrentObject
->Active
) {
666 _mesa_error(ctx
, GL_INVALID_OPERATION
,
667 "glTransformFeedbackVaryings(current object is active)");
671 switch (bufferMode
) {
672 case GL_INTERLEAVED_ATTRIBS
:
674 case GL_SEPARATE_ATTRIBS
:
677 _mesa_error(ctx
, GL_INVALID_ENUM
,
678 "glTransformFeedbackVaryings(bufferMode)");
683 (bufferMode
== GL_SEPARATE_ATTRIBS
&&
684 (GLuint
) count
> ctx
->Const
.MaxTransformFeedbackBuffers
)) {
685 _mesa_error(ctx
, GL_INVALID_VALUE
,
686 "glTransformFeedbackVaryings(count=%d)", count
);
690 shProg
= _mesa_lookup_shader_program(ctx
, program
);
692 _mesa_error(ctx
, GL_INVALID_VALUE
,
693 "glTransformFeedbackVaryings(program=%u)", program
);
697 if (ctx
->Extensions
.ARB_transform_feedback3
) {
698 if (bufferMode
== GL_INTERLEAVED_ATTRIBS
) {
699 unsigned buffers
= 1;
701 for (i
= 0; i
< count
; i
++) {
702 if (strcmp(varyings
[i
], "gl_NextBuffer") == 0)
706 if (buffers
> ctx
->Const
.MaxTransformFeedbackBuffers
) {
707 _mesa_error(ctx
, GL_INVALID_OPERATION
,
708 "glTransformFeedbackVaryings(too many gl_NextBuffer "
713 for (i
= 0; i
< count
; i
++) {
714 if (strcmp(varyings
[i
], "gl_NextBuffer") == 0 ||
715 strcmp(varyings
[i
], "gl_SkipComponents1") == 0 ||
716 strcmp(varyings
[i
], "gl_SkipComponents2") == 0 ||
717 strcmp(varyings
[i
], "gl_SkipComponents3") == 0 ||
718 strcmp(varyings
[i
], "gl_SkipComponents4") == 0) {
719 _mesa_error(ctx
, GL_INVALID_OPERATION
,
720 "glTransformFeedbackVaryings(SEPARATE_ATTRIBS,"
729 /* free existing varyings, if any */
730 for (i
= 0; i
< (GLint
) shProg
->TransformFeedback
.NumVarying
; i
++) {
731 free(shProg
->TransformFeedback
.VaryingNames
[i
]);
733 free(shProg
->TransformFeedback
.VaryingNames
);
735 /* allocate new memory for varying names */
736 shProg
->TransformFeedback
.VaryingNames
=
737 malloc(count
* sizeof(GLchar
*));
739 if (!shProg
->TransformFeedback
.VaryingNames
) {
740 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTransformFeedbackVaryings()");
744 /* Save the new names and the count */
745 for (i
= 0; i
< count
; i
++) {
746 shProg
->TransformFeedback
.VaryingNames
[i
] = _mesa_strdup(varyings
[i
]);
748 shProg
->TransformFeedback
.NumVarying
= count
;
750 shProg
->TransformFeedback
.BufferMode
= bufferMode
;
752 /* No need to invoke FLUSH_VERTICES or flag NewTransformFeedback since
753 * the varyings won't be used until shader link time.
759 * Get info about the vertex shader's outputs which are to be written
760 * to the feedback buffer(s).
763 _mesa_GetTransformFeedbackVarying(GLuint program
, GLuint index
,
764 GLsizei bufSize
, GLsizei
*length
,
765 GLsizei
*size
, GLenum
*type
, GLchar
*name
)
767 const struct gl_shader_program
*shProg
;
768 const struct gl_transform_feedback_info
*linked_xfb_info
;
769 GET_CURRENT_CONTEXT(ctx
);
771 shProg
= _mesa_lookup_shader_program(ctx
, program
);
773 _mesa_error(ctx
, GL_INVALID_VALUE
,
774 "glGetTransformFeedbackVarying(program=%u)", program
);
778 linked_xfb_info
= &shProg
->LinkedTransformFeedback
;
779 if (index
>= (GLuint
) linked_xfb_info
->NumVarying
) {
780 _mesa_error(ctx
, GL_INVALID_VALUE
,
781 "glGetTransformFeedbackVarying(index=%u)", index
);
785 /* return the varying's name and length */
786 _mesa_copy_string(name
, bufSize
, length
,
787 linked_xfb_info
->Varyings
[index
].Name
);
789 /* return the datatype and value's size (in datatype units) */
791 *type
= linked_xfb_info
->Varyings
[index
].Type
;
793 *size
= linked_xfb_info
->Varyings
[index
].Size
;
798 struct gl_transform_feedback_object
*
799 _mesa_lookup_transform_feedback_object(struct gl_context
*ctx
, GLuint name
)
802 return ctx
->TransformFeedback
.DefaultObject
;
805 return (struct gl_transform_feedback_object
*)
806 _mesa_HashLookup(ctx
->TransformFeedback
.Objects
, name
);
811 * Create new transform feedback objects. Transform feedback objects
812 * encapsulate the state related to transform feedback to allow quickly
813 * switching state (and drawing the results, below).
814 * Part of GL_ARB_transform_feedback2.
817 _mesa_GenTransformFeedbacks(GLsizei n
, GLuint
*names
)
820 GET_CURRENT_CONTEXT(ctx
);
823 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGenTransformFeedbacks(n < 0)");
830 /* we don't need contiguous IDs, but this might be faster */
831 first
= _mesa_HashFindFreeKeyBlock(ctx
->TransformFeedback
.Objects
, n
);
834 for (i
= 0; i
< n
; i
++) {
835 struct gl_transform_feedback_object
*obj
836 = ctx
->Driver
.NewTransformFeedback(ctx
, first
+ i
);
838 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glGenTransformFeedbacks");
841 names
[i
] = first
+ i
;
842 _mesa_HashInsert(ctx
->TransformFeedback
.Objects
, first
+ i
, obj
);
846 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glGenTransformFeedbacks");
852 * Is the given ID a transform feedback object?
853 * Part of GL_ARB_transform_feedback2.
856 _mesa_IsTransformFeedback(GLuint name
)
858 struct gl_transform_feedback_object
*obj
;
859 GET_CURRENT_CONTEXT(ctx
);
861 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
866 obj
= _mesa_lookup_transform_feedback_object(ctx
, name
);
870 return obj
->EverBound
;
875 * Bind the given transform feedback object.
876 * Part of GL_ARB_transform_feedback2.
879 _mesa_BindTransformFeedback(GLenum target
, GLuint name
)
881 struct gl_transform_feedback_object
*obj
;
882 GET_CURRENT_CONTEXT(ctx
);
884 if (target
!= GL_TRANSFORM_FEEDBACK
) {
885 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindTransformFeedback(target)");
889 if (_mesa_is_xfb_active_and_unpaused(ctx
)) {
890 _mesa_error(ctx
, GL_INVALID_OPERATION
,
891 "glBindTransformFeedback(transform is active, or not paused)");
895 obj
= _mesa_lookup_transform_feedback_object(ctx
, name
);
897 _mesa_error(ctx
, GL_INVALID_OPERATION
,
898 "glBindTransformFeedback(name=%u)", name
);
902 reference_transform_feedback_object(&ctx
->TransformFeedback
.CurrentObject
,
908 * Delete the given transform feedback objects.
909 * Part of GL_ARB_transform_feedback2.
912 _mesa_DeleteTransformFeedbacks(GLsizei n
, const GLuint
*names
)
915 GET_CURRENT_CONTEXT(ctx
);
918 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDeleteTransformFeedbacks(n < 0)");
925 for (i
= 0; i
< n
; i
++) {
927 struct gl_transform_feedback_object
*obj
928 = _mesa_lookup_transform_feedback_object(ctx
, names
[i
]);
931 _mesa_error(ctx
, GL_INVALID_OPERATION
,
932 "glDeleteTransformFeedbacks(object %u is active)",
936 _mesa_HashRemove(ctx
->TransformFeedback
.Objects
, names
[i
]);
937 /* unref, but object may not be deleted until later */
938 reference_transform_feedback_object(&obj
, NULL
);
946 * Pause transform feedback.
947 * Part of GL_ARB_transform_feedback2.
950 _mesa_PauseTransformFeedback(void)
952 struct gl_transform_feedback_object
*obj
;
953 GET_CURRENT_CONTEXT(ctx
);
955 obj
= ctx
->TransformFeedback
.CurrentObject
;
957 if (!_mesa_is_xfb_active_and_unpaused(ctx
)) {
958 _mesa_error(ctx
, GL_INVALID_OPERATION
,
959 "glPauseTransformFeedback(feedback not active or already paused)");
963 FLUSH_VERTICES(ctx
, 0);
964 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewTransformFeedback
;
966 obj
->Paused
= GL_TRUE
;
968 assert(ctx
->Driver
.PauseTransformFeedback
);
969 ctx
->Driver
.PauseTransformFeedback(ctx
, obj
);
974 * Resume transform feedback.
975 * Part of GL_ARB_transform_feedback2.
978 _mesa_ResumeTransformFeedback(void)
980 struct gl_transform_feedback_object
*obj
;
981 GET_CURRENT_CONTEXT(ctx
);
983 obj
= ctx
->TransformFeedback
.CurrentObject
;
985 if (!obj
->Active
|| !obj
->Paused
) {
986 _mesa_error(ctx
, GL_INVALID_OPERATION
,
987 "glResumeTransformFeedback(feedback not active or not paused)");
991 /* From the ARB_transform_feedback2 specification:
992 * "The error INVALID_OPERATION is generated by ResumeTransformFeedback if
993 * the program object being used by the current transform feedback object
996 if (obj
->shader_program
!= ctx
->Shader
.CurrentProgram
[MESA_SHADER_VERTEX
]) {
997 _mesa_error(ctx
, GL_INVALID_OPERATION
,
998 "glResumeTransformFeedback(wrong vertex program bound)");
1002 FLUSH_VERTICES(ctx
, 0);
1003 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewTransformFeedback
;
1005 obj
->Paused
= GL_FALSE
;
1007 assert(ctx
->Driver
.ResumeTransformFeedback
);
1008 ctx
->Driver
.ResumeTransformFeedback(ctx
, obj
);