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