Merge remote branch 'origin/gallium-0.1' into nouveau-gallium-0.1
[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: 7.0
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
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 current point size.
41 * \param size point diameter in pixels
42 * \sa glPointSize().
43 */
44 void GLAPIENTRY
45 _mesa_PointSize( GLfloat size )
46 {
47 GET_CURRENT_CONTEXT(ctx);
48 ASSERT_OUTSIDE_BEGIN_END(ctx);
49
50 if (size <= 0.0) {
51 _mesa_error( ctx, GL_INVALID_VALUE, "glPointSize" );
52 return;
53 }
54
55 if (ctx->Point.Size == size)
56 return;
57
58 FLUSH_VERTICES(ctx, _NEW_POINT);
59 ctx->Point.Size = size;
60
61 if (ctx->Driver.PointSize)
62 ctx->Driver.PointSize(ctx, size);
63 }
64
65
66 #if _HAVE_FULL_GL
67
68
69 void GLAPIENTRY
70 _mesa_PointParameteri( GLenum pname, GLint param )
71 {
72 const GLfloat value = (GLfloat) param;
73 _mesa_PointParameterfv(pname, &value);
74 }
75
76
77 void GLAPIENTRY
78 _mesa_PointParameteriv( GLenum pname, const GLint *params )
79 {
80 const GLfloat value = (GLfloat) params[0];
81 _mesa_PointParameterfv(pname, &value);
82 }
83
84
85 void GLAPIENTRY
86 _mesa_PointParameterf( GLenum pname, GLfloat param)
87 {
88 _mesa_PointParameterfv(pname, &param);
89 }
90
91
92 void GLAPIENTRY
93 _mesa_PointParameterfv( GLenum pname, const GLfloat *params)
94 {
95 GET_CURRENT_CONTEXT(ctx);
96 ASSERT_OUTSIDE_BEGIN_END(ctx);
97
98 switch (pname) {
99 case GL_DISTANCE_ATTENUATION_EXT:
100 if (ctx->Extensions.EXT_point_parameters) {
101 if (TEST_EQ_3V(ctx->Point.Params, params))
102 return;
103 FLUSH_VERTICES(ctx, _NEW_POINT);
104 COPY_3V(ctx->Point.Params, params);
105 ctx->Point._Attenuated = (ctx->Point.Params[0] != 1.0 ||
106 ctx->Point.Params[1] != 0.0 ||
107 ctx->Point.Params[2] != 0.0);
108 }
109 else {
110 _mesa_error(ctx, GL_INVALID_ENUM,
111 "glPointParameterf[v]{EXT,ARB}(pname)");
112 return;
113 }
114 break;
115 case GL_POINT_SIZE_MIN_EXT:
116 if (ctx->Extensions.EXT_point_parameters) {
117 if (params[0] < 0.0F) {
118 _mesa_error( ctx, GL_INVALID_VALUE,
119 "glPointParameterf[v]{EXT,ARB}(param)" );
120 return;
121 }
122 if (ctx->Point.MinSize == params[0])
123 return;
124 FLUSH_VERTICES(ctx, _NEW_POINT);
125 ctx->Point.MinSize = params[0];
126 }
127 else {
128 _mesa_error(ctx, GL_INVALID_ENUM,
129 "glPointParameterf[v]{EXT,ARB}(pname)");
130 return;
131 }
132 break;
133 case GL_POINT_SIZE_MAX_EXT:
134 if (ctx->Extensions.EXT_point_parameters) {
135 if (params[0] < 0.0F) {
136 _mesa_error( ctx, GL_INVALID_VALUE,
137 "glPointParameterf[v]{EXT,ARB}(param)" );
138 return;
139 }
140 if (ctx->Point.MaxSize == params[0])
141 return;
142 FLUSH_VERTICES(ctx, _NEW_POINT);
143 ctx->Point.MaxSize = params[0];
144 }
145 else {
146 _mesa_error(ctx, GL_INVALID_ENUM,
147 "glPointParameterf[v]{EXT,ARB}(pname)");
148 return;
149 }
150 break;
151 case GL_POINT_FADE_THRESHOLD_SIZE_EXT:
152 if (ctx->Extensions.EXT_point_parameters) {
153 if (params[0] < 0.0F) {
154 _mesa_error( ctx, GL_INVALID_VALUE,
155 "glPointParameterf[v]{EXT,ARB}(param)" );
156 return;
157 }
158 if (ctx->Point.Threshold == params[0])
159 return;
160 FLUSH_VERTICES(ctx, _NEW_POINT);
161 ctx->Point.Threshold = params[0];
162 }
163 else {
164 _mesa_error(ctx, GL_INVALID_ENUM,
165 "glPointParameterf[v]{EXT,ARB}(pname)");
166 return;
167 }
168 break;
169 case GL_POINT_SPRITE_R_MODE_NV:
170 /* This is one area where ARB_point_sprite and NV_point_sprite
171 * differ. In ARB_point_sprite the POINT_SPRITE_R_MODE is
172 * always ZERO. NV_point_sprite adds the S and R modes.
173 */
174 if (ctx->Extensions.NV_point_sprite) {
175 GLenum value = (GLenum) params[0];
176 if (value != GL_ZERO && value != GL_S && value != GL_R) {
177 _mesa_error(ctx, GL_INVALID_VALUE,
178 "glPointParameterf[v]{EXT,ARB}(param)");
179 return;
180 }
181 if (ctx->Point.SpriteRMode == value)
182 return;
183 FLUSH_VERTICES(ctx, _NEW_POINT);
184 ctx->Point.SpriteRMode = value;
185 }
186 else {
187 _mesa_error(ctx, GL_INVALID_ENUM,
188 "glPointParameterf[v]{EXT,ARB}(pname)");
189 return;
190 }
191 break;
192 case GL_POINT_SPRITE_COORD_ORIGIN:
193 if (ctx->Extensions.ARB_point_sprite) {
194 GLenum value = (GLenum) params[0];
195 if (value != GL_LOWER_LEFT && value != GL_UPPER_LEFT) {
196 _mesa_error(ctx, GL_INVALID_VALUE,
197 "glPointParameterf[v]{EXT,ARB}(param)");
198 return;
199 }
200 if (ctx->Point.SpriteOrigin == value)
201 return;
202 FLUSH_VERTICES(ctx, _NEW_POINT);
203 ctx->Point.SpriteOrigin = value;
204 }
205 else {
206 _mesa_error(ctx, GL_INVALID_ENUM,
207 "glPointParameterf[v]{EXT,ARB}(pname)");
208 return;
209 }
210 break;
211 default:
212 _mesa_error( ctx, GL_INVALID_ENUM,
213 "glPointParameterf[v]{EXT,ARB}(pname)" );
214 return;
215 }
216
217 if (ctx->Driver.PointParameterfv)
218 (*ctx->Driver.PointParameterfv)(ctx, pname, params);
219 }
220 #endif
221
222
223
224 /**
225 * Initialize the context point state.
226 *
227 * \param ctx GL context.
228 *
229 * Initializes __GLcontextRec::Point and point related constants in
230 * __GLcontextRec::Const.
231 */
232 void
233 _mesa_init_point(GLcontext *ctx)
234 {
235 GLuint i;
236
237 ctx->Point.SmoothFlag = GL_FALSE;
238 ctx->Point.Size = 1.0;
239 ctx->Point.Params[0] = 1.0;
240 ctx->Point.Params[1] = 0.0;
241 ctx->Point.Params[2] = 0.0;
242 ctx->Point._Attenuated = GL_FALSE;
243 ctx->Point.MinSize = 0.0;
244 ctx->Point.MaxSize
245 = MAX2(ctx->Const.MaxPointSize, ctx->Const.MaxPointSizeAA);
246 ctx->Point.Threshold = 1.0;
247 #if FEATURE_es2_glsl
248 ctx->Point.PointSprite = GL_TRUE; /* GL_ARB/NV_point_sprite */
249 #else
250 ctx->Point.PointSprite = GL_FALSE; /* GL_ARB/NV_point_sprite */
251 #endif
252 ctx->Point.SpriteRMode = GL_ZERO; /* GL_NV_point_sprite (only!) */
253 ctx->Point.SpriteOrigin = GL_UPPER_LEFT; /* GL_ARB_point_sprite */
254 for (i = 0; i < MAX_TEXTURE_UNITS; i++) {
255 ctx->Point.CoordReplace[i] = GL_FALSE; /* GL_ARB/NV_point_sprite */
256 }
257 }