Keith Whitwell | 8e4a95a | 2007-05-24 10:41:34 +0100 | [diff] [blame] | 1 | /************************************************************************** |
| 2 | * |
Brian | c6499a7 | 2007-11-05 18:04:30 -0700 | [diff] [blame] | 3 | * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. |
Keith Whitwell | 8e4a95a | 2007-05-24 10:41:34 +0100 | [diff] [blame] | 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 | c664302 | 2007-12-19 13:45:00 -0700 | [diff] [blame] | 31 | #include "main/matrix.h" |
| 32 | #include "main/buffers.h" |
Brian Paul | 8cad318 | 2008-06-09 14:56:29 -0600 | [diff] [blame] | 33 | #include "main/scissor.h" |
Brian Paul | 2c37851 | 2009-03-07 12:33:11 -0700 | [diff] [blame] | 34 | #include "main/viewport.h" |
Brian | 1e6d1ab | 2007-08-17 15:27:18 +0100 | [diff] [blame] | 35 | #include "vbo/vbo.h" |
Brian | 2d2bb35 | 2007-12-07 17:11:30 -0700 | [diff] [blame] | 36 | #include "shader/shader_api.h" |
Brian Paul | 5ebd849 | 2008-06-17 14:27:36 -0600 | [diff] [blame] | 37 | #include "glapi/glapi.h" |
Keith Whitwell | 8e4a95a | 2007-05-24 10:41:34 +0100 | [diff] [blame] | 38 | #include "st_public.h" |
| 39 | #include "st_context.h" |
Brian | 9f797d8 | 2007-10-14 11:52:00 -0600 | [diff] [blame] | 40 | #include "st_cb_accum.h" |
Brian | f6cd377 | 2008-03-20 14:50:17 -0600 | [diff] [blame] | 41 | #include "st_cb_bitmap.h" |
Brian | 0df877a | 2008-03-18 17:16:23 -0600 | [diff] [blame] | 42 | #include "st_cb_blit.h" |
Brian | f6cd377 | 2008-03-20 14:50:17 -0600 | [diff] [blame] | 43 | #include "st_cb_bufferobjects.h" |
Brian | 51b300c | 2007-08-02 10:29:50 -0600 | [diff] [blame] | 44 | #include "st_cb_clear.h" |
Brian Paul | d7a4d49 | 2008-06-20 08:09:59 -0600 | [diff] [blame] | 45 | #if FEATURE_drawpix |
Brian | 184b6a1 | 2007-08-02 14:21:16 -0600 | [diff] [blame] | 46 | #include "st_cb_drawpixels.h" |
Brian Paul | d7a4d49 | 2008-06-20 08:09:59 -0600 | [diff] [blame] | 47 | #include "st_cb_rasterpos.h" |
| 48 | #endif |
Brian Paul | 4424c66 | 2008-08-12 18:02:44 -0600 | [diff] [blame] | 49 | #ifdef FEATURE_OES_draw_texture |
| 50 | #include "st_cb_drawtex.h" |
| 51 | #endif |
Brian | 64da751 | 2007-08-09 12:27:44 -0600 | [diff] [blame] | 52 | #include "st_cb_fbo.h" |
Brian Paul | e90c0c9 | 2008-08-19 14:24:27 -0600 | [diff] [blame] | 53 | #include "st_cb_get.h" |
Brian Paul | d7a4d49 | 2008-06-20 08:09:59 -0600 | [diff] [blame] | 54 | #if FEATURE_feedback |
Brian | b4bacd1 | 2007-09-17 14:24:11 -0600 | [diff] [blame] | 55 | #include "st_cb_feedback.h" |
Brian Paul | d7a4d49 | 2008-06-20 08:09:59 -0600 | [diff] [blame] | 56 | #endif |
Brian Paul | 22a3d02 | 2008-03-24 11:55:29 -0600 | [diff] [blame] | 57 | #include "st_cb_program.h" |
Brian | 2486474 | 2007-08-11 19:57:37 +0100 | [diff] [blame] | 58 | #include "st_cb_queryobj.h" |
Brian | 6f27aab | 2007-08-10 11:37:21 -0600 | [diff] [blame] | 59 | #include "st_cb_readpixels.h" |
Brian | 4435bae | 2007-08-06 15:49:11 -0600 | [diff] [blame] | 60 | #include "st_cb_texture.h" |
Keith Whitwell | 5c2c056 | 2007-08-10 12:57:14 +0100 | [diff] [blame] | 61 | #include "st_cb_flush.h" |
Keith Whitwell | 39407fd | 2007-08-10 16:42:26 +0100 | [diff] [blame] | 62 | #include "st_cb_strings.h" |
Brian Paul | f24ec99 | 2009-02-23 15:07:31 -0700 | [diff] [blame] | 63 | #include "st_cb_viewport.h" |
Keith Whitwell | 8e4a95a | 2007-05-24 10:41:34 +0100 | [diff] [blame] | 64 | #include "st_atom.h" |
| 65 | #include "st_draw.h" |
Brian | c6499a7 | 2007-11-05 18:04:30 -0700 | [diff] [blame] | 66 | #include "st_extensions.h" |
Brian | 62abcb9 | 2008-02-08 14:54:18 -0700 | [diff] [blame] | 67 | #include "st_gen_mipmap.h" |
Keith Whitwell | 8e4a95a | 2007-05-24 10:41:34 +0100 | [diff] [blame] | 68 | #include "st_program.h" |
Keith Whitwell | 943964a | 2007-06-14 18:23:43 +0100 | [diff] [blame] | 69 | #include "pipe/p_context.h" |
José Fonseca | 6acd63a | 2008-02-15 17:50:12 +0900 | [diff] [blame] | 70 | #include "draw/draw_context.h" |
| 71 | #include "cso_cache/cso_cache.h" |
Brian | 339e7ec | 2008-03-11 18:54:31 -0600 | [diff] [blame] | 72 | #include "cso_cache/cso_context.h" |
Keith Whitwell | 8e4a95a | 2007-05-24 10:41:34 +0100 | [diff] [blame] | 73 | |
Brian | 6f27aab | 2007-08-10 11:37:21 -0600 | [diff] [blame] | 74 | |
Brian | d775509 | 2007-10-31 11:08:07 -0600 | [diff] [blame] | 75 | /** |
| 76 | * Called via ctx->Driver.UpdateState() |
| 77 | */ |
Keith Whitwell | 8e4a95a | 2007-05-24 10:41:34 +0100 | [diff] [blame] | 78 | void st_invalidate_state(GLcontext * ctx, GLuint new_state) |
| 79 | { |
| 80 | struct st_context *st = st_context(ctx); |
| 81 | |
| 82 | st->dirty.mesa |= new_state; |
| 83 | st->dirty.st |= ST_NEW_MESA; |
Brian | d775509 | 2007-10-31 11:08:07 -0600 | [diff] [blame] | 84 | |
| 85 | /* This is the only core Mesa module we depend upon. |
| 86 | * No longer use swrast, swsetup, tnl. |
| 87 | */ |
| 88 | _vbo_InvalidateState(ctx, new_state); |
Keith Whitwell | 8e4a95a | 2007-05-24 10:41:34 +0100 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | |
Brian Paul | 1a820f5 | 2008-09-17 14:32:33 -0600 | [diff] [blame] | 92 | /** |
| 93 | * Check for multisample env var override. |
| 94 | */ |
| 95 | int |
| 96 | st_get_msaa(void) |
| 97 | { |
| 98 | const char *msaa = _mesa_getenv("__GL_FSAA_MODE"); |
| 99 | if (msaa) |
| 100 | return atoi(msaa); |
| 101 | return 0; |
| 102 | } |
| 103 | |
| 104 | |
Brian | 91564ee | 2007-11-05 16:15:43 -0700 | [diff] [blame] | 105 | static struct st_context * |
| 106 | st_create_context_priv( GLcontext *ctx, struct pipe_context *pipe ) |
Keith Whitwell | 8e4a95a | 2007-05-24 10:41:34 +0100 | [diff] [blame] | 107 | { |
Brian | 339e7ec | 2008-03-11 18:54:31 -0600 | [diff] [blame] | 108 | uint i; |
Brian Paul | f1a59a6 | 2009-02-12 10:14:36 -0700 | [diff] [blame] | 109 | struct st_context *st = ST_CALLOC_STRUCT( st_context ); |
Keith Whitwell | 8e4a95a | 2007-05-24 10:41:34 +0100 | [diff] [blame] | 110 | |
| 111 | ctx->st = st; |
| 112 | |
| 113 | st->ctx = ctx; |
Keith Whitwell | 943964a | 2007-06-14 18:23:43 +0100 | [diff] [blame] | 114 | st->pipe = pipe; |
Keith Whitwell | 8e4a95a | 2007-05-24 10:41:34 +0100 | [diff] [blame] | 115 | |
Brian | 8984a28 | 2007-10-31 11:35:50 -0600 | [diff] [blame] | 116 | /* state tracker needs the VBO module */ |
| 117 | _vbo_CreateContext(ctx); |
Brian | 8984a28 | 2007-10-31 11:35:50 -0600 | [diff] [blame] | 118 | |
Brian Paul | bae90ed | 2008-07-10 14:23:27 -0600 | [diff] [blame] | 119 | #if FEATURE_feedback || FEATURE_drawpix |
Brian | b4bacd1 | 2007-09-17 14:24:11 -0600 | [diff] [blame] | 120 | st->draw = draw_create(); /* for selection/feedback */ |
| 121 | |
Brian Paul | 7f56c8e | 2008-03-25 14:12:55 -0600 | [diff] [blame] | 122 | /* Disable draw options that might convert points/lines to tris, etc. |
| 123 | * as that would foul-up feedback/selection mode. |
| 124 | */ |
| 125 | draw_wide_line_threshold(st->draw, 1000.0f); |
| 126 | draw_wide_point_threshold(st->draw, 1000.0f); |
| 127 | draw_enable_line_stipple(st->draw, FALSE); |
| 128 | draw_enable_point_sprites(st->draw, FALSE); |
Brian Paul | bae90ed | 2008-07-10 14:23:27 -0600 | [diff] [blame] | 129 | #endif |
Brian Paul | 7f56c8e | 2008-03-25 14:12:55 -0600 | [diff] [blame] | 130 | |
Keith Whitwell | 8e4a95a | 2007-05-24 10:41:34 +0100 | [diff] [blame] | 131 | st->dirty.mesa = ~0; |
| 132 | st->dirty.st = ~0; |
| 133 | |
Brian | 339e7ec | 2008-03-11 18:54:31 -0600 | [diff] [blame] | 134 | st->cso_context = cso_create_context(pipe); |
Zack Rusin | 9780327 | 2007-09-14 04:08:58 -0400 | [diff] [blame] | 135 | |
Keith Whitwell | 8e4a95a | 2007-05-24 10:41:34 +0100 | [diff] [blame] | 136 | st_init_atoms( st ); |
Brian | c62b197 | 2008-03-28 14:53:47 -0600 | [diff] [blame] | 137 | st_init_bitmap(st); |
Brian Paul | ce5c867 | 2008-04-03 12:54:32 -0600 | [diff] [blame] | 138 | st_init_clear(st); |
Keith Whitwell | 8e4a95a | 2007-05-24 10:41:34 +0100 | [diff] [blame] | 139 | st_init_draw( st ); |
Brian | 62abcb9 | 2008-02-08 14:54:18 -0700 | [diff] [blame] | 140 | st_init_generate_mipmap(st); |
Brian | 0df877a | 2008-03-18 17:16:23 -0600 | [diff] [blame] | 141 | st_init_blit(st); |
Brian | 61d0215 | 2007-08-02 20:40:19 -0600 | [diff] [blame] | 142 | |
Brian | 339e7ec | 2008-03-11 18:54:31 -0600 | [diff] [blame] | 143 | for (i = 0; i < PIPE_MAX_SAMPLERS; i++) |
| 144 | st->state.sampler_list[i] = &st->state.samplers[i]; |
| 145 | |
Brian | 1e6d1ab | 2007-08-17 15:27:18 +0100 | [diff] [blame] | 146 | /* we want all vertex data to be placed in buffer objects */ |
| 147 | vbo_use_buffer_objects(ctx); |
| 148 | |
Brian | 6da9234 | 2007-08-06 20:53:28 +0100 | [diff] [blame] | 149 | /* Need these flags: |
| 150 | */ |
| 151 | st->ctx->FragmentProgram._MaintainTexEnvProgram = GL_TRUE; |
Brian | 6da9234 | 2007-08-06 20:53:28 +0100 | [diff] [blame] | 152 | |
Brian | e3bdd66 | 2007-08-16 17:33:49 -0600 | [diff] [blame] | 153 | st->ctx->VertexProgram._MaintainTnlProgram = GL_TRUE; |
| 154 | |
Brian | d6a739f | 2007-10-30 16:13:37 -0600 | [diff] [blame] | 155 | st->pixel_xfer.cache = _mesa_new_program_cache(); |
Brian | df174bd | 2007-10-30 12:24:05 -0600 | [diff] [blame] | 156 | |
Brian Paul | 1a820f5 | 2008-09-17 14:32:33 -0600 | [diff] [blame] | 157 | st->force_msaa = st_get_msaa(); |
| 158 | |
Brian | c6499a7 | 2007-11-05 18:04:30 -0700 | [diff] [blame] | 159 | /* GL limits and extensions */ |
| 160 | st_init_limits(st); |
| 161 | st_init_extensions(st); |
Brian | af3d6c8 | 2007-08-21 20:15:00 -0600 | [diff] [blame] | 162 | |
Keith Whitwell | 8e4a95a | 2007-05-24 10:41:34 +0100 | [diff] [blame] | 163 | return st; |
| 164 | } |
| 165 | |
| 166 | |
Brian | 91564ee | 2007-11-05 16:15:43 -0700 | [diff] [blame] | 167 | struct st_context *st_create_context(struct pipe_context *pipe, |
| 168 | const __GLcontextModes *visual, |
| 169 | struct st_context *share) |
Brian | 80d2658 | 2007-11-01 17:46:04 -0600 | [diff] [blame] | 170 | { |
Brian | 91564ee | 2007-11-05 16:15:43 -0700 | [diff] [blame] | 171 | GLcontext *ctx; |
| 172 | GLcontext *shareCtx = share ? share->ctx : NULL; |
| 173 | struct dd_function_table funcs; |
| 174 | |
| 175 | memset(&funcs, 0, sizeof(funcs)); |
| 176 | st_init_driver_functions(&funcs); |
| 177 | |
| 178 | ctx = _mesa_create_context(visual, shareCtx, &funcs, NULL); |
| 179 | |
Keith Whitwell | b6e8256 | 2009-05-05 12:12:28 +0100 | [diff] [blame^] | 180 | /* XXX: need a capability bit in gallium to query if the pipe |
| 181 | * driver prefers DP4 or MUL/MAD for vertex transformation. |
| 182 | */ |
| 183 | if (debug_get_bool_option("MESA_MVP_DP4", FALSE)) |
| 184 | _mesa_set_mvp_with_dp4( ctx, GL_TRUE ); |
| 185 | |
Brian | 91564ee | 2007-11-05 16:15:43 -0700 | [diff] [blame] | 186 | return st_create_context_priv(ctx, pipe); |
Brian | 80d2658 | 2007-11-01 17:46:04 -0600 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | |
Brian | 91564ee | 2007-11-05 16:15:43 -0700 | [diff] [blame] | 190 | static void st_destroy_context_priv( struct st_context *st ) |
Keith Whitwell | 8e4a95a | 2007-05-24 10:41:34 +0100 | [diff] [blame] | 191 | { |
Brian | 6128c93 | 2007-12-26 07:16:12 -0700 | [diff] [blame] | 192 | uint i; |
| 193 | |
Brian Paul | bae90ed | 2008-07-10 14:23:27 -0600 | [diff] [blame] | 194 | #if FEATURE_feedback || FEATURE_drawpix |
Brian | b4bacd1 | 2007-09-17 14:24:11 -0600 | [diff] [blame] | 195 | draw_destroy(st->draw); |
Brian Paul | bae90ed | 2008-07-10 14:23:27 -0600 | [diff] [blame] | 196 | #endif |
Keith Whitwell | 8e4a95a | 2007-05-24 10:41:34 +0100 | [diff] [blame] | 197 | st_destroy_atoms( st ); |
| 198 | st_destroy_draw( st ); |
Brian | 0df877a | 2008-03-18 17:16:23 -0600 | [diff] [blame] | 199 | st_destroy_generate_mipmap(st); |
Brian Paul | 414b535 | 2008-06-17 16:57:02 -0600 | [diff] [blame] | 200 | #if FEATURE_EXT_framebuffer_blit |
Brian | 0df877a | 2008-03-18 17:16:23 -0600 | [diff] [blame] | 201 | st_destroy_blit(st); |
Brian Paul | 414b535 | 2008-06-17 16:57:02 -0600 | [diff] [blame] | 202 | #endif |
Brian | 85e4ec6 | 2008-03-20 09:13:51 -0600 | [diff] [blame] | 203 | st_destroy_clear(st); |
Brian Paul | 414b535 | 2008-06-17 16:57:02 -0600 | [diff] [blame] | 204 | #if FEATURE_drawpix |
| 205 | st_destroy_bitmap(st); |
Brian Paul | 90ce846 | 2008-05-20 13:38:45 -0600 | [diff] [blame] | 206 | st_destroy_drawpix(st); |
Brian Paul | 414b535 | 2008-06-17 16:57:02 -0600 | [diff] [blame] | 207 | #endif |
Brian Paul | 4424c66 | 2008-08-12 18:02:44 -0600 | [diff] [blame] | 208 | #ifdef FEATURE_OES_draw_texture |
| 209 | st_destroy_drawtex(st); |
| 210 | #endif |
Brian | 61d0215 | 2007-08-02 20:40:19 -0600 | [diff] [blame] | 211 | |
Brian Paul | 87afc9b | 2008-05-16 16:04:30 -0600 | [diff] [blame] | 212 | for (i = 0; i < Elements(st->state.sampler_texture); i++) { |
| 213 | pipe_texture_reference(&st->state.sampler_texture[i], NULL); |
| 214 | } |
| 215 | |
Brian | 6128c93 | 2007-12-26 07:16:12 -0700 | [diff] [blame] | 216 | for (i = 0; i < Elements(st->state.constants); i++) { |
| 217 | if (st->state.constants[i].buffer) { |
Michel Dänzer | 5e27cd4 | 2009-03-04 11:58:48 +0100 | [diff] [blame] | 218 | pipe_buffer_reference(&st->state.constants[i].buffer, NULL); |
Brian | 6128c93 | 2007-12-26 07:16:12 -0700 | [diff] [blame] | 219 | } |
| 220 | } |
| 221 | |
Brian Paul | 8f6d9e1 | 2008-08-14 15:38:09 -0600 | [diff] [blame] | 222 | if (st->default_texture) { |
| 223 | st->ctx->Driver.DeleteTexture(st->ctx, st->default_texture); |
| 224 | st->default_texture = NULL; |
| 225 | } |
| 226 | |
Brian Paul | 1a2f4dd | 2009-02-12 10:08:25 -0700 | [diff] [blame] | 227 | _mesa_free( st ); |
Keith Whitwell | 8e4a95a | 2007-05-24 10:41:34 +0100 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | |
Brian | 91564ee | 2007-11-05 16:15:43 -0700 | [diff] [blame] | 231 | void st_destroy_context( struct st_context *st ) |
| 232 | { |
Brian Paul | a770d40 | 2008-04-24 12:11:24 -0600 | [diff] [blame] | 233 | struct pipe_context *pipe = st->pipe; |
| 234 | struct cso_context *cso = st->cso_context; |
Brian | 91564ee | 2007-11-05 16:15:43 -0700 | [diff] [blame] | 235 | GLcontext *ctx = st->ctx; |
Brian Paul | f2b3f6c | 2008-04-17 11:12:44 -0600 | [diff] [blame] | 236 | |
| 237 | /* need to unbind and destroy CSO objects before anything else */ |
Brian Paul | a770d40 | 2008-04-24 12:11:24 -0600 | [diff] [blame] | 238 | cso_release_all(st->cso_context); |
Brian Paul | f2b3f6c | 2008-04-17 11:12:44 -0600 | [diff] [blame] | 239 | |
Brian Paul | 69fd676 | 2008-05-20 14:38:22 -0600 | [diff] [blame] | 240 | st_reference_fragprog(st, &st->fp, NULL); |
| 241 | st_reference_vertprog(st, &st->vp, NULL); |
| 242 | |
Brian Paul | f2b3f6c | 2008-04-17 11:12:44 -0600 | [diff] [blame] | 243 | _mesa_delete_program_cache(st->ctx, st->pixel_xfer.cache); |
| 244 | |
Brian Paul | 753635f | 2008-09-16 08:51:28 -0600 | [diff] [blame] | 245 | _vbo_DestroyContext(st->ctx); |
| 246 | |
Brian | 91564ee | 2007-11-05 16:15:43 -0700 | [diff] [blame] | 247 | _mesa_free_context_data(ctx); |
Brian Paul | a770d40 | 2008-04-24 12:11:24 -0600 | [diff] [blame] | 248 | |
Brian | 91564ee | 2007-11-05 16:15:43 -0700 | [diff] [blame] | 249 | st_destroy_context_priv(st); |
Brian Paul | a770d40 | 2008-04-24 12:11:24 -0600 | [diff] [blame] | 250 | |
| 251 | cso_destroy_context(cso); |
| 252 | |
| 253 | pipe->destroy( pipe ); |
| 254 | |
Brian Paul | 1a2f4dd | 2009-02-12 10:08:25 -0700 | [diff] [blame] | 255 | _mesa_free(ctx); |
Brian | 91564ee | 2007-11-05 16:15:43 -0700 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | |
Brian | 794e03d | 2007-11-02 13:22:22 -0600 | [diff] [blame] | 259 | void st_make_current(struct st_context *st, |
| 260 | struct st_framebuffer *draw, |
| 261 | struct st_framebuffer *read) |
| 262 | { |
Keith Whitwell | 08d4451 | 2009-03-18 19:14:45 +0000 | [diff] [blame] | 263 | /* Call this periodically to detect when the user has begun using |
| 264 | * GL rendering from multiple threads. |
| 265 | */ |
| 266 | _glapi_check_multithread(); |
| 267 | |
Brian | 794e03d | 2007-11-02 13:22:22 -0600 | [diff] [blame] | 268 | if (st) { |
Brian | c664302 | 2007-12-19 13:45:00 -0700 | [diff] [blame] | 269 | GLboolean firstTime = st->ctx->FirstTimeCurrent; |
Brian | 794e03d | 2007-11-02 13:22:22 -0600 | [diff] [blame] | 270 | _mesa_make_current(st->ctx, &draw->Base, &read->Base); |
Brian | c664302 | 2007-12-19 13:45:00 -0700 | [diff] [blame] | 271 | /* Need to initialize viewport here since draw->Base->Width/Height |
| 272 | * will still be zero at this point. |
| 273 | * This could be improved, but would require rather extensive work |
| 274 | * elsewhere (allocate rb surface storage sooner) |
| 275 | */ |
| 276 | if (firstTime) { |
| 277 | GLuint w = draw->InitWidth, h = draw->InitHeight; |
| 278 | _mesa_set_viewport(st->ctx, 0, 0, w, h); |
| 279 | _mesa_set_scissor(st->ctx, 0, 0, w, h); |
| 280 | |
| 281 | } |
Brian | 794e03d | 2007-11-02 13:22:22 -0600 | [diff] [blame] | 282 | } |
| 283 | else { |
| 284 | _mesa_make_current(NULL, NULL, NULL); |
| 285 | } |
| 286 | } |
| 287 | |
Thomas Hellstrom | 3d2bba0 | 2009-04-28 14:12:39 +0200 | [diff] [blame] | 288 | struct st_context *st_get_current(void) |
| 289 | { |
| 290 | GET_CURRENT_CONTEXT(ctx); |
| 291 | |
| 292 | return (ctx == NULL) ? NULL : ctx->st; |
| 293 | } |
Brian | 794e03d | 2007-11-02 13:22:22 -0600 | [diff] [blame] | 294 | |
Brian | e39f1b4 | 2007-11-05 15:59:55 -0700 | [diff] [blame] | 295 | void st_copy_context_state(struct st_context *dst, |
| 296 | struct st_context *src, |
| 297 | uint mask) |
| 298 | { |
| 299 | _mesa_copy_context(dst->ctx, src->ctx, mask); |
| 300 | } |
| 301 | |
Keith Whitwell | 8e4a95a | 2007-05-24 10:41:34 +0100 | [diff] [blame] | 302 | |
Brian Paul | 5ebd849 | 2008-06-17 14:27:36 -0600 | [diff] [blame] | 303 | |
| 304 | st_proc st_get_proc_address(const char *procname) |
| 305 | { |
| 306 | return (st_proc) _glapi_get_proc_address(procname); |
| 307 | } |
| 308 | |
| 309 | |
| 310 | |
Brian | 6da9234 | 2007-08-06 20:53:28 +0100 | [diff] [blame] | 311 | void st_init_driver_functions(struct dd_function_table *functions) |
| 312 | { |
Brian | 601a9ea | 2007-11-07 08:18:50 -0700 | [diff] [blame] | 313 | _mesa_init_glsl_driver_functions(functions); |
| 314 | |
Brian Paul | 04996bc | 2008-06-17 13:13:34 -0600 | [diff] [blame] | 315 | #if FEATURE_accum |
Brian | 9f797d8 | 2007-10-14 11:52:00 -0600 | [diff] [blame] | 316 | st_init_accum_functions(functions); |
Brian Paul | 04996bc | 2008-06-17 13:13:34 -0600 | [diff] [blame] | 317 | #endif |
| 318 | #if FEATURE_EXT_framebuffer_blit |
Brian | 0df877a | 2008-03-18 17:16:23 -0600 | [diff] [blame] | 319 | st_init_blit_functions(functions); |
Brian Paul | 04996bc | 2008-06-17 13:13:34 -0600 | [diff] [blame] | 320 | #endif |
Brian | f6cd377 | 2008-03-20 14:50:17 -0600 | [diff] [blame] | 321 | st_init_bufferobject_functions(functions); |
Brian | 6da9234 | 2007-08-06 20:53:28 +0100 | [diff] [blame] | 322 | st_init_clear_functions(functions); |
Brian Paul | 04996bc | 2008-06-17 13:13:34 -0600 | [diff] [blame] | 323 | #if FEATURE_drawpix |
| 324 | st_init_bitmap_functions(functions); |
Brian | 6da9234 | 2007-08-06 20:53:28 +0100 | [diff] [blame] | 325 | st_init_drawpixels_functions(functions); |
Brian | bee148c | 2007-09-10 16:28:27 -0600 | [diff] [blame] | 326 | st_init_rasterpos_functions(functions); |
Brian Paul | 04996bc | 2008-06-17 13:13:34 -0600 | [diff] [blame] | 327 | #endif |
| 328 | st_init_fbo_functions(functions); |
Brian Paul | e90c0c9 | 2008-08-19 14:24:27 -0600 | [diff] [blame] | 329 | st_init_get_functions(functions); |
Brian Paul | 04996bc | 2008-06-17 13:13:34 -0600 | [diff] [blame] | 330 | #if FEATURE_feedback |
| 331 | st_init_feedback_functions(functions); |
| 332 | #endif |
| 333 | st_init_program_functions(functions); |
| 334 | #if FEATURE_ARB_occlusion_query |
| 335 | st_init_query_functions(functions); |
| 336 | #endif |
Brian | 6f27aab | 2007-08-10 11:37:21 -0600 | [diff] [blame] | 337 | st_init_readpixels_functions(functions); |
Brian | 6da9234 | 2007-08-06 20:53:28 +0100 | [diff] [blame] | 338 | st_init_texture_functions(functions); |
Keith Whitwell | 5c2c056 | 2007-08-10 12:57:14 +0100 | [diff] [blame] | 339 | st_init_flush_functions(functions); |
Keith Whitwell | 39407fd | 2007-08-10 16:42:26 +0100 | [diff] [blame] | 340 | st_init_string_functions(functions); |
Alan Hourihane | 6b72227 | 2009-02-19 18:33:15 +0000 | [diff] [blame] | 341 | st_init_viewport_functions(functions); |
Brian | d775509 | 2007-10-31 11:08:07 -0600 | [diff] [blame] | 342 | |
| 343 | functions->UpdateState = st_invalidate_state; |
Brian | 6da9234 | 2007-08-06 20:53:28 +0100 | [diff] [blame] | 344 | } |