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
43 static ALWAYS_INLINE
void
44 point_size(struct gl_context
*ctx
, GLfloat size
, bool no_error
)
46 if (ctx
->Point
.Size
== size
)
49 if (!no_error
&& size
<= 0.0F
) {
50 _mesa_error(ctx
, GL_INVALID_VALUE
, "glPointSize");
54 FLUSH_VERTICES(ctx
, _NEW_POINT
);
55 ctx
->Point
.Size
= size
;
57 if (ctx
->Driver
.PointSize
)
58 ctx
->Driver
.PointSize(ctx
, size
);
63 _mesa_PointSize_no_error(GLfloat size
)
65 GET_CURRENT_CONTEXT(ctx
);
66 point_size(ctx
, size
, true);
71 _mesa_PointSize( GLfloat size
)
73 GET_CURRENT_CONTEXT(ctx
);
74 point_size(ctx
, size
, false);
79 _mesa_PointParameteri( GLenum pname
, GLint param
)
82 p
[0] = (GLfloat
) param
;
84 _mesa_PointParameterfv(pname
, p
);
89 _mesa_PointParameteriv( GLenum pname
, const GLint
*params
)
92 p
[0] = (GLfloat
) params
[0];
93 if (pname
== GL_DISTANCE_ATTENUATION_EXT
) {
94 p
[1] = (GLfloat
) params
[1];
95 p
[2] = (GLfloat
) params
[2];
97 _mesa_PointParameterfv(pname
, p
);
102 _mesa_PointParameterf( GLenum pname
, GLfloat param
)
107 _mesa_PointParameterfv(pname
, p
);
112 _mesa_PointParameterfv( GLenum pname
, const GLfloat
*params
)
114 GET_CURRENT_CONTEXT(ctx
);
116 /* Drivers that support point sprites must also support point parameters.
117 * If point parameters aren't supported, then this function shouldn't even
120 assert(!(ctx
->Extensions
.ARB_point_sprite
121 || ctx
->Extensions
.NV_point_sprite
)
122 || ctx
->Extensions
.EXT_point_parameters
);
124 if (!ctx
->Extensions
.EXT_point_parameters
) {
125 _mesa_error(ctx
, GL_INVALID_OPERATION
,
126 "unsupported function called (unsupported extension)");
131 case GL_DISTANCE_ATTENUATION_EXT
:
132 if (TEST_EQ_3V(ctx
->Point
.Params
, params
))
134 FLUSH_VERTICES(ctx
, _NEW_POINT
);
135 COPY_3V(ctx
->Point
.Params
, params
);
136 ctx
->Point
._Attenuated
= (ctx
->Point
.Params
[0] != 1.0F
||
137 ctx
->Point
.Params
[1] != 0.0F
||
138 ctx
->Point
.Params
[2] != 0.0F
);
140 case GL_POINT_SIZE_MIN_EXT
:
141 if (params
[0] < 0.0F
) {
142 _mesa_error( ctx
, GL_INVALID_VALUE
,
143 "glPointParameterf[v]{EXT,ARB}(param)" );
146 if (ctx
->Point
.MinSize
== params
[0])
148 FLUSH_VERTICES(ctx
, _NEW_POINT
);
149 ctx
->Point
.MinSize
= params
[0];
151 case GL_POINT_SIZE_MAX_EXT
:
152 if (params
[0] < 0.0F
) {
153 _mesa_error( ctx
, GL_INVALID_VALUE
,
154 "glPointParameterf[v]{EXT,ARB}(param)" );
157 if (ctx
->Point
.MaxSize
== params
[0])
159 FLUSH_VERTICES(ctx
, _NEW_POINT
);
160 ctx
->Point
.MaxSize
= params
[0];
162 case GL_POINT_FADE_THRESHOLD_SIZE_EXT
:
163 if (params
[0] < 0.0F
) {
164 _mesa_error( ctx
, GL_INVALID_VALUE
,
165 "glPointParameterf[v]{EXT,ARB}(param)" );
168 if (ctx
->Point
.Threshold
== params
[0])
170 FLUSH_VERTICES(ctx
, _NEW_POINT
);
171 ctx
->Point
.Threshold
= params
[0];
173 case GL_POINT_SPRITE_R_MODE_NV
:
174 /* This is one area where ARB_point_sprite and NV_point_sprite
175 * differ. In ARB_point_sprite the POINT_SPRITE_R_MODE is
176 * always ZERO. NV_point_sprite adds the S and R modes.
178 if (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.NV_point_sprite
) {
179 GLenum value
= (GLenum
) params
[0];
180 if (value
!= GL_ZERO
&& value
!= GL_S
&& value
!= GL_R
) {
181 _mesa_error(ctx
, GL_INVALID_VALUE
,
182 "glPointParameterf[v]{EXT,ARB}(param)");
185 if (ctx
->Point
.SpriteRMode
== value
)
187 FLUSH_VERTICES(ctx
, _NEW_POINT
);
188 ctx
->Point
.SpriteRMode
= value
;
191 _mesa_error(ctx
, GL_INVALID_ENUM
,
192 "glPointParameterf[v]{EXT,ARB}(pname)");
196 case GL_POINT_SPRITE_COORD_ORIGIN
:
197 /* GL_POINT_SPRITE_COORD_ORIGIN was added to point sprites when the
198 * extension was merged into OpenGL 2.0.
200 if ((ctx
->API
== API_OPENGL_COMPAT
&& ctx
->Version
>= 20)
201 || ctx
->API
== API_OPENGL_CORE
) {
202 GLenum value
= (GLenum
) params
[0];
203 if (value
!= GL_LOWER_LEFT
&& value
!= GL_UPPER_LEFT
) {
204 _mesa_error(ctx
, GL_INVALID_VALUE
,
205 "glPointParameterf[v]{EXT,ARB}(param)");
208 if (ctx
->Point
.SpriteOrigin
== value
)
210 FLUSH_VERTICES(ctx
, _NEW_POINT
);
211 ctx
->Point
.SpriteOrigin
= value
;
214 _mesa_error(ctx
, GL_INVALID_ENUM
,
215 "glPointParameterf[v]{EXT,ARB}(pname)");
220 _mesa_error( ctx
, GL_INVALID_ENUM
,
221 "glPointParameterf[v]{EXT,ARB}(pname)" );
225 if (ctx
->Driver
.PointParameterfv
)
226 ctx
->Driver
.PointParameterfv(ctx
, pname
, params
);
232 * Initialize the context point state.
234 * \param ctx GL context.
236 * Initializes __struct gl_contextRec::Point and point related constants in
237 * __struct gl_contextRec::Const.
240 _mesa_init_point(struct gl_context
*ctx
)
242 ctx
->Point
.SmoothFlag
= GL_FALSE
;
243 ctx
->Point
.Size
= 1.0;
244 ctx
->Point
.Params
[0] = 1.0;
245 ctx
->Point
.Params
[1] = 0.0;
246 ctx
->Point
.Params
[2] = 0.0;
247 ctx
->Point
._Attenuated
= GL_FALSE
;
248 ctx
->Point
.MinSize
= 0.0;
250 = MAX2(ctx
->Const
.MaxPointSize
, ctx
->Const
.MaxPointSizeAA
);
251 ctx
->Point
.Threshold
= 1.0;
253 /* Page 403 (page 423 of the PDF) of the OpenGL 3.0 spec says:
255 * "Non-sprite points (section 3.4) - Enable/Disable targets
256 * POINT_SMOOTH and POINT_SPRITE, and all associated state. Point
257 * rasterization is always performed as though POINT_SPRITE were
260 * In a core context, the state will default to true, and the setters and
261 * getters are disabled.
263 ctx
->Point
.PointSprite
= (ctx
->API
== API_OPENGL_CORE
||
264 ctx
->API
== API_OPENGLES2
);
266 ctx
->Point
.SpriteRMode
= GL_ZERO
; /* GL_NV_point_sprite (only!) */
267 ctx
->Point
.SpriteOrigin
= GL_UPPER_LEFT
; /* GL_ARB_point_sprite */
268 ctx
->Point
.CoordReplace
= 0; /* GL_ARB/NV_point_sprite */