-
Notifications
You must be signed in to change notification settings - Fork 94
/
glDrawPixels.xhtml
946 lines (920 loc) · 61.2 KB
/
glDrawPixels.xhtml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
<div class="refentry" lang="en" xml:lang="en"><a id="glDrawPixels"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>glDrawPixels — write a block of pixels to the frame buffer</p></div><div class="refsynopsisdiv"><h2>C Specification</h2><div class="funcsynopsis"><table><tr><td><code class="funcdef">void <b class="fsfunc">glDrawPixels</b>(</code></td><td>GLsizei </td><td><var class="pdparam">width</var>, </td></tr><tr><td> </td><td>GLsizei </td><td><var class="pdparam">height</var>, </td></tr><tr><td> </td><td>GLenum </td><td><var class="pdparam">format</var>, </td></tr><tr><td> </td><td>GLenum </td><td><var class="pdparam">type</var>, </td></tr><tr><td> </td><td>const GLvoid * </td><td><var class="pdparam">data</var><code>)</code>;</td></tr></table></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="parameters"></a><h2>Parameters</h2><div class="variablelist"><dl><dt><span class="term"><em class="parameter"><code>width</code></em>, </span><span class="term"><em class="parameter"><code>height</code></em></span></dt><dd><p>
Specify the dimensions of the pixel rectangle to be written
into the frame buffer.
</p></dd><dt><span class="term"><em class="parameter"><code>format</code></em></span></dt><dd><p>
Specifies the format of the pixel data.
Symbolic constants
<code class="constant">GL_COLOR_INDEX</code>,
<code class="constant">GL_STENCIL_INDEX</code>,
<code class="constant">GL_DEPTH_COMPONENT</code>,
<code class="constant">GL_RGB</code>,
<code class="constant">GL_BGR</code>,
<code class="constant">GL_RGBA</code>,
<code class="constant">GL_BGRA</code>,
<code class="constant">GL_RED</code>,
<code class="constant">GL_GREEN</code>,
<code class="constant">GL_BLUE</code>,
<code class="constant">GL_ALPHA</code>,
<code class="constant">GL_LUMINANCE</code>, and
<code class="constant">GL_LUMINANCE_ALPHA</code> are accepted.
</p></dd><dt><span class="term"><em class="parameter"><code>type</code></em></span></dt><dd><p>
Specifies the data type for <em class="parameter"><code>data</code></em>.
Symbolic constants
<code class="constant">GL_UNSIGNED_BYTE</code>,
<code class="constant">GL_BYTE</code>,
<code class="constant">GL_BITMAP</code>,
<code class="constant">GL_UNSIGNED_SHORT</code>,
<code class="constant">GL_SHORT</code>,
<code class="constant">GL_UNSIGNED_INT</code>,
<code class="constant">GL_INT</code>,
<code class="constant">GL_FLOAT</code>,
<code class="constant">GL_UNSIGNED_BYTE_3_3_2</code>,
<code class="constant">GL_UNSIGNED_BYTE_2_3_3_REV</code>,
<code class="constant">GL_UNSIGNED_SHORT_5_6_5</code>,
<code class="constant">GL_UNSIGNED_SHORT_5_6_5_REV</code>,
<code class="constant">GL_UNSIGNED_SHORT_4_4_4_4</code>,
<code class="constant">GL_UNSIGNED_SHORT_4_4_4_4_REV</code>,
<code class="constant">GL_UNSIGNED_SHORT_5_5_5_1</code>,
<code class="constant">GL_UNSIGNED_SHORT_1_5_5_5_REV</code>,
<code class="constant">GL_UNSIGNED_INT_8_8_8_8</code>,
<code class="constant">GL_UNSIGNED_INT_8_8_8_8_REV</code>,
<code class="constant">GL_UNSIGNED_INT_10_10_10_2</code>, and
<code class="constant">GL_UNSIGNED_INT_2_10_10_10_REV</code>
are accepted.
</p></dd><dt><span class="term"><em class="parameter"><code>data</code></em></span></dt><dd><p>
Specifies a pointer to the pixel data.
</p></dd></dl></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="description"></a><h2>Description</h2><p>
<code class="function">glDrawPixels</code> reads pixel data from memory and writes it into the frame buffer
relative to the current raster position, provided that the raster
position is valid. Use
<a class="citerefentry" href="glRasterPos"><span class="citerefentry"><span class="refentrytitle">glRasterPos</span></span></a> or <a class="citerefentry" href="glWindowPos"><span class="citerefentry"><span class="refentrytitle">glWindowPos</span></span></a> to set the current raster position; use
<a class="citerefentry" href="glGet"><span class="citerefentry"><span class="refentrytitle">glGet</span></span></a> with argument <code class="constant">GL_CURRENT_RASTER_POSITION_VALID</code>
to determine if the specified raster position is valid, and
<a class="citerefentry" href="glGet"><span class="citerefentry"><span class="refentrytitle">glGet</span></span></a> with argument <code class="constant">GL_CURRENT_RASTER_POSITION</code>
to query the raster position.
</p><p>
Several parameters define the encoding of pixel data in memory
and control the processing of the pixel data
before it is placed in the frame buffer.
These parameters are set with four commands:
<a class="citerefentry" href="glPixelStore"><span class="citerefentry"><span class="refentrytitle">glPixelStore</span></span></a>,
<a class="citerefentry" href="glPixelTransfer"><span class="citerefentry"><span class="refentrytitle">glPixelTransfer</span></span></a>,
<a class="citerefentry" href="glPixelMap"><span class="citerefentry"><span class="refentrytitle">glPixelMap</span></span></a>, and <a class="citerefentry" href="glPixelZoom"><span class="citerefentry"><span class="refentrytitle">glPixelZoom</span></span></a>.
This reference page describes the effects on <code class="function">glDrawPixels</code> of many,
but not all, of the parameters specified by these four commands.
</p><p>
Data is read from <em class="parameter"><code>data</code></em> as a sequence of signed or unsigned bytes,
signed or unsigned shorts, signed or unsigned integers, or
single-precision floating-point values, depending on <em class="parameter"><code>type</code></em>.
When <em class="parameter"><code>type</code></em> is one of <code class="constant">GL_UNSIGNED_BYTE</code>, <code class="constant">GL_BYTE</code>,
<code class="constant">GL_UNSIGNED_SHORT</code>, <code class="constant">GL_SHORT</code>, <code class="constant">GL_UNSIGNED_INT</code>,
<code class="constant">GL_INT</code>, or <code class="constant">GL_FLOAT</code> each of these bytes, shorts, integers, or
floating-point values is interpreted as one color or depth component, or
one index, depending on <em class="parameter"><code>format</code></em>.
When <em class="parameter"><code>type</code></em> is one of <code class="constant">GL_UNSIGNED_BYTE_3_3_2</code>,
<code class="constant">GL_UNSIGNED_SHORT_5_6_5</code>, <code class="constant">GL_UNSIGNED_SHORT_4_4_4_4</code>,
<code class="constant">GL_UNSIGNED_SHORT_5_5_5_1</code>, <code class="constant">GL_UNSIGNED_INT_8_8_8_8</code>, or
<code class="constant">GL_UNSIGNED_INT_10_10_10_2</code>, each unsigned value is interpreted as
containing all the components for a single pixel, with the color
components arranged according to <em class="parameter"><code>format</code></em>.
When <em class="parameter"><code>type</code></em> is one of <code class="constant">GL_UNSIGNED_BYTE_2_3_3_REV</code>,
<code class="constant">GL_UNSIGNED_SHORT_5_6_5_REV</code>, <code class="constant">GL_UNSIGNED_SHORT_4_4_4_4_REV</code>,
<code class="constant">GL_UNSIGNED_SHORT_1_5_5_5_REV</code>, <code class="constant">GL_UNSIGNED_INT_8_8_8_8_REV</code>, or
<code class="constant">GL_UNSIGNED_INT_2_10_10_10_REV</code>, each unsigned value is interpreted
as containing all color components, specified by <em class="parameter"><code>format</code></em>, for a single
pixel in a reversed order. Indices are always treated individually.
Color components are treated as groups of one, two, three, or four
values, again based on <em class="parameter"><code>format</code></em>. Both individual indices and groups of
components are referred to as pixels.
If <em class="parameter"><code>type</code></em> is <code class="constant">GL_BITMAP</code>, the data must be unsigned bytes, and
<em class="parameter"><code>format</code></em> must be either <code class="constant">GL_COLOR_INDEX</code> or <code class="constant">GL_STENCIL_INDEX</code>.
Each unsigned byte is treated as eight 1-bit pixels, with bit ordering
determined by <code class="constant">GL_UNPACK_LSB_FIRST</code> (see <a class="citerefentry" href="glPixelStore"><span class="citerefentry"><span class="refentrytitle">glPixelStore</span></span></a>).
</p><p>
<math overflow="scroll">
<mrow>
<mi mathvariant="italic">width</mi>
<mo>×</mo>
<mi mathvariant="italic">height</mi>
</mrow>
</math>
pixels are read from memory,
starting at location <em class="parameter"><code>data</code></em>.
By default, these pixels are taken from adjacent memory locations,
except that after all <em class="parameter"><code>width</code></em> pixels are read,
the read pointer is advanced to the next four-byte boundary.
The four-byte row alignment is specified by <a class="citerefentry" href="glPixelStore"><span class="citerefentry"><span class="refentrytitle">glPixelStore</span></span></a> with
argument <code class="constant">GL_UNPACK_ALIGNMENT</code>,
and it can be set to one, two, four, or eight bytes.
Other pixel store parameters specify different read pointer advancements,
both before the first pixel is read
and after all <em class="parameter"><code>width</code></em> pixels are read.
See the <a class="citerefentry" href="glPixelStore"><span class="citerefentry"><span class="refentrytitle">glPixelStore</span></span></a> reference page for details on these options.
</p><p>
If a non-zero named buffer object is bound to the <code class="constant">GL_PIXEL_UNPACK_BUFFER</code> target
(see <a class="citerefentry" href="glBindBuffer"><span class="citerefentry"><span class="refentrytitle">glBindBuffer</span></span></a>) while a block of pixels is
specified, <em class="parameter"><code>data</code></em> is treated as a byte offset into the buffer object's data store.
</p><p>
The
<math overflow="scroll">
<mrow>
<mi mathvariant="italic">width</mi>
<mo>×</mo>
<mi mathvariant="italic">height</mi>
</mrow>
</math>
pixels that are read from memory are
each operated on in the same way,
based on the values of several parameters specified by <a class="citerefentry" href="glPixelTransfer"><span class="citerefentry"><span class="refentrytitle">glPixelTransfer</span></span></a>
and <a class="citerefentry" href="glPixelMap"><span class="citerefentry"><span class="refentrytitle">glPixelMap</span></span></a>.
The details of these operations,
as well as the target buffer into which the pixels are drawn,
are specific to the format of the pixels,
as specified by <em class="parameter"><code>format</code></em>.
<em class="parameter"><code>format</code></em> can assume one of 13 symbolic values:
</p><div class="variablelist"><dl><dt><span class="term"><code class="constant">GL_COLOR_INDEX</code></span></dt><dd><p>
Each pixel is a single value,
a color index.
It is converted to fixed-point format,
with an unspecified number of bits to the right of the binary point,
regardless of the memory data type.
Floating-point values convert to true fixed-point values.
Signed and unsigned integer data is converted with all fraction bits
set to 0.
Bitmap data convert to either 0 or 1.
</p><p>
Each fixed-point index is then shifted left by <code class="constant">GL_INDEX_SHIFT</code> bits
and added to <code class="constant">GL_INDEX_OFFSET</code>.
If <code class="constant">GL_INDEX_SHIFT</code> is negative,
the shift is to the right.
In either case, zero bits fill otherwise unspecified bit locations in the
result.
</p><p>
If the GL is in RGBA mode,
the resulting index is converted to an RGBA pixel
with the help of the <code class="constant">GL_PIXEL_MAP_I_TO_R</code>,
<code class="constant">GL_PIXEL_MAP_I_TO_G</code>,
<code class="constant">GL_PIXEL_MAP_I_TO_B</code>,
and <code class="constant">GL_PIXEL_MAP_I_TO_A</code> tables.
If the GL is in color index mode,
and if <code class="constant">GL_MAP_COLOR</code> is true,
the index is replaced with the value that it references in lookup table
<code class="constant">GL_PIXEL_MAP_I_TO_I</code>.
Whether the lookup replacement of the index is done or not,
the integer part of the index is then ANDed with
<math overflow="scroll">
<mrow>
<msup><mn>2</mn>
<mi mathvariant="italic">b</mi>
</msup>
<mo>-</mo>
<mn>1</mn>
</mrow>
</math>,
where
<math overflow="scroll"><mi mathvariant="italic">b</mi></math>
is the number of bits in a color index buffer.
</p><p>
The GL then converts the resulting indices or RGBA colors to fragments
by attaching the current raster position <span class="emphasis"><em>z</em></span> coordinate and
texture coordinates to each pixel,
then assigning
<math overflow="scroll"><mi mathvariant="italic">x</mi></math>
and
<math overflow="scroll"><mi mathvariant="italic">y</mi></math>
window coordinates to the
<math overflow="scroll"><mi mathvariant="italic">n</mi></math>th
fragment such that
</p><div class="informalequation"><math overflow="scroll">
<mrow>
<msub><mi mathvariant="italic">x</mi>
<mi mathvariant="italic">n</mi>
</msub>
<mo>=</mo>
<mrow>
<msub><mi mathvariant="italic">x</mi>
<mi mathvariant="italic">r</mi>
</msub>
<mo>+</mo>
<mrow>
<mi mathvariant="italic">n</mi>
<mo>%</mo>
<mi mathvariant="italic">width</mi>
</mrow>
</mrow>
</mrow>
</math></div><p>
</p><p>
</p><div class="informalequation"><math overflow="scroll">
<mrow>
<msub><mi mathvariant="italic">y</mi>
<mi mathvariant="italic">n</mi>
</msub>
<mo>=</mo>
<mrow>
<msub><mi mathvariant="italic">y</mi>
<mi mathvariant="italic">r</mi>
</msub>
<mo>+</mo>
<mfenced open="⌊" close="⌋">
<mfrac>
<mi mathvariant="italic">n</mi>
<mi mathvariant="italic">width</mi>
</mfrac>
</mfenced>
</mrow>
</mrow>
</math></div><p>
</p><p>
</p><p>
</p><p>
</p><p>
where
<math overflow="scroll">
<mfenced open="(" close=")">
<msub><mi mathvariant="italic">x</mi>
<mi mathvariant="italic">r</mi>
</msub>
<msub><mi mathvariant="italic">y</mi>
<mi mathvariant="italic">r</mi>
</msub>
</mfenced>
</math>
is the current raster position.
These pixel fragments are then treated just like the fragments generated by
rasterizing points, lines, or polygons.
Texture mapping,
fog,
and all the fragment operations are applied before the fragments are written
to the frame buffer.
</p></dd><dt><span class="term"><code class="constant">GL_STENCIL_INDEX</code></span></dt><dd><p>
Each pixel is a single value,
a stencil index.
It is converted to fixed-point format,
with an unspecified number of bits to the right of the binary point,
regardless of the memory data type.
Floating-point values convert to true fixed-point values.
Signed and unsigned integer data is converted with all fraction bits
set to 0.
Bitmap data convert to either 0 or 1.
</p><p>
Each fixed-point index is then shifted left by <code class="constant">GL_INDEX_SHIFT</code> bits,
and added to <code class="constant">GL_INDEX_OFFSET</code>.
If <code class="constant">GL_INDEX_SHIFT</code> is negative,
the shift is to the right.
In either case, zero bits fill otherwise unspecified bit locations in the
result.
If <code class="constant">GL_MAP_STENCIL</code> is true,
the index is replaced with the value that it references in lookup table
<code class="constant">GL_PIXEL_MAP_S_TO_S</code>.
Whether the lookup replacement of the index is done or not,
the integer part of the index is then ANDed with
<math overflow="scroll">
<mrow>
<msup><mn>2</mn>
<mi mathvariant="italic">b</mi>
</msup>
<mo>-</mo>
<mn>1</mn>
</mrow>
</math>,
where
<math overflow="scroll"><mi mathvariant="italic">b</mi></math>
is the number of bits in the stencil buffer.
The resulting stencil indices are then written to the stencil buffer
such that the
<math overflow="scroll"><mi mathvariant="italic">n</mi></math>th
index is written to location
</p><p>
</p><div class="informalequation"><math overflow="scroll">
<mrow>
<msub><mi mathvariant="italic">x</mi>
<mi mathvariant="italic">n</mi>
</msub>
<mo>=</mo>
<mrow>
<msub><mi mathvariant="italic">x</mi>
<mi mathvariant="italic">r</mi>
</msub>
<mo>+</mo>
<mrow>
<mi mathvariant="italic">n</mi>
<mo>%</mo>
<mi mathvariant="italic">width</mi>
</mrow>
</mrow>
</mrow>
</math></div><p>
</p><p>
</p><div class="informalequation"><math overflow="scroll">
<mrow>
<msub><mi mathvariant="italic">y</mi>
<mi mathvariant="italic">n</mi>
</msub>
<mo>=</mo>
<mrow>
<msub><mi mathvariant="italic">y</mi>
<mi mathvariant="italic">r</mi>
</msub>
<mo>+</mo>
<mfenced open="⌊" close="⌋">
<mfrac>
<mi mathvariant="italic">n</mi>
<mi mathvariant="italic">width</mi>
</mfrac>
</mfenced>
</mrow>
</mrow>
</math></div><p>
</p><p>
</p><p>
where
<math overflow="scroll">
<mfenced open="(" close=")">
<msub><mi mathvariant="italic">x</mi>
<mi mathvariant="italic">r</mi>
</msub>
<msub><mi mathvariant="italic">y</mi>
<mi mathvariant="italic">r</mi>
</msub>
</mfenced>
</math>
is the current raster position.
Only the pixel ownership test,
the scissor test,
and the stencil writemask affect these write operations.
</p></dd><dt><span class="term"><code class="constant">GL_DEPTH_COMPONENT</code></span></dt><dd><p>
Each pixel is a single-depth component.
Floating-point data is converted directly to an internal floating-point
format with unspecified precision.
Signed integer data is mapped linearly to the internal floating-point
format such that the most positive representable integer value maps to 1.0,
and the most negative representable value maps to
<math overflow="scroll">
<mn>-1.0</mn>
</math>.
Unsigned integer data is mapped similarly:
the largest integer value maps to 1.0,
and 0 maps to 0.0.
The resulting floating-point depth value is then multiplied
by <code class="constant">GL_DEPTH_SCALE</code> and added to <code class="constant">GL_DEPTH_BIAS</code>.
The result is clamped to the range
<math overflow="scroll">
<mfenced open="[" close="]">
<mn>0</mn>
<mn>1</mn>
</mfenced>
</math>.
</p><p>
The GL then converts the resulting depth components to fragments
by attaching the current raster position color or color index and
texture coordinates to each pixel,
then assigning
<math overflow="scroll"><mi mathvariant="italic">x</mi></math>
and
<math overflow="scroll"><mi mathvariant="italic">y</mi></math>
window coordinates to the
<math overflow="scroll"><mi mathvariant="italic">n</mi></math>th
fragment such that
</p><p>
</p><div class="informalequation"><math overflow="scroll">
<mrow>
<msub><mi mathvariant="italic">x</mi>
<mi mathvariant="italic">n</mi>
</msub>
<mo>=</mo>
<mrow>
<msub><mi mathvariant="italic">x</mi>
<mi mathvariant="italic">r</mi>
</msub>
<mo>+</mo>
<mrow>
<mi mathvariant="italic">n</mi>
<mo>%</mo>
<mi mathvariant="italic">width</mi>
</mrow>
</mrow>
</mrow>
</math></div><p>
</p><p>
</p><div class="informalequation"><math overflow="scroll">
<mrow>
<msub><mi mathvariant="italic">y</mi>
<mi mathvariant="italic">n</mi>
</msub>
<mo>=</mo>
<mrow>
<msub><mi mathvariant="italic">y</mi>
<mi mathvariant="italic">r</mi>
</msub>
<mo>+</mo>
<mfenced open="⌊" close="⌋">
<mfrac>
<mi mathvariant="italic">n</mi>
<mi mathvariant="italic">width</mi>
</mfrac>
</mfenced>
</mrow>
</mrow>
</math></div><p>
</p><p>
</p><p>
where
<math overflow="scroll">
<mfenced open="(" close=")">
<msub><mi mathvariant="italic">x</mi>
<mi mathvariant="italic">r</mi>
</msub>
<msub><mi mathvariant="italic">y</mi>
<mi mathvariant="italic">r</mi>
</msub>
</mfenced>
</math>
is the current raster position.
These pixel fragments are then treated just like the fragments generated by
rasterizing points, lines, or polygons.
Texture mapping,
fog,
and all the fragment operations are applied before the fragments are written
to the frame buffer.
</p></dd><dt><span class="term"><code class="constant">GL_RGBA</code></span></dt><dd></dd><dt><span class="term"><code class="constant">GL_BGRA</code></span></dt><dd><p>
Each pixel is a four-component group: For <code class="constant">GL_RGBA</code>, the red
component is first, followed by green, followed by blue, followed by
alpha; for <code class="constant">GL_BGRA</code> the order is blue, green, red and then alpha.
Floating-point values are converted directly to an internal floating-point
format with unspecified precision.
Signed integer values are mapped linearly to the internal floating-point
format such that the most positive representable integer value maps to 1.0,
and the most negative representable value maps to
<math overflow="scroll">
<mn>-1.0</mn>
</math>.
(Note that
this mapping does not convert 0 precisely to 0.0.)
Unsigned integer data is mapped similarly:
The largest integer value maps to 1.0,
and 0 maps to 0.0.
The resulting floating-point color values are then multiplied
by <code class="constant">GL_c_SCALE</code> and added to <code class="constant">GL_c_BIAS</code>,
where <span class="emphasis"><em>c</em></span> is RED, GREEN, BLUE, and ALPHA
for the respective color components.
The results are clamped to the range
<math overflow="scroll">
<mfenced open="[" close="]">
<mn>0</mn>
<mn>1</mn>
</mfenced>
</math>.
</p><p>
If <code class="constant">GL_MAP_COLOR</code> is true,
each color component is scaled by the size of lookup table
<code class="constant">GL_PIXEL_MAP_c_TO_c</code>,
then replaced by the value that it references in that table.
<span class="emphasis"><em>c</em></span> is R, G, B, or A respectively.
</p><p>
The GL then converts the resulting RGBA colors to fragments
by attaching the current raster position <span class="emphasis"><em>z</em></span> coordinate and
texture coordinates to each pixel,
then assigning
<math overflow="scroll"><mi mathvariant="italic">x</mi></math>
and
<math overflow="scroll"><mi mathvariant="italic">y</mi></math>
window coordinates to the
<math overflow="scroll"><mi mathvariant="italic">n</mi></math>th
fragment such that
</p><p>
</p><div class="informalequation"><math overflow="scroll">
<mrow>
<msub><mi mathvariant="italic">x</mi>
<mi mathvariant="italic">n</mi>
</msub>
<mo>=</mo>
<mrow>
<msub><mi mathvariant="italic">x</mi>
<mi mathvariant="italic">r</mi>
</msub>
<mo>+</mo>
<mrow>
<mi mathvariant="italic">n</mi>
<mo>%</mo>
<mi mathvariant="italic">width</mi>
</mrow>
</mrow>
</mrow>
</math></div><p>
</p><p>
</p><div class="informalequation"><math overflow="scroll">
<mrow>
<msub><mi mathvariant="italic">y</mi>
<mi mathvariant="italic">n</mi>
</msub>
<mo>=</mo>
<mrow>
<msub><mi mathvariant="italic">y</mi>
<mi mathvariant="italic">r</mi>
</msub>
<mo>+</mo>
<mfenced open="⌊" close="⌋">
<mfrac>
<mi mathvariant="italic">n</mi>
<mi mathvariant="italic">width</mi>
</mfrac>
</mfenced>
</mrow>
</mrow>
</math></div><p>
</p><p>
</p><p>
where
<math overflow="scroll">
<mfenced open="(" close=")">
<msub><mi mathvariant="italic">x</mi>
<mi mathvariant="italic">r</mi>
</msub>
<msub><mi mathvariant="italic">y</mi>
<mi mathvariant="italic">r</mi>
</msub>
</mfenced>
</math>
is the current raster position.
These pixel fragments are then treated just like the fragments generated by
rasterizing points, lines, or polygons.
Texture mapping,
fog,
and all the fragment operations are applied before the fragments are written
to the frame buffer.
</p></dd><dt><span class="term"><code class="constant">GL_RED</code></span></dt><dd><p>
Each pixel is a single red component.
This component is converted to the internal floating-point format in
the same way the red component of an RGBA pixel is. It is
then converted to an RGBA pixel with green and blue set to 0,
and alpha set to 1.
After this conversion, the pixel is treated as if it had been read
as an RGBA pixel.
</p></dd><dt><span class="term"><code class="constant">GL_GREEN</code></span></dt><dd><p>
Each pixel is a single green component.
This component is converted to the internal floating-point format in
the same way the green component of an RGBA pixel is.
It is then converted to an RGBA pixel with red and blue set to 0,
and alpha set to 1.
After this conversion, the pixel is treated as if it had been read
as an RGBA pixel.
</p></dd><dt><span class="term"><code class="constant">GL_BLUE</code></span></dt><dd><p>
Each pixel is a single blue component.
This component is converted to the internal floating-point format in
the same way the blue component of an RGBA pixel is.
It is then converted to an RGBA pixel with red and green set to 0,
and alpha set to 1.
After this conversion, the pixel is treated as if it had been read
as an RGBA pixel.
</p></dd><dt><span class="term"><code class="constant">GL_ALPHA</code></span></dt><dd><p>
Each pixel is a single alpha component.
This component is converted to the internal floating-point format in
the same way the alpha component of an RGBA pixel is.
It is then converted to an RGBA pixel with red, green, and blue set to 0.
After this conversion, the pixel is treated as if it had been read
as an RGBA pixel.
</p></dd><dt><span class="term"><code class="constant">GL_RGB</code></span></dt><dd></dd><dt><span class="term"><code class="constant">GL_BGR</code></span></dt><dd><p>
Each pixel is a three-component group:
red first, followed by green, followed by blue; for <code class="constant">GL_BGR</code>, the
first component is blue, followed by green and then red.
Each component is converted to the internal floating-point format in
the same way the red, green, and blue components of an RGBA pixel are.
The color triple is converted to an RGBA pixel with alpha set to 1.
After this conversion, the pixel is treated as if it had been read
as an RGBA pixel.
</p></dd><dt><span class="term"><code class="constant">GL_LUMINANCE</code></span></dt><dd><p>
Each pixel is a single luminance component.
This component is converted to the internal floating-point format in
the same way the red component of an RGBA pixel is.
It is then converted to an RGBA pixel with red, green, and blue set to the
converted luminance value,
and alpha set to 1.
After this conversion, the pixel is treated as if it had been read
as an RGBA pixel.
</p></dd><dt><span class="term"><code class="constant">GL_LUMINANCE_ALPHA</code></span></dt><dd><p>
Each pixel is a two-component group:
luminance first, followed by alpha.
The two components are converted to the internal floating-point format in
the same way the red component of an RGBA pixel is.
They are then converted to an RGBA pixel with red, green, and blue set to the
converted luminance value,
and alpha set to the converted alpha value.
After this conversion, the pixel is treated as if it had been read
as an RGBA pixel.
</p></dd></dl></div><p>
The following table summarizes the meaning of the valid constants for the
<span class="emphasis"><em>type</em></span> parameter:
</p><p>
</p><div class="informaltable"><table><colgroup><col /><col /></colgroup><thead><tr><th><span class="bold"><strong>
Type
</strong></span></th><th><span class="bold"><strong>
Corresponding Type
</strong></span></th></tr></thead><tbody><tr><td>
<code class="constant">GL_UNSIGNED_BYTE</code>
</td><td>
unsigned 8-bit integer
</td></tr><tr><td>
<code class="constant">GL_BYTE</code>
</td><td>
signed 8-bit integer
</td></tr><tr><td>
<code class="constant">GL_BITMAP</code>
</td><td>
single bits in unsigned 8-bit integers
</td></tr><tr><td>
<code class="constant">GL_UNSIGNED_SHORT</code>
</td><td>
unsigned 16-bit integer
</td></tr><tr><td>
<code class="constant">GL_SHORT</code>
</td><td>
signed 16-bit integer
</td></tr><tr><td>
<code class="constant">GL_UNSIGNED_INT</code>
</td><td>
unsigned 32-bit integer
</td></tr><tr><td>
<code class="constant">GL_INT</code>
</td><td>
32-bit integer
</td></tr><tr><td>
<code class="constant">GL_FLOAT</code>
</td><td>
single-precision floating-point
</td></tr><tr><td>
<code class="constant">GL_UNSIGNED_BYTE_3_3_2</code>
</td><td>
unsigned 8-bit integer
</td></tr><tr><td>
<code class="constant">GL_UNSIGNED_BYTE_2_3_3_REV</code>
</td><td>
unsigned 8-bit integer with reversed component ordering
</td></tr><tr><td>
<code class="constant">GL_UNSIGNED_SHORT_5_6_5</code>
</td><td>
unsigned 16-bit integer
</td></tr><tr><td>
<code class="constant">GL_UNSIGNED_SHORT_5_6_5_REV</code>
</td><td>
unsigned 16-bit integer with reversed component ordering
</td></tr><tr><td>
<code class="constant">GL_UNSIGNED_SHORT_4_4_4_4</code>
</td><td>
unsigned 16-bit integer
</td></tr><tr><td>
<code class="constant">GL_UNSIGNED_SHORT_4_4_4_4_REV</code>
</td><td>
unsigned 16-bit integer with reversed component ordering
</td></tr><tr><td>
<code class="constant">GL_UNSIGNED_SHORT_5_5_5_1</code>
</td><td>
unsigned 16-bit integer
</td></tr><tr><td>
<code class="constant">GL_UNSIGNED_SHORT_1_5_5_5_REV</code>
</td><td>
unsigned 16-bit integer with reversed component ordering
</td></tr><tr><td>
<code class="constant">GL_UNSIGNED_INT_8_8_8_8</code>
</td><td>
unsigned 32-bit integer
</td></tr><tr><td>
<code class="constant">GL_UNSIGNED_INT_8_8_8_8_REV</code>
</td><td>
unsigned 32-bit integer with reversed component ordering
</td></tr><tr><td>
<code class="constant">GL_UNSIGNED_INT_10_10_10_2</code>
</td><td>
unsigned 32-bit integer
</td></tr><tr><td>
<code class="constant">GL_UNSIGNED_INT_2_10_10_10_REV</code>
</td><td>
unsigned 32-bit integer with reversed component ordering
</td></tr></tbody></table></div><p>
</p><p>
</p><p>
The rasterization described so far assumes pixel zoom factors of 1.
If
<a class="citerefentry" href="glPixelZoom"><span class="citerefentry"><span class="refentrytitle">glPixelZoom</span></span></a> is used to change the
<math overflow="scroll"><mi mathvariant="italic">x</mi></math>
and
<math overflow="scroll"><mi mathvariant="italic">y</mi></math>
pixel zoom factors,
pixels are converted to fragments as follows.
If
<math overflow="scroll">
<mfenced open="(" close=")">
<msub><mi mathvariant="italic">x</mi>
<mi mathvariant="italic">r</mi>
</msub>
<msub><mi mathvariant="italic">y</mi>
<mi mathvariant="italic">r</mi>
</msub>
</mfenced>
</math>
is the current raster position,
and a given pixel is in the
<math overflow="scroll"><mi mathvariant="italic">n</mi></math>th
column and
<math overflow="scroll"><mi mathvariant="italic">m</mi></math>th
row
of the pixel rectangle,
then fragments are generated for pixels whose centers are in the rectangle
with corners at
</p><p>
</p><div class="informalequation"><math overflow="scroll">
<mfenced open="(" close=")">
<mrow>
<msub><mi mathvariant="italic">x</mi>
<mi mathvariant="italic">r</mi>
</msub>
<mo>+</mo>
<mfenced open="" close="">
<msub><mi mathvariant="italic">zoom</mi>
<mi mathvariant="italic">x</mi>
</msub>
</mfenced>
<mo></mo>
<mi mathvariant="italic">n</mi>
</mrow>
<mrow>
<msub><mi mathvariant="italic">y</mi>
<mi mathvariant="italic">r</mi>
</msub>
<mo>+</mo>
<mfenced open="" close="">
<msub><mi mathvariant="italic">zoom</mi>
<mi mathvariant="italic">y</mi>
</msub>
</mfenced>
<mo></mo>
<mi mathvariant="italic">m</mi>
</mrow>
</mfenced>
</math></div><p>
</p><p>
</p><div class="informalequation"><math overflow="scroll">
<mfenced open="(" close=")">
<mrow>
<msub><mi mathvariant="italic">x</mi>
<mi mathvariant="italic">r</mi>
</msub>
<mo>+</mo>
<mrow>
<mfenced open="" close="">
<msub><mi mathvariant="italic">zoom</mi>
<mi mathvariant="italic">x</mi>
</msub>
</mfenced>
<mo></mo>
<mfenced open="(" close=")">
<mrow>
<mi mathvariant="italic">n</mi>
<mo>+</mo>
<mn>1</mn>
</mrow>
</mfenced>
</mrow>
</mrow>
<mrow>
<msub><mi mathvariant="italic">y</mi>
<mi mathvariant="italic">r</mi>
</msub>
<mo>+</mo>
<mrow>
<mfenced open="" close="">
<msub><mi mathvariant="italic">zoom</mi>
<mi mathvariant="italic">y</mi>
</msub>
</mfenced>
<mo></mo>
<mfenced open="(" close=")">
<mrow>
<mi mathvariant="italic">m</mi>
<mo>+</mo>
<mn>1</mn>
</mrow>
</mfenced>
</mrow>
</mrow>
</mfenced>
</math></div><p>
</p><p>
</p><p>
where
<math overflow="scroll">
<msub><mi mathvariant="italic">zoom</mi>
<mi mathvariant="italic">x</mi>
</msub>
</math>
is the value of <code class="constant">GL_ZOOM_X</code> and
<math overflow="scroll">
<msub><mi mathvariant="italic">zoom</mi>
<mi mathvariant="italic">y</mi>
</msub>
</math>
is the value of <code class="constant">GL_ZOOM_Y</code>.
</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="notes"></a><h2>Notes</h2><p>
<code class="constant">GL_BGR</code> and <code class="constant">GL_BGRA</code> are only valid for <em class="parameter"><code>format</code></em> if the GL
version is 1.2 or greater.
</p><p>
<code class="constant">GL_UNSIGNED_BYTE_3_3_2</code>,
<code class="constant">GL_UNSIGNED_BYTE_2_3_3_REV</code>,
<code class="constant">GL_UNSIGNED_SHORT_5_6_5</code>,
<code class="constant">GL_UNSIGNED_SHORT_5_6_5_REV</code>,
<code class="constant">GL_UNSIGNED_SHORT_4_4_4_4</code>,
<code class="constant">GL_UNSIGNED_SHORT_4_4_4_4_REV</code>,
<code class="constant">GL_UNSIGNED_SHORT_5_5_5_1</code>,
<code class="constant">GL_UNSIGNED_SHORT_1_5_5_5_REV</code>,
<code class="constant">GL_UNSIGNED_INT_8_8_8_8</code>,
<code class="constant">GL_UNSIGNED_INT_8_8_8_8_REV</code>,
<code class="constant">GL_UNSIGNED_INT_10_10_10_2</code>, and
<code class="constant">GL_UNSIGNED_INT_2_10_10_10_REV</code> are only valid for <em class="parameter"><code>type</code></em> if the
GL version is 1.2 or greater.
</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="errors"></a><h2>Errors</h2><p>
<code class="constant">GL_INVALID_ENUM</code> is generated if <em class="parameter"><code>format</code></em> or <em class="parameter"><code>type</code></em> is not one of
the accepted values.
</p><p>
<code class="constant">GL_INVALID_ENUM</code> is generated if <em class="parameter"><code>type</code></em> is <code class="constant">GL_BITMAP</code> and
<em class="parameter"><code>format</code></em> is not either <code class="constant">GL_COLOR_INDEX</code> or <code class="constant">GL_STENCIL_INDEX</code>.
</p><p>
<code class="constant">GL_INVALID_VALUE</code> is generated if either <em class="parameter"><code>width</code></em> or <em class="parameter"><code>height</code></em> is negative.
</p><p>
<code class="constant">GL_INVALID_OPERATION</code> is generated if <em class="parameter"><code>format</code></em> is <code class="constant">GL_STENCIL_INDEX</code>
and there is no stencil buffer.
</p><p>
<code class="constant">GL_INVALID_OPERATION</code> is generated if <em class="parameter"><code>format</code></em> is
<code class="constant">GL_RED</code>,
<code class="constant">GL_GREEN</code>,
<code class="constant">GL_BLUE</code>,
<code class="constant">GL_ALPHA</code>,
<code class="constant">GL_RGB</code>,
<code class="constant">GL_RGBA</code>,
<code class="constant">GL_BGR</code>,
<code class="constant">GL_BGRA</code>,
<code class="constant">GL_LUMINANCE</code>,
or
<code class="constant">GL_LUMINANCE_ALPHA</code>,
and the GL is in color index mode.
</p><p>
<code class="constant">GL_INVALID_OPERATION</code> is generated if <em class="parameter"><code>format</code></em> is one of
<code class="constant">GL_UNSIGNED_BYTE_3_3_2</code>,
<code class="constant">GL_UNSIGNED_BYTE_2_3_3_REV</code>,
<code class="constant">GL_UNSIGNED_SHORT_5_6_5</code>, or
<code class="constant">GL_UNSIGNED_SHORT_5_6_5_REV</code>
and <em class="parameter"><code>format</code></em> is not <code class="constant">GL_RGB</code>.
</p><p>
<code class="constant">GL_INVALID_OPERATION</code> is generated if <em class="parameter"><code>format</code></em> is one of
<code class="constant">GL_UNSIGNED_SHORT_4_4_4_4</code>,
<code class="constant">GL_UNSIGNED_SHORT_4_4_4_4_REV</code>,
<code class="constant">GL_UNSIGNED_SHORT_5_5_5_1</code>,
<code class="constant">GL_UNSIGNED_SHORT_1_5_5_5_REV</code>,
<code class="constant">GL_UNSIGNED_INT_8_8_8_8</code>,
<code class="constant">GL_UNSIGNED_INT_8_8_8_8_REV</code>,
<code class="constant">GL_UNSIGNED_INT_10_10_10_2</code>, or
<code class="constant">GL_UNSIGNED_INT_2_10_10_10_REV</code>
and <em class="parameter"><code>format</code></em> is neither <code class="constant">GL_RGBA</code> nor <code class="constant">GL_BGRA</code>.
</p><p>
<code class="constant">GL_INVALID_OPERATION</code> is generated if a non-zero buffer object name is bound to the
<code class="constant">GL_PIXEL_UNPACK_BUFFER</code> target and the buffer object's data store is currently mapped.
</p><p>
<code class="constant">GL_INVALID_OPERATION</code> is generated if a non-zero buffer object name is bound to the
<code class="constant">GL_PIXEL_UNPACK_BUFFER</code> target and the data would be unpacked from the buffer
object such that the memory reads required would exceed the data store size.
</p><p>
<code class="constant">GL_INVALID_OPERATION</code> is generated if a non-zero buffer object name is bound to the
<code class="constant">GL_PIXEL_UNPACK_BUFFER</code> target and <em class="parameter"><code>data</code></em> is not evenly divisible
into the number of bytes needed to store in memory a datum indicated by <em class="parameter"><code>type</code></em>.
</p><p>
<code class="constant">GL_INVALID_OPERATION</code> is generated if <code class="function">glDrawPixels</code>
is executed between the execution of <a class="citerefentry" href="glBegin"><span class="citerefentry"><span class="refentrytitle">glBegin</span></span></a>
and the corresponding execution of <a class="citerefentry" href="glEnd"><span class="citerefentry"><span class="refentrytitle">glEnd</span></span></a>.
</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="associatedgets"></a><h2>Associated Gets</h2><p>
<a class="citerefentry" href="glGet"><span class="citerefentry"><span class="refentrytitle">glGet</span></span></a> with argument <code class="constant">GL_CURRENT_RASTER_POSITION</code>
</p><p>
<a class="citerefentry" href="glGet"><span class="citerefentry"><span class="refentrytitle">glGet</span></span></a> with argument <code class="constant">GL_CURRENT_RASTER_POSITION_VALID</code>
</p><p>
<a class="citerefentry" href="glGet"><span class="citerefentry"><span class="refentrytitle">glGet</span></span></a> with argument <code class="constant">GL_PIXEL_UNPACK_BUFFER_BINDING</code>
</p></div>
{$pipelinestall}{$examples}
<div class="refsect1" lang="en" xml:lang="en"><a id="seealso"></a><h2>See Also</h2><p>
<a class="citerefentry" href="glAlphaFunc"><span class="citerefentry"><span class="refentrytitle">glAlphaFunc</span></span></a>,
<a class="citerefentry" href="glBlendFunc"><span class="citerefentry"><span class="refentrytitle">glBlendFunc</span></span></a>,
<a class="citerefentry" href="glCopyPixels"><span class="citerefentry"><span class="refentrytitle">glCopyPixels</span></span></a>,
<a class="citerefentry" href="glDepthFunc"><span class="citerefentry"><span class="refentrytitle">glDepthFunc</span></span></a>,
<a class="citerefentry" href="glLogicOp"><span class="citerefentry"><span class="refentrytitle">glLogicOp</span></span></a>,
<a class="citerefentry" href="glPixelMap"><span class="citerefentry"><span class="refentrytitle">glPixelMap</span></span></a>,
<a class="citerefentry" href="glPixelStore"><span class="citerefentry"><span class="refentrytitle">glPixelStore</span></span></a>,
<a class="citerefentry" href="glPixelTransfer"><span class="citerefentry"><span class="refentrytitle">glPixelTransfer</span></span></a>,
<a class="citerefentry" href="glPixelZoom"><span class="citerefentry"><span class="refentrytitle">glPixelZoom</span></span></a>,
<a class="citerefentry" href="glRasterPos"><span class="citerefentry"><span class="refentrytitle">glRasterPos</span></span></a>,
<a class="citerefentry" href="glReadPixels"><span class="citerefentry"><span class="refentrytitle">glReadPixels</span></span></a>,
<a class="citerefentry" href="glScissor"><span class="citerefentry"><span class="refentrytitle">glScissor</span></span></a>,
<a class="citerefentry" href="glStencilFunc"><span class="citerefentry"><span class="refentrytitle">glStencilFunc</span></span></a>,
<a class="citerefentry" href="glWindowPos"><span class="citerefentry"><span class="refentrytitle">glWindowPos</span></span></a>
</p></div><div class="refsect1" lang="en" xml:lang="en"><div id="Copyright"><h2>Copyright</h2><p>
Copyright © 1991-2006
Silicon Graphics, Inc. This document is licensed under the SGI
Free Software B License. For details, see
<a class="ulink" href="https://web.archive.org/web/20171022161616/http://oss.sgi.com/projects/FreeB/" target="_top">https://web.archive.org/web/20171022161616/http://oss.sgi.com/projects/FreeB/</a>.
</p></div></div></div>