rastpos.c revision af69d88d
1/* 2 * Mesa 3-D graphics library 3 * 4 * Copyright (C) 1999-2007 Brian Paul All Rights Reserved. 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a 7 * copy of this software and associated documentation files (the "Software"), 8 * to deal in the Software without restriction, including without limitation 9 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 * and/or sell copies of the Software, and to permit persons to whom the 11 * Software is furnished to do so, subject to the following conditions: 12 * 13 * The above copyright notice and this permission notice shall be included 14 * in all copies or substantial portions of the Software. 15 * 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 * OTHER DEALINGS IN THE SOFTWARE. 23 */ 24 25 26/** 27 * \file rastpos.c 28 * Raster position operations. 29 */ 30 31#include "glheader.h" 32#include "context.h" 33#include "feedback.h" 34#include "macros.h" 35#include "mtypes.h" 36#include "rastpos.h" 37#include "state.h" 38#include "main/dispatch.h" 39 40 41/** 42 * Helper function for all the RasterPos functions. 43 */ 44static void 45rasterpos(GLfloat x, GLfloat y, GLfloat z, GLfloat w) 46{ 47 GET_CURRENT_CONTEXT(ctx); 48 GLfloat p[4]; 49 50 p[0] = x; 51 p[1] = y; 52 p[2] = z; 53 p[3] = w; 54 55 FLUSH_VERTICES(ctx, 0); 56 FLUSH_CURRENT(ctx, 0); 57 58 if (ctx->NewState) 59 _mesa_update_state( ctx ); 60 61 ctx->Driver.RasterPos(ctx, p); 62} 63 64 65void GLAPIENTRY 66_mesa_RasterPos2d(GLdouble x, GLdouble y) 67{ 68 rasterpos((GLfloat)x, (GLfloat)y, (GLfloat)0.0, (GLfloat)1.0); 69} 70 71void GLAPIENTRY 72_mesa_RasterPos2f(GLfloat x, GLfloat y) 73{ 74 rasterpos(x, y, 0.0F, 1.0F); 75} 76 77void GLAPIENTRY 78_mesa_RasterPos2i(GLint x, GLint y) 79{ 80 rasterpos((GLfloat) x, (GLfloat) y, 0.0F, 1.0F); 81} 82 83void GLAPIENTRY 84_mesa_RasterPos2s(GLshort x, GLshort y) 85{ 86 rasterpos(x, y, 0.0F, 1.0F); 87} 88 89void GLAPIENTRY 90_mesa_RasterPos3d(GLdouble x, GLdouble y, GLdouble z) 91{ 92 rasterpos((GLfloat) x, (GLfloat) y, (GLfloat) z, 1.0F); 93} 94 95void GLAPIENTRY 96_mesa_RasterPos3f(GLfloat x, GLfloat y, GLfloat z) 97{ 98 rasterpos(x, y, z, 1.0F); 99} 100 101void GLAPIENTRY 102_mesa_RasterPos3i(GLint x, GLint y, GLint z) 103{ 104 rasterpos((GLfloat) x, (GLfloat) y, (GLfloat) z, 1.0F); 105} 106 107void GLAPIENTRY 108_mesa_RasterPos3s(GLshort x, GLshort y, GLshort z) 109{ 110 rasterpos(x, y, z, 1.0F); 111} 112 113void GLAPIENTRY 114_mesa_RasterPos4d(GLdouble x, GLdouble y, GLdouble z, GLdouble w) 115{ 116 rasterpos((GLfloat) x, (GLfloat) y, (GLfloat) z, (GLfloat) w); 117} 118 119void GLAPIENTRY 120_mesa_RasterPos4f(GLfloat x, GLfloat y, GLfloat z, GLfloat w) 121{ 122 rasterpos(x, y, z, w); 123} 124 125void GLAPIENTRY 126_mesa_RasterPos4i(GLint x, GLint y, GLint z, GLint w) 127{ 128 rasterpos((GLfloat) x, (GLfloat) y, (GLfloat) z, (GLfloat) w); 129} 130 131void GLAPIENTRY 132_mesa_RasterPos4s(GLshort x, GLshort y, GLshort z, GLshort w) 133{ 134 rasterpos(x, y, z, w); 135} 136 137void GLAPIENTRY 138_mesa_RasterPos2dv(const GLdouble *v) 139{ 140 rasterpos((GLfloat) v[0], (GLfloat) v[1], 0.0F, 1.0F); 141} 142 143void GLAPIENTRY 144_mesa_RasterPos2fv(const GLfloat *v) 145{ 146 rasterpos(v[0], v[1], 0.0F, 1.0F); 147} 148 149void GLAPIENTRY 150_mesa_RasterPos2iv(const GLint *v) 151{ 152 rasterpos((GLfloat) v[0], (GLfloat) v[1], 0.0F, 1.0F); 153} 154 155void GLAPIENTRY 156_mesa_RasterPos2sv(const GLshort *v) 157{ 158 rasterpos(v[0], v[1], 0.0F, 1.0F); 159} 160 161void GLAPIENTRY 162_mesa_RasterPos3dv(const GLdouble *v) 163{ 164 rasterpos((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], 1.0F); 165} 166 167void GLAPIENTRY 168_mesa_RasterPos3fv(const GLfloat *v) 169{ 170 rasterpos(v[0], v[1], v[2], 1.0F); 171} 172 173void GLAPIENTRY 174_mesa_RasterPos3iv(const GLint *v) 175{ 176 rasterpos((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], 1.0F); 177} 178 179void GLAPIENTRY 180_mesa_RasterPos3sv(const GLshort *v) 181{ 182 rasterpos(v[0], v[1], v[2], 1.0F); 183} 184 185void GLAPIENTRY 186_mesa_RasterPos4dv(const GLdouble *v) 187{ 188 rasterpos((GLfloat) v[0], (GLfloat) v[1], 189 (GLfloat) v[2], (GLfloat) v[3]); 190} 191 192void GLAPIENTRY 193_mesa_RasterPos4fv(const GLfloat *v) 194{ 195 rasterpos(v[0], v[1], v[2], v[3]); 196} 197 198void GLAPIENTRY 199_mesa_RasterPos4iv(const GLint *v) 200{ 201 rasterpos((GLfloat) v[0], (GLfloat) v[1], 202 (GLfloat) v[2], (GLfloat) v[3]); 203} 204 205void GLAPIENTRY 206_mesa_RasterPos4sv(const GLshort *v) 207{ 208 rasterpos(v[0], v[1], v[2], v[3]); 209} 210 211 212/**********************************************************************/ 213/*** GL_ARB_window_pos / GL_MESA_window_pos ***/ 214/**********************************************************************/ 215 216 217/** 218 * All glWindowPosMESA and glWindowPosARB commands call this function to 219 * update the current raster position. 220 */ 221static void 222window_pos3f(GLfloat x, GLfloat y, GLfloat z) 223{ 224 GET_CURRENT_CONTEXT(ctx); 225 GLfloat z2; 226 227 FLUSH_VERTICES(ctx, 0); 228 FLUSH_CURRENT(ctx, 0); 229 230 z2 = CLAMP(z, 0.0F, 1.0F) 231 * (ctx->ViewportArray[0].Far - ctx->ViewportArray[0].Near) 232 + ctx->ViewportArray[0].Near; 233 234 /* set raster position */ 235 ctx->Current.RasterPos[0] = x; 236 ctx->Current.RasterPos[1] = y; 237 ctx->Current.RasterPos[2] = z2; 238 ctx->Current.RasterPos[3] = 1.0F; 239 240 ctx->Current.RasterPosValid = GL_TRUE; 241 242 if (ctx->Fog.FogCoordinateSource == GL_FOG_COORDINATE_EXT) 243 ctx->Current.RasterDistance = ctx->Current.Attrib[VERT_ATTRIB_FOG][0]; 244 else 245 ctx->Current.RasterDistance = 0.0; 246 247 /* raster color = current color or index */ 248 ctx->Current.RasterColor[0] 249 = CLAMP(ctx->Current.Attrib[VERT_ATTRIB_COLOR0][0], 0.0F, 1.0F); 250 ctx->Current.RasterColor[1] 251 = CLAMP(ctx->Current.Attrib[VERT_ATTRIB_COLOR0][1], 0.0F, 1.0F); 252 ctx->Current.RasterColor[2] 253 = CLAMP(ctx->Current.Attrib[VERT_ATTRIB_COLOR0][2], 0.0F, 1.0F); 254 ctx->Current.RasterColor[3] 255 = CLAMP(ctx->Current.Attrib[VERT_ATTRIB_COLOR0][3], 0.0F, 1.0F); 256 ctx->Current.RasterSecondaryColor[0] 257 = CLAMP(ctx->Current.Attrib[VERT_ATTRIB_COLOR1][0], 0.0F, 1.0F); 258 ctx->Current.RasterSecondaryColor[1] 259 = CLAMP(ctx->Current.Attrib[VERT_ATTRIB_COLOR1][1], 0.0F, 1.0F); 260 ctx->Current.RasterSecondaryColor[2] 261 = CLAMP(ctx->Current.Attrib[VERT_ATTRIB_COLOR1][2], 0.0F, 1.0F); 262 ctx->Current.RasterSecondaryColor[3] 263 = CLAMP(ctx->Current.Attrib[VERT_ATTRIB_COLOR1][3], 0.0F, 1.0F); 264 265 /* raster texcoord = current texcoord */ 266 { 267 GLuint texSet; 268 for (texSet = 0; texSet < ctx->Const.MaxTextureCoordUnits; texSet++) { 269 assert(texSet < Elements(ctx->Current.RasterTexCoords)); 270 COPY_4FV( ctx->Current.RasterTexCoords[texSet], 271 ctx->Current.Attrib[VERT_ATTRIB_TEX0 + texSet] ); 272 } 273 } 274 275 if (ctx->RenderMode==GL_SELECT) { 276 _mesa_update_hitflag( ctx, ctx->Current.RasterPos[2] ); 277 } 278} 279 280 281/* This is just to support the GL_MESA_window_pos version */ 282static void 283window_pos4f(GLfloat x, GLfloat y, GLfloat z, GLfloat w) 284{ 285 GET_CURRENT_CONTEXT(ctx); 286 window_pos3f(x, y, z); 287 ctx->Current.RasterPos[3] = w; 288} 289 290 291void GLAPIENTRY 292_mesa_WindowPos2d(GLdouble x, GLdouble y) 293{ 294 window_pos4f((GLfloat) x, (GLfloat) y, 0.0F, 1.0F); 295} 296 297void GLAPIENTRY 298_mesa_WindowPos2f(GLfloat x, GLfloat y) 299{ 300 window_pos4f(x, y, 0.0F, 1.0F); 301} 302 303void GLAPIENTRY 304_mesa_WindowPos2i(GLint x, GLint y) 305{ 306 window_pos4f((GLfloat) x, (GLfloat) y, 0.0F, 1.0F); 307} 308 309void GLAPIENTRY 310_mesa_WindowPos2s(GLshort x, GLshort y) 311{ 312 window_pos4f(x, y, 0.0F, 1.0F); 313} 314 315void GLAPIENTRY 316_mesa_WindowPos3d(GLdouble x, GLdouble y, GLdouble z) 317{ 318 window_pos4f((GLfloat) x, (GLfloat) y, (GLfloat) z, 1.0F); 319} 320 321void GLAPIENTRY 322_mesa_WindowPos3f(GLfloat x, GLfloat y, GLfloat z) 323{ 324 window_pos4f(x, y, z, 1.0F); 325} 326 327void GLAPIENTRY 328_mesa_WindowPos3i(GLint x, GLint y, GLint z) 329{ 330 window_pos4f((GLfloat) x, (GLfloat) y, (GLfloat) z, 1.0F); 331} 332 333void GLAPIENTRY 334_mesa_WindowPos3s(GLshort x, GLshort y, GLshort z) 335{ 336 window_pos4f(x, y, z, 1.0F); 337} 338 339void GLAPIENTRY 340_mesa_WindowPos4dMESA(GLdouble x, GLdouble y, GLdouble z, GLdouble w) 341{ 342 window_pos4f((GLfloat) x, (GLfloat) y, (GLfloat) z, (GLfloat) w); 343} 344 345void GLAPIENTRY 346_mesa_WindowPos4fMESA(GLfloat x, GLfloat y, GLfloat z, GLfloat w) 347{ 348 window_pos4f(x, y, z, w); 349} 350 351void GLAPIENTRY 352_mesa_WindowPos4iMESA(GLint x, GLint y, GLint z, GLint w) 353{ 354 window_pos4f((GLfloat) x, (GLfloat) y, (GLfloat) z, (GLfloat) w); 355} 356 357void GLAPIENTRY 358_mesa_WindowPos4sMESA(GLshort x, GLshort y, GLshort z, GLshort w) 359{ 360 window_pos4f(x, y, z, w); 361} 362 363void GLAPIENTRY 364_mesa_WindowPos2dv(const GLdouble *v) 365{ 366 window_pos4f((GLfloat) v[0], (GLfloat) v[1], 0.0F, 1.0F); 367} 368 369void GLAPIENTRY 370_mesa_WindowPos2fv(const GLfloat *v) 371{ 372 window_pos4f(v[0], v[1], 0.0F, 1.0F); 373} 374 375void GLAPIENTRY 376_mesa_WindowPos2iv(const GLint *v) 377{ 378 window_pos4f((GLfloat) v[0], (GLfloat) v[1], 0.0F, 1.0F); 379} 380 381void GLAPIENTRY 382_mesa_WindowPos2sv(const GLshort *v) 383{ 384 window_pos4f(v[0], v[1], 0.0F, 1.0F); 385} 386 387void GLAPIENTRY 388_mesa_WindowPos3dv(const GLdouble *v) 389{ 390 window_pos4f((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], 1.0F); 391} 392 393void GLAPIENTRY 394_mesa_WindowPos3fv(const GLfloat *v) 395{ 396 window_pos4f(v[0], v[1], v[2], 1.0); 397} 398 399void GLAPIENTRY 400_mesa_WindowPos3iv(const GLint *v) 401{ 402 window_pos4f((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], 1.0F); 403} 404 405void GLAPIENTRY 406_mesa_WindowPos3sv(const GLshort *v) 407{ 408 window_pos4f(v[0], v[1], v[2], 1.0F); 409} 410 411void GLAPIENTRY 412_mesa_WindowPos4dvMESA(const GLdouble *v) 413{ 414 window_pos4f((GLfloat) v[0], (GLfloat) v[1], 415 (GLfloat) v[2], (GLfloat) v[3]); 416} 417 418void GLAPIENTRY 419_mesa_WindowPos4fvMESA(const GLfloat *v) 420{ 421 window_pos4f(v[0], v[1], v[2], v[3]); 422} 423 424void GLAPIENTRY 425_mesa_WindowPos4ivMESA(const GLint *v) 426{ 427 window_pos4f((GLfloat) v[0], (GLfloat) v[1], 428 (GLfloat) v[2], (GLfloat) v[3]); 429} 430 431void GLAPIENTRY 432_mesa_WindowPos4svMESA(const GLshort *v) 433{ 434 window_pos4f(v[0], v[1], v[2], v[3]); 435} 436 437 438#if 0 439 440/* 441 * OpenGL implementation of glWindowPos*MESA() 442 */ 443void glWindowPos4fMESA( GLfloat x, GLfloat y, GLfloat z, GLfloat w ) 444{ 445 GLfloat fx, fy; 446 447 /* Push current matrix mode and viewport attributes */ 448 glPushAttrib( GL_TRANSFORM_BIT | GL_VIEWPORT_BIT ); 449 450 /* Setup projection parameters */ 451 glMatrixMode( GL_PROJECTION ); 452 glPushMatrix(); 453 glLoadIdentity(); 454 glMatrixMode( GL_MODELVIEW ); 455 glPushMatrix(); 456 glLoadIdentity(); 457 458 glDepthRange( z, z ); 459 glViewport( (int) x - 1, (int) y - 1, 2, 2 ); 460 461 /* set the raster (window) position */ 462 fx = x - (int) x; 463 fy = y - (int) y; 464 glRasterPos4f( fx, fy, 0.0, w ); 465 466 /* restore matrices, viewport and matrix mode */ 467 glPopMatrix(); 468 glMatrixMode( GL_PROJECTION ); 469 glPopMatrix(); 470 471 glPopAttrib(); 472} 473 474#endif 475 476 477/**********************************************************************/ 478/** \name Initialization */ 479/**********************************************************************/ 480/*@{*/ 481 482/** 483 * Initialize the context current raster position information. 484 * 485 * \param ctx GL context. 486 * 487 * Initialize the current raster position information in 488 * __struct gl_contextRec::Current, and adds the extension entry points to the 489 * dispatcher. 490 */ 491void _mesa_init_rastpos( struct gl_context * ctx ) 492{ 493 int i; 494 495 ASSIGN_4V( ctx->Current.RasterPos, 0.0, 0.0, 0.0, 1.0 ); 496 ctx->Current.RasterDistance = 0.0; 497 ASSIGN_4V( ctx->Current.RasterColor, 1.0, 1.0, 1.0, 1.0 ); 498 ASSIGN_4V( ctx->Current.RasterSecondaryColor, 0.0, 0.0, 0.0, 1.0 ); 499 for (i = 0; i < Elements(ctx->Current.RasterTexCoords); i++) 500 ASSIGN_4V( ctx->Current.RasterTexCoords[i], 0.0, 0.0, 0.0, 1.0 ); 501 ctx->Current.RasterPosValid = GL_TRUE; 502} 503 504/*@}*/ 505