1 /**************************************************************************
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
28 #include "main/imports.h"
29 #include "main/context.h"
30 #include "main/extensions.h"
32 #include "drivers/common/driverfuncs.h"
33 #include "st_public.h"
34 #include "st_context.h"
35 #include "st_cb_accum.h"
36 #include "st_cb_bufferobjects.h"
37 #include "st_cb_clear.h"
38 #include "st_cb_drawpixels.h"
39 #include "st_cb_fbo.h"
40 #include "st_cb_feedback.h"
41 #include "st_cb_queryobj.h"
42 #include "st_cb_rasterpos.h"
43 #include "st_cb_readpixels.h"
44 #include "st_cb_texture.h"
45 #include "st_cb_flush.h"
46 #include "st_cb_strings.h"
49 #include "st_extensions.h"
50 #include "st_program.h"
51 #include "pipe/p_context.h"
52 #include "pipe/draw/draw_context.h"
53 #include "pipe/cso_cache/cso_cache.h"
57 * Called via ctx->Driver.UpdateState()
59 void st_invalidate_state(GLcontext
* ctx
, GLuint new_state
)
61 struct st_context
*st
= st_context(ctx
);
63 st
->dirty
.mesa
|= new_state
;
64 st
->dirty
.st
|= ST_NEW_MESA
;
66 /* This is the only core Mesa module we depend upon.
67 * No longer use swrast, swsetup, tnl.
69 _vbo_InvalidateState(ctx
, new_state
);
73 static struct st_context
*
74 st_create_context_priv( GLcontext
*ctx
, struct pipe_context
*pipe
)
76 struct st_context
*st
= CALLOC_STRUCT( st_context
);
83 /* state tracker needs the VBO module */
84 _vbo_CreateContext(ctx
);
86 st
->draw
= draw_create(); /* for selection/feedback */
91 st
->cache
= cso_cache_create();
96 /* we want all vertex data to be placed in buffer objects */
97 vbo_use_buffer_objects(ctx
);
101 st
->ctx
->FragmentProgram
._MaintainTexEnvProgram
= GL_TRUE
;
102 st
->ctx
->FragmentProgram
._UseTexEnvProgram
= GL_TRUE
;
104 st
->ctx
->VertexProgram
._MaintainTnlProgram
= GL_TRUE
;
106 st
->haveFramebufferSurfaces
= GL_TRUE
;
108 st
->pixel_xfer
.cache
= _mesa_new_program_cache();
110 /* GL limits and extensions */
112 st_init_extensions(st
);
118 struct st_context
*st_create_context(struct pipe_context
*pipe
,
119 const __GLcontextModes
*visual
,
120 struct st_context
*share
)
123 GLcontext
*shareCtx
= share
? share
->ctx
: NULL
;
124 struct dd_function_table funcs
;
126 memset(&funcs
, 0, sizeof(funcs
));
127 st_init_driver_functions(&funcs
);
129 ctx
= _mesa_create_context(visual
, shareCtx
, &funcs
, NULL
);
131 return st_create_context_priv(ctx
, pipe
);
135 static void st_destroy_context_priv( struct st_context
*st
)
137 draw_destroy(st
->draw
);
138 st_destroy_atoms( st
);
139 st_destroy_draw( st
);
141 _vbo_DestroyContext(st
->ctx
);
143 cso_cache_delete( st
->cache
);
145 _mesa_delete_program_cache(st
->ctx
, st
->pixel_xfer
.cache
);
147 st
->pipe
->destroy( st
->pipe
);
152 void st_destroy_context( struct st_context
*st
)
154 GLcontext
*ctx
= st
->ctx
;
155 _mesa_free_context_data(ctx
);
156 st_destroy_context_priv(st
);
161 void st_make_current(struct st_context
*st
,
162 struct st_framebuffer
*draw
,
163 struct st_framebuffer
*read
)
166 _mesa_make_current(st
->ctx
, &draw
->Base
, &read
->Base
);
169 _mesa_make_current(NULL
, NULL
, NULL
);
174 void st_copy_context_state(struct st_context
*dst
,
175 struct st_context
*src
,
178 _mesa_copy_context(dst
->ctx
, src
->ctx
, mask
);
182 void st_init_driver_functions(struct dd_function_table
*functions
)
184 _mesa_init_glsl_driver_functions(functions
);
186 st_init_accum_functions(functions
);
187 st_init_bufferobject_functions(functions
);
188 st_init_clear_functions(functions
);
189 st_init_drawpixels_functions(functions
);
190 st_init_fbo_functions(functions
);
191 st_init_feedback_functions(functions
);
192 st_init_program_functions(functions
);
193 st_init_query_functions(functions
);
194 st_init_rasterpos_functions(functions
);
195 st_init_readpixels_functions(functions
);
196 st_init_texture_functions(functions
);
197 st_init_flush_functions(functions
);
198 st_init_string_functions(functions
);
200 functions
->UpdateState
= st_invalidate_state
;