1edb310ea13d650c138c9080b8f304f35db25c41
[mesa.git] / src / mesa / main / fbobject.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 7.1
4 *
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
6 * Copyright (C) 1999-2009 VMware, Inc. All Rights Reserved.
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 */
25
26
27 /*
28 * GL_EXT/ARB_framebuffer_object extensions
29 *
30 * Authors:
31 * Brian Paul
32 */
33
34
35 #include "buffers.h"
36 #include "context.h"
37 #include "enums.h"
38 #include "fbobject.h"
39 #include "formats.h"
40 #include "framebuffer.h"
41 #include "hash.h"
42 #include "macros.h"
43 #include "mfeatures.h"
44 #include "mtypes.h"
45 #include "renderbuffer.h"
46 #include "state.h"
47 #include "teximage.h"
48 #include "texobj.h"
49
50
51 /** Set this to 1 to help debug FBO incompleteness problems */
52 #define DEBUG_FBO 0
53
54 /** Set this to 1 to debug/log glBlitFramebuffer() calls */
55 #define DEBUG_BLIT 0
56
57
58 /**
59 * Notes:
60 *
61 * None of the GL_EXT_framebuffer_object functions are compiled into
62 * display lists.
63 */
64
65
66
67 /*
68 * When glGenRender/FramebuffersEXT() is called we insert pointers to
69 * these placeholder objects into the hash table.
70 * Later, when the object ID is first bound, we replace the placeholder
71 * with the real frame/renderbuffer.
72 */
73 static struct gl_framebuffer DummyFramebuffer;
74 static struct gl_renderbuffer DummyRenderbuffer;
75
76 /* We bind this framebuffer when applications pass a NULL
77 * drawable/surface in make current. */
78 static struct gl_framebuffer IncompleteFramebuffer;
79
80
81 #define IS_CUBE_FACE(TARGET) \
82 ((TARGET) >= GL_TEXTURE_CUBE_MAP_POSITIVE_X && \
83 (TARGET) <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z)
84
85
86 static void
87 delete_dummy_renderbuffer(struct gl_renderbuffer *rb)
88 {
89 /* no op */
90 }
91
92 static void
93 delete_dummy_framebuffer(struct gl_framebuffer *fb)
94 {
95 /* no op */
96 }
97
98
99 void
100 _mesa_init_fbobjects(struct gl_context *ctx)
101 {
102 _glthread_INIT_MUTEX(DummyFramebuffer.Mutex);
103 _glthread_INIT_MUTEX(DummyRenderbuffer.Mutex);
104 _glthread_INIT_MUTEX(IncompleteFramebuffer.Mutex);
105 DummyFramebuffer.Delete = delete_dummy_framebuffer;
106 DummyRenderbuffer.Delete = delete_dummy_renderbuffer;
107 IncompleteFramebuffer.Delete = delete_dummy_framebuffer;
108 }
109
110 struct gl_framebuffer *
111 _mesa_get_incomplete_framebuffer(void)
112 {
113 return &IncompleteFramebuffer;
114 }
115
116 /**
117 * Helper routine for getting a gl_renderbuffer.
118 */
119 struct gl_renderbuffer *
120 _mesa_lookup_renderbuffer(struct gl_context *ctx, GLuint id)
121 {
122 struct gl_renderbuffer *rb;
123
124 if (id == 0)
125 return NULL;
126
127 rb = (struct gl_renderbuffer *)
128 _mesa_HashLookup(ctx->Shared->RenderBuffers, id);
129 return rb;
130 }
131
132
133 /**
134 * Helper routine for getting a gl_framebuffer.
135 */
136 struct gl_framebuffer *
137 _mesa_lookup_framebuffer(struct gl_context *ctx, GLuint id)
138 {
139 struct gl_framebuffer *fb;
140
141 if (id == 0)
142 return NULL;
143
144 fb = (struct gl_framebuffer *)
145 _mesa_HashLookup(ctx->Shared->FrameBuffers, id);
146 return fb;
147 }
148
149
150 /**
151 * Mark the given framebuffer as invalid. This will force the
152 * test for framebuffer completeness to be done before the framebuffer
153 * is used.
154 */
155 static void
156 invalidate_framebuffer(struct gl_framebuffer *fb)
157 {
158 fb->_Status = 0; /* "indeterminate" */
159 }
160
161
162 /**
163 * Return the gl_framebuffer object which corresponds to the given
164 * framebuffer target, such as GL_DRAW_FRAMEBUFFER.
165 * Check support for GL_EXT_framebuffer_blit to determine if certain
166 * targets are legal.
167 * \return gl_framebuffer pointer or NULL if target is illegal
168 */
169 static struct gl_framebuffer *
170 get_framebuffer_target(struct gl_context *ctx, GLenum target)
171 {
172 switch (target) {
173 case GL_DRAW_FRAMEBUFFER:
174 return ctx->Extensions.EXT_framebuffer_blit ? ctx->DrawBuffer : NULL;
175 case GL_READ_FRAMEBUFFER:
176 return ctx->Extensions.EXT_framebuffer_blit ? ctx->ReadBuffer : NULL;
177 case GL_FRAMEBUFFER_EXT:
178 return ctx->DrawBuffer;
179 default:
180 return NULL;
181 }
182 }
183
184
185 /**
186 * Given a GL_*_ATTACHMENTn token, return a pointer to the corresponding
187 * gl_renderbuffer_attachment object.
188 * This function is only used for user-created FB objects, not the
189 * default / window-system FB object.
190 * If \p attachment is GL_DEPTH_STENCIL_ATTACHMENT, return a pointer to
191 * the depth buffer attachment point.
192 */
193 struct gl_renderbuffer_attachment *
194 _mesa_get_attachment(struct gl_context *ctx, struct gl_framebuffer *fb,
195 GLenum attachment)
196 {
197 GLuint i;
198
199 assert(fb->Name > 0);
200
201 switch (attachment) {
202 case GL_COLOR_ATTACHMENT0_EXT:
203 case GL_COLOR_ATTACHMENT1_EXT:
204 case GL_COLOR_ATTACHMENT2_EXT:
205 case GL_COLOR_ATTACHMENT3_EXT:
206 case GL_COLOR_ATTACHMENT4_EXT:
207 case GL_COLOR_ATTACHMENT5_EXT:
208 case GL_COLOR_ATTACHMENT6_EXT:
209 case GL_COLOR_ATTACHMENT7_EXT:
210 case GL_COLOR_ATTACHMENT8_EXT:
211 case GL_COLOR_ATTACHMENT9_EXT:
212 case GL_COLOR_ATTACHMENT10_EXT:
213 case GL_COLOR_ATTACHMENT11_EXT:
214 case GL_COLOR_ATTACHMENT12_EXT:
215 case GL_COLOR_ATTACHMENT13_EXT:
216 case GL_COLOR_ATTACHMENT14_EXT:
217 case GL_COLOR_ATTACHMENT15_EXT:
218 i = attachment - GL_COLOR_ATTACHMENT0_EXT;
219 if (i >= ctx->Const.MaxColorAttachments) {
220 return NULL;
221 }
222 return &fb->Attachment[BUFFER_COLOR0 + i];
223 case GL_DEPTH_STENCIL_ATTACHMENT:
224 /* fall-through */
225 case GL_DEPTH_BUFFER:
226 /* fall-through / new in GL 3.0 */
227 case GL_DEPTH_ATTACHMENT_EXT:
228 return &fb->Attachment[BUFFER_DEPTH];
229 case GL_STENCIL_BUFFER:
230 /* fall-through / new in GL 3.0 */
231 case GL_STENCIL_ATTACHMENT_EXT:
232 return &fb->Attachment[BUFFER_STENCIL];
233 default:
234 return NULL;
235 }
236 }
237
238
239 /**
240 * As above, but only used for getting attachments of the default /
241 * window-system framebuffer (not user-created framebuffer objects).
242 */
243 static struct gl_renderbuffer_attachment *
244 _mesa_get_fb0_attachment(struct gl_context *ctx, struct gl_framebuffer *fb,
245 GLenum attachment)
246 {
247 assert(fb->Name == 0);
248
249 switch (attachment) {
250 case GL_FRONT_LEFT:
251 return &fb->Attachment[BUFFER_FRONT_LEFT];
252 case GL_FRONT_RIGHT:
253 return &fb->Attachment[BUFFER_FRONT_RIGHT];
254 case GL_BACK_LEFT:
255 return &fb->Attachment[BUFFER_BACK_LEFT];
256 case GL_BACK_RIGHT:
257 return &fb->Attachment[BUFFER_BACK_RIGHT];
258 case GL_AUX0:
259 if (fb->Visual.numAuxBuffers == 1) {
260 return &fb->Attachment[BUFFER_AUX0];
261 }
262 return NULL;
263 case GL_DEPTH_BUFFER:
264 /* fall-through / new in GL 3.0 */
265 case GL_DEPTH_ATTACHMENT_EXT:
266 return &fb->Attachment[BUFFER_DEPTH];
267 case GL_STENCIL_BUFFER:
268 /* fall-through / new in GL 3.0 */
269 case GL_STENCIL_ATTACHMENT_EXT:
270 return &fb->Attachment[BUFFER_STENCIL];
271 default:
272 return NULL;
273 }
274 }
275
276
277
278 /**
279 * Remove any texture or renderbuffer attached to the given attachment
280 * point. Update reference counts, etc.
281 */
282 void
283 _mesa_remove_attachment(struct gl_context *ctx,
284 struct gl_renderbuffer_attachment *att)
285 {
286 if (att->Type == GL_TEXTURE) {
287 ASSERT(att->Texture);
288 if (ctx->Driver.FinishRenderTexture) {
289 /* tell driver that we're done rendering to this texture. */
290 ctx->Driver.FinishRenderTexture(ctx, att);
291 }
292 _mesa_reference_texobj(&att->Texture, NULL); /* unbind */
293 ASSERT(!att->Texture);
294 }
295 if (att->Type == GL_TEXTURE || att->Type == GL_RENDERBUFFER_EXT) {
296 ASSERT(!att->Texture);
297 _mesa_reference_renderbuffer(&att->Renderbuffer, NULL); /* unbind */
298 ASSERT(!att->Renderbuffer);
299 }
300 att->Type = GL_NONE;
301 att->Complete = GL_TRUE;
302 }
303
304
305 /**
306 * Bind a texture object to an attachment point.
307 * The previous binding, if any, will be removed first.
308 */
309 void
310 _mesa_set_texture_attachment(struct gl_context *ctx,
311 struct gl_framebuffer *fb,
312 struct gl_renderbuffer_attachment *att,
313 struct gl_texture_object *texObj,
314 GLenum texTarget, GLuint level, GLuint zoffset)
315 {
316 if (att->Texture == texObj) {
317 /* re-attaching same texture */
318 ASSERT(att->Type == GL_TEXTURE);
319 if (ctx->Driver.FinishRenderTexture)
320 ctx->Driver.FinishRenderTexture(ctx, att);
321 }
322 else {
323 /* new attachment */
324 if (ctx->Driver.FinishRenderTexture && att->Texture)
325 ctx->Driver.FinishRenderTexture(ctx, att);
326 _mesa_remove_attachment(ctx, att);
327 att->Type = GL_TEXTURE;
328 assert(!att->Texture);
329 _mesa_reference_texobj(&att->Texture, texObj);
330 }
331
332 /* always update these fields */
333 att->TextureLevel = level;
334 att->CubeMapFace = _mesa_tex_target_to_face(texTarget);
335 att->Zoffset = zoffset;
336 att->Complete = GL_FALSE;
337
338 if (_mesa_get_attachment_teximage(att)) {
339 ctx->Driver.RenderTexture(ctx, fb, att);
340 }
341
342 invalidate_framebuffer(fb);
343 }
344
345
346 /**
347 * Bind a renderbuffer to an attachment point.
348 * The previous binding, if any, will be removed first.
349 */
350 void
351 _mesa_set_renderbuffer_attachment(struct gl_context *ctx,
352 struct gl_renderbuffer_attachment *att,
353 struct gl_renderbuffer *rb)
354 {
355 /* XXX check if re-doing same attachment, exit early */
356 _mesa_remove_attachment(ctx, att);
357 att->Type = GL_RENDERBUFFER_EXT;
358 att->Texture = NULL; /* just to be safe */
359 att->Complete = GL_FALSE;
360 _mesa_reference_renderbuffer(&att->Renderbuffer, rb);
361 }
362
363
364 /**
365 * Fallback for ctx->Driver.FramebufferRenderbuffer()
366 * Attach a renderbuffer object to a framebuffer object.
367 */
368 void
369 _mesa_framebuffer_renderbuffer(struct gl_context *ctx,
370 struct gl_framebuffer *fb,
371 GLenum attachment, struct gl_renderbuffer *rb)
372 {
373 struct gl_renderbuffer_attachment *att;
374
375 _glthread_LOCK_MUTEX(fb->Mutex);
376
377 att = _mesa_get_attachment(ctx, fb, attachment);
378 ASSERT(att);
379 if (rb) {
380 _mesa_set_renderbuffer_attachment(ctx, att, rb);
381 if (attachment == GL_DEPTH_STENCIL_ATTACHMENT) {
382 /* do stencil attachment here (depth already done above) */
383 att = _mesa_get_attachment(ctx, fb, GL_STENCIL_ATTACHMENT_EXT);
384 assert(att);
385 _mesa_set_renderbuffer_attachment(ctx, att, rb);
386 }
387 rb->AttachedAnytime = GL_TRUE;
388 }
389 else {
390 _mesa_remove_attachment(ctx, att);
391 }
392
393 invalidate_framebuffer(fb);
394
395 _glthread_UNLOCK_MUTEX(fb->Mutex);
396 }
397
398
399 /**
400 * Fallback for ctx->Driver.ValidateFramebuffer()
401 * Check if the renderbuffer's formats are supported by the software
402 * renderer.
403 * Drivers should probably override this.
404 */
405 void
406 _mesa_validate_framebuffer(struct gl_context *ctx, struct gl_framebuffer *fb)
407 {
408 gl_buffer_index buf;
409 for (buf = 0; buf < BUFFER_COUNT; buf++) {
410 const struct gl_renderbuffer *rb = fb->Attachment[buf].Renderbuffer;
411 if (rb) {
412 switch (rb->_BaseFormat) {
413 case GL_ALPHA:
414 case GL_LUMINANCE_ALPHA:
415 case GL_LUMINANCE:
416 case GL_INTENSITY:
417 case GL_RED:
418 case GL_RG:
419 fb->_Status = GL_FRAMEBUFFER_UNSUPPORTED;
420 return;
421 default:
422 /* render buffer format is supported by software rendering */
423 ;
424 }
425 }
426 }
427 }
428
429
430 /**
431 * For debug only.
432 */
433 static void
434 att_incomplete(const char *msg)
435 {
436 #if DEBUG_FBO
437 _mesa_debug(NULL, "attachment incomplete: %s\n", msg);
438 #else
439 (void) msg;
440 #endif
441 }
442
443
444 /**
445 * For debug only.
446 */
447 static void
448 fbo_incomplete(const char *msg, int index)
449 {
450 #if DEBUG_FBO
451 _mesa_debug(NULL, "FBO Incomplete: %s [%d]\n", msg, index);
452 #else
453 (void) msg;
454 (void) index;
455 #endif
456 }
457
458
459 /**
460 * Is the given base format a legal format for a color renderbuffer?
461 */
462 GLboolean
463 _mesa_is_legal_color_format(const struct gl_context *ctx, GLenum baseFormat)
464 {
465 switch (baseFormat) {
466 case GL_RGB:
467 case GL_RGBA:
468 return GL_TRUE;
469 case GL_LUMINANCE:
470 case GL_LUMINANCE_ALPHA:
471 case GL_INTENSITY:
472 case GL_ALPHA:
473 return ctx->Extensions.ARB_framebuffer_object;
474 case GL_RED:
475 case GL_RG:
476 return ctx->Extensions.ARB_texture_rg;
477 default:
478 return GL_FALSE;
479 }
480 }
481
482
483 /**
484 * Is the given base format a legal format for a depth/stencil renderbuffer?
485 */
486 static GLboolean
487 is_legal_depth_format(const struct gl_context *ctx, GLenum baseFormat)
488 {
489 switch (baseFormat) {
490 case GL_DEPTH_COMPONENT:
491 case GL_DEPTH_STENCIL_EXT:
492 return GL_TRUE;
493 default:
494 return GL_FALSE;
495 }
496 }
497
498
499 /**
500 * Test if an attachment point is complete and update its Complete field.
501 * \param format if GL_COLOR, this is a color attachment point,
502 * if GL_DEPTH, this is a depth component attachment point,
503 * if GL_STENCIL, this is a stencil component attachment point.
504 */
505 static void
506 test_attachment_completeness(const struct gl_context *ctx, GLenum format,
507 struct gl_renderbuffer_attachment *att)
508 {
509 assert(format == GL_COLOR || format == GL_DEPTH || format == GL_STENCIL);
510
511 /* assume complete */
512 att->Complete = GL_TRUE;
513
514 /* Look for reasons why the attachment might be incomplete */
515 if (att->Type == GL_TEXTURE) {
516 const struct gl_texture_object *texObj = att->Texture;
517 struct gl_texture_image *texImage;
518 GLenum baseFormat;
519
520 if (!texObj) {
521 att_incomplete("no texobj");
522 att->Complete = GL_FALSE;
523 return;
524 }
525
526 texImage = texObj->Image[att->CubeMapFace][att->TextureLevel];
527 if (!texImage) {
528 att_incomplete("no teximage");
529 att->Complete = GL_FALSE;
530 return;
531 }
532 if (texImage->Width < 1 || texImage->Height < 1) {
533 att_incomplete("teximage width/height=0");
534 printf("texobj = %u\n", texObj->Name);
535 printf("level = %d\n", att->TextureLevel);
536 att->Complete = GL_FALSE;
537 return;
538 }
539 if (texObj->Target == GL_TEXTURE_3D && att->Zoffset >= texImage->Depth) {
540 att_incomplete("bad z offset");
541 att->Complete = GL_FALSE;
542 return;
543 }
544
545 baseFormat = _mesa_get_format_base_format(texImage->TexFormat);
546
547 if (format == GL_COLOR) {
548 if (!_mesa_is_legal_color_format(ctx, baseFormat)) {
549 att_incomplete("bad format");
550 att->Complete = GL_FALSE;
551 return;
552 }
553 if (_mesa_is_format_compressed(texImage->TexFormat)) {
554 att_incomplete("compressed internalformat");
555 att->Complete = GL_FALSE;
556 return;
557 }
558 }
559 else if (format == GL_DEPTH) {
560 if (baseFormat == GL_DEPTH_COMPONENT) {
561 /* OK */
562 }
563 else if (ctx->Extensions.EXT_packed_depth_stencil &&
564 ctx->Extensions.ARB_depth_texture &&
565 baseFormat == GL_DEPTH_STENCIL_EXT) {
566 /* OK */
567 }
568 else {
569 att->Complete = GL_FALSE;
570 att_incomplete("bad depth format");
571 return;
572 }
573 }
574 else {
575 ASSERT(format == GL_STENCIL);
576 if (ctx->Extensions.EXT_packed_depth_stencil &&
577 ctx->Extensions.ARB_depth_texture &&
578 baseFormat == GL_DEPTH_STENCIL_EXT) {
579 /* OK */
580 }
581 else {
582 /* no such thing as stencil-only textures */
583 att_incomplete("illegal stencil texture");
584 att->Complete = GL_FALSE;
585 return;
586 }
587 }
588 }
589 else if (att->Type == GL_RENDERBUFFER_EXT) {
590 const GLenum baseFormat =
591 _mesa_get_format_base_format(att->Renderbuffer->Format);
592
593 ASSERT(att->Renderbuffer);
594 if (!att->Renderbuffer->InternalFormat ||
595 att->Renderbuffer->Width < 1 ||
596 att->Renderbuffer->Height < 1) {
597 att_incomplete("0x0 renderbuffer");
598 att->Complete = GL_FALSE;
599 return;
600 }
601 if (format == GL_COLOR) {
602 if (!_mesa_is_legal_color_format(ctx, baseFormat)) {
603 att_incomplete("bad renderbuffer color format");
604 att->Complete = GL_FALSE;
605 return;
606 }
607 }
608 else if (format == GL_DEPTH) {
609 if (baseFormat == GL_DEPTH_COMPONENT) {
610 /* OK */
611 }
612 else if (ctx->Extensions.EXT_packed_depth_stencil &&
613 baseFormat == GL_DEPTH_STENCIL_EXT) {
614 /* OK */
615 }
616 else {
617 att_incomplete("bad renderbuffer depth format");
618 att->Complete = GL_FALSE;
619 return;
620 }
621 }
622 else {
623 assert(format == GL_STENCIL);
624 if (baseFormat == GL_STENCIL_INDEX) {
625 /* OK */
626 }
627 else if (ctx->Extensions.EXT_packed_depth_stencil &&
628 baseFormat == GL_DEPTH_STENCIL_EXT) {
629 /* OK */
630 }
631 else {
632 att->Complete = GL_FALSE;
633 att_incomplete("bad renderbuffer stencil format");
634 return;
635 }
636 }
637 }
638 else {
639 ASSERT(att->Type == GL_NONE);
640 /* complete */
641 return;
642 }
643 }
644
645
646 /**
647 * Test if the given framebuffer object is complete and update its
648 * Status field with the results.
649 * Calls the ctx->Driver.ValidateFramebuffer() function to allow the
650 * driver to make hardware-specific validation/completeness checks.
651 * Also update the framebuffer's Width and Height fields if the
652 * framebuffer is complete.
653 */
654 void
655 _mesa_test_framebuffer_completeness(struct gl_context *ctx,
656 struct gl_framebuffer *fb)
657 {
658 GLuint numImages;
659 GLenum intFormat = GL_NONE; /* color buffers' internal format */
660 GLuint minWidth = ~0, minHeight = ~0, maxWidth = 0, maxHeight = 0;
661 GLint numSamples = -1;
662 GLint i;
663 GLuint j;
664
665 assert(fb->Name != 0);
666
667 numImages = 0;
668 fb->Width = 0;
669 fb->Height = 0;
670
671 /* Start at -2 to more easily loop over all attachment points.
672 * -2: depth buffer
673 * -1: stencil buffer
674 * >=0: color buffer
675 */
676 for (i = -2; i < (GLint) ctx->Const.MaxColorAttachments; i++) {
677 struct gl_renderbuffer_attachment *att;
678 GLenum f;
679 gl_format attFormat;
680
681 /*
682 * XXX for ARB_fbo, only check color buffers that are named by
683 * GL_READ_BUFFER and GL_DRAW_BUFFERi.
684 */
685
686 /* check for attachment completeness
687 */
688 if (i == -2) {
689 att = &fb->Attachment[BUFFER_DEPTH];
690 test_attachment_completeness(ctx, GL_DEPTH, att);
691 if (!att->Complete) {
692 fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT;
693 fbo_incomplete("depth attachment incomplete", -1);
694 return;
695 }
696 }
697 else if (i == -1) {
698 att = &fb->Attachment[BUFFER_STENCIL];
699 test_attachment_completeness(ctx, GL_STENCIL, att);
700 if (!att->Complete) {
701 fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT;
702 fbo_incomplete("stencil attachment incomplete", -1);
703 return;
704 }
705 }
706 else {
707 att = &fb->Attachment[BUFFER_COLOR0 + i];
708 test_attachment_completeness(ctx, GL_COLOR, att);
709 if (!att->Complete) {
710 fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT;
711 fbo_incomplete("color attachment incomplete", i);
712 return;
713 }
714 }
715
716 /* get width, height, format of the renderbuffer/texture
717 */
718 if (att->Type == GL_TEXTURE) {
719 const struct gl_texture_image *texImg =
720 _mesa_get_attachment_teximage(att);
721 minWidth = MIN2(minWidth, texImg->Width);
722 maxWidth = MAX2(maxWidth, texImg->Width);
723 minHeight = MIN2(minHeight, texImg->Height);
724 maxHeight = MAX2(maxHeight, texImg->Height);
725 f = texImg->_BaseFormat;
726 attFormat = texImg->TexFormat;
727 numImages++;
728 if (!_mesa_is_legal_color_format(ctx, f) &&
729 !is_legal_depth_format(ctx, f)) {
730 fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT;
731 fbo_incomplete("texture attachment incomplete", -1);
732 return;
733 }
734 }
735 else if (att->Type == GL_RENDERBUFFER_EXT) {
736 minWidth = MIN2(minWidth, att->Renderbuffer->Width);
737 maxWidth = MAX2(minWidth, att->Renderbuffer->Width);
738 minHeight = MIN2(minHeight, att->Renderbuffer->Height);
739 maxHeight = MAX2(minHeight, att->Renderbuffer->Height);
740 f = att->Renderbuffer->InternalFormat;
741 attFormat = att->Renderbuffer->Format;
742 numImages++;
743 }
744 else {
745 assert(att->Type == GL_NONE);
746 continue;
747 }
748
749 if (att->Renderbuffer && numSamples < 0) {
750 /* first buffer */
751 numSamples = att->Renderbuffer->NumSamples;
752 }
753
754 /* check if integer color */
755 fb->_IntegerColor = _mesa_is_format_integer_color(attFormat);
756
757 /* Error-check width, height, format, samples
758 */
759 if (numImages == 1) {
760 /* save format, num samples */
761 if (i >= 0) {
762 intFormat = f;
763 }
764 }
765 else {
766 if (!ctx->Extensions.ARB_framebuffer_object) {
767 /* check that width, height, format are same */
768 if (minWidth != maxWidth || minHeight != maxHeight) {
769 fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT;
770 fbo_incomplete("width or height mismatch", -1);
771 return;
772 }
773 /* check that all color buffer have same format */
774 if (intFormat != GL_NONE && f != intFormat) {
775 fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT;
776 fbo_incomplete("format mismatch", -1);
777 return;
778 }
779 }
780 if (att->Renderbuffer &&
781 att->Renderbuffer->NumSamples != numSamples) {
782 fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE;
783 fbo_incomplete("inconsistant number of samples", i);
784 return;
785 }
786
787 }
788 }
789
790 #if FEATURE_GL
791 if (ctx->API == API_OPENGL) {
792 /* Check that all DrawBuffers are present */
793 for (j = 0; j < ctx->Const.MaxDrawBuffers; j++) {
794 if (fb->ColorDrawBuffer[j] != GL_NONE) {
795 const struct gl_renderbuffer_attachment *att
796 = _mesa_get_attachment(ctx, fb, fb->ColorDrawBuffer[j]);
797 assert(att);
798 if (att->Type == GL_NONE) {
799 fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT;
800 fbo_incomplete("missing drawbuffer", j);
801 return;
802 }
803 }
804 }
805
806 /* Check that the ReadBuffer is present */
807 if (fb->ColorReadBuffer != GL_NONE) {
808 const struct gl_renderbuffer_attachment *att
809 = _mesa_get_attachment(ctx, fb, fb->ColorReadBuffer);
810 assert(att);
811 if (att->Type == GL_NONE) {
812 fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT;
813 fbo_incomplete("missing readbuffer", -1);
814 return;
815 }
816 }
817 }
818 #else
819 (void) j;
820 #endif
821
822 if (numImages == 0) {
823 fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT;
824 fbo_incomplete("no attachments", -1);
825 return;
826 }
827
828 /* Provisionally set status = COMPLETE ... */
829 fb->_Status = GL_FRAMEBUFFER_COMPLETE_EXT;
830
831 /* ... but the driver may say the FB is incomplete.
832 * Drivers will most likely set the status to GL_FRAMEBUFFER_UNSUPPORTED
833 * if anything.
834 */
835 if (ctx->Driver.ValidateFramebuffer) {
836 ctx->Driver.ValidateFramebuffer(ctx, fb);
837 if (fb->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) {
838 fbo_incomplete("driver marked FBO as incomplete", -1);
839 }
840 }
841
842 if (fb->_Status == GL_FRAMEBUFFER_COMPLETE_EXT) {
843 /*
844 * Note that if ARB_framebuffer_object is supported and the attached
845 * renderbuffers/textures are different sizes, the framebuffer
846 * width/height will be set to the smallest width/height.
847 */
848 fb->Width = minWidth;
849 fb->Height = minHeight;
850
851 /* finally, update the visual info for the framebuffer */
852 _mesa_update_framebuffer_visual(ctx, fb);
853 }
854 }
855
856
857 GLboolean GLAPIENTRY
858 _mesa_IsRenderbufferEXT(GLuint renderbuffer)
859 {
860 GET_CURRENT_CONTEXT(ctx);
861 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE);
862 if (renderbuffer) {
863 struct gl_renderbuffer *rb = _mesa_lookup_renderbuffer(ctx, renderbuffer);
864 if (rb != NULL && rb != &DummyRenderbuffer)
865 return GL_TRUE;
866 }
867 return GL_FALSE;
868 }
869
870
871 void GLAPIENTRY
872 _mesa_BindRenderbufferEXT(GLenum target, GLuint renderbuffer)
873 {
874 struct gl_renderbuffer *newRb;
875 GET_CURRENT_CONTEXT(ctx);
876
877 ASSERT_OUTSIDE_BEGIN_END(ctx);
878
879 if (target != GL_RENDERBUFFER_EXT) {
880 _mesa_error(ctx, GL_INVALID_ENUM, "glBindRenderbufferEXT(target)");
881 return;
882 }
883
884 /* No need to flush here since the render buffer binding has no
885 * effect on rendering state.
886 */
887
888 if (renderbuffer) {
889 newRb = _mesa_lookup_renderbuffer(ctx, renderbuffer);
890 if (newRb == &DummyRenderbuffer) {
891 /* ID was reserved, but no real renderbuffer object made yet */
892 newRb = NULL;
893 }
894 else if (!newRb && ctx->Extensions.ARB_framebuffer_object) {
895 /* All RB IDs must be Gen'd */
896 _mesa_error(ctx, GL_INVALID_OPERATION, "glBindRenderbuffer(buffer)");
897 return;
898 }
899
900 if (!newRb) {
901 /* create new renderbuffer object */
902 newRb = ctx->Driver.NewRenderbuffer(ctx, renderbuffer);
903 if (!newRb) {
904 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glBindRenderbufferEXT");
905 return;
906 }
907 ASSERT(newRb->AllocStorage);
908 _mesa_HashInsert(ctx->Shared->RenderBuffers, renderbuffer, newRb);
909 newRb->RefCount = 1; /* referenced by hash table */
910 }
911 }
912 else {
913 newRb = NULL;
914 }
915
916 ASSERT(newRb != &DummyRenderbuffer);
917
918 _mesa_reference_renderbuffer(&ctx->CurrentRenderbuffer, newRb);
919 }
920
921
922 /**
923 * If the given renderbuffer is anywhere attached to the framebuffer, detach
924 * the renderbuffer.
925 * This is used when a renderbuffer object is deleted.
926 * The spec calls for unbinding.
927 */
928 static void
929 detach_renderbuffer(struct gl_context *ctx,
930 struct gl_framebuffer *fb,
931 struct gl_renderbuffer *rb)
932 {
933 GLuint i;
934 for (i = 0; i < BUFFER_COUNT; i++) {
935 if (fb->Attachment[i].Renderbuffer == rb) {
936 _mesa_remove_attachment(ctx, &fb->Attachment[i]);
937 }
938 }
939 invalidate_framebuffer(fb);
940 }
941
942
943 void GLAPIENTRY
944 _mesa_DeleteRenderbuffersEXT(GLsizei n, const GLuint *renderbuffers)
945 {
946 GLint i;
947 GET_CURRENT_CONTEXT(ctx);
948
949 ASSERT_OUTSIDE_BEGIN_END(ctx);
950 FLUSH_VERTICES(ctx, _NEW_BUFFERS);
951
952 for (i = 0; i < n; i++) {
953 if (renderbuffers[i] > 0) {
954 struct gl_renderbuffer *rb;
955 rb = _mesa_lookup_renderbuffer(ctx, renderbuffers[i]);
956 if (rb) {
957 /* check if deleting currently bound renderbuffer object */
958 if (rb == ctx->CurrentRenderbuffer) {
959 /* bind default */
960 ASSERT(rb->RefCount >= 2);
961 _mesa_BindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0);
962 }
963
964 if (ctx->DrawBuffer->Name) {
965 detach_renderbuffer(ctx, ctx->DrawBuffer, rb);
966 }
967 if (ctx->ReadBuffer->Name && ctx->ReadBuffer != ctx->DrawBuffer) {
968 detach_renderbuffer(ctx, ctx->ReadBuffer, rb);
969 }
970
971 /* Remove from hash table immediately, to free the ID.
972 * But the object will not be freed until it's no longer
973 * referenced anywhere else.
974 */
975 _mesa_HashRemove(ctx->Shared->RenderBuffers, renderbuffers[i]);
976
977 if (rb != &DummyRenderbuffer) {
978 /* no longer referenced by hash table */
979 _mesa_reference_renderbuffer(&rb, NULL);
980 }
981 }
982 }
983 }
984 }
985
986
987 void GLAPIENTRY
988 _mesa_GenRenderbuffersEXT(GLsizei n, GLuint *renderbuffers)
989 {
990 GET_CURRENT_CONTEXT(ctx);
991 GLuint first;
992 GLint i;
993
994 ASSERT_OUTSIDE_BEGIN_END(ctx);
995
996 if (n < 0) {
997 _mesa_error(ctx, GL_INVALID_VALUE, "glGenRenderbuffersEXT(n)");
998 return;
999 }
1000
1001 if (!renderbuffers)
1002 return;
1003
1004 first = _mesa_HashFindFreeKeyBlock(ctx->Shared->RenderBuffers, n);
1005
1006 for (i = 0; i < n; i++) {
1007 GLuint name = first + i;
1008 renderbuffers[i] = name;
1009 /* insert dummy placeholder into hash table */
1010 _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
1011 _mesa_HashInsert(ctx->Shared->RenderBuffers, name, &DummyRenderbuffer);
1012 _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
1013 }
1014 }
1015
1016
1017 /**
1018 * Given an internal format token for a render buffer, return the
1019 * corresponding base format (one of GL_RGB, GL_RGBA, GL_STENCIL_INDEX,
1020 * GL_DEPTH_COMPONENT, GL_DEPTH_STENCIL_EXT, GL_ALPHA, GL_LUMINANCE,
1021 * GL_LUMINANCE_ALPHA, GL_INTENSITY, etc).
1022 *
1023 * This is similar to _mesa_base_tex_format() but the set of valid
1024 * internal formats is different.
1025 *
1026 * Note that even if a format is determined to be legal here, validation
1027 * of the FBO may fail if the format is not supported by the driver/GPU.
1028 *
1029 * \param internalFormat as passed to glRenderbufferStorage()
1030 * \return the base internal format, or 0 if internalFormat is illegal
1031 */
1032 GLenum
1033 _mesa_base_fbo_format(struct gl_context *ctx, GLenum internalFormat)
1034 {
1035 /*
1036 * Notes: some formats such as alpha, luminance, etc. were added
1037 * with GL_ARB_framebuffer_object.
1038 */
1039 switch (internalFormat) {
1040 case GL_ALPHA:
1041 case GL_ALPHA4:
1042 case GL_ALPHA8:
1043 case GL_ALPHA12:
1044 case GL_ALPHA16:
1045 return ctx->Extensions.ARB_framebuffer_object ? GL_ALPHA : 0;
1046 case GL_LUMINANCE:
1047 case GL_LUMINANCE4:
1048 case GL_LUMINANCE8:
1049 case GL_LUMINANCE12:
1050 case GL_LUMINANCE16:
1051 return ctx->Extensions.ARB_framebuffer_object ? GL_LUMINANCE : 0;
1052 case GL_LUMINANCE_ALPHA:
1053 case GL_LUMINANCE4_ALPHA4:
1054 case GL_LUMINANCE6_ALPHA2:
1055 case GL_LUMINANCE8_ALPHA8:
1056 case GL_LUMINANCE12_ALPHA4:
1057 case GL_LUMINANCE12_ALPHA12:
1058 case GL_LUMINANCE16_ALPHA16:
1059 return ctx->Extensions.ARB_framebuffer_object ? GL_LUMINANCE_ALPHA : 0;
1060 case GL_INTENSITY:
1061 case GL_INTENSITY4:
1062 case GL_INTENSITY8:
1063 case GL_INTENSITY12:
1064 case GL_INTENSITY16:
1065 return ctx->Extensions.ARB_framebuffer_object ? GL_INTENSITY : 0;
1066 case GL_RGB:
1067 case GL_R3_G3_B2:
1068 case GL_RGB4:
1069 case GL_RGB5:
1070 case GL_RGB8:
1071 case GL_RGB10:
1072 case GL_RGB12:
1073 case GL_RGB16:
1074 case GL_SRGB8_EXT:
1075 return GL_RGB;
1076 case GL_RGBA:
1077 case GL_RGBA2:
1078 case GL_RGBA4:
1079 case GL_RGB5_A1:
1080 case GL_RGBA8:
1081 case GL_RGB10_A2:
1082 case GL_RGBA12:
1083 case GL_RGBA16:
1084 case GL_SRGB8_ALPHA8_EXT:
1085 return GL_RGBA;
1086 case GL_STENCIL_INDEX:
1087 case GL_STENCIL_INDEX1_EXT:
1088 case GL_STENCIL_INDEX4_EXT:
1089 case GL_STENCIL_INDEX8_EXT:
1090 case GL_STENCIL_INDEX16_EXT:
1091 return GL_STENCIL_INDEX;
1092 case GL_DEPTH_COMPONENT:
1093 case GL_DEPTH_COMPONENT16:
1094 case GL_DEPTH_COMPONENT24:
1095 case GL_DEPTH_COMPONENT32:
1096 return GL_DEPTH_COMPONENT;
1097 case GL_DEPTH_STENCIL_EXT:
1098 case GL_DEPTH24_STENCIL8_EXT:
1099 if (ctx->Extensions.EXT_packed_depth_stencil)
1100 return GL_DEPTH_STENCIL_EXT;
1101 else
1102 return 0;
1103 case GL_RED:
1104 case GL_R8:
1105 case GL_R16:
1106 return ctx->Extensions.ARB_texture_rg ? GL_RED : 0;
1107 case GL_RG:
1108 case GL_RG8:
1109 case GL_RG16:
1110 return ctx->Extensions.ARB_texture_rg ? GL_RG : 0;
1111 /* signed normalized texture formats */
1112 case GL_RED_SNORM:
1113 case GL_R8_SNORM:
1114 case GL_R16_SNORM:
1115 return ctx->Extensions.EXT_texture_snorm ? GL_RED : 0;
1116 case GL_RG_SNORM:
1117 case GL_RG8_SNORM:
1118 case GL_RG16_SNORM:
1119 return ctx->Extensions.EXT_texture_snorm ? GL_RG : 0;
1120 case GL_RGB_SNORM:
1121 case GL_RGB8_SNORM:
1122 case GL_RGB16_SNORM:
1123 return ctx->Extensions.EXT_texture_snorm ? GL_RGB : 0;
1124 case GL_RGBA_SNORM:
1125 case GL_RGBA8_SNORM:
1126 case GL_RGBA16_SNORM:
1127 return ctx->Extensions.EXT_texture_snorm ? GL_RGBA : 0;
1128 case GL_ALPHA_SNORM:
1129 case GL_ALPHA8_SNORM:
1130 case GL_ALPHA16_SNORM:
1131 return ctx->Extensions.EXT_texture_snorm &&
1132 ctx->Extensions.ARB_framebuffer_object ? GL_ALPHA : 0;
1133 case GL_LUMINANCE_SNORM:
1134 case GL_LUMINANCE8_SNORM:
1135 case GL_LUMINANCE16_SNORM:
1136 return ctx->Extensions.EXT_texture_snorm &&
1137 ctx->Extensions.ARB_framebuffer_object ? GL_LUMINANCE : 0;
1138 case GL_LUMINANCE_ALPHA_SNORM:
1139 case GL_LUMINANCE8_ALPHA8_SNORM:
1140 case GL_LUMINANCE16_ALPHA16_SNORM:
1141 return ctx->Extensions.EXT_texture_snorm &&
1142 ctx->Extensions.ARB_framebuffer_object ? GL_LUMINANCE_ALPHA : 0;
1143 case GL_INTENSITY_SNORM:
1144 case GL_INTENSITY8_SNORM:
1145 case GL_INTENSITY16_SNORM:
1146 return ctx->Extensions.EXT_texture_snorm &&
1147 ctx->Extensions.ARB_framebuffer_object ? GL_INTENSITY : 0;
1148 case GL_R16F:
1149 case GL_R32F:
1150 return ctx->Extensions.ARB_texture_rg &&
1151 ctx->Extensions.ARB_texture_float ? GL_RED : 0;
1152 case GL_RG16F:
1153 case GL_RG32F:
1154 return ctx->Extensions.ARB_texture_rg &&
1155 ctx->Extensions.ARB_texture_float ? GL_RG : 0;
1156 case GL_RGB16F:
1157 case GL_RGB32F:
1158 return ctx->Extensions.ARB_texture_float ? GL_RGB : 0;
1159 case GL_RGBA16F:
1160 case GL_RGBA32F:
1161 return ctx->Extensions.ARB_texture_float ? GL_RGBA : 0;
1162 case GL_ALPHA16F_ARB:
1163 case GL_ALPHA32F_ARB:
1164 return ctx->Extensions.ARB_texture_float &&
1165 ctx->Extensions.ARB_framebuffer_object ? GL_ALPHA : 0;
1166 case GL_LUMINANCE16F_ARB:
1167 case GL_LUMINANCE32F_ARB:
1168 return ctx->Extensions.ARB_texture_float &&
1169 ctx->Extensions.ARB_framebuffer_object ? GL_LUMINANCE : 0;
1170 case GL_LUMINANCE_ALPHA16F_ARB:
1171 case GL_LUMINANCE_ALPHA32F_ARB:
1172 return ctx->Extensions.ARB_texture_float &&
1173 ctx->Extensions.ARB_framebuffer_object ? GL_LUMINANCE_ALPHA : 0;
1174 case GL_INTENSITY16F_ARB:
1175 case GL_INTENSITY32F_ARB:
1176 return ctx->Extensions.ARB_texture_float &&
1177 ctx->Extensions.ARB_framebuffer_object ? GL_INTENSITY : 0;
1178 /* XXX add integer formats eventually */
1179 default:
1180 return 0;
1181 }
1182 }
1183
1184
1185 /**
1186 * Invalidate a renderbuffer attachment. Called from _mesa_HashWalk().
1187 */
1188 static void
1189 invalidate_rb(GLuint key, void *data, void *userData)
1190 {
1191 struct gl_framebuffer *fb = (struct gl_framebuffer *) data;
1192 struct gl_renderbuffer *rb = (struct gl_renderbuffer *) userData;
1193
1194 /* If this is a user-created FBO */
1195 if (fb->Name) {
1196 GLuint i;
1197 for (i = 0; i < BUFFER_COUNT; i++) {
1198 struct gl_renderbuffer_attachment *att = fb->Attachment + i;
1199 if (att->Type == GL_RENDERBUFFER &&
1200 att->Renderbuffer == rb) {
1201 /* Mark fb status as indeterminate to force re-validation */
1202 fb->_Status = 0;
1203 return;
1204 }
1205 }
1206 }
1207 }
1208
1209
1210 /** sentinal value, see below */
1211 #define NO_SAMPLES 1000
1212
1213
1214 /**
1215 * Helper function used by _mesa_RenderbufferStorageEXT() and
1216 * _mesa_RenderbufferStorageMultisample().
1217 * samples will be NO_SAMPLES if called by _mesa_RenderbufferStorageEXT().
1218 */
1219 static void
1220 renderbuffer_storage(GLenum target, GLenum internalFormat,
1221 GLsizei width, GLsizei height, GLsizei samples)
1222 {
1223 const char *func = samples == NO_SAMPLES ?
1224 "glRenderbufferStorage" : "RenderbufferStorageMultisample";
1225 struct gl_renderbuffer *rb;
1226 GLenum baseFormat;
1227 GET_CURRENT_CONTEXT(ctx);
1228
1229 ASSERT_OUTSIDE_BEGIN_END(ctx);
1230
1231 if (target != GL_RENDERBUFFER_EXT) {
1232 _mesa_error(ctx, GL_INVALID_ENUM, "%s(target)", func);
1233 return;
1234 }
1235
1236 baseFormat = _mesa_base_fbo_format(ctx, internalFormat);
1237 if (baseFormat == 0) {
1238 _mesa_error(ctx, GL_INVALID_ENUM, "%s(internalFormat)", func);
1239 return;
1240 }
1241
1242 if (width < 1 || width > (GLsizei) ctx->Const.MaxRenderbufferSize) {
1243 _mesa_error(ctx, GL_INVALID_VALUE, "%s(width)", func);
1244 return;
1245 }
1246
1247 if (height < 1 || height > (GLsizei) ctx->Const.MaxRenderbufferSize) {
1248 _mesa_error(ctx, GL_INVALID_VALUE, "%s(height)", func);
1249 return;
1250 }
1251
1252 if (samples == NO_SAMPLES) {
1253 /* NumSamples == 0 indicates non-multisampling */
1254 samples = 0;
1255 }
1256 else if (samples > (GLsizei) ctx->Const.MaxSamples) {
1257 /* note: driver may choose to use more samples than what's requested */
1258 _mesa_error(ctx, GL_INVALID_VALUE, "%s(samples)", func);
1259 return;
1260 }
1261
1262 rb = ctx->CurrentRenderbuffer;
1263 if (!rb) {
1264 _mesa_error(ctx, GL_INVALID_OPERATION, "%s", func);
1265 return;
1266 }
1267
1268 FLUSH_VERTICES(ctx, _NEW_BUFFERS);
1269
1270 if (rb->InternalFormat == internalFormat &&
1271 rb->Width == (GLuint) width &&
1272 rb->Height == (GLuint) height) {
1273 /* no change in allocation needed */
1274 return;
1275 }
1276
1277 /* These MUST get set by the AllocStorage func */
1278 rb->Format = MESA_FORMAT_NONE;
1279 rb->NumSamples = samples;
1280
1281 /* Now allocate the storage */
1282 ASSERT(rb->AllocStorage);
1283 if (rb->AllocStorage(ctx, rb, internalFormat, width, height)) {
1284 /* No error - check/set fields now */
1285 assert(rb->Format != MESA_FORMAT_NONE);
1286 assert(rb->Width == (GLuint) width);
1287 assert(rb->Height == (GLuint) height);
1288 rb->InternalFormat = internalFormat;
1289 rb->_BaseFormat = baseFormat;
1290 assert(rb->_BaseFormat != 0);
1291 }
1292 else {
1293 /* Probably ran out of memory - clear the fields */
1294 rb->Width = 0;
1295 rb->Height = 0;
1296 rb->Format = MESA_FORMAT_NONE;
1297 rb->InternalFormat = GL_NONE;
1298 rb->_BaseFormat = GL_NONE;
1299 rb->NumSamples = 0;
1300 }
1301
1302 /* Invalidate the framebuffers the renderbuffer is attached in. */
1303 if (rb->AttachedAnytime) {
1304 _mesa_HashWalk(ctx->Shared->FrameBuffers, invalidate_rb, rb);
1305 }
1306 }
1307
1308
1309 #if FEATURE_OES_EGL_image
1310 void GLAPIENTRY
1311 _mesa_EGLImageTargetRenderbufferStorageOES(GLenum target, GLeglImageOES image)
1312 {
1313 struct gl_renderbuffer *rb;
1314 GET_CURRENT_CONTEXT(ctx);
1315 ASSERT_OUTSIDE_BEGIN_END(ctx);
1316
1317 if (!ctx->Extensions.OES_EGL_image) {
1318 _mesa_error(ctx, GL_INVALID_OPERATION,
1319 "glEGLImageTargetRenderbufferStorageOES(unsupported)");
1320 return;
1321 }
1322
1323 if (target != GL_RENDERBUFFER) {
1324 _mesa_error(ctx, GL_INVALID_ENUM,
1325 "EGLImageTargetRenderbufferStorageOES");
1326 return;
1327 }
1328
1329 rb = ctx->CurrentRenderbuffer;
1330 if (!rb) {
1331 _mesa_error(ctx, GL_INVALID_OPERATION,
1332 "EGLImageTargetRenderbufferStorageOES");
1333 return;
1334 }
1335
1336 FLUSH_VERTICES(ctx, _NEW_BUFFERS);
1337
1338 ctx->Driver.EGLImageTargetRenderbufferStorage(ctx, rb, image);
1339 }
1340 #endif
1341
1342
1343 /**
1344 * Helper function for _mesa_GetRenderbufferParameterivEXT() and
1345 * _mesa_GetFramebufferAttachmentParameterivEXT()
1346 * We have to be careful to respect the base format. For example, if a
1347 * renderbuffer/texture was created with internalFormat=GL_RGB but the
1348 * driver actually chose a GL_RGBA format, when the user queries ALPHA_SIZE
1349 * we need to return zero.
1350 */
1351 static GLint
1352 get_component_bits(GLenum pname, GLenum baseFormat, gl_format format)
1353 {
1354 switch (pname) {
1355 case GL_RENDERBUFFER_RED_SIZE_EXT:
1356 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE:
1357 if (baseFormat == GL_RGB || baseFormat == GL_RGBA ||
1358 baseFormat == GL_RG || baseFormat == GL_RED)
1359 return _mesa_get_format_bits(format, pname);
1360 else
1361 return 0;
1362 case GL_RENDERBUFFER_GREEN_SIZE_EXT:
1363 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE:
1364 if (baseFormat == GL_RGB || baseFormat == GL_RGBA || baseFormat == GL_RG)
1365 return _mesa_get_format_bits(format, pname);
1366 else
1367 return 0;
1368 case GL_RENDERBUFFER_BLUE_SIZE_EXT:
1369 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE:
1370 if (baseFormat == GL_RGB || baseFormat == GL_RGBA)
1371 return _mesa_get_format_bits(format, pname);
1372 else
1373 return 0;
1374 case GL_RENDERBUFFER_ALPHA_SIZE_EXT:
1375 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE:
1376 if (baseFormat == GL_RGBA || baseFormat == GL_ALPHA ||
1377 baseFormat == GL_LUMINANCE_ALPHA)
1378 return _mesa_get_format_bits(format, pname);
1379 else
1380 return 0;
1381 case GL_RENDERBUFFER_DEPTH_SIZE_EXT:
1382 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE:
1383 if (baseFormat == GL_DEPTH_COMPONENT || baseFormat == GL_DEPTH_STENCIL)
1384 return _mesa_get_format_bits(format, pname);
1385 else
1386 return 0;
1387 case GL_RENDERBUFFER_STENCIL_SIZE_EXT:
1388 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE:
1389 if (baseFormat == GL_STENCIL_INDEX || baseFormat == GL_DEPTH_STENCIL)
1390 return _mesa_get_format_bits(format, pname);
1391 else
1392 return 0;
1393 default:
1394 return 0;
1395 }
1396 }
1397
1398
1399
1400 void GLAPIENTRY
1401 _mesa_RenderbufferStorageEXT(GLenum target, GLenum internalFormat,
1402 GLsizei width, GLsizei height)
1403 {
1404 /* GL_ARB_fbo says calling this function is equivalent to calling
1405 * glRenderbufferStorageMultisample() with samples=0. We pass in
1406 * a token value here just for error reporting purposes.
1407 */
1408 renderbuffer_storage(target, internalFormat, width, height, NO_SAMPLES);
1409 }
1410
1411
1412 void GLAPIENTRY
1413 _mesa_RenderbufferStorageMultisample(GLenum target, GLsizei samples,
1414 GLenum internalFormat,
1415 GLsizei width, GLsizei height)
1416 {
1417 renderbuffer_storage(target, internalFormat, width, height, samples);
1418 }
1419
1420
1421 /**
1422 * OpenGL ES version of glRenderBufferStorage.
1423 */
1424 void GLAPIENTRY
1425 _es_RenderbufferStorageEXT(GLenum target, GLenum internalFormat,
1426 GLsizei width, GLsizei height)
1427 {
1428 switch (internalFormat) {
1429 case GL_RGB565:
1430 /* XXX this confuses GL_RENDERBUFFER_INTERNAL_FORMAT_OES */
1431 /* choose a closest format */
1432 internalFormat = GL_RGB5;
1433 break;
1434 default:
1435 break;
1436 }
1437
1438 renderbuffer_storage(target, internalFormat, width, height, 0);
1439 }
1440
1441
1442 void GLAPIENTRY
1443 _mesa_GetRenderbufferParameterivEXT(GLenum target, GLenum pname, GLint *params)
1444 {
1445 struct gl_renderbuffer *rb;
1446 GET_CURRENT_CONTEXT(ctx);
1447
1448 ASSERT_OUTSIDE_BEGIN_END(ctx);
1449
1450 if (target != GL_RENDERBUFFER_EXT) {
1451 _mesa_error(ctx, GL_INVALID_ENUM,
1452 "glGetRenderbufferParameterivEXT(target)");
1453 return;
1454 }
1455
1456 rb = ctx->CurrentRenderbuffer;
1457 if (!rb) {
1458 _mesa_error(ctx, GL_INVALID_OPERATION,
1459 "glGetRenderbufferParameterivEXT");
1460 return;
1461 }
1462
1463 /* No need to flush here since we're just quering state which is
1464 * not effected by rendering.
1465 */
1466
1467 switch (pname) {
1468 case GL_RENDERBUFFER_WIDTH_EXT:
1469 *params = rb->Width;
1470 return;
1471 case GL_RENDERBUFFER_HEIGHT_EXT:
1472 *params = rb->Height;
1473 return;
1474 case GL_RENDERBUFFER_INTERNAL_FORMAT_EXT:
1475 *params = rb->InternalFormat;
1476 return;
1477 case GL_RENDERBUFFER_RED_SIZE_EXT:
1478 case GL_RENDERBUFFER_GREEN_SIZE_EXT:
1479 case GL_RENDERBUFFER_BLUE_SIZE_EXT:
1480 case GL_RENDERBUFFER_ALPHA_SIZE_EXT:
1481 case GL_RENDERBUFFER_DEPTH_SIZE_EXT:
1482 case GL_RENDERBUFFER_STENCIL_SIZE_EXT:
1483 *params = get_component_bits(pname, rb->_BaseFormat, rb->Format);
1484 break;
1485 case GL_RENDERBUFFER_SAMPLES:
1486 if (ctx->Extensions.ARB_framebuffer_object) {
1487 *params = rb->NumSamples;
1488 break;
1489 }
1490 /* fallthrough */
1491 default:
1492 _mesa_error(ctx, GL_INVALID_ENUM,
1493 "glGetRenderbufferParameterivEXT(target)");
1494 return;
1495 }
1496 }
1497
1498
1499 GLboolean GLAPIENTRY
1500 _mesa_IsFramebufferEXT(GLuint framebuffer)
1501 {
1502 GET_CURRENT_CONTEXT(ctx);
1503 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE);
1504 if (framebuffer) {
1505 struct gl_framebuffer *rb = _mesa_lookup_framebuffer(ctx, framebuffer);
1506 if (rb != NULL && rb != &DummyFramebuffer)
1507 return GL_TRUE;
1508 }
1509 return GL_FALSE;
1510 }
1511
1512
1513 /**
1514 * Check if any of the attachments of the given framebuffer are textures
1515 * (render to texture). Call ctx->Driver.RenderTexture() for such
1516 * attachments.
1517 */
1518 static void
1519 check_begin_texture_render(struct gl_context *ctx, struct gl_framebuffer *fb)
1520 {
1521 GLuint i;
1522 ASSERT(ctx->Driver.RenderTexture);
1523
1524 if (fb->Name == 0)
1525 return; /* can't render to texture with winsys framebuffers */
1526
1527 for (i = 0; i < BUFFER_COUNT; i++) {
1528 struct gl_renderbuffer_attachment *att = fb->Attachment + i;
1529 if (att->Texture && _mesa_get_attachment_teximage(att)) {
1530 ctx->Driver.RenderTexture(ctx, fb, att);
1531 }
1532 }
1533 }
1534
1535
1536 /**
1537 * Examine all the framebuffer's attachments to see if any are textures.
1538 * If so, call ctx->Driver.FinishRenderTexture() for each texture to
1539 * notify the device driver that the texture image may have changed.
1540 */
1541 static void
1542 check_end_texture_render(struct gl_context *ctx, struct gl_framebuffer *fb)
1543 {
1544 if (fb->Name == 0)
1545 return; /* can't render to texture with winsys framebuffers */
1546
1547 if (ctx->Driver.FinishRenderTexture) {
1548 GLuint i;
1549 for (i = 0; i < BUFFER_COUNT; i++) {
1550 struct gl_renderbuffer_attachment *att = fb->Attachment + i;
1551 if (att->Texture && att->Renderbuffer) {
1552 ctx->Driver.FinishRenderTexture(ctx, att);
1553 }
1554 }
1555 }
1556 }
1557
1558
1559 void GLAPIENTRY
1560 _mesa_BindFramebufferEXT(GLenum target, GLuint framebuffer)
1561 {
1562 struct gl_framebuffer *newDrawFb, *newReadFb;
1563 struct gl_framebuffer *oldDrawFb, *oldReadFb;
1564 GLboolean bindReadBuf, bindDrawBuf;
1565 GET_CURRENT_CONTEXT(ctx);
1566
1567 #ifdef DEBUG
1568 if (ctx->Extensions.ARB_framebuffer_object) {
1569 ASSERT(ctx->Extensions.EXT_framebuffer_object);
1570 ASSERT(ctx->Extensions.EXT_framebuffer_blit);
1571 }
1572 #endif
1573
1574 ASSERT_OUTSIDE_BEGIN_END(ctx);
1575
1576 if (!ctx->Extensions.EXT_framebuffer_object) {
1577 _mesa_error(ctx, GL_INVALID_OPERATION,
1578 "glBindFramebufferEXT(unsupported)");
1579 return;
1580 }
1581
1582 switch (target) {
1583 #if FEATURE_EXT_framebuffer_blit
1584 case GL_DRAW_FRAMEBUFFER_EXT:
1585 if (!ctx->Extensions.EXT_framebuffer_blit) {
1586 _mesa_error(ctx, GL_INVALID_ENUM, "glBindFramebufferEXT(target)");
1587 return;
1588 }
1589 bindDrawBuf = GL_TRUE;
1590 bindReadBuf = GL_FALSE;
1591 break;
1592 case GL_READ_FRAMEBUFFER_EXT:
1593 if (!ctx->Extensions.EXT_framebuffer_blit) {
1594 _mesa_error(ctx, GL_INVALID_ENUM, "glBindFramebufferEXT(target)");
1595 return;
1596 }
1597 bindDrawBuf = GL_FALSE;
1598 bindReadBuf = GL_TRUE;
1599 break;
1600 #endif
1601 case GL_FRAMEBUFFER_EXT:
1602 bindDrawBuf = GL_TRUE;
1603 bindReadBuf = GL_TRUE;
1604 break;
1605 default:
1606 _mesa_error(ctx, GL_INVALID_ENUM, "glBindFramebufferEXT(target)");
1607 return;
1608 }
1609
1610 if (framebuffer) {
1611 /* Binding a user-created framebuffer object */
1612 newDrawFb = _mesa_lookup_framebuffer(ctx, framebuffer);
1613 if (newDrawFb == &DummyFramebuffer) {
1614 /* ID was reserved, but no real framebuffer object made yet */
1615 newDrawFb = NULL;
1616 }
1617 else if (!newDrawFb && ctx->Extensions.ARB_framebuffer_object) {
1618 /* All FBO IDs must be Gen'd */
1619 _mesa_error(ctx, GL_INVALID_OPERATION, "glBindFramebuffer(buffer)");
1620 return;
1621 }
1622
1623 if (!newDrawFb) {
1624 /* create new framebuffer object */
1625 newDrawFb = ctx->Driver.NewFramebuffer(ctx, framebuffer);
1626 if (!newDrawFb) {
1627 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glBindFramebufferEXT");
1628 return;
1629 }
1630 _mesa_HashInsert(ctx->Shared->FrameBuffers, framebuffer, newDrawFb);
1631 }
1632 newReadFb = newDrawFb;
1633 }
1634 else {
1635 /* Binding the window system framebuffer (which was originally set
1636 * with MakeCurrent).
1637 */
1638 newDrawFb = ctx->WinSysDrawBuffer;
1639 newReadFb = ctx->WinSysReadBuffer;
1640 }
1641
1642 ASSERT(newDrawFb);
1643 ASSERT(newDrawFb != &DummyFramebuffer);
1644
1645 /* save pointers to current/old framebuffers */
1646 oldDrawFb = ctx->DrawBuffer;
1647 oldReadFb = ctx->ReadBuffer;
1648
1649 /* check if really changing bindings */
1650 if (oldDrawFb == newDrawFb)
1651 bindDrawBuf = GL_FALSE;
1652 if (oldReadFb == newReadFb)
1653 bindReadBuf = GL_FALSE;
1654
1655 /*
1656 * OK, now bind the new Draw/Read framebuffers, if they're changing.
1657 *
1658 * We also check if we're beginning and/or ending render-to-texture.
1659 * When a framebuffer with texture attachments is unbound, call
1660 * ctx->Driver.FinishRenderTexture().
1661 * When a framebuffer with texture attachments is bound, call
1662 * ctx->Driver.RenderTexture().
1663 *
1664 * Note that if the ReadBuffer has texture attachments we don't consider
1665 * that a render-to-texture case.
1666 */
1667 if (bindReadBuf) {
1668 FLUSH_VERTICES(ctx, _NEW_BUFFERS);
1669
1670 /* check if old readbuffer was render-to-texture */
1671 check_end_texture_render(ctx, oldReadFb);
1672
1673 _mesa_reference_framebuffer(&ctx->ReadBuffer, newReadFb);
1674 }
1675
1676 if (bindDrawBuf) {
1677 FLUSH_VERTICES(ctx, _NEW_BUFFERS);
1678
1679 /* check if old read/draw buffers were render-to-texture */
1680 if (!bindReadBuf)
1681 check_end_texture_render(ctx, oldReadFb);
1682
1683 if (oldDrawFb != oldReadFb)
1684 check_end_texture_render(ctx, oldDrawFb);
1685
1686 /* check if newly bound framebuffer has any texture attachments */
1687 check_begin_texture_render(ctx, newDrawFb);
1688
1689 _mesa_reference_framebuffer(&ctx->DrawBuffer, newDrawFb);
1690 }
1691
1692 if ((bindDrawBuf || bindReadBuf) && ctx->Driver.BindFramebuffer) {
1693 ctx->Driver.BindFramebuffer(ctx, target, newDrawFb, newReadFb);
1694 }
1695 }
1696
1697
1698 void GLAPIENTRY
1699 _mesa_DeleteFramebuffersEXT(GLsizei n, const GLuint *framebuffers)
1700 {
1701 GLint i;
1702 GET_CURRENT_CONTEXT(ctx);
1703
1704 ASSERT_OUTSIDE_BEGIN_END(ctx);
1705 FLUSH_VERTICES(ctx, _NEW_BUFFERS);
1706
1707 for (i = 0; i < n; i++) {
1708 if (framebuffers[i] > 0) {
1709 struct gl_framebuffer *fb;
1710 fb = _mesa_lookup_framebuffer(ctx, framebuffers[i]);
1711 if (fb) {
1712 ASSERT(fb == &DummyFramebuffer || fb->Name == framebuffers[i]);
1713
1714 /* check if deleting currently bound framebuffer object */
1715 if (ctx->Extensions.EXT_framebuffer_blit) {
1716 /* separate draw/read binding points */
1717 if (fb == ctx->DrawBuffer) {
1718 /* bind default */
1719 ASSERT(fb->RefCount >= 2);
1720 _mesa_BindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, 0);
1721 }
1722 if (fb == ctx->ReadBuffer) {
1723 /* bind default */
1724 ASSERT(fb->RefCount >= 2);
1725 _mesa_BindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, 0);
1726 }
1727 }
1728 else {
1729 /* only one binding point for read/draw buffers */
1730 if (fb == ctx->DrawBuffer || fb == ctx->ReadBuffer) {
1731 /* bind default */
1732 ASSERT(fb->RefCount >= 2);
1733 _mesa_BindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
1734 }
1735 }
1736
1737 /* remove from hash table immediately, to free the ID */
1738 _mesa_HashRemove(ctx->Shared->FrameBuffers, framebuffers[i]);
1739
1740 if (fb != &DummyFramebuffer) {
1741 /* But the object will not be freed until it's no longer
1742 * bound in any context.
1743 */
1744 _mesa_reference_framebuffer(&fb, NULL);
1745 }
1746 }
1747 }
1748 }
1749 }
1750
1751
1752 void GLAPIENTRY
1753 _mesa_GenFramebuffersEXT(GLsizei n, GLuint *framebuffers)
1754 {
1755 GET_CURRENT_CONTEXT(ctx);
1756 GLuint first;
1757 GLint i;
1758
1759 ASSERT_OUTSIDE_BEGIN_END(ctx);
1760
1761 if (n < 0) {
1762 _mesa_error(ctx, GL_INVALID_VALUE, "glGenFramebuffersEXT(n)");
1763 return;
1764 }
1765
1766 if (!framebuffers)
1767 return;
1768
1769 first = _mesa_HashFindFreeKeyBlock(ctx->Shared->FrameBuffers, n);
1770
1771 for (i = 0; i < n; i++) {
1772 GLuint name = first + i;
1773 framebuffers[i] = name;
1774 /* insert dummy placeholder into hash table */
1775 _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
1776 _mesa_HashInsert(ctx->Shared->FrameBuffers, name, &DummyFramebuffer);
1777 _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
1778 }
1779 }
1780
1781
1782
1783 GLenum GLAPIENTRY
1784 _mesa_CheckFramebufferStatusEXT(GLenum target)
1785 {
1786 struct gl_framebuffer *buffer;
1787 GET_CURRENT_CONTEXT(ctx);
1788
1789 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, 0);
1790
1791 buffer = get_framebuffer_target(ctx, target);
1792 if (!buffer) {
1793 _mesa_error(ctx, GL_INVALID_ENUM, "glCheckFramebufferStatus(target)");
1794 return 0;
1795 }
1796
1797 if (buffer->Name == 0) {
1798 /* The window system / default framebuffer is always complete */
1799 return GL_FRAMEBUFFER_COMPLETE_EXT;
1800 }
1801
1802 /* No need to flush here */
1803
1804 if (buffer->_Status != GL_FRAMEBUFFER_COMPLETE) {
1805 _mesa_test_framebuffer_completeness(ctx, buffer);
1806 }
1807
1808 return buffer->_Status;
1809 }
1810
1811
1812
1813 /**
1814 * Common code called by glFramebufferTexture1D/2D/3DEXT().
1815 */
1816 static void
1817 framebuffer_texture(struct gl_context *ctx, const char *caller, GLenum target,
1818 GLenum attachment, GLenum textarget, GLuint texture,
1819 GLint level, GLint zoffset)
1820 {
1821 struct gl_renderbuffer_attachment *att;
1822 struct gl_texture_object *texObj = NULL;
1823 struct gl_framebuffer *fb;
1824
1825 ASSERT_OUTSIDE_BEGIN_END(ctx);
1826
1827 fb = get_framebuffer_target(ctx, target);
1828 if (!fb) {
1829 _mesa_error(ctx, GL_INVALID_ENUM,
1830 "glFramebufferTexture%sEXT(target=0x%x)", caller, target);
1831 return;
1832 }
1833
1834 /* check framebuffer binding */
1835 if (fb->Name == 0) {
1836 _mesa_error(ctx, GL_INVALID_OPERATION,
1837 "glFramebufferTexture%sEXT", caller);
1838 return;
1839 }
1840
1841
1842 /* The textarget, level, and zoffset parameters are only validated if
1843 * texture is non-zero.
1844 */
1845 if (texture) {
1846 GLboolean err = GL_TRUE;
1847
1848 texObj = _mesa_lookup_texture(ctx, texture);
1849 if (texObj != NULL) {
1850 if (textarget == 0) {
1851 /* XXX what's the purpose of this? */
1852 err = (texObj->Target != GL_TEXTURE_3D) &&
1853 (texObj->Target != GL_TEXTURE_1D_ARRAY_EXT) &&
1854 (texObj->Target != GL_TEXTURE_2D_ARRAY_EXT);
1855 }
1856 else {
1857 err = (texObj->Target == GL_TEXTURE_CUBE_MAP)
1858 ? !IS_CUBE_FACE(textarget)
1859 : (texObj->Target != textarget);
1860 }
1861 }
1862 else {
1863 /* can't render to a non-existant texture */
1864 _mesa_error(ctx, GL_INVALID_OPERATION,
1865 "glFramebufferTexture%sEXT(non existant texture)",
1866 caller);
1867 return;
1868 }
1869
1870 if (err) {
1871 _mesa_error(ctx, GL_INVALID_OPERATION,
1872 "glFramebufferTexture%sEXT(texture target mismatch)",
1873 caller);
1874 return;
1875 }
1876
1877 if (texObj->Target == GL_TEXTURE_3D) {
1878 const GLint maxSize = 1 << (ctx->Const.Max3DTextureLevels - 1);
1879 if (zoffset < 0 || zoffset >= maxSize) {
1880 _mesa_error(ctx, GL_INVALID_VALUE,
1881 "glFramebufferTexture%sEXT(zoffset)", caller);
1882 return;
1883 }
1884 }
1885 else if ((texObj->Target == GL_TEXTURE_1D_ARRAY_EXT) ||
1886 (texObj->Target == GL_TEXTURE_2D_ARRAY_EXT)) {
1887 if (zoffset < 0 || zoffset >= ctx->Const.MaxArrayTextureLayers) {
1888 _mesa_error(ctx, GL_INVALID_VALUE,
1889 "glFramebufferTexture%sEXT(layer)", caller);
1890 return;
1891 }
1892 }
1893
1894 if ((level < 0) ||
1895 (level >= _mesa_max_texture_levels(ctx, texObj->Target))) {
1896 _mesa_error(ctx, GL_INVALID_VALUE,
1897 "glFramebufferTexture%sEXT(level)", caller);
1898 return;
1899 }
1900 }
1901
1902 att = _mesa_get_attachment(ctx, fb, attachment);
1903 if (att == NULL) {
1904 _mesa_error(ctx, GL_INVALID_ENUM,
1905 "glFramebufferTexture%sEXT(attachment)", caller);
1906 return;
1907 }
1908
1909 FLUSH_VERTICES(ctx, _NEW_BUFFERS);
1910
1911 _glthread_LOCK_MUTEX(fb->Mutex);
1912 if (texObj) {
1913 _mesa_set_texture_attachment(ctx, fb, att, texObj, textarget,
1914 level, zoffset);
1915 /* Set the render-to-texture flag. We'll check this flag in
1916 * glTexImage() and friends to determine if we need to revalidate
1917 * any FBOs that might be rendering into this texture.
1918 * This flag never gets cleared since it's non-trivial to determine
1919 * when all FBOs might be done rendering to this texture. That's OK
1920 * though since it's uncommon to render to a texture then repeatedly
1921 * call glTexImage() to change images in the texture.
1922 */
1923 texObj->_RenderToTexture = GL_TRUE;
1924 }
1925 else {
1926 _mesa_remove_attachment(ctx, att);
1927 }
1928
1929 invalidate_framebuffer(fb);
1930
1931 _glthread_UNLOCK_MUTEX(fb->Mutex);
1932 }
1933
1934
1935
1936 void GLAPIENTRY
1937 _mesa_FramebufferTexture1DEXT(GLenum target, GLenum attachment,
1938 GLenum textarget, GLuint texture, GLint level)
1939 {
1940 GET_CURRENT_CONTEXT(ctx);
1941
1942 if ((texture != 0) && (textarget != GL_TEXTURE_1D)) {
1943 _mesa_error(ctx, GL_INVALID_ENUM,
1944 "glFramebufferTexture1DEXT(textarget)");
1945 return;
1946 }
1947
1948 framebuffer_texture(ctx, "1D", target, attachment, textarget, texture,
1949 level, 0);
1950 }
1951
1952
1953 void GLAPIENTRY
1954 _mesa_FramebufferTexture2DEXT(GLenum target, GLenum attachment,
1955 GLenum textarget, GLuint texture, GLint level)
1956 {
1957 GET_CURRENT_CONTEXT(ctx);
1958
1959 if ((texture != 0) &&
1960 (textarget != GL_TEXTURE_2D) &&
1961 (textarget != GL_TEXTURE_RECTANGLE_ARB) &&
1962 (!IS_CUBE_FACE(textarget))) {
1963 _mesa_error(ctx, GL_INVALID_OPERATION,
1964 "glFramebufferTexture2DEXT(textarget=0x%x)", textarget);
1965 return;
1966 }
1967
1968 framebuffer_texture(ctx, "2D", target, attachment, textarget, texture,
1969 level, 0);
1970 }
1971
1972
1973 void GLAPIENTRY
1974 _mesa_FramebufferTexture3DEXT(GLenum target, GLenum attachment,
1975 GLenum textarget, GLuint texture,
1976 GLint level, GLint zoffset)
1977 {
1978 GET_CURRENT_CONTEXT(ctx);
1979
1980 if ((texture != 0) && (textarget != GL_TEXTURE_3D)) {
1981 _mesa_error(ctx, GL_INVALID_ENUM,
1982 "glFramebufferTexture3DEXT(textarget)");
1983 return;
1984 }
1985
1986 framebuffer_texture(ctx, "3D", target, attachment, textarget, texture,
1987 level, zoffset);
1988 }
1989
1990
1991 void GLAPIENTRY
1992 _mesa_FramebufferTextureLayerEXT(GLenum target, GLenum attachment,
1993 GLuint texture, GLint level, GLint layer)
1994 {
1995 GET_CURRENT_CONTEXT(ctx);
1996
1997 framebuffer_texture(ctx, "Layer", target, attachment, 0, texture,
1998 level, layer);
1999 }
2000
2001
2002 void GLAPIENTRY
2003 _mesa_FramebufferRenderbufferEXT(GLenum target, GLenum attachment,
2004 GLenum renderbufferTarget,
2005 GLuint renderbuffer)
2006 {
2007 struct gl_renderbuffer_attachment *att;
2008 struct gl_framebuffer *fb;
2009 struct gl_renderbuffer *rb;
2010 GET_CURRENT_CONTEXT(ctx);
2011
2012 ASSERT_OUTSIDE_BEGIN_END(ctx);
2013
2014 fb = get_framebuffer_target(ctx, target);
2015 if (!fb) {
2016 _mesa_error(ctx, GL_INVALID_ENUM, "glFramebufferRenderbufferEXT(target)");
2017 return;
2018 }
2019
2020 if (renderbufferTarget != GL_RENDERBUFFER_EXT) {
2021 _mesa_error(ctx, GL_INVALID_ENUM,
2022 "glFramebufferRenderbufferEXT(renderbufferTarget)");
2023 return;
2024 }
2025
2026 if (fb->Name == 0) {
2027 /* Can't attach new renderbuffers to a window system framebuffer */
2028 _mesa_error(ctx, GL_INVALID_OPERATION, "glFramebufferRenderbufferEXT");
2029 return;
2030 }
2031
2032 att = _mesa_get_attachment(ctx, fb, attachment);
2033 if (att == NULL) {
2034 _mesa_error(ctx, GL_INVALID_ENUM,
2035 "glFramebufferRenderbufferEXT(invalid attachment %s)",
2036 _mesa_lookup_enum_by_nr(attachment));
2037 return;
2038 }
2039
2040 if (renderbuffer) {
2041 rb = _mesa_lookup_renderbuffer(ctx, renderbuffer);
2042 if (!rb) {
2043 _mesa_error(ctx, GL_INVALID_OPERATION,
2044 "glFramebufferRenderbufferEXT(non-existant"
2045 " renderbuffer %u)", renderbuffer);
2046 return;
2047 }
2048 else if (rb == &DummyRenderbuffer) {
2049 /* This is what NVIDIA does */
2050 _mesa_error(ctx, GL_INVALID_VALUE,
2051 "glFramebufferRenderbufferEXT(renderbuffer %u)",
2052 renderbuffer);
2053 return;
2054 }
2055 }
2056 else {
2057 /* remove renderbuffer attachment */
2058 rb = NULL;
2059 }
2060
2061 if (attachment == GL_DEPTH_STENCIL_ATTACHMENT &&
2062 rb && rb->Format != MESA_FORMAT_NONE) {
2063 /* make sure the renderbuffer is a depth/stencil format */
2064 const GLenum baseFormat = _mesa_get_format_base_format(rb->Format);
2065 if (baseFormat != GL_DEPTH_STENCIL) {
2066 _mesa_error(ctx, GL_INVALID_OPERATION,
2067 "glFramebufferRenderbufferEXT(renderbuffer"
2068 " is not DEPTH_STENCIL format)");
2069 return;
2070 }
2071 }
2072
2073
2074 FLUSH_VERTICES(ctx, _NEW_BUFFERS);
2075
2076 assert(ctx->Driver.FramebufferRenderbuffer);
2077 ctx->Driver.FramebufferRenderbuffer(ctx, fb, attachment, rb);
2078
2079 /* Some subsequent GL commands may depend on the framebuffer's visual
2080 * after the binding is updated. Update visual info now.
2081 */
2082 _mesa_update_framebuffer_visual(ctx, fb);
2083 }
2084
2085
2086 void GLAPIENTRY
2087 _mesa_GetFramebufferAttachmentParameterivEXT(GLenum target, GLenum attachment,
2088 GLenum pname, GLint *params)
2089 {
2090 const struct gl_renderbuffer_attachment *att;
2091 struct gl_framebuffer *buffer;
2092 GET_CURRENT_CONTEXT(ctx);
2093
2094 ASSERT_OUTSIDE_BEGIN_END(ctx);
2095
2096 buffer = get_framebuffer_target(ctx, target);
2097 if (!buffer) {
2098 _mesa_error(ctx, GL_INVALID_ENUM,
2099 "glGetFramebufferAttachmentParameterivEXT(target)");
2100 return;
2101 }
2102
2103 if (buffer->Name == 0) {
2104 /* the default / window-system FBO */
2105 att = _mesa_get_fb0_attachment(ctx, buffer, attachment);
2106 }
2107 else {
2108 /* user-created framebuffer FBO */
2109 att = _mesa_get_attachment(ctx, buffer, attachment);
2110 }
2111
2112 if (att == NULL) {
2113 _mesa_error(ctx, GL_INVALID_ENUM,
2114 "glGetFramebufferAttachmentParameterivEXT(attachment)");
2115 return;
2116 }
2117
2118 if (attachment == GL_DEPTH_STENCIL_ATTACHMENT) {
2119 /* the depth and stencil attachments must point to the same buffer */
2120 const struct gl_renderbuffer_attachment *depthAtt, *stencilAtt;
2121 depthAtt = _mesa_get_attachment(ctx, buffer, GL_DEPTH_ATTACHMENT);
2122 stencilAtt = _mesa_get_attachment(ctx, buffer, GL_STENCIL_ATTACHMENT);
2123 if (depthAtt->Renderbuffer != stencilAtt->Renderbuffer) {
2124 _mesa_error(ctx, GL_INVALID_OPERATION,
2125 "glGetFramebufferAttachmentParameterivEXT(DEPTH/STENCIL"
2126 " attachments differ)");
2127 return;
2128 }
2129 }
2130
2131 /* No need to flush here */
2132
2133 switch (pname) {
2134 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_EXT:
2135 *params = buffer->Name == 0 ? GL_FRAMEBUFFER_DEFAULT : att->Type;
2136 return;
2137 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_EXT:
2138 if (att->Type == GL_RENDERBUFFER_EXT) {
2139 *params = att->Renderbuffer->Name;
2140 }
2141 else if (att->Type == GL_TEXTURE) {
2142 *params = att->Texture->Name;
2143 }
2144 else {
2145 assert(att->Type == GL_NONE);
2146 *params = 0;
2147 }
2148 return;
2149 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_EXT:
2150 if (att->Type == GL_TEXTURE) {
2151 *params = att->TextureLevel;
2152 }
2153 else {
2154 _mesa_error(ctx, GL_INVALID_ENUM,
2155 "glGetFramebufferAttachmentParameterivEXT(pname)");
2156 }
2157 return;
2158 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE_EXT:
2159 if (att->Type == GL_TEXTURE) {
2160 if (att->Texture && att->Texture->Target == GL_TEXTURE_CUBE_MAP) {
2161 *params = GL_TEXTURE_CUBE_MAP_POSITIVE_X + att->CubeMapFace;
2162 }
2163 else {
2164 *params = 0;
2165 }
2166 }
2167 else {
2168 _mesa_error(ctx, GL_INVALID_ENUM,
2169 "glGetFramebufferAttachmentParameterivEXT(pname)");
2170 }
2171 return;
2172 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_3D_ZOFFSET_EXT:
2173 if (att->Type == GL_TEXTURE) {
2174 if (att->Texture && att->Texture->Target == GL_TEXTURE_3D) {
2175 *params = att->Zoffset;
2176 }
2177 else {
2178 *params = 0;
2179 }
2180 }
2181 else {
2182 _mesa_error(ctx, GL_INVALID_ENUM,
2183 "glGetFramebufferAttachmentParameterivEXT(pname)");
2184 }
2185 return;
2186 case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING:
2187 if (!ctx->Extensions.ARB_framebuffer_object) {
2188 _mesa_error(ctx, GL_INVALID_ENUM,
2189 "glGetFramebufferAttachmentParameterivEXT(pname)");
2190 }
2191 else {
2192 if (ctx->Extensions.EXT_framebuffer_sRGB && ctx->Const.sRGBCapable) {
2193 *params = _mesa_get_format_color_encoding(att->Renderbuffer->Format);
2194 }
2195 else {
2196 /* According to ARB_framebuffer_sRGB, we should return LINEAR
2197 * if the sRGB conversion is unsupported. */
2198 *params = GL_LINEAR;
2199 }
2200 }
2201 return;
2202 case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE:
2203 if (!ctx->Extensions.ARB_framebuffer_object) {
2204 _mesa_error(ctx, GL_INVALID_ENUM,
2205 "glGetFramebufferAttachmentParameterivEXT(pname)");
2206 return;
2207 }
2208 else {
2209 gl_format format = att->Renderbuffer->Format;
2210 if (format == MESA_FORMAT_CI8 || format == MESA_FORMAT_S8) {
2211 /* special cases */
2212 *params = GL_INDEX;
2213 }
2214 else {
2215 *params = _mesa_get_format_datatype(format);
2216 }
2217 }
2218 return;
2219 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE:
2220 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE:
2221 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE:
2222 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE:
2223 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE:
2224 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE:
2225 if (!ctx->Extensions.ARB_framebuffer_object) {
2226 _mesa_error(ctx, GL_INVALID_ENUM,
2227 "glGetFramebufferAttachmentParameterivEXT(pname)");
2228 }
2229 else if (att->Texture) {
2230 const struct gl_texture_image *texImage =
2231 _mesa_select_tex_image(ctx, att->Texture, att->Texture->Target,
2232 att->TextureLevel);
2233 if (texImage) {
2234 *params = get_component_bits(pname, texImage->_BaseFormat,
2235 texImage->TexFormat);
2236 }
2237 else {
2238 *params = 0;
2239 }
2240 }
2241 else if (att->Renderbuffer) {
2242 *params = get_component_bits(pname, att->Renderbuffer->_BaseFormat,
2243 att->Renderbuffer->Format);
2244 }
2245 else {
2246 *params = 0;
2247 }
2248 return;
2249 default:
2250 _mesa_error(ctx, GL_INVALID_ENUM,
2251 "glGetFramebufferAttachmentParameterivEXT(pname)");
2252 return;
2253 }
2254 }
2255
2256
2257 void GLAPIENTRY
2258 _mesa_GenerateMipmapEXT(GLenum target)
2259 {
2260 struct gl_texture_object *texObj;
2261 GET_CURRENT_CONTEXT(ctx);
2262
2263 ASSERT_OUTSIDE_BEGIN_END(ctx);
2264 FLUSH_VERTICES(ctx, _NEW_BUFFERS);
2265
2266 switch (target) {
2267 case GL_TEXTURE_1D:
2268 case GL_TEXTURE_2D:
2269 case GL_TEXTURE_3D:
2270 case GL_TEXTURE_CUBE_MAP:
2271 /* OK, legal value */
2272 break;
2273 default:
2274 /* XXX need to implement GL_TEXTURE_1D_ARRAY and GL_TEXTURE_2D_ARRAY */
2275 _mesa_error(ctx, GL_INVALID_ENUM, "glGenerateMipmapEXT(target)");
2276 return;
2277 }
2278
2279 texObj = _mesa_get_current_tex_object(ctx, target);
2280
2281 if (texObj->BaseLevel >= texObj->MaxLevel) {
2282 /* nothing to do */
2283 return;
2284 }
2285
2286 if (texObj->Target == GL_TEXTURE_CUBE_MAP &&
2287 !_mesa_cube_complete(texObj)) {
2288 _mesa_error(ctx, GL_INVALID_OPERATION,
2289 "glGenerateMipmap(incomplete cube map)");
2290 return;
2291 }
2292
2293 _mesa_lock_texture(ctx, texObj);
2294 if (target == GL_TEXTURE_CUBE_MAP) {
2295 GLuint face;
2296 for (face = 0; face < 6; face++)
2297 ctx->Driver.GenerateMipmap(ctx,
2298 GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB + face,
2299 texObj);
2300 }
2301 else {
2302 ctx->Driver.GenerateMipmap(ctx, target, texObj);
2303 }
2304 _mesa_unlock_texture(ctx, texObj);
2305 }
2306
2307
2308 #if FEATURE_EXT_framebuffer_blit
2309
2310 static const struct gl_renderbuffer_attachment *
2311 find_attachment(const struct gl_framebuffer *fb,
2312 const struct gl_renderbuffer *rb)
2313 {
2314 GLuint i;
2315 for (i = 0; i < Elements(fb->Attachment); i++) {
2316 if (fb->Attachment[i].Renderbuffer == rb)
2317 return &fb->Attachment[i];
2318 }
2319 return NULL;
2320 }
2321
2322
2323
2324 /**
2325 * Blit rectangular region, optionally from one framebuffer to another.
2326 *
2327 * Note, if the src buffer is multisampled and the dest is not, this is
2328 * when the samples must be resolved to a single color.
2329 */
2330 void GLAPIENTRY
2331 _mesa_BlitFramebufferEXT(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
2332 GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
2333 GLbitfield mask, GLenum filter)
2334 {
2335 const GLbitfield legalMaskBits = (GL_COLOR_BUFFER_BIT |
2336 GL_DEPTH_BUFFER_BIT |
2337 GL_STENCIL_BUFFER_BIT);
2338 const struct gl_framebuffer *readFb, *drawFb;
2339 const struct gl_renderbuffer *colorReadRb, *colorDrawRb;
2340 GET_CURRENT_CONTEXT(ctx);
2341
2342 ASSERT_OUTSIDE_BEGIN_END(ctx);
2343 FLUSH_VERTICES(ctx, _NEW_BUFFERS);
2344
2345 if (MESA_VERBOSE & VERBOSE_API)
2346 _mesa_debug(ctx,
2347 "glBlitFramebuffer(%d, %d, %d, %d, %d, %d, %d, %d, 0x%x, %s)\n",
2348 srcX0, srcY0, srcX1, srcY1,
2349 dstX0, dstY0, dstX1, dstY1,
2350 mask, _mesa_lookup_enum_by_nr(filter));
2351
2352 if (ctx->NewState) {
2353 _mesa_update_state(ctx);
2354 }
2355
2356 readFb = ctx->ReadBuffer;
2357 drawFb = ctx->DrawBuffer;
2358
2359 if (!readFb || !drawFb) {
2360 /* This will normally never happen but someday we may want to
2361 * support MakeCurrent() with no drawables.
2362 */
2363 return;
2364 }
2365
2366 /* check for complete framebuffers */
2367 if (drawFb->_Status != GL_FRAMEBUFFER_COMPLETE_EXT ||
2368 readFb->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) {
2369 _mesa_error(ctx, GL_INVALID_FRAMEBUFFER_OPERATION_EXT,
2370 "glBlitFramebufferEXT(incomplete draw/read buffers)");
2371 return;
2372 }
2373
2374 if (filter != GL_NEAREST && filter != GL_LINEAR) {
2375 _mesa_error(ctx, GL_INVALID_ENUM, "glBlitFramebufferEXT(filter)");
2376 return;
2377 }
2378
2379 if (mask & ~legalMaskBits) {
2380 _mesa_error( ctx, GL_INVALID_VALUE, "glBlitFramebufferEXT(mask)");
2381 return;
2382 }
2383
2384 /* depth/stencil must be blitted with nearest filtering */
2385 if ((mask & (GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT))
2386 && filter != GL_NEAREST) {
2387 _mesa_error(ctx, GL_INVALID_OPERATION,
2388 "glBlitFramebufferEXT(depth/stencil requires GL_NEAREST filter)");
2389 return;
2390 }
2391
2392 /* get color read/draw renderbuffers */
2393 if (mask & GL_COLOR_BUFFER_BIT) {
2394 colorReadRb = readFb->_ColorReadBuffer;
2395 colorDrawRb = drawFb->_ColorDrawBuffers[0];
2396 }
2397 else {
2398 colorReadRb = colorDrawRb = NULL;
2399 }
2400
2401 if (mask & GL_STENCIL_BUFFER_BIT) {
2402 struct gl_renderbuffer *readRb = readFb->_StencilBuffer;
2403 struct gl_renderbuffer *drawRb = drawFb->_StencilBuffer;
2404 if (!readRb ||
2405 !drawRb ||
2406 _mesa_get_format_bits(readRb->Format, GL_STENCIL_BITS) !=
2407 _mesa_get_format_bits(drawRb->Format, GL_STENCIL_BITS)) {
2408 _mesa_error(ctx, GL_INVALID_OPERATION,
2409 "glBlitFramebufferEXT(stencil buffer size mismatch)");
2410 return;
2411 }
2412 }
2413
2414 if (mask & GL_DEPTH_BUFFER_BIT) {
2415 struct gl_renderbuffer *readRb = readFb->_DepthBuffer;
2416 struct gl_renderbuffer *drawRb = drawFb->_DepthBuffer;
2417 if (!readRb ||
2418 !drawRb ||
2419 _mesa_get_format_bits(readRb->Format, GL_DEPTH_BITS) !=
2420 _mesa_get_format_bits(drawRb->Format, GL_DEPTH_BITS)) {
2421 _mesa_error(ctx, GL_INVALID_OPERATION,
2422 "glBlitFramebufferEXT(depth buffer size mismatch)");
2423 return;
2424 }
2425 }
2426
2427 if (readFb->Visual.samples > 0 &&
2428 drawFb->Visual.samples > 0 &&
2429 readFb->Visual.samples != drawFb->Visual.samples) {
2430 _mesa_error(ctx, GL_INVALID_OPERATION,
2431 "glBlitFramebufferEXT(mismatched samples");
2432 return;
2433 }
2434
2435 /* extra checks for multisample copies... */
2436 if (readFb->Visual.samples > 0 || drawFb->Visual.samples > 0) {
2437 /* src and dest region sizes must be the same */
2438 if (srcX1 - srcX0 != dstX1 - dstX0 ||
2439 srcY1 - srcY0 != dstY1 - dstY0) {
2440 _mesa_error(ctx, GL_INVALID_OPERATION,
2441 "glBlitFramebufferEXT(bad src/dst multisample region sizes)");
2442 return;
2443 }
2444
2445 /* color formats must match */
2446 if (colorReadRb &&
2447 colorDrawRb &&
2448 colorReadRb->Format != colorDrawRb->Format) {
2449 _mesa_error(ctx, GL_INVALID_OPERATION,
2450 "glBlitFramebufferEXT(bad src/dst multisample pixel formats)");
2451 return;
2452 }
2453 }
2454
2455 if (!ctx->Extensions.EXT_framebuffer_blit) {
2456 _mesa_error(ctx, GL_INVALID_OPERATION, "glBlitFramebufferEXT");
2457 return;
2458 }
2459
2460 /* Debug code */
2461 if (DEBUG_BLIT) {
2462 printf("glBlitFramebuffer(%d, %d, %d, %d, %d, %d, %d, %d,"
2463 " 0x%x, 0x%x)\n",
2464 srcX0, srcY0, srcX1, srcY1,
2465 dstX0, dstY0, dstX1, dstY1,
2466 mask, filter);
2467 if (colorReadRb) {
2468 const struct gl_renderbuffer_attachment *att;
2469
2470 att = find_attachment(readFb, colorReadRb);
2471 printf(" Src FBO %u RB %u (%dx%d) ",
2472 readFb->Name, colorReadRb->Name,
2473 colorReadRb->Width, colorReadRb->Height);
2474 if (att && att->Texture) {
2475 printf("Tex %u tgt 0x%x level %u face %u",
2476 att->Texture->Name,
2477 att->Texture->Target,
2478 att->TextureLevel,
2479 att->CubeMapFace);
2480 }
2481 printf("\n");
2482
2483 att = find_attachment(drawFb, colorDrawRb);
2484 printf(" Dst FBO %u RB %u (%dx%d) ",
2485 drawFb->Name, colorDrawRb->Name,
2486 colorDrawRb->Width, colorDrawRb->Height);
2487 if (att && att->Texture) {
2488 printf("Tex %u tgt 0x%x level %u face %u",
2489 att->Texture->Name,
2490 att->Texture->Target,
2491 att->TextureLevel,
2492 att->CubeMapFace);
2493 }
2494 printf("\n");
2495 }
2496 }
2497
2498 ASSERT(ctx->Driver.BlitFramebuffer);
2499 ctx->Driver.BlitFramebuffer(ctx,
2500 srcX0, srcY0, srcX1, srcY1,
2501 dstX0, dstY0, dstX1, dstY1,
2502 mask, filter);
2503 }
2504 #endif /* FEATURE_EXT_framebuffer_blit */
2505
2506 #if FEATURE_ARB_geometry_shader4
2507 void GLAPIENTRY
2508 _mesa_FramebufferTextureARB(GLenum target, GLenum attachment,
2509 GLuint texture, GLint level)
2510 {
2511 GET_CURRENT_CONTEXT(ctx);
2512 _mesa_error(ctx, GL_INVALID_OPERATION,
2513 "glFramebufferTextureARB "
2514 "not implemented!");
2515 }
2516
2517 void GLAPIENTRY
2518 _mesa_FramebufferTextureFaceARB(GLenum target, GLenum attachment,
2519 GLuint texture, GLint level, GLenum face)
2520 {
2521 GET_CURRENT_CONTEXT(ctx);
2522 _mesa_error(ctx, GL_INVALID_OPERATION,
2523 "glFramebufferTextureFaceARB "
2524 "not implemented!");
2525 }
2526 #endif /* FEATURE_ARB_geometry_shader4 */