st/mesa: fix accum buffer allocation in st_renderbuffer_alloc_storage()
[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 strb->Base.DataType = st_format_datatype(format);
101 strb->format = format;
102
103 strb->defined = GL_FALSE; /* undefined contents now */
104
105 if (strb->software) {
106 size_t size;
107
108 free(strb->data);
109
110 assert(strb->format != PIPE_FORMAT_NONE);
111
112 strb->stride = util_format_get_stride(strb->format, width);
113 size = util_format_get_2d_size(strb->format, strb->stride, height);
114
115 strb->data = malloc(size);
116
117 return strb->data != NULL;
118 }
119 else {
120 struct pipe_resource template;
121
122 /* Free the old surface and texture
123 */
124 pipe_surface_reference( &strb->surface, NULL );
125 pipe_resource_reference( &strb->texture, NULL );
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 {
142 template.bind = (PIPE_BIND_DISPLAY_TARGET |
143 PIPE_BIND_RENDER_TARGET);
144 }
145
146 strb->texture = screen->resource_create(screen, &template);
147
148 if (!strb->texture)
149 return FALSE;
150
151 memset(&surf_tmpl, 0, sizeof(surf_tmpl));
152 u_surface_default_template(&surf_tmpl, strb->texture, template.bind);
153 strb->surface = pipe->create_surface(pipe,
154 strb->texture,
155 &surf_tmpl);
156 if (strb->surface) {
157 assert(strb->surface->texture);
158 assert(strb->surface->format);
159 assert(strb->surface->width == width);
160 assert(strb->surface->height == height);
161 }
162
163 return strb->surface != NULL;
164 }
165 }
166
167
168 /**
169 * gl_renderbuffer::Delete()
170 */
171 static void
172 st_renderbuffer_delete(struct gl_renderbuffer *rb)
173 {
174 struct st_renderbuffer *strb = st_renderbuffer(rb);
175 ASSERT(strb);
176 pipe_surface_reference(&strb->surface, NULL);
177 pipe_resource_reference(&strb->texture, NULL);
178 free(strb->data);
179 free(strb);
180 }
181
182
183 /**
184 * gl_renderbuffer::GetPointer()
185 */
186 static void *
187 null_get_pointer(struct gl_context * ctx, struct gl_renderbuffer *rb,
188 GLint x, GLint y)
189 {
190 /* By returning NULL we force all software rendering to go through
191 * the span routines.
192 */
193 #if 0
194 assert(0); /* Should never get called with softpipe */
195 #endif
196 return NULL;
197 }
198
199
200 /**
201 * Called via ctx->Driver.NewFramebuffer()
202 */
203 static struct gl_framebuffer *
204 st_new_framebuffer(struct gl_context *ctx, GLuint name)
205 {
206 /* XXX not sure we need to subclass gl_framebuffer for pipe */
207 return _mesa_new_framebuffer(ctx, name);
208 }
209
210
211 /**
212 * Called via ctx->Driver.NewRenderbuffer()
213 */
214 static struct gl_renderbuffer *
215 st_new_renderbuffer(struct gl_context *ctx, GLuint name)
216 {
217 struct st_renderbuffer *strb = ST_CALLOC_STRUCT(st_renderbuffer);
218 if (strb) {
219 _mesa_init_renderbuffer(&strb->Base, name);
220 strb->Base.Delete = st_renderbuffer_delete;
221 strb->Base.AllocStorage = st_renderbuffer_alloc_storage;
222 strb->Base.GetPointer = null_get_pointer;
223 strb->format = PIPE_FORMAT_NONE;
224 return &strb->Base;
225 }
226 return NULL;
227 }
228
229
230 /**
231 * Allocate a renderbuffer for a an on-screen window (not a user-created
232 * renderbuffer). The window system code determines the format.
233 */
234 struct gl_renderbuffer *
235 st_new_renderbuffer_fb(enum pipe_format format, int samples, boolean sw)
236 {
237 struct st_renderbuffer *strb;
238
239 strb = ST_CALLOC_STRUCT(st_renderbuffer);
240 if (!strb) {
241 _mesa_error(NULL, GL_OUT_OF_MEMORY, "creating renderbuffer");
242 return NULL;
243 }
244
245 _mesa_init_renderbuffer(&strb->Base, 0);
246 strb->Base.ClassID = 0x4242; /* just a unique value */
247 strb->Base.NumSamples = samples;
248 strb->Base.Format = st_pipe_format_to_mesa_format(format);
249 strb->Base._BaseFormat = _mesa_get_format_base_format(strb->Base.Format);
250 strb->Base.DataType = st_format_datatype(format);
251 strb->format = format;
252 strb->software = sw;
253
254 switch (format) {
255 case PIPE_FORMAT_R8G8B8A8_UNORM:
256 case PIPE_FORMAT_B8G8R8A8_UNORM:
257 case PIPE_FORMAT_A8R8G8B8_UNORM:
258 case PIPE_FORMAT_R8G8B8X8_UNORM:
259 case PIPE_FORMAT_B8G8R8X8_UNORM:
260 case PIPE_FORMAT_X8R8G8B8_UNORM:
261 case PIPE_FORMAT_B5G5R5A1_UNORM:
262 case PIPE_FORMAT_B4G4R4A4_UNORM:
263 case PIPE_FORMAT_B5G6R5_UNORM:
264 strb->Base.InternalFormat = GL_RGBA;
265 break;
266 case PIPE_FORMAT_Z16_UNORM:
267 strb->Base.InternalFormat = GL_DEPTH_COMPONENT16;
268 break;
269 case PIPE_FORMAT_Z32_UNORM:
270 strb->Base.InternalFormat = GL_DEPTH_COMPONENT32;
271 break;
272 case PIPE_FORMAT_Z24_UNORM_S8_UINT:
273 case PIPE_FORMAT_S8_UINT_Z24_UNORM:
274 case PIPE_FORMAT_Z24X8_UNORM:
275 case PIPE_FORMAT_X8Z24_UNORM:
276 strb->Base.InternalFormat = GL_DEPTH24_STENCIL8_EXT;
277 break;
278 case PIPE_FORMAT_S8_UINT:
279 strb->Base.InternalFormat = GL_STENCIL_INDEX8_EXT;
280 break;
281 case PIPE_FORMAT_R16G16B16A16_SNORM:
282 /* accum buffer */
283 strb->Base.InternalFormat = GL_RGBA16_SNORM;
284 break;
285 case PIPE_FORMAT_R8_UNORM:
286 strb->Base.InternalFormat = GL_R8;
287 break;
288 case PIPE_FORMAT_R8G8_UNORM:
289 strb->Base.InternalFormat = GL_RG8;
290 break;
291 case PIPE_FORMAT_R16_UNORM:
292 strb->Base.InternalFormat = GL_R16;
293 break;
294 case PIPE_FORMAT_R16G16_UNORM:
295 strb->Base.InternalFormat = GL_RG16;
296 break;
297 default:
298 _mesa_problem(NULL,
299 "Unexpected format in st_new_renderbuffer_fb");
300 free(strb);
301 return NULL;
302 }
303
304 /* st-specific methods */
305 strb->Base.Delete = st_renderbuffer_delete;
306 strb->Base.AllocStorage = st_renderbuffer_alloc_storage;
307 strb->Base.GetPointer = null_get_pointer;
308
309 /* surface is allocated in st_renderbuffer_alloc_storage() */
310 strb->surface = NULL;
311
312 return &strb->Base;
313 }
314
315
316
317
318 /**
319 * Called via ctx->Driver.BindFramebufferEXT().
320 */
321 static void
322 st_bind_framebuffer(struct gl_context *ctx, GLenum target,
323 struct gl_framebuffer *fb, struct gl_framebuffer *fbread)
324 {
325
326 }
327
328 /**
329 * Called by ctx->Driver.FramebufferRenderbuffer
330 */
331 static void
332 st_framebuffer_renderbuffer(struct gl_context *ctx,
333 struct gl_framebuffer *fb,
334 GLenum attachment,
335 struct gl_renderbuffer *rb)
336 {
337 /* XXX no need for derivation? */
338 _mesa_framebuffer_renderbuffer(ctx, fb, attachment, rb);
339 }
340
341
342 /**
343 * Called by ctx->Driver.RenderTexture
344 */
345 static void
346 st_render_texture(struct gl_context *ctx,
347 struct gl_framebuffer *fb,
348 struct gl_renderbuffer_attachment *att)
349 {
350 struct st_context *st = st_context(ctx);
351 struct pipe_context *pipe = st->pipe;
352 struct st_renderbuffer *strb;
353 struct gl_renderbuffer *rb;
354 struct pipe_resource *pt;
355 struct st_texture_object *stObj;
356 const struct gl_texture_image *texImage;
357 struct pipe_surface surf_tmpl;
358
359 if (!st_finalize_texture(ctx, pipe, att->Texture))
360 return;
361
362 pt = st_get_texobj_resource(att->Texture);
363 assert(pt);
364
365 /* get pointer to texture image we're rendeing to */
366 texImage = _mesa_get_attachment_teximage(att);
367
368 /* create new renderbuffer which wraps the texture image.
369 * Use the texture's name as the renderbuffer's name so that we have
370 * something that's non-zero (to determine vertical orientation) and
371 * possibly helpful for debugging.
372 */
373 rb = st_new_renderbuffer(ctx, att->Texture->Name);
374 if (!rb) {
375 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glFramebufferTexture()");
376 return;
377 }
378
379 _mesa_reference_renderbuffer(&att->Renderbuffer, rb);
380 assert(rb->RefCount == 1);
381 rb->AllocStorage = NULL; /* should not get called */
382 strb = st_renderbuffer(rb);
383
384 assert(strb->Base.RefCount > 0);
385
386 /* get the texture for the texture object */
387 stObj = st_texture_object(att->Texture);
388
389 /* point renderbuffer at texobject */
390 strb->rtt = stObj;
391 strb->rtt_level = att->TextureLevel;
392 strb->rtt_face = att->CubeMapFace;
393 strb->rtt_slice = att->Zoffset;
394
395 rb->Width = texImage->Width2;
396 rb->Height = texImage->Height2;
397 rb->_BaseFormat = texImage->_BaseFormat;
398 rb->InternalFormat = texImage->InternalFormat;
399 /*printf("***** render to texture level %d: %d x %d\n", att->TextureLevel, rb->Width, rb->Height);*/
400
401 /*printf("***** pipe texture %d x %d\n", pt->width0, pt->height0);*/
402
403 pipe_resource_reference( &strb->texture, pt );
404
405 pipe_surface_reference(&strb->surface, NULL);
406
407 assert(strb->rtt_level <= strb->texture->last_level);
408
409 /* new surface for rendering into the texture */
410 memset(&surf_tmpl, 0, sizeof(surf_tmpl));
411 surf_tmpl.format = ctx->Color.sRGBEnabled ? strb->texture->format : util_format_linear(strb->texture->format);
412 surf_tmpl.usage = PIPE_BIND_RENDER_TARGET;
413 surf_tmpl.u.tex.level = strb->rtt_level;
414 surf_tmpl.u.tex.first_layer = strb->rtt_face + strb->rtt_slice;
415 surf_tmpl.u.tex.last_layer = strb->rtt_face + strb->rtt_slice;
416 strb->surface = pipe->create_surface(pipe,
417 strb->texture,
418 &surf_tmpl);
419
420 strb->format = pt->format;
421
422 strb->Base.Format = st_pipe_format_to_mesa_format(pt->format);
423 strb->Base.DataType = st_format_datatype(pt->format);
424
425 /*
426 printf("RENDER TO TEXTURE obj=%p pt=%p surf=%p %d x %d\n",
427 att->Texture, pt, strb->surface, rb->Width, rb->Height);
428 */
429
430 /* Invalidate buffer state so that the pipe's framebuffer state
431 * gets updated.
432 * That's where the new renderbuffer (which we just created) gets
433 * passed to the pipe as a (color/depth) render target.
434 */
435 st_invalidate_state(ctx, _NEW_BUFFERS);
436 }
437
438
439 /**
440 * Called via ctx->Driver.FinishRenderTexture.
441 */
442 static void
443 st_finish_render_texture(struct gl_context *ctx,
444 struct gl_renderbuffer_attachment *att)
445 {
446 struct st_renderbuffer *strb = st_renderbuffer(att->Renderbuffer);
447
448 if (!strb)
449 return;
450
451 strb->rtt = NULL;
452
453 /*
454 printf("FINISH RENDER TO TEXTURE surf=%p\n", strb->surface);
455 */
456
457 /* restore previous framebuffer state */
458 st_invalidate_state(ctx, _NEW_BUFFERS);
459 }
460
461
462 /**
463 * Validate a renderbuffer attachment for a particular set of bindings.
464 */
465 static GLboolean
466 st_validate_attachment(struct gl_context *ctx,
467 struct pipe_screen *screen,
468 const struct gl_renderbuffer_attachment *att,
469 unsigned bindings)
470 {
471 const struct st_texture_object *stObj = st_texture_object(att->Texture);
472 enum pipe_format format;
473 gl_format texFormat;
474
475 /* Only validate texture attachments for now, since
476 * st_renderbuffer_alloc_storage makes sure that
477 * the format is supported.
478 */
479 if (att->Type != GL_TEXTURE)
480 return GL_TRUE;
481
482 if (!stObj)
483 return GL_FALSE;
484
485 format = stObj->pt->format;
486 texFormat = _mesa_get_attachment_teximage_const(att)->TexFormat;
487
488 /* If the encoding is sRGB and sRGB rendering cannot be enabled,
489 * check for linear format support instead.
490 * Later when we create a surface, we change the format to a linear one. */
491 if (!ctx->Const.sRGBCapable &&
492 _mesa_get_format_color_encoding(texFormat) == GL_SRGB) {
493 const gl_format linearFormat = _mesa_get_srgb_format_linear(texFormat);
494 format = st_mesa_format_to_pipe_format(linearFormat);
495 }
496
497 return screen->is_format_supported(screen, format,
498 PIPE_TEXTURE_2D,
499 stObj->pt->nr_samples, bindings);
500 }
501
502
503 /**
504 * Check if two renderbuffer attachments name a combined depth/stencil
505 * renderbuffer.
506 */
507 GLboolean
508 st_is_depth_stencil_combined(const struct gl_renderbuffer_attachment *depth,
509 const struct gl_renderbuffer_attachment *stencil)
510 {
511 assert(depth && stencil);
512
513 if (depth->Type == stencil->Type) {
514 if (depth->Type == GL_RENDERBUFFER_EXT &&
515 depth->Renderbuffer == stencil->Renderbuffer)
516 return GL_TRUE;
517
518 if (depth->Type == GL_TEXTURE &&
519 depth->Texture == stencil->Texture)
520 return GL_TRUE;
521 }
522
523 return GL_FALSE;
524 }
525
526
527 /**
528 * Check that the framebuffer configuration is valid in terms of what
529 * the driver can support.
530 *
531 * For Gallium we only supports combined Z+stencil, not separate buffers.
532 */
533 static void
534 st_validate_framebuffer(struct gl_context *ctx, struct gl_framebuffer *fb)
535 {
536 struct st_context *st = st_context(ctx);
537 struct pipe_screen *screen = st->pipe->screen;
538 const struct gl_renderbuffer_attachment *depth =
539 &fb->Attachment[BUFFER_DEPTH];
540 const struct gl_renderbuffer_attachment *stencil =
541 &fb->Attachment[BUFFER_STENCIL];
542 GLuint i;
543 enum pipe_format first_format = PIPE_FORMAT_NONE;
544 boolean mixed_formats =
545 screen->get_param(screen, PIPE_CAP_MIXED_COLORBUFFER_FORMATS) != 0;
546
547 if (depth->Type && stencil->Type && depth->Type != stencil->Type) {
548 fb->_Status = GL_FRAMEBUFFER_UNSUPPORTED_EXT;
549 return;
550 }
551 if (depth->Type == GL_RENDERBUFFER_EXT &&
552 stencil->Type == GL_RENDERBUFFER_EXT &&
553 depth->Renderbuffer != stencil->Renderbuffer) {
554 fb->_Status = GL_FRAMEBUFFER_UNSUPPORTED_EXT;
555 return;
556 }
557 if (depth->Type == GL_TEXTURE &&
558 stencil->Type == GL_TEXTURE &&
559 depth->Texture != stencil->Texture) {
560 fb->_Status = GL_FRAMEBUFFER_UNSUPPORTED_EXT;
561 return;
562 }
563
564 if (!st_validate_attachment(ctx,
565 screen,
566 depth,
567 PIPE_BIND_DEPTH_STENCIL)) {
568 fb->_Status = GL_FRAMEBUFFER_UNSUPPORTED_EXT;
569 return;
570 }
571 if (!st_validate_attachment(ctx,
572 screen,
573 stencil,
574 PIPE_BIND_DEPTH_STENCIL)) {
575 fb->_Status = GL_FRAMEBUFFER_UNSUPPORTED_EXT;
576 return;
577 }
578 for (i = 0; i < ctx->Const.MaxColorAttachments; i++) {
579 struct gl_renderbuffer_attachment *att =
580 &fb->Attachment[BUFFER_COLOR0 + i];
581 enum pipe_format format;
582
583 if (!st_validate_attachment(ctx,
584 screen,
585 att,
586 PIPE_BIND_RENDER_TARGET)) {
587 fb->_Status = GL_FRAMEBUFFER_UNSUPPORTED_EXT;
588 return;
589 }
590
591 if (!mixed_formats) {
592 /* Disallow mixed formats. */
593 if (att->Type != GL_NONE) {
594 format = st_renderbuffer(att->Renderbuffer)->surface->format;
595 } else {
596 continue;
597 }
598
599 if (first_format == PIPE_FORMAT_NONE) {
600 first_format = format;
601 } else if (format != first_format) {
602 fb->_Status = GL_FRAMEBUFFER_UNSUPPORTED_EXT;
603 return;
604 }
605 }
606 }
607 }
608
609
610 /**
611 * Called via glDrawBuffer.
612 */
613 static void
614 st_DrawBuffers(struct gl_context *ctx, GLsizei count, const GLenum *buffers)
615 {
616 struct st_context *st = st_context(ctx);
617 struct gl_framebuffer *fb = ctx->DrawBuffer;
618 GLuint i;
619
620 (void) count;
621 (void) buffers;
622
623 /* add the renderbuffers on demand */
624 for (i = 0; i < fb->_NumColorDrawBuffers; i++) {
625 gl_buffer_index idx = fb->_ColorDrawBufferIndexes[i];
626 st_manager_add_color_renderbuffer(st, fb, idx);
627 }
628 }
629
630
631 /**
632 * Called via glReadBuffer.
633 */
634 static void
635 st_ReadBuffer(struct gl_context *ctx, GLenum buffer)
636 {
637 struct st_context *st = st_context(ctx);
638 struct gl_framebuffer *fb = ctx->ReadBuffer;
639
640 (void) buffer;
641
642 /* add the renderbuffer on demand */
643 st_manager_add_color_renderbuffer(st, fb, fb->_ColorReadBufferIndex);
644 }
645
646
647
648 /**
649 * Called via ctx->Driver.MapRenderbuffer.
650 */
651 static void
652 st_MapRenderbuffer(struct gl_context *ctx,
653 struct gl_renderbuffer *rb,
654 GLuint x, GLuint y, GLuint w, GLuint h,
655 GLbitfield mode,
656 GLubyte **mapOut, GLint *rowStrideOut)
657 {
658 struct st_context *st = st_context(ctx);
659 struct st_renderbuffer *strb = st_renderbuffer(rb);
660 struct pipe_context *pipe = st->pipe;
661 const GLboolean invert = rb->Name == 0;
662 unsigned usage;
663 GLuint y2;
664
665 usage = 0x0;
666 if (mode & GL_MAP_READ_BIT)
667 usage |= PIPE_TRANSFER_READ;
668 if (mode & GL_MAP_WRITE_BIT)
669 usage |= PIPE_TRANSFER_WRITE;
670
671 /* Note: y=0=bottom of buffer while y2=0=top of buffer.
672 * 'invert' will be true for window-system buffers and false for
673 * user-allocated renderbuffers and textures.
674 */
675 if (invert)
676 y2 = strb->Base.Height - y - h;
677 else
678 y2 = y;
679
680 strb->transfer = pipe_get_transfer(pipe,
681 strb->texture,
682 strb->rtt_level,
683 strb->rtt_face + strb->rtt_slice,
684 usage, x, y2, w, h);
685 if (strb->transfer) {
686 GLubyte *map = pipe_transfer_map(pipe, strb->transfer);
687 if (invert) {
688 *rowStrideOut = -strb->transfer->stride;
689 map += (h - 1) * strb->transfer->stride;
690 }
691 else {
692 *rowStrideOut = strb->transfer->stride;
693 }
694 *mapOut = map;
695 }
696 else {
697 *mapOut = NULL;
698 *rowStrideOut = 0;
699 }
700 }
701
702
703 /**
704 * Called via ctx->Driver.UnmapRenderbuffer.
705 */
706 static void
707 st_UnmapRenderbuffer(struct gl_context *ctx,
708 struct gl_renderbuffer *rb)
709 {
710 struct st_context *st = st_context(ctx);
711 struct st_renderbuffer *strb = st_renderbuffer(rb);
712 struct pipe_context *pipe = st->pipe;
713
714 pipe_transfer_unmap(pipe, strb->transfer);
715 pipe->transfer_destroy(pipe, strb->transfer);
716 strb->transfer = NULL;
717 }
718
719
720
721 void st_init_fbo_functions(struct dd_function_table *functions)
722 {
723 #if FEATURE_EXT_framebuffer_object
724 functions->NewFramebuffer = st_new_framebuffer;
725 functions->NewRenderbuffer = st_new_renderbuffer;
726 functions->BindFramebuffer = st_bind_framebuffer;
727 functions->FramebufferRenderbuffer = st_framebuffer_renderbuffer;
728 functions->RenderTexture = st_render_texture;
729 functions->FinishRenderTexture = st_finish_render_texture;
730 functions->ValidateFramebuffer = st_validate_framebuffer;
731 #endif
732 /* no longer needed by core Mesa, drivers handle resizes...
733 functions->ResizeBuffers = st_resize_buffers;
734 */
735
736 functions->DrawBuffers = st_DrawBuffers;
737 functions->ReadBuffer = st_ReadBuffer;
738
739 functions->MapRenderbuffer = st_MapRenderbuffer;
740 functions->UnmapRenderbuffer = st_UnmapRenderbuffer;
741 }
742
743