Added PointSize and PointParametersfv to dd interface, for completeness.
[mesa.git] / src / mesa / main / points.c
1 /* $Id: points.c,v 1.27 2001/01/09 00:02:55 brianp Exp $ */
2
3 /*
4 * Mesa 3-D graphics library
5 * Version: 3.4
6 *
7 * Copyright (C) 1999-2000 Brian Paul All Rights Reserved.
8 *
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 */
26
27
28 #ifdef PC_HEADER
29 #include "all.h"
30 #else
31 #include "glheader.h"
32 #include "context.h"
33 #include "feedback.h"
34 #include "macros.h"
35 #include "mmath.h"
36 #include "points.h"
37 #include "texstate.h"
38 #include "mtypes.h"
39 #endif
40
41
42
43 void
44 _mesa_PointSize( GLfloat size )
45 {
46 GET_CURRENT_CONTEXT(ctx);
47 ASSERT_OUTSIDE_BEGIN_END(ctx);
48
49 if (size <= 0.0) {
50 gl_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 ctx->Point._Size = CLAMP(size,
60 ctx->Const.MinPointSize,
61 ctx->Const.MaxPointSize);
62
63 if (ctx->Point._Size == 1.0F)
64 ctx->_TriangleCaps &= ~DD_POINT_SIZE;
65 else
66 ctx->_TriangleCaps |= DD_POINT_SIZE;
67
68 if (ctx->Driver.PointSize)
69 (*ctx->Driver.PointSize)(ctx, size);
70 }
71
72
73
74 void
75 _mesa_PointParameterfEXT( GLenum pname, GLfloat param)
76 {
77 _mesa_PointParameterfvEXT(pname, &param);
78 }
79
80
81 void
82 _mesa_PointParameterfvEXT( GLenum pname, const GLfloat *params)
83 {
84 GET_CURRENT_CONTEXT(ctx);
85 ASSERT_OUTSIDE_BEGIN_END(ctx);
86
87 switch (pname) {
88 case GL_DISTANCE_ATTENUATION_EXT:
89 {
90 const GLboolean tmp = ctx->Point._Attenuated;
91 if (TEST_EQ_3V(ctx->Point.Params, params))
92 return;
93
94 FLUSH_VERTICES(ctx, _NEW_POINT);
95 COPY_3V(ctx->Point.Params, params);
96
97 /* Update several derived values now. This likely to be
98 * more efficient than trying to catch this statechange in
99 * state.c.
100 */
101 ctx->Point._Attenuated = (params[0] != 1.0 ||
102 params[1] != 0.0 ||
103 params[2] != 0.0);
104
105 if (tmp != ctx->Point._Attenuated) {
106 ctx->_Enabled ^= ENABLE_POINT_ATTEN;
107 ctx->_TriangleCaps ^= DD_POINT_ATTEN;
108 ctx->_NeedEyeCoords ^= NEED_EYE_POINT_ATTEN;
109 }
110 }
111 break;
112 case GL_POINT_SIZE_MIN_EXT:
113 if (*params < 0.0F) {
114 gl_error( ctx, GL_INVALID_VALUE, "glPointParameterfvEXT" );
115 return;
116 }
117 if (ctx->Point.MinSize == *params)
118 return;
119 FLUSH_VERTICES(ctx, _NEW_POINT);
120 ctx->Point.MinSize = *params;
121 break;
122 case GL_POINT_SIZE_MAX_EXT:
123 if (*params < 0.0F) {
124 gl_error( ctx, GL_INVALID_VALUE, "glPointParameterfvEXT" );
125 return;
126 }
127 if (ctx->Point.MaxSize == *params)
128 return;
129 FLUSH_VERTICES(ctx, _NEW_POINT);
130 ctx->Point.MaxSize = *params;
131 break;
132 case GL_POINT_FADE_THRESHOLD_SIZE_EXT:
133 if (*params < 0.0F) {
134 gl_error( ctx, GL_INVALID_VALUE, "glPointParameterfvEXT" );
135 return;
136 }
137 if (ctx->Point.Threshold == *params)
138 return;
139 FLUSH_VERTICES(ctx, _NEW_POINT);
140 ctx->Point.Threshold = *params;
141 break;
142 default:
143 gl_error( ctx, GL_INVALID_ENUM, "glPointParameterfvEXT" );
144 return;
145 }
146
147 if (ctx->Driver.PointParameterfv)
148 (*ctx->Driver.PointParameterfv)(ctx, pname, params);
149 }
150