1 /**************************************************************************
3 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
29 #include "main/glheader.h"
30 #include "main/context.h"
32 #include "pipe/p_defines.h"
33 #include "st_context.h"
35 #include "st_cb_bitmap.h"
36 #include "st_program.h"
37 #include "st_manager.h"
41 * This is used to initialize st->atoms[].
43 static const struct st_tracked_state *atoms[] =
45 &st_update_depth_stencil_alpha,
48 &st_finalize_textures,
53 &st_update_rasterizer,
54 &st_update_polygon_stipple,
59 &st_update_vertex_texture,
61 &st_update_framebuffer,
63 &st_update_vs_constants,
64 &st_update_gs_constants,
65 &st_update_fs_constants,
66 &st_update_pixel_transfer
70 void st_init_atoms( struct st_context *st )
76 void st_destroy_atoms( struct st_context *st )
82 /***********************************************************************
85 static GLboolean check_state( const struct st_state_flags *a,
86 const struct st_state_flags *b )
88 return ((a->mesa & b->mesa) ||
92 static void accumulate_state( struct st_state_flags *a,
93 const struct st_state_flags *b )
100 static void xor_states( struct st_state_flags *result,
101 const struct st_state_flags *a,
102 const struct st_state_flags *b )
104 result->mesa = a->mesa ^ b->mesa;
105 result->st = a->st ^ b->st;
109 /* Too complex to figure out, just check every time:
111 static void check_program_state( struct st_context *st )
113 struct gl_context *ctx = st->ctx;
115 if (ctx->VertexProgram._Current != &st->vp->Base)
116 st->dirty.st |= ST_NEW_VERTEX_PROGRAM;
118 if (ctx->FragmentProgram._Current != &st->fp->Base)
119 st->dirty.st |= ST_NEW_FRAGMENT_PROGRAM;
121 if (ctx->GeometryProgram._Current != &st->gp->Base)
122 st->dirty.st |= ST_NEW_GEOMETRY_PROGRAM;
126 /***********************************************************************
127 * Update all derived state:
130 void st_validate_state( struct st_context *st )
132 struct st_state_flags *state = &st->dirty;
135 /* The bitmap cache is immune to pixel unpack changes.
136 * Note that GLUT makes several calls to glPixelStore for each
137 * bitmap char it draws so this is an important check.
139 if (state->mesa & ~_NEW_PACKUNPACK)
140 st_flush_bitmap_cache(st);
142 check_program_state( st );
144 st_manager_validate_framebuffers(st);
149 /*printf("%s %x/%x\n", __FUNCTION__, state->mesa, state->st);*/
156 /* Debug version which enforces various sanity checks on the
157 * state flags which are generated and checked to help ensure
158 * state atoms are ordered correctly in the list.
160 struct st_state_flags examined, prev;
161 memset(&examined, 0, sizeof(examined));
164 for (i = 0; i < Elements(atoms); i++) {
165 const struct st_tracked_state *atom = atoms[i];
166 struct st_state_flags generated;
168 /*printf("atom %s %x/%x\n", atom->name, atom->dirty.mesa, atom->dirty.st);*/
170 if (!(atom->dirty.mesa || atom->dirty.st) ||
172 printf("malformed atom %s\n", atom->name);
176 if (check_state(state, &atom->dirty)) {
177 atoms[i]->update( st );
178 /*printf("after: %x\n", atom->dirty.mesa);*/
181 accumulate_state(&examined, &atom->dirty);
183 /* generated = (prev ^ state)
184 * if (examined & generated)
187 xor_states(&generated, &prev, state);
188 assert(!check_state(&examined, &generated));
195 for (i = 0; i < Elements(atoms); i++) {
196 if (check_state(state, &atoms[i]->dirty))
197 atoms[i]->update( st );
201 memset(state, 0, sizeof(*state));