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