st_public.h File Reference

Include dependency graph for st_public.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define ST_SURFACE_FRONT_LEFT   0
#define ST_SURFACE_BACK_LEFT   1
#define ST_SURFACE_FRONT_RIGHT   2
#define ST_SURFACE_BACK_RIGHT   3
#define ST_SURFACE_DEPTH   8
#define ST_TEXTURE_2D   0x2
#define ST_TEXTURE_RGB   0x1
#define ST_TEXTURE_RGBA   0x2

Typedefs

typedef void(* st_proc )()
 Generic function type.

Functions

struct st_contextst_create_context (struct pipe_context *pipe, const __GLcontextModes *visual, struct st_context *share)
void st_destroy_context (struct st_context *st)
void st_copy_context_state (struct st_context *dst, struct st_context *src, uint mask)
struct st_framebufferst_create_framebuffer (const __GLcontextModes *visual, enum pipe_format colorFormat, enum pipe_format depthFormat, enum pipe_format stencilFormat, uint width, uint height, void *privateData)
void st_resize_framebuffer (struct st_framebuffer *stfb, uint width, uint height)
void st_set_framebuffer_surface (struct st_framebuffer *stfb, uint surfIndex, struct pipe_surface *surf)
 Set/replace a framebuffer surface.
struct pipe_surfacest_get_framebuffer_surface (struct st_framebuffer *stfb, uint surfIndex)
 Return the pipe_surface for the given renderbuffer.
struct pipe_texturest_get_framebuffer_texture (struct st_framebuffer *stfb, uint surfIndex)
void * st_framebuffer_private (struct st_framebuffer *stfb)
void st_unreference_framebuffer (struct st_framebuffer **stfb)
void st_make_current (struct st_context *st, struct st_framebuffer *draw, struct st_framebuffer *read)
void st_flush (struct st_context *st, uint pipeFlushFlags, struct pipe_fence_handle **fence)
void st_finish (struct st_context *st)
 Flush, and wait for completion.
void st_notify_swapbuffers (struct st_framebuffer *stfb)
 This function is to be called prior to SwapBuffers on the given framebuffer.
void st_notify_swapbuffers_complete (struct st_framebuffer *stfb)
 Quick hack - allows the winsys to inform the driver that surface states are now undefined after a glXSwapBuffers or similar.
int st_bind_teximage (struct st_framebuffer *stfb, uint surfIndex, int target, int format, int level)
 Redirect rendering into stfb's surface to a texture image.
int st_release_teximage (struct st_framebuffer *stfb, uint surfIndex, int target, int format, int level)
 Undo surface-to-texture binding.
st_proc st_get_proc_address (const char *procname)


Define Documentation

#define ST_SURFACE_BACK_LEFT   1

Definition at line 39 of file st_public.h.

#define ST_SURFACE_BACK_RIGHT   3

Definition at line 41 of file st_public.h.

#define ST_SURFACE_DEPTH   8

Definition at line 42 of file st_public.h.

#define ST_SURFACE_FRONT_LEFT   0

Definition at line 38 of file st_public.h.

#define ST_SURFACE_FRONT_RIGHT   2

Definition at line 40 of file st_public.h.

#define ST_TEXTURE_2D   0x2

Definition at line 44 of file st_public.h.

#define ST_TEXTURE_RGB   0x1

Definition at line 45 of file st_public.h.

#define ST_TEXTURE_RGBA   0x2

Definition at line 46 of file st_public.h.


Typedef Documentation

typedef void(* st_proc)()

Generic function type.

Definition at line 110 of file st_public.h.


Function Documentation

int st_bind_teximage ( struct st_framebuffer stfb,
uint  surfIndex,
int  target,
int  format,
int  level 
)

Redirect rendering into stfb's surface to a texture image.

Definition at line 356 of file st_texture.c.

