Keith Whitwell | 8e4a95a | 2007-05-24 10:41:34 +0100 | [diff] [blame] | 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 | |
Brian | 1e6d1ab | 2007-08-17 15:27:18 +0100 | [diff] [blame] | 28 | #include "main/imports.h" |
Brian | 80d2658 | 2007-11-01 17:46:04 -0600 | [diff] [blame] | 29 | #include "main/context.h" |
Brian | 3bf8d2a | 2007-09-25 15:18:51 -0600 | [diff] [blame] | 30 | #include "main/extensions.h" |
Brian | 1e6d1ab | 2007-08-17 15:27:18 +0100 | [diff] [blame] | 31 | #include "vbo/vbo.h" |
Keith Whitwell | 8e4a95a | 2007-05-24 10:41:34 +0100 | [diff] [blame] | 32 | #include "st_public.h" |
| 33 | #include "st_context.h" |
Brian | 9f797d8 | 2007-10-14 11:52:00 -0600 | [diff] [blame] | 34 | #include "st_cb_accum.h" |
Brian | 6da9234 | 2007-08-06 20:53:28 +0100 | [diff] [blame] | 35 | #include "st_cb_bufferobjects.h" |
Brian | 51b300c | 2007-08-02 10:29:50 -0600 | [diff] [blame] | 36 | #include "st_cb_clear.h" |
Brian | 184b6a1 | 2007-08-02 14:21:16 -0600 | [diff] [blame] | 37 | #include "st_cb_drawpixels.h" |
Brian | 64da751 | 2007-08-09 12:27:44 -0600 | [diff] [blame] | 38 | #include "st_cb_fbo.h" |
Brian | b4bacd1 | 2007-09-17 14:24:11 -0600 | [diff] [blame] | 39 | #include "st_cb_feedback.h" |
Brian | 2486474 | 2007-08-11 19:57:37 +0100 | [diff] [blame] | 40 | #include "st_cb_queryobj.h" |
Brian | bee148c | 2007-09-10 16:28:27 -0600 | [diff] [blame] | 41 | #include "st_cb_rasterpos.h" |
Brian | 6f27aab | 2007-08-10 11:37:21 -0600 | [diff] [blame] | 42 | #include "st_cb_readpixels.h" |
Brian | 4435bae | 2007-08-06 15:49:11 -0600 | [diff] [blame] | 43 | #include "st_cb_texture.h" |
Keith Whitwell | 5c2c056 | 2007-08-10 12:57:14 +0100 | [diff] [blame] | 44 | #include "st_cb_flush.h" |
Keith Whitwell | 39407fd | 2007-08-10 16:42:26 +0100 | [diff] [blame] | 45 | #include "st_cb_strings.h" |
Keith Whitwell | 8e4a95a | 2007-05-24 10:41:34 +0100 | [diff] [blame] | 46 | #include "st_atom.h" |
| 47 | #include "st_draw.h" |
| 48 | #include "st_program.h" |
Keith Whitwell | 943964a | 2007-06-14 18:23:43 +0100 | [diff] [blame] | 49 | #include "pipe/p_context.h" |
Brian | b4bacd1 | 2007-09-17 14:24:11 -0600 | [diff] [blame] | 50 | #include "pipe/draw/draw_context.h" |
Zack Rusin | fbb2f84 | 2007-09-18 06:24:54 -0400 | [diff] [blame] | 51 | #include "pipe/cso_cache/cso_cache.h" |
Keith Whitwell | 8e4a95a | 2007-05-24 10:41:34 +0100 | [diff] [blame] | 52 | |
Brian | 6f27aab | 2007-08-10 11:37:21 -0600 | [diff] [blame] | 53 | |
Brian | d775509 | 2007-10-31 11:08:07 -0600 | [diff] [blame] | 54 | /** |
| 55 | * Called via ctx->Driver.UpdateState() |
| 56 | */ |
Keith Whitwell | 8e4a95a | 2007-05-24 10:41:34 +0100 | [diff] [blame] | 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; |
Brian | d775509 | 2007-10-31 11:08:07 -0600 | [diff] [blame] | 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); |
Keith Whitwell | 8e4a95a | 2007-05-24 10:41:34 +0100 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | |
Brian | f221ea6 | 2007-11-05 09:35:31 -0700 | [diff] [blame] | 71 | /* |
| 72 | * XXX rename after above func is removed. |
| 73 | */ |
Brian | 80d2658 | 2007-11-01 17:46:04 -0600 | [diff] [blame] | 74 | struct st_context *st_create_context2(struct pipe_context *pipe, |
Brian | f221ea6 | 2007-11-05 09:35:31 -0700 | [diff] [blame] | 75 | const __GLcontextModes *visual, |
Brian | 80d2658 | 2007-11-01 17:46:04 -0600 | [diff] [blame] | 76 | 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 Whitwell | 8e4a95a | 2007-05-24 10:41:34 +0100 | [diff] [blame] | 91 | struct st_context *st_create_context( GLcontext *ctx, |
Keith Whitwell | 943964a | 2007-06-14 18:23:43 +0100 | [diff] [blame] | 92 | struct pipe_context *pipe ) |
Keith Whitwell | 8e4a95a | 2007-05-24 10:41:34 +0100 | [diff] [blame] | 93 | { |
| 94 | struct st_context *st = CALLOC_STRUCT( st_context ); |
| 95 | |
| 96 | ctx->st = st; |
| 97 | |
| 98 | st->ctx = ctx; |
Keith Whitwell | 943964a | 2007-06-14 18:23:43 +0100 | [diff] [blame] | 99 | st->pipe = pipe; |
Keith Whitwell | 8e4a95a | 2007-05-24 10:41:34 +0100 | [diff] [blame] | 100 | |
Brian | 8984a28 | 2007-10-31 11:35:50 -0600 | [diff] [blame] | 101 | /* state tracker needs the VBO module */ |
| 102 | _vbo_CreateContext(ctx); |
Brian | 8984a28 | 2007-10-31 11:35:50 -0600 | [diff] [blame] | 103 | |
Brian | b4bacd1 | 2007-09-17 14:24:11 -0600 | [diff] [blame] | 104 | st->draw = draw_create(); /* for selection/feedback */ |
| 105 | |
Keith Whitwell | 8e4a95a | 2007-05-24 10:41:34 +0100 | [diff] [blame] | 106 | st->dirty.mesa = ~0; |
| 107 | st->dirty.st = ~0; |
| 108 | |
Zack Rusin | 9780327 | 2007-09-14 04:08:58 -0400 | [diff] [blame] | 109 | st->cache = cso_cache_create(); |
| 110 | |
Keith Whitwell | 8e4a95a | 2007-05-24 10:41:34 +0100 | [diff] [blame] | 111 | st_init_atoms( st ); |
| 112 | st_init_draw( st ); |
Brian | 61d0215 | 2007-08-02 20:40:19 -0600 | [diff] [blame] | 113 | |
Brian | 1e6d1ab | 2007-08-17 15:27:18 +0100 | [diff] [blame] | 114 | /* we want all vertex data to be placed in buffer objects */ |
| 115 | vbo_use_buffer_objects(ctx); |
| 116 | |
Brian | 6da9234 | 2007-08-06 20:53:28 +0100 | [diff] [blame] | 117 | /* Need these flags: |
| 118 | */ |
| 119 | st->ctx->FragmentProgram._MaintainTexEnvProgram = GL_TRUE; |
| 120 | st->ctx->FragmentProgram._UseTexEnvProgram = GL_TRUE; |
| 121 | |
Brian | e3bdd66 | 2007-08-16 17:33:49 -0600 | [diff] [blame] | 122 | st->ctx->VertexProgram._MaintainTnlProgram = GL_TRUE; |
| 123 | |
Brian | 0007cd7 | 2007-10-18 15:18:55 -0600 | [diff] [blame] | 124 | st->haveFramebufferRegions = GL_TRUE; |
Brian | e3bdd66 | 2007-08-16 17:33:49 -0600 | [diff] [blame] | 125 | |
Brian | d6a739f | 2007-10-30 16:13:37 -0600 | [diff] [blame] | 126 | st->pixel_xfer.cache = _mesa_new_program_cache(); |
Brian | df174bd | 2007-10-30 12:24:05 -0600 | [diff] [blame] | 127 | |
Brian | af3d6c8 | 2007-08-21 20:15:00 -0600 | [diff] [blame] | 128 | /* XXXX This is temporary! */ |
| 129 | _mesa_enable_sw_extensions(ctx); |
| 130 | |
Keith Whitwell | 8e4a95a | 2007-05-24 10:41:34 +0100 | [diff] [blame] | 131 | return st; |
| 132 | } |
| 133 | |
| 134 | |
Brian | f221ea6 | 2007-11-05 09:35:31 -0700 | [diff] [blame] | 135 | /* |
| 136 | * XXX rename after below func is removed. |
| 137 | */ |
Brian | 80d2658 | 2007-11-01 17:46:04 -0600 | [diff] [blame] | 138 | void 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 Whitwell | 8e4a95a | 2007-05-24 10:41:34 +0100 | [diff] [blame] | 147 | void st_destroy_context( struct st_context *st ) |
| 148 | { |
Brian | b4bacd1 | 2007-09-17 14:24:11 -0600 | [diff] [blame] | 149 | draw_destroy(st->draw); |
Keith Whitwell | 8e4a95a | 2007-05-24 10:41:34 +0100 | [diff] [blame] | 150 | st_destroy_atoms( st ); |
| 151 | st_destroy_draw( st ); |
Brian | 61d0215 | 2007-08-02 20:40:19 -0600 | [diff] [blame] | 152 | |
Brian | 8984a28 | 2007-10-31 11:35:50 -0600 | [diff] [blame] | 153 | _vbo_DestroyContext(st->ctx); |
Brian | 8984a28 | 2007-10-31 11:35:50 -0600 | [diff] [blame] | 154 | |
Zack Rusin | e16c045 | 2007-09-17 07:56:56 -0400 | [diff] [blame] | 155 | cso_cache_delete( st->cache ); |
Brian | 61d0215 | 2007-08-02 20:40:19 -0600 | [diff] [blame] | 156 | |
Brian | d6a739f | 2007-10-30 16:13:37 -0600 | [diff] [blame] | 157 | _mesa_delete_program_cache(st->ctx, st->pixel_xfer.cache); |
Brian | df174bd | 2007-10-30 12:24:05 -0600 | [diff] [blame] | 158 | |
Keith Whitwell | 943964a | 2007-06-14 18:23:43 +0100 | [diff] [blame] | 159 | st->pipe->destroy( st->pipe ); |
Brian | f221ea6 | 2007-11-05 09:35:31 -0700 | [diff] [blame] | 160 | free( st ); |
Keith Whitwell | 8e4a95a | 2007-05-24 10:41:34 +0100 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | |
Brian | 794e03d | 2007-11-02 13:22:22 -0600 | [diff] [blame] | 164 | void 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 | |
Brian | e39f1b4 | 2007-11-05 15:59:55 -0700 | [diff] [blame^] | 177 | void 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 Whitwell | 8e4a95a | 2007-05-24 10:41:34 +0100 | [diff] [blame] | 184 | |
Brian | 6da9234 | 2007-08-06 20:53:28 +0100 | [diff] [blame] | 185 | void st_init_driver_functions(struct dd_function_table *functions) |
| 186 | { |
Brian | 9f797d8 | 2007-10-14 11:52:00 -0600 | [diff] [blame] | 187 | st_init_accum_functions(functions); |
Brian | 6da9234 | 2007-08-06 20:53:28 +0100 | [diff] [blame] | 188 | st_init_bufferobject_functions(functions); |
| 189 | st_init_clear_functions(functions); |
| 190 | st_init_drawpixels_functions(functions); |
Brian | 64da751 | 2007-08-09 12:27:44 -0600 | [diff] [blame] | 191 | st_init_fbo_functions(functions); |
Brian | b4bacd1 | 2007-09-17 14:24:11 -0600 | [diff] [blame] | 192 | st_init_feedback_functions(functions); |
Brian | 6da9234 | 2007-08-06 20:53:28 +0100 | [diff] [blame] | 193 | st_init_program_functions(functions); |
Brian | 2486474 | 2007-08-11 19:57:37 +0100 | [diff] [blame] | 194 | st_init_query_functions(functions); |
Brian | bee148c | 2007-09-10 16:28:27 -0600 | [diff] [blame] | 195 | st_init_rasterpos_functions(functions); |
Brian | 6f27aab | 2007-08-10 11:37:21 -0600 | [diff] [blame] | 196 | st_init_readpixels_functions(functions); |
Brian | 6da9234 | 2007-08-06 20:53:28 +0100 | [diff] [blame] | 197 | st_init_texture_functions(functions); |
Keith Whitwell | 5c2c056 | 2007-08-10 12:57:14 +0100 | [diff] [blame] | 198 | st_init_flush_functions(functions); |
Keith Whitwell | 39407fd | 2007-08-10 16:42:26 +0100 | [diff] [blame] | 199 | st_init_string_functions(functions); |
Brian | d775509 | 2007-10-31 11:08:07 -0600 | [diff] [blame] | 200 | |
| 201 | functions->UpdateState = st_invalidate_state; |
Brian | 6da9234 | 2007-08-06 20:53:28 +0100 | [diff] [blame] | 202 | } |