1 /**************************************************************************
3 * Copyright 2007 VMware, Inc.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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 VMWARE 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.
26 **************************************************************************/
30 * Framebuffer/renderbuffer functions.
36 #include "main/imports.h"
37 #include "main/context.h"
38 #include "main/fbobject.h"
39 #include "main/framebuffer.h"
40 #include "main/glformats.h"
41 #include "main/macros.h"
42 #include "main/renderbuffer.h"
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"
55 #include "util/u_format.h"
56 #include "util/u_inlines.h"
57 #include "util/u_surface.h"
61 st_renderbuffer_alloc_sw_storage(struct gl_context
* ctx
,
62 struct gl_renderbuffer
*rb
,
63 GLenum internalFormat
,
64 GLuint width
, GLuint height
)
66 struct st_context
*st
= st_context(ctx
);
67 struct st_renderbuffer
*strb
= st_renderbuffer(rb
);
68 enum pipe_format format
;
74 if (internalFormat
== GL_RGBA16_SNORM
) {
75 /* Special case for software accum buffers. Otherwise, if the
76 * call to st_choose_renderbuffer_format() fails (because the
77 * driver doesn't support signed 16-bit/channel colors) we'd
78 * just return without allocating the software accum buffer.
80 format
= PIPE_FORMAT_R16G16B16A16_SNORM
;
83 format
= st_choose_renderbuffer_format(st
, internalFormat
, 0);
85 /* Not setting gl_renderbuffer::Format here will cause
86 * FRAMEBUFFER_UNSUPPORTED and ValidateFramebuffer will not be called.
88 if (format
== PIPE_FORMAT_NONE
) {
93 strb
->Base
.Format
= st_pipe_format_to_mesa_format(format
);
95 size
= _mesa_format_image_size(strb
->Base
.Format
, width
, height
, 1);
96 strb
->data
= malloc(size
);
97 return strb
->data
!= NULL
;
102 * gl_renderbuffer::AllocStorage()
103 * This is called to allocate the original drawing surface, and
104 * during window resize.
107 st_renderbuffer_alloc_storage(struct gl_context
* ctx
,
108 struct gl_renderbuffer
*rb
,
109 GLenum internalFormat
,
110 GLuint width
, GLuint height
)
112 struct st_context
*st
= st_context(ctx
);
113 struct pipe_context
*pipe
= st
->pipe
;
114 struct pipe_screen
*screen
= st
->pipe
->screen
;
115 struct st_renderbuffer
*strb
= st_renderbuffer(rb
);
116 enum pipe_format format
= PIPE_FORMAT_NONE
;
117 struct pipe_surface surf_tmpl
;
118 struct pipe_resource templ
;
120 /* init renderbuffer fields */
121 strb
->Base
.Width
= width
;
122 strb
->Base
.Height
= height
;
123 strb
->Base
._BaseFormat
= _mesa_base_fbo_format(ctx
, internalFormat
);
124 strb
->defined
= GL_FALSE
; /* undefined contents now */
126 if (strb
->software
) {
127 return st_renderbuffer_alloc_sw_storage(ctx
, rb
, internalFormat
,
131 /* Free the old surface and texture
133 pipe_surface_reference( &strb
->surface
, NULL
);
134 pipe_resource_reference( &strb
->texture
, NULL
);
136 /* If an sRGB framebuffer is unsupported, sRGB formats behave like linear
139 if (!ctx
->Extensions
.EXT_framebuffer_sRGB
) {
140 internalFormat
= _mesa_get_linear_internalformat(internalFormat
);
143 /* Handle multisample renderbuffers first.
145 * From ARB_framebuffer_object:
146 * If <samples> is zero, then RENDERBUFFER_SAMPLES is set to zero.
147 * Otherwise <samples> represents a request for a desired minimum
148 * number of samples. Since different implementations may support
149 * different sample counts for multisampled rendering, the actual
150 * number of samples allocated for the renderbuffer image is
151 * implementation dependent. However, the resulting value for
152 * RENDERBUFFER_SAMPLES is guaranteed to be greater than or equal
153 * to <samples> and no more than the next larger sample count supported
154 * by the implementation.
156 * So let's find the supported number of samples closest to NumSamples.
157 * (NumSamples == 1) is treated the same as (NumSamples == 0).
159 if (rb
->NumSamples
> 1) {
162 for (i
= rb
->NumSamples
; i
<= ctx
->Const
.MaxSamples
; i
++) {
163 format
= st_choose_renderbuffer_format(st
, internalFormat
, i
);
165 if (format
!= PIPE_FORMAT_NONE
) {
171 format
= st_choose_renderbuffer_format(st
, internalFormat
, 0);
174 /* Not setting gl_renderbuffer::Format here will cause
175 * FRAMEBUFFER_UNSUPPORTED and ValidateFramebuffer will not be called.
177 if (format
== PIPE_FORMAT_NONE
) {
181 strb
->Base
.Format
= st_pipe_format_to_mesa_format(format
);
183 if (width
== 0 || height
== 0) {
184 /* if size is zero, nothing to allocate */
188 /* Setup new texture template.
190 memset(&templ
, 0, sizeof(templ
));
191 templ
.target
= st
->internal_target
;
192 templ
.format
= format
;
193 templ
.width0
= width
;
194 templ
.height0
= height
;
196 templ
.array_size
= 1;
197 templ
.nr_samples
= rb
->NumSamples
;
198 if (util_format_is_depth_or_stencil(format
)) {
199 templ
.bind
= PIPE_BIND_DEPTH_STENCIL
;
201 else if (strb
->Base
.Name
!= 0) {
202 /* this is a user-created renderbuffer */
203 templ
.bind
= PIPE_BIND_RENDER_TARGET
;
206 /* this is a window-system buffer */
207 templ
.bind
= (PIPE_BIND_DISPLAY_TARGET
|
208 PIPE_BIND_RENDER_TARGET
);
211 strb
->texture
= screen
->resource_create(screen
, &templ
);
216 u_surface_default_template(&surf_tmpl
, strb
->texture
);
217 strb
->surface
= pipe
->create_surface(pipe
,
221 assert(strb
->surface
->texture
);
222 assert(strb
->surface
->format
);
223 assert(strb
->surface
->width
== width
);
224 assert(strb
->surface
->height
== height
);
227 return strb
->surface
!= NULL
;
232 * gl_renderbuffer::Delete()
235 st_renderbuffer_delete(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
)
237 struct st_renderbuffer
*strb
= st_renderbuffer(rb
);
239 struct st_context
*st
= st_context(ctx
);
240 pipe_surface_release(st
->pipe
, &strb
->surface
);
242 pipe_resource_reference(&strb
->texture
, NULL
);
244 _mesa_delete_renderbuffer(ctx
, rb
);
249 * Called via ctx->Driver.NewFramebuffer()
251 static struct gl_framebuffer
*
252 st_new_framebuffer(struct gl_context
*ctx
, GLuint name
)
254 /* XXX not sure we need to subclass gl_framebuffer for pipe */
255 return _mesa_new_framebuffer(ctx
, name
);
260 * Called via ctx->Driver.NewRenderbuffer()
262 static struct gl_renderbuffer
*
263 st_new_renderbuffer(struct gl_context
*ctx
, GLuint name
)
265 struct st_renderbuffer
*strb
= ST_CALLOC_STRUCT(st_renderbuffer
);
268 _mesa_init_renderbuffer(&strb
->Base
, name
);
269 strb
->Base
.Delete
= st_renderbuffer_delete
;
270 strb
->Base
.AllocStorage
= st_renderbuffer_alloc_storage
;
278 * Allocate a renderbuffer for a an on-screen window (not a user-created
279 * renderbuffer). The window system code determines the format.
281 struct gl_renderbuffer
*
282 st_new_renderbuffer_fb(enum pipe_format format
, int samples
, boolean sw
)
284 struct st_renderbuffer
*strb
;
286 strb
= ST_CALLOC_STRUCT(st_renderbuffer
);
288 _mesa_error(NULL
, GL_OUT_OF_MEMORY
, "creating renderbuffer");
292 _mesa_init_renderbuffer(&strb
->Base
, 0);
293 strb
->Base
.ClassID
= 0x4242; /* just a unique value */
294 strb
->Base
.NumSamples
= samples
;
295 strb
->Base
.Format
= st_pipe_format_to_mesa_format(format
);
296 strb
->Base
._BaseFormat
= _mesa_get_format_base_format(strb
->Base
.Format
);
300 case PIPE_FORMAT_R8G8B8A8_UNORM
:
301 case PIPE_FORMAT_B8G8R8A8_UNORM
:
302 case PIPE_FORMAT_A8R8G8B8_UNORM
:
303 strb
->Base
.InternalFormat
= GL_RGBA8
;
305 case PIPE_FORMAT_R8G8B8X8_UNORM
:
306 case PIPE_FORMAT_B8G8R8X8_UNORM
:
307 case PIPE_FORMAT_X8R8G8B8_UNORM
:
308 strb
->Base
.InternalFormat
= GL_RGB8
;
310 case PIPE_FORMAT_B5G5R5A1_UNORM
:
311 strb
->Base
.InternalFormat
= GL_RGB5_A1
;
313 case PIPE_FORMAT_B4G4R4A4_UNORM
:
314 strb
->Base
.InternalFormat
= GL_RGBA4
;
316 case PIPE_FORMAT_B5G6R5_UNORM
:
317 strb
->Base
.InternalFormat
= GL_RGB565
;
319 case PIPE_FORMAT_Z16_UNORM
:
320 strb
->Base
.InternalFormat
= GL_DEPTH_COMPONENT16
;
322 case PIPE_FORMAT_Z32_UNORM
:
323 strb
->Base
.InternalFormat
= GL_DEPTH_COMPONENT32
;
325 case PIPE_FORMAT_Z24_UNORM_S8_UINT
:
326 case PIPE_FORMAT_S8_UINT_Z24_UNORM
:
327 strb
->Base
.InternalFormat
= GL_DEPTH24_STENCIL8_EXT
;
329 case PIPE_FORMAT_Z24X8_UNORM
:
330 case PIPE_FORMAT_X8Z24_UNORM
:
331 strb
->Base
.InternalFormat
= GL_DEPTH_COMPONENT24
;
333 case PIPE_FORMAT_S8_UINT
:
334 strb
->Base
.InternalFormat
= GL_STENCIL_INDEX8_EXT
;
336 case PIPE_FORMAT_R16G16B16A16_SNORM
:
338 strb
->Base
.InternalFormat
= GL_RGBA16_SNORM
;
340 case PIPE_FORMAT_R16G16B16A16_UNORM
:
341 strb
->Base
.InternalFormat
= GL_RGBA16
;
343 case PIPE_FORMAT_R8_UNORM
:
344 strb
->Base
.InternalFormat
= GL_R8
;
346 case PIPE_FORMAT_R8G8_UNORM
:
347 strb
->Base
.InternalFormat
= GL_RG8
;
349 case PIPE_FORMAT_R16_UNORM
:
350 strb
->Base
.InternalFormat
= GL_R16
;
352 case PIPE_FORMAT_R16G16_UNORM
:
353 strb
->Base
.InternalFormat
= GL_RG16
;
355 case PIPE_FORMAT_R32G32B32A32_FLOAT
:
356 strb
->Base
.InternalFormat
= GL_RGBA32F
;
358 case PIPE_FORMAT_R16G16B16A16_FLOAT
:
359 strb
->Base
.InternalFormat
= GL_RGBA16F
;
363 "Unexpected format %s in st_new_renderbuffer_fb",
364 util_format_name(format
));
369 /* st-specific methods */
370 strb
->Base
.Delete
= st_renderbuffer_delete
;
371 strb
->Base
.AllocStorage
= st_renderbuffer_alloc_storage
;
373 /* surface is allocated in st_renderbuffer_alloc_storage() */
374 strb
->surface
= NULL
;
381 * Called via ctx->Driver.BindFramebufferEXT().
384 st_bind_framebuffer(struct gl_context
*ctx
, GLenum target
,
385 struct gl_framebuffer
*fb
, struct gl_framebuffer
*fbread
)
392 * Create or update the pipe_surface of a FBO renderbuffer.
393 * This is usually called after st_finalize_texture.
396 st_update_renderbuffer_surface(struct st_context
*st
,
397 struct st_renderbuffer
*strb
)
399 struct pipe_context
*pipe
= st
->pipe
;
400 struct pipe_resource
*resource
= strb
->texture
;
401 int rtt_width
= strb
->Base
.Width
;
402 int rtt_height
= strb
->Base
.Height
;
403 int rtt_depth
= strb
->Base
.Depth
;
404 enum pipe_format format
= st
->ctx
->Color
.sRGBEnabled
? resource
->format
:
405 util_format_linear(resource
->format
);
406 unsigned first_layer
, last_layer
, level
;
408 if (resource
->target
== PIPE_TEXTURE_1D_ARRAY
) {
409 rtt_depth
= rtt_height
;
413 /* find matching mipmap level size */
414 for (level
= 0; level
<= resource
->last_level
; level
++) {
415 if (u_minify(resource
->width0
, level
) == rtt_width
&&
416 u_minify(resource
->height0
, level
) == rtt_height
&&
417 (resource
->target
!= PIPE_TEXTURE_3D
||
418 u_minify(resource
->depth0
, level
) == rtt_depth
)) {
422 assert(level
<= resource
->last_level
);
424 /* determine the layer bounds */
425 if (strb
->rtt_layered
) {
427 last_layer
= util_max_layer(strb
->texture
, level
);
431 last_layer
= strb
->rtt_face
+ strb
->rtt_slice
;
434 if (!strb
->surface
||
435 strb
->surface
->texture
->nr_samples
!= strb
->Base
.NumSamples
||
436 strb
->surface
->format
!= format
||
437 strb
->surface
->texture
!= resource
||
438 strb
->surface
->width
!= rtt_width
||
439 strb
->surface
->height
!= rtt_height
||
440 strb
->surface
->u
.tex
.level
!= level
||
441 strb
->surface
->u
.tex
.first_layer
!= first_layer
||
442 strb
->surface
->u
.tex
.last_layer
!= last_layer
) {
443 /* create a new pipe_surface */
444 struct pipe_surface surf_tmpl
;
445 memset(&surf_tmpl
, 0, sizeof(surf_tmpl
));
446 surf_tmpl
.format
= format
;
447 surf_tmpl
.u
.tex
.level
= level
;
448 surf_tmpl
.u
.tex
.first_layer
= first_layer
;
449 surf_tmpl
.u
.tex
.last_layer
= last_layer
;
451 pipe_surface_reference(&strb
->surface
, NULL
);
453 strb
->surface
= pipe
->create_surface(pipe
, resource
, &surf_tmpl
);
458 * Called by ctx->Driver.RenderTexture
461 st_render_texture(struct gl_context
*ctx
,
462 struct gl_framebuffer
*fb
,
463 struct gl_renderbuffer_attachment
*att
)
465 struct st_context
*st
= st_context(ctx
);
466 struct pipe_context
*pipe
= st
->pipe
;
467 struct gl_renderbuffer
*rb
= att
->Renderbuffer
;
468 struct st_renderbuffer
*strb
= st_renderbuffer(rb
);
469 struct pipe_resource
*pt
;
471 if (!st_finalize_texture(ctx
, pipe
, att
->Texture
))
474 pt
= st_get_texobj_resource(att
->Texture
);
477 /* point renderbuffer at texobject */
479 strb
->rtt_face
= att
->CubeMapFace
;
480 strb
->rtt_slice
= att
->Zoffset
;
481 strb
->rtt_layered
= att
->Layered
;
482 pipe_resource_reference(&strb
->texture
, pt
);
484 pipe_surface_release(pipe
, &strb
->surface
);
486 st_update_renderbuffer_surface(st
, strb
);
488 strb
->Base
.Format
= st_pipe_format_to_mesa_format(pt
->format
);
490 /* Invalidate buffer state so that the pipe's framebuffer state
492 * That's where the new renderbuffer (which we just created) gets
493 * passed to the pipe as a (color/depth) render target.
495 st_invalidate_state(ctx
, _NEW_BUFFERS
);
498 /* Need to trigger a call to update_framebuffer() since we just
499 * attached a new renderbuffer.
501 ctx
->NewState
|= _NEW_BUFFERS
;
506 * Called via ctx->Driver.FinishRenderTexture.
509 st_finish_render_texture(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
)
511 struct st_renderbuffer
*strb
= st_renderbuffer(rb
);
516 strb
->is_rtt
= FALSE
;
518 /* restore previous framebuffer state */
519 st_invalidate_state(ctx
, _NEW_BUFFERS
);
525 st_fbo_invalid(const char *reason
)
527 if (MESA_DEBUG_FLAGS
& DEBUG_INCOMPLETE_FBO
) {
528 _mesa_debug(NULL
, "Invalid FBO: %s\n", reason
);
534 * Validate a renderbuffer attachment for a particular set of bindings.
537 st_validate_attachment(struct gl_context
*ctx
,
538 struct pipe_screen
*screen
,
539 const struct gl_renderbuffer_attachment
*att
,
542 const struct st_texture_object
*stObj
= st_texture_object(att
->Texture
);
543 enum pipe_format format
;
547 /* Only validate texture attachments for now, since
548 * st_renderbuffer_alloc_storage makes sure that
549 * the format is supported.
551 if (att
->Type
!= GL_TEXTURE
)
554 if (!stObj
|| !stObj
->pt
)
557 format
= stObj
->pt
->format
;
558 texFormat
= att
->Renderbuffer
->TexImage
->TexFormat
;
560 /* If the encoding is sRGB and sRGB rendering cannot be enabled,
561 * check for linear format support instead.
562 * Later when we create a surface, we change the format to a linear one. */
563 if (!ctx
->Extensions
.EXT_framebuffer_sRGB
&&
564 _mesa_get_format_color_encoding(texFormat
) == GL_SRGB
) {
565 const gl_format linearFormat
= _mesa_get_srgb_format_linear(texFormat
);
566 format
= st_mesa_format_to_pipe_format(linearFormat
);
569 valid
= screen
->is_format_supported(screen
, format
,
571 stObj
->pt
->nr_samples
, bindings
);
573 st_fbo_invalid("Invalid format");
581 * Check that the framebuffer configuration is valid in terms of what
582 * the driver can support.
584 * For Gallium we only supports combined Z+stencil, not separate buffers.
587 st_validate_framebuffer(struct gl_context
*ctx
, struct gl_framebuffer
*fb
)
589 struct st_context
*st
= st_context(ctx
);
590 struct pipe_screen
*screen
= st
->pipe
->screen
;
591 const struct gl_renderbuffer_attachment
*depth
=
592 &fb
->Attachment
[BUFFER_DEPTH
];
593 const struct gl_renderbuffer_attachment
*stencil
=
594 &fb
->Attachment
[BUFFER_STENCIL
];
596 enum pipe_format first_format
= PIPE_FORMAT_NONE
;
597 boolean mixed_formats
=
598 screen
->get_param(screen
, PIPE_CAP_MIXED_COLORBUFFER_FORMATS
) != 0;
600 if (depth
->Type
&& stencil
->Type
&& depth
->Type
!= stencil
->Type
) {
601 st_fbo_invalid("Different Depth/Stencil buffer formats");
602 fb
->_Status
= GL_FRAMEBUFFER_UNSUPPORTED_EXT
;
605 if (depth
->Type
== GL_RENDERBUFFER_EXT
&&
606 stencil
->Type
== GL_RENDERBUFFER_EXT
&&
607 depth
->Renderbuffer
!= stencil
->Renderbuffer
) {
608 st_fbo_invalid("Separate Depth/Stencil buffers");
609 fb
->_Status
= GL_FRAMEBUFFER_UNSUPPORTED_EXT
;
612 if (depth
->Type
== GL_TEXTURE
&&
613 stencil
->Type
== GL_TEXTURE
&&
614 depth
->Texture
!= stencil
->Texture
) {
615 fb
->_Status
= GL_FRAMEBUFFER_UNSUPPORTED_EXT
;
616 st_fbo_invalid("Different Depth/Stencil textures");
620 if (!st_validate_attachment(ctx
,
623 PIPE_BIND_DEPTH_STENCIL
)) {
624 fb
->_Status
= GL_FRAMEBUFFER_UNSUPPORTED_EXT
;
627 if (!st_validate_attachment(ctx
,
630 PIPE_BIND_DEPTH_STENCIL
)) {
631 fb
->_Status
= GL_FRAMEBUFFER_UNSUPPORTED_EXT
;
634 for (i
= 0; i
< ctx
->Const
.MaxColorAttachments
; i
++) {
635 struct gl_renderbuffer_attachment
*att
=
636 &fb
->Attachment
[BUFFER_COLOR0
+ i
];
637 enum pipe_format format
;
639 if (!st_validate_attachment(ctx
,
642 PIPE_BIND_RENDER_TARGET
)) {
643 fb
->_Status
= GL_FRAMEBUFFER_UNSUPPORTED_EXT
;
647 if (!mixed_formats
) {
648 /* Disallow mixed formats. */
649 if (att
->Type
!= GL_NONE
) {
650 format
= st_renderbuffer(att
->Renderbuffer
)->surface
->format
;
655 if (first_format
== PIPE_FORMAT_NONE
) {
656 first_format
= format
;
657 } else if (format
!= first_format
) {
658 fb
->_Status
= GL_FRAMEBUFFER_UNSUPPORTED_EXT
;
659 st_fbo_invalid("Mixed color formats");
668 * Called via glDrawBuffer.
671 st_DrawBuffers(struct gl_context
*ctx
, GLsizei count
, const GLenum
*buffers
)
673 struct st_context
*st
= st_context(ctx
);
674 struct gl_framebuffer
*fb
= ctx
->DrawBuffer
;
680 /* add the renderbuffers on demand */
681 for (i
= 0; i
< fb
->_NumColorDrawBuffers
; i
++) {
682 gl_buffer_index idx
= fb
->_ColorDrawBufferIndexes
[i
];
685 st_manager_add_color_renderbuffer(st
, fb
, idx
);
692 * Called via glReadBuffer.
695 st_ReadBuffer(struct gl_context
*ctx
, GLenum buffer
)
697 struct st_context
*st
= st_context(ctx
);
698 struct gl_framebuffer
*fb
= ctx
->ReadBuffer
;
702 /* add the renderbuffer on demand */
703 st_manager_add_color_renderbuffer(st
, fb
, fb
->_ColorReadBufferIndex
);
709 * Called via ctx->Driver.MapRenderbuffer.
712 st_MapRenderbuffer(struct gl_context
*ctx
,
713 struct gl_renderbuffer
*rb
,
714 GLuint x
, GLuint y
, GLuint w
, GLuint h
,
716 GLubyte
**mapOut
, GLint
*rowStrideOut
)
718 struct st_context
*st
= st_context(ctx
);
719 struct st_renderbuffer
*strb
= st_renderbuffer(rb
);
720 struct pipe_context
*pipe
= st
->pipe
;
721 const GLboolean invert
= rb
->Name
== 0;
726 if (strb
->software
) {
727 /* software-allocated renderbuffer (probably an accum buffer) */
729 GLint bpp
= _mesa_get_format_bytes(strb
->Base
.Format
);
730 GLint stride
= _mesa_format_row_stride(strb
->Base
.Format
,
732 *mapOut
= (GLubyte
*) strb
->data
+ y
* stride
+ x
* bpp
;
733 *rowStrideOut
= stride
;
743 if (mode
& GL_MAP_READ_BIT
)
744 usage
|= PIPE_TRANSFER_READ
;
745 if (mode
& GL_MAP_WRITE_BIT
)
746 usage
|= PIPE_TRANSFER_WRITE
;
747 if (mode
& GL_MAP_INVALIDATE_RANGE_BIT
)
748 usage
|= PIPE_TRANSFER_DISCARD_RANGE
;
750 /* Note: y=0=bottom of buffer while y2=0=top of buffer.
751 * 'invert' will be true for window-system buffers and false for
752 * user-allocated renderbuffers and textures.
755 y2
= strb
->Base
.Height
- y
- h
;
759 map
= pipe_transfer_map(pipe
,
761 strb
->surface
->u
.tex
.level
,
762 strb
->surface
->u
.tex
.first_layer
,
763 usage
, x
, y2
, w
, h
, &strb
->transfer
);
766 *rowStrideOut
= -(int) strb
->transfer
->stride
;
767 map
+= (h
- 1) * strb
->transfer
->stride
;
770 *rowStrideOut
= strb
->transfer
->stride
;
782 * Called via ctx->Driver.UnmapRenderbuffer.
785 st_UnmapRenderbuffer(struct gl_context
*ctx
,
786 struct gl_renderbuffer
*rb
)
788 struct st_context
*st
= st_context(ctx
);
789 struct st_renderbuffer
*strb
= st_renderbuffer(rb
);
790 struct pipe_context
*pipe
= st
->pipe
;
792 if (strb
->software
) {
793 /* software-allocated renderbuffer (probably an accum buffer) */
797 pipe_transfer_unmap(pipe
, strb
->transfer
);
798 strb
->transfer
= NULL
;
803 void st_init_fbo_functions(struct dd_function_table
*functions
)
805 functions
->NewFramebuffer
= st_new_framebuffer
;
806 functions
->NewRenderbuffer
= st_new_renderbuffer
;
807 functions
->BindFramebuffer
= st_bind_framebuffer
;
808 functions
->FramebufferRenderbuffer
= _mesa_framebuffer_renderbuffer
;
809 functions
->RenderTexture
= st_render_texture
;
810 functions
->FinishRenderTexture
= st_finish_render_texture
;
811 functions
->ValidateFramebuffer
= st_validate_framebuffer
;
813 functions
->DrawBuffers
= st_DrawBuffers
;
814 functions
->ReadBuffer
= st_ReadBuffer
;
816 functions
->MapRenderbuffer
= st_MapRenderbuffer
;
817 functions
->UnmapRenderbuffer
= st_UnmapRenderbuffer
;