mesa: Add missing include guards
[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 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.
23 */
24
25
26 /*
27 * Transform feedback support.
28 *
29 * Authors:
30 * Brian Paul
31 */
32
33
34 #include "buffers.h"
35 #include "context.h"
36 #include "hash.h"
37 #include "macros.h"
38 #include "mtypes.h"
39 #include "transformfeedback.h"
40 #include "shaderapi.h"
41 #include "shaderobj.h"
42
43 #include "program/prog_parameter.h"
44
45 struct using_program_tuple
46 {
47 struct gl_program *prog;
48 bool found;
49 };
50
51 static void
52 active_xfb_object_references_program(GLuint key, void *data, void *user_data)
53 {
54 struct using_program_tuple *callback_data = user_data;
55 struct gl_transform_feedback_object *obj = data;
56 if (obj->Active && obj->program == callback_data->prog)
57 callback_data->found = true;
58 }
59
60 /**
61 * Return true if any active transform feedback object is using a program.
62 */
63 bool
64 _mesa_transform_feedback_is_using_program(struct gl_context *ctx,
65 struct gl_shader_program *shProg)
66 {
67 if (!shProg->last_vert_prog)
68 return false;
69
70 struct using_program_tuple callback_data;
71 callback_data.found = false;
72 callback_data.prog = shProg->last_vert_prog;
73
74 _mesa_HashWalkLocked(ctx->TransformFeedback.Objects,
75 active_xfb_object_references_program, &callback_data);
76
77 /* Also check DefaultObject, as it's not in the Objects hash table. */
78 active_xfb_object_references_program(0, ctx->TransformFeedback.DefaultObject,
79 &callback_data);
80
81 return callback_data.found;
82 }
83
84 /**
85 * Do reference counting of transform feedback buffers.
86 */
87 static void
88 reference_transform_feedback_object(struct gl_transform_feedback_object **ptr,
89 struct gl_transform_feedback_object *obj)
90 {
91 if (*ptr == obj)
92 return;
93
94 if (*ptr) {
95 /* Unreference the old object */
96 struct gl_transform_feedback_object *oldObj = *ptr;
97
98 assert(oldObj->RefCount > 0);
99 oldObj->RefCount--;
100
101 if (oldObj->RefCount == 0) {
102 GET_CURRENT_CONTEXT(ctx);
103 if (ctx)
104 ctx->Driver.DeleteTransformFeedback(ctx, oldObj);
105 }
106
107 *ptr = NULL;
108 }
109 assert(!*ptr);
110
111 if (obj) {
112 assert(obj->RefCount > 0);
113
114 /* reference new object */
115 obj->RefCount++;
116 obj->EverBound = GL_TRUE;
117 *ptr = obj;
118 }
119 }
120
121
122 /**
123 * Per-context init for transform feedback.
124 */
125 void
126 _mesa_init_transform_feedback(struct gl_context *ctx)
127 {
128 /* core mesa expects this, even a dummy one, to be available */
129 assert(ctx->Driver.NewTransformFeedback);
130
131 ctx->TransformFeedback.DefaultObject =
132 ctx->Driver.NewTransformFeedback(ctx, 0);
133
134 assert(ctx->TransformFeedback.DefaultObject->RefCount == 1);
135
136 reference_transform_feedback_object(&ctx->TransformFeedback.CurrentObject,
137 ctx->TransformFeedback.DefaultObject);
138
139 assert(ctx->TransformFeedback.DefaultObject->RefCount == 2);
140
141 ctx->TransformFeedback.Objects = _mesa_NewHashTable();
142
143 _mesa_reference_buffer_object(ctx,
144 &ctx->TransformFeedback.CurrentBuffer,
145 ctx->Shared->NullBufferObj);
146 }
147
148
149
150 /**
151 * Callback for _mesa_HashDeleteAll().
152 */
153 static void
154 delete_cb(GLuint key, void *data, void *userData)
155 {
156 struct gl_context *ctx = (struct gl_context *) userData;
157 struct gl_transform_feedback_object *obj =
158 (struct gl_transform_feedback_object *) data;
159
160 ctx->Driver.DeleteTransformFeedback(ctx, obj);
161 }
162
163
164 /**
165 * Per-context free/clean-up for transform feedback.
166 */
167 void
168 _mesa_free_transform_feedback(struct gl_context *ctx)
169 {
170 /* core mesa expects this, even a dummy one, to be available */
171 assert(ctx->Driver.NewTransformFeedback);
172
173 _mesa_reference_buffer_object(ctx,
174 &ctx->TransformFeedback.CurrentBuffer,
175 NULL);
176
177 /* Delete all feedback objects */
178 _mesa_HashDeleteAll(ctx->TransformFeedback.Objects, delete_cb, ctx);
179 _mesa_DeleteHashTable(ctx->TransformFeedback.Objects);
180
181 /* Delete the default feedback object */
182 assert(ctx->Driver.DeleteTransformFeedback);
183 ctx->Driver.DeleteTransformFeedback(ctx,
184 ctx->TransformFeedback.DefaultObject);
185
186 ctx->TransformFeedback.CurrentObject = NULL;
187 }
188
189
190 /** Initialize the fields of a gl_transform_feedback_object. */
191 void
192 _mesa_init_transform_feedback_object(struct gl_transform_feedback_object *obj,
193 GLuint name)
194 {
195 obj->Name = name;
196 obj->RefCount = 1;
197 obj->EverBound = GL_FALSE;
198 }
199
200
201 /** Default fallback for ctx->Driver.NewTransformFeedback() */
202 static struct gl_transform_feedback_object *
203 new_transform_feedback_fallback(struct gl_context *ctx, GLuint name)
204 {
205 struct gl_transform_feedback_object *obj;
206
207 obj = CALLOC_STRUCT(gl_transform_feedback_object);
208 if (!obj)
209 return NULL;
210
211 _mesa_init_transform_feedback_object(obj, name);
212 return obj;
213 }
214
215 /** Default fallback for ctx->Driver.DeleteTransformFeedback() */
216 static void
217 delete_transform_feedback_fallback(struct gl_context *ctx,
218 struct gl_transform_feedback_object *obj)
219 {
220 GLuint i;
221
222 for (i = 0; i < ARRAY_SIZE(obj->Buffers); i++) {
223 _mesa_reference_buffer_object(ctx, &obj->Buffers[i], NULL);
224 }
225
226 free(obj->Label);
227 free(obj);
228 }
229
230
231 /** Default fallback for ctx->Driver.BeginTransformFeedback() */
232 static void
233 begin_transform_feedback_fallback(struct gl_context *ctx, GLenum mode,
234 struct gl_transform_feedback_object *obj)
235 {
236 /* nop */
237 }
238
239 /** Default fallback for ctx->Driver.EndTransformFeedback() */
240 static void
241 end_transform_feedback_fallback(struct gl_context *ctx,
242 struct gl_transform_feedback_object *obj)
243 {
244 /* nop */
245 }
246
247 /** Default fallback for ctx->Driver.PauseTransformFeedback() */
248 static void
249 pause_transform_feedback_fallback(struct gl_context *ctx,
250 struct gl_transform_feedback_object *obj)
251 {
252 /* nop */
253 }
254
255 /** Default fallback for ctx->Driver.ResumeTransformFeedback() */
256 static void
257 resume_transform_feedback_fallback(struct gl_context *ctx,
258 struct gl_transform_feedback_object *obj)
259 {
260 /* nop */
261 }
262
263
264 /**
265 * Plug in default device driver functions for transform feedback.
266 * Most drivers will override some/all of these.
267 */
268 void
269 _mesa_init_transform_feedback_functions(struct dd_function_table *driver)
270 {
271 driver->NewTransformFeedback = new_transform_feedback_fallback;
272 driver->DeleteTransformFeedback = delete_transform_feedback_fallback;
273 driver->BeginTransformFeedback = begin_transform_feedback_fallback;
274 driver->EndTransformFeedback = end_transform_feedback_fallback;
275 driver->PauseTransformFeedback = pause_transform_feedback_fallback;
276 driver->ResumeTransformFeedback = resume_transform_feedback_fallback;
277 }
278
279
280 /**
281 * Fill in the correct Size value for each buffer in \c obj.
282 *
283 * From the GL 4.3 spec, section 6.1.1 ("Binding Buffer Objects to Indexed
284 * Targets"):
285 *
286 * BindBufferBase binds the entire buffer, even when the size of the buffer
287 * is changed after the binding is established. It is equivalent to calling
288 * BindBufferRange with offset zero, while size is determined by the size of
289 * the bound buffer at the time the binding is used.
290 *
291 * Regardless of the size specified with BindBufferRange, or indirectly with
292 * BindBufferBase, the GL will never read or write beyond the end of a bound
293 * buffer. In some cases this constraint may result in visibly different
294 * behavior when a buffer overflow would otherwise result, such as described
295 * for transform feedback operations in section 13.2.2.
296 */
297 static void
298 compute_transform_feedback_buffer_sizes(
299 struct gl_transform_feedback_object *obj)
300 {
301 unsigned i = 0;
302 for (i = 0; i < MAX_FEEDBACK_BUFFERS; ++i) {
303 GLintptr offset = obj->Offset[i];
304 GLsizeiptr buffer_size
305 = obj->Buffers[i] == NULL ? 0 : obj->Buffers[i]->Size;
306 GLsizeiptr available_space
307 = buffer_size <= offset ? 0 : buffer_size - offset;
308 GLsizeiptr computed_size;
309 if (obj->RequestedSize[i] == 0) {
310 /* No size was specified at the time the buffer was bound, so allow
311 * writing to all available space in the buffer.
312 */
313 computed_size = available_space;
314 } else {
315 /* A size was specified at the time the buffer was bound, however
316 * it's possible that the buffer has shrunk since then. So only
317 * allow writing to the minimum of the specified size and the space
318 * available.
319 */
320 computed_size = MIN2(available_space, obj->RequestedSize[i]);
321 }
322
323 /* Legal sizes must be multiples of four, so round down if necessary. */
324 obj->Size[i] = computed_size & ~0x3;
325 }
326 }
327
328
329 /**
330 * Compute the maximum number of vertices that can be written to the currently
331 * enabled transform feedback buffers without overflowing any of them.
332 */
333 unsigned
334 _mesa_compute_max_transform_feedback_vertices(struct gl_context *ctx,
335 const struct gl_transform_feedback_object *obj,
336 const struct gl_transform_feedback_info *info)
337 {
338 unsigned max_index = 0xffffffff;
339 unsigned i;
340
341 for (i = 0; i < ctx->Const.MaxTransformFeedbackBuffers; i++) {
342 if ((info->ActiveBuffers >> i) & 1) {
343 unsigned stride = info->Buffers[i].Stride;
344 unsigned max_for_this_buffer;
345
346 /* Skip any inactive buffers, which have a stride of 0. */
347 if (stride == 0)
348 continue;
349
350 max_for_this_buffer = obj->Size[i] / (4 * stride);
351 max_index = MIN2(max_index, max_for_this_buffer);
352 }
353 }
354
355 return max_index;
356 }
357
358
359 /**
360 ** Begin API functions
361 **/
362
363
364 /**
365 * Figure out which stage of the pipeline is the source of transform feedback
366 * data given the current context state, and return its gl_program.
367 *
368 * If no active program can generate transform feedback data (i.e. no vertex
369 * shader is active), returns NULL.
370 */
371 static struct gl_program *
372 get_xfb_source(struct gl_context *ctx)
373 {
374 int i;
375 for (i = MESA_SHADER_GEOMETRY; i >= MESA_SHADER_VERTEX; i--) {
376 if (ctx->_Shader->CurrentProgram[i] != NULL)
377 return ctx->_Shader->CurrentProgram[i];
378 }
379 return NULL;
380 }
381
382
383 static ALWAYS_INLINE void
384 begin_transform_feedback(struct gl_context *ctx, GLenum mode, bool no_error)
385 {
386 struct gl_transform_feedback_object *obj;
387 struct gl_transform_feedback_info *info = NULL;
388 struct gl_program *source;
389 GLuint i;
390 unsigned vertices_per_prim;
391
392 obj = ctx->TransformFeedback.CurrentObject;
393
394 /* Figure out what pipeline stage is the source of data for transform
395 * feedback.
396 */
397 source = get_xfb_source(ctx);
398 if (!no_error && source == NULL) {
399 _mesa_error(ctx, GL_INVALID_OPERATION,
400 "glBeginTransformFeedback(no program active)");
401 return;
402 }
403
404 info = source->sh.LinkedTransformFeedback;
405
406 if (!no_error && info->NumOutputs == 0) {
407 _mesa_error(ctx, GL_INVALID_OPERATION,
408 "glBeginTransformFeedback(no varyings to record)");
409 return;
410 }
411
412 switch (mode) {
413 case GL_POINTS:
414 vertices_per_prim = 1;
415 break;
416 case GL_LINES:
417 vertices_per_prim = 2;
418 break;
419 case GL_TRIANGLES:
420 vertices_per_prim = 3;
421 break;
422 default:
423 if (!no_error) {
424 _mesa_error(ctx, GL_INVALID_ENUM, "glBeginTransformFeedback(mode)");
425 return;
426 } else {
427 /* Stop compiler warnings */
428 unreachable("Error in API use when using KHR_no_error");
429 }
430 }
431
432 if (!no_error) {
433 if (obj->Active) {
434 _mesa_error(ctx, GL_INVALID_OPERATION,
435 "glBeginTransformFeedback(already active)");
436 return;
437 }
438
439 for (i = 0; i < ctx->Const.MaxTransformFeedbackBuffers; i++) {
440 if ((info->ActiveBuffers >> i) & 1) {
441 if (obj->BufferNames[i] == 0) {
442 _mesa_error(ctx, GL_INVALID_OPERATION,
443 "glBeginTransformFeedback(binding point %d does not "
444 "have a buffer object bound)", i);
445 return;
446 }
447 }
448 }
449 }
450
451 FLUSH_VERTICES(ctx, 0);
452 ctx->NewDriverState |= ctx->DriverFlags.NewTransformFeedback;
453
454 obj->Active = GL_TRUE;
455 ctx->TransformFeedback.Mode = mode;
456
457 compute_transform_feedback_buffer_sizes(obj);
458
459 if (_mesa_is_gles3(ctx)) {
460 /* In GLES3, we are required to track the usage of the transform
461 * feedback buffer and report INVALID_OPERATION if a draw call tries to
462 * exceed it. So compute the maximum number of vertices that we can
463 * write without overflowing any of the buffers currently being used for
464 * feedback.
465 */
466 unsigned max_vertices
467 = _mesa_compute_max_transform_feedback_vertices(ctx, obj, info);
468 obj->GlesRemainingPrims = max_vertices / vertices_per_prim;
469 }
470
471 if (obj->program != source) {
472 ctx->NewDriverState |= ctx->DriverFlags.NewTransformFeedbackProg;
473 obj->program = source;
474 }
475
476 assert(ctx->Driver.BeginTransformFeedback);
477 ctx->Driver.BeginTransformFeedback(ctx, mode, obj);
478 }
479
480
481 void GLAPIENTRY
482 _mesa_BeginTransformFeedback_no_error(GLenum mode)
483 {
484 GET_CURRENT_CONTEXT(ctx);
485 begin_transform_feedback(ctx, mode, true);
486 }
487
488
489 void GLAPIENTRY
490 _mesa_BeginTransformFeedback(GLenum mode)
491 {
492 GET_CURRENT_CONTEXT(ctx);
493 begin_transform_feedback(ctx, mode, false);
494 }
495
496
497 static void
498 end_transform_feedback(struct gl_context *ctx,
499 struct gl_transform_feedback_object *obj)
500 {
501 FLUSH_VERTICES(ctx, 0);
502 ctx->NewDriverState |= ctx->DriverFlags.NewTransformFeedback;
503
504 assert(ctx->Driver.EndTransformFeedback);
505 ctx->Driver.EndTransformFeedback(ctx, obj);
506
507 ctx->TransformFeedback.CurrentObject->Active = GL_FALSE;
508 ctx->TransformFeedback.CurrentObject->Paused = GL_FALSE;
509 ctx->TransformFeedback.CurrentObject->EndedAnytime = GL_TRUE;
510 }
511
512
513 void GLAPIENTRY
514 _mesa_EndTransformFeedback_no_error(void)
515 {
516 GET_CURRENT_CONTEXT(ctx);
517 end_transform_feedback(ctx, ctx->TransformFeedback.CurrentObject);
518 }
519
520
521 void GLAPIENTRY
522 _mesa_EndTransformFeedback(void)
523 {
524 struct gl_transform_feedback_object *obj;
525 GET_CURRENT_CONTEXT(ctx);
526
527 obj = ctx->TransformFeedback.CurrentObject;
528
529 if (!obj->Active) {
530 _mesa_error(ctx, GL_INVALID_OPERATION,
531 "glEndTransformFeedback(not active)");
532 return;
533 }
534
535 end_transform_feedback(ctx, obj);
536 }
537
538
539 /**
540 * Helper used by BindBufferRange() and BindBufferBase().
541 */
542 static void
543 bind_buffer_range(struct gl_context *ctx,
544 struct gl_transform_feedback_object *obj,
545 GLuint index,
546 struct gl_buffer_object *bufObj,
547 GLintptr offset, GLsizeiptr size,
548 bool dsa)
549 {
550 /* Note: no need to FLUSH_VERTICES or flag NewTransformFeedback, because
551 * transform feedback buffers can't be changed while transform feedback is
552 * active.
553 */
554
555 if (!dsa) {
556 /* The general binding point */
557 _mesa_reference_buffer_object(ctx,
558 &ctx->TransformFeedback.CurrentBuffer,
559 bufObj);
560 }
561
562 /* The per-attribute binding point */
563 _mesa_set_transform_feedback_binding(ctx, obj, index, bufObj, offset, size);
564 }
565
566
567 /**
568 * Validate the buffer object to receive transform feedback results. Plus,
569 * validate the starting offset to place the results, and max size.
570 * Called from the glBindBufferRange() and glTransformFeedbackBufferRange
571 * functions.
572 */
573 bool
574 _mesa_validate_buffer_range_xfb(struct gl_context *ctx,
575 struct gl_transform_feedback_object *obj,
576 GLuint index, struct gl_buffer_object *bufObj,
577 GLintptr offset, GLsizeiptr size, bool dsa)
578 {
579 const char *gl_methd_name;
580 if (dsa)
581 gl_methd_name = "glTransformFeedbackBufferRange";
582 else
583 gl_methd_name = "glBindBufferRange";
584
585
586 if (obj->Active) {
587 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(transform feedback active)",
588 gl_methd_name);
589 return false;
590 }
591
592 if (index >= ctx->Const.MaxTransformFeedbackBuffers) {
593 /* OpenGL 4.5 core profile, 6.1, pdf page 82: "An INVALID_VALUE error is
594 * generated if index is greater than or equal to the number of binding
595 * points for transform feedback, as described in section 6.7.1."
596 */
597 _mesa_error(ctx, GL_INVALID_VALUE, "%s(index=%d out of bounds)",
598 gl_methd_name, index);
599 return false;
600 }
601
602 if (size & 0x3) {
603 /* OpenGL 4.5 core profile, 6.7, pdf page 103: multiple of 4 */
604 _mesa_error(ctx, GL_INVALID_VALUE, "%s(size=%d must be a multiple of "
605 "four)", gl_methd_name, (int) size);
606 return false;
607 }
608
609 if (offset & 0x3) {
610 /* OpenGL 4.5 core profile, 6.7, pdf page 103: multiple of 4 */
611 _mesa_error(ctx, GL_INVALID_VALUE, "%s(offset=%d must be a multiple "
612 "of four)", gl_methd_name, (int) offset);
613 return false;
614 }
615
616 if (offset < 0) {
617 /* OpenGL 4.5 core profile, 6.1, pdf page 82: "An INVALID_VALUE error is
618 * generated by BindBufferRange if offset is negative."
619 *
620 * OpenGL 4.5 core profile, 13.2, pdf page 445: "An INVALID_VALUE error
621 * is generated by TransformFeedbackBufferRange if offset is negative."
622 */
623 _mesa_error(ctx, GL_INVALID_VALUE, "%s(offset=%d must be >= 0)",
624 gl_methd_name,
625 (int) offset);
626 return false;
627 }
628
629 if (size <= 0 && (dsa || bufObj != ctx->Shared->NullBufferObj)) {
630 /* OpenGL 4.5 core profile, 6.1, pdf page 82: "An INVALID_VALUE error is
631 * generated by BindBufferRange if buffer is non-zero and size is less
632 * than or equal to zero."
633 *
634 * OpenGL 4.5 core profile, 13.2, pdf page 445: "An INVALID_VALUE error
635 * is generated by TransformFeedbackBufferRange if size is less than or
636 * equal to zero."
637 */
638 _mesa_error(ctx, GL_INVALID_VALUE, "%s(size=%d must be > 0)",
639 gl_methd_name, (int) size);
640 return false;
641 }
642
643 return true;
644 }
645
646
647 /**
648 * Specify a buffer object to receive transform feedback results.
649 * As above, but start at offset = 0.
650 * Called from the glBindBufferBase() and glTransformFeedbackBufferBase()
651 * functions.
652 */
653 void
654 _mesa_bind_buffer_base_transform_feedback(struct gl_context *ctx,
655 struct gl_transform_feedback_object *obj,
656 GLuint index,
657 struct gl_buffer_object *bufObj,
658 bool dsa)
659 {
660 if (obj->Active) {
661 _mesa_error(ctx, GL_INVALID_OPERATION,
662 "%s(transform feedback active)",
663 dsa ? "glTransformFeedbackBufferBase" : "glBindBufferBase");
664 return;
665 }
666
667 if (index >= ctx->Const.MaxTransformFeedbackBuffers) {
668 _mesa_error(ctx, GL_INVALID_VALUE, "%s(index=%d out of bounds)",
669 dsa ? "glTransformFeedbackBufferBase" : "glBindBufferBase",
670 index);
671 return;
672 }
673
674 bind_buffer_range(ctx, obj, index, bufObj, 0, 0, dsa);
675 }
676
677 /**
678 * Wrapper around lookup_transform_feedback_object that throws
679 * GL_INVALID_OPERATION if id is not in the hash table. After calling
680 * _mesa_error, it returns NULL.
681 */
682 static struct gl_transform_feedback_object *
683 lookup_transform_feedback_object_err(struct gl_context *ctx,
684 GLuint xfb, const char* func)
685 {
686 struct gl_transform_feedback_object *obj;
687
688 obj = _mesa_lookup_transform_feedback_object(ctx, xfb);
689 if (!obj) {
690 _mesa_error(ctx, GL_INVALID_OPERATION,
691 "%s(xfb=%u: non-generated object name)", func, xfb);
692 }
693
694 return obj;
695 }
696
697 /**
698 * Wrapper around _mesa_lookup_bufferobj that throws GL_INVALID_VALUE if id
699 * is not in the hash table. Specialised version for the
700 * transform-feedback-related functions. After calling _mesa_error, it
701 * returns NULL.
702 */
703 static struct gl_buffer_object *
704 lookup_transform_feedback_bufferobj_err(struct gl_context *ctx,
705 GLuint buffer, const char* func)
706 {
707 struct gl_buffer_object *bufObj;
708
709 /* OpenGL 4.5 core profile, 13.2, pdf page 444: buffer must be zero or the
710 * name of an existing buffer object.
711 */
712 if (buffer == 0) {
713 bufObj = ctx->Shared->NullBufferObj;
714 } else {
715 bufObj = _mesa_lookup_bufferobj(ctx, buffer);
716 if (!bufObj) {
717 _mesa_error(ctx, GL_INVALID_VALUE, "%s(invalid buffer=%u)", func,
718 buffer);
719 }
720 }
721
722 return bufObj;
723 }
724
725 void GLAPIENTRY
726 _mesa_TransformFeedbackBufferBase(GLuint xfb, GLuint index, GLuint buffer)
727 {
728 GET_CURRENT_CONTEXT(ctx);
729 struct gl_transform_feedback_object *obj;
730 struct gl_buffer_object *bufObj;
731
732 obj = lookup_transform_feedback_object_err(ctx, xfb,
733 "glTransformFeedbackBufferBase");
734 if (!obj) {
735 return;
736 }
737
738 bufObj = lookup_transform_feedback_bufferobj_err(ctx, buffer,
739 "glTransformFeedbackBufferBase");
740 if (!bufObj) {
741 return;
742 }
743
744 _mesa_bind_buffer_base_transform_feedback(ctx, obj, index, bufObj, true);
745 }
746
747 void GLAPIENTRY
748 _mesa_TransformFeedbackBufferRange(GLuint xfb, GLuint index, GLuint buffer,
749 GLintptr offset, GLsizeiptr size)
750 {
751 GET_CURRENT_CONTEXT(ctx);
752 struct gl_transform_feedback_object *obj;
753 struct gl_buffer_object *bufObj;
754
755 obj = lookup_transform_feedback_object_err(ctx, xfb,
756 "glTransformFeedbackBufferRange");
757 if (!obj) {
758 return;
759 }
760
761 bufObj = lookup_transform_feedback_bufferobj_err(ctx, buffer,
762 "glTransformFeedbackBufferRange");
763 if (!bufObj) {
764 return;
765 }
766
767 if (!_mesa_validate_buffer_range_xfb(ctx, obj, index, bufObj, offset,
768 size, true))
769 return;
770
771 /* The per-attribute binding point */
772 _mesa_set_transform_feedback_binding(ctx, obj, index, bufObj, offset,
773 size);
774 }
775
776 /**
777 * Specify a buffer object to receive transform feedback results, plus the
778 * offset in the buffer to start placing results.
779 * This function is part of GL_EXT_transform_feedback, but not GL3.
780 */
781 static ALWAYS_INLINE void
782 bind_buffer_offset(struct gl_context *ctx,
783 struct gl_transform_feedback_object *obj, GLuint index,
784 GLuint buffer, GLintptr offset, bool no_error)
785 {
786 struct gl_buffer_object *bufObj;
787
788 if (buffer == 0) {
789 bufObj = ctx->Shared->NullBufferObj;
790 } else {
791 bufObj = _mesa_lookup_bufferobj(ctx, buffer);
792 if (!no_error && !bufObj) {
793 _mesa_error(ctx, GL_INVALID_OPERATION,
794 "glBindBufferOffsetEXT(invalid buffer=%u)", buffer);
795 return;
796 }
797 }
798
799 _mesa_bind_buffer_range_xfb(ctx, obj, index, bufObj, offset, 0);
800 }
801
802
803 void GLAPIENTRY
804 _mesa_BindBufferOffsetEXT_no_error(GLenum target, GLuint index, GLuint buffer,
805 GLintptr offset)
806 {
807 GET_CURRENT_CONTEXT(ctx);
808 bind_buffer_offset(ctx, ctx->TransformFeedback.CurrentObject, index, buffer,
809 offset, true);
810 }
811
812
813 void GLAPIENTRY
814 _mesa_BindBufferOffsetEXT(GLenum target, GLuint index, GLuint buffer,
815 GLintptr offset)
816 {
817 struct gl_transform_feedback_object *obj;
818 GET_CURRENT_CONTEXT(ctx);
819
820 if (target != GL_TRANSFORM_FEEDBACK_BUFFER) {
821 _mesa_error(ctx, GL_INVALID_ENUM, "glBindBufferOffsetEXT(target)");
822 return;
823 }
824
825 obj = ctx->TransformFeedback.CurrentObject;
826
827 if (obj->Active) {
828 _mesa_error(ctx, GL_INVALID_OPERATION,
829 "glBindBufferOffsetEXT(transform feedback active)");
830 return;
831 }
832
833 if (index >= ctx->Const.MaxTransformFeedbackBuffers) {
834 _mesa_error(ctx, GL_INVALID_VALUE,
835 "glBindBufferOffsetEXT(index=%d)", index);
836 return;
837 }
838
839 if (offset & 0x3) {
840 /* must be multiple of four */
841 _mesa_error(ctx, GL_INVALID_VALUE,
842 "glBindBufferOffsetEXT(offset=%d)", (int) offset);
843 return;
844 }
845
846 bind_buffer_offset(ctx, obj, index, buffer, offset, false);
847 }
848
849
850 /**
851 * This function specifies the transform feedback outputs to be written
852 * to the feedback buffer(s), and in what order.
853 */
854 static ALWAYS_INLINE void
855 transform_feedback_varyings(struct gl_context *ctx,
856 struct gl_shader_program *shProg, GLsizei count,
857 const GLchar *const *varyings, GLenum bufferMode)
858 {
859 GLint i;
860
861 /* free existing varyings, if any */
862 for (i = 0; i < (GLint) shProg->TransformFeedback.NumVarying; i++) {
863 free(shProg->TransformFeedback.VaryingNames[i]);
864 }
865 free(shProg->TransformFeedback.VaryingNames);
866
867 /* allocate new memory for varying names */
868 shProg->TransformFeedback.VaryingNames =
869 malloc(count * sizeof(GLchar *));
870
871 if (!shProg->TransformFeedback.VaryingNames) {
872 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTransformFeedbackVaryings()");
873 return;
874 }
875
876 /* Save the new names and the count */
877 for (i = 0; i < count; i++) {
878 shProg->TransformFeedback.VaryingNames[i] = strdup(varyings[i]);
879 }
880 shProg->TransformFeedback.NumVarying = count;
881
882 shProg->TransformFeedback.BufferMode = bufferMode;
883
884 /* No need to invoke FLUSH_VERTICES or flag NewTransformFeedback since
885 * the varyings won't be used until shader link time.
886 */
887 }
888
889
890 void GLAPIENTRY
891 _mesa_TransformFeedbackVaryings_no_error(GLuint program, GLsizei count,
892 const GLchar *const *varyings,
893 GLenum bufferMode)
894 {
895 GET_CURRENT_CONTEXT(ctx);
896
897 struct gl_shader_program *shProg = _mesa_lookup_shader_program(ctx, program);
898 transform_feedback_varyings(ctx, shProg, count, varyings, bufferMode);
899 }
900
901 void GLAPIENTRY
902 _mesa_TransformFeedbackVaryings(GLuint program, GLsizei count,
903 const GLchar * const *varyings,
904 GLenum bufferMode)
905 {
906 struct gl_shader_program *shProg;
907 GLint i;
908 GET_CURRENT_CONTEXT(ctx);
909
910 /* From the ARB_transform_feedback2 specification:
911 * "The error INVALID_OPERATION is generated by TransformFeedbackVaryings
912 * if the current transform feedback object is active, even if paused."
913 */
914 if (ctx->TransformFeedback.CurrentObject->Active) {
915 _mesa_error(ctx, GL_INVALID_OPERATION,
916 "glTransformFeedbackVaryings(current object is active)");
917 return;
918 }
919
920 switch (bufferMode) {
921 case GL_INTERLEAVED_ATTRIBS:
922 break;
923 case GL_SEPARATE_ATTRIBS:
924 break;
925 default:
926 _mesa_error(ctx, GL_INVALID_ENUM,
927 "glTransformFeedbackVaryings(bufferMode)");
928 return;
929 }
930
931 if (count < 0 ||
932 (bufferMode == GL_SEPARATE_ATTRIBS &&
933 (GLuint) count > ctx->Const.MaxTransformFeedbackBuffers)) {
934 _mesa_error(ctx, GL_INVALID_VALUE,
935 "glTransformFeedbackVaryings(count=%d)", count);
936 return;
937 }
938
939 shProg = _mesa_lookup_shader_program_err(ctx, program,
940 "glTransformFeedbackVaryings");
941 if (!shProg)
942 return;
943
944 if (ctx->Extensions.ARB_transform_feedback3) {
945 if (bufferMode == GL_INTERLEAVED_ATTRIBS) {
946 unsigned buffers = 1;
947
948 for (i = 0; i < count; i++) {
949 if (strcmp(varyings[i], "gl_NextBuffer") == 0)
950 buffers++;
951 }
952
953 if (buffers > ctx->Const.MaxTransformFeedbackBuffers) {
954 _mesa_error(ctx, GL_INVALID_OPERATION,
955 "glTransformFeedbackVaryings(too many gl_NextBuffer "
956 "occurrences)");
957 return;
958 }
959 } else {
960 for (i = 0; i < count; i++) {
961 if (strcmp(varyings[i], "gl_NextBuffer") == 0 ||
962 strcmp(varyings[i], "gl_SkipComponents1") == 0 ||
963 strcmp(varyings[i], "gl_SkipComponents2") == 0 ||
964 strcmp(varyings[i], "gl_SkipComponents3") == 0 ||
965 strcmp(varyings[i], "gl_SkipComponents4") == 0) {
966 _mesa_error(ctx, GL_INVALID_OPERATION,
967 "glTransformFeedbackVaryings(SEPARATE_ATTRIBS,"
968 "varying=%s)",
969 varyings[i]);
970 return;
971 }
972 }
973 }
974 }
975
976 transform_feedback_varyings(ctx, shProg, count, varyings, bufferMode);
977 }
978
979
980 /**
981 * Get info about the transform feedback outputs which are to be written
982 * to the feedback buffer(s).
983 */
984 void GLAPIENTRY
985 _mesa_GetTransformFeedbackVarying(GLuint program, GLuint index,
986 GLsizei bufSize, GLsizei *length,
987 GLsizei *size, GLenum *type, GLchar *name)
988 {
989 const struct gl_shader_program *shProg;
990 struct gl_program_resource *res;
991 GET_CURRENT_CONTEXT(ctx);
992
993 shProg = _mesa_lookup_shader_program_err(ctx, program,
994 "glGetTransformFeedbackVarying");
995 if (!shProg)
996 return;
997
998 res = _mesa_program_resource_find_index((struct gl_shader_program *) shProg,
999 GL_TRANSFORM_FEEDBACK_VARYING,
1000 index);
1001 if (!res) {
1002 _mesa_error(ctx, GL_INVALID_VALUE,
1003 "glGetTransformFeedbackVarying(index=%u)", index);
1004 return;
1005 }
1006
1007 /* return the varying's name and length */
1008 _mesa_copy_string(name, bufSize, length, _mesa_program_resource_name(res));
1009
1010 /* return the datatype and value's size (in datatype units) */
1011 if (type)
1012 _mesa_program_resource_prop((struct gl_shader_program *) shProg,
1013 res, index, GL_TYPE, (GLint*) type,
1014 "glGetTransformFeedbackVarying");
1015 if (size)
1016 _mesa_program_resource_prop((struct gl_shader_program *) shProg,
1017 res, index, GL_ARRAY_SIZE, (GLint*) size,
1018 "glGetTransformFeedbackVarying");
1019 }
1020
1021
1022
1023 struct gl_transform_feedback_object *
1024 _mesa_lookup_transform_feedback_object(struct gl_context *ctx, GLuint name)
1025 {
1026 /* OpenGL 4.5 core profile, 13.2 pdf page 444: "xfb must be zero, indicating
1027 * the default transform feedback object, or the name of an existing
1028 * transform feedback object."
1029 */
1030 if (name == 0) {
1031 return ctx->TransformFeedback.DefaultObject;
1032 }
1033 else
1034 return (struct gl_transform_feedback_object *)
1035 _mesa_HashLookupLocked(ctx->TransformFeedback.Objects, name);
1036 }
1037
1038 static void
1039 create_transform_feedbacks(struct gl_context *ctx, GLsizei n, GLuint *ids,
1040 bool dsa)
1041 {
1042 GLuint first;
1043 const char* func;
1044
1045 if (dsa)
1046 func = "glCreateTransformFeedbacks";
1047 else
1048 func = "glGenTransformFeedbacks";
1049
1050 if (n < 0) {
1051 _mesa_error(ctx, GL_INVALID_VALUE, "%s(n < 0)", func);
1052 return;
1053 }
1054
1055 if (!ids)
1056 return;
1057
1058 /* we don't need contiguous IDs, but this might be faster */
1059 first = _mesa_HashFindFreeKeyBlock(ctx->TransformFeedback.Objects, n);
1060 if (first) {
1061 GLsizei i;
1062 for (i = 0; i < n; i++) {
1063 struct gl_transform_feedback_object *obj
1064 = ctx->Driver.NewTransformFeedback(ctx, first + i);
1065 if (!obj) {
1066 _mesa_error(ctx, GL_OUT_OF_MEMORY, "%s", func);
1067 return;
1068 }
1069 ids[i] = first + i;
1070 _mesa_HashInsertLocked(ctx->TransformFeedback.Objects, first + i,
1071 obj);
1072 if (dsa) {
1073 /* this is normally done at bind time in the non-dsa case */
1074 obj->EverBound = GL_TRUE;
1075 }
1076 }
1077 }
1078 else {
1079 _mesa_error(ctx, GL_OUT_OF_MEMORY, "%s", func);
1080 }
1081 }
1082
1083 /**
1084 * Create new transform feedback objects. Transform feedback objects
1085 * encapsulate the state related to transform feedback to allow quickly
1086 * switching state (and drawing the results, below).
1087 * Part of GL_ARB_transform_feedback2.
1088 */
1089 void GLAPIENTRY
1090 _mesa_GenTransformFeedbacks(GLsizei n, GLuint *names)
1091 {
1092 GET_CURRENT_CONTEXT(ctx);
1093
1094 /* GenTransformFeedbacks should just reserve the object names that a
1095 * subsequent call to BindTransformFeedback should actively create. For
1096 * the sake of simplicity, we reserve the names and create the objects
1097 * straight away.
1098 */
1099
1100 create_transform_feedbacks(ctx, n, names, false);
1101 }
1102
1103 /**
1104 * Create new transform feedback objects. Transform feedback objects
1105 * encapsulate the state related to transform feedback to allow quickly
1106 * switching state (and drawing the results, below).
1107 * Part of GL_ARB_direct_state_access.
1108 */
1109 void GLAPIENTRY
1110 _mesa_CreateTransformFeedbacks(GLsizei n, GLuint *names)
1111 {
1112 GET_CURRENT_CONTEXT(ctx);
1113
1114 create_transform_feedbacks(ctx, n, names, true);
1115 }
1116
1117
1118 /**
1119 * Is the given ID a transform feedback object?
1120 * Part of GL_ARB_transform_feedback2.
1121 */
1122 GLboolean GLAPIENTRY
1123 _mesa_IsTransformFeedback(GLuint name)
1124 {
1125 struct gl_transform_feedback_object *obj;
1126 GET_CURRENT_CONTEXT(ctx);
1127
1128 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE);
1129
1130 if (name == 0)
1131 return GL_FALSE;
1132
1133 obj = _mesa_lookup_transform_feedback_object(ctx, name);
1134 if (obj == NULL)
1135 return GL_FALSE;
1136
1137 return obj->EverBound;
1138 }
1139
1140
1141 /**
1142 * Bind the given transform feedback object.
1143 * Part of GL_ARB_transform_feedback2.
1144 */
1145 static ALWAYS_INLINE void
1146 bind_transform_feedback(struct gl_context *ctx, GLuint name, bool no_error)
1147 {
1148 struct gl_transform_feedback_object *obj;
1149
1150 obj = _mesa_lookup_transform_feedback_object(ctx, name);
1151 if (!no_error && !obj) {
1152 _mesa_error(ctx, GL_INVALID_OPERATION,
1153 "glBindTransformFeedback(name=%u)", name);
1154 return;
1155 }
1156
1157 reference_transform_feedback_object(&ctx->TransformFeedback.CurrentObject,
1158 obj);
1159 }
1160
1161
1162 void GLAPIENTRY
1163 _mesa_BindTransformFeedback_no_error(GLenum target, GLuint name)
1164 {
1165 GET_CURRENT_CONTEXT(ctx);
1166 bind_transform_feedback(ctx, name, true);
1167 }
1168
1169
1170 void GLAPIENTRY
1171 _mesa_BindTransformFeedback(GLenum target, GLuint name)
1172 {
1173 GET_CURRENT_CONTEXT(ctx);
1174
1175 if (target != GL_TRANSFORM_FEEDBACK) {
1176 _mesa_error(ctx, GL_INVALID_ENUM, "glBindTransformFeedback(target)");
1177 return;
1178 }
1179
1180 if (_mesa_is_xfb_active_and_unpaused(ctx)) {
1181 _mesa_error(ctx, GL_INVALID_OPERATION,
1182 "glBindTransformFeedback(transform is active, or not paused)");
1183 return;
1184 }
1185
1186 bind_transform_feedback(ctx, name, false);
1187 }
1188
1189
1190 /**
1191 * Delete the given transform feedback objects.
1192 * Part of GL_ARB_transform_feedback2.
1193 */
1194 void GLAPIENTRY
1195 _mesa_DeleteTransformFeedbacks(GLsizei n, const GLuint *names)
1196 {
1197 GLint i;
1198 GET_CURRENT_CONTEXT(ctx);
1199
1200 if (n < 0) {
1201 _mesa_error(ctx, GL_INVALID_VALUE, "glDeleteTransformFeedbacks(n < 0)");
1202 return;
1203 }
1204
1205 if (!names)
1206 return;
1207
1208 for (i = 0; i < n; i++) {
1209 if (names[i] > 0) {
1210 struct gl_transform_feedback_object *obj
1211 = _mesa_lookup_transform_feedback_object(ctx, names[i]);
1212 if (obj) {
1213 if (obj->Active) {
1214 _mesa_error(ctx, GL_INVALID_OPERATION,
1215 "glDeleteTransformFeedbacks(object %u is active)",
1216 names[i]);
1217 return;
1218 }
1219 _mesa_HashRemoveLocked(ctx->TransformFeedback.Objects, names[i]);
1220 /* unref, but object may not be deleted until later */
1221 if (obj == ctx->TransformFeedback.CurrentObject) {
1222 reference_transform_feedback_object(
1223 &ctx->TransformFeedback.CurrentObject,
1224 ctx->TransformFeedback.DefaultObject);
1225 }
1226 reference_transform_feedback_object(&obj, NULL);
1227 }
1228 }
1229 }
1230 }
1231
1232
1233 /**
1234 * Pause transform feedback.
1235 * Part of GL_ARB_transform_feedback2.
1236 */
1237 static void
1238 pause_transform_feedback(struct gl_context *ctx,
1239 struct gl_transform_feedback_object *obj)
1240 {
1241 FLUSH_VERTICES(ctx, 0);
1242 ctx->NewDriverState |= ctx->DriverFlags.NewTransformFeedback;
1243
1244 assert(ctx->Driver.PauseTransformFeedback);
1245 ctx->Driver.PauseTransformFeedback(ctx, obj);
1246
1247 obj->Paused = GL_TRUE;
1248 }
1249
1250
1251 void GLAPIENTRY
1252 _mesa_PauseTransformFeedback_no_error(void)
1253 {
1254 GET_CURRENT_CONTEXT(ctx);
1255 pause_transform_feedback(ctx, ctx->TransformFeedback.CurrentObject);
1256 }
1257
1258
1259 void GLAPIENTRY
1260 _mesa_PauseTransformFeedback(void)
1261 {
1262 struct gl_transform_feedback_object *obj;
1263 GET_CURRENT_CONTEXT(ctx);
1264
1265 obj = ctx->TransformFeedback.CurrentObject;
1266
1267 if (!_mesa_is_xfb_active_and_unpaused(ctx)) {
1268 _mesa_error(ctx, GL_INVALID_OPERATION,
1269 "glPauseTransformFeedback(feedback not active or already paused)");
1270 return;
1271 }
1272
1273 pause_transform_feedback(ctx, obj);
1274 }
1275
1276
1277 /**
1278 * Resume transform feedback.
1279 * Part of GL_ARB_transform_feedback2.
1280 */
1281 static void
1282 resume_transform_feedback(struct gl_context *ctx,
1283 struct gl_transform_feedback_object *obj)
1284 {
1285 FLUSH_VERTICES(ctx, 0);
1286 ctx->NewDriverState |= ctx->DriverFlags.NewTransformFeedback;
1287
1288 obj->Paused = GL_FALSE;
1289
1290 assert(ctx->Driver.ResumeTransformFeedback);
1291 ctx->Driver.ResumeTransformFeedback(ctx, obj);
1292 }
1293
1294
1295 void GLAPIENTRY
1296 _mesa_ResumeTransformFeedback_no_error(void)
1297 {
1298 GET_CURRENT_CONTEXT(ctx);
1299 resume_transform_feedback(ctx, ctx->TransformFeedback.CurrentObject);
1300 }
1301
1302
1303 void GLAPIENTRY
1304 _mesa_ResumeTransformFeedback(void)
1305 {
1306 struct gl_transform_feedback_object *obj;
1307 GET_CURRENT_CONTEXT(ctx);
1308
1309 obj = ctx->TransformFeedback.CurrentObject;
1310
1311 if (!obj->Active || !obj->Paused) {
1312 _mesa_error(ctx, GL_INVALID_OPERATION,
1313 "glResumeTransformFeedback(feedback not active or not paused)");
1314 return;
1315 }
1316
1317 /* From the ARB_transform_feedback2 specification:
1318 * "The error INVALID_OPERATION is generated by ResumeTransformFeedback if
1319 * the program object being used by the current transform feedback object
1320 * is not active."
1321 */
1322 if (obj->program != get_xfb_source(ctx)) {
1323 _mesa_error(ctx, GL_INVALID_OPERATION,
1324 "glResumeTransformFeedback(wrong program bound)");
1325 return;
1326 }
1327
1328 resume_transform_feedback(ctx, obj);
1329 }
1330
1331 extern void GLAPIENTRY
1332 _mesa_GetTransformFeedbackiv(GLuint xfb, GLenum pname, GLint *param)
1333 {
1334 struct gl_transform_feedback_object *obj;
1335 GET_CURRENT_CONTEXT(ctx);
1336
1337 obj = lookup_transform_feedback_object_err(ctx, xfb,
1338 "glGetTransformFeedbackiv");
1339 if (!obj) {
1340 return;
1341 }
1342
1343 switch(pname) {
1344 case GL_TRANSFORM_FEEDBACK_PAUSED:
1345 *param = obj->Paused;
1346 break;
1347 case GL_TRANSFORM_FEEDBACK_ACTIVE:
1348 *param = obj->Active;
1349 break;
1350 default:
1351 _mesa_error(ctx, GL_INVALID_ENUM,
1352 "glGetTransformFeedbackiv(pname=%i)", pname);
1353 }
1354 }
1355
1356 extern void GLAPIENTRY
1357 _mesa_GetTransformFeedbacki_v(GLuint xfb, GLenum pname, GLuint index,
1358 GLint *param)
1359 {
1360 struct gl_transform_feedback_object *obj;
1361 GET_CURRENT_CONTEXT(ctx);
1362
1363 obj = lookup_transform_feedback_object_err(ctx, xfb,
1364 "glGetTransformFeedbacki_v");
1365 if (!obj) {
1366 return;
1367 }
1368
1369 if (index >= ctx->Const.MaxTransformFeedbackBuffers) {
1370 _mesa_error(ctx, GL_INVALID_VALUE,
1371 "glGetTransformFeedbacki_v(index=%i)", index);
1372 return;
1373 }
1374
1375 switch(pname) {
1376 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
1377 *param = obj->BufferNames[index];
1378 break;
1379 default:
1380 _mesa_error(ctx, GL_INVALID_ENUM,
1381 "glGetTransformFeedbacki_v(pname=%i)", pname);
1382 }
1383 }
1384
1385 extern void GLAPIENTRY
1386 _mesa_GetTransformFeedbacki64_v(GLuint xfb, GLenum pname, GLuint index,
1387 GLint64 *param)
1388 {
1389 struct gl_transform_feedback_object *obj;
1390 GET_CURRENT_CONTEXT(ctx);
1391
1392 obj = lookup_transform_feedback_object_err(ctx, xfb,
1393 "glGetTransformFeedbacki64_v");
1394 if (!obj) {
1395 return;
1396 }
1397
1398 if (index >= ctx->Const.MaxTransformFeedbackBuffers) {
1399 _mesa_error(ctx, GL_INVALID_VALUE,
1400 "glGetTransformFeedbacki64_v(index=%i)", index);
1401 return;
1402 }
1403
1404 /**
1405 * This follows the same general rules used for BindBufferBase:
1406 *
1407 * "To query the starting offset or size of the range of a buffer
1408 * object binding in an indexed array, call GetInteger64i_v with
1409 * target set to respectively the starting offset or binding size
1410 * name from table 6.5 for that array. Index must be in the range
1411 * zero to the number of bind points supported minus one. If the
1412 * starting offset or size was not specified when the buffer object
1413 * was bound (e.g. if it was bound with BindBufferBase), or if no
1414 * buffer object is bound to the target array at index, zero is
1415 * returned."
1416 */
1417 if (obj->RequestedSize[index] == 0 &&
1418 (pname == GL_TRANSFORM_FEEDBACK_BUFFER_START ||
1419 pname == GL_TRANSFORM_FEEDBACK_BUFFER_SIZE)) {
1420 *param = 0;
1421 return;
1422 }
1423
1424 compute_transform_feedback_buffer_sizes(obj);
1425 switch(pname) {
1426 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
1427 assert(obj->RequestedSize[index] > 0);
1428 *param = obj->Offset[index];
1429 break;
1430 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
1431 assert(obj->RequestedSize[index] > 0);
1432 *param = obj->Size[index];
1433 break;
1434 default:
1435 _mesa_error(ctx, GL_INVALID_ENUM,
1436 "glGetTransformFeedbacki64_v(pname=%i)", pname);
1437 }
1438 }