2 * Mesa 3-D graphics library
5 * Copyright (C) 2010 LunarG Inc.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 * DEALINGS IN THE SOFTWARE.
26 * Chia-I Wu <olv@lunarg.com>
29 #include "main/mtypes.h"
30 #include "main/context.h"
31 #include "main/texobj.h"
32 #include "main/teximage.h"
33 #include "main/texstate.h"
34 #include "main/framebuffer.h"
35 #include "main/fbobject.h"
36 #include "main/renderbuffer.h"
37 #include "main/version.h"
38 #include "st_texture.h"
40 #include "st_context.h"
41 #include "st_format.h"
42 #include "st_cb_fbo.h"
43 #include "st_cb_flush.h"
44 #include "st_manager.h"
46 #include "state_tracker/st_gl_api.h"
48 #include "pipe/p_context.h"
49 #include "pipe/p_screen.h"
50 #include "util/u_format.h"
51 #include "util/u_pointer.h"
52 #include "util/u_inlines.h"
53 #include "util/u_atomic.h"
54 #include "util/u_surface.h"
57 * Cast wrapper to convert a struct gl_framebuffer to an st_framebuffer.
58 * Return NULL if the struct gl_framebuffer is a user-created framebuffer.
59 * We'll only return non-null for window system framebuffers.
60 * Note that this function may fail.
62 static INLINE
struct st_framebuffer
*
63 st_ws_framebuffer(struct gl_framebuffer
*fb
)
65 /* FBO cannot be casted. See st_new_framebuffer */
66 if (fb
&& _mesa_is_winsys_fbo(fb
))
67 return (struct st_framebuffer
*) fb
;
72 * Map an attachment to a buffer index.
74 static INLINE gl_buffer_index
75 attachment_to_buffer_index(enum st_attachment_type statt
)
77 gl_buffer_index index
;
80 case ST_ATTACHMENT_FRONT_LEFT
:
81 index
= BUFFER_FRONT_LEFT
;
83 case ST_ATTACHMENT_BACK_LEFT
:
84 index
= BUFFER_BACK_LEFT
;
86 case ST_ATTACHMENT_FRONT_RIGHT
:
87 index
= BUFFER_FRONT_RIGHT
;
89 case ST_ATTACHMENT_BACK_RIGHT
:
90 index
= BUFFER_BACK_RIGHT
;
92 case ST_ATTACHMENT_DEPTH_STENCIL
:
95 case ST_ATTACHMENT_ACCUM
:
98 case ST_ATTACHMENT_SAMPLE
:
100 index
= BUFFER_COUNT
;
108 * Map a buffer index to an attachment.
110 static INLINE
enum st_attachment_type
111 buffer_index_to_attachment(gl_buffer_index index
)
113 enum st_attachment_type statt
;
116 case BUFFER_FRONT_LEFT
:
117 statt
= ST_ATTACHMENT_FRONT_LEFT
;
119 case BUFFER_BACK_LEFT
:
120 statt
= ST_ATTACHMENT_BACK_LEFT
;
122 case BUFFER_FRONT_RIGHT
:
123 statt
= ST_ATTACHMENT_FRONT_RIGHT
;
125 case BUFFER_BACK_RIGHT
:
126 statt
= ST_ATTACHMENT_BACK_RIGHT
;
129 statt
= ST_ATTACHMENT_DEPTH_STENCIL
;
132 statt
= ST_ATTACHMENT_ACCUM
;
135 statt
= ST_ATTACHMENT_INVALID
;
143 * Make sure a context picks up the latest cached state of the
144 * drawables it binds to.
147 st_context_validate(struct st_context
*st
,
148 struct st_framebuffer
*stdraw
,
149 struct st_framebuffer
*stread
)
151 if (stdraw
&& stdraw
->stamp
!= st
->draw_stamp
) {
152 st
->dirty
.st
|= ST_NEW_FRAMEBUFFER
;
153 _mesa_resize_framebuffer(st
->ctx
, &stdraw
->Base
,
155 stdraw
->Base
.Height
);
156 st
->draw_stamp
= stdraw
->stamp
;
159 if (stread
&& stread
->stamp
!= st
->read_stamp
) {
160 if (stread
!= stdraw
) {
161 st
->dirty
.st
|= ST_NEW_FRAMEBUFFER
;
162 _mesa_resize_framebuffer(st
->ctx
, &stread
->Base
,
164 stread
->Base
.Height
);
166 st
->read_stamp
= stread
->stamp
;
171 * Validate a framebuffer to make sure up-to-date pipe_textures are used.
172 * The context is only used for creating pipe surfaces and for calling
173 * _mesa_resize_framebuffer().
174 * (That should probably be rethought, since those surfaces become
175 * drawable state, not context state, and can be freed by another pipe
179 st_framebuffer_validate(struct st_framebuffer
*stfb
,
180 struct st_context
*st
)
182 struct pipe_resource
*textures
[ST_ATTACHMENT_COUNT
];
185 boolean changed
= FALSE
;
186 int32_t new_stamp
= p_atomic_read(&stfb
->iface
->stamp
);
188 if (stfb
->iface_stamp
== new_stamp
)
191 /* validate the fb */
193 if (!stfb
->iface
->validate(stfb
->iface
, stfb
->statts
,
194 stfb
->num_statts
, textures
))
197 stfb
->iface_stamp
= new_stamp
;
198 new_stamp
= p_atomic_read(&stfb
->iface
->stamp
);
199 } while(stfb
->iface_stamp
!= new_stamp
);
201 width
= stfb
->Base
.Width
;
202 height
= stfb
->Base
.Height
;
204 for (i
= 0; i
< stfb
->num_statts
; i
++) {
205 struct st_renderbuffer
*strb
;
206 struct pipe_surface
*ps
, surf_tmpl
;
212 idx
= attachment_to_buffer_index(stfb
->statts
[i
]);
213 if (idx
>= BUFFER_COUNT
) {
214 pipe_resource_reference(&textures
[i
], NULL
);
218 strb
= st_renderbuffer(stfb
->Base
.Attachment
[idx
].Renderbuffer
);
220 if (strb
->texture
== textures
[i
]) {
221 pipe_resource_reference(&textures
[i
], NULL
);
225 u_surface_default_template(&surf_tmpl
, textures
[i
]);
226 ps
= st
->pipe
->create_surface(st
->pipe
, textures
[i
], &surf_tmpl
);
228 pipe_surface_reference(&strb
->surface
, ps
);
229 pipe_resource_reference(&strb
->texture
, ps
->texture
);
230 /* ownership transfered */
231 pipe_surface_reference(&ps
, NULL
);
235 strb
->Base
.Width
= strb
->surface
->width
;
236 strb
->Base
.Height
= strb
->surface
->height
;
238 width
= strb
->Base
.Width
;
239 height
= strb
->Base
.Height
;
242 pipe_resource_reference(&textures
[i
], NULL
);
247 _mesa_resize_framebuffer(st
->ctx
, &stfb
->Base
, width
, height
);
252 * Update the attachments to validate by looping the existing renderbuffers.
255 st_framebuffer_update_attachments(struct st_framebuffer
*stfb
)
259 stfb
->num_statts
= 0;
260 for (idx
= 0; idx
< BUFFER_COUNT
; idx
++) {
261 struct st_renderbuffer
*strb
;
262 enum st_attachment_type statt
;
264 strb
= st_renderbuffer(stfb
->Base
.Attachment
[idx
].Renderbuffer
);
265 if (!strb
|| strb
->software
)
268 statt
= buffer_index_to_attachment(idx
);
269 if (statt
!= ST_ATTACHMENT_INVALID
&&
270 st_visual_have_buffers(stfb
->iface
->visual
, 1 << statt
))
271 stfb
->statts
[stfb
->num_statts
++] = statt
;
277 * Add a renderbuffer to the framebuffer.
280 st_framebuffer_add_renderbuffer(struct st_framebuffer
*stfb
,
283 struct gl_renderbuffer
*rb
;
284 enum pipe_format format
;
290 /* do not distinguish depth/stencil buffers */
291 if (idx
== BUFFER_STENCIL
)
296 format
= stfb
->iface
->visual
->depth_stencil_format
;
300 format
= stfb
->iface
->visual
->accum_format
;
304 format
= stfb
->iface
->visual
->color_format
;
309 if (format
== PIPE_FORMAT_NONE
)
312 rb
= st_new_renderbuffer_fb(format
, stfb
->iface
->visual
->samples
, sw
);
316 if (idx
!= BUFFER_DEPTH
) {
317 _mesa_add_renderbuffer(&stfb
->Base
, idx
, rb
);
320 if (util_format_get_component_bits(format
, UTIL_FORMAT_COLORSPACE_ZS
, 0))
321 _mesa_add_renderbuffer(&stfb
->Base
, BUFFER_DEPTH
, rb
);
322 if (util_format_get_component_bits(format
, UTIL_FORMAT_COLORSPACE_ZS
, 1))
323 _mesa_add_renderbuffer(&stfb
->Base
, BUFFER_STENCIL
, rb
);
330 * Intialize a struct gl_config from a visual.
333 st_visual_to_context_mode(const struct st_visual
*visual
,
334 struct gl_config
*mode
)
336 memset(mode
, 0, sizeof(*mode
));
338 if (st_visual_have_buffers(visual
, ST_ATTACHMENT_BACK_LEFT_MASK
))
339 mode
->doubleBufferMode
= GL_TRUE
;
340 if (st_visual_have_buffers(visual
,
341 ST_ATTACHMENT_FRONT_RIGHT_MASK
| ST_ATTACHMENT_BACK_RIGHT_MASK
))
342 mode
->stereoMode
= GL_TRUE
;
344 if (visual
->color_format
!= PIPE_FORMAT_NONE
) {
345 mode
->rgbMode
= GL_TRUE
;
348 util_format_get_component_bits(visual
->color_format
,
349 UTIL_FORMAT_COLORSPACE_RGB
, 0);
351 util_format_get_component_bits(visual
->color_format
,
352 UTIL_FORMAT_COLORSPACE_RGB
, 1);
354 util_format_get_component_bits(visual
->color_format
,
355 UTIL_FORMAT_COLORSPACE_RGB
, 2);
357 util_format_get_component_bits(visual
->color_format
,
358 UTIL_FORMAT_COLORSPACE_RGB
, 3);
360 mode
->rgbBits
= mode
->redBits
+
361 mode
->greenBits
+ mode
->blueBits
+ mode
->alphaBits
;
364 if (visual
->depth_stencil_format
!= PIPE_FORMAT_NONE
) {
366 util_format_get_component_bits(visual
->depth_stencil_format
,
367 UTIL_FORMAT_COLORSPACE_ZS
, 0);
369 util_format_get_component_bits(visual
->depth_stencil_format
,
370 UTIL_FORMAT_COLORSPACE_ZS
, 1);
372 mode
->haveDepthBuffer
= mode
->depthBits
> 0;
373 mode
->haveStencilBuffer
= mode
->stencilBits
> 0;
376 if (visual
->accum_format
!= PIPE_FORMAT_NONE
) {
377 mode
->haveAccumBuffer
= GL_TRUE
;
380 util_format_get_component_bits(visual
->accum_format
,
381 UTIL_FORMAT_COLORSPACE_RGB
, 0);
382 mode
->accumGreenBits
=
383 util_format_get_component_bits(visual
->accum_format
,
384 UTIL_FORMAT_COLORSPACE_RGB
, 1);
385 mode
->accumBlueBits
=
386 util_format_get_component_bits(visual
->accum_format
,
387 UTIL_FORMAT_COLORSPACE_RGB
, 2);
388 mode
->accumAlphaBits
=
389 util_format_get_component_bits(visual
->accum_format
,
390 UTIL_FORMAT_COLORSPACE_RGB
, 3);
393 if (visual
->samples
> 1) {
394 mode
->sampleBuffers
= 1;
395 mode
->samples
= visual
->samples
;
400 * Create a framebuffer from a manager interface.
402 static struct st_framebuffer
*
403 st_framebuffer_create(struct st_framebuffer_iface
*stfbi
)
405 struct st_framebuffer
*stfb
;
406 struct gl_config mode
;
412 stfb
= CALLOC_STRUCT(st_framebuffer
);
416 st_visual_to_context_mode(stfbi
->visual
, &mode
);
417 _mesa_initialize_window_framebuffer(&stfb
->Base
, &mode
);
420 stfb
->iface_stamp
= p_atomic_read(&stfbi
->stamp
) - 1;
422 /* add the color buffer */
423 idx
= stfb
->Base
._ColorDrawBufferIndexes
[0];
424 if (!st_framebuffer_add_renderbuffer(stfb
, idx
)) {
429 st_framebuffer_add_renderbuffer(stfb
, BUFFER_DEPTH
);
430 st_framebuffer_add_renderbuffer(stfb
, BUFFER_ACCUM
);
433 st_framebuffer_update_attachments(stfb
);
435 stfb
->Base
.Initialized
= GL_TRUE
;
441 * Reference a framebuffer.
444 st_framebuffer_reference(struct st_framebuffer
**ptr
,
445 struct st_framebuffer
*stfb
)
447 struct gl_framebuffer
*fb
= &stfb
->Base
;
448 _mesa_reference_framebuffer((struct gl_framebuffer
**) ptr
, fb
);
452 st_context_flush(struct st_context_iface
*stctxi
, unsigned flags
,
453 struct pipe_fence_handle
**fence
)
455 struct st_context
*st
= (struct st_context
*) stctxi
;
456 enum pipe_flush_flags pipe_flags
= 0;
458 if (flags
& ST_FLUSH_END_OF_FRAME
) {
459 pipe_flags
|= PIPE_FLUSH_END_OF_FRAME
;
462 st_flush(st
, fence
, pipe_flags
);
463 if (flags
& ST_FLUSH_FRONT
)
464 st_manager_flush_frontbuffer(st
);
468 st_context_teximage(struct st_context_iface
*stctxi
,
469 enum st_texture_type tex_type
,
470 int level
, enum pipe_format internal_format
,
471 struct pipe_resource
*tex
, boolean mipmap
)
473 struct st_context
*st
= (struct st_context
*) stctxi
;
474 struct gl_context
*ctx
= st
->ctx
;
475 struct gl_texture_unit
*texUnit
= _mesa_get_current_tex_unit(ctx
);
476 struct gl_texture_object
*texObj
;
477 struct gl_texture_image
*texImage
;
478 struct st_texture_object
*stObj
;
479 struct st_texture_image
*stImage
;
480 GLenum internalFormat
;
481 GLuint width
, height
, depth
;
486 target
= GL_TEXTURE_1D
;
489 target
= GL_TEXTURE_2D
;
492 target
= GL_TEXTURE_3D
;
494 case ST_TEXTURE_RECT
:
495 target
= GL_TEXTURE_RECTANGLE_ARB
;
501 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
502 _mesa_lock_texture(ctx
, texObj
);
504 stObj
= st_texture_object(texObj
);
505 /* switch to surface based */
506 if (!stObj
->surface_based
) {
507 _mesa_clear_texture_object(ctx
, texObj
);
508 stObj
->surface_based
= GL_TRUE
;
511 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
512 stImage
= st_texture_image(texImage
);
517 * XXX When internal_format and tex->format differ, st_finalize_texture
518 * needs to allocate a new texture with internal_format and copy the
519 * texture here into the new one. It will result in surface_copy being
520 * called on surfaces whose formats differ.
522 * To avoid that, internal_format is (wrongly) ignored here. A sane fix
523 * is to use a sampler view.
525 if (!st_sampler_compat_formats(tex
->format
, internal_format
))
526 internal_format
= tex
->format
;
528 if (util_format_get_component_bits(internal_format
,
529 UTIL_FORMAT_COLORSPACE_RGB
, 3) > 0)
530 internalFormat
= GL_RGBA
;
532 internalFormat
= GL_RGB
;
534 texFormat
= st_ChooseTextureFormat(ctx
, target
, internalFormat
,
535 GL_BGRA
, GL_UNSIGNED_BYTE
);
537 _mesa_init_teximage_fields(ctx
, texImage
,
538 tex
->width0
, tex
->height0
, 1, 0,
539 internalFormat
, texFormat
);
542 height
= tex
->height0
;
545 /* grow the image size until we hit level = 0 */
557 _mesa_clear_texture_image(ctx
, texImage
);
558 width
= height
= depth
= 0;
561 pipe_resource_reference(&stImage
->pt
, tex
);
562 stObj
->width0
= width
;
563 stObj
->height0
= height
;
564 stObj
->depth0
= depth
;
566 _mesa_dirty_texobj(ctx
, texObj
, GL_TRUE
);
567 _mesa_unlock_texture(ctx
, texObj
);
573 st_context_copy(struct st_context_iface
*stctxi
,
574 struct st_context_iface
*stsrci
, unsigned mask
)
576 struct st_context
*st
= (struct st_context
*) stctxi
;
577 struct st_context
*src
= (struct st_context
*) stsrci
;
579 _mesa_copy_context(src
->ctx
, st
->ctx
, mask
);
583 st_context_share(struct st_context_iface
*stctxi
,
584 struct st_context_iface
*stsrci
)
586 struct st_context
*st
= (struct st_context
*) stctxi
;
587 struct st_context
*src
= (struct st_context
*) stsrci
;
589 return _mesa_share_state(st
->ctx
, src
->ctx
);
593 st_context_destroy(struct st_context_iface
*stctxi
)
595 struct st_context
*st
= (struct st_context
*) stctxi
;
596 st_destroy_context(st
);
599 static struct st_context_iface
*
600 st_api_create_context(struct st_api
*stapi
, struct st_manager
*smapi
,
601 const struct st_context_attribs
*attribs
,
602 enum st_context_error
*error
,
603 struct st_context_iface
*shared_stctxi
)
605 struct st_context
*shared_ctx
= (struct st_context
*) shared_stctxi
;
606 struct st_context
*st
;
607 struct pipe_context
*pipe
;
608 struct gl_config mode
;
611 if (!(stapi
->profile_mask
& (1 << attribs
->profile
)))
614 switch (attribs
->profile
) {
615 case ST_PROFILE_DEFAULT
:
616 api
= API_OPENGL_COMPAT
;
618 case ST_PROFILE_OPENGL_ES1
:
621 case ST_PROFILE_OPENGL_ES2
:
624 case ST_PROFILE_OPENGL_CORE
:
625 api
= API_OPENGL_CORE
;
628 *error
= ST_CONTEXT_ERROR_BAD_API
;
633 pipe
= smapi
->screen
->context_create(smapi
->screen
, NULL
);
635 *error
= ST_CONTEXT_ERROR_NO_MEMORY
;
639 st_visual_to_context_mode(&attribs
->visual
, &mode
);
640 st
= st_create_context(api
, pipe
, &mode
, shared_ctx
, &attribs
->options
);
642 *error
= ST_CONTEXT_ERROR_NO_MEMORY
;
647 if (attribs
->flags
& ST_CONTEXT_FLAG_DEBUG
)
648 st
->ctx
->Const
.ContextFlags
|= GL_CONTEXT_FLAG_DEBUG_BIT
;
649 if (attribs
->flags
& ST_CONTEXT_FLAG_FORWARD_COMPATIBLE
)
650 st
->ctx
->Const
.ContextFlags
|= GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT
;
652 /* need to perform version check */
653 if (attribs
->major
> 1 || attribs
->minor
> 0) {
654 /* Is the actual version less than the requested version?
656 if (st
->ctx
->Version
< attribs
->major
* 10 + attribs
->minor
) {
657 *error
= ST_CONTEXT_ERROR_BAD_VERSION
;
658 st_destroy_context(st
);
663 st
->invalidate_on_gl_viewport
=
664 smapi
->get_param(smapi
, ST_MANAGER_BROKEN_INVALIDATE
);
666 st
->iface
.destroy
= st_context_destroy
;
667 st
->iface
.flush
= st_context_flush
;
668 st
->iface
.teximage
= st_context_teximage
;
669 st
->iface
.copy
= st_context_copy
;
670 st
->iface
.share
= st_context_share
;
671 st
->iface
.st_context_private
= (void *) smapi
;
672 st
->iface
.cso_context
= st
->cso_context
;
673 st
->iface
.pipe
= st
->pipe
;
675 *error
= ST_CONTEXT_SUCCESS
;
679 static struct st_context_iface
*
680 st_api_get_current(struct st_api
*stapi
)
682 GET_CURRENT_CONTEXT(ctx
);
683 struct st_context
*st
= (ctx
) ? ctx
->st
: NULL
;
685 return (st
) ? &st
->iface
: NULL
;
688 static struct st_framebuffer
*
689 st_framebuffer_reuse_or_create(struct gl_framebuffer
*fb
,
690 struct st_framebuffer_iface
*stfbi
)
692 struct st_framebuffer
*cur
= st_ws_framebuffer(fb
), *stfb
= NULL
;
694 /* dummy framebuffers cant be used as st_framebuffer */
695 if (cur
&& &cur
->Base
!= _mesa_get_incomplete_framebuffer() &&
696 cur
->iface
== stfbi
) {
697 /* reuse the current stfb */
698 st_framebuffer_reference(&stfb
, cur
);
701 /* create a new one */
702 stfb
= st_framebuffer_create(stfbi
);
709 st_api_make_current(struct st_api
*stapi
, struct st_context_iface
*stctxi
,
710 struct st_framebuffer_iface
*stdrawi
,
711 struct st_framebuffer_iface
*streadi
)
713 struct st_context
*st
= (struct st_context
*) stctxi
;
714 struct st_framebuffer
*stdraw
, *stread
;
717 _glapi_check_multithread();
720 /* reuse or create the draw fb */
721 stdraw
= st_framebuffer_reuse_or_create(st
->ctx
->WinSysDrawBuffer
,
723 if (streadi
!= stdrawi
) {
724 /* do the same for the read fb */
725 stread
= st_framebuffer_reuse_or_create(st
->ctx
->WinSysReadBuffer
,
730 /* reuse the draw fb for the read fb */
732 st_framebuffer_reference(&stread
, stdraw
);
735 if (stdraw
&& stread
) {
736 st_framebuffer_validate(stdraw
, st
);
737 if (stread
!= stdraw
)
738 st_framebuffer_validate(stread
, st
);
740 ret
= _mesa_make_current(st
->ctx
, &stdraw
->Base
, &stread
->Base
);
742 st
->draw_stamp
= stdraw
->stamp
- 1;
743 st
->read_stamp
= stread
->stamp
- 1;
744 st_context_validate(st
, stdraw
, stread
);
747 struct gl_framebuffer
*incomplete
= _mesa_get_incomplete_framebuffer();
748 ret
= _mesa_make_current(st
->ctx
, incomplete
, incomplete
);
751 st_framebuffer_reference(&stdraw
, NULL
);
752 st_framebuffer_reference(&stread
, NULL
);
755 ret
= _mesa_make_current(NULL
, NULL
, NULL
);
762 st_api_get_proc_address(struct st_api
*stapi
, const char *procname
)
764 return (st_proc_t
) _glapi_get_proc_address(procname
);
768 st_api_destroy(struct st_api
*stapi
)
773 * Flush the front buffer if the current context renders to the front buffer.
776 st_manager_flush_frontbuffer(struct st_context
*st
)
778 struct st_framebuffer
*stfb
= st_ws_framebuffer(st
->ctx
->DrawBuffer
);
779 struct st_renderbuffer
*strb
= NULL
;
782 strb
= st_renderbuffer(stfb
->Base
.Attachment
[BUFFER_FRONT_LEFT
].Renderbuffer
);
786 /* never a dummy fb */
787 assert(&stfb
->Base
!= _mesa_get_incomplete_framebuffer());
788 stfb
->iface
->flush_front(&st
->iface
, stfb
->iface
, ST_ATTACHMENT_FRONT_LEFT
);
792 * Return the surface of an EGLImage.
793 * FIXME: I think this should operate on resources, not surfaces
795 struct pipe_surface
*
796 st_manager_get_egl_image_surface(struct st_context
*st
, void *eglimg
)
798 struct st_manager
*smapi
=
799 (struct st_manager
*) st
->iface
.st_context_private
;
800 struct st_egl_image stimg
;
801 struct pipe_surface
*ps
, surf_tmpl
;
803 if (!smapi
|| !smapi
->get_egl_image
)
806 memset(&stimg
, 0, sizeof(stimg
));
807 if (!smapi
->get_egl_image(smapi
, eglimg
, &stimg
))
810 u_surface_default_template(&surf_tmpl
, stimg
.texture
);
811 surf_tmpl
.u
.tex
.level
= stimg
.level
;
812 surf_tmpl
.u
.tex
.first_layer
= stimg
.layer
;
813 surf_tmpl
.u
.tex
.last_layer
= stimg
.layer
;
814 ps
= st
->pipe
->create_surface(st
->pipe
, stimg
.texture
, &surf_tmpl
);
815 pipe_resource_reference(&stimg
.texture
, NULL
);
821 * Re-validate the framebuffers.
824 st_manager_validate_framebuffers(struct st_context
*st
)
826 struct st_framebuffer
*stdraw
= st_ws_framebuffer(st
->ctx
->DrawBuffer
);
827 struct st_framebuffer
*stread
= st_ws_framebuffer(st
->ctx
->ReadBuffer
);
830 st_framebuffer_validate(stdraw
, st
);
831 if (stread
&& stread
!= stdraw
)
832 st_framebuffer_validate(stread
, st
);
834 st_context_validate(st
, stdraw
, stread
);
838 * Add a color renderbuffer on demand.
841 st_manager_add_color_renderbuffer(struct st_context
*st
,
842 struct gl_framebuffer
*fb
,
845 struct st_framebuffer
*stfb
= st_ws_framebuffer(fb
);
851 if (stfb
->Base
.Attachment
[idx
].Renderbuffer
)
855 case BUFFER_FRONT_LEFT
:
856 case BUFFER_BACK_LEFT
:
857 case BUFFER_FRONT_RIGHT
:
858 case BUFFER_BACK_RIGHT
:
865 if (!st_framebuffer_add_renderbuffer(stfb
, idx
))
868 st_framebuffer_update_attachments(stfb
);
871 * Force a call to the state tracker manager to validate the
872 * new renderbuffer. It might be that there is a window system
873 * renderbuffer available.
876 stfb
->iface_stamp
= p_atomic_read(&stfb
->iface
->stamp
) - 1;
878 st_invalidate_state(st
->ctx
, _NEW_BUFFERS
);
883 static const struct st_api st_gl_api
= {
884 "Mesa " PACKAGE_VERSION
,
886 ST_PROFILE_DEFAULT_MASK
|
887 ST_PROFILE_OPENGL_CORE_MASK
|
888 ST_PROFILE_OPENGL_ES1_MASK
|
889 ST_PROFILE_OPENGL_ES2_MASK
|
891 ST_API_FEATURE_MS_VISUALS_MASK
,
893 st_api_get_proc_address
,
894 st_api_create_context
,
900 st_gl_api_create(void)
902 return (struct st_api
*) &st_gl_api
;