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