st_context.c

Go to the documentation of this file.
00001 /**************************************************************************
00002  * 
00003  * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
00004  * All Rights Reserved.
00005  * 
00006  * Permission is hereby granted, free of charge, to any person obtaining a
00007  * copy of this software and associated documentation files (the
00008  * "Software"), to deal in the Software without restriction, including
00009  * without limitation the rights to use, copy, modify, merge, publish,
00010  * distribute, sub license, and/or sell copies of the Software, and to
00011  * permit persons to whom the Software is furnished to do so, subject to
00012  * the following conditions:
00013  * 
00014  * The above copyright notice and this permission notice (including the
00015  * next paragraph) shall be included in all copies or substantial portions
00016  * of the Software.
00017  * 
00018  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00019  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00020  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
00021  * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
00022  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
00023  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
00024  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00025  * 
00026  **************************************************************************/
00027 
00028 #include "main/imports.h"
00029 #include "main/context.h"
00030 #include "main/extensions.h"
00031 #include "main/matrix.h"
00032 #include "main/buffers.h"
00033 #include "main/scissor.h"
00034 #include "vbo/vbo.h"
00035 #include "shader/shader_api.h"
00036 #include "glapi/glapi.h"
00037 #include "st_public.h"
00038 #include "st_context.h"
00039 #include "st_cb_accum.h"
00040 #include "st_cb_bitmap.h"
00041 #include "st_cb_blit.h"
00042 #include "st_cb_bufferobjects.h"
00043 #include "st_cb_clear.h"
00044 #if FEATURE_drawpix
00045 #include "st_cb_drawpixels.h"
00046 #include "st_cb_rasterpos.h"
00047 #endif
00048 #ifdef FEATURE_OES_draw_texture
00049 #include "st_cb_drawtex.h"
00050 #endif
00051 #include "st_cb_fbo.h"
00052 #include "st_cb_get.h"
00053 #if FEATURE_feedback
00054 #include "st_cb_feedback.h"
00055 #endif
00056 #include "st_cb_program.h"
00057 #include "st_cb_queryobj.h"
00058 #include "st_cb_readpixels.h"
00059 #include "st_cb_texture.h"
00060 #include "st_cb_flush.h"
00061 #include "st_cb_strings.h"
00062 #include "st_atom.h"
00063 #include "st_draw.h"
00064 #include "st_extensions.h"
00065 #include "st_gen_mipmap.h"
00066 #include "st_program.h"
00067 #include "pipe/p_context.h"
00068 #include "pipe/p_inlines.h"
00069 #include "draw/draw_context.h"
00070 #include "cso_cache/cso_cache.h"
00071 #include "cso_cache/cso_context.h"
00072 
00073 
00077 void st_invalidate_state(GLcontext * ctx, GLuint new_state)
00078 {
00079    struct st_context *st = st_context(ctx);
00080 
00081    st->dirty.mesa |= new_state;
00082    st->dirty.st |= ST_NEW_MESA;
00083 
00084    /* This is the only core Mesa module we depend upon.
00085     * No longer use swrast, swsetup, tnl.
00086     */
00087    _vbo_InvalidateState(ctx, new_state);
00088 }
00089 
00090 
00094 int
00095 st_get_msaa(void)
00096 {
00097    const char *msaa = _mesa_getenv("__GL_FSAA_MODE");
00098    if (msaa)
00099       return atoi(msaa);
00100    return 0;
00101 }
00102 
00103 
00104 static struct st_context *
00105 st_create_context_priv( GLcontext *ctx, struct pipe_context *pipe )
00106 {
00107    uint i;
00108    struct st_context *st = CALLOC_STRUCT( st_context );
00109    
00110    ctx->st = st;
00111 
00112    st->ctx = ctx;
00113    st->pipe = pipe;
00114 
00115    /* state tracker needs the VBO module */
00116    _vbo_CreateContext(ctx);
00117 
00118 #if FEATURE_feedback || FEATURE_drawpix
00119    st->draw = draw_create(); /* for selection/feedback */
00120 
00121    /* Disable draw options that might convert points/lines to tris, etc.
00122     * as that would foul-up feedback/selection mode.
00123     */
00124    draw_wide_line_threshold(st->draw, 1000.0f);
00125    draw_wide_point_threshold(st->draw, 1000.0f);
00126    draw_enable_line_stipple(st->draw, FALSE);
00127    draw_enable_point_sprites(st->draw, FALSE);
00128 #endif
00129 
00130    st->dirty.mesa = ~0;
00131    st->dirty.st = ~0;
00132 
00133    st->cso_context = cso_create_context(pipe);
00134 
00135    st_init_atoms( st );
00136    st_init_bitmap(st);
00137    st_init_clear(st);
00138    st_init_draw( st );
00139    st_init_generate_mipmap(st);
00140    st_init_blit(st);
00141 
00142    for (i = 0; i < PIPE_MAX_SAMPLERS; i++)
00143       st->state.sampler_list[i] = &st->state.samplers[i];
00144 
00145    /* we want all vertex data to be placed in buffer objects */
00146    vbo_use_buffer_objects(ctx);
00147 
00148    /* Need these flags:
00149     */
00150    st->ctx->FragmentProgram._MaintainTexEnvProgram = GL_TRUE;
00151    st->ctx->FragmentProgram._UseTexEnvProgram = GL_TRUE;
00152 
00153    st->ctx->VertexProgram._MaintainTnlProgram = GL_TRUE;
00154 
00155    st->pixel_xfer.cache = _mesa_new_program_cache();
00156 
00157    st->force_msaa = st_get_msaa();
00158 
00159    /* GL limits and extensions */
00160    st_init_limits(st);
00161    st_init_extensions(st);
00162 
00163    return st;
00164 }
00165 
00166 
00167 struct st_context *st_create_context(struct pipe_context *pipe,
00168                                      const __GLcontextModes *visual,
00169                                      struct st_context *share)
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 }
00182 
00183 
00184 static void st_destroy_context_priv( struct st_context *st )
00185 {
00186    uint i;
00187 
00188 #if FEATURE_feedback || FEATURE_drawpix
00189    draw_destroy(st->draw);
00190 #endif
00191    st_destroy_atoms( st );
00192    st_destroy_draw( st );
00193    st_destroy_generate_mipmap(st);
00194 #if FEATURE_EXT_framebuffer_blit
00195    st_destroy_blit(st);
00196 #endif
00197    st_destroy_clear(st);
00198 #if FEATURE_drawpix
00199    st_destroy_bitmap(st);
00200    st_destroy_drawpix(st);
00201 #endif
00202 #ifdef FEATURE_OES_draw_texture
00203    st_destroy_drawtex(st);
00204 #endif
00205 
00206    for (i = 0; i < Elements(st->state.sampler_texture); i++) {
00207       pipe_texture_reference(&st->state.sampler_texture[i], NULL);
00208    }
00209 
00210    for (i = 0; i < Elements(st->state.constants); i++) {
00211       if (st->state.constants[i].buffer) {
00212          pipe_buffer_reference(st->pipe->screen, &st->state.constants[i].buffer, NULL);
00213       }
00214    }
00215 
00216    if (st->default_texture) {
00217       st->ctx->Driver.DeleteTexture(st->ctx, st->default_texture);
00218       st->default_texture = NULL;
00219    }
00220 
00221    free( st );
00222 }
00223 
00224  
00225 void st_destroy_context( struct st_context *st )
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 }
00251 
00252 
00253 void st_make_current(struct st_context *st,
00254                      struct st_framebuffer *draw,
00255                      struct st_framebuffer *read)
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 }
00276 
00277 
00278 void st_copy_context_state(struct st_context *dst,
00279                            struct st_context *src,
00280                            uint mask)
00281 {
00282    _mesa_copy_context(dst->ctx, src->ctx, mask);
00283 }
00284 
00285 
00286 
00287 st_proc st_get_proc_address(const char *procname)
00288 {
00289    return (st_proc) _glapi_get_proc_address(procname);
00290 }
00291 
00292 
00293 
00294 void st_init_driver_functions(struct dd_function_table *functions)
00295 {
00296    _mesa_init_glsl_driver_functions(functions);
00297 
00298 #if FEATURE_accum
00299    st_init_accum_functions(functions);
00300 #endif
00301 #if FEATURE_EXT_framebuffer_blit
00302    st_init_blit_functions(functions);
00303 #endif
00304    st_init_bufferobject_functions(functions);
00305    st_init_clear_functions(functions);
00306 #if FEATURE_drawpix
00307    st_init_bitmap_functions(functions);
00308    st_init_drawpixels_functions(functions);
00309    st_init_rasterpos_functions(functions);
00310 #endif
00311    st_init_fbo_functions(functions);
00312    st_init_get_functions(functions);
00313 #if FEATURE_feedback
00314    st_init_feedback_functions(functions);
00315 #endif
00316    st_init_program_functions(functions);
00317 #if FEATURE_ARB_occlusion_query
00318    st_init_query_functions(functions);
00319 #endif
00320    st_init_readpixels_functions(functions);
00321    st_init_texture_functions(functions);
00322    st_init_flush_functions(functions);
00323    st_init_string_functions(functions);
00324 
00325    functions->UpdateState = st_invalidate_state;
00326 }

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