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