dispatch: Make all API functions non-static.
[mesa.git] / src / mesa / main / pixel.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 7.1
4 *
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25
26 /**
27 * \file pixel.c
28 * Pixel transfer functions (glPixelZoom, glPixelMap, glPixelTransfer)
29 */
30
31 #include "glheader.h"
32 #include "bufferobj.h"
33 #include "colormac.h"
34 #include "context.h"
35 #include "macros.h"
36 #include "mfeatures.h"
37 #include "pixel.h"
38 #include "pbo.h"
39 #include "mtypes.h"
40 #include "main/dispatch.h"
41
42
43 /**********************************************************************/
44 /***** glPixelZoom *****/
45 /**********************************************************************/
46
47 void GLAPIENTRY
48 _mesa_PixelZoom( GLfloat xfactor, GLfloat yfactor )
49 {
50 GET_CURRENT_CONTEXT(ctx);
51
52 ASSERT_OUTSIDE_BEGIN_END(ctx);
53
54 if (ctx->Pixel.ZoomX == xfactor &&
55 ctx->Pixel.ZoomY == yfactor)
56 return;
57
58 FLUSH_VERTICES(ctx, _NEW_PIXEL);
59 ctx->Pixel.ZoomX = xfactor;
60 ctx->Pixel.ZoomY = yfactor;
61 }
62
63
64
65 /**********************************************************************/
66 /***** glPixelMap *****/
67 /**********************************************************************/
68
69 /**
70 * Return pointer to a pixelmap by name.
71 */
72 static struct gl_pixelmap *
73 get_pixelmap(struct gl_context *ctx, GLenum map)
74 {
75 switch (map) {
76 case GL_PIXEL_MAP_I_TO_I:
77 return &ctx->PixelMaps.ItoI;
78 case GL_PIXEL_MAP_S_TO_S:
79 return &ctx->PixelMaps.StoS;
80 case GL_PIXEL_MAP_I_TO_R:
81 return &ctx->PixelMaps.ItoR;
82 case GL_PIXEL_MAP_I_TO_G:
83 return &ctx->PixelMaps.ItoG;
84 case GL_PIXEL_MAP_I_TO_B:
85 return &ctx->PixelMaps.ItoB;
86 case GL_PIXEL_MAP_I_TO_A:
87 return &ctx->PixelMaps.ItoA;
88 case GL_PIXEL_MAP_R_TO_R:
89 return &ctx->PixelMaps.RtoR;
90 case GL_PIXEL_MAP_G_TO_G:
91 return &ctx->PixelMaps.GtoG;
92 case GL_PIXEL_MAP_B_TO_B:
93 return &ctx->PixelMaps.BtoB;
94 case GL_PIXEL_MAP_A_TO_A:
95 return &ctx->PixelMaps.AtoA;
96 default:
97 return NULL;
98 }
99 }
100
101
102 /**
103 * Helper routine used by the other _mesa_PixelMap() functions.
104 */
105 static void
106 store_pixelmap(struct gl_context *ctx, GLenum map, GLsizei mapsize,
107 const GLfloat *values)
108 {
109 GLint i;
110 struct gl_pixelmap *pm = get_pixelmap(ctx, map);
111 if (!pm) {
112 _mesa_error(ctx, GL_INVALID_ENUM, "glPixelMap(map)");
113 return;
114 }
115
116 switch (map) {
117 case GL_PIXEL_MAP_S_TO_S:
118 /* special case */
119 ctx->PixelMaps.StoS.Size = mapsize;
120 for (i = 0; i < mapsize; i++) {
121 ctx->PixelMaps.StoS.Map[i] = (GLfloat)IROUND(values[i]);
122 }
123 break;
124 case GL_PIXEL_MAP_I_TO_I:
125 /* special case */
126 ctx->PixelMaps.ItoI.Size = mapsize;
127 for (i = 0; i < mapsize; i++) {
128 ctx->PixelMaps.ItoI.Map[i] = values[i];
129 }
130 break;
131 default:
132 /* general case */
133 pm->Size = mapsize;
134 for (i = 0; i < mapsize; i++) {
135 GLfloat val = CLAMP(values[i], 0.0F, 1.0F);
136 pm->Map[i] = val;
137 }
138 }
139 }
140
141
142 /**
143 * Convenience wrapper for _mesa_validate_pbo_access() for gl[Get]PixelMap().
144 */
145 static GLboolean
146 validate_pbo_access(struct gl_context *ctx,
147 struct gl_pixelstore_attrib *pack, GLsizei mapsize,
148 GLenum format, GLenum type, GLsizei clientMemSize,
149 const GLvoid *ptr)
150 {
151 GLboolean ok;
152
153 /* Note, need to use DefaultPacking and Unpack's buffer object */
154 _mesa_reference_buffer_object(ctx,
155 &ctx->DefaultPacking.BufferObj,
156 pack->BufferObj);
157
158 ok = _mesa_validate_pbo_access(1, &ctx->DefaultPacking, mapsize, 1, 1,
159 format, type, clientMemSize, ptr);
160
161 /* restore */
162 _mesa_reference_buffer_object(ctx,
163 &ctx->DefaultPacking.BufferObj,
164 ctx->Shared->NullBufferObj);
165
166 if (!ok) {
167 if (_mesa_is_bufferobj(pack->BufferObj)) {
168 _mesa_error(ctx, GL_INVALID_OPERATION,
169 "gl[Get]PixelMap*v(out of bounds PBO access)");
170 } else {
171 _mesa_error(ctx, GL_INVALID_OPERATION,
172 "glGetnPixelMap*vARB(out of bounds access:"
173 " bufSize (%d) is too small)", clientMemSize);
174 }
175 }
176 return ok;
177 }
178
179
180 void GLAPIENTRY
181 _mesa_PixelMapfv( GLenum map, GLsizei mapsize, const GLfloat *values )
182 {
183 GET_CURRENT_CONTEXT(ctx);
184 ASSERT_OUTSIDE_BEGIN_END(ctx);
185
186 /* XXX someday, test against ctx->Const.MaxPixelMapTableSize */
187 if (mapsize < 1 || mapsize > MAX_PIXEL_MAP_TABLE) {
188 _mesa_error( ctx, GL_INVALID_VALUE, "glPixelMapfv(mapsize)" );
189 return;
190 }
191
192 if (map >= GL_PIXEL_MAP_S_TO_S && map <= GL_PIXEL_MAP_I_TO_A) {
193 /* test that mapsize is a power of two */
194 if (!_mesa_is_pow_two(mapsize)) {
195 _mesa_error( ctx, GL_INVALID_VALUE, "glPixelMapfv(mapsize)" );
196 return;
197 }
198 }
199
200 FLUSH_VERTICES(ctx, _NEW_PIXEL);
201
202 if (!validate_pbo_access(ctx, &ctx->Unpack, mapsize, GL_INTENSITY,
203 GL_FLOAT, INT_MAX, values)) {
204 return;
205 }
206
207 values = (const GLfloat *) _mesa_map_pbo_source(ctx, &ctx->Unpack, values);
208 if (!values) {
209 if (_mesa_is_bufferobj(ctx->Unpack.BufferObj)) {
210 _mesa_error(ctx, GL_INVALID_OPERATION,
211 "glPixelMapfv(PBO is mapped)");
212 }
213 return;
214 }
215
216 store_pixelmap(ctx, map, mapsize, values);
217
218 _mesa_unmap_pbo_source(ctx, &ctx->Unpack);
219 }
220
221
222 void GLAPIENTRY
223 _mesa_PixelMapuiv(GLenum map, GLsizei mapsize, const GLuint *values )
224 {
225 GLfloat fvalues[MAX_PIXEL_MAP_TABLE];
226 GET_CURRENT_CONTEXT(ctx);
227 ASSERT_OUTSIDE_BEGIN_END(ctx);
228
229 if (mapsize < 1 || mapsize > MAX_PIXEL_MAP_TABLE) {
230 _mesa_error( ctx, GL_INVALID_VALUE, "glPixelMapuiv(mapsize)" );
231 return;
232 }
233
234 if (map >= GL_PIXEL_MAP_S_TO_S && map <= GL_PIXEL_MAP_I_TO_A) {
235 /* test that mapsize is a power of two */
236 if (!_mesa_is_pow_two(mapsize)) {
237 _mesa_error( ctx, GL_INVALID_VALUE, "glPixelMapuiv(mapsize)" );
238 return;
239 }
240 }
241
242 FLUSH_VERTICES(ctx, _NEW_PIXEL);
243
244 if (!validate_pbo_access(ctx, &ctx->Unpack, mapsize, GL_INTENSITY,
245 GL_UNSIGNED_INT, INT_MAX, values)) {
246 return;
247 }
248
249 values = (const GLuint *) _mesa_map_pbo_source(ctx, &ctx->Unpack, values);
250 if (!values) {
251 if (_mesa_is_bufferobj(ctx->Unpack.BufferObj)) {
252 _mesa_error(ctx, GL_INVALID_OPERATION,
253 "glPixelMapuiv(PBO is mapped)");
254 }
255 return;
256 }
257
258 /* convert to floats */
259 if (map == GL_PIXEL_MAP_I_TO_I || map == GL_PIXEL_MAP_S_TO_S) {
260 GLint i;
261 for (i = 0; i < mapsize; i++) {
262 fvalues[i] = (GLfloat) values[i];
263 }
264 }
265 else {
266 GLint i;
267 for (i = 0; i < mapsize; i++) {
268 fvalues[i] = UINT_TO_FLOAT( values[i] );
269 }
270 }
271
272 _mesa_unmap_pbo_source(ctx, &ctx->Unpack);
273
274 store_pixelmap(ctx, map, mapsize, fvalues);
275 }
276
277
278 void GLAPIENTRY
279 _mesa_PixelMapusv(GLenum map, GLsizei mapsize, const GLushort *values )
280 {
281 GLfloat fvalues[MAX_PIXEL_MAP_TABLE];
282 GET_CURRENT_CONTEXT(ctx);
283 ASSERT_OUTSIDE_BEGIN_END(ctx);
284
285 if (mapsize < 1 || mapsize > MAX_PIXEL_MAP_TABLE) {
286 _mesa_error( ctx, GL_INVALID_VALUE, "glPixelMapusv(mapsize)" );
287 return;
288 }
289
290 if (map >= GL_PIXEL_MAP_S_TO_S && map <= GL_PIXEL_MAP_I_TO_A) {
291 /* test that mapsize is a power of two */
292 if (!_mesa_is_pow_two(mapsize)) {
293 _mesa_error( ctx, GL_INVALID_VALUE, "glPixelMapuiv(mapsize)" );
294 return;
295 }
296 }
297
298 FLUSH_VERTICES(ctx, _NEW_PIXEL);
299
300 if (!validate_pbo_access(ctx, &ctx->Unpack, mapsize, GL_INTENSITY,
301 GL_UNSIGNED_SHORT, INT_MAX, values)) {
302 return;
303 }
304
305 values = (const GLushort *) _mesa_map_pbo_source(ctx, &ctx->Unpack, values);
306 if (!values) {
307 if (_mesa_is_bufferobj(ctx->Unpack.BufferObj)) {
308 _mesa_error(ctx, GL_INVALID_OPERATION,
309 "glPixelMapusv(PBO is mapped)");
310 }
311 return;
312 }
313
314 /* convert to floats */
315 if (map == GL_PIXEL_MAP_I_TO_I || map == GL_PIXEL_MAP_S_TO_S) {
316 GLint i;
317 for (i = 0; i < mapsize; i++) {
318 fvalues[i] = (GLfloat) values[i];
319 }
320 }
321 else {
322 GLint i;
323 for (i = 0; i < mapsize; i++) {
324 fvalues[i] = USHORT_TO_FLOAT( values[i] );
325 }
326 }
327
328 _mesa_unmap_pbo_source(ctx, &ctx->Unpack);
329
330 store_pixelmap(ctx, map, mapsize, fvalues);
331 }
332
333
334 void GLAPIENTRY
335 _mesa_GetnPixelMapfvARB( GLenum map, GLsizei bufSize, GLfloat *values )
336 {
337 GET_CURRENT_CONTEXT(ctx);
338 GLint mapsize, i;
339 const struct gl_pixelmap *pm;
340
341 ASSERT_OUTSIDE_BEGIN_END(ctx);
342
343 pm = get_pixelmap(ctx, map);
344 if (!pm) {
345 _mesa_error(ctx, GL_INVALID_ENUM, "glGetPixelMapfv(map)");
346 return;
347 }
348
349 mapsize = pm->Size;
350
351 if (!validate_pbo_access(ctx, &ctx->Pack, mapsize, GL_INTENSITY,
352 GL_FLOAT, bufSize, values)) {
353 return;
354 }
355
356 values = (GLfloat *) _mesa_map_pbo_dest(ctx, &ctx->Pack, values);
357 if (!values) {
358 if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) {
359 _mesa_error(ctx, GL_INVALID_OPERATION,
360 "glGetPixelMapfv(PBO is mapped)");
361 }
362 return;
363 }
364
365 if (map == GL_PIXEL_MAP_S_TO_S) {
366 /* special case */
367 for (i = 0; i < mapsize; i++) {
368 values[i] = (GLfloat) ctx->PixelMaps.StoS.Map[i];
369 }
370 }
371 else {
372 memcpy(values, pm->Map, mapsize * sizeof(GLfloat));
373 }
374
375 _mesa_unmap_pbo_dest(ctx, &ctx->Pack);
376 }
377
378
379 void GLAPIENTRY
380 _mesa_GetPixelMapfv( GLenum map, GLfloat *values )
381 {
382 _mesa_GetnPixelMapfvARB(map, INT_MAX, values);
383 }
384
385 void GLAPIENTRY
386 _mesa_GetnPixelMapuivARB( GLenum map, GLsizei bufSize, GLuint *values )
387 {
388 GET_CURRENT_CONTEXT(ctx);
389 GLint mapsize, i;
390 const struct gl_pixelmap *pm;
391
392 ASSERT_OUTSIDE_BEGIN_END(ctx);
393
394 pm = get_pixelmap(ctx, map);
395 if (!pm) {
396 _mesa_error(ctx, GL_INVALID_ENUM, "glGetPixelMapuiv(map)");
397 return;
398 }
399
400 mapsize = pm->Size;
401
402 if (!validate_pbo_access(ctx, &ctx->Pack, mapsize, GL_INTENSITY,
403 GL_UNSIGNED_INT, bufSize, values)) {
404 return;
405 }
406
407 values = (GLuint *) _mesa_map_pbo_dest(ctx, &ctx->Pack, values);
408 if (!values) {
409 if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) {
410 _mesa_error(ctx, GL_INVALID_OPERATION,
411 "glGetPixelMapuiv(PBO is mapped)");
412 }
413 return;
414 }
415
416 if (map == GL_PIXEL_MAP_S_TO_S) {
417 /* special case */
418 memcpy(values, ctx->PixelMaps.StoS.Map, mapsize * sizeof(GLint));
419 }
420 else {
421 for (i = 0; i < mapsize; i++) {
422 values[i] = FLOAT_TO_UINT( pm->Map[i] );
423 }
424 }
425
426 _mesa_unmap_pbo_dest(ctx, &ctx->Pack);
427 }
428
429
430 void GLAPIENTRY
431 _mesa_GetPixelMapuiv( GLenum map, GLuint *values )
432 {
433 _mesa_GetnPixelMapuivARB(map, INT_MAX, values);
434 }
435
436 void GLAPIENTRY
437 _mesa_GetnPixelMapusvARB( GLenum map, GLsizei bufSize, GLushort *values )
438 {
439 GET_CURRENT_CONTEXT(ctx);
440 GLint mapsize, i;
441 const struct gl_pixelmap *pm;
442
443 ASSERT_OUTSIDE_BEGIN_END(ctx);
444
445 pm = get_pixelmap(ctx, map);
446 if (!pm) {
447 _mesa_error(ctx, GL_INVALID_ENUM, "glGetPixelMapusv(map)");
448 return;
449 }
450
451 mapsize = pm->Size;
452
453 if (!validate_pbo_access(ctx, &ctx->Pack, mapsize, GL_INTENSITY,
454 GL_UNSIGNED_SHORT, bufSize, values)) {
455 return;
456 }
457
458 values = (GLushort *) _mesa_map_pbo_dest(ctx, &ctx->Pack, values);
459 if (!values) {
460 if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) {
461 _mesa_error(ctx, GL_INVALID_OPERATION,
462 "glGetPixelMapusv(PBO is mapped)");
463 }
464 return;
465 }
466
467 switch (map) {
468 /* special cases */
469 case GL_PIXEL_MAP_I_TO_I:
470 for (i = 0; i < mapsize; i++) {
471 values[i] = (GLushort) CLAMP(ctx->PixelMaps.ItoI.Map[i], 0.0, 65535.);
472 }
473 break;
474 case GL_PIXEL_MAP_S_TO_S:
475 for (i = 0; i < mapsize; i++) {
476 values[i] = (GLushort) CLAMP(ctx->PixelMaps.StoS.Map[i], 0.0, 65535.);
477 }
478 break;
479 default:
480 for (i = 0; i < mapsize; i++) {
481 CLAMPED_FLOAT_TO_USHORT(values[i], pm->Map[i] );
482 }
483 }
484
485 _mesa_unmap_pbo_dest(ctx, &ctx->Pack);
486 }
487
488
489 void GLAPIENTRY
490 _mesa_GetPixelMapusv( GLenum map, GLushort *values )
491 {
492 _mesa_GetnPixelMapusvARB(map, INT_MAX, values);
493 }
494
495
496 /**********************************************************************/
497 /***** glPixelTransfer *****/
498 /**********************************************************************/
499
500
501 /*
502 * Implements glPixelTransfer[fi] whether called immediately or from a
503 * display list.
504 */
505 void GLAPIENTRY
506 _mesa_PixelTransferf( GLenum pname, GLfloat param )
507 {
508 GET_CURRENT_CONTEXT(ctx);
509 ASSERT_OUTSIDE_BEGIN_END(ctx);
510
511 switch (pname) {
512 case GL_MAP_COLOR:
513 if (ctx->Pixel.MapColorFlag == (param ? GL_TRUE : GL_FALSE))
514 return;
515 FLUSH_VERTICES(ctx, _NEW_PIXEL);
516 ctx->Pixel.MapColorFlag = param ? GL_TRUE : GL_FALSE;
517 break;
518 case GL_MAP_STENCIL:
519 if (ctx->Pixel.MapStencilFlag == (param ? GL_TRUE : GL_FALSE))
520 return;
521 FLUSH_VERTICES(ctx, _NEW_PIXEL);
522 ctx->Pixel.MapStencilFlag = param ? GL_TRUE : GL_FALSE;
523 break;
524 case GL_INDEX_SHIFT:
525 if (ctx->Pixel.IndexShift == (GLint) param)
526 return;
527 FLUSH_VERTICES(ctx, _NEW_PIXEL);
528 ctx->Pixel.IndexShift = (GLint) param;
529 break;
530 case GL_INDEX_OFFSET:
531 if (ctx->Pixel.IndexOffset == (GLint) param)
532 return;
533 FLUSH_VERTICES(ctx, _NEW_PIXEL);
534 ctx->Pixel.IndexOffset = (GLint) param;
535 break;
536 case GL_RED_SCALE:
537 if (ctx->Pixel.RedScale == param)
538 return;
539 FLUSH_VERTICES(ctx, _NEW_PIXEL);
540 ctx->Pixel.RedScale = param;
541 break;
542 case GL_RED_BIAS:
543 if (ctx->Pixel.RedBias == param)
544 return;
545 FLUSH_VERTICES(ctx, _NEW_PIXEL);
546 ctx->Pixel.RedBias = param;
547 break;
548 case GL_GREEN_SCALE:
549 if (ctx->Pixel.GreenScale == param)
550 return;
551 FLUSH_VERTICES(ctx, _NEW_PIXEL);
552 ctx->Pixel.GreenScale = param;
553 break;
554 case GL_GREEN_BIAS:
555 if (ctx->Pixel.GreenBias == param)
556 return;
557 FLUSH_VERTICES(ctx, _NEW_PIXEL);
558 ctx->Pixel.GreenBias = param;
559 break;
560 case GL_BLUE_SCALE:
561 if (ctx->Pixel.BlueScale == param)
562 return;
563 FLUSH_VERTICES(ctx, _NEW_PIXEL);
564 ctx->Pixel.BlueScale = param;
565 break;
566 case GL_BLUE_BIAS:
567 if (ctx->Pixel.BlueBias == param)
568 return;
569 FLUSH_VERTICES(ctx, _NEW_PIXEL);
570 ctx->Pixel.BlueBias = param;
571 break;
572 case GL_ALPHA_SCALE:
573 if (ctx->Pixel.AlphaScale == param)
574 return;
575 FLUSH_VERTICES(ctx, _NEW_PIXEL);
576 ctx->Pixel.AlphaScale = param;
577 break;
578 case GL_ALPHA_BIAS:
579 if (ctx->Pixel.AlphaBias == param)
580 return;
581 FLUSH_VERTICES(ctx, _NEW_PIXEL);
582 ctx->Pixel.AlphaBias = param;
583 break;
584 case GL_DEPTH_SCALE:
585 if (ctx->Pixel.DepthScale == param)
586 return;
587 FLUSH_VERTICES(ctx, _NEW_PIXEL);
588 ctx->Pixel.DepthScale = param;
589 break;
590 case GL_DEPTH_BIAS:
591 if (ctx->Pixel.DepthBias == param)
592 return;
593 FLUSH_VERTICES(ctx, _NEW_PIXEL);
594 ctx->Pixel.DepthBias = param;
595 break;
596 default:
597 _mesa_error( ctx, GL_INVALID_ENUM, "glPixelTransfer(pname)" );
598 return;
599 }
600 }
601
602
603 void GLAPIENTRY
604 _mesa_PixelTransferi( GLenum pname, GLint param )
605 {
606 _mesa_PixelTransferf( pname, (GLfloat) param );
607 }
608
609
610
611 /**********************************************************************/
612 /***** State Management *****/
613 /**********************************************************************/
614
615 /*
616 * Return a bitmask of IMAGE_*_BIT flags which to indicate which
617 * pixel transfer operations are enabled.
618 */
619 static void
620 update_image_transfer_state(struct gl_context *ctx)
621 {
622 GLuint mask = 0;
623
624 if (ctx->Pixel.RedScale != 1.0F || ctx->Pixel.RedBias != 0.0F ||
625 ctx->Pixel.GreenScale != 1.0F || ctx->Pixel.GreenBias != 0.0F ||
626 ctx->Pixel.BlueScale != 1.0F || ctx->Pixel.BlueBias != 0.0F ||
627 ctx->Pixel.AlphaScale != 1.0F || ctx->Pixel.AlphaBias != 0.0F)
628 mask |= IMAGE_SCALE_BIAS_BIT;
629
630 if (ctx->Pixel.IndexShift || ctx->Pixel.IndexOffset)
631 mask |= IMAGE_SHIFT_OFFSET_BIT;
632
633 if (ctx->Pixel.MapColorFlag)
634 mask |= IMAGE_MAP_COLOR_BIT;
635
636 ctx->_ImageTransferState = mask;
637 }
638
639
640 /**
641 * Update mesa pixel transfer derived state.
642 */
643 void _mesa_update_pixel( struct gl_context *ctx, GLuint new_state )
644 {
645 if (new_state & _NEW_PIXEL)
646 update_image_transfer_state(ctx);
647 }
648
649
650 void
651 _mesa_init_pixel_dispatch(struct _glapi_table *disp)
652 {
653 SET_GetPixelMapfv(disp, _mesa_GetPixelMapfv);
654 SET_GetPixelMapuiv(disp, _mesa_GetPixelMapuiv);
655 SET_GetPixelMapusv(disp, _mesa_GetPixelMapusv);
656 SET_PixelMapfv(disp, _mesa_PixelMapfv);
657 SET_PixelMapuiv(disp, _mesa_PixelMapuiv);
658 SET_PixelMapusv(disp, _mesa_PixelMapusv);
659 SET_PixelTransferf(disp, _mesa_PixelTransferf);
660 SET_PixelTransferi(disp, _mesa_PixelTransferi);
661 SET_PixelZoom(disp, _mesa_PixelZoom);
662
663 /* GL_ARB_robustness */
664 SET_GetnPixelMapfvARB(disp, _mesa_GetnPixelMapfvARB);
665 SET_GetnPixelMapuivARB(disp, _mesa_GetnPixelMapuivARB);
666 SET_GetnPixelMapusvARB(disp, _mesa_GetnPixelMapusvARB);
667 }
668
669
670 /**********************************************************************/
671 /***** Initialization *****/
672 /**********************************************************************/
673
674 static void
675 init_pixelmap(struct gl_pixelmap *map)
676 {
677 map->Size = 1;
678 map->Map[0] = 0.0;
679 }
680
681
682 /**
683 * Initialize the context's PIXEL attribute group.
684 */
685 void
686 _mesa_init_pixel( struct gl_context *ctx )
687 {
688 /* Pixel group */
689 ctx->Pixel.RedBias = 0.0;
690 ctx->Pixel.RedScale = 1.0;
691 ctx->Pixel.GreenBias = 0.0;
692 ctx->Pixel.GreenScale = 1.0;
693 ctx->Pixel.BlueBias = 0.0;
694 ctx->Pixel.BlueScale = 1.0;
695 ctx->Pixel.AlphaBias = 0.0;
696 ctx->Pixel.AlphaScale = 1.0;
697 ctx->Pixel.DepthBias = 0.0;
698 ctx->Pixel.DepthScale = 1.0;
699 ctx->Pixel.IndexOffset = 0;
700 ctx->Pixel.IndexShift = 0;
701 ctx->Pixel.ZoomX = 1.0;
702 ctx->Pixel.ZoomY = 1.0;
703 ctx->Pixel.MapColorFlag = GL_FALSE;
704 ctx->Pixel.MapStencilFlag = GL_FALSE;
705 init_pixelmap(&ctx->PixelMaps.StoS);
706 init_pixelmap(&ctx->PixelMaps.ItoI);
707 init_pixelmap(&ctx->PixelMaps.ItoR);
708 init_pixelmap(&ctx->PixelMaps.ItoG);
709 init_pixelmap(&ctx->PixelMaps.ItoB);
710 init_pixelmap(&ctx->PixelMaps.ItoA);
711 init_pixelmap(&ctx->PixelMaps.RtoR);
712 init_pixelmap(&ctx->PixelMaps.GtoG);
713 init_pixelmap(&ctx->PixelMaps.BtoB);
714 init_pixelmap(&ctx->PixelMaps.AtoA);
715
716 if (ctx->Visual.doubleBufferMode) {
717 ctx->Pixel.ReadBuffer = GL_BACK;
718 }
719 else {
720 ctx->Pixel.ReadBuffer = GL_FRONT;
721 }
722
723 /* Miscellaneous */
724 ctx->_ImageTransferState = 0;
725 }