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/renderbuffer.h"
46 #include "st_texture.h"
48 #include "st_context.h"
49 #include "st_format.h"
50 #include "st_cb_fbo.h"
51 #include "st_cb_flush.h"
52 #include "st_manager.h"
55 * Cast wrapper to convert a GLframebuffer to an st_framebuffer.
56 * Return NULL if the GLframebuffer is a user-created framebuffer.
57 * We'll only return non-null for window system framebuffers.
58 * Note that this function may fail.
60 static INLINE
struct st_framebuffer
*
61 st_ws_framebuffer(GLframebuffer
*fb
)
63 /* FBO cannot be casted. See st_new_framebuffer */
64 return (struct st_framebuffer
*) ((fb
&& !fb
->Name
) ? fb
: NULL
);
68 * Map an attachment to a buffer index.
70 static INLINE gl_buffer_index
71 attachment_to_buffer_index(enum st_attachment_type statt
)
73 gl_buffer_index index
;
76 case ST_ATTACHMENT_FRONT_LEFT
:
77 index
= BUFFER_FRONT_LEFT
;
79 case ST_ATTACHMENT_BACK_LEFT
:
80 index
= BUFFER_BACK_LEFT
;
82 case ST_ATTACHMENT_FRONT_RIGHT
:
83 index
= BUFFER_FRONT_RIGHT
;
85 case ST_ATTACHMENT_BACK_RIGHT
:
86 index
= BUFFER_BACK_RIGHT
;
88 case ST_ATTACHMENT_DEPTH_STENCIL
:
91 case ST_ATTACHMENT_ACCUM
:
94 case ST_ATTACHMENT_SAMPLE
:
104 * Map a buffer index to an attachment.
106 static INLINE
enum st_attachment_type
107 buffer_index_to_attachment(gl_buffer_index index
)
109 enum st_attachment_type statt
;
112 case BUFFER_FRONT_LEFT
:
113 statt
= ST_ATTACHMENT_FRONT_LEFT
;
115 case BUFFER_BACK_LEFT
:
116 statt
= ST_ATTACHMENT_BACK_LEFT
;
118 case BUFFER_FRONT_RIGHT
:
119 statt
= ST_ATTACHMENT_FRONT_RIGHT
;
121 case BUFFER_BACK_RIGHT
:
122 statt
= ST_ATTACHMENT_BACK_RIGHT
;
125 statt
= ST_ATTACHMENT_DEPTH_STENCIL
;
128 statt
= ST_ATTACHMENT_ACCUM
;
131 statt
= ST_ATTACHMENT_INVALID
;
139 * Validate a framebuffer to make sure up-to-date pipe_textures are used.
142 st_framebuffer_validate(struct st_framebuffer
*stfb
, struct st_context
*st
)
144 struct pipe_screen
*screen
= st
->pipe
->screen
;
145 struct pipe_resource
*textures
[ST_ATTACHMENT_COUNT
];
148 boolean changed
= FALSE
;
150 if (!p_atomic_read(&stfb
->revalidate
))
153 /* validate the fb */
154 if (!stfb
->iface
->validate(stfb
->iface
, stfb
->statts
, stfb
->num_statts
, textures
))
157 width
= stfb
->Base
.Width
;
158 height
= stfb
->Base
.Height
;
160 for (i
= 0; i
< stfb
->num_statts
; i
++) {
161 struct st_renderbuffer
*strb
;
162 struct pipe_surface
*ps
;
168 idx
= attachment_to_buffer_index(stfb
->statts
[i
]);
169 if (idx
>= BUFFER_COUNT
) {
170 pipe_resource_reference(&textures
[i
], NULL
);
174 strb
= st_renderbuffer(stfb
->Base
.Attachment
[idx
].Renderbuffer
);
176 if (strb
->texture
== textures
[i
]) {
177 pipe_resource_reference(&textures
[i
], NULL
);
181 ps
= screen
->get_tex_surface(screen
, textures
[i
], 0, 0, 0,
182 PIPE_BIND_RENDER_TARGET
);
184 pipe_surface_reference(&strb
->surface
, ps
);
185 pipe_resource_reference(&strb
->texture
, ps
->texture
);
186 /* ownership transfered */
187 pipe_surface_reference(&ps
, NULL
);
191 strb
->Base
.Width
= strb
->surface
->width
;
192 strb
->Base
.Height
= strb
->surface
->height
;
194 width
= strb
->Base
.Width
;
195 height
= strb
->Base
.Height
;
198 pipe_resource_reference(&textures
[i
], NULL
);
202 st
->dirty
.st
|= ST_NEW_FRAMEBUFFER
;
203 _mesa_resize_framebuffer(st
->ctx
, &stfb
->Base
, width
, height
);
205 assert(stfb
->Base
.Width
== width
);
206 assert(stfb
->Base
.Height
== height
);
209 p_atomic_set(&stfb
->revalidate
, FALSE
);
213 * Update the attachments to validate by looping the existing renderbuffers.
216 st_framebuffer_update_attachments(struct st_framebuffer
*stfb
)
220 stfb
->num_statts
= 0;
221 for (idx
= 0; idx
< BUFFER_COUNT
; idx
++) {
222 struct st_renderbuffer
*strb
;
223 enum st_attachment_type statt
;
225 strb
= st_renderbuffer(stfb
->Base
.Attachment
[idx
].Renderbuffer
);
226 if (!strb
|| strb
->software
)
229 statt
= buffer_index_to_attachment(idx
);
230 if (statt
!= ST_ATTACHMENT_INVALID
&&
231 st_visual_have_buffers(stfb
->iface
->visual
, 1 << statt
))
232 stfb
->statts
[stfb
->num_statts
++] = statt
;
235 p_atomic_set(&stfb
->revalidate
, TRUE
);
239 * Add a renderbuffer to the framebuffer.
242 st_framebuffer_add_renderbuffer(struct st_framebuffer
*stfb
,
245 struct gl_renderbuffer
*rb
;
246 enum pipe_format format
;
250 /* do not distinguish depth/stencil buffers */
251 if (idx
== BUFFER_STENCIL
)
256 format
= stfb
->iface
->visual
->depth_stencil_format
;
260 format
= stfb
->iface
->visual
->accum_format
;
264 format
= stfb
->iface
->visual
->color_format
;
269 if (format
== PIPE_FORMAT_NONE
)
272 samples
= stfb
->iface
->visual
->samples
;
274 samples
= st_get_msaa();
276 rb
= st_new_renderbuffer_fb(format
, samples
, sw
);
280 if (idx
!= BUFFER_DEPTH
) {
281 _mesa_add_renderbuffer(&stfb
->Base
, idx
, rb
);
284 if (util_format_get_component_bits(format
, UTIL_FORMAT_COLORSPACE_ZS
, 0))
285 _mesa_add_renderbuffer(&stfb
->Base
, BUFFER_DEPTH
, rb
);
286 if (util_format_get_component_bits(format
, UTIL_FORMAT_COLORSPACE_ZS
, 1))
287 _mesa_add_renderbuffer(&stfb
->Base
, BUFFER_STENCIL
, rb
);
294 * Intialize a __GLcontextModes from a visual.
297 st_visual_to_context_mode(const struct st_visual
*visual
,
298 __GLcontextModes
*mode
)
300 memset(mode
, 0, sizeof(*mode
));
302 if (st_visual_have_buffers(visual
, ST_ATTACHMENT_BACK_LEFT_MASK
))
303 mode
->doubleBufferMode
= GL_TRUE
;
304 if (st_visual_have_buffers(visual
,
305 ST_ATTACHMENT_FRONT_RIGHT_MASK
| ST_ATTACHMENT_BACK_RIGHT_MASK
))
306 mode
->stereoMode
= GL_TRUE
;
308 if (visual
->color_format
!= PIPE_FORMAT_NONE
) {
309 mode
->rgbMode
= GL_TRUE
;
312 util_format_get_component_bits(visual
->color_format
,
313 UTIL_FORMAT_COLORSPACE_RGB
, 0);
315 util_format_get_component_bits(visual
->color_format
,
316 UTIL_FORMAT_COLORSPACE_RGB
, 1);
318 util_format_get_component_bits(visual
->color_format
,
319 UTIL_FORMAT_COLORSPACE_RGB
, 2);
321 util_format_get_component_bits(visual
->color_format
,
322 UTIL_FORMAT_COLORSPACE_RGB
, 3);
324 mode
->rgbBits
= mode
->redBits
+
325 mode
->greenBits
+ mode
->blueBits
+ mode
->alphaBits
;
328 if (visual
->depth_stencil_format
!= PIPE_FORMAT_NONE
) {
330 util_format_get_component_bits(visual
->depth_stencil_format
,
331 UTIL_FORMAT_COLORSPACE_ZS
, 0);
333 util_format_get_component_bits(visual
->depth_stencil_format
,
334 UTIL_FORMAT_COLORSPACE_ZS
, 1);
336 mode
->haveDepthBuffer
= mode
->depthBits
> 0;
337 mode
->haveStencilBuffer
= mode
->stencilBits
> 0;
340 if (visual
->accum_format
!= PIPE_FORMAT_NONE
) {
341 mode
->haveAccumBuffer
= GL_TRUE
;
344 util_format_get_component_bits(visual
->accum_format
,
345 UTIL_FORMAT_COLORSPACE_RGB
, 0);
346 mode
->accumGreenBits
=
347 util_format_get_component_bits(visual
->accum_format
,
348 UTIL_FORMAT_COLORSPACE_RGB
, 1);
349 mode
->accumBlueBits
=
350 util_format_get_component_bits(visual
->accum_format
,
351 UTIL_FORMAT_COLORSPACE_RGB
, 2);
352 mode
->accumAlphaBits
=
353 util_format_get_component_bits(visual
->accum_format
,
354 UTIL_FORMAT_COLORSPACE_RGB
, 3);
357 if (visual
->samples
) {
358 mode
->sampleBuffers
= 1;
359 mode
->samples
= visual
->samples
;
364 * Determine the default draw or read buffer from a visual.
367 st_visual_to_default_buffer(const struct st_visual
*visual
,
368 GLenum
*buffer
, GLint
*index
)
370 enum st_attachment_type statt
;
374 statt
= visual
->render_buffer
;
375 /* do nothing if an invalid render buffer is specified */
376 if (statt
== ST_ATTACHMENT_INVALID
||
377 !st_visual_have_buffers(visual
, 1 << statt
))
381 case ST_ATTACHMENT_FRONT_LEFT
:
383 idx
= BUFFER_FRONT_LEFT
;
385 case ST_ATTACHMENT_BACK_LEFT
:
387 idx
= BUFFER_BACK_LEFT
;
389 case ST_ATTACHMENT_FRONT_RIGHT
:
390 buf
= GL_FRONT_RIGHT
;
391 idx
= BUFFER_FRONT_RIGHT
;
393 case ST_ATTACHMENT_BACK_RIGHT
:
395 idx
= BUFFER_BACK_RIGHT
;
403 if (buf
!= GL_NONE
) {
412 * Create a framebuffer from a manager interface.
414 static struct st_framebuffer
*
415 st_framebuffer_create(struct st_framebuffer_iface
*stfbi
)
417 struct st_framebuffer
*stfb
;
418 __GLcontextModes mode
;
421 stfb
= CALLOC_STRUCT(st_framebuffer
);
425 st_visual_to_context_mode(stfbi
->visual
, &mode
);
426 _mesa_initialize_window_framebuffer(&stfb
->Base
, &mode
);
428 /* modify the draw/read buffers of the fb */
429 st_visual_to_default_buffer(stfbi
->visual
, &stfb
->Base
.ColorDrawBuffer
[0],
430 &stfb
->Base
._ColorDrawBufferIndexes
[0]);
431 st_visual_to_default_buffer(stfbi
->visual
, &stfb
->Base
.ColorReadBuffer
,
432 &stfb
->Base
._ColorReadBufferIndex
);
436 /* add the color buffer */
437 idx
= stfb
->Base
._ColorDrawBufferIndexes
[0];
438 if (!st_framebuffer_add_renderbuffer(stfb
, idx
)) {
443 st_framebuffer_add_renderbuffer(stfb
, BUFFER_DEPTH
);
444 st_framebuffer_add_renderbuffer(stfb
, BUFFER_ACCUM
);
446 st_framebuffer_update_attachments(stfb
);
448 stfb
->Base
.Initialized
= GL_TRUE
;
454 * Reference a framebuffer.
457 st_framebuffer_reference(struct st_framebuffer
**ptr
,
458 struct st_framebuffer
*stfb
)
460 GLframebuffer
*fb
= &stfb
->Base
;
461 _mesa_reference_framebuffer((GLframebuffer
**) ptr
, fb
);
465 st_context_notify_invalid_framebuffer(struct st_context_iface
*stctxi
,
466 struct st_framebuffer_iface
*stfbi
)
468 struct st_context
*st
= (struct st_context
*) stctxi
;
469 struct st_framebuffer
*stfb
;
471 /* either draw or read winsys fb */
472 stfb
= st_ws_framebuffer(st
->ctx
->WinSysDrawBuffer
);
473 if (!stfb
|| stfb
->iface
!= stfbi
)
474 stfb
= st_ws_framebuffer(st
->ctx
->WinSysReadBuffer
);
475 assert(stfb
&& stfb
->iface
== stfbi
);
477 p_atomic_set(&stfb
->revalidate
, TRUE
);
481 st_context_flush(struct st_context_iface
*stctxi
, unsigned flags
,
482 struct pipe_fence_handle
**fence
)
484 struct st_context
*st
= (struct st_context
*) stctxi
;
485 st_flush(st
, flags
, fence
);
486 if (flags
& PIPE_FLUSH_RENDER_CACHE
)
487 st_manager_flush_frontbuffer(st
);
491 st_context_teximage(struct st_context_iface
*stctxi
, enum st_texture_type target
,
492 int level
, enum pipe_format internal_format
,
493 struct pipe_resource
*tex
, boolean mipmap
)
495 struct st_context
*st
= (struct st_context
*) stctxi
;
496 GLcontext
*ctx
= st
->ctx
;
497 struct gl_texture_unit
*texUnit
= _mesa_get_current_tex_unit(ctx
);
498 struct gl_texture_object
*texObj
;
499 struct gl_texture_image
*texImage
;
500 struct st_texture_object
*stObj
;
501 struct st_texture_image
*stImage
;
502 GLenum internalFormat
;
503 GLuint width
, height
, depth
;
507 target
= GL_TEXTURE_1D
;
510 target
= GL_TEXTURE_2D
;
513 target
= GL_TEXTURE_3D
;
515 case ST_TEXTURE_RECT
:
516 target
= GL_TEXTURE_RECTANGLE_ARB
;
523 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
524 _mesa_lock_texture(ctx
, texObj
);
526 stObj
= st_texture_object(texObj
);
527 /* switch to surface based */
528 if (!stObj
->surface_based
) {
529 _mesa_clear_texture_object(ctx
, texObj
);
530 stObj
->surface_based
= GL_TRUE
;
533 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
534 stImage
= st_texture_image(texImage
);
537 * XXX When internal_format and tex->format differ, st_finalize_texture
538 * needs to allocate a new texture with internal_format and copy the
539 * texture here into the new one. It will result in surface_copy being
540 * called on surfaces whose formats differ.
542 * To avoid that, internal_format is (wrongly) ignored here. A sane fix
543 * is to use a sampler view.
545 if (!st_sampler_compat_formats(tex
->format
, internal_format
))
546 internal_format
= tex
->format
;
548 if (util_format_get_component_bits(internal_format
,
549 UTIL_FORMAT_COLORSPACE_RGB
, 3) > 0)
550 internalFormat
= GL_RGBA
;
552 internalFormat
= GL_RGB
;
553 _mesa_init_teximage_fields(ctx
, target
, texImage
,
554 tex
->width0
, tex
->height0
, 1, 0, internalFormat
);
555 texImage
->TexFormat
= st_ChooseTextureFormat(ctx
, internalFormat
,
556 GL_RGBA
, GL_UNSIGNED_BYTE
);
557 _mesa_set_fetch_functions(texImage
, 2);
560 height
= tex
->height0
;
563 /* grow the image size until we hit level = 0 */
575 _mesa_clear_texture_image(ctx
, texImage
);
576 width
= height
= depth
= 0;
579 pipe_resource_reference(&stImage
->pt
, tex
);
580 stObj
->width0
= width
;
581 stObj
->height0
= height
;
582 stObj
->depth0
= depth
;
584 _mesa_dirty_texobj(ctx
, texObj
, GL_TRUE
);
585 _mesa_unlock_texture(ctx
, texObj
);
591 st_context_destroy(struct st_context_iface
*stctxi
)
593 struct st_context
*st
= (struct st_context
*) stctxi
;
594 st_destroy_context(st
);
597 static struct st_context_iface
*
598 create_context(gl_api api
, struct st_manager
*smapi
,
599 const struct st_visual
*visual
,
600 struct st_context_iface
*shared_stctxi
)
602 struct st_context
*shared_ctx
= (struct st_context
*) shared_stctxi
;
603 struct st_context
*st
;
604 struct pipe_context
*pipe
;
605 __GLcontextModes mode
;
607 pipe
= smapi
->screen
->context_create(smapi
->screen
, NULL
);
611 st_visual_to_context_mode(visual
, &mode
);
612 st
= st_create_context(api
, pipe
, &mode
, shared_ctx
);
618 st
->invalidate_on_gl_viewport
=
619 smapi
->get_param(smapi
, ST_MANAGER_BROKEN_INVALIDATE
);
621 st
->iface
.destroy
= st_context_destroy
;
622 st
->iface
.notify_invalid_framebuffer
=
623 st_context_notify_invalid_framebuffer
;
624 st
->iface
.flush
= st_context_flush
;
625 st
->iface
.teximage
= st_context_teximage
;
626 st
->iface
.copy
= NULL
;
627 st
->iface
.st_context_private
= (void *) smapi
;
632 static struct st_context_iface
*
633 st_api_create_context(struct st_api
*stapi
, struct st_manager
*smapi
,
634 const struct st_visual
*visual
,
635 struct st_context_iface
*shared_stctxi
)
637 return create_context(API_OPENGL
, smapi
, visual
, shared_stctxi
);
640 static struct st_context_iface
*
641 st_api_create_context_es1(struct st_api
*stapi
, struct st_manager
*smapi
,
642 const struct st_visual
*visual
,
643 struct st_context_iface
*shared_stctxi
)
645 return create_context(API_OPENGLES
, smapi
, visual
, shared_stctxi
);
648 static struct st_context_iface
*
649 st_api_create_context_es2(struct st_api
*stapi
, struct st_manager
*smapi
,
650 const struct st_visual
*visual
,
651 struct st_context_iface
*shared_stctxi
)
653 return create_context(API_OPENGLES2
, smapi
, visual
, shared_stctxi
);
657 st_api_make_current(struct st_api
*stapi
, struct st_context_iface
*stctxi
,
658 struct st_framebuffer_iface
*stdrawi
,
659 struct st_framebuffer_iface
*streadi
)
661 struct st_context
*st
= (struct st_context
*) stctxi
;
662 struct st_framebuffer
*stdraw
, *stread
, *stfb
;
665 _glapi_check_multithread();
668 /* reuse/create the draw fb */
669 stfb
= st_ws_framebuffer(st
->ctx
->WinSysDrawBuffer
);
670 if (stfb
&& stfb
->iface
== stdrawi
) {
672 st_framebuffer_reference(&stdraw
, stfb
);
675 stdraw
= st_framebuffer_create(stdrawi
);
678 /* reuse/create the read fb */
679 stfb
= st_ws_framebuffer(st
->ctx
->WinSysReadBuffer
);
680 if (!stfb
|| stfb
->iface
!= streadi
)
682 if (stfb
&& stfb
->iface
== streadi
) {
684 st_framebuffer_reference(&stread
, stfb
);
687 stread
= st_framebuffer_create(streadi
);
690 if (stdraw
&& stread
) {
691 st_framebuffer_validate(stdraw
, st
);
692 if (stread
!= stdraw
)
693 st_framebuffer_validate(stread
, st
);
695 /* modify the draw/read buffers of the context */
696 st_visual_to_default_buffer(stdraw
->iface
->visual
,
697 &st
->ctx
->Color
.DrawBuffer
[0], NULL
);
698 st_visual_to_default_buffer(stread
->iface
->visual
,
699 &st
->ctx
->Pixel
.ReadBuffer
, NULL
);
701 ret
= _mesa_make_current(st
->ctx
, &stdraw
->Base
, &stread
->Base
);
707 st_framebuffer_reference(&stdraw
, NULL
);
708 st_framebuffer_reference(&stread
, NULL
);
711 ret
= _mesa_make_current(NULL
, NULL
, NULL
);
717 static struct st_context_iface
*
718 st_api_get_current(struct st_api
*stapi
)
720 GET_CURRENT_CONTEXT(ctx
);
721 struct st_context
*st
= (ctx
) ? ctx
->st
: NULL
;
723 return (st
) ? &st
->iface
: NULL
;
727 st_api_get_proc_address(struct st_api
*stapi
, const char *procname
)
729 return (st_proc_t
) _glapi_get_proc_address(procname
);
733 st_api_destroy(struct st_api
*stapi
)
738 * Flush the front buffer if the current context renders to the front buffer.
741 st_manager_flush_frontbuffer(struct st_context
*st
)
743 struct st_framebuffer
*stfb
= st_ws_framebuffer(st
->ctx
->DrawBuffer
);
744 struct st_renderbuffer
*strb
= NULL
;
747 strb
= st_renderbuffer(stfb
->Base
.Attachment
[BUFFER_FRONT_LEFT
].Renderbuffer
);
751 stfb
->iface
->flush_front(stfb
->iface
, ST_ATTACHMENT_FRONT_LEFT
);
755 * Return the surface of an EGLImage.
757 struct pipe_surface
*
758 st_manager_get_egl_image_surface(struct st_context
*st
,
759 void *eglimg
, unsigned usage
)
761 struct st_manager
*smapi
=
762 (struct st_manager
*) st
->iface
.st_context_private
;
763 struct st_egl_image stimg
;
764 struct pipe_surface
*ps
;
766 if (!smapi
|| !smapi
->get_egl_image
)
769 memset(&stimg
, 0, sizeof(stimg
));
770 if (!smapi
->get_egl_image(smapi
, &st
->iface
, eglimg
, &stimg
))
773 ps
= smapi
->screen
->get_tex_surface(smapi
->screen
,
774 stimg
.texture
, stimg
.face
, stimg
.level
, stimg
.zslice
, usage
);
775 pipe_resource_reference(&stimg
.texture
, NULL
);
781 * Re-validate the framebuffers.
784 st_manager_validate_framebuffers(struct st_context
*st
)
786 struct st_framebuffer
*stdraw
= st_ws_framebuffer(st
->ctx
->DrawBuffer
);
787 struct st_framebuffer
*stread
= st_ws_framebuffer(st
->ctx
->ReadBuffer
);
790 st_framebuffer_validate(stdraw
, st
);
791 if (stread
&& stread
!= stdraw
)
792 st_framebuffer_validate(stread
, st
);
796 * Add a color renderbuffer on demand.
799 st_manager_add_color_renderbuffer(struct st_context
*st
, GLframebuffer
*fb
,
802 struct st_framebuffer
*stfb
= st_ws_framebuffer(fb
);
808 if (stfb
->Base
.Attachment
[idx
].Renderbuffer
)
812 case BUFFER_FRONT_LEFT
:
813 case BUFFER_BACK_LEFT
:
814 case BUFFER_FRONT_RIGHT
:
815 case BUFFER_BACK_RIGHT
:
822 if (!st_framebuffer_add_renderbuffer(stfb
, idx
))
825 st_framebuffer_update_attachments(stfb
);
826 st_invalidate_state(st
->ctx
, _NEW_BUFFERS
);
831 static const struct st_api st_gl_api
= {
833 st_api_get_proc_address
,
834 st_api_create_context
,
839 static const struct st_api st_gl_api_es1
= {
841 st_api_get_proc_address
,
842 st_api_create_context_es1
,
847 static const struct st_api st_gl_api_es2
= {
849 st_api_get_proc_address
,
850 st_api_create_context_es2
,
856 st_gl_api_create(void)
859 (void) st_gl_api_es1
;
860 (void) st_gl_api_es2
;
863 return (struct st_api
*) &st_gl_api
;
870 st_gl_api_create_es1(void)
873 return (struct st_api
*) &st_gl_api_es1
;
880 st_gl_api_create_es2(void)
883 return (struct st_api
*) &st_gl_api_es2
;