summaryrefslogtreecommitdiff
path: root/src/mesa/state_tracker
diff options
context:
space:
mode:
Diffstat (limited to 'src/mesa/state_tracker')
-rw-r--r--src/mesa/state_tracker/Makefile2
-rw-r--r--src/mesa/state_tracker/st_atom.c175
-rw-r--r--src/mesa/state_tracker/st_atom.h62
-rw-r--r--src/mesa/state_tracker/st_atom_alphatest.c94
-rw-r--r--src/mesa/state_tracker/st_atom_blend.c240
-rw-r--r--src/mesa/state_tracker/st_atom_cbuf.c72
-rw-r--r--src/mesa/state_tracker/st_atom_clear_color.c62
-rw-r--r--src/mesa/state_tracker/st_atom_clip.c75
-rw-r--r--src/mesa/state_tracker/st_atom_depth.c92
-rw-r--r--src/mesa/state_tracker/st_atom_framebuffer.c88
-rw-r--r--src/mesa/state_tracker/st_atom_fs.c102
-rw-r--r--src/mesa/state_tracker/st_atom_sampler.c135
-rw-r--r--src/mesa/state_tracker/st_atom_scissor.c88
-rw-r--r--src/mesa/state_tracker/st_atom_setup.c220
-rw-r--r--src/mesa/state_tracker/st_atom_stencil.c140
-rw-r--r--src/mesa/state_tracker/st_atom_stipple.c62
-rw-r--r--src/mesa/state_tracker/st_atom_viewport.c117
-rw-r--r--src/mesa/state_tracker/st_atom_vs.c49
-rw-r--r--src/mesa/state_tracker/st_cb_program.c170
-rw-r--r--src/mesa/state_tracker/st_context.c76
-rw-r--r--src/mesa/state_tracker/st_context.h116
-rw-r--r--src/mesa/state_tracker/st_draw.c120
-rw-r--r--src/mesa/state_tracker/st_draw.h44
-rw-r--r--src/mesa/state_tracker/st_program.h105
-rw-r--r--src/mesa/state_tracker/st_public.h43
-rw-r--r--src/mesa/state_tracker/st_texobj.c102
-rw-r--r--src/mesa/state_tracker/st_texobj.h41
27 files changed, 2692 insertions, 0 deletions
diff --git a/src/mesa/state_tracker/Makefile b/src/mesa/state_tracker/Makefile
new file mode 100644
index 0000000000..0ab1dc6e6b
--- /dev/null
+++ b/src/mesa/state_tracker/Makefile
@@ -0,0 +1,2 @@
+default:
+ cd ../.. ; make \ No newline at end of file
diff --git a/src/mesa/state_tracker/st_atom.c b/src/mesa/state_tracker/st_atom.c
new file mode 100644
index 0000000000..85c99bc182
--- /dev/null
+++ b/src/mesa/state_tracker/st_atom.c
@@ -0,0 +1,175 @@
+/**************************************************************************
+ *
+ * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * 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.
+ *
+ **************************************************************************/
+
+
+#include "glheader.h"
+#include "context.h"
+
+#include "st_context.h"
+#include "st_atom.h"
+
+
+
+/* This is used to initialize st->atoms[]. We could use this list
+ * directly except for a single atom, st_update_constants, which has a
+ * .dirty value which changes according to the parameters of the
+ * current fragment and vertex programs, and so cannot be a static
+ * value.
+ */
+static const struct st_tracked_state *atoms[] =
+{
+ &st_update_framebuffer,
+ &st_update_clear_color,
+ &st_update_depth,
+ &st_update_clip,
+ &st_update_vs,
+ &st_update_fs,
+ &st_update_setup,
+ &st_update_polygon_stipple,
+ &st_update_viewport,
+ &st_update_scissor,
+ &st_update_blend,
+ &st_update_stencil,
+ /* will be patched out at runtime */
+/* &st_update_constants */
+};
+
+
+void st_init_atoms( struct st_context *st )
+{
+ GLuint i;
+
+ st->atoms = malloc(sizeof(atoms));
+ st->nr_atoms = sizeof(atoms)/sizeof(*atoms);
+ memcpy(st->atoms, atoms, sizeof(atoms));
+
+ /* Patch in a pointer to the dynamic state atom:
+ */
+ for (i = 0; i < st->nr_atoms; i++)
+ if (st->atoms[i] == &st_update_constants)
+ st->atoms[i] = &st->constants.tracked_state;
+
+ memcpy(&st->constants.tracked_state,
+ &st_update_constants,
+ sizeof(st_update_constants));
+}
+
+
+void st_destroy_atoms( struct st_context *st )
+{
+ if (st->atoms) {
+ free(st->atoms);
+ st->atoms = NULL;
+ }
+}
+
+
+/***********************************************************************
+ */
+
+static GLboolean check_state( const struct st_state_flags *a,
+ const struct st_state_flags *b )
+{
+ return ((a->mesa & b->mesa) ||
+ (a->st & b->st));
+}
+
+static void accumulate_state( struct st_state_flags *a,
+ const struct st_state_flags *b )
+{
+ a->mesa |= b->mesa;
+ a->st |= b->st;
+}
+
+
+static void xor_states( struct st_state_flags *result,
+ const struct st_state_flags *a,
+ const struct st_state_flags *b )
+{
+ result->mesa = a->mesa ^ b->mesa;
+ result->st = a->st ^ b->st;
+}
+
+
+/***********************************************************************
+ * Update all derived state:
+ */
+
+void st_validate_state( struct st_context *st )
+{
+ struct st_state_flags *state = &st->dirty;
+ GLuint i;
+
+ if (state->st == 0)
+ return;
+
+ if (1) {
+ /* Debug version which enforces various sanity checks on the
+ * state flags which are generated and checked to help ensure
+ * state atoms are ordered correctly in the list.
+ */
+ struct st_state_flags examined, prev;
+ memset(&examined, 0, sizeof(examined));
+ prev = *state;
+
+ for (i = 0; i < st->nr_atoms; i++) {
+ const struct st_tracked_state *atom = st->atoms[i];
+ struct st_state_flags generated;
+
+ assert(atom->dirty.mesa ||
+ atom->dirty.st);
+ assert(atom->update);
+
+ if (check_state(state, &atom->dirty)) {
+ st->atoms[i]->update( st );
+ }
+
+ accumulate_state(&examined, &atom->dirty);
+
+ /* generated = (prev ^ state)
+ * if (examined & generated)
+ * fail;
+ */
+ xor_states(&generated, &prev, state);
+ assert(!check_state(&examined, &generated));
+ prev = *state;
+ }
+ }
+ else {
+ const GLuint nr = st->nr_atoms;
+
+ for (i = 0; i < nr; i++) {
+ if (check_state(state, &st->atoms[i]->dirty))
+ st->atoms[i]->update( st );
+ }
+ }
+
+ memset(state, 0, sizeof(*state));
+}
+
+
+
diff --git a/src/mesa/state_tracker/st_atom.h b/src/mesa/state_tracker/st_atom.h
new file mode 100644
index 0000000000..1b70e27933
--- /dev/null
+++ b/src/mesa/state_tracker/st_atom.h
@@ -0,0 +1,62 @@
+/**************************************************************************
+ *
+ * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * 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.
+ *
+ **************************************************************************/
+
+ /*
+ * Authors:
+ * Keith Whitwell <keith@tungstengraphics.com>
+ */
+
+
+#ifndef ST_ATOM_H
+#define ST_ATOM_H
+
+struct st_context;
+struct st_tracked_state;
+
+void st_init_atoms( struct st_context *st );
+void st_destroy_atoms( struct st_context *st );
+
+
+void st_validate_state( struct st_context *st );
+
+
+const struct st_tracked_state st_update_framebuffer;
+const struct st_tracked_state st_update_clip;
+const struct st_tracked_state st_update_clear_color;
+const struct st_tracked_state st_update_depth;
+const struct st_tracked_state st_update_fs;
+const struct st_tracked_state st_update_vs;
+const struct st_tracked_state st_update_setup;
+const struct st_tracked_state st_update_polygon_stipple;
+const struct st_tracked_state st_update_viewport;
+const struct st_tracked_state st_update_constants;
+const struct st_tracked_state st_update_scissor;
+const struct st_tracked_state st_update_blend;
+const struct st_tracked_state st_update_stencil;
+
+
+#endif
diff --git a/src/mesa/state_tracker/st_atom_alphatest.c b/src/mesa/state_tracker/st_atom_alphatest.c
new file mode 100644
index 0000000000..1e2e449795
--- /dev/null
+++ b/src/mesa/state_tracker/st_atom_alphatest.c
@@ -0,0 +1,94 @@
+/**************************************************************************
+ *
+ * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * 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.
+ *
+ **************************************************************************/
+
+ /*
+ * Authors:
+ * Keith Whitwell <keith@tungstengraphics.com>
+ * Brian Paul
+ */
+
+
+#include "st_context.h"
+#include "st_atom.h"
+#include "pipe/p_context.h"
+#include "pipe/p_defines.h"
+
+
+/**
+ * Convert GLenum stencil func tokens to pipe tokens.
+ */
+static GLuint
+gl_alpha_func_to_sp(GLenum func)
+{
+ /* Same values, just biased */
+ assert(PIPE_FUNC_NEVER == GL_NEVER - GL_NEVER);
+ assert(PIPE_FUNC_LESS == GL_LESS - GL_NEVER);
+ assert(PIPE_FUNC_EQUAL == GL_EQUAL - GL_NEVER);
+ assert(PIPE_FUNC_LEQUAL == GL_LEQUAL - GL_NEVER);
+ assert(PIPE_FUNC_GREATER == GL_GREATER - GL_NEVER);
+ assert(PIPE_FUNC_NOTEQUAL == GL_NOTEQUAL - GL_NEVER);
+ assert(PIPE_FUNC_GEQUAL == GL_GEQUAL - GL_NEVER);
+ assert(PIPE_FUNC_ALWAYS == GL_ALWAYS - GL_NEVER);
+ assert(func >= GL_NEVER);
+ assert(func <= GL_ALWAYS);
+ return func - GL_NEVER;
+}
+
+
+static void
+update_alpha_test( struct st_context *st )
+{
+ struct pipe_alpha_test_state alpha;
+
+ memset(&alpha, 0, sizeof(alpha));
+
+ if (st->ctx->Color.AlphaEnabled) {
+ alpha.enabled = 1;
+ alpha.func = gl_alpha_func_to_sp(st->ctx->Color.AlphaFunc);
+ alpha.ref = st->ctx->Color.AlphaRef;
+ }
+
+ if (memcmp(&alpha, &st->state.alpha_test, sizeof(alpha)) != 0) {
+ /* state has changed */
+ st->state.alpha_test = alpha; /* struct copy */
+ st->pipe->set_alpha_test_state(st->pipe, &alpha); /* set new state */
+ }
+}
+
+
+const struct st_tracked_state st_update_alpha_test = {
+ .dirty = {
+ .mesa = (_NEW_COLOR),
+ .st = 0,
+ },
+ .update = update_alpha_test
+};
+
+
+
+
+
diff --git a/src/mesa/state_tracker/st_atom_blend.c b/src/mesa/state_tracker/st_atom_blend.c
new file mode 100644
index 0000000000..256f13471a
--- /dev/null
+++ b/src/mesa/state_tracker/st_atom_blend.c
@@ -0,0 +1,240 @@
+/**************************************************************************
+ *
+ * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * 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.
+ *
+ **************************************************************************/
+
+ /*
+ * Authors:
+ * Keith Whitwell <keith@tungstengraphics.com>
+ * Brian Paul
+ */
+
+
+#include "st_context.h"
+#include "st_atom.h"
+#include "pipe/p_context.h"
+#include "pipe/p_defines.h"
+
+
+/**
+ * Convert GLenum blend tokens to pipe tokens.
+ * Both blend factors and blend funcs are accepted.
+ */
+static GLuint
+gl_blend_to_sp(GLenum blend)
+{
+ switch (blend) {
+ /* blend functions */
+ case GL_FUNC_ADD:
+ return PIPE_BLEND_ADD;
+ case GL_FUNC_SUBTRACT:
+ return PIPE_BLEND_SUBTRACT;
+ case GL_FUNC_REVERSE_SUBTRACT:
+ return PIPE_BLEND_REVERSE_SUBTRACT;
+ case GL_MIN:
+ return PIPE_BLEND_MIN;
+ case GL_MAX:
+ return PIPE_BLEND_MAX;
+
+ /* blend factors */
+ case GL_ONE:
+ return PIPE_BLENDFACTOR_ONE;
+ case GL_SRC_COLOR:
+ return PIPE_BLENDFACTOR_SRC_COLOR;
+ case GL_SRC_ALPHA:
+ return PIPE_BLENDFACTOR_SRC_ALPHA;
+ case GL_DST_ALPHA:
+ return PIPE_BLENDFACTOR_DST_ALPHA;
+ case GL_DST_COLOR:
+ return PIPE_BLENDFACTOR_DST_COLOR;
+ case GL_SRC_ALPHA_SATURATE:
+ return PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE;
+ case GL_CONSTANT_COLOR:
+ return PIPE_BLENDFACTOR_CONST_COLOR;
+ case GL_CONSTANT_ALPHA:
+ return PIPE_BLENDFACTOR_CONST_ALPHA;
+ /*
+ return PIPE_BLENDFACTOR_SRC1_COLOR;
+ return PIPE_BLENDFACTOR_SRC1_ALPHA;
+ */
+ case GL_ZERO:
+ return PIPE_BLENDFACTOR_ZERO;
+ case GL_ONE_MINUS_SRC_COLOR:
+ return PIPE_BLENDFACTOR_INV_SRC_COLOR;
+ case GL_ONE_MINUS_SRC_ALPHA:
+ return PIPE_BLENDFACTOR_INV_SRC_ALPHA;
+ case GL_ONE_MINUS_DST_COLOR:
+ return PIPE_BLENDFACTOR_INV_DST_ALPHA;
+ case GL_ONE_MINUS_DST_ALPHA:
+ return PIPE_BLENDFACTOR_INV_DST_COLOR;
+ case GL_ONE_MINUS_CONSTANT_COLOR:
+ return PIPE_BLENDFACTOR_INV_CONST_COLOR;
+ case GL_ONE_MINUS_CONSTANT_ALPHA:
+ return PIPE_BLENDFACTOR_INV_CONST_ALPHA;
+ /*
+ return PIPE_BLENDFACTOR_INV_SRC1_COLOR;
+ return PIPE_BLENDFACTOR_INV_SRC1_ALPHA;
+ */
+ default:
+ assert("invalid GL token in gl_blend_to_sp()" == NULL);
+ return 0;
+ }
+}
+
+
+/**
+ * Convert GLenum logicop tokens to pipe tokens.
+ */
+static GLuint
+gl_logicop_to_sp(GLenum logicop)
+{
+ switch (logicop) {
+ case GL_CLEAR:
+ return PIPE_LOGICOP_CLEAR;
+ case GL_NOR:
+ return PIPE_LOGICOP_NOR;
+ case GL_AND_INVERTED:
+ return PIPE_LOGICOP_AND_INVERTED;
+ case GL_COPY_INVERTED:
+ return PIPE_LOGICOP_COPY_INVERTED;
+ case GL_AND_REVERSE:
+ return PIPE_LOGICOP_AND_REVERSE;
+ case GL_INVERT:
+ return PIPE_LOGICOP_INVERT;
+ case GL_XOR:
+ return PIPE_LOGICOP_XOR;
+ case GL_NAND:
+ return PIPE_LOGICOP_NAND;
+ case GL_AND:
+ return PIPE_LOGICOP_AND;
+ case GL_EQUIV:
+ return PIPE_LOGICOP_EQUIV;
+ case GL_NOOP:
+ return PIPE_LOGICOP_NOOP;
+ case GL_OR_INVERTED:
+ return PIPE_LOGICOP_OR_INVERTED;
+ case GL_COPY:
+ return PIPE_LOGICOP_COPY;
+ case GL_OR_REVERSE:
+ return PIPE_LOGICOP_OR_REVERSE;
+ case GL_OR:
+ return PIPE_LOGICOP_OR;
+ case GL_SET:
+ return PIPE_LOGICOP_SET;
+ default:
+ assert("invalid GL token in gl_logicop_to_sp()" == NULL);
+ return 0;
+ }
+}
+
+
+static void
+update_blend( struct st_context *st )
+{
+ struct pipe_blend_state blend;
+
+ memset(&blend, 0, sizeof(blend));
+
+ if (st->ctx->Color.ColorLogicOpEnabled ||
+ (st->ctx->Color.BlendEnabled &&
+ st->ctx->Color.BlendEquationRGB == GL_LOGIC_OP)) {
+ /* logicop enabled */
+ blend.logicop_enable = 1;
+ blend.logicop_func = gl_logicop_to_sp(st->ctx->Color.LogicOp);
+ }
+ else if (st->ctx->Color.BlendEnabled) {
+ /* blending enabled */
+ blend.blend_enable = 1;
+
+ blend.rgb_func = gl_blend_to_sp(st->ctx->Color.BlendEquationRGB);
+ if (st->ctx->Color.BlendEquationRGB == GL_MIN ||
+ st->ctx->Color.BlendEquationRGB == GL_MAX) {
+ /* Min/max are special */
+ blend.rgb_src_factor = PIPE_BLENDFACTOR_ONE;
+ blend.rgb_dst_factor = PIPE_BLENDFACTOR_ONE;
+ }
+ else {
+ blend.rgb_src_factor = gl_blend_to_sp(st->ctx->Color.BlendSrcRGB);
+ blend.rgb_dst_factor = gl_blend_to_sp(st->ctx->Color.BlendDstRGB);
+ }
+
+ blend.alpha_func = gl_blend_to_sp(st->ctx->Color.BlendEquationA);
+ if (st->ctx->Color.BlendEquationA == GL_MIN ||
+ st->ctx->Color.BlendEquationA == GL_MAX) {
+ /* Min/max are special */
+ blend.alpha_src_factor = PIPE_BLENDFACTOR_ONE;
+ blend.alpha_dst_factor = PIPE_BLENDFACTOR_ONE;
+ }
+ else {
+ blend.alpha_src_factor = gl_blend_to_sp(st->ctx->Color.BlendSrcA);
+ blend.alpha_dst_factor = gl_blend_to_sp(st->ctx->Color.BlendDstA);
+ }
+ }
+ else {
+ /* no blending / logicop */
+ }
+
+ /* Colormask - maybe reverse these bits? */
+ if (st->ctx->Color.ColorMask[0])
+ blend.colormask |= PIPE_MASK_R;
+ if (st->ctx->Color.ColorMask[1])
+ blend.colormask |= PIPE_MASK_G;
+ if (st->ctx->Color.ColorMask[2])
+ blend.colormask |= PIPE_MASK_B;
+ if (st->ctx->Color.ColorMask[3])
+ blend.colormask |= PIPE_MASK_A;
+
+ if (st->ctx->Color.DitherFlag)
+ blend.dither = 1;
+
+ if (memcmp(&blend, &st->state.blend, sizeof(blend)) != 0) {
+ /* state has changed */
+ st->state.blend = blend; /* struct copy */
+ st->pipe->set_blend_state(st->pipe, &blend); /* set new state */
+ }
+
+ if (memcmp(st->ctx->Color.BlendColor, &st->state.blend_color, 4 * sizeof(GLfloat)) != 0) {
+ /* state has changed */
+ st->state.blend_color.color[0] = st->ctx->Color.BlendColor[0];
+ st->state.blend_color.color[1] = st->ctx->Color.BlendColor[1];
+ st->state.blend_color.color[2] = st->ctx->Color.BlendColor[2];
+ st->state.blend_color.color[3] = st->ctx->Color.BlendColor[3];
+ st->pipe->set_blend_color(st->pipe, (struct pipe_blend_color *) st->ctx->Color.BlendColor);
+ }
+}
+
+
+const struct st_tracked_state st_update_blend = {
+ .dirty = {
+ .mesa = (_NEW_COLOR), /* XXX _NEW_BLEND someday? */
+ .st = 0,
+ },
+ .update = update_blend
+};
+
+
+
+
+
diff --git a/src/mesa/state_tracker/st_atom_cbuf.c b/src/mesa/state_tracker/st_atom_cbuf.c
new file mode 100644
index 0000000000..0f90aa7646
--- /dev/null
+++ b/src/mesa/state_tracker/st_atom_cbuf.c
@@ -0,0 +1,72 @@
+/**************************************************************************
+ *
+ * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * 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.
+ *
+ **************************************************************************/
+
+ /*
+ * Authors:
+ * Keith Whitwell <keith@tungstengraphics.com>
+ */
+
+#include "st_context.h"
+#include "pipe/p_context.h"
+#include "st_atom.h"
+
+extern GLboolean xmesa_get_cbuf_details( GLcontext *ctx,
+ void **ptr,
+ GLuint *cpp,
+ GLint *stride,
+ GLuint *format );
+
+
+/* This is a hack to work with the X11 driver as a test harness
+ */
+static void update_cbuf_state( struct st_context *st )
+{
+ struct pipe_surface cbuf;
+ GLboolean ok;
+
+ ok = xmesa_get_cbuf_details( st->ctx,
+ (void **)&cbuf.ptr,
+ &cbuf.cpp,
+ &cbuf.stride,
+ &cbuf.format );
+
+ assert(ok);
+
+ if (memcmp(&cbuf, &st->state.cbuf, sizeof(cbuf)) != 0) {
+ st->state.cbuf = cbuf;
+ st->pipe->set_cbuf_state( st->pipe, &cbuf );
+ }
+}
+
+const struct st_tracked_state st_update_cbuf = {
+ .dirty = {
+ .mesa = _NEW_BUFFERS,
+ .st = 0,
+ },
+ .update = update_cbuf_state
+};
+
diff --git a/src/mesa/state_tracker/st_atom_clear_color.c b/src/mesa/state_tracker/st_atom_clear_color.c
new file mode 100644
index 0000000000..adf730cd8c
--- /dev/null
+++ b/src/mesa/state_tracker/st_atom_clear_color.c
@@ -0,0 +1,62 @@
+/**************************************************************************
+ *
+ * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * 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.
+ *
+ **************************************************************************/
+
+ /*
+ * Authors:
+ * Keith Whitwell <keith@tungstengraphics.com>
+ * Brian Paul
+ */
+
+#include "st_context.h"
+#include "st_atom.h"
+#include "pipe/p_context.h"
+
+
+static void
+update_clear_color_state( struct st_context *st )
+{
+ struct pipe_clear_color_state clear;
+
+ clear.color[0] = st->ctx->Color.ClearColor[0];
+ clear.color[1] = st->ctx->Color.ClearColor[1];
+ clear.color[2] = st->ctx->Color.ClearColor[2];
+ clear.color[3] = st->ctx->Color.ClearColor[3];
+
+ if (memcmp(&clear, &st->state.clear_color, sizeof(clear)) != 0) {
+ st->state.clear_color = clear;
+ st->pipe->set_clear_color_state( st->pipe, &clear );
+ }
+}
+
+
+const struct st_tracked_state st_update_clear_color = {
+ .dirty = {
+ .mesa = _NEW_COLOR,
+ .st = 0,
+ },
+ .update = update_clear_color_state
+};
diff --git a/src/mesa/state_tracker/st_atom_clip.c b/src/mesa/state_tracker/st_atom_clip.c
new file mode 100644
index 0000000000..8ccad637d5
--- /dev/null
+++ b/src/mesa/state_tracker/st_atom_clip.c
@@ -0,0 +1,75 @@
+/**************************************************************************
+ *
+ * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * 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.
+ *
+ **************************************************************************/
+
+ /*
+ * Authors:
+ * Keith Whitwell <keith@tungstengraphics.com>
+ */
+
+
+#include "st_context.h"
+#include "pipe/p_context.h"
+#include "st_atom.h"
+
+
+/* Second state atom for user clip planes:
+ */
+static void update_clip( struct st_context *st )
+{
+ struct pipe_clip_state clip;
+ GLuint i;
+
+ memset(&clip, 0, sizeof(clip));
+
+ for (i = 0; i < PIPE_MAX_CLIP_PLANES; i++) {
+ if (st->ctx->Transform.ClipPlanesEnabled & (1 << i)) {
+ memcpy(clip.ucp[clip.nr],
+ st->ctx->Transform._ClipUserPlane[i],
+ sizeof(clip.ucp[0]));
+ clip.nr++;
+ }
+ }
+
+ if (memcmp(&clip, &st->state.clip, sizeof(clip)) != 0) {
+ st->state.clip = clip;
+ st->pipe->set_clip_state(st->pipe, &clip);
+ }
+}
+
+
+const struct st_tracked_state st_update_clip = {
+ .dirty = {
+ .mesa = (_NEW_TRANSFORM),
+ .st = 0,
+ },
+ .update = update_clip
+};
+
+
+
+
+
diff --git a/src/mesa/state_tracker/st_atom_depth.c b/src/mesa/state_tracker/st_atom_depth.c
new file mode 100644
index 0000000000..7fc51953dc
--- /dev/null
+++ b/src/mesa/state_tracker/st_atom_depth.c
@@ -0,0 +1,92 @@
+/**************************************************************************
+ *
+ * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * 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.
+ *
+ **************************************************************************/
+
+ /*
+ * Authors:
+ * Keith Whitwell <keith@tungstengraphics.com>
+ * Brian Paul
+ */
+
+
+#include "st_context.h"
+#include "st_atom.h"
+#include "pipe/p_context.h"
+#include "pipe/p_defines.h"
+
+
+/**
+ * Convert GLenum depth func tokens to pipe tokens.
+ */
+static GLuint
+gl_depth_func_to_sp(GLenum func)
+{
+ /* Same values, just biased */
+ assert(PIPE_FUNC_NEVER == GL_NEVER - GL_NEVER);
+ assert(PIPE_FUNC_LESS == GL_LESS - GL_NEVER);
+ assert(PIPE_FUNC_EQUAL == GL_EQUAL - GL_NEVER);
+ assert(PIPE_FUNC_LEQUAL == GL_LEQUAL - GL_NEVER);
+ assert(PIPE_FUNC_GREATER == GL_GREATER - GL_NEVER);
+ assert(PIPE_FUNC_NOTEQUAL == GL_NOTEQUAL - GL_NEVER);
+ assert(PIPE_FUNC_GEQUAL == GL_GEQUAL - GL_NEVER);
+ assert(PIPE_FUNC_ALWAYS == GL_ALWAYS - GL_NEVER);
+ assert(func >= GL_NEVER);
+ assert(func <= GL_ALWAYS);
+ return func - GL_NEVER;
+}
+
+
+static void
+update_depth( struct st_context *st )
+{
+ struct pipe_depth_state depth;
+
+ memset(&depth, 0, sizeof(depth));
+
+ depth.enabled = st->ctx->Depth.Test;
+ depth.writemask = st->ctx->Depth.Mask;
+ depth.func = gl_depth_func_to_sp(st->ctx->Depth.Func);
+ depth.clear = st->ctx->Depth.Clear;
+
+ if (st->ctx->Query.CurrentOcclusionObject &&
+ st->ctx->Query.CurrentOcclusionObject->Active)
+ depth.occlusion_count = 1;
+
+ if (memcmp(&depth, &st->state.depth, sizeof(depth)) != 0) {
+ /* state has changed */
+ st->state.depth = depth; /* struct copy */
+ st->pipe->set_depth_state(st->pipe, &depth); /* set new state */
+ }
+}
+
+
+const struct st_tracked_state st_update_depth = {
+ .dirty = {
+ .mesa = (_NEW_DEPTH),
+ .st = 0,
+ },
+ .update = update_depth
+};
diff --git a/src/mesa/state_tracker/st_atom_framebuffer.c b/src/mesa/state_tracker/st_atom_framebuffer.c
new file mode 100644
index 0000000000..a8d47ea4f4
--- /dev/null
+++ b/src/mesa/state_tracker/st_atom_framebuffer.c
@@ -0,0 +1,88 @@
+/**************************************************************************
+ *
+ * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * 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.
+ *
+ **************************************************************************/
+
+ /*
+ * Authors:
+ * Keith Whitwell <keith@tungstengraphics.com>
+ * Brian Paul
+ */
+
+#include "st_context.h"
+#include "st_atom.h"
+#include "pipe/p_context.h"
+
+
+/**
+ * Update framebuffer state (color, depth, stencil, etc. buffers)
+ * XXX someday: separate draw/read buffers.
+ */
+static void
+update_framebuffer_state( struct st_context *st )
+{
+ struct pipe_framebuffer_state framebuffer;
+ struct gl_renderbuffer *rb;
+ GLuint i;
+
+ memset(&framebuffer, 0, sizeof(framebuffer));
+
+ /* Examine Mesa's ctx->DrawBuffer->_ColorDrawBuffers state
+ * to determine which surfaces to draw to
+ */
+ framebuffer.num_cbufs = st->ctx->DrawBuffer->_NumColorDrawBuffers[0];
+ for (i = 0; i < framebuffer.num_cbufs; i++) {
+ rb = st->ctx->DrawBuffer->_ColorDrawBuffers[0][i];
+ assert(rb->surface);
+ framebuffer.cbufs[i] = rb->surface;
+ }
+
+ rb = st->ctx->DrawBuffer->_DepthBuffer;
+ if (rb) {
+ assert(rb->surface);
+ framebuffer.zbuf = rb->Wrapped->surface;
+ }
+
+ rb = st->ctx->DrawBuffer->_StencilBuffer;
+ if (rb) {
+ assert(rb->surface);
+ framebuffer.sbuf = rb->Wrapped->surface;
+ }
+
+ if (memcmp(&framebuffer, &st->state.framebuffer, sizeof(framebuffer)) != 0) {
+ st->state.framebuffer = framebuffer;
+ st->pipe->set_framebuffer_state( st->pipe, &framebuffer );
+ }
+}
+
+
+const struct st_tracked_state st_update_framebuffer = {
+ .dirty = {
+ .mesa = _NEW_BUFFERS,
+ .st = 0,
+ },
+ .update = update_framebuffer_state
+};
+
diff --git a/src/mesa/state_tracker/st_atom_fs.c b/src/mesa/state_tracker/st_atom_fs.c
new file mode 100644
index 0000000000..9ca1807913
--- /dev/null
+++ b/src/mesa/state_tracker/st_atom_fs.c
@@ -0,0 +1,102 @@
+/**************************************************************************
+ *
+ * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * 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.
+ *
+ **************************************************************************/
+ /*
+ * Authors:
+ * Keith Whitwell <keith@tungstengraphics.com>
+ */
+
+#include "shader/prog_parameter.h"
+#include "st_context.h"
+#include "pipe/p_context.h"
+#include "st_atom.h"
+#include "st_program.h"
+#include "pipe/tgsi/mesa/mesa_to_tgsi.h"
+#include "pipe/tgsi/core/tgsi_dump.h"
+
+static void compile_fs( struct st_context *st,
+ struct st_fragment_program *fs )
+{
+ /* XXX: fix static allocation of tokens:
+ */
+ tgsi_mesa_compile_fp_program( &fs->Base, fs->tokens, ST_FP_MAX_TOKENS );
+
+ tgsi_dump( fs->tokens, TGSI_DUMP_VERBOSE );
+}
+
+
+static void update_fs( struct st_context *st )
+{
+ struct pipe_fs_state fs;
+ struct st_fragment_program *fp = NULL;
+ struct gl_program_parameter_list *params = NULL;
+
+ if (st->ctx->Shader.CurrentProgram &&
+ st->ctx->Shader.CurrentProgram->LinkStatus &&
+ st->ctx->Shader.CurrentProgram->FragmentProgram) {
+ struct gl_fragment_program *f
+ = st->ctx->Shader.CurrentProgram->FragmentProgram;
+ fp = st_fragment_program(f);
+ params = f->Base.Parameters;
+ }
+ else if (st->ctx->FragmentProgram._Current) {
+ fp = st_fragment_program(st->ctx->FragmentProgram._Current);
+ params = st->ctx->FragmentProgram._Current->Base.Parameters;
+ }
+
+ if (fp && params) {
+ /* load program's constants array */
+ fp->constants.nr_constants = params->NumParameters;
+ memcpy(fp->constants.constant,
+ params->ParameterValues,
+ params->NumParameters * sizeof(GLfloat) * 4);
+ }
+
+ if (fp->dirty)
+ compile_fs( st, fp );
+
+ memset( &fs, 0, sizeof(fs) );
+ fs.inputs_read = fp->Base.Base.InputsRead;
+ fs.tokens = &fp->tokens[0];
+ fs.constants = &fp->constants;
+
+ if (memcmp(&fs, &st->state.fs, sizeof(fs)) != 0 ||
+ fp->dirty)
+ {
+ fp->dirty = 0;
+ st->state.fs = fs;
+ st->pipe->set_fs_state(st->pipe, &fs);
+ }
+}
+
+
+const struct st_tracked_state st_update_fs = {
+ .dirty = {
+ .mesa = _NEW_PROGRAM,
+ .st = ST_NEW_FRAGMENT_PROGRAM,
+ },
+ .update = update_fs
+};
diff --git a/src/mesa/state_tracker/st_atom_sampler.c b/src/mesa/state_tracker/st_atom_sampler.c
new file mode 100644
index 0000000000..1aa9da8484
--- /dev/null
+++ b/src/mesa/state_tracker/st_atom_sampler.c
@@ -0,0 +1,135 @@
+/**************************************************************************
+ *
+ * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * 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.
+ *
+ **************************************************************************/
+
+ /*
+ * Authors:
+ * Keith Whitwell <keith@tungstengraphics.com>
+ * Brian Paul
+ */
+
+
+#include "st_context.h"
+#include "st_atom.h"
+#include "pipe/p_context.h"
+#include "pipe/p_defines.h"
+
+
+/**
+ * Convert GLenum texcoord wrap tokens to pipe tokens.
+ */
+static GLuint
+gl_wrap_to_sp(GLenum wrap)
+{
+ switch (wrap) {
+ case GL_REPEAT:
+ return PIPE_TEX_WRAP_REPEAT;
+ case GL_CLAMP:
+ return PIPE_TEX_WRAP_CLAMP;
+ case GL_CLAMP_TO_EDGE:
+ return PIPE_TEX_WRAP_CLAMP_TO_EDGE;
+ case GL_CLAMP_TO_BORDER:
+ return PIPE_TEX_WRAP_CLAMP_TO_BORDER;
+ case GL_MIRRORED_REPEAT:
+ return PIPE_TEX_WRAP_MIRROR_REPEAT;
+ case GL_MIRROR_CLAMP_EXT:
+ return PIPE_TEX_WRAP_MIRROR_CLAMP;
+ case GL_MIRROR_CLAMP_TO_EDGE_EXT:
+ return PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE;
+ case GL_MIRROR_CLAMP_TO_BORDER_EXT:
+ return PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER;
+ default:
+ abort();
+ return 0;
+ }
+}
+
+
+static GLuint
+gl_filter_to_sp(GLenum filter)
+{
+ switch (filter) {
+ case GL_NEAREST:
+ return PIPE_TEX_FILTER_NEAREST;
+ case GL_LINEAR:
+ return PIPE_TEX_FILTER_LINEAR;
+ case GL_NEAREST_MIPMAP_NEAREST:
+ return PIPE_TEX_FILTER_NEAREST_MIPMAP_NEAREST;
+ case GL_NEAREST_MIPMAP_LINEAR:
+ return PIPE_TEX_FILTER_NEAREST_MIPMAP_LINEAR;
+ case GL_LINEAR_MIPMAP_NEAREST:
+ return PIPE_TEX_FILTER_LINEAR_MIPMAP_NEAREST;
+ case GL_LINEAR_MIPMAP_LINEAR:
+ return PIPE_TEX_FILTER_LINEAR_MIPMAP_LINEAR;
+ default:
+ abort();
+ return 0;
+ }
+}
+
+
+static void
+update_samplers(struct st_context *st)
+{
+ GLuint u;
+
+ for (u = 0; u < st->ctx->Const.MaxTextureImageUnits; u++) {
+ const struct gl_texture_object *texobj
+ = st->ctx->Texture.Unit[u]._Current;
+ struct pipe_sampler_state sampler;
+
+ memset(&sampler, 0, sizeof(sampler));
+
+ sampler.wrap_s = gl_wrap_to_sp(texobj->WrapS);
+ sampler.wrap_t = gl_wrap_to_sp(texobj->WrapT);
+ sampler.wrap_r = gl_wrap_to_sp(texobj->WrapR);
+
+ sampler.min_filter = gl_filter_to_sp(texobj->MinFilter);
+ sampler.mag_filter = gl_filter_to_sp(texobj->MagFilter);
+
+ /* XXX more sampler state here */
+
+ if (memcmp(&sampler, &st->state.sampler[u], sizeof(sampler)) != 0) {
+ /* state has changed */
+ st->state.sampler[u] = sampler;
+ st->pipe->set_sampler_state(st->pipe, u, &sampler);
+ }
+ }
+}
+
+
+const struct st_tracked_state st_update_sampler = {
+ .dirty = {
+ .mesa = _NEW_TEXTURE,
+ .st = 0,
+ },
+ .update = update_samplers
+};
+
+
+
+
+
diff --git a/src/mesa/state_tracker/st_atom_scissor.c b/src/mesa/state_tracker/st_atom_scissor.c
new file mode 100644
index 0000000000..05a9f3eed1
--- /dev/null
+++ b/src/mesa/state_tracker/st_atom_scissor.c
@@ -0,0 +1,88 @@
+/**************************************************************************
+ *
+ * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * 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.
+ *
+ **************************************************************************/
+
+ /*
+ * Authors:
+ * Keith Whitwell <keith@tungstengraphics.com>
+ */
+
+
+#include "st_context.h"
+#include "pipe/p_context.h"
+#include "st_atom.h"
+
+
+/**
+ * Scissor depends on the scissor box, and the framebuffer dimensions.
+ */
+static void
+update_scissor( struct st_context *st )
+{
+ struct pipe_scissor_state scissor;
+ const struct gl_framebuffer *fb = st->ctx->DrawBuffer;
+
+ scissor.minx = 0;
+ scissor.miny = 0;
+ scissor.maxx = fb->Width;
+ scissor.maxy = fb->Height;
+
+ if (st->ctx->Scissor.Enabled) {
+ if (st->ctx->Scissor.X > scissor.minx)
+ scissor.minx = st->ctx->Scissor.X;
+ if (st->ctx->Scissor.Y > scissor.miny)
+ scissor.miny = st->ctx->Scissor.Y;
+
+ if (st->ctx->Scissor.X + st->ctx->Scissor.Width < scissor.maxx)
+ scissor.maxx = st->ctx->Scissor.X + st->ctx->Scissor.Width;
+ if (st->ctx->Scissor.Y + st->ctx->Scissor.Height < scissor.maxy)
+ scissor.maxy = st->ctx->Scissor.Y + st->ctx->Scissor.Height;
+
+ /* check for null space */
+ if (scissor.minx >= scissor.maxx || scissor.miny >= scissor.maxy)
+ scissor.minx = scissor.miny = scissor.maxx = scissor.maxy = 0;
+ }
+
+ if (memcmp(&scissor, &st->state.scissor, sizeof(scissor)) != 0) {
+ /* state has changed */
+ st->state.scissor = scissor; /* struct copy */
+ st->pipe->set_scissor_state(st->pipe, &scissor); /* activate */
+ }
+}
+
+
+const struct st_tracked_state st_update_scissor = {
+ .dirty = {
+ .mesa = (_NEW_SCISSOR | _NEW_BUFFERS),
+ .st = 0,
+ },
+ .update = update_scissor
+};
+
+
+
+
+
diff --git a/src/mesa/state_tracker/st_atom_setup.c b/src/mesa/state_tracker/st_atom_setup.c
new file mode 100644
index 0000000000..3eac2588df
--- /dev/null
+++ b/src/mesa/state_tracker/st_atom_setup.c
@@ -0,0 +1,220 @@
+/**************************************************************************
+ *
+ * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * 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.
+ *
+ **************************************************************************/
+
+ /*
+ * Authors:
+ * Keith Whitwell <keith@tungstengraphics.com>
+ */
+
+
+#include "st_context.h"
+#include "pipe/p_context.h"
+#include "pipe/p_defines.h"
+#include "st_atom.h"
+
+static GLuint translate_fill( GLenum mode )
+{
+ switch (mode) {
+ case GL_POINT:
+ return PIPE_POLYGON_MODE_POINT;
+ case GL_LINE:
+ return PIPE_POLYGON_MODE_LINE;
+ case GL_FILL:
+ return PIPE_POLYGON_MODE_FILL;
+ default:
+ assert(0);
+ return 0;
+ }
+}
+
+static GLboolean get_offset_flag( GLuint fill_mode,
+ const struct gl_polygon_attrib *p )
+{
+ switch (fill_mode) {
+ case PIPE_POLYGON_MODE_POINT:
+ return p->OffsetPoint;
+ case PIPE_POLYGON_MODE_LINE:
+ return p->OffsetLine;
+ case PIPE_POLYGON_MODE_FILL:
+ return p->OffsetFill;
+ default:
+ assert(0);
+ return 0;
+ }
+}
+
+
+static void update_setup_state( struct st_context *st )
+{
+ GLcontext *ctx = st->ctx;
+ struct pipe_setup_state setup;
+
+ memset(&setup, 0, sizeof(setup));
+
+ /* _NEW_POLYGON, _NEW_BUFFERS
+ */
+ {
+ if (ctx->Polygon.FrontFace == GL_CCW)
+ setup.front_winding = PIPE_WINDING_CCW;
+ else
+ setup.front_winding = PIPE_WINDING_CW;
+
+ /* XXX
+ * I think the intention here is that user-created framebuffer objects
+ * use Y=0=TOP layout instead of OpenGL's normal Y=0=bottom layout.
+ * Flipping Y changes CW to CCW and vice-versa.
+ * But this is an implementation/driver-specific artifact - remove...
+ */
+ if (ctx->DrawBuffer && ctx->DrawBuffer->Name != 0)
+ setup.front_winding ^= PIPE_WINDING_BOTH;
+ }
+
+ /* _NEW_LIGHT
+ */
+ if (ctx->Light.ShadeModel == GL_FLAT)
+ setup.flatshade = 1;
+
+ /* _NEW_LIGHT | _NEW_PROGRAM
+ *
+ * Back-face colors can come from traditional lighting (when
+ * GL_LIGHT_MODEL_TWO_SIDE is set) or from vertex programs (when
+ * GL_VERTEX_PROGRAM_TWO_SIDE is set). Note the logic here.
+ */
+ if (ctx->VertexProgram._Enabled) {
+ setup.light_twoside = ctx->VertexProgram.TwoSideEnabled;
+ }
+ else if (ctx->Light.Enabled && ctx->Light.Model.TwoSide) {
+ setup.light_twoside = 1;
+ }
+
+ /* _NEW_POLYGON
+ */
+ if (ctx->Polygon.CullFlag) {
+ if (ctx->Polygon.CullFaceMode == GL_FRONT_AND_BACK) {
+ setup.cull_mode = PIPE_WINDING_BOTH;
+ }
+ else if (ctx->Polygon.CullFaceMode == GL_FRONT) {
+ setup.cull_mode = setup.front_winding;
+ }
+ else {
+ setup.cull_mode = setup.front_winding ^ PIPE_WINDING_BOTH;
+ }
+ }
+
+ /* _NEW_POLYGON
+ */
+ {
+ GLuint fill_front = translate_fill( ctx->Polygon.FrontMode );
+ GLuint fill_back = translate_fill( ctx->Polygon.BackMode );
+
+ if (setup.front_winding == PIPE_WINDING_CW) {
+ setup.fill_cw = fill_front;
+ setup.fill_ccw = fill_back;
+ }
+ else {
+ setup.fill_cw = fill_back;
+ setup.fill_ccw = fill_front;
+ }
+
+ /* Simplify when culling is active:
+ */
+ if (setup.cull_mode & PIPE_WINDING_CW) {
+ setup.fill_cw = setup.fill_ccw;
+ }
+
+ if (setup.cull_mode & PIPE_WINDING_CCW) {
+ setup.fill_ccw = setup.fill_cw;
+ }
+ }
+
+ /* _NEW_POLYGON
+ */
+ if (ctx->Polygon.OffsetUnits != 0.0 ||
+ ctx->Polygon.OffsetFactor != 0.0) {
+ setup.offset_cw = get_offset_flag( setup.fill_cw, &ctx->Polygon );
+ setup.offset_ccw = get_offset_flag( setup.fill_ccw, &ctx->Polygon );
+ setup.offset_units = ctx->Polygon.OffsetUnits;
+ setup.offset_scale = ctx->Polygon.OffsetFactor;
+ }
+
+ if (ctx->Polygon.SmoothFlag)
+ setup.poly_smooth = 1;
+
+ if (ctx->Polygon.StippleFlag)
+ setup.poly_stipple_enable = 1;
+
+
+ /* _NEW_BUFFERS, _NEW_POLYGON
+ */
+ if (setup.fill_cw != PIPE_POLYGON_MODE_FILL ||
+ setup.fill_ccw != PIPE_POLYGON_MODE_FILL)
+ {
+ GLfloat mrd = (ctx->DrawBuffer ?
+ ctx->DrawBuffer->_MRD :
+ 1.0);
+
+ setup.offset_units = ctx->Polygon.OffsetFactor * mrd;
+ setup.offset_scale = (ctx->Polygon.OffsetUnits * mrd *
+ st->polygon_offset_scale);
+ }
+
+ /* _NEW_POINT
+ */
+ setup.point_size = ctx->Point.Size;
+ setup.point_smooth = ctx->Point.SmoothFlag;
+
+ /* _NEW_LINE
+ */
+ setup.line_width = ctx->Line.Width;
+ setup.line_smooth = ctx->Line.SmoothFlag;
+ setup.line_stipple_enable = ctx->Line.StippleFlag;
+ setup.line_stipple_pattern = ctx->Line.StipplePattern;
+ /* GL stipple factor is in [1,256], remap to [0, 255] here */
+ setup.line_stipple_factor = ctx->Line.StippleFactor - 1;
+
+ /* _NEW_MULTISAMPLE */
+ if (ctx->Multisample.Enabled)
+ setup.multisample = 1;
+
+ /* _NEW_SCISSOR */
+ if (ctx->Scissor.Enabled)
+ setup.scissor = 1;
+
+ if (memcmp(&setup, &st->state.setup, sizeof(setup)) != 0) {
+ st->state.setup = setup;
+ st->pipe->set_setup_state( st->pipe, &setup );
+ }
+}
+
+const struct st_tracked_state st_update_setup = {
+ .dirty = {
+ .mesa = (_NEW_LIGHT | _NEW_POLYGON | _NEW_LINE | _NEW_SCISSOR |
+ _NEW_POINT | _NEW_BUFFERS | _NEW_MULTISAMPLE),
+ .st = 0,
+ },
+ .update = update_setup_state
+};
diff --git a/src/mesa/state_tracker/st_atom_stencil.c b/src/mesa/state_tracker/st_atom_stencil.c
new file mode 100644
index 0000000000..d037335e9e
--- /dev/null
+++ b/src/mesa/state_tracker/st_atom_stencil.c
@@ -0,0 +1,140 @@
+/**************************************************************************
+ *
+ * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * 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.
+ *
+ **************************************************************************/
+
+ /*
+ * Authors:
+ * Keith Whitwell <keith@tungstengraphics.com>
+ * Brian Paul
+ */
+
+
+#include "st_context.h"
+#include "st_atom.h"
+#include "pipe/p_context.h"
+#include "pipe/p_defines.h"
+
+
+/**
+ * Convert GLenum stencil func tokens to pipe tokens.
+ */
+static GLuint
+gl_stencil_func_to_sp(GLenum func)
+{
+ /* Same values, just biased */
+ assert(PIPE_FUNC_NEVER == GL_NEVER - GL_NEVER);
+ assert(PIPE_FUNC_LESS == GL_LESS - GL_NEVER);
+ assert(PIPE_FUNC_EQUAL == GL_EQUAL - GL_NEVER);
+ assert(PIPE_FUNC_LEQUAL == GL_LEQUAL - GL_NEVER);
+ assert(PIPE_FUNC_GREATER == GL_GREATER - GL_NEVER);
+ assert(PIPE_FUNC_NOTEQUAL == GL_NOTEQUAL - GL_NEVER);
+ assert(PIPE_FUNC_GEQUAL == GL_GEQUAL - GL_NEVER);
+ assert(PIPE_FUNC_ALWAYS == GL_ALWAYS - GL_NEVER);
+ assert(func >= GL_NEVER);
+ assert(func <= GL_ALWAYS);
+ return func - GL_NEVER;
+}
+
+
+/**
+ * Convert GLenum stencil op tokens to pipe tokens.
+ */
+static GLuint
+gl_stencil_op_to_sp(GLenum func)
+{
+ switch (func) {
+ case GL_KEEP:
+ return PIPE_STENCIL_OP_KEEP;
+ case GL_ZERO:
+ return PIPE_STENCIL_OP_ZERO;
+ case GL_REPLACE:
+ return PIPE_STENCIL_OP_REPLACE;
+ case GL_INCR:
+ return PIPE_STENCIL_OP_INCR;
+ case GL_DECR:
+ return PIPE_STENCIL_OP_DECR;
+ case GL_INCR_WRAP:
+ return PIPE_STENCIL_OP_INCR_WRAP;
+ case GL_DECR_WRAP:
+ return PIPE_STENCIL_OP_DECR_WRAP;
+ case GL_INVERT:
+ return PIPE_STENCIL_OP_INVERT;
+ default:
+ assert("invalid GL token in gl_stencil_op_to_sp()" == NULL);
+ return 0;
+ }
+}
+
+
+static void
+update_stencil( struct st_context *st )
+{
+ struct pipe_stencil_state stencil;
+
+ memset(&stencil, 0, sizeof(stencil));
+
+ if (st->ctx->Stencil.Enabled) {
+ stencil.front_enabled = 1;
+ stencil.front_func = gl_stencil_func_to_sp(st->ctx->Stencil.Function[0]);
+ stencil.front_fail_op = gl_stencil_op_to_sp(st->ctx->Stencil.FailFunc[0]);
+ stencil.front_zfail_op = gl_stencil_op_to_sp(st->ctx->Stencil.ZFailFunc[0]);
+ stencil.front_zpass_op = gl_stencil_op_to_sp(st->ctx->Stencil.ZPassFunc[0]);
+ stencil.ref_value[0] = st->ctx->Stencil.Ref[0] & 0xff;
+ stencil.value_mask[0] = st->ctx->Stencil.ValueMask[0] & 0xff;
+ stencil.write_mask[0] = st->ctx->Stencil.WriteMask[0] & 0xff;
+ if (st->ctx->Stencil.TestTwoSide) {
+ stencil.back_enabled = 1;
+ stencil.back_func = gl_stencil_func_to_sp(st->ctx->Stencil.Function[1]);
+ stencil.back_fail_op = gl_stencil_op_to_sp(st->ctx->Stencil.FailFunc[1]);
+ stencil.back_zfail_op = gl_stencil_op_to_sp(st->ctx->Stencil.ZFailFunc[1]);
+ stencil.back_zpass_op = gl_stencil_op_to_sp(st->ctx->Stencil.ZPassFunc[1]);
+ stencil.ref_value[1] = st->ctx->Stencil.Ref[1] & 0xff;
+ stencil.value_mask[1] = st->ctx->Stencil.ValueMask[1] & 0xff;
+ stencil.write_mask[1] = st->ctx->Stencil.WriteMask[1] & 0xff;
+ }
+ stencil.clear_value = st->ctx->Stencil.Clear & 0xff;
+ }
+
+ if (memcmp(&stencil, &st->state.stencil, sizeof(stencil)) != 0) {
+ /* state has changed */
+ st->state.stencil = stencil; /* struct copy */
+ st->pipe->set_stencil_state(st->pipe, &stencil); /* set new state */
+ }
+}
+
+
+const struct st_tracked_state st_update_stencil = {
+ .dirty = {
+ .mesa = (_NEW_STENCIL),
+ .st = 0,
+ },
+ .update = update_stencil
+};
+
+
+
+
+
diff --git a/src/mesa/state_tracker/st_atom_stipple.c b/src/mesa/state_tracker/st_atom_stipple.c
new file mode 100644
index 0000000000..dd04d2158c
--- /dev/null
+++ b/src/mesa/state_tracker/st_atom_stipple.c
@@ -0,0 +1,62 @@
+/**************************************************************************
+ *
+ * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * 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.
+ *
+ **************************************************************************/
+
+ /*
+ * \brief polygon stipple state
+ *
+ * Authors:
+ * Brian Paul
+ */
+
+
+#include "st_context.h"
+#include "st_atom.h"
+#include "pipe/p_context.h"
+#include "pipe/p_defines.h"
+
+
+static void
+update_stipple( struct st_context *st )
+{
+ const GLuint sz = sizeof(st->state.poly_stipple.stipple);
+ assert(sz == sizeof(st->ctx->PolygonStipple));
+
+ if (memcmp(&st->state.poly_stipple.stipple, st->ctx->PolygonStipple, sz)) {
+ /* state has changed */
+ memcpy(st->state.poly_stipple.stipple, st->ctx->PolygonStipple, sz);
+ st->pipe->set_polygon_stipple(st->pipe, &st->state.poly_stipple);
+ }
+}
+
+
+const struct st_tracked_state st_update_polygon_stipple = {
+ .dirty = {
+ .mesa = (_NEW_POLYGONSTIPPLE),
+ .st = 0,
+ },
+ .update = update_stipple
+};
diff --git a/src/mesa/state_tracker/st_atom_viewport.c b/src/mesa/state_tracker/st_atom_viewport.c
new file mode 100644
index 0000000000..ac91f628aa
--- /dev/null
+++ b/src/mesa/state_tracker/st_atom_viewport.c
@@ -0,0 +1,117 @@
+/**************************************************************************
+ *
+ * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * 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.
+ *
+ **************************************************************************/
+
+
+#include "context.h"
+#include "colormac.h"
+#include "st_context.h"
+#include "pipe/p_context.h"
+#include "st_atom.h"
+
+
+
+
+
+/**
+ * Update the viewport transformation matrix. Depends on:
+ * - viewport pos/size
+ * - depthrange
+ * - window pos/size or FBO size
+ */
+static void update_viewport( struct st_context *st )
+{
+ GLcontext *ctx = st->ctx;
+ const GLframebuffer *DrawBuffer = ctx->DrawBuffer;
+ GLfloat yScale = 1.0;
+ GLfloat yBias = 0.0;
+
+ /* _NEW_BUFFERS
+ */
+ if (DrawBuffer) {
+
+#if 0
+ if (DrawBuffer->Name) {
+ /* User created FBO */
+ struct st_renderbuffer *irb
+ = st_renderbuffer(DrawBuffer->_ColorDrawBuffers[0][0]);
+ if (irb && !irb->RenderToTexture) {
+ /* y=0=top */
+ yScale = -1.0;
+ yBias = irb->Base.Height;
+ }
+ else {
+ /* y=0=bottom */
+ yScale = 1.0;
+ yBias = 0.0;
+ }
+ }
+ else
+ {
+ /* window buffer, y=0=top */
+ yScale = -1.0;
+ yBias = DrawBuffer->Height;
+ }
+#endif
+ }
+
+ {
+ /* _NEW_VIEWPORT
+ */
+ GLfloat x = ctx->Viewport.X;
+ GLfloat y = ctx->Viewport.Y;
+ GLfloat z = ctx->Viewport.Near;
+ GLfloat half_width = ctx->Viewport.Width / 2.0;
+ GLfloat half_height = ctx->Viewport.Height / 2.0;
+ GLfloat half_depth = (ctx->Viewport.Far - ctx->Viewport.Near) / 2.0;
+
+ struct pipe_viewport_state vp;
+
+ vp.scale[0] = half_width;
+ vp.scale[1] = half_height * yScale;
+ vp.scale[2] = half_depth;
+ vp.scale[3] = 1.0;
+
+ vp.translate[0] = (half_width + x);
+ vp.translate[1] = (half_height + y) * yScale + yBias;
+ vp.translate[2] = (half_depth + z);
+ vp.translate[3] = 0.0;
+
+ if (memcmp(&vp, &st->state.viewport, sizeof(vp)) != 0) {
+ st->state.viewport = vp;
+ st->pipe->set_viewport_state(st->pipe, &vp);
+ }
+ }
+}
+
+
+const struct st_tracked_state st_update_viewport = {
+ .dirty = {
+ .mesa = _NEW_BUFFERS | _NEW_VIEWPORT,
+ .st = 0,
+ },
+ .update = update_viewport
+};
diff --git a/src/mesa/state_tracker/st_atom_vs.c b/src/mesa/state_tracker/st_atom_vs.c
new file mode 100644
index 0000000000..6a26bfdd19
--- /dev/null
+++ b/src/mesa/state_tracker/st_atom_vs.c
@@ -0,0 +1,49 @@
+/**************************************************************************
+ *
+ * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * 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.
+ *
+ **************************************************************************/
+ /*
+ * Authors:
+ * Keith Whitwell <keith@tungstengraphics.com>
+ */
+
+#include "st_context.h"
+#include "pipe/p_context.h"
+#include "st_atom.h"
+
+
+
+static void update_vs( struct st_context *st )
+{
+}
+
+
+const struct st_tracked_state st_update_vs = {
+ .dirty = {
+ .mesa = 0,
+ .st = ST_NEW_VERTEX_PROGRAM,
+ },
+ .update = update_vs
+};
diff --git a/src/mesa/state_tracker/st_cb_program.c b/src/mesa/state_tracker/st_cb_program.c
new file mode 100644
index 0000000000..6da2aeb2f2
--- /dev/null
+++ b/src/mesa/state_tracker/st_cb_program.c
@@ -0,0 +1,170 @@
+/**************************************************************************
+ *
+ * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * 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.
+ *
+ **************************************************************************/
+
+ /*
+ * Authors:
+ * Keith Whitwell <keith@tungstengraphics.com>
+ */
+
+#include "st_context.h"
+#include "st_program.h"
+
+#include "glheader.h"
+#include "macros.h"
+#include "enums.h"
+#include "prog_instruction.h"
+#include "prog_parameter.h"
+#include "program.h"
+#include "programopt.h"
+#include "tnl/tnl.h"
+#include "pipe/tgsi/mesa/tgsi_mesa.h"
+
+
+static void st_bind_program( GLcontext *ctx,
+ GLenum target,
+ struct gl_program *prog )
+{
+ struct st_context *st = st_context(ctx);
+
+ switch (target) {
+ case GL_VERTEX_PROGRAM_ARB:
+ st->dirty.st |= ST_NEW_VERTEX_PROGRAM;
+ break;
+ case GL_FRAGMENT_PROGRAM_ARB:
+ st->dirty.st |= ST_NEW_FRAGMENT_PROGRAM;
+ break;
+ }
+}
+
+static struct gl_program *st_new_program( GLcontext *ctx,
+ GLenum target,
+ GLuint id )
+{
+ struct st_context *st = st_context(ctx);
+
+ switch (target) {
+ case GL_VERTEX_PROGRAM_ARB: {
+ struct st_vertex_program *prog = CALLOC_STRUCT(st_vertex_program);
+
+ prog->id = st->program_id++;
+ prog->dirty = 1;
+
+ return _mesa_init_vertex_program( ctx,
+ &prog->Base,
+ target,
+ id );
+ }
+
+ case GL_FRAGMENT_PROGRAM_ARB:
+ case GL_FRAGMENT_PROGRAM_NV:
+ {
+ struct st_fragment_program *prog = CALLOC_STRUCT(st_fragment_program);
+
+ prog->id = st->program_id++;
+ prog->dirty = 1;
+
+ return _mesa_init_fragment_program( ctx,
+ &prog->Base,
+ target,
+ id );
+ }
+
+ default:
+ return _mesa_new_program(ctx, target, id);
+ }
+}
+
+static void st_delete_program( GLcontext *ctx,
+ struct gl_program *prog )
+{
+ _mesa_delete_program( ctx, prog );
+}
+
+
+static GLboolean st_is_program_native( GLcontext *ctx,
+ GLenum target,
+ struct gl_program *prog )
+{
+ return GL_TRUE;
+}
+
+static void st_program_string_notify( GLcontext *ctx,
+ GLenum target,
+ struct gl_program *prog )
+{
+ struct st_context *st = st_context(ctx);
+
+ if (target == GL_FRAGMENT_PROGRAM_ARB) {
+ struct st_fragment_program *p = (struct st_fragment_program *)prog;
+
+ if (prog == &ctx->FragmentProgram._Current->Base)
+ st->dirty.st |= ST_NEW_FRAGMENT_PROGRAM;
+
+ p->id = st->program_id++;
+ p->param_state = p->Base.Base.Parameters->StateFlags;
+ }
+ else if (target == GL_VERTEX_PROGRAM_ARB) {
+ struct st_vertex_program *p = (struct st_vertex_program *)prog;
+
+ if (prog == &ctx->VertexProgram._Current->Base)
+ st->dirty.st |= ST_NEW_VERTEX_PROGRAM;
+
+ p->id = st->program_id++;
+ p->param_state = p->Base.Base.Parameters->StateFlags;
+
+ /* Also tell tnl about it:
+ */
+ _tnl_program_string(ctx, target, prog);
+ }
+}
+
+
+
+void st_init_cb_program( struct st_context *st )
+{
+ struct dd_function_table *functions = &st->ctx->Driver;
+
+ /* Need these flags:
+ */
+ st->ctx->FragmentProgram._MaintainTexEnvProgram = GL_TRUE;
+ st->ctx->FragmentProgram._UseTexEnvProgram = GL_TRUE;
+
+#if 0
+ assert(functions->ProgramStringNotify == _tnl_program_string);
+#endif
+ functions->BindProgram = st_bind_program;
+ functions->NewProgram = st_new_program;
+ functions->DeleteProgram = st_delete_program;
+ functions->IsProgramNative = st_is_program_native;
+ functions->ProgramStringNotify = st_program_string_notify;
+}
+
+
+void st_destroy_cb_program( struct st_context *st )
+{
+}
+
diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c
new file mode 100644
index 0000000000..6308e81a61
--- /dev/null
+++ b/src/mesa/state_tracker/st_context.c
@@ -0,0 +1,76 @@
+/**************************************************************************
+ *
+ * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * 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.
+ *
+ **************************************************************************/
+
+#include "imports.h"
+#include "st_public.h"
+#include "st_context.h"
+#include "st_atom.h"
+#include "st_draw.h"
+#include "st_program.h"
+#include "pipe/p_context.h"
+
+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;
+}
+
+
+struct st_context *st_create_context( GLcontext *ctx,
+ struct pipe_context *pipe )
+{
+ struct st_context *st = CALLOC_STRUCT( st_context );
+
+ ctx->st = st;
+
+ st->ctx = ctx;
+ st->pipe = pipe;
+
+ st->dirty.mesa = ~0;
+ st->dirty.st = ~0;
+
+ st_init_atoms( st );
+ st_init_draw( st );
+ st_init_cb_program( st );
+
+ return st;
+}
+
+
+void st_destroy_context( struct st_context *st )
+{
+ st_destroy_atoms( st );
+ st_destroy_draw( st );
+ st_destroy_cb_program( st );
+ st->pipe->destroy( st->pipe );
+ FREE( st );
+}
+
+
+
diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h
new file mode 100644
index 0000000000..ef3cdb3b09
--- /dev/null
+++ b/src/mesa/state_tracker/st_context.h
@@ -0,0 +1,116 @@
+/**************************************************************************
+ *
+ * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * 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.
+ *
+ **************************************************************************/
+
+#ifndef ST_CONTEXT_H
+#define ST_CONTEXT_H
+
+#include "mtypes.h"
+#include "pipe/p_state.h"
+
+
+struct st_context;
+struct st_region;
+struct st_texture_object;
+struct st_texture_image;
+struct st_fragment_program;
+
+#define ST_NEW_MESA 0x1 /* Mesa state has changed */
+#define ST_NEW_FRAGMENT_PROGRAM 0x2
+#define ST_NEW_VERTEX_PROGRAM 0x4
+
+struct st_state_flags {
+ GLuint mesa;
+ GLuint st;
+};
+
+struct st_tracked_state {
+ struct st_state_flags dirty;
+ void (*update)( struct st_context *st );
+};
+
+
+
+
+struct st_context
+{
+ GLcontext *ctx;
+
+ struct pipe_context *pipe;
+
+ /* Eventually will use a cache to feed the pipe with
+ * create/bind/delete calls to constant state objects. Not yet
+ * though, we just shove random objects across the interface.
+ */
+ struct {
+ struct pipe_alpha_test_state alpha_test;
+ struct pipe_blend_state blend;
+ struct pipe_blend_color blend_color;
+ struct pipe_clear_color_state clear_color;
+ struct pipe_clip_state clip;
+ struct pipe_depth_state depth;
+ struct pipe_framebuffer_state framebuffer;
+ struct pipe_fs_state fs;
+ struct pipe_poly_stipple poly_stipple;
+ struct pipe_sampler_state sampler[PIPE_MAX_SAMPLERS];
+ struct pipe_scissor_state scissor;
+ struct pipe_setup_state setup;
+ struct pipe_stencil_state stencil;
+ struct pipe_viewport_state viewport;
+ } state;
+
+ struct {
+ struct st_tracked_state tracked_state;
+ } constants;
+
+ struct {
+ struct gl_fragment_program *fragment_program;
+ } cb;
+
+ /* State to be validated:
+ */
+ struct st_tracked_state **atoms;
+ GLuint nr_atoms;
+
+ struct st_state_flags dirty;
+
+ /* Counter to track program string changes:
+ */
+ GLuint program_id;
+
+ GLfloat polygon_offset_scale; /* ?? */
+};
+
+
+/* Need this so that we can implement Mesa callbacks in this module.
+ */
+static INLINE struct st_context *st_context(GLcontext *ctx)
+{
+ return ctx->st;
+}
+
+
+#endif
diff --git a/src/mesa/state_tracker/st_draw.c b/src/mesa/state_tracker/st_draw.c
new file mode 100644
index 0000000000..a424d1dd05
--- /dev/null
+++ b/src/mesa/state_tracker/st_draw.c
@@ -0,0 +1,120 @@
+/**************************************************************************
+ *
+ * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * 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.
+ *
+ **************************************************************************/
+
+ /*
+ * Authors:
+ * Keith Whitwell <keith@tungstengraphics.com>
+ */
+
+#include "imports.h"
+
+#include "tnl/t_context.h"
+#include "tnl/t_pipeline.h"
+
+#include "st_context.h"
+#include "st_atom.h"
+#include "st_draw.h"
+#include "pipe/p_context.h"
+
+/*
+ * TNL stage which feeds into the above.
+ *
+ * XXX: this needs to go into each driver using this code, because we
+ * cannot make the leap from ctx->draw_context in this file. The
+ * driver needs to customize tnl anyway, so this isn't a big deal.
+ */
+static GLboolean draw( GLcontext * ctx, struct tnl_pipeline_stage *stage )
+{
+ struct st_context *st = st_context(ctx);
+ struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
+
+ /* Validate driver and pipe state:
+ */
+ st_validate_state( st );
+
+ /* Call into the new draw code to handle the VB:
+ */
+ st->pipe->draw_vb( st->pipe, VB );
+
+ /* Finished
+ */
+ return GL_FALSE;
+}
+
+const struct tnl_pipeline_stage st_draw = {
+ "check state and draw",
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ draw
+};
+
+static const struct tnl_pipeline_stage *st_pipeline[] = {
+ &_tnl_vertex_transform_stage,
+ &_tnl_vertex_cull_stage,
+ &_tnl_normal_transform_stage,
+ &_tnl_lighting_stage,
+ &_tnl_fog_coordinate_stage,
+ &_tnl_texgen_stage,
+ &_tnl_texture_transform_stage,
+ &_tnl_point_attenuation_stage,
+ &_tnl_vertex_program_stage,
+ &st_draw, /* ADD: escape to pipe */
+ 0,
+};
+
+/* This is all a hack to keep using tnl until we have vertex programs
+ * up and running.
+ */
+void st_init_draw( struct st_context *st )
+{
+ GLcontext *ctx = st->ctx;
+
+ _tnl_destroy_pipeline( ctx );
+ _tnl_install_pipeline( ctx, st_pipeline );
+}
+
+
+void st_destroy_draw( struct st_context *st )
+{
+ /* Nothing to do.
+ */
+}
+
+
+/** XXX temporary here */
+void
+st_clear(struct st_context *st, GLboolean color, GLboolean depth,
+ GLboolean stencil, GLboolean accum)
+{
+ /* This makes sure the softpipe has the latest scissor, etc values */
+ st_validate_state( st );
+
+ st->pipe->clear(st->pipe, color, depth, stencil, accum);
+}
+
diff --git a/src/mesa/state_tracker/st_draw.h b/src/mesa/state_tracker/st_draw.h
new file mode 100644
index 0000000000..7a3ba52130
--- /dev/null
+++ b/src/mesa/state_tracker/st_draw.h
@@ -0,0 +1,44 @@
+/**************************************************************************
+ *
+ * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * 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.
+ *
+ **************************************************************************/
+
+ /*
+ * Authors:
+ * Keith Whitwell <keith@tungstengraphics.com>
+ */
+
+
+#ifndef ST_DRAW_H
+#define ST_DRAW_H
+
+void st_init_draw( struct st_context *st );
+void st_destroy_draw( struct st_context *st );
+
+/** XXX temporary here */
+void st_clear(struct st_context *st, GLboolean color, GLboolean depth,
+ GLboolean stencil, GLboolean accum);
+
+#endif
diff --git a/src/mesa/state_tracker/st_program.h b/src/mesa/state_tracker/st_program.h
new file mode 100644
index 0000000000..f6d5f6d76c
--- /dev/null
+++ b/src/mesa/state_tracker/st_program.h
@@ -0,0 +1,105 @@
+/**************************************************************************
+ *
+ * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * 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.
+ *
+ **************************************************************************/
+
+ /*
+ * Authors:
+ * Keith Whitwell <keith@tungstengraphics.com>
+ */
+
+
+#ifndef ST_PROGRAM_H
+#define ST_PROGRAM_H
+
+#include "mtypes.h"
+#include "pipe/tgsi/core/tgsi_token.h"
+
+#define ST_FP_MAX_TOKENS 1024
+
+
+struct st_fragment_program
+{
+ struct gl_fragment_program Base;
+ GLboolean error; /* If program is malformed for any reason. */
+
+ GLuint id; /* String id, for tracking
+ * ProgramStringNotify changes.
+ */
+
+
+ struct tgsi_token tokens[ST_FP_MAX_TOKENS];
+ GLboolean dirty;
+
+ struct pipe_constant_buffer constants;
+
+#if 0
+ GLfloat (*cbuffer)[4];
+ GLuint nr_constants;
+
+ /* Translate all the parameters, etc, into a constant buffer which
+ * we update on state changes.
+ */
+ struct
+ {
+ GLuint reg; /* Constant idx */
+ const GLfloat *values; /* Pointer to tracked values */
+ } *param;
+ GLuint nr_params;
+#endif
+
+ GLuint param_state;
+};
+
+
+struct st_vertex_program
+{
+ struct gl_vertex_program Base;
+ GLboolean error; /* If program is malformed for any reason. */
+
+ GLuint id; /* String id, for tracking
+ * ProgramStringNotify changes.
+ */
+
+ GLboolean dirty;
+ GLuint param_state;
+};
+
+void st_init_cb_program( struct st_context *st );
+void st_destroy_cb_program( struct st_context *st );
+
+static inline struct st_fragment_program *
+st_fragment_program( struct gl_fragment_program *fp )
+{
+ return (struct st_fragment_program *)fp;
+}
+
+static inline struct st_vertex_program *
+st_vertex_program( struct gl_vertex_program *vp )
+{
+ return (struct st_vertex_program *)vp;
+}
+
+#endif
diff --git a/src/mesa/state_tracker/st_public.h b/src/mesa/state_tracker/st_public.h
new file mode 100644
index 0000000000..3191549a2f
--- /dev/null
+++ b/src/mesa/state_tracker/st_public.h
@@ -0,0 +1,43 @@
+/**************************************************************************
+ *
+ * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * 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.
+ *
+ **************************************************************************/
+
+#ifndef ST_PUBLIC_H
+#define ST_PUBLIC_H
+
+#include "mtypes.h"
+
+struct st_context;
+struct pipe_context;
+
+struct st_context *st_create_context( GLcontext *ctx,
+ struct pipe_context *pipe);
+
+void st_destroy_context( struct st_context *st );
+
+void st_invalidate_state(GLcontext * ctx, GLuint new_state);
+
+#endif
diff --git a/src/mesa/state_tracker/st_texobj.c b/src/mesa/state_tracker/st_texobj.c
new file mode 100644
index 0000000000..eb5bdb2d08
--- /dev/null
+++ b/src/mesa/state_tracker/st_texobj.c
@@ -0,0 +1,102 @@
+/**************************************************************************
+ *
+ * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * 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.
+ *
+ **************************************************************************/
+
+/*
+ * Authors:
+ * Brian Paul
+ */
+
+#include "imports.h"
+#include "texformat.h"
+
+#include "st_context.h"
+#include "st_texobj.h"
+#include "pipe/p_defines.h"
+
+
+/**
+ * Create a pipe_texture_object from a Mesa texture object.
+ * Eventually, gl_texture_object may be derived from this...
+ */
+struct pipe_texture_object *
+create_texture_object(struct gl_texture_object *texObj)
+{
+ struct pipe_texture_object *pto;
+ const struct gl_texture_image *texImage;
+
+ pto = calloc(1, sizeof(*pto));
+ if (!pto)
+ return NULL;
+
+ /* XXX: Member not defined. Comment-out to get it compile. */
+ /*assert(texObj->Complete);*/
+
+ switch (texObj->Target) {
+ case GL_TEXTURE_1D:
+ pto->type = PIPE_TEXTURE_1D;
+ break;
+ case GL_TEXTURE_2D:
+ pto->type = PIPE_TEXTURE_2D;
+ break;
+ case GL_TEXTURE_3D:
+ pto->type = PIPE_TEXTURE_3D;
+ break;
+ case GL_TEXTURE_CUBE_MAP:
+ pto->type = PIPE_TEXTURE_CUBE;
+ break;
+ default:
+ assert(0);
+ return NULL;
+ }
+
+ texImage = texObj->Image[0][texObj->BaseLevel];
+ assert(texImage);
+
+ switch (texImage->TexFormat->MesaFormat) {
+ case MESA_FORMAT_RGBA8888:
+ pto->format = PIPE_FORMAT_U_R8_G8_B8_A8;
+ break;
+ case MESA_FORMAT_RGB565:
+ pto->format = PIPE_FORMAT_U_R5_G6_B5;
+ break;
+
+ /* XXX fill in more formats */
+
+ default:
+ assert(0);
+ return NULL;
+ }
+
+ pto->width = texImage->Width;
+ pto->height = texImage->Height;
+ pto->depth = texImage->Depth;
+
+ /* XXX verify this */
+ pto->mipmapped = texObj->Image[0][texObj->BaseLevel + 1] != NULL;
+
+ return pto;
+}
diff --git a/src/mesa/state_tracker/st_texobj.h b/src/mesa/state_tracker/st_texobj.h
new file mode 100644
index 0000000000..3c66031018
--- /dev/null
+++ b/src/mesa/state_tracker/st_texobj.h
@@ -0,0 +1,41 @@
+/**************************************************************************
+ *
+ * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * 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.
+ *
+ **************************************************************************/
+
+/*
+ * Authors:
+ * Brian Paul
+ */
+
+#ifndef ST_TEXOBJ_H
+#define ST_TEXOBJ_H 1
+
+
+extern struct pipe_texture_object *
+create_texture_object(struct gl_texture_object *texObj);
+
+
+#endif /* ST_TEXOBJ_H */