1 /* $Id: osmesa.c,v 1.93 2002/10/24 23:57:23 brianp Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 * Off-Screen Mesa rendering / Rendering into client memory space
31 * Note on thread safety: this driver is thread safe. All
32 * functions are reentrant. The notion of current context is
33 * managed by the core _mesa_make_current() and _mesa_get_current_context()
34 * functions. Those functions are thread-safe.
39 #include "GL/osmesa.h"
44 #include "extensions.h"
50 #include "texformat.h"
52 #include "array_cache/acache.h"
53 #include "swrast/swrast.h"
54 #include "swrast_setup/swrast_setup.h"
55 #include "swrast/s_context.h"
56 #include "swrast/s_depth.h"
57 #include "swrast/s_lines.h"
58 #include "swrast/s_triangle.h"
60 #include "tnl/t_context.h"
61 #include "tnl/t_pipeline.h"
66 * This is the OS/Mesa context struct.
67 * Notice how it includes a GLcontext. By doing this we're mimicking
68 * C++ inheritance/derivation.
69 * Later, we can cast a GLcontext pointer into an OSMesaContext pointer
72 struct osmesa_context
{
73 GLcontext gl_ctx
; /* The core GL/Mesa context */
74 GLvisual
*gl_visual
; /* Describes the buffers */
75 GLframebuffer
*gl_buffer
; /* Depth, stencil, accum, etc buffers */
76 GLenum format
; /* either GL_RGBA or GL_COLOR_INDEX */
77 void *buffer
; /* the image buffer */
78 GLint width
, height
; /* size of image buffer */
79 GLint rowlength
; /* number of pixels per row */
80 GLint userRowLength
; /* user-specified number of pixels per row */
81 GLint rshift
, gshift
; /* bit shifts for RGBA formats */
83 GLint rInd
, gInd
, bInd
, aInd
;/* index offsets for RGBA formats */
84 GLchan
*rowaddr
[MAX_HEIGHT
]; /* address of first pixel in each image row */
85 GLboolean yup
; /* TRUE -> Y increases upward */
86 /* FALSE -> Y increases downward */
91 /* A forward declaration: */
92 static void osmesa_update_state( GLcontext
*ctx
, GLuint newstate
);
93 static void osmesa_register_swrast_functions( GLcontext
*ctx
);
97 #define OSMESA_CONTEXT(ctx) ((OSMesaContext) (ctx->DriverCtx))
101 /**********************************************************************/
102 /***** Public Functions *****/
103 /**********************************************************************/
107 * Create an Off-Screen Mesa rendering context. The only attribute needed is
108 * an RGBA vs Color-Index mode flag.
110 * Input: format - either GL_RGBA or GL_COLOR_INDEX
111 * sharelist - specifies another OSMesaContext with which to share
112 * display lists. NULL indicates no sharing.
113 * Return: an OSMesaContext or 0 if error
115 GLAPI OSMesaContext GLAPIENTRY
116 OSMesaCreateContext( GLenum format
, OSMesaContext sharelist
)
118 return OSMesaCreateContextExt(format
, DEFAULT_SOFTWARE_DEPTH_BITS
,
127 * Create context and specify size of ancillary buffers.
129 GLAPI OSMesaContext GLAPIENTRY
130 OSMesaCreateContextExt( GLenum format
, GLint depthBits
, GLint stencilBits
,
131 GLint accumBits
, OSMesaContext sharelist
)
133 OSMesaContext osmesa
;
134 GLint rshift
, gshift
, bshift
, ashift
;
135 GLint rind
, gind
, bind
, aind
;
136 GLint indexBits
= 0, redBits
= 0, greenBits
= 0, blueBits
= 0, alphaBits
=0;
139 const GLubyte
*i1
= (GLubyte
*) &i4
;
140 const GLint little_endian
= *i1
;
142 rind
= gind
= bind
= aind
= 0;
143 if (format
==OSMESA_COLOR_INDEX
) {
145 rshift
= gshift
= bshift
= ashift
= 0;
148 else if (format
==OSMESA_RGBA
) {
151 greenBits
= CHAN_BITS
;
152 blueBits
= CHAN_BITS
;
153 alphaBits
= CHAN_BITS
;
172 else if (format
==OSMESA_BGRA
) {
175 greenBits
= CHAN_BITS
;
176 blueBits
= CHAN_BITS
;
177 alphaBits
= CHAN_BITS
;
196 else if (format
==OSMESA_ARGB
) {
199 greenBits
= CHAN_BITS
;
200 blueBits
= CHAN_BITS
;
201 alphaBits
= CHAN_BITS
;
220 else if (format
==OSMESA_RGB
) {
223 greenBits
= CHAN_BITS
;
224 blueBits
= CHAN_BITS
;
235 else if (format
==OSMESA_BGR
) {
238 greenBits
= CHAN_BITS
;
239 blueBits
= CHAN_BITS
;
250 else if (format
==OSMESA_RGB_565
) {
260 rind
= 0; /* not used */
270 osmesa
= (OSMesaContext
) CALLOC_STRUCT(osmesa_context
);
272 osmesa
->gl_visual
= _mesa_create_visual( rgbmode
,
273 GL_FALSE
, /* double buffer */
274 GL_FALSE
, /* stereo */
285 alphaBits
? accumBits
: 0,
288 if (!osmesa
->gl_visual
) {
293 if (!_mesa_initialize_context(&osmesa
->gl_ctx
,
295 sharelist
? &sharelist
->gl_ctx
296 : (GLcontext
*) NULL
,
299 _mesa_destroy_visual( osmesa
->gl_visual
);
304 _mesa_enable_sw_extensions(&(osmesa
->gl_ctx
));
305 _mesa_enable_1_3_extensions(&(osmesa
->gl_ctx
));
306 /*_mesa_enable_1_4_extensions(&(osmesa->gl_ctx));*/
308 osmesa
->gl_buffer
= _mesa_create_framebuffer( osmesa
->gl_visual
,
309 (GLboolean
) ( osmesa
->gl_visual
->depthBits
> 0 ),
310 (GLboolean
) ( osmesa
->gl_visual
->stencilBits
> 0 ),
311 (GLboolean
) ( osmesa
->gl_visual
->accumRedBits
> 0 ),
312 GL_FALSE
/* s/w alpha */ );
314 if (!osmesa
->gl_buffer
) {
315 _mesa_destroy_visual( osmesa
->gl_visual
);
316 _mesa_free_context_data( &osmesa
->gl_ctx
);
320 osmesa
->format
= format
;
321 osmesa
->buffer
= NULL
;
324 osmesa
->userRowLength
= 0;
325 osmesa
->rowlength
= 0;
326 osmesa
->yup
= GL_TRUE
;
327 osmesa
->rshift
= rshift
;
328 osmesa
->gshift
= gshift
;
329 osmesa
->bshift
= bshift
;
330 osmesa
->ashift
= ashift
;
337 /* Initialize the software rasterizer and helper modules.
340 GLcontext
*ctx
= &osmesa
->gl_ctx
;
342 _swrast_CreateContext( ctx
);
343 _ac_CreateContext( ctx
);
344 _tnl_CreateContext( ctx
);
345 _swsetup_CreateContext( ctx
);
347 _swsetup_Wakeup( ctx
);
348 osmesa_register_swrast_functions( ctx
);
358 * Destroy an Off-Screen Mesa rendering context.
360 * Input: ctx - the context to destroy
362 GLAPI
void GLAPIENTRY
OSMesaDestroyContext( OSMesaContext ctx
)
365 _swsetup_DestroyContext( &ctx
->gl_ctx
);
366 _tnl_DestroyContext( &ctx
->gl_ctx
);
367 _ac_DestroyContext( &ctx
->gl_ctx
);
368 _swrast_DestroyContext( &ctx
->gl_ctx
);
370 _mesa_destroy_visual( ctx
->gl_visual
);
371 _mesa_destroy_framebuffer( ctx
->gl_buffer
);
372 _mesa_free_context_data( &ctx
->gl_ctx
);
380 * Recompute the values of the context's rowaddr array.
382 static void compute_row_addresses( OSMesaContext ctx
)
384 GLint bytesPerPixel
, bytesPerRow
, i
;
385 GLubyte
*origin
= (GLubyte
*) ctx
->buffer
;
387 if (ctx
->format
== OSMESA_COLOR_INDEX
) {
389 bytesPerPixel
= 1 * sizeof(GLchan
);
391 else if ((ctx
->format
== OSMESA_RGB
) || (ctx
->format
== OSMESA_BGR
)) {
393 bytesPerPixel
= 3 * sizeof(GLchan
);
395 else if (ctx
->format
== OSMESA_RGB_565
) {
396 /* 5/6/5 RGB pixel in 16 bits */
401 bytesPerPixel
= 4 * sizeof(GLchan
);
404 bytesPerRow
= ctx
->rowlength
* bytesPerPixel
;
407 /* Y=0 is bottom line of window */
408 for (i
= 0; i
< MAX_HEIGHT
; i
++) {
409 ctx
->rowaddr
[i
] = (GLchan
*) ((GLubyte
*) origin
+ i
* bytesPerRow
);
413 /* Y=0 is top line of window */
414 for (i
= 0; i
< MAX_HEIGHT
; i
++) {
415 GLint j
= ctx
->height
- i
- 1;
416 ctx
->rowaddr
[i
] = (GLchan
*) ((GLubyte
*) origin
+ j
* bytesPerRow
);
423 * Bind an OSMesaContext to an image buffer. The image buffer is just a
424 * block of memory which the client provides. Its size must be at least
425 * as large as width*height*sizeof(type). Its address should be a multiple
426 * of 4 if using RGBA mode.
428 * Image data is stored in the order of glDrawPixels: row-major order
429 * with the lower-left image pixel stored in the first array position
430 * (ie. bottom-to-top).
432 * If the context's viewport hasn't been initialized yet, it will now be
433 * initialized to (0,0,width,height).
435 * Input: ctx - the rendering context
436 * buffer - the image buffer memory
437 * type - data type for pixel components
438 * Normally, only GL_UNSIGNED_BYTE and GL_UNSIGNED_SHORT_5_6_5
439 * are supported. But if Mesa's been compiled with CHAN_BITS==16
440 * then type must be GL_UNSIGNED_SHORT. And if Mesa's been build
441 * with CHAN_BITS==32 then type must be GL_FLOAT.
442 * width, height - size of image buffer in pixels, at least 1
443 * Return: GL_TRUE if success, GL_FALSE if error because of invalid ctx,
444 * invalid buffer address, invalid type, width<1, height<1,
445 * width>internal limit or height>internal limit.
447 GLAPI GLboolean GLAPIENTRY
448 OSMesaMakeCurrent( OSMesaContext ctx
, void *buffer
, GLenum type
,
449 GLsizei width
, GLsizei height
)
451 if (!ctx
|| !buffer
||
452 width
< 1 || height
< 1 ||
453 width
> MAX_WIDTH
|| height
> MAX_HEIGHT
) {
457 if (ctx
->format
== OSMESA_RGB_565
) {
458 if (type
!= GL_UNSIGNED_SHORT_5_6_5
)
461 else if (type
!= CHAN_TYPE
) {
465 osmesa_update_state( &ctx
->gl_ctx
, 0 );
466 _mesa_make_current( &ctx
->gl_ctx
, ctx
->gl_buffer
);
468 ctx
->buffer
= buffer
;
470 ctx
->height
= height
;
471 if (ctx
->userRowLength
)
472 ctx
->rowlength
= ctx
->userRowLength
;
474 ctx
->rowlength
= width
;
476 compute_row_addresses( ctx
);
479 if (ctx
->gl_ctx
.Viewport
.Width
== 0) {
480 /* initialize viewport and scissor box to buffer size */
481 _mesa_Viewport( 0, 0, width
, height
);
482 ctx
->gl_ctx
.Scissor
.Width
= width
;
483 ctx
->gl_ctx
.Scissor
.Height
= height
;
486 /* this will make ensure we recognize the new buffer size */
487 _mesa_ResizeBuffersMESA();
490 /* Added by Gerk Huisma: */
491 _tnl_MakeCurrent( &ctx
->gl_ctx
, ctx
->gl_ctx
.DrawBuffer
,
492 ctx
->gl_ctx
.ReadBuffer
);
499 GLAPI OSMesaContext GLAPIENTRY
OSMesaGetCurrentContext( void )
501 GLcontext
*ctx
= _mesa_get_current_context();
503 return (OSMesaContext
) ctx
;
510 GLAPI
void GLAPIENTRY
OSMesaPixelStore( GLint pname
, GLint value
)
512 OSMesaContext ctx
= OSMesaGetCurrentContext();
515 case OSMESA_ROW_LENGTH
:
517 _mesa_error( &ctx
->gl_ctx
, GL_INVALID_VALUE
,
518 "OSMesaPixelStore(value)" );
521 ctx
->userRowLength
= value
;
522 ctx
->rowlength
= value
;
525 ctx
->yup
= value
? GL_TRUE
: GL_FALSE
;
528 _mesa_error( &ctx
->gl_ctx
, GL_INVALID_ENUM
, "OSMesaPixelStore(pname)" );
532 compute_row_addresses( ctx
);
536 GLAPI
void GLAPIENTRY
OSMesaGetIntegerv( GLint pname
, GLint
*value
)
538 OSMesaContext ctx
= OSMesaGetCurrentContext();
545 *value
= ctx
->height
;
548 *value
= ctx
->format
;
553 case OSMESA_ROW_LENGTH
:
554 *value
= ctx
->rowlength
;
559 case OSMESA_MAX_WIDTH
:
562 case OSMESA_MAX_HEIGHT
:
566 _mesa_error(&ctx
->gl_ctx
, GL_INVALID_ENUM
, "OSMesaGetIntergerv(pname)");
572 * Return the depth buffer associated with an OSMesa context.
573 * Input: c - the OSMesa context
574 * Output: width, height - size of buffer in pixels
575 * bytesPerValue - bytes per depth value (2 or 4)
576 * buffer - pointer to depth buffer values
577 * Return: GL_TRUE or GL_FALSE to indicate success or failure.
579 GLAPI GLboolean GLAPIENTRY
580 OSMesaGetDepthBuffer( OSMesaContext c
, GLint
*width
, GLint
*height
,
581 GLint
*bytesPerValue
, void **buffer
)
583 if ((!c
->gl_buffer
) || (!c
->gl_buffer
->DepthBuffer
)) {
591 *width
= c
->gl_buffer
->Width
;
592 *height
= c
->gl_buffer
->Height
;
593 if (c
->gl_visual
->depthBits
<= 16)
594 *bytesPerValue
= sizeof(GLushort
);
596 *bytesPerValue
= sizeof(GLuint
);
597 *buffer
= c
->gl_buffer
->DepthBuffer
;
603 * Return the color buffer associated with an OSMesa context.
604 * Input: c - the OSMesa context
605 * Output: width, height - size of buffer in pixels
606 * format - the pixel format (OSMESA_FORMAT)
607 * buffer - pointer to color buffer values
608 * Return: GL_TRUE or GL_FALSE to indicate success or failure.
610 GLAPI GLboolean GLAPIENTRY
611 OSMesaGetColorBuffer( OSMesaContext c
, GLint
*width
,
612 GLint
*height
, GLint
*format
, void **buffer
)
632 struct name_address
{
637 static struct name_address functions
[] = {
638 { "OSMesaCreateContext", (void *) OSMesaCreateContext
},
639 { "OSMesaCreateContextExt", (void *) OSMesaCreateContextExt
},
640 { "OSMesaDestroyContext", (void *) OSMesaDestroyContext
},
641 { "OSMesaMakeCurrent", (void *) OSMesaMakeCurrent
},
642 { "OSMesaGetCurrentContext", (void *) OSMesaGetCurrentContext
},
643 { "OSMesaPixelsStore", (void *) OSMesaPixelStore
},
644 { "OSMesaGetIntegerv", (void *) OSMesaGetIntegerv
},
645 { "OSMesaGetDepthBuffer", (void *) OSMesaGetDepthBuffer
},
646 { "OSMesaGetColorBuffer", (void *) OSMesaGetColorBuffer
},
647 { "OSMesaGetProcAddress", (void *) OSMesaGetProcAddress
},
651 GLAPI
void * GLAPIENTRY
652 OSMesaGetProcAddress( const char *funcName
)
655 for (i
= 0; functions
[i
].Name
; i
++) {
656 if (strcmp(functions
[i
].Name
, funcName
) == 0)
657 return (void *) functions
[i
].Address
;
659 return (void *) _glapi_get_proc_address(funcName
);
663 /**********************************************************************/
664 /*** Device Driver Functions ***/
665 /**********************************************************************/
672 #if CHAN_TYPE == GL_FLOAT
673 #define PACK_RGBA(DST, R, G, B, A) \
675 (DST)[0] = MAX2( R, 0.0F ); \
676 (DST)[1] = MAX2( G, 0.0F ); \
677 (DST)[2] = MAX2( B, 0.0F ); \
678 (DST)[3] = CLAMP(A, 0.0F, CHAN_MAXF);\
681 #define PACK_RGBA(DST, R, G, B, A) \
683 (DST)[osmesa->rInd] = R; \
684 (DST)[osmesa->gInd] = G; \
685 (DST)[osmesa->bInd] = B; \
686 (DST)[osmesa->aInd] = A; \
690 #define PACK_RGB(DST, R, G, B) \
697 #define PACK_BGR(DST, R, G, B) \
704 #define PACK_RGB_565(DST, R, G, B) \
706 (DST) = (((int) (R) << 8) & 0xf800) | (((int) (G) << 3) & 0x7e0) | ((int) (B) >> 3);\
710 #define UNPACK_RED(P) ( (P)[osmesa->rInd] )
711 #define UNPACK_GREEN(P) ( (P)[osmesa->gInd] )
712 #define UNPACK_BLUE(P) ( (P)[osmesa->bInd] )
713 #define UNPACK_ALPHA(P) ( (P)[osmesa->aInd] )
716 #define PIXELADDR1(X,Y) (osmesa->rowaddr[Y] + (X))
717 #define PIXELADDR2(X,Y) (osmesa->rowaddr[Y] + 2 * (X))
718 #define PIXELADDR3(X,Y) (osmesa->rowaddr[Y] + 3 * (X))
719 #define PIXELADDR4(X,Y) (osmesa->rowaddr[Y] + 4 * (X))
723 static void set_buffer( GLcontext
*ctx
, GLframebuffer
*buffer
, GLuint bufferBit
)
725 /* separate read buffer not supported */
726 ASSERT(buffer
== ctx
->DrawBuffer
);
727 ASSERT(bufferBit
== FRONT_LEFT_BIT
);
731 static void clear( GLcontext
*ctx
, GLbitfield mask
, GLboolean all
,
732 GLint x
, GLint y
, GLint width
, GLint height
)
734 OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
735 const GLuint
*colorMask
= (GLuint
*) &ctx
->Color
.ColorMask
;
737 /* sanity check - we only have a front-left buffer */
738 ASSERT((mask
& (DD_FRONT_RIGHT_BIT
| DD_BACK_LEFT_BIT
| DD_BACK_RIGHT_BIT
)) == 0);
739 if (*colorMask
== 0xffffffff && ctx
->Color
.IndexMask
== 0xffffffff) {
740 if (mask
& DD_FRONT_LEFT_BIT
) {
741 if (osmesa
->format
== OSMESA_COLOR_INDEX
) {
743 /* Clear whole CI buffer */
744 #if CHAN_TYPE == GL_UNSIGNED_BYTE
745 MEMSET(osmesa
->buffer
, ctx
->Color
.ClearIndex
,
746 osmesa
->rowlength
* osmesa
->height
);
748 const GLint n
= osmesa
->rowlength
* osmesa
->height
;
749 GLchan
*buffer
= (GLchan
*) osmesa
->buffer
;
751 for (i
= 0; i
< n
; i
++) {
752 buffer
[i
] = ctx
->Color
.ClearIndex
;
757 /* Clear part of CI buffer */
758 const GLchan clearIndex
= (GLchan
) ctx
->Color
.ClearIndex
;
760 for (i
= 0; i
< height
; i
++) {
761 GLchan
*ptr1
= PIXELADDR1(x
, (y
+ i
));
762 for (j
= 0; j
< width
; j
++) {
763 *ptr1
++ = clearIndex
;
768 else if (osmesa
->format
== OSMESA_RGB
) {
770 CLAMPED_FLOAT_TO_CHAN(r
, ctx
->Color
.ClearColor
[0]);
771 CLAMPED_FLOAT_TO_CHAN(g
, ctx
->Color
.ClearColor
[1]);
772 CLAMPED_FLOAT_TO_CHAN(b
, ctx
->Color
.ClearColor
[2]);
774 /* Clear whole RGB buffer */
775 GLuint n
= osmesa
->rowlength
* osmesa
->height
;
776 GLchan
*ptr3
= (GLchan
*) osmesa
->buffer
;
778 for (i
= 0; i
< n
; i
++) {
779 PACK_RGB(ptr3
, r
, g
, b
);
784 /* Clear part of RGB buffer */
786 for (i
= 0; i
< height
; i
++) {
787 GLchan
*ptr3
= PIXELADDR3(x
, (y
+ i
));
788 for (j
= 0; j
< width
; j
++) {
789 PACK_RGB(ptr3
, r
, g
, b
);
795 else if (osmesa
->format
== OSMESA_BGR
) {
797 CLAMPED_FLOAT_TO_CHAN(r
, ctx
->Color
.ClearColor
[0]);
798 CLAMPED_FLOAT_TO_CHAN(g
, ctx
->Color
.ClearColor
[1]);
799 CLAMPED_FLOAT_TO_CHAN(b
, ctx
->Color
.ClearColor
[2]);
801 /* Clear whole RGB buffer */
802 const GLint n
= osmesa
->rowlength
* osmesa
->height
;
803 GLchan
*ptr3
= (GLchan
*) osmesa
->buffer
;
805 for (i
= 0; i
< n
; i
++) {
806 PACK_BGR(ptr3
, r
, g
, b
);
811 /* Clear part of RGB buffer */
813 for (i
= 0; i
< height
; i
++) {
814 GLchan
*ptr3
= PIXELADDR3(x
, (y
+ i
));
815 for (j
= 0; j
< width
; j
++) {
816 PACK_BGR(ptr3
, r
, g
, b
);
822 else if (osmesa
->format
== OSMESA_RGB_565
) {
825 CLAMPED_FLOAT_TO_CHAN(r
, ctx
->Color
.ClearColor
[0]);
826 CLAMPED_FLOAT_TO_CHAN(g
, ctx
->Color
.ClearColor
[1]);
827 CLAMPED_FLOAT_TO_CHAN(b
, ctx
->Color
.ClearColor
[2]);
828 PACK_RGB_565(clearPixel
, r
, g
, b
);
830 /* Clear whole RGB buffer */
831 const GLuint n
= osmesa
->rowlength
* osmesa
->height
;
832 GLushort
*ptr2
= (GLushort
*) osmesa
->buffer
;
834 for (i
= 0; i
< n
; i
++) {
840 /* clear scissored region */
842 for (i
= 0; i
< height
; i
++) {
843 GLushort
*ptr2
= (GLushort
*) PIXELADDR2(x
, (y
+ i
));
844 for (j
= 0; j
< width
; j
++) {
852 #if CHAN_TYPE == GL_UNSIGNED_BYTE
853 /* 4-byte pixel value */
855 GLchan
*clr
= (GLchan
*) &clearPixel
;
856 CLAMPED_FLOAT_TO_CHAN(clr
[osmesa
->rInd
], ctx
->Color
.ClearColor
[0]);
857 CLAMPED_FLOAT_TO_CHAN(clr
[osmesa
->gInd
], ctx
->Color
.ClearColor
[1]);
858 CLAMPED_FLOAT_TO_CHAN(clr
[osmesa
->bInd
], ctx
->Color
.ClearColor
[2]);
859 CLAMPED_FLOAT_TO_CHAN(clr
[osmesa
->aInd
], ctx
->Color
.ClearColor
[3]);
861 /* Clear whole RGBA buffer */
862 const GLuint n
= osmesa
->rowlength
* osmesa
->height
;
863 GLuint
*ptr4
= (GLuint
*) osmesa
->buffer
;
866 for (i
= 0; i
< n
; i
++) {
867 *ptr4
++ = clearPixel
;
871 BZERO(ptr4
, n
* sizeof(GLuint
));
875 /* Clear part of RGBA buffer */
877 for (i
= 0; i
< height
; i
++) {
878 GLuint
*ptr4
= (GLuint
*) PIXELADDR4(x
, (y
+ i
));
879 for (j
= 0; j
< width
; j
++) {
880 *ptr4
++ = clearPixel
;
886 CLAMPED_FLOAT_TO_CHAN(r
, ctx
->Color
.ClearColor
[0]);
887 CLAMPED_FLOAT_TO_CHAN(g
, ctx
->Color
.ClearColor
[1]);
888 CLAMPED_FLOAT_TO_CHAN(b
, ctx
->Color
.ClearColor
[2]);
889 CLAMPED_FLOAT_TO_CHAN(a
, ctx
->Color
.ClearColor
[3]);
891 /* Clear whole RGBA buffer */
892 const GLuint n
= osmesa
->rowlength
* osmesa
->height
;
893 GLchan
*p
= (GLchan
*) osmesa
->buffer
;
895 for (i
= 0; i
< n
; i
++) {
896 PACK_RGBA(p
, r
, g
, b
, a
);
901 /* Clear part of RGBA buffer */
903 for (i
= 0; i
< height
; i
++) {
904 GLchan
*p
= PIXELADDR4(x
, (y
+ i
));
905 for (j
= 0; j
< width
; j
++) {
906 PACK_RGBA(p
, r
, g
, b
, a
);
914 mask
&= ~DD_FRONT_LEFT_BIT
;
919 _swrast_Clear( ctx
, mask
, all
, x
, y
, width
, height
);
924 static void buffer_size( GLframebuffer
*buffer
, GLuint
*width
, GLuint
*height
)
926 /* don't use GET_CURRENT_CONTEXT(ctx) here - it's a problem on Windows */
927 GLcontext
*ctx
= (GLcontext
*) _glapi_get_context();
930 OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
931 *width
= osmesa
->width
;
932 *height
= osmesa
->height
;
937 /**********************************************************************/
938 /***** Read/write spans/arrays of RGBA pixels *****/
939 /**********************************************************************/
941 /* Write RGBA pixels to an RGBA (or permuted) buffer. */
943 write_rgba_span( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
944 CONST GLchan rgba
[][4], const GLubyte mask
[] )
946 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
947 GLchan
*p
= PIXELADDR4(x
, y
);
950 for (i
= 0; i
< n
; i
++, p
+= 4) {
952 PACK_RGBA(p
, rgba
[i
][RCOMP
], rgba
[i
][GCOMP
],
953 rgba
[i
][BCOMP
], rgba
[i
][ACOMP
]);
958 for (i
= 0; i
< n
; i
++, p
+= 4) {
959 PACK_RGBA(p
, rgba
[i
][RCOMP
], rgba
[i
][GCOMP
],
960 rgba
[i
][BCOMP
], rgba
[i
][ACOMP
]);
966 /* Write RGBA pixels to an RGBA buffer. This is the fastest span-writer. */
968 write_rgba_span_rgba( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
969 CONST GLchan rgba
[][4], const GLubyte mask
[] )
971 OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
972 GLuint
*ptr4
= (GLuint
*) PIXELADDR4(x
, y
);
973 const GLuint
*rgba4
= (const GLuint
*) rgba
;
975 ASSERT(CHAN_TYPE
== GL_UNSIGNED_BYTE
);
977 for (i
= 0; i
< n
; i
++) {
984 MEMCPY( ptr4
, rgba4
, n
* 4 );
989 /* Write RGB pixels to an RGBA (or permuted) buffer. */
991 write_rgb_span( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
992 CONST GLchan rgb
[][3], const GLubyte mask
[] )
994 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
995 GLchan
*p
= PIXELADDR4(x
, y
);
998 for (i
= 0; i
< n
; i
++, p
+=4) {
1000 PACK_RGBA(p
, rgb
[i
][RCOMP
], rgb
[i
][GCOMP
], rgb
[i
][BCOMP
], CHAN_MAX
);
1005 for (i
= 0; i
< n
; i
++, p
+=4) {
1006 PACK_RGBA(p
, rgb
[i
][RCOMP
], rgb
[i
][GCOMP
], rgb
[i
][BCOMP
], CHAN_MAX
);
1014 write_monocolor_span( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
1015 const GLchan color
[4], const GLubyte mask
[] )
1017 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1018 GLchan
*p
= PIXELADDR4(x
, y
);
1020 for (i
= 0; i
< n
; i
++, p
+= 4) {
1022 PACK_RGBA(p
, color
[RCOMP
], color
[GCOMP
], color
[BCOMP
], color
[ACOMP
]);
1030 write_rgba_pixels( const GLcontext
*ctx
, GLuint n
,
1031 const GLint x
[], const GLint y
[],
1032 CONST GLchan rgba
[][4], const GLubyte mask
[] )
1034 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1036 for (i
= 0; i
< n
; i
++) {
1038 GLchan
*p
= PIXELADDR4(x
[i
], y
[i
]);
1039 PACK_RGBA(p
, rgba
[i
][RCOMP
], rgba
[i
][GCOMP
],
1040 rgba
[i
][BCOMP
], rgba
[i
][ACOMP
]);
1048 write_monocolor_pixels( const GLcontext
*ctx
, GLuint n
,
1049 const GLint x
[], const GLint y
[],
1050 const GLchan color
[4], const GLubyte mask
[] )
1052 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1054 for (i
= 0; i
< n
; i
++) {
1056 GLchan
*p
= PIXELADDR4(x
[i
], y
[i
]);
1057 PACK_RGBA(p
, color
[RCOMP
], color
[GCOMP
], color
[BCOMP
], color
[ACOMP
]);
1064 read_rgba_span( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
1067 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1069 GLchan
*p
= PIXELADDR4(x
, y
);
1070 for (i
= 0; i
< n
; i
++, p
+= 4) {
1071 rgba
[i
][RCOMP
] = UNPACK_RED(p
);
1072 rgba
[i
][GCOMP
] = UNPACK_GREEN(p
);
1073 rgba
[i
][BCOMP
] = UNPACK_BLUE(p
);
1074 rgba
[i
][ACOMP
] = UNPACK_ALPHA(p
);
1079 /* Read RGBA pixels from an RGBA buffer */
1081 read_rgba_span_rgba( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
1084 OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1085 GLuint
*ptr4
= (GLuint
*) PIXELADDR4(x
, y
);
1086 MEMCPY( rgba
, ptr4
, n
* 4 * sizeof(GLchan
) );
1091 read_rgba_pixels( const GLcontext
*ctx
,
1092 GLuint n
, const GLint x
[], const GLint y
[],
1093 GLchan rgba
[][4], const GLubyte mask
[] )
1095 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1097 for (i
= 0; i
< n
; i
++) {
1099 const GLchan
*p
= PIXELADDR4(x
[i
], y
[i
]);
1100 rgba
[i
][RCOMP
] = UNPACK_RED(p
);
1101 rgba
[i
][GCOMP
] = UNPACK_GREEN(p
);
1102 rgba
[i
][BCOMP
] = UNPACK_BLUE(p
);
1103 rgba
[i
][ACOMP
] = UNPACK_ALPHA(p
);
1108 /**********************************************************************/
1109 /***** 3 byte RGB pixel support funcs *****/
1110 /**********************************************************************/
1112 /* Write RGBA pixels to an RGB buffer. */
1114 write_rgba_span_RGB( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
1115 CONST GLchan rgba
[][4], const GLubyte mask
[] )
1117 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1118 GLchan
*p
= PIXELADDR3(x
, y
);
1121 for (i
= 0; i
< n
; i
++, p
+= 3) {
1123 PACK_RGB(p
, rgba
[i
][RCOMP
], rgba
[i
][GCOMP
], rgba
[i
][BCOMP
]);
1128 for (i
= 0; i
< n
; i
++, p
+= 3) {
1129 PACK_RGB(p
, rgba
[i
][RCOMP
], rgba
[i
][GCOMP
], rgba
[i
][BCOMP
]);
1134 /* Write RGBA pixels to an BGR buffer. */
1136 write_rgba_span_BGR( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
1137 CONST GLchan rgba
[][4], const GLubyte mask
[] )
1139 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1140 GLchan
*p
= PIXELADDR3(x
, y
);
1143 for (i
= 0; i
< n
; i
++, p
+= 3) {
1145 PACK_BGR(p
, rgba
[i
][RCOMP
], rgba
[i
][GCOMP
], rgba
[i
][BCOMP
]);
1150 for (i
= 0; i
< n
; i
++, p
+= 3) {
1151 PACK_BGR(p
, rgba
[i
][RCOMP
], rgba
[i
][GCOMP
], rgba
[i
][BCOMP
]);
1156 /* Write RGB pixels to an RGB buffer. */
1158 write_rgb_span_RGB( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
1159 CONST GLchan rgb
[][3], const GLubyte mask
[] )
1161 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1162 GLchan
*p
= PIXELADDR3(x
, y
);
1165 for (i
= 0; i
< n
; i
++, p
+= 3) {
1167 PACK_RGB(p
, rgb
[i
][RCOMP
], rgb
[i
][GCOMP
], rgb
[i
][BCOMP
]);
1172 for (i
= 0; i
< n
; i
++, p
+= 3) {
1173 PACK_RGB(p
, rgb
[i
][RCOMP
], rgb
[i
][GCOMP
], rgb
[i
][BCOMP
]);
1178 /* Write RGB pixels to an BGR buffer. */
1180 write_rgb_span_BGR( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
1181 CONST GLchan rgb
[][3], const GLubyte mask
[] )
1183 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1184 GLchan
*p
= PIXELADDR3(x
, y
);
1187 for (i
= 0; i
< n
; i
++, p
+= 3) {
1189 PACK_BGR(p
, rgb
[i
][RCOMP
], rgb
[i
][GCOMP
], rgb
[i
][BCOMP
]);
1194 for (i
= 0; i
< n
; i
++, p
+= 3) {
1195 PACK_BGR(p
, rgb
[i
][RCOMP
], rgb
[i
][GCOMP
], rgb
[i
][BCOMP
]);
1202 write_monocolor_span_RGB( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
1203 const GLchan color
[4], const GLubyte mask
[] )
1205 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1206 GLchan
*p
= PIXELADDR3(x
, y
);
1208 for (i
= 0; i
< n
; i
++, p
+= 3) {
1210 PACK_RGB(p
, color
[RCOMP
], color
[GCOMP
], color
[BCOMP
]);
1216 write_monocolor_span_BGR( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
1217 const GLchan color
[4], const GLubyte mask
[] )
1219 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1220 GLchan
*p
= PIXELADDR3(x
, y
);
1222 for (i
= 0; i
< n
; i
++, p
+= 3) {
1224 PACK_BGR(p
, color
[RCOMP
], color
[GCOMP
], color
[BCOMP
]);
1230 write_rgba_pixels_RGB( const GLcontext
*ctx
, GLuint n
,
1231 const GLint x
[], const GLint y
[],
1232 CONST GLchan rgba
[][4], const GLubyte mask
[] )
1234 const OSMesaContext osmesa
= (const OSMesaContext
) ctx
;
1236 for (i
= 0; i
< n
; i
++) {
1238 GLchan
*p
= PIXELADDR3(x
[i
], y
[i
]);
1239 PACK_RGB(p
, rgba
[i
][RCOMP
], rgba
[i
][GCOMP
], rgba
[i
][BCOMP
]);
1245 write_rgba_pixels_BGR( const GLcontext
*ctx
, GLuint n
,
1246 const GLint x
[], const GLint y
[],
1247 CONST GLchan rgba
[][4], const GLubyte mask
[] )
1249 const OSMesaContext osmesa
= (const OSMesaContext
) ctx
;
1251 for (i
= 0; i
< n
; i
++) {
1253 GLchan
*p
= PIXELADDR3(x
[i
], y
[i
]);
1254 PACK_BGR(p
, rgba
[i
][RCOMP
], rgba
[i
][GCOMP
], rgba
[i
][BCOMP
]);
1260 write_monocolor_pixels_RGB( const GLcontext
*ctx
,
1261 GLuint n
, const GLint x
[], const GLint y
[],
1262 const GLchan color
[4], const GLubyte mask
[] )
1264 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1266 for (i
= 0; i
< n
; i
++) {
1268 GLchan
*p
= PIXELADDR3(x
[i
], y
[i
]);
1269 PACK_RGB(p
, color
[RCOMP
], color
[GCOMP
], color
[BCOMP
]);
1275 write_monocolor_pixels_BGR( const GLcontext
*ctx
,
1276 GLuint n
, const GLint x
[], const GLint y
[],
1277 const GLchan color
[4], const GLubyte mask
[] )
1279 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1281 for (i
= 0; i
< n
; i
++) {
1283 GLchan
*p
= PIXELADDR3(x
[i
], y
[i
]);
1284 PACK_BGR(p
, color
[RCOMP
], color
[GCOMP
], color
[BCOMP
]);
1290 read_rgba_span3( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
1293 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1295 const GLchan
*p
= PIXELADDR3(x
, y
);
1296 for (i
= 0; i
< n
; i
++, p
+= 3) {
1297 rgba
[i
][RCOMP
] = UNPACK_RED(p
);
1298 rgba
[i
][GCOMP
] = UNPACK_GREEN(p
);
1299 rgba
[i
][BCOMP
] = UNPACK_BLUE(p
);
1300 rgba
[i
][ACOMP
] = CHAN_MAX
;
1305 read_rgba_pixels3( const GLcontext
*ctx
,
1306 GLuint n
, const GLint x
[], const GLint y
[],
1307 GLchan rgba
[][4], const GLubyte mask
[] )
1309 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1311 for (i
= 0; i
< n
; i
++) {
1313 const GLchan
*p
= PIXELADDR3(x
[i
], y
[i
]);
1314 rgba
[i
][RCOMP
] = UNPACK_RED(p
);
1315 rgba
[i
][GCOMP
] = UNPACK_GREEN(p
);
1316 rgba
[i
][BCOMP
] = UNPACK_BLUE(p
);
1317 rgba
[i
][ACOMP
] = CHAN_MAX
;
1323 /**********************************************************************/
1324 /***** 2 byte RGB pixel support funcs *****/
1325 /**********************************************************************/
1327 /* Write RGBA pixels to an RGB_565 buffer. */
1329 write_rgba_span2( const GLcontext
*ctx
,
1330 GLuint n
, GLint x
, GLint y
,
1331 CONST GLchan rgba
[][4], const GLubyte mask
[] )
1333 OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1334 GLushort
*ptr2
= (GLushort
*) PIXELADDR2(x
, y
);
1337 for (i
= 0; i
< n
; i
++, ptr2
++) {
1339 PACK_RGB_565(*ptr2
, rgba
[i
][RCOMP
], rgba
[i
][GCOMP
], rgba
[i
][BCOMP
]);
1344 for (i
= 0; i
< n
; i
++, ptr2
++) {
1345 PACK_RGB_565(*ptr2
, rgba
[i
][RCOMP
], rgba
[i
][GCOMP
], rgba
[i
][BCOMP
]);
1351 /* Write RGB pixels to an RGB_565 buffer. */
1353 write_rgb_span2( const GLcontext
*ctx
,
1354 GLuint n
, GLint x
, GLint y
,
1355 CONST GLchan rgb
[][3], const GLubyte mask
[] )
1357 OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1358 GLushort
*ptr2
= (GLushort
*) PIXELADDR2(x
, y
);
1361 for (i
= 0; i
< n
; i
++, ptr2
++) {
1363 PACK_RGB_565(*ptr2
, rgb
[i
][RCOMP
], rgb
[i
][GCOMP
], rgb
[i
][BCOMP
]);
1368 for (i
= 0; i
< n
; i
++, ptr2
++) {
1369 PACK_RGB_565(*ptr2
, rgb
[i
][RCOMP
], rgb
[i
][GCOMP
], rgb
[i
][BCOMP
]);
1376 write_monocolor_span2( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
1377 const GLchan color
[4], const GLubyte mask
[] )
1379 OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1381 GLushort
*ptr2
= (GLushort
*) PIXELADDR2(x
, y
);
1383 PACK_RGB_565(pixel
, color
[RCOMP
], color
[GCOMP
], color
[BCOMP
]);
1384 for (i
= 0; i
< n
; i
++, ptr2
++) {
1393 write_rgba_pixels2( const GLcontext
*ctx
,
1394 GLuint n
, const GLint x
[], const GLint y
[],
1395 CONST GLchan rgba
[][4], const GLubyte mask
[] )
1397 OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1399 for (i
= 0; i
< n
; i
++) {
1401 GLushort
*ptr2
= (GLushort
*) PIXELADDR2(x
[i
],y
[i
]);
1402 PACK_RGB_565(*ptr2
, rgba
[i
][RCOMP
], rgba
[i
][GCOMP
], rgba
[i
][BCOMP
]);
1408 write_monocolor_pixels2( const GLcontext
*ctx
,
1409 GLuint n
, const GLint x
[], const GLint y
[],
1410 const GLchan color
[4], const GLubyte mask
[] )
1412 OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1415 PACK_RGB_565(pixel
, color
[RCOMP
], color
[GCOMP
], color
[BCOMP
]);
1416 for (i
= 0; i
< n
; i
++) {
1418 GLushort
*ptr2
= (GLushort
*) PIXELADDR2(x
[i
],y
[i
]);
1425 read_rgba_span2( const GLcontext
*ctx
,
1426 GLuint n
, GLint x
, GLint y
,
1429 OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1431 const GLushort
*ptr2
= (const GLushort
*) PIXELADDR2(x
, y
);
1432 for (i
= 0; i
< n
; i
++, ptr2
++) {
1433 /* This should be fixed to get the low bits right */
1434 rgba
[i
][RCOMP
] = (*ptr2
>> 8) & 0xFe;
1435 rgba
[i
][GCOMP
] = (*ptr2
>> 3) & 0xFc;
1436 rgba
[i
][BCOMP
] = (*ptr2
<< 3) & 0xFe;
1442 read_rgba_pixels2( const GLcontext
*ctx
,
1443 GLuint n
, const GLint x
[], const GLint y
[],
1444 GLchan rgba
[][4], const GLubyte mask
[] )
1446 OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1448 for (i
= 0; i
< n
; i
++) {
1450 /* This should be fixed to get the low bits right */
1451 const GLushort
*ptr2
= (const GLushort
*) PIXELADDR2(x
[i
],y
[i
]);
1452 rgba
[i
][RCOMP
] = (*ptr2
>> 8) & 0xFE;
1453 rgba
[i
][GCOMP
] = (*ptr2
>> 3) & 0xFC;
1454 rgba
[i
][BCOMP
] = (*ptr2
<< 3) & 0xFE;
1462 /**********************************************************************/
1463 /***** Read/write spans/arrays of CI pixels *****/
1464 /**********************************************************************/
1466 /* Write 32-bit color index to buffer */
1468 write_index32_span( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
1469 const GLuint index
[], const GLubyte mask
[] )
1471 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1472 GLchan
*ptr1
= PIXELADDR1(x
, y
);
1475 for (i
=0;i
<n
;i
++,ptr1
++) {
1477 *ptr1
= (GLchan
) index
[i
];
1482 for (i
=0;i
<n
;i
++,ptr1
++) {
1483 *ptr1
= (GLchan
) index
[i
];
1489 /* Write 8-bit color index to buffer */
1491 write_index8_span( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
1492 const GLubyte index
[], const GLubyte mask
[] )
1494 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1495 GLchan
*ptr1
= PIXELADDR1(x
, y
);
1498 for (i
=0;i
<n
;i
++,ptr1
++) {
1500 *ptr1
= (GLchan
) index
[i
];
1505 MEMCPY(ptr1
, index
, n
* sizeof(GLchan
));
1511 write_monoindex_span( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
1512 GLuint colorIndex
, const GLubyte mask
[] )
1514 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1515 GLchan
*ptr1
= PIXELADDR1(x
, y
);
1517 for (i
=0;i
<n
;i
++,ptr1
++) {
1519 *ptr1
= (GLchan
) colorIndex
;
1526 write_index_pixels( const GLcontext
*ctx
,
1527 GLuint n
, const GLint x
[], const GLint y
[],
1528 const GLuint index
[], const GLubyte mask
[] )
1530 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1534 GLchan
*ptr1
= PIXELADDR1(x
[i
], y
[i
]);
1535 *ptr1
= (GLchan
) index
[i
];
1542 write_monoindex_pixels( const GLcontext
*ctx
,
1543 GLuint n
, const GLint x
[], const GLint y
[],
1544 GLuint colorIndex
, const GLubyte mask
[] )
1546 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1550 GLchan
*ptr1
= PIXELADDR1(x
[i
], y
[i
]);
1551 *ptr1
= (GLchan
) colorIndex
;
1558 read_index_span( const GLcontext
*ctx
,
1559 GLuint n
, GLint x
, GLint y
, GLuint index
[] )
1561 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1563 const GLchan
*ptr1
= (const GLchan
*) PIXELADDR1(x
, y
);
1564 for (i
=0;i
<n
;i
++,ptr1
++) {
1565 index
[i
] = (GLuint
) *ptr1
;
1571 read_index_pixels( const GLcontext
*ctx
,
1572 GLuint n
, const GLint x
[], const GLint y
[],
1573 GLuint index
[], const GLubyte mask
[] )
1575 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1579 const GLchan
*ptr1
= PIXELADDR1(x
[i
], y
[i
]);
1580 index
[i
] = (GLuint
) *ptr1
;
1587 /**********************************************************************/
1588 /***** Optimized line rendering *****/
1589 /**********************************************************************/
1593 * Draw a flat-shaded, RGB line into an osmesa buffer.
1596 flat_rgba_line( GLcontext
*ctx
, const SWvertex
*vert0
, const SWvertex
*vert1
)
1598 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1599 const GLchan
*color
= vert1
->color
;
1603 #define PLOT(X, Y) \
1605 GLchan *p = PIXELADDR4(X, Y); \
1606 PACK_RGBA(p, color[0], color[1], color[2], color[3]); \
1610 #include "..\swrast\s_linetemp.h"
1612 #include "swrast/s_linetemp.h"
1618 * Draw a flat-shaded, Z-less, RGB line into an osmesa buffer.
1621 flat_rgba_z_line(GLcontext
*ctx
, const SWvertex
*vert0
, const SWvertex
*vert1
)
1623 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1624 const GLchan
*color
= vert1
->color
;
1628 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
1630 #define PLOT(X, Y) \
1633 GLchan *p = PIXELADDR4(X, Y); \
1634 PACK_RGBA(p, color[RCOMP], color[GCOMP], \
1635 color[BCOMP], color[ACOMP]); \
1642 #include "..\swrast\s_linetemp.h"
1644 #include "swrast/s_linetemp.h"
1650 * Draw a flat-shaded, alpha-blended, RGB line into an osmesa buffer.
1651 * XXX update for GLchan
1654 flat_blend_rgba_line( GLcontext
*ctx
,
1655 const SWvertex
*vert0
, const SWvertex
*vert1
)
1657 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1658 const GLint rshift
= osmesa
->rshift
;
1659 const GLint gshift
= osmesa
->gshift
;
1660 const GLint bshift
= osmesa
->bshift
;
1661 const GLint avalue
= vert0
->color
[3];
1662 const GLint msavalue
= CHAN_MAX
- avalue
;
1663 const GLint rvalue
= vert1
->color
[0]*avalue
;
1664 const GLint gvalue
= vert1
->color
[1]*avalue
;
1665 const GLint bvalue
= vert1
->color
[2]*avalue
;
1670 { GLuint *ptr4 = (GLuint *) PIXELADDR4(X, Y); \
1672 pixel |=((((((*ptr4) >> rshift) & 0xff)*msavalue+rvalue)>>8) << rshift);\
1673 pixel |=((((((*ptr4) >> gshift) & 0xff)*msavalue+gvalue)>>8) << gshift);\
1674 pixel |=((((((*ptr4) >> bshift) & 0xff)*msavalue+bvalue)>>8) << bshift);\
1678 #if 0 /* XXX use this in the future */
1681 GLchan *pixel = (GLchan *) PIXELADDR4(X, Y); \
1682 pixel[rInd] = (pixel[rInd] * msavalue + rvalue) >> CHAN_BITS; \
1683 pixel[gInd] = (pixel[gInd] * msavalue + gvalue) >> CHAN_BITS; \
1684 pixel[bInd] = (pixel[bInd] * msavalue + bvalue) >> CHAN_BITS; \
1685 pixel[aInd] = (pixel[aInd] * msavalue + avalue) >> CHAN_BITS; \
1690 #include "..\swrast\s_linetemp.h"
1692 #include "swrast/s_linetemp.h"
1698 * Draw a flat-shaded, Z-less, alpha-blended, RGB line into an osmesa buffer.
1699 * But don't write to Z buffer.
1700 * XXX update for GLchan
1703 flat_blend_rgba_z_line( GLcontext
*ctx
,
1704 const SWvertex
*vert0
, const SWvertex
*vert1
)
1706 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1707 const GLint rshift
= osmesa
->rshift
;
1708 const GLint gshift
= osmesa
->gshift
;
1709 const GLint bshift
= osmesa
->bshift
;
1710 const GLint avalue
= vert0
->color
[3];
1711 const GLint msavalue
= 256 - avalue
;
1712 const GLint rvalue
= vert1
->color
[0]*avalue
;
1713 const GLint gvalue
= vert1
->color
[1]*avalue
;
1714 const GLint bvalue
= vert1
->color
[2]*avalue
;
1718 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
1722 GLuint *ptr4 = (GLuint *) PIXELADDR4(X, Y); \
1724 pixel |=((((((*ptr4) >> rshift) & 0xff)*msavalue+rvalue)>>8) << rshift); \
1725 pixel |=((((((*ptr4) >> gshift) & 0xff)*msavalue+gvalue)>>8) << gshift); \
1726 pixel |=((((((*ptr4) >> bshift) & 0xff)*msavalue+bvalue)>>8) << bshift); \
1730 #if 0 /* XXX use this in the future */
1733 GLchan *pixel = (GLchan *) PIXELADDR4(X, Y); \
1734 pixel[rInd] = (pixel[rInd] * msavalue + rvalue) >> CHAN_BITS; \
1735 pixel[gInd] = (pixel[gInd] * msavalue + gvalue) >> CHAN_BITS; \
1736 pixel[bInd] = (pixel[bInd] * msavalue + bvalue) >> CHAN_BITS; \
1737 pixel[aInd] = (pixel[aInd] * msavalue + avalue) >> CHAN_BITS; \
1742 #include "..\swrast\s_linetemp.h"
1744 #include "swrast/s_linetemp.h"
1750 * Draw a flat-shaded, Z-less, alpha-blended, RGB line into an osmesa buffer.
1751 * XXX update for GLchan
1754 flat_blend_rgba_z_line_write( GLcontext
*ctx
,
1755 const SWvertex
*vert0
, const SWvertex
*vert1
)
1757 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1758 const GLint rshift
= osmesa
->rshift
;
1759 const GLint gshift
= osmesa
->gshift
;
1760 const GLint bshift
= osmesa
->bshift
;
1761 const GLint avalue
= vert0
->color
[3];
1762 const GLint msavalue
= 256 - avalue
;
1763 const GLint rvalue
= vert1
->color
[0]*avalue
;
1764 const GLint gvalue
= vert1
->color
[1]*avalue
;
1765 const GLint bvalue
= vert1
->color
[2]*avalue
;
1769 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
1773 GLuint *ptr4 = (GLuint *) PIXELADDR4(X, Y); \
1775 pixel |=((((((*ptr4) >> rshift) & 0xff)*msavalue+rvalue)>>8) << rshift); \
1776 pixel |=((((((*ptr4) >> gshift) & 0xff)*msavalue+gvalue)>>8) << gshift); \
1777 pixel |=((((((*ptr4) >> bshift) & 0xff)*msavalue+bvalue)>>8) << bshift); \
1782 #if 0 /* XXX use this in the future */
1785 GLchan *pixel = (GLchan *) PIXELADDR4(X, Y); \
1786 pixel[rInd] = (pixel[rInd] * msavalue + rvalue) >> CHAN_BITS; \
1787 pixel[gInd] = (pixel[gInd] * msavalue + gvalue) >> CHAN_BITS; \
1788 pixel[bInd] = (pixel[bInd] * msavalue + bvalue) >> CHAN_BITS; \
1789 pixel[aInd] = (pixel[aInd] * msavalue + avalue) >> CHAN_BITS; \
1795 #include "..\swrast\s_linetemp.h"
1797 #include "swrast/s_linetemp.h"
1803 * Analyze context state to see if we can provide a fast line drawing
1804 * function, like those in lines.c. Otherwise, return NULL.
1806 static swrast_line_func
1807 osmesa_choose_line_function( GLcontext
*ctx
)
1809 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1810 const SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
1812 if (CHAN_BITS
!= 8) return NULL
;
1813 if (ctx
->RenderMode
!= GL_RENDER
) return NULL
;
1814 if (ctx
->Line
.SmoothFlag
) return NULL
;
1815 if (ctx
->Texture
._EnabledUnits
) return NULL
;
1816 if (ctx
->Light
.ShadeModel
!= GL_FLAT
) return NULL
;
1817 if (ctx
->Line
.Width
!= 1.0F
) return NULL
;
1818 if (ctx
->Line
.StippleFlag
) return NULL
;
1819 if (ctx
->Line
.SmoothFlag
) return NULL
;
1820 if (osmesa
->format
!= OSMESA_RGBA
&&
1821 osmesa
->format
!= OSMESA_BGRA
&&
1822 osmesa
->format
!= OSMESA_ARGB
) return NULL
;
1824 if (swrast
->_RasterMask
==DEPTH_BIT
1825 && ctx
->Depth
.Func
==GL_LESS
1826 && ctx
->Depth
.Mask
==GL_TRUE
1827 && ctx
->Visual
.depthBits
== DEFAULT_SOFTWARE_DEPTH_BITS
) {
1828 return (swrast_line_func
) flat_rgba_z_line
;
1831 if (swrast
->_RasterMask
== 0) {
1832 return (swrast_line_func
) flat_rgba_line
;
1835 if (swrast
->_RasterMask
==(DEPTH_BIT
|BLEND_BIT
)
1836 && ctx
->Depth
.Func
==GL_LESS
1837 && ctx
->Depth
.Mask
==GL_TRUE
1838 && ctx
->Visual
.depthBits
== DEFAULT_SOFTWARE_DEPTH_BITS
1839 && ctx
->Color
.BlendSrcRGB
==GL_SRC_ALPHA
1840 && ctx
->Color
.BlendDstRGB
==GL_ONE_MINUS_SRC_ALPHA
1841 && ctx
->Color
.BlendSrcA
==GL_SRC_ALPHA
1842 && ctx
->Color
.BlendDstA
==GL_ONE_MINUS_SRC_ALPHA
1843 && ctx
->Color
.BlendEquation
==GL_FUNC_ADD_EXT
) {
1844 return (swrast_line_func
) flat_blend_rgba_z_line_write
;
1847 if (swrast
->_RasterMask
==(DEPTH_BIT
|BLEND_BIT
)
1848 && ctx
->Depth
.Func
==GL_LESS
1849 && ctx
->Depth
.Mask
==GL_FALSE
1850 && ctx
->Visual
.depthBits
== DEFAULT_SOFTWARE_DEPTH_BITS
1851 && ctx
->Color
.BlendSrcRGB
==GL_SRC_ALPHA
1852 && ctx
->Color
.BlendDstRGB
==GL_ONE_MINUS_SRC_ALPHA
1853 && ctx
->Color
.BlendSrcA
==GL_SRC_ALPHA
1854 && ctx
->Color
.BlendDstA
==GL_ONE_MINUS_SRC_ALPHA
1855 && ctx
->Color
.BlendEquation
==GL_FUNC_ADD_EXT
) {
1856 return (swrast_line_func
) flat_blend_rgba_z_line
;
1859 if (swrast
->_RasterMask
==BLEND_BIT
1860 && ctx
->Color
.BlendSrcRGB
==GL_SRC_ALPHA
1861 && ctx
->Color
.BlendDstRGB
==GL_ONE_MINUS_SRC_ALPHA
1862 && ctx
->Color
.BlendSrcA
==GL_SRC_ALPHA
1863 && ctx
->Color
.BlendDstA
==GL_ONE_MINUS_SRC_ALPHA
1864 && ctx
->Color
.BlendEquation
==GL_FUNC_ADD_EXT
) {
1865 return (swrast_line_func
) flat_blend_rgba_line
;
1868 return (swrast_line_func
) NULL
;
1872 /**********************************************************************/
1873 /***** Optimized triangle rendering *****/
1874 /**********************************************************************/
1878 * Smooth-shaded, z-less triangle, RGBA color.
1880 static void smooth_rgba_z_triangle( GLcontext
*ctx
,
1883 const SWvertex
*v2
)
1885 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1887 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
1888 #define INTERP_RGB 1
1889 #define INTERP_ALPHA 1
1890 #define RENDER_SPAN( span ) \
1892 GLchan *img = PIXELADDR4(span.x, span.y); \
1893 for (i = 0; i < span.end; i++, img += 4) { \
1894 const GLdepth z = FixedToDepth(span.z); \
1895 if (z < zRow[i]) { \
1896 PACK_RGBA(img, FixedToChan(span.red), \
1897 FixedToChan(span.green), FixedToChan(span.blue), \
1898 FixedToChan(span.alpha)); \
1901 span.red += span.redStep; \
1902 span.green += span.greenStep; \
1903 span.blue += span.blueStep; \
1904 span.alpha += span.alphaStep; \
1905 span.z += span.zStep; \
1909 #include "..\swrast\s_tritemp.h"
1911 #include "swrast/s_tritemp.h"
1919 * Flat-shaded, z-less triangle, RGBA color.
1921 static void flat_rgba_z_triangle( GLcontext
*ctx
,
1924 const SWvertex
*v2
)
1926 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1928 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
1929 #define SETUP_CODE \
1931 PACK_RGBA((GLchan *) &pixel, v2->color[0], v2->color[1], \
1932 v2->color[2], v2->color[3]);
1934 #define RENDER_SPAN( span ) \
1936 GLuint *img = (GLuint *) PIXELADDR4(span.x, span.y); \
1937 for (i = 0; i < span.end; i++) { \
1938 const GLdepth z = FixedToDepth(span.z); \
1939 if (z < zRow[i]) { \
1943 span.z += span.zStep; \
1947 #include "..\swrast\s_tritemp.h"
1949 #include "swrast/s_tritemp.h"
1956 * Return pointer to an accelerated triangle function if possible.
1958 static swrast_tri_func
1959 osmesa_choose_triangle_function( GLcontext
*ctx
)
1961 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1962 const SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
1964 if (CHAN_BITS
!= 8) return (swrast_tri_func
) NULL
;
1965 if (ctx
->RenderMode
!= GL_RENDER
) return (swrast_tri_func
) NULL
;
1966 if (ctx
->Polygon
.SmoothFlag
) return (swrast_tri_func
) NULL
;
1967 if (ctx
->Polygon
.StippleFlag
) return (swrast_tri_func
) NULL
;
1968 if (ctx
->Texture
._EnabledUnits
) return (swrast_tri_func
) NULL
;
1969 if (osmesa
->format
!= OSMESA_RGBA
&&
1970 osmesa
->format
!= OSMESA_BGRA
&&
1971 osmesa
->format
!= OSMESA_ARGB
) return (swrast_tri_func
) NULL
;
1972 if (ctx
->Polygon
.CullFlag
&&
1973 ctx
->Polygon
.CullFaceMode
== GL_FRONT_AND_BACK
)
1974 return (swrast_tri_func
) NULL
;
1976 if (swrast
->_RasterMask
== DEPTH_BIT
&&
1977 ctx
->Depth
.Func
== GL_LESS
&&
1978 ctx
->Depth
.Mask
== GL_TRUE
&&
1979 ctx
->Visual
.depthBits
== DEFAULT_SOFTWARE_DEPTH_BITS
) {
1980 if (ctx
->Light
.ShadeModel
== GL_SMOOTH
) {
1981 return (swrast_tri_func
) smooth_rgba_z_triangle
;
1984 return (swrast_tri_func
) flat_rgba_z_triangle
;
1987 return (swrast_tri_func
) NULL
;
1992 /* Override for the swrast triangle-selection function. Try to use one
1993 * of our internal triangle functions, otherwise fall back to the
1994 * standard swrast functions.
1996 static void osmesa_choose_triangle( GLcontext
*ctx
)
1998 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
2000 swrast
->Triangle
= osmesa_choose_triangle_function( ctx
);
2001 if (!swrast
->Triangle
)
2002 _swrast_choose_triangle( ctx
);
2005 static void osmesa_choose_line( GLcontext
*ctx
)
2007 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
2009 swrast
->Line
= osmesa_choose_line_function( ctx
);
2011 _swrast_choose_line( ctx
);
2015 #define OSMESA_NEW_LINE (_NEW_LINE | \
2020 _SWRAST_NEW_RASTERMASK)
2022 #define OSMESA_NEW_TRIANGLE (_NEW_POLYGON | \
2027 _SWRAST_NEW_RASTERMASK)
2030 /* Extend the software rasterizer with our line and triangle
2033 static void osmesa_register_swrast_functions( GLcontext
*ctx
)
2035 SWcontext
*swrast
= SWRAST_CONTEXT( ctx
);
2037 swrast
->choose_line
= osmesa_choose_line
;
2038 swrast
->choose_triangle
= osmesa_choose_triangle
;
2040 swrast
->invalidate_line
|= OSMESA_NEW_LINE
;
2041 swrast
->invalidate_triangle
|= OSMESA_NEW_TRIANGLE
;
2045 static const GLubyte
*get_string( GLcontext
*ctx
, GLenum name
)
2051 return (const GLubyte
*) "Mesa OffScreen32";
2052 #elif CHAN_BITS == 16
2053 return (const GLubyte
*) "Mesa OffScreen16";
2055 return (const GLubyte
*) "Mesa OffScreen";
2063 static void osmesa_update_state( GLcontext
*ctx
, GLuint new_state
)
2065 OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
2066 struct swrast_device_driver
*swdd
= _swrast_GetDeviceDriverReference( ctx
);
2067 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
2069 ASSERT((void *) osmesa
== (void *) ctx
->DriverCtx
);
2072 * XXX these function pointers could be initialized just once during
2073 * context creation since they don't depend on any state changes.
2076 ctx
->Driver
.GetString
= get_string
;
2077 ctx
->Driver
.UpdateState
= osmesa_update_state
;
2078 ctx
->Driver
.ResizeBuffers
= _swrast_alloc_buffers
;
2079 ctx
->Driver
.GetBufferSize
= buffer_size
;
2081 ctx
->Driver
.Accum
= _swrast_Accum
;
2082 ctx
->Driver
.Bitmap
= _swrast_Bitmap
;
2083 ctx
->Driver
.Clear
= clear
;
2084 ctx
->Driver
.CopyPixels
= _swrast_CopyPixels
;
2085 ctx
->Driver
.DrawPixels
= _swrast_DrawPixels
;
2086 ctx
->Driver
.ReadPixels
= _swrast_ReadPixels
;
2087 ctx
->Driver
.DrawBuffer
= _swrast_DrawBuffer
;
2089 ctx
->Driver
.ChooseTextureFormat
= _mesa_choose_tex_format
;
2090 ctx
->Driver
.TexImage1D
= _mesa_store_teximage1d
;
2091 ctx
->Driver
.TexImage2D
= _mesa_store_teximage2d
;
2092 ctx
->Driver
.TexImage3D
= _mesa_store_teximage3d
;
2093 ctx
->Driver
.TexSubImage1D
= _mesa_store_texsubimage1d
;
2094 ctx
->Driver
.TexSubImage2D
= _mesa_store_texsubimage2d
;
2095 ctx
->Driver
.TexSubImage3D
= _mesa_store_texsubimage3d
;
2096 ctx
->Driver
.TestProxyTexImage
= _mesa_test_proxy_teximage
;
2098 ctx
->Driver
.CompressedTexImage1D
= _mesa_store_compressed_teximage1d
;
2099 ctx
->Driver
.CompressedTexImage2D
= _mesa_store_compressed_teximage2d
;
2100 ctx
->Driver
.CompressedTexImage3D
= _mesa_store_compressed_teximage3d
;
2101 ctx
->Driver
.CompressedTexSubImage1D
= _mesa_store_compressed_texsubimage1d
;
2102 ctx
->Driver
.CompressedTexSubImage2D
= _mesa_store_compressed_texsubimage2d
;
2103 ctx
->Driver
.CompressedTexSubImage3D
= _mesa_store_compressed_texsubimage3d
;
2105 ctx
->Driver
.CopyTexImage1D
= _swrast_copy_teximage1d
;
2106 ctx
->Driver
.CopyTexImage2D
= _swrast_copy_teximage2d
;
2107 ctx
->Driver
.CopyTexSubImage1D
= _swrast_copy_texsubimage1d
;
2108 ctx
->Driver
.CopyTexSubImage2D
= _swrast_copy_texsubimage2d
;
2109 ctx
->Driver
.CopyTexSubImage3D
= _swrast_copy_texsubimage3d
;
2110 ctx
->Driver
.CopyColorTable
= _swrast_CopyColorTable
;
2111 ctx
->Driver
.CopyColorSubTable
= _swrast_CopyColorSubTable
;
2112 ctx
->Driver
.CopyConvolutionFilter1D
= _swrast_CopyConvolutionFilter1D
;
2113 ctx
->Driver
.CopyConvolutionFilter2D
= _swrast_CopyConvolutionFilter2D
;
2115 swdd
->SetBuffer
= set_buffer
;
2117 /* RGB(A) span/pixel functions */
2118 if (osmesa
->format
== OSMESA_RGB
) {
2119 swdd
->WriteRGBASpan
= write_rgba_span_RGB
;
2120 swdd
->WriteRGBSpan
= write_rgb_span_RGB
;
2121 swdd
->WriteMonoRGBASpan
= write_monocolor_span_RGB
;
2122 swdd
->WriteRGBAPixels
= write_rgba_pixels_RGB
;
2123 swdd
->WriteMonoRGBAPixels
= write_monocolor_pixels_RGB
;
2124 swdd
->ReadRGBASpan
= read_rgba_span3
;
2125 swdd
->ReadRGBAPixels
= read_rgba_pixels3
;
2127 else if (osmesa
->format
== OSMESA_BGR
) {
2128 swdd
->WriteRGBASpan
= write_rgba_span_BGR
;
2129 swdd
->WriteRGBSpan
= write_rgb_span_BGR
;
2130 swdd
->WriteMonoRGBASpan
= write_monocolor_span_BGR
;
2131 swdd
->WriteRGBAPixels
= write_rgba_pixels_BGR
;
2132 swdd
->WriteMonoRGBAPixels
= write_monocolor_pixels_BGR
;
2133 swdd
->ReadRGBASpan
= read_rgba_span3
;
2134 swdd
->ReadRGBAPixels
= read_rgba_pixels3
;
2136 else if (osmesa
->format
== OSMESA_RGB_565
) {
2137 swdd
->WriteRGBASpan
= write_rgba_span2
;
2138 swdd
->WriteRGBSpan
= write_rgb_span2
;
2139 swdd
->WriteMonoRGBASpan
= write_monocolor_span2
;
2140 swdd
->WriteRGBAPixels
= write_rgba_pixels2
;
2141 swdd
->WriteMonoRGBAPixels
= write_monocolor_pixels2
;
2142 swdd
->ReadRGBASpan
= read_rgba_span2
;
2143 swdd
->ReadRGBAPixels
= read_rgba_pixels2
;
2146 /* 4 GLchan / pixel in frame buffer */
2147 swdd
->WriteRGBSpan
= write_rgb_span
;
2148 swdd
->WriteRGBAPixels
= write_rgba_pixels
;
2149 swdd
->WriteMonoRGBASpan
= write_monocolor_span
;
2150 swdd
->WriteMonoRGBAPixels
= write_monocolor_pixels
;
2151 if (osmesa
->format
== OSMESA_RGBA
&&
2152 CHAN_TYPE
== GL_UNSIGNED_BYTE
&&
2153 RCOMP
==0 && GCOMP
==1 && BCOMP
==2 && ACOMP
==3) {
2154 /* special, fast case */
2155 swdd
->WriteRGBASpan
= write_rgba_span_rgba
;
2156 swdd
->ReadRGBASpan
= read_rgba_span_rgba
;
2159 swdd
->WriteRGBASpan
= write_rgba_span
;
2160 swdd
->ReadRGBASpan
= read_rgba_span
;
2162 swdd
->ReadRGBAPixels
= read_rgba_pixels
;
2165 /* CI span/pixel functions */
2166 swdd
->WriteCI32Span
= write_index32_span
;
2167 swdd
->WriteCI8Span
= write_index8_span
;
2168 swdd
->WriteMonoCISpan
= write_monoindex_span
;
2169 swdd
->WriteCI32Pixels
= write_index_pixels
;
2170 swdd
->WriteMonoCIPixels
= write_monoindex_pixels
;
2171 swdd
->ReadCI32Span
= read_index_span
;
2172 swdd
->ReadCI32Pixels
= read_index_pixels
;
2174 tnl
->Driver
.RunPipeline
= _tnl_run_pipeline
;
2176 _swrast_InvalidateState( ctx
, new_state
);
2177 _swsetup_InvalidateState( ctx
, new_state
);
2178 _ac_InvalidateState( ctx
, new_state
);
2179 _tnl_InvalidateState( ctx
, new_state
);