1 /**************************************************************************
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
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 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.
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/macros.h"
41 #include "main/mfeatures.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 /* Handle multisample renderbuffers first.
138 * From ARB_framebuffer_object:
139 * If <samples> is zero, then RENDERBUFFER_SAMPLES is set to zero.
140 * Otherwise <samples> represents a request for a desired minimum
141 * number of samples. Since different implementations may support
142 * different sample counts for multisampled rendering, the actual
143 * number of samples allocated for the renderbuffer image is
144 * implementation dependent. However, the resulting value for
145 * RENDERBUFFER_SAMPLES is guaranteed to be greater than or equal
146 * to <samples> and no more than the next larger sample count supported
147 * by the implementation.
149 * So let's find the supported number of samples closest to NumSamples.
150 * (NumSamples == 1) is treated the same as (NumSamples == 0).
152 if (rb
->NumSamples
> 1) {
155 for (i
= rb
->NumSamples
; i
<= ctx
->Const
.MaxSamples
; i
++) {
156 format
= st_choose_renderbuffer_format(st
, internalFormat
, i
);
158 if (format
!= PIPE_FORMAT_NONE
) {
164 format
= st_choose_renderbuffer_format(st
, internalFormat
, 0);
167 /* Not setting gl_renderbuffer::Format here will cause
168 * FRAMEBUFFER_UNSUPPORTED and ValidateFramebuffer will not be called.
170 if (format
== PIPE_FORMAT_NONE
) {
174 strb
->Base
.Format
= st_pipe_format_to_mesa_format(format
);
176 if (width
== 0 || height
== 0) {
177 /* if size is zero, nothing to allocate */
181 /* Setup new texture template.
183 memset(&templ
, 0, sizeof(templ
));
184 templ
.target
= st
->internal_target
;
185 templ
.format
= format
;
186 templ
.width0
= width
;
187 templ
.height0
= height
;
189 templ
.array_size
= 1;
190 templ
.nr_samples
= rb
->NumSamples
;
191 if (util_format_is_depth_or_stencil(format
)) {
192 templ
.bind
= PIPE_BIND_DEPTH_STENCIL
;
194 else if (strb
->Base
.Name
!= 0) {
195 /* this is a user-created renderbuffer */
196 templ
.bind
= PIPE_BIND_RENDER_TARGET
;
199 /* this is a window-system buffer */
200 templ
.bind
= (PIPE_BIND_DISPLAY_TARGET
|
201 PIPE_BIND_RENDER_TARGET
);
204 strb
->texture
= screen
->resource_create(screen
, &templ
);
209 u_surface_default_template(&surf_tmpl
, strb
->texture
);
210 strb
->surface
= pipe
->create_surface(pipe
,
214 assert(strb
->surface
->texture
);
215 assert(strb
->surface
->format
);
216 assert(strb
->surface
->width
== width
);
217 assert(strb
->surface
->height
== height
);
220 return strb
->surface
!= NULL
;
225 * gl_renderbuffer::Delete()
228 st_renderbuffer_delete(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
)
230 struct st_renderbuffer
*strb
= st_renderbuffer(rb
);
232 struct st_context
*st
= st_context(ctx
);
233 pipe_surface_release(st
->pipe
, &strb
->surface
);
235 pipe_resource_reference(&strb
->texture
, NULL
);
237 _mesa_delete_renderbuffer(ctx
, rb
);
242 * Called via ctx->Driver.NewFramebuffer()
244 static struct gl_framebuffer
*
245 st_new_framebuffer(struct gl_context
*ctx
, GLuint name
)
247 /* XXX not sure we need to subclass gl_framebuffer for pipe */
248 return _mesa_new_framebuffer(ctx
, name
);
253 * Called via ctx->Driver.NewRenderbuffer()
255 static struct gl_renderbuffer
*
256 st_new_renderbuffer(struct gl_context
*ctx
, GLuint name
)
258 struct st_renderbuffer
*strb
= ST_CALLOC_STRUCT(st_renderbuffer
);
261 _mesa_init_renderbuffer(&strb
->Base
, name
);
262 strb
->Base
.Delete
= st_renderbuffer_delete
;
263 strb
->Base
.AllocStorage
= st_renderbuffer_alloc_storage
;
271 * Allocate a renderbuffer for a an on-screen window (not a user-created
272 * renderbuffer). The window system code determines the format.
274 struct gl_renderbuffer
*
275 st_new_renderbuffer_fb(enum pipe_format format
, int samples
, boolean sw
)
277 struct st_renderbuffer
*strb
;
279 strb
= ST_CALLOC_STRUCT(st_renderbuffer
);
281 _mesa_error(NULL
, GL_OUT_OF_MEMORY
, "creating renderbuffer");
285 _mesa_init_renderbuffer(&strb
->Base
, 0);
286 strb
->Base
.ClassID
= 0x4242; /* just a unique value */
287 strb
->Base
.NumSamples
= samples
;
288 strb
->Base
.Format
= st_pipe_format_to_mesa_format(format
);
289 strb
->Base
._BaseFormat
= _mesa_get_format_base_format(strb
->Base
.Format
);
293 case PIPE_FORMAT_R8G8B8A8_UNORM
:
294 case PIPE_FORMAT_B8G8R8A8_UNORM
:
295 case PIPE_FORMAT_A8R8G8B8_UNORM
:
296 strb
->Base
.InternalFormat
= GL_RGBA8
;
298 case PIPE_FORMAT_R8G8B8X8_UNORM
:
299 case PIPE_FORMAT_B8G8R8X8_UNORM
:
300 case PIPE_FORMAT_X8R8G8B8_UNORM
:
301 strb
->Base
.InternalFormat
= GL_RGB8
;
303 case PIPE_FORMAT_B5G5R5A1_UNORM
:
304 strb
->Base
.InternalFormat
= GL_RGB5_A1
;
306 case PIPE_FORMAT_B4G4R4A4_UNORM
:
307 strb
->Base
.InternalFormat
= GL_RGBA4
;
309 case PIPE_FORMAT_B5G6R5_UNORM
:
310 strb
->Base
.InternalFormat
= GL_RGB565
;
312 case PIPE_FORMAT_Z16_UNORM
:
313 strb
->Base
.InternalFormat
= GL_DEPTH_COMPONENT16
;
315 case PIPE_FORMAT_Z32_UNORM
:
316 strb
->Base
.InternalFormat
= GL_DEPTH_COMPONENT32
;
318 case PIPE_FORMAT_Z24_UNORM_S8_UINT
:
319 case PIPE_FORMAT_S8_UINT_Z24_UNORM
:
320 strb
->Base
.InternalFormat
= GL_DEPTH24_STENCIL8_EXT
;
322 case PIPE_FORMAT_Z24X8_UNORM
:
323 case PIPE_FORMAT_X8Z24_UNORM
:
324 strb
->Base
.InternalFormat
= GL_DEPTH_COMPONENT24
;
326 case PIPE_FORMAT_S8_UINT
:
327 strb
->Base
.InternalFormat
= GL_STENCIL_INDEX8_EXT
;
329 case PIPE_FORMAT_R16G16B16A16_SNORM
:
331 strb
->Base
.InternalFormat
= GL_RGBA16_SNORM
;
333 case PIPE_FORMAT_R16G16B16A16_UNORM
:
334 strb
->Base
.InternalFormat
= GL_RGBA16
;
336 case PIPE_FORMAT_R8_UNORM
:
337 strb
->Base
.InternalFormat
= GL_R8
;
339 case PIPE_FORMAT_R8G8_UNORM
:
340 strb
->Base
.InternalFormat
= GL_RG8
;
342 case PIPE_FORMAT_R16_UNORM
:
343 strb
->Base
.InternalFormat
= GL_R16
;
345 case PIPE_FORMAT_R16G16_UNORM
:
346 strb
->Base
.InternalFormat
= GL_RG16
;
348 case PIPE_FORMAT_R32G32B32A32_FLOAT
:
349 strb
->Base
.InternalFormat
= GL_RGBA32F
;
351 case PIPE_FORMAT_R16G16B16A16_FLOAT
:
352 strb
->Base
.InternalFormat
= GL_RGBA16F
;
356 "Unexpected format %s in st_new_renderbuffer_fb",
357 util_format_name(format
));
362 /* st-specific methods */
363 strb
->Base
.Delete
= st_renderbuffer_delete
;
364 strb
->Base
.AllocStorage
= st_renderbuffer_alloc_storage
;
366 /* surface is allocated in st_renderbuffer_alloc_storage() */
367 strb
->surface
= NULL
;
374 * Called via ctx->Driver.BindFramebufferEXT().
377 st_bind_framebuffer(struct gl_context
*ctx
, GLenum target
,
378 struct gl_framebuffer
*fb
, struct gl_framebuffer
*fbread
)
385 * Called by ctx->Driver.RenderTexture
388 st_render_texture(struct gl_context
*ctx
,
389 struct gl_framebuffer
*fb
,
390 struct gl_renderbuffer_attachment
*att
)
392 struct st_context
*st
= st_context(ctx
);
393 struct pipe_context
*pipe
= st
->pipe
;
394 struct st_renderbuffer
*strb
;
395 struct gl_renderbuffer
*rb
;
396 struct pipe_resource
*pt
;
397 struct st_texture_object
*stObj
;
398 const struct gl_texture_image
*texImage
;
399 struct pipe_surface surf_tmpl
;
401 if (!st_finalize_texture(ctx
, pipe
, att
->Texture
))
404 pt
= st_get_texobj_resource(att
->Texture
);
407 /* get pointer to texture image we're rendeing to */
408 texImage
= _mesa_get_attachment_teximage(att
);
410 /* create new renderbuffer which wraps the texture image.
411 * Use the texture's name as the renderbuffer's name so that we have
412 * something that's non-zero (to determine vertical orientation) and
413 * possibly helpful for debugging.
415 rb
= st_new_renderbuffer(ctx
, att
->Texture
->Name
);
417 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glFramebufferTexture()");
421 _mesa_reference_renderbuffer(&att
->Renderbuffer
, rb
);
422 assert(rb
->RefCount
== 1);
423 rb
->AllocStorage
= NULL
; /* should not get called */
424 strb
= st_renderbuffer(rb
);
426 assert(strb
->Base
.RefCount
> 0);
428 /* get the texture for the texture object */
429 stObj
= st_texture_object(att
->Texture
);
431 /* point renderbuffer at texobject */
433 strb
->rtt_level
= att
->TextureLevel
;
434 strb
->rtt_face
= att
->CubeMapFace
;
435 strb
->rtt_slice
= att
->Zoffset
;
437 rb
->Width
= texImage
->Width2
;
438 rb
->Height
= texImage
->Height2
;
439 rb
->_BaseFormat
= texImage
->_BaseFormat
;
440 rb
->InternalFormat
= texImage
->InternalFormat
;
442 pipe_resource_reference( &strb
->texture
, pt
);
444 pipe_surface_release(pipe
, &strb
->surface
);
446 assert(strb
->rtt_level
<= strb
->texture
->last_level
);
448 /* new surface for rendering into the texture */
449 memset(&surf_tmpl
, 0, sizeof(surf_tmpl
));
450 surf_tmpl
.format
= ctx
->Color
.sRGBEnabled
451 ? strb
->texture
->format
: util_format_linear(strb
->texture
->format
);
452 surf_tmpl
.u
.tex
.level
= strb
->rtt_level
;
453 surf_tmpl
.u
.tex
.first_layer
= strb
->rtt_face
+ strb
->rtt_slice
;
454 surf_tmpl
.u
.tex
.last_layer
= strb
->rtt_face
+ strb
->rtt_slice
;
455 strb
->surface
= pipe
->create_surface(pipe
,
459 strb
->Base
.Format
= st_pipe_format_to_mesa_format(pt
->format
);
461 /* Invalidate buffer state so that the pipe's framebuffer state
463 * That's where the new renderbuffer (which we just created) gets
464 * passed to the pipe as a (color/depth) render target.
466 st_invalidate_state(ctx
, _NEW_BUFFERS
);
469 /* Need to trigger a call to update_framebuffer() since we just
470 * attached a new renderbuffer.
472 ctx
->NewState
|= _NEW_BUFFERS
;
477 * Called via ctx->Driver.FinishRenderTexture.
480 st_finish_render_texture(struct gl_context
*ctx
,
481 struct gl_renderbuffer_attachment
*att
)
483 struct st_renderbuffer
*strb
= st_renderbuffer(att
->Renderbuffer
);
490 /* restore previous framebuffer state */
491 st_invalidate_state(ctx
, _NEW_BUFFERS
);
497 st_fbo_invalid(const char *reason
)
499 if (MESA_DEBUG_FLAGS
& DEBUG_INCOMPLETE_FBO
) {
500 _mesa_debug(NULL
, "Invalid FBO: %s\n", reason
);
506 * Validate a renderbuffer attachment for a particular set of bindings.
509 st_validate_attachment(struct gl_context
*ctx
,
510 struct pipe_screen
*screen
,
511 const struct gl_renderbuffer_attachment
*att
,
514 const struct st_texture_object
*stObj
= st_texture_object(att
->Texture
);
515 enum pipe_format format
;
519 /* Only validate texture attachments for now, since
520 * st_renderbuffer_alloc_storage makes sure that
521 * the format is supported.
523 if (att
->Type
!= GL_TEXTURE
)
529 format
= stObj
->pt
->format
;
530 texFormat
= _mesa_get_attachment_teximage_const(att
)->TexFormat
;
532 /* If the encoding is sRGB and sRGB rendering cannot be enabled,
533 * check for linear format support instead.
534 * Later when we create a surface, we change the format to a linear one. */
535 if (!ctx
->Extensions
.EXT_framebuffer_sRGB
&&
536 _mesa_get_format_color_encoding(texFormat
) == GL_SRGB
) {
537 const gl_format linearFormat
= _mesa_get_srgb_format_linear(texFormat
);
538 format
= st_mesa_format_to_pipe_format(linearFormat
);
541 valid
= screen
->is_format_supported(screen
, format
,
543 stObj
->pt
->nr_samples
, bindings
);
545 st_fbo_invalid("Invalid format");
553 * Check if two renderbuffer attachments name a combined depth/stencil
557 st_is_depth_stencil_combined(const struct gl_renderbuffer_attachment
*depth
,
558 const struct gl_renderbuffer_attachment
*stencil
)
560 assert(depth
&& stencil
);
562 if (depth
->Type
== stencil
->Type
) {
563 if (depth
->Type
== GL_RENDERBUFFER_EXT
&&
564 depth
->Renderbuffer
== stencil
->Renderbuffer
)
567 if (depth
->Type
== GL_TEXTURE
&&
568 depth
->Texture
== stencil
->Texture
)
577 * Check that the framebuffer configuration is valid in terms of what
578 * the driver can support.
580 * For Gallium we only supports combined Z+stencil, not separate buffers.
583 st_validate_framebuffer(struct gl_context
*ctx
, struct gl_framebuffer
*fb
)
585 struct st_context
*st
= st_context(ctx
);
586 struct pipe_screen
*screen
= st
->pipe
->screen
;
587 const struct gl_renderbuffer_attachment
*depth
=
588 &fb
->Attachment
[BUFFER_DEPTH
];
589 const struct gl_renderbuffer_attachment
*stencil
=
590 &fb
->Attachment
[BUFFER_STENCIL
];
592 enum pipe_format first_format
= PIPE_FORMAT_NONE
;
593 boolean mixed_formats
=
594 screen
->get_param(screen
, PIPE_CAP_MIXED_COLORBUFFER_FORMATS
) != 0;
596 if (depth
->Type
&& stencil
->Type
&& depth
->Type
!= stencil
->Type
) {
597 st_fbo_invalid("Different Depth/Stencil buffer formats");
598 fb
->_Status
= GL_FRAMEBUFFER_UNSUPPORTED_EXT
;
601 if (depth
->Type
== GL_RENDERBUFFER_EXT
&&
602 stencil
->Type
== GL_RENDERBUFFER_EXT
&&
603 depth
->Renderbuffer
!= stencil
->Renderbuffer
) {
604 st_fbo_invalid("Separate Depth/Stencil buffers");
605 fb
->_Status
= GL_FRAMEBUFFER_UNSUPPORTED_EXT
;
608 if (depth
->Type
== GL_TEXTURE
&&
609 stencil
->Type
== GL_TEXTURE
&&
610 depth
->Texture
!= stencil
->Texture
) {
611 fb
->_Status
= GL_FRAMEBUFFER_UNSUPPORTED_EXT
;
612 st_fbo_invalid("Different Depth/Stencil textures");
616 if (!st_validate_attachment(ctx
,
619 PIPE_BIND_DEPTH_STENCIL
)) {
620 fb
->_Status
= GL_FRAMEBUFFER_UNSUPPORTED_EXT
;
623 if (!st_validate_attachment(ctx
,
626 PIPE_BIND_DEPTH_STENCIL
)) {
627 fb
->_Status
= GL_FRAMEBUFFER_UNSUPPORTED_EXT
;
630 for (i
= 0; i
< ctx
->Const
.MaxColorAttachments
; i
++) {
631 struct gl_renderbuffer_attachment
*att
=
632 &fb
->Attachment
[BUFFER_COLOR0
+ i
];
633 enum pipe_format format
;
635 if (!st_validate_attachment(ctx
,
638 PIPE_BIND_RENDER_TARGET
)) {
639 fb
->_Status
= GL_FRAMEBUFFER_UNSUPPORTED_EXT
;
643 if (!mixed_formats
) {
644 /* Disallow mixed formats. */
645 if (att
->Type
!= GL_NONE
) {
646 format
= st_renderbuffer(att
->Renderbuffer
)->surface
->format
;
651 if (first_format
== PIPE_FORMAT_NONE
) {
652 first_format
= format
;
653 } else if (format
!= first_format
) {
654 fb
->_Status
= GL_FRAMEBUFFER_UNSUPPORTED_EXT
;
655 st_fbo_invalid("Mixed color formats");
664 * Called via glDrawBuffer.
667 st_DrawBuffers(struct gl_context
*ctx
, GLsizei count
, const GLenum
*buffers
)
669 struct st_context
*st
= st_context(ctx
);
670 struct gl_framebuffer
*fb
= ctx
->DrawBuffer
;
676 /* add the renderbuffers on demand */
677 for (i
= 0; i
< fb
->_NumColorDrawBuffers
; i
++) {
678 gl_buffer_index idx
= fb
->_ColorDrawBufferIndexes
[i
];
679 st_manager_add_color_renderbuffer(st
, fb
, idx
);
685 * Called via glReadBuffer.
688 st_ReadBuffer(struct gl_context
*ctx
, GLenum buffer
)
690 struct st_context
*st
= st_context(ctx
);
691 struct gl_framebuffer
*fb
= ctx
->ReadBuffer
;
695 /* add the renderbuffer on demand */
696 st_manager_add_color_renderbuffer(st
, fb
, fb
->_ColorReadBufferIndex
);
702 * Called via ctx->Driver.MapRenderbuffer.
705 st_MapRenderbuffer(struct gl_context
*ctx
,
706 struct gl_renderbuffer
*rb
,
707 GLuint x
, GLuint y
, GLuint w
, GLuint h
,
709 GLubyte
**mapOut
, GLint
*rowStrideOut
)
711 struct st_context
*st
= st_context(ctx
);
712 struct st_renderbuffer
*strb
= st_renderbuffer(rb
);
713 struct pipe_context
*pipe
= st
->pipe
;
714 const GLboolean invert
= rb
->Name
== 0;
719 if (strb
->software
) {
720 /* software-allocated renderbuffer (probably an accum buffer) */
722 GLint bpp
= _mesa_get_format_bytes(strb
->Base
.Format
);
723 GLint stride
= _mesa_format_row_stride(strb
->Base
.Format
,
725 *mapOut
= (GLubyte
*) strb
->data
+ y
* stride
+ x
* bpp
;
726 *rowStrideOut
= stride
;
736 if (mode
& GL_MAP_READ_BIT
)
737 usage
|= PIPE_TRANSFER_READ
;
738 if (mode
& GL_MAP_WRITE_BIT
)
739 usage
|= PIPE_TRANSFER_WRITE
;
740 if (mode
& GL_MAP_INVALIDATE_RANGE_BIT
)
741 usage
|= PIPE_TRANSFER_DISCARD_RANGE
;
743 /* Note: y=0=bottom of buffer while y2=0=top of buffer.
744 * 'invert' will be true for window-system buffers and false for
745 * user-allocated renderbuffers and textures.
748 y2
= strb
->Base
.Height
- y
- h
;
752 map
= pipe_transfer_map(pipe
,
755 strb
->rtt_face
+ strb
->rtt_slice
,
756 usage
, x
, y2
, w
, h
, &strb
->transfer
);
759 *rowStrideOut
= -(int) strb
->transfer
->stride
;
760 map
+= (h
- 1) * strb
->transfer
->stride
;
763 *rowStrideOut
= strb
->transfer
->stride
;
775 * Called via ctx->Driver.UnmapRenderbuffer.
778 st_UnmapRenderbuffer(struct gl_context
*ctx
,
779 struct gl_renderbuffer
*rb
)
781 struct st_context
*st
= st_context(ctx
);
782 struct st_renderbuffer
*strb
= st_renderbuffer(rb
);
783 struct pipe_context
*pipe
= st
->pipe
;
785 if (strb
->software
) {
786 /* software-allocated renderbuffer (probably an accum buffer) */
790 pipe_transfer_unmap(pipe
, strb
->transfer
);
791 strb
->transfer
= NULL
;
796 void st_init_fbo_functions(struct dd_function_table
*functions
)
798 functions
->NewFramebuffer
= st_new_framebuffer
;
799 functions
->NewRenderbuffer
= st_new_renderbuffer
;
800 functions
->BindFramebuffer
= st_bind_framebuffer
;
801 functions
->FramebufferRenderbuffer
= _mesa_framebuffer_renderbuffer
;
802 functions
->RenderTexture
= st_render_texture
;
803 functions
->FinishRenderTexture
= st_finish_render_texture
;
804 functions
->ValidateFramebuffer
= st_validate_framebuffer
;
806 functions
->DrawBuffers
= st_DrawBuffers
;
807 functions
->ReadBuffer
= st_ReadBuffer
;
809 functions
->MapRenderbuffer
= st_MapRenderbuffer
;
810 functions
->UnmapRenderbuffer
= st_UnmapRenderbuffer
;