st_atom_depth.c revision 4185da4681405f3cc4d0cc601d428f2f44d0dda8
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 "pipe/p_context.h" 38#include "pipe/p_defines.h" 39 40 41/** 42 * Convert GLenum depth func tokens to pipe tokens. 43 */ 44static GLuint 45gl_depth_func_to_sp(GLenum func) 46{ 47 /* Same values, just biased */ 48 assert(PIPE_FUNC_NEVER == GL_NEVER - GL_NEVER); 49 assert(PIPE_FUNC_LESS == GL_LESS - GL_NEVER); 50 assert(PIPE_FUNC_EQUAL == GL_EQUAL - GL_NEVER); 51 assert(PIPE_FUNC_LEQUAL == GL_LEQUAL - GL_NEVER); 52 assert(PIPE_FUNC_GREATER == GL_GREATER - GL_NEVER); 53 assert(PIPE_FUNC_NOTEQUAL == GL_NOTEQUAL - GL_NEVER); 54 assert(PIPE_FUNC_GEQUAL == GL_GEQUAL - GL_NEVER); 55 assert(PIPE_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 pipe_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 (st->ctx->Query.CurrentOcclusionObject && 75 st->ctx->Query.CurrentOcclusionObject->Active) 76 depth.occlusion_count = 1; 77 78 if (memcmp(&depth, &st->state.depth, sizeof(depth)) != 0) { 79 /* state has changed */ 80 st->state.depth = depth; /* struct copy */ 81 st->pipe->set_depth_state(st->pipe, &depth); /* set new state */ 82 } 83} 84 85 86const struct st_tracked_state st_update_depth = { 87 .name = "st_update_depth", 88 .dirty = { 89 .mesa = (_NEW_DEPTH), 90 .st = 0, 91 }, 92 .update = update_depth 93}; 94