| Brian Paul | 0883634 | 2001-03-03 20:33:27 +0000 | [diff] [blame] | 1 | /* $Id: depth.c,v 1.26 2001/03/03 20:33:27 brianp Exp $ */ |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2 | |
| 3 | /* |
| 4 | * Mesa 3-D graphics library |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 5 | * Version: 3.3 |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 6 | * |
| Brian Paul | ed30dfa | 2000-03-03 17:47:39 +0000 | [diff] [blame] | 7 | * Copyright (C) 1999-2000 Brian Paul All Rights Reserved. |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 8 | * |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 9 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 10 | * copy of this software and associated documentation files (the "Software"), |
| 11 | * to deal in the Software without restriction, including without limitation |
| 12 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 13 | * and/or sell copies of the Software, and to permit persons to whom the |
| 14 | * Software is furnished to do so, subject to the following conditions: |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 15 | * |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 16 | * The above copyright notice and this permission notice shall be included |
| 17 | * in all copies or substantial portions of the Software. |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 18 | * |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 20 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 22 | * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN |
| 23 | * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 24 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 25 | */ |
| 26 | |
| Brian Paul | 5c3bee5 | 1999-12-10 19:09:21 +0000 | [diff] [blame] | 27 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 28 | #ifdef PC_HEADER |
| 29 | #include "all.h" |
| 30 | #else |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 31 | #include "glheader.h" |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 32 | #include "context.h" |
| 33 | #include "enums.h" |
| 34 | #include "depth.h" |
| Brian Paul | ebb248a | 2000-10-29 18:23:16 +0000 | [diff] [blame] | 35 | #include "macros.h" |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 36 | #include "mem.h" |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 37 | #include "mtypes.h" |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 38 | #endif |
| 39 | |
| 40 | |
| 41 | |
| 42 | /**********************************************************************/ |
| 43 | /***** API Functions *****/ |
| 44 | /**********************************************************************/ |
| 45 | |
| 46 | |
| 47 | |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 48 | void |
| 49 | _mesa_ClearDepth( GLclampd depth ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 50 | { |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 51 | GET_CURRENT_CONTEXT(ctx); |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 52 | GLfloat tmp = (GLfloat) CLAMP( depth, 0.0, 1.0 ); |
| 53 | ASSERT_OUTSIDE_BEGIN_END(ctx); |
| 54 | |
| 55 | if (ctx->Depth.Clear == tmp) |
| 56 | return; |
| 57 | |
| 58 | FLUSH_VERTICES(ctx, _NEW_DEPTH); |
| 59 | ctx->Depth.Clear = tmp; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 60 | if (ctx->Driver.ClearDepth) |
| 61 | (*ctx->Driver.ClearDepth)( ctx, ctx->Depth.Clear ); |
| 62 | } |
| 63 | |
| 64 | |
| 65 | |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 66 | void |
| 67 | _mesa_DepthFunc( GLenum func ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 68 | { |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 69 | GET_CURRENT_CONTEXT(ctx); |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 70 | ASSERT_OUTSIDE_BEGIN_END(ctx); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 71 | |
| 72 | if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE)) |
| Brian Paul | 0883634 | 2001-03-03 20:33:27 +0000 | [diff] [blame] | 73 | fprintf(stderr, "glDepthFunc %s\n", _mesa_lookup_enum_by_nr(func)); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 74 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 75 | switch (func) { |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 76 | case GL_LESS: /* (default) pass if incoming z < stored z */ |
| 77 | case GL_GEQUAL: |
| 78 | case GL_LEQUAL: |
| 79 | case GL_GREATER: |
| 80 | case GL_NOTEQUAL: |
| 81 | case GL_EQUAL: |
| 82 | case GL_ALWAYS: |
| 83 | case GL_NEVER: |
| 84 | break; |
| 85 | default: |
| Brian Paul | 0883634 | 2001-03-03 20:33:27 +0000 | [diff] [blame] | 86 | _mesa_error( ctx, GL_INVALID_ENUM, "glDepth.Func" ); |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 87 | return; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 88 | } |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 89 | |
| 90 | if (ctx->Depth.Func == func) |
| 91 | return; |
| 92 | |
| 93 | FLUSH_VERTICES(ctx, _NEW_DEPTH); |
| 94 | ctx->Depth.Func = func; |
| 95 | |
| 96 | if (func == GL_NEVER) |
| 97 | ctx->_TriangleCaps |= DD_Z_NEVER; |
| 98 | else |
| 99 | ctx->_TriangleCaps &= ~DD_Z_NEVER; |
| 100 | |
| 101 | if (ctx->Driver.DepthFunc) |
| 102 | ctx->Driver.DepthFunc( ctx, func ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | |
| 106 | |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 107 | void |
| 108 | _mesa_DepthMask( GLboolean flag ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 109 | { |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 110 | GET_CURRENT_CONTEXT(ctx); |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 111 | ASSERT_OUTSIDE_BEGIN_END(ctx); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 112 | |
| 113 | if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE)) |
| 114 | fprintf(stderr, "glDepthMask %d\n", flag); |
| 115 | |
| 116 | /* |
| 117 | * GL_TRUE indicates depth buffer writing is enabled (default) |
| 118 | * GL_FALSE indicates depth buffer writing is disabled |
| 119 | */ |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 120 | if (ctx->Depth.Mask == flag) |
| 121 | return; |
| 122 | |
| 123 | FLUSH_VERTICES(ctx, _NEW_DEPTH); |
| 124 | ctx->Depth.Mask = flag; |
| 125 | |
| 126 | if (ctx->Driver.DepthMask) |
| 127 | ctx->Driver.DepthMask( ctx, flag ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | |