1f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/*
2f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Mesa 3-D graphics library
3f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Version:  7.1
4f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *
5f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Copyright (C) 1999-2007  Brian Paul   All Rights Reserved.
6f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *
7f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Permission is hereby granted, free of charge, to any person obtaining a
8f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * copy of this software and associated documentation files (the "Software"),
9f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * to deal in the Software without restriction, including without limitation
10f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * and/or sell copies of the Software, and to permit persons to whom the
12f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Software is furnished to do so, subject to the following conditions:
13f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *
14f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * The above copyright notice and this permission notice shall be included
15f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * in all copies or substantial portions of the Software.
16f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *
17f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
20f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */
24f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
25f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
26f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "glheader.h"
27f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "imports.h"
28f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "context.h"
29f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "depth.h"
30f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "enums.h"
31f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "macros.h"
32f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "mtypes.h"
33f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
34f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
35f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/**********************************************************************/
36f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/*****                          API Functions                     *****/
37f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/**********************************************************************/
38f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
39f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
40f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
41f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgvoid GLAPIENTRY
42f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org_mesa_ClearDepth( GLclampd depth )
43f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
44f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   GET_CURRENT_CONTEXT(ctx);
45f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   ASSERT_OUTSIDE_BEGIN_END(ctx);
46f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
47f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   if (MESA_VERBOSE & VERBOSE_API)
48f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      _mesa_debug(ctx, "glClearDepth(%f)\n", depth);
49f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
50f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   depth = CLAMP( depth, 0.0, 1.0 );
51f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
52f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   if (ctx->Depth.Clear == depth)
53f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      return;
54f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
55f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   FLUSH_VERTICES(ctx, _NEW_DEPTH);
56f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   ctx->Depth.Clear = depth;
57f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
58f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
59f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
60f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgvoid GLAPIENTRY
61f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org_mesa_ClearDepthf( GLclampf depth )
62f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
63f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   _mesa_ClearDepth(depth);
64f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
65f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
66f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
67f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgvoid GLAPIENTRY
68f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org_mesa_DepthFunc( GLenum func )
69f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
70f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   GET_CURRENT_CONTEXT(ctx);
71f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   ASSERT_OUTSIDE_BEGIN_END(ctx);
72f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
73f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   if (MESA_VERBOSE & VERBOSE_API)
74f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      _mesa_debug(ctx, "glDepthFunc %s\n", _mesa_lookup_enum_by_nr(func));
75f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
76f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   switch (func) {
77f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   case GL_LESS:    /* (default) pass if incoming z < stored z */
78f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   case GL_GEQUAL:
79f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   case GL_LEQUAL:
80f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   case GL_GREATER:
81f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   case GL_NOTEQUAL:
82f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   case GL_EQUAL:
83f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   case GL_ALWAYS:
84f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   case GL_NEVER:
85f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      break;
86f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   default:
87f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      _mesa_error( ctx, GL_INVALID_ENUM, "glDepth.Func" );
88f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      return;
89f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   }
90f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
91f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   if (ctx->Depth.Func == func)
92f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      return;
93f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
94f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   FLUSH_VERTICES(ctx, _NEW_DEPTH);
95f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   ctx->Depth.Func = func;
96f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
97f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   if (ctx->Driver.DepthFunc)
98f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      ctx->Driver.DepthFunc( ctx, func );
99f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
100f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
101f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
102f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
103f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgvoid GLAPIENTRY
104f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org_mesa_DepthMask( GLboolean flag )
105f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
106f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   GET_CURRENT_CONTEXT(ctx);
107f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   ASSERT_OUTSIDE_BEGIN_END(ctx);
108f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
109f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   if (MESA_VERBOSE & VERBOSE_API)
110f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      _mesa_debug(ctx, "glDepthMask %d\n", flag);
111f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
112f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   /*
113f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    * GL_TRUE indicates depth buffer writing is enabled (default)
114f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    * GL_FALSE indicates depth buffer writing is disabled
115f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    */
116f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   if (ctx->Depth.Mask == flag)
117f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      return;
118f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
119f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   FLUSH_VERTICES(ctx, _NEW_DEPTH);
120f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   ctx->Depth.Mask = flag;
121f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
122f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   if (ctx->Driver.DepthMask)
123f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      ctx->Driver.DepthMask( ctx, flag );
124f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
125f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
126f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
127f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
128f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/**
129f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Specified by the GL_EXT_depth_bounds_test extension.
130f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */
131f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgvoid GLAPIENTRY
132f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org_mesa_DepthBoundsEXT( GLclampd zmin, GLclampd zmax )
133f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
134f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   GET_CURRENT_CONTEXT(ctx);
135f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   ASSERT_OUTSIDE_BEGIN_END(ctx);
136f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
137f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   if (MESA_VERBOSE & VERBOSE_API)
138f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      _mesa_debug(ctx, "glDepthBounds(%f, %f)\n", zmin, zmax);
139f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
140f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   if (zmin > zmax) {
141f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      _mesa_error(ctx, GL_INVALID_VALUE, "glDepthBoundsEXT(zmin > zmax)");
142f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      return;
143f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   }
144f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
145f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   zmin = CLAMP(zmin, 0.0, 1.0);
146f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   zmax = CLAMP(zmax, 0.0, 1.0);
147f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
148f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   if (ctx->Depth.BoundsMin == zmin && ctx->Depth.BoundsMax == zmax)
149f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      return;
150f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
151f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   FLUSH_VERTICES(ctx, _NEW_DEPTH);
152f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   ctx->Depth.BoundsMin = (GLfloat) zmin;
153f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   ctx->Depth.BoundsMax = (GLfloat) zmax;
154f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
155f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
156f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
157f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/**********************************************************************/
158f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/*****                      Initialization                        *****/
159f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/**********************************************************************/
160f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
161f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
162f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/**
163f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Initialize the depth buffer attribute group in the given context.
164f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */
165f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgvoid
166f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org_mesa_init_depth(struct gl_context *ctx)
167f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
168f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   ctx->Depth.Test = GL_FALSE;
169f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   ctx->Depth.Clear = 1.0;
170f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   ctx->Depth.Func = GL_LESS;
171f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   ctx->Depth.Mask = GL_TRUE;
172f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
173