534c7c12ac7482b342c5a30977d721b6d73ee6ee
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"
31 #include "main/matrix.h"
32 #include "main/buffers.h"
33 #include "main/scissor.h"
35 #include "shader/shader_api.h"
36 #include "glapi/glapi.h"
37 #include "st_public.h"
38 #include "st_context.h"
39 #include "st_cb_accum.h"
40 #include "st_cb_bitmap.h"
41 #include "st_cb_blit.h"
42 #include "st_cb_bufferobjects.h"
43 #include "st_cb_clear.h"
45 #include "st_cb_drawpixels.h"
46 #include "st_cb_rasterpos.h"
48 #ifdef FEATURE_OES_draw_texture
49 #include "st_cb_drawtex.h"
51 #include "st_cb_fbo.h"
52 #include "st_cb_get.h"
54 #include "st_cb_feedback.h"
56 #include "st_cb_program.h"
57 #include "st_cb_queryobj.h"
58 #include "st_cb_readpixels.h"
59 #include "st_cb_texture.h"
60 #include "st_cb_flush.h"
61 #include "st_cb_strings.h"
64 #include "st_extensions.h"
65 #include "st_gen_mipmap.h"
66 #include "st_program.h"
67 #include "pipe/p_context.h"
68 #include "pipe/p_inlines.h"
69 #include "draw/draw_context.h"
70 #include "cso_cache/cso_cache.h"
71 #include "cso_cache/cso_context.h"
75 * Called via ctx->Driver.UpdateState()
77 void st_invalidate_state(GLcontext
* ctx
, GLuint new_state
)
79 struct st_context
*st
= st_context(ctx
);
81 st
->dirty
.mesa
|= new_state
;
82 st
->dirty
.st
|= ST_NEW_MESA
;
84 /* This is the only core Mesa module we depend upon.
85 * No longer use swrast, swsetup, tnl.
87 _vbo_InvalidateState(ctx
, new_state
);
91 static struct st_context
*
92 st_create_context_priv( GLcontext
*ctx
, struct pipe_context
*pipe
)
95 struct st_context
*st
= CALLOC_STRUCT( st_context
);
102 /* state tracker needs the VBO module */
103 _vbo_CreateContext(ctx
);
105 #if FEATURE_feedback || FEATURE_drawpix
106 st
->draw
= draw_create(); /* for selection/feedback */
108 /* Disable draw options that might convert points/lines to tris, etc.
109 * as that would foul-up feedback/selection mode.
111 draw_wide_line_threshold(st
->draw
, 1000.0f
);
112 draw_wide_point_threshold(st
->draw
, 1000.0f
);
113 draw_enable_line_stipple(st
->draw
, FALSE
);
114 draw_enable_point_sprites(st
->draw
, FALSE
);
120 st
->cso_context
= cso_create_context(pipe
);
126 st_init_generate_mipmap(st
);
129 for (i
= 0; i
< PIPE_MAX_SAMPLERS
; i
++)
130 st
->state
.sampler_list
[i
] = &st
->state
.samplers
[i
];
132 /* we want all vertex data to be placed in buffer objects */
133 vbo_use_buffer_objects(ctx
);
137 st
->ctx
->FragmentProgram
._MaintainTexEnvProgram
= GL_TRUE
;
138 st
->ctx
->FragmentProgram
._UseTexEnvProgram
= GL_TRUE
;
140 st
->ctx
->VertexProgram
._MaintainTnlProgram
= GL_TRUE
;
142 st
->pixel_xfer
.cache
= _mesa_new_program_cache();
144 /* GL limits and extensions */
146 st_init_extensions(st
);
152 struct st_context
*st_create_context(struct pipe_context
*pipe
,
153 const __GLcontextModes
*visual
,
154 struct st_context
*share
)
157 GLcontext
*shareCtx
= share
? share
->ctx
: NULL
;
158 struct dd_function_table funcs
;
160 memset(&funcs
, 0, sizeof(funcs
));
161 st_init_driver_functions(&funcs
);
163 ctx
= _mesa_create_context(visual
, shareCtx
, &funcs
, NULL
);
165 return st_create_context_priv(ctx
, pipe
);
169 static void st_destroy_context_priv( struct st_context
*st
)
173 #if FEATURE_feedback || FEATURE_drawpix
174 draw_destroy(st
->draw
);
176 st_destroy_atoms( st
);
177 st_destroy_draw( st
);
178 st_destroy_generate_mipmap(st
);
179 #if FEATURE_EXT_framebuffer_blit
182 st_destroy_clear(st
);
184 st_destroy_bitmap(st
);
185 st_destroy_drawpix(st
);
187 #ifdef FEATURE_OES_draw_texture
188 st_destroy_drawtex(st
);
191 for (i
= 0; i
< Elements(st
->state
.sampler_texture
); i
++) {
192 pipe_texture_reference(&st
->state
.sampler_texture
[i
], NULL
);
195 for (i
= 0; i
< Elements(st
->state
.constants
); i
++) {
196 if (st
->state
.constants
[i
].buffer
) {
197 pipe_buffer_reference(st
->pipe
->screen
, &st
->state
.constants
[i
].buffer
, NULL
);
201 if (st
->default_texture
) {
202 st
->ctx
->Driver
.DeleteTexture(st
->ctx
, st
->default_texture
);
203 st
->default_texture
= NULL
;
210 void st_destroy_context( struct st_context
*st
)
212 struct pipe_context
*pipe
= st
->pipe
;
213 struct cso_context
*cso
= st
->cso_context
;
214 GLcontext
*ctx
= st
->ctx
;
216 /* need to unbind and destroy CSO objects before anything else */
217 cso_release_all(st
->cso_context
);
219 st_reference_fragprog(st
, &st
->fp
, NULL
);
220 st_reference_vertprog(st
, &st
->vp
, NULL
);
222 _mesa_delete_program_cache(st
->ctx
, st
->pixel_xfer
.cache
);
224 _vbo_DestroyContext(st
->ctx
);
226 _mesa_free_context_data(ctx
);
228 st_destroy_context_priv(st
);
230 cso_destroy_context(cso
);
232 pipe
->destroy( pipe
);
238 void st_make_current(struct st_context
*st
,
239 struct st_framebuffer
*draw
,
240 struct st_framebuffer
*read
)
243 GLboolean firstTime
= st
->ctx
->FirstTimeCurrent
;
244 _mesa_make_current(st
->ctx
, &draw
->Base
, &read
->Base
);
245 /* Need to initialize viewport here since draw->Base->Width/Height
246 * will still be zero at this point.
247 * This could be improved, but would require rather extensive work
248 * elsewhere (allocate rb surface storage sooner)
251 GLuint w
= draw
->InitWidth
, h
= draw
->InitHeight
;
252 _mesa_set_viewport(st
->ctx
, 0, 0, w
, h
);
253 _mesa_set_scissor(st
->ctx
, 0, 0, w
, h
);
258 _mesa_make_current(NULL
, NULL
, NULL
);
263 void st_copy_context_state(struct st_context
*dst
,
264 struct st_context
*src
,
267 _mesa_copy_context(dst
->ctx
, src
->ctx
, mask
);
272 st_proc
st_get_proc_address(const char *procname
)
274 return (st_proc
) _glapi_get_proc_address(procname
);
279 void st_init_driver_functions(struct dd_function_table
*functions
)
281 _mesa_init_glsl_driver_functions(functions
);
284 st_init_accum_functions(functions
);
286 #if FEATURE_EXT_framebuffer_blit
287 st_init_blit_functions(functions
);
289 st_init_bufferobject_functions(functions
);
290 st_init_clear_functions(functions
);
292 st_init_bitmap_functions(functions
);
293 st_init_drawpixels_functions(functions
);
294 st_init_rasterpos_functions(functions
);
296 st_init_fbo_functions(functions
);
297 st_init_get_functions(functions
);
299 st_init_feedback_functions(functions
);
301 st_init_program_functions(functions
);
302 #if FEATURE_ARB_occlusion_query
303 st_init_query_functions(functions
);
305 st_init_readpixels_functions(functions
);
306 st_init_texture_functions(functions
);
307 st_init_flush_functions(functions
);
308 st_init_string_functions(functions
);
310 functions
->UpdateState
= st_invalidate_state
;