• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * \file points.c
3  * Point operations.
4  */
5 
6 /*
7  * Mesa 3-D graphics library
8  *
9  * Copyright (C) 1999-2007  Brian Paul   All Rights Reserved.
10  *
11  * Permission is hereby granted, free of charge, to any person obtaining a
12  * copy of this software and associated documentation files (the "Software"),
13  * to deal in the Software without restriction, including without limitation
14  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15  * and/or sell copies of the Software, and to permit persons to whom the
16  * Software is furnished to do so, subject to the following conditions:
17  *
18  * The above copyright notice and this permission notice shall be included
19  * in all copies or substantial portions of the Software.
20  *
21  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
24  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
25  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
26  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27  * OTHER DEALINGS IN THE SOFTWARE.
28  */
29 
30 
31 #include "glheader.h"
32 #include "context.h"
33 #include "macros.h"
34 #include "points.h"
35 #include "mtypes.h"
36 
37 
38 /**
39  * Set current point size.
40  * \param size  point diameter in pixels
41  * \sa glPointSize().
42  */
43 static ALWAYS_INLINE void
point_size(struct gl_context * ctx,GLfloat size,bool no_error)44 point_size(struct gl_context *ctx, GLfloat size, bool no_error)
45 {
46    if (ctx->Point.Size == size)
47       return;
48 
49    if (!no_error && size <= 0.0F) {
50       _mesa_error(ctx, GL_INVALID_VALUE, "glPointSize");
51       return;
52    }
53 
54    FLUSH_VERTICES(ctx, _NEW_POINT, GL_POINT_BIT);
55    ctx->Point.Size = size;
56 
57    if (ctx->Driver.PointSize)
58       ctx->Driver.PointSize(ctx, size);
59 }
60 
61 
62 void GLAPIENTRY
_mesa_PointSize_no_error(GLfloat size)63 _mesa_PointSize_no_error(GLfloat size)
64 {
65    GET_CURRENT_CONTEXT(ctx);
66    point_size(ctx, size, true);
67 }
68 
69 
70 void GLAPIENTRY
_mesa_PointSize(GLfloat size)71 _mesa_PointSize( GLfloat size )
72 {
73    GET_CURRENT_CONTEXT(ctx);
74    point_size(ctx, size, false);
75 }
76 
77 
78 void GLAPIENTRY
_mesa_PointParameteri(GLenum pname,GLint param)79 _mesa_PointParameteri( GLenum pname, GLint param )
80 {
81    GLfloat p[3];
82    p[0] = (GLfloat) param;
83    p[1] = p[2] = 0.0F;
84    _mesa_PointParameterfv(pname, p);
85 }
86 
87 
88 void GLAPIENTRY
_mesa_PointParameteriv(GLenum pname,const GLint * params)89 _mesa_PointParameteriv( GLenum pname, const GLint *params )
90 {
91    GLfloat p[3];
92    p[0] = (GLfloat) params[0];
93    if (pname == GL_DISTANCE_ATTENUATION_EXT) {
94       p[1] = (GLfloat) params[1];
95       p[2] = (GLfloat) params[2];
96    }
97    _mesa_PointParameterfv(pname, p);
98 }
99 
100 
101 void GLAPIENTRY
_mesa_PointParameterf(GLenum pname,GLfloat param)102 _mesa_PointParameterf( GLenum pname, GLfloat param)
103 {
104    GLfloat p[3];
105    p[0] = param;
106    p[1] = p[2] = 0.0F;
107    _mesa_PointParameterfv(pname, p);
108 }
109 
110 
111 void GLAPIENTRY
_mesa_PointParameterfv(GLenum pname,const GLfloat * params)112 _mesa_PointParameterfv( GLenum pname, const GLfloat *params)
113 {
114    GET_CURRENT_CONTEXT(ctx);
115 
116    /* Drivers that support point sprites must also support point parameters.
117     * If point parameters aren't supported, then this function shouldn't even
118     * exist.
119     */
120    assert(!ctx->Extensions.ARB_point_sprite ||
121           ctx->Extensions.EXT_point_parameters);
122 
123    if (!ctx->Extensions.EXT_point_parameters) {
124       _mesa_error(ctx, GL_INVALID_OPERATION,
125                   "unsupported function called (unsupported extension)");
126       return;
127    }
128 
129    switch (pname) {
130       case GL_DISTANCE_ATTENUATION_EXT:
131          if (TEST_EQ_3V(ctx->Point.Params, params))
132             return;
133          FLUSH_VERTICES(ctx, _NEW_POINT | _NEW_FF_VERT_PROGRAM |
134                         _NEW_TNL_SPACES, GL_POINT_BIT);
135          COPY_3V(ctx->Point.Params, params);
136          ctx->Point._Attenuated = (ctx->Point.Params[0] != 1.0F ||
137                                    ctx->Point.Params[1] != 0.0F ||
138                                    ctx->Point.Params[2] != 0.0F);
139          break;
140       case GL_POINT_SIZE_MIN_EXT:
141          if (params[0] < 0.0F) {
142             _mesa_error( ctx, GL_INVALID_VALUE,
143                          "glPointParameterf[v]{EXT,ARB}(param)" );
144             return;
145          }
146          if (ctx->Point.MinSize == params[0])
147             return;
148          FLUSH_VERTICES(ctx, _NEW_POINT, GL_POINT_BIT);
149          ctx->Point.MinSize = params[0];
150          break;
151       case GL_POINT_SIZE_MAX_EXT:
152          if (params[0] < 0.0F) {
153             _mesa_error( ctx, GL_INVALID_VALUE,
154                          "glPointParameterf[v]{EXT,ARB}(param)" );
155             return;
156          }
157          if (ctx->Point.MaxSize == params[0])
158             return;
159          FLUSH_VERTICES(ctx, _NEW_POINT, GL_POINT_BIT);
160          ctx->Point.MaxSize = params[0];
161          break;
162       case GL_POINT_FADE_THRESHOLD_SIZE_EXT:
163          if (params[0] < 0.0F) {
164             _mesa_error( ctx, GL_INVALID_VALUE,
165                          "glPointParameterf[v]{EXT,ARB}(param)" );
166             return;
167          }
168          if (ctx->Point.Threshold == params[0])
169             return;
170          FLUSH_VERTICES(ctx, _NEW_POINT, GL_POINT_BIT);
171          ctx->Point.Threshold = params[0];
172          break;
173       case GL_POINT_SPRITE_COORD_ORIGIN:
174 	 /* GL_POINT_SPRITE_COORD_ORIGIN was added to point sprites when the
175 	  * extension was merged into OpenGL 2.0.
176 	  */
177          if ((ctx->API == API_OPENGL_COMPAT && ctx->Version >= 20)
178              || ctx->API == API_OPENGL_CORE) {
179             GLenum value = (GLenum) params[0];
180             if (value != GL_LOWER_LEFT && value != GL_UPPER_LEFT) {
181                _mesa_error(ctx, GL_INVALID_VALUE,
182                            "glPointParameterf[v]{EXT,ARB}(param)");
183                return;
184             }
185             if (ctx->Point.SpriteOrigin == value)
186                return;
187             FLUSH_VERTICES(ctx, _NEW_POINT, GL_POINT_BIT);
188             ctx->Point.SpriteOrigin = value;
189          }
190          else {
191             _mesa_error(ctx, GL_INVALID_ENUM,
192                         "glPointParameterf[v]{EXT,ARB}(pname)");
193             return;
194          }
195          break;
196       default:
197          _mesa_error( ctx, GL_INVALID_ENUM,
198                       "glPointParameterf[v]{EXT,ARB}(pname)" );
199          return;
200    }
201 
202    if (ctx->Driver.PointParameterfv)
203       ctx->Driver.PointParameterfv(ctx, pname, params);
204 }
205 
206 
207 
208 /**
209  * Initialize the context point state.
210  *
211  * \param ctx GL context.
212  *
213  * Initializes __struct gl_contextRec::Point and point related constants in
214  * __struct gl_contextRec::Const.
215  */
216 void
_mesa_init_point(struct gl_context * ctx)217 _mesa_init_point(struct gl_context *ctx)
218 {
219    ctx->Point.SmoothFlag = GL_FALSE;
220    ctx->Point.Size = 1.0;
221    ctx->Point.Params[0] = 1.0;
222    ctx->Point.Params[1] = 0.0;
223    ctx->Point.Params[2] = 0.0;
224    ctx->Point._Attenuated = GL_FALSE;
225    ctx->Point.MinSize = 0.0;
226    ctx->Point.MaxSize
227       = MAX2(ctx->Const.MaxPointSize, ctx->Const.MaxPointSizeAA);
228    ctx->Point.Threshold = 1.0;
229 
230    /* Page 403 (page 423 of the PDF) of the OpenGL 3.0 spec says:
231     *
232     *     "Non-sprite points (section 3.4) - Enable/Disable targets
233     *     POINT_SMOOTH and POINT_SPRITE, and all associated state. Point
234     *     rasterization is always performed as though POINT_SPRITE were
235     *     enabled."
236     *
237     * In a core context, the state will default to true, and the setters and
238     * getters are disabled.
239     */
240    ctx->Point.PointSprite = (ctx->API == API_OPENGL_CORE ||
241                              ctx->API == API_OPENGLES2);
242 
243    ctx->Point.SpriteOrigin = GL_UPPER_LEFT; /* GL_ARB_point_sprite */
244    ctx->Point.CoordReplace = 0; /* GL_ARB_point_sprite */
245 }
246