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:  5.1
  4.  *
  5.  * Copyright (C) 1999-2003  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 "colormac.h"
  28. #include "context.h"
  29. #include "fog.h"
  30. #include "macros.h"
  31. #include "mtypes.h"
  32.  
  33.  
  34.  
  35. void GLAPIENTRY
  36. _mesa_Fogf(GLenum pname, GLfloat param)
  37. {
  38.    GLfloat fparam[4];
  39.    fparam[0] = param;
  40.    fparam[1] = fparam[2] = fparam[3] = 0.0F;
  41.    _mesa_Fogfv(pname, fparam);
  42. }
  43.  
  44.  
  45. void GLAPIENTRY
  46. _mesa_Fogi(GLenum pname, GLint param )
  47. {
  48.    GLfloat fparam[4];
  49.    fparam[0] = (GLfloat) param;
  50.    fparam[1] = fparam[2] = fparam[3] = 0.0F;
  51.    _mesa_Fogfv(pname, fparam);
  52. }
  53.  
  54.  
  55. void GLAPIENTRY
  56. _mesa_Fogiv(GLenum pname, const GLint *params )
  57. {
  58.    GLfloat p[4];
  59.    switch (pname) {
  60.       case GL_FOG_MODE:
  61.       case GL_FOG_DENSITY:
  62.       case GL_FOG_START:
  63.       case GL_FOG_END:
  64.       case GL_FOG_INDEX:
  65.       case GL_FOG_COORDINATE_SOURCE_EXT:
  66.          p[0] = (GLfloat) *params;
  67.          break;
  68.       case GL_FOG_COLOR:
  69.          p[0] = INT_TO_FLOAT( params[0] );
  70.          p[1] = INT_TO_FLOAT( params[1] );
  71.          p[2] = INT_TO_FLOAT( params[2] );
  72.          p[3] = INT_TO_FLOAT( params[3] );
  73.          break;
  74.       default:
  75.          /* Error will be caught later in _mesa_Fogfv */
  76.          ASSIGN_4V(p, 0.0F, 0.0F, 0.0F, 0.0F);
  77.    }
  78.    _mesa_Fogfv(pname, p);
  79. }
  80.  
  81.  
  82. #define UPDATE_FOG_SCALE(ctx) do {\
  83.       if (ctx->Fog.End == ctx->Fog.Start)\
  84.          ctx->Fog._Scale = 1.0f;\
  85.       else\
  86.          ctx->Fog._Scale = 1.0f / (ctx->Fog.End - ctx->Fog.Start);\
  87.    } while(0)
  88.  
  89.  
  90. void GLAPIENTRY
  91. _mesa_Fogfv( GLenum pname, const GLfloat *params )
  92. {
  93.    GET_CURRENT_CONTEXT(ctx);
  94.    GLenum m;
  95.    ASSERT_OUTSIDE_BEGIN_END(ctx);
  96.  
  97.    switch (pname) {
  98.       case GL_FOG_MODE:
  99.          m = (GLenum) (GLint) *params;
  100.          switch (m) {
  101.          case GL_LINEAR:
  102.          case GL_EXP:
  103.          case GL_EXP2:
  104.             break;
  105.          default:
  106.             _mesa_error( ctx, GL_INVALID_ENUM, "glFog" );
  107.             return;
  108.          }
  109.          if (ctx->Fog.Mode == m)
  110.             return;
  111.          FLUSH_VERTICES(ctx, _NEW_FOG);
  112.          ctx->Fog.Mode = m;
  113.          break;
  114.       case GL_FOG_DENSITY:
  115.          if (*params<0.0) {
  116.             _mesa_error( ctx, GL_INVALID_VALUE, "glFog" );
  117.             return;
  118.          }
  119.          if (ctx->Fog.Density == *params)
  120.             return;
  121.          FLUSH_VERTICES(ctx, _NEW_FOG);
  122.          ctx->Fog.Density = *params;
  123.          break;
  124.       case GL_FOG_START:
  125.          if (ctx->Fog.Start == *params)
  126.             return;
  127.          FLUSH_VERTICES(ctx, _NEW_FOG);
  128.          ctx->Fog.Start = *params;
  129.          UPDATE_FOG_SCALE(ctx);
  130.          break;
  131.       case GL_FOG_END:
  132.          if (ctx->Fog.End == *params)
  133.             return;
  134.          FLUSH_VERTICES(ctx, _NEW_FOG);
  135.          ctx->Fog.End = *params;
  136.          UPDATE_FOG_SCALE(ctx);
  137.          break;
  138.       case GL_FOG_INDEX:
  139.          if (ctx->Fog.Index == *params)
  140.             return;
  141.          FLUSH_VERTICES(ctx, _NEW_FOG);
  142.          ctx->Fog.Index = *params;
  143.          break;
  144.       case GL_FOG_COLOR:
  145.          if (TEST_EQ_4V(ctx->Fog.Color, params))
  146.             return;
  147.          FLUSH_VERTICES(ctx, _NEW_FOG);
  148.          ctx->Fog.Color[0] = CLAMP(params[0], 0.0F, 1.0F);
  149.          ctx->Fog.Color[1] = CLAMP(params[1], 0.0F, 1.0F);
  150.          ctx->Fog.Color[2] = CLAMP(params[2], 0.0F, 1.0F);
  151.          ctx->Fog.Color[3] = CLAMP(params[3], 0.0F, 1.0F);
  152.          break;
  153.       case GL_FOG_COORDINATE_SOURCE_EXT: {
  154.          GLenum p = (GLenum) (GLint) *params;
  155.          if (!ctx->Extensions.EXT_fog_coord ||
  156.              (p != GL_FOG_COORDINATE_EXT && p != GL_FRAGMENT_DEPTH_EXT)) {
  157.             _mesa_error(ctx, GL_INVALID_ENUM, "glFog");
  158.             return;
  159.          }
  160.          if (ctx->Fog.FogCoordinateSource == p)
  161.             return;
  162.          FLUSH_VERTICES(ctx, _NEW_FOG);
  163.          ctx->Fog.FogCoordinateSource = p;
  164.          break;
  165.       }
  166.       default:
  167.          _mesa_error( ctx, GL_INVALID_ENUM, "glFog" );
  168.          return;
  169.    }
  170.  
  171.    if (ctx->Driver.Fogfv) {
  172.       (*ctx->Driver.Fogfv)( ctx, pname, params );
  173.    }
  174. }
  175.  
  176.  
  177. /**********************************************************************/
  178. /*****                      Initialization                        *****/
  179. /**********************************************************************/
  180.  
  181. void _mesa_init_fog( struct gl_context * ctx )
  182. {
  183.    /* Fog group */
  184.    ctx->Fog.Enabled = GL_FALSE;
  185.    ctx->Fog.Mode = GL_EXP;
  186.    ASSIGN_4V( ctx->Fog.Color, 0.0, 0.0, 0.0, 0.0 );
  187.    ctx->Fog.Index = 0.0;
  188.    ctx->Fog.Density = 1.0;
  189.    ctx->Fog.Start = 0.0;
  190.    ctx->Fog.End = 1.0;
  191.    ctx->Fog.ColorSumEnabled = GL_FALSE;
  192.    ctx->Fog.FogCoordinateSource = GL_FRAGMENT_DEPTH_EXT;
  193.    ctx->Fog._Scale = 1.0f;
  194. }
  195.