00360 {
00361    GET_CURRENT_CONTEXT(ctx);
00362    struct st_context *st = ctx->st;
00363    struct pipe_context *pipe = st->pipe;
00364    struct pipe_screen *screen = pipe->screen;
00365    const GLuint unit = ctx->Texture.CurrentUnit;
00366    struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit];
00367    struct gl_texture_object *texObj;
00368    struct gl_texture_image *texImage;
00369    struct st_texture_image *stImage;
00370    struct st_renderbuffer *strb;
00371    GLint face = 0, slice = 0;
00372 
00373    assert(surfIndex <= ST_SURFACE_DEPTH);
00374 
00375    strb = st_renderbuffer(stfb->Base.Attachment[surfIndex].Renderbuffer);
00376 
00377    if (strb->texture_save || strb->surface_save) {
00378       /* Error! */
00379       return 0;
00380    }
00381 
00382    if (target == ST_TEXTURE_2D) {
00383       texObj = texUnit->Current2D;
00384       texImage = _mesa_get_tex_image(ctx, texObj, GL_TEXTURE_2D, level);
00385       stImage = st_texture_image(texImage);
00386    }
00387    else {
00388       /* unsupported target */
00389       return 0;
00390    }
00391 
00392    st_flush(ctx->st, PIPE_FLUSH_RENDER_CACHE, NULL);
00393 
00394    /* save the renderbuffer's surface/texture info */
00395    pipe_texture_reference(&strb->texture_save, strb->texture);
00396    pipe_surface_reference(&strb->surface_save, strb->surface);
00397 
00398    /* plug in new surface/texture info */
00399    pipe_texture_reference(&strb->texture, stImage->pt);
00400    strb->surface = screen->get_tex_surface(screen, strb->texture,
00401                                            face, level, slice,
00402                                            (PIPE_BUFFER_USAGE_GPU_READ |
00403                                             PIPE_BUFFER_USAGE_GPU_WRITE));
00404 
00405    st->dirty.st |= ST_NEW_FRAMEBUFFER;
00406 

void st_copy_context_state ( struct st_context dst,
struct st_context src,
uint  mask 
)

Definition at line 278 of file st_context.c.

References st_context::ctx.

00281 {
00282    _mesa_copy_context(dst->ctx, src->ctx, mask);
00283 }

struct st_context* st_create_context ( struct pipe_context pipe,
const __GLcontextModes *  visual,
struct st_context share 
) [read]

Definition at line 167 of file st_context.c.

References st_context::ctx, st_create_context_priv(), and st_init_driver_functions().

00170 {
00171    GLcontext *ctx;
00172    GLcontext *shareCtx = share ? share->ctx : NULL;
00173    struct dd_function_table funcs;
00174 
00175    memset(&funcs, 0, sizeof(funcs));
00176    st_init_driver_functions(&funcs);
00177 
00178    ctx = _mesa_create_context(visual, shareCtx, &funcs, NULL);
00179 
00180    return st_create_context_priv(ctx, pipe);
00181 }

struct st_framebuffer* st_create_framebuffer ( const __GLcontextModes *  visual,
enum pipe_format  colorFormat,
enum pipe_format  depthFormat,
enum pipe_format  stencilFormat,
uint  width,
uint  height,
void *  privateData 
) [read]

Definition at line 45 of file st_framebuffer.c.

References st_framebuffer::Base, CALLOC_STRUCT, DEFAULT_ACCUM_PIPE_FORMAT, st_framebuffer::InitHeight, st_framebuffer::InitWidth, PIPE_FORMAT_NONE, st_framebuffer::Private, st_get_msaa(), and st_new_renderbuffer_fb().

