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"
37 #include "util/u_surface.h"
39 #include "main/mtypes.h"
40 #include "main/context.h"
41 #include "main/mfeatures.h"
42 #include "main/texobj.h"
43 #include "main/teximage.h"
44 #include "main/texstate.h"
45 #include "main/framebuffer.h"
46 #include "main/fbobject.h"
47 #include "main/renderbuffer.h"
48 #include "main/version.h"
49 #include "st_texture.h"
51 #include "st_context.h"
52 #include "st_format.h"
53 #include "st_cb_fbo.h"
54 #include "st_cb_flush.h"
55 #include "st_manager.h"
58 * Cast wrapper to convert a struct gl_framebuffer to an st_framebuffer.
59 * Return NULL if the struct gl_framebuffer is a user-created framebuffer.
60 * We'll only return non-null for window system framebuffers.
61 * Note that this function may fail.
63 static INLINE
struct st_framebuffer
*
64 st_ws_framebuffer(struct gl_framebuffer
*fb
)
66 /* FBO cannot be casted. See st_new_framebuffer */
67 return (struct st_framebuffer
*) ((fb
&& !fb
->Name
) ? fb
: NULL
);
71 * Map an attachment to a buffer index.
73 static INLINE gl_buffer_index
74 attachment_to_buffer_index(enum st_attachment_type statt
)
76 gl_buffer_index index
;
79 case ST_ATTACHMENT_FRONT_LEFT
:
80 index
= BUFFER_FRONT_LEFT
;
82 case ST_ATTACHMENT_BACK_LEFT
:
83 index
= BUFFER_BACK_LEFT
;
85 case ST_ATTACHMENT_FRONT_RIGHT
:
86 index
= BUFFER_FRONT_RIGHT
;
88 case ST_ATTACHMENT_BACK_RIGHT
:
89 index
= BUFFER_BACK_RIGHT
;
91 case ST_ATTACHMENT_DEPTH_STENCIL
:
94 case ST_ATTACHMENT_ACCUM
:
97 case ST_ATTACHMENT_SAMPLE
:
107 * Map a buffer index to an attachment.
109 static INLINE
enum st_attachment_type
110 buffer_index_to_attachment(gl_buffer_index index
)
112 enum st_attachment_type statt
;
115 case BUFFER_FRONT_LEFT
:
116 statt
= ST_ATTACHMENT_FRONT_LEFT
;
118 case BUFFER_BACK_LEFT
:
119 statt
= ST_ATTACHMENT_BACK_LEFT
;
121 case BUFFER_FRONT_RIGHT
:
122 statt
= ST_ATTACHMENT_FRONT_RIGHT
;
124 case BUFFER_BACK_RIGHT
:
125 statt
= ST_ATTACHMENT_BACK_RIGHT
;
128 statt
= ST_ATTACHMENT_DEPTH_STENCIL
;
131 statt
= ST_ATTACHMENT_ACCUM
;
134 statt
= ST_ATTACHMENT_INVALID
;
142 * Make sure a context picks up the latest cached state of the
143 * drawables it binds to.
146 st_context_validate(struct st_context
*st
,
147 struct st_framebuffer
*stdraw
,
148 struct st_framebuffer
*stread
)
150 if (stdraw
&& stdraw
->stamp
!= st
->draw_stamp
) {
151 st
->dirty
.st
|= ST_NEW_FRAMEBUFFER
;
152 _mesa_resize_framebuffer(st
->ctx
, &stdraw
->Base
,
154 stdraw
->Base
.Height
);
155 st
->draw_stamp
= stdraw
->stamp
;
158 if (stread
&& stread
->stamp
!= st
->read_stamp
) {
159 if (stread
!= stdraw
) {
160 st
->dirty
.st
|= ST_NEW_FRAMEBUFFER
;
161 _mesa_resize_framebuffer(st
->ctx
, &stread
->Base
,
163 stread
->Base
.Height
);
165 st
->read_stamp
= stread
->stamp
;
170 * Validate a framebuffer to make sure up-to-date pipe_textures are used.
171 * The context we need to pass in is s dummy context needed only to be
172 * able to get a pipe context to create pipe surfaces, and to have a
173 * context to call _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(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 memset(&surf_tmpl
, 0, sizeof(surf_tmpl
));
226 u_surface_default_template(&surf_tmpl
, textures
[i
],
227 PIPE_BIND_RENDER_TARGET
);
228 ps
= st
->pipe
->create_surface(st
->pipe
, textures
[i
], &surf_tmpl
);
230 pipe_surface_reference(&strb
->surface
, ps
);
231 pipe_resource_reference(&strb
->texture
, ps
->texture
);
232 /* ownership transfered */
233 pipe_surface_reference(&ps
, NULL
);
237 strb
->Base
.Width
= strb
->surface
->width
;
238 strb
->Base
.Height
= strb
->surface
->height
;
240 width
= strb
->Base
.Width
;
241 height
= strb
->Base
.Height
;
244 pipe_resource_reference(&textures
[i
], NULL
);
249 _mesa_resize_framebuffer(st
->ctx
, &stfb
->Base
, width
, height
);
254 * Update the attachments to validate by looping the existing renderbuffers.
257 st_framebuffer_update_attachments(struct st_framebuffer
*stfb
)
261 stfb
->num_statts
= 0;
262 for (idx
= 0; idx
< BUFFER_COUNT
; idx
++) {
263 struct st_renderbuffer
*strb
;
264 enum st_attachment_type statt
;
266 strb
= st_renderbuffer(stfb
->Base
.Attachment
[idx
].Renderbuffer
);
267 if (!strb
|| strb
->software
)
270 statt
= buffer_index_to_attachment(idx
);
271 if (statt
!= ST_ATTACHMENT_INVALID
&&
272 st_visual_have_buffers(stfb
->iface
->visual
, 1 << statt
))
273 stfb
->statts
[stfb
->num_statts
++] = statt
;
279 * Add a renderbuffer to the framebuffer.
282 st_framebuffer_add_renderbuffer(struct st_framebuffer
*stfb
,
285 struct gl_renderbuffer
*rb
;
286 enum pipe_format format
;
293 /* do not distinguish depth/stencil buffers */
294 if (idx
== BUFFER_STENCIL
)
299 format
= stfb
->iface
->visual
->depth_stencil_format
;
303 format
= stfb
->iface
->visual
->accum_format
;
307 format
= stfb
->iface
->visual
->color_format
;
312 if (format
== PIPE_FORMAT_NONE
)
315 samples
= stfb
->iface
->visual
->samples
;
317 samples
= st_get_msaa();
319 rb
= st_new_renderbuffer_fb(format
, 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
) {
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_framebuffer_iface
*stfbi
)
412 struct st_framebuffer
*stfb
;
413 struct gl_config mode
;
419 stfb
= CALLOC_STRUCT(st_framebuffer
);
423 st_visual_to_context_mode(stfbi
->visual
, &mode
);
424 _mesa_initialize_window_framebuffer(&stfb
->Base
, &mode
);
427 stfb
->iface_stamp
= p_atomic_read(&stfbi
->stamp
) - 1;
429 /* add the color buffer */
430 idx
= stfb
->Base
._ColorDrawBufferIndexes
[0];
431 if (!st_framebuffer_add_renderbuffer(stfb
, idx
)) {
436 st_framebuffer_add_renderbuffer(stfb
, BUFFER_DEPTH
);
437 st_framebuffer_add_renderbuffer(stfb
, BUFFER_ACCUM
);
440 st_framebuffer_update_attachments(stfb
);
442 stfb
->Base
.Initialized
= GL_TRUE
;
448 * Reference a framebuffer.
451 st_framebuffer_reference(struct st_framebuffer
**ptr
,
452 struct st_framebuffer
*stfb
)
454 struct gl_framebuffer
*fb
= &stfb
->Base
;
455 _mesa_reference_framebuffer((struct gl_framebuffer
**) ptr
, fb
);
459 st_context_flush(struct st_context_iface
*stctxi
, unsigned flags
,
460 struct pipe_fence_handle
**fence
)
462 struct st_context
*st
= (struct st_context
*) stctxi
;
464 if (flags
& ST_FLUSH_FRONT
)
465 st_manager_flush_frontbuffer(st
);
469 st_context_teximage(struct st_context_iface
*stctxi
,
470 enum st_texture_type target
,
471 int level
, enum pipe_format internal_format
,
472 struct pipe_resource
*tex
, boolean mipmap
)
474 struct st_context
*st
= (struct st_context
*) stctxi
;
475 struct gl_context
*ctx
= st
->ctx
;
476 struct gl_texture_unit
*texUnit
= _mesa_get_current_tex_unit(ctx
);
477 struct gl_texture_object
*texObj
;
478 struct gl_texture_image
*texImage
;
479 struct st_texture_object
*stObj
;
480 struct st_texture_image
*stImage
;
481 GLenum internalFormat
;
482 GLuint width
, height
, depth
;
486 target
= GL_TEXTURE_1D
;
489 target
= GL_TEXTURE_2D
;
492 target
= GL_TEXTURE_3D
;
494 case ST_TEXTURE_RECT
:
495 target
= GL_TEXTURE_RECTANGLE_ARB
;
502 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
503 _mesa_lock_texture(ctx
, texObj
);
505 stObj
= st_texture_object(texObj
);
506 /* switch to surface based */
507 if (!stObj
->surface_based
) {
508 _mesa_clear_texture_object(ctx
, texObj
);
509 stObj
->surface_based
= GL_TRUE
;
512 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
513 stImage
= st_texture_image(texImage
);
518 * XXX When internal_format and tex->format differ, st_finalize_texture
519 * needs to allocate a new texture with internal_format and copy the
520 * texture here into the new one. It will result in surface_copy being
521 * called on surfaces whose formats differ.
523 * To avoid that, internal_format is (wrongly) ignored here. A sane fix
524 * is to use a sampler view.
526 if (!st_sampler_compat_formats(tex
->format
, internal_format
))
527 internal_format
= tex
->format
;
529 if (util_format_get_component_bits(internal_format
,
530 UTIL_FORMAT_COLORSPACE_RGB
, 3) > 0)
531 internalFormat
= GL_RGBA
;
533 internalFormat
= GL_RGB
;
535 texFormat
= st_ChooseTextureFormat(ctx
, internalFormat
,
536 GL_BGRA
, GL_UNSIGNED_BYTE
);
538 _mesa_init_teximage_fields(ctx
, target
, texImage
,
539 tex
->width0
, tex
->height0
, 1, 0,
540 internalFormat
, texFormat
);
543 height
= tex
->height0
;
546 /* grow the image size until we hit level = 0 */
558 _mesa_clear_texture_image(ctx
, texImage
);
559 width
= height
= depth
= 0;
562 pipe_resource_reference(&stImage
->pt
, tex
);
563 stObj
->width0
= width
;
564 stObj
->height0
= height
;
565 stObj
->depth0
= depth
;
567 _mesa_dirty_texobj(ctx
, texObj
, GL_TRUE
);
568 _mesa_unlock_texture(ctx
, texObj
);
574 st_context_copy(struct st_context_iface
*stctxi
,
575 struct st_context_iface
*stsrci
, unsigned mask
)
577 struct st_context
*st
= (struct st_context
*) stctxi
;
578 struct st_context
*src
= (struct st_context
*) stsrci
;
580 _mesa_copy_context(src
->ctx
, st
->ctx
, mask
);
584 st_context_share(struct st_context_iface
*stctxi
,
585 struct st_context_iface
*stsrci
)
587 struct st_context
*st
= (struct st_context
*) stctxi
;
588 struct st_context
*src
= (struct st_context
*) stsrci
;
590 return _mesa_share_state(st
->ctx
, src
->ctx
);
594 st_context_destroy(struct st_context_iface
*stctxi
)
596 struct st_context
*st
= (struct st_context
*) stctxi
;
597 st_destroy_context(st
);
600 static struct st_context_iface
*
601 st_api_create_context(struct st_api
*stapi
, struct st_manager
*smapi
,
602 const struct st_context_attribs
*attribs
,
603 enum st_context_error
*error
,
604 struct st_context_iface
*shared_stctxi
)
606 struct st_context
*shared_ctx
= (struct st_context
*) shared_stctxi
;
607 struct st_context
*st
;
608 struct pipe_context
*pipe
;
609 struct gl_config mode
;
612 if (!(stapi
->profile_mask
& (1 << attribs
->profile
)))
615 switch (attribs
->profile
) {
616 case ST_PROFILE_DEFAULT
:
619 case ST_PROFILE_OPENGL_ES1
:
622 case ST_PROFILE_OPENGL_ES2
:
625 case ST_PROFILE_OPENGL_CORE
:
627 *error
= ST_CONTEXT_ERROR_BAD_API
;
632 pipe
= smapi
->screen
->context_create(smapi
->screen
, NULL
);
634 *error
= ST_CONTEXT_ERROR_NO_MEMORY
;
638 st_visual_to_context_mode(&attribs
->visual
, &mode
);
639 st
= st_create_context(api
, pipe
, &mode
, shared_ctx
);
641 *error
= ST_CONTEXT_ERROR_NO_MEMORY
;
646 /* need to perform version check */
647 if (attribs
->major
> 1 || attribs
->minor
> 0) {
648 _mesa_compute_version(st
->ctx
);
650 /* is the actual version less than the requested version? */
651 if (st
->ctx
->VersionMajor
* 10 + st
->ctx
->VersionMinor
<
652 attribs
->major
* 10 + attribs
->minor
) {
653 *error
= ST_CONTEXT_ERROR_BAD_VERSION
;
654 st_destroy_context(st
);
659 st
->invalidate_on_gl_viewport
=
660 smapi
->get_param(smapi
, ST_MANAGER_BROKEN_INVALIDATE
);
662 st
->iface
.destroy
= st_context_destroy
;
663 st
->iface
.flush
= st_context_flush
;
664 st
->iface
.teximage
= st_context_teximage
;
665 st
->iface
.copy
= st_context_copy
;
666 st
->iface
.share
= st_context_share
;
667 st
->iface
.st_context_private
= (void *) smapi
;
669 *error
= ST_CONTEXT_SUCCESS
;
673 static struct st_context_iface
*
674 st_api_get_current(struct st_api
*stapi
)
676 GET_CURRENT_CONTEXT(ctx
);
677 struct st_context
*st
= (ctx
) ? ctx
->st
: NULL
;
679 return (st
) ? &st
->iface
: NULL
;
682 static struct st_framebuffer
*
683 st_framebuffer_reuse_or_create(struct gl_framebuffer
*fb
,
684 struct st_framebuffer_iface
*stfbi
)
686 struct st_framebuffer
*cur
= st_ws_framebuffer(fb
), *stfb
= NULL
;
688 if (cur
&& cur
->iface
== stfbi
) {
689 /* reuse the current stfb */
690 st_framebuffer_reference(&stfb
, cur
);
693 /* create a new one */
694 stfb
= st_framebuffer_create(stfbi
);
701 st_api_make_current(struct st_api
*stapi
, struct st_context_iface
*stctxi
,
702 struct st_framebuffer_iface
*stdrawi
,
703 struct st_framebuffer_iface
*streadi
)
705 struct st_context
*st
= (struct st_context
*) stctxi
;
706 struct st_framebuffer
*stdraw
, *stread
;
709 _glapi_check_multithread();
712 /* reuse or create the draw fb */
713 stdraw
= st_framebuffer_reuse_or_create(st
->ctx
->WinSysDrawBuffer
,
715 if (streadi
!= stdrawi
) {
716 /* do the same for the read fb */
717 stread
= st_framebuffer_reuse_or_create(st
->ctx
->WinSysReadBuffer
,
722 /* reuse the draw fb for the read fb */
724 st_framebuffer_reference(&stread
, stdraw
);
727 if (stdraw
&& stread
) {
728 st_framebuffer_validate(stdraw
, st
);
729 if (stread
!= stdraw
)
730 st_framebuffer_validate(stread
, st
);
732 ret
= _mesa_make_current(st
->ctx
, &stdraw
->Base
, &stread
->Base
);
734 st
->draw_stamp
= stdraw
->stamp
- 1;
735 st
->read_stamp
= stread
->stamp
- 1;
736 st_context_validate(st
, stdraw
, stread
);
739 struct gl_framebuffer
*incomplete
= _mesa_get_incomplete_framebuffer();
740 ret
= _mesa_make_current(st
->ctx
, incomplete
, incomplete
);
743 st_framebuffer_reference(&stdraw
, NULL
);
744 st_framebuffer_reference(&stread
, NULL
);
747 ret
= _mesa_make_current(NULL
, NULL
, NULL
);
754 st_api_get_proc_address(struct st_api
*stapi
, const char *procname
)
756 return (st_proc_t
) _glapi_get_proc_address(procname
);
760 st_api_destroy(struct st_api
*stapi
)
765 * Flush the front buffer if the current context renders to the front buffer.
768 st_manager_flush_frontbuffer(struct st_context
*st
)
770 struct st_framebuffer
*stfb
= st_ws_framebuffer(st
->ctx
->DrawBuffer
);
771 struct st_renderbuffer
*strb
= NULL
;
774 strb
= st_renderbuffer(stfb
->Base
.Attachment
[BUFFER_FRONT_LEFT
].Renderbuffer
);
778 /* never a dummy fb */
780 stfb
->iface
->flush_front(stfb
->iface
, ST_ATTACHMENT_FRONT_LEFT
);
784 * Return the surface of an EGLImage.
785 * FIXME: I think this should operate on resources, not surfaces
787 struct pipe_surface
*
788 st_manager_get_egl_image_surface(struct st_context
*st
,
789 void *eglimg
, unsigned usage
)
791 struct st_manager
*smapi
=
792 (struct st_manager
*) st
->iface
.st_context_private
;
793 struct st_egl_image stimg
;
794 struct pipe_surface
*ps
, surf_tmpl
;
796 if (!smapi
|| !smapi
->get_egl_image
)
799 memset(&stimg
, 0, sizeof(stimg
));
800 if (!smapi
->get_egl_image(smapi
, eglimg
, &stimg
))
803 memset(&surf_tmpl
, 0, sizeof(surf_tmpl
));
804 surf_tmpl
.format
= stimg
.texture
->format
;
805 surf_tmpl
.usage
= usage
;
806 surf_tmpl
.u
.tex
.level
= stimg
.level
;
807 surf_tmpl
.u
.tex
.first_layer
= stimg
.layer
;
808 surf_tmpl
.u
.tex
.last_layer
= stimg
.layer
;
809 ps
= st
->pipe
->create_surface(st
->pipe
, stimg
.texture
, &surf_tmpl
);
810 pipe_resource_reference(&stimg
.texture
, NULL
);
816 * Re-validate the framebuffers.
819 st_manager_validate_framebuffers(struct st_context
*st
)
821 struct st_framebuffer
*stdraw
= st_ws_framebuffer(st
->ctx
->DrawBuffer
);
822 struct st_framebuffer
*stread
= st_ws_framebuffer(st
->ctx
->ReadBuffer
);
825 st_framebuffer_validate(stdraw
, st
);
826 if (stread
&& stread
!= stdraw
)
827 st_framebuffer_validate(stread
, st
);
829 st_context_validate(st
, stdraw
, stread
);
833 * Add a color renderbuffer on demand.
836 st_manager_add_color_renderbuffer(struct st_context
*st
,
837 struct gl_framebuffer
*fb
,
840 struct st_framebuffer
*stfb
= st_ws_framebuffer(fb
);
846 if (stfb
->Base
.Attachment
[idx
].Renderbuffer
)
850 case BUFFER_FRONT_LEFT
:
851 case BUFFER_BACK_LEFT
:
852 case BUFFER_FRONT_RIGHT
:
853 case BUFFER_BACK_RIGHT
:
860 if (!st_framebuffer_add_renderbuffer(stfb
, idx
))
863 st_framebuffer_update_attachments(stfb
);
866 * Force a call to the state tracker manager to validate the
867 * new renderbuffer. It might be that there is a window system
868 * renderbuffer available.
871 stfb
->iface_stamp
= p_atomic_read(&stfb
->iface
->stamp
) - 1;
873 st_invalidate_state(st
->ctx
, _NEW_BUFFERS
);
878 static const struct st_api st_gl_api
= {
879 "Mesa " MESA_VERSION_STRING
,
882 ST_PROFILE_DEFAULT_MASK
|
885 ST_PROFILE_OPENGL_ES1_MASK
|
888 ST_PROFILE_OPENGL_ES2_MASK
|
892 st_api_get_proc_address
,
893 st_api_create_context
,
899 st_gl_api_create(void)
901 return (struct st_api
*) &st_gl_api
;