points.c revision 3464ebd5
17117f1b4Smrg/** 27117f1b4Smrg * \file points.c 37117f1b4Smrg * Point operations. 47117f1b4Smrg */ 57117f1b4Smrg 67117f1b4Smrg/* 77117f1b4Smrg * Mesa 3-D graphics library 8c1f859d4Smrg * Version: 7.1 97117f1b4Smrg * 107117f1b4Smrg * Copyright (C) 1999-2007 Brian Paul All Rights Reserved. 117117f1b4Smrg * 127117f1b4Smrg * Permission is hereby granted, free of charge, to any person obtaining a 137117f1b4Smrg * copy of this software and associated documentation files (the "Software"), 147117f1b4Smrg * to deal in the Software without restriction, including without limitation 157117f1b4Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 167117f1b4Smrg * and/or sell copies of the Software, and to permit persons to whom the 177117f1b4Smrg * Software is furnished to do so, subject to the following conditions: 187117f1b4Smrg * 197117f1b4Smrg * The above copyright notice and this permission notice shall be included 207117f1b4Smrg * in all copies or substantial portions of the Software. 217117f1b4Smrg * 227117f1b4Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 237117f1b4Smrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 247117f1b4Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 257117f1b4Smrg * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 267117f1b4Smrg * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 277117f1b4Smrg * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 287117f1b4Smrg */ 297117f1b4Smrg 307117f1b4Smrg 317117f1b4Smrg#include "glheader.h" 327117f1b4Smrg#include "context.h" 337117f1b4Smrg#include "macros.h" 347117f1b4Smrg#include "points.h" 357117f1b4Smrg#include "mtypes.h" 367117f1b4Smrg 377117f1b4Smrg 387117f1b4Smrg/** 397117f1b4Smrg * Set current point size. 407117f1b4Smrg * \param size point diameter in pixels 417117f1b4Smrg * \sa glPointSize(). 427117f1b4Smrg */ 437117f1b4Smrgvoid GLAPIENTRY 447117f1b4Smrg_mesa_PointSize( GLfloat size ) 457117f1b4Smrg{ 467117f1b4Smrg GET_CURRENT_CONTEXT(ctx); 477117f1b4Smrg ASSERT_OUTSIDE_BEGIN_END(ctx); 487117f1b4Smrg 497117f1b4Smrg if (size <= 0.0) { 507117f1b4Smrg _mesa_error( ctx, GL_INVALID_VALUE, "glPointSize" ); 517117f1b4Smrg return; 527117f1b4Smrg } 537117f1b4Smrg 547117f1b4Smrg if (ctx->Point.Size == size) 557117f1b4Smrg return; 567117f1b4Smrg 577117f1b4Smrg FLUSH_VERTICES(ctx, _NEW_POINT); 587117f1b4Smrg ctx->Point.Size = size; 597117f1b4Smrg 607117f1b4Smrg if (ctx->Driver.PointSize) 617117f1b4Smrg ctx->Driver.PointSize(ctx, size); 627117f1b4Smrg} 637117f1b4Smrg 647117f1b4Smrg 657117f1b4Smrg#if _HAVE_FULL_GL 667117f1b4Smrg 67c1f859d4Smrg 687117f1b4Smrgvoid GLAPIENTRY 69c1f859d4Smrg_mesa_PointParameteri( GLenum pname, GLint param ) 707117f1b4Smrg{ 714a49301eSmrg GLfloat p[3]; 724a49301eSmrg p[0] = (GLfloat) param; 734a49301eSmrg p[1] = p[2] = 0.0F; 744a49301eSmrg _mesa_PointParameterfv(pname, p); 757117f1b4Smrg} 767117f1b4Smrg 777117f1b4Smrg 787117f1b4Smrgvoid GLAPIENTRY 79c1f859d4Smrg_mesa_PointParameteriv( GLenum pname, const GLint *params ) 807117f1b4Smrg{ 817117f1b4Smrg GLfloat p[3]; 827117f1b4Smrg p[0] = (GLfloat) params[0]; 837117f1b4Smrg if (pname == GL_DISTANCE_ATTENUATION_EXT) { 847117f1b4Smrg p[1] = (GLfloat) params[1]; 857117f1b4Smrg p[2] = (GLfloat) params[2]; 867117f1b4Smrg } 87c1f859d4Smrg _mesa_PointParameterfv(pname, p); 887117f1b4Smrg} 897117f1b4Smrg 907117f1b4Smrg 917117f1b4Smrgvoid GLAPIENTRY 92c1f859d4Smrg_mesa_PointParameterf( GLenum pname, GLfloat param) 937117f1b4Smrg{ 944a49301eSmrg GLfloat p[3]; 954a49301eSmrg p[0] = param; 964a49301eSmrg p[1] = p[2] = 0.0F; 974a49301eSmrg _mesa_PointParameterfv(pname, p); 987117f1b4Smrg} 997117f1b4Smrg 1007117f1b4Smrg 1017117f1b4Smrgvoid GLAPIENTRY 102c1f859d4Smrg_mesa_PointParameterfv( GLenum pname, const GLfloat *params) 1037117f1b4Smrg{ 1047117f1b4Smrg GET_CURRENT_CONTEXT(ctx); 1057117f1b4Smrg ASSERT_OUTSIDE_BEGIN_END(ctx); 1067117f1b4Smrg 1077117f1b4Smrg switch (pname) { 1087117f1b4Smrg case GL_DISTANCE_ATTENUATION_EXT: 1097117f1b4Smrg if (ctx->Extensions.EXT_point_parameters) { 1107117f1b4Smrg if (TEST_EQ_3V(ctx->Point.Params, params)) 1117117f1b4Smrg return; 1127117f1b4Smrg FLUSH_VERTICES(ctx, _NEW_POINT); 1137117f1b4Smrg COPY_3V(ctx->Point.Params, params); 1147117f1b4Smrg ctx->Point._Attenuated = (ctx->Point.Params[0] != 1.0 || 1157117f1b4Smrg ctx->Point.Params[1] != 0.0 || 1167117f1b4Smrg ctx->Point.Params[2] != 0.0); 1177117f1b4Smrg 1187117f1b4Smrg if (ctx->Point._Attenuated) 1197117f1b4Smrg ctx->_TriangleCaps |= DD_POINT_ATTEN; 1207117f1b4Smrg else 1217117f1b4Smrg ctx->_TriangleCaps &= ~DD_POINT_ATTEN; 1227117f1b4Smrg } 1237117f1b4Smrg else { 1247117f1b4Smrg _mesa_error(ctx, GL_INVALID_ENUM, 1257117f1b4Smrg "glPointParameterf[v]{EXT,ARB}(pname)"); 1267117f1b4Smrg return; 1277117f1b4Smrg } 1287117f1b4Smrg break; 1297117f1b4Smrg case GL_POINT_SIZE_MIN_EXT: 1307117f1b4Smrg if (ctx->Extensions.EXT_point_parameters) { 1317117f1b4Smrg if (params[0] < 0.0F) { 1327117f1b4Smrg _mesa_error( ctx, GL_INVALID_VALUE, 1337117f1b4Smrg "glPointParameterf[v]{EXT,ARB}(param)" ); 1347117f1b4Smrg return; 1357117f1b4Smrg } 1367117f1b4Smrg if (ctx->Point.MinSize == params[0]) 1377117f1b4Smrg return; 1387117f1b4Smrg FLUSH_VERTICES(ctx, _NEW_POINT); 1397117f1b4Smrg ctx->Point.MinSize = params[0]; 1407117f1b4Smrg } 1417117f1b4Smrg else { 1427117f1b4Smrg _mesa_error(ctx, GL_INVALID_ENUM, 1437117f1b4Smrg "glPointParameterf[v]{EXT,ARB}(pname)"); 1447117f1b4Smrg return; 1457117f1b4Smrg } 1467117f1b4Smrg break; 1477117f1b4Smrg case GL_POINT_SIZE_MAX_EXT: 1487117f1b4Smrg if (ctx->Extensions.EXT_point_parameters) { 1497117f1b4Smrg if (params[0] < 0.0F) { 1507117f1b4Smrg _mesa_error( ctx, GL_INVALID_VALUE, 1517117f1b4Smrg "glPointParameterf[v]{EXT,ARB}(param)" ); 1527117f1b4Smrg return; 1537117f1b4Smrg } 1547117f1b4Smrg if (ctx->Point.MaxSize == params[0]) 1557117f1b4Smrg return; 1567117f1b4Smrg FLUSH_VERTICES(ctx, _NEW_POINT); 1577117f1b4Smrg ctx->Point.MaxSize = params[0]; 1587117f1b4Smrg } 1597117f1b4Smrg else { 1607117f1b4Smrg _mesa_error(ctx, GL_INVALID_ENUM, 1617117f1b4Smrg "glPointParameterf[v]{EXT,ARB}(pname)"); 1627117f1b4Smrg return; 1637117f1b4Smrg } 1647117f1b4Smrg break; 1657117f1b4Smrg case GL_POINT_FADE_THRESHOLD_SIZE_EXT: 1667117f1b4Smrg if (ctx->Extensions.EXT_point_parameters) { 1677117f1b4Smrg if (params[0] < 0.0F) { 1687117f1b4Smrg _mesa_error( ctx, GL_INVALID_VALUE, 1697117f1b4Smrg "glPointParameterf[v]{EXT,ARB}(param)" ); 1707117f1b4Smrg return; 1717117f1b4Smrg } 1727117f1b4Smrg if (ctx->Point.Threshold == params[0]) 1737117f1b4Smrg return; 1747117f1b4Smrg FLUSH_VERTICES(ctx, _NEW_POINT); 1757117f1b4Smrg ctx->Point.Threshold = params[0]; 1767117f1b4Smrg } 1777117f1b4Smrg else { 1787117f1b4Smrg _mesa_error(ctx, GL_INVALID_ENUM, 1797117f1b4Smrg "glPointParameterf[v]{EXT,ARB}(pname)"); 1807117f1b4Smrg return; 1817117f1b4Smrg } 1827117f1b4Smrg break; 1837117f1b4Smrg case GL_POINT_SPRITE_R_MODE_NV: 1847117f1b4Smrg /* This is one area where ARB_point_sprite and NV_point_sprite 1857117f1b4Smrg * differ. In ARB_point_sprite the POINT_SPRITE_R_MODE is 1867117f1b4Smrg * always ZERO. NV_point_sprite adds the S and R modes. 1877117f1b4Smrg */ 1887117f1b4Smrg if (ctx->Extensions.NV_point_sprite) { 1897117f1b4Smrg GLenum value = (GLenum) params[0]; 1907117f1b4Smrg if (value != GL_ZERO && value != GL_S && value != GL_R) { 1917117f1b4Smrg _mesa_error(ctx, GL_INVALID_VALUE, 1927117f1b4Smrg "glPointParameterf[v]{EXT,ARB}(param)"); 1937117f1b4Smrg return; 1947117f1b4Smrg } 1957117f1b4Smrg if (ctx->Point.SpriteRMode == value) 1967117f1b4Smrg return; 1977117f1b4Smrg FLUSH_VERTICES(ctx, _NEW_POINT); 1987117f1b4Smrg ctx->Point.SpriteRMode = value; 1997117f1b4Smrg } 2007117f1b4Smrg else { 2017117f1b4Smrg _mesa_error(ctx, GL_INVALID_ENUM, 2027117f1b4Smrg "glPointParameterf[v]{EXT,ARB}(pname)"); 2037117f1b4Smrg return; 2047117f1b4Smrg } 2057117f1b4Smrg break; 2067117f1b4Smrg case GL_POINT_SPRITE_COORD_ORIGIN: 2074a49301eSmrg /* This is not completely correct. GL_POINT_SPRITE_COORD_ORIGIN was 2084a49301eSmrg * added to point sprites when the extension was merged into OpenGL 2094a49301eSmrg * 2.0. It is expected that an implementation supporting OpenGL 1.4 2104a49301eSmrg * and GL_ARB_point_sprite will generate an error here. 2114a49301eSmrg */ 2124a49301eSmrg if (ctx->Extensions.ARB_point_sprite) { 2137117f1b4Smrg GLenum value = (GLenum) params[0]; 2147117f1b4Smrg if (value != GL_LOWER_LEFT && value != GL_UPPER_LEFT) { 2157117f1b4Smrg _mesa_error(ctx, GL_INVALID_VALUE, 2167117f1b4Smrg "glPointParameterf[v]{EXT,ARB}(param)"); 2177117f1b4Smrg return; 2187117f1b4Smrg } 2197117f1b4Smrg if (ctx->Point.SpriteOrigin == value) 2207117f1b4Smrg return; 2217117f1b4Smrg FLUSH_VERTICES(ctx, _NEW_POINT); 2227117f1b4Smrg ctx->Point.SpriteOrigin = value; 2237117f1b4Smrg } 2247117f1b4Smrg else { 2257117f1b4Smrg _mesa_error(ctx, GL_INVALID_ENUM, 2267117f1b4Smrg "glPointParameterf[v]{EXT,ARB}(pname)"); 2277117f1b4Smrg return; 2287117f1b4Smrg } 2297117f1b4Smrg break; 2307117f1b4Smrg default: 2317117f1b4Smrg _mesa_error( ctx, GL_INVALID_ENUM, 2327117f1b4Smrg "glPointParameterf[v]{EXT,ARB}(pname)" ); 2337117f1b4Smrg return; 2347117f1b4Smrg } 2357117f1b4Smrg 2367117f1b4Smrg if (ctx->Driver.PointParameterfv) 2377117f1b4Smrg (*ctx->Driver.PointParameterfv)(ctx, pname, params); 2387117f1b4Smrg} 2397117f1b4Smrg#endif 2407117f1b4Smrg 2417117f1b4Smrg 2427117f1b4Smrg 2437117f1b4Smrg/** 2447117f1b4Smrg * Initialize the context point state. 2457117f1b4Smrg * 2467117f1b4Smrg * \param ctx GL context. 2477117f1b4Smrg * 2483464ebd5Sriastradh * Initializes __struct gl_contextRec::Point and point related constants in 2493464ebd5Sriastradh * __struct gl_contextRec::Const. 2507117f1b4Smrg */ 2517117f1b4Smrgvoid 2523464ebd5Sriastradh_mesa_init_point(struct gl_context *ctx) 2537117f1b4Smrg{ 2547117f1b4Smrg GLuint i; 2557117f1b4Smrg 2567117f1b4Smrg ctx->Point.SmoothFlag = GL_FALSE; 2577117f1b4Smrg ctx->Point.Size = 1.0; 2587117f1b4Smrg ctx->Point.Params[0] = 1.0; 2597117f1b4Smrg ctx->Point.Params[1] = 0.0; 2607117f1b4Smrg ctx->Point.Params[2] = 0.0; 2617117f1b4Smrg ctx->Point._Attenuated = GL_FALSE; 2627117f1b4Smrg ctx->Point.MinSize = 0.0; 2637117f1b4Smrg ctx->Point.MaxSize 2647117f1b4Smrg = MAX2(ctx->Const.MaxPointSize, ctx->Const.MaxPointSizeAA); 2657117f1b4Smrg ctx->Point.Threshold = 1.0; 2667117f1b4Smrg ctx->Point.PointSprite = GL_FALSE; /* GL_ARB/NV_point_sprite */ 2677117f1b4Smrg ctx->Point.SpriteRMode = GL_ZERO; /* GL_NV_point_sprite (only!) */ 2687117f1b4Smrg ctx->Point.SpriteOrigin = GL_UPPER_LEFT; /* GL_ARB_point_sprite */ 269cdc920a0Smrg for (i = 0; i < Elements(ctx->Point.CoordReplace); i++) { 2707117f1b4Smrg ctx->Point.CoordReplace[i] = GL_FALSE; /* GL_ARB/NV_point_sprite */ 2717117f1b4Smrg } 2727117f1b4Smrg} 273