00051 {
00052    struct st_framebuffer *stfb = CALLOC_STRUCT(st_framebuffer);
00053    if (stfb) {
00054       int samples = st_get_msaa();
00055 
00056       if (visual->sampleBuffers)
00057          samples = visual->samples;
00058 
00059       _mesa_initialize_framebuffer(&stfb->Base, visual);
00060 
00061       {
00062          /* fake frontbuffer */
00063          /* XXX allocation should only happen in the unusual case
00064             it's actually needed */
00065          struct gl_renderbuffer *rb
00066             = st_new_renderbuffer_fb(colorFormat, samples);
00067          _mesa_add_renderbuffer(&stfb->Base, BUFFER_FRONT_LEFT, rb);
00068       }
00069 
00070       if (visual->doubleBufferMode) {
00071          struct gl_renderbuffer *rb
00072             = st_new_renderbuffer_fb(colorFormat, samples);
00073          _mesa_add_renderbuffer(&stfb->Base, BUFFER_BACK_LEFT, rb);
00074       }
00075 
00076       if (depthFormat == stencilFormat && depthFormat != PIPE_FORMAT_NONE) {
00077          /* combined depth/stencil buffer */
00078          struct gl_renderbuffer *depthStencilRb
00079             = st_new_renderbuffer_fb(depthFormat, samples);
00080          /* note: bind RB to two attachment points */
00081          _mesa_add_renderbuffer(&stfb->Base, BUFFER_DEPTH, depthStencilRb);
00082          _mesa_add_renderbuffer(&stfb->Base, BUFFER_STENCIL, depthStencilRb);
00083       }
00084       else {
00085          /* separate depth and/or stencil */
00086 
00087          if (visual->depthBits == 32) {
00088             /* 32-bit depth buffer */
00089             struct gl_renderbuffer *depthRb
00090                = st_new_renderbuffer_fb(depthFormat, samples);
00091             _mesa_add_renderbuffer(&stfb->Base, BUFFER_DEPTH, depthRb);
00092          }
00093          else if (visual->depthBits == 24) {
00094             /* 24-bit depth buffer, ignore stencil bits */
00095             struct gl_renderbuffer *depthRb
00096                = st_new_renderbuffer_fb(depthFormat, samples);
00097             _mesa_add_renderbuffer(&stfb->Base, BUFFER_DEPTH, depthRb);
00098          }
00099          else if (visual->depthBits > 0) {
00100             /* 16-bit depth buffer */
00101             struct gl_renderbuffer *depthRb
00102                = st_new_renderbuffer_fb(depthFormat, samples);
00103             _mesa_add_renderbuffer(&stfb->Base, BUFFER_DEPTH, depthRb);
00104          }
00105 
00106          if (visual->stencilBits > 0) {
00107             /* 8-bit stencil */
00108             struct gl_renderbuffer *stencilRb
00109                = st_new_renderbuffer_fb(stencilFormat, samples);
00110             _mesa_add_renderbuffer(&stfb->Base, BUFFER_STENCIL, stencilRb);
00111          }
00112       }
00113 
00114       if (visual->accumRedBits > 0) {
00115          /* 16-bit/channel accum */
00116          struct gl_renderbuffer *accumRb
00117             = st_new_renderbuffer_fb(DEFAULT_ACCUM_PIPE_FORMAT, 0); /* XXX accum isn't multisampled right? */
00118          _mesa_add_renderbuffer(&stfb->Base, BUFFER_ACCUM, accumRb);
00119       }
00120 
00121       stfb->Base.Initialized = GL_TRUE;
00122       stfb->InitWidth = width;
00123       stfb->InitHeight = height;
00124       stfb->Private = private;
00125    }
00126    return stfb;
00127 }

void st_destroy_context ( struct st_context st  ) 

Definition at line 225 of file st_context.c.

References st_context::cache, st_context::cso_context, cso_destroy_context(), cso_release_all(), st_context::ctx, pipe_context::destroy, st_context::fp, st_context::pipe, st_context::pixel_xfer, st_destroy_context_priv(), st_reference_fragprog(), st_reference_vertprog(), and st_context::vp.

00226 {
00227    struct pipe_context *pipe = st->pipe;
00228    struct cso_context *cso = st->cso_context;
00229    GLcontext *ctx = st->ctx;
00230 
00231    /* need to unbind and destroy CSO objects before anything else */
00232    cso_release_all(st->cso_context);
00233 
00234    st_reference_fragprog(st, &st->fp, NULL);
00235    st_reference_vertprog(st, &st->vp, NULL);
00236 
00237    _mesa_delete_program_cache(st->ctx, st->pixel_xfer.cache);
00238 
00239    _vbo_DestroyContext(st->ctx);
00240 
00241    _mesa_free_context_data(ctx);
00242 
00243    st_destroy_context_priv(st);
00244 
00245    cso_destroy_context(cso);
00246 
00247    pipe->destroy( pipe );
00248 
00249    free(ctx);
00250 }

void st_finish ( struct st_context st  ) 

Flush, and wait for completion.

Definition at line 99 of file st_cb_flush.c.

