1 /* $Id: osmesa.c,v 1.44 2001/02/06 21:42:49 brianp Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2001 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"
43 #include "extensions.h"
50 #include "array_cache/acache.h"
51 #include "swrast/swrast.h"
52 #include "swrast_setup/swrast_setup.h"
53 #include "swrast/s_context.h"
54 #include "swrast/s_depth.h"
55 #include "swrast/s_lines.h"
56 #include "swrast/s_triangle.h"
62 * This is the OS/Mesa context struct.
63 * Notice how it includes a GLcontext. By doing this we're mimicking
64 * C++ inheritance/derivation.
65 * Later, we can cast a GLcontext pointer into an OSMesaContext pointer
68 struct osmesa_context
{
69 GLcontext gl_ctx
; /* The core GL/Mesa context */
70 GLvisual
*gl_visual
; /* Describes the buffers */
71 GLframebuffer
*gl_buffer
; /* Depth, stencil, accum, etc buffers */
72 GLenum format
; /* either GL_RGBA or GL_COLOR_INDEX */
73 void *buffer
; /* the image buffer */
74 GLint width
, height
; /* size of image buffer */
75 GLint rowlength
; /* number of pixels per row */
76 GLint userRowLength
; /* user-specified number of pixels per row */
77 GLint rshift
, gshift
; /* bit shifts for RGBA formats */
79 GLint rInd
, gInd
, bInd
, aInd
;/* index offsets for RGBA formats */
80 GLchan
*rowaddr
[MAX_HEIGHT
]; /* address of first pixel in each image row */
81 GLboolean yup
; /* TRUE -> Y increases upward */
82 /* FALSE -> Y increases downward */
87 /* A forward declaration: */
88 static void osmesa_update_state( GLcontext
*ctx
, GLuint newstate
);
89 static void osmesa_register_swrast_functions( GLcontext
*ctx
);
93 #define OSMESA_CONTEXT(ctx) ((OSMesaContext) (ctx->DriverCtx))
97 /**********************************************************************/
98 /***** Public Functions *****/
99 /**********************************************************************/
103 * Create an Off-Screen Mesa rendering context. The only attribute needed is
104 * an RGBA vs Color-Index mode flag.
106 * Input: format - either GL_RGBA or GL_COLOR_INDEX
107 * sharelist - specifies another OSMesaContext with which to share
108 * display lists. NULL indicates no sharing.
109 * Return: an OSMesaContext or 0 if error
111 OSMesaContext GLAPIENTRY
112 OSMesaCreateContext( GLenum format
, OSMesaContext sharelist
)
114 return OSMesaCreateContextExt(format
, DEFAULT_SOFTWARE_DEPTH_BITS
,
123 * Create context and specify size of ancillary buffers.
125 OSMesaContext GLAPIENTRY
126 OSMesaCreateContextExt( GLenum format
, GLint depthBits
, GLint stencilBits
,
127 GLint accumBits
, OSMesaContext sharelist
)
129 OSMesaContext osmesa
;
130 GLint rshift
, gshift
, bshift
, ashift
;
131 GLint rind
, gind
, bind
, aind
;
132 GLint indexBits
, redBits
, greenBits
, blueBits
, alphaBits
;
136 const GLubyte
*i1
= (GLubyte
*) &i4
;
137 const GLint little_endian
= *i1
;
140 rind
= gind
= bind
= aind
= 0;
141 if (format
==OSMESA_COLOR_INDEX
) {
143 rshift
= gshift
= bshift
= ashift
= 0;
146 else if (format
==OSMESA_RGBA
) {
170 else if (format
==OSMESA_BGRA
) {
194 else if (format
==OSMESA_ARGB
) {
218 else if (format
==OSMESA_RGB
) {
234 else if (format
==OSMESA_BGR
) {
255 osmesa
= (OSMesaContext
) CALLOC_STRUCT(osmesa_context
);
257 osmesa
->gl_visual
= _mesa_create_visual( rgbmode
,
258 GL_FALSE
, /* double buffer */
259 GL_FALSE
, /* stereo */
270 alphaBits
? accumBits
: 0,
273 if (!osmesa
->gl_visual
) {
278 if (!_mesa_initialize_context(&osmesa
->gl_ctx
,
280 sharelist
? &sharelist
->gl_ctx
281 : (GLcontext
*) NULL
,
282 (void *) osmesa
, GL_TRUE
)) {
283 _mesa_destroy_visual( osmesa
->gl_visual
);
288 _mesa_enable_sw_extensions(&(osmesa
->gl_ctx
));
290 osmesa
->gl_buffer
= _mesa_create_framebuffer( osmesa
->gl_visual
,
291 osmesa
->gl_visual
->depthBits
> 0,
292 osmesa
->gl_visual
->stencilBits
> 0,
293 osmesa
->gl_visual
->accumRedBits
> 0,
294 osmesa
->gl_visual
->alphaBits
> 0 );
296 if (!osmesa
->gl_buffer
) {
297 _mesa_destroy_visual( osmesa
->gl_visual
);
298 _mesa_free_context_data( &osmesa
->gl_ctx
);
302 osmesa
->format
= format
;
303 osmesa
->buffer
= NULL
;
306 osmesa
->userRowLength
= 0;
307 osmesa
->rowlength
= 0;
308 osmesa
->yup
= GL_TRUE
;
309 osmesa
->rshift
= rshift
;
310 osmesa
->gshift
= gshift
;
311 osmesa
->bshift
= bshift
;
312 osmesa
->ashift
= ashift
;
319 /* Initialize the software rasterizer and helper modules.
322 GLcontext
*ctx
= &osmesa
->gl_ctx
;
324 _swrast_CreateContext( ctx
);
325 _ac_CreateContext( ctx
);
326 _tnl_CreateContext( ctx
);
327 _swsetup_CreateContext( ctx
);
329 osmesa_register_swrast_functions( ctx
);
339 * Destroy an Off-Screen Mesa rendering context.
341 * Input: ctx - the context to destroy
343 void GLAPIENTRY
OSMesaDestroyContext( OSMesaContext ctx
)
346 _mesa_destroy_visual( ctx
->gl_visual
);
347 _mesa_destroy_framebuffer( ctx
->gl_buffer
);
348 _mesa_free_context_data( &ctx
->gl_ctx
);
356 * Recompute the values of the context's rowaddr array.
358 static void compute_row_addresses( OSMesaContext ctx
)
360 GLint bytesPerPixel
, bytesPerRow
, i
;
361 GLubyte
*origin
= (GLubyte
*) ctx
->buffer
;
363 if (ctx
->format
== OSMESA_COLOR_INDEX
) {
365 bytesPerPixel
= 1 * sizeof(GLchan
);
367 else if ((ctx
->format
== OSMESA_RGB
) || (ctx
->format
== OSMESA_BGR
)) {
369 bytesPerPixel
= 3 * sizeof(GLchan
);
373 bytesPerPixel
= 4 * sizeof(GLchan
);
376 bytesPerRow
= ctx
->rowlength
* bytesPerPixel
;
379 /* Y=0 is bottom line of window */
380 for (i
= 0; i
< MAX_HEIGHT
; i
++) {
381 ctx
->rowaddr
[i
] = (GLchan
*) ((GLubyte
*) origin
+ i
* bytesPerRow
);
385 /* Y=0 is top line of window */
386 for (i
= 0; i
< MAX_HEIGHT
; i
++) {
387 GLint j
= ctx
->height
- i
- 1;
388 ctx
->rowaddr
[i
] = (GLchan
*) ((GLubyte
*) origin
+ j
* bytesPerRow
);
395 * Bind an OSMesaContext to an image buffer. The image buffer is just a
396 * block of memory which the client provides. Its size must be at least
397 * as large as width*height*sizeof(type). Its address should be a multiple
398 * of 4 if using RGBA mode.
400 * Image data is stored in the order of glDrawPixels: row-major order
401 * with the lower-left image pixel stored in the first array position
402 * (ie. bottom-to-top).
404 * Since the only type initially supported is GL_UNSIGNED_BYTE, if the
405 * context is in RGBA mode, each pixel will be stored as a 4-byte RGBA
406 * value. If the context is in color indexed mode, each pixel will be
407 * stored as a 1-byte value.
409 * If the context's viewport hasn't been initialized yet, it will now be
410 * initialized to (0,0,width,height).
412 * Input: ctx - the rendering context
413 * buffer - the image buffer memory
414 * type - data type for pixel components, only GL_UNSIGNED_BYTE
416 * width, height - size of image buffer in pixels, at least 1
417 * Return: GL_TRUE if success, GL_FALSE if error because of invalid ctx,
418 * invalid buffer address, type!=GL_UNSIGNED_BYTE, width<1, height<1,
419 * width>internal limit or height>internal limit.
422 OSMesaMakeCurrent( OSMesaContext ctx
, void *buffer
, GLenum type
,
423 GLsizei width
, GLsizei height
)
425 if (!ctx
|| !buffer
|| type
!= CHAN_TYPE
||
426 width
< 1 || height
< 1 ||
427 width
> MAX_WIDTH
|| height
> MAX_HEIGHT
) {
431 osmesa_update_state( &ctx
->gl_ctx
, 0 );
432 _mesa_make_current( &ctx
->gl_ctx
, ctx
->gl_buffer
);
434 ctx
->buffer
= buffer
;
436 ctx
->height
= height
;
437 if (ctx
->userRowLength
)
438 ctx
->rowlength
= ctx
->userRowLength
;
440 ctx
->rowlength
= width
;
442 compute_row_addresses( ctx
);
445 if (ctx
->gl_ctx
.Viewport
.Width
==0) {
446 /* initialize viewport and scissor box to buffer size */
447 _mesa_Viewport( 0, 0, width
, height
);
448 ctx
->gl_ctx
.Scissor
.Width
= width
;
449 ctx
->gl_ctx
.Scissor
.Height
= height
;
457 OSMesaContext GLAPIENTRY
OSMesaGetCurrentContext( void )
459 GLcontext
*ctx
= _mesa_get_current_context();
461 return (OSMesaContext
) ctx
;
468 void GLAPIENTRY
OSMesaPixelStore( GLint pname
, GLint value
)
470 OSMesaContext ctx
= OSMesaGetCurrentContext();
473 case OSMESA_ROW_LENGTH
:
475 gl_error( &ctx
->gl_ctx
, GL_INVALID_VALUE
,
476 "OSMesaPixelStore(value)" );
479 ctx
->userRowLength
= value
;
480 ctx
->rowlength
= value
;
483 ctx
->yup
= value
? GL_TRUE
: GL_FALSE
;
486 gl_error( &ctx
->gl_ctx
, GL_INVALID_ENUM
, "OSMesaPixelStore(pname)" );
490 compute_row_addresses( ctx
);
494 void GLAPIENTRY
OSMesaGetIntegerv( GLint pname
, GLint
*value
)
496 OSMesaContext ctx
= OSMesaGetCurrentContext();
503 *value
= ctx
->height
;
506 *value
= ctx
->format
;
509 *value
= GL_UNSIGNED_BYTE
;
511 case OSMESA_ROW_LENGTH
:
512 *value
= ctx
->rowlength
;
518 gl_error(&ctx
->gl_ctx
, GL_INVALID_ENUM
, "OSMesaGetIntergerv(pname)");
524 * Return the depth buffer associated with an OSMesa context.
525 * Input: c - the OSMesa context
526 * Output: width, height - size of buffer in pixels
527 * bytesPerValue - bytes per depth value (2 or 4)
528 * buffer - pointer to depth buffer values
529 * Return: GL_TRUE or GL_FALSE to indicate success or failure.
532 OSMesaGetDepthBuffer( OSMesaContext c
, GLint
*width
, GLint
*height
,
533 GLint
*bytesPerValue
, void **buffer
)
535 if ((!c
->gl_buffer
) || (!c
->gl_buffer
->DepthBuffer
)) {
543 *width
= c
->gl_buffer
->Width
;
544 *height
= c
->gl_buffer
->Height
;
545 *bytesPerValue
= sizeof(GLdepth
);
546 *buffer
= c
->gl_buffer
->DepthBuffer
;
552 * Return the color buffer associated with an OSMesa context.
553 * Input: c - the OSMesa context
554 * Output: width, height - size of buffer in pixels
555 * format - the pixel format (OSMESA_FORMAT)
556 * buffer - pointer to color buffer values
557 * Return: GL_TRUE or GL_FALSE to indicate success or failure.
560 OSMesaGetColorBuffer( OSMesaContext c
, GLint
*width
,
561 GLint
*height
, GLint
*format
, void **buffer
)
579 /**********************************************************************/
580 /*** Device Driver Functions ***/
581 /**********************************************************************/
588 #define PACK_RGBA(DST, R, G, B, A) \
590 (DST)[osmesa->rInd] = R; \
591 (DST)[osmesa->gInd] = G; \
592 (DST)[osmesa->bInd] = B; \
593 (DST)[osmesa->aInd] = A; \
596 #define PACK_RGB(DST, R, G, B) \
603 #define PACK_BGR(DST, R, G, B) \
611 #define UNPACK_RED(P) ( ((GLchan *) &(P))[osmesa->rInd] )
612 #define UNPACK_GREEN(P) ( ((GLchan *) &(P))[osmesa->gInd] )
613 #define UNPACK_BLUE(P) ( ((GLchan *) &(P))[osmesa->bInd] )
614 #define UNPACK_ALPHA(P) ( ((GLchan *) &(P))[osmesa->aInd] )
617 #define PIXELADDR1(X,Y) (osmesa->rowaddr[Y] + (X))
618 #define PIXELADDR3(X,Y) (osmesa->rowaddr[Y] + 3 * (X))
619 #define PIXELADDR4(X,Y) (osmesa->rowaddr[Y] + 4 * (X))
623 static GLboolean
set_draw_buffer( GLcontext
*ctx
, GLenum mode
)
626 if (mode
==GL_FRONT_LEFT
) {
635 static void set_read_buffer( GLcontext
*ctx
, GLframebuffer
*buffer
, GLenum mode
)
637 /* separate read buffer not supported */
638 ASSERT(buffer
== ctx
->DrawBuffer
);
639 ASSERT(mode
== GL_FRONT_LEFT
);
643 static void clear( GLcontext
*ctx
, GLbitfield mask
, GLboolean all
,
644 GLint x
, GLint y
, GLint width
, GLint height
)
646 OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
647 const GLuint
*colorMask
= (GLuint
*) &ctx
->Color
.ColorMask
;
649 /* sanity check - we only have a front-left buffer */
650 ASSERT((mask
& (DD_FRONT_RIGHT_BIT
| DD_BACK_LEFT_BIT
| DD_BACK_RIGHT_BIT
)) == 0);
651 if (*colorMask
== 0xffffffff && ctx
->Color
.IndexMask
== 0xffffffff) {
652 if (mask
& DD_FRONT_LEFT_BIT
) {
653 if (osmesa
->format
== OSMESA_COLOR_INDEX
) {
655 /* Clear whole CI buffer */
656 #if CHAN_TYPE == GL_UNSIGNED_BYTE
657 MEMSET(osmesa
->buffer
, ctx
->Color
.ClearIndex
,
658 osmesa
->rowlength
* osmesa
->height
);
660 const GLint n
= osmesa
->rowlength
* osmesa
->height
;
661 GLchan
*buffer
= (GLchan
*) osmesa
->buffer
;
663 for (i
= 0; i
< n
; i
++) {
664 buffer
[i
] = ctx
->Color
.ClearIndex
;
669 /* Clear part of CI buffer */
670 const GLchan clearIndex
= (GLchan
) ctx
->Color
.ClearIndex
;
672 for (i
= 0; i
< height
; i
++) {
673 GLchan
*ptr1
= PIXELADDR1(x
, (y
+ i
));
674 for (j
= 0; j
< width
; j
++) {
675 *ptr1
++ = clearIndex
;
680 else if (osmesa
->format
== OSMESA_RGB
) {
681 const GLchan r
= ctx
->Color
.ClearColor
[0];
682 const GLchan g
= ctx
->Color
.ClearColor
[1];
683 const GLchan b
= ctx
->Color
.ClearColor
[2];
685 /* Clear whole RGB buffer */
686 GLuint n
= osmesa
->rowlength
* osmesa
->height
;
687 GLchan
*ptr3
= (GLchan
*) osmesa
->buffer
;
689 for (i
= 0; i
< n
; i
++) {
690 PACK_RGB(ptr3
, r
, g
, b
);
695 /* Clear part of RGB buffer */
697 for (i
= 0; i
< height
; i
++) {
698 GLchan
*ptr3
= PIXELADDR3(x
, (y
+ i
));
699 for (j
= 0; j
< width
; j
++) {
700 PACK_RGB(ptr3
, r
, g
, b
);
706 else if (osmesa
->format
== OSMESA_BGR
) {
707 const GLchan r
= ctx
->Color
.ClearColor
[0];
708 const GLchan g
= ctx
->Color
.ClearColor
[1];
709 const GLchan b
= ctx
->Color
.ClearColor
[2];
711 /* Clear whole RGB buffer */
712 const GLint n
= osmesa
->rowlength
* osmesa
->height
;
713 GLchan
*ptr3
= (GLchan
*) osmesa
->buffer
;
715 for (i
= 0; i
< n
; i
++) {
716 PACK_BGR(ptr3
, r
, g
, b
);
721 /* Clear part of RGB buffer */
723 for (i
= 0; i
< height
; i
++) {
724 GLchan
*ptr3
= PIXELADDR3(x
, (y
+ i
));
725 for (j
= 0; j
< width
; j
++) {
726 PACK_BGR(ptr3
, r
, g
, b
);
733 #if CHAN_TYPE == GL_UNSIGNED_BYTE
734 /* 4-byte pixel value */
736 GLchan
*clr
= (GLchan
*) &clearPixel
;
737 clr
[osmesa
->rInd
] = ctx
->Color
.ClearColor
[0];
738 clr
[osmesa
->gInd
] = ctx
->Color
.ClearColor
[1];
739 clr
[osmesa
->bInd
] = ctx
->Color
.ClearColor
[2];
740 clr
[osmesa
->aInd
] = ctx
->Color
.ClearColor
[3];
742 /* Clear whole RGBA buffer */
743 const GLuint n
= osmesa
->rowlength
* osmesa
->height
;
744 GLuint
*ptr4
= (GLuint
*) osmesa
->buffer
;
747 for (i
= 0; i
< n
; i
++) {
748 *ptr4
++ = clearPixel
;
752 BZERO(ptr4
, n
* sizeof(GLuint
));
756 /* Clear part of RGBA buffer */
758 for (i
= 0; i
< height
; i
++) {
759 GLuint
*ptr4
= (GLuint
*) PIXELADDR4(x
, (y
+ i
));
760 for (j
= 0; j
< width
; j
++) {
761 *ptr4
++ = clearPixel
;
766 const GLchan r
= ctx
->Color
.ClearColor
[0];
767 const GLchan g
= ctx
->Color
.ClearColor
[1];
768 const GLchan b
= ctx
->Color
.ClearColor
[2];
769 const GLchan a
= ctx
->Color
.ClearColor
[3];
771 /* Clear whole RGBA buffer */
772 const GLuint n
= osmesa
->rowlength
* osmesa
->height
;
773 GLchan
*p
= (GLchan
*) osmesa
->buffer
;
775 for (i
= 0; i
< n
; i
++) {
776 PACK_RGBA(p
, r
, g
, b
, a
);
781 /* Clear part of RGBA buffer */
783 for (i
= 0; i
< height
; i
++) {
784 GLchan
*p
= PIXELADDR4(x
, (y
+ i
));
785 for (j
= 0; j
< width
; j
++) {
786 PACK_RGBA(p
, r
, g
, b
, a
);
794 mask
&= ~DD_FRONT_LEFT_BIT
;
799 _swrast_Clear( ctx
, mask
, all
, x
, y
, width
, height
);
804 static void buffer_size( GLcontext
*ctx
, GLuint
*width
, GLuint
*height
)
806 OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
807 *width
= osmesa
->width
;
808 *height
= osmesa
->height
;
812 /**********************************************************************/
813 /***** Read/write spans/arrays of RGBA pixels *****/
814 /**********************************************************************/
816 /* Write RGBA pixels to an RGBA (or permuted) buffer. */
818 write_rgba_span( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
819 CONST GLchan rgba
[][4], const GLubyte mask
[] )
821 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
822 GLchan
*p
= PIXELADDR4(x
, y
);
825 for (i
= 0; i
< n
; i
++, p
+= 4) {
827 PACK_RGBA(p
, rgba
[i
][RCOMP
], rgba
[i
][GCOMP
],
828 rgba
[i
][BCOMP
], rgba
[i
][ACOMP
]);
833 for (i
= 0; i
< n
; i
++, p
+= 4) {
834 PACK_RGBA(p
, rgba
[i
][RCOMP
], rgba
[i
][GCOMP
],
835 rgba
[i
][BCOMP
], rgba
[i
][ACOMP
]);
841 /* Write RGBA pixels to an RGBA buffer. This is the fastest span-writer. */
843 write_rgba_span_rgba( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
844 CONST GLchan rgba
[][4], const GLubyte mask
[] )
846 OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
847 GLuint
*ptr4
= (GLuint
*) PIXELADDR4(x
, y
);
848 const GLuint
*rgba4
= (const GLuint
*) rgba
;
850 ASSERT(CHAN_TYPE
== GL_UNSIGNED_BYTE
);
852 for (i
= 0; i
< n
; i
++) {
859 MEMCPY( ptr4
, rgba4
, n
* 4 );
864 /* Write RGB pixels to an RGBA (or permuted) buffer. */
866 write_rgb_span( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
867 CONST GLchan rgb
[][3], const GLubyte mask
[] )
869 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
870 GLchan
*p
= PIXELADDR4(x
, y
);
873 for (i
= 0; i
< n
; i
++, p
+=4) {
875 PACK_RGBA(p
, rgb
[i
][RCOMP
], rgb
[i
][GCOMP
], rgb
[i
][BCOMP
], 255);
880 for (i
= 0; i
< n
; i
++, p
+=4) {
881 PACK_RGBA(p
, rgb
[i
][RCOMP
], rgb
[i
][GCOMP
], rgb
[i
][BCOMP
], 255);
889 write_monocolor_span( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
890 const GLchan color
[4], const GLubyte mask
[] )
892 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
893 GLchan
*p
= PIXELADDR4(x
, y
);
895 for (i
= 0; i
< n
; i
++, p
+= 4) {
897 PACK_RGBA(p
, color
[RCOMP
], color
[GCOMP
], color
[BCOMP
], color
[ACOMP
]);
905 write_rgba_pixels( const GLcontext
*ctx
, GLuint n
,
906 const GLint x
[], const GLint y
[],
907 CONST GLchan rgba
[][4], const GLubyte mask
[] )
909 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
911 for (i
= 0; i
< n
; i
++) {
913 GLchan
*p
= PIXELADDR4(x
[i
], y
[i
]);
914 PACK_RGBA(p
, rgba
[i
][RCOMP
], rgba
[i
][GCOMP
],
915 rgba
[i
][BCOMP
], rgba
[i
][ACOMP
]);
923 write_monocolor_pixels( const GLcontext
*ctx
, GLuint n
,
924 const GLint x
[], const GLint y
[],
925 const GLchan color
[4], const GLubyte mask
[] )
927 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
929 for (i
= 0; i
< n
; i
++) {
931 GLchan
*p
= PIXELADDR4(x
[i
], y
[i
]);
932 PACK_RGBA(p
, color
[RCOMP
], color
[GCOMP
], color
[BCOMP
], color
[ACOMP
]);
939 read_rgba_span( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
942 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
944 GLchan
*p
= PIXELADDR4(x
, y
);
945 for (i
= 0; i
< n
; i
++, p
+= 4) {
946 rgba
[i
][RCOMP
] = UNPACK_RED(p
);
947 rgba
[i
][GCOMP
] = UNPACK_GREEN(p
);
948 rgba
[i
][BCOMP
] = UNPACK_BLUE(p
);
949 rgba
[i
][ACOMP
] = UNPACK_ALPHA(p
);
954 /* Read RGBA pixels from an RGBA buffer */
956 read_rgba_span_rgba( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
959 OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
960 GLuint
*ptr4
= (GLuint
*) PIXELADDR4(x
, y
);
961 MEMCPY( rgba
, ptr4
, n
* 4 * sizeof(GLchan
) );
966 read_rgba_pixels( const GLcontext
*ctx
,
967 GLuint n
, const GLint x
[], const GLint y
[],
968 GLchan rgba
[][4], const GLubyte mask
[] )
970 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
972 for (i
= 0; i
< n
; i
++) {
974 const GLchan
*p
= PIXELADDR4(x
[i
], y
[i
]);
975 rgba
[i
][RCOMP
] = UNPACK_RED(p
);
976 rgba
[i
][GCOMP
] = UNPACK_GREEN(p
);
977 rgba
[i
][BCOMP
] = UNPACK_BLUE(p
);
978 rgba
[i
][ACOMP
] = UNPACK_ALPHA(p
);
983 /**********************************************************************/
984 /***** 3 byte RGB pixel support funcs *****/
985 /**********************************************************************/
987 /* Write RGBA pixels to an RGB buffer. */
989 write_rgba_span_RGB( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
990 CONST GLchan rgba
[][4], const GLubyte mask
[] )
992 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
993 GLchan
*p
= PIXELADDR3(x
, y
);
996 for (i
= 0; i
< n
; i
++, p
+= 3) {
998 PACK_RGB(p
, rgba
[i
][RCOMP
], rgba
[i
][GCOMP
], rgba
[i
][BCOMP
]);
1003 for (i
= 0; i
< n
; i
++, p
+= 3) {
1004 PACK_RGB(p
, rgba
[i
][RCOMP
], rgba
[i
][GCOMP
], rgba
[i
][BCOMP
]);
1009 /* Write RGBA pixels to an BGR buffer. */
1011 write_rgba_span_BGR( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
1012 CONST GLchan rgba
[][4], const GLubyte mask
[] )
1014 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1015 GLchan
*p
= PIXELADDR3(x
, y
);
1018 for (i
= 0; i
< n
; i
++, p
+= 3) {
1020 PACK_BGR(p
, rgba
[i
][RCOMP
], rgba
[i
][GCOMP
], rgba
[i
][BCOMP
]);
1025 for (i
= 0; i
< n
; i
++, p
+= 3) {
1026 PACK_BGR(p
, rgba
[i
][RCOMP
], rgba
[i
][GCOMP
], rgba
[i
][BCOMP
]);
1031 /* Write RGB pixels to an RGB buffer. */
1033 write_rgb_span_RGB( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
1034 CONST GLchan rgb
[][3], const GLubyte mask
[] )
1036 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1037 GLchan
*p
= PIXELADDR3(x
, y
);
1040 for (i
= 0; i
< n
; i
++, p
+= 3) {
1042 PACK_RGB(p
, rgb
[i
][RCOMP
], rgb
[i
][GCOMP
], rgb
[i
][BCOMP
]);
1047 for (i
= 0; i
< n
; i
++, p
+= 3) {
1048 PACK_RGB(p
, rgb
[i
][RCOMP
], rgb
[i
][GCOMP
], rgb
[i
][BCOMP
]);
1053 /* Write RGB pixels to an BGR buffer. */
1055 write_rgb_span_BGR( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
1056 CONST GLchan rgb
[][3], const GLubyte mask
[] )
1058 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1059 GLchan
*p
= PIXELADDR3(x
, y
);
1062 for (i
= 0; i
< n
; i
++, p
+= 3) {
1064 PACK_BGR(p
, rgb
[i
][RCOMP
], rgb
[i
][GCOMP
], rgb
[i
][BCOMP
]);
1069 for (i
= 0; i
< n
; i
++, p
+= 3) {
1070 PACK_BGR(p
, rgb
[i
][RCOMP
], rgb
[i
][GCOMP
], rgb
[i
][BCOMP
]);
1077 write_monocolor_span_RGB( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
1078 const GLchan color
[4], const GLubyte mask
[] )
1080 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1081 GLchan
*p
= PIXELADDR3(x
, y
);
1083 for (i
= 0; i
< n
; i
++, p
+= 3) {
1085 PACK_RGB(p
, color
[RCOMP
], color
[GCOMP
], color
[BCOMP
]);
1091 write_monocolor_span_BGR( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
1092 const GLchan color
[4], const GLubyte mask
[] )
1094 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1095 GLchan
*p
= PIXELADDR3(x
, y
);
1097 for (i
= 0; i
< n
; i
++, p
+= 3) {
1099 PACK_BGR(p
, color
[RCOMP
], color
[GCOMP
], color
[BCOMP
]);
1105 write_rgba_pixels_RGB( const GLcontext
*ctx
, GLuint n
,
1106 const GLint x
[], const GLint y
[],
1107 CONST GLchan rgba
[][4], const GLubyte mask
[] )
1109 const OSMesaContext osmesa
= (const OSMesaContext
) ctx
;
1111 for (i
= 0; i
< n
; i
++) {
1113 GLchan
*p
= PIXELADDR3(x
[i
], y
[i
]);
1114 PACK_RGB(p
, rgba
[i
][RCOMP
], rgba
[i
][GCOMP
], rgba
[i
][BCOMP
]);
1120 write_rgba_pixels_BGR( const GLcontext
*ctx
, GLuint n
,
1121 const GLint x
[], const GLint y
[],
1122 CONST GLchan rgba
[][4], const GLubyte mask
[] )
1124 const OSMesaContext osmesa
= (const OSMesaContext
) ctx
;
1126 for (i
= 0; i
< n
; i
++) {
1128 GLchan
*p
= PIXELADDR3(x
[i
], y
[i
]);
1129 PACK_BGR(p
, rgba
[i
][RCOMP
], rgba
[i
][GCOMP
], rgba
[i
][BCOMP
]);
1135 write_monocolor_pixels_RGB( const GLcontext
*ctx
,
1136 GLuint n
, const GLint x
[], const GLint y
[],
1137 const GLchan color
[4], const GLubyte mask
[] )
1139 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1141 for (i
= 0; i
< n
; i
++) {
1143 GLchan
*p
= PIXELADDR3(x
[i
], y
[i
]);
1144 PACK_RGB(p
, color
[RCOMP
], color
[GCOMP
], color
[BCOMP
]);
1150 write_monocolor_pixels_BGR( const GLcontext
*ctx
,
1151 GLuint n
, const GLint x
[], const GLint y
[],
1152 const GLchan color
[4], const GLubyte mask
[] )
1154 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1156 for (i
= 0; i
< n
; i
++) {
1158 GLchan
*p
= PIXELADDR3(x
[i
], y
[i
]);
1159 PACK_BGR(p
, color
[RCOMP
], color
[GCOMP
], color
[BCOMP
]);
1165 read_rgba_span3( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
1168 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1170 const GLchan
*p
= PIXELADDR3(x
, y
);
1171 for (i
= 0; i
< n
; i
++, p
+= 3) {
1172 rgba
[i
][RCOMP
] = UNPACK_RED(p
);
1173 rgba
[i
][GCOMP
] = UNPACK_GREEN(p
);
1174 rgba
[i
][BCOMP
] = UNPACK_BLUE(p
);
1175 rgba
[i
][ACOMP
] = 255;
1180 read_rgba_pixels3( const GLcontext
*ctx
,
1181 GLuint n
, const GLint x
[], const GLint y
[],
1182 GLchan rgba
[][4], const GLubyte mask
[] )
1184 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1186 for (i
= 0; i
< n
; i
++) {
1188 const GLchan
*p
= PIXELADDR3(x
[i
], y
[i
]);
1189 rgba
[i
][RCOMP
] = UNPACK_RED(p
);
1190 rgba
[i
][GCOMP
] = UNPACK_GREEN(p
);
1191 rgba
[i
][BCOMP
] = UNPACK_BLUE(p
);
1192 rgba
[i
][ACOMP
] = 255;
1198 /**********************************************************************/
1199 /***** Read/write spans/arrays of CI pixels *****/
1200 /**********************************************************************/
1202 /* Write 32-bit color index to buffer */
1204 write_index32_span( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
1205 const GLuint index
[], const GLubyte mask
[] )
1207 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1208 GLchan
*ptr1
= PIXELADDR1(x
, y
);
1211 for (i
=0;i
<n
;i
++,ptr1
++) {
1213 *ptr1
= (GLchan
) index
[i
];
1218 for (i
=0;i
<n
;i
++,ptr1
++) {
1219 *ptr1
= (GLchan
) index
[i
];
1225 /* Write 8-bit color index to buffer */
1227 write_index8_span( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
1228 const GLubyte index
[], const GLubyte mask
[] )
1230 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1231 GLchan
*ptr1
= PIXELADDR1(x
, y
);
1234 for (i
=0;i
<n
;i
++,ptr1
++) {
1236 *ptr1
= (GLchan
) index
[i
];
1241 MEMCPY(ptr1
, index
, n
* sizeof(GLchan
));
1247 write_monoindex_span( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
1248 GLuint colorIndex
, const GLubyte mask
[] )
1250 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1251 GLchan
*ptr1
= PIXELADDR1(x
, y
);
1253 for (i
=0;i
<n
;i
++,ptr1
++) {
1255 *ptr1
= (GLchan
) colorIndex
;
1262 write_index_pixels( const GLcontext
*ctx
,
1263 GLuint n
, const GLint x
[], const GLint y
[],
1264 const GLuint index
[], const GLubyte mask
[] )
1266 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1270 GLchan
*ptr1
= PIXELADDR1(x
[i
], y
[i
]);
1271 *ptr1
= (GLchan
) index
[i
];
1278 write_monoindex_pixels( const GLcontext
*ctx
,
1279 GLuint n
, const GLint x
[], const GLint y
[],
1280 GLuint colorIndex
, const GLubyte mask
[] )
1282 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1286 GLchan
*ptr1
= PIXELADDR1(x
[i
], y
[i
]);
1287 *ptr1
= (GLchan
) colorIndex
;
1294 read_index_span( const GLcontext
*ctx
,
1295 GLuint n
, GLint x
, GLint y
, GLuint index
[] )
1297 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1299 const GLchan
*ptr1
= (const GLchan
*) PIXELADDR1(x
, y
);
1300 for (i
=0;i
<n
;i
++,ptr1
++) {
1301 index
[i
] = (GLuint
) *ptr1
;
1307 read_index_pixels( const GLcontext
*ctx
,
1308 GLuint n
, const GLint x
[], const GLint y
[],
1309 GLuint index
[], const GLubyte mask
[] )
1311 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1315 const GLchan
*ptr1
= PIXELADDR1(x
[i
], y
[i
]);
1316 index
[i
] = (GLuint
) *ptr1
;
1323 /**********************************************************************/
1324 /***** Optimized line rendering *****/
1325 /**********************************************************************/
1329 * Draw a flat-shaded, RGB line into an osmesa buffer.
1332 flat_rgba_line( GLcontext
*ctx
, const SWvertex
*vert0
, const SWvertex
*vert1
)
1334 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1335 const GLchan
*color
= vert0
->color
;
1339 #define PLOT(X, Y) \
1341 GLchan *p = PIXELADDR4(X, Y); \
1342 PACK_RGBA(p, color[0], color[1], color[2], color[3]); \
1346 #include "..\swrast\s_linetemp.h"
1348 #include "swrast/s_linetemp.h"
1354 * Draw a flat-shaded, Z-less, RGB line into an osmesa buffer.
1357 flat_rgba_z_line(GLcontext
*ctx
, const SWvertex
*vert0
, const SWvertex
*vert1
)
1359 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1360 const GLchan
*color
= vert0
->color
;
1364 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
1366 #define PLOT(X, Y) \
1369 GLchan *p = PIXELADDR4(X, Y); \
1370 PACK_RGBA(p, color[RCOMP], color[GCOMP], \
1371 color[BCOMP], color[ACOMP]); \
1378 #include "..\swrast\s_linetemp.h"
1380 #include "swrast/s_linetemp.h"
1386 * Draw a flat-shaded, alpha-blended, RGB line into an osmesa buffer.
1387 * XXX update for GLchan
1390 flat_blend_rgba_line( GLcontext
*ctx
,
1391 const SWvertex
*vert0
, const SWvertex
*vert1
)
1393 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1394 const GLint rshift
= osmesa
->rshift
;
1395 const GLint gshift
= osmesa
->gshift
;
1396 const GLint bshift
= osmesa
->bshift
;
1397 const GLint avalue
= vert0
->color
[3];
1398 const GLint msavalue
= 255 - avalue
;
1399 const GLint rvalue
= vert0
->color
[0]*avalue
;
1400 const GLint gvalue
= vert0
->color
[1]*avalue
;
1401 const GLint bvalue
= vert0
->color
[2]*avalue
;
1406 { GLuint *ptr4 = (GLuint *) PIXELADDR4(X, Y); \
1408 pixel |=((((((*ptr4) >> rshift) & 0xff)*msavalue+rvalue)>>8) << rshift);\
1409 pixel |=((((((*ptr4) >> gshift) & 0xff)*msavalue+gvalue)>>8) << gshift);\
1410 pixel |=((((((*ptr4) >> bshift) & 0xff)*msavalue+bvalue)>>8) << bshift);\
1415 #include "..\swrast\s_linetemp.h"
1417 #include "swrast/s_linetemp.h"
1423 * Draw a flat-shaded, Z-less, alpha-blended, RGB line into an osmesa buffer.
1424 * XXX update for GLchan
1427 flat_blend_rgba_z_line( GLcontext
*ctx
,
1428 const SWvertex
*vert0
, const SWvertex
*vert1
)
1430 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1431 const GLint rshift
= osmesa
->rshift
;
1432 const GLint gshift
= osmesa
->gshift
;
1433 const GLint bshift
= osmesa
->bshift
;
1434 const GLint avalue
= vert0
->color
[3];
1435 const GLint msavalue
= 256 - avalue
;
1436 const GLint rvalue
= vert0
->color
[0]*avalue
;
1437 const GLint gvalue
= vert0
->color
[1]*avalue
;
1438 const GLint bvalue
= vert0
->color
[2]*avalue
;
1442 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
1446 GLuint *ptr4 = (GLuint *) PIXELADDR4(X, Y); \
1448 pixel |=((((((*ptr4) >> rshift) & 0xff)*msavalue+rvalue)>>8) << rshift); \
1449 pixel |=((((((*ptr4) >> gshift) & 0xff)*msavalue+gvalue)>>8) << gshift); \
1450 pixel |=((((((*ptr4) >> bshift) & 0xff)*msavalue+bvalue)>>8) << bshift); \
1455 #include "..\swrast\s_linetemp.h"
1457 #include "swrast/s_linetemp.h"
1463 * Draw a flat-shaded, Z-less, alpha-blended, RGB line into an osmesa buffer.
1464 * XXX update for GLchan
1467 flat_blend_rgba_z_line_write( GLcontext
*ctx
,
1468 const SWvertex
*vert0
, const SWvertex
*vert1
)
1470 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1471 const GLint rshift
= osmesa
->rshift
;
1472 const GLint gshift
= osmesa
->gshift
;
1473 const GLint bshift
= osmesa
->bshift
;
1474 const GLint avalue
= vert0
->color
[3];
1475 const GLint msavalue
= 256 - avalue
;
1476 const GLint rvalue
= vert0
->color
[0]*avalue
;
1477 const GLint gvalue
= vert0
->color
[1]*avalue
;
1478 const GLint bvalue
= vert0
->color
[2]*avalue
;
1482 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
1486 GLuint *ptr4 = (GLuint *) PIXELADDR4(X, Y); \
1488 pixel |=((((((*ptr4) >> rshift) & 0xff)*msavalue+rvalue)>>8) << rshift); \
1489 pixel |=((((((*ptr4) >> gshift) & 0xff)*msavalue+gvalue)>>8) << gshift); \
1490 pixel |=((((((*ptr4) >> bshift) & 0xff)*msavalue+bvalue)>>8) << bshift); \
1496 #include "..\swrast\s_linetemp.h"
1498 #include "swrast/s_linetemp.h"
1504 * Analyze context state to see if we can provide a fast line drawing
1505 * function, like those in lines.c. Otherwise, return NULL.
1507 static swrast_line_func
1508 osmesa_choose_line_function( GLcontext
*ctx
)
1510 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1511 const SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
1513 if (CHAN_BITS
!= 8) return NULL
;
1514 if (ctx
->RenderMode
!= GL_RENDER
) return NULL
;
1515 if (ctx
->Line
.SmoothFlag
) return NULL
;
1516 if (ctx
->Texture
._ReallyEnabled
) return NULL
;
1517 if (ctx
->Light
.ShadeModel
!= GL_FLAT
) return NULL
;
1518 if (ctx
->Line
.Width
!= 1.0F
) return NULL
;
1519 if (ctx
->Line
.StippleFlag
) return NULL
;
1520 if (ctx
->Line
.SmoothFlag
) return NULL
;
1521 if (osmesa
->format
!= OSMESA_RGBA
&&
1522 osmesa
->format
!= OSMESA_BGRA
&&
1523 osmesa
->format
!= OSMESA_ARGB
) return NULL
;
1525 if (swrast
->_RasterMask
==DEPTH_BIT
1526 && ctx
->Depth
.Func
==GL_LESS
1527 && ctx
->Depth
.Mask
==GL_TRUE
1528 && ctx
->Visual
.depthBits
== DEFAULT_SOFTWARE_DEPTH_BITS
) {
1529 return flat_rgba_z_line
;
1532 if (swrast
->_RasterMask
== 0) {
1533 return flat_rgba_line
;
1536 if (swrast
->_RasterMask
==(DEPTH_BIT
|BLEND_BIT
)
1537 && ctx
->Depth
.Func
==GL_LESS
1538 && ctx
->Depth
.Mask
==GL_TRUE
1539 && ctx
->Visual
.depthBits
== DEFAULT_SOFTWARE_DEPTH_BITS
1540 && ctx
->Color
.BlendSrcRGB
==GL_SRC_ALPHA
1541 && ctx
->Color
.BlendDstRGB
==GL_ONE_MINUS_SRC_ALPHA
1542 && ctx
->Color
.BlendSrcA
==GL_SRC_ALPHA
1543 && ctx
->Color
.BlendDstA
==GL_ONE_MINUS_SRC_ALPHA
1544 && ctx
->Color
.BlendEquation
==GL_FUNC_ADD_EXT
) {
1545 return flat_blend_rgba_z_line_write
;
1548 if (swrast
->_RasterMask
==(DEPTH_BIT
|BLEND_BIT
)
1549 && ctx
->Depth
.Func
==GL_LESS
1550 && ctx
->Depth
.Mask
==GL_FALSE
1551 && ctx
->Visual
.depthBits
== DEFAULT_SOFTWARE_DEPTH_BITS
1552 && ctx
->Color
.BlendSrcRGB
==GL_SRC_ALPHA
1553 && ctx
->Color
.BlendDstRGB
==GL_ONE_MINUS_SRC_ALPHA
1554 && ctx
->Color
.BlendSrcA
==GL_SRC_ALPHA
1555 && ctx
->Color
.BlendDstA
==GL_ONE_MINUS_SRC_ALPHA
1556 && ctx
->Color
.BlendEquation
==GL_FUNC_ADD_EXT
) {
1557 return flat_blend_rgba_z_line
;
1560 if (swrast
->_RasterMask
==BLEND_BIT
1561 && ctx
->Color
.BlendSrcRGB
==GL_SRC_ALPHA
1562 && ctx
->Color
.BlendDstRGB
==GL_ONE_MINUS_SRC_ALPHA
1563 && ctx
->Color
.BlendSrcA
==GL_SRC_ALPHA
1564 && ctx
->Color
.BlendDstA
==GL_ONE_MINUS_SRC_ALPHA
1565 && ctx
->Color
.BlendEquation
==GL_FUNC_ADD_EXT
) {
1566 return flat_blend_rgba_line
;
1573 /**********************************************************************/
1574 /***** Optimized triangle rendering *****/
1575 /**********************************************************************/
1579 * Smooth-shaded, z-less triangle, RGBA color.
1581 static void smooth_rgba_z_triangle( GLcontext
*ctx
,
1584 const SWvertex
*v2
)
1586 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1589 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
1590 #define INTERP_RGB 1
1591 #define INTERP_ALPHA 1
1592 #define INNER_LOOP( LEFT, RIGHT, Y ) \
1594 GLint i, len = RIGHT-LEFT; \
1595 GLchan *img = PIXELADDR4(LEFT, Y); \
1597 for (i = 0; i < len; i++, img += 4) { \
1598 GLdepth z = FixedToDepth(ffz); \
1599 if (z < zRow[i]) { \
1600 PACK_RGBA(img, FixedToInt(ffr), FixedToInt(ffg), \
1601 FixedToInt(ffb), FixedToInt(ffa)); \
1604 ffr += fdrdx; ffg += fdgdx; ffb += fdbdx; ffa += fdadx;\
1609 #include "..\swrast\s_tritemp.h"
1611 #include "swrast/s_tritemp.h"
1619 * Flat-shaded, z-less triangle, RGBA color.
1621 static void flat_rgba_z_triangle( GLcontext
*ctx
,
1624 const SWvertex
*v2
)
1626 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1628 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
1629 #define SETUP_CODE \
1631 PACK_RGBA((GLchan *) &pixel, v0->color[0], v0->color[1], \
1632 v0->color[2], v0->color[3]);
1634 #define INNER_LOOP( LEFT, RIGHT, Y ) \
1636 GLint i, len = RIGHT-LEFT; \
1637 GLuint *img = (GLuint *) PIXELADDR4(LEFT, Y); \
1639 for (i=0;i<len;i++) { \
1640 GLdepth z = FixedToDepth(ffz); \
1641 if (z < zRow[i]) { \
1649 #include "..\swrast\s_tritemp.h"
1651 #include "swrast/s_tritemp.h"
1658 * Return pointer to an accelerated triangle function if possible.
1660 static swrast_tri_func
1661 osmesa_choose_triangle_function( GLcontext
*ctx
)
1663 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1664 const SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
1666 if (CHAN_BITS
!= 8) return (swrast_tri_func
) NULL
;
1667 if (ctx
->RenderMode
!= GL_RENDER
) return (swrast_tri_func
) NULL
;
1668 if (ctx
->Polygon
.SmoothFlag
) return (swrast_tri_func
) NULL
;
1669 if (ctx
->Polygon
.StippleFlag
) return (swrast_tri_func
) NULL
;
1670 if (ctx
->Texture
._ReallyEnabled
) return (swrast_tri_func
) NULL
;
1671 if (osmesa
->format
!= OSMESA_RGBA
&&
1672 osmesa
->format
!= OSMESA_BGRA
&&
1673 osmesa
->format
!= OSMESA_ARGB
) return (swrast_tri_func
) NULL
;
1675 if (swrast
->_RasterMask
== DEPTH_BIT
&&
1676 ctx
->Depth
.Func
== GL_LESS
&&
1677 ctx
->Depth
.Mask
== GL_TRUE
&&
1678 ctx
->Visual
.depthBits
== DEFAULT_SOFTWARE_DEPTH_BITS
) {
1679 if (ctx
->Light
.ShadeModel
== GL_SMOOTH
) {
1680 return smooth_rgba_z_triangle
;
1683 return flat_rgba_z_triangle
;
1686 return (swrast_tri_func
) NULL
;
1691 /* Override for the swrast triangle-selection function. Try to use one
1692 * of our internal triangle functions, otherwise fall back to the
1693 * standard swrast functions.
1695 static void osmesa_choose_triangle( GLcontext
*ctx
)
1697 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
1699 swrast
->Triangle
= osmesa_choose_triangle_function( ctx
);
1700 if (!swrast
->Triangle
)
1701 _swrast_choose_triangle( ctx
);
1704 static void osmesa_choose_line( GLcontext
*ctx
)
1706 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
1708 swrast
->Line
= osmesa_choose_line_function( ctx
);
1710 _swrast_choose_line( ctx
);
1714 #define OSMESA_NEW_LINE (_NEW_LINE | \
1719 _SWRAST_NEW_RASTERMASK)
1721 #define OSMESA_NEW_TRIANGLE (_NEW_POLYGON | \
1726 _SWRAST_NEW_RASTERMASK)
1729 /* Extend the software rasterizer with our line and triangle
1732 static void osmesa_register_swrast_functions( GLcontext
*ctx
)
1734 SWcontext
*swrast
= SWRAST_CONTEXT( ctx
);
1736 swrast
->choose_line
= osmesa_choose_line
;
1737 swrast
->choose_triangle
= osmesa_choose_triangle
;
1739 swrast
->invalidate_line
|= OSMESA_NEW_LINE
;
1740 swrast
->invalidate_triangle
|= OSMESA_NEW_TRIANGLE
;
1744 static const GLubyte
*get_string( GLcontext
*ctx
, GLenum name
)
1749 return (const GLubyte
*) "Mesa OffScreen";
1756 static void osmesa_update_state( GLcontext
*ctx
, GLuint new_state
)
1758 OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1760 ASSERT((void *) osmesa
== (void *) ctx
->DriverCtx
);
1763 * XXX these function pointers could be initialized just once during
1764 * context creation since they don't depend on any state changes.
1767 ctx
->Driver
.GetString
= get_string
;
1768 ctx
->Driver
.UpdateState
= osmesa_update_state
;
1770 ctx
->Driver
.SetDrawBuffer
= set_draw_buffer
;
1771 ctx
->Driver
.SetReadBuffer
= set_read_buffer
;
1773 ctx
->Driver
.Accum
= _swrast_Accum
;
1774 ctx
->Driver
.Bitmap
= _swrast_Bitmap
;
1775 ctx
->Driver
.Clear
= clear
;
1776 ctx
->Driver
.CopyPixels
= _swrast_CopyPixels
;
1777 ctx
->Driver
.DrawPixels
= _swrast_DrawPixels
;
1778 ctx
->Driver
.ReadPixels
= _swrast_ReadPixels
;
1779 ctx
->Driver
.ResizeBuffersMESA
= _swrast_alloc_buffers
;
1781 ctx
->Driver
.GetBufferSize
= buffer_size
;
1783 ctx
->Driver
.TexImage1D
= _mesa_store_teximage1d
;
1784 ctx
->Driver
.TexImage2D
= _mesa_store_teximage2d
;
1785 ctx
->Driver
.TexImage3D
= _mesa_store_teximage3d
;
1786 ctx
->Driver
.TexSubImage1D
= _mesa_store_texsubimage1d
;
1787 ctx
->Driver
.TexSubImage2D
= _mesa_store_texsubimage2d
;
1788 ctx
->Driver
.TexSubImage3D
= _mesa_store_texsubimage3d
;
1789 ctx
->Driver
.TestProxyTexImage
= _mesa_test_proxy_teximage
;
1791 ctx
->Driver
.PointsFunc
= _swsetup_Points
;
1792 ctx
->Driver
.LineFunc
= _swsetup_Line
;
1793 ctx
->Driver
.TriangleFunc
= _swsetup_Triangle
;
1794 ctx
->Driver
.QuadFunc
= _swsetup_Quad
;
1795 ctx
->Driver
.BuildProjectedVertices
= _swsetup_BuildProjectedVertices
;
1796 ctx
->Driver
.RenderPrimitive
= _swsetup_RenderPrimitive
;
1797 ctx
->Driver
.RenderStart
= _swsetup_RenderStart
;
1798 ctx
->Driver
.RenderFinish
= _swsetup_RenderFinish
;
1799 ctx
->Driver
.RenderInterp
= _swsetup_RenderInterp
;
1800 ctx
->Driver
.RenderCopyPV
= _swsetup_RenderCopyPV
;
1801 ctx
->Driver
.RenderClippedLine
= _swsetup_RenderClippedLine
;
1802 ctx
->Driver
.RenderClippedPolygon
= _swsetup_RenderClippedPolygon
;
1804 /* RGB(A) span/pixel functions */
1805 if (osmesa
->format
== OSMESA_RGB
) {
1806 ctx
->Driver
.WriteRGBASpan
= write_rgba_span_RGB
;
1807 ctx
->Driver
.WriteRGBSpan
= write_rgb_span_RGB
;
1808 ctx
->Driver
.WriteMonoRGBASpan
= write_monocolor_span_RGB
;
1809 ctx
->Driver
.WriteRGBAPixels
= write_rgba_pixels_RGB
;
1810 ctx
->Driver
.WriteMonoRGBAPixels
= write_monocolor_pixels_RGB
;
1811 ctx
->Driver
.ReadRGBASpan
= read_rgba_span3
;
1812 ctx
->Driver
.ReadRGBAPixels
= read_rgba_pixels3
;
1814 else if (osmesa
->format
== OSMESA_BGR
) {
1815 ctx
->Driver
.WriteRGBASpan
= write_rgba_span_BGR
;
1816 ctx
->Driver
.WriteRGBSpan
= write_rgb_span_BGR
;
1817 ctx
->Driver
.WriteMonoRGBASpan
= write_monocolor_span_BGR
;
1818 ctx
->Driver
.WriteRGBAPixels
= write_rgba_pixels_BGR
;
1819 ctx
->Driver
.WriteMonoRGBAPixels
= write_monocolor_pixels_BGR
;
1820 ctx
->Driver
.ReadRGBASpan
= read_rgba_span3
;
1821 ctx
->Driver
.ReadRGBAPixels
= read_rgba_pixels3
;
1824 /* 4 bytes / pixel in frame buffer */
1825 ctx
->Driver
.WriteRGBSpan
= write_rgb_span
;
1826 ctx
->Driver
.WriteRGBAPixels
= write_rgba_pixels
;
1827 ctx
->Driver
.WriteMonoRGBASpan
= write_monocolor_span
;
1828 ctx
->Driver
.WriteMonoRGBAPixels
= write_monocolor_pixels
;
1829 if (osmesa
->format
== OSMESA_RGBA
&&
1830 CHAN_TYPE
== GL_UNSIGNED_BYTE
&&
1831 RCOMP
==0 && GCOMP
==1 && BCOMP
==2 && ACOMP
==3) {
1832 /* special, fast case */
1833 ctx
->Driver
.WriteRGBASpan
= write_rgba_span_rgba
;
1834 ctx
->Driver
.ReadRGBASpan
= read_rgba_span_rgba
;
1837 ctx
->Driver
.WriteRGBASpan
= write_rgba_span
;
1838 ctx
->Driver
.ReadRGBASpan
= read_rgba_span
;
1840 ctx
->Driver
.ReadRGBAPixels
= read_rgba_pixels
;
1843 /* CI span/pixel functions */
1844 ctx
->Driver
.WriteCI32Span
= write_index32_span
;
1845 ctx
->Driver
.WriteCI8Span
= write_index8_span
;
1846 ctx
->Driver
.WriteMonoCISpan
= write_monoindex_span
;
1847 ctx
->Driver
.WriteCI32Pixels
= write_index_pixels
;
1848 ctx
->Driver
.WriteMonoCIPixels
= write_monoindex_pixels
;
1849 ctx
->Driver
.ReadCI32Span
= read_index_span
;
1850 ctx
->Driver
.ReadCI32Pixels
= read_index_pixels
;
1852 _swrast_InvalidateState( ctx
, new_state
);
1853 _swsetup_InvalidateState( ctx
, new_state
);
1854 _ac_InvalidateState( ctx
, new_state
);
1855 _tnl_InvalidateState( ctx
, new_state
);