Merge branch 'gallium-edgeflags'
[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 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
26 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
27 * CONNECTION WITH THE SOFTWARE OR THE USE OR 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 "texstate.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 ASSERT_OUTSIDE_BEGIN_END(ctx);
49
50 if (size <= 0.0) {
51 _mesa_error( ctx, GL_INVALID_VALUE, "glPointSize" );
52 return;
53 }
54
55 if (ctx->Point.Size == size)
56 return;
57
58 FLUSH_VERTICES(ctx, _NEW_POINT);
59 ctx->Point.Size = size;
60
61 if (ctx->Driver.PointSize)
62 ctx->Driver.PointSize(ctx, size);
63 }
64
65
66 #if _HAVE_FULL_GL
67
68
69 void GLAPIENTRY
70 _mesa_PointParameteri( GLenum pname, GLint param )
71 {
72 GLfloat p[3];
73 p[0] = (GLfloat) param;
74 p[1] = p[2] = 0.0F;
75 _mesa_PointParameterfv(pname, p);
76 }
77
78
79 void GLAPIENTRY
80 _mesa_PointParameteriv( GLenum pname, const GLint *params )
81 {
82 GLfloat p[3];
83 p[0] = (GLfloat) params[0];
84 if (pname == GL_DISTANCE_ATTENUATION_EXT) {
85 p[1] = (GLfloat) params[1];
86 p[2] = (GLfloat) params[2];
87 }
88 _mesa_PointParameterfv(pname, p);
89 }
90
91
92 void GLAPIENTRY
93 _mesa_PointParameterf( GLenum pname, GLfloat param)
94 {
95 GLfloat p[3];
96 p[0] = param;
97 p[1] = p[2] = 0.0F;
98 _mesa_PointParameterfv(pname, p);
99 }
100
101
102 void GLAPIENTRY
103 _mesa_PointParameterfv( GLenum pname, const GLfloat *params)
104 {
105 GET_CURRENT_CONTEXT(ctx);
106 ASSERT_OUTSIDE_BEGIN_END(ctx);
107
108 switch (pname) {
109 case GL_DISTANCE_ATTENUATION_EXT:
110 if (ctx->Extensions.EXT_point_parameters) {
111 if (TEST_EQ_3V(ctx->Point.Params, params))
112 return;
113 FLUSH_VERTICES(ctx, _NEW_POINT);
114 COPY_3V(ctx->Point.Params, params);
115 ctx->Point._Attenuated = (ctx->Point.Params[0] != 1.0 ||
116 ctx->Point.Params[1] != 0.0 ||
117 ctx->Point.Params[2] != 0.0);
118
119 if (ctx->Point._Attenuated)
120 ctx->_TriangleCaps |= DD_POINT_ATTEN;
121 else
122 ctx->_TriangleCaps &= ~DD_POINT_ATTEN;
123 }
124 else {
125 _mesa_error(ctx, GL_INVALID_ENUM,
126 "glPointParameterf[v]{EXT,ARB}(pname)");
127 return;
128 }
129 break;
130 case GL_POINT_SIZE_MIN_EXT:
131 if (ctx->Extensions.EXT_point_parameters) {
132 if (params[0] < 0.0F) {
133 _mesa_error( ctx, GL_INVALID_VALUE,
134 "glPointParameterf[v]{EXT,ARB}(param)" );
135 return;
136 }
137 if (ctx->Point.MinSize == params[0])
138 return;
139 FLUSH_VERTICES(ctx, _NEW_POINT);
140 ctx->Point.MinSize = params[0];
141 }
142 else {
143 _mesa_error(ctx, GL_INVALID_ENUM,
144 "glPointParameterf[v]{EXT,ARB}(pname)");
145 return;
146 }
147 break;
148 case GL_POINT_SIZE_MAX_EXT:
149 if (ctx->Extensions.EXT_point_parameters) {
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.MaxSize == params[0])
156 return;
157 FLUSH_VERTICES(ctx, _NEW_POINT);
158 ctx->Point.MaxSize = params[0];
159 }
160 else {
161 _mesa_error(ctx, GL_INVALID_ENUM,
162 "glPointParameterf[v]{EXT,ARB}(pname)");
163 return;
164 }
165 break;
166 case GL_POINT_FADE_THRESHOLD_SIZE_EXT:
167 if (ctx->Extensions.EXT_point_parameters) {
168 if (params[0] < 0.0F) {
169 _mesa_error( ctx, GL_INVALID_VALUE,
170 "glPointParameterf[v]{EXT,ARB}(param)" );
171 return;
172 }
173 if (ctx->Point.Threshold == params[0])
174 return;
175 FLUSH_VERTICES(ctx, _NEW_POINT);
176 ctx->Point.Threshold = params[0];
177 }
178 else {
179 _mesa_error(ctx, GL_INVALID_ENUM,
180 "glPointParameterf[v]{EXT,ARB}(pname)");
181 return;
182 }
183 break;
184 case GL_POINT_SPRITE_R_MODE_NV:
185 /* This is one area where ARB_point_sprite and NV_point_sprite
186 * differ. In ARB_point_sprite the POINT_SPRITE_R_MODE is
187 * always ZERO. NV_point_sprite adds the S and R modes.
188 */
189 if (ctx->Extensions.NV_point_sprite) {
190 GLenum value = (GLenum) params[0];
191 if (value != GL_ZERO && value != GL_S && value != GL_R) {
192 _mesa_error(ctx, GL_INVALID_VALUE,
193 "glPointParameterf[v]{EXT,ARB}(param)");
194 return;
195 }
196 if (ctx->Point.SpriteRMode == value)
197 return;
198 FLUSH_VERTICES(ctx, _NEW_POINT);
199 ctx->Point.SpriteRMode = value;
200 }
201 else {
202 _mesa_error(ctx, GL_INVALID_ENUM,
203 "glPointParameterf[v]{EXT,ARB}(pname)");
204 return;
205 }
206 break;
207 case GL_POINT_SPRITE_COORD_ORIGIN:
208 /* This is not completely correct. GL_POINT_SPRITE_COORD_ORIGIN was
209 * added to point sprites when the extension was merged into OpenGL
210 * 2.0. It is expected that an implementation supporting OpenGL 1.4
211 * and GL_ARB_point_sprite will generate an error here.
212 */
213 if (ctx->Extensions.ARB_point_sprite) {
214 GLenum value = (GLenum) params[0];
215 if (value != GL_LOWER_LEFT && value != GL_UPPER_LEFT) {
216 _mesa_error(ctx, GL_INVALID_VALUE,
217 "glPointParameterf[v]{EXT,ARB}(param)");
218 return;
219 }
220 if (ctx->Point.SpriteOrigin == value)
221 return;
222 FLUSH_VERTICES(ctx, _NEW_POINT);
223 ctx->Point.SpriteOrigin = value;
224 }
225 else {
226 _mesa_error(ctx, GL_INVALID_ENUM,
227 "glPointParameterf[v]{EXT,ARB}(pname)");
228 return;
229 }
230 break;
231 default:
232 _mesa_error( ctx, GL_INVALID_ENUM,
233 "glPointParameterf[v]{EXT,ARB}(pname)" );
234 return;
235 }
236
237 if (ctx->Driver.PointParameterfv)
238 (*ctx->Driver.PointParameterfv)(ctx, pname, params);
239 }
240 #endif
241
242
243
244 /**
245 * Initialize the context point state.
246 *
247 * \param ctx GL context.
248 *
249 * Initializes __GLcontextRec::Point and point related constants in
250 * __GLcontextRec::Const.
251 */
252 void
253 _mesa_init_point(GLcontext *ctx)
254 {
255 GLuint i;
256
257 ctx->Point.SmoothFlag = GL_FALSE;
258 ctx->Point.Size = 1.0;
259 ctx->Point.Params[0] = 1.0;
260 ctx->Point.Params[1] = 0.0;
261 ctx->Point.Params[2] = 0.0;
262 ctx->Point._Attenuated = GL_FALSE;
263 ctx->Point.MinSize = 0.0;
264 ctx->Point.MaxSize
265 = MAX2(ctx->Const.MaxPointSize, ctx->Const.MaxPointSizeAA);
266 ctx->Point.Threshold = 1.0;
267 ctx->Point.PointSprite = GL_FALSE; /* GL_ARB/NV_point_sprite */
268 ctx->Point.SpriteRMode = GL_ZERO; /* GL_NV_point_sprite (only!) */
269 ctx->Point.SpriteOrigin = GL_UPPER_LEFT; /* GL_ARB_point_sprite */
270 for (i = 0; i < MAX_TEXTURE_COORD_UNITS; i++) {
271 ctx->Point.CoordReplace[i] = GL_FALSE; /* GL_ARB/NV_point_sprite */
272 }
273 }