References pipe_winsys::fence_finish, pipe_winsys::fence_reference, st_context::pipe, PIPE_FLUSH_FRAME, PIPE_FLUSH_RENDER_CACHE, st_flush(), and pipe_context::winsys.

00100 {
00101    struct pipe_fence_handle *fence = NULL;
00102 
00103    st_flush(st, PIPE_FLUSH_RENDER_CACHE | PIPE_FLUSH_FRAME, &fence);
00104 
00105    if(fence) {
00106       st->pipe->winsys->fence_finish(st->pipe->winsys, fence, 0);
00107       st->pipe->winsys->fence_reference(st->pipe->winsys, &fence, NULL);
00108    }
00109 }

void st_flush ( struct st_context st,
uint  pipeFlushFlags,
struct pipe_fence_handle **  fence 
)

Definition at line 79 of file st_cb_flush.c.

References st_context::blit, st_context::ctx, pipe_context::flush, st_context::gen_mipmap, st_context::pipe, st_flush_bitmap(), st_flush_clear(), util_blit_flush(), and util_gen_mipmap_flush().

00081 {
00082    FLUSH_VERTICES(st->ctx, 0);
00083 
00084    /* Release any vertex buffers that might potentially be accessed in
00085     * successive frames:
00086     */
00087    st_flush_bitmap(st);
00088    st_flush_clear(st);
00089    util_blit_flush(st->blit);
00090    util_gen_mipmap_flush(st->gen_mipmap);
00091 
00092    st->pipe->flush( st->pipe, pipeFlushFlags, fence );
00093 }

void* st_framebuffer_private ( struct st_framebuffer stfb  ) 

Definition at line 302 of file st_framebuffer.c.

References st_framebuffer::Private.

00303 {
00304    return stfb->Private;
00305 }

struct pipe_surface* st_get_framebuffer_surface ( struct st_framebuffer stfb,
uint  surfIndex 
) [read]

Return the pipe_surface for the given renderbuffer.

Definition at line 222 of file st_framebuffer.c.

References assert, st_framebuffer::Base, st_renderbuffer(), ST_SURFACE_BACK_RIGHT, ST_SURFACE_DEPTH, ST_SURFACE_FRONT_LEFT, and st_renderbuffer::surface.

00223 {
00224    struct st_renderbuffer *strb;
00225 
00226    assert(surfIndex <= ST_SURFACE_DEPTH);
00227 
00228    /* sanity checks, ST tokens should match Mesa tokens */
00229    assert(ST_SURFACE_FRONT_LEFT == BUFFER_FRONT_LEFT);
00230    assert(ST_SURFACE_BACK_RIGHT == BUFFER_BACK_RIGHT);
00231 
00232    strb = st_renderbuffer(stfb->Base.Attachment[surfIndex].Renderbuffer);
00233    if (strb)
00234       return strb->surface;
00235    return NULL;
00236 }

struct pipe_texture* st_get_framebuffer_texture ( struct st_framebuffer stfb,
uint  surfIndex 
) [read]

Definition at line 239 of file st_framebuffer.c.

References assert, st_framebuffer::Base, st_renderbuffer(), ST_SURFACE_BACK_RIGHT, ST_SURFACE_DEPTH, ST_SURFACE_FRONT_LEFT, and st_renderbuffer::texture.

00240 {
00241    struct st_renderbuffer *strb;
00242 
00243    assert(surfIndex <= ST_SURFACE_DEPTH);
00244 
00245    /* sanity checks, ST tokens should match Mesa tokens */
00246    assert(ST_SURFACE_FRONT_LEFT == BUFFER_FRONT_LEFT);
00247    assert(ST_SURFACE_BACK_RIGHT == BUFFER_BACK_RIGHT);
00248 
00249    strb = st_renderbuffer(stfb->Base.Attachment[surfIndex].Renderbuffer);
00250    if (strb)
00251       return strb->texture;
00252    return NULL;
00253 }

st_proc st_get_proc_address ( const char *  procname  ) 

Definition at line 287 of file st_context.c.

00288 {
00289    return (st_proc) _glapi_get_proc_address(procname);
00290 }

void st_make_current ( struct st_context st,
struct st_framebuffer draw,
struct st_framebuffer read 
)

Definition at line 253 of file st_context.c.

