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