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