References st_framebuffer::Base, st_context::ctx, st_framebuffer::InitHeight, and st_framebuffer::InitWidth.

00256 {
00257    if (st) {
00258       GLboolean firstTime = st->ctx->FirstTimeCurrent;
00259       _mesa_make_current(st->ctx, &draw->Base, &read->Base);
00260       /* Need to initialize viewport here since draw->Base->Width/Height
00261        * will still be zero at this point.
00262        * This could be improved, but would require rather extensive work
00263        * elsewhere (allocate rb surface storage sooner)
00264        */
00265       if (firstTime) {
00266          GLuint w = draw->InitWidth, h = draw->InitHeight;
00267          _mesa_set_viewport(st->ctx, 0, 0, w, h);
00268          _mesa_set_scissor(st->ctx, 0, 0, w, h);
00269 
00270       }
00271    }
00272    else {
00273       _mesa_make_current(NULL, NULL, NULL);
00274    }
00275 }

void st_notify_swapbuffers ( struct st_framebuffer stfb  ) 

This function is to be called prior to SwapBuffers on the given framebuffer.

It checks if the current context is bound to the framebuffer and flushes rendering if needed.

Definition at line 261 of file st_framebuffer.c.

References st_framebuffer::Base, FRONT_STATUS_COPY_OF_BACK, PIPE_FLUSH_FRAME, PIPE_FLUSH_RENDER_CACHE, PIPE_FLUSH_SWAPBUFFERS, and st_flush().

00262 {
00263    GET_CURRENT_CONTEXT(ctx);
00264 
00265    if (ctx && ctx->DrawBuffer == &stfb->Base) {
00266       st_flush( ctx->st, 
00267                 PIPE_FLUSH_RENDER_CACHE | 
00268                 PIPE_FLUSH_SWAPBUFFERS |
00269                 PIPE_FLUSH_FRAME,
00270                 NULL );
00271       ctx->st->frontbuffer_status = FRONT_STATUS_COPY_OF_BACK;
00272    }
00273 }

void st_notify_swapbuffers_complete ( struct st_framebuffer stfb  ) 

Quick hack - allows the winsys to inform the driver that surface states are now undefined after a glXSwapBuffers or similar.

Definition at line 281 of file st_framebuffer.c.

References st_framebuffer::Base, PIPE_SURFACE_STATUS_UNDEFINED, st_renderbuffer(), pipe_surface::status, and st_renderbuffer::surface.

00282 {
00283    GET_CURRENT_CONTEXT(ctx);
00284 
00285    if (ctx && ctx->DrawBuffer == &stfb->Base) {
00286       struct st_renderbuffer *strb;
00287 
00288       /* Mark back color buffers as undefined */
00289       strb = st_renderbuffer(stfb->Base.Attachment[BUFFER_BACK_LEFT].
00290                              Renderbuffer);
00291       if (strb && strb->surface)
00292          strb->surface->status = PIPE_SURFACE_STATUS_UNDEFINED;
00293 
00294       strb = st_renderbuffer(stfb->Base.Attachment[BUFFER_BACK_RIGHT].
00295                              Renderbuffer);
00296       if (strb && strb->surface)
00297          strb->surface->status = PIPE_SURFACE_STATUS_UNDEFINED;
00298    }
00299 }

int st_release_teximage ( struct st_framebuffer stfb,
uint  surfIndex,
int  target,
int  format,
int  level 
)

Undo surface-to-texture binding.

Definition at line 411 of file st_texture.c.

