gallium: remove some debug assertions in vertex format validation
[mesa.git] / src / mesa / state_tracker / st_context.c
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 "main/matrix.h"
32 #include "main/buffers.h"
33 #include "vbo/vbo.h"
34 #include "shader/shader_api.h"
35 #include "st_public.h"
36 #include "st_context.h"
37 #include "st_cb_accum.h"
38 #include "st_cb_bufferobjects.h"
39 #include "st_cb_clear.h"
40 #include "st_cb_drawpixels.h"
41 #include "st_cb_fbo.h"
42 #include "st_cb_feedback.h"
43 #include "st_cb_queryobj.h"
44 #include "st_cb_rasterpos.h"
45 #include "st_cb_readpixels.h"
46 #include "st_cb_texture.h"
47 #include "st_cb_flush.h"
48 #include "st_cb_strings.h"
49 #include "st_atom.h"
50 #include "st_draw.h"
51 #include "st_extensions.h"
52 #include "st_gen_mipmap.h"
53 #include "st_program.h"
54 #include "pipe/p_context.h"
55 #include "pipe/p_winsys.h"
56 #include "pipe/p_inlines.h"
57 #include "pipe/draw/draw_context.h"
58 #include "pipe/cso_cache/cso_cache.h"
59
60
61 /**
62 * Called via ctx->Driver.UpdateState()
63 */
64 void st_invalidate_state(GLcontext * ctx, GLuint new_state)
65 {
66 struct st_context *st = st_context(ctx);
67
68 st->dirty.mesa |= new_state;
69 st->dirty.st |= ST_NEW_MESA;
70
71 /* This is the only core Mesa module we depend upon.
72 * No longer use swrast, swsetup, tnl.
73 */
74 _vbo_InvalidateState(ctx, new_state);
75 }
76
77
78 static struct st_context *
79 st_create_context_priv( GLcontext *ctx, struct pipe_context *pipe )
80 {
81 struct st_context *st = CALLOC_STRUCT( st_context );
82
83 ctx->st = st;
84
85 st->ctx = ctx;
86 st->pipe = pipe;
87
88 /* state tracker needs the VBO module */
89 _vbo_CreateContext(ctx);
90
91 st->draw = draw_create(); /* for selection/feedback */
92
93 st->dirty.mesa = ~0;
94 st->dirty.st = ~0;
95
96 st->cache = cso_cache_create();
97
98 st_init_atoms( st );
99 st_init_draw( st );
100 st_init_generate_mipmap(st);
101
102 /* we want all vertex data to be placed in buffer objects */
103 vbo_use_buffer_objects(ctx);
104
105 /* Need these flags:
106 */
107 st->ctx->FragmentProgram._MaintainTexEnvProgram = GL_TRUE;
108 st->ctx->FragmentProgram._UseTexEnvProgram = GL_TRUE;
109
110 st->ctx->VertexProgram._MaintainTnlProgram = GL_TRUE;
111
112 st->haveFramebufferSurfaces = GL_TRUE;
113
114 st->pixel_xfer.cache = _mesa_new_program_cache();
115
116 /* GL limits and extensions */
117 st_init_limits(st);
118 st_init_extensions(st);
119
120 return st;
121 }
122
123
124 struct st_context *st_create_context(struct pipe_context *pipe,
125 const __GLcontextModes *visual,
126 struct st_context *share)
127 {
128 GLcontext *ctx;
129 GLcontext *shareCtx = share ? share->ctx : NULL;
130 struct dd_function_table funcs;
131
132 memset(&funcs, 0, sizeof(funcs));
133 st_init_driver_functions(&funcs);
134
135 ctx = _mesa_create_context(visual, shareCtx, &funcs, NULL);
136
137 return st_create_context_priv(ctx, pipe);
138 }
139
140
141 static void st_destroy_context_priv( struct st_context *st )
142 {
143 struct pipe_winsys *ws = st->pipe->winsys;
144 uint i;
145
146 draw_destroy(st->draw);
147 st_destroy_atoms( st );
148 st_destroy_draw( st );
149
150 _vbo_DestroyContext(st->ctx);
151
152 cso_cache_delete( st->cache );
153
154 _mesa_delete_program_cache(st->ctx, st->pixel_xfer.cache);
155
156 for (i = 0; i < Elements(st->state.constants); i++) {
157 if (st->state.constants[i].buffer) {
158 pipe_buffer_reference(ws, &st->state.constants[i].buffer, NULL);
159 }
160 }
161
162 st->pipe->destroy( st->pipe );
163 free( st );
164 }
165
166
167 void st_destroy_context( struct st_context *st )
168 {
169 GLcontext *ctx = st->ctx;
170 _mesa_free_context_data(ctx);
171 st_destroy_context_priv(st);
172 free(ctx);
173 }
174
175
176 void st_make_current(struct st_context *st,
177 struct st_framebuffer *draw,
178 struct st_framebuffer *read)
179 {
180 if (st) {
181 GLboolean firstTime = st->ctx->FirstTimeCurrent;
182 _mesa_make_current(st->ctx, &draw->Base, &read->Base);
183 /* Need to initialize viewport here since draw->Base->Width/Height
184 * will still be zero at this point.
185 * This could be improved, but would require rather extensive work
186 * elsewhere (allocate rb surface storage sooner)
187 */
188 if (firstTime) {
189 GLuint w = draw->InitWidth, h = draw->InitHeight;
190 _mesa_set_viewport(st->ctx, 0, 0, w, h);
191 _mesa_set_scissor(st->ctx, 0, 0, w, h);
192
193 }
194 }
195 else {
196 _mesa_make_current(NULL, NULL, NULL);
197 }
198 }
199
200
201 void st_copy_context_state(struct st_context *dst,
202 struct st_context *src,
203 uint mask)
204 {
205 _mesa_copy_context(dst->ctx, src->ctx, mask);
206 }
207
208
209 void st_init_driver_functions(struct dd_function_table *functions)
210 {
211 _mesa_init_glsl_driver_functions(functions);
212
213 st_init_accum_functions(functions);
214 st_init_bufferobject_functions(functions);
215 st_init_clear_functions(functions);
216 st_init_drawpixels_functions(functions);
217 st_init_fbo_functions(functions);
218 st_init_feedback_functions(functions);
219 st_init_program_functions(functions);
220 st_init_query_functions(functions);
221 st_init_rasterpos_functions(functions);
222 st_init_readpixels_functions(functions);
223 st_init_texture_functions(functions);
224 st_init_flush_functions(functions);
225 st_init_string_functions(functions);
226
227 functions->UpdateState = st_invalidate_state;
228 }