points.c revision 7117f1b4
17117f1b4Smrg/**
27117f1b4Smrg * \file points.c
37117f1b4Smrg * Point operations.
47117f1b4Smrg */
57117f1b4Smrg
67117f1b4Smrg/*
77117f1b4Smrg * Mesa 3-D graphics library
87117f1b4Smrg * Version:  7.0.3
97117f1b4Smrg *
107117f1b4Smrg * Copyright (C) 1999-2007  Brian Paul   All Rights Reserved.
117117f1b4Smrg *
127117f1b4Smrg * Permission is hereby granted, free of charge, to any person obtaining a
137117f1b4Smrg * copy of this software and associated documentation files (the "Software"),
147117f1b4Smrg * to deal in the Software without restriction, including without limitation
157117f1b4Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
167117f1b4Smrg * and/or sell copies of the Software, and to permit persons to whom the
177117f1b4Smrg * Software is furnished to do so, subject to the following conditions:
187117f1b4Smrg *
197117f1b4Smrg * The above copyright notice and this permission notice shall be included
207117f1b4Smrg * in all copies or substantial portions of the Software.
217117f1b4Smrg *
227117f1b4Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
237117f1b4Smrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
247117f1b4Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
257117f1b4Smrg * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
267117f1b4Smrg * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
277117f1b4Smrg * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
287117f1b4Smrg */
297117f1b4Smrg
307117f1b4Smrg
317117f1b4Smrg#include "glheader.h"
327117f1b4Smrg#include "context.h"
337117f1b4Smrg#include "macros.h"
347117f1b4Smrg#include "points.h"
357117f1b4Smrg#include "texstate.h"
367117f1b4Smrg#include "mtypes.h"
377117f1b4Smrg
387117f1b4Smrg
397117f1b4Smrg/**
407117f1b4Smrg * Set current point size.
417117f1b4Smrg * \param size  point diameter in pixels
427117f1b4Smrg * \sa glPointSize().
437117f1b4Smrg */
447117f1b4Smrgvoid GLAPIENTRY
457117f1b4Smrg_mesa_PointSize( GLfloat size )
467117f1b4Smrg{
477117f1b4Smrg   GET_CURRENT_CONTEXT(ctx);
487117f1b4Smrg   ASSERT_OUTSIDE_BEGIN_END(ctx);
497117f1b4Smrg
507117f1b4Smrg   if (size <= 0.0) {
517117f1b4Smrg      _mesa_error( ctx, GL_INVALID_VALUE, "glPointSize" );
527117f1b4Smrg      return;
537117f1b4Smrg   }
547117f1b4Smrg
557117f1b4Smrg   if (ctx->Point.Size == size)
567117f1b4Smrg      return;
577117f1b4Smrg
587117f1b4Smrg   FLUSH_VERTICES(ctx, _NEW_POINT);
597117f1b4Smrg   ctx->Point.Size = size;
607117f1b4Smrg   /* _Size is only used for non-attenuated path */
617117f1b4Smrg   ctx->Point._Size = CLAMP(ctx->Point.Size,
627117f1b4Smrg			    ctx->Point.MinSize,
637117f1b4Smrg			    ctx->Point.MaxSize);
647117f1b4Smrg
657117f1b4Smrg   if (ctx->Driver.PointSize)
667117f1b4Smrg      ctx->Driver.PointSize(ctx, size);
677117f1b4Smrg}
687117f1b4Smrg
697117f1b4Smrg
707117f1b4Smrg#if _HAVE_FULL_GL
717117f1b4Smrg
727117f1b4Smrg/*
737117f1b4Smrg * Added by GL_NV_point_sprite
747117f1b4Smrg */
757117f1b4Smrgvoid GLAPIENTRY
767117f1b4Smrg_mesa_PointParameteriNV( GLenum pname, GLint param )
777117f1b4Smrg{
787117f1b4Smrg   const GLfloat value = (GLfloat) param;
797117f1b4Smrg   _mesa_PointParameterfvEXT(pname, &value);
807117f1b4Smrg}
817117f1b4Smrg
827117f1b4Smrg
837117f1b4Smrg/*
847117f1b4Smrg * Added by GL_NV_point_sprite
857117f1b4Smrg */
867117f1b4Smrgvoid GLAPIENTRY
877117f1b4Smrg_mesa_PointParameterivNV( GLenum pname, const GLint *params )
887117f1b4Smrg{
897117f1b4Smrg   GLfloat p[3];
907117f1b4Smrg   p[0] = (GLfloat) params[0];
917117f1b4Smrg   if (pname == GL_DISTANCE_ATTENUATION_EXT) {
927117f1b4Smrg      p[1] = (GLfloat) params[1];
937117f1b4Smrg      p[2] = (GLfloat) params[2];
947117f1b4Smrg   }
957117f1b4Smrg   _mesa_PointParameterfvEXT(pname, p);
967117f1b4Smrg}
977117f1b4Smrg
987117f1b4Smrg
997117f1b4Smrg
1007117f1b4Smrg/*
1017117f1b4Smrg * Same for both GL_EXT_point_parameters and GL_ARB_point_parameters.
1027117f1b4Smrg */
1037117f1b4Smrgvoid GLAPIENTRY
1047117f1b4Smrg_mesa_PointParameterfEXT( GLenum pname, GLfloat param)
1057117f1b4Smrg{
1067117f1b4Smrg   _mesa_PointParameterfvEXT(pname, &param);
1077117f1b4Smrg}
1087117f1b4Smrg
1097117f1b4Smrg
1107117f1b4Smrg
1117117f1b4Smrg/*
1127117f1b4Smrg * Same for both GL_EXT_point_parameters and GL_ARB_point_parameters.
1137117f1b4Smrg */
1147117f1b4Smrgvoid GLAPIENTRY
1157117f1b4Smrg_mesa_PointParameterfvEXT( GLenum pname, const GLfloat *params)
1167117f1b4Smrg{
1177117f1b4Smrg   GET_CURRENT_CONTEXT(ctx);
1187117f1b4Smrg   ASSERT_OUTSIDE_BEGIN_END(ctx);
1197117f1b4Smrg
1207117f1b4Smrg   switch (pname) {
1217117f1b4Smrg      case GL_DISTANCE_ATTENUATION_EXT:
1227117f1b4Smrg         if (ctx->Extensions.EXT_point_parameters) {
1237117f1b4Smrg            if (TEST_EQ_3V(ctx->Point.Params, params))
1247117f1b4Smrg	       return;
1257117f1b4Smrg	    FLUSH_VERTICES(ctx, _NEW_POINT);
1267117f1b4Smrg            COPY_3V(ctx->Point.Params, params);
1277117f1b4Smrg
1287117f1b4Smrg            ctx->Point._Attenuated = (ctx->Point.Params[0] != 1.0 ||
1297117f1b4Smrg                                      ctx->Point.Params[1] != 0.0 ||
1307117f1b4Smrg                                      ctx->Point.Params[2] != 0.0);
1317117f1b4Smrg
1327117f1b4Smrg            if (ctx->Point._Attenuated)
1337117f1b4Smrg               ctx->_TriangleCaps |= DD_POINT_ATTEN;
1347117f1b4Smrg            else
1357117f1b4Smrg               ctx->_TriangleCaps &= ~DD_POINT_ATTEN;
1367117f1b4Smrg         }
1377117f1b4Smrg         else {
1387117f1b4Smrg            _mesa_error(ctx, GL_INVALID_ENUM,
1397117f1b4Smrg                        "glPointParameterf[v]{EXT,ARB}(pname)");
1407117f1b4Smrg            return;
1417117f1b4Smrg         }
1427117f1b4Smrg         break;
1437117f1b4Smrg      case GL_POINT_SIZE_MIN_EXT:
1447117f1b4Smrg         if (ctx->Extensions.EXT_point_parameters) {
1457117f1b4Smrg            if (params[0] < 0.0F) {
1467117f1b4Smrg               _mesa_error( ctx, GL_INVALID_VALUE,
1477117f1b4Smrg                            "glPointParameterf[v]{EXT,ARB}(param)" );
1487117f1b4Smrg               return;
1497117f1b4Smrg            }
1507117f1b4Smrg            if (ctx->Point.MinSize == params[0])
1517117f1b4Smrg               return;
1527117f1b4Smrg            FLUSH_VERTICES(ctx, _NEW_POINT);
1537117f1b4Smrg            ctx->Point.MinSize = params[0];
1547117f1b4Smrg            /* re-clamp _Size */
1557117f1b4Smrg            ctx->Point._Size = CLAMP(ctx->Point.Size,
1567117f1b4Smrg                                     ctx->Point.MinSize,
1577117f1b4Smrg                                     ctx->Point.MaxSize);
1587117f1b4Smrg         }
1597117f1b4Smrg         else {
1607117f1b4Smrg            _mesa_error(ctx, GL_INVALID_ENUM,
1617117f1b4Smrg                        "glPointParameterf[v]{EXT,ARB}(pname)");
1627117f1b4Smrg            return;
1637117f1b4Smrg         }
1647117f1b4Smrg         break;
1657117f1b4Smrg      case GL_POINT_SIZE_MAX_EXT:
1667117f1b4Smrg         if (ctx->Extensions.EXT_point_parameters) {
1677117f1b4Smrg            if (params[0] < 0.0F) {
1687117f1b4Smrg               _mesa_error( ctx, GL_INVALID_VALUE,
1697117f1b4Smrg                            "glPointParameterf[v]{EXT,ARB}(param)" );
1707117f1b4Smrg               return;
1717117f1b4Smrg            }
1727117f1b4Smrg            if (ctx->Point.MaxSize == params[0])
1737117f1b4Smrg               return;
1747117f1b4Smrg            FLUSH_VERTICES(ctx, _NEW_POINT);
1757117f1b4Smrg            ctx->Point.MaxSize = params[0];
1767117f1b4Smrg            /* re-clamp _Size */
1777117f1b4Smrg            ctx->Point._Size = CLAMP(ctx->Point.Size,
1787117f1b4Smrg                                     ctx->Point.MinSize,
1797117f1b4Smrg                                     ctx->Point.MaxSize);
1807117f1b4Smrg         }
1817117f1b4Smrg         else {
1827117f1b4Smrg            _mesa_error(ctx, GL_INVALID_ENUM,
1837117f1b4Smrg                        "glPointParameterf[v]{EXT,ARB}(pname)");
1847117f1b4Smrg            return;
1857117f1b4Smrg         }
1867117f1b4Smrg         break;
1877117f1b4Smrg      case GL_POINT_FADE_THRESHOLD_SIZE_EXT:
1887117f1b4Smrg         if (ctx->Extensions.EXT_point_parameters) {
1897117f1b4Smrg            if (params[0] < 0.0F) {
1907117f1b4Smrg               _mesa_error( ctx, GL_INVALID_VALUE,
1917117f1b4Smrg                            "glPointParameterf[v]{EXT,ARB}(param)" );
1927117f1b4Smrg               return;
1937117f1b4Smrg            }
1947117f1b4Smrg            if (ctx->Point.Threshold == params[0])
1957117f1b4Smrg               return;
1967117f1b4Smrg            FLUSH_VERTICES(ctx, _NEW_POINT);
1977117f1b4Smrg            ctx->Point.Threshold = params[0];
1987117f1b4Smrg         }
1997117f1b4Smrg         else {
2007117f1b4Smrg            _mesa_error(ctx, GL_INVALID_ENUM,
2017117f1b4Smrg                        "glPointParameterf[v]{EXT,ARB}(pname)");
2027117f1b4Smrg            return;
2037117f1b4Smrg         }
2047117f1b4Smrg         break;
2057117f1b4Smrg      case GL_POINT_SPRITE_R_MODE_NV:
2067117f1b4Smrg         /* This is one area where ARB_point_sprite and NV_point_sprite
2077117f1b4Smrg	  * differ.  In ARB_point_sprite the POINT_SPRITE_R_MODE is
2087117f1b4Smrg	  * always ZERO.  NV_point_sprite adds the S and R modes.
2097117f1b4Smrg	  */
2107117f1b4Smrg         if (ctx->Extensions.NV_point_sprite) {
2117117f1b4Smrg            GLenum value = (GLenum) params[0];
2127117f1b4Smrg            if (value != GL_ZERO && value != GL_S && value != GL_R) {
2137117f1b4Smrg               _mesa_error(ctx, GL_INVALID_VALUE,
2147117f1b4Smrg                           "glPointParameterf[v]{EXT,ARB}(param)");
2157117f1b4Smrg               return;
2167117f1b4Smrg            }
2177117f1b4Smrg            if (ctx->Point.SpriteRMode == value)
2187117f1b4Smrg               return;
2197117f1b4Smrg            FLUSH_VERTICES(ctx, _NEW_POINT);
2207117f1b4Smrg            ctx->Point.SpriteRMode = value;
2217117f1b4Smrg         }
2227117f1b4Smrg         else {
2237117f1b4Smrg            _mesa_error(ctx, GL_INVALID_ENUM,
2247117f1b4Smrg                        "glPointParameterf[v]{EXT,ARB}(pname)");
2257117f1b4Smrg            return;
2267117f1b4Smrg         }
2277117f1b4Smrg         break;
2287117f1b4Smrg      case GL_POINT_SPRITE_COORD_ORIGIN:
2297117f1b4Smrg         if (ctx->Extensions.ARB_point_sprite) {
2307117f1b4Smrg            GLenum value = (GLenum) params[0];
2317117f1b4Smrg            if (value != GL_LOWER_LEFT && value != GL_UPPER_LEFT) {
2327117f1b4Smrg               _mesa_error(ctx, GL_INVALID_VALUE,
2337117f1b4Smrg                           "glPointParameterf[v]{EXT,ARB}(param)");
2347117f1b4Smrg               return;
2357117f1b4Smrg            }
2367117f1b4Smrg            if (ctx->Point.SpriteOrigin == value)
2377117f1b4Smrg               return;
2387117f1b4Smrg            FLUSH_VERTICES(ctx, _NEW_POINT);
2397117f1b4Smrg            ctx->Point.SpriteOrigin = value;
2407117f1b4Smrg         }
2417117f1b4Smrg         else {
2427117f1b4Smrg            _mesa_error(ctx, GL_INVALID_ENUM,
2437117f1b4Smrg                        "glPointParameterf[v]{EXT,ARB}(pname)");
2447117f1b4Smrg            return;
2457117f1b4Smrg         }
2467117f1b4Smrg         break;
2477117f1b4Smrg      default:
2487117f1b4Smrg         _mesa_error( ctx, GL_INVALID_ENUM,
2497117f1b4Smrg                      "glPointParameterf[v]{EXT,ARB}(pname)" );
2507117f1b4Smrg         return;
2517117f1b4Smrg   }
2527117f1b4Smrg
2537117f1b4Smrg   if (ctx->Driver.PointParameterfv)
2547117f1b4Smrg      (*ctx->Driver.PointParameterfv)(ctx, pname, params);
2557117f1b4Smrg}
2567117f1b4Smrg#endif
2577117f1b4Smrg
2587117f1b4Smrg
2597117f1b4Smrg
2607117f1b4Smrg/**
2617117f1b4Smrg * Initialize the context point state.
2627117f1b4Smrg *
2637117f1b4Smrg * \param ctx GL context.
2647117f1b4Smrg *
2657117f1b4Smrg * Initializes __GLcontextRec::Point and point related constants in
2667117f1b4Smrg * __GLcontextRec::Const.
2677117f1b4Smrg */
2687117f1b4Smrgvoid
2697117f1b4Smrg_mesa_init_point(GLcontext *ctx)
2707117f1b4Smrg{
2717117f1b4Smrg   GLuint i;
2727117f1b4Smrg
2737117f1b4Smrg   ctx->Point.SmoothFlag = GL_FALSE;
2747117f1b4Smrg   ctx->Point.Size = 1.0;
2757117f1b4Smrg   ctx->Point._Size = 1.0;
2767117f1b4Smrg   ctx->Point.Params[0] = 1.0;
2777117f1b4Smrg   ctx->Point.Params[1] = 0.0;
2787117f1b4Smrg   ctx->Point.Params[2] = 0.0;
2797117f1b4Smrg   ctx->Point._Attenuated = GL_FALSE;
2807117f1b4Smrg   ctx->Point.MinSize = 0.0;
2817117f1b4Smrg   ctx->Point.MaxSize
2827117f1b4Smrg      = MAX2(ctx->Const.MaxPointSize, ctx->Const.MaxPointSizeAA);
2837117f1b4Smrg   ctx->Point.Threshold = 1.0;
2847117f1b4Smrg   ctx->Point.PointSprite = GL_FALSE; /* GL_ARB/NV_point_sprite */
2857117f1b4Smrg   ctx->Point.SpriteRMode = GL_ZERO; /* GL_NV_point_sprite (only!) */
2867117f1b4Smrg   ctx->Point.SpriteOrigin = GL_UPPER_LEFT; /* GL_ARB_point_sprite */
2877117f1b4Smrg   for (i = 0; i < MAX_TEXTURE_UNITS; i++) {
2887117f1b4Smrg      ctx->Point.CoordReplace[i] = GL_FALSE; /* GL_ARB/NV_point_sprite */
2897117f1b4Smrg   }
2907117f1b4Smrg}
291