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 "state_tracker/st_gl_api.h"
31 #include "pipe/p_context.h"
32 #include "pipe/p_screen.h"
33 #include "util/u_format.h"
34 #include "util/u_pointer.h"
35 #include "util/u_inlines.h"
36 #include "util/u_atomic.h"
38 #include "main/mtypes.h"
39 #include "main/context.h"
40 #include "main/texobj.h"
41 #include "main/teximage.h"
42 #include "main/texstate.h"
43 #include "main/framebuffer.h"
44 #include "main/fbobject.h"
45 #include "main/renderbuffer.h"
46 #include "main/version.h"
47 #include "st_texture.h"
49 #include "st_context.h"
50 #include "st_format.h"
51 #include "st_cb_fbo.h"
52 #include "st_cb_flush.h"
53 #include "st_manager.h"
56 * Cast wrapper to convert a struct gl_framebuffer to an st_framebuffer.
57 * Return NULL if the struct gl_framebuffer is a user-created framebuffer.
58 * We'll only return non-null for window system framebuffers.
59 * Note that this function may fail.
61 static INLINE
struct st_framebuffer
*
62 st_ws_framebuffer(struct gl_framebuffer
*fb
)
64 /* FBO cannot be casted. See st_new_framebuffer */
65 return (struct st_framebuffer
*) ((fb
&& !fb
->Name
) ? fb
: NULL
);
69 * Map an attachment to a buffer index.
71 static INLINE gl_buffer_index
72 attachment_to_buffer_index(enum st_attachment_type statt
)
74 gl_buffer_index index
;
77 case ST_ATTACHMENT_FRONT_LEFT
:
78 index
= BUFFER_FRONT_LEFT
;
80 case ST_ATTACHMENT_BACK_LEFT
:
81 index
= BUFFER_BACK_LEFT
;
83 case ST_ATTACHMENT_FRONT_RIGHT
:
84 index
= BUFFER_FRONT_RIGHT
;
86 case ST_ATTACHMENT_BACK_RIGHT
:
87 index
= BUFFER_BACK_RIGHT
;
89 case ST_ATTACHMENT_DEPTH_STENCIL
:
92 case ST_ATTACHMENT_ACCUM
:
95 case ST_ATTACHMENT_SAMPLE
:
105 * Map a buffer index to an attachment.
107 static INLINE
enum st_attachment_type
108 buffer_index_to_attachment(gl_buffer_index index
)
110 enum st_attachment_type statt
;
113 case BUFFER_FRONT_LEFT
:
114 statt
= ST_ATTACHMENT_FRONT_LEFT
;
116 case BUFFER_BACK_LEFT
:
117 statt
= ST_ATTACHMENT_BACK_LEFT
;
119 case BUFFER_FRONT_RIGHT
:
120 statt
= ST_ATTACHMENT_FRONT_RIGHT
;
122 case BUFFER_BACK_RIGHT
:
123 statt
= ST_ATTACHMENT_BACK_RIGHT
;
126 statt
= ST_ATTACHMENT_DEPTH_STENCIL
;
129 statt
= ST_ATTACHMENT_ACCUM
;
132 statt
= ST_ATTACHMENT_INVALID
;
140 * Validate a framebuffer to make sure up-to-date pipe_textures are used.
143 st_framebuffer_validate(struct st_framebuffer
*stfb
, struct st_context
*st
)
145 struct pipe_screen
*screen
= st
->pipe
->screen
;
146 struct pipe_resource
*textures
[ST_ATTACHMENT_COUNT
];
149 boolean changed
= FALSE
;
151 if (!p_atomic_read(&stfb
->revalidate
))
154 /* validate the fb */
155 if (!stfb
->iface
->validate(stfb
->iface
, stfb
->statts
, stfb
->num_statts
, textures
))
158 width
= stfb
->Base
.Width
;
159 height
= stfb
->Base
.Height
;
161 for (i
= 0; i
< stfb
->num_statts
; i
++) {
162 struct st_renderbuffer
*strb
;
163 struct pipe_surface
*ps
;
169 idx
= attachment_to_buffer_index(stfb
->statts
[i
]);
170 if (idx
>= BUFFER_COUNT
) {
171 pipe_resource_reference(&textures
[i
], NULL
);
175 strb
= st_renderbuffer(stfb
->Base
.Attachment
[idx
].Renderbuffer
);
177 if (strb
->texture
== textures
[i
]) {
178 pipe_resource_reference(&textures
[i
], NULL
);
182 ps
= screen
->get_tex_surface(screen
, textures
[i
], 0, 0, 0,
183 PIPE_BIND_RENDER_TARGET
);
185 pipe_surface_reference(&strb
->surface
, ps
);
186 pipe_resource_reference(&strb
->texture
, ps
->texture
);
187 /* ownership transfered */
188 pipe_surface_reference(&ps
, NULL
);
192 strb
->Base
.Width
= strb
->surface
->width
;
193 strb
->Base
.Height
= strb
->surface
->height
;
195 width
= strb
->Base
.Width
;
196 height
= strb
->Base
.Height
;
199 pipe_resource_reference(&textures
[i
], NULL
);
203 st
->dirty
.st
|= ST_NEW_FRAMEBUFFER
;
204 _mesa_resize_framebuffer(st
->ctx
, &stfb
->Base
, width
, height
);
206 assert(stfb
->Base
.Width
== width
);
207 assert(stfb
->Base
.Height
== height
);
210 p_atomic_set(&stfb
->revalidate
, FALSE
);
214 * Update the attachments to validate by looping the existing renderbuffers.
217 st_framebuffer_update_attachments(struct st_framebuffer
*stfb
)
221 stfb
->num_statts
= 0;
222 for (idx
= 0; idx
< BUFFER_COUNT
; idx
++) {
223 struct st_renderbuffer
*strb
;
224 enum st_attachment_type statt
;
226 strb
= st_renderbuffer(stfb
->Base
.Attachment
[idx
].Renderbuffer
);
227 if (!strb
|| strb
->software
)
230 statt
= buffer_index_to_attachment(idx
);
231 if (statt
!= ST_ATTACHMENT_INVALID
&&
232 st_visual_have_buffers(stfb
->iface
->visual
, 1 << statt
))
233 stfb
->statts
[stfb
->num_statts
++] = statt
;
236 p_atomic_set(&stfb
->revalidate
, TRUE
);
240 * Add a renderbuffer to the framebuffer.
243 st_framebuffer_add_renderbuffer(struct st_framebuffer
*stfb
,
246 struct gl_renderbuffer
*rb
;
247 enum pipe_format format
;
254 /* do not distinguish depth/stencil buffers */
255 if (idx
== BUFFER_STENCIL
)
260 format
= stfb
->iface
->visual
->depth_stencil_format
;
264 format
= stfb
->iface
->visual
->accum_format
;
268 format
= stfb
->iface
->visual
->color_format
;
273 if (format
== PIPE_FORMAT_NONE
)
276 samples
= stfb
->iface
->visual
->samples
;
278 samples
= st_get_msaa();
280 rb
= st_new_renderbuffer_fb(format
, samples
, sw
);
284 if (idx
!= BUFFER_DEPTH
) {
285 _mesa_add_renderbuffer(&stfb
->Base
, idx
, rb
);
288 if (util_format_get_component_bits(format
, UTIL_FORMAT_COLORSPACE_ZS
, 0))
289 _mesa_add_renderbuffer(&stfb
->Base
, BUFFER_DEPTH
, rb
);
290 if (util_format_get_component_bits(format
, UTIL_FORMAT_COLORSPACE_ZS
, 1))
291 _mesa_add_renderbuffer(&stfb
->Base
, BUFFER_STENCIL
, rb
);
298 * Intialize a struct gl_config from a visual.
301 st_visual_to_context_mode(const struct st_visual
*visual
,
302 struct gl_config
*mode
)
304 memset(mode
, 0, sizeof(*mode
));
306 if (st_visual_have_buffers(visual
, ST_ATTACHMENT_BACK_LEFT_MASK
))
307 mode
->doubleBufferMode
= GL_TRUE
;
308 if (st_visual_have_buffers(visual
,
309 ST_ATTACHMENT_FRONT_RIGHT_MASK
| ST_ATTACHMENT_BACK_RIGHT_MASK
))
310 mode
->stereoMode
= GL_TRUE
;
312 if (visual
->color_format
!= PIPE_FORMAT_NONE
) {
313 mode
->rgbMode
= GL_TRUE
;
316 util_format_get_component_bits(visual
->color_format
,
317 UTIL_FORMAT_COLORSPACE_RGB
, 0);
319 util_format_get_component_bits(visual
->color_format
,
320 UTIL_FORMAT_COLORSPACE_RGB
, 1);
322 util_format_get_component_bits(visual
->color_format
,
323 UTIL_FORMAT_COLORSPACE_RGB
, 2);
325 util_format_get_component_bits(visual
->color_format
,
326 UTIL_FORMAT_COLORSPACE_RGB
, 3);
328 mode
->rgbBits
= mode
->redBits
+
329 mode
->greenBits
+ mode
->blueBits
+ mode
->alphaBits
;
332 if (visual
->depth_stencil_format
!= PIPE_FORMAT_NONE
) {
334 util_format_get_component_bits(visual
->depth_stencil_format
,
335 UTIL_FORMAT_COLORSPACE_ZS
, 0);
337 util_format_get_component_bits(visual
->depth_stencil_format
,
338 UTIL_FORMAT_COLORSPACE_ZS
, 1);
340 mode
->haveDepthBuffer
= mode
->depthBits
> 0;
341 mode
->haveStencilBuffer
= mode
->stencilBits
> 0;
344 if (visual
->accum_format
!= PIPE_FORMAT_NONE
) {
345 mode
->haveAccumBuffer
= GL_TRUE
;
348 util_format_get_component_bits(visual
->accum_format
,
349 UTIL_FORMAT_COLORSPACE_RGB
, 0);
350 mode
->accumGreenBits
=
351 util_format_get_component_bits(visual
->accum_format
,
352 UTIL_FORMAT_COLORSPACE_RGB
, 1);
353 mode
->accumBlueBits
=
354 util_format_get_component_bits(visual
->accum_format
,
355 UTIL_FORMAT_COLORSPACE_RGB
, 2);
356 mode
->accumAlphaBits
=
357 util_format_get_component_bits(visual
->accum_format
,
358 UTIL_FORMAT_COLORSPACE_RGB
, 3);
361 if (visual
->samples
) {
362 mode
->sampleBuffers
= 1;
363 mode
->samples
= visual
->samples
;
368 * Determine the default draw or read buffer from a visual.
371 st_visual_to_default_buffer(const struct st_visual
*visual
,
372 GLenum
*buffer
, GLint
*index
)
374 enum st_attachment_type statt
;
378 statt
= visual
->render_buffer
;
379 /* do nothing if an invalid render buffer is specified */
380 if (statt
== ST_ATTACHMENT_INVALID
||
381 !st_visual_have_buffers(visual
, 1 << statt
))
385 case ST_ATTACHMENT_FRONT_LEFT
:
387 idx
= BUFFER_FRONT_LEFT
;
389 case ST_ATTACHMENT_BACK_LEFT
:
391 idx
= BUFFER_BACK_LEFT
;
393 case ST_ATTACHMENT_FRONT_RIGHT
:
394 buf
= GL_FRONT_RIGHT
;
395 idx
= BUFFER_FRONT_RIGHT
;
397 case ST_ATTACHMENT_BACK_RIGHT
:
399 idx
= BUFFER_BACK_RIGHT
;
407 if (buf
!= GL_NONE
) {
416 * Create a framebuffer from a manager interface.
418 static struct st_framebuffer
*
419 st_framebuffer_create(struct st_framebuffer_iface
*stfbi
)
421 struct st_framebuffer
*stfb
;
422 struct gl_config mode
;
425 stfb
= CALLOC_STRUCT(st_framebuffer
);
429 /* for FBO-only context */
431 struct gl_framebuffer
*base
= _mesa_get_incomplete_framebuffer();
438 st_visual_to_context_mode(stfbi
->visual
, &mode
);
439 _mesa_initialize_window_framebuffer(&stfb
->Base
, &mode
);
441 /* modify the draw/read buffers of the fb */
442 st_visual_to_default_buffer(stfbi
->visual
, &stfb
->Base
.ColorDrawBuffer
[0],
443 &stfb
->Base
._ColorDrawBufferIndexes
[0]);
444 st_visual_to_default_buffer(stfbi
->visual
, &stfb
->Base
.ColorReadBuffer
,
445 &stfb
->Base
._ColorReadBufferIndex
);
449 /* add the color buffer */
450 idx
= stfb
->Base
._ColorDrawBufferIndexes
[0];
451 if (!st_framebuffer_add_renderbuffer(stfb
, idx
)) {
456 st_framebuffer_add_renderbuffer(stfb
, BUFFER_DEPTH
);
457 st_framebuffer_add_renderbuffer(stfb
, BUFFER_ACCUM
);
459 st_framebuffer_update_attachments(stfb
);
461 stfb
->Base
.Initialized
= GL_TRUE
;
467 * Reference a framebuffer.
470 st_framebuffer_reference(struct st_framebuffer
**ptr
,
471 struct st_framebuffer
*stfb
)
473 struct gl_framebuffer
*fb
= &stfb
->Base
;
474 _mesa_reference_framebuffer((struct gl_framebuffer
**) ptr
, fb
);
478 st_context_notify_invalid_framebuffer(struct st_context_iface
*stctxi
,
479 struct st_framebuffer_iface
*stfbi
)
481 struct st_context
*st
= (struct st_context
*) stctxi
;
482 struct st_framebuffer
*stfb
;
484 /* either draw or read winsys fb */
485 stfb
= st_ws_framebuffer(st
->ctx
->WinSysDrawBuffer
);
486 if (!stfb
|| stfb
->iface
!= stfbi
)
487 stfb
= st_ws_framebuffer(st
->ctx
->WinSysReadBuffer
);
489 if (stfb
&& stfb
->iface
== stfbi
) {
490 p_atomic_set(&stfb
->revalidate
, TRUE
);
493 /* This function is probably getting called when we've detected a
494 * change in a window's size but the currently bound context is
495 * not bound to that window.
496 * If the st_framebuffer_iface structure had a pointer to the
497 * corresponding st_framebuffer we'd be able to handle this.
503 st_context_flush(struct st_context_iface
*stctxi
, unsigned flags
,
504 struct pipe_fence_handle
**fence
)
506 struct st_context
*st
= (struct st_context
*) stctxi
;
507 st_flush(st
, flags
, fence
);
508 if (flags
& PIPE_FLUSH_RENDER_CACHE
)
509 st_manager_flush_frontbuffer(st
);
513 st_context_teximage(struct st_context_iface
*stctxi
, enum st_texture_type target
,
514 int level
, enum pipe_format internal_format
,
515 struct pipe_resource
*tex
, boolean mipmap
)
517 struct st_context
*st
= (struct st_context
*) stctxi
;
518 struct gl_context
*ctx
= st
->ctx
;
519 struct gl_texture_unit
*texUnit
= _mesa_get_current_tex_unit(ctx
);
520 struct gl_texture_object
*texObj
;
521 struct gl_texture_image
*texImage
;
522 struct st_texture_object
*stObj
;
523 struct st_texture_image
*stImage
;
524 GLenum internalFormat
;
525 GLuint width
, height
, depth
;
529 target
= GL_TEXTURE_1D
;
532 target
= GL_TEXTURE_2D
;
535 target
= GL_TEXTURE_3D
;
537 case ST_TEXTURE_RECT
:
538 target
= GL_TEXTURE_RECTANGLE_ARB
;
545 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
546 _mesa_lock_texture(ctx
, texObj
);
548 stObj
= st_texture_object(texObj
);
549 /* switch to surface based */
550 if (!stObj
->surface_based
) {
551 _mesa_clear_texture_object(ctx
, texObj
);
552 stObj
->surface_based
= GL_TRUE
;
555 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
556 stImage
= st_texture_image(texImage
);
561 * XXX When internal_format and tex->format differ, st_finalize_texture
562 * needs to allocate a new texture with internal_format and copy the
563 * texture here into the new one. It will result in surface_copy being
564 * called on surfaces whose formats differ.
566 * To avoid that, internal_format is (wrongly) ignored here. A sane fix
567 * is to use a sampler view.
569 if (!st_sampler_compat_formats(tex
->format
, internal_format
))
570 internal_format
= tex
->format
;
572 if (util_format_get_component_bits(internal_format
,
573 UTIL_FORMAT_COLORSPACE_RGB
, 3) > 0)
574 internalFormat
= GL_RGBA
;
576 internalFormat
= GL_RGB
;
578 texFormat
= st_ChooseTextureFormat(ctx
, internalFormat
,
579 GL_RGBA
, GL_UNSIGNED_BYTE
);
581 _mesa_init_teximage_fields(ctx
, target
, texImage
,
582 tex
->width0
, tex
->height0
, 1, 0,
583 internalFormat
, texFormat
);
586 height
= tex
->height0
;
589 /* grow the image size until we hit level = 0 */
601 _mesa_clear_texture_image(ctx
, texImage
);
602 width
= height
= depth
= 0;
605 pipe_resource_reference(&stImage
->pt
, tex
);
606 stObj
->width0
= width
;
607 stObj
->height0
= height
;
608 stObj
->depth0
= depth
;
610 _mesa_dirty_texobj(ctx
, texObj
, GL_TRUE
);
611 _mesa_unlock_texture(ctx
, texObj
);
617 st_context_copy(struct st_context_iface
*stctxi
,
618 struct st_context_iface
*stsrci
, unsigned mask
)
620 struct st_context
*st
= (struct st_context
*) stctxi
;
621 struct st_context
*src
= (struct st_context
*) stsrci
;
623 _mesa_copy_context(src
->ctx
, st
->ctx
, mask
);
627 st_context_share(struct st_context_iface
*stctxi
,
628 struct st_context_iface
*stsrci
)
630 struct st_context
*st
= (struct st_context
*) stctxi
;
631 struct st_context
*src
= (struct st_context
*) stsrci
;
633 return _mesa_share_state(st
->ctx
, src
->ctx
);
637 st_context_destroy(struct st_context_iface
*stctxi
)
639 struct st_context
*st
= (struct st_context
*) stctxi
;
640 st_destroy_context(st
);
643 static struct st_context_iface
*
644 st_api_create_context(struct st_api
*stapi
, struct st_manager
*smapi
,
645 const struct st_context_attribs
*attribs
,
646 struct st_context_iface
*shared_stctxi
)
648 struct st_context
*shared_ctx
= (struct st_context
*) shared_stctxi
;
649 struct st_context
*st
;
650 struct pipe_context
*pipe
;
651 struct gl_config mode
;
654 if (!(stapi
->profile_mask
& (1 << attribs
->profile
)))
657 switch (attribs
->profile
) {
658 case ST_PROFILE_DEFAULT
:
661 case ST_PROFILE_OPENGL_ES1
:
664 case ST_PROFILE_OPENGL_ES2
:
667 case ST_PROFILE_OPENGL_CORE
:
673 pipe
= smapi
->screen
->context_create(smapi
->screen
, NULL
);
677 st_visual_to_context_mode(&attribs
->visual
, &mode
);
678 st
= st_create_context(api
, pipe
, &mode
, shared_ctx
);
684 /* need to perform version check */
685 if (attribs
->major
> 1 || attribs
->minor
> 0) {
686 _mesa_compute_version(st
->ctx
);
688 if (st
->ctx
->VersionMajor
< attribs
->major
||
689 st
->ctx
->VersionMajor
< attribs
->minor
) {
690 st_destroy_context(st
);
695 st
->invalidate_on_gl_viewport
=
696 smapi
->get_param(smapi
, ST_MANAGER_BROKEN_INVALIDATE
);
698 st
->iface
.destroy
= st_context_destroy
;
699 st
->iface
.notify_invalid_framebuffer
=
700 st_context_notify_invalid_framebuffer
;
701 st
->iface
.flush
= st_context_flush
;
702 st
->iface
.teximage
= st_context_teximage
;
703 st
->iface
.copy
= st_context_copy
;
704 st
->iface
.share
= st_context_share
;
705 st
->iface
.st_context_private
= (void *) smapi
;
711 st_api_make_current(struct st_api
*stapi
, struct st_context_iface
*stctxi
,
712 struct st_framebuffer_iface
*stdrawi
,
713 struct st_framebuffer_iface
*streadi
)
715 struct st_context
*st
= (struct st_context
*) stctxi
;
716 struct st_framebuffer
*stdraw
, *stread
, *stfb
;
719 _glapi_check_multithread();
722 /* reuse/create the draw fb */
723 stfb
= st_ws_framebuffer(st
->ctx
->WinSysDrawBuffer
);
724 if (stfb
&& stfb
->iface
== stdrawi
) {
726 st_framebuffer_reference(&stdraw
, stfb
);
729 stdraw
= st_framebuffer_create(stdrawi
);
732 /* reuse/create the read fb */
733 stfb
= st_ws_framebuffer(st
->ctx
->WinSysReadBuffer
);
734 if (!stfb
|| stfb
->iface
!= streadi
)
736 if (stfb
&& stfb
->iface
== streadi
) {
738 st_framebuffer_reference(&stread
, stfb
);
741 stread
= st_framebuffer_create(streadi
);
744 if (stdraw
&& stread
) {
745 st_framebuffer_validate(stdraw
, st
);
746 if (stread
!= stdraw
)
747 st_framebuffer_validate(stread
, st
);
749 /* modify the draw/read buffers of the context */
751 st_visual_to_default_buffer(stdraw
->iface
->visual
,
752 &st
->ctx
->Color
.DrawBuffer
[0], NULL
);
755 st_visual_to_default_buffer(stread
->iface
->visual
,
756 &st
->ctx
->Pixel
.ReadBuffer
, NULL
);
759 ret
= _mesa_make_current(st
->ctx
, &stdraw
->Base
, &stread
->Base
);
765 st_framebuffer_reference(&stdraw
, NULL
);
766 st_framebuffer_reference(&stread
, NULL
);
769 ret
= _mesa_make_current(NULL
, NULL
, NULL
);
775 static struct st_context_iface
*
776 st_api_get_current(struct st_api
*stapi
)
778 GET_CURRENT_CONTEXT(ctx
);
779 struct st_context
*st
= (ctx
) ? ctx
->st
: NULL
;
781 return (st
) ? &st
->iface
: NULL
;
785 st_api_get_proc_address(struct st_api
*stapi
, const char *procname
)
787 return (st_proc_t
) _glapi_get_proc_address(procname
);
791 st_api_destroy(struct st_api
*stapi
)
796 * Flush the front buffer if the current context renders to the front buffer.
799 st_manager_flush_frontbuffer(struct st_context
*st
)
801 struct st_framebuffer
*stfb
= st_ws_framebuffer(st
->ctx
->DrawBuffer
);
802 struct st_renderbuffer
*strb
= NULL
;
805 strb
= st_renderbuffer(stfb
->Base
.Attachment
[BUFFER_FRONT_LEFT
].Renderbuffer
);
809 /* never a dummy fb */
811 stfb
->iface
->flush_front(stfb
->iface
, ST_ATTACHMENT_FRONT_LEFT
);
815 * Return the surface of an EGLImage.
817 struct pipe_surface
*
818 st_manager_get_egl_image_surface(struct st_context
*st
,
819 void *eglimg
, unsigned usage
)
821 struct st_manager
*smapi
=
822 (struct st_manager
*) st
->iface
.st_context_private
;
823 struct st_egl_image stimg
;
824 struct pipe_surface
*ps
;
826 if (!smapi
|| !smapi
->get_egl_image
)
829 memset(&stimg
, 0, sizeof(stimg
));
830 if (!smapi
->get_egl_image(smapi
, eglimg
, &stimg
))
833 ps
= smapi
->screen
->get_tex_surface(smapi
->screen
,
834 stimg
.texture
, stimg
.face
, stimg
.level
, stimg
.zslice
, usage
);
835 pipe_resource_reference(&stimg
.texture
, NULL
);
841 * Re-validate the framebuffers.
844 st_manager_validate_framebuffers(struct st_context
*st
)
846 struct st_framebuffer
*stdraw
= st_ws_framebuffer(st
->ctx
->DrawBuffer
);
847 struct st_framebuffer
*stread
= st_ws_framebuffer(st
->ctx
->ReadBuffer
);
850 st_framebuffer_validate(stdraw
, st
);
851 if (stread
&& stread
!= stdraw
)
852 st_framebuffer_validate(stread
, st
);
856 * Add a color renderbuffer on demand.
859 st_manager_add_color_renderbuffer(struct st_context
*st
, struct gl_framebuffer
*fb
,
862 struct st_framebuffer
*stfb
= st_ws_framebuffer(fb
);
868 if (stfb
->Base
.Attachment
[idx
].Renderbuffer
)
872 case BUFFER_FRONT_LEFT
:
873 case BUFFER_BACK_LEFT
:
874 case BUFFER_FRONT_RIGHT
:
875 case BUFFER_BACK_RIGHT
:
882 if (!st_framebuffer_add_renderbuffer(stfb
, idx
))
885 st_framebuffer_update_attachments(stfb
);
886 st_invalidate_state(st
->ctx
, _NEW_BUFFERS
);
891 static const struct st_api st_gl_api
= {
892 "Mesa " MESA_VERSION_STRING
,
895 ST_PROFILE_DEFAULT_MASK
|
898 ST_PROFILE_OPENGL_ES1_MASK
|
901 ST_PROFILE_OPENGL_ES2_MASK
|
905 st_api_get_proc_address
,
906 st_api_create_context
,
912 st_gl_api_create(void)
914 return (struct st_api
*) &st_gl_api
;