cf9922479d5592c9f07ee8c9fafdee0fad5e5748
[mesa.git] / src / mesa / main / points.c
1 /* $Id: points.c,v 1.33 2002/05/27 17:04:53 brianp Exp $ */
2
3 /*
4 * Mesa 3-D graphics library
5 * Version: 4.1
6 *
7 * Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
8 *
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 */
26
27
28 #ifdef PC_HEADER
29 #include "all.h"
30 #else
31 #include "glheader.h"
32 #include "context.h"
33 #include "macros.h"
34 #include "mmath.h"
35 #include "points.h"
36 #include "texstate.h"
37 #include "mtypes.h"
38 #endif
39
40
41
42 void
43 _mesa_PointSize( GLfloat size )
44 {
45 GET_CURRENT_CONTEXT(ctx);
46 ASSERT_OUTSIDE_BEGIN_END(ctx);
47
48 if (size <= 0.0) {
49 _mesa_error( ctx, GL_INVALID_VALUE, "glPointSize" );
50 return;
51 }
52
53 if (ctx->Point.Size == size)
54 return;
55
56 FLUSH_VERTICES(ctx, _NEW_POINT);
57 ctx->Point.Size = size;
58 ctx->Point._Size = CLAMP(size,
59 ctx->Const.MinPointSize,
60 ctx->Const.MaxPointSize);
61
62 if (ctx->Point._Size == 1.0F)
63 ctx->_TriangleCaps &= ~DD_POINT_SIZE;
64 else
65 ctx->_TriangleCaps |= DD_POINT_SIZE;
66
67 if (ctx->Driver.PointSize)
68 (*ctx->Driver.PointSize)(ctx, size);
69 }
70
71
72
73 /*
74 * Added by GL_NV_point_sprite
75 */
76 void
77 _mesa_PointParameteriNV( GLenum pname, GLint param )
78 {
79 const GLfloat value = (GLfloat) param;
80 _mesa_PointParameterfvEXT(pname, &value);
81 }
82
83
84 /*
85 * Added by GL_NV_point_sprite
86 */
87 void
88 _mesa_PointParameterivNV( GLenum pname, const GLint *params )
89 {
90 const GLfloat value = (GLfloat) params[0];
91 _mesa_PointParameterfvEXT(pname, &value);
92 }
93
94
95
96 /*
97 * Same for both GL_EXT_point_parameters and GL_ARB_point_parameters.
98 */
99 void
100 _mesa_PointParameterfEXT( GLenum pname, GLfloat param)
101 {
102 _mesa_PointParameterfvEXT(pname, &param);
103 }
104
105
106
107 /*
108 * Same for both GL_EXT_point_parameters and GL_ARB_point_parameters.
109 */
110 void
111 _mesa_PointParameterfvEXT( GLenum pname, const GLfloat *params)
112 {
113 GET_CURRENT_CONTEXT(ctx);
114 ASSERT_OUTSIDE_BEGIN_END(ctx);
115
116 switch (pname) {
117 case GL_DISTANCE_ATTENUATION_EXT:
118 if (ctx->Extensions.EXT_point_parameters) {
119 const GLboolean tmp = ctx->Point._Attenuated;
120 if (TEST_EQ_3V(ctx->Point.Params, params))
121 return;
122
123 FLUSH_VERTICES(ctx, _NEW_POINT);
124 COPY_3V(ctx->Point.Params, params);
125
126 /* Update several derived values now. This likely to be
127 * more efficient than trying to catch this statechange in
128 * state.c.
129 */
130 ctx->Point._Attenuated = (params[0] != 1.0 ||
131 params[1] != 0.0 ||
132 params[2] != 0.0);
133
134 if (tmp != ctx->Point._Attenuated) {
135 ctx->_TriangleCaps ^= DD_POINT_ATTEN;
136 ctx->_NeedEyeCoords ^= NEED_EYE_POINT_ATTEN;
137 }
138 }
139 else {
140 _mesa_error(ctx, GL_INVALID_ENUM,
141 "glPointParameterf[v]{EXT,ARB}(pname)");
142 return;
143 }
144 break;
145 case GL_POINT_SIZE_MIN_EXT:
146 if (ctx->Extensions.EXT_point_parameters) {
147 if (params[0] < 0.0F) {
148 _mesa_error( ctx, GL_INVALID_VALUE,
149 "glPointParameterf[v]{EXT,ARB}(param)" );
150 return;
151 }
152 if (ctx->Point.MinSize == params[0])
153 return;
154 FLUSH_VERTICES(ctx, _NEW_POINT);
155 ctx->Point.MinSize = params[0];
156 }
157 else {
158 _mesa_error(ctx, GL_INVALID_ENUM,
159 "glPointParameterf[v]{EXT,ARB}(pname)");
160 return;
161 }
162 break;
163 case GL_POINT_SIZE_MAX_EXT:
164 if (ctx->Extensions.EXT_point_parameters) {
165 if (params[0] < 0.0F) {
166 _mesa_error( ctx, GL_INVALID_VALUE,
167 "glPointParameterf[v]{EXT,ARB}(param)" );
168 return;
169 }
170 if (ctx->Point.MaxSize == params[0])
171 return;
172 FLUSH_VERTICES(ctx, _NEW_POINT);
173 ctx->Point.MaxSize = params[0];
174 }
175 else {
176 _mesa_error(ctx, GL_INVALID_ENUM,
177 "glPointParameterf[v]{EXT,ARB}(pname)");
178 return;
179 }
180 break;
181 case GL_POINT_FADE_THRESHOLD_SIZE_EXT:
182 if (ctx->Extensions.EXT_point_parameters) {
183 if (params[0] < 0.0F) {
184 _mesa_error( ctx, GL_INVALID_VALUE,
185 "glPointParameterf[v]{EXT,ARB}(param)" );
186 return;
187 }
188 if (ctx->Point.Threshold == params[0])
189 return;
190 FLUSH_VERTICES(ctx, _NEW_POINT);
191 ctx->Point.Threshold = params[0];
192 }
193 else {
194 _mesa_error(ctx, GL_INVALID_ENUM,
195 "glPointParameterf[v]{EXT,ARB}(pname)");
196 return;
197 }
198 break;
199 case GL_POINT_SPRITE_R_MODE_NV:
200 if (ctx->Extensions.NV_point_sprite) {
201 GLenum value = (GLenum) params[0];
202 if (value != GL_ZERO && value != GL_S && value != GL_R) {
203 _mesa_error(ctx, GL_INVALID_VALUE,
204 "glPointParameterf[v]{EXT,ARB}(param)");
205 return;
206 }
207 if (ctx->Point.SpriteRMode == value)
208 return;
209 FLUSH_VERTICES(ctx, _NEW_POINT);
210 ctx->Point.SpriteRMode = value;
211 }
212 else {
213 _mesa_error(ctx, GL_INVALID_ENUM,
214 "glPointParameterf[v]{EXT,ARB}(pname)");
215 return;
216 }
217 break;
218 default:
219 _mesa_error( ctx, GL_INVALID_ENUM,
220 "glPointParameterf[v]{EXT,ARB}(pname)" );
221 return;
222 }
223
224 if (ctx->Driver.PointParameterfv)
225 (*ctx->Driver.PointParameterfv)(ctx, pname, params);
226 }