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