mesa: Use correct glGetTransformFeedbackVarying name in error msg
[mesa.git] / src / mesa / main / transformfeedback.c
1 /*
2 * Mesa 3-D graphics library
3 *
4 * Copyright (C) 2010 VMware, Inc. All Rights Reserved.
5 *
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:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
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.
22 */
23
24
25 /*
26 * Vertex transform feedback support.
27 *
28 * Authors:
29 * Brian Paul
30 */
31
32
33 #include "buffers.h"
34 #include "bufferobj.h"
35 #include "context.h"
36 #include "hash.h"
37 #include "mfeatures.h"
38 #include "mtypes.h"
39 #include "transformfeedback.h"
40 #include "shaderapi.h"
41 #include "shaderobj.h"
42 #include "main/dispatch.h"
43
44 #include "program/prog_parameter.h"
45
46
47 /**
48 * Do reference counting of transform feedback buffers.
49 */
50 static void
51 reference_transform_feedback_object(struct gl_transform_feedback_object **ptr,
52 struct gl_transform_feedback_object *obj)
53 {
54 if (*ptr == obj)
55 return;
56
57 if (*ptr) {
58 /* Unreference the old object */
59 struct gl_transform_feedback_object *oldObj = *ptr;
60
61 ASSERT(oldObj->RefCount > 0);
62 oldObj->RefCount--;
63
64 if (oldObj->RefCount == 0) {
65 GET_CURRENT_CONTEXT(ctx);
66 if (ctx)
67 ctx->Driver.DeleteTransformFeedback(ctx, oldObj);
68 }
69
70 *ptr = NULL;
71 }
72 ASSERT(!*ptr);
73
74 if (obj) {
75 /* reference new object */
76 if (obj->RefCount == 0) {
77 _mesa_problem(NULL, "referencing deleted transform feedback object");
78 *ptr = NULL;
79 }
80 else {
81 obj->RefCount++;
82 *ptr = obj;
83 }
84 }
85 }
86
87
88 /**
89 * Check that all the buffer objects currently bound for transform
90 * feedback actually exist. Raise a GL_INVALID_OPERATION error if
91 * any buffers are missing.
92 * \return GL_TRUE for success, GL_FALSE if error
93 */
94 GLboolean
95 _mesa_validate_transform_feedback_buffers(struct gl_context *ctx)
96 {
97 /* XXX to do */
98 return GL_TRUE;
99 }
100
101
102
103 /**
104 * Per-context init for transform feedback.
105 */
106 void
107 _mesa_init_transform_feedback(struct gl_context *ctx)
108 {
109 /* core mesa expects this, even a dummy one, to be available */
110 ASSERT(ctx->Driver.NewTransformFeedback);
111
112 ctx->TransformFeedback.DefaultObject =
113 ctx->Driver.NewTransformFeedback(ctx, 0);
114
115 assert(ctx->TransformFeedback.DefaultObject->RefCount == 1);
116
117 reference_transform_feedback_object(&ctx->TransformFeedback.CurrentObject,
118 ctx->TransformFeedback.DefaultObject);
119
120 assert(ctx->TransformFeedback.DefaultObject->RefCount == 2);
121
122 ctx->TransformFeedback.Objects = _mesa_NewHashTable();
123
124 _mesa_reference_buffer_object(ctx,
125 &ctx->TransformFeedback.CurrentBuffer,
126 ctx->Shared->NullBufferObj);
127 }
128
129
130
131 /**
132 * Callback for _mesa_HashDeleteAll().
133 */
134 static void
135 delete_cb(GLuint key, void *data, void *userData)
136 {
137 struct gl_context *ctx = (struct gl_context *) userData;
138 struct gl_transform_feedback_object *obj =
139 (struct gl_transform_feedback_object *) data;
140
141 ctx->Driver.DeleteTransformFeedback(ctx, obj);
142 }
143
144
145 /**
146 * Per-context free/clean-up for transform feedback.
147 */
148 void
149 _mesa_free_transform_feedback(struct gl_context *ctx)
150 {
151 /* core mesa expects this, even a dummy one, to be available */
152 ASSERT(ctx->Driver.NewTransformFeedback);
153
154 _mesa_reference_buffer_object(ctx,
155 &ctx->TransformFeedback.CurrentBuffer,
156 NULL);
157
158 /* Delete all feedback objects */
159 _mesa_HashDeleteAll(ctx->TransformFeedback.Objects, delete_cb, ctx);
160 _mesa_DeleteHashTable(ctx->TransformFeedback.Objects);
161
162 /* Delete the default feedback object */
163 assert(ctx->Driver.DeleteTransformFeedback);
164 ctx->Driver.DeleteTransformFeedback(ctx,
165 ctx->TransformFeedback.DefaultObject);
166
167 ctx->TransformFeedback.CurrentObject = NULL;
168 }
169
170
171 /** Default fallback for ctx->Driver.NewTransformFeedback() */
172 static struct gl_transform_feedback_object *
173 new_transform_feedback(struct gl_context *ctx, GLuint name)
174 {
175 struct gl_transform_feedback_object *obj;
176 obj = CALLOC_STRUCT(gl_transform_feedback_object);
177 if (obj) {
178 obj->Name = name;
179 obj->RefCount = 1;
180 }
181 return obj;
182 }
183
184 /** Default fallback for ctx->Driver.DeleteTransformFeedback() */
185 static void
186 delete_transform_feedback(struct gl_context *ctx,
187 struct gl_transform_feedback_object *obj)
188 {
189 GLuint i;
190
191 for (i = 0; i < Elements(obj->Buffers); i++) {
192 _mesa_reference_buffer_object(ctx, &obj->Buffers[i], NULL);
193 }
194
195 free(obj);
196 }
197
198
199 /** Default fallback for ctx->Driver.BeginTransformFeedback() */
200 static void
201 begin_transform_feedback(struct gl_context *ctx, GLenum mode,
202 struct gl_transform_feedback_object *obj)
203 {
204 /* nop */
205 }
206
207 /** Default fallback for ctx->Driver.EndTransformFeedback() */
208 static void
209 end_transform_feedback(struct gl_context *ctx,
210 struct gl_transform_feedback_object *obj)
211 {
212 /* nop */
213 }
214
215 /** Default fallback for ctx->Driver.PauseTransformFeedback() */
216 static void
217 pause_transform_feedback(struct gl_context *ctx,
218 struct gl_transform_feedback_object *obj)
219 {
220 /* nop */
221 }
222
223 /** Default fallback for ctx->Driver.ResumeTransformFeedback() */
224 static void
225 resume_transform_feedback(struct gl_context *ctx,
226 struct gl_transform_feedback_object *obj)
227 {
228 /* nop */
229 }
230
231
232 /**
233 * Plug in default device driver functions for transform feedback.
234 * Most drivers will override some/all of these.
235 */
236 void
237 _mesa_init_transform_feedback_functions(struct dd_function_table *driver)
238 {
239 driver->NewTransformFeedback = new_transform_feedback;
240 driver->DeleteTransformFeedback = delete_transform_feedback;
241 driver->BeginTransformFeedback = begin_transform_feedback;
242 driver->EndTransformFeedback = end_transform_feedback;
243 driver->PauseTransformFeedback = pause_transform_feedback;
244 driver->ResumeTransformFeedback = resume_transform_feedback;
245 }
246
247
248 /**
249 ** Begin API functions
250 **/
251
252
253 void GLAPIENTRY
254 _mesa_BeginTransformFeedback(GLenum mode)
255 {
256 struct gl_transform_feedback_object *obj;
257 struct gl_transform_feedback_info *info;
258 GLuint i;
259 GET_CURRENT_CONTEXT(ctx);
260
261 obj = ctx->TransformFeedback.CurrentObject;
262
263 if (ctx->Shader.CurrentVertexProgram == NULL) {
264 _mesa_error(ctx, GL_INVALID_OPERATION,
265 "glBeginTransformFeedback(no program active)");
266 return;
267 }
268
269 info = &ctx->Shader.CurrentVertexProgram->LinkedTransformFeedback;
270
271 if (info->NumOutputs == 0) {
272 _mesa_error(ctx, GL_INVALID_OPERATION,
273 "glBeginTransformFeedback(no varyings to record)");
274 return;
275 }
276
277 switch (mode) {
278 case GL_POINTS:
279 case GL_LINES:
280 case GL_TRIANGLES:
281 /* legal */
282 break;
283 default:
284 _mesa_error(ctx, GL_INVALID_ENUM, "glBeginTransformFeedback(mode)");
285 return;
286 }
287
288 if (obj->Active) {
289 _mesa_error(ctx, GL_INVALID_OPERATION,
290 "glBeginTransformFeedback(already active)");
291 return;
292 }
293
294 for (i = 0; i < info->NumBuffers; ++i) {
295 if (obj->BufferNames[i] == 0) {
296 _mesa_error(ctx, GL_INVALID_OPERATION,
297 "glBeginTransformFeedback(binding point %d does not have "
298 "a buffer object bound)", i);
299 return;
300 }
301 }
302
303 FLUSH_VERTICES(ctx, _NEW_TRANSFORM_FEEDBACK);
304 obj->Active = GL_TRUE;
305 ctx->TransformFeedback.Mode = mode;
306
307 assert(ctx->Driver.BeginTransformFeedback);
308 ctx->Driver.BeginTransformFeedback(ctx, mode, obj);
309 }
310
311
312 void GLAPIENTRY
313 _mesa_EndTransformFeedback(void)
314 {
315 struct gl_transform_feedback_object *obj;
316 GET_CURRENT_CONTEXT(ctx);
317
318 obj = ctx->TransformFeedback.CurrentObject;
319
320 if (!obj->Active) {
321 _mesa_error(ctx, GL_INVALID_OPERATION,
322 "glEndTransformFeedback(not active)");
323 return;
324 }
325
326 FLUSH_VERTICES(ctx, _NEW_TRANSFORM_FEEDBACK);
327 ctx->TransformFeedback.CurrentObject->Active = GL_FALSE;
328 ctx->TransformFeedback.CurrentObject->Paused = GL_FALSE;
329 ctx->TransformFeedback.CurrentObject->EndedAnytime = GL_TRUE;
330
331 assert(ctx->Driver.EndTransformFeedback);
332 ctx->Driver.EndTransformFeedback(ctx, obj);
333 }
334
335
336 /**
337 * Helper used by BindBufferRange() and BindBufferBase().
338 */
339 static void
340 bind_buffer_range(struct gl_context *ctx, GLuint index,
341 struct gl_buffer_object *bufObj,
342 GLintptr offset, GLsizeiptr size)
343 {
344 struct gl_transform_feedback_object *obj =
345 ctx->TransformFeedback.CurrentObject;
346
347 /* Note: no need to FLUSH_VERTICES or flag _NEW_TRANSFORM_FEEDBACK, because
348 * transform feedback buffers can't be changed while transform feedback is
349 * active.
350 */
351
352 /* The general binding point */
353 _mesa_reference_buffer_object(ctx,
354 &ctx->TransformFeedback.CurrentBuffer,
355 bufObj);
356
357 /* The per-attribute binding point */
358 _mesa_reference_buffer_object(ctx,
359 &obj->Buffers[index],
360 bufObj);
361
362 obj->BufferNames[index] = bufObj->Name;
363
364 obj->Offset[index] = offset;
365 obj->Size[index] = size;
366 }
367
368
369 /**
370 * Specify a buffer object to receive vertex shader results. Plus,
371 * specify the starting offset to place the results, and max size.
372 * Called from the glBindBufferRange() function.
373 */
374 void
375 _mesa_bind_buffer_range_transform_feedback(struct gl_context *ctx,
376 GLuint index,
377 struct gl_buffer_object *bufObj,
378 GLintptr offset,
379 GLsizeiptr size)
380 {
381 struct gl_transform_feedback_object *obj;
382
383 obj = ctx->TransformFeedback.CurrentObject;
384
385 if (obj->Active) {
386 _mesa_error(ctx, GL_INVALID_OPERATION,
387 "glBindBufferRange(transform feedback active)");
388 return;
389 }
390
391 if (index >= ctx->Const.MaxTransformFeedbackBuffers) {
392 _mesa_error(ctx, GL_INVALID_VALUE, "glBindBufferRange(index=%d)", index);
393 return;
394 }
395
396 if (size & 0x3) {
397 /* must a multiple of four */
398 _mesa_error(ctx, GL_INVALID_VALUE, "glBindBufferRange(size=%d)", (int) size);
399 return;
400 }
401
402 if (offset & 0x3) {
403 /* must be multiple of four */
404 _mesa_error(ctx, GL_INVALID_VALUE,
405 "glBindBufferRange(offset=%d)", (int) offset);
406 return;
407 }
408
409 bind_buffer_range(ctx, index, bufObj, offset, size);
410 }
411
412
413 /**
414 * Specify a buffer object to receive vertex shader results.
415 * As above, but start at offset = 0.
416 * Called from the glBindBufferBase() function.
417 */
418 void
419 _mesa_bind_buffer_base_transform_feedback(struct gl_context *ctx,
420 GLuint index,
421 struct gl_buffer_object *bufObj)
422 {
423 struct gl_transform_feedback_object *obj;
424 GLsizeiptr size;
425
426 obj = ctx->TransformFeedback.CurrentObject;
427
428 if (obj->Active) {
429 _mesa_error(ctx, GL_INVALID_OPERATION,
430 "glBindBufferBase(transform feedback active)");
431 return;
432 }
433
434 if (index >= ctx->Const.MaxTransformFeedbackBuffers) {
435 _mesa_error(ctx, GL_INVALID_VALUE, "glBindBufferBase(index=%d)", index);
436 return;
437 }
438
439 /* default size is the buffer size rounded down to nearest
440 * multiple of four.
441 */
442 size = bufObj->Size & ~0x3;
443
444 bind_buffer_range(ctx, index, bufObj, 0, size);
445 }
446
447
448 /**
449 * Specify a buffer object to receive vertex shader results, plus the
450 * offset in the buffer to start placing results.
451 * This function is part of GL_EXT_transform_feedback, but not GL3.
452 */
453 void GLAPIENTRY
454 _mesa_BindBufferOffsetEXT(GLenum target, GLuint index, GLuint buffer,
455 GLintptr offset)
456 {
457 struct gl_transform_feedback_object *obj;
458 struct gl_buffer_object *bufObj;
459 GET_CURRENT_CONTEXT(ctx);
460 GLsizeiptr size;
461
462 if (target != GL_TRANSFORM_FEEDBACK_BUFFER) {
463 _mesa_error(ctx, GL_INVALID_ENUM, "glBindBufferOffsetEXT(target)");
464 return;
465 }
466
467 obj = ctx->TransformFeedback.CurrentObject;
468
469 if (obj->Active) {
470 _mesa_error(ctx, GL_INVALID_OPERATION,
471 "glBindBufferOffsetEXT(transform feedback active)");
472 return;
473 }
474
475 if (index >= ctx->Const.MaxTransformFeedbackBuffers) {
476 _mesa_error(ctx, GL_INVALID_VALUE,
477 "glBindBufferOffsetEXT(index=%d)", index);
478 return;
479 }
480
481 if (offset & 0x3) {
482 /* must be multiple of four */
483 _mesa_error(ctx, GL_INVALID_VALUE,
484 "glBindBufferOffsetEXT(offset=%d)", (int) offset);
485 return;
486 }
487
488 if (buffer == 0) {
489 bufObj = ctx->Shared->NullBufferObj;
490 } else {
491 bufObj = _mesa_lookup_bufferobj(ctx, buffer);
492 }
493
494 if (!bufObj) {
495 _mesa_error(ctx, GL_INVALID_OPERATION,
496 "glBindBufferOffsetEXT(invalid buffer=%u)", buffer);
497 return;
498 }
499
500 /* default size is the buffer size rounded down to nearest
501 * multiple of four.
502 */
503 size = (bufObj->Size - offset) & ~0x3;
504
505 bind_buffer_range(ctx, index, bufObj, offset, size);
506 }
507
508
509 /**
510 * This function specifies the vertex shader outputs to be written
511 * to the feedback buffer(s), and in what order.
512 */
513 void GLAPIENTRY
514 _mesa_TransformFeedbackVaryings(GLuint program, GLsizei count,
515 const GLchar * const *varyings,
516 GLenum bufferMode)
517 {
518 struct gl_shader_program *shProg;
519 GLint i;
520 GET_CURRENT_CONTEXT(ctx);
521
522 switch (bufferMode) {
523 case GL_INTERLEAVED_ATTRIBS:
524 break;
525 case GL_SEPARATE_ATTRIBS:
526 break;
527 default:
528 _mesa_error(ctx, GL_INVALID_ENUM,
529 "glTransformFeedbackVaryings(bufferMode)");
530 return;
531 }
532
533 if (count < 0 ||
534 (bufferMode == GL_SEPARATE_ATTRIBS &&
535 (GLuint) count > ctx->Const.MaxTransformFeedbackBuffers)) {
536 _mesa_error(ctx, GL_INVALID_VALUE,
537 "glTransformFeedbackVaryings(count=%d)", count);
538 return;
539 }
540
541 shProg = _mesa_lookup_shader_program(ctx, program);
542 if (!shProg) {
543 _mesa_error(ctx, GL_INVALID_VALUE,
544 "glTransformFeedbackVaryings(program=%u)", program);
545 return;
546 }
547
548 if (ctx->Extensions.ARB_transform_feedback3) {
549 if (bufferMode == GL_INTERLEAVED_ATTRIBS) {
550 unsigned buffers = 1;
551
552 for (i = 0; i < count; i++) {
553 if (strcmp(varyings[i], "gl_NextBuffer") == 0)
554 buffers++;
555 }
556
557 if (buffers > ctx->Const.MaxTransformFeedbackBuffers) {
558 _mesa_error(ctx, GL_INVALID_OPERATION,
559 "glTransformFeedbackVaryings(too many gl_NextBuffer "
560 "occurences)");
561 return;
562 }
563 } else {
564 for (i = 0; i < count; i++) {
565 if (strcmp(varyings[i], "gl_NextBuffer") == 0 ||
566 strcmp(varyings[i], "gl_SkipComponents1") == 0 ||
567 strcmp(varyings[i], "gl_SkipComponents2") == 0 ||
568 strcmp(varyings[i], "gl_SkipComponents3") == 0 ||
569 strcmp(varyings[i], "gl_SkipComponents4") == 0) {
570 _mesa_error(ctx, GL_INVALID_OPERATION,
571 "glTransformFeedbackVaryings(SEPARATE_ATTRIBS,"
572 "varying=%s)",
573 varyings[i]);
574 return;
575 }
576 }
577 }
578 }
579
580 /* free existing varyings, if any */
581 for (i = 0; i < (GLint) shProg->TransformFeedback.NumVarying; i++) {
582 free(shProg->TransformFeedback.VaryingNames[i]);
583 }
584 free(shProg->TransformFeedback.VaryingNames);
585
586 /* allocate new memory for varying names */
587 shProg->TransformFeedback.VaryingNames =
588 malloc(count * sizeof(GLchar *));
589
590 if (!shProg->TransformFeedback.VaryingNames) {
591 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTransformFeedbackVaryings()");
592 return;
593 }
594
595 /* Save the new names and the count */
596 for (i = 0; i < count; i++) {
597 shProg->TransformFeedback.VaryingNames[i] = _mesa_strdup(varyings[i]);
598 }
599 shProg->TransformFeedback.NumVarying = count;
600
601 shProg->TransformFeedback.BufferMode = bufferMode;
602
603 /* No need to set _NEW_TRANSFORM_FEEDBACK (or invoke FLUSH_VERTICES) since
604 * the varyings won't be used until shader link time.
605 */
606 }
607
608
609 /**
610 * Get info about the vertex shader's outputs which are to be written
611 * to the feedback buffer(s).
612 */
613 void GLAPIENTRY
614 _mesa_GetTransformFeedbackVarying(GLuint program, GLuint index,
615 GLsizei bufSize, GLsizei *length,
616 GLsizei *size, GLenum *type, GLchar *name)
617 {
618 const struct gl_shader_program *shProg;
619 const struct gl_transform_feedback_info *linked_xfb_info;
620 GET_CURRENT_CONTEXT(ctx);
621
622 shProg = _mesa_lookup_shader_program(ctx, program);
623 if (!shProg) {
624 _mesa_error(ctx, GL_INVALID_VALUE,
625 "glGetTransformFeedbackVarying(program=%u)", program);
626 return;
627 }
628
629 linked_xfb_info = &shProg->LinkedTransformFeedback;
630 if (index >= (GLuint) linked_xfb_info->NumVarying) {
631 _mesa_error(ctx, GL_INVALID_VALUE,
632 "glGetTransformFeedbackVarying(index=%u)", index);
633 return;
634 }
635
636 /* return the varying's name and length */
637 _mesa_copy_string(name, bufSize, length,
638 linked_xfb_info->Varyings[index].Name);
639
640 /* return the datatype and value's size (in datatype units) */
641 if (type)
642 *type = linked_xfb_info->Varyings[index].Type;
643 if (size)
644 *size = linked_xfb_info->Varyings[index].Size;
645 }
646
647
648
649 struct gl_transform_feedback_object *
650 _mesa_lookup_transform_feedback_object(struct gl_context *ctx, GLuint name)
651 {
652 if (name == 0) {
653 return ctx->TransformFeedback.DefaultObject;
654 }
655 else
656 return (struct gl_transform_feedback_object *)
657 _mesa_HashLookup(ctx->TransformFeedback.Objects, name);
658 }
659
660
661 /**
662 * Create new transform feedback objects. Transform feedback objects
663 * encapsulate the state related to transform feedback to allow quickly
664 * switching state (and drawing the results, below).
665 * Part of GL_ARB_transform_feedback2.
666 */
667 void GLAPIENTRY
668 _mesa_GenTransformFeedbacks(GLsizei n, GLuint *names)
669 {
670 GLuint first;
671 GET_CURRENT_CONTEXT(ctx);
672
673 ASSERT_OUTSIDE_BEGIN_END(ctx);
674
675 if (n < 0) {
676 _mesa_error(ctx, GL_INVALID_VALUE, "glGenTransformFeedbacks(n < 0)");
677 return;
678 }
679
680 if (!names)
681 return;
682
683 /* we don't need contiguous IDs, but this might be faster */
684 first = _mesa_HashFindFreeKeyBlock(ctx->TransformFeedback.Objects, n);
685 if (first) {
686 GLsizei i;
687 for (i = 0; i < n; i++) {
688 struct gl_transform_feedback_object *obj
689 = ctx->Driver.NewTransformFeedback(ctx, first + i);
690 if (!obj) {
691 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glGenTransformFeedbacks");
692 return;
693 }
694 names[i] = first + i;
695 _mesa_HashInsert(ctx->TransformFeedback.Objects, first + i, obj);
696 }
697 }
698 else {
699 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glGenTransformFeedbacks");
700 }
701 }
702
703
704 /**
705 * Is the given ID a transform feedback object?
706 * Part of GL_ARB_transform_feedback2.
707 */
708 GLboolean GLAPIENTRY
709 _mesa_IsTransformFeedback(GLuint name)
710 {
711 GET_CURRENT_CONTEXT(ctx);
712
713 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE);
714
715 if (name && _mesa_lookup_transform_feedback_object(ctx, name))
716 return GL_TRUE;
717 else
718 return GL_FALSE;
719 }
720
721
722 /**
723 * Bind the given transform feedback object.
724 * Part of GL_ARB_transform_feedback2.
725 */
726 void GLAPIENTRY
727 _mesa_BindTransformFeedback(GLenum target, GLuint name)
728 {
729 struct gl_transform_feedback_object *obj;
730 GET_CURRENT_CONTEXT(ctx);
731
732 if (target != GL_TRANSFORM_FEEDBACK) {
733 _mesa_error(ctx, GL_INVALID_ENUM, "glBindTransformFeedback(target)");
734 return;
735 }
736
737 if (ctx->TransformFeedback.CurrentObject->Active &&
738 !ctx->TransformFeedback.CurrentObject->Paused) {
739 _mesa_error(ctx, GL_INVALID_OPERATION,
740 "glBindTransformFeedback(transform is active, or not paused)");
741 return;
742 }
743
744 obj = _mesa_lookup_transform_feedback_object(ctx, name);
745 if (!obj) {
746 _mesa_error(ctx, GL_INVALID_OPERATION,
747 "glBindTransformFeedback(name=%u)", name);
748 return;
749 }
750
751 reference_transform_feedback_object(&ctx->TransformFeedback.CurrentObject,
752 obj);
753 }
754
755
756 /**
757 * Delete the given transform feedback objects.
758 * Part of GL_ARB_transform_feedback2.
759 */
760 void GLAPIENTRY
761 _mesa_DeleteTransformFeedbacks(GLsizei n, const GLuint *names)
762 {
763 GLint i;
764 GET_CURRENT_CONTEXT(ctx);
765
766 ASSERT_OUTSIDE_BEGIN_END(ctx);
767
768 if (n < 0) {
769 _mesa_error(ctx, GL_INVALID_VALUE, "glDeleteTransformFeedbacks(n < 0)");
770 return;
771 }
772
773 if (!names)
774 return;
775
776 for (i = 0; i < n; i++) {
777 if (names[i] > 0) {
778 struct gl_transform_feedback_object *obj
779 = _mesa_lookup_transform_feedback_object(ctx, names[i]);
780 if (obj) {
781 if (obj->Active) {
782 _mesa_error(ctx, GL_INVALID_OPERATION,
783 "glDeleteTransformFeedbacks(object %u is active)",
784 names[i]);
785 return;
786 }
787 _mesa_HashRemove(ctx->TransformFeedback.Objects, names[i]);
788 /* unref, but object may not be deleted until later */
789 reference_transform_feedback_object(&obj, NULL);
790 }
791 }
792 }
793 }
794
795
796 /**
797 * Pause transform feedback.
798 * Part of GL_ARB_transform_feedback2.
799 */
800 void GLAPIENTRY
801 _mesa_PauseTransformFeedback(void)
802 {
803 struct gl_transform_feedback_object *obj;
804 GET_CURRENT_CONTEXT(ctx);
805
806 obj = ctx->TransformFeedback.CurrentObject;
807
808 if (!obj->Active || obj->Paused) {
809 _mesa_error(ctx, GL_INVALID_OPERATION,
810 "glPauseTransformFeedback(feedback not active or already paused)");
811 return;
812 }
813
814 FLUSH_VERTICES(ctx, _NEW_TRANSFORM_FEEDBACK);
815 obj->Paused = GL_TRUE;
816
817 assert(ctx->Driver.PauseTransformFeedback);
818 ctx->Driver.PauseTransformFeedback(ctx, obj);
819 }
820
821
822 /**
823 * Resume transform feedback.
824 * Part of GL_ARB_transform_feedback2.
825 */
826 void GLAPIENTRY
827 _mesa_ResumeTransformFeedback(void)
828 {
829 struct gl_transform_feedback_object *obj;
830 GET_CURRENT_CONTEXT(ctx);
831
832 obj = ctx->TransformFeedback.CurrentObject;
833
834 if (!obj->Active || !obj->Paused) {
835 _mesa_error(ctx, GL_INVALID_OPERATION,
836 "glResumeTransformFeedback(feedback not active or not paused)");
837 return;
838 }
839
840 FLUSH_VERTICES(ctx, _NEW_TRANSFORM_FEEDBACK);
841 obj->Paused = GL_FALSE;
842
843 assert(ctx->Driver.ResumeTransformFeedback);
844 ctx->Driver.ResumeTransformFeedback(ctx, obj);
845 }