st_atom_depth.c revision 6393cda6766b707ef01e925d378239a66d143ae0
1/**************************************************************************
2 *
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28 /*
29  * Authors:
30  *   Keith Whitwell <keith@tungstengraphics.com>
31  *   Brian Paul
32  */
33
34
35#include "st_context.h"
36#include "st_atom.h"
37#include "softpipe/sp_context.h"
38#include "softpipe/sp_defines.h"
39
40
41/**
42 * Convert GLenum depth func tokens to softpipe tokens.
43 */
44static GLuint
45gl_depth_func_to_sp(GLenum func)
46{
47   /* Same values, just biased */
48   assert(SP_DEPTH_FUNC_NEVER == GL_NEVER - GL_NEVER);
49   assert(SP_DEPTH_FUNC_LESS == GL_LESS - GL_NEVER);
50   assert(SP_DEPTH_FUNC_EQUAL == GL_EQUAL - GL_NEVER);
51   assert(SP_DEPTH_FUNC_LEQUAL == GL_LEQUAL - GL_NEVER);
52   assert(SP_DEPTH_FUNC_GREATER == GL_GREATER - GL_NEVER);
53   assert(SP_DEPTH_FUNC_NOTEQUAL == GL_NOTEQUAL - GL_NEVER);
54   assert(SP_DEPTH_FUNC_GEQUAL == GL_GEQUAL - GL_NEVER);
55   assert(SP_DEPTH_FUNC_ALWAYS == GL_ALWAYS - GL_NEVER);
56   assert(func >= GL_NEVER);
57   assert(func <= GL_ALWAYS);
58   return func - GL_NEVER;
59}
60
61
62static void
63update_depth( struct st_context *st )
64{
65   struct softpipe_depth_state depth;
66
67   memset(&depth, 0, sizeof(depth));
68
69   depth.enabled = st->ctx->Depth.Test;
70   depth.writemask = st->ctx->Depth.Mask;
71   depth.func = gl_depth_func_to_sp(st->ctx->Depth.Func);
72   depth.clear = st->ctx->Depth.Clear;
73
74   if (memcmp(&depth, &st->state.depth, sizeof(depth)) != 0) {
75      /* state has changed */
76      st->state.depth = depth;  /* struct copy */
77      st->softpipe->set_depth_state(st->softpipe, &depth); /* set new state */
78   }
79}
80
81
82const struct st_tracked_state st_update_depth = {
83   .dirty = {
84      .mesa = (_NEW_DEPTH),
85      .st  = 0,
86   },
87   .update = update_depth
88};
89