Trivial changes to add support for GL_ARB_point_sprite, which is a
[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: 5.1
9 *
10 * Copyright (C) 1999-2003 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 the point size.
41 *
42 * \param size pointer diameter.
43 *
44 * \sa glPointSize().
45 *
46 * Verifies the parameter and updates gl_point_attrib::Size. On a change,
47 * flushes the vertices, updates the clamped point size and marks the
48 * DD_POINT_SIZE flag in __GLcontextRec::_TriangleCaps for the drivers if the
49 * size is different from one. Notifies the driver via
50 * the dd_function_table::PointSize callback.
51 */
52 void
53 _mesa_PointSize( GLfloat size )
54 {
55 GET_CURRENT_CONTEXT(ctx);
56 ASSERT_OUTSIDE_BEGIN_END(ctx);
57
58 if (size <= 0.0) {
59 _mesa_error( ctx, GL_INVALID_VALUE, "glPointSize" );
60 return;
61 }
62
63 if (ctx->Point.Size == size)
64 return;
65
66 FLUSH_VERTICES(ctx, _NEW_POINT);
67 ctx->Point.Size = size;
68 ctx->Point._Size = CLAMP(size,
69 ctx->Const.MinPointSize,
70 ctx->Const.MaxPointSize);
71
72 if (ctx->Point._Size == 1.0F)
73 ctx->_TriangleCaps &= ~DD_POINT_SIZE;
74 else
75 ctx->_TriangleCaps |= DD_POINT_SIZE;
76
77 if (ctx->Driver.PointSize)
78 (*ctx->Driver.PointSize)(ctx, size);
79 }
80
81
82 #if _HAVE_FULL_GL
83
84 /*
85 * Added by GL_NV_point_sprite
86 */
87 void
88 _mesa_PointParameteriNV( GLenum pname, GLint param )
89 {
90 const GLfloat value = (GLfloat) param;
91 _mesa_PointParameterfvEXT(pname, &value);
92 }
93
94
95 /*
96 * Added by GL_NV_point_sprite
97 */
98 void
99 _mesa_PointParameterivNV( GLenum pname, const GLint *params )
100 {
101 const GLfloat value = (GLfloat) params[0];
102 _mesa_PointParameterfvEXT(pname, &value);
103 }
104
105
106
107 /*
108 * Same for both GL_EXT_point_parameters and GL_ARB_point_parameters.
109 */
110 void
111 _mesa_PointParameterfEXT( GLenum pname, GLfloat param)
112 {
113 _mesa_PointParameterfvEXT(pname, &param);
114 }
115
116
117
118 /*
119 * Same for both GL_EXT_point_parameters and GL_ARB_point_parameters.
120 */
121 void
122 _mesa_PointParameterfvEXT( GLenum pname, const GLfloat *params)
123 {
124 GET_CURRENT_CONTEXT(ctx);
125 ASSERT_OUTSIDE_BEGIN_END(ctx);
126
127 switch (pname) {
128 case GL_DISTANCE_ATTENUATION_EXT:
129 if (ctx->Extensions.EXT_point_parameters) {
130 const GLboolean tmp = ctx->Point._Attenuated;
131 if (TEST_EQ_3V(ctx->Point.Params, params))
132 return;
133
134 FLUSH_VERTICES(ctx, _NEW_POINT);
135 COPY_3V(ctx->Point.Params, params);
136
137 /* Update several derived values now. This likely to be
138 * more efficient than trying to catch this statechange in
139 * state.c.
140 */
141 ctx->Point._Attenuated = (params[0] != 1.0 ||
142 params[1] != 0.0 ||
143 params[2] != 0.0);
144
145 if (tmp != ctx->Point._Attenuated) {
146 ctx->_TriangleCaps ^= DD_POINT_ATTEN;
147 }
148 }
149 else {
150 _mesa_error(ctx, GL_INVALID_ENUM,
151 "glPointParameterf[v]{EXT,ARB}(pname)");
152 return;
153 }
154 break;
155 case GL_POINT_SIZE_MIN_EXT:
156 if (ctx->Extensions.EXT_point_parameters) {
157 if (params[0] < 0.0F) {
158 _mesa_error( ctx, GL_INVALID_VALUE,
159 "glPointParameterf[v]{EXT,ARB}(param)" );
160 return;
161 }
162 if (ctx->Point.MinSize == params[0])
163 return;
164 FLUSH_VERTICES(ctx, _NEW_POINT);
165 ctx->Point.MinSize = params[0];
166 }
167 else {
168 _mesa_error(ctx, GL_INVALID_ENUM,
169 "glPointParameterf[v]{EXT,ARB}(pname)");
170 return;
171 }
172 break;
173 case GL_POINT_SIZE_MAX_EXT:
174 if (ctx->Extensions.EXT_point_parameters) {
175 if (params[0] < 0.0F) {
176 _mesa_error( ctx, GL_INVALID_VALUE,
177 "glPointParameterf[v]{EXT,ARB}(param)" );
178 return;
179 }
180 if (ctx->Point.MaxSize == params[0])
181 return;
182 FLUSH_VERTICES(ctx, _NEW_POINT);
183 ctx->Point.MaxSize = params[0];
184 }
185 else {
186 _mesa_error(ctx, GL_INVALID_ENUM,
187 "glPointParameterf[v]{EXT,ARB}(pname)");
188 return;
189 }
190 break;
191 case GL_POINT_FADE_THRESHOLD_SIZE_EXT:
192 if (ctx->Extensions.EXT_point_parameters) {
193 if (params[0] < 0.0F) {
194 _mesa_error( ctx, GL_INVALID_VALUE,
195 "glPointParameterf[v]{EXT,ARB}(param)" );
196 return;
197 }
198 if (ctx->Point.Threshold == params[0])
199 return;
200 FLUSH_VERTICES(ctx, _NEW_POINT);
201 ctx->Point.Threshold = params[0];
202 }
203 else {
204 _mesa_error(ctx, GL_INVALID_ENUM,
205 "glPointParameterf[v]{EXT,ARB}(pname)");
206 return;
207 }
208 break;
209 case GL_POINT_SPRITE_R_MODE_NV:
210 /* This is one area where ARB_point_sprite and NV_point_sprite
211 * differ. In ARB_point_sprite the POINT_SPRITE_R_MODE is
212 * always ZERO. NV_point_sprite adds the S and R modes.
213 */
214 if (ctx->Extensions.NV_point_sprite) {
215 GLenum value = (GLenum) params[0];
216 if (value != GL_ZERO && value != GL_S && value != GL_R) {
217 _mesa_error(ctx, GL_INVALID_VALUE,
218 "glPointParameterf[v]{EXT,ARB}(param)");
219 return;
220 }
221 if (ctx->Point.SpriteRMode == value)
222 return;
223 FLUSH_VERTICES(ctx, _NEW_POINT);
224 ctx->Point.SpriteRMode = value;
225 }
226 else {
227 _mesa_error(ctx, GL_INVALID_ENUM,
228 "glPointParameterf[v]{EXT,ARB}(pname)");
229 return;
230 }
231 break;
232 default:
233 _mesa_error( ctx, GL_INVALID_ENUM,
234 "glPointParameterf[v]{EXT,ARB}(pname)" );
235 return;
236 }
237
238 if (ctx->Driver.PointParameterfv)
239 (*ctx->Driver.PointParameterfv)(ctx, pname, params);
240 }
241 #endif
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 _mesa_init_point( GLcontext * ctx )
253 {
254 int i;
255
256 /* Point group */
257 ctx->Point.SmoothFlag = GL_FALSE;
258 ctx->Point.Size = 1.0;
259 ctx->Point._Size = 1.0;
260 ctx->Point.Params[0] = 1.0;
261 ctx->Point.Params[1] = 0.0;
262 ctx->Point.Params[2] = 0.0;
263 ctx->Point._Attenuated = GL_FALSE;
264 ctx->Point.MinSize = 0.0;
265 ctx->Point.MaxSize = ctx->Const.MaxPointSize;
266 ctx->Point.Threshold = 1.0;
267 ctx->Point.PointSprite = GL_FALSE; /* GL_ARB_point_sprite / GL_NV_point_sprite */
268 ctx->Point.SpriteRMode = GL_ZERO; /* GL_NV_point_sprite (only!) */
269 for (i = 0; i < MAX_TEXTURE_UNITS; i++) {
270 ctx->Point.CoordReplace[i] = GL_FALSE; /* GL_ARB_point_sprite / GL_NV_point_sprite */
271 }
272 }