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
;
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(&st
->iface
, 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
;
305 if (stfb
->Base
.Visual
.sRGBCapable
)
306 format
= util_format_srgb(format
);
311 if (format
== PIPE_FORMAT_NONE
)
314 rb
= st_new_renderbuffer_fb(format
, stfb
->iface
->visual
->samples
, sw
);
318 if (idx
!= BUFFER_DEPTH
) {
319 _mesa_add_renderbuffer(&stfb
->Base
, idx
, rb
);
322 if (util_format_get_component_bits(format
, UTIL_FORMAT_COLORSPACE_ZS
, 0))
323 _mesa_add_renderbuffer(&stfb
->Base
, BUFFER_DEPTH
, rb
);
324 if (util_format_get_component_bits(format
, UTIL_FORMAT_COLORSPACE_ZS
, 1))
325 _mesa_add_renderbuffer(&stfb
->Base
, BUFFER_STENCIL
, rb
);
332 * Intialize a struct gl_config from a visual.
335 st_visual_to_context_mode(const struct st_visual
*visual
,
336 struct gl_config
*mode
)
338 memset(mode
, 0, sizeof(*mode
));
340 if (st_visual_have_buffers(visual
, ST_ATTACHMENT_BACK_LEFT_MASK
))
341 mode
->doubleBufferMode
= GL_TRUE
;
342 if (st_visual_have_buffers(visual
,
343 ST_ATTACHMENT_FRONT_RIGHT_MASK
| ST_ATTACHMENT_BACK_RIGHT_MASK
))
344 mode
->stereoMode
= GL_TRUE
;
346 if (visual
->color_format
!= PIPE_FORMAT_NONE
) {
347 mode
->rgbMode
= GL_TRUE
;
350 util_format_get_component_bits(visual
->color_format
,
351 UTIL_FORMAT_COLORSPACE_RGB
, 0);
353 util_format_get_component_bits(visual
->color_format
,
354 UTIL_FORMAT_COLORSPACE_RGB
, 1);
356 util_format_get_component_bits(visual
->color_format
,
357 UTIL_FORMAT_COLORSPACE_RGB
, 2);
359 util_format_get_component_bits(visual
->color_format
,
360 UTIL_FORMAT_COLORSPACE_RGB
, 3);
362 mode
->rgbBits
= mode
->redBits
+
363 mode
->greenBits
+ mode
->blueBits
+ mode
->alphaBits
;
366 if (visual
->depth_stencil_format
!= PIPE_FORMAT_NONE
) {
368 util_format_get_component_bits(visual
->depth_stencil_format
,
369 UTIL_FORMAT_COLORSPACE_ZS
, 0);
371 util_format_get_component_bits(visual
->depth_stencil_format
,
372 UTIL_FORMAT_COLORSPACE_ZS
, 1);
374 mode
->haveDepthBuffer
= mode
->depthBits
> 0;
375 mode
->haveStencilBuffer
= mode
->stencilBits
> 0;
378 if (visual
->accum_format
!= PIPE_FORMAT_NONE
) {
379 mode
->haveAccumBuffer
= GL_TRUE
;
382 util_format_get_component_bits(visual
->accum_format
,
383 UTIL_FORMAT_COLORSPACE_RGB
, 0);
384 mode
->accumGreenBits
=
385 util_format_get_component_bits(visual
->accum_format
,
386 UTIL_FORMAT_COLORSPACE_RGB
, 1);
387 mode
->accumBlueBits
=
388 util_format_get_component_bits(visual
->accum_format
,
389 UTIL_FORMAT_COLORSPACE_RGB
, 2);
390 mode
->accumAlphaBits
=
391 util_format_get_component_bits(visual
->accum_format
,
392 UTIL_FORMAT_COLORSPACE_RGB
, 3);
395 if (visual
->samples
> 1) {
396 mode
->sampleBuffers
= 1;
397 mode
->samples
= visual
->samples
;
402 * Create a framebuffer from a manager interface.
404 static struct st_framebuffer
*
405 st_framebuffer_create(struct st_context
*st
,
406 struct st_framebuffer_iface
*stfbi
)
408 struct st_framebuffer
*stfb
;
409 struct gl_config mode
;
415 stfb
= CALLOC_STRUCT(st_framebuffer
);
419 st_visual_to_context_mode(stfbi
->visual
, &mode
);
422 * For desktop GL, sRGB framebuffer write is controlled by both the
423 * capability of the framebuffer and GL_FRAMEBUFFER_SRGB. We should
424 * advertise the capability when the pipe driver (and core Mesa) supports
425 * it so that applications can enable sRGB write when they want to.
427 * This is not to be confused with GLX_FRAMEBUFFER_SRGB_CAPABLE_ARB. When
428 * the attribute is GLX_TRUE, it tells the st manager to pick a color
429 * format such that util_format_srgb(visual->color_format) can be supported
430 * by the pipe driver. We still need to advertise the capability here.
432 * For GLES, however, sRGB framebuffer write is controlled only by the
433 * capability of the framebuffer. There is GL_EXT_sRGB_write_control to
434 * give applications the control back, but sRGB write is still enabled by
435 * default. To avoid unexpected results, we should not advertise the
436 * capability. This could change when we add support for
437 * EGL_KHR_gl_colorspace.
439 if (_mesa_is_desktop_gl(st
->ctx
)) {
440 struct pipe_screen
*screen
= st
->pipe
->screen
;
441 const enum pipe_format srgb_format
=
442 util_format_srgb(stfbi
->visual
->color_format
);
444 if (srgb_format
!= PIPE_FORMAT_NONE
&&
445 st_pipe_format_to_mesa_format(srgb_format
) != MESA_FORMAT_NONE
&&
446 screen
->is_format_supported(screen
, srgb_format
,
447 PIPE_TEXTURE_2D
, stfbi
->visual
->samples
,
448 PIPE_BIND_RENDER_TARGET
))
449 mode
.sRGBCapable
= GL_TRUE
;
452 _mesa_initialize_window_framebuffer(&stfb
->Base
, &mode
);
455 stfb
->iface_stamp
= p_atomic_read(&stfbi
->stamp
) - 1;
457 /* add the color buffer */
458 idx
= stfb
->Base
._ColorDrawBufferIndexes
[0];
459 if (!st_framebuffer_add_renderbuffer(stfb
, idx
)) {
464 st_framebuffer_add_renderbuffer(stfb
, BUFFER_DEPTH
);
465 st_framebuffer_add_renderbuffer(stfb
, BUFFER_ACCUM
);
468 st_framebuffer_update_attachments(stfb
);
474 * Reference a framebuffer.
477 st_framebuffer_reference(struct st_framebuffer
**ptr
,
478 struct st_framebuffer
*stfb
)
480 struct gl_framebuffer
*fb
= &stfb
->Base
;
481 _mesa_reference_framebuffer((struct gl_framebuffer
**) ptr
, fb
);
485 st_context_flush(struct st_context_iface
*stctxi
, unsigned flags
,
486 struct pipe_fence_handle
**fence
)
488 struct st_context
*st
= (struct st_context
*) stctxi
;
489 unsigned pipe_flags
= 0;
491 if (flags
& ST_FLUSH_END_OF_FRAME
) {
492 pipe_flags
|= PIPE_FLUSH_END_OF_FRAME
;
495 st_flush(st
, fence
, pipe_flags
);
496 if (flags
& ST_FLUSH_FRONT
)
497 st_manager_flush_frontbuffer(st
);
501 st_context_teximage(struct st_context_iface
*stctxi
,
502 enum st_texture_type tex_type
,
503 int level
, enum pipe_format pipe_format
,
504 struct pipe_resource
*tex
, boolean mipmap
)
506 struct st_context
*st
= (struct st_context
*) stctxi
;
507 struct gl_context
*ctx
= st
->ctx
;
508 struct gl_texture_object
*texObj
;
509 struct gl_texture_image
*texImage
;
510 struct st_texture_object
*stObj
;
511 struct st_texture_image
*stImage
;
512 GLenum internalFormat
;
513 GLuint width
, height
, depth
;
518 target
= GL_TEXTURE_1D
;
521 target
= GL_TEXTURE_2D
;
524 target
= GL_TEXTURE_3D
;
526 case ST_TEXTURE_RECT
:
527 target
= GL_TEXTURE_RECTANGLE_ARB
;
533 texObj
= _mesa_get_current_tex_object(ctx
, target
);
535 _mesa_lock_texture(ctx
, texObj
);
537 stObj
= st_texture_object(texObj
);
538 /* switch to surface based */
539 if (!stObj
->surface_based
) {
540 _mesa_clear_texture_object(ctx
, texObj
);
541 stObj
->surface_based
= GL_TRUE
;
544 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
545 stImage
= st_texture_image(texImage
);
547 mesa_format texFormat
= st_pipe_format_to_mesa_format(pipe_format
);
549 if (util_format_has_alpha(tex
->format
))
550 internalFormat
= GL_RGBA
;
552 internalFormat
= GL_RGB
;
554 _mesa_init_teximage_fields(ctx
, texImage
,
555 tex
->width0
, tex
->height0
, 1, 0,
556 internalFormat
, texFormat
);
559 height
= tex
->height0
;
562 /* grow the image size until we hit level = 0 */
574 _mesa_clear_texture_image(ctx
, texImage
);
575 width
= height
= depth
= 0;
578 pipe_resource_reference(&stImage
->pt
, tex
);
579 stObj
->width0
= width
;
580 stObj
->height0
= height
;
581 stObj
->depth0
= depth
;
582 stObj
->surface_format
= pipe_format
;
584 _mesa_dirty_texobj(ctx
, texObj
);
585 _mesa_unlock_texture(ctx
, texObj
);
591 st_context_copy(struct st_context_iface
*stctxi
,
592 struct st_context_iface
*stsrci
, unsigned mask
)
594 struct st_context
*st
= (struct st_context
*) stctxi
;
595 struct st_context
*src
= (struct st_context
*) stsrci
;
597 _mesa_copy_context(src
->ctx
, st
->ctx
, mask
);
601 st_context_share(struct st_context_iface
*stctxi
,
602 struct st_context_iface
*stsrci
)
604 struct st_context
*st
= (struct st_context
*) stctxi
;
605 struct st_context
*src
= (struct st_context
*) stsrci
;
607 return _mesa_share_state(st
->ctx
, src
->ctx
);
611 st_context_destroy(struct st_context_iface
*stctxi
)
613 struct st_context
*st
= (struct st_context
*) stctxi
;
614 st_destroy_context(st
);
617 static struct st_context_iface
*
618 st_api_create_context(struct st_api
*stapi
, struct st_manager
*smapi
,
619 const struct st_context_attribs
*attribs
,
620 enum st_context_error
*error
,
621 struct st_context_iface
*shared_stctxi
)
623 struct st_context
*shared_ctx
= (struct st_context
*) shared_stctxi
;
624 struct st_context
*st
;
625 struct pipe_context
*pipe
;
626 struct gl_config mode
;
629 if (!(stapi
->profile_mask
& (1 << attribs
->profile
)))
632 switch (attribs
->profile
) {
633 case ST_PROFILE_DEFAULT
:
634 api
= API_OPENGL_COMPAT
;
636 case ST_PROFILE_OPENGL_ES1
:
639 case ST_PROFILE_OPENGL_ES2
:
642 case ST_PROFILE_OPENGL_CORE
:
643 api
= API_OPENGL_CORE
;
646 *error
= ST_CONTEXT_ERROR_BAD_API
;
651 pipe
= smapi
->screen
->context_create(smapi
->screen
, NULL
);
653 *error
= ST_CONTEXT_ERROR_NO_MEMORY
;
657 st_visual_to_context_mode(&attribs
->visual
, &mode
);
658 st
= st_create_context(api
, pipe
, &mode
, shared_ctx
, &attribs
->options
);
660 *error
= ST_CONTEXT_ERROR_NO_MEMORY
;
665 if (attribs
->flags
& ST_CONTEXT_FLAG_DEBUG
){
666 if (!_mesa_set_debug_state_int(st
->ctx
, GL_DEBUG_OUTPUT
, GL_TRUE
)) {
667 *error
= ST_CONTEXT_ERROR_NO_MEMORY
;
670 st
->ctx
->Const
.ContextFlags
|= GL_CONTEXT_FLAG_DEBUG_BIT
;
673 if (attribs
->flags
& ST_CONTEXT_FLAG_FORWARD_COMPATIBLE
)
674 st
->ctx
->Const
.ContextFlags
|= GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT
;
676 /* need to perform version check */
677 if (attribs
->major
> 1 || attribs
->minor
> 0) {
678 /* Is the actual version less than the requested version?
680 if (st
->ctx
->Version
< attribs
->major
* 10 + attribs
->minor
) {
681 *error
= ST_CONTEXT_ERROR_BAD_VERSION
;
682 st_destroy_context(st
);
687 st
->invalidate_on_gl_viewport
=
688 smapi
->get_param(smapi
, ST_MANAGER_BROKEN_INVALIDATE
);
690 st
->iface
.destroy
= st_context_destroy
;
691 st
->iface
.flush
= st_context_flush
;
692 st
->iface
.teximage
= st_context_teximage
;
693 st
->iface
.copy
= st_context_copy
;
694 st
->iface
.share
= st_context_share
;
695 st
->iface
.st_context_private
= (void *) smapi
;
696 st
->iface
.cso_context
= st
->cso_context
;
697 st
->iface
.pipe
= st
->pipe
;
699 *error
= ST_CONTEXT_SUCCESS
;
703 static struct st_context_iface
*
704 st_api_get_current(struct st_api
*stapi
)
706 GET_CURRENT_CONTEXT(ctx
);
707 struct st_context
*st
= (ctx
) ? ctx
->st
: NULL
;
709 return (st
) ? &st
->iface
: NULL
;
712 static struct st_framebuffer
*
713 st_framebuffer_reuse_or_create(struct st_context
*st
,
714 struct gl_framebuffer
*fb
,
715 struct st_framebuffer_iface
*stfbi
)
717 struct st_framebuffer
*cur
= st_ws_framebuffer(fb
), *stfb
= NULL
;
719 /* dummy framebuffers cant be used as st_framebuffer */
720 if (cur
&& &cur
->Base
!= _mesa_get_incomplete_framebuffer() &&
721 cur
->iface
== stfbi
) {
722 /* reuse the current stfb */
723 st_framebuffer_reference(&stfb
, cur
);
726 /* create a new one */
727 stfb
= st_framebuffer_create(st
, stfbi
);
734 st_api_make_current(struct st_api
*stapi
, struct st_context_iface
*stctxi
,
735 struct st_framebuffer_iface
*stdrawi
,
736 struct st_framebuffer_iface
*streadi
)
738 struct st_context
*st
= (struct st_context
*) stctxi
;
739 struct st_framebuffer
*stdraw
, *stread
;
742 _glapi_check_multithread();
745 /* reuse or create the draw fb */
746 stdraw
= st_framebuffer_reuse_or_create(st
,
747 st
->ctx
->WinSysDrawBuffer
, stdrawi
);
748 if (streadi
!= stdrawi
) {
749 /* do the same for the read fb */
750 stread
= st_framebuffer_reuse_or_create(st
,
751 st
->ctx
->WinSysReadBuffer
, streadi
);
755 /* reuse the draw fb for the read fb */
757 st_framebuffer_reference(&stread
, stdraw
);
760 if (stdraw
&& stread
) {
761 st_framebuffer_validate(stdraw
, st
);
762 if (stread
!= stdraw
)
763 st_framebuffer_validate(stread
, st
);
765 ret
= _mesa_make_current(st
->ctx
, &stdraw
->Base
, &stread
->Base
);
767 st
->draw_stamp
= stdraw
->stamp
- 1;
768 st
->read_stamp
= stread
->stamp
- 1;
769 st_context_validate(st
, stdraw
, stread
);
772 struct gl_framebuffer
*incomplete
= _mesa_get_incomplete_framebuffer();
773 ret
= _mesa_make_current(st
->ctx
, incomplete
, incomplete
);
776 st_framebuffer_reference(&stdraw
, NULL
);
777 st_framebuffer_reference(&stread
, NULL
);
780 ret
= _mesa_make_current(NULL
, NULL
, NULL
);
787 st_api_get_proc_address(struct st_api
*stapi
, const char *procname
)
789 return (st_proc_t
) _glapi_get_proc_address(procname
);
793 st_api_destroy(struct st_api
*stapi
)
798 * Flush the front buffer if the current context renders to the front buffer.
801 st_manager_flush_frontbuffer(struct st_context
*st
)
803 struct st_framebuffer
*stfb
= st_ws_framebuffer(st
->ctx
->DrawBuffer
);
804 struct st_renderbuffer
*strb
= NULL
;
807 strb
= st_renderbuffer(stfb
->Base
.Attachment
[BUFFER_FRONT_LEFT
].Renderbuffer
);
811 /* never a dummy fb */
812 assert(&stfb
->Base
!= _mesa_get_incomplete_framebuffer());
813 stfb
->iface
->flush_front(&st
->iface
, stfb
->iface
, ST_ATTACHMENT_FRONT_LEFT
);
817 * Return the surface of an EGLImage.
818 * FIXME: I think this should operate on resources, not surfaces
820 struct pipe_surface
*
821 st_manager_get_egl_image_surface(struct st_context
*st
, void *eglimg
)
823 struct st_manager
*smapi
=
824 (struct st_manager
*) st
->iface
.st_context_private
;
825 struct st_egl_image stimg
;
826 struct pipe_surface
*ps
, surf_tmpl
;
828 if (!smapi
|| !smapi
->get_egl_image
)
831 memset(&stimg
, 0, sizeof(stimg
));
832 if (!smapi
->get_egl_image(smapi
, eglimg
, &stimg
))
835 u_surface_default_template(&surf_tmpl
, stimg
.texture
);
836 surf_tmpl
.u
.tex
.level
= stimg
.level
;
837 surf_tmpl
.u
.tex
.first_layer
= stimg
.layer
;
838 surf_tmpl
.u
.tex
.last_layer
= stimg
.layer
;
839 ps
= st
->pipe
->create_surface(st
->pipe
, stimg
.texture
, &surf_tmpl
);
840 pipe_resource_reference(&stimg
.texture
, NULL
);
846 * Re-validate the framebuffers.
849 st_manager_validate_framebuffers(struct st_context
*st
)
851 struct st_framebuffer
*stdraw
= st_ws_framebuffer(st
->ctx
->DrawBuffer
);
852 struct st_framebuffer
*stread
= st_ws_framebuffer(st
->ctx
->ReadBuffer
);
855 st_framebuffer_validate(stdraw
, st
);
856 if (stread
&& stread
!= stdraw
)
857 st_framebuffer_validate(stread
, st
);
859 st_context_validate(st
, stdraw
, stread
);
863 * Add a color renderbuffer on demand.
866 st_manager_add_color_renderbuffer(struct st_context
*st
,
867 struct gl_framebuffer
*fb
,
870 struct st_framebuffer
*stfb
= st_ws_framebuffer(fb
);
876 if (stfb
->Base
.Attachment
[idx
].Renderbuffer
)
880 case BUFFER_FRONT_LEFT
:
881 case BUFFER_BACK_LEFT
:
882 case BUFFER_FRONT_RIGHT
:
883 case BUFFER_BACK_RIGHT
:
890 if (!st_framebuffer_add_renderbuffer(stfb
, idx
))
893 st_framebuffer_update_attachments(stfb
);
896 * Force a call to the state tracker manager to validate the
897 * new renderbuffer. It might be that there is a window system
898 * renderbuffer available.
901 stfb
->iface_stamp
= p_atomic_read(&stfb
->iface
->stamp
) - 1;
903 st_invalidate_state(st
->ctx
, _NEW_BUFFERS
);
908 static const struct st_api st_gl_api
= {
909 "Mesa " PACKAGE_VERSION
,
911 ST_PROFILE_DEFAULT_MASK
|
912 ST_PROFILE_OPENGL_CORE_MASK
|
913 ST_PROFILE_OPENGL_ES1_MASK
|
914 ST_PROFILE_OPENGL_ES2_MASK
|
916 ST_API_FEATURE_MS_VISUALS_MASK
,
918 st_api_get_proc_address
,
919 st_api_create_context
,
925 st_gl_api_create(void)
927 return (struct st_api
*) &st_gl_api
;