953295c0e1652331264302b630624e8834ac0fcb
[mesa.git] / src / mesa / state_tracker / st_cb_fbo.c
1 /**************************************************************************
2 *
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * 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
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * 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
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28
29 /**
30 * Framebuffer/renderbuffer functions.
31 *
32 * \author Brian Paul
33 */
34
35
36 #include "main/imports.h"
37 #include "main/context.h"
38 #include "main/fbobject.h"
39 #include "main/framebuffer.h"
40 #include "main/macros.h"
41 #include "main/mfeatures.h"
42 #include "main/renderbuffer.h"
43
44 #include "pipe/p_context.h"
45 #include "pipe/p_defines.h"
46 #include "pipe/p_screen.h"
47 #include "st_context.h"
48 #include "st_cb_fbo.h"
49 #include "st_cb_flush.h"
50 #include "st_cb_texture.h"
51 #include "st_format.h"
52 #include "st_texture.h"
53 #include "st_manager.h"
54
55 #include "util/u_format.h"
56 #include "util/u_inlines.h"
57 #include "util/u_surface.h"
58
59
60 /**
61 * gl_renderbuffer::AllocStorage()
62 * This is called to allocate the original drawing surface, and
63 * during window resize.
64 */
65 static GLboolean
66 st_renderbuffer_alloc_storage(struct gl_context * ctx,
67 struct gl_renderbuffer *rb,
68 GLenum internalFormat,
69 GLuint width, GLuint height)
70 {
71 struct st_context *st = st_context(ctx);
72 struct pipe_context *pipe = st->pipe;
73 struct pipe_screen *screen = st->pipe->screen;
74 struct st_renderbuffer *strb = st_renderbuffer(rb);
75 enum pipe_format format;
76 struct pipe_surface surf_tmpl;
77
78 if (internalFormat == GL_RGBA16_SNORM && strb->software) {
79 /* Special case for software accum buffers. Otherwise, if the
80 * call to st_choose_renderbuffer_format() fails (because the
81 * driver doesn't support signed 16-bit/channel colors) we'd
82 * just return without allocating the software accum buffer.
83 */
84 format = PIPE_FORMAT_R16G16B16A16_SNORM;
85 }
86 else {
87 format = st_choose_renderbuffer_format(screen, internalFormat,
88 rb->NumSamples);
89 }
90
91 if (format == PIPE_FORMAT_NONE) {
92 return FALSE;
93 }
94
95 /* init renderbuffer fields */
96 strb->Base.Width = width;
97 strb->Base.Height = height;
98 strb->Base.Format = st_pipe_format_to_mesa_format(format);
99 strb->Base._BaseFormat = _mesa_base_fbo_format(ctx, internalFormat);
100
101 strb->defined = GL_FALSE; /* undefined contents now */
102
103 if (strb->software) {
104 size_t size;
105
106 free(strb->data);
107
108 size = _mesa_format_image_size(strb->Base.Format, width, height, 1);
109
110 strb->data = malloc(size);
111
112 return strb->data != NULL;
113 }
114 else {
115 struct pipe_resource template;
116
117 /* Free the old surface and texture
118 */
119 pipe_surface_reference( &strb->surface, NULL );
120 pipe_resource_reference( &strb->texture, NULL );
121
122 if (width == 0 || height == 0) {
123 /* if size is zero, nothing to allocate */
124 return GL_TRUE;
125 }
126
127 /* Setup new texture template.
128 */
129 memset(&template, 0, sizeof(template));
130 template.target = st->internal_target;
131 template.format = format;
132 template.width0 = width;
133 template.height0 = height;
134 template.depth0 = 1;
135 template.array_size = 1;
136 template.last_level = 0;
137 template.nr_samples = rb->NumSamples;
138 if (util_format_is_depth_or_stencil(format)) {
139 template.bind = PIPE_BIND_DEPTH_STENCIL;
140 }
141 else if (strb->Base.Name != 0) {
142 /* this is a user-created renderbuffer */
143 template.bind = PIPE_BIND_RENDER_TARGET;
144 }
145 else {
146 /* this is a window-system buffer */
147 template.bind = (PIPE_BIND_DISPLAY_TARGET |
148 PIPE_BIND_RENDER_TARGET);
149 }
150
151 strb->texture = screen->resource_create(screen, &template);
152
153 if (!strb->texture)
154 return FALSE;
155
156 u_surface_default_template(&surf_tmpl, strb->texture, template.bind);
157 strb->surface = pipe->create_surface(pipe,
158 strb->texture,
159 &surf_tmpl);
160 if (strb->surface) {
161 assert(strb->surface->texture);
162 assert(strb->surface->format);
163 assert(strb->surface->width == width);
164 assert(strb->surface->height == height);
165 }
166
167 return strb->surface != NULL;
168 }
169 }
170
171
172 /**
173 * gl_renderbuffer::Delete()
174 */
175 static void
176 st_renderbuffer_delete(struct gl_renderbuffer *rb)
177 {
178 struct st_renderbuffer *strb = st_renderbuffer(rb);
179 ASSERT(strb);
180 pipe_surface_reference(&strb->surface, NULL);
181 pipe_resource_reference(&strb->texture, NULL);
182 free(strb->data);
183 free(strb);
184 }
185
186
187 /**
188 * Called via ctx->Driver.NewFramebuffer()
189 */
190 static struct gl_framebuffer *
191 st_new_framebuffer(struct gl_context *ctx, GLuint name)
192 {
193 /* XXX not sure we need to subclass gl_framebuffer for pipe */
194 return _mesa_new_framebuffer(ctx, name);
195 }
196
197
198 /**
199 * Called via ctx->Driver.NewRenderbuffer()
200 */
201 static struct gl_renderbuffer *
202 st_new_renderbuffer(struct gl_context *ctx, GLuint name)
203 {
204 struct st_renderbuffer *strb = ST_CALLOC_STRUCT(st_renderbuffer);
205 if (strb) {
206 assert(name != 0);
207 _mesa_init_renderbuffer(&strb->Base, name);
208 strb->Base.Delete = st_renderbuffer_delete;
209 strb->Base.AllocStorage = st_renderbuffer_alloc_storage;
210 return &strb->Base;
211 }
212 return NULL;
213 }
214
215
216 /**
217 * Allocate a renderbuffer for a an on-screen window (not a user-created
218 * renderbuffer). The window system code determines the format.
219 */
220 struct gl_renderbuffer *
221 st_new_renderbuffer_fb(enum pipe_format format, int samples, boolean sw)
222 {
223 struct st_renderbuffer *strb;
224
225 strb = ST_CALLOC_STRUCT(st_renderbuffer);
226 if (!strb) {
227 _mesa_error(NULL, GL_OUT_OF_MEMORY, "creating renderbuffer");
228 return NULL;
229 }
230
231 _mesa_init_renderbuffer(&strb->Base, 0);
232 strb->Base.ClassID = 0x4242; /* just a unique value */
233 strb->Base.NumSamples = samples;
234 strb->Base.Format = st_pipe_format_to_mesa_format(format);
235 strb->Base._BaseFormat = _mesa_get_format_base_format(strb->Base.Format);
236 strb->software = sw;
237
238 switch (format) {
239 case PIPE_FORMAT_R8G8B8A8_UNORM:
240 case PIPE_FORMAT_B8G8R8A8_UNORM:
241 case PIPE_FORMAT_A8R8G8B8_UNORM:
242 case PIPE_FORMAT_R8G8B8X8_UNORM:
243 case PIPE_FORMAT_B8G8R8X8_UNORM:
244 case PIPE_FORMAT_X8R8G8B8_UNORM:
245 case PIPE_FORMAT_B5G5R5A1_UNORM:
246 case PIPE_FORMAT_B4G4R4A4_UNORM:
247 case PIPE_FORMAT_B5G6R5_UNORM:
248 strb->Base.InternalFormat = GL_RGBA;
249 break;
250 case PIPE_FORMAT_Z16_UNORM:
251 strb->Base.InternalFormat = GL_DEPTH_COMPONENT16;
252 break;
253 case PIPE_FORMAT_Z32_UNORM:
254 strb->Base.InternalFormat = GL_DEPTH_COMPONENT32;
255 break;
256 case PIPE_FORMAT_Z24_UNORM_S8_UINT:
257 case PIPE_FORMAT_S8_UINT_Z24_UNORM:
258 case PIPE_FORMAT_Z24X8_UNORM:
259 case PIPE_FORMAT_X8Z24_UNORM:
260 strb->Base.InternalFormat = GL_DEPTH24_STENCIL8_EXT;
261 break;
262 case PIPE_FORMAT_S8_UINT:
263 strb->Base.InternalFormat = GL_STENCIL_INDEX8_EXT;
264 break;
265 case PIPE_FORMAT_R16G16B16A16_SNORM:
266 /* accum buffer */
267 strb->Base.InternalFormat = GL_RGBA16_SNORM;
268 break;
269 case PIPE_FORMAT_R8_UNORM:
270 strb->Base.InternalFormat = GL_R8;
271 break;
272 case PIPE_FORMAT_R8G8_UNORM:
273 strb->Base.InternalFormat = GL_RG8;
274 break;
275 case PIPE_FORMAT_R16_UNORM:
276 strb->Base.InternalFormat = GL_R16;
277 break;
278 case PIPE_FORMAT_R16G16_UNORM:
279 strb->Base.InternalFormat = GL_RG16;
280 break;
281 case PIPE_FORMAT_R32G32B32A32_FLOAT:
282 strb->Base.InternalFormat = GL_RGBA32F;
283 break;
284 case PIPE_FORMAT_R16G16B16A16_FLOAT:
285 strb->Base.InternalFormat = GL_RGBA16F;
286 break;
287 default:
288 _mesa_problem(NULL,
289 "Unexpected format %s in st_new_renderbuffer_fb",
290 util_format_name(format));
291 free(strb);
292 return NULL;
293 }
294
295 /* st-specific methods */
296 strb->Base.Delete = st_renderbuffer_delete;
297 strb->Base.AllocStorage = st_renderbuffer_alloc_storage;
298
299 /* surface is allocated in st_renderbuffer_alloc_storage() */
300 strb->surface = NULL;
301
302 return &strb->Base;
303 }
304
305
306 /**
307 * Called via ctx->Driver.BindFramebufferEXT().
308 */
309 static void
310 st_bind_framebuffer(struct gl_context *ctx, GLenum target,
311 struct gl_framebuffer *fb, struct gl_framebuffer *fbread)
312 {
313 /* no-op */
314 }
315
316
317 /**
318 * Called by ctx->Driver.RenderTexture
319 */
320 static void
321 st_render_texture(struct gl_context *ctx,
322 struct gl_framebuffer *fb,
323 struct gl_renderbuffer_attachment *att)
324 {
325 struct st_context *st = st_context(ctx);
326 struct pipe_context *pipe = st->pipe;
327 struct st_renderbuffer *strb;
328 struct gl_renderbuffer *rb;
329 struct pipe_resource *pt;
330 struct st_texture_object *stObj;
331 const struct gl_texture_image *texImage;
332 struct pipe_surface surf_tmpl;
333
334 if (!st_finalize_texture(ctx, pipe, att->Texture))
335 return;
336
337 pt = st_get_texobj_resource(att->Texture);
338 assert(pt);
339
340 /* get pointer to texture image we're rendeing to */
341 texImage = _mesa_get_attachment_teximage(att);
342
343 /* create new renderbuffer which wraps the texture image.
344 * Use the texture's name as the renderbuffer's name so that we have
345 * something that's non-zero (to determine vertical orientation) and
346 * possibly helpful for debugging.
347 */
348 rb = st_new_renderbuffer(ctx, att->Texture->Name);
349 if (!rb) {
350 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glFramebufferTexture()");
351 return;
352 }
353
354 _mesa_reference_renderbuffer(&att->Renderbuffer, rb);
355 assert(rb->RefCount == 1);
356 rb->AllocStorage = NULL; /* should not get called */
357 strb = st_renderbuffer(rb);
358
359 assert(strb->Base.RefCount > 0);
360
361 /* get the texture for the texture object */
362 stObj = st_texture_object(att->Texture);
363
364 /* point renderbuffer at texobject */
365 strb->rtt = stObj;
366 strb->rtt_level = att->TextureLevel;
367 strb->rtt_face = att->CubeMapFace;
368 strb->rtt_slice = att->Zoffset;
369
370 rb->Width = texImage->Width2;
371 rb->Height = texImage->Height2;
372 rb->_BaseFormat = texImage->_BaseFormat;
373 rb->InternalFormat = texImage->InternalFormat;
374
375 pipe_resource_reference( &strb->texture, pt );
376
377 pipe_surface_reference(&strb->surface, NULL);
378
379 assert(strb->rtt_level <= strb->texture->last_level);
380
381 /* new surface for rendering into the texture */
382 memset(&surf_tmpl, 0, sizeof(surf_tmpl));
383 surf_tmpl.format = ctx->Color.sRGBEnabled
384 ? strb->texture->format : util_format_linear(strb->texture->format);
385 surf_tmpl.usage = PIPE_BIND_RENDER_TARGET;
386 surf_tmpl.u.tex.level = strb->rtt_level;
387 surf_tmpl.u.tex.first_layer = strb->rtt_face + strb->rtt_slice;
388 surf_tmpl.u.tex.last_layer = strb->rtt_face + strb->rtt_slice;
389 strb->surface = pipe->create_surface(pipe,
390 strb->texture,
391 &surf_tmpl);
392
393 strb->Base.Format = st_pipe_format_to_mesa_format(pt->format);
394
395 /* Invalidate buffer state so that the pipe's framebuffer state
396 * gets updated.
397 * That's where the new renderbuffer (which we just created) gets
398 * passed to the pipe as a (color/depth) render target.
399 */
400 st_invalidate_state(ctx, _NEW_BUFFERS);
401 }
402
403
404 /**
405 * Called via ctx->Driver.FinishRenderTexture.
406 */
407 static void
408 st_finish_render_texture(struct gl_context *ctx,
409 struct gl_renderbuffer_attachment *att)
410 {
411 struct st_renderbuffer *strb = st_renderbuffer(att->Renderbuffer);
412
413 if (!strb)
414 return;
415
416 strb->rtt = NULL;
417
418 /* restore previous framebuffer state */
419 st_invalidate_state(ctx, _NEW_BUFFERS);
420 }
421
422
423 /**
424 * Validate a renderbuffer attachment for a particular set of bindings.
425 */
426 static GLboolean
427 st_validate_attachment(struct gl_context *ctx,
428 struct pipe_screen *screen,
429 const struct gl_renderbuffer_attachment *att,
430 unsigned bindings)
431 {
432 const struct st_texture_object *stObj = st_texture_object(att->Texture);
433 enum pipe_format format;
434 gl_format texFormat;
435
436 /* Only validate texture attachments for now, since
437 * st_renderbuffer_alloc_storage makes sure that
438 * the format is supported.
439 */
440 if (att->Type != GL_TEXTURE)
441 return GL_TRUE;
442
443 if (!stObj)
444 return GL_FALSE;
445
446 format = stObj->pt->format;
447 texFormat = _mesa_get_attachment_teximage_const(att)->TexFormat;
448
449 /* If the encoding is sRGB and sRGB rendering cannot be enabled,
450 * check for linear format support instead.
451 * Later when we create a surface, we change the format to a linear one. */
452 if (!ctx->Extensions.EXT_framebuffer_sRGB &&
453 _mesa_get_format_color_encoding(texFormat) == GL_SRGB) {
454 const gl_format linearFormat = _mesa_get_srgb_format_linear(texFormat);
455 format = st_mesa_format_to_pipe_format(linearFormat);
456 }
457
458 return screen->is_format_supported(screen, format,
459 PIPE_TEXTURE_2D,
460 stObj->pt->nr_samples, bindings);
461 }
462
463
464 /**
465 * Check if two renderbuffer attachments name a combined depth/stencil
466 * renderbuffer.
467 */
468 GLboolean
469 st_is_depth_stencil_combined(const struct gl_renderbuffer_attachment *depth,
470 const struct gl_renderbuffer_attachment *stencil)
471 {
472 assert(depth && stencil);
473
474 if (depth->Type == stencil->Type) {
475 if (depth->Type == GL_RENDERBUFFER_EXT &&
476 depth->Renderbuffer == stencil->Renderbuffer)
477 return GL_TRUE;
478
479 if (depth->Type == GL_TEXTURE &&
480 depth->Texture == stencil->Texture)
481 return GL_TRUE;
482 }
483
484 return GL_FALSE;
485 }
486
487
488 /**
489 * Check that the framebuffer configuration is valid in terms of what
490 * the driver can support.
491 *
492 * For Gallium we only supports combined Z+stencil, not separate buffers.
493 */
494 static void
495 st_validate_framebuffer(struct gl_context *ctx, struct gl_framebuffer *fb)
496 {
497 struct st_context *st = st_context(ctx);
498 struct pipe_screen *screen = st->pipe->screen;
499 const struct gl_renderbuffer_attachment *depth =
500 &fb->Attachment[BUFFER_DEPTH];
501 const struct gl_renderbuffer_attachment *stencil =
502 &fb->Attachment[BUFFER_STENCIL];
503 GLuint i;
504 enum pipe_format first_format = PIPE_FORMAT_NONE;
505 boolean mixed_formats =
506 screen->get_param(screen, PIPE_CAP_MIXED_COLORBUFFER_FORMATS) != 0;
507
508 if (depth->Type && stencil->Type && depth->Type != stencil->Type) {
509 fb->_Status = GL_FRAMEBUFFER_UNSUPPORTED_EXT;
510 return;
511 }
512 if (depth->Type == GL_RENDERBUFFER_EXT &&
513 stencil->Type == GL_RENDERBUFFER_EXT &&
514 depth->Renderbuffer != stencil->Renderbuffer) {
515 fb->_Status = GL_FRAMEBUFFER_UNSUPPORTED_EXT;
516 return;
517 }
518 if (depth->Type == GL_TEXTURE &&
519 stencil->Type == GL_TEXTURE &&
520 depth->Texture != stencil->Texture) {
521 fb->_Status = GL_FRAMEBUFFER_UNSUPPORTED_EXT;
522 return;
523 }
524
525 if (!st_validate_attachment(ctx,
526 screen,
527 depth,
528 PIPE_BIND_DEPTH_STENCIL)) {
529 fb->_Status = GL_FRAMEBUFFER_UNSUPPORTED_EXT;
530 return;
531 }
532 if (!st_validate_attachment(ctx,
533 screen,
534 stencil,
535 PIPE_BIND_DEPTH_STENCIL)) {
536 fb->_Status = GL_FRAMEBUFFER_UNSUPPORTED_EXT;
537 return;
538 }
539 for (i = 0; i < ctx->Const.MaxColorAttachments; i++) {
540 struct gl_renderbuffer_attachment *att =
541 &fb->Attachment[BUFFER_COLOR0 + i];
542 enum pipe_format format;
543
544 if (!st_validate_attachment(ctx,
545 screen,
546 att,
547 PIPE_BIND_RENDER_TARGET)) {
548 fb->_Status = GL_FRAMEBUFFER_UNSUPPORTED_EXT;
549 return;
550 }
551
552 if (!mixed_formats) {
553 /* Disallow mixed formats. */
554 if (att->Type != GL_NONE) {
555 format = st_renderbuffer(att->Renderbuffer)->surface->format;
556 } else {
557 continue;
558 }
559
560 if (first_format == PIPE_FORMAT_NONE) {
561 first_format = format;
562 } else if (format != first_format) {
563 fb->_Status = GL_FRAMEBUFFER_UNSUPPORTED_EXT;
564 return;
565 }
566 }
567 }
568 }
569
570
571 /**
572 * Called via glDrawBuffer.
573 */
574 static void
575 st_DrawBuffers(struct gl_context *ctx, GLsizei count, const GLenum *buffers)
576 {
577 struct st_context *st = st_context(ctx);
578 struct gl_framebuffer *fb = ctx->DrawBuffer;
579 GLuint i;
580
581 (void) count;
582 (void) buffers;
583
584 /* add the renderbuffers on demand */
585 for (i = 0; i < fb->_NumColorDrawBuffers; i++) {
586 gl_buffer_index idx = fb->_ColorDrawBufferIndexes[i];
587 st_manager_add_color_renderbuffer(st, fb, idx);
588 }
589 }
590
591
592 /**
593 * Called via glReadBuffer.
594 */
595 static void
596 st_ReadBuffer(struct gl_context *ctx, GLenum buffer)
597 {
598 struct st_context *st = st_context(ctx);
599 struct gl_framebuffer *fb = ctx->ReadBuffer;
600
601 (void) buffer;
602
603 /* add the renderbuffer on demand */
604 st_manager_add_color_renderbuffer(st, fb, fb->_ColorReadBufferIndex);
605 }
606
607
608
609 /**
610 * Called via ctx->Driver.MapRenderbuffer.
611 */
612 static void
613 st_MapRenderbuffer(struct gl_context *ctx,
614 struct gl_renderbuffer *rb,
615 GLuint x, GLuint y, GLuint w, GLuint h,
616 GLbitfield mode,
617 GLubyte **mapOut, GLint *rowStrideOut)
618 {
619 struct st_context *st = st_context(ctx);
620 struct st_renderbuffer *strb = st_renderbuffer(rb);
621 struct pipe_context *pipe = st->pipe;
622 const GLboolean invert = rb->Name == 0;
623 unsigned usage;
624 GLuint y2;
625
626 if (strb->software) {
627 /* software-allocated renderbuffer (probably an accum buffer) */
628 if (strb->data) {
629 GLint bpp = _mesa_get_format_bytes(strb->Base.Format);
630 GLint stride = _mesa_format_row_stride(strb->Base.Format,
631 strb->Base.Width);
632 *mapOut = (GLubyte *) strb->data + y * stride + x * bpp;
633 *rowStrideOut = stride;
634 }
635 else {
636 *mapOut = NULL;
637 *rowStrideOut = 0;
638 }
639 return;
640 }
641
642 usage = 0x0;
643 if (mode & GL_MAP_READ_BIT)
644 usage |= PIPE_TRANSFER_READ;
645 if (mode & GL_MAP_WRITE_BIT)
646 usage |= PIPE_TRANSFER_WRITE;
647 if (mode & GL_MAP_INVALIDATE_RANGE_BIT)
648 usage |= PIPE_TRANSFER_DISCARD_RANGE;
649
650 /* Note: y=0=bottom of buffer while y2=0=top of buffer.
651 * 'invert' will be true for window-system buffers and false for
652 * user-allocated renderbuffers and textures.
653 */
654 if (invert)
655 y2 = strb->Base.Height - y - h;
656 else
657 y2 = y;
658
659 strb->transfer = pipe_get_transfer(pipe,
660 strb->texture,
661 strb->rtt_level,
662 strb->rtt_face + strb->rtt_slice,
663 usage, x, y2, w, h);
664 if (strb->transfer) {
665 GLubyte *map = pipe_transfer_map(pipe, strb->transfer);
666 if (invert) {
667 *rowStrideOut = -strb->transfer->stride;
668 map += (h - 1) * strb->transfer->stride;
669 }
670 else {
671 *rowStrideOut = strb->transfer->stride;
672 }
673 *mapOut = map;
674 }
675 else {
676 *mapOut = NULL;
677 *rowStrideOut = 0;
678 }
679 }
680
681
682 /**
683 * Called via ctx->Driver.UnmapRenderbuffer.
684 */
685 static void
686 st_UnmapRenderbuffer(struct gl_context *ctx,
687 struct gl_renderbuffer *rb)
688 {
689 struct st_context *st = st_context(ctx);
690 struct st_renderbuffer *strb = st_renderbuffer(rb);
691 struct pipe_context *pipe = st->pipe;
692
693 if (strb->software) {
694 /* software-allocated renderbuffer (probably an accum buffer) */
695 return;
696 }
697
698 pipe_transfer_unmap(pipe, strb->transfer);
699 pipe->transfer_destroy(pipe, strb->transfer);
700 strb->transfer = NULL;
701 }
702
703
704
705 void st_init_fbo_functions(struct dd_function_table *functions)
706 {
707 #if FEATURE_EXT_framebuffer_object
708 functions->NewFramebuffer = st_new_framebuffer;
709 functions->NewRenderbuffer = st_new_renderbuffer;
710 functions->BindFramebuffer = st_bind_framebuffer;
711 functions->FramebufferRenderbuffer = _mesa_framebuffer_renderbuffer;
712 functions->RenderTexture = st_render_texture;
713 functions->FinishRenderTexture = st_finish_render_texture;
714 functions->ValidateFramebuffer = st_validate_framebuffer;
715 #endif
716
717 functions->DrawBuffers = st_DrawBuffers;
718 functions->ReadBuffer = st_ReadBuffer;
719
720 functions->MapRenderbuffer = st_MapRenderbuffer;
721 functions->UnmapRenderbuffer = st_UnmapRenderbuffer;
722 }
723
724