| 1 |
/** |
| 2 |
* \file points.c |
| 3 |
* Point operations. |
| 4 |
*/ |
| 5 |
|
| 6 |
/* |
| 7 |
* Mesa 3-D graphics library |
| 8 |
* Version: 6.5 |
| 9 |
* |
| 10 |
* Copyright (C) 1999-2005 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 |
* Added by GL_NV_point_sprite |
| 70 |
*/ |
| 71 |
void GLAPIENTRY |
| 72 |
_mesa_PointParameteriNV( GLenum pname, GLint param ) |
| 73 |
{ |
| 74 |
const GLfloat value = (GLfloat) param; |
| 75 |
_mesa_PointParameterfvEXT(pname, &value); |
| 76 |
} |
| 77 |
|
| 78 |
|
| 79 |
/* |
| 80 |
* Added by GL_NV_point_sprite |
| 81 |
*/ |
| 82 |
void GLAPIENTRY |
| 83 |
_mesa_PointParameterivNV( GLenum pname, const GLint *params ) |
| 84 |
{ |
| 85 |
const GLfloat value = (GLfloat) params[0]; |
| 86 |
_mesa_PointParameterfvEXT(pname, &value); |
| 87 |
} |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
/* |
| 92 |
* Same for both GL_EXT_point_parameters and GL_ARB_point_parameters. |
| 93 |
*/ |
| 94 |
void GLAPIENTRY |
| 95 |
_mesa_PointParameterfEXT( GLenum pname, GLfloat param) |
| 96 |
{ |
| 97 |
_mesa_PointParameterfvEXT(pname, ¶m); |
| 98 |
} |
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
/* |
| 103 |
* Same for both GL_EXT_point_parameters and GL_ARB_point_parameters. |
| 104 |
*/ |
| 105 |
void GLAPIENTRY |
| 106 |
_mesa_PointParameterfvEXT( GLenum pname, const GLfloat *params) |
| 107 |
{ |
| 108 |
GET_CURRENT_CONTEXT(ctx); |
| 109 |
ASSERT_OUTSIDE_BEGIN_END(ctx); |
| 110 |
|
| 111 |
switch (pname) { |
| 112 |
case GL_DISTANCE_ATTENUATION_EXT: |
| 113 |
if (ctx->Extensions.EXT_point_parameters) { |
| 114 |
if (TEST_EQ_3V(ctx->Point.Params, params)) |
| 115 |
return; |
| 116 |
FLUSH_VERTICES(ctx, _NEW_POINT); |
| 117 |
COPY_3V(ctx->Point.Params, params); |
| 118 |
} |
| 119 |
else { |
| 120 |
_mesa_error(ctx, GL_INVALID_ENUM, |
| 121 |
"glPointParameterf[v]{EXT,ARB}(pname)"); |
| 122 |
return; |
| 123 |
} |
| 124 |
break; |
| 125 |
case GL_POINT_SIZE_MIN_EXT: |
| 126 |
if (ctx->Extensions.EXT_point_parameters) { |
| 127 |
if (params[0] < 0.0F) { |
| 128 |
_mesa_error( ctx, GL_INVALID_VALUE, |
| 129 |
"glPointParameterf[v]{EXT,ARB}(param)" ); |
| 130 |
return; |
| 131 |
} |
| 132 |
if (ctx->Point.MinSize == params[0]) |
| 133 |
return; |
| 134 |
FLUSH_VERTICES(ctx, _NEW_POINT); |
| 135 |
ctx->Point.MinSize = params[0]; |
| 136 |
} |
| 137 |
else { |
| 138 |
_mesa_error(ctx, GL_INVALID_ENUM, |
| 139 |
"glPointParameterf[v]{EXT,ARB}(pname)"); |
| 140 |
return; |
| 141 |
} |
| 142 |
break; |
| 143 |
case GL_POINT_SIZE_MAX_EXT: |
| 144 |
if (ctx->Extensions.EXT_point_parameters) { |
| 145 |
if (params[0] < 0.0F) { |
| 146 |
_mesa_error( ctx, GL_INVALID_VALUE, |
| 147 |
"glPointParameterf[v]{EXT,ARB}(param)" ); |
| 148 |
return; |
| 149 |
} |
| 150 |
if (ctx->Point.MaxSize == params[0]) |
| 151 |
return; |
| 152 |
FLUSH_VERTICES(ctx, _NEW_POINT); |
| 153 |
ctx->Point.MaxSize = params[0]; |
| 154 |
} |
| 155 |
else { |
| 156 |
_mesa_error(ctx, GL_INVALID_ENUM, |
| 157 |
"glPointParameterf[v]{EXT,ARB}(pname)"); |
| 158 |
return; |
| 159 |
} |
| 160 |
break; |
| 161 |
case GL_POINT_FADE_THRESHOLD_SIZE_EXT: |
| 162 |
if (ctx->Extensions.EXT_point_parameters) { |
| 163 |
if (params[0] < 0.0F) { |
| 164 |
_mesa_error( ctx, GL_INVALID_VALUE, |
| 165 |
"glPointParameterf[v]{EXT,ARB}(param)" ); |
| 166 |
return; |
| 167 |
} |
| 168 |
if (ctx->Point.Threshold == params[0]) |
| 169 |
return; |
| 170 |
FLUSH_VERTICES(ctx, _NEW_POINT); |
| 171 |
ctx->Point.Threshold = params[0]; |
| 172 |
} |
| 173 |
else { |
| 174 |
_mesa_error(ctx, GL_INVALID_ENUM, |
| 175 |
"glPointParameterf[v]{EXT,ARB}(pname)"); |
| 176 |
return; |
| 177 |
} |
| 178 |
break; |
| 179 |
case GL_POINT_SPRITE_R_MODE_NV: |
| 180 |
/* This is one area where ARB_point_sprite and NV_point_sprite |
| 181 |
* differ. In ARB_point_sprite the POINT_SPRITE_R_MODE is |
| 182 |
* always ZERO. NV_point_sprite adds the S and R modes. |
| 183 |
*/ |
| 184 |
if (ctx->Extensions.NV_point_sprite) { |
| 185 |
GLenum value = (GLenum) params[0]; |
| 186 |
if (value != GL_ZERO && value != GL_S && value != GL_R) { |
| 187 |
_mesa_error(ctx, GL_INVALID_VALUE, |
| 188 |
"glPointParameterf[v]{EXT,ARB}(param)"); |
| 189 |
return; |
| 190 |
} |
| 191 |
if (ctx->Point.SpriteRMode == value) |
| 192 |
return; |
| 193 |
FLUSH_VERTICES(ctx, _NEW_POINT); |
| 194 |
ctx->Point.SpriteRMode = value; |
| 195 |
} |
| 196 |
else { |
| 197 |
_mesa_error(ctx, GL_INVALID_ENUM, |
| 198 |
"glPointParameterf[v]{EXT,ARB}(pname)"); |
| 199 |
return; |
| 200 |
} |
| 201 |
break; |
| 202 |
case GL_POINT_SPRITE_COORD_ORIGIN: |
| 203 |
if (ctx->Extensions.ARB_point_sprite) { |
| 204 |
GLenum value = (GLenum) params[0]; |
| 205 |
if (value != GL_LOWER_LEFT && value != GL_UPPER_LEFT) { |
| 206 |
_mesa_error(ctx, GL_INVALID_VALUE, |
| 207 |
"glPointParameterf[v]{EXT,ARB}(param)"); |
| 208 |
return; |
| 209 |
} |
| 210 |
if (ctx->Point.SpriteOrigin == value) |
| 211 |
return; |
| 212 |
FLUSH_VERTICES(ctx, _NEW_POINT); |
| 213 |
ctx->Point.SpriteOrigin = value; |
| 214 |
} |
| 215 |
else { |
| 216 |
_mesa_error(ctx, GL_INVALID_ENUM, |
| 217 |
"glPointParameterf[v]{EXT,ARB}(pname)"); |
| 218 |
return; |
| 219 |
} |
| 220 |
break; |
| 221 |
default: |
| 222 |
_mesa_error( ctx, GL_INVALID_ENUM, |
| 223 |
"glPointParameterf[v]{EXT,ARB}(pname)" ); |
| 224 |
return; |
| 225 |
} |
| 226 |
|
| 227 |
if (ctx->Driver.PointParameterfv) |
| 228 |
(*ctx->Driver.PointParameterfv)(ctx, pname, params); |
| 229 |
} |
| 230 |
#endif |
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
/** |
| 235 |
* Update derived point-related state. |
| 236 |
*/ |
| 237 |
void |
| 238 |
_mesa_update_point(GLcontext *ctx) |
| 239 |
{ |
| 240 |
/* clamp to user-specified limits now, clamp to ctx->Const.Min/Max |
| 241 |
* limits during rasterization. |
| 242 |
*/ |
| 243 |
ctx->Point._Size = CLAMP(ctx->Point.Size, |
| 244 |
ctx->Point.MinSize, |
| 245 |
ctx->Point.MaxSize); |
| 246 |
|
| 247 |
if (ctx->Point._Size == 1.0F) |
| 248 |
ctx->_TriangleCaps &= ~DD_POINT_SIZE; |
| 249 |
else |
| 250 |
ctx->_TriangleCaps |= DD_POINT_SIZE; |
| 251 |
|
| 252 |
ctx->Point._Attenuated = (ctx->Point.Params[0] != 1.0 || |
| 253 |
ctx->Point.Params[1] != 0.0 || |
| 254 |
ctx->Point.Params[2] != 0.0); |
| 255 |
|
| 256 |
if (ctx->Point._Attenuated) |
| 257 |
ctx->_TriangleCaps |= DD_POINT_ATTEN; |
| 258 |
else |
| 259 |
ctx->_TriangleCaps &= ~DD_POINT_ATTEN; |
| 260 |
} |
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
/** |
| 265 |
* Initialize the context point state. |
| 266 |
* |
| 267 |
* \param ctx GL context. |
| 268 |
* |
| 269 |
* Initializes __GLcontextRec::Point and point related constants in |
| 270 |
* __GLcontextRec::Const. |
| 271 |
*/ |
| 272 |
void |
| 273 |
_mesa_init_point(GLcontext *ctx) |
| 274 |
{ |
| 275 |
GLuint i; |
| 276 |
|
| 277 |
ctx->Point.SmoothFlag = GL_FALSE; |
| 278 |
ctx->Point.Size = 1.0; |
| 279 |
ctx->Point._Size = 1.0; |
| 280 |
ctx->Point.Params[0] = 1.0; |
| 281 |
ctx->Point.Params[1] = 0.0; |
| 282 |
ctx->Point.Params[2] = 0.0; |
| 283 |
ctx->Point._Attenuated = GL_FALSE; |
| 284 |
ctx->Point.MinSize = 0.0; |
| 285 |
ctx->Point.MaxSize |
| 286 |
= MAX2(ctx->Const.MaxPointSize, ctx->Const.MaxPointSizeAA); |
| 287 |
ctx->Point.Threshold = 1.0; |
| 288 |
ctx->Point.PointSprite = GL_FALSE; /* GL_ARB/NV_point_sprite */ |
| 289 |
ctx->Point.SpriteRMode = GL_ZERO; /* GL_NV_point_sprite (only!) */ |
| 290 |
ctx->Point.SpriteOrigin = GL_UPPER_LEFT; /* GL_ARB_point_sprite */ |
| 291 |
for (i = 0; i < MAX_TEXTURE_UNITS; i++) { |
| 292 |
ctx->Point.CoordReplace[i] = GL_FALSE; /* GL_ARB/NV_point_sprite */ |
| 293 |
} |
| 294 |
} |