st/mesa: don't set PIPE_BIND_DISPLAY_TARGET for user-created renderbuffers
[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 default:
282 _mesa_problem(NULL,
283 "Unexpected format in st_new_renderbuffer_fb");
284 free(strb);
285 return NULL;
286 }
287
288 /* st-specific methods */
289 strb->Base.Delete = st_renderbuffer_delete;
290 strb->Base.AllocStorage = st_renderbuffer_alloc_storage;
291
292 /* surface is allocated in st_renderbuffer_alloc_storage() */
293 strb->surface = NULL;
294
295 return &strb->Base;
296 }
297
298
299
300
301 /**
302 * Called via ctx->Driver.BindFramebufferEXT().
303 */
304 static void
305 st_bind_framebuffer(struct gl_context *ctx, GLenum target,
306 struct gl_framebuffer *fb, struct gl_framebuffer *fbread)
307 {
308
309 }
310
311 /**
312 * Called by ctx->Driver.FramebufferRenderbuffer
313 */
314 static void
315 st_framebuffer_renderbuffer(struct gl_context *ctx,
316 struct gl_framebuffer *fb,
317 GLenum attachment,
318 struct gl_renderbuffer *rb)
319 {
320 /* XXX no need for derivation? */
321 _mesa_framebuffer_renderbuffer(ctx, fb, attachment, rb);
322 }
323
324
325 /**
326 * Called by ctx->Driver.RenderTexture
327 */
328 static void
329 st_render_texture(struct gl_context *ctx,
330 struct gl_framebuffer *fb,
331 struct gl_renderbuffer_attachment *att)
332 {
333 struct st_context *st = st_context(ctx);
334 struct pipe_context *pipe = st->pipe;
335 struct st_renderbuffer *strb;
336 struct gl_renderbuffer *rb;
337 struct pipe_resource *pt;
338 struct st_texture_object *stObj;
339 const struct gl_texture_image *texImage;
340 struct pipe_surface surf_tmpl;
341
342 if (!st_finalize_texture(ctx, pipe, att->Texture))
343 return;
344
345 pt = st_get_texobj_resource(att->Texture);
346 assert(pt);
347
348 /* get pointer to texture image we're rendeing to */
349 texImage = _mesa_get_attachment_teximage(att);
350
351 /* create new renderbuffer which wraps the texture image.
352 * Use the texture's name as the renderbuffer's name so that we have
353 * something that's non-zero (to determine vertical orientation) and
354 * possibly helpful for debugging.
355 */
356 rb = st_new_renderbuffer(ctx, att->Texture->Name);
357 if (!rb) {
358 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glFramebufferTexture()");
359 return;
360 }
361
362 _mesa_reference_renderbuffer(&att->Renderbuffer, rb);
363 assert(rb->RefCount == 1);
364 rb->AllocStorage = NULL; /* should not get called */
365 strb = st_renderbuffer(rb);
366
367 assert(strb->Base.RefCount > 0);
368
369 /* get the texture for the texture object */
370 stObj = st_texture_object(att->Texture);
371
372 /* point renderbuffer at texobject */
373 strb->rtt = stObj;
374 strb->rtt_level = att->TextureLevel;
375 strb->rtt_face = att->CubeMapFace;
376 strb->rtt_slice = att->Zoffset;
377
378 rb->Width = texImage->Width2;
379 rb->Height = texImage->Height2;
380 rb->_BaseFormat = texImage->_BaseFormat;
381 rb->InternalFormat = texImage->InternalFormat;
382 /*printf("***** render to texture level %d: %d x %d\n", att->TextureLevel, rb->Width, rb->Height);*/
383
384 /*printf("***** pipe texture %d x %d\n", pt->width0, pt->height0);*/
385
386 pipe_resource_reference( &strb->texture, pt );
387
388 pipe_surface_reference(&strb->surface, NULL);
389
390 assert(strb->rtt_level <= strb->texture->last_level);
391
392 /* new surface for rendering into the texture */
393 memset(&surf_tmpl, 0, sizeof(surf_tmpl));
394 surf_tmpl.format = ctx->Color.sRGBEnabled ? strb->texture->format : util_format_linear(strb->texture->format);
395 surf_tmpl.usage = PIPE_BIND_RENDER_TARGET;
396 surf_tmpl.u.tex.level = strb->rtt_level;
397 surf_tmpl.u.tex.first_layer = strb->rtt_face + strb->rtt_slice;
398 surf_tmpl.u.tex.last_layer = strb->rtt_face + strb->rtt_slice;
399 strb->surface = pipe->create_surface(pipe,
400 strb->texture,
401 &surf_tmpl);
402
403 strb->Base.Format = st_pipe_format_to_mesa_format(pt->format);
404
405 /*
406 printf("RENDER TO TEXTURE obj=%p pt=%p surf=%p %d x %d\n",
407 att->Texture, pt, strb->surface, rb->Width, rb->Height);
408 */
409
410 /* Invalidate buffer state so that the pipe's framebuffer state
411 * gets updated.
412 * That's where the new renderbuffer (which we just created) gets
413 * passed to the pipe as a (color/depth) render target.
414 */
415 st_invalidate_state(ctx, _NEW_BUFFERS);
416 }
417
418
419 /**
420 * Called via ctx->Driver.FinishRenderTexture.
421 */
422 static void
423 st_finish_render_texture(struct gl_context *ctx,
424 struct gl_renderbuffer_attachment *att)
425 {
426 struct st_renderbuffer *strb = st_renderbuffer(att->Renderbuffer);
427
428 if (!strb)
429 return;
430
431 strb->rtt = NULL;
432
433 /*
434 printf("FINISH RENDER TO TEXTURE surf=%p\n", strb->surface);
435 */
436
437 /* restore previous framebuffer state */
438 st_invalidate_state(ctx, _NEW_BUFFERS);
439 }
440
441
442 /**
443 * Validate a renderbuffer attachment for a particular set of bindings.
444 */
445 static GLboolean
446 st_validate_attachment(struct gl_context *ctx,
447 struct pipe_screen *screen,
448 const struct gl_renderbuffer_attachment *att,
449 unsigned bindings)
450 {
451 const struct st_texture_object *stObj = st_texture_object(att->Texture);
452 enum pipe_format format;
453 gl_format texFormat;
454
455 /* Only validate texture attachments for now, since
456 * st_renderbuffer_alloc_storage makes sure that
457 * the format is supported.
458 */
459 if (att->Type != GL_TEXTURE)
460 return GL_TRUE;
461
462 if (!stObj)
463 return GL_FALSE;
464
465 format = stObj->pt->format;
466 texFormat = _mesa_get_attachment_teximage_const(att)->TexFormat;
467
468 /* If the encoding is sRGB and sRGB rendering cannot be enabled,
469 * check for linear format support instead.
470 * Later when we create a surface, we change the format to a linear one. */
471 if (!ctx->Extensions.EXT_framebuffer_sRGB &&
472 _mesa_get_format_color_encoding(texFormat) == GL_SRGB) {
473 const gl_format linearFormat = _mesa_get_srgb_format_linear(texFormat);
474 format = st_mesa_format_to_pipe_format(linearFormat);
475 }
476
477 return screen->is_format_supported(screen, format,
478 PIPE_TEXTURE_2D,
479 stObj->pt->nr_samples, bindings);
480 }
481
482
483 /**
484 * Check if two renderbuffer attachments name a combined depth/stencil
485 * renderbuffer.
486 */
487 GLboolean
488 st_is_depth_stencil_combined(const struct gl_renderbuffer_attachment *depth,
489 const struct gl_renderbuffer_attachment *stencil)
490 {
491 assert(depth && stencil);
492
493 if (depth->Type == stencil->Type) {
494 if (depth->Type == GL_RENDERBUFFER_EXT &&
495 depth->Renderbuffer == stencil->Renderbuffer)
496 return GL_TRUE;
497
498 if (depth->Type == GL_TEXTURE &&
499 depth->Texture == stencil->Texture)
500 return GL_TRUE;
501 }
502
503 return GL_FALSE;
504 }
505
506
507 /**
508 * Check that the framebuffer configuration is valid in terms of what
509 * the driver can support.
510 *
511 * For Gallium we only supports combined Z+stencil, not separate buffers.
512 */
513 static void
514 st_validate_framebuffer(struct gl_context *ctx, struct gl_framebuffer *fb)
515 {
516 struct st_context *st = st_context(ctx);
517 struct pipe_screen *screen = st->pipe->screen;
518 const struct gl_renderbuffer_attachment *depth =
519 &fb->Attachment[BUFFER_DEPTH];
520 const struct gl_renderbuffer_attachment *stencil =
521 &fb->Attachment[BUFFER_STENCIL];
522 GLuint i;
523 enum pipe_format first_format = PIPE_FORMAT_NONE;
524 boolean mixed_formats =
525 screen->get_param(screen, PIPE_CAP_MIXED_COLORBUFFER_FORMATS) != 0;
526
527 if (depth->Type && stencil->Type && depth->Type != stencil->Type) {
528 fb->_Status = GL_FRAMEBUFFER_UNSUPPORTED_EXT;
529 return;
530 }
531 if (depth->Type == GL_RENDERBUFFER_EXT &&
532 stencil->Type == GL_RENDERBUFFER_EXT &&
533 depth->Renderbuffer != stencil->Renderbuffer) {
534 fb->_Status = GL_FRAMEBUFFER_UNSUPPORTED_EXT;
535 return;
536 }
537 if (depth->Type == GL_TEXTURE &&
538 stencil->Type == GL_TEXTURE &&
539 depth->Texture != stencil->Texture) {
540 fb->_Status = GL_FRAMEBUFFER_UNSUPPORTED_EXT;
541 return;
542 }
543
544 if (!st_validate_attachment(ctx,
545 screen,
546 depth,
547 PIPE_BIND_DEPTH_STENCIL)) {
548 fb->_Status = GL_FRAMEBUFFER_UNSUPPORTED_EXT;
549 return;
550 }
551 if (!st_validate_attachment(ctx,
552 screen,
553 stencil,
554 PIPE_BIND_DEPTH_STENCIL)) {
555 fb->_Status = GL_FRAMEBUFFER_UNSUPPORTED_EXT;
556 return;
557 }
558 for (i = 0; i < ctx->Const.MaxColorAttachments; i++) {
559 struct gl_renderbuffer_attachment *att =
560 &fb->Attachment[BUFFER_COLOR0 + i];
561 enum pipe_format format;
562
563 if (!st_validate_attachment(ctx,
564 screen,
565 att,
566 PIPE_BIND_RENDER_TARGET)) {
567 fb->_Status = GL_FRAMEBUFFER_UNSUPPORTED_EXT;
568 return;
569 }
570
571 if (!mixed_formats) {
572 /* Disallow mixed formats. */
573 if (att->Type != GL_NONE) {
574 format = st_renderbuffer(att->Renderbuffer)->surface->format;
575 } else {
576 continue;
577 }
578
579 if (first_format == PIPE_FORMAT_NONE) {
580 first_format = format;
581 } else if (format != first_format) {
582 fb->_Status = GL_FRAMEBUFFER_UNSUPPORTED_EXT;
583 return;
584 }
585 }
586 }
587 }
588
589
590 /**
591 * Called via glDrawBuffer.
592 */
593 static void
594 st_DrawBuffers(struct gl_context *ctx, GLsizei count, const GLenum *buffers)
595 {
596 struct st_context *st = st_context(ctx);
597 struct gl_framebuffer *fb = ctx->DrawBuffer;
598 GLuint i;
599
600 (void) count;
601 (void) buffers;
602
603 /* add the renderbuffers on demand */
604 for (i = 0; i < fb->_NumColorDrawBuffers; i++) {
605 gl_buffer_index idx = fb->_ColorDrawBufferIndexes[i];
606 st_manager_add_color_renderbuffer(st, fb, idx);
607 }
608 }
609
610
611 /**
612 * Called via glReadBuffer.
613 */
614 static void
615 st_ReadBuffer(struct gl_context *ctx, GLenum buffer)
616 {
617 struct st_context *st = st_context(ctx);
618 struct gl_framebuffer *fb = ctx->ReadBuffer;
619
620 (void) buffer;
621
622 /* add the renderbuffer on demand */
623 st_manager_add_color_renderbuffer(st, fb, fb->_ColorReadBufferIndex);
624 }
625
626
627
628 /**
629 * Called via ctx->Driver.MapRenderbuffer.
630 */
631 static void
632 st_MapRenderbuffer(struct gl_context *ctx,
633 struct gl_renderbuffer *rb,
634 GLuint x, GLuint y, GLuint w, GLuint h,
635 GLbitfield mode,
636 GLubyte **mapOut, GLint *rowStrideOut)
637 {
638 struct st_context *st = st_context(ctx);
639 struct st_renderbuffer *strb = st_renderbuffer(rb);
640 struct pipe_context *pipe = st->pipe;
641 const GLboolean invert = rb->Name == 0;
642 unsigned usage;
643 GLuint y2;
644
645 if (strb->software) {
646 /* software-allocated renderbuffer (probably an accum buffer) */
647 if (strb->data) {
648 GLint bpp = _mesa_get_format_bytes(strb->Base.Format);
649 GLint stride = _mesa_format_row_stride(strb->Base.Format,
650 strb->Base.Width);
651 *mapOut = (GLubyte *) strb->data + y * stride + x * bpp;
652 *rowStrideOut = stride;
653 }
654 else {
655 *mapOut = NULL;
656 *rowStrideOut = 0;
657 }
658 return;
659 }
660
661 usage = 0x0;
662 if (mode & GL_MAP_READ_BIT)
663 usage |= PIPE_TRANSFER_READ;
664 if (mode & GL_MAP_WRITE_BIT)
665 usage |= PIPE_TRANSFER_WRITE;
666 if (mode & GL_MAP_INVALIDATE_RANGE_BIT)
667 usage |= PIPE_TRANSFER_DISCARD_RANGE;
668
669 /* Note: y=0=bottom of buffer while y2=0=top of buffer.
670 * 'invert' will be true for window-system buffers and false for
671 * user-allocated renderbuffers and textures.
672 */
673 if (invert)
674 y2 = strb->Base.Height - y - h;
675 else
676 y2 = y;
677
678 strb->transfer = pipe_get_transfer(pipe,
679 strb->texture,
680 strb->rtt_level,
681 strb->rtt_face + strb->rtt_slice,
682 usage, x, y2, w, h);
683 if (strb->transfer) {
684 GLubyte *map = pipe_transfer_map(pipe, strb->transfer);
685 if (invert) {
686 *rowStrideOut = -strb->transfer->stride;
687 map += (h - 1) * strb->transfer->stride;
688 }
689 else {
690 *rowStrideOut = strb->transfer->stride;
691 }
692 *mapOut = map;
693 }
694 else {
695 *mapOut = NULL;
696 *rowStrideOut = 0;
697 }
698 }
699
700
701 /**
702 * Called via ctx->Driver.UnmapRenderbuffer.
703 */
704 static void
705 st_UnmapRenderbuffer(struct gl_context *ctx,
706 struct gl_renderbuffer *rb)
707 {
708 struct st_context *st = st_context(ctx);
709 struct st_renderbuffer *strb = st_renderbuffer(rb);
710 struct pipe_context *pipe = st->pipe;
711
712 if (strb->software) {
713 /* software-allocated renderbuffer (probably an accum buffer) */
714 return;
715 }
716
717 pipe_transfer_unmap(pipe, strb->transfer);
718 pipe->transfer_destroy(pipe, strb->transfer);
719 strb->transfer = NULL;
720 }
721
722
723
724 void st_init_fbo_functions(struct dd_function_table *functions)
725 {
726 #if FEATURE_EXT_framebuffer_object
727 functions->NewFramebuffer = st_new_framebuffer;
728 functions->NewRenderbuffer = st_new_renderbuffer;
729 functions->BindFramebuffer = st_bind_framebuffer;
730 functions->FramebufferRenderbuffer = st_framebuffer_renderbuffer;
731 functions->RenderTexture = st_render_texture;
732 functions->FinishRenderTexture = st_finish_render_texture;
733 functions->ValidateFramebuffer = st_validate_framebuffer;
734 #endif
735 /* no longer needed by core Mesa, drivers handle resizes...
736 functions->ResizeBuffers = st_resize_buffers;
737 */
738
739 functions->DrawBuffers = st_DrawBuffers;
740 functions->ReadBuffer = st_ReadBuffer;
741
742 functions->MapRenderbuffer = st_MapRenderbuffer;
743 functions->UnmapRenderbuffer = st_UnmapRenderbuffer;
744 }
745
746