Move all the code for computing ctx->_TriangleCaps into state.c.
[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: 6.5.1
9 *
10 * Copyright (C) 1999-2006 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 * Added by GL_NV_point_sprite
70 */
71 void GLAPIENTRY
72 _mesa_PointParameteriNV( GLenum pname, GLint param )
73 {
74 const GLfloat value = (GLfloat) param;
75 _mesa_PointParameterfvEXT(pname, &value);
76 }
77
78
79 /*
80 * Added by GL_NV_point_sprite
81 */
82 void GLAPIENTRY
83 _mesa_PointParameterivNV( GLenum pname, const GLint *params )
84 {
85 const GLfloat value = (GLfloat) params[0];
86 _mesa_PointParameterfvEXT(pname, &value);
87 }
88
89
90
91 /*
92 * Same for both GL_EXT_point_parameters and GL_ARB_point_parameters.
93 */
94 void GLAPIENTRY
95 _mesa_PointParameterfEXT( GLenum pname, GLfloat param)
96 {
97 _mesa_PointParameterfvEXT(pname, &param);
98 }
99
100
101
102 /*
103 * Same for both GL_EXT_point_parameters and GL_ARB_point_parameters.
104 */
105 void GLAPIENTRY
106 _mesa_PointParameterfvEXT( GLenum pname, const GLfloat *params)
107 {
108 GET_CURRENT_CONTEXT(ctx);
109 ASSERT_OUTSIDE_BEGIN_END(ctx);
110
111 switch (pname) {
112 case GL_DISTANCE_ATTENUATION_EXT:
113 if (ctx->Extensions.EXT_point_parameters) {
114 if (TEST_EQ_3V(ctx->Point.Params, params))
115 return;
116 FLUSH_VERTICES(ctx, _NEW_POINT);
117 COPY_3V(ctx->Point.Params, params);
118 }
119 else {
120 _mesa_error(ctx, GL_INVALID_ENUM,
121 "glPointParameterf[v]{EXT,ARB}(pname)");
122 return;
123 }
124 break;
125 case GL_POINT_SIZE_MIN_EXT:
126 if (ctx->Extensions.EXT_point_parameters) {
127 if (params[0] < 0.0F) {
128 _mesa_error( ctx, GL_INVALID_VALUE,
129 "glPointParameterf[v]{EXT,ARB}(param)" );
130 return;
131 }
132 if (ctx->Point.MinSize == params[0])
133 return;
134 FLUSH_VERTICES(ctx, _NEW_POINT);
135 ctx->Point.MinSize = params[0];
136 }
137 else {
138 _mesa_error(ctx, GL_INVALID_ENUM,
139 "glPointParameterf[v]{EXT,ARB}(pname)");
140 return;
141 }
142 break;
143 case GL_POINT_SIZE_MAX_EXT:
144 if (ctx->Extensions.EXT_point_parameters) {
145 if (params[0] < 0.0F) {
146 _mesa_error( ctx, GL_INVALID_VALUE,
147 "glPointParameterf[v]{EXT,ARB}(param)" );
148 return;
149 }
150 if (ctx->Point.MaxSize == params[0])
151 return;
152 FLUSH_VERTICES(ctx, _NEW_POINT);
153 ctx->Point.MaxSize = params[0];
154 }
155 else {
156 _mesa_error(ctx, GL_INVALID_ENUM,
157 "glPointParameterf[v]{EXT,ARB}(pname)");
158 return;
159 }
160 break;
161 case GL_POINT_FADE_THRESHOLD_SIZE_EXT:
162 if (ctx->Extensions.EXT_point_parameters) {
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);
171 ctx->Point.Threshold = params[0];
172 }
173 else {
174 _mesa_error(ctx, GL_INVALID_ENUM,
175 "glPointParameterf[v]{EXT,ARB}(pname)");
176 return;
177 }
178 break;
179 case GL_POINT_SPRITE_R_MODE_NV:
180 /* This is one area where ARB_point_sprite and NV_point_sprite
181 * differ. In ARB_point_sprite the POINT_SPRITE_R_MODE is
182 * always ZERO. NV_point_sprite adds the S and R modes.
183 */
184 if (ctx->Extensions.NV_point_sprite) {
185 GLenum value = (GLenum) params[0];
186 if (value != GL_ZERO && value != GL_S && value != GL_R) {
187 _mesa_error(ctx, GL_INVALID_VALUE,
188 "glPointParameterf[v]{EXT,ARB}(param)");
189 return;
190 }
191 if (ctx->Point.SpriteRMode == value)
192 return;
193 FLUSH_VERTICES(ctx, _NEW_POINT);
194 ctx->Point.SpriteRMode = value;
195 }
196 else {
197 _mesa_error(ctx, GL_INVALID_ENUM,
198 "glPointParameterf[v]{EXT,ARB}(pname)");
199 return;
200 }
201 break;
202 case GL_POINT_SPRITE_COORD_ORIGIN:
203 if (ctx->Extensions.ARB_point_sprite) {
204 GLenum value = (GLenum) params[0];
205 if (value != GL_LOWER_LEFT && value != GL_UPPER_LEFT) {
206 _mesa_error(ctx, GL_INVALID_VALUE,
207 "glPointParameterf[v]{EXT,ARB}(param)");
208 return;
209 }
210 if (ctx->Point.SpriteOrigin == value)
211 return;
212 FLUSH_VERTICES(ctx, _NEW_POINT);
213 ctx->Point.SpriteOrigin = value;
214 }
215 else {
216 _mesa_error(ctx, GL_INVALID_ENUM,
217 "glPointParameterf[v]{EXT,ARB}(pname)");
218 return;
219 }
220 break;
221 default:
222 _mesa_error( ctx, GL_INVALID_ENUM,
223 "glPointParameterf[v]{EXT,ARB}(pname)" );
224 return;
225 }
226
227 if (ctx->Driver.PointParameterfv)
228 (*ctx->Driver.PointParameterfv)(ctx, pname, params);
229 }
230 #endif
231
232
233
234 /**
235 * Update derived point-related state.
236 */
237 void
238 _mesa_update_point(GLcontext *ctx)
239 {
240 /* clamp to user-specified limits now, clamp to ctx->Const.Min/Max
241 * limits during rasterization.
242 */
243 ctx->Point._Size = CLAMP(ctx->Point.Size,
244 ctx->Point.MinSize,
245 ctx->Point.MaxSize);
246
247 ctx->Point._Attenuated = (ctx->Point.Params[0] != 1.0 ||
248 ctx->Point.Params[1] != 0.0 ||
249 ctx->Point.Params[2] != 0.0);
250 }
251
252
253
254 /**
255 * Initialize the context point state.
256 *
257 * \param ctx GL context.
258 *
259 * Initializes __GLcontextRec::Point and point related constants in
260 * __GLcontextRec::Const.
261 */
262 void
263 _mesa_init_point(GLcontext *ctx)
264 {
265 GLuint i;
266
267 ctx->Point.SmoothFlag = GL_FALSE;
268 ctx->Point.Size = 1.0;
269 ctx->Point._Size = 1.0;
270 ctx->Point.Params[0] = 1.0;
271 ctx->Point.Params[1] = 0.0;
272 ctx->Point.Params[2] = 0.0;
273 ctx->Point._Attenuated = GL_FALSE;
274 ctx->Point.MinSize = 0.0;
275 ctx->Point.MaxSize
276 = MAX2(ctx->Const.MaxPointSize, ctx->Const.MaxPointSizeAA);
277 ctx->Point.Threshold = 1.0;
278 ctx->Point.PointSprite = GL_FALSE; /* GL_ARB/NV_point_sprite */
279 ctx->Point.SpriteRMode = GL_ZERO; /* GL_NV_point_sprite (only!) */
280 ctx->Point.SpriteOrigin = GL_UPPER_LEFT; /* GL_ARB_point_sprite */
281 for (i = 0; i < MAX_TEXTURE_UNITS; i++) {
282 ctx->Point.CoordReplace[i] = GL_FALSE; /* GL_ARB/NV_point_sprite */
283 }
284 }