depth.c revision af69d88d
17117f1b4Smrg/* 27117f1b4Smrg * Mesa 3-D graphics library 37117f1b4Smrg * 4c1f859d4Smrg * Copyright (C) 1999-2007 Brian Paul All Rights Reserved. 57117f1b4Smrg * 67117f1b4Smrg * Permission is hereby granted, free of charge, to any person obtaining a 77117f1b4Smrg * copy of this software and associated documentation files (the "Software"), 87117f1b4Smrg * to deal in the Software without restriction, including without limitation 97117f1b4Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 107117f1b4Smrg * and/or sell copies of the Software, and to permit persons to whom the 117117f1b4Smrg * Software is furnished to do so, subject to the following conditions: 127117f1b4Smrg * 137117f1b4Smrg * The above copyright notice and this permission notice shall be included 147117f1b4Smrg * in all copies or substantial portions of the Software. 157117f1b4Smrg * 167117f1b4Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 177117f1b4Smrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 187117f1b4Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19af69d88dSmrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20af69d88dSmrg * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21af69d88dSmrg * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22af69d88dSmrg * 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 463464ebd5Sriastradh if (MESA_VERBOSE & VERBOSE_API) 473464ebd5Sriastradh _mesa_debug(ctx, "glClearDepth(%f)\n", depth); 483464ebd5Sriastradh 49af69d88dSmrg ctx->Depth.Clear = CLAMP( depth, 0.0, 1.0 ); 507117f1b4Smrg} 517117f1b4Smrg 527117f1b4Smrg 533464ebd5Sriastradhvoid GLAPIENTRY 543464ebd5Sriastradh_mesa_ClearDepthf( GLclampf depth ) 553464ebd5Sriastradh{ 563464ebd5Sriastradh _mesa_ClearDepth(depth); 573464ebd5Sriastradh} 583464ebd5Sriastradh 597117f1b4Smrg 607117f1b4Smrgvoid GLAPIENTRY 617117f1b4Smrg_mesa_DepthFunc( GLenum func ) 627117f1b4Smrg{ 637117f1b4Smrg GET_CURRENT_CONTEXT(ctx); 647117f1b4Smrg 654a49301eSmrg if (MESA_VERBOSE & VERBOSE_API) 667117f1b4Smrg _mesa_debug(ctx, "glDepthFunc %s\n", _mesa_lookup_enum_by_nr(func)); 677117f1b4Smrg 687117f1b4Smrg switch (func) { 697117f1b4Smrg case GL_LESS: /* (default) pass if incoming z < stored z */ 707117f1b4Smrg case GL_GEQUAL: 717117f1b4Smrg case GL_LEQUAL: 727117f1b4Smrg case GL_GREATER: 737117f1b4Smrg case GL_NOTEQUAL: 747117f1b4Smrg case GL_EQUAL: 757117f1b4Smrg case GL_ALWAYS: 767117f1b4Smrg case GL_NEVER: 777117f1b4Smrg break; 787117f1b4Smrg default: 797117f1b4Smrg _mesa_error( ctx, GL_INVALID_ENUM, "glDepth.Func" ); 807117f1b4Smrg return; 817117f1b4Smrg } 827117f1b4Smrg 837117f1b4Smrg if (ctx->Depth.Func == func) 847117f1b4Smrg return; 857117f1b4Smrg 867117f1b4Smrg FLUSH_VERTICES(ctx, _NEW_DEPTH); 877117f1b4Smrg ctx->Depth.Func = func; 887117f1b4Smrg 897117f1b4Smrg if (ctx->Driver.DepthFunc) 907117f1b4Smrg ctx->Driver.DepthFunc( ctx, func ); 917117f1b4Smrg} 927117f1b4Smrg 937117f1b4Smrg 947117f1b4Smrg 957117f1b4Smrgvoid GLAPIENTRY 967117f1b4Smrg_mesa_DepthMask( GLboolean flag ) 977117f1b4Smrg{ 987117f1b4Smrg GET_CURRENT_CONTEXT(ctx); 997117f1b4Smrg 1004a49301eSmrg if (MESA_VERBOSE & VERBOSE_API) 1017117f1b4Smrg _mesa_debug(ctx, "glDepthMask %d\n", flag); 1027117f1b4Smrg 1037117f1b4Smrg /* 1047117f1b4Smrg * GL_TRUE indicates depth buffer writing is enabled (default) 1057117f1b4Smrg * GL_FALSE indicates depth buffer writing is disabled 1067117f1b4Smrg */ 1077117f1b4Smrg if (ctx->Depth.Mask == flag) 1087117f1b4Smrg return; 1097117f1b4Smrg 1107117f1b4Smrg FLUSH_VERTICES(ctx, _NEW_DEPTH); 1117117f1b4Smrg ctx->Depth.Mask = flag; 1127117f1b4Smrg 1137117f1b4Smrg if (ctx->Driver.DepthMask) 1147117f1b4Smrg ctx->Driver.DepthMask( ctx, flag ); 1157117f1b4Smrg} 1167117f1b4Smrg 1177117f1b4Smrg 1187117f1b4Smrg 1197117f1b4Smrg/** 1207117f1b4Smrg * Specified by the GL_EXT_depth_bounds_test extension. 1217117f1b4Smrg */ 1227117f1b4Smrgvoid GLAPIENTRY 1237117f1b4Smrg_mesa_DepthBoundsEXT( GLclampd zmin, GLclampd zmax ) 1247117f1b4Smrg{ 1257117f1b4Smrg GET_CURRENT_CONTEXT(ctx); 1267117f1b4Smrg 1273464ebd5Sriastradh if (MESA_VERBOSE & VERBOSE_API) 1283464ebd5Sriastradh _mesa_debug(ctx, "glDepthBounds(%f, %f)\n", zmin, zmax); 1293464ebd5Sriastradh 1307117f1b4Smrg if (zmin > zmax) { 1317117f1b4Smrg _mesa_error(ctx, GL_INVALID_VALUE, "glDepthBoundsEXT(zmin > zmax)"); 1327117f1b4Smrg return; 1337117f1b4Smrg } 1347117f1b4Smrg 1357117f1b4Smrg zmin = CLAMP(zmin, 0.0, 1.0); 1367117f1b4Smrg zmax = CLAMP(zmax, 0.0, 1.0); 1377117f1b4Smrg 1387117f1b4Smrg if (ctx->Depth.BoundsMin == zmin && ctx->Depth.BoundsMax == zmax) 1397117f1b4Smrg return; 1407117f1b4Smrg 1417117f1b4Smrg FLUSH_VERTICES(ctx, _NEW_DEPTH); 1427117f1b4Smrg ctx->Depth.BoundsMin = (GLfloat) zmin; 1437117f1b4Smrg ctx->Depth.BoundsMax = (GLfloat) zmax; 1447117f1b4Smrg} 1457117f1b4Smrg 1467117f1b4Smrg 1477117f1b4Smrg/**********************************************************************/ 1487117f1b4Smrg/***** Initialization *****/ 1497117f1b4Smrg/**********************************************************************/ 1507117f1b4Smrg 1517117f1b4Smrg 1527117f1b4Smrg/** 1537117f1b4Smrg * Initialize the depth buffer attribute group in the given context. 1547117f1b4Smrg */ 155c1f859d4Smrgvoid 1563464ebd5Sriastradh_mesa_init_depth(struct gl_context *ctx) 1577117f1b4Smrg{ 1587117f1b4Smrg ctx->Depth.Test = GL_FALSE; 1597117f1b4Smrg ctx->Depth.Clear = 1.0; 1607117f1b4Smrg ctx->Depth.Func = GL_LESS; 1617117f1b4Smrg ctx->Depth.Mask = GL_TRUE; 1627117f1b4Smrg} 163