1Name 2 3 ARB_fragment_program 4 5Name Strings 6 7 GL_ARB_fragment_program 8 9Contributors 10 11 Bob Beretta 12 Pat Brown 13 Matt Craighead 14 Cass Everitt 15 Evan Hart 16 Jon Leech 17 Bill Licea-Kane 18 Bimal Poddar 19 Jeremy Sandmel 20 Jon Paul Schelter 21 Avinash Seetharamaiah 22 Nick Triantos 23 24 and contributors to the ARB_vertex_program working group, 25 the product of which provided the basis for this spec 26 27Contact 28 29 Benj Lipchak, AMD (benj.lipchak 'at' amd.com) 30 31Notice 32 33 Copyright (c) 2002-2013 The Khronos Group Inc. Copyright terms at 34 http://www.khronos.org/registry/speccopyright.html 35 36Specification Update Policy 37 38 Khronos-approved extension specifications are updated in response to 39 issues and bugs prioritized by the Khronos OpenGL Working Group. For 40 extensions which have been promoted to a core Specification, fixes will 41 first appear in the latest version of that core Specification, and will 42 eventually be backported to the extension document. This policy is 43 described in more detail at 44 https://www.khronos.org/registry/OpenGL/docs/update_policy.php 45 46IP Status 47 48 Microsoft claims to own intellectual property related to this 49 extension. 50 51Status 52 53 Complete. Approved by ARB on September 18, 2002 54 55Version 56 57 Last Modified Date: October 8, 2013 58 Revision: 28 59 60Number 61 62 ARB Extension #27 63 64Dependencies 65 66 The extension is written against the OpenGL 1.3 Specification. 67 68 OpenGL 1.3 is required. 69 70 EXT_texture_lod_bias or OpenGL 1.4 is required. 71 72 OpenGL 1.4 affects the definition of this extension. 73 74 ARB_vertex_blend and EXT_vertex_weighting affect the definition of 75 this extension. 76 77 ARB_matrix_palette affects the definition of this extension. 78 79 ARB_transpose_matrix affects the definition of this extension. 80 81 EXT_fog_coord affects the definition of this extension. 82 83 EXT_texture_rectangle affects the definition of this extension. 84 85 ARB_shadow interacts with this extension. 86 87 ARB_vertex_program interacts with this extension. 88 89 ATI_fragment_shader interacts with this extension. 90 91 NV_fragment_program interacts with this extension. 92 93 94Overview 95 96 Unextended OpenGL mandates a certain set of configurable per- 97 fragment computations defining texture application, texture 98 environment, color sum, and fog operations. Several extensions have 99 added further per-fragment computations to OpenGL. For example, 100 extensions have defined new texture environment capabilities 101 (ARB_texture_env_add, ARB_texture_env_combine, ARB_texture_env_dot3, 102 ARB_texture_env_crossbar), per-fragment depth comparisons 103 (ARB_depth_texture, ARB_shadow, ARB_shadow_ambient, 104 EXT_shadow_funcs), per-fragment lighting (EXT_fragment_lighting, 105 EXT_light_texture), and environment mapped bump mapping 106 (ATI_envmap_bumpmap). 107 108 Each such extension adds a small set of relatively inflexible per- 109 fragment computations. 110 111 This inflexibility is in contrast to the typical flexibility 112 provided by the underlying programmable floating point engines 113 (whether micro-coded fragment engines, DSPs, or CPUs) that are 114 traditionally used to implement OpenGL's texturing computations. 115 The purpose of this extension is to expose to the OpenGL application 116 writer a significant degree of per-fragment programmability for 117 computing fragment parameters. 118 119 For the purposes of discussing this extension, a fragment program is 120 a sequence of floating-point 4-component vector operations that 121 determines how a set of program parameters (not specific to an 122 individual fragment) and an input set of per-fragment parameters are 123 transformed to a set of per-fragment result parameters. 124 125 The per-fragment computations for standard OpenGL given a particular 126 set of texture and fog application modes (along with any state for 127 extensions defining per-fragment computations) is, in essence, a 128 fragment program. However, the sequence of operations is defined 129 implicitly by the current OpenGL state settings rather than defined 130 explicitly as a sequence of instructions. 131 132 This extension provides an explicit mechanism for defining fragment 133 program instruction sequences for application-defined fragment 134 programs. In order to define such fragment programs, this extension 135 defines a fragment programming model including a floating-point 136 4-component vector instruction set and a relatively large set of 137 floating-point 4-component registers. 138 139 The extension's fragment programming model is designed for efficient 140 hardware implementation and to support a wide variety of fragment 141 programs. By design, the entire set of existing fragment programs 142 defined by existing OpenGL per-fragment computation extensions can 143 be implemented using the extension's fragment programming model. 144 145Issues 146 147 This extension is closely related to ARB_vertex_program, and is in 148 sync with revision 36 of that spec. ARB_fragment_program will 149 continue to track changes made to ARB_vertex_program. 150 151 (1) Should we provide precision queries? 152 153 RESOLVED: We've decided not to include precision queries. 154 Implementations are expected to meet or exceed the precision 155 guidelines set forth in the core GL spec, section 2.1.1, p. 6, 156 as ammended by this extension. 157 158 To summarize section 2.1.1, the maximum representable magnitude of 159 colors must be at least 2^10, while the maximum representable 160 magnitude of other floating-point values must be at least 2^32. 161 The individual results of floating-point operations must be 162 accurate to about 1 part in 10^5. 163 164 Here are the reasons why precision queries were not included: 165 1. It is unclear what the queries should be: 166 a) min, max, [0,1) granularity 167 b) min +, max +, min -, max -, [0,1) granularity 168 c) IEEE mantissa bits, IEEE exponent bits 169 2. Due to instruction emulation, there is no way to query the 170 actual precision that can be expected. Should the query 171 return the best-case or worst-case precision? 172 3. Implementations may support multiple precisions, on a per- 173 instruction basis or across the board. How would this be 174 exposed? 175 4. Current implementations are able to meet the minimum 176 requirements specified in the core GL, thanks to its 177 sufficiently loose wording "... so that the individual 178 results of floating-point operations are accurate to ABOUT 179 1 part in 10^5." (Emphasis added.) 180 5. A conformance test can act as watchdog to ensure 181 implementations are not cutting corners on precision. 182 6. Adding precision queries would require a new entrypoint. 183 184 See issue 22 regarding reduced-precision modes. 185 186 (2) Should the LOD biased texture sample be optional? 187 188 RESOLVED: TXB support is mandatory. This exposes useful 189 functionality which enables blurring and sharpening effects. It 190 will be more useful to entirely override derivatives (scale 191 factor) rather than just biasing the level-of-detail. This would 192 be a future extension to fragment programs. 193 194 It should be noted here that the bias introduced per-fragment by 195 TXB is added to any per-object or per-stage LOD bias. If per- 196 fragment LOD bias is not necessary, using the per-object and/or 197 per-stage LOD biases may perform better. 198 199 (3) Should we include the ability to bind to the color matrix? How 200 about others? Program matrices? 201 202 RESOLVED: We will not specifically add anything that depends on 203 the ARB_imaging subset. So we have not included matrix bindings 204 to the color matrix (or parameter bindings to the color biases, 205 etc.). However, we have included matrix binding support and 206 support for all of the matrices present in ARB_vertex_program. 207 208 (4) Should we include the ability to bind to just a texcoord 209 attribute's S,T components? (Or just S, or S,T,P for that matter?) 210 211 RESOLVED: No. Issue #15 below obviates this issue by making the 212 texture coordinate usage within a program explicit, thereby making 213 optimizations to reduce the number of interpolated texture 214 coordinates something an implementation can do at compile time 215 instead of having to do it during every texture target change. 216 217 (5) What other instructions should be added? Should any be removed? 218 219 RESOLVED: The differences between the ARB_vertex_program 220 instruction set and the ARB_fragment_program instruction set are 221 minimal. ARB_fragment_program removes the LOG and EXP rough 222 approximation instructions and the ARL address register load 223 instruction. ARB_fragment_program adds the SIN/COS/SCS 224 trigonometric instructions, the LRP linear interpolation 225 instruction, the CMP compare instruction, and the TEX/TXP/TXB/KIL 226 texture instructions. 227 228 (6) Should depth output be a program option or a mandatory feature? 229 230 RESOLVED: Depth output capability should be mandatory. 231 232 (6a) How should per-vertex geometric depth clipping be handled when 233 replacing depth in a fragment program? 234 235 RESOLVED: Per-vertex geometric depth clipping should be performed 236 by the GL as usual, so no spec change is required. The ideal 237 behavior would be to disable near and far clipping planes when 238 replacing depth, but not all implementations can natively support 239 disabling individual clip planes. 240 241 (6b) How should depth output from the fragment program be further 242 processed before being handed to the per-fragment operations? 243 244 RESOLVED: Depth gets clamped by GL to [0,1]. App has access to 245 depth range as a bindable parameter if it wants to either scale 246 and bias its depth to fall within the depth range, or to kill 247 fragments outside the depth range. 248 249 (7) If a fragment program does not write a color value, what should 250 be the final color of the fragment? 251 252 RESOLVED: The final fragment color is undefined. Note that it may 253 be perfectly reasonable to have a program that computes depth 254 values but not colors. Fragment colors are often irrelevant if 255 color writes are disabled (via ColorMask). 256 257 (7a) If a fragment program does not write a depth value, what should 258 be the final depth value of the fragment? 259 260 RESOLVED: "Depth fly-over" (using the conventional depth produced 261 by rasterization) should happen whenever a depth-replacing program 262 is not in use. A depth-replacing program is defined as a program 263 that writes to result.depth in at least one instruction. The 264 presence of a depth declaration alone DOES NOT designate a depth- 265 replacing program. The intention is that a future extension 266 introducing conditional execution will still consider a program to 267 be depth-replacing even if the instruction(s) writing to 268 result.depth do(es) not execute. 269 270 Other considered definitions of depth-replacing program: 271 1. The presence of a depth declaration -OR- the use of 272 result.depth as an instruction destination anywhere in the 273 program designates a depth-replacing program. 274 2. Every program is a depth-replacing program, but the GL 275 initializes the depth output to be the depth produced by 276 rasterization. The app may then overwrite the depth output. 277 3. Every program is a depth-replacing program, and the app is 278 solely responsible for copying the depth input to depth 279 output if desired. 280 281 (8) Should relative addressing, like that defined in 282 ARB_vertex_program, be supported in this spec? 283 284 RESOLVED: No, relative addressing won't be included in this spec. 285 286 (9) Should full-featured operand component swizzling, like that 287 defined in ARB_vertex_program, be supported in this spec? 288 289 RESOLVED: Yes, full swizzling is mandatory. 290 291 (10) Should texture instructions contain specific limitations on 292 operations that can be performed? For example, should write masks 293 or operand component swizzling be disallowed? 294 295 RESOLVED: Texture instructions are specified to be very similar to 296 ALU instructions. They have been given 3-letter names, they allow 297 writemasking and saturation (which would be useful for floating- 298 point texture formats), source swizzles and negates, and the 299 ability to use parameters as sources. 300 301 (11) Should we standardize options for stencil or aux data buffer 302 outputs? 303 304 RESOLVED: Stencil and aux data buffers will be saved for a 305 possible future extension to fragment programs. 306 307 (12) Should depth output be pulled from the 3rd or 4th component? 308 309 RESOLVED: 3rd component, as the 3rd component is also used for 310 depth input from the "fragment.position" attribute. 311 312 (13) Which stages are subsumed by fragment programs? 313 314 RESOLVED: Texturing, color sum, and fog. 315 316 (14) What should the minimum resource limits be? 317 318 RESOLVED: 10 attributes, 24 parameters, 4 texture indirections, 319 48 ALU instructions, 24 texture instructions, and 16 temporaries. 320 321 (15) OpenGL provides a hierarchy of texture enables (cube map, 3D, 322 2D, 1D). Should the texture sampling instructions here override 323 that hierarchy and select specific texture targets? 324 325 RESOLVED: Yes. This removes a potential pitfall for developers: 326 leaving the hierarchy of enables in an undesired state. It makes 327 programs more readable as the intent of the sample is more 328 obvious. Finally, it allows compilers to be more aggressive as 329 to which texcoord components are "don't cares" without having to 330 recompile programs when fixed-function texenables change. One 331 drawback is that programs cannot be reused for both 2D and 3D 332 texturing, for example, by simply changing the texture enables. 333 334 Texture sampling can be specified by instructions like 335 336 TEX myTexel, fragment.texcoord[1], texture[2], 3D; 337 338 which would indicate to use texture coordinate set number 1 to 339 sample from the texture object bound to the TEXTURE_3D target on 340 texture image unit 2. 341 342 Each texture unit can have only one "active" target. Programs are 343 not allowed to reference different texture targets in the same 344 texture image unit. In the example above, any other texture 345 instructions using texture image unit 2 must specify the 3D 346 texture target. 347 348 Note that every texture image unit always has a texture bound to 349 every texture target, whether it is a named texture object or a 350 default texture. However, the texture may not be complete as 351 defined in section 3.8.9 of the core GL spec. See issue 23. 352 353 (16) Should aux texture units be additional units on top of existing 354 full-featured texture units, or should this spec fully deprecate 355 "legacy" texture units and only expose texture coordinate sets and 356 texture image units? 357 358 Background: Some implementations are able to expose more 359 "texture image units" (texture maps and associated parameters) 360 than "texture coordinate sets" (current texcoords, texgen, and 361 texture matrices). A conventional GL "texture unit" encompasses 362 both a texture image unit and a texture coordinate set as well as 363 texture environment state. 364 365 RESOLVED: Yes, deprecate "legacy" texture units. This is a more 366 flexible model. 367 368 (17) Should fragment programs affect all fragments, or just those 369 produced by the rasterization of points, lines, and triangles? 370 371 RESOLVED: Every fragment generated by the GL is subject to 372 fragment program mode. This includes point, line, and polygon 373 primitives as well as pixel rectangles and bitmaps. 374 375 (18) Should per-fragment position and fogcoord be bindable as 376 fragment attributes? 377 378 RESOLVED: Yes, interpolated fogcoord will make per-fragment 379 fog application possible, in addition to full fog stage 380 subsummation. Interpolated window position, especially depth, 381 enables interesting depth-replacing algorithms. 382 383 (19) What characters should be used to identify individual 384 components in swizzle selectors and write masks? 385 386 RESOLVED: ARB_vertex_program provides "xyzw". This extension 387 supports "xyzw" and also provides "rgba" for better readability 388 when dealing with RGBA color values. Adding support for special 389 identifiers for dealing with texture coordinates was considered 390 and rejected. "strq" could be used to identify texture coordinate 391 components, but the "r" would conflict with the "r" from "rgba". 392 "stpq" would be another possibility, but could be a source of 393 confusion. 394 395 (20) Should implementations be required to support all programs that 396 fit within the exported limits on the number of resources (e.g., 397 instructions, temporaries) that can be present in a program, even if 398 it means falling back to software? Should implementations be 399 required to reject programs that could never be accelerated? 400 401 RESOLVED: No and no. An implementation is allowed to fail 402 ProgramStringARB due to the program exceeding native resources. 403 Note that this failure must be invariant with respect to all other 404 OpenGL state. In other words, a program cannot succeed to load 405 with default state, but then fail to load when certain GL state 406 is altered. However, an implementation is not required to fail 407 when a program would exceed native resources, and is in fact 408 encouraged to fallback to a software path. See issue 21 for a way 409 of determining if this has happened. 410 411 This notable departure from ARB_vertex_program was made as an 412 accommodation to vendors who could not justify implementing a 413 software fallback path which would be relatively slow even 414 compared to an ARB_vertex_program software fallback path. 415 416 Two issues with this decision: 417 1. The API limits become hints, and one can no longer tell by 418 visual inspection whether or not a program will load on 419 every implementation. 420 2. Program loading will now depend on the optimizer, which may 421 vary from release to release of an implementation. A 422 program that succeeded to load when an ISV first wrote it 423 may fail to load in a future driver version, and vice versa. 424 425 (21) How can applications determine if their programs are too large 426 to run on the native (likely hardware) implementation, and therefore may 427 run with reduced performance? 428 429 RESOLVED: The following code snippet uses a native resource 430 query to guarantee a program is loaded natively (or not at all): 431 432 GLboolean ProgramStringIsNative(GLenum target, GLenum format, 433 GLsizei len, const void *string) 434 { 435 GLint errorPos, isNative; 436 glProgramStringARB(target, format, len, string); 437 glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &errorPos); 438 glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, 439 GL_PROGRAM_UNDER_NATIVE_LIMITS_ARB, &isNative); 440 if ((errorPos == -1) && (isNative == 1)) 441 return GL_TRUE; 442 else 443 return GL_FALSE; 444 } 445 446 Note that a program that successfully loads, and falls under the 447 native limits, is still not guaranteed to execute in hardware. 448 Lack of other resources (e.g., texture memory) or the use of other 449 OpenGL features not natively supported by the implementation 450 (e.g., textures with borders) may also prevent the program from 451 executing in hardware. 452 453 (22) Should we provide applications with a method to control the 454 level of precision used to carry out fragment program computations? 455 456 RESOLVED: Yes. The GL implementation ultimately has control over 457 the level of precision used for fragment program computations. 458 However, the "ARB_precision_hint_fastest" and 459 "ARB_precision_hint_nicest" program options allow applications to 460 guide the GL implementation in its precision selection. The 461 "fastest" option encourages the GL to minimize execution time, 462 with possibly reduced precision. The "nicest" option encourages 463 the GL to maximize precision, with possibly increased execution 464 time. 465 466 If the precision hint is not "fastest", GL implementations should 467 perform low-precision operations only if they could not 468 appreciably affect the final results of the program. Regardless 469 of the precision hint, GL implementations are discouraged from 470 reducing the precision of computations so aggressively that final 471 rendering results could be seriously compromised due to overflow 472 of intermediate values or insufficient number of mantissa bits. 473 474 Some implementations may provide only a single level of precision, 475 in which case these hints may have no effect. However, all 476 implementations will accept these options, even if they are 477 silently ignored. 478 479 More explicit control of precision, such as provided in "C" with 480 data types such as "short", "int", "float", "double", may also be 481 a desirable feature, but this level of detail is left to a 482 separate extension. 483 484 (23) What is the result of a sample from an incomplete texture? 485 The definition of texture completeness can be found in section 3.8.9 486 of the core GL spec. 487 488 RESOLVED: The result of a sample from an incomplete texture is the 489 constant vector (0,0,0,1). The benefit of defining the result to 490 be a constant is that broken apps are guaranteed to generate 491 unexpected (black) results from their bad samples. If we were to 492 leave the result undefined, some implementations may generate 493 expected results some of the time, for example when magfiltering, 494 giving app developers a false sense of correctness in their apps. 495 496 (24) What is a texture indirection, and how is it counted? 497 498 RESOLVED: On some implementations, fragment programs that have 499 complex texture dependency chains may not be supported, even if 500 the instruction counts fit within the exported limits. A texture 501 dependency occurs when a texture instruction depends on the 502 result of a previous instruction (ALU or texture) for use as its 503 texture coordinate. 504 505 A texture indirection can be considered a node in the texture 506 dependency chain. Each node contains a set of texture 507 instructions which execute in parallel, followed by a sequence of 508 ALU instructions. A dependent texture instruction is one that 509 uses a temporary as an input coordinate rather than an attribute 510 or a parameter. A program with no dependent texture instructions 511 (or no texture instructions at all) will have a single node in 512 its texture dependency chain, and thus a single indirection. 513 514 API-level texture indirections are counted by keeping track of 515 which temporaries are read and written within the current node in 516 the texture dependency chain. When a texture instruction is 517 encountered, an indirection may be added and a new node started 518 if either of the following two conditions is true: 519 520 1. the source coordinate of the texture instruction is a 521 temporary that has already been written in the current node, 522 either by a previous texture instruction or ALU instruction; 523 524 2. the result of the texture instruction is a temporary that 525 has already been read or written in the current node by an 526 ALU instruction. 527 528 The texture instruction provoking a new indirection and all 529 subsequent instructions are added to the new node. This process 530 is repeated until the end of the program is encountered. Below 531 is some pseudo-code to describe this: 532 533 indirections = 1; 534 tempsOutput = 0; 535 aluTemps = 0; 536 while (i = getInst()) 537 { 538 if (i.type == TEX) 539 { 540 if (((i.input.type == TEMP) && 541 (tempsOutput & (1 << i.input.index))) || 542 ((i.op != KILL) && (i.output.type == TEMP) && 543 (aluTemps & (1 << i.output.index)))) 544 { 545 indirections++; 546 tempsOutput = 0; 547 aluTemps = 0; 548 } 549 } else { 550 if (i.input1.type == TEMP) 551 aluTemps |= (1 << i.input1.index); 552 if (i.input2 && i.input2.type == TEMP) 553 aluTemps |= (1 << i.input2.index); 554 if (i.input3 && i.input3.type == TEMP) 555 aluTemps |= (1 << i.input3.index); 556 if (i.output.type == TEMP) 557 aluTemps |= (1 << i.output.index); 558 } 559 if ((i.op != KILL) && (i.output.type == TEMP)) 560 tempsOutput |= (1 << i.output.index); 561 } 562 563 For example, the following programs would have 1, 2, and 3 564 texture indirections, respectively: 565 566 !!ARBfp1.0 567 # No texture instructions, but always 1 indirection 568 MOV result.color, fragment.color; 569 END 570 571 !!ARBfp1.0 572 # A simple dependent texture instruction, 2 indirections 573 TEMP myColor; 574 MUL myColor, fragment.texcoord[0], fragment.texcoord[1]; 575 TEX result.color, myColor, texture[0], 2D; 576 END 577 578 !!ARBfp1.0 579 # A more complex example with 3 indirections 580 TEMP myColor1, myColor2; 581 TEX myColor1, fragment.texcoord[0], texture[0], 2D; 582 MUL myColor1, myColor1, myColor1; 583 TEX myColor2, fragment.texcoord[1], texture[1], 2D; 584 # so far we still only have 1 indirection 585 TEX myColor2, myColor1, texture[2], 2D; # This is #2 586 TEX result.color, myColor2, texture[3], 2D; # And #3 587 END 588 589 Note that writemasks for the temporaries written and swizzles 590 for the temporaries read are not taken into consideration when 591 counting indirections. This makes hand-counting of indirections 592 by a developer an easier task. 593 594 Native texture indirections may be counted differently by an 595 implementation to reflect its exact restrictions, to reflect the 596 true dependencies taking into account writemasks and swizzles, 597 and to reflect optimizations such as instruction reordering. 598 599 For implementations with no restrictions on the number of 600 indirections, the maximum indirection count will equal the 601 maximum texture instruction count. 602 603 (25) How can a program reduce SCS's scalar operand to the 604 fundamental period [-PI,PI]? 605 606 RESOLVED: Unlike the individual SIN and COS instructions, SCS 607 requires that its argument be reduced ahead of time to the 608 fundamental period. The reason SCS doesn't perform this 609 operation automatically is that it may make unnecessary redundant 610 work for programs that already have their operand in the correct 611 range. Other programs that do need to reduce their operand 612 simply need to add a block of code before the SCS instruction: 613 614 PARAM myParams = { 0.5, -3.14159, 6.28319, 0.15915 }; 615 MAD myOperand.x, myOperand.x, myParams.w, myParams.x; # a = (a/(2*PI))+0.5 616 FRC myOperand.x, myOperand.x; # a = frac(a) 617 MAD myOperand.x, myOperand.x, myParams.z, myParams.y # a = (a*2*PI)-PI 618 ... 619 SCS myResult, myOperand.x; 620 621 (26) Is depth output from a fragment program guaranteed to be 622 invariant with respect to depth produced via conventional 623 rasterization? 624 625 RESOLVED: No. The floating-point representation of depth values 626 output from a fragment program may lead to the output of depth 627 with less precision than the depth output by convention GL 628 rasterization. For example, a floating-point representation with 629 16 bits of mantissa will certainly produce depth with lesser 630 precision than that of conventional rasterization used in 631 conjunction with a 24-bit depth buffer, where all values are 632 maintained as integers. Be aware of this when mixing conventional 633 GL rendering with fragment program rendering. 634 635 (27) How can conventional GL fog application be achieved within a 636 fragment program? 637 638 RESOLVED: Program options have been introduced that allow a 639 program to request fog to be applied to the final clamped fragment 640 color before being passed along to the antialiasing application 641 stage. This makes it easy for: 642 1. developers to request conventional fog behavior 643 2. implementations with dedicated fog hardware to use it 644 3. implementations without dedicated fog hardware, so they need 645 not track fog state after compilation, and constantly 646 recompile when fog state changes. 647 648 The three mandatory options are ARB_fog_exp, ARB_fog_exp2, and 649 ARB_fog_linear. As these options are mutually exclusive by 650 nature, specifying more than one is not useful. If more than one 651 is specified, the last one encountered in the <optionSequence> 652 will be the one to actually modify the execution environment. 653 654 (28) Why have all of the enums, entrypoints, GLX protocol, and spec 655 language shared with ARB_vertex_program been reproduced here? 656 657 RESOLVED: The two extensions are independent of one another, in 658 so far as an implementation need not support both of them in order 659 to support one of them. Everything needed to implement or make 660 use of ARB_fragment_program is present in this spec without the 661 need to refer to the ARB_vertex_program spec. When and if these 662 two extensions are incorporated into the core OpenGL, the 663 significant overlap of the two will be collapsed into a single 664 instance of the shared parts. 665 666 (29) How might an implementation implement the fog options? To What 667 does the extra resource consumption described in 3.11.4.5.1 668 correspond? 669 670 RESOLVED: The following code snippets reflect possible 671 implementations of the fog options. While an implementation may 672 use other instruction sequences to achieve the same result, or may 673 use external fog hardware if available, all implementations must 674 enforce the API-level resource consumption as described: 2 params, 675 1 temp, 1 attribute, and 3, 4, or 2 instructions. "finalColor" in 676 the examples below is the color that would otherwise be 677 "result.color", with components clamped to the range [0,1]. 678 "result.color.a" is assumed to have already been written, as fog 679 blending does not affect the alpha component. 680 681 EXP: 682 # Exponential fog 683 # f = exp(-d*z) 684 # 685 PARAM p = {DENSITY/LN(2), NOT USED, NOT USED, NOT USED}; 686 PARAM fogColor = state.fog.color; 687 TEMP fogFactor; 688 ATTRIB fogCoord = fragment.fogcoord.x; 689 MUL fogFactor.x, p.x, fogCoord.x; 690 EX2_SAT fogFactor.x, -fogFactor.x; 691 LRP result.color.rgb, fogFactor.x, finalColor, fogColor; 692 693 EXP2: 694 # 695 # 2nd-order Exponential fog 696 # f = exp(-(d*z)^2) 697 # 698 PARAM p = {DENSITY/SQRT(LN(2)), NOT USED, NOT USED, NOT USED}; 699 PARAM fogColor = state.fog.color; 700 TEMP fogFactor; 701 ATTRIB fogCoord = fragment.fogcoord.x; 702 MUL fogFactor.x, p.x, fogCoord.x; 703 MUL fogFactor.x, fogFactor.x, fogFactor.x; 704 EX2_SAT fogFactor.x, -fogFactor.x; 705 LRP result.color.rgb, fogFactor.x, finalColor, fogColor; 706 707 LINEAR: 708 # 709 # Linear fog 710 # f = (end-z)/(end-start) 711 # 712 PARAM p = {-1/(END-START), END/(END-START), NOT USED, NOT USED}; 713 PARAM fogColor = state.fog.color; 714 TEMP fogFactor; 715 ATTRIB fogCoord = fragment.fogcoord.x; 716 MAD_SAT fogFactor.x, p.x, fogCoord.x, p.y; 717 LRP result.color.rgb, fogFactor.x, finalColor, fogColor; 718 719 (30) Why is the order of operands for the CMP instruction different 720 than the order used by another popular graphics API? 721 722 RESOLVED: No other graphics API was used as a basis for the 723 design of ARB_fragment_program except ARB_vertex_program, which 724 did not have a CMP instruction. This independent evolution 725 naturally led to differences in minor details such as order of 726 operands. This discrepancy is noted here to help developers 727 familiar with the other API to avoid this potential pitfall. 728 729 (31) Is depth offset applied to the window z value before it enters 730 the fragment program? 731 732 RESOLVED: As in the base OpenGL specification, the depth offset 733 generated by polygon offset is added during polygon rasterization. 734 The depth value provided to shaders in the fragment.position.z 735 attribute already includes polygon offset, if enabled. If the 736 depth value is replaced by a fragment program, the polygon offset 737 value will NOT be recomputed and added back after fragment program 738 execution. 739 740 NOTE: This is probably not desirable for fragment programs that 741 modify depth values since the partials used to generate the offset 742 may not match the partials of the computed depth value. 743 744 745New Procedures and Functions 746 747 void ProgramStringARB(enum target, enum format, sizei len, 748 const void *string); 749 750 void BindProgramARB(enum target, uint program); 751 752 void DeleteProgramsARB(sizei n, const uint *programs); 753 754 void GenProgramsARB(sizei n, uint *programs); 755 756 void ProgramEnvParameter4dARB(enum target, uint index, 757 double x, double y, double z, double w); 758 void ProgramEnvParameter4dvARB(enum target, uint index, 759 const double *params); 760 void ProgramEnvParameter4fARB(enum target, uint index, 761 float x, float y, float z, float w); 762 void ProgramEnvParameter4fvARB(enum target, uint index, 763 const float *params); 764 765 void ProgramLocalParameter4dARB(enum target, uint index, 766 double x, double y, double z, double w); 767 void ProgramLocalParameter4dvARB(enum target, uint index, 768 const double *params); 769 void ProgramLocalParameter4fARB(enum target, uint index, 770 float x, float y, float z, float w); 771 void ProgramLocalParameter4fvARB(enum target, uint index, 772 const float *params); 773 774 void GetProgramEnvParameterdvARB(enum target, uint index, 775 double *params); 776 void GetProgramEnvParameterfvARB(enum target, uint index, 777 float *params); 778 779 void GetProgramLocalParameterdvARB(enum target, uint index, 780 double *params); 781 void GetProgramLocalParameterfvARB(enum target, uint index, 782 float *params); 783 784 void GetProgramivARB(enum target, enum pname, int *params); 785 786 void GetProgramStringARB(enum target, enum pname, void *string); 787 788 boolean IsProgramARB(uint program); 789 790 791New Tokens 792 793 Accepted by the <cap> parameter of Disable, Enable, and IsEnabled, 794 by the <pname> parameter of GetBooleanv, GetIntegerv, GetFloatv, 795 and GetDoublev, and by the <target> parameter of ProgramStringARB, 796 BindProgramARB, ProgramEnvParameter4[df][v]ARB, 797 ProgramLocalParameter4[df][v]ARB, GetProgramEnvParameter[df]vARB, 798 GetProgramLocalParameter[df]vARB, GetProgramivARB and 799 GetProgramStringARB. 800 801 FRAGMENT_PROGRAM_ARB 0x8804 802 803 Accepted by the <format> parameter of ProgramStringARB: 804 805 PROGRAM_FORMAT_ASCII_ARB 0x8875 806 807 Accepted by the <pname> parameter of GetProgramivARB: 808 809 PROGRAM_LENGTH_ARB 0x8627 810 PROGRAM_FORMAT_ARB 0x8876 811 PROGRAM_BINDING_ARB 0x8677 812 PROGRAM_INSTRUCTIONS_ARB 0x88A0 813 MAX_PROGRAM_INSTRUCTIONS_ARB 0x88A1 814 PROGRAM_NATIVE_INSTRUCTIONS_ARB 0x88A2 815 MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB 0x88A3 816 PROGRAM_TEMPORARIES_ARB 0x88A4 817 MAX_PROGRAM_TEMPORARIES_ARB 0x88A5 818 PROGRAM_NATIVE_TEMPORARIES_ARB 0x88A6 819 MAX_PROGRAM_NATIVE_TEMPORARIES_ARB 0x88A7 820 PROGRAM_PARAMETERS_ARB 0x88A8 821 MAX_PROGRAM_PARAMETERS_ARB 0x88A9 822 PROGRAM_NATIVE_PARAMETERS_ARB 0x88AA 823 MAX_PROGRAM_NATIVE_PARAMETERS_ARB 0x88AB 824 PROGRAM_ATTRIBS_ARB 0x88AC 825 MAX_PROGRAM_ATTRIBS_ARB 0x88AD 826 PROGRAM_NATIVE_ATTRIBS_ARB 0x88AE 827 MAX_PROGRAM_NATIVE_ATTRIBS_ARB 0x88AF 828 MAX_PROGRAM_LOCAL_PARAMETERS_ARB 0x88B4 829 MAX_PROGRAM_ENV_PARAMETERS_ARB 0x88B5 830 PROGRAM_UNDER_NATIVE_LIMITS_ARB 0x88B6 831 832 PROGRAM_ALU_INSTRUCTIONS_ARB 0x8805 833 PROGRAM_TEX_INSTRUCTIONS_ARB 0x8806 834 PROGRAM_TEX_INDIRECTIONS_ARB 0x8807 835 PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB 0x8808 836 PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB 0x8809 837 PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB 0x880A 838 MAX_PROGRAM_ALU_INSTRUCTIONS_ARB 0x880B 839 MAX_PROGRAM_TEX_INSTRUCTIONS_ARB 0x880C 840 MAX_PROGRAM_TEX_INDIRECTIONS_ARB 0x880D 841 MAX_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB 0x880E 842 MAX_PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB 0x880F 843 MAX_PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB 0x8810 844 845 Accepted by the <pname> parameter of GetProgramStringARB: 846 847 PROGRAM_STRING_ARB 0x8628 848 849 Accepted by the <pname> parameter of GetBooleanv, GetIntegerv, 850 GetFloatv, and GetDoublev: 851 852 PROGRAM_ERROR_POSITION_ARB 0x864B 853 CURRENT_MATRIX_ARB 0x8641 854 TRANSPOSE_CURRENT_MATRIX_ARB 0x88B7 855 CURRENT_MATRIX_STACK_DEPTH_ARB 0x8640 856 MAX_PROGRAM_MATRICES_ARB 0x862F 857 MAX_PROGRAM_MATRIX_STACK_DEPTH_ARB 0x862E 858 859 MAX_TEXTURE_COORDS_ARB 0x8871 860 MAX_TEXTURE_IMAGE_UNITS_ARB 0x8872 861 862 Accepted by the <name> parameter of GetString: 863 864 PROGRAM_ERROR_STRING_ARB 0x8874 865 866 Accepted by the <mode> parameter of MatrixMode: 867 868 MATRIX0_ARB 0x88C0 869 MATRIX1_ARB 0x88C1 870 MATRIX2_ARB 0x88C2 871 MATRIX3_ARB 0x88C3 872 MATRIX4_ARB 0x88C4 873 MATRIX5_ARB 0x88C5 874 MATRIX6_ARB 0x88C6 875 MATRIX7_ARB 0x88C7 876 MATRIX8_ARB 0x88C8 877 MATRIX9_ARB 0x88C9 878 MATRIX10_ARB 0x88CA 879 MATRIX11_ARB 0x88CB 880 MATRIX12_ARB 0x88CC 881 MATRIX13_ARB 0x88CD 882 MATRIX14_ARB 0x88CE 883 MATRIX15_ARB 0x88CF 884 MATRIX16_ARB 0x88D0 885 MATRIX17_ARB 0x88D1 886 MATRIX18_ARB 0x88D2 887 MATRIX19_ARB 0x88D3 888 MATRIX20_ARB 0x88D4 889 MATRIX21_ARB 0x88D5 890 MATRIX22_ARB 0x88D6 891 MATRIX23_ARB 0x88D7 892 MATRIX24_ARB 0x88D8 893 MATRIX25_ARB 0x88D9 894 MATRIX26_ARB 0x88DA 895 MATRIX27_ARB 0x88DB 896 MATRIX28_ARB 0x88DC 897 MATRIX29_ARB 0x88DD 898 MATRIX30_ARB 0x88DE 899 MATRIX31_ARB 0x88DF 900 901 902Additions to Chapter 2 of the OpenGL 1.3 Specification (OpenGL 903Operation) 904 905 Modify Section 2.1.1, Floating-Point Computation (p. 6) 906 907 (modify first paragraph, p. 6) ... The maximum representable 908 magnitude of a floating-point number used to represent position, 909 normal, or texture coordinates must be at least 2^32; the maximum 910 representable magnitude for colors must be at least 2^10. ... 911 912 913 Modify Section 2.7, Vertex Specification (p. 19) 914 915 (modify second paragraph, p. 20) Implementations support more than 916 one set of texture coordinates. The commands 917 918 void MultiTexCoord{1234}{sifd}(enum texture, T coords); 919 void MultiTexCoord{1234}{sifd}v(enum texture, T coords); 920 921 take the coordinate set to be modified as the <texture> parameter. 922 <texture> is a symbolic constant of the form TEXTUREi, indicating 923 that texture coordinate set i is to be modified. The constants obey 924 TEXTUREi = TEXTURE0 + i (i is in the range 0 to k-1, where k is the 925 implementation-dependent number of texture units defined by 926 MAX_TEXTURE_COORDS_ARB). 927 928 929 Modify Section 2.8, Vertex Arrays (p. 21) 930 931 (modify first paragraph, p. 21) ... The client may specify up to 5 932 plus the value of MAX_TEXTURE_COORDS_ARB arrays: one each to store 933 vertex coordinates... 934 935 936 (modify first paragraph, p. 23) The command 937 938 void ClientActiveTexture(enum texture); 939 940 is used to select the vertex array client state parameters to be 941 modified by the TexCoordPointer command and the array affected by 942 EnableClientState and DisableClientState with parameter 943 TEXTURE_COORD_ARRAY. This command sets the client state variable 944 CLIENT_ACTIVE_TEXTURE. Each texture coordinate set has a client 945 state vector which is selected when this command is invoked. This 946 state vector includes the vertex array state. This call also 947 selects the texture coordinate set state used for queries of client 948 state. 949 950 951 (modify first paragraph, p. 28) If the number of supported texture 952 coordinate sets (the value of MAX_TEXTURE_COORDS_ARB) is k, ... 953 954 955 Modify Section 2.10.2, Matrices (p. 31) 956 957 (modify first paragraph, p. 31) The projection matrix and model-view 958 matrix are set and modified with a variety of commands. The 959 affected matrix is determined by the current matrix mode. The 960 current matrix mode is set with 961 962 void MatrixMode(enum mode); 963 964 which takes one of the pre-defined constants TEXTURE, MODELVIEW, 965 COLOR, PROJECTION, or MATRIX<i>_ARB as the argument. In the case of 966 MATRIX<i>_ARB, <i> is an integer between 0 and <n>-1 indicating one 967 of <n> program matrices where <n> is the value of the implementation 968 defined constant MAX_PROGRAM_MATRICES_ARB. Such program matrices 969 are described in section 3.11.7. TEXTURE is described later in 970 section 2.10.2, and COLOR is described in section 3.6.3. If the 971 current matrix mode is MODELVIEW, then matrix operations apply to 972 the model-view matrix; if PROJECTION, then they apply to the 973 projection matrix. 974 975 976 (modify first paragraph, p. 34) For each texture coordinate set, a 977 4x4 matrix is applied to the corresponding texture coordinates... 978 979 980 (modify first and second paragraphs, p. 35) The command 981 982 void ActiveTexture(enum texture); 983 984 specifies the active texture unit selector, ACTIVE_TEXTURE. Each 985 texture unit contains up to two distinct sub-units: a texture 986 coordinate processing unit (consisting of a texture matrix stack and 987 texture coordinate generation state) and a texture image unit 988 (consisting of all the texture state defined in Section 3.8). In 989 implementations with a different number of supported texture 990 coordinate sets and texture image units, some texture units may 991 consist of only one of the two sub-units. 992 993 The active texture unit selector specifies the texture coordinate 994 set accessed by commands involving texture coordinate processing. 995 Such commands include those accessing the current matrix stack (if 996 MATRIX_MODE is TEXTURE), TexGen (section 2.10.4), Enable/Disable (if 997 any texture coordinate generation enum is selected), as well as 998 queries of the current texture coordinates and current raster 999 texture coordinates. If the texture coordinate set number 1000 corresponding to the current value of ACTIVE_TEXTURE is greater than 1001 or equal to the implementation-dependent constant 1002 MAX_TEXTURE_COORDS_ARB, the error INVALID_OPERATION is generated by 1003 any such command. 1004 1005 The active texture unit selector also selects the texture image unit 1006 accessed by commands involving texture image processing (section 1007 3.8). Such commands include all variants of TexEnv, TexParameter, 1008 and TexImage commands, BindTexture, Enable/Disable for any texture 1009 target (e.g., TEXTURE_2D), and queries of all such state. If the 1010 texture image unit number corresponding to the current value of 1011 ACTIVE_TEXTURE is greater than or equal to the implementation- 1012 dependent constant MAX_TEXTURE_IMAGE_UNITS_ARB, the error 1013 INVALID_OPERATION is generated by any such command. 1014 1015 ActiveTexture generates the error INVALID_ENUM if an invalid 1016 <texture> is specified. <texture> is a symbolic constant of the 1017 form TEXTUREi, indicating that texture unit i is to be modified. 1018 The constants obey TEXTUREi = TEXTURE0 + i (i is in the range 0 to 1019 k-1, where k is the larger of the MAX_TEXTURE_COORDS_ARB and 1020 MAX_TEXTURE_IMAGE_UNITS_ARB). For compatibility with old OpenGL 1021 specifications, the implementation-dependent constant 1022 MAX_TEXTURE_UNITS specifies the number of conventional texture units 1023 supported by the implementation. Its value must be no larger than 1024 the minimum of MAX_TEXTURE_COORDS_ARB and 1025 MAX_TEXTURE_IMAGE_UNITS_ARB. 1026 1027 1028 (modify last paragraph, p. 35) The state required to implement 1029 transformations consists of a <n>-value integer indicating the 1030 current matrix mode (where <n> is 4 + the number of supported 1031 texture and program matrices), a stack of at least two 4x4 matrices 1032 for each of COLOR, PROJECTION, and TEXTURE with associated stack 1033 pointers, <n> stacks (where <n> is at least 8) of at least one 4x4 1034 matrix for each MATRIX<i>_ARB with associated stack pointers, and a 1035 stack of at least 32 4x4 matrices with an associated stack pointer 1036 for MODELVIEW. Initially, there is only one matrix on each stack, 1037 and all matrices are set to the identity. The initial matrix mode 1038 is MODELVIEW. The initial value of ACTIVE_TEXTURE is TEXTURE0. 1039 1040 1041Additions to Chapter 3 of the OpenGL 1.3 Specification (Rasterization) 1042 1043 Modify Chapter 3, Introduction (p. 58) 1044 1045 (modify first paragraph, p. 58) ... Figure 3.1 diagrams the 1046 rasterization process. The color value assigned to a fragment is 1047 initially determined by the rasterization operations (sections 3.3 1048 through 3.7) and modified by either the execution of the texturing, 1049 color sum, and fog operations as defined in sections 3.8, 3.9, and 1050 3.10, or of a fragment program defined in section 3.11. The final 1051 depth value is initially determined by the rasterization operations 1052 and may be modified or replaced by a fragment program. 1053 1054 (modify Figure 3.1) 1055 1056 _ +---------------+ FRAGMENT_PROGRAM_ARB 1057 /|| Point | enable 1058 / | Rasterization |\ | 1059 / +---------------+ \ V o-------------+ 1060 From / +---------------+ \ | 1061 Primitive ---> | Line |---+++--->o o | 1062 Assembly \ | Rasterization | / || | | 1063 \ +---------------+ / || | | 1064 \ +---------------+/ || +-----+-----+ +----+-----+ 1065 \|| Polygon | || | Texturing | | Fragment | 1066 - | Rasterization | / | +-----+-----+ | Program | 1067 +---------------+ / | | +----+-----+ 1068 +---------------+ / | +-----+-----+ | 1069 | Pixel |/ | | Color Sum | | 1070 DrawPixels --> | Rectangle | / +-----+-----+ | 1071 | Rasterization | / | V 1072 +---------------+ / +-----+-----+ 1073 +---------------+ / | Fog |---> Fragments 1074 Bitmap ----> | Bitmap |/ +-----------+ 1075 | Rasterization | 1076 +---------------+ 1077 1078 1079 Modify Section 3.3, Points (p. 63) 1080 1081 (modify first and second paragraphs, p. 64) All fragments produced 1082 in rasterizing a non-antialiased point are assigned the same 1083 associated data, which are those of the vertex corresponding to the 1084 point. (delete reference to divide by q) 1085 1086 If antialiasing is enabled, then ... The data associated with each 1087 fragment are otherwise the data associated with the point being 1088 rasterized. (delete reference to divide by q) 1089 1090 1091 Modify Section 3.4.1, Basic Line Segment Rasterization (p. 66) 1092 1093 (modify first paragraph, p. 68) ... (Note that t=0 at p_a and t=1 at 1094 p_b). The value of an associated datum f from the fragment center, 1095 whether it be R, G, B, or A (in RGBA mode) or a color index (in 1096 color index mode) or the s, t, r, or q texture coordinate or the 1097 clip w coordinate (the depth value, window z, must be found using 1098 equation 3.3, below), is found as 1099 1100 f = (1-t)*(f_a/w_a) + t*(f_b/w_b) (3.2) 1101 ----------------------------- 1102 (1-t)*(1/w_a) + t*(1/w_b) 1103 1104 where f_a and f_b are the data associated with the starting and 1105 ending endpoints of the segment, respectively; w_a and w_b are the 1106 clip w coordinates of the starting and ending endpoints of the 1107 segments, respectively. Note that linear interpolation would use 1108 1109 f = (1-t)*f_a + t*f_b. (3.3) 1110 1111 ... A GL implementation may choose to approximate equation 3.2 with 1112 3.3, but this will normally lead to inacceptable distortion effects 1113 when interpolating texture coordinates or clip w coordinates. 1114 1115 1116 Modify Section 3.5.1, Basic Polygon Rasterization (p. 73) 1117 1118 (modify third and fourth paragraphs, p. 74) Denote a datum at p_a, 1119 p_b, or p_c as f_a, f_b, or f_c, respectively. Then the value f of 1120 a datum at a fragment produced by rasterizing a triangle is given by 1121 1122 f = a*(f_a/w_a) + b*(f_b/w_b) + c*(f_c/w_c) (3.4) 1123 --------------------------------------- 1124 a*(1/w_a) + b*(1/w_b) + c*(1/w_c) 1125 1126 where w_a, w_b, and w_c are the clip w coordinates of p_a, p_b, and 1127 p_c, respectively. a, b, and c are the barycentric coordinates of 1128 the fragment for which the data are produced. a, b, and c must 1129 correspond precisely to the ... at the fragment's center. 1130 1131 Just as with line segment rasterization, equation 3.4 may be 1132 approximated by 1133 1134 f = a*f_a + b*f_b + c*f_c; 1135 1136 this may yield ... for texture coordinates or clip w coordinates. 1137 1138 1139 Modify Section 3.6.4, Rasterization of Pixel Rectangles (p. 91) 1140 1141 (modify third paragraph, p. 103) A fragment arising from a group ... 1142 the color and texture coordinates are given by those associated with 1143 the current raster position. (delete reference to divide by q) 1144 Groups arising from DrawPixels... 1145 1146 1147 Modify Section 3.7, Bitmaps (p. 113) 1148 1149 (modify third paragraph, p. 114) Otherwise, a rectangular array ... 1150 The associated data for each fragment are those associated with the 1151 current raster position. (delete reference to divide by q) Once 1152 the fragments have been produced ... 1153 1154 1155 Modify Section 3.8, Texturing (p. 115) 1156 1157 (add new paragraphs before first paragraph, p. 115) Texture 1158 coordinate sets are mapped to RGBA colors for application to 1159 primitives in one of two modes. The first mode, described in this 1160 and subsequent sections, is GL's conventional multitexture pipeline, 1161 describing texture environment and texture application. The second 1162 mode, referred to as fragment program mode and described in section 1163 3.11, applies textures, color sum, and fog as specified in an 1164 application-supplied fragment program. 1165 1166 The fragment program mode is enabled and disabled using the generic 1167 Enable and Disable commands, respectively, with the symbolic 1168 constant FRAGMENT_PROGRAM_ARB. The required state is one bit 1169 indicating whether the fragment program mode is enabled or disabled. 1170 In the initial state, the fragment program mode is disabled. When 1171 fragment program mode is enabled, texturing, color sum, and fog 1172 application stages are ignored and a general purpose program is 1173 executed instead. 1174 1175 (modify first and second paragraph, p. 115) Conventional texturing 1176 is employed when fragment program mode is disabled. Texturing maps 1177 ... color of an image at the location indicated by a fragment's 1178 texture coordinates to modify the fragment's primary RGBA color. 1179 Texturing does not affect the secondary color. 1180 1181 An implementation may support texturing using more than one image at 1182 a time. In this case the fragment carries multiple sets of texture 1183 coordinates which are used to index ... 1184 1185 (add paragraph before 1st paragraph, p. 116) Except when in fragment 1186 program mode (section 3.11), the (s,t,r) texture coordinates used 1187 for texturing are the values s/q, t/q, and r/q, respectively, where 1188 s, t, r, and q are the texture coordinates associated with the 1189 fragment. When in fragment program mode, the (s,t,r) texture 1190 coordinates are specified by the program. If q is less than or 1191 equal to zero, the results of texturing are undefined. 1192 1193 1194 Modify Section 3.8.7, Texture Minification (p. 135) 1195 1196 (add new paragraph after first paragraph, p. 137) When fragment 1197 program mode is enabled, the derivatives of the coordinates may be 1198 ill-defined or non-existent. As a result, the implementation is 1199 free to approximate these derivatives with such techniques as 1200 differencing. The only requirement is that texture samples be 1201 equivalent across the two modes. In other words, the texture sample 1202 chosen for a fragment of a primitive must be invariant between 1203 fragment program mode and conventional mode subject to the rules 1204 set forth in Appendix A, Invariance. 1205 1206 1207 Modify Section 3.8.13, Texture Application (p. 149) 1208 1209 (modify fourth paragraph, p. 152) Texturing is enabled and disabled 1210 individually for each texture unit. If texturing is disabled for 1211 one of the units, then the fragment resulting from the previous unit 1212 is passed unaltered to the following unit. Individual texture units 1213 beyond those specified by MAX_TEXTURE_UNITS may be incomplete and 1214 are always treated as disabled. 1215 1216 1217 Insert a new Section 3.11, (p. 154), between existing sections 3.10 1218 and 3.11. Renumber 3.11, Antialiasing Application, to 3.12. 1219 1220 3.11 Fragment Programs 1221 1222 The conventional GL texturing model described in section 3.8 is a 1223 configurable but essentially hard-wired sequence of per-fragment 1224 computations based on a canonical set of per-fragment parameters 1225 and texturing-related state such as texture images, texture 1226 parameters, and texture environment parameters. The general success 1227 and utility of the conventional GL texturing model reflects its 1228 basic correspondence to the typical texturing requirements of 3D 1229 applications. 1230 1231 However when the conventional GL texturing model is not sufficient, 1232 the fragment program mode provides a substantially more flexible 1233 model for generating fragment colors. The fragment program mode 1234 permits applications to define their own fragment programs. 1235 1236 A fragment program is a character string that specifies a sequence 1237 of operations to perform. Fragment program instructions are 1238 typically 4-component vector operations that operate on per-fragment 1239 attributes and program parameters. Fragment programs execute on a 1240 per-fragment basis and operate on each fragment completely 1241 independently from any other fragments. Fragment programs execute a 1242 finite fixed sequence of instructions with no branching or looping. 1243 Fragment programs execute without data hazards so results computed 1244 in one instruction can be used immediately afterwards. The result 1245 of a fragment program is a set of fragment result registers that 1246 becomes the color used by antialiasing application and/or a depth 1247 value used in place of the interpolated depth value generated by 1248 conventional rasterization. 1249 1250 In fragment program mode, the color sum is subsumed by the fragment 1251 program. An application desiring the primary and secondary colors 1252 to be summed must explicitly include this operation in its program. 1253 1254 Fragment programs are defined to operate only in RGBA mode. The 1255 results of fragment program execution are undefined if the GL is in 1256 color index mode. 1257 1258 1259 3.11.1 Program Objects 1260 1261 The GL provides one or more program targets, each identifying a 1262 portion of the GL that can be controlled through application- 1263 specified programs. The program target for fragment programs is 1264 FRAGMENT_PROGRAM_ARB. Each program target has an associated program 1265 object, called the current program object. Each program target also 1266 has a default program object, which is initially the current program 1267 object. 1268 1269 Each program object has an associated program string. The command 1270 1271 ProgramStringARB(enum target, enum format, sizei len, 1272 const void *string); 1273 1274 updates the program string for the current program object for 1275 <target>. <format> describes the format of the program string, 1276 which must currently be PROGRAM_FORMAT_ASCII_ARB. <string> is a 1277 pointer to the array of bytes representing the program string being 1278 loaded, which need not be null-terminated. The length of the array 1279 is given by <len>. If <string> is null-terminated, <len> should not 1280 include the terminator. 1281 1282 When a program string is loaded, it is interpreted according to 1283 syntactic and semantic rules corresponding to the program target 1284 specified by <target>. If a program violates the syntactic or 1285 semantic restrictions of the program target, ProgramStringARB 1286 generates the error INVALID_OPERATION. An implementation may also 1287 generate the error INVALID_OPERATION if the program would exceed 1288 the native resource limits defined in section 6.1.12. A program 1289 which fails to load due to exceeding native resource limits must 1290 always fail, regardless of any other GL state. 1291 1292 Additionally, ProgramString will update the program error position 1293 (PROGRAM_ERROR_POSITION_ARB) and error string 1294 (PROGRAM_ERROR_STRING_ARB). If a program fails to load, the value 1295 of the program error position is set to the ubyte offset into the 1296 specified program string indicating where the first program error 1297 was detected. If the program fails to load because of a semantic 1298 restriction that is not detected until the program is fully 1299 scanned, the error position is set to the value of <len>. If a 1300 program loads successfully, the error position is set to the value 1301 negative one. The implementation-dependent program error string 1302 contains one or more error or warning messages. If a program loads 1303 succesfully, the error string may either contain warning messages or 1304 be empty. 1305 1306 Each program object has an associated array of program local 1307 parameters. The number and type of program local parameters is 1308 target- and implementation-dependent. For fragment programs, 1309 program local parameters are four-component floating-point vectors. 1310 The number of vectors is given by the implementation-dependent 1311 constant MAX_PROGRAM_LOCAL_PARAMETERS_ARB, which must be at least 1312 24. The commands 1313 1314 void ProgramLocalParameter4fARB(enum target, uint index, 1315 float x, float y, float z, float w); 1316 void ProgramLocalParameter4fvARB(enum target, uint index, 1317 const float *params); 1318 void ProgramLocalParameter4dARB(enum target, uint index, 1319 double x, double y, double z, double w); 1320 void ProgramLocalParameter4dvARB(enum target, uint index, 1321 const double *params); 1322 1323 update the values of the program local parameter numbered <index> 1324 belonging to the program object currently bound to <target>. For 1325 ProgramLocalParameter4fARB and ProgramLocalParameter4dARB, the four 1326 components of the parameter are updated with the values of <x>, <y>, 1327 <z>, and <w>, respectively. For ProgramLocalParameter4fvARB and 1328 ProgramLocalParameter4dvARB, the four components of the parameter 1329 are updated with the array of four values pointed to by <params>. 1330 The error INVALID_VALUE is generated if <index> is greater than or 1331 equal to the number of program local parameters supported by 1332 <target>. 1333 1334 Additionally, each program target has an associated array of program 1335 environment parameters. Unlike program local parameters, program 1336 environment parameters are shared by all program objects of a given 1337 target. The number and type of program environment parameters is 1338 target- and implementation-dependent. For fragment programs, 1339 program environment parameters are four-component floating-point 1340 vectors. The number of vectors is given by the implementation- 1341 dependent constant MAX_PROGRAM_ENV_PARAMETERS_ARB, which must be at 1342 least 24. The commands 1343 1344 void ProgramEnvParameter4fARB(enum target, uint index, 1345 float x, float y, float z, float w); 1346 void ProgramEnvParameter4fvARB(enum target, uint index, 1347 const float *params); 1348 void ProgramEnvParameter4dARB(enum target, uint index, 1349 double x, double y, double z, double w); 1350 void ProgramEnvParameter4dvARB(enum target, uint index, 1351 const double *params); 1352 1353 update the values of the program environment parameter numbered 1354 <index> for the given program target <target>. For 1355 ProgramEnvParameter4fARB and ProgramEnvParameter4dARB, the four 1356 components of the parameter are updated with the values of <x>, <y>, 1357 <z>, and <w>, respectively. For ProgramEnvParameter4fvARB and 1358 ProgramEnvParameter4dvARB, the four components of the parameter are 1359 updated with the array of four values pointed to by <params>. The 1360 error INVALID_VALUE is generated if <index> is greater than or equal 1361 to the number of program environment parameters supported by 1362 <target>. 1363 1364 Each program target has a default program object. Additionally, 1365 named program objects can be created and operated upon. The name 1366 space for program objects is the positive integers and is shared by 1367 programs of all targets. The name zero is reserved by the GL. 1368 1369 A named program object is created by binding an unused program 1370 object name to a valid program target. The binding is effected by 1371 calling 1372 1373 BindProgramARB(enum target, uint program); 1374 1375 with <target> set to the desired program target and <program> set to 1376 the unused program name. The resulting program object has a program 1377 target given by <target> and is assigned target-specific default 1378 values (see section 3.11.8 for fragment programs). BindProgramARB 1379 may also be used to bind an existing program object to a program 1380 target. If <program> is zero, the default program object for 1381 <target> is bound. If <program> is the name of an existing program 1382 object whose associated program target is <target>, the named 1383 program object is bound. The error INVALID_OPERATION is generated 1384 if <program> names an existing program object whose associated 1385 program target is anything other than <target>. 1386 1387 Programs objects are deleted by calling 1388 1389 void DeleteProgramsARB(sizei n, const uint *programs); 1390 1391 <programs> contains <n> names of programs to be deleted. After a 1392 program object is deleted, its name is again unused. If a program 1393 object that is bound to any target is deleted, it is as though 1394 BindProgramARB is first executed with same target and a <program> of 1395 zero. Unused names in <programs> are silently ignored, as is the 1396 value zero. 1397 1398 The command 1399 1400 void GenProgramsARB(sizei n, uint *programs); 1401 1402 returns <n> currently unused program names in <programs>. These 1403 names are marked as used, for the purposes of GenProgramsARB only, 1404 but objects are created only when they are first bound using 1405 BindProgramARB. 1406 1407 1408 3.11.2 Fragment Program Grammar and Semantic Restrictions 1409 1410 Fragment program strings are specified as an array of ASCII 1411 characters containing the program text. When a fragment program is 1412 loaded by a call to ProgramStringARB, the program string is parsed 1413 into a set of tokens possibly separated by whitespace. Spaces, 1414 tabs, newlines, carriage returns, and comments are considered 1415 whitespace. Comments begin with the character "#" and are 1416 terminated by a newline, a carriage return, or the end of the 1417 program array. 1418 1419 The Backus-Naur Form (BNF) grammar below specifies the syntactically 1420 valid sequences for fragment programs. The set of valid tokens can 1421 be inferred from the grammar. The token "" represents an empty 1422 string and is used to indicate optional rules. A program is invalid 1423 if it contains any undefined tokens or characters. 1424 1425 A fragment program is required to begin with the header string 1426 "!!ARBfp1.0", without any preceding whitespace. This string 1427 identifies the subsequent program text as a fragment program 1428 (version 1.0) that should be parsed according to the following 1429 grammar and semantic rules. Program string parsing begins with the 1430 character immediately following the header string. 1431 1432 <program> ::= <optionSequence> <statementSequence> "END" 1433 1434 <optionSequence> ::= <optionSequence> <option> 1435 | "" 1436 1437 <option> ::= "OPTION" <identifier> ";" 1438 1439 <statementSequence> ::= <statementSequence> <statement> 1440 | "" 1441 1442 <statement> ::= <instruction> ";" 1443 | <namingStatement> ";" 1444 1445 <instruction> ::= <ALUInstruction> 1446 | <TexInstruction> 1447 1448 <ALUInstruction> ::= <VECTORop_instruction> 1449 | <SCALARop_instruction> 1450 | <BINSCop_instruction> 1451 | <BINop_instruction> 1452 | <TRIop_instruction> 1453 | <SWZ_instruction> 1454 1455 <TexInstruction> ::= <SAMPLE_instruction> 1456 | <KIL_instruction> 1457 1458 <VECTORop_instruction> ::= <VECTORop> <maskedDstReg> "," 1459 <vectorSrcReg> 1460 1461 <VECTORop> ::= "ABS" | "ABS_SAT" 1462 | "FLR" | "FLR_SAT" 1463 | "FRC" | "FRC_SAT" 1464 | "LIT" | "LIT_SAT" 1465 | "MOV" | "MOV_SAT" 1466 1467 <SCALARop_instruction> ::= <SCALARop> <maskedDstReg> "," 1468 <scalarSrcReg> 1469 1470 <SCALARop> ::= "COS" | "COS_SAT" 1471 | "EX2" | "EX2_SAT" 1472 | "LG2" | "LG2_SAT" 1473 | "RCP" | "RCP_SAT" 1474 | "RSQ" | "RSQ_SAT" 1475 | "SIN" | "SIN_SAT" 1476 | "SCS" | "SCS_SAT" 1477 1478 <BINSCop_instruction> ::= <BINSCop> <maskedDstReg> "," 1479 <scalarSrcReg> "," <scalarSrcReg> 1480 1481 <BINSCop> ::= "POW" | "POW_SAT" 1482 1483 <BINop_instruction> ::= <BINop> <maskedDstReg> "," 1484 <vectorSrcReg> "," <vectorSrcReg> 1485 1486 <BINop> ::= "ADD" | "ADD_SAT" 1487 | "DP3" | "DP3_SAT" 1488 | "DP4" | "DP4_SAT" 1489 | "DPH" | "DPH_SAT" 1490 | "DST" | "DST_SAT" 1491 | "MAX" | "MAX_SAT" 1492 | "MIN" | "MIN_SAT" 1493 | "MUL" | "MUL_SAT" 1494 | "SGE" | "SGE_SAT" 1495 | "SLT" | "SLT_SAT" 1496 | "SUB" | "SUB_SAT" 1497 | "XPD" | "XPD_SAT" 1498 1499 <TRIop_instruction> ::= <TRIop> <maskedDstReg> "," 1500 <vectorSrcReg> "," <vectorSrcReg> "," 1501 <vectorSrcReg> 1502 1503 <TRIop> ::= "CMP" | "CMP_SAT" 1504 | "LRP" | "LRP_SAT" 1505 | "MAD" | "MAD_SAT" 1506 1507 <SWZ_instruction> ::= <SWZop> <maskedDstReg> "," 1508 <srcReg> "," <extendedSwizzle> 1509 1510 <SWZop> ::= "SWZ" | "SWZ_SAT" 1511 1512 <SAMPLE_instruction> ::= <SAMPLEop> <maskedDstReg> "," 1513 <vectorSrcReg> "," <texImageUnit> "," 1514 <texTarget> 1515 1516 <SAMPLEop> ::= "TEX" | "TEX_SAT" 1517 | "TXP" | "TXP_SAT" 1518 | "TXB" | "TXB_SAT" 1519 1520 <KIL_instruction> ::= "KIL" <vectorSrcReg> 1521 1522 <texImageUnit> ::= "texture" <optTexImageUnitNum> 1523 1524 <texTarget> ::= "1D" 1525 | "2D" 1526 | "3D" 1527 | "CUBE" 1528 | "RECT" 1529 1530 <optTexImageUnitNum> ::= "" 1531 | "[" <texImageUnitNum> "]" 1532 1533 <texImageUnitNum> ::= <integer> from 0 to 1534 MAX_TEXTURE_IMAGE_UNITS_ARB-1 1535 1536 <scalarSrcReg> ::= <optionalSign> <srcReg> <scalarSuffix> 1537 1538 <vectorSrcReg> ::= <optionalSign> <srcReg> <optionalSuffix> 1539 1540 <maskedDstReg> ::= <dstReg> <optionalMask> 1541 1542 <extendedSwizzle> ::= <xyzwExtendedSwizzle> 1543 | <rgbaExtendedSwizzle> 1544 1545 <xyzwExtendedSwizzle> ::= <xyzwExtSwizComp> "," <xyzwExtSwizComp> "," 1546 <xyzwExtSwizComp> "," <xyzwExtSwizComp> 1547 1548 <rgbaExtendedSwizzle> ::= <rgbaExtSwizComp> "," <rgbaExtSwizComp> "," 1549 <rgbaExtSwizComp> "," <rgbaExtSwizComp> 1550 1551 <xyzwExtSwizComp> ::= <optionalSign> <xyzwExtSwizSel> 1552 1553 <rgbaExtSwizComp> ::= <optionalSign> <rgbaExtSwizSel> 1554 1555 <xyzwExtSwizSel> ::= "0" 1556 | "1" 1557 | <xyzwComponent> 1558 1559 <rgbaExtSwizSel> ::= "0" 1560 | "1" 1561 | <rgbaComponent> 1562 1563 <srcReg> ::= <fragmentAttribReg> 1564 | <temporaryReg> 1565 | <progParamReg> 1566 1567 <dstReg> ::= <temporaryReg> 1568 | <fragmentResultReg> 1569 1570 <fragmentAttribReg> ::= <establishedName> 1571 | <fragAttribBinding> 1572 1573 <temporaryReg> ::= <establishedName> 1574 1575 <progParamReg> ::= <progParamSingle> 1576 | <progParamArray> "[" <progParamArrayAbs> "]" 1577 | <paramSingleItemUse> 1578 1579 <progParamSingle> ::= <establishedName> 1580 1581 <progParamArray> ::= <establishedName> 1582 1583 <progParamArrayAbs> ::= <integer> 1584 1585 <fragmentResultReg> ::= <establishedName> 1586 | <resultBinding> 1587 1588 <scalarSuffix> ::= "." <component> 1589 1590 <optionalSuffix> ::= "" 1591 | "." <component> 1592 | "." <xyzwComponent> <xyzwComponent> 1593 <xyzwComponent> <xyzwComponent> 1594 | "." <rgbaComponent> <rgbaComponent> 1595 <rgbaComponent> <rgbaComponent> 1596 1597 <component> ::= <xyzwComponent> 1598 | <rgbaComponent> 1599 1600 <xyzwComponent> ::= "x" | "y" | "z" | "w" 1601 1602 <rgbaComponent> ::= "r" | "g" | "b" | "a" 1603 1604 <optionalMask> ::= "" 1605 | <xyzwMask> 1606 | <rgbaMask> 1607 1608 <xyzwMask> ::= "." "x" 1609 | "." "y" 1610 | "." "xy" 1611 | "." "z" 1612 | "." "xz" 1613 | "." "yz" 1614 | "." "xyz" 1615 | "." "w" 1616 | "." "xw" 1617 | "." "yw" 1618 | "." "xyw" 1619 | "." "zw" 1620 | "." "xzw" 1621 | "." "yzw" 1622 | "." "xyzw" 1623 1624 <rgbaMask> ::= "." "r" 1625 | "." "g" 1626 | "." "rg" 1627 | "." "b" 1628 | "." "rb" 1629 | "." "gb" 1630 | "." "rgb" 1631 | "." "a" 1632 | "." "ra" 1633 | "." "ga" 1634 | "." "rga" 1635 | "." "ba" 1636 | "." "rba" 1637 | "." "gba" 1638 | "." "rgba" 1639 1640 <namingStatement> ::= <ATTRIB_statement> 1641 | <PARAM_statement> 1642 | <TEMP_statement> 1643 | <OUTPUT_statement> 1644 | <ALIAS_statement> 1645 1646 <ATTRIB_statement> ::= "ATTRIB" <establishName> "=" 1647 <fragAttribBinding> 1648 1649 <fragAttribBinding> ::= "fragment" "." <fragAttribItem> 1650 1651 <fragAttribItem> ::= "color" <optColorType> 1652 | "texcoord" <optTexCoordNum> 1653 | "fogcoord" 1654 | "position" 1655 1656 <PARAM_statement> ::= <PARAM_singleStmt> 1657 | <PARAM_multipleStmt> 1658 1659 <PARAM_singleStmt> ::= "PARAM" <establishName> <paramSingleInit> 1660 1661 <PARAM_multipleStmt> ::= "PARAM" <establishName> "[" <optArraySize> "]" 1662 <paramMultipleInit> 1663 1664 <optArraySize> ::= "" 1665 | <integer> from 1 to MAX_PROGRAM_PARAMETERS_ARB 1666 (maximum number of allowed program 1667 parameter bindings) 1668 1669 <paramSingleInit> ::= "=" <paramSingleItemDecl> 1670 1671 <paramMultipleInit> ::= "=" "{" <paramMultInitList> "}" 1672 1673 <paramMultInitList> ::= <paramMultipleItem> 1674 | <paramMultipleItem> "," <paramMultInitList> 1675 1676 <paramSingleItemDecl> ::= <stateSingleItem> 1677 | <programSingleItem> 1678 | <paramConstDecl> 1679 1680 <paramSingleItemUse> ::= <stateSingleItem> 1681 | <programSingleItem> 1682 | <paramConstUse> 1683 1684 <paramMultipleItem> ::= <stateMultipleItem> 1685 | <programMultipleItem> 1686 | <paramConstDecl> 1687 1688 <stateMultipleItem> ::= <stateSingleItem> 1689 | "state" "." <stateMatrixRows> 1690 1691 <stateSingleItem> ::= "state" "." <stateMaterialItem> 1692 | "state" "." <stateLightItem> 1693 | "state" "." <stateLightModelItem> 1694 | "state" "." <stateLightProdItem> 1695 | "state" "." <stateTexEnvItem> 1696 | "state" "." <stateFogItem> 1697 | "state" "." <stateDepthItem> 1698 | "state" "." <stateMatrixRow> 1699 1700 <stateMaterialItem> ::= "material" <optFaceType> "." <stateMatProperty> 1701 1702 <stateMatProperty> ::= "ambient" 1703 | "diffuse" 1704 | "specular" 1705 | "emission" 1706 | "shininess" 1707 1708 <stateLightItem> ::= "light" "[" <stateLightNumber> "]" "." 1709 <stateLightProperty> 1710 1711 <stateLightProperty> ::= "ambient" 1712 | "diffuse" 1713 | "specular" 1714 | "position" 1715 | "attenuation" 1716 | "spot" "." <stateSpotProperty> 1717 | "half" 1718 1719 <stateSpotProperty> ::= "direction" 1720 1721 <stateLightModelItem> ::= "lightmodel" <stateLModProperty> 1722 1723 <stateLModProperty> ::= "." "ambient" 1724 | <optFaceType> "." "scenecolor" 1725 1726 <stateLightProdItem> ::= "lightprod" "[" <stateLightNumber> "]" 1727 <optFaceType> "." <stateLProdProperty> 1728 1729 <stateLProdProperty> ::= "ambient" 1730 | "diffuse" 1731 | "specular" 1732 1733 <stateLightNumber> ::= <integer> from 0 to MAX_LIGHTS-1 1734 1735 <stateTexEnvItem> ::= "texenv" <optLegacyTexUnitNum> "." 1736 <stateTexEnvProperty> 1737 1738 <stateTexEnvProperty> ::= "color" 1739 1740 <optLegacyTexUnitNum> ::= "" 1741 | "[" <legacyTexUnitNum> "]" 1742 1743 <legacyTexUnitNum> ::= <integer> from 0 to MAX_TEXTURE_UNITS-1 1744 1745 <stateFogItem> ::= "fog" "." <stateFogProperty> 1746 1747 <stateFogProperty> ::= "color" 1748 | "params" 1749 1750 <stateDepthItem> ::= "depth" "." <stateDepthProperty> 1751 1752 <stateDepthProperty> ::= "range" 1753 1754 <stateMatrixRow> ::= <stateMatrixItem> "." "row" "[" 1755 <stateMatrixRowNum> "]" 1756 1757 <stateMatrixRows> ::= <stateMatrixItem> <optMatrixRows> 1758 1759 <optMatrixRows> ::= "" 1760 | "." "row" "[" <stateMatrixRowNum> ".." 1761 <stateMatrixRowNum> "]" 1762 1763 <stateMatrixItem> ::= "matrix" "." <stateMatrixName> 1764 <stateOptMatModifier> 1765 1766 <stateOptMatModifier> ::= "" 1767 | "." <stateMatModifier> 1768 1769 <stateMatModifier> ::= "inverse" 1770 | "transpose" 1771 | "invtrans" 1772 1773 <stateMatrixRowNum> ::= <integer> from 0 to 3 1774 1775 <stateMatrixName> ::= "modelview" <stateOptModMatNum> 1776 | "projection" 1777 | "mvp" 1778 | "texture" <optTexCoordNum> 1779 | "palette" "[" <statePaletteMatNum> "]" 1780 | "program" "[" <stateProgramMatNum> "]" 1781 1782 <stateOptModMatNum> ::= "" 1783 | "[" <stateModMatNum> "]" 1784 1785 <stateModMatNum> ::= <integer> from 0 to MAX_VERTEX_UNITS_ARB-1 1786 1787 <optTexCoordNum> ::= "" 1788 | "[" <texCoordNum> "]" 1789 1790 <texCoordNum> ::= <integer> from 0 to MAX_TEXTURE_COORDS_ARB-1 1791 1792 <statePaletteMatNum> ::= <integer> from 0 to MAX_PALETTE_MATRICES_ARB-1 1793 1794 <stateProgramMatNum> ::= <integer> from 0 to MAX_PROGRAM_MATRICES_ARB-1 1795 1796 <programSingleItem> ::= <progEnvParam> 1797 | <progLocalParam> 1798 1799 <programMultipleItem> ::= <progEnvParams> 1800 | <progLocalParams> 1801 1802 <progEnvParams> ::= "program" "." "env" 1803 "[" <progEnvParamNums> "]" 1804 1805 <progEnvParamNums> ::= <progEnvParamNum> 1806 | <progEnvParamNum> ".." <progEnvParamNum> 1807 1808 <progEnvParam> ::= "program" "." "env" 1809 "[" <progEnvParamNum> "]" 1810 1811 <progLocalParams> ::= "program" "." "local" 1812 "[" <progLocalParamNums> "]" 1813 1814 <progLocalParamNums> ::= <progLocalParamNum> 1815 | <progLocalParamNum> ".." <progLocalParamNum> 1816 1817 <progLocalParam> ::= "program" "." "local" 1818 "[" <progLocalParamNum> "]" 1819 1820 <progEnvParamNum> ::= <integer> from 0 to 1821 MAX_PROGRAM_ENV_PARAMETERS_ARB - 1 1822 1823 <progLocalParamNum> ::= <integer> from 0 to 1824 MAX_PROGRAM_LOCAL_PARAMETERS_ARB - 1 1825 1826 <paramConstDecl> ::= <paramConstScalarDecl> 1827 | <paramConstVector> 1828 1829 <paramConstUse> ::= <paramConstScalarUse> 1830 | <paramConstVector> 1831 1832 <paramConstScalarDecl> ::= <signedFloatConstant> 1833 1834 <paramConstScalarUse> ::= <floatConstant> 1835 1836 <paramConstVector> ::= "{" <signedFloatConstant> "}" 1837 | "{" <signedFloatConstant> "," 1838 <signedFloatConstant> "}" 1839 | "{" <signedFloatConstant> "," 1840 <signedFloatConstant> "," 1841 <signedFloatConstant> "}" 1842 | "{" <signedFloatConstant> "," 1843 <signedFloatConstant> "," 1844 <signedFloatConstant> "," 1845 <signedFloatConstant> "}" 1846 1847 <signedFloatConstant> ::= <optionalSign> <floatConstant> 1848 1849 <floatConstant> ::= see text 1850 1851 <optionalSign> ::= "" 1852 | "-" 1853 | "+" 1854 1855 <TEMP_statement> ::= "TEMP" <varNameList> 1856 1857 <varNameList> ::= <establishName> 1858 | <establishName> "," <varNameList> 1859 1860 <OUTPUT_statement> ::= "OUTPUT" <establishName> "=" 1861 <resultBinding> 1862 1863 <resultBinding> ::= "result" "." "color" 1864 | "result" "." "depth" 1865 1866 <optFaceType> ::= "" 1867 | "." "front" 1868 | "." "back" 1869 1870 <optColorType> ::= "" 1871 | "." "primary" 1872 | "." "secondary" 1873 1874 <ALIAS_statement> ::= "ALIAS" <establishName> "=" 1875 <establishedName> 1876 1877 <establishName> ::= <identifier> 1878 1879 <establishedName> ::= <identifier> 1880 1881 <identifier> ::= see text 1882 1883 The <integer> rule matches an integer constant. The integer 1884 consists of a sequence of one or more digits ("0" through "9"). 1885 1886 The <floatConstant> rule matches a floating-point constant 1887 consisting of an integer part, a decimal point, a fraction part, an 1888 "e" or "E", and an optionally signed integer exponent. The integer 1889 and fraction parts both consist of a sequence of one or more digits 1890 ("0" through "9"). Either the integer part or the fraction parts 1891 (not both) may be missing; either the decimal point or the "e" (or 1892 "E") and the exponent (not both) may be missing. 1893 1894 The <identifier> rule matches a sequence of one or more letters ("A" 1895 through "Z", "a" through "z"), digits ("0" through "9), underscores 1896 ("_"), or dollar signs ("$"); the first character must not be a 1897 number. Upper and lower case letters are considered different 1898 (names are case-sensitive). The following strings are reserved 1899 keywords and may not be used as identifiers: 1900 1901 ABS, ABS_SAT, ADD, ADD_SAT, ALIAS, ATTRIB, CMP, CMP_SAT, COS, 1902 COS_SAT, DP3, DP3_SAT, DP4, DP4_SAT, DPH, DPH_SAT, DST, DST_SAT, 1903 END, EX2, EX2_SAT, FLR, FLR_SAT, FRC, FRC_SAT, KIL, LG2, 1904 LG2_SAT, LIT, LIT_SAT, LRP, LRP_SAT, MAD, MAD_SAT, MAX, MAX_SAT, 1905 MIN, MIN_SAT, MOV, MOV_SAT, MUL, MUL_SAT, OPTION, OUTPUT, PARAM, 1906 POW, POW_SAT, RCP, RCP_SAT, RSQ, RSQ_SAT, SIN, SIN_SAT, SCS, 1907 SCS_SAT, SGE, SGE_SAT, SLT, SLT_SAT, SUB, SUB_SAT, SWZ, SWZ_SAT, 1908 TEMP, TEX, TEX_SAT, TXB, TXB_SAT, TXP, TXP_SAT, XPD, XPD_SAT, 1909 fragment, program, result, state, and texture. 1910 1911 The error INVALID_OPERATION is generated if a fragment program fails 1912 to load because it is not syntactically correct or for one of the 1913 semantic restrictions described in the following sections. 1914 1915 A successfully loaded fragment program is parsed into a sequence of 1916 instructions. Each instruction is identified by its tokenized name. 1917 The operation of these instructions when executed is defined in 1918 section 3.11.5. 1919 1920 A successfully loaded program string replaces the program string 1921 previously loaded into the specified program object. If the 1922 OUT_OF_MEMORY error is generated by ProgramStringARB, no change is 1923 made to the previous contents of the current program object. 1924 1925 1926 3.11.3 Fragment Program Variables 1927 1928 Fragment programs may access a number of different variables during 1929 their execution. The following sections define the variables that 1930 can be declared and used by a fragment program. 1931 1932 Explicit variable declarations allow a fragment program to establish 1933 a variable name that can be used to refer to a specified resource in 1934 subsequent instructions. A fragment program will fail to load if it 1935 declares the same variable name more than once or if it refers to a 1936 variable name that has not been previously declared in the program 1937 string. 1938 1939 Implicit variable declarations allow a fragment program to use the 1940 name of certain available resources by name. 1941 1942 1943 3.11.3.1 Fragment Attributes 1944 1945 Fragment program attribute variables are a set of four-component 1946 floating-point vectors holding the attributes of the fragment being 1947 processed. Fragment attribute variables are read-only during 1948 fragment program execution. 1949 1950 Fragment attribute variables can be declared explicitly using the 1951 <ATTRIB_statement> grammar rule, or implicitly using the 1952 <fragAttribBinding> grammar rule in an executable instruction. 1953 1954 Each fragment attribute variable is bound to a single item of 1955 fragment state according to the <fragAttrBinding> grammar rule. The 1956 set of GL state that can be bound to a fragment attribute variable 1957 is given in Table X.1. Fragment attribute variables are initialized 1958 at each fragment program invocation with the current values of the 1959 bound state. 1960 1961 Fragment Attribute Binding Components Underlying State 1962 -------------------------- ---------- ---------------------------- 1963 fragment.color (r,g,b,a) primary color 1964 fragment.color.primary (r,g,b,a) primary color 1965 fragment.color.secondary (r,g,b,a) secondary color 1966 fragment.texcoord (s,t,r,q) texture coordinate, unit 0 1967 fragment.texcoord[n] (s,t,r,q) texture coordinate, unit n 1968 fragment.fogcoord (f,0,0,1) fog distance/coordinate 1969 fragment.position (x,y,z,1/w) window position 1970 1971 Table X.1: Fragment Attribute Bindings. The "Components" column 1972 indicates the mapping of the state in the "Underlying State" 1973 column. Bindings containing "[n]" require an integer value of <n> 1974 to select an individual item. 1975 1976 If a fragment attribute binding matches "fragment.color" or 1977 "fragment.color.primary", the "x", "y", "z", and "w" components of 1978 the fragment attribute variable are filled with the "r", "g", "b", 1979 and "a" components, respectively, of the fragment color. Each 1980 fixed-point color component undergoes an implied conversion to 1981 floating point. This conversion must leave the values 0 and 1 1982 invariant. 1983 1984 If a fragment attribute binding matches "fragment.color.secondary", 1985 the "x", "y", "z", and "w" components of the fragment attribute 1986 variable are filled with the "r", "g", "b", and "a" components, 1987 respectively, of the fragment secondary color. Each fixed-point 1988 color component undergoes an implied conversion to floating point. 1989 This conversion must leave the values 0 and 1 invariant. 1990 1991 If a fragment attribute binding matches "fragment.texcoord" or 1992 "fragment.texcoord[n]", the "x", "y", "z", and "w" components of the 1993 fragment attribute variable are filled with the "s", "t", "r", and 1994 "q" components, respectively, of the fragment texture coordinates 1995 for texture unit <n>. If "[n]" is omitted, texture unit zero is 1996 used. 1997 1998 If a fragment attribute binding matches "fragment.fogcoord", the "x" 1999 component of the fragment attribute variable is filled with either 2000 the fragment eye distance or the fog coordinate, depending on 2001 whether the fog source is set to FRAGMENT_DEPTH_EXT or 2002 FOG_COORDINATE_EXT, respectively. The "y", "z", and "w" coordinates 2003 are filled with 0, 0, and 1, respectively. 2004 2005 If a fragment attribute binding matches "fragment.position", the "x" 2006 and "y" components of the fragment attribute variable are filled 2007 with the (x,y) window coordinates of the fragment center, relative 2008 to the lower left corner of the window. The "z" component is filled 2009 with the fragment's z window coordinate. This z window coordinate 2010 undergoes an implied conversion to floating point. This conversion 2011 must leave the values 0 and 1 invariant. The "w" component is 2012 filled with the reciprocal of the fragment's clip w coordinate. 2013 2014 On some implementations, the components of fragment.position may be 2015 generated by interpolating per-vertex position values. This may 2016 produce x and y window coordinates that don't exactly match those of 2017 the fragment center and z window coordinates that do not exactly 2018 match those generated by fixed-function rasterization. Therefore, 2019 there is no guaranteed invariance between the final z window 2020 coordinates of fragments processed by fragment programs that write 2021 depth values and fragments processed by any other means, even if the 2022 fragment programs in question simply copy the z value from the 2023 fragment.position binding. 2024 2025 2026 3.11.3.2 Fragment Program Parameters 2027 2028 Fragment program parameter variables are a set of four-component 2029 floating-point vectors used as constants during fragment program 2030 execution. Fragment program parameters retain their values across 2031 fragment program invocations, although their values can change 2032 between invocations due to GL state changes. 2033 2034 Single program parameter variables and arrays of program parameter 2035 variables can be declared explicitly using the <PARAM_statement> 2036 grammar rule. Single program parameter variables can also be 2037 declared implicitly using the <paramSingleItemUse> grammar rule in 2038 an executable instruction. 2039 2040 Each single program parameter variable is bound to a constant vector 2041 or to a GL state vector according to the <paramSingleInit> grammar 2042 rule. Individual items of a program parameter array are bound to 2043 constant vectors or GL state vectors according to the 2044 <programMultipleInit> grammar rule. The set of GL state that can be 2045 bound to program parameter variables are given in Tables X.2.1 2046 through X.2.4. 2047 2048 2049 Constant Bindings 2050 2051 A program parameter variable can be bound to a scalar or vector 2052 constant using the <paramConstDecl> grammar rule (explicit 2053 declarations) or the <paramConstUse> grammar rule (implicit 2054 declarations). 2055 2056 If a program parameter binding matches the <paramConstScalarDecl> or 2057 <paramConstScalarUse> grammar rules, the corresponding program 2058 parameter variable is bound to the vector (X,X,X,X), where X is the 2059 value of the specified constant. Note that the 2060 <paramConstScalarUse> grammar rule, used only in implicit 2061 declarations, allows only non-negative constants. This 2062 disambiguates cases like "-2", which could conceivably be taken to 2063 mean either the vector "(2,2,2,2)" with all components negated or 2064 "(-2,-2,-2,-2)" without negation. Only the former interpretation is 2065 allowed by the grammar. 2066 2067 If a program parameter binding matches <paramConstVector>, the 2068 corresponding program parameter variable is bound to the vector 2069 (X,Y,Z,W), where X, Y, Z, and W are the values corresponding to the 2070 first, second, third, and fourth match of <signedFloatConstant>. If 2071 fewer than four constants are specified, Y, Z, and W assume the 2072 values 0.0, 0.0, and 1.0, if their respective constants are not 2073 specified. 2074 2075 Program parameter variables initialized to constant values can never 2076 be modified. 2077 2078 2079 Program Environment/Local Parameter Bindings 2080 2081 Binding Components Underlying State 2082 ----------------------------- ---------- ---------------------------- 2083 program.env[a] (x,y,z,w) program environment 2084 parameter a 2085 program.local[a] (x,y,z,w) program local parameter a 2086 program.env[a..b] (x,y,z,w) program environment 2087 parameters a through b 2088 program.local[a..b] (x,y,z,w) program local parameters 2089 a through b 2090 2091 Table X.2.1: Program Environment/Local Parameter Bindings. <a> 2092 and <b> indicate parameter numbers, where <a> must be less than or 2093 equal to <b>. 2094 2095 If a program parameter binding matches "program.env[a]" or 2096 "program.local[a]", the four components of the program parameter 2097 variable are filled with the four components of program environment 2098 parameter <a> or program local parameter <a>, respectively. 2099 2100 Additionally, for program parameter array bindings, 2101 "program.env[a..b]" and "program.local[a..b]" are equivalent to 2102 specifying program environment parameters <a> through <b> in order 2103 or program local parameters <a> through <b> in order, respectively. 2104 In either case, a program will fail to load if <a> is greater than 2105 <b>. 2106 2107 2108 Material Property Bindings 2109 2110 Binding Components Underlying State 2111 ----------------------------- ---------- ---------------------------- 2112 state.material.ambient (r,g,b,a) front ambient material color 2113 state.material.diffuse (r,g,b,a) front diffuse material color 2114 state.material.specular (r,g,b,a) front specular material color 2115 state.material.emission (r,g,b,a) front emissive material color 2116 state.material.shininess (s,0,0,1) front material shininess 2117 state.material.front.ambient (r,g,b,a) front ambient material color 2118 state.material.front.diffuse (r,g,b,a) front diffuse material color 2119 state.material.front.specular (r,g,b,a) front specular material color 2120 state.material.front.emission (r,g,b,a) front emissive material color 2121 state.material.front.shininess (s,0,0,1) front material shininess 2122 state.material.back.ambient (r,g,b,a) back ambient material color 2123 state.material.back.diffuse (r,g,b,a) back diffuse material color 2124 state.material.back.specular (r,g,b,a) back specular material color 2125 state.material.back.emission (r,g,b,a) back emissive material color 2126 state.material.back.shininess (s,0,0,1) back material shininess 2127 2128 Table X.2.2: Material Property Bindings. If a material face is 2129 not specified in the binding, the front property is used. 2130 2131 If a program parameter binding matches any of the material 2132 properties listed in Table X.2.2, the program parameter variable is 2133 filled according to the table. For ambient, diffuse, specular, or 2134 emissive colors, the "x", "y", "z", and "w" components are filled 2135 with the "r", "g", "b", and "a" components, respectively, of the 2136 corresponding material color. For material shininess, the "x" 2137 component is filled with the material's specular exponent, and the 2138 "y", "z", and "w" components are filled with 0, 0, and 1, 2139 respectively. Bindings containing ".back" refer to the back 2140 material; all other bindings refer to the front material. 2141 2142 Material properties can be changed inside a Begin/End pair, either 2143 directly by calling Material, or indirectly through color material. 2144 However, such property changes are not guaranteed to update program 2145 parameter bindings until the following End command. Program 2146 parameter variables bound to material properties changed inside a 2147 Begin/End pair are undefined until the following End command. 2148 2149 2150 Light Property Bindings 2151 2152 Binding Components Underlying State 2153 ----------------------------- ---------- ---------------------------- 2154 state.light[n].ambient (r,g,b,a) light n ambient color 2155 state.light[n].diffuse (r,g,b,a) light n diffuse color 2156 state.light[n].specular (r,g,b,a) light n specular color 2157 state.light[n].position (x,y,z,w) light n position 2158 state.light[n].attenuation (a,b,c,e) light n attenuation constants 2159 and spot light exponent 2160 state.light[n].spot.direction (x,y,z,c) light n spot direction and 2161 cutoff angle cosine 2162 state.light[n].half (x,y,z,1) light n infinite half-angle 2163 state.lightmodel.ambient (r,g,b,a) light model ambient color 2164 state.lightmodel.scenecolor (r,g,b,a) light model front scene color 2165 state.lightmodel . (r,g,b,a) light model front scene color 2166 front.scenecolor 2167 state.lightmodel . (r,g,b,a) light model back scene color 2168 back.scenecolor 2169 state.lightprod[n].ambient (r,g,b,a) light n / front material 2170 ambient color product 2171 state.lightprod[n].diffuse (r,g,b,a) light n / front material 2172 diffuse color product 2173 state.lightprod[n].specular (r,g,b,a) light n / front material 2174 specular color product 2175 state.lightprod[n]. (r,g,b,a) light n / front material 2176 front.ambient ambient color product 2177 state.lightprod[n]. (r,g,b,a) light n / front material 2178 front.diffuse diffuse color product 2179 state.lightprod[n]. (r,g,b,a) light n / front material 2180 front.specular specular color product 2181 state.lightprod[n]. (r,g,b,a) light n / back material 2182 back.ambient ambient color product 2183 state.lightprod[n]. (r,g,b,a) light n / back material 2184 back.diffuse diffuse color product 2185 state.lightprod[n]. (r,g,b,a) light n / back material 2186 back.specular specular color product 2187 2188 Table X.2.3: Light Property Bindings. <n> indicates a light 2189 number. 2190 2191 If a program parameter binding matches "state.light[n].ambient", 2192 "state.light[n].diffuse", or "state.light[n].specular", the "x", 2193 "y", "z", and "w" components of the program parameter variable are 2194 filled with the "r", "g", "b", and "a" components, respectively, of 2195 the corresponding light color. 2196 2197 If a program parameter binding matches "state.light[n].position", 2198 the "x", "y", "z", and "w" components of the program parameter 2199 variable are filled with the "x", "y", "z", and "w" components, 2200 respectively, of the light position. 2201 2202 If a program parameter binding matches "state.light[n].attenuation", 2203 the "x", "y", and "z" components of the program parameter variable 2204 are filled with the constant, linear, and quadratic attenuation 2205 parameters of the specified light, respectively (section 2.13.1). 2206 The "w" component of the program parameter variable is filled with 2207 the spot light exponent of the specified light. 2208 2209 If a program parameter binding matches 2210 "state.light[n].spot.direction", the "x", "y", and "z" components of 2211 the program parameter variable are filled with the "x", "y", and "z" 2212 components of the spot light direction of the specified light, 2213 respectively (section 2.13.1). The "w" component of the program 2214 parameter variable is filled with the cosine of the spot light 2215 cutoff angle of the specified light. 2216 2217 If a program parameter binding matches "state.light[n].half", the 2218 "x", "y", and "z" components of the program parameter variable are 2219 filled with the x, y, and z components, respectively, of the 2220 normalized infinite half-angle vector 2221 2222 h_inf = || P + (0, 0, 1) ||. 2223 2224 The "w" component is filled with 1. In the computation of h_inf, P 2225 consists of the x, y, and z coordinates of the normalized vector 2226 from the eye position P_e to the eye-space light position P_pli 2227 (section 2.13.1). h_inf is defined to correspond to the normalized 2228 half-angle vector when using an infinite light (w coordinate of the 2229 position is zero) and an infinite viewer (v_bs is FALSE). For local 2230 lights or a local viewer, h_inf is well-defined but does not match 2231 the normalized half-angle vector, which will vary depending on the 2232 vertex position. 2233 2234 If a program parameter binding matches "state.lightmodel.ambient", 2235 the "x", "y", "z", and "w" components of the program parameter 2236 variable are filled with the "r", "g", "b", and "a" components of 2237 the light model ambient color, respectively. 2238 2239 If a program parameter binding matches "state.lightmodel.scenecolor" 2240 or "state.lightmodel.front.scenecolor", the "x", "y", and "z" 2241 components of the program parameter variable are filled with the 2242 "r", "g", and "b" components respectively of the "front scene color" 2243 2244 c_scene = a_cs * a_cm + e_cm, 2245 2246 where a_cs is the light model ambient color, a_cm is the front 2247 ambient material color, and e_cm is the front emissive material 2248 color. The "w" component of the program parameter variable is 2249 filled with the alpha component of the front diffuse material color. 2250 If a program parameter binding matches 2251 "state.lightmodel.back.scenecolor", a similar back scene color, 2252 computed using back-facing material properties, is used. The front 2253 and back scene colors match the values that would be assigned to 2254 vertices using conventional lighting if all lights were disabled. 2255 2256 If a program parameter binding matches anything beginning with 2257 "state.lightprod[n]", the "x", "y", and "z" components of the 2258 program parameter variable are filled with the "r", "g", and "b" 2259 components, respectively, of the corresponding light product. The 2260 three light product components are the products of the corresponding 2261 color components of the specified material property and the light 2262 color of the specified light (see Table X.2.3). The "w" component 2263 of the program parameter variable is filled with the alpha component 2264 of the specified material property. 2265 2266 Light products depend on material properties, which can be changed 2267 inside a Begin/End pair. Such property changes are not guaranteed 2268 to take effect until the following End command. Program parameter 2269 variables bound to light products whose corresponding material 2270 property changes inside a Begin/End pair are undefined until the 2271 following End command. 2272 2273 2274 Texture Environment Property Bindings 2275 2276 Binding Components Underlying State 2277 ------------------------- ---------- ---------------------------- 2278 state.texenv[n].color (r,g,b,a) texture environment n color 2279 2280 Table X.2.4: Texture Environment Property Bindings. "[n]" is 2281 optional -- texture unit <n> is used if specified; texture unit 0 2282 is used otherwise. 2283 2284 If a program parameter binding matches "state.texenv[n].color", the 2285 "x", "y", "z", and "w" components of the program parameter variable 2286 are filled with the "r", "g", "b", and "a" components, respectively, 2287 of the corresponding texture environment color. Note that only 2288 "legacy" texture units, as queried by MAX_TEXTURE_UNITS, include 2289 texture environment state. Texture image units and texture 2290 coordinate sets do not have associated texture environment state. 2291 2292 2293 Fog Property Bindings 2294 2295 Binding Components Underlying State 2296 --------------------------- ---------- ---------------------------- 2297 state.fog.color (r,g,b,a) RGB fog color (section 3.11) 2298 state.fog.params (d,s,e,r) fog density, linear start 2299 and end, and 1/(end-start) 2300 (section 3.11) 2301 2302 Table X.2.5: Fog Property Bindings 2303 2304 If a program parameter binding matches "state.fog.color", the "x", 2305 "y", "z", and "w" components of the program parameter variable are 2306 filled with the "r", "g", "b", and "a" components, respectively, of 2307 the fog color (section 3.11). 2308 2309 If a program parameter binding matches "state.fog.params", the "x", 2310 "y", and "z" components of the program parameter variable are filled 2311 with the fog density, linear fog start, and linear fog end 2312 parameters (section 3.11), respectively. The "w" component is 2313 filled with 1/(end-start), where end and start are the linear fog 2314 end and start parameters, respectively. 2315 2316 2317 Depth Property Bindings 2318 2319 Binding Components Underlying State 2320 --------------------------- ---------- ---------------------------- 2321 state.depth.range (n,f,d,1) Depth range near, far, and 2322 (far-near) (section 2.10.1) 2323 2324 Table X.2.6: Depth Property Bindings 2325 2326 If a program parameter binding matches "state.depth.range", the "x" 2327 and "y" components of the program parameter variable are filled with 2328 the mappings of near and far clipping planes to window coordinates, 2329 respectively. The "z" component is filled with the difference of 2330 the mappings of near and far clipping planes, far minus near. The 2331 "w" component is filled with 1. 2332 2333 2334 Matrix Property Bindings 2335 2336 Binding Underlying State 2337 ------------------------------------ --------------------------- 2338 * state.matrix.modelview[n] modelview matrix n 2339 state.matrix.projection projection matrix 2340 state.matrix.mvp modelview-projection matrix 2341 * state.matrix.texture[n] texture matrix n 2342 state.matrix.palette[n] modelview palette matrix n 2343 state.matrix.program[n] program matrix n 2344 2345 Table X.2.7: Base Matrix Property Bindings. The "[n]" syntax 2346 indicates a specific matrix number. For modelview and texture 2347 matrices, a matrix number is optional, and matrix zero will be 2348 used if the matrix number is omitted. These base bindings may 2349 further be modified by a inverse/transpose selector and a row 2350 selector. 2351 2352 If the beginning of a program parameter binding matches any of the 2353 matrix binding names listed in Table X.2.7, the binding corresponds 2354 to a 4x4 matrix. If the parameter binding is followed by 2355 ".inverse", ".transpose", or ".invtrans" (<stateMatModifier> grammar 2356 rule), the inverse, transpose, or transpose of the inverse, 2357 respectively, of the matrix specified in Table X.2.7 is selected. 2358 Otherwise, the matrix specified in Table X.2.7 is selected. If the 2359 specified matrix is poorly-conditioned (singular or nearly so), its 2360 inverse matrix is undefined. The binding name "state.matrix.mvp" 2361 refers to the product of modelview matrix zero and the projection 2362 matrix, defined as 2363 2364 MVP = P * M0, 2365 2366 where P is the projection matrix and M0 is modelview matrix zero. 2367 2368 If the selected matrix is followed by ".row[<a>]" (matching the 2369 <stateMatrixRow> grammar rule), the "x", "y", "z", and "w" 2370 components of the program parameter variable are filled with the 2371 four entries of row <a> of the selected matrix. In the example, 2372 2373 PARAM m0 = state.matrix.modelview[1].row[0]; 2374 PARAM m1 = state.matrix.projection.transpose.row[3]; 2375 2376 the variable "m0" is set to the first row (row 0) of modelview 2377 matrix 1 and "m1" is set to the last row (row 3) of the transpose of 2378 the projection matrix. 2379 2380 For program parameter array bindings, multiple rows of the selected 2381 matrix can be bound via the <stateMatrixRows> grammar rule. If the 2382 selected matrix binding is followed by ".row[<a>..<b>]", the result 2383 is equivalent to specifying matrix rows <a> through <b>, in order. 2384 A program will fail to load if <a> is greater than <b>. If no row 2385 selection is specified (<optMatrixRows> matches ""), matrix rows 0 2386 through 3 are bound in order. In the example, 2387 2388 PARAM m2[] = { state.matrix.program[0].row[1..2] }; 2389 PARAM m3[] = { state.matrix.program[0].transpose }; 2390 2391 the array "m2" has two entries, containing rows 1 and 2 of program 2392 matrix zero, and "m3" has four entries, containing all four rows of 2393 the transpose of program matrix zero. 2394 2395 2396 Program Parameter Arrays 2397 2398 A program parameter array variable can be declared explicitly by 2399 matching the <PARAM_multipleStmt> grammar rule. Programs can 2400 optionally specify the number of individual program parameters in 2401 the array, using the <optArraySize> grammar rule. Program parameter 2402 arrays may not be declared implicity. 2403 2404 Individual parameter variables in a program parameter array are 2405 bound to GL state vectors or constant vectors as specified by the 2406 grammar rule <paramMultInitList>. Each individual parameter in the 2407 array is bound in turn as described above. 2408 2409 The total number of entries in the array is equal to the number of 2410 parameters bound in the initializer list. A fragment program that 2411 specifies an array size (<optArraySize> matches <integer>) that does 2412 not match the number of parameter bindings in the initialization 2413 list will fail to load. 2414 2415 Program parameter array variables may only be accessed using 2416 absolute addressing by matching the <progParamArrayAbs> grammar 2417 rule. Array accesses are checked against the limits of the array. 2418 If any fragment program instruction accesses a program parameter 2419 array with an out-of-range index (greater than or equal to the size 2420 of the array), the fragment program will fail to load. 2421 2422 Individual state vectors can have no more than one unique binding in 2423 any given program. The GL will automatically combine multiple 2424 bindings of the same state vector into a single unique binding. 2425 2426 2427 3.11.3.3 Fragment Program Temporaries 2428 2429 Fragment program temporary variables are a set of four-component 2430 floating-point vectors used to hold temporary results during 2431 fragment program execution. Temporaries do not persist between 2432 program invocations, and are undefined at the beginning of each 2433 fragment program invocation. 2434 2435 Fragment program temporary variables can be declared explicitly 2436 using the <TEMP_statement> grammar rule. Each such statement can 2437 declare one or more temporaries. Fragment program temporary 2438 variables can not be declared implicitly. 2439 2440 2441 3.11.3.4 Fragment Program Results 2442 2443 Fragment program result variables are a set of four component 2444 floating-point vectors used to hold the final results of a fragment 2445 program. Fragment program result variables are write-only during 2446 fragment program execution. 2447 2448 Fragment program result variables can be declared explicitly using 2449 the <OUTPUT_statement> grammar rule, or implicitly using the 2450 <resultBinding> grammar rule in an executable instruction. Each 2451 fragment program result variable is bound to a fragment attribute 2452 used in subsequent back-end processing. The set of fragment program 2453 result variable bindings is given in Table X.3. 2454 2455 Binding Components Description 2456 ----------------------------- ---------- ---------------------------- 2457 result.color (r,g,b,a) color 2458 result.depth (*,*,d,*) depth coordinate 2459 2460 Table X.3: Fragment Result Variable Bindings. Components labeled 2461 "*" are unused. 2462 2463 If a result variable binding matches "result.color", updates to the 2464 "x", "y", "z", and "w" components of the result variable modify the 2465 "r", "g", "b", and "a" components, respectively, of the fragment's 2466 output color. If "result.color" is not both bound by the fragment 2467 program and written by some instruction of the program, the output 2468 color of the fragment program is undefined. 2469 2470 If a result variable binding matches "result.depth", updates to the 2471 "z" component of the result variable modify the fragment's output 2472 depth value. If "result.depth" is not both bound by the fragment 2473 program and written by some instruction of the program, the 2474 interpolated depth value produced by rasterization is used as if 2475 fragment program mode is not enabled. Writes to any component of 2476 depth other than the "z" component have no effect. 2477 2478 2479 3.11.3.5 Fragment Program Aliases 2480 2481 Fragment programs can create aliases by matching the 2482 <ALIAS_statement> grammar rule. Aliases allow programs to use 2483 multiple variable names to refer to a single underlying variable. 2484 For example, the statement 2485 2486 ALIAS var1 = var0 2487 2488 establishes a variable name named "var1". Subsequent references to 2489 "var1" in the program text are treated as references to "var0". The 2490 left hand side of an ALIAS statement must be a new variable name, 2491 and the right hand side must be an established variable name. 2492 2493 Aliases are not considered variable declarations, so do not count 2494 against the limits on the number of variable declarations allowed in 2495 the program text. 2496 2497 2498 3.11.3.6 Fragment Program Resource Limits 2499 2500 The fragment program execution environment provides implementation- 2501 dependent resource limits on the number of ALU instructions, texture 2502 instructions, total instructions (ALU or texture), temporary 2503 variable declarations, program parameter bindings, or texture 2504 indirections. A program that exceeds any of these resource limits 2505 will fail to load. The resource limits for fragment programs can be 2506 queried by calling GetProgramiv (section 6.1.12) with a target of 2507 FRAGMENT_PROGRAM_ARB. 2508 2509 The limit on fragment program ALU instructions can be queried with 2510 a <pname> of MAX_PROGRAM_ALU_INSTRUCTIONS_ARB, and must be at least 2511 48. Each ALU instruction in the program (matches of the 2512 <ALUInstruction> grammar rule) counts against this limit. 2513 2514 The limit on fragment program texture instructions can be queried 2515 with a <pname> of MAX_PROGRAM_TEX_INSTRUCTIONS_ARB, and must be at 2516 least 24. Each texture instruction in the program (matches of the 2517 <TexInstruction> grammar rule) counts against this limit. 2518 2519 The limit on fragment program total instructions can be queried with 2520 a <pname> of MAX_PROGRAM_INSTRUCTIONS_ARB, and must be at least 72. 2521 Each instruction in the program (matching the <instruction> grammar 2522 rule) counts against this limit. Note that the limit on total 2523 instructions is not necessarily equal to the sum of the limits on 2524 ALU instructions and texture instructions. 2525 2526 The limit on fragment program texture indirections can be queried 2527 with a <pname> of MAX_PROGRAM_TEX_INDIRECTIONS_ARB, and must be at 2528 least 4. Texture indirections are described in 3.11.6. If an 2529 implementation has no limit on texture indirections, the limit will 2530 be equal to the limit on texture instructions. 2531 2532 The limit on fragment program temporary variable declarations can be 2533 queried with a <pname> of MAX_PROGRAM_TEMPORARIES_ARB, and must be at 2534 least 16. Each temporary declared in the program, using the 2535 <TEMP_statement> grammar rule, counts against this limit. Aliases 2536 of declared temporaries do not. 2537 2538 The limit on fragment program attribute bindings can be queried with 2539 a <pname> of MAX_PROGRAM_ATTRIBS_ARB and must be at least 10. Each 2540 distinct vertex attribute bound explicitly or implicitly in the 2541 program counts against this limit; vertex attributes bound multiple 2542 times count only once. 2543 2544 The limit on fragment program parameter bindings can be queried with 2545 a <pname> of MAX_PROGRAM_PARAMETERS_ARB, and must be at least 24. 2546 Each distinct GL state vector bound explicitly or implicitly in the 2547 program counts against this limit; GL state vectors bound multiple 2548 times count only once. Every other constant vector bound in the 2549 program is counted if and only if an identical constant vector has 2550 not already been counted. Two constant vectors are considered 2551 identical if the four component values are numerically equivalent. 2552 Recall that scalar constants bound in a program are treated as 2553 vector constants with the scalar value replicated. 2554 2555 In addition to the limits described above, the GL provides a similar 2556 set of implementation-dependent native resource limits. These 2557 limits, specified in Section 6.1.12, provide guidance as to whether 2558 the program is small enough to use a "native" mode where fragment 2559 programs may be executed with higher performance. The native 2560 resource limits and usage counts are implementation-dependent and 2561 may not exactly correspond to limits and counts described above. 2562 A program's native resource consumption may be reduced by program 2563 optimizations performed by the GL. Native resource consumption may 2564 be increased due to emulation of instructions or any other program 2565 features not natively supported by an implementation. Notably, an 2566 additional texture indirection may be consumed due to an 2567 implementation's lack of native support for texture instructions 2568 with source coordinate swizzles or parameter source coordinates, 2569 which may require emulation by prepending ALU instructions. An 2570 implementation may also fail to natively support all combinations of 2571 attributes described in Table X.1, even if the total number of 2572 bound attributes is fewer than the native attribute limit. In this 2573 case the program is still considered to exceed the native resource 2574 limits, as queried by PROGRAM_UNDER_NATIVE_LIMITS_ARB (section 2575 6.1.12). 2576 2577 To assist in resource counting, the GL additionally provides 2578 GetProgram queries to determine the resource usage and native 2579 resource usage of the currently bound program, and to determine 2580 whether the bound program exceeds any native resource limit. 2581 2582 Programs that exceed any native resource limit may or may not load 2583 depending on the implementation. 2584 2585 2586 3.11.4 Fragment Program Execution Environment 2587 2588 If fragment program mode is enabled, the currently bound fragment 2589 program is executed when any fragment is produced by rasterization. 2590 2591 If fragment program mode is enabled and the currently bound program 2592 object does not contain a valid fragment program, the error 2593 INVALID_OPERATION will be generated by Begin, RasterPos, and any 2594 command that implicitly calls Begin (e.g., DrawArrays). 2595 2596 Fragment programs execute a sequence of instructions without 2597 branching. Fragment programs begin by executing the first 2598 instruction in the program, and execute instructions in the order 2599 specified in the program until the last instruction is completed. 2600 2601 There are 33 fragment program instructions. The instructions and 2602 their respective input and output parameters are summarized in 2603 Table X.5. 2604 2605 Instruction Inputs Output Description 2606 ----------- ------ ------ -------------------------------- 2607 ABS v v absolute value 2608 ADD v,v v add 2609 CMP v,v,v v compare 2610 COS s ssss cosine with reduction to [-PI,PI] 2611 DP3 v,v ssss 3-component dot product 2612 DP4 v,v ssss 4-component dot product 2613 DPH v,v ssss homogeneous dot product 2614 DST v,v v distance vector 2615 EX2 s ssss exponential base 2 2616 FLR v v floor 2617 FRC v v fraction 2618 KIL v v kill fragment 2619 LG2 s ssss logarithm base 2 2620 LIT v v compute light coefficients 2621 LRP v,v,v v linear interpolation 2622 MAD v,v,v v multiply and add 2623 MAX v,v v maximum 2624 MIN v,v v minimum 2625 MOV v v move 2626 MUL v,v v multiply 2627 POW s,s ssss exponentiate 2628 RCP s ssss reciprocal 2629 RSQ s ssss reciprocal square root 2630 SCS s ss-- sine/cosine without reduction 2631 SGE v,v v set on greater than or equal 2632 SIN s ssss sine with reduction to [-PI,PI] 2633 SLT v,v v set on less than 2634 SUB v,v v subtract 2635 SWZ v v extended swizzle 2636 TEX v,u,t v texture sample 2637 TXB v,u,t v texture sample with bias 2638 TXP v,u,t v texture sample with projection 2639 XPD v,v v cross product 2640 2641 Table X.5: Summary of fragment program instructions. "v" 2642 indicates a floating-point vector input or output, "s" indicates a 2643 floating-point scalar input, "ssss" indicates a scalar output 2644 replicated across a 4-component result vector, "ss--" indicates 2645 two scalar outputs in the first two components, "u" indicates a 2646 texture image unit identifier, and "t" indicates a texture target. 2647 2648 2649 3.11.4.1 Fragment Program Operands 2650 2651 Most fragment program instructions operate on floating-point vectors 2652 or scalars, as indicated by the grammar rules <vectorSrcReg> and 2653 <scalarSrcReg>, respectively. 2654 2655 Vector and scalar operands can be obtained from fragment attribute, 2656 program parameter, or temporary registers, as indicated by the 2657 <srcReg> rule. For scalar operands, a single vector component is 2658 selected by the <scalarSuffix> rule, where the characters "x", "y", 2659 "z", and "w", or "r", "g", "b", and "a" select the first, second, 2660 third, and fourth components, respectively, of the vector. 2661 2662 Vector operands can be swizzled according to the <optionalSuffix> 2663 rule. In its most general form, the <optionalSuffix> rule matches 2664 the pattern ".????" where each question mark is replaced with one of 2665 "x", "y", "z", "w", "r", "g", "b", or "a". For such patterns, the 2666 first, second, third, and fourth components of the operand are taken 2667 from the vector components named by the first, second, third, and 2668 fourth character of the pattern, respectively. For example, if the 2669 swizzle suffix is ".yzzx" or ".gbbr" and the specified source 2670 contains {2,8,9,0}, the swizzled operand used by the instruction is 2671 {8,9,9,2}. 2672 2673 If the <optionalSuffix> rule matches "", it is treated as though it 2674 were ".xyzw". If the <optionalSuffix> rule matches (ignoring 2675 whitespace) ".x", ".y", ".z", or ".w", these are treated the same as 2676 ".xxxx", ".yyyy", ".zzzz", and ".wwww" respectively. Likewise, if 2677 the <optionalSuffix> rule matches ".r", ".g", ".b", or ".a", these 2678 are treated the same as ".rrrr", ".gggg", ".bbbb", and ".aaaa" 2679 respectively. 2680 2681 Floating-point scalar or vector operands can optionally be negated 2682 according to the <optionalSign> rule in <scalarSrcReg> and 2683 <vectorSrcReg>. If the <optionalSign> matches "-", each operand or 2684 operand component is negated. 2685 2686 The following pseudo-code spells out the operand generation process. 2687 In the example, "float" is a floating-point scalar type, while 2688 "floatVec" is a four-component vector. "source" refers to the 2689 register used for the operand, matching the <srcReg> rule. "negate" 2690 is TRUE if the <optionalSign> rule in <scalarSrcReg> or 2691 <vectorSrcReg> matches "-" and FALSE otherwise. The ".c***", 2692 ".*c**", ".**c*", ".***c" modifiers refer to the x, y, z, and w 2693 components obtained by the swizzle operation; the ".c" modifier 2694 refers to the single component selected for a scalar load. 2695 2696 floatVec VectorLoad(floatVec source) 2697 { 2698 floatVec operand; 2699 2700 operand.x = source.c***; 2701 operand.y = source.*c**; 2702 operand.z = source.**c*; 2703 operand.w = source.***c; 2704 if (negate) { 2705 operand.x = -operand.x; 2706 operand.y = -operand.y; 2707 operand.z = -operand.z; 2708 operand.w = -operand.w; 2709 } 2710 2711 return operand; 2712 } 2713 2714 float ScalarLoad(floatVec source) 2715 { 2716 float operand; 2717 2718 operand = source.c; 2719 if (negate) { 2720 operand = -operand; 2721 } 2722 2723 return operand; 2724 } 2725 2726 2727 3.11.4.2 Fragment Program Parameter Arrays 2728 2729 A fragment program can load a single element of a program parameter 2730 array using only absolute addressing. Program parameter arrays are 2731 accessed when the <progParamArrayAbs> rule is matched. The offset 2732 of the selected entry in the array is given by the number matching 2733 <progParamRegNum>. If the offset exceeds the size of the 2734 array, the results of the access are undefined, but may not lead to 2735 program or GL termination. 2736 2737 2738 3.11.4.3 Fragment Program Destination Register Update 2739 2740 Fragment program instructions write a 4-component result vector to a 2741 single temporary or fragment result register. Writes to individual 2742 components of the destination register are controlled by individual 2743 component write masks specified as part of the instruction. 2744 Optional clamping of each component of the destination register to 2745 the range [0,1] is controlled by an opcode modifier. 2746 2747 The component write mask is specified by the <optionalMask> rule 2748 found in the <maskedDstReg> rule. If the optional mask is "", all 2749 components are enabled. Otherwise, the optional mask names the 2750 individual components to enable. The characters "x", "y", "z", and 2751 "w", or "r", "g", "b", and "a" match the first, second, third, and 2752 fourth components, respectively. For example, an optional mask of 2753 ".xzw" indicates that the x, z, and w components should be enabled 2754 for writing but the y component should not. The grammar requires 2755 that the destination register mask components must be listed in 2756 "xyzw", or "rgba" order. Component names from one set (xyzw or 2757 rgba) cannot be mixed with component names from another set. For 2758 example, ".rgw" is not a valid writemask. 2759 2760 Each component of the destination register is updated with the 2761 result of the fragment program instruction if and only if the 2762 component is enabled for writes by the component write mask. 2763 Otherwise, the component of the destination register remains 2764 unchanged. 2765 2766 If the instruction opcode has the "_SAT" suffix, requesting 2767 saturated result vectors, each component of the result vector 2768 enabled in the writemask is clamped to the range [0,1] before being 2769 updated in the destination register. 2770 2771 The following pseudocode illustrates the process of writing a result 2772 vector to the destination register. In the pseudocode, "instrmask" 2773 refers to the component write mask given by the <optionalMask> rule. 2774 "clamp" is TRUE if the instruction specifies that the result should 2775 be clamped. "result" and "destination" refer to the result vector 2776 and the register selected by <dstReg>, respectively. 2777 2778 void UpdateDestination(floatVec destination, floatVec result) 2779 { 2780 floatVec merged; 2781 2782 // Clamp the result vector components to [0,1], if requested. 2783 if (instrClamp) { 2784 if (result.x < 0) result.x = 0; 2785 else if (result.x > 1) result.x = 1; 2786 if (result.y < 0) result.y = 0; 2787 else if (result.y > 1) result.y = 1; 2788 if (result.z < 0) result.z = 0; 2789 else if (result.z > 1) result.z = 1; 2790 if (result.w < 0) result.w = 0; 2791 else if (result.w > 1) result.w = 1; 2792 } 2793 2794 // Merge the converted result into the destination register, 2795 // under control of the compile-time write mask. 2796 merged = destination; 2797 if (instrMask.x) { 2798 merged.x = result.x; 2799 } 2800 if (instrMask.y) { 2801 merged.y = result.y; 2802 } 2803 if (instrMask.z) { 2804 merged.z = result.z; 2805 } 2806 if (instrMask.w) { 2807 merged.w = result.w; 2808 } 2809 2810 // Write out the new destination register. 2811 destination = merged; 2812 } 2813 2814 2815 3.11.4.4 Fragment Program Result Processing 2816 2817 As a fragment program executes, it will write to either one or two 2818 result registers that are mapped to the fragment's color and depth. 2819 2820 The fragment's color components are first clamped to the range [0,1] 2821 then converted to fixed point as in section 2.13.9. If the fragment 2822 program does not write result.color, the color will be undefined in 2823 subsequent stages. 2824 2825 If the fragment program contains an instruction to write to 2826 result.depth, the fragment's depth is replaced by the value of the 2827 "z" component of result.depth. This z value is first clamped to the 2828 range [0,1] then converted to fixed-point as if it were a window z 2829 value (section 2.10.1). If the fragment program does not write 2830 result.depth, the fragment's original depth is unmodified. 2831 2832 2833 3.11.4.5 Fragment Program Options 2834 2835 The <optionSequence> grammar rule provides a mechanism for programs 2836 to indicate that one or more extended language features are used by 2837 the program. All program options used by the program must be 2838 declared at the beginning of the program string. Each program 2839 option specified in a program string will modify the syntactic or 2840 semantic rules used to interpet the program and the execution 2841 environment used to execute the program. Program options not 2842 present in the program string are ignored, even if they are 2843 supported by the GL. 2844 2845 The <identifier> token in the <option> rule must match the name of a 2846 program option supported by the implementation. To avoid option 2847 name conflicts, option identifiers are required to begin with a 2848 vendor prefix. A program will fail to load if it specifies a 2849 program option not supported by the GL. 2850 2851 Fragment program options should confine their semantic changes to 2852 the domain of fragment programs. Support for a fragment program 2853 option should not change the specification and behavior of fragment 2854 programs not requesting use of that option. 2855 2856 2857 3.11.4.5.1 Fog Application Fragment Program Options 2858 2859 If a fragment program specifies one of the options "ARB_fog_exp", 2860 "ARB_fog_exp2", or "ARB_fog_linear", the program will apply fog to 2861 the program's final clamped color using a fog mode of EXP, EXP2, or 2862 LINEAR, respectively, as described in section 3.10. 2863 2864 When a fog option is specified in a fragment program, semantic 2865 restrictions are added to indicate that a fragment program 2866 will fail to load if the number of temporaries it contains exceeds 2867 the implementation-dependent limit minus 1, if the number of 2868 attributes it contains exceeds the implementation-dependent limit 2869 minus 1, or if the number of parameters it contains exceeds the 2870 implementation-dependent limit minus 2. 2871 2872 Additionally, when the ARB_fog_exp option is specified in a fragment 2873 program, a semantic restriction is added to indicate that a fragment 2874 program will fail to load if the number of instructions or ALU 2875 instructions it contains exceeds the implementation-dependent limit 2876 minus 3. When the ARB_fog_exp2 option is specified in a fragment 2877 program, a semantic restriction is added to indicate that a fragment 2878 program will fail to load if the number of instructions or ALU 2879 instructions it contains exceeds the implementation-dependent limit 2880 minus 4. When the ARB_fog_linear option is specified in a fragment 2881 program, a semantic restriction is added to indicate that a fragment 2882 program will fail to load if the number of instructions or ALU 2883 instructions it contains exceeds the implementation-dependent limit 2884 minus 2. 2885 2886 Only one fog application option may be specified by any given 2887 fragment program. A fragment program that specifies more than one 2888 of the program options "ARB_fog_exp", "ARB_fog_exp2", and 2889 "ARB_fog_linear", will fail to load. 2890 2891 2892 3.11.4.5.2 Precision Hint Options 2893 2894 Fragment program computations are carried out at an implementation- 2895 dependent precision. However, some implementations may be able to 2896 perform fragment program computations at more than one precision, 2897 and may be able to trade off computation precision for performance. 2898 2899 If a fragment program specifies the "ARB_precision_hint_fastest" 2900 program option, implementations should select precision to minimize 2901 program execution time, with possibly reduced precision. If a 2902 fragment program specifies the "ARB_precision_hint_nicest" program 2903 option, implementations should maximize the precision, with possibly 2904 increased execution time. 2905 2906 Only one precision control option may be specified by any given 2907 fragment program. A fragment program that specifies both the 2908 "ARB_precision_hint_fastest" and "ARB_precision_hint_nicest" program 2909 options will fail to load. 2910 2911 2912 3.11.5 Fragment Program ALU Instruction Set 2913 2914 The following sections describe the set of supported fragment 2915 program instructions. Each section contains pseudocode describing 2916 the instruction. Instructions will have up to three operands, 2917 referred to as "op0", "op1", and "op2". The operands are loaded 2918 using the mechanisms specified in section 3.11.4.1. The variables 2919 "tmp", "tmp0", "tmp1", and "tmp2" describe scalars or vectors used 2920 to hold intermediate results in the instruction. Instructions will 2921 generate a result vector called "result". The result vector is then 2922 written to the destination register specified in the instruction as 2923 described in section 3.11.4.3. 2924 2925 2926 3.11.5.1 ABS: Absolute Value 2927 2928 The ABS instruction performs a component-wise absolute value 2929 operation on the single operand to yield a result vector. 2930 2931 tmp = VectorLoad(op0); 2932 result.x = fabs(tmp.x); 2933 result.y = fabs(tmp.y); 2934 result.z = fabs(tmp.z); 2935 result.w = fabs(tmp.w); 2936 2937 2938 3.11.5.2 ADD: Add 2939 2940 The ADD instruction performs a component-wise add of the two 2941 operands to yield a result vector. 2942 2943 tmp0 = VectorLoad(op0); 2944 tmp1 = VectorLoad(op1); 2945 result.x = tmp0.x + tmp1.x; 2946 result.y = tmp0.y + tmp1.y; 2947 result.z = tmp0.z + tmp1.z; 2948 result.w = tmp0.w + tmp1.w; 2949 2950 The following rules apply to addition: 2951 2952 1. <x> + <y> == <y> + <x>, for all <x> and <y>. 2953 2. <x> + 0.0 == <x>, for all <x>. 2954 2955 2956 3.11.5.3 CMP: Compare 2957 2958 The CMP instructions performs a component-wise comparison of the 2959 first operand against zero, and copies the values of the second or 2960 third operands based on the results of the compare. 2961 2962 tmp0 = VectorLoad(op0); 2963 tmp1 = VectorLoad(op1); 2964 tmp2 = VectorLoad(op2); 2965 result.x = (tmp0.x < 0.0) ? tmp1.x : tmp2.x; 2966 result.y = (tmp0.y < 0.0) ? tmp1.y : tmp2.y; 2967 result.z = (tmp0.z < 0.0) ? tmp1.z : tmp2.z; 2968 result.w = (tmp0.w < 0.0) ? tmp1.w : tmp2.w; 2969 2970 2971 3.11.5.4 COS: Cosine 2972 2973 The COS instruction approximates the trigonometric cosine of the 2974 angle specified by the scalar operand and replicates it to all four 2975 components of the result vector. The angle is specified in radians 2976 and does not have to be in the range [-PI,PI]. 2977 2978 tmp = ScalarLoad(op0); 2979 result.x = ApproxCosine(tmp); 2980 result.y = ApproxCosine(tmp); 2981 result.z = ApproxCosine(tmp); 2982 result.w = ApproxCosine(tmp); 2983 2984 2985 3.11.5.5 DP3: Three-Component Dot Product 2986 2987 The DP3 instruction computes a three-component dot product of the 2988 two operands (using the first three components) and replicates the 2989 dot product to all four components of the result vector. 2990 2991 tmp0 = VectorLoad(op0); 2992 tmp1 = VectorLoad(op1); 2993 dot = (tmp0.x * tmp1.x) + (tmp0.y * tmp1.y) + (tmp0.z * tmp1.z); 2994 result.x = dot; 2995 result.y = dot; 2996 result.z = dot; 2997 result.w = dot; 2998 2999 3000 3.11.5.6 DP4: Four-Component Dot Product 3001 3002 The DP4 instruction computes a four-component dot product of the two 3003 operands and replicates the dot product to all four components of 3004 the result vector. 3005 3006 tmp0 = VectorLoad(op0); 3007 tmp1 = VectorLoad(op1): 3008 dot = (tmp0.x * tmp1.x) + (tmp0.y * tmp1.y) + 3009 (tmp0.z * tmp1.z) + (tmp0.w * tmp1.w); 3010 result.x = dot; 3011 result.y = dot; 3012 result.z = dot; 3013 result.w = dot; 3014 3015 3016 3.11.5.7 DPH: Homogeneous Dot Product 3017 3018 The DPH instruction computes a three-component dot product of the 3019 two operands (using the x, y, and z components), adds the w 3020 component of the second operand, and replicates the sum to all four 3021 components of the result vector. This is equivalent to a four- 3022 component dot product where the w component of the first operand is 3023 forced to 1.0. 3024 3025 tmp0 = VectorLoad(op0); 3026 tmp1 = VectorLoad(op1): 3027 dot = (tmp0.x * tmp1.x) + (tmp0.y * tmp1.y) + 3028 (tmp0.z * tmp1.z) + tmp1.w; 3029 result.x = dot; 3030 result.y = dot; 3031 result.z = dot; 3032 result.w = dot; 3033 3034 3035 3.11.5.8 DST: Distance Vector 3036 3037 The DST instruction computes a distance vector from two specially- 3038 formatted operands. The first operand should be of the form [NA, 3039 d^2, d^2, NA] and the second operand should be of the form [NA, 1/d, 3040 NA, 1/d], where NA values are not relevant to the calculation and d 3041 is a vector length. If both vectors satisfy these conditions, the 3042 result vector will be of the form [1.0, d, d^2, 1/d]. 3043 3044 The exact behavior is specified in the following pseudo-code: 3045 3046 tmp0 = VectorLoad(op0); 3047 tmp1 = VectorLoad(op1); 3048 result.x = 1.0; 3049 result.y = tmp0.y * tmp1.y; 3050 result.z = tmp0.z; 3051 result.w = tmp1.w; 3052 3053 Given an arbitrary vector, d^2 can be obtained using the DP3 3054 instruction (using the same vector for both operands) and 1/d can be 3055 obtained from d^2 using the RSQ instruction. 3056 3057 This distance vector is useful for per-fragment light attenuation 3058 calculations: a DP3 operation using the distance vector and an 3059 attenuation constants vector as operands will yield the attenuation 3060 factor. 3061 3062 3063 3.11.5.9 EX2: Exponential Base 2 3064 3065 The EX2 instruction approximates 2 raised to the power of the scalar 3066 operand and replicates the approximation to all four components of 3067 the result vector. 3068 3069 tmp = ScalarLoad(op0); 3070 result.x = Approx2ToX(tmp); 3071 result.y = Approx2ToX(tmp); 3072 result.z = Approx2ToX(tmp); 3073 result.w = Approx2ToX(tmp); 3074 3075 3076 3.11.5.10 FLR: Floor 3077 3078 The FLR instruction performs a component-wise floor operation on the 3079 operand to generate a result vector. The floor of a value is 3080 defined as the largest integer less than or equal to the value. The 3081 floor of 2.3 is 2.0; the floor of -3.6 is -4.0. 3082 3083 tmp = VectorLoad(op0); 3084 result.x = floor(tmp.x); 3085 result.y = floor(tmp.y); 3086 result.z = floor(tmp.z); 3087 result.w = floor(tmp.w); 3088 3089 3090 3.11.5.11 FRC: Fraction 3091 3092 The FRC instruction extracts the fractional portion of each 3093 component of the operand to generate a result vector. The 3094 fractional portion of a component is defined as the result after 3095 subtracting off the floor of the component (see FLR), and is always 3096 in the range [0.0, 1.0). 3097 3098 For negative values, the fractional portion is NOT the number 3099 written to the right of the decimal point -- the fractional portion 3100 of -1.7 is not 0.7 -- it is 0.3. 0.3 is produced by subtracting the 3101 floor of -1.7 (-2.0) from -1.7. 3102 3103 tmp = VectorLoad(op0); 3104 result.x = fraction(tmp.x); 3105 result.y = fraction(tmp.y); 3106 result.z = fraction(tmp.z); 3107 result.w = fraction(tmp.w); 3108 3109 3110 3.11.5.12 LG2: Logarithm Base 2 3111 3112 The LG2 instruction approximates the base 2 logarithm of the scalar 3113 operand and replicates it to all four components of the result 3114 vector. 3115 3116 tmp = ScalarLoad(op0); 3117 result.x = ApproxLog2(tmp); 3118 result.y = ApproxLog2(tmp); 3119 result.z = ApproxLog2(tmp); 3120 result.w = ApproxLog2(tmp); 3121 3122 If the scalar operand is zero or negative, the result is undefined. 3123 3124 3125 3.11.5.13 LIT: Light Coefficients 3126 3127 The LIT instruction accelerates per-fragment lighting by computing 3128 lighting coefficients for ambient, diffuse, and specular light 3129 contributions. The "x" component of the single operand is assumed 3130 to hold a diffuse dot product (n dot VP_pli, as in the vertex 3131 lighting equations in Section 2.13.1). The "y" component of the 3132 operand is assumed to hold a specular dot product (n dot h_i). The 3133 "w" component of the operand is assumed to hold the specular 3134 exponent of the material (s_rm), and is clamped to the range (-128, 3135 +128) exclusive. 3136 3137 The "x" component of the result vector receives the value that 3138 should be multiplied by the ambient light/material product (always 3139 1.0). The "y" component of the result vector receives the value 3140 that should be multiplied by the diffuse light/material product 3141 (n dot VP_pli). The "z" component of the result vector receives the 3142 value that should be multiplied by the specular light/material 3143 product (f_i * (n dot h_i) ^ s_rm). The "w" component of the result 3144 is the constant 1.0. 3145 3146 Negative diffuse and specular dot products are clamped to 0.0, as is 3147 done in the standard per-vertex lighting operations. In addition, 3148 if the diffuse dot product is zero or negative, the specular 3149 coefficient is forced to zero. 3150 3151 tmp = VectorLoad(op0); 3152 if (tmp.x < 0) tmp.x = 0; 3153 if (tmp.y < 0) tmp.y = 0; 3154 if (tmp.w < -(128.0-epsilon)) tmp.w = -(128.0-epsilon); 3155 else if (tmp.w > 128-epsilon) tmp.w = 128-epsilon; 3156 result.x = 1.0; 3157 result.y = tmp.x; 3158 result.z = (tmp.x > 0) ? RoughApproxPower(tmp.y, tmp.w) : 0.0; 3159 result.w = 1.0; 3160 3161 The exponentiation approximation function may be defined in terms of 3162 the base 2 exponentiation and logarithm approximation operations in 3163 the EX2 and LG2 instructions, where 3164 3165 ApproxPower(a,b) = ApproxExp2(b * ApproxLog2(a)). 3166 3167 In particular, the approximation may not be any more accurate than 3168 the underlying EX2 and LG2 operations. 3169 3170 Also, since 0^0 is defined to be 1, RoughApproxPower(0.0, 0.0) will 3171 produce 1.0. 3172 3173 3174 3.11.5.14 LRP: Linear Interpolation 3175 3176 The LRP instruction performs a component-wise linear interpolation 3177 between the second and third operands using the first operand as the 3178 blend factor. 3179 3180 tmp0 = VectorLoad(op0); 3181 tmp1 = VectorLoad(op1); 3182 tmp2 = VectorLoad(op2); 3183 result.x = tmp0.x * tmp1.x + (1 - tmp0.x) * tmp2.x; 3184 result.y = tmp0.y * tmp1.y + (1 - tmp0.y) * tmp2.y; 3185 result.z = tmp0.z * tmp1.z + (1 - tmp0.z) * tmp2.z; 3186 result.w = tmp0.w * tmp1.w + (1 - tmp0.w) * tmp2.w; 3187 3188 3189 3.11.5.15 MAD: Multiply and Add 3190 3191 The MAD instruction performs a component-wise multiply of the first two 3192 operands, and then does a component-wise add of the product to the 3193 third operand to yield a result vector. 3194 3195 tmp0 = VectorLoad(op0); 3196 tmp1 = VectorLoad(op1); 3197 tmp2 = VectorLoad(op2); 3198 result.x = tmp0.x * tmp1.x + tmp2.x; 3199 result.y = tmp0.y * tmp1.y + tmp2.y; 3200 result.z = tmp0.z * tmp1.z + tmp2.z; 3201 result.w = tmp0.w * tmp1.w + tmp2.w; 3202 3203 The multiplication and addition operations in this instruction are 3204 subject to the same rules as described for the MUL and ADD 3205 instructions. 3206 3207 3208 3.11.5.16 MAX: Maximum 3209 3210 The MAX instruction computes component-wise maximums of the values 3211 in the two operands to yield a result vector. 3212 3213 tmp0 = VectorLoad(op0); 3214 tmp1 = VectorLoad(op1); 3215 result.x = (tmp0.x > tmp1.x) ? tmp0.x : tmp1.x; 3216 result.y = (tmp0.y > tmp1.y) ? tmp0.y : tmp1.y; 3217 result.z = (tmp0.z > tmp1.z) ? tmp0.z : tmp1.z; 3218 result.w = (tmp0.w > tmp1.w) ? tmp0.w : tmp1.w; 3219 3220 3221 3.11.5.17 MIN: Minimum 3222 3223 The MIN instruction computes component-wise minimums of the values 3224 in the two operands to yield a result vector. 3225 3226 tmp0 = VectorLoad(op0); 3227 tmp1 = VectorLoad(op1); 3228 result.x = (tmp0.x > tmp1.x) ? tmp1.x : tmp0.x; 3229 result.y = (tmp0.y > tmp1.y) ? tmp1.y : tmp0.y; 3230 result.z = (tmp0.z > tmp1.z) ? tmp1.z : tmp0.z; 3231 result.w = (tmp0.w > tmp1.w) ? tmp1.w : tmp0.w; 3232 3233 3234 3.11.5.18 MOV: Move 3235 3236 The MOV instruction copies the value of the operand to yield a 3237 result vector. 3238 3239 result = VectorLoad(op0); 3240 3241 3242 3.11.5.19 MUL: Multiply 3243 3244 The MUL instruction performs a component-wise multiply of the two 3245 operands to yield a result vector. 3246 3247 tmp0 = VectorLoad(op0); 3248 tmp1 = VectorLoad(op1); 3249 result.x = tmp0.x * tmp1.x; 3250 result.y = tmp0.y * tmp1.y; 3251 result.z = tmp0.z * tmp1.z; 3252 result.w = tmp0.w * tmp1.w; 3253 3254 The following rules apply to multiplication: 3255 3256 1. <x> * <y> == <y> * <x>, for all <x> and <y>. 3257 2. +/-0.0 * <x> = +/-0.0, at least for all <x> that correspond to 3258 representable numbers (IEEE "not a number" and "infinity" 3259 encodings may be exceptions). 3260 3. +1.0 * <x> = <x>, for all <x>. 3261 3262 Multiplication by zero and one should be invariant, as it may be 3263 used to evaluate conditional expressions without branching. 3264 3265 3266 3.11.5.20 POW: Exponentiate 3267 3268 The POW instruction approximates the value of the first scalar 3269 operand raised to the power of the second scalar operand and 3270 replicates it to all four components of the result vector. 3271 3272 tmp0 = ScalarLoad(op0); 3273 tmp1 = ScalarLoad(op1); 3274 result.x = ApproxPower(tmp0, tmp1); 3275 result.y = ApproxPower(tmp0, tmp1); 3276 result.z = ApproxPower(tmp0, tmp1); 3277 result.w = ApproxPower(tmp0, tmp1); 3278 3279 The exponentiation approximation function may be implemented using 3280 the base 2 exponentiation and logarithm approximation operations in 3281 the EX2 and LG2 instructions. In particular, 3282 3283 ApproxPower(a,b) = ApproxExp2(b * ApproxLog2(a)). 3284 3285 Note that a logarithm may be involved even for cases where the 3286 exponent is an integer. This means that it may not be possible to 3287 exponentiate correctly with a negative base. In constrast, it is 3288 possible in a "normal" mathematical formulation to raise negative 3289 numbers to integral powers (e.g., (-3)^2== 9, and (-0.5)^-2==4). 3290 3291 3292 3.11.5.21 RCP: Reciprocal 3293 3294 The RCP instruction approximates the reciprocal of the scalar 3295 operand and replicates it to all four components of the result 3296 vector. 3297 3298 tmp = ScalarLoad(op0); 3299 result.x = ApproxReciprocal(tmp); 3300 result.y = ApproxReciprocal(tmp); 3301 result.z = ApproxReciprocal(tmp); 3302 result.w = ApproxReciprocal(tmp); 3303 3304 The following rule applies to reciprocation: 3305 3306 1. ApproxReciprocal(+1.0) = +1.0. 3307 3308 3309 3.11.5.22 RSQ: Reciprocal Square Root 3310 3311 The RSQ instruction approximates the reciprocal of the square root 3312 of the absolute value of the scalar operand and replicates it to all 3313 four components of the result vector. 3314 3315 tmp = fabs(ScalarLoad(op0)); 3316 result.x = ApproxRSQRT(tmp); 3317 result.y = ApproxRSQRT(tmp); 3318 result.z = ApproxRSQRT(tmp); 3319 result.w = ApproxRSQRT(tmp); 3320 3321 3322 3.11.5.23 SCS: Sine/Cosine 3323 3324 The SCS instruction approximates the trigonometric sine and cosine 3325 of the angle specified by the scalar operand and places the cosine 3326 in the x component and the sine in the y component of the result 3327 vector. The z and w components of the result vector are undefined. 3328 The angle is specified in radians and must be in the range [-PI,PI]. 3329 3330 tmp = ScalarLoad(op0); 3331 result.x = ApproxCosine(tmp); 3332 result.y = ApproxSine(tmp); 3333 3334 If the scalar operand is not in the range [-PI,PI], the result 3335 vector is undefined. 3336 3337 3338 3.11.5.24 SGE: Set On Greater or Equal Than 3339 3340 The SGE instruction performs a component-wise comparison of the two 3341 operands. Each component of the result vector is 1.0 if the 3342 corresponding component of the first operands is greater than or 3343 equal that of the second, and 0.0 otherwise. 3344 3345 tmp0 = VectorLoad(op0); 3346 tmp1 = VectorLoad(op1); 3347 result.x = (tmp0.x >= tmp1.x) ? 1.0 : 0.0; 3348 result.y = (tmp0.y >= tmp1.y) ? 1.0 : 0.0; 3349 result.z = (tmp0.z >= tmp1.z) ? 1.0 : 0.0; 3350 result.w = (tmp0.w >= tmp1.w) ? 1.0 : 0.0; 3351 3352 3353 3.11.5.25 SIN: Sine 3354 3355 The SIN instruction approximates the trigonometric sine of the angle 3356 specified by the scalar operand and replicates it to all four 3357 components of the result vector. The angle is specified in radians 3358 and does not have to be in the range [-PI,PI]. 3359 3360 tmp = ScalarLoad(op0); 3361 result.x = ApproxSine(tmp); 3362 result.y = ApproxSine(tmp); 3363 result.z = ApproxSine(tmp); 3364 result.w = ApproxSine(tmp); 3365 3366 3367 3.11.5.26 SLT: Set On Less Than 3368 3369 The SLT instruction performs a component-wise comparison of the two 3370 operands. Each component of the result vector is 1.0 if the 3371 corresponding component of the first operand is less than that of 3372 the second, and 0.0 otherwise. 3373 3374 tmp0 = VectorLoad(op0); 3375 tmp1 = VectorLoad(op1); 3376 result.x = (tmp0.x < tmp1.x) ? 1.0 : 0.0; 3377 result.y = (tmp0.y < tmp1.y) ? 1.0 : 0.0; 3378 result.z = (tmp0.z < tmp1.z) ? 1.0 : 0.0; 3379 result.w = (tmp0.w < tmp1.w) ? 1.0 : 0.0; 3380 3381 3382 3.11.5.27 SUB: Subtract 3383 3384 The SUB instruction performs a component-wise subtraction of the 3385 second operand from the first to yield a result vector. 3386 3387 tmp0 = VectorLoad(op0); 3388 tmp1 = VectorLoad(op1); 3389 result.x = tmp0.x - tmp1.x; 3390 result.y = tmp0.y - tmp1.y; 3391 result.z = tmp0.z - tmp1.z; 3392 result.w = tmp0.w - tmp1.w; 3393 3394 3395 3.11.5.28 SWZ: Extended Swizzle 3396 3397 The SWZ instruction loads the single vector operand, and performs a 3398 swizzle operation more powerful than that provided for loading 3399 normal vector operands to yield an instruction vector. 3400 3401 After the operand is loaded, the "x", "y", "z", and "w" components 3402 of the result vector are selected by the first, second, third, and 3403 fourth matches of the <xyzwExtSwizComp> or <rgbaExtSwizComp> pattern 3404 in the <extendedSwizzle> rule. 3405 3406 A result component can be selected from any of the four components 3407 of the operand or the constants 0.0 and 1.0. The result component 3408 can also be optionally negated. The following pseudocode describes 3409 the component selection method. "operand" refers to the vector 3410 operand. "select" is an enumerant where the values ZERO, ONE, X, Y, 3411 Z, and W correspond to the <xyzwExtSwizSel> rule matching "0", "1", "x", 3412 "y", "z", and "w", respectively, or the <rgbaExtSwizSel> rule 3413 matching "0", 1", "r", "g", "b", and "a", respectively. "negate" is 3414 TRUE if and only if the <optionalSign> rule in <xyzwExtSwizComp> 3415 or <rgbaExtSwizComp> matches "-". 3416 3417 float ExtSwizComponent(floatVec operand, enum select, boolean negate) 3418 { 3419 float result; 3420 switch (select) { 3421 case ZERO: result = 0.0; break; 3422 case ONE: result = 1.0; break; 3423 case X: result = operand.x; break; 3424 case Y: result = operand.y; break; 3425 case Z: result = operand.z; break; 3426 case W: result = operand.w; break; 3427 } 3428 if (negate) { 3429 result = -result; 3430 } 3431 return result; 3432 } 3433 3434 The entire extended swizzle operation is then defined using the 3435 following pseudocode: 3436 3437 tmp = VectorLoad(op0); 3438 result.x = ExtSwizComponent(tmp, xSelect, xNegate); 3439 result.y = ExtSwizComponent(tmp, ySelect, yNegate); 3440 result.z = ExtSwizComponent(tmp, zSelect, zNegate); 3441 result.w = ExtSwizComponent(tmp, wSelect, wNegate); 3442 3443 "xSelect", "xNegate", "ySelect", "yNegate", "zSelect", "zNegate", 3444 "wSelect", and "wNegate" correspond to the "select" and "negate" 3445 values above for the four <xyzwExtSwizComp> or <rgbaExtSwizComp> 3446 matches. 3447 3448 Since this instruction allows for component selection and negation 3449 for each individual component, the grammar does not allow the use of 3450 the normal swizzle and negation operations allowed for vector 3451 operands in other instructions. 3452 3453 3454 3.11.5.29 XPD: Cross Product 3455 3456 The XPD instruction computes the cross product using the first three 3457 components of its two vector operands to generate the x, y, and z 3458 components of the result vector. The w component of the result 3459 vector is undefined. 3460 3461 tmp0 = VectorLoad(op0); 3462 tmp1 = VectorLoad(op1); 3463 result.x = tmp0.y * tmp1.z - tmp0.z * tmp1.y; 3464 result.y = tmp0.z * tmp1.x - tmp0.x * tmp1.z; 3465 result.z = tmp0.x * tmp1.y - tmp0.y * tmp1.x; 3466 3467 3468 3.11.6 Fragment Program Texture Instruction Set 3469 3470 The first three texture instructions described below specify the 3471 mapping of 4-tuple vectors to colors of an image. The sampling of 3472 the texture works as described in section 3.8, except that texture 3473 environments and texture functions are not applicable, and the 3474 texture enables hierarchy is replaced by explicit references to 3475 the desired texture target (i.e., 1D, 2D, 3D, cube map, rectangle). 3476 These texture instructions specify how the 4-tuple is mapped into 3477 the coordinates used for sampling. The following function is used 3478 to describe the texture sampling in the descriptions below: 3479 3480 vec4 TextureSample(float s, float t, float r, float lodBias, 3481 int texImageUnit, enum texTarget); 3482 3483 Note that not all three texture coordinates, s, t, and r, are 3484 used by all texture targets. In particular, 1D texture targets only 3485 use the s component, and 2D and rectangle (non-power-of-two) texture 3486 targets only use the s and t components. The descriptions of the 3487 texture instructions below supply all three components, as would be 3488 the case with 3D or cube map targets. 3489 3490 If a fragment program samples from a texture target on a texture 3491 image unit where the bound texture object is not complete, as 3492 defined in section 3.8.9, the result will be the vector 3493 (R, G, B, A) = (0, 0, 0, 1). 3494 3495 A fragment program will fail to load if it attempts to sample from 3496 multiple texture targets on the same texture image unit. For 3497 example, the following program would fail to load: 3498 3499 !!ARBfp1.0 3500 TEX result.color, fragment.texcoord[0], texture[0], 2D; 3501 TEX result.depth, fragment.texcoord[1], texture[0], 3D; 3502 END 3503 3504 The fourth texture instruction described below, KIL, does not sample 3505 from a texture, but rather prevents further processing of the 3506 current fragment if any component of its 4-tuple vector is less than 3507 zero. 3508 3509 A dependent texture instruction is one that samples using a texture 3510 coordinate residing in a temporary, rather than in an attribute or 3511 a parameter. A program may have a chain of dependent texture 3512 instructions, where the result of the first texture instruction is 3513 used as the coordinate for a second texture instruction, which is in 3514 turn used as the coordinate for a third texture instruction, and so 3515 on. Each node in this chain is termed an indirection, and can be 3516 thought of as a set of texture samples that execute in parallel 3517 followed by a sequence of ALU instructions. 3518 3519 Some implementations may have limitations on how long the dependency 3520 chain may be, and so indirections are counted as a resource just 3521 like instructions or temporaries are counted. All programs have at 3522 least one indirection, or one node in this chain, even if the 3523 program performs no texture operation. Each instruction encountered 3524 is included in this node until a texture instruction is encountered 3525 3526 - whose texture coordinate is a temporary that has been previously 3527 written in the current node; or 3528 3529 - whose result vector is a temporary that is also the operand or 3530 result vector of a previous ALU instruction in the current node. 3531 3532 A new node is then started, including the texture instruction and 3533 all subsequent instructions, and the process repeats for all 3534 instructions in the program. Note that for simplicity in counting, 3535 result writemasks and operand suffixes are not taken into 3536 consideration when counting indirections. 3537 3538 3539 3.11.6.1 TEX: Map coordinate to color 3540 3541 The TEX instruction takes the first three components of 3542 its source vector, and maps them to s, t, and r. These coordinates 3543 are used to sample from the specified texture target on the 3544 specified texture image unit in a manner consistent with its 3545 parameters. The resulting sample is mapped to RGBA as described in 3546 table 3.21 and written to the result vector. 3547 3548 tmp = VectorLoad(op0); 3549 result = TextureSample(tmp.x, tmp.y, tmp.z, 0.0, op1, op2); 3550 3551 3552 3.11.6.2 TXP: Project coordinate and map to color 3553 3554 The TXP instruction divides the first three components of its source 3555 vector by the fourth component and maps the results to s, t, and r. 3556 These coordinates are used to sample from the specified texture 3557 target on the specified texture image unit in a manner consistent 3558 with its parameters. The resulting sample is mapped to RGBA as 3559 described in table 3.21 and written to the result vector. If the 3560 value of the fourth component of the source vector is less than or 3561 equal to zero, the result vector is undefined. 3562 3563 tmp = VectorLoad(op0); 3564 tmp.x = tmp.x / tmp.w; 3565 tmp.y = tmp.y / tmp.w; 3566 tmp.z = tmp.z / tmp.w; 3567 result = TextureSample(tmp.x, tmp.y, tmp.z, 0.0, op1, op2); 3568 3569 3570 3.11.6.3 TXB: Map coordinate to color while biasing its LOD 3571 3572 The TXB instruction takes the first three components of its source 3573 vector and maps them to s, t, and r. These coordinates are used to 3574 sample from the specified texture target on the specified texture 3575 image unit in a manner consistent with its parameters. 3576 Additionally, the fourth component of the source vector is applied 3577 to equation 3.14 as fragment_bias below to further bias the level of 3578 detail. 3579 3580 lambda'(x,y) = log2[p(x,y)] + 3581 clamp(texobj_bias + texunit_bias + fragment_bias) 3582 3583 The resulting sample is mapped to RGBA as described in table 3.21 3584 and written to the result vector. 3585 3586 tmp = VectorLoad(op0); 3587 result = TextureSample(tmp.x, tmp.y, tmp.z, tmp.w, op1, op2); 3588 3589 3590 3.11.6.4 KIL: Kill fragment 3591 3592 Rather than mapping a coordinate set to a color, this function 3593 prevents a fragment from receiving any future processing. If any 3594 component of its source vector is negative, the processing of this 3595 fragment will be discontinued and no further outputs to this 3596 fragment will occur. Subsequent stages of the GL pipeline will be 3597 skipped for this fragment. 3598 3599 tmp = VectorLoad(op0); 3600 if ((tmp.x < 0) || (tmp.y < 0) || 3601 (tmp.z < 0) || (tmp.w < 0)) 3602 { 3603 exit; 3604 } 3605 3606 3607 3.11.7 Program Matrices 3608 3609 In addition to GL's conventional matrices, several additional 3610 program matrices are available for use as program parameters. These 3611 matrices have names of the form MATRIX<i>_ARB where <i> is between 3612 zero and <n>-1 where <n> is the value of the implementation- 3613 dependent constant MAX_PROGRAM_MATRICES_ARB. The MATRIX<i>_ARB 3614 constants obey MATRIX<i>_ARB = MATRIX0_ARB + <i>. The value of 3615 MAX_PROGRAM_MATRICES_ARB must be at least eight. The maximum stack 3616 depth for program matrices is defined by the 3617 MAX_PROGRAM_MATRIX_STACK_DEPTH_ARB and must be at least 1. 3618 3619 3620 3.11.8 Required Fragment Program State 3621 3622 The state required to support program objects of all targets 3623 consists of: 3624 3625 an integer for the program error position, initially -1; 3626 3627 an array of ubytes for the program error string, initially empty; 3628 3629 and the state that must be maintained to indicate which integers 3630 are currently in use as program object names. 3631 3632 The state required to support the fragment program target consists 3633 of: 3634 3635 a bit indicating whether or not fragment program mode is enabled, 3636 initially disabled; 3637 3638 a set of MAX_PROGRAM_ENV_PARAMETERS_ARB four-component floating- 3639 point program environment parameters, initially set to (0,0,0,0); 3640 3641 an unsigned integer naming the currently bound fragment program, 3642 initially zero; 3643 3644 The state required for each fragment program object consists of: 3645 3646 an unsigned integer indicating the program object name; 3647 3648 an array of type ubyte containing the program string, initially 3649 empty; 3650 3651 an unsigned integer holding the length of the program string, 3652 initially zero; 3653 3654 an enum indicating the program string format, initially 3655 PROGRAM_FORMAT_ASCII_ARB; 3656 3657 a bit indicating whether or not the program exceeds the native 3658 limits; 3659 3660 six unsigned integers holding the number of instruction (ALU, 3661 texture, and total), texture indirection, temporary variable, and 3662 program parameter binding resources used by the program, initially 3663 all zero; 3664 3665 six unsigned integers holding the number of native instruction 3666 (ALU, texture, and total), texture indirection, temporary 3667 variable, and program parameter binding resources used by the 3668 program, initially all zero; 3669 3670 and a set of MAX_PROGRAM_LOCAL_PARAMETERS_ARB four-component 3671 floating-point program local parameters, initially set to 3672 (0,0,0,0). 3673 3674 Initially, no fragment program objects exist. 3675 3676 3677Additions to Chapter 4 of the OpenGL 1.3 Specification (Per-Fragment 3678Operations and the Frame Buffer) 3679 3680 None 3681 3682 3683Additions to Chapter 5 of the OpenGL 1.3 Specification (Special 3684Functions) 3685 3686 Modify Section 5.4, Display Lists (p. 191) 3687 3688 (modify third paragraph, p. 195) ... These are IsList, GenLists, 3689 ..., IsProgramARB, GenProgramsARB, and DeleteProgramsARB, as well as 3690 IsEnabled and all the Get commands (chapter 6). 3691 3692 3693Additions to Chapter 6 of the OpenGL 1.3 Specification (State and 3694State Requests) 3695 3696 Modify Section 6.1.2, Data Conversions (p. 198) 3697 3698 (add before last paragraph, p. 198) The matrix selected by the 3699 current matrix mode can be queried by calling GetBooleanv, 3700 GetIntegerv, GetFloatv, and GetDoublev with <pname> set to 3701 CURRENT_MATRIX_ARB; the matrix will be returned in transposed form 3702 with <pname> set to TRANSPOSE_CURRENT_MATRIX_ARB. The depth of the 3703 selected matrix stack can be queried with <pname> set to 3704 CURRENT_MATRIX_STACK_DEPTH_ARB. Querying CURRENT_MATRIX_ARB and 3705 CURRENT_MATRIX_STACK_DEPTH_ARB is the only means for querying the 3706 matrix and matrix stack depth of the program matrices described in 3707 section 3.11.7. 3708 3709 3710 (add to end of last paragraph, p. 199) Queries of texture state 3711 variables corresponding to texture coordinate processing unit 3712 (namely, TexGen state and enables, and matrices) will produce an 3713 INVALID_OPERATION error if the value of ACTIVE_TEXTURE is greater 3714 than or equal to MAX_TEXTURE_COORDS_ARB. All other texture state 3715 queries will result in an INVALID_OPERATION error if the value of 3716 ACTIVE_TEXTURE is greater than or equal to 3717 MAX_TEXTURE_IMAGE_UNITS_ARB. 3718 3719 3720 Modify Section 6.1.11, Pointer and String Queries (p. 206) 3721 3722 (modify last paragraph, p. 206) ... The possible values for <name> 3723 are VENDOR, RENDERER, VERSION, EXTENSIONS, and 3724 PROGRAM_ERROR_STRING_ARB. 3725 3726 3727 (add after last paragraph of section, p. 207) Queries of 3728 PROGRAM_ERROR_STRING_ARB return a pointer to an implementation- 3729 dependent program load error string. If the last call to 3730 ProgramStringARB failed to load a program, the returned string 3731 describes at least one reason why the program failed to load. If 3732 the last call to ProgramStringARB successfully loaded a program, the 3733 returned string may be empty (containing only a zero terminator) or 3734 may contain one or more implementation-dependent warning messages. 3735 The contents of the error string are guaranteed to remain constant 3736 only until the next ProgramStringARB command, which may overwrite 3737 the error string. 3738 3739 3740 Insert a new Section 6.1.12, Program Queries (p. 207), between 3741 existing sections 6.1.11 and 6.1.12. 3742 3743 6.1.12 Program Queries 3744 3745 The commands 3746 3747 void GetProgramEnvParameterdvARB(enum target, uint index, 3748 double *params); 3749 void GetProgramEnvParameterfvARB(enum target, uint index, 3750 float *params); 3751 3752 obtain the current value for the program environment parameter 3753 numbered <index> for the given program target <target>, and places 3754 the information in the array <params>. The error INVALID_ENUM is 3755 generated if <target> specifies a nonexistent program target or a 3756 program target that does not support program environment parameters. 3757 The error INVALID_VALUE is generated if <index> is greater than or 3758 equal to the implementation-dependent number of supported program 3759 environment parameters for the program target. 3760 3761 When <target> is FRAGMENT_PROGRAM_ARB, each program parameter 3762 returned is an array of four values. 3763 3764 The commands 3765 3766 void GetProgramLocalParameterdvARB(enum target, uint index, 3767 double *params); 3768 void GetProgramLocalParameterfvARB(enum target, uint index, 3769 float *params); 3770 3771 obtain the current value for the program local parameter numbered 3772 <index> belonging to the program object currently bound to <target>, 3773 and places the information in the array <params>. The error 3774 INVALID_ENUM is generated if <target> specifies a nonexistent 3775 program target or a program target that does not support program 3776 local parameters. The error INVALID_VALUE is generated if <index> 3777 is greater than or equal to the implementation-dependent number of 3778 supported program local parameters for the program target. 3779 3780 When the program target type is FRAGMENT_PROGRAM_ARB, each program 3781 local parameter returned is an array of four values. 3782 3783 The command 3784 3785 void GetProgramivARB(enum target, enum pname, int *params); 3786 3787 obtains program state for the program target <target>, writing the 3788 state into the array given by <params>. GetProgramivARB can be used 3789 to determine the properties of the currently bound program object or 3790 implementation limits for <target>. 3791 3792 If <pname> is PROGRAM_LENGTH_ARB, PROGRAM_FORMAT_ARB, or 3793 PROGRAM_BINDING_ARB, GetProgramivARB returns one integer holding the 3794 program string length (in bytes), program string format, and program 3795 name, respectively, for the program object currently bound to 3796 <target>. 3797 3798 If <pname> is MAX_PROGRAM_LOCAL_PARAMETERS_ARB or 3799 MAX_PROGRAM_ENV_PARAMETERS_ARB, GetProgramivARB returns one integer 3800 holding the maximum number of program local parameters or program 3801 environment parameters, respectively, supported for the program 3802 target <target>. 3803 3804 If <pname> is MAX_PROGRAM_INSTRUCTIONS_ARB, 3805 MAX_PROGRAM_ALU_INSTRUCTIONS_ARB, MAX_PROGRAM_TEX_INSTRUCTIONS_ARB, 3806 MAX_PROGRAM_TEX_INDIRECTIONS_ARB, MAX_PROGRAM_TEMPORARIES_ARB, 3807 MAX_PROGRAM_PARAMETERS_ARB, or MAX_PROGRAM_ATTRIBS_ARB, 3808 GetProgramivARB returns a single integer giving the maximum number 3809 of total instructions, ALU instructions, texture instructions, 3810 texture indirections, temporaries, parameters, and attributes that 3811 can be used by a program of type <target>. If <pname> is 3812 PROGRAM_INSTRUCTIONS_ARB, PROGRAM_ALU_INSTRUCTIONS_ARB, 3813 PROGRAM_TEX_INSTRUCTIONS_ARB, PROGRAM_TEX_INDIRECTIONS_ARB, 3814 PROGRAM_TEMPORARIES_ARB, PROGRAM_PARAMETERS_ARB, or 3815 PROGRAM_ATTRIBS_ARB, GetProgramivARB returns a single integer giving 3816 the number of total instructions, ALU instructions, texture 3817 instructions, texture indirections, temporaries, parameters, and 3818 attributes used by the current program for <target>. 3819 3820 If <pname> is MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB, 3821 MAX_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB, 3822 MAX_PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB, 3823 MAX_PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB, 3824 MAX_PROGRAM_NATIVE_TEMPORARIES_ARB, 3825 MAX_PROGRAM_NATIVE_PARAMETERS_ARB, or 3826 MAX_PROGRAM_NATIVE_ATTRIBS_ARB, GetProgramivARB returns a single 3827 integer giving the maximum number of native instruction, ALU 3828 instruction, texture instruction, texture indirection, temporary, 3829 parameter, and attribute resources available to a program of type 3830 <target>. If <pname> is PROGRAM_NATIVE_INSTRUCTIONS_ARB, 3831 PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB, 3832 PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB, 3833 PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB, 3834 PROGRAM_NATIVE_TEMPORARIES_ARB, PROGRAM_NATIVE_PARAMETERS_ARB, or 3835 PROGRAM_NATIVE_ATTRIBS_ARB, GetProgramivARB returns a single integer 3836 giving the number of native instruction, ALU instruction, texture 3837 instruction, texture indirection, temporary, parameter, and 3838 attribute resources consumed by the program currently bound to 3839 <target>. Native resource counts will reflect the results of 3840 implementation-dependent scheduling and optimization algorithms 3841 applied by the GL, as well as emulation of non-native features. If 3842 <pname> is PROGRAM_UNDER_NATIVE_LIMITS_ARB, GetProgramivARB returns 3843 0 if the native resource consumption of the program currently bound 3844 to <target> exceeds the number of available resources for any 3845 resource type, and 1 otherwise. 3846 3847 The command 3848 3849 void GetProgramStringARB(enum target, enum pname, void *string); 3850 3851 obtains the program string for the program object bound to <target> 3852 and places the information in the array <string>. <pname> must be 3853 PROGRAM_STRING_ARB. <n> ubytes are returned into the array program 3854 where <n> is the length of the program in ubytes, as returned by 3855 GetProgramivARB when <pname> is PROGRAM_LENGTH_ARB. The program 3856 string is always returned using the format given when the program 3857 string was specified. 3858 3859 The command 3860 3861 boolean IsProgramARB(uint program); 3862 3863 returns TRUE if <program> is the name of a program object. If 3864 <program> is zero or is a non-zero value that is not the name of a 3865 program object, or if an error condition occurs, IsProgramARB 3866 returns FALSE. A name returned by GenProgramsARB, but not yet 3867 bound, is not the name of a program object. 3868 3869 3870 Modify Section 6.2, State Tables (p. 216) 3871 3872 (add to caption of Table 6.5) When accessing the current texture 3873 coordinates (CURRENT_TEXTURE_COORDS) or the texture coordinates 3874 associated with raster position (CURRENT_RASTER_TEXTURE_COORDS), the 3875 active texture unit selector (ACTIVE_TEXTURE) must be less than the 3876 implementation dependent maximum number of texture coordinate sets 3877 (MAX_TEXTURE_COORDS_ARB). 3878 3879 (add to caption of Table 6.8) When accessing the texture matrix 3880 stack (TEXTURE_MATRIX, TRANSPOSE_TEXTURE_MATRIX) or the texture 3881 matrix stack pointer (TEXTURE_STACK_DEPTH), the active texture unit 3882 selector (ACTIVE_TEXTURE) must be less than the implementation 3883 dependent maximum number of texture coordinate sets 3884 (MAX_TEXTURE_COORDS_ARB). 3885 3886 (split Table 6.17 into two tables, Texture Environment and Texture 3887 Coordinate Generation; move active texture unit selector and texture 3888 coordinate generation state to table 6.18; renumber subsequent 3889 tables) 3890 3891 (add to captions of Tables 6.14, 6.15, 6.16) The active texture unit 3892 selector (ACTIVE_TEXTURE) identifies which texture object is 3893 accessed, and must be less than the implementation dependent maximum 3894 number of texture image units (MAX_TEXTURE_IMAGE_UNITS_ARB). 3895 3896 (add to caption of Table 6.18) With the exception of ACTIVE_TEXTURE, 3897 the active texture unit selector (ACTIVE_TEXTURE) identifies which 3898 texture coordinate set is accessed, and must be less than the 3899 implementation dependent maximum number of texture coordinate sets 3900 (MAX_TEXTURE_COORDS_ARB). 3901 3902Additions to Appendix A of the OpenGL 1.3 Specification (Invariance) 3903 3904 Add to end of Section A.3 (p. 242): 3905 3906 Rule 4. Fragment program instructions not relevant to the 3907 calculation of any result must have no effect on that result. 3908 3909 Rule 5. Fragment program instructions relevant to the calculation 3910 of any result must always produce the identical result. 3911 3912 Instructions relevant to the calculation of a result are any 3913 instructions in a sequence of instructions that eventually determine 3914 the source values for the calculation under consideration. 3915 3916 There is no guaranteed invariance between fragment colors generated 3917 by conventional GL texturing mode and fragment colors generated by 3918 fragment program mode. Multi-pass rendering algorithms that require 3919 rendering invariances to operate correctly should not mix 3920 conventional GL fragment texturing mode with fragment program mode 3921 for different rendering passes. However, such algorithms will 3922 operate correctly if the algorithms limit themselves to a single 3923 mode of fragment color generation. 3924 3925 There is no guaranteed invariance between the final z window 3926 coordinates of fragments processed by fragment programs that write 3927 depth values and fragments processed by any other means, even if the 3928 fragment programs in question simply copy the z value from the 3929 "fragment.position" binding. Multi-pass rendering algorithms that 3930 use depth-replacing fragment programs should use depth-replacing 3931 fragment programs on each pass to guarantee identical z values. 3932 3933 The texture sample chosen for a fragment of a primitive must be 3934 invariant between fragment program mode and conventional texture 3935 application mode subject to these conditions: 3936 3937 1. All state with the exception of fragment program state is 3938 identical 3939 3940 2. The primitives generating the fragments are identical 3941 3942 3. The sample in the fragment program mode is the result of a 3943 'TEX' instruction (or a 'TXP' instruction with a unity q) 3944 3945 4. The texture coordinate operand for the texture instruction uses 3946 the same texture coordinate set as the conventional mode sample 3947 3948 5. The texture coordinate operand for the texture instruction has 3949 not been the result of any other operations in the fragment 3950 program 3951 3952 3953Additions to the AGL/GLX/WGL Specifications 3954 3955 Program objects are shared between AGL/GLX/WGL rendering contexts if 3956 and only if the rendering contexts share display lists. No change 3957 is made to the AGL/GLX/WGL API. 3958 3959 Changes to program objects shared between multiple rendering 3960 contexts will be serialized (i.e., the changes will occur in a 3961 specific order). 3962 3963 Changes to a program object made by one rendering context are not 3964 guaranteed to take effect in another rendering context until the 3965 other calls BindProgram to bind the program object. 3966 3967 When a program object is deleted by one rendering context, the 3968 object itself is not destroyed until it is no longer the current 3969 program object in any context. However, the name of the deleted 3970 object is removed from the program object name space, so the next 3971 attempt to bind a program using the same name will create a new 3972 program object. Recall that destroying a program object bound in 3973 the current rendering context effectively unbinds the object being 3974 destroyed. 3975 3976 3977Dependencies on OpenGL 1.4 3978 3979 If OpenGL 1.4 is not supported, the modified equation for the 3980 calculation of level of detail by the TXB instruction in 3.11.6.3 3981 should read 3982 3983 lambda'(x,y) = log2[p(x,y)] + 3984 clamp(texunit_bias + fragment_bias) 3985 3986Dependencies on EXT_vertex_weighting and ARB_vertex_blend 3987 3988 If EXT_vertex_weighting and ARB_vertex_blend are both not supported, 3989 all discussions of multiple modelview matrices should be removed. 3990 3991 In particular, the line in the grammar 3992 3993 <stateMatrixName> ::= "modelview" <stateOptModMatNum> 3994 3995 should be changed to 3996 3997 <stateMatrixName> ::= "modelview" 3998 3999 and the rules <stateOptModMatNum> and <stateModMatNum> should be 4000 deleted. The first line of Table X.2.7 should be modified to read: 4001 4002 Binding Underlying State 4003 ------------------------------------ --------------------------- 4004 state.matrix.modelview modelview matrix 4005 4006 The caption for Table X.2.7 should be modified to exclude optional 4007 modelview matrix number. Subsequent references to "modelview matrix 4008 zero" and "modelview matrix 1" should be changed to "modelview 4009 matrix" and the example "state.matrix.modelview[1].row[0]" should be 4010 changed to "state.matrix.modelview.row[0]". 4011 4012 4013Dependencies on ARB_matrix_palette: 4014 4015 If ARB_matrix_palette is not supported, all discussions of the 4016 matrix palette should be removed. 4017 4018 In particular, the line 4019 4020 "palette" "[" <statePaletteMatNum> "]" 4021 4022 should be removed from the <stateMatrixName> grammar rule, and the 4023 <statePaletteMatNum> grammar rule should be removed entirely. 4024 "state.matrix.palette[n]" should be removed from Table X.2.7. 4025 4026 4027Dependencies on ARB_transpose_matrix 4028 4029 If ARB_transpose_matrix is not supported, the discussion of 4030 TRANSPOSE_CURRENT_MATRIX_ARB in the edits to section 6.1.2 should be 4031 removed. 4032 4033 4034Dependencies on EXT_fog_coord 4035 4036 If EXT_fog_coord is not supported, references to "fog coordinate" 4037 in the definition of the "fragment.fogcoord" attribute should be 4038 removed. 4039 4040Dependencies on EXT_texture_rectangle 4041 4042 If NV_texture_rectangle is not supported, the discussion of the 4043 rectangle (non-power-of-two) texture target in section 3.11.6 should 4044 be removed, and the line 4045 4046 "RECT" 4047 4048 should be removed from the <texTarget> grammar rule. 4049 4050 4051Interactions with ARB_shadow 4052 4053 The texture comparison introduced by ARB_shadow can be expressed in 4054 terms of a fragment program, and in fact use the same internal 4055 resources on some implementations. Therefore, if fragment program 4056 mode is enabled, the GL behaves as if TEXTURE_COMPARE_MODE_ARB is 4057 NONE. 4058 4059 4060Interactions with ARB_vertex_program 4061 4062 The program object management entrypoints described in sections 4063 2.14.1 (for vertex programs) and 3.11.1 (for fragment programs) 4064 are shared by both program targets. The PROGRAM_ERROR_STRING_ARB 4065 and program queries in sections 6.1.11 and 6.1.12 are also shared, 4066 as are all common tokens. 4067 4068 The Errors section should be modified to generate INVALID_OPERATION 4069 from the Get command with argument CURRENT_MATRIX_ARB, 4070 TRANSPOSE_CURRENT_MATRIX_ARB, and CURRENT_MATRIX_STACK_DEPTH_ARB 4071 when the current matrix mode is TEXTURE. 4072 4073 In the presence of ARB_vertex_program, ARB_fragment_program must 4074 recognize and return appropriate values for the GetProgram <pname> 4075 tokens introduced in that spec but not otherwise shared by 4076 ARB_fragment_program: 4077 4078 PROGRAM_ADDRESS_REGISTERS_ARB 0x88B0 4079 MAX_PROGRAM_ADDRESS_REGISTERS_ARB 0x88B1 4080 PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB 0x88B2 4081 MAX_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB 0x88B3 4082 4083 The following tables list new program object state and 4084 implementation-dependent state: 4085 4086 Get Value Type Get Command Initial Value Description Sec Attrib 4087 -------------------- ----- ------------------- --------------- ---------------------- -------- ------ 4088 PROGRAM_ADDRESS_REGISTERS_ARB Z+ GetProgramivARB 0 bound program 6.1.12 - 4089 address registers 4090 PROGRAM_NATIVE_ADDRESS_ Z+ GetProgramivARB 0 bound program native 6.1.12 - 4091 REGISTERS_ARB address registers 4092 4093 Table X.7. Program Object State. Program object queries return attributes of 4094 the program object currently bound to the program target <target>. 4095 4096 4097 Minimum 4098 Get Value Type Get Command Value Description Sec. Attrib 4099 --------- ---- ----------- ------- ----------- ---- ------ 4100 MAX_PROGRAM_ADDRESS_REGISTERS_ARB Z+ GetProgramivARB 0 maximum program 6.1.12 - 4101 address registers 4102 MAX_PROGRAM_NATIVE_ADDRESS_ Z+ GetProgramivARB 0 maximum program native 6.1.12 - 4103 REGISTERS_ARB address registers 4104 4105 Table X.10. New Implementation-Dependent Values Introduced by 4106 ARB_vertex_program. 4107 4108 4109 In the presence of ARB_fragment_program, ARB_vertex_program must 4110 recognize and return appropriate values for the GetProgram <pname> 4111 tokens introduced in this spec. The following tables list new 4112 program object state and implementation-dependent state: 4113 4114 Get Value Type Get Command Initial Value Description Sec Attrib 4115 -------------------- ----- ------------------- --------------- ---------------------- -------- ------ 4116 PROGRAM_ALU_INSTRUCTIONS_ARB Z+ GetProgramivARB 0 maximum program 6.1.12 - 4117 ALU instructions 4118 PROGRAM_TEX_INSTRUCTIONS_ARB Z+ GetProgramivARB 0 maximum program 6.1.12 - 4119 texture instructions 4120 PROGRAM_TEX_INDIRECTIONS_ARB Z+ GetProgramivARB 0 maximum program 6.1.12 - 4121 texture indirections 4122 PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB Z+ GetProgramivARB 0 maximum program native 6.1.12 - 4123 ALU instructions 4124 PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB Z+ GetProgramivARB 0 maximum program native 6.1.12 - 4125 texture instructions 4126 PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB Z+ GetProgramivARB 0 maximum program native 6.1.12 - 4127 texture indirections 4128 4129 Table X.7. Program Object State. Program object queries return attributes of 4130 the program object currently bound to the program target <target>. 4131 4132 4133 Minimum 4134 Get Value Type Get Command Value Description Sec. Attrib 4135 --------- ---- ----------- ------- ----------- ---- ------ 4136 MAX_PROGRAM_ALU_INSTRUCTIONS_ARB Z+ GetProgramivARB 0 Number of frag. prg. 6.1.12 - 4137 ALU instructions 4138 MAX_PROGRAM_TEX_INSTRUCTIONS_ARB Z+ GetProgramivARB 0 Number of frag. prg. 6.1.12 - 4139 texture instructions 4140 MAX_PROGRAM_TEX_INDIRECTIONS_ARB Z+ GetProgramivARB 0 Number of frag. prg. 6.1.12 - 4141 texture indirections 4142 MAX_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB Z+ GetProgramivARB 0 maximum program native 6.1.12 - 4143 ALU instructions 4144 MAX_PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB Z+ GetProgramivARB 0 maximum program native 6.1.12 - 4145 texture instructions 4146 MAX_PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB Z+ GetProgramivARB 0 maximum program native 6.1.12 - 4147 texture indirections 4148 4149 Table X.10. New Implementation-Dependent Values Introduced by 4150 ARB_fragment_program. 4151 4152 4153Interactions with ATI_fragment_shader 4154 4155 The existing ATI_fragment_shader extension, if supported, also 4156 provides a similar fragment programming model. Mixing the two 4157 models in a single application is possible but not recommended. 4158 FRAGMENT_PROGRAM_ARB has priority over FRAGMENT_SHADER_ATI if 4159 both are enabled. 4160 4161 4162Interactions with NV_fragment_program 4163 4164 The NV_fragment_program extension, if supported, also provides a 4165 similar programming model. This extension is incompatible with 4166 NV_fragment_program in a number of different ways. Mixing the two 4167 models in a single application is possible but not recommended. The 4168 interactions between the extensions are defined below. 4169 4170 Functions, enumerants, and programs defined in NV_fragment_program 4171 are called "NV functions", "NV enumerants", and "NV programs," 4172 respectively. Functions, enumerants, and programs defined in 4173 ARB_fragment_program are called "ARB functions", "ARB enumerants", 4174 and "ARB programs," respectively. 4175 4176 The following GL state is identical in the two extensions: 4177 4178 - Fragment program mode enable. The NV and ARB enumerants have 4179 different values, but the same effect. 4180 4181 - Program error position. 4182 4183 - Program error string. 4184 4185 - NV_fragment_program and ARB_fragment_program "program local 4186 parameters." 4187 4188 - Fragment program names, targets, formats, program string, 4189 program string lengths, and residency information. The ARB and 4190 NV query functions operate differently. The ARB query function 4191 does not allow queries of target (passed in to the query) and 4192 residency information. The NV query function does not allow 4193 queries of program name (passed in to the query) or format. The 4194 format of NV programs is always PROGRAM_FORMAT_ASCII_ARB. 4195 4196 - Program object name space. Program objects are created 4197 differently in the NV and ARB specs. Under the NV spec, program 4198 objects are created by calling LoadProgramNV. Under the ARB 4199 spec, program objects are created by calling BindProgramARB with 4200 an unused program name. 4201 4202 The following state is provided only by ARB_fragment_program: 4203 4204 - Program environment parameters. 4205 4206 - Implementation-dependent limits on the number of instructions, 4207 ALU instructions, texture instructions, texture indirections, 4208 program parameters, fragment attributes, resource counts, and 4209 native resource counts. The instruction limit is baked into the 4210 NV spec. Implementations supporting NV_fragment_program have no 4211 specific restrictions on the number of ALU instructions, texture 4212 instructions, texture indirections, or fragment attributes used. 4213 Such implementations also have no limit on program parameters 4214 used, except that no more than one may be used by any single 4215 program instruction. 4216 4217 The following state is provided only by NV_fragment_program: 4218 4219 - Named program parameters (variables defined in the program text 4220 and updated by name). 4221 4222 The following are additional functional differences between 4223 ARB_fragment_program and NV_fragment_program: 4224 4225 - NV programs use a set of register names, with no support for 4226 user-defined variables (other than parameters in the program). 4227 ARB programs provide no support for fixed variable names; all 4228 variables must be declared, explicitly or implicitly, in the 4229 program. 4230 4231 - ARB programs support parameter variables that can be bound to 4232 selected GL state variables, and are updated automatically when 4233 the underlying state changes. NV programs provide no such 4234 support; applications must set program parameters themselves. 4235 4236 - ARB_fragment_program doesn't provide explicit support for 4237 multiple data types (fx12, fp16, fp32) described in 4238 NV_fragment_program, and provides no mechanism for controlling 4239 the precision used to carry out arithmetic operations. 4240 4241 - ARB_fragment_program doesn't support condition codes, 4242 conditional writemasks, or the "C" instruction suffix that 4243 specifies a condition code update. 4244 4245 - ARB_fragment_program doesn't support an absolute value operator 4246 that can be applied to a source vector as it is loaded. 4247 4248 - ARB_fragment_program doesn't define behavior for many floating- 4249 point special cases. On platforms where NV_fragment_program is 4250 supported, ARB programs will have the same special-case 4251 behavior. 4252 4253 - Language to declare program parameters is slightly different 4254 (NV_fragment_program has "DECLARE" and "DEFINE"; 4255 ARB_fragment_program has "PARAM"). 4256 4257 - NV_fragment_program provides a number of instructions not found 4258 in ARB_fragment_program: 4259 4260 * DDX, DDY: partial derivatives relative to x and y. 4261 4262 * "PK*" and "UP*": packing and unpacking instructions. 4263 4264 * RFL: reflection vector. 4265 4266 * SEQ, SFL, SGT, SLE, SNE, STR: set on equal, false, greater 4267 than, less than or equal, not equal, and true, respectively. 4268 4269 * TXD: texture lookup w/partials. 4270 4271 * X2D: 2D coordinate transformation. 4272 4273 - ARB_fragment_program provides several instructions not found in 4274 NV_fragment_program, and there are a few instruction set 4275 differences: 4276 4277 * ABS: absolute value. ABS instructions are unnecessary in 4278 NV_fragment_program because of the free absolute value on 4279 input operator. Equivalent to: 4280 4281 MOV dst, |src|; 4282 4283 * CMP: compare. Roughly equivalent to the following 4284 sequence, but may be optimized further: 4285 4286 SLT tmp, src0; 4287 LRP dst, tmp, src1, src2; 4288 4289 * DPH: homogenous dot product. Equivalent to: 4290 4291 DP3 tmp, src0, src1; 4292 ADD dst, tmp, src0.w; 4293 4294 * KIL: kill fragment. Both extensions support this 4295 instruction, but the ARB instruction takes a vector 4296 operand rather than a condition code. 4297 4298 * SCS: sine/cosine. Emulated using the separate SIN and COS 4299 instructions in NV_fragment_program, which also have no 4300 restriction on the input values. 4301 4302 * SWZ: extended swizzle. On NV_fragment_program platforms, 4303 this instruction will be emulated using a single MAD 4304 instruction and a program parameter constant. 4305 4306 * TXB: texture sample with bias. Not exposed in the 4307 NV_fragment_program API. 4308 4309 * XPD: cross product. Emulated using a MUL and a MAD 4310 instruction. 4311 4312 4313GLX Protocol 4314 4315 The following rendering commands are sent to the server as part of 4316 a glXRender request: 4317 4318 BindProgramARB 4319 2 12 rendering command length 4320 2 4180 rendering command opcode 4321 4 ENUM target 4322 4 CARD32 program 4323 4324 ProgramEnvParameter4fvARB 4325 2 32 rendering command length 4326 2 4184 rendering command opcode 4327 4 ENUM target 4328 4 CARD32 index 4329 4 FLOAT32 params[0] 4330 4 FLOAT32 params[1] 4331 4 FLOAT32 params[2] 4332 4 FLOAT32 params[3] 4333 4334 ProgramEnvParameter4dvARB 4335 2 44 rendering command length 4336 2 4185 rendering command opcode 4337 4 ENUM target 4338 4 CARD32 index 4339 8 FLOAT64 params[0] 4340 8 FLOAT64 params[1] 4341 8 FLOAT64 params[2] 4342 8 FLOAT64 params[3] 4343 4344 ProgramLocalParameter4fvARB 4345 2 32 rendering command length 4346 2 4215 rendering command opcode 4347 4 ENUM target 4348 4 CARD32 index 4349 4 FLOAT32 params[0] 4350 4 FLOAT32 params[1] 4351 4 FLOAT32 params[2] 4352 4 FLOAT32 params[3] 4353 4354 ProgramLocalParameter4dvARB 4355 2 44 rendering command length 4356 2 4216 rendering command opcode 4357 4 ENUM target 4358 4 CARD32 index 4359 8 FLOAT64 params[0] 4360 8 FLOAT64 params[1] 4361 8 FLOAT64 params[2] 4362 8 FLOAT64 params[3] 4363 4364 The ProgramStringARB is potentially large, and hence can be sent in 4365 a glXRender or glXRenderLarge request. 4366 4367 ProgramStringARB 4368 2 16+len+p rendering command length 4369 2 4217 rendering command opcode 4370 4 ENUM target 4371 4 ENUM format 4372 4 sizei len 4373 len LISTofBYTE program 4374 p unused, p=pad(len) 4375 4376 If the command is encoded in a glxRenderLarge request, the 4377 command opcode and command length fields above are expanded to 4378 4 bytes each: 4379 4380 4 16+len+p rendering command length 4381 4 4217 rendering command opcode 4382 4383 The remaining commands are non-rendering commands. These commands 4384 are sent separately (i.e., not as part of a glXRender or 4385 glXRenderLarge request), using the glXVendorPrivateWithReply 4386 request: 4387 4388 DeleteProgramsARB 4389 1 CARD8 opcode (X assigned) 4390 1 17 GLX opcode (glXVendorPrivateWithReply) 4391 2 4+n request length 4392 4 1294 vendor specific opcode 4393 4 GLX_CONTEXT_TAG context tag 4394 4 INT32 n 4395 n*4 LISTofCARD32 programs 4396 4397 GenProgramsARB 4398 1 CARD8 opcode (X assigned) 4399 1 17 GLX opcode (glXVendorPrivateWithReply) 4400 2 4 request length 4401 4 1295 vendor specific opcode 4402 4 GLX_CONTEXT_TAG context tag 4403 4 INT32 n 4404 => 4405 1 1 reply 4406 1 unused 4407 2 CARD16 sequence number 4408 4 n reply length 4409 24 unused 4410 n*4 LISTofCARD322 programs 4411 4412 GetProgramEnvParameterfvARB 4413 1 CARD8 opcode (X assigned) 4414 1 17 GLX opcode (glXVendorPrivateWithReply) 4415 2 6 request length 4416 4 1296 vendor specific opcode 4417 4 GLX_CONTEXT_TAG context tag 4418 4 ENUM target 4419 4 CARD32 index 4420 4 ENUM pname 4421 => 4422 1 1 reply 4423 1 unused 4424 2 CARD16 sequence number 4425 4 m reply length, m=(n==1?0:n) 4426 4 unused 4427 4 CARD32 n (number of parameter components) 4428 4429 if (n=1) this follows: 4430 4431 4 FLOAT32 params 4432 12 unused 4433 4434 otherwise this follows: 4435 4436 16 unused 4437 n*4 LISTofFLOAT32 params 4438 4439 GetProgramEnvParameterdvARB 4440 1 CARD8 opcode (X assigned) 4441 1 17 GLX opcode (glXVendorPrivateWithReply) 4442 2 6 request length 4443 4 1297 vendor specific opcode 4444 4 GLX_CONTEXT_TAG context tag 4445 4 ENUM target 4446 4 CARD32 index 4447 4 ENUM pname 4448 => 4449 1 1 reply 4450 1 unused 4451 2 CARD16 sequence number 4452 4 m reply length, m=(n==1?0:n*2) 4453 4 unused 4454 4 CARD32 n (number of parameter components) 4455 4456 if (n=1) this follows: 4457 4458 8 FLOAT64 params 4459 8 unused 4460 4461 otherwise this follows: 4462 4463 16 unused 4464 n*8 LISTofFLOAT64 params 4465 4466 GetProgramLocalParameterfvARB 4467 1 CARD8 opcode (X assigned) 4468 1 17 GLX opcode (glXVendorPrivateWithReply) 4469 2 6 request length 4470 4 1305 vendor specific opcode 4471 4 GLX_CONTEXT_TAG context tag 4472 4 ENUM target 4473 4 CARD32 index 4474 4 ENUM pname 4475 => 4476 1 1 reply 4477 1 unused 4478 2 CARD16 sequence number 4479 4 m reply length, m=(n==1?0:n) 4480 4 unused 4481 4 CARD32 n (number of parameter components) 4482 4483 if (n=1) this follows: 4484 4485 4 FLOAT32 params 4486 12 unused 4487 4488 otherwise this follows: 4489 4490 16 unused 4491 n*4 LISTofFLOAT32 params 4492 4493 GetProgramLocalParameterdvARB 4494 1 CARD8 opcode (X assigned) 4495 1 17 GLX opcode (glXVendorPrivateWithReply) 4496 2 6 request length 4497 4 1306 vendor specific opcode 4498 4 GLX_CONTEXT_TAG context tag 4499 4 ENUM target 4500 4 CARD32 index 4501 4 ENUM pname 4502 => 4503 1 1 reply 4504 1 unused 4505 2 CARD16 sequence number 4506 4 m reply length, m=(n==1?0:n*2) 4507 4 unused 4508 4 CARD32 n (number of parameter components) 4509 4510 if (n=1) this follows: 4511 4512 8 FLOAT64 params 4513 8 unused 4514 4515 otherwise this follows: 4516 4517 16 unused 4518 n*8 LISTofFLOAT64 params 4519 4520 GetProgramivARB 4521 1 CARD8 opcode (X assigned) 4522 1 17 GLX opcode (glXVendorPrivateWithReply) 4523 2 5 request length 4524 4 1307 vendor specific opcode 4525 4 GLX_CONTEXT_TAG context tag 4526 4 ENUM target 4527 4 ENUM pname 4528 => 4529 1 1 reply 4530 1 unused 4531 2 CARD16 sequence number 4532 4 m reply length, m=(n==1?0:n) 4533 4 unused 4534 4 CARD32 n 4535 4536 if (n=1) this follows: 4537 4538 4 INT32 params 4539 12 unused 4540 4541 otherwise this follows: 4542 4543 16 unused 4544 n*4 LISTofINT32 params 4545 4546 GetProgramStringARB 4547 1 CARD8 opcode (X assigned) 4548 1 17 GLX opcode (glXVendorPrivateWithReply) 4549 2 5 request length 4550 4 1308 vendor specific opcode 4551 4 GLX_CONTEXT_TAG context tag 4552 4 ENUM target 4553 4 ENUM pname 4554 => 4555 1 1 reply 4556 1 unused 4557 2 CARD16 sequence number 4558 4 (n+p)/4 reply length 4559 4 unused 4560 4 CARD32 n 4561 16 unused 4562 n STRING program 4563 p unused, p=pad(n) 4564 4565 IsProgramARB 4566 1 CARD8 opcode (X assigned) 4567 1 17 GLX opcode (glXVendorPrivateWithReply) 4568 2 4 request length 4569 4 1304 vendor specific opcode 4570 4 GLX_CONTEXT_TAG context tag 4571 4 INT32 n 4572 => 4573 1 1 reply 4574 1 unused 4575 2 CARD16 sequence number 4576 4 0 reply length 4577 4 BOOL32 return value 4578 20 unused 4579 4580 4581Errors 4582 4583 The error INVALID_OPERATION is generated by ProgramStringARB if the 4584 program string <string> is syntactically incorrect or violates any 4585 semantic restriction of the execution environment of the specified 4586 program target <target>. The error INVALID_OPERATION may also be 4587 generated by ProgramStringARB if the specified program would exceed 4588 native resource limits of the implementation. 4589 4590 The error INVALID_OPERATION is generated by BindProgramARB if 4591 <program> is the name of a program whose target does not match 4592 <target>. 4593 4594 The error INVALID_VALUE is generated by commands 4595 ProgramEnvParameter{fd}ARB, ProgramEnvParameter{fd}vARB, and 4596 GetProgramEnvParameter{fd}vARB if <index> is greater than or equal 4597 to the value of MAX_PROGRAM_ENV_PARAMETERS_ARB corresponding to the 4598 program target <target>. 4599 4600 The error INVALID_VALUE is generated by commands 4601 ProgramLocalParameter4{fd}ARB, ProgramLocalParameter4{fd}vARB, and 4602 GetProgramLocalParameter{fd}vARB if <index> is greater than or equal 4603 to the value of MAX_PROGRAM_LOCAL_PARAMETERS_ARB corresponding to 4604 the program target <target>. 4605 4606 The error INVALID_OPERATION is generated if Begin, RasterPos, or any 4607 command that performs an explicit Begin is called when fragment 4608 program mode is enabled and the currently bound fragment program 4609 object does not contain a valid fragment program. 4610 4611 The error INVALID_OPERATION is generated by any command accessing 4612 texture coordinate processing state if the texture unit number 4613 corresponding to the current value of ACTIVE_TEXTURE is greater than 4614 or equal to the implementation-dependent constant 4615 MAX_TEXTURE_COORDS_ARB. Such commands include: GetTexGen{if}v; 4616 TexGen{ifd}, TexGen{ifd}v; Disable, Enable, IsEnabled with argument 4617 TEXTURE_GEN_{STRQ}; Get with argument CURRENT_TEXTURE_COORDS, 4618 CURRENT_RASTER_TEXTURE_COORDS, TEXTURE_STACK_DEPTH, TEXTURE_MATRIX, 4619 TRANSPOSE_TEXTURE_MATRIX; when the current matrix mode is TEXTURE, 4620 Frustum, LoadIdentity, LoadMatrix{fd}, LoadTransposeMatrix{fd}, 4621 MultMatrix{fd}, MultTransposeMatrix{fd}, Ortho, PopMatrix, 4622 PushMatrix, Rotate{fd}, Scale{fd}, Translate{fd}. 4623 4624 The error INVALID_OPERATION is generated by any command accessing 4625 texture image processing state if the texture unit number 4626 corresponding to the current value of ACTIVE_TEXTURE is greater than 4627 or equal to the implementation-dependent constant 4628 MAX_TEXTURE_IMAGE_UNITS_ARB. Such commands include: BindTexture; 4629 GetCompressedTexImage, GetTexEnv{if}v, GetTexImage, 4630 GetTexLevelParameter{if}v, GetTexParameter{if}v; TexEnv{if}, 4631 TexEnv{if}v, TexParameter{if}, TexParameter{if}v; Disable, Enable, 4632 IsEnabled with argument TEXTURE_{123}D, TEXTURE_CUBE_MAP; Get with 4633 argument TEXTURE_BINDING_{123}D, TEXTURE_BINDING_CUBE_MAP; 4634 CompressedTexImage{123}D, CompressedTexSubImage{123}D, 4635 CopyTexImage{12}D, CopyTexSubImage{123}D, TexImage{123}D, 4636 TexSubImage{123}D. 4637 4638 4639New State 4640 4641 4642 Get Value Type Get Command Initial Value Description Section Attribute 4643 ------------------------------- ------ ------------- ------------- ------------------ ------------ ------------ 4644 FRAGMENT_PROGRAM_ARB B IsEnabled False fragment program 3.8 enable 4645 enable 4646 - 24+xR4 GetProgramEnv- (0,0,0,0) program environment 3.11.1 - 4647 ParameterARB parameters 4648 PROGRAM_ERROR_POSITION_ARB Z GetIntegerv -1 last program error 3.11.1 - 4649 position 4650 PROGRAM_ERROR_STRING_ARB 0+xub GetString "" last program error 3.11.1 - 4651 string 4652 4653 Table X.6. New Accessible State Introduced by ARB_fragment_program. 4654 4655 4656 Get Value Type Get Command Initial Value Description Sec Attrib 4657 -------------------- ----- ------------------- --------------- ---------------------- -------- ------ 4658 PROGRAM_BINDING_ARB Z+ GetProgramivARB object-specific bound program name 6.1.12 - 4659 PROGRAM_LENGTH_ARB Z+ GetProgramivARB 0 bound program length 6.1.12 - 4660 PROGRAM_FORMAT_ARB Z1 GetProgramivARB PROGRAM_FORMAT_ bound program format 6.1.12 - 4661 ASCII_ARB 4662 PROGRAM_STRING_ARB ubxn GetProgramStringARB (empty) bound program string 6.1.12 - 4663 PROGRAM_INSTRUCTIONS_ARB Z+ GetProgramivARB 0 bound program 6.1.12 - 4664 total instructions 4665 PROGRAM_ALU_INSTRUCTIONS_ARB Z+ GetProgramivARB 0 bound program 6.1.12 - 4666 ALU instructions 4667 PROGRAM_TEX_INSTRUCTIONS_ARB Z+ GetProgramivARB 0 bound program 6.1.12 - 4668 texture instructions 4669 PROGRAM_TEX_INDIRECTIONS_ARB Z+ GetProgramivARB 0 bound program 6.1.12 - 4670 texture indirections 4671 PROGRAM_TEMPORARIES_ARB Z+ GetProgramivARB 0 bound program 6.1.12 - 4672 temporaries 4673 PROGRAM_PARAMETERS_ARB Z+ GetProgramivARB 0 bound program 6.1.12 - 4674 parameter bindings 4675 PROGRAM_ATTRIBS_ARB Z+ GetProgramivARB 0 bound program 6.1.12 - 4676 attribute bindings 4677 PROGRAM_NATIVE_INSTRUCTIONS_ARB Z+ GetProgramivARB 0 bound program native 6.1.12 - 4678 instructions 4679 PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB Z+ GetProgramivARB 0 bound program native 6.1.12 - 4680 ALU instructions 4681 PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB Z+ GetProgramivARB 0 bound program native 6.1.12 - 4682 texture instructions 4683 PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB Z+ GetProgramivARB 0 bound program native 6.1.12 - 4684 texture indirections 4685 PROGRAM_NATIVE_TEMPORARIES_ARB Z+ GetProgramivARB 0 bound program native 6.1.12 - 4686 temporaries 4687 PROGRAM_NATIVE_PARAMETERS_ARB Z+ GetProgramivARB 0 bound program native 6.1.12 - 4688 parameter bindings 4689 PROGRAM_NATIVE_ATTRIBS_ARB Z+ GetProgramivARB 0 bound program native 6.1.12 - 4690 attribute bindings 4691 PROGRAM_UNDER_NATIVE_LIMITS_ARB B GetProgramivARB 0 bound program under 6.1.12 - 4692 native resource limits 4693 - 24+xR4 GetProgramLocal- (0,0,0,0) bound program local 3.11.1 - 4694 ParameterARB parameter value 4695 4696 Table X.7. Program Object State. Program object queries return attributes of 4697 the program object currently bound to the program target <target>. 4698 4699 4700 Get Value Type Get Command Initial Value Description Sec Attribute 4701 --------- ------ ----------- ------------- ------------------------- -------- --------- 4702 - 16+xR4 - undefined temporary registers 3.11.3.3 - 4703 - 2xR4 - undefined fragment result registers 3.11.3.4 - 4704 4705 Table X.8. Fragment Program Per-fragment Execution State. All per-fragment 4706 execution state registers are uninitialized at the beginning of program 4707 execution. 4708 4709 4710 Get Value Type Get Command Initial Value Description Sec Attribute 4711 ------------------------------ -------- -------------- ------------- ------------------- ------- --------- 4712 CURRENT_MATRIX_ARB m*n*xM^4 GetFloatv Identity current matrix 6.1.2 - 4713 CURRENT_MATRIX_STACK_DEPTH_ARB m*Z+ GetIntegerv 1 current stack depth 6.1.2 - 4714 4715 Table X.9. Current matrix state where m is the total number of matrices 4716 including texture matrices and program matrices and n is the number of 4717 matrices on each particular matrix stack. Note that this state is aliased 4718 with existing matrix state. 4719 4720 4721New Implementation Dependent State 4722 Minimum 4723 Get Value Type Get Command Value Description Sec. Attrib 4724 --------- ---- ----------- ------- ----------- ---- ------ 4725 MAX_TEXTURE_COORDS_ARB Z+ GetIntegerv 2 number of texture 2.7 - 4726 coordinate sets 4727 MAX_TEXTURE_IMAGE_UNITS_ARB Z+ GetIntegerv 2 number of texture 2.10.2 - 4728 image units 4729 MAX_PROGRAM_ENV_PARAMETERS_ARB Z+ GetProgramivARB 24 maximum program 3.11.1 - 4730 env parameters 4731 MAX_PROGRAM_LOCAL_PARAMETERS_ARB Z+ GetProgramivARB 24 maximum program 3.11.1 - 4732 local parameters 4733 MAX_PROGRAM_MATRICES_ARB Z+ GetIntegerv 8 (not to maximum number of 3.11.7 - 4734 exceed 32) program matrices 4735 MAX_PROGRAM_MATRIX_STACK_DEPTH_ARB Z+ GetIntegerv 1 maximum program 3.11.7 - 4736 matrix stack depth 4737 MAX_PROGRAM_INSTRUCTIONS_ARB Z+ GetProgramivARB 72 maximum program 6.1.12 - 4738 total instructions 4739 MAX_PROGRAM_ALU_INSTRUCTIONS_ARB Z+ GetProgramivARB 48 number of frag. prg. 6.1.12 - 4740 ALU instructions 4741 MAX_PROGRAM_TEX_INSTRUCTIONS_ARB Z+ GetProgramivARB 24 number of frag. prg. 6.1.12 - 4742 texture instructions 4743 MAX_PROGRAM_TEX_INDIRECTIONS_ARB Z+ GetProgramivARB 4 number of frag. prg. 6.1.12 - 4744 texture indirections 4745 MAX_PROGRAM_TEMPORARIES_ARB Z+ GetProgramivARB 16 maximum program 6.1.12 - 4746 temporaries 4747 MAX_PROGRAM_PARAMETERS_ARB Z+ GetProgramivARB 24 maximum program 6.1.12 - 4748 parameter bindings 4749 MAX_PROGRAM_ATTRIBS_ARB Z+ GetProgramivARB 10 maximum program 6.1.12 - 4750 attribute bindings 4751 MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB Z+ GetProgramivARB - maximum program native 6.1.12 - 4752 total instructions 4753 MAX_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB Z+ GetProgramivARB - maximum program native 6.1.12 - 4754 ALU instructions 4755 MAX_PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB Z+ GetProgramivARB - maximum program native 6.1.12 - 4756 texture instructions 4757 MAX_PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB Z+ GetProgramivARB - maximum program native 6.1.12 - 4758 texture indirections 4759 MAX_PROGRAM_NATIVE_TEMPORARIES_ARB Z+ GetProgramivARB - maximum program native 6.1.12 - 4760 temporaries 4761 MAX_PROGRAM_NATIVE_PARAMETERS_ARB Z+ GetProgramivARB - maximum program native 6.1.12 - 4762 parameter bindings 4763 MAX_PROGRAM_NATIVE_ATTRIBS_ARB Z+ GetProgramivARB - maximum program native 6.1.12 - 4764 attribute bindings 4765 4766 Table X.10. New Implementation-Dependent Values Introduced by 4767 ARB_fragment_program. Values queried by GetProgram require a <pname> of 4768 FRAGMENT_PROGRAM_ARB. 4769 4770 4771Sample Usage 4772 4773 The following program shows how to perform a simple modulation 4774 between the interpolated color and a single texture: 4775 4776 !!ARBfp1.0 4777 # Simple program to show how to code up the default texture environment 4778 4779 ATTRIB tex = fragment.texcoord; #first set of texture coordinates 4780 ATTRIB col = fragment.color.primary; #diffuse interpolated color 4781 4782 OUTPUT outColor = result.color; 4783 4784 TEMP tmp; 4785 4786 TXP tmp, tex, texture, 2D; #sample the texture 4787 4788 MUL outColor, tmp, col; #perform the modulation 4789 4790 END 4791 4792 The following is an example the simulates a chrome surface: 4793 4794 !!ARBfp1.0 4795 4796 ######################## 4797 # Input Textures: 4798 #----------------------- 4799 # Texture 0 contains the default 2D texture used for general mapping 4800 # Texture 2 contains a 1D pointlight falloff map 4801 # Texture 3 contains a 2D map for calculating specular lighting 4802 # Texture 4 contains normalizer cube map 4803 # 4804 # Input Texture Coordinates: 4805 #----------------------- 4806 # TexCoord1 contains the calculated normal 4807 # TexCoord2 contains the light to vertex vector 4808 # TexCoord3 contains the half-vector in tangent space 4809 # TexCoord4 contains the light vector in tangent space 4810 # TexCoord5 contains the eye vector in tangent space 4811 ######################## 4812 4813 TEMP NdotH, lV, L; 4814 4815 ALIAS diffuse = L; 4816 PARAM half = { 0.5, 0.5, 0.5, 0.5 }; 4817 ATTRIB norm_tc = fragment.texcoord[1]; 4818 ATTRIB lv_tc = fragment.texcoord[2]; 4819 ATTRIB half_tc = fragment.texcoord[3]; 4820 ATTRIB light_tc = fragment.texcoord[4]; 4821 ATTRIB eye_tc = fragment.texcoord[5]; 4822 OUTPUT oCol = result.color; 4823 4824 TEX L, light_tc, texture[4], CUBE; # Sample cube map normalizer 4825 4826 # Calculate diffuse lighting (N.L) 4827 SUB L, L, half; # Bias L and then multiply by 2 4828 ADD L, L, L; 4829 DP3 diffuse, norm_tc, L; # N.L 4830 4831 # Calculate specular lighting component { (N.H), |H|^2 } 4832 DP3 NdotH.x, norm_tc, half_tc; 4833 DP3 NdotH.y, half_tc, half_tc; 4834 4835 DP3 lV.x, lv_tc, lv_tc; # lV = (|light to vertex|)^2 4836 4837 4838 ############# 4839 # Pass 2 4840 ############# 4841 4842 TEMP base, specular; 4843 ALIAS atten = lV; 4844 4845 TEX base, eye_tc, texture[0], 2D; # sample enviroment map using eye vector 4846 TEX atten, lV, texture[2], 1D; # Sample attenuation map 4847 TEX specular, NdotH, texture[3], 2D; # Sample specular NHHH map= (N.H)^256 4848 4849 # specular = (N.H)^256 * (N.L) 4850 # this ensures a pixel is only lit if facing the light (since the specular 4851 # exponent makes negative N.H positive we must do this) 4852 MUL specular, specular, diffuse; 4853 4854 # specular = specular * environment map 4855 MUL specular, base, specular; 4856 4857 # diffuse = diffuse * environment map 4858 MUL diffuse, base, diffuse; 4859 4860 # outColor = (specular * environment map) + (diffuse * environment map) 4861 ADD base, specular, diffuse; 4862 4863 # Apply point light attenutaion 4864 MUL oCol, base, atten.r; 4865 4866 END 4867 4868 4869Revision History 4870 4871 Date: 10/08/2013 4872 Revision: 28 4873 - Change GLvoid -> void (Bug 10412). 4874 4875 Date: 11/04/2006 4876 Revision: 27 4877 - Updated contact info after ATI/AMD merger. 4878 4879 Date: 8/22/2003 4880 Revision: 26 4881 - Added list of commands generating errors when active texture 4882 unit selector is out of range. 4883 - Fixed typo in <stateMatrixItem> rule. 4884 - Clarified behavior of fragment.position.z with respect to depth 4885 offset. 4886 4887 Date: 2/26/2003 4888 Revision: 25 4889 - Fixed description of KIL instruction to reflect less than zero 4890 test, not less than or equal to zero. 4891 - Clarified the processing of incoming and outgoing depths and 4892 colors to reflect the conversion to floating-point on input and 4893 the conversion to fixed-point on output. 4894 4895 Date: 1/10/2003 4896 Revision: 24 4897 - Fixed bug where "state.matrix.mvp" was specified incorrectly. 4898 It should be P*M0 rather than M0*P. 4899 - Added issue warning about CMP opcode's order of operands. 4900 4901 Date: 10/22/2002 4902 Revision: 23 4903 - Fixed reference to <extSwizComp> rule in 3.11.5.28. Instead 4904 reference both <xyzwExtSwizComp> and <rgbaExtSwizComp> rules. 4905 4906 Date: 10/02/2002 4907 Revision: 22 4908 - Fixed typo in section 3.11.1, where 8 program environment and 4909 8 program local parameters are listed as the minimums instead 4910 of 24 of each. Table X.10 had the correct values. 4911 - Fixed <stateTexEnvItem> to refer to legacy texture units. 4912 - Fixed typos in issue 29 pseudo-code, added some clarification. 4913 4914 Date: 9/19/2002 4915 Revision: 21 4916 - Added clarifying paragraph for native texture indirection 4917 counting, offering examples of possible cases where texture 4918 indirections may be increased. 4919 - Fixed typos in issues 25 and 29. 4920 4921 Date: 9/16/2002 4922 Revision: 20 4923 - Added precision hint program options. 4924 - Fixed various typos, reworded some parts for consistency. 4925 - Updated issues list. 4926 4927 Date: 9/13/2002 4928 Revision: 19 4929 - Promoted minimum precision of texture coordinates in 2.1.1. 4930 - Added ARB_fog_* program options. 4931 - Removed modification to 3.9, put clamps in 3.11.4.4. 4932 - Made 'texture' a reserved keyword in the grammar. 4933 - Fixed various typos. 4934 - Updated section 3.11.6. 4935 - Updated issues list. 4936 4937 Date: 9/11/2002 4938 Revision: 18 4939 - Updated for consistency with ARB_vertex_program revision 36. 4940 - Depth output moved to 3rd component of result.depth. 4941 - Fixed various typos, reworded things in many places. 4942 - Added NV_fragment_program interactions. 4943 - Updated issues list. 4944 4945 Date: 9/09/2002 4946 Revision: 17 4947 - Added fogcoord and position attributes. 4948 - Moved fragment program section to 3.11, after fog. 4949 - Changed MAX_TEXTURE_UNITS/MAX_AUX_TEXTURE_UNITS to 4950 MAX_TEXTURE_COORDS/MAX_TEXTURE_IMAGE_UNITS. 4951 - Removed TRC and MOD instructions. 4952 - Added SIN and COS instructions. 4953 - Added more clarity to resource consumption wording. 4954 - Added invariance wording concerning depth-replacement. 4955 - Added rule that a program that fails to load must always fail to 4956 load, regardless of GL state. 4957 - Updated issues list. 4958 4959 Date: 8/30/2002 4960 Revision: 16 4961 - Improved texture indirection description. 4962 - Defined result of sample from incomplete texture as (0,0,0,1). 4963 - Removed PROGRAMS_LOAD_OVER_NATIVE_LIMITS_ARB per-target query. 4964 - Allowed ProgramStringARB to fail on non-native programs. 4965 - Updated issues list. 4966 4967 Date: 8/28/2002 4968 Revision: 15 4969 - Updated for consistency with ARB_vertex_program revision 35. 4970 - Added PROGRAMS_LOAD_OVER_NATIVE_LIMITS_ARB per-target query. 4971 - Changed MAX_AUX_TEXTURE_UNITS_ARB enum value. 4972 - Updated issues list. 4973 4974 Date: 8/22/2002 4975 Revision: 14 4976 - Added sine/cosine instruction (SCS). 4977 - Updated texture sample grammar, replaced texenables hierarchy. 4978 - Added EXT_vertex_weighting and ARB_vertex_blend dependency. 4979 - Updated issues list. 4980 4981 Date: 8/14/2002 4982 Revision: 13 4983 - Fixed <paramConstant> grammar rule. 4984 - Updated issues list. 4985 4986 Date: 8/06/2002 4987 Revision: 12 4988 - Fixed various typos. 4989 - Updated issues list. 4990 - Added wording to 3.10.3.6 to reflect that native resource 4991 consumption may increase due to emulated instructions. 4992 4993 Date: 7/29/2002 4994 Revision: 11 4995 - Updated for consistency with ARB_vertex_program revision 34. 4996 - Added support for matrix binding. 4997 - Removed precision queries. 4998 - Updated issues list. 4999 5000 Date: 7/16/2002 5001 Revision: 10 5002 - Updated for consistency with ARB_vertex_program revision 31. 5003 - Added fog params and depth range bindings to grammar. 5004 - Removed stpq writemasks and swizzles from grammar. 5005 - Required swizzle components to come from same set, xyzw or rgba. 5006 5007 Date: 7/10/2002 5008 Revision: 9 5009 - Made fog params and depth range bindable. 5010 - Changed texture instruction names to match 3-letter format. 5011 - Made texture instructions more consistent with ALU instructions. 5012 - Increased minimums for implementation-dependent values. 5013 - Re-introduced 4-components swizzles and the SWZ instruction. 5014 - Updated issues list. 5015 5016 Date: 7/03/2002 5017 Revision: 8 5018 - Fixed typos. 5019 - Added DST, LIT, SGE, SLT instructions. 5020 - Changed FRC definition to match ARB_vertex_program, added MOD 5021 instruction to expose fmod(arg, 1.0) behavior. 5022 5023 Date: 6/25/2002 5024 Revision: 7 5025 - Updated for consistency with ARB_vertex_program revision 29. 5026 5027 Date: 6/19/2002 5028 Revision: 6 5029 - Updated for consistency with ARB_vertex_program revision 28. 5030 - Changed from ATI to ARB prefix/suffix. 5031 - Started using single integer revision number. 5032 - Added a few more issues to the list. 5033 5034 Date: 6/14/2002 5035 Revision: 1.4 5036 - Updated for consistency with ARB_vertex_program revision 27. 5037 - Added a few more issues to the list. 5038 5039 Date: 6/05/2002 5040 Revision: 1.3 5041 - Updated for consistency with ARB_vertex_program revision 26. 5042 - Incorporated program object management, removing dependency on 5043 ARB_vertex_program. 5044 - Added interaction with ARB_shadow. 5045 5046 Date: 6/03/2002 5047 Revision: 1.2 5048 - Updated for consistency with ARB_vertex_program revision 25. 5049 - Fixed TexInstructions to use <texSrcReg>, i.e. no parameters. 5050 - Added TRC, POW, DPH instructions, updated FRC and LRP. 5051 - Added fog color parameter binding. 5052 5053 Date: 5/23/2002 5054 Revision: 1.1 5055 - Updated for consistency with ARB_vertex_program revision 24. 5056 - Added GetProgramfvATI entrypoint for querying precision values. 5057 5058 Date: 5/10/2002 5059 Revision: 1.0 5060 - First draft for circulation. 5061