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/texfetch.h"
44 #include "main/framebuffer.h"
45 #include "main/fbobject.h"
46 #include "main/renderbuffer.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 GLframebuffer to an st_framebuffer.
57 * Return NULL if the GLframebuffer 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(GLframebuffer
*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 __GLcontextModes from a visual.
301 st_visual_to_context_mode(const struct st_visual
*visual
,
302 __GLcontextModes
*mode
)
304 memset(mode
, 0, sizeof(*mode
));
306 /* FBO-only context */
310 if (st_visual_have_buffers(visual
, ST_ATTACHMENT_BACK_LEFT_MASK
))
311 mode
->doubleBufferMode
= GL_TRUE
;
312 if (st_visual_have_buffers(visual
,
313 ST_ATTACHMENT_FRONT_RIGHT_MASK
| ST_ATTACHMENT_BACK_RIGHT_MASK
))
314 mode
->stereoMode
= GL_TRUE
;
316 if (visual
->color_format
!= PIPE_FORMAT_NONE
) {
317 mode
->rgbMode
= GL_TRUE
;
320 util_format_get_component_bits(visual
->color_format
,
321 UTIL_FORMAT_COLORSPACE_RGB
, 0);
323 util_format_get_component_bits(visual
->color_format
,
324 UTIL_FORMAT_COLORSPACE_RGB
, 1);
326 util_format_get_component_bits(visual
->color_format
,
327 UTIL_FORMAT_COLORSPACE_RGB
, 2);
329 util_format_get_component_bits(visual
->color_format
,
330 UTIL_FORMAT_COLORSPACE_RGB
, 3);
332 mode
->rgbBits
= mode
->redBits
+
333 mode
->greenBits
+ mode
->blueBits
+ mode
->alphaBits
;
336 if (visual
->depth_stencil_format
!= PIPE_FORMAT_NONE
) {
338 util_format_get_component_bits(visual
->depth_stencil_format
,
339 UTIL_FORMAT_COLORSPACE_ZS
, 0);
341 util_format_get_component_bits(visual
->depth_stencil_format
,
342 UTIL_FORMAT_COLORSPACE_ZS
, 1);
344 mode
->haveDepthBuffer
= mode
->depthBits
> 0;
345 mode
->haveStencilBuffer
= mode
->stencilBits
> 0;
348 if (visual
->accum_format
!= PIPE_FORMAT_NONE
) {
349 mode
->haveAccumBuffer
= GL_TRUE
;
352 util_format_get_component_bits(visual
->accum_format
,
353 UTIL_FORMAT_COLORSPACE_RGB
, 0);
354 mode
->accumGreenBits
=
355 util_format_get_component_bits(visual
->accum_format
,
356 UTIL_FORMAT_COLORSPACE_RGB
, 1);
357 mode
->accumBlueBits
=
358 util_format_get_component_bits(visual
->accum_format
,
359 UTIL_FORMAT_COLORSPACE_RGB
, 2);
360 mode
->accumAlphaBits
=
361 util_format_get_component_bits(visual
->accum_format
,
362 UTIL_FORMAT_COLORSPACE_RGB
, 3);
365 if (visual
->samples
) {
366 mode
->sampleBuffers
= 1;
367 mode
->samples
= visual
->samples
;
372 * Determine the default draw or read buffer from a visual.
375 st_visual_to_default_buffer(const struct st_visual
*visual
,
376 GLenum
*buffer
, GLint
*index
)
378 enum st_attachment_type statt
;
382 statt
= visual
->render_buffer
;
383 /* do nothing if an invalid render buffer is specified */
384 if (statt
== ST_ATTACHMENT_INVALID
||
385 !st_visual_have_buffers(visual
, 1 << statt
))
389 case ST_ATTACHMENT_FRONT_LEFT
:
391 idx
= BUFFER_FRONT_LEFT
;
393 case ST_ATTACHMENT_BACK_LEFT
:
395 idx
= BUFFER_BACK_LEFT
;
397 case ST_ATTACHMENT_FRONT_RIGHT
:
398 buf
= GL_FRONT_RIGHT
;
399 idx
= BUFFER_FRONT_RIGHT
;
401 case ST_ATTACHMENT_BACK_RIGHT
:
403 idx
= BUFFER_BACK_RIGHT
;
411 if (buf
!= GL_NONE
) {
420 * Create a framebuffer from a manager interface.
422 static struct st_framebuffer
*
423 st_framebuffer_create(struct st_framebuffer_iface
*stfbi
)
425 struct st_framebuffer
*stfb
;
426 __GLcontextModes mode
;
429 stfb
= CALLOC_STRUCT(st_framebuffer
);
433 /* for FBO-only context */
435 GLframebuffer
*base
= _mesa_get_incomplete_framebuffer();
442 st_visual_to_context_mode(stfbi
->visual
, &mode
);
443 _mesa_initialize_window_framebuffer(&stfb
->Base
, &mode
);
445 /* modify the draw/read buffers of the fb */
446 st_visual_to_default_buffer(stfbi
->visual
, &stfb
->Base
.ColorDrawBuffer
[0],
447 &stfb
->Base
._ColorDrawBufferIndexes
[0]);
448 st_visual_to_default_buffer(stfbi
->visual
, &stfb
->Base
.ColorReadBuffer
,
449 &stfb
->Base
._ColorReadBufferIndex
);
453 /* add the color buffer */
454 idx
= stfb
->Base
._ColorDrawBufferIndexes
[0];
455 if (!st_framebuffer_add_renderbuffer(stfb
, idx
)) {
460 st_framebuffer_add_renderbuffer(stfb
, BUFFER_DEPTH
);
461 st_framebuffer_add_renderbuffer(stfb
, BUFFER_ACCUM
);
463 st_framebuffer_update_attachments(stfb
);
465 stfb
->Base
.Initialized
= GL_TRUE
;
471 * Reference a framebuffer.
474 st_framebuffer_reference(struct st_framebuffer
**ptr
,
475 struct st_framebuffer
*stfb
)
477 GLframebuffer
*fb
= &stfb
->Base
;
478 _mesa_reference_framebuffer((GLframebuffer
**) ptr
, fb
);
482 st_context_notify_invalid_framebuffer(struct st_context_iface
*stctxi
,
483 struct st_framebuffer_iface
*stfbi
)
485 struct st_context
*st
= (struct st_context
*) stctxi
;
486 struct st_framebuffer
*stfb
;
488 /* either draw or read winsys fb */
489 stfb
= st_ws_framebuffer(st
->ctx
->WinSysDrawBuffer
);
490 if (!stfb
|| stfb
->iface
!= stfbi
)
491 stfb
= st_ws_framebuffer(st
->ctx
->WinSysReadBuffer
);
492 assert(stfb
&& stfb
->iface
== stfbi
);
494 p_atomic_set(&stfb
->revalidate
, TRUE
);
498 st_context_flush(struct st_context_iface
*stctxi
, unsigned flags
,
499 struct pipe_fence_handle
**fence
)
501 struct st_context
*st
= (struct st_context
*) stctxi
;
502 st_flush(st
, flags
, fence
);
503 if (flags
& PIPE_FLUSH_RENDER_CACHE
)
504 st_manager_flush_frontbuffer(st
);
508 st_context_teximage(struct st_context_iface
*stctxi
, enum st_texture_type target
,
509 int level
, enum pipe_format internal_format
,
510 struct pipe_resource
*tex
, boolean mipmap
)
512 struct st_context
*st
= (struct st_context
*) stctxi
;
513 GLcontext
*ctx
= st
->ctx
;
514 struct gl_texture_unit
*texUnit
= _mesa_get_current_tex_unit(ctx
);
515 struct gl_texture_object
*texObj
;
516 struct gl_texture_image
*texImage
;
517 struct st_texture_object
*stObj
;
518 struct st_texture_image
*stImage
;
519 GLenum internalFormat
;
520 GLuint width
, height
, depth
;
524 target
= GL_TEXTURE_1D
;
527 target
= GL_TEXTURE_2D
;
530 target
= GL_TEXTURE_3D
;
532 case ST_TEXTURE_RECT
:
533 target
= GL_TEXTURE_RECTANGLE_ARB
;
540 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
541 _mesa_lock_texture(ctx
, texObj
);
543 stObj
= st_texture_object(texObj
);
544 /* switch to surface based */
545 if (!stObj
->surface_based
) {
546 _mesa_clear_texture_object(ctx
, texObj
);
547 stObj
->surface_based
= GL_TRUE
;
550 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
551 stImage
= st_texture_image(texImage
);
554 * XXX When internal_format and tex->format differ, st_finalize_texture
555 * needs to allocate a new texture with internal_format and copy the
556 * texture here into the new one. It will result in surface_copy being
557 * called on surfaces whose formats differ.
559 * To avoid that, internal_format is (wrongly) ignored here. A sane fix
560 * is to use a sampler view.
562 if (!st_sampler_compat_formats(tex
->format
, internal_format
))
563 internal_format
= tex
->format
;
565 if (util_format_get_component_bits(internal_format
,
566 UTIL_FORMAT_COLORSPACE_RGB
, 3) > 0)
567 internalFormat
= GL_RGBA
;
569 internalFormat
= GL_RGB
;
570 _mesa_init_teximage_fields(ctx
, target
, texImage
,
571 tex
->width0
, tex
->height0
, 1, 0, internalFormat
);
572 texImage
->TexFormat
= st_ChooseTextureFormat(ctx
, internalFormat
,
573 GL_RGBA
, GL_UNSIGNED_BYTE
);
574 _mesa_set_fetch_functions(texImage
, 2);
577 height
= tex
->height0
;
580 /* grow the image size until we hit level = 0 */
592 _mesa_clear_texture_image(ctx
, texImage
);
593 width
= height
= depth
= 0;
596 pipe_resource_reference(&stImage
->pt
, tex
);
597 stObj
->width0
= width
;
598 stObj
->height0
= height
;
599 stObj
->depth0
= depth
;
601 _mesa_dirty_texobj(ctx
, texObj
, GL_TRUE
);
602 _mesa_unlock_texture(ctx
, texObj
);
608 st_context_destroy(struct st_context_iface
*stctxi
)
610 struct st_context
*st
= (struct st_context
*) stctxi
;
611 st_destroy_context(st
);
614 static struct st_context_iface
*
615 create_context(gl_api api
, struct st_manager
*smapi
,
616 const struct st_visual
*visual
,
617 struct st_context_iface
*shared_stctxi
)
619 struct st_context
*shared_ctx
= (struct st_context
*) shared_stctxi
;
620 struct st_context
*st
;
621 struct pipe_context
*pipe
;
622 __GLcontextModes mode
;
624 pipe
= smapi
->screen
->context_create(smapi
->screen
, NULL
);
628 st_visual_to_context_mode(visual
, &mode
);
629 st
= st_create_context(api
, pipe
, &mode
, shared_ctx
);
635 st
->invalidate_on_gl_viewport
=
636 smapi
->get_param(smapi
, ST_MANAGER_BROKEN_INVALIDATE
);
638 st
->iface
.destroy
= st_context_destroy
;
639 st
->iface
.notify_invalid_framebuffer
=
640 st_context_notify_invalid_framebuffer
;
641 st
->iface
.flush
= st_context_flush
;
642 st
->iface
.teximage
= st_context_teximage
;
643 st
->iface
.copy
= NULL
;
644 st
->iface
.st_context_private
= (void *) smapi
;
649 static struct st_context_iface
*
650 st_api_create_context(struct st_api
*stapi
, struct st_manager
*smapi
,
651 const struct st_visual
*visual
,
652 struct st_context_iface
*shared_stctxi
)
654 return create_context(API_OPENGL
, smapi
, visual
, shared_stctxi
);
657 static struct st_context_iface
*
658 st_api_create_context_es1(struct st_api
*stapi
, struct st_manager
*smapi
,
659 const struct st_visual
*visual
,
660 struct st_context_iface
*shared_stctxi
)
662 return create_context(API_OPENGLES
, smapi
, visual
, shared_stctxi
);
665 static struct st_context_iface
*
666 st_api_create_context_es2(struct st_api
*stapi
, struct st_manager
*smapi
,
667 const struct st_visual
*visual
,
668 struct st_context_iface
*shared_stctxi
)
670 return create_context(API_OPENGLES2
, smapi
, visual
, shared_stctxi
);
674 st_api_make_current(struct st_api
*stapi
, struct st_context_iface
*stctxi
,
675 struct st_framebuffer_iface
*stdrawi
,
676 struct st_framebuffer_iface
*streadi
)
678 struct st_context
*st
= (struct st_context
*) stctxi
;
679 struct st_framebuffer
*stdraw
, *stread
, *stfb
;
682 _glapi_check_multithread();
685 /* reuse/create the draw fb */
686 stfb
= st_ws_framebuffer(st
->ctx
->WinSysDrawBuffer
);
687 if (stfb
&& stfb
->iface
== stdrawi
) {
689 st_framebuffer_reference(&stdraw
, stfb
);
692 stdraw
= st_framebuffer_create(stdrawi
);
695 /* reuse/create the read fb */
696 stfb
= st_ws_framebuffer(st
->ctx
->WinSysReadBuffer
);
697 if (!stfb
|| stfb
->iface
!= streadi
)
699 if (stfb
&& stfb
->iface
== streadi
) {
701 st_framebuffer_reference(&stread
, stfb
);
704 stread
= st_framebuffer_create(streadi
);
707 if (stdraw
&& stread
) {
708 st_framebuffer_validate(stdraw
, st
);
709 if (stread
!= stdraw
)
710 st_framebuffer_validate(stread
, st
);
712 /* modify the draw/read buffers of the context */
714 st_visual_to_default_buffer(stdraw
->iface
->visual
,
715 &st
->ctx
->Color
.DrawBuffer
[0], NULL
);
718 st_visual_to_default_buffer(stread
->iface
->visual
,
719 &st
->ctx
->Pixel
.ReadBuffer
, NULL
);
722 ret
= _mesa_make_current(st
->ctx
, &stdraw
->Base
, &stread
->Base
);
728 st_framebuffer_reference(&stdraw
, NULL
);
729 st_framebuffer_reference(&stread
, NULL
);
732 ret
= _mesa_make_current(NULL
, NULL
, NULL
);
738 static struct st_context_iface
*
739 st_api_get_current(struct st_api
*stapi
)
741 GET_CURRENT_CONTEXT(ctx
);
742 struct st_context
*st
= (ctx
) ? ctx
->st
: NULL
;
744 return (st
) ? &st
->iface
: NULL
;
748 st_api_get_proc_address(struct st_api
*stapi
, const char *procname
)
750 return (st_proc_t
) _glapi_get_proc_address(procname
);
754 st_api_destroy(struct st_api
*stapi
)
759 * Flush the front buffer if the current context renders to the front buffer.
762 st_manager_flush_frontbuffer(struct st_context
*st
)
764 struct st_framebuffer
*stfb
= st_ws_framebuffer(st
->ctx
->DrawBuffer
);
765 struct st_renderbuffer
*strb
= NULL
;
768 strb
= st_renderbuffer(stfb
->Base
.Attachment
[BUFFER_FRONT_LEFT
].Renderbuffer
);
772 /* never a dummy fb */
774 stfb
->iface
->flush_front(stfb
->iface
, ST_ATTACHMENT_FRONT_LEFT
);
778 * Return the surface of an EGLImage.
780 struct pipe_surface
*
781 st_manager_get_egl_image_surface(struct st_context
*st
,
782 void *eglimg
, unsigned usage
)
784 struct st_manager
*smapi
=
785 (struct st_manager
*) st
->iface
.st_context_private
;
786 struct st_egl_image stimg
;
787 struct pipe_surface
*ps
;
789 if (!smapi
|| !smapi
->get_egl_image
)
792 memset(&stimg
, 0, sizeof(stimg
));
793 if (!smapi
->get_egl_image(smapi
, &st
->iface
, eglimg
, &stimg
))
796 ps
= smapi
->screen
->get_tex_surface(smapi
->screen
,
797 stimg
.texture
, stimg
.face
, stimg
.level
, stimg
.zslice
, usage
);
798 pipe_resource_reference(&stimg
.texture
, NULL
);
804 * Re-validate the framebuffers.
807 st_manager_validate_framebuffers(struct st_context
*st
)
809 struct st_framebuffer
*stdraw
= st_ws_framebuffer(st
->ctx
->DrawBuffer
);
810 struct st_framebuffer
*stread
= st_ws_framebuffer(st
->ctx
->ReadBuffer
);
813 st_framebuffer_validate(stdraw
, st
);
814 if (stread
&& stread
!= stdraw
)
815 st_framebuffer_validate(stread
, st
);
819 * Add a color renderbuffer on demand.
822 st_manager_add_color_renderbuffer(struct st_context
*st
, GLframebuffer
*fb
,
825 struct st_framebuffer
*stfb
= st_ws_framebuffer(fb
);
831 if (stfb
->Base
.Attachment
[idx
].Renderbuffer
)
835 case BUFFER_FRONT_LEFT
:
836 case BUFFER_BACK_LEFT
:
837 case BUFFER_FRONT_RIGHT
:
838 case BUFFER_BACK_RIGHT
:
845 if (!st_framebuffer_add_renderbuffer(stfb
, idx
))
848 st_framebuffer_update_attachments(stfb
);
849 st_invalidate_state(st
->ctx
, _NEW_BUFFERS
);
854 static const struct st_api st_gl_api
= {
856 st_api_get_proc_address
,
857 st_api_create_context
,
862 static const struct st_api st_gl_api_es1
= {
864 st_api_get_proc_address
,
865 st_api_create_context_es1
,
870 static const struct st_api st_gl_api_es2
= {
872 st_api_get_proc_address
,
873 st_api_create_context_es2
,
879 st_gl_api_create(void)
882 (void) st_gl_api_es1
;
883 (void) st_gl_api_es2
;
886 return (struct st_api
*) &st_gl_api
;
893 st_gl_api_create_es1(void)
896 return (struct st_api
*) &st_gl_api_es1
;
903 st_gl_api_create_es2(void)
906 return (struct st_api
*) &st_gl_api_es2
;