[PROPSYS]
[reactos.git] / reactos / dll / opengl / mesa / main / points.c
1 /**
2 * \file points.c
3 * Point operations.
4 */
5
6 /*
7 * Mesa 3-D graphics library
8 * Version: 7.1
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 #include <precomp.h>
31
32 /**
33 * Set current point size.
34 * \param size point diameter in pixels
35 * \sa glPointSize().
36 */
37 void GLAPIENTRY
38 _mesa_PointSize( GLfloat size )
39 {
40 GET_CURRENT_CONTEXT(ctx);
41 ASSERT_OUTSIDE_BEGIN_END(ctx);
42
43 if (size <= 0.0) {
44 _mesa_error( ctx, GL_INVALID_VALUE, "glPointSize" );
45 return;
46 }
47
48 if (ctx->Point.Size == size)
49 return;
50
51 FLUSH_VERTICES(ctx, _NEW_POINT);
52 ctx->Point.Size = size;
53
54 if (ctx->Driver.PointSize)
55 ctx->Driver.PointSize(ctx, size);
56 }
57
58
59 #if _HAVE_FULL_GL
60
61
62 void GLAPIENTRY
63 _mesa_PointParameteri( GLenum pname, GLint param )
64 {
65 GLfloat p[3];
66 p[0] = (GLfloat) param;
67 p[1] = p[2] = 0.0F;
68 _mesa_PointParameterfv(pname, p);
69 }
70
71
72 void GLAPIENTRY
73 _mesa_PointParameteriv( GLenum pname, const GLint *params )
74 {
75 GLfloat p[3];
76 p[0] = (GLfloat) params[0];
77 if (pname == GL_DISTANCE_ATTENUATION_EXT) {
78 p[1] = (GLfloat) params[1];
79 p[2] = (GLfloat) params[2];
80 }
81 _mesa_PointParameterfv(pname, p);
82 }
83
84
85 void GLAPIENTRY
86 _mesa_PointParameterf( GLenum pname, GLfloat param)
87 {
88 GLfloat p[3];
89 p[0] = param;
90 p[1] = p[2] = 0.0F;
91 _mesa_PointParameterfv(pname, p);
92 }
93
94
95 void GLAPIENTRY
96 _mesa_PointParameterfv( GLenum pname, const GLfloat *params)
97 {
98 GET_CURRENT_CONTEXT(ctx);
99 ASSERT_OUTSIDE_BEGIN_END(ctx);
100
101 switch (pname) {
102 case GL_DISTANCE_ATTENUATION_EXT:
103 if (ctx->Extensions.EXT_point_parameters) {
104 if (TEST_EQ_3V(ctx->Point.Params, params))
105 return;
106 FLUSH_VERTICES(ctx, _NEW_POINT);
107 COPY_3V(ctx->Point.Params, params);
108 ctx->Point._Attenuated = (ctx->Point.Params[0] != 1.0 ||
109 ctx->Point.Params[1] != 0.0 ||
110 ctx->Point.Params[2] != 0.0);
111
112 if (ctx->Point._Attenuated)
113 ctx->_TriangleCaps |= DD_POINT_ATTEN;
114 else
115 ctx->_TriangleCaps &= ~DD_POINT_ATTEN;
116 }
117 else {
118 _mesa_error(ctx, GL_INVALID_ENUM,
119 "glPointParameterf[v]{EXT,ARB}(pname)");
120 return;
121 }
122 break;
123 case GL_POINT_SIZE_MIN_EXT:
124 if (ctx->Extensions.EXT_point_parameters) {
125 if (params[0] < 0.0F) {
126 _mesa_error( ctx, GL_INVALID_VALUE,
127 "glPointParameterf[v]{EXT,ARB}(param)" );
128 return;
129 }
130 if (ctx->Point.MinSize == params[0])
131 return;
132 FLUSH_VERTICES(ctx, _NEW_POINT);
133 ctx->Point.MinSize = params[0];
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_MAX_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.MaxSize == params[0])
149 return;
150 FLUSH_VERTICES(ctx, _NEW_POINT);
151 ctx->Point.MaxSize = 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_FADE_THRESHOLD_SIZE_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.Threshold == params[0])
167 return;
168 FLUSH_VERTICES(ctx, _NEW_POINT);
169 ctx->Point.Threshold = 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_SPRITE_R_MODE_NV:
178 /* This is one area where ARB_point_sprite and NV_point_sprite
179 * differ. In ARB_point_sprite the POINT_SPRITE_R_MODE is
180 * always ZERO. NV_point_sprite adds the S and R modes.
181 */
182 if (ctx->Extensions.NV_point_sprite) {
183 GLenum value = (GLenum) params[0];
184 if (value != GL_ZERO && value != GL_S && value != GL_R) {
185 _mesa_error(ctx, GL_INVALID_VALUE,
186 "glPointParameterf[v]{EXT,ARB}(param)");
187 return;
188 }
189 if (ctx->Point.SpriteRMode == value)
190 return;
191 FLUSH_VERTICES(ctx, _NEW_POINT);
192 ctx->Point.SpriteRMode = value;
193 }
194 else {
195 _mesa_error(ctx, GL_INVALID_ENUM,
196 "glPointParameterf[v]{EXT,ARB}(pname)");
197 return;
198 }
199 break;
200 case GL_POINT_SPRITE_COORD_ORIGIN:
201 /* This is not completely correct. GL_POINT_SPRITE_COORD_ORIGIN was
202 * added to point sprites when the extension was merged into OpenGL
203 * 2.0. It is expected that an implementation supporting OpenGL 1.4
204 * and GL_ARB_point_sprite will generate an error here.
205 */
206 if (ctx->Extensions.ARB_point_sprite) {
207 GLenum value = (GLenum) params[0];
208 if (value != GL_LOWER_LEFT && value != GL_UPPER_LEFT) {
209 _mesa_error(ctx, GL_INVALID_VALUE,
210 "glPointParameterf[v]{EXT,ARB}(param)");
211 return;
212 }
213 if (ctx->Point.SpriteOrigin == value)
214 return;
215 FLUSH_VERTICES(ctx, _NEW_POINT);
216 ctx->Point.SpriteOrigin = value;
217 }
218 else {
219 _mesa_error(ctx, GL_INVALID_ENUM,
220 "glPointParameterf[v]{EXT,ARB}(pname)");
221 return;
222 }
223 break;
224 default:
225 _mesa_error( ctx, GL_INVALID_ENUM,
226 "glPointParameterf[v]{EXT,ARB}(pname)" );
227 return;
228 }
229
230 if (ctx->Driver.PointParameterfv)
231 (*ctx->Driver.PointParameterfv)(ctx, pname, params);
232 }
233 #endif
234
235
236
237 /**
238 * Initialize the context point state.
239 *
240 * \param ctx GL context.
241 *
242 * Initializes __struct gl_contextRec::Point and point related constants in
243 * __struct gl_contextRec::Const.
244 */
245 void
246 _mesa_init_point(struct gl_context *ctx)
247 {
248 ctx->Point.SmoothFlag = GL_FALSE;
249 ctx->Point.Size = 1.0;
250 ctx->Point.Params[0] = 1.0;
251 ctx->Point.Params[1] = 0.0;
252 ctx->Point.Params[2] = 0.0;
253 ctx->Point._Attenuated = GL_FALSE;
254 ctx->Point.MinSize = 0.0;
255 ctx->Point.MaxSize
256 = MAX2(ctx->Const.MaxPointSize, ctx->Const.MaxPointSizeAA);
257 ctx->Point.Threshold = 1.0;
258 ctx->Point.PointSprite = GL_FALSE; /* GL_ARB/NV_point_sprite */
259 ctx->Point.SpriteRMode = GL_ZERO; /* GL_NV_point_sprite (only!) */
260 ctx->Point.SpriteOrigin = GL_UPPER_LEFT; /* GL_ARB_point_sprite */
261 ctx->Point.CoordReplace = GL_FALSE; /* GL_ARB/NV_point_sprite */
262 }