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"
43 #include "main/state.h"
45 #include "pipe/p_context.h"
46 #include "pipe/p_defines.h"
47 #include "pipe/p_screen.h"
49 #include "st_context.h"
50 #include "st_cb_fbo.h"
51 #include "st_cb_flush.h"
52 #include "st_cb_texture.h"
53 #include "st_format.h"
54 #include "st_texture.h"
55 #include "st_manager.h"
57 #include "util/u_format.h"
58 #include "util/u_inlines.h"
59 #include "util/u_surface.h"
63 st_renderbuffer_alloc_sw_storage(struct gl_context
* ctx
,
64 struct gl_renderbuffer
*rb
,
65 GLenum internalFormat
,
66 GLuint width
, GLuint height
)
68 struct st_context
*st
= st_context(ctx
);
69 struct st_renderbuffer
*strb
= st_renderbuffer(rb
);
70 enum pipe_format format
;
76 if (internalFormat
== GL_RGBA16_SNORM
) {
77 /* Special case for software accum buffers. Otherwise, if the
78 * call to st_choose_renderbuffer_format() fails (because the
79 * driver doesn't support signed 16-bit/channel colors) we'd
80 * just return without allocating the software accum buffer.
82 format
= PIPE_FORMAT_R16G16B16A16_SNORM
;
85 format
= st_choose_renderbuffer_format(st
, internalFormat
, 0);
87 /* Not setting gl_renderbuffer::Format here will cause
88 * FRAMEBUFFER_UNSUPPORTED and ValidateFramebuffer will not be called.
90 if (format
== PIPE_FORMAT_NONE
) {
95 strb
->Base
.Format
= st_pipe_format_to_mesa_format(format
);
97 size
= _mesa_format_image_size(strb
->Base
.Format
, width
, height
, 1);
98 strb
->data
= malloc(size
);
99 return strb
->data
!= NULL
;
104 * gl_renderbuffer::AllocStorage()
105 * This is called to allocate the original drawing surface, and
106 * during window resize.
109 st_renderbuffer_alloc_storage(struct gl_context
* ctx
,
110 struct gl_renderbuffer
*rb
,
111 GLenum internalFormat
,
112 GLuint width
, GLuint height
)
114 struct st_context
*st
= st_context(ctx
);
115 struct pipe_screen
*screen
= st
->pipe
->screen
;
116 struct st_renderbuffer
*strb
= st_renderbuffer(rb
);
117 enum pipe_format format
= PIPE_FORMAT_NONE
;
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_srgb
, NULL
);
134 pipe_surface_reference(&strb
->surface_linear
, NULL
);
135 strb
->surface
= NULL
;
136 pipe_resource_reference(&strb
->texture
, NULL
);
138 /* If an sRGB framebuffer is unsupported, sRGB formats behave like linear
141 if (!ctx
->Extensions
.EXT_framebuffer_sRGB
) {
142 internalFormat
= _mesa_get_linear_internalformat(internalFormat
);
145 /* Handle multisample renderbuffers first.
147 * From ARB_framebuffer_object:
148 * If <samples> is zero, then RENDERBUFFER_SAMPLES is set to zero.
149 * Otherwise <samples> represents a request for a desired minimum
150 * number of samples. Since different implementations may support
151 * different sample counts for multisampled rendering, the actual
152 * number of samples allocated for the renderbuffer image is
153 * implementation dependent. However, the resulting value for
154 * RENDERBUFFER_SAMPLES is guaranteed to be greater than or equal
155 * to <samples> and no more than the next larger sample count supported
156 * by the implementation.
158 * So let's find the supported number of samples closest to NumSamples.
159 * (NumSamples == 1) is treated the same as (NumSamples == 0).
161 if (rb
->NumSamples
> 1) {
164 for (i
= rb
->NumSamples
; i
<= ctx
->Const
.MaxSamples
; i
++) {
165 format
= st_choose_renderbuffer_format(st
, internalFormat
, i
);
167 if (format
!= PIPE_FORMAT_NONE
) {
173 format
= st_choose_renderbuffer_format(st
, internalFormat
, 0);
176 /* Not setting gl_renderbuffer::Format here will cause
177 * FRAMEBUFFER_UNSUPPORTED and ValidateFramebuffer will not be called.
179 if (format
== PIPE_FORMAT_NONE
) {
183 strb
->Base
.Format
= st_pipe_format_to_mesa_format(format
);
185 if (width
== 0 || height
== 0) {
186 /* if size is zero, nothing to allocate */
190 /* Setup new texture template.
192 memset(&templ
, 0, sizeof(templ
));
193 templ
.target
= st
->internal_target
;
194 templ
.format
= format
;
195 templ
.width0
= width
;
196 templ
.height0
= height
;
198 templ
.array_size
= 1;
199 templ
.nr_samples
= rb
->NumSamples
;
200 if (util_format_is_depth_or_stencil(format
)) {
201 templ
.bind
= PIPE_BIND_DEPTH_STENCIL
;
203 else if (strb
->Base
.Name
!= 0) {
204 /* this is a user-created renderbuffer */
205 templ
.bind
= PIPE_BIND_RENDER_TARGET
;
208 /* this is a window-system buffer */
209 templ
.bind
= (PIPE_BIND_DISPLAY_TARGET
|
210 PIPE_BIND_RENDER_TARGET
);
213 strb
->texture
= screen
->resource_create(screen
, &templ
);
218 st_update_renderbuffer_surface(st
, strb
);
219 return strb
->surface
!= NULL
;
224 * gl_renderbuffer::Delete()
227 st_renderbuffer_delete(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
)
229 struct st_renderbuffer
*strb
= st_renderbuffer(rb
);
231 struct st_context
*st
= st_context(ctx
);
232 pipe_surface_release(st
->pipe
, &strb
->surface_srgb
);
233 pipe_surface_release(st
->pipe
, &strb
->surface_linear
);
234 strb
->surface
= NULL
;
236 pipe_resource_reference(&strb
->texture
, NULL
);
238 _mesa_delete_renderbuffer(ctx
, rb
);
243 * Called via ctx->Driver.NewRenderbuffer()
245 static struct gl_renderbuffer
*
246 st_new_renderbuffer(struct gl_context
*ctx
, GLuint name
)
248 struct st_renderbuffer
*strb
= ST_CALLOC_STRUCT(st_renderbuffer
);
251 _mesa_init_renderbuffer(&strb
->Base
, name
);
252 strb
->Base
.Delete
= st_renderbuffer_delete
;
253 strb
->Base
.AllocStorage
= st_renderbuffer_alloc_storage
;
261 * Allocate a renderbuffer for an on-screen window (not a user-created
262 * renderbuffer). The window system code determines the format.
264 struct gl_renderbuffer
*
265 st_new_renderbuffer_fb(enum pipe_format format
, int samples
, boolean sw
)
267 struct st_renderbuffer
*strb
;
269 strb
= ST_CALLOC_STRUCT(st_renderbuffer
);
271 _mesa_error(NULL
, GL_OUT_OF_MEMORY
, "creating renderbuffer");
275 _mesa_init_renderbuffer(&strb
->Base
, 0);
276 strb
->Base
.ClassID
= 0x4242; /* just a unique value */
277 strb
->Base
.NumSamples
= samples
;
278 strb
->Base
.Format
= st_pipe_format_to_mesa_format(format
);
279 strb
->Base
._BaseFormat
= _mesa_get_format_base_format(strb
->Base
.Format
);
283 case PIPE_FORMAT_R8G8B8A8_UNORM
:
284 case PIPE_FORMAT_B8G8R8A8_UNORM
:
285 case PIPE_FORMAT_A8R8G8B8_UNORM
:
286 strb
->Base
.InternalFormat
= GL_RGBA8
;
288 case PIPE_FORMAT_R8G8B8X8_UNORM
:
289 case PIPE_FORMAT_B8G8R8X8_UNORM
:
290 case PIPE_FORMAT_X8R8G8B8_UNORM
:
291 strb
->Base
.InternalFormat
= GL_RGB8
;
293 case PIPE_FORMAT_R8G8B8A8_SRGB
:
294 case PIPE_FORMAT_B8G8R8A8_SRGB
:
295 case PIPE_FORMAT_A8R8G8B8_SRGB
:
296 strb
->Base
.InternalFormat
= GL_SRGB8_ALPHA8
;
298 case PIPE_FORMAT_R8G8B8X8_SRGB
:
299 case PIPE_FORMAT_B8G8R8X8_SRGB
:
300 case PIPE_FORMAT_X8R8G8B8_SRGB
:
301 strb
->Base
.InternalFormat
= GL_SRGB8
;
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 * Create or update the pipe_surface of a FBO renderbuffer.
375 * This is usually called after st_finalize_texture.
378 st_update_renderbuffer_surface(struct st_context
*st
,
379 struct st_renderbuffer
*strb
)
381 struct pipe_context
*pipe
= st
->pipe
;
382 struct pipe_resource
*resource
= strb
->texture
;
383 const struct st_texture_object
*stTexObj
= NULL
;
384 unsigned rtt_width
= strb
->Base
.Width
;
385 unsigned rtt_height
= strb
->Base
.Height
;
386 unsigned rtt_depth
= strb
->Base
.Depth
;
389 * For winsys fbo, it is possible that the renderbuffer is sRGB-capable but
390 * the format of strb->texture is linear (because we have no control over
391 * the format). Check strb->Base.Format instead of strb->texture->format
392 * to determine if the rb is sRGB-capable.
394 boolean enable_srgb
= st
->ctx
->Color
.sRGBEnabled
&&
395 _mesa_get_format_color_encoding(strb
->Base
.Format
) == GL_SRGB
;
396 enum pipe_format format
= resource
->format
;
399 stTexObj
= st_texture_object(strb
->Base
.TexImage
->TexObject
);
400 if (stTexObj
->surface_based
)
401 format
= stTexObj
->surface_format
;
404 format
= enable_srgb
? util_format_srgb(format
) : util_format_linear(format
);
406 if (resource
->target
== PIPE_TEXTURE_1D_ARRAY
) {
407 rtt_depth
= rtt_height
;
411 /* find matching mipmap level size */
413 for (level
= 0; level
<= resource
->last_level
; level
++) {
414 if (u_minify(resource
->width0
, level
) == rtt_width
&&
415 u_minify(resource
->height0
, level
) == rtt_height
&&
416 (resource
->target
!= PIPE_TEXTURE_3D
||
417 u_minify(resource
->depth0
, level
) == rtt_depth
)) {
421 assert(level
<= resource
->last_level
);
423 /* determine the layer bounds */
424 unsigned first_layer
, last_layer
;
425 if (strb
->rtt_layered
) {
427 last_layer
= util_max_layer(strb
->texture
, level
);
431 last_layer
= strb
->rtt_face
+ strb
->rtt_slice
;
434 /* Adjust for texture views */
435 if (strb
->is_rtt
&& resource
->array_size
> 1 &&
436 stTexObj
->base
.Immutable
) {
437 const struct gl_texture_object
*tex
= &stTexObj
->base
;
438 first_layer
+= tex
->MinLayer
;
439 if (!strb
->rtt_layered
)
440 last_layer
+= tex
->MinLayer
;
442 last_layer
= MIN2(first_layer
+ tex
->NumLayers
- 1, last_layer
);
445 struct pipe_surface
**psurf
=
446 enable_srgb
? &strb
->surface_srgb
: &strb
->surface_linear
;
447 struct pipe_surface
*surf
= *psurf
;
450 surf
->texture
->nr_samples
!= strb
->Base
.NumSamples
||
451 surf
->format
!= format
||
452 surf
->texture
!= resource
||
453 surf
->width
!= rtt_width
||
454 surf
->height
!= rtt_height
||
455 surf
->u
.tex
.level
!= level
||
456 surf
->u
.tex
.first_layer
!= first_layer
||
457 surf
->u
.tex
.last_layer
!= last_layer
) {
458 /* create a new pipe_surface */
459 struct pipe_surface surf_tmpl
;
460 memset(&surf_tmpl
, 0, sizeof(surf_tmpl
));
461 surf_tmpl
.format
= format
;
462 surf_tmpl
.u
.tex
.level
= level
;
463 surf_tmpl
.u
.tex
.first_layer
= first_layer
;
464 surf_tmpl
.u
.tex
.last_layer
= last_layer
;
466 pipe_surface_release(pipe
, psurf
);
468 *psurf
= pipe
->create_surface(pipe
, resource
, &surf_tmpl
);
470 strb
->surface
= *psurf
;
475 * Return the pipe_resource which stores a particular texture image.
477 static struct pipe_resource
*
478 get_teximage_resource(struct gl_texture_object
*texObj
,
479 unsigned face
, unsigned level
)
481 struct st_texture_image
*stImg
=
482 st_texture_image(texObj
->Image
[face
][level
]);
489 * Called by ctx->Driver.RenderTexture
492 st_render_texture(struct gl_context
*ctx
,
493 struct gl_framebuffer
*fb
,
494 struct gl_renderbuffer_attachment
*att
)
496 struct st_context
*st
= st_context(ctx
);
497 struct pipe_context
*pipe
= st
->pipe
;
498 struct gl_renderbuffer
*rb
= att
->Renderbuffer
;
499 struct st_renderbuffer
*strb
= st_renderbuffer(rb
);
500 struct pipe_resource
*pt
;
502 if (!st_finalize_texture(ctx
, pipe
, att
->Texture
, att
->CubeMapFace
))
505 pt
= get_teximage_resource(att
->Texture
,
510 /* point renderbuffer at texobject */
512 strb
->rtt_face
= att
->CubeMapFace
;
513 strb
->rtt_slice
= att
->Zoffset
;
514 strb
->rtt_layered
= att
->Layered
;
515 pipe_resource_reference(&strb
->texture
, pt
);
517 st_update_renderbuffer_surface(st
, strb
);
519 /* Invalidate buffer state so that the pipe's framebuffer state
521 * That's where the new renderbuffer (which we just created) gets
522 * passed to the pipe as a (color/depth) render target.
524 st_invalidate_buffers(st
);
527 /* Need to trigger a call to update_framebuffer() since we just
528 * attached a new renderbuffer.
530 ctx
->NewState
|= _NEW_BUFFERS
;
535 * Called via ctx->Driver.FinishRenderTexture.
538 st_finish_render_texture(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
)
540 struct st_context
*st
= st_context(ctx
);
541 struct st_renderbuffer
*strb
= st_renderbuffer(rb
);
546 strb
->is_rtt
= FALSE
;
548 /* restore previous framebuffer state */
549 st_invalidate_buffers(st
);
555 st_fbo_invalid(const char *reason
)
557 if (MESA_DEBUG_FLAGS
& DEBUG_INCOMPLETE_FBO
) {
558 _mesa_debug(NULL
, "Invalid FBO: %s\n", reason
);
564 * Validate a renderbuffer attachment for a particular set of bindings.
567 st_validate_attachment(struct gl_context
*ctx
,
568 struct pipe_screen
*screen
,
569 const struct gl_renderbuffer_attachment
*att
,
572 const struct st_texture_object
*stObj
= st_texture_object(att
->Texture
);
573 enum pipe_format format
;
574 mesa_format texFormat
;
577 /* Sanity check: we must be binding the surface as a (color) render target
578 * or depth/stencil target.
580 assert(bindings
== PIPE_BIND_RENDER_TARGET
||
581 bindings
== PIPE_BIND_DEPTH_STENCIL
);
583 /* Only validate texture attachments for now, since
584 * st_renderbuffer_alloc_storage makes sure that
585 * the format is supported.
587 if (att
->Type
!= GL_TEXTURE
)
590 if (!stObj
|| !stObj
->pt
)
593 format
= stObj
->pt
->format
;
594 texFormat
= att
->Renderbuffer
->TexImage
->TexFormat
;
596 /* If the encoding is sRGB and sRGB rendering cannot be enabled,
597 * check for linear format support instead.
598 * Later when we create a surface, we change the format to a linear one. */
599 if (!ctx
->Extensions
.EXT_framebuffer_sRGB
&&
600 _mesa_get_format_color_encoding(texFormat
) == GL_SRGB
) {
601 const mesa_format linearFormat
= _mesa_get_srgb_format_linear(texFormat
);
602 format
= st_mesa_format_to_pipe_format(st_context(ctx
), linearFormat
);
605 valid
= screen
->is_format_supported(screen
, format
,
607 stObj
->pt
->nr_samples
, bindings
);
609 st_fbo_invalid("Invalid format");
617 * Check that the framebuffer configuration is valid in terms of what
618 * the driver can support.
620 * For Gallium we only supports combined Z+stencil, not separate buffers.
623 st_validate_framebuffer(struct gl_context
*ctx
, struct gl_framebuffer
*fb
)
625 struct st_context
*st
= st_context(ctx
);
626 struct pipe_screen
*screen
= st
->pipe
->screen
;
627 const struct gl_renderbuffer_attachment
*depth
=
628 &fb
->Attachment
[BUFFER_DEPTH
];
629 const struct gl_renderbuffer_attachment
*stencil
=
630 &fb
->Attachment
[BUFFER_STENCIL
];
632 enum pipe_format first_format
= PIPE_FORMAT_NONE
;
633 boolean mixed_formats
=
634 screen
->get_param(screen
, PIPE_CAP_MIXED_COLORBUFFER_FORMATS
) != 0;
636 if (depth
->Type
&& stencil
->Type
&& depth
->Type
!= stencil
->Type
) {
637 st_fbo_invalid("Different Depth/Stencil buffer formats");
638 fb
->_Status
= GL_FRAMEBUFFER_UNSUPPORTED_EXT
;
641 if (depth
->Type
== GL_RENDERBUFFER_EXT
&&
642 stencil
->Type
== GL_RENDERBUFFER_EXT
&&
643 depth
->Renderbuffer
!= stencil
->Renderbuffer
) {
644 st_fbo_invalid("Separate Depth/Stencil buffers");
645 fb
->_Status
= GL_FRAMEBUFFER_UNSUPPORTED_EXT
;
648 if (depth
->Type
== GL_TEXTURE
&&
649 stencil
->Type
== GL_TEXTURE
&&
650 depth
->Texture
!= stencil
->Texture
) {
651 fb
->_Status
= GL_FRAMEBUFFER_UNSUPPORTED_EXT
;
652 st_fbo_invalid("Different Depth/Stencil textures");
656 if (!st_validate_attachment(ctx
, screen
, depth
, PIPE_BIND_DEPTH_STENCIL
)) {
657 fb
->_Status
= GL_FRAMEBUFFER_UNSUPPORTED_EXT
;
658 st_fbo_invalid("Invalid depth attachment");
661 if (!st_validate_attachment(ctx
, screen
, stencil
, PIPE_BIND_DEPTH_STENCIL
)) {
662 fb
->_Status
= GL_FRAMEBUFFER_UNSUPPORTED_EXT
;
663 st_fbo_invalid("Invalid stencil attachment");
666 for (i
= 0; i
< ctx
->Const
.MaxColorAttachments
; i
++) {
667 struct gl_renderbuffer_attachment
*att
=
668 &fb
->Attachment
[BUFFER_COLOR0
+ i
];
669 enum pipe_format format
;
671 if (!st_validate_attachment(ctx
, screen
, att
, PIPE_BIND_RENDER_TARGET
)) {
672 fb
->_Status
= GL_FRAMEBUFFER_UNSUPPORTED_EXT
;
673 st_fbo_invalid("Invalid color attachment");
677 if (!mixed_formats
) {
678 /* Disallow mixed formats. */
679 if (att
->Type
!= GL_NONE
) {
680 format
= st_renderbuffer(att
->Renderbuffer
)->surface
->format
;
685 if (first_format
== PIPE_FORMAT_NONE
) {
686 first_format
= format
;
687 } else if (format
!= first_format
) {
688 fb
->_Status
= GL_FRAMEBUFFER_UNSUPPORTED_EXT
;
689 st_fbo_invalid("Mixed color formats");
698 * Called via glDrawBuffer. We only provide this driver function so that we
699 * can check if we need to allocate a new renderbuffer. Specifically, we
700 * don't usually allocate a front color buffer when using a double-buffered
701 * visual. But if the app calls glDrawBuffer(GL_FRONT) we need to allocate
702 * that buffer. Note, this is only for window system buffers, not user-
706 st_DrawBuffers(struct gl_context
*ctx
, GLsizei count
, const GLenum
*buffers
)
708 struct st_context
*st
= st_context(ctx
);
709 struct gl_framebuffer
*fb
= ctx
->DrawBuffer
;
714 if (_mesa_is_winsys_fbo(fb
)) {
716 /* add the renderbuffers on demand */
717 for (i
= 0; i
< fb
->_NumColorDrawBuffers
; i
++) {
718 GLint idx
= fb
->_ColorDrawBufferIndexes
[i
];
721 st_manager_add_color_renderbuffer(st
, fb
, idx
);
729 * Called via glReadBuffer. As with st_DrawBuffers, we use this function
730 * to check if we need to allocate a renderbuffer on demand.
733 st_ReadBuffer(struct gl_context
*ctx
, GLenum buffer
)
735 struct st_context
*st
= st_context(ctx
);
736 struct gl_framebuffer
*fb
= ctx
->ReadBuffer
;
740 /* Check if we need to allocate a front color buffer.
741 * Front buffers are often allocated on demand (other color buffers are
742 * always allocated in advance).
744 if ((fb
->_ColorReadBufferIndex
== BUFFER_FRONT_LEFT
||
745 fb
->_ColorReadBufferIndex
== BUFFER_FRONT_RIGHT
) &&
746 fb
->Attachment
[fb
->_ColorReadBufferIndex
].Type
== GL_NONE
) {
747 assert(_mesa_is_winsys_fbo(fb
));
749 st_manager_add_color_renderbuffer(st
, fb
, fb
->_ColorReadBufferIndex
);
750 _mesa_update_state(ctx
);
751 st_validate_state(st
, ST_PIPELINE_UPDATE_FRAMEBUFFER
);
758 * Called via ctx->Driver.MapRenderbuffer.
761 st_MapRenderbuffer(struct gl_context
*ctx
,
762 struct gl_renderbuffer
*rb
,
763 GLuint x
, GLuint y
, GLuint w
, GLuint h
,
765 GLubyte
**mapOut
, GLint
*rowStrideOut
)
767 struct st_context
*st
= st_context(ctx
);
768 struct st_renderbuffer
*strb
= st_renderbuffer(rb
);
769 struct pipe_context
*pipe
= st
->pipe
;
770 const GLboolean invert
= rb
->Name
== 0;
775 if (strb
->software
) {
776 /* software-allocated renderbuffer (probably an accum buffer) */
778 GLint bpp
= _mesa_get_format_bytes(strb
->Base
.Format
);
779 GLint stride
= _mesa_format_row_stride(strb
->Base
.Format
,
781 *mapOut
= (GLubyte
*) strb
->data
+ y
* stride
+ x
* bpp
;
782 *rowStrideOut
= stride
;
792 if (mode
& GL_MAP_READ_BIT
)
793 usage
|= PIPE_TRANSFER_READ
;
794 if (mode
& GL_MAP_WRITE_BIT
)
795 usage
|= PIPE_TRANSFER_WRITE
;
796 if (mode
& GL_MAP_INVALIDATE_RANGE_BIT
)
797 usage
|= PIPE_TRANSFER_DISCARD_RANGE
;
799 /* Note: y=0=bottom of buffer while y2=0=top of buffer.
800 * 'invert' will be true for window-system buffers and false for
801 * user-allocated renderbuffers and textures.
804 y2
= strb
->Base
.Height
- y
- h
;
808 map
= pipe_transfer_map(pipe
,
810 strb
->surface
->u
.tex
.level
,
811 strb
->surface
->u
.tex
.first_layer
,
812 usage
, x
, y2
, w
, h
, &strb
->transfer
);
815 *rowStrideOut
= -(int) strb
->transfer
->stride
;
816 map
+= (h
- 1) * strb
->transfer
->stride
;
819 *rowStrideOut
= strb
->transfer
->stride
;
831 * Called via ctx->Driver.UnmapRenderbuffer.
834 st_UnmapRenderbuffer(struct gl_context
*ctx
,
835 struct gl_renderbuffer
*rb
)
837 struct st_context
*st
= st_context(ctx
);
838 struct st_renderbuffer
*strb
= st_renderbuffer(rb
);
839 struct pipe_context
*pipe
= st
->pipe
;
841 if (strb
->software
) {
842 /* software-allocated renderbuffer (probably an accum buffer) */
846 pipe_transfer_unmap(pipe
, strb
->transfer
);
847 strb
->transfer
= NULL
;
853 st_init_fbo_functions(struct dd_function_table
*functions
)
855 functions
->NewFramebuffer
= _mesa_new_framebuffer
;
856 functions
->NewRenderbuffer
= st_new_renderbuffer
;
857 functions
->FramebufferRenderbuffer
= _mesa_FramebufferRenderbuffer_sw
;
858 functions
->RenderTexture
= st_render_texture
;
859 functions
->FinishRenderTexture
= st_finish_render_texture
;
860 functions
->ValidateFramebuffer
= st_validate_framebuffer
;
862 functions
->DrawBuffers
= st_DrawBuffers
;
863 functions
->ReadBuffer
= st_ReadBuffer
;
865 functions
->MapRenderbuffer
= st_MapRenderbuffer
;
866 functions
->UnmapRenderbuffer
= st_UnmapRenderbuffer
;