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" 277ec681f3Smrg 287117f1b4Smrg#include "context.h" 297117f1b4Smrg#include "depth.h" 307117f1b4Smrg#include "enums.h" 317117f1b4Smrg#include "macros.h" 327117f1b4Smrg#include "mtypes.h" 337ec681f3Smrg#include "state.h" 347117f1b4Smrg 357117f1b4Smrg 367117f1b4Smrg/**********************************************************************/ 377117f1b4Smrg/***** API Functions *****/ 387117f1b4Smrg/**********************************************************************/ 397117f1b4Smrg 407117f1b4Smrg 417117f1b4Smrg 427117f1b4Smrgvoid GLAPIENTRY 437117f1b4Smrg_mesa_ClearDepth( GLclampd depth ) 447117f1b4Smrg{ 457117f1b4Smrg GET_CURRENT_CONTEXT(ctx); 467117f1b4Smrg 473464ebd5Sriastradh if (MESA_VERBOSE & VERBOSE_API) 483464ebd5Sriastradh _mesa_debug(ctx, "glClearDepth(%f)\n", depth); 493464ebd5Sriastradh 507ec681f3Smrg ctx->PopAttribState |= GL_DEPTH_BUFFER_BIT; 51af69d88dSmrg ctx->Depth.Clear = CLAMP( depth, 0.0, 1.0 ); 527117f1b4Smrg} 537117f1b4Smrg 547117f1b4Smrg 553464ebd5Sriastradhvoid GLAPIENTRY 563464ebd5Sriastradh_mesa_ClearDepthf( GLclampf depth ) 573464ebd5Sriastradh{ 583464ebd5Sriastradh _mesa_ClearDepth(depth); 593464ebd5Sriastradh} 603464ebd5Sriastradh 617117f1b4Smrg 6201e04c3fSmrgstatic ALWAYS_INLINE void 6301e04c3fSmrgdepth_func(struct gl_context *ctx, GLenum func, bool no_error) 647117f1b4Smrg{ 657117f1b4Smrg if (ctx->Depth.Func == func) 667117f1b4Smrg return; 677117f1b4Smrg 6801e04c3fSmrg if (!no_error) { 6901e04c3fSmrg switch (func) { 7001e04c3fSmrg case GL_LESS: /* (default) pass if incoming z < stored z */ 7101e04c3fSmrg case GL_GEQUAL: 7201e04c3fSmrg case GL_LEQUAL: 7301e04c3fSmrg case GL_GREATER: 7401e04c3fSmrg case GL_NOTEQUAL: 7501e04c3fSmrg case GL_EQUAL: 7601e04c3fSmrg case GL_ALWAYS: 7701e04c3fSmrg case GL_NEVER: 7801e04c3fSmrg break; 7901e04c3fSmrg default: 8001e04c3fSmrg _mesa_error(ctx, GL_INVALID_ENUM, "glDepth.Func"); 8101e04c3fSmrg return; 8201e04c3fSmrg } 8301e04c3fSmrg } 8401e04c3fSmrg 857ec681f3Smrg FLUSH_VERTICES(ctx, ctx->DriverFlags.NewDepth ? 0 : _NEW_DEPTH, 867ec681f3Smrg GL_DEPTH_BUFFER_BIT); 8701e04c3fSmrg ctx->NewDriverState |= ctx->DriverFlags.NewDepth; 887117f1b4Smrg ctx->Depth.Func = func; 897ec681f3Smrg _mesa_update_allow_draw_out_of_order(ctx); 907117f1b4Smrg 917117f1b4Smrg if (ctx->Driver.DepthFunc) 9201e04c3fSmrg ctx->Driver.DepthFunc(ctx, func); 9301e04c3fSmrg} 9401e04c3fSmrg 9501e04c3fSmrg 9601e04c3fSmrgvoid GLAPIENTRY 9701e04c3fSmrg_mesa_DepthFunc_no_error(GLenum func) 9801e04c3fSmrg{ 9901e04c3fSmrg GET_CURRENT_CONTEXT(ctx); 10001e04c3fSmrg depth_func(ctx, func, true); 10101e04c3fSmrg} 10201e04c3fSmrg 10301e04c3fSmrg 10401e04c3fSmrgvoid GLAPIENTRY 10501e04c3fSmrg_mesa_DepthFunc(GLenum func) 10601e04c3fSmrg{ 10701e04c3fSmrg GET_CURRENT_CONTEXT(ctx); 10801e04c3fSmrg 10901e04c3fSmrg if (MESA_VERBOSE & VERBOSE_API) 11001e04c3fSmrg _mesa_debug(ctx, "glDepthFunc %s\n", _mesa_enum_to_string(func)); 11101e04c3fSmrg 11201e04c3fSmrg depth_func(ctx, func, false); 1137117f1b4Smrg} 1147117f1b4Smrg 1157117f1b4Smrg 1167117f1b4Smrg 1177117f1b4Smrgvoid GLAPIENTRY 1187117f1b4Smrg_mesa_DepthMask( GLboolean flag ) 1197117f1b4Smrg{ 1207117f1b4Smrg GET_CURRENT_CONTEXT(ctx); 1217117f1b4Smrg 1224a49301eSmrg if (MESA_VERBOSE & VERBOSE_API) 1237117f1b4Smrg _mesa_debug(ctx, "glDepthMask %d\n", flag); 1247117f1b4Smrg 1257117f1b4Smrg /* 1267117f1b4Smrg * GL_TRUE indicates depth buffer writing is enabled (default) 1277117f1b4Smrg * GL_FALSE indicates depth buffer writing is disabled 1287117f1b4Smrg */ 1297117f1b4Smrg if (ctx->Depth.Mask == flag) 1307117f1b4Smrg return; 1317117f1b4Smrg 1327ec681f3Smrg FLUSH_VERTICES(ctx, ctx->DriverFlags.NewDepth ? 0 : _NEW_DEPTH, 1337ec681f3Smrg GL_DEPTH_BUFFER_BIT); 13401e04c3fSmrg ctx->NewDriverState |= ctx->DriverFlags.NewDepth; 1357117f1b4Smrg ctx->Depth.Mask = flag; 1367ec681f3Smrg _mesa_update_allow_draw_out_of_order(ctx); 1377117f1b4Smrg 1387117f1b4Smrg if (ctx->Driver.DepthMask) 1397117f1b4Smrg ctx->Driver.DepthMask( ctx, flag ); 1407117f1b4Smrg} 1417117f1b4Smrg 1427117f1b4Smrg 1437117f1b4Smrg 1447117f1b4Smrg/** 1457117f1b4Smrg * Specified by the GL_EXT_depth_bounds_test extension. 1467117f1b4Smrg */ 1477117f1b4Smrgvoid GLAPIENTRY 1487117f1b4Smrg_mesa_DepthBoundsEXT( GLclampd zmin, GLclampd zmax ) 1497117f1b4Smrg{ 1507117f1b4Smrg GET_CURRENT_CONTEXT(ctx); 1517117f1b4Smrg 1523464ebd5Sriastradh if (MESA_VERBOSE & VERBOSE_API) 1533464ebd5Sriastradh _mesa_debug(ctx, "glDepthBounds(%f, %f)\n", zmin, zmax); 1543464ebd5Sriastradh 1557117f1b4Smrg if (zmin > zmax) { 1567117f1b4Smrg _mesa_error(ctx, GL_INVALID_VALUE, "glDepthBoundsEXT(zmin > zmax)"); 1577117f1b4Smrg return; 1587117f1b4Smrg } 1597117f1b4Smrg 1607ec681f3Smrg zmin = SATURATE(zmin); 1617ec681f3Smrg zmax = SATURATE(zmax); 1627117f1b4Smrg 1637117f1b4Smrg if (ctx->Depth.BoundsMin == zmin && ctx->Depth.BoundsMax == zmax) 1647117f1b4Smrg return; 1657117f1b4Smrg 1667ec681f3Smrg FLUSH_VERTICES(ctx, ctx->DriverFlags.NewDepth ? 0 : _NEW_DEPTH, 1677ec681f3Smrg GL_DEPTH_BUFFER_BIT); 16801e04c3fSmrg ctx->NewDriverState |= ctx->DriverFlags.NewDepth; 1697ec681f3Smrg ctx->Depth.BoundsMin = zmin; 1707ec681f3Smrg ctx->Depth.BoundsMax = zmax; 1717117f1b4Smrg} 1727117f1b4Smrg 1737117f1b4Smrg 1747117f1b4Smrg/**********************************************************************/ 1757117f1b4Smrg/***** Initialization *****/ 1767117f1b4Smrg/**********************************************************************/ 1777117f1b4Smrg 1787117f1b4Smrg 1797117f1b4Smrg/** 1807117f1b4Smrg * Initialize the depth buffer attribute group in the given context. 1817117f1b4Smrg */ 182c1f859d4Smrgvoid 1833464ebd5Sriastradh_mesa_init_depth(struct gl_context *ctx) 1847117f1b4Smrg{ 1857117f1b4Smrg ctx->Depth.Test = GL_FALSE; 1867117f1b4Smrg ctx->Depth.Clear = 1.0; 1877117f1b4Smrg ctx->Depth.Func = GL_LESS; 1887117f1b4Smrg ctx->Depth.Mask = GL_TRUE; 1897117f1b4Smrg} 190