void st_flush(struct st_context *st, uint pipeFlushFlags,
struct pipe_fence_handle **fence);
+/**
+ * Note that this function may fail.
+ */
+static INLINE struct st_framebuffer *
+st_framebuffer(GLframebuffer *fb)
+{
+ /* FBO cannot be casted. See st_new_framebuffer */
+ return (struct st_framebuffer *) ((fb && !fb->Name) ? fb : NULL);
+}
+
/**
* Map an attachment to a buffer index.
*/
struct st_framebuffer *stfb;
/* either draw or read winsys fb */
- stfb = (struct st_framebuffer *) st->ctx->WinSysDrawBuffer;
+ stfb = st_framebuffer(st->ctx->WinSysDrawBuffer);
if (!stfb || stfb->iface != stfbi)
- stfb = (struct st_framebuffer *) st->ctx->WinSysReadBuffer;
+ stfb = st_framebuffer(st->ctx->WinSysReadBuffer);
assert(stfb && stfb->iface == stfbi);
p_atomic_set(&stfb->revalidate, TRUE);
if (st) {
/* reuse/create the draw fb */
- stfb = (struct st_framebuffer * ) st->ctx->DrawBuffer;
+ stfb = st_framebuffer(st->ctx->WinSysDrawBuffer);
if (stfb && stfb->iface == stdrawi) {
stdraw = NULL;
st_framebuffer_reference(&stdraw, stfb);
}
/* reuse/create the read fb */
- stfb = (struct st_framebuffer * ) st->ctx->ReadBuffer;
+ stfb = st_framebuffer(st->ctx->WinSysReadBuffer);
if (!stfb || stfb->iface != streadi)
stfb = stdraw;
if (stfb && stfb->iface == streadi) {
void
st_manager_flush_frontbuffer(struct st_context *st)
{
- struct st_framebuffer *stfb = (struct st_framebuffer *) st->ctx->DrawBuffer;
+ struct st_framebuffer *stfb = st_framebuffer(st->ctx->DrawBuffer);
struct st_renderbuffer *strb = NULL;
if (stfb)
if (!strb)
return;
- /* st_public.h or FBO */
+ /* st_public.h */
if (!stfb->iface) {
struct pipe_surface *front_surf = strb->surface;
st->pipe->screen->flush_frontbuffer(st->pipe->screen,
void
st_manager_validate_framebuffers(struct st_context *st)
{
- struct st_framebuffer *stdraw, *stread;
+ struct st_framebuffer *stdraw = st_framebuffer(st->ctx->DrawBuffer);
+ struct st_framebuffer *stread = st_framebuffer(st->ctx->ReadBuffer);
- stdraw = (struct st_framebuffer *) st->ctx->DrawBuffer;
- stread = (struct st_framebuffer *) st->ctx->ReadBuffer;
-
- /* st_public.h or FBO */
+ /* st_public.h */
if ((stdraw && !stdraw->iface) || (stread && !stread->iface)) {
struct pipe_screen *screen = st->pipe->screen;
if (screen->update_buffer)
st_manager_add_color_renderbuffer(struct st_context *st, GLframebuffer *fb,
gl_buffer_index idx)
{
- struct st_framebuffer *stfb = (struct st_framebuffer *) fb;
+ struct st_framebuffer *stfb = st_framebuffer(fb);
+
+ /* FBO or st_public.h */
+ if (!stfb || !stfb->iface)
+ return FALSE;
if (stfb->Base.Attachment[idx].Renderbuffer)
return TRUE;
- /* st_public.h or FBO */
- if (!stfb->iface)
- return FALSE;
-
switch (idx) {
case BUFFER_FRONT_LEFT:
case BUFFER_BACK_LEFT: