depth.c revision 3464ebd5
17117f1b4Smrg/*
27117f1b4Smrg * Mesa 3-D graphics library
3c1f859d4Smrg * Version:  7.1
47117f1b4Smrg *
5c1f859d4Smrg * Copyright (C) 1999-2007  Brian Paul   All Rights Reserved.
67117f1b4Smrg *
77117f1b4Smrg * Permission is hereby granted, free of charge, to any person obtaining a
87117f1b4Smrg * copy of this software and associated documentation files (the "Software"),
97117f1b4Smrg * to deal in the Software without restriction, including without limitation
107117f1b4Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
117117f1b4Smrg * and/or sell copies of the Software, and to permit persons to whom the
127117f1b4Smrg * Software is furnished to do so, subject to the following conditions:
137117f1b4Smrg *
147117f1b4Smrg * The above copyright notice and this permission notice shall be included
157117f1b4Smrg * in all copies or substantial portions of the Software.
167117f1b4Smrg *
177117f1b4Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
187117f1b4Smrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
197117f1b4Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
207117f1b4Smrg * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
217117f1b4Smrg * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
227117f1b4Smrg * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
237117f1b4Smrg */
247117f1b4Smrg
257117f1b4Smrg
267117f1b4Smrg#include "glheader.h"
277117f1b4Smrg#include "imports.h"
287117f1b4Smrg#include "context.h"
297117f1b4Smrg#include "depth.h"
307117f1b4Smrg#include "enums.h"
317117f1b4Smrg#include "macros.h"
327117f1b4Smrg#include "mtypes.h"
337117f1b4Smrg
347117f1b4Smrg
357117f1b4Smrg/**********************************************************************/
367117f1b4Smrg/*****                          API Functions                     *****/
377117f1b4Smrg/**********************************************************************/
387117f1b4Smrg
397117f1b4Smrg
407117f1b4Smrg
417117f1b4Smrgvoid GLAPIENTRY
427117f1b4Smrg_mesa_ClearDepth( GLclampd depth )
437117f1b4Smrg{
447117f1b4Smrg   GET_CURRENT_CONTEXT(ctx);
457117f1b4Smrg   ASSERT_OUTSIDE_BEGIN_END(ctx);
467117f1b4Smrg
473464ebd5Sriastradh   if (MESA_VERBOSE & VERBOSE_API)
483464ebd5Sriastradh      _mesa_debug(ctx, "glClearDepth(%f)\n", depth);
493464ebd5Sriastradh
507117f1b4Smrg   depth = CLAMP( depth, 0.0, 1.0 );
517117f1b4Smrg
527117f1b4Smrg   if (ctx->Depth.Clear == depth)
537117f1b4Smrg      return;
547117f1b4Smrg
557117f1b4Smrg   FLUSH_VERTICES(ctx, _NEW_DEPTH);
567117f1b4Smrg   ctx->Depth.Clear = depth;
577117f1b4Smrg   if (ctx->Driver.ClearDepth)
587117f1b4Smrg      (*ctx->Driver.ClearDepth)( ctx, ctx->Depth.Clear );
597117f1b4Smrg}
607117f1b4Smrg
617117f1b4Smrg
623464ebd5Sriastradhvoid GLAPIENTRY
633464ebd5Sriastradh_mesa_ClearDepthf( GLclampf depth )
643464ebd5Sriastradh{
653464ebd5Sriastradh   _mesa_ClearDepth(depth);
663464ebd5Sriastradh}
673464ebd5Sriastradh
687117f1b4Smrg
697117f1b4Smrgvoid GLAPIENTRY
707117f1b4Smrg_mesa_DepthFunc( GLenum func )
717117f1b4Smrg{
727117f1b4Smrg   GET_CURRENT_CONTEXT(ctx);
737117f1b4Smrg   ASSERT_OUTSIDE_BEGIN_END(ctx);
747117f1b4Smrg
754a49301eSmrg   if (MESA_VERBOSE & VERBOSE_API)
767117f1b4Smrg      _mesa_debug(ctx, "glDepthFunc %s\n", _mesa_lookup_enum_by_nr(func));
777117f1b4Smrg
787117f1b4Smrg   switch (func) {
797117f1b4Smrg   case GL_LESS:    /* (default) pass if incoming z < stored z */
807117f1b4Smrg   case GL_GEQUAL:
817117f1b4Smrg   case GL_LEQUAL:
827117f1b4Smrg   case GL_GREATER:
837117f1b4Smrg   case GL_NOTEQUAL:
847117f1b4Smrg   case GL_EQUAL:
857117f1b4Smrg   case GL_ALWAYS:
867117f1b4Smrg   case GL_NEVER:
877117f1b4Smrg      break;
887117f1b4Smrg   default:
897117f1b4Smrg      _mesa_error( ctx, GL_INVALID_ENUM, "glDepth.Func" );
907117f1b4Smrg      return;
917117f1b4Smrg   }
927117f1b4Smrg
937117f1b4Smrg   if (ctx->Depth.Func == func)
947117f1b4Smrg      return;
957117f1b4Smrg
967117f1b4Smrg   FLUSH_VERTICES(ctx, _NEW_DEPTH);
977117f1b4Smrg   ctx->Depth.Func = func;
987117f1b4Smrg
997117f1b4Smrg   if (ctx->Driver.DepthFunc)
1007117f1b4Smrg      ctx->Driver.DepthFunc( ctx, func );
1017117f1b4Smrg}
1027117f1b4Smrg
1037117f1b4Smrg
1047117f1b4Smrg
1057117f1b4Smrgvoid GLAPIENTRY
1067117f1b4Smrg_mesa_DepthMask( GLboolean flag )
1077117f1b4Smrg{
1087117f1b4Smrg   GET_CURRENT_CONTEXT(ctx);
1097117f1b4Smrg   ASSERT_OUTSIDE_BEGIN_END(ctx);
1107117f1b4Smrg
1114a49301eSmrg   if (MESA_VERBOSE & VERBOSE_API)
1127117f1b4Smrg      _mesa_debug(ctx, "glDepthMask %d\n", flag);
1137117f1b4Smrg
1147117f1b4Smrg   /*
1157117f1b4Smrg    * GL_TRUE indicates depth buffer writing is enabled (default)
1167117f1b4Smrg    * GL_FALSE indicates depth buffer writing is disabled
1177117f1b4Smrg    */
1187117f1b4Smrg   if (ctx->Depth.Mask == flag)
1197117f1b4Smrg      return;
1207117f1b4Smrg
1217117f1b4Smrg   FLUSH_VERTICES(ctx, _NEW_DEPTH);
1227117f1b4Smrg   ctx->Depth.Mask = flag;
1237117f1b4Smrg
1247117f1b4Smrg   if (ctx->Driver.DepthMask)
1257117f1b4Smrg      ctx->Driver.DepthMask( ctx, flag );
1267117f1b4Smrg}
1277117f1b4Smrg
1287117f1b4Smrg
1297117f1b4Smrg
1307117f1b4Smrg/**
1317117f1b4Smrg * Specified by the GL_EXT_depth_bounds_test extension.
1327117f1b4Smrg */
1337117f1b4Smrgvoid GLAPIENTRY
1347117f1b4Smrg_mesa_DepthBoundsEXT( GLclampd zmin, GLclampd zmax )
1357117f1b4Smrg{
1367117f1b4Smrg   GET_CURRENT_CONTEXT(ctx);
1377117f1b4Smrg   ASSERT_OUTSIDE_BEGIN_END(ctx);
1387117f1b4Smrg
1393464ebd5Sriastradh   if (MESA_VERBOSE & VERBOSE_API)
1403464ebd5Sriastradh      _mesa_debug(ctx, "glDepthBounds(%f, %f)\n", zmin, zmax);
1413464ebd5Sriastradh
1427117f1b4Smrg   if (zmin > zmax) {
1437117f1b4Smrg      _mesa_error(ctx, GL_INVALID_VALUE, "glDepthBoundsEXT(zmin > zmax)");
1447117f1b4Smrg      return;
1457117f1b4Smrg   }
1467117f1b4Smrg
1477117f1b4Smrg   zmin = CLAMP(zmin, 0.0, 1.0);
1487117f1b4Smrg   zmax = CLAMP(zmax, 0.0, 1.0);
1497117f1b4Smrg
1507117f1b4Smrg   if (ctx->Depth.BoundsMin == zmin && ctx->Depth.BoundsMax == zmax)
1517117f1b4Smrg      return;
1527117f1b4Smrg
1537117f1b4Smrg   FLUSH_VERTICES(ctx, _NEW_DEPTH);
1547117f1b4Smrg   ctx->Depth.BoundsMin = (GLfloat) zmin;
1557117f1b4Smrg   ctx->Depth.BoundsMax = (GLfloat) zmax;
1567117f1b4Smrg}
1577117f1b4Smrg
1587117f1b4Smrg
1597117f1b4Smrg/**********************************************************************/
1607117f1b4Smrg/*****                      Initialization                        *****/
1617117f1b4Smrg/**********************************************************************/
1627117f1b4Smrg
1637117f1b4Smrg
1647117f1b4Smrg/**
1657117f1b4Smrg * Initialize the depth buffer attribute group in the given context.
1667117f1b4Smrg */
167c1f859d4Smrgvoid
1683464ebd5Sriastradh_mesa_init_depth(struct gl_context *ctx)
1697117f1b4Smrg{
1707117f1b4Smrg   ctx->Depth.Test = GL_FALSE;
1717117f1b4Smrg   ctx->Depth.Clear = 1.0;
1727117f1b4Smrg   ctx->Depth.Func = GL_LESS;
1737117f1b4Smrg   ctx->Depth.Mask = GL_TRUE;
1747117f1b4Smrg}
175