st_context.c revision c6499a741c99394e81d1d86ffd066f3d9749875c
1/************************************************************************** 2 * 3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. 4 * All Rights Reserved. 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a 7 * copy of this software and associated documentation files (the 8 * "Software"), to deal in the Software without restriction, including 9 * without limitation the rights to use, copy, modify, merge, publish, 10 * distribute, sub license, and/or sell copies of the Software, and to 11 * permit persons to whom the Software is furnished to do so, subject to 12 * the following conditions: 13 * 14 * The above copyright notice and this permission notice (including the 15 * next paragraph) shall be included in all copies or substantial portions 16 * of the Software. 17 * 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR 22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 * 26 **************************************************************************/ 27 28#include "main/imports.h" 29#include "main/context.h" 30#include "main/extensions.h" 31#include "vbo/vbo.h" 32#include "st_public.h" 33#include "st_context.h" 34#include "st_cb_accum.h" 35#include "st_cb_bufferobjects.h" 36#include "st_cb_clear.h" 37#include "st_cb_drawpixels.h" 38#include "st_cb_fbo.h" 39#include "st_cb_feedback.h" 40#include "st_cb_queryobj.h" 41#include "st_cb_rasterpos.h" 42#include "st_cb_readpixels.h" 43#include "st_cb_texture.h" 44#include "st_cb_flush.h" 45#include "st_cb_strings.h" 46#include "st_atom.h" 47#include "st_draw.h" 48#include "st_extensions.h" 49#include "st_program.h" 50#include "pipe/p_context.h" 51#include "pipe/draw/draw_context.h" 52#include "pipe/cso_cache/cso_cache.h" 53 54 55/** 56 * Called via ctx->Driver.UpdateState() 57 */ 58void st_invalidate_state(GLcontext * ctx, GLuint new_state) 59{ 60 struct st_context *st = st_context(ctx); 61 62 st->dirty.mesa |= new_state; 63 st->dirty.st |= ST_NEW_MESA; 64 65 /* This is the only core Mesa module we depend upon. 66 * No longer use swrast, swsetup, tnl. 67 */ 68 _vbo_InvalidateState(ctx, new_state); 69} 70 71 72static struct st_context * 73st_create_context_priv( GLcontext *ctx, struct pipe_context *pipe ) 74{ 75 struct st_context *st = CALLOC_STRUCT( st_context ); 76 77 ctx->st = st; 78 79 st->ctx = ctx; 80 st->pipe = pipe; 81 82 /* state tracker needs the VBO module */ 83 _vbo_CreateContext(ctx); 84 85 st->draw = draw_create(); /* for selection/feedback */ 86 87 st->dirty.mesa = ~0; 88 st->dirty.st = ~0; 89 90 st->cache = cso_cache_create(); 91 92 st_init_atoms( st ); 93 st_init_draw( st ); 94 95 /* we want all vertex data to be placed in buffer objects */ 96 vbo_use_buffer_objects(ctx); 97 98 /* Need these flags: 99 */ 100 st->ctx->FragmentProgram._MaintainTexEnvProgram = GL_TRUE; 101 st->ctx->FragmentProgram._UseTexEnvProgram = GL_TRUE; 102 103 st->ctx->VertexProgram._MaintainTnlProgram = GL_TRUE; 104 105 st->haveFramebufferRegions = GL_TRUE; 106 107 st->pixel_xfer.cache = _mesa_new_program_cache(); 108 109 /* GL limits and extensions */ 110 st_init_limits(st); 111 st_init_extensions(st); 112 113 return st; 114} 115 116 117struct st_context *st_create_context(struct pipe_context *pipe, 118 const __GLcontextModes *visual, 119 struct st_context *share) 120{ 121 GLcontext *ctx; 122 GLcontext *shareCtx = share ? share->ctx : NULL; 123 struct dd_function_table funcs; 124 125 memset(&funcs, 0, sizeof(funcs)); 126 st_init_driver_functions(&funcs); 127 128 ctx = _mesa_create_context(visual, shareCtx, &funcs, NULL); 129 130 return st_create_context_priv(ctx, pipe); 131} 132 133 134static void st_destroy_context_priv( struct st_context *st ) 135{ 136 draw_destroy(st->draw); 137 st_destroy_atoms( st ); 138 st_destroy_draw( st ); 139 140 _vbo_DestroyContext(st->ctx); 141 142 cso_cache_delete( st->cache ); 143 144 _mesa_delete_program_cache(st->ctx, st->pixel_xfer.cache); 145 146 st->pipe->destroy( st->pipe ); 147 free( st ); 148} 149 150 151void st_destroy_context( struct st_context *st ) 152{ 153 GLcontext *ctx = st->ctx; 154 _mesa_free_context_data(ctx); 155 st_destroy_context_priv(st); 156 free(ctx); 157} 158 159 160void st_make_current(struct st_context *st, 161 struct st_framebuffer *draw, 162 struct st_framebuffer *read) 163{ 164 if (st) { 165 _mesa_make_current(st->ctx, &draw->Base, &read->Base); 166 } 167 else { 168 _mesa_make_current(NULL, NULL, NULL); 169 } 170} 171 172 173void st_copy_context_state(struct st_context *dst, 174 struct st_context *src, 175 uint mask) 176{ 177 _mesa_copy_context(dst->ctx, src->ctx, mask); 178} 179 180 181void st_init_driver_functions(struct dd_function_table *functions) 182{ 183 st_init_accum_functions(functions); 184 st_init_bufferobject_functions(functions); 185 st_init_clear_functions(functions); 186 st_init_drawpixels_functions(functions); 187 st_init_fbo_functions(functions); 188 st_init_feedback_functions(functions); 189 st_init_program_functions(functions); 190 st_init_query_functions(functions); 191 st_init_rasterpos_functions(functions); 192 st_init_readpixels_functions(functions); 193 st_init_texture_functions(functions); 194 st_init_flush_functions(functions); 195 st_init_string_functions(functions); 196 197 functions->UpdateState = st_invalidate_state; 198} 199