7 * Mesa 3-D graphics library
9 * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
11 * Permission is hereby granted, free of charge, to any person obtaining a
12 * copy of this software and associated documentation files (the "Software"),
13 * to deal in the Software without restriction, including without limitation
14 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15 * and/or sell copies of the Software, and to permit persons to whom the
16 * Software is furnished to do so, subject to the following conditions:
18 * The above copyright notice and this permission notice shall be included
19 * in all copies or substantial portions of the Software.
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
25 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
26 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27 * OTHER DEALINGS IN THE SOFTWARE.
39 * Set current point size.
40 * \param size point diameter in pixels
44 point_size(struct gl_context
*ctx
, GLfloat size
)
46 if (ctx
->Point
.Size
== size
)
49 FLUSH_VERTICES(ctx
, _NEW_POINT
);
50 ctx
->Point
.Size
= size
;
52 if (ctx
->Driver
.PointSize
)
53 ctx
->Driver
.PointSize(ctx
, size
);
58 _mesa_PointSize_no_error(GLfloat size
)
60 GET_CURRENT_CONTEXT(ctx
);
61 point_size(ctx
, size
);
66 _mesa_PointSize( GLfloat size
)
68 GET_CURRENT_CONTEXT(ctx
);
71 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPointSize" );
75 point_size(ctx
, size
);
80 _mesa_PointParameteri( GLenum pname
, GLint param
)
83 p
[0] = (GLfloat
) param
;
85 _mesa_PointParameterfv(pname
, p
);
90 _mesa_PointParameteriv( GLenum pname
, const GLint
*params
)
93 p
[0] = (GLfloat
) params
[0];
94 if (pname
== GL_DISTANCE_ATTENUATION_EXT
) {
95 p
[1] = (GLfloat
) params
[1];
96 p
[2] = (GLfloat
) params
[2];
98 _mesa_PointParameterfv(pname
, p
);
103 _mesa_PointParameterf( GLenum pname
, GLfloat param
)
108 _mesa_PointParameterfv(pname
, p
);
113 _mesa_PointParameterfv( GLenum pname
, const GLfloat
*params
)
115 GET_CURRENT_CONTEXT(ctx
);
117 /* Drivers that support point sprites must also support point parameters.
118 * If point parameters aren't supported, then this function shouldn't even
121 assert(!(ctx
->Extensions
.ARB_point_sprite
122 || ctx
->Extensions
.NV_point_sprite
)
123 || ctx
->Extensions
.EXT_point_parameters
);
125 if (!ctx
->Extensions
.EXT_point_parameters
) {
126 _mesa_error(ctx
, GL_INVALID_OPERATION
,
127 "unsupported function called (unsupported extension)");
132 case GL_DISTANCE_ATTENUATION_EXT
:
133 if (TEST_EQ_3V(ctx
->Point
.Params
, params
))
135 FLUSH_VERTICES(ctx
, _NEW_POINT
);
136 COPY_3V(ctx
->Point
.Params
, params
);
137 ctx
->Point
._Attenuated
= (ctx
->Point
.Params
[0] != 1.0F
||
138 ctx
->Point
.Params
[1] != 0.0F
||
139 ctx
->Point
.Params
[2] != 0.0F
);
141 case GL_POINT_SIZE_MIN_EXT
:
142 if (params
[0] < 0.0F
) {
143 _mesa_error( ctx
, GL_INVALID_VALUE
,
144 "glPointParameterf[v]{EXT,ARB}(param)" );
147 if (ctx
->Point
.MinSize
== params
[0])
149 FLUSH_VERTICES(ctx
, _NEW_POINT
);
150 ctx
->Point
.MinSize
= params
[0];
152 case GL_POINT_SIZE_MAX_EXT
:
153 if (params
[0] < 0.0F
) {
154 _mesa_error( ctx
, GL_INVALID_VALUE
,
155 "glPointParameterf[v]{EXT,ARB}(param)" );
158 if (ctx
->Point
.MaxSize
== params
[0])
160 FLUSH_VERTICES(ctx
, _NEW_POINT
);
161 ctx
->Point
.MaxSize
= params
[0];
163 case GL_POINT_FADE_THRESHOLD_SIZE_EXT
:
164 if (params
[0] < 0.0F
) {
165 _mesa_error( ctx
, GL_INVALID_VALUE
,
166 "glPointParameterf[v]{EXT,ARB}(param)" );
169 if (ctx
->Point
.Threshold
== params
[0])
171 FLUSH_VERTICES(ctx
, _NEW_POINT
);
172 ctx
->Point
.Threshold
= params
[0];
174 case GL_POINT_SPRITE_R_MODE_NV
:
175 /* This is one area where ARB_point_sprite and NV_point_sprite
176 * differ. In ARB_point_sprite the POINT_SPRITE_R_MODE is
177 * always ZERO. NV_point_sprite adds the S and R modes.
179 if (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.NV_point_sprite
) {
180 GLenum value
= (GLenum
) params
[0];
181 if (value
!= GL_ZERO
&& value
!= GL_S
&& value
!= GL_R
) {
182 _mesa_error(ctx
, GL_INVALID_VALUE
,
183 "glPointParameterf[v]{EXT,ARB}(param)");
186 if (ctx
->Point
.SpriteRMode
== value
)
188 FLUSH_VERTICES(ctx
, _NEW_POINT
);
189 ctx
->Point
.SpriteRMode
= value
;
192 _mesa_error(ctx
, GL_INVALID_ENUM
,
193 "glPointParameterf[v]{EXT,ARB}(pname)");
197 case GL_POINT_SPRITE_COORD_ORIGIN
:
198 /* GL_POINT_SPRITE_COORD_ORIGIN was added to point sprites when the
199 * extension was merged into OpenGL 2.0.
201 if ((ctx
->API
== API_OPENGL_COMPAT
&& ctx
->Version
>= 20)
202 || ctx
->API
== API_OPENGL_CORE
) {
203 GLenum value
= (GLenum
) params
[0];
204 if (value
!= GL_LOWER_LEFT
&& value
!= GL_UPPER_LEFT
) {
205 _mesa_error(ctx
, GL_INVALID_VALUE
,
206 "glPointParameterf[v]{EXT,ARB}(param)");
209 if (ctx
->Point
.SpriteOrigin
== value
)
211 FLUSH_VERTICES(ctx
, _NEW_POINT
);
212 ctx
->Point
.SpriteOrigin
= value
;
215 _mesa_error(ctx
, GL_INVALID_ENUM
,
216 "glPointParameterf[v]{EXT,ARB}(pname)");
221 _mesa_error( ctx
, GL_INVALID_ENUM
,
222 "glPointParameterf[v]{EXT,ARB}(pname)" );
226 if (ctx
->Driver
.PointParameterfv
)
227 ctx
->Driver
.PointParameterfv(ctx
, pname
, params
);
233 * Initialize the context point state.
235 * \param ctx GL context.
237 * Initializes __struct gl_contextRec::Point and point related constants in
238 * __struct gl_contextRec::Const.
241 _mesa_init_point(struct gl_context
*ctx
)
243 ctx
->Point
.SmoothFlag
= GL_FALSE
;
244 ctx
->Point
.Size
= 1.0;
245 ctx
->Point
.Params
[0] = 1.0;
246 ctx
->Point
.Params
[1] = 0.0;
247 ctx
->Point
.Params
[2] = 0.0;
248 ctx
->Point
._Attenuated
= GL_FALSE
;
249 ctx
->Point
.MinSize
= 0.0;
251 = MAX2(ctx
->Const
.MaxPointSize
, ctx
->Const
.MaxPointSizeAA
);
252 ctx
->Point
.Threshold
= 1.0;
254 /* Page 403 (page 423 of the PDF) of the OpenGL 3.0 spec says:
256 * "Non-sprite points (section 3.4) - Enable/Disable targets
257 * POINT_SMOOTH and POINT_SPRITE, and all associated state. Point
258 * rasterization is always performed as though POINT_SPRITE were
261 * In a core context, the state will default to true, and the setters and
262 * getters are disabled.
264 ctx
->Point
.PointSprite
= (ctx
->API
== API_OPENGL_CORE
||
265 ctx
->API
== API_OPENGLES2
);
267 ctx
->Point
.SpriteRMode
= GL_ZERO
; /* GL_NV_point_sprite (only!) */
268 ctx
->Point
.SpriteOrigin
= GL_UPPER_LEFT
; /* GL_ARB_point_sprite */
269 ctx
->Point
.CoordReplace
= 0; /* GL_ARB/NV_point_sprite */