2007-05-24 10:41:34 +01:00
|
|
|
/**************************************************************************
|
|
|
|
*
|
2007-11-05 18:04:30 -07:00
|
|
|
* Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
|
2007-05-24 10:41:34 +01:00
|
|
|
* All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
* distribute, sub license, and/or sell copies of the Software, and to
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
* the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice (including the
|
|
|
|
* next paragraph) shall be included in all copies or substantial portions
|
|
|
|
* of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
|
|
|
|
* IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
|
|
|
|
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
|
|
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
|
|
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*
|
|
|
|
**************************************************************************/
|
|
|
|
|
2007-08-17 15:27:18 +01:00
|
|
|
#include "main/imports.h"
|
2007-11-01 17:46:04 -06:00
|
|
|
#include "main/context.h"
|
2007-09-25 15:18:51 -06:00
|
|
|
#include "main/extensions.h"
|
2007-12-19 13:45:00 -07:00
|
|
|
#include "main/matrix.h"
|
|
|
|
#include "main/buffers.h"
|
2007-08-17 15:27:18 +01:00
|
|
|
#include "vbo/vbo.h"
|
2007-12-07 17:11:30 -07:00
|
|
|
#include "shader/shader_api.h"
|
2007-05-24 10:41:34 +01:00
|
|
|
#include "st_public.h"
|
|
|
|
#include "st_context.h"
|
2007-10-14 11:52:00 -06:00
|
|
|
#include "st_cb_accum.h"
|
2008-03-20 14:50:17 -06:00
|
|
|
#include "st_cb_bitmap.h"
|
2008-03-18 17:16:23 -06:00
|
|
|
#include "st_cb_blit.h"
|
2008-03-20 14:50:17 -06:00
|
|
|
#include "st_cb_bufferobjects.h"
|
2007-08-02 10:29:50 -06:00
|
|
|
#include "st_cb_clear.h"
|
2007-08-02 14:21:16 -06:00
|
|
|
#include "st_cb_drawpixels.h"
|
2007-08-09 12:27:44 -06:00
|
|
|
#include "st_cb_fbo.h"
|
2007-09-17 14:24:11 -06:00
|
|
|
#include "st_cb_feedback.h"
|
2008-03-24 11:55:29 -06:00
|
|
|
#include "st_cb_program.h"
|
2007-08-11 19:57:37 +01:00
|
|
|
#include "st_cb_queryobj.h"
|
2007-09-10 16:28:27 -06:00
|
|
|
#include "st_cb_rasterpos.h"
|
2007-08-10 11:37:21 -06:00
|
|
|
#include "st_cb_readpixels.h"
|
2007-08-06 15:49:11 -06:00
|
|
|
#include "st_cb_texture.h"
|
2007-08-10 12:57:14 +01:00
|
|
|
#include "st_cb_flush.h"
|
2007-08-10 16:42:26 +01:00
|
|
|
#include "st_cb_strings.h"
|
2007-05-24 10:41:34 +01:00
|
|
|
#include "st_atom.h"
|
|
|
|
#include "st_draw.h"
|
2007-11-05 18:04:30 -07:00
|
|
|
#include "st_extensions.h"
|
2008-02-08 14:54:18 -07:00
|
|
|
#include "st_gen_mipmap.h"
|
2007-05-24 10:41:34 +01:00
|
|
|
#include "st_program.h"
|
2007-06-14 18:23:43 +01:00
|
|
|
#include "pipe/p_context.h"
|
2008-01-25 20:53:31 +00:00
|
|
|
#include "pipe/p_inlines.h"
|
2008-02-15 17:50:12 +09:00
|
|
|
#include "draw/draw_context.h"
|
|
|
|
#include "cso_cache/cso_cache.h"
|
2008-03-11 18:54:31 -06:00
|
|
|
#include "cso_cache/cso_context.h"
|
2007-05-24 10:41:34 +01:00
|
|
|
|
2007-08-10 11:37:21 -06:00
|
|
|
|
2007-10-31 11:08:07 -06:00
|
|
|
/**
|
|
|
|
* Called via ctx->Driver.UpdateState()
|
|
|
|
*/
|
2007-05-24 10:41:34 +01:00
|
|
|
void st_invalidate_state(GLcontext * ctx, GLuint new_state)
|
|
|
|
{
|
|
|
|
struct st_context *st = st_context(ctx);
|
|
|
|
|
|
|
|
st->dirty.mesa |= new_state;
|
|
|
|
st->dirty.st |= ST_NEW_MESA;
|
2007-10-31 11:08:07 -06:00
|
|
|
|
|
|
|
/* This is the only core Mesa module we depend upon.
|
|
|
|
* No longer use swrast, swsetup, tnl.
|
|
|
|
*/
|
|
|
|
_vbo_InvalidateState(ctx, new_state);
|
2007-05-24 10:41:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-05 16:15:43 -07:00
|
|
|
static struct st_context *
|
|
|
|
st_create_context_priv( GLcontext *ctx, struct pipe_context *pipe )
|
2007-05-24 10:41:34 +01:00
|
|
|
{
|
2008-03-11 18:54:31 -06:00
|
|
|
uint i;
|
2007-05-24 10:41:34 +01:00
|
|
|
struct st_context *st = CALLOC_STRUCT( st_context );
|
|
|
|
|
|
|
|
ctx->st = st;
|
|
|
|
|
|
|
|
st->ctx = ctx;
|
2007-06-14 18:23:43 +01:00
|
|
|
st->pipe = pipe;
|
2007-05-24 10:41:34 +01:00
|
|
|
|
2007-10-31 11:35:50 -06:00
|
|
|
/* state tracker needs the VBO module */
|
|
|
|
_vbo_CreateContext(ctx);
|
|
|
|
|
2007-09-17 14:24:11 -06:00
|
|
|
st->draw = draw_create(); /* for selection/feedback */
|
|
|
|
|
2008-03-25 14:12:55 -06:00
|
|
|
/* Disable draw options that might convert points/lines to tris, etc.
|
|
|
|
* as that would foul-up feedback/selection mode.
|
|
|
|
*/
|
|
|
|
draw_wide_line_threshold(st->draw, 1000.0f);
|
|
|
|
draw_wide_point_threshold(st->draw, 1000.0f);
|
|
|
|
draw_enable_line_stipple(st->draw, FALSE);
|
|
|
|
draw_enable_point_sprites(st->draw, FALSE);
|
|
|
|
|
2007-05-24 10:41:34 +01:00
|
|
|
st->dirty.mesa = ~0;
|
|
|
|
st->dirty.st = ~0;
|
|
|
|
|
2008-03-11 18:54:31 -06:00
|
|
|
st->cso_context = cso_create_context(pipe);
|
2007-09-14 04:08:58 -04:00
|
|
|
|
2007-05-24 10:41:34 +01:00
|
|
|
st_init_atoms( st );
|
2008-03-28 14:53:47 -06:00
|
|
|
st_init_bitmap(st);
|
2008-04-03 12:54:32 -06:00
|
|
|
st_init_clear(st);
|
2007-05-24 10:41:34 +01:00
|
|
|
st_init_draw( st );
|
2008-02-08 14:54:18 -07:00
|
|
|
st_init_generate_mipmap(st);
|
2008-03-18 17:16:23 -06:00
|
|
|
st_init_blit(st);
|
2007-08-02 20:40:19 -06:00
|
|
|
|
2008-03-11 18:54:31 -06:00
|
|
|
for (i = 0; i < PIPE_MAX_SAMPLERS; i++)
|
|
|
|
st->state.sampler_list[i] = &st->state.samplers[i];
|
|
|
|
|
2007-08-17 15:27:18 +01:00
|
|
|
/* we want all vertex data to be placed in buffer objects */
|
|
|
|
vbo_use_buffer_objects(ctx);
|
|
|
|
|
2007-08-06 20:53:28 +01:00
|
|
|
/* Need these flags:
|
|
|
|
*/
|
|
|
|
st->ctx->FragmentProgram._MaintainTexEnvProgram = GL_TRUE;
|
|
|
|
st->ctx->FragmentProgram._UseTexEnvProgram = GL_TRUE;
|
|
|
|
|
2007-08-16 17:33:49 -06:00
|
|
|
st->ctx->VertexProgram._MaintainTnlProgram = GL_TRUE;
|
|
|
|
|
2007-10-30 16:13:37 -06:00
|
|
|
st->pixel_xfer.cache = _mesa_new_program_cache();
|
2007-10-30 12:24:05 -06:00
|
|
|
|
2007-11-05 18:04:30 -07:00
|
|
|
/* GL limits and extensions */
|
|
|
|
st_init_limits(st);
|
|
|
|
st_init_extensions(st);
|
2007-08-21 20:15:00 -06:00
|
|
|
|
2007-05-24 10:41:34 +01:00
|
|
|
return st;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-05 16:15:43 -07:00
|
|
|
struct st_context *st_create_context(struct pipe_context *pipe,
|
|
|
|
const __GLcontextModes *visual,
|
|
|
|
struct st_context *share)
|
2007-11-01 17:46:04 -06:00
|
|
|
{
|
2007-11-05 16:15:43 -07:00
|
|
|
GLcontext *ctx;
|
|
|
|
GLcontext *shareCtx = share ? share->ctx : NULL;
|
|
|
|
struct dd_function_table funcs;
|
|
|
|
|
|
|
|
memset(&funcs, 0, sizeof(funcs));
|
|
|
|
st_init_driver_functions(&funcs);
|
|
|
|
|
|
|
|
ctx = _mesa_create_context(visual, shareCtx, &funcs, NULL);
|
|
|
|
|
|
|
|
return st_create_context_priv(ctx, pipe);
|
2007-11-01 17:46:04 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-05 16:15:43 -07:00
|
|
|
static void st_destroy_context_priv( struct st_context *st )
|
2007-05-24 10:41:34 +01:00
|
|
|
{
|
2007-12-26 07:16:12 -07:00
|
|
|
uint i;
|
|
|
|
|
2008-05-07 08:55:33 -06:00
|
|
|
st_reference_fragprog(st, &st->fp, NULL);
|
|
|
|
st_reference_vertprog(st, &st->vp, NULL);
|
|
|
|
|
2007-09-17 14:24:11 -06:00
|
|
|
draw_destroy(st->draw);
|
2007-05-24 10:41:34 +01:00
|
|
|
st_destroy_atoms( st );
|
|
|
|
st_destroy_draw( st );
|
2008-03-18 17:16:23 -06:00
|
|
|
st_destroy_generate_mipmap(st);
|
2008-03-20 14:50:17 -06:00
|
|
|
st_destroy_bitmap(st);
|
2008-03-18 17:16:23 -06:00
|
|
|
st_destroy_blit(st);
|
2008-03-20 09:13:51 -06:00
|
|
|
st_destroy_clear(st);
|
2007-08-02 20:40:19 -06:00
|
|
|
|
2007-10-31 11:35:50 -06:00
|
|
|
_vbo_DestroyContext(st->ctx);
|
|
|
|
|
2007-12-26 07:16:12 -07:00
|
|
|
for (i = 0; i < Elements(st->state.constants); i++) {
|
|
|
|
if (st->state.constants[i].buffer) {
|
2008-04-30 10:43:59 -06:00
|
|
|
pipe_reference_buffer(st->pipe, &st->state.constants[i].buffer, NULL);
|
2007-12-26 07:16:12 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-05 09:35:31 -07:00
|
|
|
free( st );
|
2007-05-24 10:41:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-05 16:15:43 -07:00
|
|
|
void st_destroy_context( struct st_context *st )
|
|
|
|
{
|
2008-04-24 12:11:24 -06:00
|
|
|
struct pipe_context *pipe = st->pipe;
|
|
|
|
struct cso_context *cso = st->cso_context;
|
2007-11-05 16:15:43 -07:00
|
|
|
GLcontext *ctx = st->ctx;
|
2008-04-17 11:12:44 -06:00
|
|
|
|
|
|
|
/* need to unbind and destroy CSO objects before anything else */
|
2008-04-24 12:11:24 -06:00
|
|
|
cso_release_all(st->cso_context);
|
2008-04-17 11:12:44 -06:00
|
|
|
|
|
|
|
_mesa_delete_program_cache(st->ctx, st->pixel_xfer.cache);
|
|
|
|
|
2007-11-05 16:15:43 -07:00
|
|
|
_mesa_free_context_data(ctx);
|
2008-04-24 12:11:24 -06:00
|
|
|
|
2007-11-05 16:15:43 -07:00
|
|
|
st_destroy_context_priv(st);
|
2008-04-24 12:11:24 -06:00
|
|
|
|
|
|
|
cso_destroy_context(cso);
|
|
|
|
|
|
|
|
pipe->destroy( pipe );
|
|
|
|
|
2007-11-05 16:15:43 -07:00
|
|
|
free(ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-02 13:22:22 -06:00
|
|
|
void st_make_current(struct st_context *st,
|
|
|
|
struct st_framebuffer *draw,
|
|
|
|
struct st_framebuffer *read)
|
|
|
|
{
|
|
|
|
if (st) {
|
2007-12-19 13:45:00 -07:00
|
|
|
GLboolean firstTime = st->ctx->FirstTimeCurrent;
|
2007-11-02 13:22:22 -06:00
|
|
|
_mesa_make_current(st->ctx, &draw->Base, &read->Base);
|
2007-12-19 13:45:00 -07:00
|
|
|
/* Need to initialize viewport here since draw->Base->Width/Height
|
|
|
|
* will still be zero at this point.
|
|
|
|
* This could be improved, but would require rather extensive work
|
|
|
|
* elsewhere (allocate rb surface storage sooner)
|
|
|
|
*/
|
|
|
|
if (firstTime) {
|
|
|
|
GLuint w = draw->InitWidth, h = draw->InitHeight;
|
|
|
|
_mesa_set_viewport(st->ctx, 0, 0, w, h);
|
|
|
|
_mesa_set_scissor(st->ctx, 0, 0, w, h);
|
|
|
|
|
|
|
|
}
|
2007-11-02 13:22:22 -06:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
_mesa_make_current(NULL, NULL, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-05 15:59:55 -07:00
|
|
|
void st_copy_context_state(struct st_context *dst,
|
|
|
|
struct st_context *src,
|
|
|
|
uint mask)
|
|
|
|
{
|
|
|
|
_mesa_copy_context(dst->ctx, src->ctx, mask);
|
|
|
|
}
|
|
|
|
|
2007-05-24 10:41:34 +01:00
|
|
|
|
2007-08-06 20:53:28 +01:00
|
|
|
void st_init_driver_functions(struct dd_function_table *functions)
|
|
|
|
{
|
2007-11-07 08:18:50 -07:00
|
|
|
_mesa_init_glsl_driver_functions(functions);
|
|
|
|
|
2007-10-14 11:52:00 -06:00
|
|
|
st_init_accum_functions(functions);
|
2008-03-20 14:50:17 -06:00
|
|
|
st_init_bitmap_functions(functions);
|
2008-03-18 17:16:23 -06:00
|
|
|
st_init_blit_functions(functions);
|
2008-03-20 14:50:17 -06:00
|
|
|
st_init_bufferobject_functions(functions);
|
2007-08-06 20:53:28 +01:00
|
|
|
st_init_clear_functions(functions);
|
|
|
|
st_init_drawpixels_functions(functions);
|
2007-08-09 12:27:44 -06:00
|
|
|
st_init_fbo_functions(functions);
|
2007-09-17 14:24:11 -06:00
|
|
|
st_init_feedback_functions(functions);
|
2007-08-06 20:53:28 +01:00
|
|
|
st_init_program_functions(functions);
|
2007-08-11 19:57:37 +01:00
|
|
|
st_init_query_functions(functions);
|
2007-09-10 16:28:27 -06:00
|
|
|
st_init_rasterpos_functions(functions);
|
2007-08-10 11:37:21 -06:00
|
|
|
st_init_readpixels_functions(functions);
|
2007-08-06 20:53:28 +01:00
|
|
|
st_init_texture_functions(functions);
|
2007-08-10 12:57:14 +01:00
|
|
|
st_init_flush_functions(functions);
|
2007-08-10 16:42:26 +01:00
|
|
|
st_init_string_functions(functions);
|
2007-10-31 11:08:07 -06:00
|
|
|
|
|
|
|
functions->UpdateState = st_invalidate_state;
|
2007-08-06 20:53:28 +01:00
|
|
|
}
|