blob: 138f18aa99b62fa72a37a2ff68ec2528d1b05d57 [file] [log] [blame]
Keith Whitwell8e4a95a2007-05-24 10:41:34 +01001/**************************************************************************
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
Brian1e6d1ab2007-08-17 15:27:18 +010028#include "main/imports.h"
Brian80d26582007-11-01 17:46:04 -060029#include "main/context.h"
Brian3bf8d2a2007-09-25 15:18:51 -060030#include "main/extensions.h"
Brian1e6d1ab2007-08-17 15:27:18 +010031#include "vbo/vbo.h"
Keith Whitwell8e4a95a2007-05-24 10:41:34 +010032#include "st_public.h"
33#include "st_context.h"
Brian9f797d82007-10-14 11:52:00 -060034#include "st_cb_accum.h"
Brian6da92342007-08-06 20:53:28 +010035#include "st_cb_bufferobjects.h"
Brian51b300c2007-08-02 10:29:50 -060036#include "st_cb_clear.h"
Brian184b6a12007-08-02 14:21:16 -060037#include "st_cb_drawpixels.h"
Brian64da7512007-08-09 12:27:44 -060038#include "st_cb_fbo.h"
Brianb4bacd12007-09-17 14:24:11 -060039#include "st_cb_feedback.h"
Brian24864742007-08-11 19:57:37 +010040#include "st_cb_queryobj.h"
Brianbee148c2007-09-10 16:28:27 -060041#include "st_cb_rasterpos.h"
Brian6f27aab2007-08-10 11:37:21 -060042#include "st_cb_readpixels.h"
Brian4435bae2007-08-06 15:49:11 -060043#include "st_cb_texture.h"
Keith Whitwell5c2c0562007-08-10 12:57:14 +010044#include "st_cb_flush.h"
Keith Whitwell39407fd2007-08-10 16:42:26 +010045#include "st_cb_strings.h"
Keith Whitwell8e4a95a2007-05-24 10:41:34 +010046#include "st_atom.h"
47#include "st_draw.h"
48#include "st_program.h"
Keith Whitwell943964a2007-06-14 18:23:43 +010049#include "pipe/p_context.h"
Brianb4bacd12007-09-17 14:24:11 -060050#include "pipe/draw/draw_context.h"
Zack Rusinfbb2f842007-09-18 06:24:54 -040051#include "pipe/cso_cache/cso_cache.h"
Keith Whitwell8e4a95a2007-05-24 10:41:34 +010052
Brian6f27aab2007-08-10 11:37:21 -060053
Briand7755092007-10-31 11:08:07 -060054/**
55 * Called via ctx->Driver.UpdateState()
56 */
Keith Whitwell8e4a95a2007-05-24 10:41:34 +010057void 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;
Briand7755092007-10-31 11:08:07 -060063
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);
Keith Whitwell8e4a95a2007-05-24 10:41:34 +010068}
69
70
Brianf221ea62007-11-05 09:35:31 -070071/*
72 * XXX rename after above func is removed.
73 */
Brian80d26582007-11-01 17:46:04 -060074struct st_context *st_create_context2(struct pipe_context *pipe,
Brianf221ea62007-11-05 09:35:31 -070075 const __GLcontextModes *visual,
Brian80d26582007-11-01 17:46:04 -060076 struct st_context *share)
77{
78 GLcontext *ctx;
79 GLcontext *shareCtx = share ? share->ctx : NULL;
80 struct dd_function_table funcs;
81
82 memset(&funcs, 0, sizeof(funcs));
83 st_init_driver_functions(&funcs);
84
85 ctx = _mesa_create_context(visual, shareCtx, &funcs, NULL);
86
87 return st_create_context(ctx, pipe);
88}
89
90
Keith Whitwell8e4a95a2007-05-24 10:41:34 +010091struct st_context *st_create_context( GLcontext *ctx,
Keith Whitwell943964a2007-06-14 18:23:43 +010092 struct pipe_context *pipe )
Keith Whitwell8e4a95a2007-05-24 10:41:34 +010093{
94 struct st_context *st = CALLOC_STRUCT( st_context );
95
96 ctx->st = st;
97
98 st->ctx = ctx;
Keith Whitwell943964a2007-06-14 18:23:43 +010099 st->pipe = pipe;
Keith Whitwell8e4a95a2007-05-24 10:41:34 +0100100
Brian8984a282007-10-31 11:35:50 -0600101 /* state tracker needs the VBO module */
102 _vbo_CreateContext(ctx);
Brian8984a282007-10-31 11:35:50 -0600103
Brianb4bacd12007-09-17 14:24:11 -0600104 st->draw = draw_create(); /* for selection/feedback */
105
Keith Whitwell8e4a95a2007-05-24 10:41:34 +0100106 st->dirty.mesa = ~0;
107 st->dirty.st = ~0;
108
Zack Rusin97803272007-09-14 04:08:58 -0400109 st->cache = cso_cache_create();
110
Keith Whitwell8e4a95a2007-05-24 10:41:34 +0100111 st_init_atoms( st );
112 st_init_draw( st );
Brian61d02152007-08-02 20:40:19 -0600113
Brian1e6d1ab2007-08-17 15:27:18 +0100114 /* we want all vertex data to be placed in buffer objects */
115 vbo_use_buffer_objects(ctx);
116
Brian6da92342007-08-06 20:53:28 +0100117 /* Need these flags:
118 */
119 st->ctx->FragmentProgram._MaintainTexEnvProgram = GL_TRUE;
120 st->ctx->FragmentProgram._UseTexEnvProgram = GL_TRUE;
121
Briane3bdd662007-08-16 17:33:49 -0600122 st->ctx->VertexProgram._MaintainTnlProgram = GL_TRUE;
123
Brian0007cd72007-10-18 15:18:55 -0600124 st->haveFramebufferRegions = GL_TRUE;
Briane3bdd662007-08-16 17:33:49 -0600125
Briand6a739f2007-10-30 16:13:37 -0600126 st->pixel_xfer.cache = _mesa_new_program_cache();
Briandf174bd2007-10-30 12:24:05 -0600127
Brianaf3d6c82007-08-21 20:15:00 -0600128 /* XXXX This is temporary! */
129 _mesa_enable_sw_extensions(ctx);
130
Keith Whitwell8e4a95a2007-05-24 10:41:34 +0100131 return st;
132}
133
134
Brianf221ea62007-11-05 09:35:31 -0700135/*
136 * XXX rename after below func is removed.
137 */
Brian80d26582007-11-01 17:46:04 -0600138void st_destroy_context2( struct st_context *st )
139{
140 GLcontext *ctx = st->ctx;
141 _mesa_free_context_data(ctx);
142 st_destroy_context(st);
143 free(ctx);
144}
145
146
Keith Whitwell8e4a95a2007-05-24 10:41:34 +0100147void st_destroy_context( struct st_context *st )
148{
Brianb4bacd12007-09-17 14:24:11 -0600149 draw_destroy(st->draw);
Keith Whitwell8e4a95a2007-05-24 10:41:34 +0100150 st_destroy_atoms( st );
151 st_destroy_draw( st );
Brian61d02152007-08-02 20:40:19 -0600152
Brian8984a282007-10-31 11:35:50 -0600153 _vbo_DestroyContext(st->ctx);
Brian8984a282007-10-31 11:35:50 -0600154
Zack Rusine16c0452007-09-17 07:56:56 -0400155 cso_cache_delete( st->cache );
Brian61d02152007-08-02 20:40:19 -0600156
Briand6a739f2007-10-30 16:13:37 -0600157 _mesa_delete_program_cache(st->ctx, st->pixel_xfer.cache);
Briandf174bd2007-10-30 12:24:05 -0600158
Keith Whitwell943964a2007-06-14 18:23:43 +0100159 st->pipe->destroy( st->pipe );
Brianf221ea62007-11-05 09:35:31 -0700160 free( st );
Keith Whitwell8e4a95a2007-05-24 10:41:34 +0100161}
162
163
Brian794e03d2007-11-02 13:22:22 -0600164void st_make_current(struct st_context *st,
165 struct st_framebuffer *draw,
166 struct st_framebuffer *read)
167{
168 if (st) {
169 _mesa_make_current(st->ctx, &draw->Base, &read->Base);
170 }
171 else {
172 _mesa_make_current(NULL, NULL, NULL);
173 }
174}
175
176
Briane39f1b42007-11-05 15:59:55 -0700177void st_copy_context_state(struct st_context *dst,
178 struct st_context *src,
179 uint mask)
180{
181 _mesa_copy_context(dst->ctx, src->ctx, mask);
182}
183
Keith Whitwell8e4a95a2007-05-24 10:41:34 +0100184
Brian6da92342007-08-06 20:53:28 +0100185void st_init_driver_functions(struct dd_function_table *functions)
186{
Brian9f797d82007-10-14 11:52:00 -0600187 st_init_accum_functions(functions);
Brian6da92342007-08-06 20:53:28 +0100188 st_init_bufferobject_functions(functions);
189 st_init_clear_functions(functions);
190 st_init_drawpixels_functions(functions);
Brian64da7512007-08-09 12:27:44 -0600191 st_init_fbo_functions(functions);
Brianb4bacd12007-09-17 14:24:11 -0600192 st_init_feedback_functions(functions);
Brian6da92342007-08-06 20:53:28 +0100193 st_init_program_functions(functions);
Brian24864742007-08-11 19:57:37 +0100194 st_init_query_functions(functions);
Brianbee148c2007-09-10 16:28:27 -0600195 st_init_rasterpos_functions(functions);
Brian6f27aab2007-08-10 11:37:21 -0600196 st_init_readpixels_functions(functions);
Brian6da92342007-08-06 20:53:28 +0100197 st_init_texture_functions(functions);
Keith Whitwell5c2c0562007-08-10 12:57:14 +0100198 st_init_flush_functions(functions);
Keith Whitwell39407fd2007-08-10 16:42:26 +0100199 st_init_string_functions(functions);
Briand7755092007-10-31 11:08:07 -0600200
201 functions->UpdateState = st_invalidate_state;
Brian6da92342007-08-06 20:53:28 +0100202}