points.c revision 01e04c3f
17117f1b4Smrg/**
27117f1b4Smrg * \file points.c
37117f1b4Smrg * Point operations.
47117f1b4Smrg */
57117f1b4Smrg
67117f1b4Smrg/*
77117f1b4Smrg * Mesa 3-D graphics library
87117f1b4Smrg *
97117f1b4Smrg * Copyright (C) 1999-2007  Brian Paul   All Rights Reserved.
107117f1b4Smrg *
117117f1b4Smrg * Permission is hereby granted, free of charge, to any person obtaining a
127117f1b4Smrg * copy of this software and associated documentation files (the "Software"),
137117f1b4Smrg * to deal in the Software without restriction, including without limitation
147117f1b4Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
157117f1b4Smrg * and/or sell copies of the Software, and to permit persons to whom the
167117f1b4Smrg * Software is furnished to do so, subject to the following conditions:
177117f1b4Smrg *
187117f1b4Smrg * The above copyright notice and this permission notice shall be included
197117f1b4Smrg * in all copies or substantial portions of the Software.
207117f1b4Smrg *
217117f1b4Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
227117f1b4Smrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
237117f1b4Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
24af69d88dSmrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
25af69d88dSmrg * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
26af69d88dSmrg * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27af69d88dSmrg * 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 "mtypes.h"
367117f1b4Smrg
377117f1b4Smrg
387117f1b4Smrg/**
397117f1b4Smrg * Set current point size.
407117f1b4Smrg * \param size  point diameter in pixels
417117f1b4Smrg * \sa glPointSize().
427117f1b4Smrg */
4301e04c3fSmrgstatic ALWAYS_INLINE void
4401e04c3fSmrgpoint_size(struct gl_context *ctx, GLfloat size, bool no_error)
457117f1b4Smrg{
4601e04c3fSmrg   if (ctx->Point.Size == size)
477117f1b4Smrg      return;
487117f1b4Smrg
4901e04c3fSmrg   if (!no_error && size <= 0.0F) {
5001e04c3fSmrg      _mesa_error(ctx, GL_INVALID_VALUE, "glPointSize");
517117f1b4Smrg      return;
5201e04c3fSmrg   }
537117f1b4Smrg
547117f1b4Smrg   FLUSH_VERTICES(ctx, _NEW_POINT);
557117f1b4Smrg   ctx->Point.Size = size;
567117f1b4Smrg
577117f1b4Smrg   if (ctx->Driver.PointSize)
587117f1b4Smrg      ctx->Driver.PointSize(ctx, size);
597117f1b4Smrg}
607117f1b4Smrg
617117f1b4Smrg
6201e04c3fSmrgvoid GLAPIENTRY
6301e04c3fSmrg_mesa_PointSize_no_error(GLfloat size)
6401e04c3fSmrg{
6501e04c3fSmrg   GET_CURRENT_CONTEXT(ctx);
6601e04c3fSmrg   point_size(ctx, size, true);
6701e04c3fSmrg}
6801e04c3fSmrg
6901e04c3fSmrg
7001e04c3fSmrgvoid GLAPIENTRY
7101e04c3fSmrg_mesa_PointSize( GLfloat size )
7201e04c3fSmrg{
7301e04c3fSmrg   GET_CURRENT_CONTEXT(ctx);
7401e04c3fSmrg   point_size(ctx, size, false);
7501e04c3fSmrg}
7601e04c3fSmrg
7701e04c3fSmrg
787117f1b4Smrgvoid GLAPIENTRY
79c1f859d4Smrg_mesa_PointParameteri( GLenum pname, GLint param )
807117f1b4Smrg{
814a49301eSmrg   GLfloat p[3];
824a49301eSmrg   p[0] = (GLfloat) param;
834a49301eSmrg   p[1] = p[2] = 0.0F;
844a49301eSmrg   _mesa_PointParameterfv(pname, p);
857117f1b4Smrg}
867117f1b4Smrg
877117f1b4Smrg
887117f1b4Smrgvoid GLAPIENTRY
89c1f859d4Smrg_mesa_PointParameteriv( GLenum pname, const GLint *params )
907117f1b4Smrg{
917117f1b4Smrg   GLfloat p[3];
927117f1b4Smrg   p[0] = (GLfloat) params[0];
937117f1b4Smrg   if (pname == GL_DISTANCE_ATTENUATION_EXT) {
947117f1b4Smrg      p[1] = (GLfloat) params[1];
957117f1b4Smrg      p[2] = (GLfloat) params[2];
967117f1b4Smrg   }
97c1f859d4Smrg   _mesa_PointParameterfv(pname, p);
987117f1b4Smrg}
997117f1b4Smrg
1007117f1b4Smrg
1017117f1b4Smrgvoid GLAPIENTRY
102c1f859d4Smrg_mesa_PointParameterf( GLenum pname, GLfloat param)
1037117f1b4Smrg{
1044a49301eSmrg   GLfloat p[3];
1054a49301eSmrg   p[0] = param;
1064a49301eSmrg   p[1] = p[2] = 0.0F;
1074a49301eSmrg   _mesa_PointParameterfv(pname, p);
1087117f1b4Smrg}
1097117f1b4Smrg
1107117f1b4Smrg
1117117f1b4Smrgvoid GLAPIENTRY
112c1f859d4Smrg_mesa_PointParameterfv( GLenum pname, const GLfloat *params)
1137117f1b4Smrg{
1147117f1b4Smrg   GET_CURRENT_CONTEXT(ctx);
115af69d88dSmrg
116af69d88dSmrg   /* Drivers that support point sprites must also support point parameters.
117af69d88dSmrg    * If point parameters aren't supported, then this function shouldn't even
118af69d88dSmrg    * exist.
119af69d88dSmrg    */
12001e04c3fSmrg   assert(!(ctx->Extensions.ARB_point_sprite
121af69d88dSmrg            || ctx->Extensions.NV_point_sprite)
122af69d88dSmrg          || ctx->Extensions.EXT_point_parameters);
123af69d88dSmrg
124af69d88dSmrg   if (!ctx->Extensions.EXT_point_parameters) {
125af69d88dSmrg      _mesa_error(ctx, GL_INVALID_OPERATION,
126af69d88dSmrg                  "unsupported function called (unsupported extension)");
127af69d88dSmrg      return;
128af69d88dSmrg   }
1297117f1b4Smrg
1307117f1b4Smrg   switch (pname) {
1317117f1b4Smrg      case GL_DISTANCE_ATTENUATION_EXT:
132af69d88dSmrg         if (TEST_EQ_3V(ctx->Point.Params, params))
1337117f1b4Smrg            return;
134af69d88dSmrg         FLUSH_VERTICES(ctx, _NEW_POINT);
135af69d88dSmrg         COPY_3V(ctx->Point.Params, params);
13601e04c3fSmrg         ctx->Point._Attenuated = (ctx->Point.Params[0] != 1.0F ||
13701e04c3fSmrg                                   ctx->Point.Params[1] != 0.0F ||
13801e04c3fSmrg                                   ctx->Point.Params[2] != 0.0F);
1397117f1b4Smrg         break;
1407117f1b4Smrg      case GL_POINT_SIZE_MIN_EXT:
141af69d88dSmrg         if (params[0] < 0.0F) {
142af69d88dSmrg            _mesa_error( ctx, GL_INVALID_VALUE,
143af69d88dSmrg                         "glPointParameterf[v]{EXT,ARB}(param)" );
1447117f1b4Smrg            return;
1457117f1b4Smrg         }
146af69d88dSmrg         if (ctx->Point.MinSize == params[0])
147af69d88dSmrg            return;
148af69d88dSmrg         FLUSH_VERTICES(ctx, _NEW_POINT);
149af69d88dSmrg         ctx->Point.MinSize = params[0];
1507117f1b4Smrg         break;
1517117f1b4Smrg      case GL_POINT_SIZE_MAX_EXT:
152af69d88dSmrg         if (params[0] < 0.0F) {
153af69d88dSmrg            _mesa_error( ctx, GL_INVALID_VALUE,
154af69d88dSmrg                         "glPointParameterf[v]{EXT,ARB}(param)" );
1557117f1b4Smrg            return;
1567117f1b4Smrg         }
157af69d88dSmrg         if (ctx->Point.MaxSize == params[0])
158af69d88dSmrg            return;
159af69d88dSmrg         FLUSH_VERTICES(ctx, _NEW_POINT);
160af69d88dSmrg         ctx->Point.MaxSize = params[0];
1617117f1b4Smrg         break;
1627117f1b4Smrg      case GL_POINT_FADE_THRESHOLD_SIZE_EXT:
163af69d88dSmrg         if (params[0] < 0.0F) {
164af69d88dSmrg            _mesa_error( ctx, GL_INVALID_VALUE,
165af69d88dSmrg                         "glPointParameterf[v]{EXT,ARB}(param)" );
1667117f1b4Smrg            return;
1677117f1b4Smrg         }
168af69d88dSmrg         if (ctx->Point.Threshold == params[0])
169af69d88dSmrg            return;
170af69d88dSmrg         FLUSH_VERTICES(ctx, _NEW_POINT);
171af69d88dSmrg         ctx->Point.Threshold = params[0];
1727117f1b4Smrg         break;
1737117f1b4Smrg      case GL_POINT_SPRITE_R_MODE_NV:
1747117f1b4Smrg         /* This is one area where ARB_point_sprite and NV_point_sprite
1757117f1b4Smrg	  * differ.  In ARB_point_sprite the POINT_SPRITE_R_MODE is
1767117f1b4Smrg	  * always ZERO.  NV_point_sprite adds the S and R modes.
1777117f1b4Smrg	  */
178af69d88dSmrg         if (_mesa_is_desktop_gl(ctx) && ctx->Extensions.NV_point_sprite) {
1797117f1b4Smrg            GLenum value = (GLenum) params[0];
1807117f1b4Smrg            if (value != GL_ZERO && value != GL_S && value != GL_R) {
1817117f1b4Smrg               _mesa_error(ctx, GL_INVALID_VALUE,
1827117f1b4Smrg                           "glPointParameterf[v]{EXT,ARB}(param)");
1837117f1b4Smrg               return;
1847117f1b4Smrg            }
1857117f1b4Smrg            if (ctx->Point.SpriteRMode == value)
1867117f1b4Smrg               return;
1877117f1b4Smrg            FLUSH_VERTICES(ctx, _NEW_POINT);
1887117f1b4Smrg            ctx->Point.SpriteRMode = value;
1897117f1b4Smrg         }
1907117f1b4Smrg         else {
1917117f1b4Smrg            _mesa_error(ctx, GL_INVALID_ENUM,
1927117f1b4Smrg                        "glPointParameterf[v]{EXT,ARB}(pname)");
1937117f1b4Smrg            return;
1947117f1b4Smrg         }
1957117f1b4Smrg         break;
1967117f1b4Smrg      case GL_POINT_SPRITE_COORD_ORIGIN:
197af69d88dSmrg	 /* GL_POINT_SPRITE_COORD_ORIGIN was added to point sprites when the
198af69d88dSmrg	  * extension was merged into OpenGL 2.0.
1994a49301eSmrg	  */
200af69d88dSmrg         if ((ctx->API == API_OPENGL_COMPAT && ctx->Version >= 20)
201af69d88dSmrg             || ctx->API == API_OPENGL_CORE) {
2027117f1b4Smrg            GLenum value = (GLenum) params[0];
2037117f1b4Smrg            if (value != GL_LOWER_LEFT && value != GL_UPPER_LEFT) {
2047117f1b4Smrg               _mesa_error(ctx, GL_INVALID_VALUE,
2057117f1b4Smrg                           "glPointParameterf[v]{EXT,ARB}(param)");
2067117f1b4Smrg               return;
2077117f1b4Smrg            }
2087117f1b4Smrg            if (ctx->Point.SpriteOrigin == value)
2097117f1b4Smrg               return;
2107117f1b4Smrg            FLUSH_VERTICES(ctx, _NEW_POINT);
2117117f1b4Smrg            ctx->Point.SpriteOrigin = value;
2127117f1b4Smrg         }
2137117f1b4Smrg         else {
2147117f1b4Smrg            _mesa_error(ctx, GL_INVALID_ENUM,
2157117f1b4Smrg                        "glPointParameterf[v]{EXT,ARB}(pname)");
2167117f1b4Smrg            return;
2177117f1b4Smrg         }
2187117f1b4Smrg         break;
2197117f1b4Smrg      default:
2207117f1b4Smrg         _mesa_error( ctx, GL_INVALID_ENUM,
2217117f1b4Smrg                      "glPointParameterf[v]{EXT,ARB}(pname)" );
2227117f1b4Smrg         return;
2237117f1b4Smrg   }
2247117f1b4Smrg
2257117f1b4Smrg   if (ctx->Driver.PointParameterfv)
22601e04c3fSmrg      ctx->Driver.PointParameterfv(ctx, pname, params);
2277117f1b4Smrg}
2287117f1b4Smrg
2297117f1b4Smrg
2307117f1b4Smrg
2317117f1b4Smrg/**
2327117f1b4Smrg * Initialize the context point state.
2337117f1b4Smrg *
2347117f1b4Smrg * \param ctx GL context.
2357117f1b4Smrg *
2363464ebd5Sriastradh * Initializes __struct gl_contextRec::Point and point related constants in
2373464ebd5Sriastradh * __struct gl_contextRec::Const.
2387117f1b4Smrg */
2397117f1b4Smrgvoid
2403464ebd5Sriastradh_mesa_init_point(struct gl_context *ctx)
2417117f1b4Smrg{
2427117f1b4Smrg   ctx->Point.SmoothFlag = GL_FALSE;
2437117f1b4Smrg   ctx->Point.Size = 1.0;
2447117f1b4Smrg   ctx->Point.Params[0] = 1.0;
2457117f1b4Smrg   ctx->Point.Params[1] = 0.0;
2467117f1b4Smrg   ctx->Point.Params[2] = 0.0;
2477117f1b4Smrg   ctx->Point._Attenuated = GL_FALSE;
2487117f1b4Smrg   ctx->Point.MinSize = 0.0;
2497117f1b4Smrg   ctx->Point.MaxSize
2507117f1b4Smrg      = MAX2(ctx->Const.MaxPointSize, ctx->Const.MaxPointSizeAA);
2517117f1b4Smrg   ctx->Point.Threshold = 1.0;
252af69d88dSmrg
253af69d88dSmrg   /* Page 403 (page 423 of the PDF) of the OpenGL 3.0 spec says:
254af69d88dSmrg    *
255af69d88dSmrg    *     "Non-sprite points (section 3.4) - Enable/Disable targets
256af69d88dSmrg    *     POINT_SMOOTH and POINT_SPRITE, and all associated state. Point
257af69d88dSmrg    *     rasterization is always performed as though POINT_SPRITE were
258af69d88dSmrg    *     enabled."
259af69d88dSmrg    *
260af69d88dSmrg    * In a core context, the state will default to true, and the setters and
261af69d88dSmrg    * getters are disabled.
262af69d88dSmrg    */
263af69d88dSmrg   ctx->Point.PointSprite = (ctx->API == API_OPENGL_CORE ||
264af69d88dSmrg                             ctx->API == API_OPENGLES2);
265af69d88dSmrg
2667117f1b4Smrg   ctx->Point.SpriteRMode = GL_ZERO; /* GL_NV_point_sprite (only!) */
2677117f1b4Smrg   ctx->Point.SpriteOrigin = GL_UPPER_LEFT; /* GL_ARB_point_sprite */
26801e04c3fSmrg   ctx->Point.CoordReplace = 0; /* GL_ARB/NV_point_sprite */
2697117f1b4Smrg}
270