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