Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

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