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