Sketch out new create/destroy context functions which create/wrap a Mesa context.
[mesa.git] / src / mesa / state_tracker / st_context.c
1 /**************************************************************************
2 *
3 * Copyright 2003 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_program.h"
49 #include "pipe/p_context.h"
50 #include "pipe/draw/draw_context.h"
51 #include "pipe/cso_cache/cso_cache.h"
52
53
54 /**
55 * Called via ctx->Driver.UpdateState()
56 */
57 void st_invalidate_state(GLcontext * ctx, GLuint new_state)
58 {
59 struct st_context *st = st_context(ctx);
60
61 st->dirty.mesa |= new_state;
62 st->dirty.st |= ST_NEW_MESA;
63
64 /* This is the only core Mesa module we depend upon.
65 * No longer use swrast, swsetup, tnl.
66 */
67 _vbo_InvalidateState(ctx, new_state);
68 }
69
70
71 struct st_context *st_create_context2(struct pipe_context *pipe,
72 const GLvisual *visual,
73 struct st_context *share)
74 {
75 GLcontext *ctx;
76 GLcontext *shareCtx = share ? share->ctx : NULL;
77 struct dd_function_table funcs;
78
79 memset(&funcs, 0, sizeof(funcs));
80 st_init_driver_functions(&funcs);
81
82 ctx = _mesa_create_context(visual, shareCtx, &funcs, NULL);
83
84 return st_create_context(ctx, pipe);
85 }
86
87
88 struct st_context *st_create_context( GLcontext *ctx,
89 struct pipe_context *pipe )
90 {
91 struct st_context *st = CALLOC_STRUCT( st_context );
92
93 ctx->st = st;
94
95 st->ctx = ctx;
96 st->pipe = pipe;
97
98 /* state tracker needs the VBO module */
99 _vbo_CreateContext(ctx);
100
101 st->draw = draw_create(); /* for selection/feedback */
102
103 st->dirty.mesa = ~0;
104 st->dirty.st = ~0;
105
106 st->cache = cso_cache_create();
107
108 st_init_atoms( st );
109 st_init_draw( st );
110
111 /* we want all vertex data to be placed in buffer objects */
112 vbo_use_buffer_objects(ctx);
113
114 /* Need these flags:
115 */
116 st->ctx->FragmentProgram._MaintainTexEnvProgram = GL_TRUE;
117 st->ctx->FragmentProgram._UseTexEnvProgram = GL_TRUE;
118
119 st->ctx->VertexProgram._MaintainTnlProgram = GL_TRUE;
120
121 st->haveFramebufferRegions = GL_TRUE;
122
123 st->pixel_xfer.cache = _mesa_new_program_cache();
124
125 /* XXXX This is temporary! */
126 _mesa_enable_sw_extensions(ctx);
127
128 return st;
129 }
130
131
132 void st_destroy_context2( struct st_context *st )
133 {
134 GLcontext *ctx = st->ctx;
135 _mesa_free_context_data(ctx);
136 st_destroy_context(st);
137 free(ctx);
138 }
139
140
141 void st_destroy_context( struct st_context *st )
142 {
143 draw_destroy(st->draw);
144 st_destroy_atoms( st );
145 st_destroy_draw( st );
146
147 _vbo_DestroyContext(st->ctx);
148
149 cso_cache_delete( st->cache );
150
151 _mesa_delete_program_cache(st->ctx, st->pixel_xfer.cache);
152
153 st->pipe->destroy( st->pipe );
154 FREE( st );
155 }
156
157
158
159 void st_init_driver_functions(struct dd_function_table *functions)
160 {
161 st_init_accum_functions(functions);
162 st_init_bufferobject_functions(functions);
163 st_init_clear_functions(functions);
164 st_init_drawpixels_functions(functions);
165 st_init_fbo_functions(functions);
166 st_init_feedback_functions(functions);
167 st_init_program_functions(functions);
168 st_init_query_functions(functions);
169 st_init_rasterpos_functions(functions);
170 st_init_readpixels_functions(functions);
171 st_init_texture_functions(functions);
172 st_init_flush_functions(functions);
173 st_init_string_functions(functions);
174
175 functions->UpdateState = st_invalidate_state;
176 }