points.c revision c1f859d4
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 "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 */ 44void 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 69void GLAPIENTRY 70_mesa_PointParameteri( GLenum pname, GLint param ) 71{ 72 const GLfloat value = (GLfloat) param; 73 _mesa_PointParameterfv(pname, &value); 74} 75 76 77void GLAPIENTRY 78_mesa_PointParameteriv( GLenum pname, const GLint *params ) 79{ 80 GLfloat p[3]; 81 p[0] = (GLfloat) params[0]; 82 if (pname == GL_DISTANCE_ATTENUATION_EXT) { 83 p[1] = (GLfloat) params[1]; 84 p[2] = (GLfloat) params[2]; 85 } 86 _mesa_PointParameterfv(pname, p); 87} 88 89 90void GLAPIENTRY 91_mesa_PointParameterf( GLenum pname, GLfloat param) 92{ 93 _mesa_PointParameterfv(pname, ¶m); 94} 95 96 97void GLAPIENTRY 98_mesa_PointParameterfv( GLenum pname, const GLfloat *params) 99{ 100 GET_CURRENT_CONTEXT(ctx); 101 ASSERT_OUTSIDE_BEGIN_END(ctx); 102 103 switch (pname) { 104 case GL_DISTANCE_ATTENUATION_EXT: 105 if (ctx->Extensions.EXT_point_parameters) { 106 if (TEST_EQ_3V(ctx->Point.Params, params)) 107 return; 108 FLUSH_VERTICES(ctx, _NEW_POINT); 109 COPY_3V(ctx->Point.Params, params); 110 ctx->Point._Attenuated = (ctx->Point.Params[0] != 1.0 || 111 ctx->Point.Params[1] != 0.0 || 112 ctx->Point.Params[2] != 0.0); 113 114 if (ctx->Point._Attenuated) 115 ctx->_TriangleCaps |= DD_POINT_ATTEN; 116 else 117 ctx->_TriangleCaps &= ~DD_POINT_ATTEN; 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 || ctx->Extensions.NV_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 * Initialize the context point state. 236 * 237 * \param ctx GL context. 238 * 239 * Initializes __GLcontextRec::Point and point related constants in 240 * __GLcontextRec::Const. 241 */ 242void 243_mesa_init_point(GLcontext *ctx) 244{ 245 GLuint i; 246 247 ctx->Point.SmoothFlag = GL_FALSE; 248 ctx->Point.Size = 1.0; 249 ctx->Point.Params[0] = 1.0; 250 ctx->Point.Params[1] = 0.0; 251 ctx->Point.Params[2] = 0.0; 252 ctx->Point._Attenuated = GL_FALSE; 253 ctx->Point.MinSize = 0.0; 254 ctx->Point.MaxSize 255 = MAX2(ctx->Const.MaxPointSize, ctx->Const.MaxPointSizeAA); 256 ctx->Point.Threshold = 1.0; 257 ctx->Point.PointSprite = GL_FALSE; /* GL_ARB/NV_point_sprite */ 258 ctx->Point.SpriteRMode = GL_ZERO; /* GL_NV_point_sprite (only!) */ 259 ctx->Point.SpriteOrigin = GL_UPPER_LEFT; /* GL_ARB_point_sprite */ 260 for (i = 0; i < MAX_TEXTURE_COORD_UNITS; i++) { 261 ctx->Point.CoordReplace[i] = GL_FALSE; /* GL_ARB/NV_point_sprite */ 262 } 263} 264