00415 {
00416    GET_CURRENT_CONTEXT(ctx);
00417    struct st_context *st = ctx->st;
00418    struct st_renderbuffer *strb;
00419 
00420    assert(surfIndex <= ST_SURFACE_DEPTH);
00421 
00422    strb = st_renderbuffer(stfb->Base.Attachment[surfIndex].Renderbuffer);
00423 
00424    if (!strb->texture_save || !strb->surface_save) {
00425       /* Error! */
00426       return 0;
00427    }
00428 
00429    st_flush(ctx->st, PIPE_FLUSH_RENDER_CACHE, NULL);
00430 
00431    /* free tex surface, restore original */
00432    pipe_surface_reference(&strb->surface, strb->surface_save);
00433    pipe_texture_reference(&strb->texture, strb->texture_save);
00434 
00435    pipe_surface_reference(&strb->surface_save, NULL);
00436    pipe_texture_reference(&strb->texture_save, NULL);
00437 
00438    st->dirty.st |= ST_NEW_FRAMEBUFFER;
00439 

void st_resize_framebuffer ( struct st_framebuffer stfb,
uint  width,
uint  height 
)

Definition at line 130 of file st_framebuffer.c.

References assert, st_framebuffer::Base, st_framebuffer::InitHeight, and st_framebuffer::InitWidth.

00132 {
00133    if (stfb->Base.Width != width || stfb->Base.Height != height) {
00134       GET_CURRENT_CONTEXT(ctx);
00135       if (ctx) {
00136          if (stfb->InitWidth == 0 && stfb->InitHeight == 0) {
00137             /* didn't have a valid size until now */
00138             stfb->InitWidth = width;
00139             stfb->InitHeight = height;
00140             if (ctx->Viewport.Width <= 1) {
00141                /* set context's initial viewport/scissor size */
00142                _mesa_set_viewport(ctx, 0, 0, width, height);
00143                _mesa_set_scissor(ctx, 0, 0, width, height);
00144             }
00145          }
00146 
00147          _mesa_resize_framebuffer(ctx, &stfb->Base, width, height);
00148 
00149          assert(stfb->Base.Width == width);
00150          assert(stfb->Base.Height == height);
00151       }
00152    }
00153 }

void st_set_framebuffer_surface ( struct st_framebuffer stfb,
uint  surfIndex,
struct pipe_surface surf 
)

Set/replace a framebuffer surface.

The user of the state tracker can use this instead of st_resize_framebuffer() to provide new surfaces when a window is resized.

Definition at line 169 of file st_framebuffer.c.

References assert, st_renderbuffer::Base, st_framebuffer::Base, pipe_surface::height, pipe_surface_reference(), pipe_texture_reference(), st_renderbuffer(), st_renderbuffer::surface, pipe_surface::texture, st_renderbuffer::texture, and pipe_surface::width.

00171 {
00172    static const GLuint invalid_size = 9999999;
00173    struct st_renderbuffer *strb;
00174    GLuint width, height, i;
00175 
00176    assert(surfIndex < BUFFER_COUNT);
00177 
00178    strb = st_renderbuffer(stfb->Base.Attachment[surfIndex].Renderbuffer);
00179    assert(strb);
00180 
00181    /* replace the renderbuffer's surface/texture pointers */
00182    pipe_surface_reference( &strb->surface, surf );
00183    pipe_texture_reference( &strb->texture, surf->texture );
00184 
00185    /* update renderbuffer's width/height */
00186    strb->Base.Width = surf->width;
00187    strb->Base.Height = surf->height;
00188 
00189    /* Try to update the framebuffer's width/height from the renderbuffer
00190     * sizes.  Before we start drawing, all the rbs _should_ be the same size.
00191     */
00192    width = height = invalid_size;
00193    for (i = 0; i < BUFFER_COUNT; i++) {
00194       if (stfb->Base.Attachment[i].Renderbuffer) {
00195          if (width == invalid_size) {
00196             width = stfb->Base.Attachment[i].Renderbuffer->Width;
00197             height = stfb->Base.Attachment[i].Renderbuffer->Height;
00198          }
00199          else if (width != stfb->Base.Attachment[i].Renderbuffer->Width ||
00200                   height != stfb->Base.Attachment[i].Renderbuffer->Height) {
00201             /* inconsistant renderbuffer sizes, bail out */
00202             return;
00203          }
00204       }
00205    }
00206 
00207    if (width != invalid_size) {
00208       /* OK, the renderbuffers are of a consistant size, so update the
00209        * parent framebuffer's size.
00210        */
00211       stfb->Base.Width = width;
00212       stfb->Base.Height = height;
00213    }
00214 }

void st_unreference_framebuffer ( struct st_framebuffer **  stfb  ) 

Definition at line 156 of file st_framebuffer.c.

00157 {
00158    _mesa_unreference_framebuffer((struct gl_framebuffer **) stfb);
00159 }


Generated on Tue Sep 29 06:25:55 2009 for Gallium3D by  doxygen 1.5.4