Clone of mesa.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

st_context.c 8.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  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. #include "main/imports.h"
  28. #include "main/context.h"
  29. #include "main/extensions.h"
  30. #include "main/matrix.h"
  31. #include "main/buffers.h"
  32. #include "main/scissor.h"
  33. #include "main/viewport.h"
  34. #include "vbo/vbo.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"
  44. #if FEATURE_drawpix
  45. #include "st_cb_drawpixels.h"
  46. #include "st_cb_rasterpos.h"
  47. #endif
  48. #ifdef FEATURE_OES_draw_texture
  49. #include "st_cb_drawtex.h"
  50. #endif
  51. #include "st_cb_fbo.h"
  52. #include "st_cb_get.h"
  53. #if FEATURE_feedback
  54. #include "st_cb_feedback.h"
  55. #endif
  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"
  62. #include "st_cb_viewport.h"
  63. #include "st_atom.h"
  64. #include "st_draw.h"
  65. #include "st_extensions.h"
  66. #include "st_gen_mipmap.h"
  67. #include "st_program.h"
  68. #include "pipe/p_context.h"
  69. #include "draw/draw_context.h"
  70. #include "cso_cache/cso_cache.h"
  71. #include "cso_cache/cso_context.h"
  72. /**
  73. * Called via ctx->Driver.UpdateState()
  74. */
  75. void st_invalidate_state(GLcontext * ctx, GLuint new_state)
  76. {
  77. struct st_context *st = st_context(ctx);
  78. st->dirty.mesa |= new_state;
  79. st->dirty.st |= ST_NEW_MESA;
  80. /* This is the only core Mesa module we depend upon.
  81. * No longer use swrast, swsetup, tnl.
  82. */
  83. _vbo_InvalidateState(ctx, new_state);
  84. }
  85. /**
  86. * Check for multisample env var override.
  87. */
  88. int
  89. st_get_msaa(void)
  90. {
  91. const char *msaa = _mesa_getenv("__GL_FSAA_MODE");
  92. if (msaa)
  93. return atoi(msaa);
  94. return 0;
  95. }
  96. static struct st_context *
  97. st_create_context_priv( GLcontext *ctx, struct pipe_context *pipe )
  98. {
  99. uint i;
  100. struct st_context *st = ST_CALLOC_STRUCT( st_context );
  101. ctx->st = st;
  102. st->ctx = ctx;
  103. st->pipe = pipe;
  104. /* state tracker needs the VBO module */
  105. _vbo_CreateContext(ctx);
  106. #if FEATURE_feedback || FEATURE_drawpix
  107. 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.
  110. */
  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);
  115. #endif
  116. st->dirty.mesa = ~0;
  117. st->dirty.st = ~0;
  118. st->cso_context = cso_create_context(pipe);
  119. st_init_atoms( st );
  120. st_init_bitmap(st);
  121. st_init_clear(st);
  122. st_init_draw( st );
  123. st_init_generate_mipmap(st);
  124. st_init_blit(st);
  125. for (i = 0; i < PIPE_MAX_SAMPLERS; i++)
  126. st->state.sampler_list[i] = &st->state.samplers[i];
  127. /* we want all vertex data to be placed in buffer objects */
  128. vbo_use_buffer_objects(ctx);
  129. /* Need these flags:
  130. */
  131. st->ctx->FragmentProgram._MaintainTexEnvProgram = GL_TRUE;
  132. st->ctx->VertexProgram._MaintainTnlProgram = GL_TRUE;
  133. st->pixel_xfer.cache = _mesa_new_program_cache();
  134. st->force_msaa = st_get_msaa();
  135. /* GL limits and extensions */
  136. st_init_limits(st);
  137. st_init_extensions(st);
  138. return st;
  139. }
  140. struct st_context *st_create_context(struct pipe_context *pipe,
  141. const __GLcontextModes *visual,
  142. struct st_context *share)
  143. {
  144. GLcontext *ctx;
  145. GLcontext *shareCtx = share ? share->ctx : NULL;
  146. struct dd_function_table funcs;
  147. memset(&funcs, 0, sizeof(funcs));
  148. st_init_driver_functions(&funcs);
  149. ctx = _mesa_create_context(visual, shareCtx, &funcs, NULL);
  150. /* XXX: need a capability bit in gallium to query if the pipe
  151. * driver prefers DP4 or MUL/MAD for vertex transformation.
  152. */
  153. if (debug_get_bool_option("MESA_MVP_DP4", FALSE))
  154. _mesa_set_mvp_with_dp4( ctx, GL_TRUE );
  155. return st_create_context_priv(ctx, pipe);
  156. }
  157. static void st_destroy_context_priv( struct st_context *st )
  158. {
  159. uint i;
  160. #if FEATURE_feedback || FEATURE_drawpix
  161. draw_destroy(st->draw);
  162. #endif
  163. st_destroy_atoms( st );
  164. st_destroy_draw( st );
  165. st_destroy_generate_mipmap(st);
  166. #if FEATURE_EXT_framebuffer_blit
  167. st_destroy_blit(st);
  168. #endif
  169. st_destroy_clear(st);
  170. #if FEATURE_drawpix
  171. st_destroy_bitmap(st);
  172. st_destroy_drawpix(st);
  173. #endif
  174. #ifdef FEATURE_OES_draw_texture
  175. st_destroy_drawtex(st);
  176. #endif
  177. for (i = 0; i < Elements(st->state.sampler_texture); i++) {
  178. pipe_texture_reference(&st->state.sampler_texture[i], NULL);
  179. }
  180. for (i = 0; i < Elements(st->state.constants); i++) {
  181. if (st->state.constants[i].buffer) {
  182. pipe_buffer_reference(&st->state.constants[i].buffer, NULL);
  183. }
  184. }
  185. if (st->default_texture) {
  186. st->ctx->Driver.DeleteTexture(st->ctx, st->default_texture);
  187. st->default_texture = NULL;
  188. }
  189. _mesa_free( st );
  190. }
  191. void st_destroy_context( struct st_context *st )
  192. {
  193. struct pipe_context *pipe = st->pipe;
  194. struct cso_context *cso = st->cso_context;
  195. GLcontext *ctx = st->ctx;
  196. GLuint i;
  197. /* need to unbind and destroy CSO objects before anything else */
  198. cso_release_all(st->cso_context);
  199. st_reference_fragprog(st, &st->fp, NULL);
  200. st_reference_vertprog(st, &st->vp, NULL);
  201. /* release framebuffer surfaces */
  202. for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++) {
  203. pipe_surface_reference(&st->state.framebuffer.cbufs[i], NULL);
  204. }
  205. pipe_surface_reference(&st->state.framebuffer.zsbuf, NULL);
  206. _mesa_delete_program_cache(st->ctx, st->pixel_xfer.cache);
  207. _vbo_DestroyContext(st->ctx);
  208. _mesa_free_context_data(ctx);
  209. st_destroy_context_priv(st);
  210. cso_destroy_context(cso);
  211. pipe->destroy( pipe );
  212. _mesa_free(ctx);
  213. }
  214. GLboolean
  215. st_make_current(struct st_context *st,
  216. struct st_framebuffer *draw,
  217. struct st_framebuffer *read)
  218. {
  219. /* Call this periodically to detect when the user has begun using
  220. * GL rendering from multiple threads.
  221. */
  222. _glapi_check_multithread();
  223. if (st) {
  224. if (!_mesa_make_current(st->ctx, &draw->Base, &read->Base))
  225. return GL_FALSE;
  226. _mesa_check_init_viewport(st->ctx, draw->InitWidth, draw->InitHeight);
  227. return GL_TRUE;
  228. }
  229. else {
  230. return _mesa_make_current(NULL, NULL, NULL);
  231. }
  232. }
  233. struct st_context *st_get_current(void)
  234. {
  235. GET_CURRENT_CONTEXT(ctx);
  236. return (ctx == NULL) ? NULL : ctx->st;
  237. }
  238. void st_copy_context_state(struct st_context *dst,
  239. struct st_context *src,
  240. uint mask)
  241. {
  242. _mesa_copy_context(dst->ctx, src->ctx, mask);
  243. }
  244. st_proc st_get_proc_address(const char *procname)
  245. {
  246. return (st_proc) _glapi_get_proc_address(procname);
  247. }
  248. void st_init_driver_functions(struct dd_function_table *functions)
  249. {
  250. _mesa_init_glsl_driver_functions(functions);
  251. #if FEATURE_accum
  252. st_init_accum_functions(functions);
  253. #endif
  254. #if FEATURE_EXT_framebuffer_blit
  255. st_init_blit_functions(functions);
  256. #endif
  257. st_init_bufferobject_functions(functions);
  258. st_init_clear_functions(functions);
  259. #if FEATURE_drawpix
  260. st_init_bitmap_functions(functions);
  261. st_init_drawpixels_functions(functions);
  262. st_init_rasterpos_functions(functions);
  263. #endif
  264. st_init_fbo_functions(functions);
  265. st_init_get_functions(functions);
  266. #if FEATURE_feedback
  267. st_init_feedback_functions(functions);
  268. #endif
  269. st_init_program_functions(functions);
  270. #if FEATURE_queryobj
  271. st_init_query_functions(functions);
  272. #endif
  273. st_init_readpixels_functions(functions);
  274. st_init_texture_functions(functions);
  275. st_init_flush_functions(functions);
  276. st_init_string_functions(functions);
  277. st_init_viewport_functions(functions);
  278. functions->UpdateState = st_invalidate_state;
  279. }