2 * Mesa 3-D graphics library
4 * Copyright (C) 2010 LunarG Inc.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
25 * Chia-I Wu <olv@lunarg.com>
28 #include "main/mtypes.h"
29 #include "main/context.h"
30 #include "main/texobj.h"
31 #include "main/teximage.h"
32 #include "main/texstate.h"
33 #include "main/errors.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
;
188 /* Check for incomplete framebuffers (e.g. EGL_KHR_surfaceless_context) */
192 new_stamp
= p_atomic_read(&stfb
->iface
->stamp
);
193 if (stfb
->iface_stamp
== new_stamp
)
196 /* validate the fb */
198 if (!stfb
->iface
->validate(&st
->iface
, stfb
->iface
, stfb
->statts
,
199 stfb
->num_statts
, textures
))
202 stfb
->iface_stamp
= new_stamp
;
203 new_stamp
= p_atomic_read(&stfb
->iface
->stamp
);
204 } while(stfb
->iface_stamp
!= new_stamp
);
206 width
= stfb
->Base
.Width
;
207 height
= stfb
->Base
.Height
;
209 for (i
= 0; i
< stfb
->num_statts
; i
++) {
210 struct st_renderbuffer
*strb
;
211 struct pipe_surface
*ps
, surf_tmpl
;
217 idx
= attachment_to_buffer_index(stfb
->statts
[i
]);
218 if (idx
>= BUFFER_COUNT
) {
219 pipe_resource_reference(&textures
[i
], NULL
);
223 strb
= st_renderbuffer(stfb
->Base
.Attachment
[idx
].Renderbuffer
);
225 if (strb
->texture
== textures
[i
]) {
226 pipe_resource_reference(&textures
[i
], NULL
);
230 u_surface_default_template(&surf_tmpl
, textures
[i
]);
231 ps
= st
->pipe
->create_surface(st
->pipe
, textures
[i
], &surf_tmpl
);
233 pipe_surface_reference(&strb
->surface
, ps
);
234 pipe_resource_reference(&strb
->texture
, ps
->texture
);
235 /* ownership transfered */
236 pipe_surface_reference(&ps
, NULL
);
240 strb
->Base
.Width
= strb
->surface
->width
;
241 strb
->Base
.Height
= strb
->surface
->height
;
243 width
= strb
->Base
.Width
;
244 height
= strb
->Base
.Height
;
247 pipe_resource_reference(&textures
[i
], NULL
);
252 _mesa_resize_framebuffer(st
->ctx
, &stfb
->Base
, width
, height
);
257 * Update the attachments to validate by looping the existing renderbuffers.
260 st_framebuffer_update_attachments(struct st_framebuffer
*stfb
)
264 stfb
->num_statts
= 0;
265 for (idx
= 0; idx
< BUFFER_COUNT
; idx
++) {
266 struct st_renderbuffer
*strb
;
267 enum st_attachment_type statt
;
269 strb
= st_renderbuffer(stfb
->Base
.Attachment
[idx
].Renderbuffer
);
270 if (!strb
|| strb
->software
)
273 statt
= buffer_index_to_attachment(idx
);
274 if (statt
!= ST_ATTACHMENT_INVALID
&&
275 st_visual_have_buffers(stfb
->iface
->visual
, 1 << statt
))
276 stfb
->statts
[stfb
->num_statts
++] = statt
;
282 * Add a renderbuffer to the framebuffer.
285 st_framebuffer_add_renderbuffer(struct st_framebuffer
*stfb
,
288 struct gl_renderbuffer
*rb
;
289 enum pipe_format format
;
295 /* do not distinguish depth/stencil buffers */
296 if (idx
== BUFFER_STENCIL
)
301 format
= stfb
->iface
->visual
->depth_stencil_format
;
305 format
= stfb
->iface
->visual
->accum_format
;
309 format
= stfb
->iface
->visual
->color_format
;
310 if (stfb
->Base
.Visual
.sRGBCapable
)
311 format
= util_format_srgb(format
);
316 if (format
== PIPE_FORMAT_NONE
)
319 rb
= st_new_renderbuffer_fb(format
, stfb
->iface
->visual
->samples
, sw
);
323 if (idx
!= BUFFER_DEPTH
) {
324 _mesa_add_renderbuffer(&stfb
->Base
, idx
, rb
);
327 if (util_format_get_component_bits(format
, UTIL_FORMAT_COLORSPACE_ZS
, 0))
328 _mesa_add_renderbuffer(&stfb
->Base
, BUFFER_DEPTH
, rb
);
329 if (util_format_get_component_bits(format
, UTIL_FORMAT_COLORSPACE_ZS
, 1))
330 _mesa_add_renderbuffer(&stfb
->Base
, BUFFER_STENCIL
, rb
);
337 * Intialize a struct gl_config from a visual.
340 st_visual_to_context_mode(const struct st_visual
*visual
,
341 struct gl_config
*mode
)
343 memset(mode
, 0, sizeof(*mode
));
345 if (st_visual_have_buffers(visual
, ST_ATTACHMENT_BACK_LEFT_MASK
))
346 mode
->doubleBufferMode
= GL_TRUE
;
347 if (st_visual_have_buffers(visual
,
348 ST_ATTACHMENT_FRONT_RIGHT_MASK
| ST_ATTACHMENT_BACK_RIGHT_MASK
))
349 mode
->stereoMode
= GL_TRUE
;
351 if (visual
->color_format
!= PIPE_FORMAT_NONE
) {
352 mode
->rgbMode
= GL_TRUE
;
355 util_format_get_component_bits(visual
->color_format
,
356 UTIL_FORMAT_COLORSPACE_RGB
, 0);
358 util_format_get_component_bits(visual
->color_format
,
359 UTIL_FORMAT_COLORSPACE_RGB
, 1);
361 util_format_get_component_bits(visual
->color_format
,
362 UTIL_FORMAT_COLORSPACE_RGB
, 2);
364 util_format_get_component_bits(visual
->color_format
,
365 UTIL_FORMAT_COLORSPACE_RGB
, 3);
367 mode
->rgbBits
= mode
->redBits
+
368 mode
->greenBits
+ mode
->blueBits
+ mode
->alphaBits
;
371 if (visual
->depth_stencil_format
!= PIPE_FORMAT_NONE
) {
373 util_format_get_component_bits(visual
->depth_stencil_format
,
374 UTIL_FORMAT_COLORSPACE_ZS
, 0);
376 util_format_get_component_bits(visual
->depth_stencil_format
,
377 UTIL_FORMAT_COLORSPACE_ZS
, 1);
379 mode
->haveDepthBuffer
= mode
->depthBits
> 0;
380 mode
->haveStencilBuffer
= mode
->stencilBits
> 0;
383 if (visual
->accum_format
!= PIPE_FORMAT_NONE
) {
384 mode
->haveAccumBuffer
= GL_TRUE
;
387 util_format_get_component_bits(visual
->accum_format
,
388 UTIL_FORMAT_COLORSPACE_RGB
, 0);
389 mode
->accumGreenBits
=
390 util_format_get_component_bits(visual
->accum_format
,
391 UTIL_FORMAT_COLORSPACE_RGB
, 1);
392 mode
->accumBlueBits
=
393 util_format_get_component_bits(visual
->accum_format
,
394 UTIL_FORMAT_COLORSPACE_RGB
, 2);
395 mode
->accumAlphaBits
=
396 util_format_get_component_bits(visual
->accum_format
,
397 UTIL_FORMAT_COLORSPACE_RGB
, 3);
400 if (visual
->samples
> 1) {
401 mode
->sampleBuffers
= 1;
402 mode
->samples
= visual
->samples
;
407 * Create a framebuffer from a manager interface.
409 static struct st_framebuffer
*
410 st_framebuffer_create(struct st_context
*st
,
411 struct st_framebuffer_iface
*stfbi
)
413 struct st_framebuffer
*stfb
;
414 struct gl_config mode
;
420 stfb
= CALLOC_STRUCT(st_framebuffer
);
424 st_visual_to_context_mode(stfbi
->visual
, &mode
);
427 * For desktop GL, sRGB framebuffer write is controlled by both the
428 * capability of the framebuffer and GL_FRAMEBUFFER_SRGB. We should
429 * advertise the capability when the pipe driver (and core Mesa) supports
430 * it so that applications can enable sRGB write when they want to.
432 * This is not to be confused with GLX_FRAMEBUFFER_SRGB_CAPABLE_ARB. When
433 * the attribute is GLX_TRUE, it tells the st manager to pick a color
434 * format such that util_format_srgb(visual->color_format) can be supported
435 * by the pipe driver. We still need to advertise the capability here.
437 * For GLES, however, sRGB framebuffer write is controlled only by the
438 * capability of the framebuffer. There is GL_EXT_sRGB_write_control to
439 * give applications the control back, but sRGB write is still enabled by
440 * default. To avoid unexpected results, we should not advertise the
441 * capability. This could change when we add support for
442 * EGL_KHR_gl_colorspace.
444 if (_mesa_is_desktop_gl(st
->ctx
)) {
445 struct pipe_screen
*screen
= st
->pipe
->screen
;
446 const enum pipe_format srgb_format
=
447 util_format_srgb(stfbi
->visual
->color_format
);
449 if (srgb_format
!= PIPE_FORMAT_NONE
&&
450 st_pipe_format_to_mesa_format(srgb_format
) != MESA_FORMAT_NONE
&&
451 screen
->is_format_supported(screen
, srgb_format
,
452 PIPE_TEXTURE_2D
, stfbi
->visual
->samples
,
453 PIPE_BIND_RENDER_TARGET
))
454 mode
.sRGBCapable
= GL_TRUE
;
457 _mesa_initialize_window_framebuffer(&stfb
->Base
, &mode
);
460 stfb
->iface_stamp
= p_atomic_read(&stfbi
->stamp
) - 1;
462 /* add the color buffer */
463 idx
= stfb
->Base
._ColorDrawBufferIndexes
[0];
464 if (!st_framebuffer_add_renderbuffer(stfb
, idx
)) {
469 st_framebuffer_add_renderbuffer(stfb
, BUFFER_DEPTH
);
470 st_framebuffer_add_renderbuffer(stfb
, BUFFER_ACCUM
);
473 st_framebuffer_update_attachments(stfb
);
479 * Reference a framebuffer.
482 st_framebuffer_reference(struct st_framebuffer
**ptr
,
483 struct st_framebuffer
*stfb
)
485 struct gl_framebuffer
*fb
= &stfb
->Base
;
486 _mesa_reference_framebuffer((struct gl_framebuffer
**) ptr
, fb
);
490 st_context_flush(struct st_context_iface
*stctxi
, unsigned flags
,
491 struct pipe_fence_handle
**fence
)
493 struct st_context
*st
= (struct st_context
*) stctxi
;
494 unsigned pipe_flags
= 0;
496 if (flags
& ST_FLUSH_END_OF_FRAME
) {
497 pipe_flags
|= PIPE_FLUSH_END_OF_FRAME
;
500 st_flush(st
, fence
, pipe_flags
);
501 if (flags
& ST_FLUSH_FRONT
)
502 st_manager_flush_frontbuffer(st
);
506 st_context_teximage(struct st_context_iface
*stctxi
,
507 enum st_texture_type tex_type
,
508 int level
, enum pipe_format pipe_format
,
509 struct pipe_resource
*tex
, boolean mipmap
)
511 struct st_context
*st
= (struct st_context
*) stctxi
;
512 struct gl_context
*ctx
= st
->ctx
;
513 struct gl_texture_object
*texObj
;
514 struct gl_texture_image
*texImage
;
515 struct st_texture_object
*stObj
;
516 struct st_texture_image
*stImage
;
517 GLenum internalFormat
;
518 GLuint width
, height
, depth
;
523 target
= GL_TEXTURE_1D
;
526 target
= GL_TEXTURE_2D
;
529 target
= GL_TEXTURE_3D
;
531 case ST_TEXTURE_RECT
:
532 target
= GL_TEXTURE_RECTANGLE_ARB
;
538 texObj
= _mesa_get_current_tex_object(ctx
, target
);
540 _mesa_lock_texture(ctx
, texObj
);
542 stObj
= st_texture_object(texObj
);
543 /* switch to surface based */
544 if (!stObj
->surface_based
) {
545 _mesa_clear_texture_object(ctx
, texObj
);
546 stObj
->surface_based
= GL_TRUE
;
549 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
550 stImage
= st_texture_image(texImage
);
552 mesa_format texFormat
= st_pipe_format_to_mesa_format(pipe_format
);
554 if (util_format_has_alpha(tex
->format
))
555 internalFormat
= GL_RGBA
;
557 internalFormat
= GL_RGB
;
559 _mesa_init_teximage_fields(ctx
, texImage
,
560 tex
->width0
, tex
->height0
, 1, 0,
561 internalFormat
, texFormat
);
564 height
= tex
->height0
;
567 /* grow the image size until we hit level = 0 */
579 _mesa_clear_texture_image(ctx
, texImage
);
580 width
= height
= depth
= 0;
583 pipe_resource_reference(&stImage
->pt
, tex
);
584 stObj
->width0
= width
;
585 stObj
->height0
= height
;
586 stObj
->depth0
= depth
;
587 stObj
->surface_format
= pipe_format
;
589 _mesa_dirty_texobj(ctx
, texObj
);
590 _mesa_unlock_texture(ctx
, texObj
);
596 st_context_copy(struct st_context_iface
*stctxi
,
597 struct st_context_iface
*stsrci
, unsigned mask
)
599 struct st_context
*st
= (struct st_context
*) stctxi
;
600 struct st_context
*src
= (struct st_context
*) stsrci
;
602 _mesa_copy_context(src
->ctx
, st
->ctx
, mask
);
606 st_context_share(struct st_context_iface
*stctxi
,
607 struct st_context_iface
*stsrci
)
609 struct st_context
*st
= (struct st_context
*) stctxi
;
610 struct st_context
*src
= (struct st_context
*) stsrci
;
612 return _mesa_share_state(st
->ctx
, src
->ctx
);
616 st_context_destroy(struct st_context_iface
*stctxi
)
618 struct st_context
*st
= (struct st_context
*) stctxi
;
619 st_destroy_context(st
);
622 static struct st_context_iface
*
623 st_api_create_context(struct st_api
*stapi
, struct st_manager
*smapi
,
624 const struct st_context_attribs
*attribs
,
625 enum st_context_error
*error
,
626 struct st_context_iface
*shared_stctxi
)
628 struct st_context
*shared_ctx
= (struct st_context
*) shared_stctxi
;
629 struct st_context
*st
;
630 struct pipe_context
*pipe
;
631 struct gl_config mode
;
634 if (!(stapi
->profile_mask
& (1 << attribs
->profile
)))
637 switch (attribs
->profile
) {
638 case ST_PROFILE_DEFAULT
:
639 api
= API_OPENGL_COMPAT
;
641 case ST_PROFILE_OPENGL_ES1
:
644 case ST_PROFILE_OPENGL_ES2
:
647 case ST_PROFILE_OPENGL_CORE
:
648 api
= API_OPENGL_CORE
;
651 *error
= ST_CONTEXT_ERROR_BAD_API
;
656 pipe
= smapi
->screen
->context_create(smapi
->screen
, NULL
);
658 *error
= ST_CONTEXT_ERROR_NO_MEMORY
;
662 st_visual_to_context_mode(&attribs
->visual
, &mode
);
663 st
= st_create_context(api
, pipe
, &mode
, shared_ctx
, &attribs
->options
);
665 *error
= ST_CONTEXT_ERROR_NO_MEMORY
;
670 if (attribs
->flags
& ST_CONTEXT_FLAG_DEBUG
){
671 if (!_mesa_set_debug_state_int(st
->ctx
, GL_DEBUG_OUTPUT
, GL_TRUE
)) {
672 *error
= ST_CONTEXT_ERROR_NO_MEMORY
;
675 st
->ctx
->Const
.ContextFlags
|= GL_CONTEXT_FLAG_DEBUG_BIT
;
678 if (attribs
->flags
& ST_CONTEXT_FLAG_FORWARD_COMPATIBLE
)
679 st
->ctx
->Const
.ContextFlags
|= GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT
;
681 /* need to perform version check */
682 if (attribs
->major
> 1 || attribs
->minor
> 0) {
683 /* Is the actual version less than the requested version?
685 if (st
->ctx
->Version
< attribs
->major
* 10 + attribs
->minor
) {
686 *error
= ST_CONTEXT_ERROR_BAD_VERSION
;
687 st_destroy_context(st
);
692 st
->invalidate_on_gl_viewport
=
693 smapi
->get_param(smapi
, ST_MANAGER_BROKEN_INVALIDATE
);
695 st
->iface
.destroy
= st_context_destroy
;
696 st
->iface
.flush
= st_context_flush
;
697 st
->iface
.teximage
= st_context_teximage
;
698 st
->iface
.copy
= st_context_copy
;
699 st
->iface
.share
= st_context_share
;
700 st
->iface
.st_context_private
= (void *) smapi
;
701 st
->iface
.cso_context
= st
->cso_context
;
702 st
->iface
.pipe
= st
->pipe
;
704 *error
= ST_CONTEXT_SUCCESS
;
708 static struct st_context_iface
*
709 st_api_get_current(struct st_api
*stapi
)
711 GET_CURRENT_CONTEXT(ctx
);
712 struct st_context
*st
= (ctx
) ? ctx
->st
: NULL
;
714 return (st
) ? &st
->iface
: NULL
;
717 static struct st_framebuffer
*
718 st_framebuffer_reuse_or_create(struct st_context
*st
,
719 struct gl_framebuffer
*fb
,
720 struct st_framebuffer_iface
*stfbi
)
722 struct st_framebuffer
*cur
= st_ws_framebuffer(fb
), *stfb
= NULL
;
724 /* dummy framebuffers cant be used as st_framebuffer */
725 if (cur
&& &cur
->Base
!= _mesa_get_incomplete_framebuffer() &&
726 cur
->iface
== stfbi
) {
727 /* reuse the current stfb */
728 st_framebuffer_reference(&stfb
, cur
);
731 /* create a new one */
732 stfb
= st_framebuffer_create(st
, stfbi
);
739 st_api_make_current(struct st_api
*stapi
, struct st_context_iface
*stctxi
,
740 struct st_framebuffer_iface
*stdrawi
,
741 struct st_framebuffer_iface
*streadi
)
743 struct st_context
*st
= (struct st_context
*) stctxi
;
744 struct st_framebuffer
*stdraw
, *stread
;
747 _glapi_check_multithread();
750 /* reuse or create the draw fb */
751 stdraw
= st_framebuffer_reuse_or_create(st
,
752 st
->ctx
->WinSysDrawBuffer
, stdrawi
);
753 if (streadi
!= stdrawi
) {
754 /* do the same for the read fb */
755 stread
= st_framebuffer_reuse_or_create(st
,
756 st
->ctx
->WinSysReadBuffer
, streadi
);
760 /* reuse the draw fb for the read fb */
762 st_framebuffer_reference(&stread
, stdraw
);
765 if (stdraw
&& stread
) {
766 st_framebuffer_validate(stdraw
, st
);
767 if (stread
!= stdraw
)
768 st_framebuffer_validate(stread
, st
);
770 ret
= _mesa_make_current(st
->ctx
, &stdraw
->Base
, &stread
->Base
);
772 st
->draw_stamp
= stdraw
->stamp
- 1;
773 st
->read_stamp
= stread
->stamp
- 1;
774 st_context_validate(st
, stdraw
, stread
);
777 struct gl_framebuffer
*incomplete
= _mesa_get_incomplete_framebuffer();
778 ret
= _mesa_make_current(st
->ctx
, incomplete
, incomplete
);
781 st_framebuffer_reference(&stdraw
, NULL
);
782 st_framebuffer_reference(&stread
, NULL
);
785 ret
= _mesa_make_current(NULL
, NULL
, NULL
);
792 st_api_get_proc_address(struct st_api
*stapi
, const char *procname
)
794 return (st_proc_t
) _glapi_get_proc_address(procname
);
798 st_api_destroy(struct st_api
*stapi
)
803 * Flush the front buffer if the current context renders to the front buffer.
806 st_manager_flush_frontbuffer(struct st_context
*st
)
808 struct st_framebuffer
*stfb
= st_ws_framebuffer(st
->ctx
->DrawBuffer
);
809 struct st_renderbuffer
*strb
= NULL
;
812 strb
= st_renderbuffer(stfb
->Base
.Attachment
[BUFFER_FRONT_LEFT
].Renderbuffer
);
816 /* never a dummy fb */
817 assert(&stfb
->Base
!= _mesa_get_incomplete_framebuffer());
818 stfb
->iface
->flush_front(&st
->iface
, stfb
->iface
, ST_ATTACHMENT_FRONT_LEFT
);
822 * Return the surface of an EGLImage.
823 * FIXME: I think this should operate on resources, not surfaces
825 struct pipe_surface
*
826 st_manager_get_egl_image_surface(struct st_context
*st
, void *eglimg
)
828 struct st_manager
*smapi
=
829 (struct st_manager
*) st
->iface
.st_context_private
;
830 struct st_egl_image stimg
;
831 struct pipe_surface
*ps
, surf_tmpl
;
833 if (!smapi
|| !smapi
->get_egl_image
)
836 memset(&stimg
, 0, sizeof(stimg
));
837 if (!smapi
->get_egl_image(smapi
, eglimg
, &stimg
))
840 u_surface_default_template(&surf_tmpl
, stimg
.texture
);
841 surf_tmpl
.u
.tex
.level
= stimg
.level
;
842 surf_tmpl
.u
.tex
.first_layer
= stimg
.layer
;
843 surf_tmpl
.u
.tex
.last_layer
= stimg
.layer
;
844 ps
= st
->pipe
->create_surface(st
->pipe
, stimg
.texture
, &surf_tmpl
);
845 pipe_resource_reference(&stimg
.texture
, NULL
);
851 * Re-validate the framebuffers.
854 st_manager_validate_framebuffers(struct st_context
*st
)
856 struct st_framebuffer
*stdraw
= st_ws_framebuffer(st
->ctx
->DrawBuffer
);
857 struct st_framebuffer
*stread
= st_ws_framebuffer(st
->ctx
->ReadBuffer
);
860 st_framebuffer_validate(stdraw
, st
);
861 if (stread
&& stread
!= stdraw
)
862 st_framebuffer_validate(stread
, st
);
864 st_context_validate(st
, stdraw
, stread
);
868 * Add a color renderbuffer on demand.
871 st_manager_add_color_renderbuffer(struct st_context
*st
,
872 struct gl_framebuffer
*fb
,
875 struct st_framebuffer
*stfb
= st_ws_framebuffer(fb
);
881 if (stfb
->Base
.Attachment
[idx
].Renderbuffer
)
885 case BUFFER_FRONT_LEFT
:
886 case BUFFER_BACK_LEFT
:
887 case BUFFER_FRONT_RIGHT
:
888 case BUFFER_BACK_RIGHT
:
895 if (!st_framebuffer_add_renderbuffer(stfb
, idx
))
898 st_framebuffer_update_attachments(stfb
);
901 * Force a call to the state tracker manager to validate the
902 * new renderbuffer. It might be that there is a window system
903 * renderbuffer available.
906 stfb
->iface_stamp
= p_atomic_read(&stfb
->iface
->stamp
) - 1;
908 st_invalidate_state(st
->ctx
, _NEW_BUFFERS
);
914 st_api_query_versions(struct st_api
*stapi
, struct st_manager
*sm
,
915 int *gl_core_version
,
916 int *gl_compat_version
,
920 *gl_core_version
= 33;
921 *gl_compat_version
= 30;
922 *gl_es1_version
= 11;
923 *gl_es2_version
= 30;
926 static const struct st_api st_gl_api
= {
927 "Mesa " PACKAGE_VERSION
,
929 ST_PROFILE_DEFAULT_MASK
|
930 ST_PROFILE_OPENGL_CORE_MASK
|
931 ST_PROFILE_OPENGL_ES1_MASK
|
932 ST_PROFILE_OPENGL_ES2_MASK
|
934 ST_API_FEATURE_MS_VISUALS_MASK
,
936 st_api_query_versions
,
937 st_api_get_proc_address
,
938 st_api_create_context
,
944 st_gl_api_create(void)
946 return (struct st_api
*) &st_gl_api
;