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 unsigned 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 pipe_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
);
514 gl_format texFormat
= st_pipe_format_to_mesa_format(pipe_format
);
516 if (util_format_has_alpha(tex
->format
))
517 internalFormat
= GL_RGBA
;
519 internalFormat
= GL_RGB
;
521 _mesa_init_teximage_fields(ctx
, texImage
,
522 tex
->width0
, tex
->height0
, 1, 0,
523 internalFormat
, texFormat
);
526 height
= tex
->height0
;
529 /* grow the image size until we hit level = 0 */
541 _mesa_clear_texture_image(ctx
, texImage
);
542 width
= height
= depth
= 0;
545 pipe_resource_reference(&stImage
->pt
, tex
);
546 stObj
->width0
= width
;
547 stObj
->height0
= height
;
548 stObj
->depth0
= depth
;
549 stObj
->surface_format
= pipe_format
;
551 _mesa_dirty_texobj(ctx
, texObj
, GL_TRUE
);
552 _mesa_unlock_texture(ctx
, texObj
);
558 st_context_copy(struct st_context_iface
*stctxi
,
559 struct st_context_iface
*stsrci
, unsigned mask
)
561 struct st_context
*st
= (struct st_context
*) stctxi
;
562 struct st_context
*src
= (struct st_context
*) stsrci
;
564 _mesa_copy_context(src
->ctx
, st
->ctx
, mask
);
568 st_context_share(struct st_context_iface
*stctxi
,
569 struct st_context_iface
*stsrci
)
571 struct st_context
*st
= (struct st_context
*) stctxi
;
572 struct st_context
*src
= (struct st_context
*) stsrci
;
574 return _mesa_share_state(st
->ctx
, src
->ctx
);
578 st_context_destroy(struct st_context_iface
*stctxi
)
580 struct st_context
*st
= (struct st_context
*) stctxi
;
581 st_destroy_context(st
);
584 static struct st_context_iface
*
585 st_api_create_context(struct st_api
*stapi
, struct st_manager
*smapi
,
586 const struct st_context_attribs
*attribs
,
587 enum st_context_error
*error
,
588 struct st_context_iface
*shared_stctxi
)
590 struct st_context
*shared_ctx
= (struct st_context
*) shared_stctxi
;
591 struct st_context
*st
;
592 struct pipe_context
*pipe
;
593 struct gl_config mode
;
596 if (!(stapi
->profile_mask
& (1 << attribs
->profile
)))
599 switch (attribs
->profile
) {
600 case ST_PROFILE_DEFAULT
:
601 api
= API_OPENGL_COMPAT
;
603 case ST_PROFILE_OPENGL_ES1
:
606 case ST_PROFILE_OPENGL_ES2
:
609 case ST_PROFILE_OPENGL_CORE
:
610 api
= API_OPENGL_CORE
;
613 *error
= ST_CONTEXT_ERROR_BAD_API
;
618 pipe
= smapi
->screen
->context_create(smapi
->screen
, NULL
);
620 *error
= ST_CONTEXT_ERROR_NO_MEMORY
;
624 st_visual_to_context_mode(&attribs
->visual
, &mode
);
625 st
= st_create_context(api
, pipe
, &mode
, shared_ctx
, &attribs
->options
);
627 *error
= ST_CONTEXT_ERROR_NO_MEMORY
;
632 if (attribs
->flags
& ST_CONTEXT_FLAG_DEBUG
)
633 st
->ctx
->Const
.ContextFlags
|= GL_CONTEXT_FLAG_DEBUG_BIT
;
634 if (attribs
->flags
& ST_CONTEXT_FLAG_FORWARD_COMPATIBLE
)
635 st
->ctx
->Const
.ContextFlags
|= GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT
;
637 /* need to perform version check */
638 if (attribs
->major
> 1 || attribs
->minor
> 0) {
639 /* Is the actual version less than the requested version?
641 if (st
->ctx
->Version
< attribs
->major
* 10 + attribs
->minor
) {
642 *error
= ST_CONTEXT_ERROR_BAD_VERSION
;
643 st_destroy_context(st
);
648 st
->invalidate_on_gl_viewport
=
649 smapi
->get_param(smapi
, ST_MANAGER_BROKEN_INVALIDATE
);
651 st
->iface
.destroy
= st_context_destroy
;
652 st
->iface
.flush
= st_context_flush
;
653 st
->iface
.teximage
= st_context_teximage
;
654 st
->iface
.copy
= st_context_copy
;
655 st
->iface
.share
= st_context_share
;
656 st
->iface
.st_context_private
= (void *) smapi
;
657 st
->iface
.cso_context
= st
->cso_context
;
658 st
->iface
.pipe
= st
->pipe
;
660 *error
= ST_CONTEXT_SUCCESS
;
664 static struct st_context_iface
*
665 st_api_get_current(struct st_api
*stapi
)
667 GET_CURRENT_CONTEXT(ctx
);
668 struct st_context
*st
= (ctx
) ? ctx
->st
: NULL
;
670 return (st
) ? &st
->iface
: NULL
;
673 static struct st_framebuffer
*
674 st_framebuffer_reuse_or_create(struct gl_framebuffer
*fb
,
675 struct st_framebuffer_iface
*stfbi
)
677 struct st_framebuffer
*cur
= st_ws_framebuffer(fb
), *stfb
= NULL
;
679 /* dummy framebuffers cant be used as st_framebuffer */
680 if (cur
&& &cur
->Base
!= _mesa_get_incomplete_framebuffer() &&
681 cur
->iface
== stfbi
) {
682 /* reuse the current stfb */
683 st_framebuffer_reference(&stfb
, cur
);
686 /* create a new one */
687 stfb
= st_framebuffer_create(stfbi
);
694 st_api_make_current(struct st_api
*stapi
, struct st_context_iface
*stctxi
,
695 struct st_framebuffer_iface
*stdrawi
,
696 struct st_framebuffer_iface
*streadi
)
698 struct st_context
*st
= (struct st_context
*) stctxi
;
699 struct st_framebuffer
*stdraw
, *stread
;
702 _glapi_check_multithread();
705 /* reuse or create the draw fb */
706 stdraw
= st_framebuffer_reuse_or_create(st
->ctx
->WinSysDrawBuffer
,
708 if (streadi
!= stdrawi
) {
709 /* do the same for the read fb */
710 stread
= st_framebuffer_reuse_or_create(st
->ctx
->WinSysReadBuffer
,
715 /* reuse the draw fb for the read fb */
717 st_framebuffer_reference(&stread
, stdraw
);
720 if (stdraw
&& stread
) {
721 st_framebuffer_validate(stdraw
, st
);
722 if (stread
!= stdraw
)
723 st_framebuffer_validate(stread
, st
);
725 ret
= _mesa_make_current(st
->ctx
, &stdraw
->Base
, &stread
->Base
);
727 st
->draw_stamp
= stdraw
->stamp
- 1;
728 st
->read_stamp
= stread
->stamp
- 1;
729 st_context_validate(st
, stdraw
, stread
);
732 struct gl_framebuffer
*incomplete
= _mesa_get_incomplete_framebuffer();
733 ret
= _mesa_make_current(st
->ctx
, incomplete
, incomplete
);
736 st_framebuffer_reference(&stdraw
, NULL
);
737 st_framebuffer_reference(&stread
, NULL
);
740 ret
= _mesa_make_current(NULL
, NULL
, NULL
);
747 st_api_get_proc_address(struct st_api
*stapi
, const char *procname
)
749 return (st_proc_t
) _glapi_get_proc_address(procname
);
753 st_api_destroy(struct st_api
*stapi
)
758 * Flush the front buffer if the current context renders to the front buffer.
761 st_manager_flush_frontbuffer(struct st_context
*st
)
763 struct st_framebuffer
*stfb
= st_ws_framebuffer(st
->ctx
->DrawBuffer
);
764 struct st_renderbuffer
*strb
= NULL
;
767 strb
= st_renderbuffer(stfb
->Base
.Attachment
[BUFFER_FRONT_LEFT
].Renderbuffer
);
771 /* never a dummy fb */
772 assert(&stfb
->Base
!= _mesa_get_incomplete_framebuffer());
773 stfb
->iface
->flush_front(&st
->iface
, stfb
->iface
, ST_ATTACHMENT_FRONT_LEFT
);
777 * Return the surface of an EGLImage.
778 * FIXME: I think this should operate on resources, not surfaces
780 struct pipe_surface
*
781 st_manager_get_egl_image_surface(struct st_context
*st
, void *eglimg
)
783 struct st_manager
*smapi
=
784 (struct st_manager
*) st
->iface
.st_context_private
;
785 struct st_egl_image stimg
;
786 struct pipe_surface
*ps
, surf_tmpl
;
788 if (!smapi
|| !smapi
->get_egl_image
)
791 memset(&stimg
, 0, sizeof(stimg
));
792 if (!smapi
->get_egl_image(smapi
, eglimg
, &stimg
))
795 u_surface_default_template(&surf_tmpl
, stimg
.texture
);
796 surf_tmpl
.u
.tex
.level
= stimg
.level
;
797 surf_tmpl
.u
.tex
.first_layer
= stimg
.layer
;
798 surf_tmpl
.u
.tex
.last_layer
= stimg
.layer
;
799 ps
= st
->pipe
->create_surface(st
->pipe
, stimg
.texture
, &surf_tmpl
);
800 pipe_resource_reference(&stimg
.texture
, NULL
);
806 * Re-validate the framebuffers.
809 st_manager_validate_framebuffers(struct st_context
*st
)
811 struct st_framebuffer
*stdraw
= st_ws_framebuffer(st
->ctx
->DrawBuffer
);
812 struct st_framebuffer
*stread
= st_ws_framebuffer(st
->ctx
->ReadBuffer
);
815 st_framebuffer_validate(stdraw
, st
);
816 if (stread
&& stread
!= stdraw
)
817 st_framebuffer_validate(stread
, st
);
819 st_context_validate(st
, stdraw
, stread
);
823 * Add a color renderbuffer on demand.
826 st_manager_add_color_renderbuffer(struct st_context
*st
,
827 struct gl_framebuffer
*fb
,
830 struct st_framebuffer
*stfb
= st_ws_framebuffer(fb
);
836 if (stfb
->Base
.Attachment
[idx
].Renderbuffer
)
840 case BUFFER_FRONT_LEFT
:
841 case BUFFER_BACK_LEFT
:
842 case BUFFER_FRONT_RIGHT
:
843 case BUFFER_BACK_RIGHT
:
850 if (!st_framebuffer_add_renderbuffer(stfb
, idx
))
853 st_framebuffer_update_attachments(stfb
);
856 * Force a call to the state tracker manager to validate the
857 * new renderbuffer. It might be that there is a window system
858 * renderbuffer available.
861 stfb
->iface_stamp
= p_atomic_read(&stfb
->iface
->stamp
) - 1;
863 st_invalidate_state(st
->ctx
, _NEW_BUFFERS
);
868 static const struct st_api st_gl_api
= {
869 "Mesa " PACKAGE_VERSION
,
871 ST_PROFILE_DEFAULT_MASK
|
872 ST_PROFILE_OPENGL_CORE_MASK
|
873 ST_PROFILE_OPENGL_ES1_MASK
|
874 ST_PROFILE_OPENGL_ES2_MASK
|
876 ST_API_FEATURE_MS_VISUALS_MASK
,
878 st_api_get_proc_address
,
879 st_api_create_context
,
885 st_gl_api_create(void)
887 return (struct st_api
*) &st_gl_api
;