Header file clean-up:
[mesa.git] / src / mesa / main / points.c
1 /* $Id: points.c,v 1.34 2002/10/24 23:57:21 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 #include "glheader.h"
29 #include "context.h"
30 #include "macros.h"
31 #include "mmath.h"
32 #include "points.h"
33 #include "texstate.h"
34 #include "mtypes.h"
35
36
37
38 void
39 _mesa_PointSize( GLfloat size )
40 {
41 GET_CURRENT_CONTEXT(ctx);
42 ASSERT_OUTSIDE_BEGIN_END(ctx);
43
44 if (size <= 0.0) {
45 _mesa_error( ctx, GL_INVALID_VALUE, "glPointSize" );
46 return;
47 }
48
49 if (ctx->Point.Size == size)
50 return;
51
52 FLUSH_VERTICES(ctx, _NEW_POINT);
53 ctx->Point.Size = size;
54 ctx->Point._Size = CLAMP(size,
55 ctx->Const.MinPointSize,
56 ctx->Const.MaxPointSize);
57
58 if (ctx->Point._Size == 1.0F)
59 ctx->_TriangleCaps &= ~DD_POINT_SIZE;
60 else
61 ctx->_TriangleCaps |= DD_POINT_SIZE;
62
63 if (ctx->Driver.PointSize)
64 (*ctx->Driver.PointSize)(ctx, size);
65 }
66
67
68
69 /*
70 * Added by GL_NV_point_sprite
71 */
72 void
73 _mesa_PointParameteriNV( GLenum pname, GLint param )
74 {
75 const GLfloat value = (GLfloat) param;
76 _mesa_PointParameterfvEXT(pname, &value);
77 }
78
79
80 /*
81 * Added by GL_NV_point_sprite
82 */
83 void
84 _mesa_PointParameterivNV( GLenum pname, const GLint *params )
85 {
86 const GLfloat value = (GLfloat) params[0];
87 _mesa_PointParameterfvEXT(pname, &value);
88 }
89
90
91
92 /*
93 * Same for both GL_EXT_point_parameters and GL_ARB_point_parameters.
94 */
95 void
96 _mesa_PointParameterfEXT( GLenum pname, GLfloat param)
97 {
98 _mesa_PointParameterfvEXT(pname, &param);
99 }
100
101
102
103 /*
104 * Same for both GL_EXT_point_parameters and GL_ARB_point_parameters.
105 */
106 void
107 _mesa_PointParameterfvEXT( GLenum pname, const GLfloat *params)
108 {
109 GET_CURRENT_CONTEXT(ctx);
110 ASSERT_OUTSIDE_BEGIN_END(ctx);
111
112 switch (pname) {
113 case GL_DISTANCE_ATTENUATION_EXT:
114 if (ctx->Extensions.EXT_point_parameters) {
115 const GLboolean tmp = ctx->Point._Attenuated;
116 if (TEST_EQ_3V(ctx->Point.Params, params))
117 return;
118
119 FLUSH_VERTICES(ctx, _NEW_POINT);
120 COPY_3V(ctx->Point.Params, params);
121
122 /* Update several derived values now. This likely to be
123 * more efficient than trying to catch this statechange in
124 * state.c.
125 */
126 ctx->Point._Attenuated = (params[0] != 1.0 ||
127 params[1] != 0.0 ||
128 params[2] != 0.0);
129
130 if (tmp != ctx->Point._Attenuated) {
131 ctx->_TriangleCaps ^= DD_POINT_ATTEN;
132 ctx->_NeedEyeCoords ^= NEED_EYE_POINT_ATTEN;
133 }
134 }
135 else {
136 _mesa_error(ctx, GL_INVALID_ENUM,
137 "glPointParameterf[v]{EXT,ARB}(pname)");
138 return;
139 }
140 break;
141 case GL_POINT_SIZE_MIN_EXT:
142 if (ctx->Extensions.EXT_point_parameters) {
143 if (params[0] < 0.0F) {
144 _mesa_error( ctx, GL_INVALID_VALUE,
145 "glPointParameterf[v]{EXT,ARB}(param)" );
146 return;
147 }
148 if (ctx->Point.MinSize == params[0])
149 return;
150 FLUSH_VERTICES(ctx, _NEW_POINT);
151 ctx->Point.MinSize = params[0];
152 }
153 else {
154 _mesa_error(ctx, GL_INVALID_ENUM,
155 "glPointParameterf[v]{EXT,ARB}(pname)");
156 return;
157 }
158 break;
159 case GL_POINT_SIZE_MAX_EXT:
160 if (ctx->Extensions.EXT_point_parameters) {
161 if (params[0] < 0.0F) {
162 _mesa_error( ctx, GL_INVALID_VALUE,
163 "glPointParameterf[v]{EXT,ARB}(param)" );
164 return;
165 }
166 if (ctx->Point.MaxSize == params[0])
167 return;
168 FLUSH_VERTICES(ctx, _NEW_POINT);
169 ctx->Point.MaxSize = params[0];
170 }
171 else {
172 _mesa_error(ctx, GL_INVALID_ENUM,
173 "glPointParameterf[v]{EXT,ARB}(pname)");
174 return;
175 }
176 break;
177 case GL_POINT_FADE_THRESHOLD_SIZE_EXT:
178 if (ctx->Extensions.EXT_point_parameters) {
179 if (params[0] < 0.0F) {
180 _mesa_error( ctx, GL_INVALID_VALUE,
181 "glPointParameterf[v]{EXT,ARB}(param)" );
182 return;
183 }
184 if (ctx->Point.Threshold == params[0])
185 return;
186 FLUSH_VERTICES(ctx, _NEW_POINT);
187 ctx->Point.Threshold = params[0];
188 }
189 else {
190 _mesa_error(ctx, GL_INVALID_ENUM,
191 "glPointParameterf[v]{EXT,ARB}(pname)");
192 return;
193 }
194 break;
195 case GL_POINT_SPRITE_R_MODE_NV:
196 if (ctx->Extensions.NV_point_sprite) {
197 GLenum value = (GLenum) params[0];
198 if (value != GL_ZERO && value != GL_S && value != GL_R) {
199 _mesa_error(ctx, GL_INVALID_VALUE,
200 "glPointParameterf[v]{EXT,ARB}(param)");
201 return;
202 }
203 if (ctx->Point.SpriteRMode == value)
204 return;
205 FLUSH_VERTICES(ctx, _NEW_POINT);
206 ctx->Point.SpriteRMode = value;
207 }
208 else {
209 _mesa_error(ctx, GL_INVALID_ENUM,
210 "glPointParameterf[v]{EXT,ARB}(pname)");
211 return;
212 }
213 break;
214 default:
215 _mesa_error( ctx, GL_INVALID_ENUM,
216 "glPointParameterf[v]{EXT,ARB}(pname)" );
217 return;
218 }
219
220 if (ctx->Driver.PointParameterfv)
221 (*ctx->Driver.PointParameterfv)(ctx, pname, params);
222 }