1 /* $Id: osmesa.c,v 1.45 2001/02/08 23:52:29 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 if (c
->gl_visual
->depthBits
<= 16)
546 *bytesPerValue
= sizeof(GLushort
);
548 *bytesPerValue
= sizeof(GLuint
);
549 *buffer
= c
->gl_buffer
->DepthBuffer
;
555 * Return the color buffer associated with an OSMesa context.
556 * Input: c - the OSMesa context
557 * Output: width, height - size of buffer in pixels
558 * format - the pixel format (OSMESA_FORMAT)
559 * buffer - pointer to color buffer values
560 * Return: GL_TRUE or GL_FALSE to indicate success or failure.
563 OSMesaGetColorBuffer( OSMesaContext c
, GLint
*width
,
564 GLint
*height
, GLint
*format
, void **buffer
)
582 /**********************************************************************/
583 /*** Device Driver Functions ***/
584 /**********************************************************************/
591 #define PACK_RGBA(DST, R, G, B, A) \
593 (DST)[osmesa->rInd] = R; \
594 (DST)[osmesa->gInd] = G; \
595 (DST)[osmesa->bInd] = B; \
596 (DST)[osmesa->aInd] = A; \
599 #define PACK_RGB(DST, R, G, B) \
606 #define PACK_BGR(DST, R, G, B) \
614 #define UNPACK_RED(P) ( ((GLchan *) &(P))[osmesa->rInd] )
615 #define UNPACK_GREEN(P) ( ((GLchan *) &(P))[osmesa->gInd] )
616 #define UNPACK_BLUE(P) ( ((GLchan *) &(P))[osmesa->bInd] )
617 #define UNPACK_ALPHA(P) ( ((GLchan *) &(P))[osmesa->aInd] )
620 #define PIXELADDR1(X,Y) (osmesa->rowaddr[Y] + (X))
621 #define PIXELADDR3(X,Y) (osmesa->rowaddr[Y] + 3 * (X))
622 #define PIXELADDR4(X,Y) (osmesa->rowaddr[Y] + 4 * (X))
626 static GLboolean
set_draw_buffer( GLcontext
*ctx
, GLenum mode
)
629 if (mode
==GL_FRONT_LEFT
) {
638 static void set_read_buffer( GLcontext
*ctx
, GLframebuffer
*buffer
, GLenum mode
)
640 /* separate read buffer not supported */
641 ASSERT(buffer
== ctx
->DrawBuffer
);
642 ASSERT(mode
== GL_FRONT_LEFT
);
646 static void clear( GLcontext
*ctx
, GLbitfield mask
, GLboolean all
,
647 GLint x
, GLint y
, GLint width
, GLint height
)
649 OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
650 const GLuint
*colorMask
= (GLuint
*) &ctx
->Color
.ColorMask
;
652 /* sanity check - we only have a front-left buffer */
653 ASSERT((mask
& (DD_FRONT_RIGHT_BIT
| DD_BACK_LEFT_BIT
| DD_BACK_RIGHT_BIT
)) == 0);
654 if (*colorMask
== 0xffffffff && ctx
->Color
.IndexMask
== 0xffffffff) {
655 if (mask
& DD_FRONT_LEFT_BIT
) {
656 if (osmesa
->format
== OSMESA_COLOR_INDEX
) {
658 /* Clear whole CI buffer */
659 #if CHAN_TYPE == GL_UNSIGNED_BYTE
660 MEMSET(osmesa
->buffer
, ctx
->Color
.ClearIndex
,
661 osmesa
->rowlength
* osmesa
->height
);
663 const GLint n
= osmesa
->rowlength
* osmesa
->height
;
664 GLchan
*buffer
= (GLchan
*) osmesa
->buffer
;
666 for (i
= 0; i
< n
; i
++) {
667 buffer
[i
] = ctx
->Color
.ClearIndex
;
672 /* Clear part of CI buffer */
673 const GLchan clearIndex
= (GLchan
) ctx
->Color
.ClearIndex
;
675 for (i
= 0; i
< height
; i
++) {
676 GLchan
*ptr1
= PIXELADDR1(x
, (y
+ i
));
677 for (j
= 0; j
< width
; j
++) {
678 *ptr1
++ = clearIndex
;
683 else if (osmesa
->format
== OSMESA_RGB
) {
684 const GLchan r
= ctx
->Color
.ClearColor
[0];
685 const GLchan g
= ctx
->Color
.ClearColor
[1];
686 const GLchan b
= ctx
->Color
.ClearColor
[2];
688 /* Clear whole RGB buffer */
689 GLuint n
= osmesa
->rowlength
* osmesa
->height
;
690 GLchan
*ptr3
= (GLchan
*) osmesa
->buffer
;
692 for (i
= 0; i
< n
; i
++) {
693 PACK_RGB(ptr3
, r
, g
, b
);
698 /* Clear part of RGB buffer */
700 for (i
= 0; i
< height
; i
++) {
701 GLchan
*ptr3
= PIXELADDR3(x
, (y
+ i
));
702 for (j
= 0; j
< width
; j
++) {
703 PACK_RGB(ptr3
, r
, g
, b
);
709 else if (osmesa
->format
== OSMESA_BGR
) {
710 const GLchan r
= ctx
->Color
.ClearColor
[0];
711 const GLchan g
= ctx
->Color
.ClearColor
[1];
712 const GLchan b
= ctx
->Color
.ClearColor
[2];
714 /* Clear whole RGB buffer */
715 const GLint n
= osmesa
->rowlength
* osmesa
->height
;
716 GLchan
*ptr3
= (GLchan
*) osmesa
->buffer
;
718 for (i
= 0; i
< n
; i
++) {
719 PACK_BGR(ptr3
, r
, g
, b
);
724 /* Clear part of RGB buffer */
726 for (i
= 0; i
< height
; i
++) {
727 GLchan
*ptr3
= PIXELADDR3(x
, (y
+ i
));
728 for (j
= 0; j
< width
; j
++) {
729 PACK_BGR(ptr3
, r
, g
, b
);
736 #if CHAN_TYPE == GL_UNSIGNED_BYTE
737 /* 4-byte pixel value */
739 GLchan
*clr
= (GLchan
*) &clearPixel
;
740 clr
[osmesa
->rInd
] = ctx
->Color
.ClearColor
[0];
741 clr
[osmesa
->gInd
] = ctx
->Color
.ClearColor
[1];
742 clr
[osmesa
->bInd
] = ctx
->Color
.ClearColor
[2];
743 clr
[osmesa
->aInd
] = ctx
->Color
.ClearColor
[3];
745 /* Clear whole RGBA buffer */
746 const GLuint n
= osmesa
->rowlength
* osmesa
->height
;
747 GLuint
*ptr4
= (GLuint
*) osmesa
->buffer
;
750 for (i
= 0; i
< n
; i
++) {
751 *ptr4
++ = clearPixel
;
755 BZERO(ptr4
, n
* sizeof(GLuint
));
759 /* Clear part of RGBA buffer */
761 for (i
= 0; i
< height
; i
++) {
762 GLuint
*ptr4
= (GLuint
*) PIXELADDR4(x
, (y
+ i
));
763 for (j
= 0; j
< width
; j
++) {
764 *ptr4
++ = clearPixel
;
769 const GLchan r
= ctx
->Color
.ClearColor
[0];
770 const GLchan g
= ctx
->Color
.ClearColor
[1];
771 const GLchan b
= ctx
->Color
.ClearColor
[2];
772 const GLchan a
= ctx
->Color
.ClearColor
[3];
774 /* Clear whole RGBA buffer */
775 const GLuint n
= osmesa
->rowlength
* osmesa
->height
;
776 GLchan
*p
= (GLchan
*) osmesa
->buffer
;
778 for (i
= 0; i
< n
; i
++) {
779 PACK_RGBA(p
, r
, g
, b
, a
);
784 /* Clear part of RGBA buffer */
786 for (i
= 0; i
< height
; i
++) {
787 GLchan
*p
= PIXELADDR4(x
, (y
+ i
));
788 for (j
= 0; j
< width
; j
++) {
789 PACK_RGBA(p
, r
, g
, b
, a
);
797 mask
&= ~DD_FRONT_LEFT_BIT
;
802 _swrast_Clear( ctx
, mask
, all
, x
, y
, width
, height
);
807 static void buffer_size( GLcontext
*ctx
, GLuint
*width
, GLuint
*height
)
809 OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
810 *width
= osmesa
->width
;
811 *height
= osmesa
->height
;
815 /**********************************************************************/
816 /***** Read/write spans/arrays of RGBA pixels *****/
817 /**********************************************************************/
819 /* Write RGBA pixels to an RGBA (or permuted) buffer. */
821 write_rgba_span( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
822 CONST GLchan rgba
[][4], const GLubyte mask
[] )
824 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
825 GLchan
*p
= PIXELADDR4(x
, y
);
828 for (i
= 0; i
< n
; i
++, p
+= 4) {
830 PACK_RGBA(p
, rgba
[i
][RCOMP
], rgba
[i
][GCOMP
],
831 rgba
[i
][BCOMP
], rgba
[i
][ACOMP
]);
836 for (i
= 0; i
< n
; i
++, p
+= 4) {
837 PACK_RGBA(p
, rgba
[i
][RCOMP
], rgba
[i
][GCOMP
],
838 rgba
[i
][BCOMP
], rgba
[i
][ACOMP
]);
844 /* Write RGBA pixels to an RGBA buffer. This is the fastest span-writer. */
846 write_rgba_span_rgba( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
847 CONST GLchan rgba
[][4], const GLubyte mask
[] )
849 OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
850 GLuint
*ptr4
= (GLuint
*) PIXELADDR4(x
, y
);
851 const GLuint
*rgba4
= (const GLuint
*) rgba
;
853 ASSERT(CHAN_TYPE
== GL_UNSIGNED_BYTE
);
855 for (i
= 0; i
< n
; i
++) {
862 MEMCPY( ptr4
, rgba4
, n
* 4 );
867 /* Write RGB pixels to an RGBA (or permuted) buffer. */
869 write_rgb_span( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
870 CONST GLchan rgb
[][3], const GLubyte mask
[] )
872 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
873 GLchan
*p
= PIXELADDR4(x
, y
);
876 for (i
= 0; i
< n
; i
++, p
+=4) {
878 PACK_RGBA(p
, rgb
[i
][RCOMP
], rgb
[i
][GCOMP
], rgb
[i
][BCOMP
], 255);
883 for (i
= 0; i
< n
; i
++, p
+=4) {
884 PACK_RGBA(p
, rgb
[i
][RCOMP
], rgb
[i
][GCOMP
], rgb
[i
][BCOMP
], 255);
892 write_monocolor_span( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
893 const GLchan color
[4], const GLubyte mask
[] )
895 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
896 GLchan
*p
= PIXELADDR4(x
, y
);
898 for (i
= 0; i
< n
; i
++, p
+= 4) {
900 PACK_RGBA(p
, color
[RCOMP
], color
[GCOMP
], color
[BCOMP
], color
[ACOMP
]);
908 write_rgba_pixels( const GLcontext
*ctx
, GLuint n
,
909 const GLint x
[], const GLint y
[],
910 CONST GLchan rgba
[][4], const GLubyte mask
[] )
912 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
914 for (i
= 0; i
< n
; i
++) {
916 GLchan
*p
= PIXELADDR4(x
[i
], y
[i
]);
917 PACK_RGBA(p
, rgba
[i
][RCOMP
], rgba
[i
][GCOMP
],
918 rgba
[i
][BCOMP
], rgba
[i
][ACOMP
]);
926 write_monocolor_pixels( const GLcontext
*ctx
, GLuint n
,
927 const GLint x
[], const GLint y
[],
928 const GLchan color
[4], const GLubyte mask
[] )
930 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
932 for (i
= 0; i
< n
; i
++) {
934 GLchan
*p
= PIXELADDR4(x
[i
], y
[i
]);
935 PACK_RGBA(p
, color
[RCOMP
], color
[GCOMP
], color
[BCOMP
], color
[ACOMP
]);
942 read_rgba_span( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
945 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
947 GLchan
*p
= PIXELADDR4(x
, y
);
948 for (i
= 0; i
< n
; i
++, p
+= 4) {
949 rgba
[i
][RCOMP
] = UNPACK_RED(p
);
950 rgba
[i
][GCOMP
] = UNPACK_GREEN(p
);
951 rgba
[i
][BCOMP
] = UNPACK_BLUE(p
);
952 rgba
[i
][ACOMP
] = UNPACK_ALPHA(p
);
957 /* Read RGBA pixels from an RGBA buffer */
959 read_rgba_span_rgba( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
962 OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
963 GLuint
*ptr4
= (GLuint
*) PIXELADDR4(x
, y
);
964 MEMCPY( rgba
, ptr4
, n
* 4 * sizeof(GLchan
) );
969 read_rgba_pixels( const GLcontext
*ctx
,
970 GLuint n
, const GLint x
[], const GLint y
[],
971 GLchan rgba
[][4], const GLubyte mask
[] )
973 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
975 for (i
= 0; i
< n
; i
++) {
977 const GLchan
*p
= PIXELADDR4(x
[i
], y
[i
]);
978 rgba
[i
][RCOMP
] = UNPACK_RED(p
);
979 rgba
[i
][GCOMP
] = UNPACK_GREEN(p
);
980 rgba
[i
][BCOMP
] = UNPACK_BLUE(p
);
981 rgba
[i
][ACOMP
] = UNPACK_ALPHA(p
);
986 /**********************************************************************/
987 /***** 3 byte RGB pixel support funcs *****/
988 /**********************************************************************/
990 /* Write RGBA pixels to an RGB buffer. */
992 write_rgba_span_RGB( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
993 CONST GLchan rgba
[][4], const GLubyte mask
[] )
995 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
996 GLchan
*p
= PIXELADDR3(x
, y
);
999 for (i
= 0; i
< n
; i
++, p
+= 3) {
1001 PACK_RGB(p
, rgba
[i
][RCOMP
], rgba
[i
][GCOMP
], rgba
[i
][BCOMP
]);
1006 for (i
= 0; i
< n
; i
++, p
+= 3) {
1007 PACK_RGB(p
, rgba
[i
][RCOMP
], rgba
[i
][GCOMP
], rgba
[i
][BCOMP
]);
1012 /* Write RGBA pixels to an BGR buffer. */
1014 write_rgba_span_BGR( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
1015 CONST GLchan rgba
[][4], const GLubyte mask
[] )
1017 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1018 GLchan
*p
= PIXELADDR3(x
, y
);
1021 for (i
= 0; i
< n
; i
++, p
+= 3) {
1023 PACK_BGR(p
, rgba
[i
][RCOMP
], rgba
[i
][GCOMP
], rgba
[i
][BCOMP
]);
1028 for (i
= 0; i
< n
; i
++, p
+= 3) {
1029 PACK_BGR(p
, rgba
[i
][RCOMP
], rgba
[i
][GCOMP
], rgba
[i
][BCOMP
]);
1034 /* Write RGB pixels to an RGB buffer. */
1036 write_rgb_span_RGB( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
1037 CONST GLchan rgb
[][3], const GLubyte mask
[] )
1039 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1040 GLchan
*p
= PIXELADDR3(x
, y
);
1043 for (i
= 0; i
< n
; i
++, p
+= 3) {
1045 PACK_RGB(p
, rgb
[i
][RCOMP
], rgb
[i
][GCOMP
], rgb
[i
][BCOMP
]);
1050 for (i
= 0; i
< n
; i
++, p
+= 3) {
1051 PACK_RGB(p
, rgb
[i
][RCOMP
], rgb
[i
][GCOMP
], rgb
[i
][BCOMP
]);
1056 /* Write RGB pixels to an BGR buffer. */
1058 write_rgb_span_BGR( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
1059 CONST GLchan rgb
[][3], const GLubyte mask
[] )
1061 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1062 GLchan
*p
= PIXELADDR3(x
, y
);
1065 for (i
= 0; i
< n
; i
++, p
+= 3) {
1067 PACK_BGR(p
, rgb
[i
][RCOMP
], rgb
[i
][GCOMP
], rgb
[i
][BCOMP
]);
1072 for (i
= 0; i
< n
; i
++, p
+= 3) {
1073 PACK_BGR(p
, rgb
[i
][RCOMP
], rgb
[i
][GCOMP
], rgb
[i
][BCOMP
]);
1080 write_monocolor_span_RGB( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
1081 const GLchan color
[4], const GLubyte mask
[] )
1083 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1084 GLchan
*p
= PIXELADDR3(x
, y
);
1086 for (i
= 0; i
< n
; i
++, p
+= 3) {
1088 PACK_RGB(p
, color
[RCOMP
], color
[GCOMP
], color
[BCOMP
]);
1094 write_monocolor_span_BGR( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
1095 const GLchan color
[4], const GLubyte mask
[] )
1097 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1098 GLchan
*p
= PIXELADDR3(x
, y
);
1100 for (i
= 0; i
< n
; i
++, p
+= 3) {
1102 PACK_BGR(p
, color
[RCOMP
], color
[GCOMP
], color
[BCOMP
]);
1108 write_rgba_pixels_RGB( const GLcontext
*ctx
, GLuint n
,
1109 const GLint x
[], const GLint y
[],
1110 CONST GLchan rgba
[][4], const GLubyte mask
[] )
1112 const OSMesaContext osmesa
= (const OSMesaContext
) ctx
;
1114 for (i
= 0; i
< n
; i
++) {
1116 GLchan
*p
= PIXELADDR3(x
[i
], y
[i
]);
1117 PACK_RGB(p
, rgba
[i
][RCOMP
], rgba
[i
][GCOMP
], rgba
[i
][BCOMP
]);
1123 write_rgba_pixels_BGR( const GLcontext
*ctx
, GLuint n
,
1124 const GLint x
[], const GLint y
[],
1125 CONST GLchan rgba
[][4], const GLubyte mask
[] )
1127 const OSMesaContext osmesa
= (const OSMesaContext
) ctx
;
1129 for (i
= 0; i
< n
; i
++) {
1131 GLchan
*p
= PIXELADDR3(x
[i
], y
[i
]);
1132 PACK_BGR(p
, rgba
[i
][RCOMP
], rgba
[i
][GCOMP
], rgba
[i
][BCOMP
]);
1138 write_monocolor_pixels_RGB( const GLcontext
*ctx
,
1139 GLuint n
, const GLint x
[], const GLint y
[],
1140 const GLchan color
[4], const GLubyte mask
[] )
1142 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1144 for (i
= 0; i
< n
; i
++) {
1146 GLchan
*p
= PIXELADDR3(x
[i
], y
[i
]);
1147 PACK_RGB(p
, color
[RCOMP
], color
[GCOMP
], color
[BCOMP
]);
1153 write_monocolor_pixels_BGR( const GLcontext
*ctx
,
1154 GLuint n
, const GLint x
[], const GLint y
[],
1155 const GLchan color
[4], const GLubyte mask
[] )
1157 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1159 for (i
= 0; i
< n
; i
++) {
1161 GLchan
*p
= PIXELADDR3(x
[i
], y
[i
]);
1162 PACK_BGR(p
, color
[RCOMP
], color
[GCOMP
], color
[BCOMP
]);
1168 read_rgba_span3( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
1171 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1173 const GLchan
*p
= PIXELADDR3(x
, y
);
1174 for (i
= 0; i
< n
; i
++, p
+= 3) {
1175 rgba
[i
][RCOMP
] = UNPACK_RED(p
);
1176 rgba
[i
][GCOMP
] = UNPACK_GREEN(p
);
1177 rgba
[i
][BCOMP
] = UNPACK_BLUE(p
);
1178 rgba
[i
][ACOMP
] = 255;
1183 read_rgba_pixels3( const GLcontext
*ctx
,
1184 GLuint n
, const GLint x
[], const GLint y
[],
1185 GLchan rgba
[][4], const GLubyte mask
[] )
1187 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1189 for (i
= 0; i
< n
; i
++) {
1191 const GLchan
*p
= PIXELADDR3(x
[i
], y
[i
]);
1192 rgba
[i
][RCOMP
] = UNPACK_RED(p
);
1193 rgba
[i
][GCOMP
] = UNPACK_GREEN(p
);
1194 rgba
[i
][BCOMP
] = UNPACK_BLUE(p
);
1195 rgba
[i
][ACOMP
] = 255;
1201 /**********************************************************************/
1202 /***** Read/write spans/arrays of CI pixels *****/
1203 /**********************************************************************/
1205 /* Write 32-bit color index to buffer */
1207 write_index32_span( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
1208 const GLuint index
[], const GLubyte mask
[] )
1210 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1211 GLchan
*ptr1
= PIXELADDR1(x
, y
);
1214 for (i
=0;i
<n
;i
++,ptr1
++) {
1216 *ptr1
= (GLchan
) index
[i
];
1221 for (i
=0;i
<n
;i
++,ptr1
++) {
1222 *ptr1
= (GLchan
) index
[i
];
1228 /* Write 8-bit color index to buffer */
1230 write_index8_span( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
1231 const GLubyte index
[], const GLubyte mask
[] )
1233 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1234 GLchan
*ptr1
= PIXELADDR1(x
, y
);
1237 for (i
=0;i
<n
;i
++,ptr1
++) {
1239 *ptr1
= (GLchan
) index
[i
];
1244 MEMCPY(ptr1
, index
, n
* sizeof(GLchan
));
1250 write_monoindex_span( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
1251 GLuint colorIndex
, const GLubyte mask
[] )
1253 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1254 GLchan
*ptr1
= PIXELADDR1(x
, y
);
1256 for (i
=0;i
<n
;i
++,ptr1
++) {
1258 *ptr1
= (GLchan
) colorIndex
;
1265 write_index_pixels( const GLcontext
*ctx
,
1266 GLuint n
, const GLint x
[], const GLint y
[],
1267 const GLuint index
[], const GLubyte mask
[] )
1269 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1273 GLchan
*ptr1
= PIXELADDR1(x
[i
], y
[i
]);
1274 *ptr1
= (GLchan
) index
[i
];
1281 write_monoindex_pixels( const GLcontext
*ctx
,
1282 GLuint n
, const GLint x
[], const GLint y
[],
1283 GLuint colorIndex
, const GLubyte mask
[] )
1285 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1289 GLchan
*ptr1
= PIXELADDR1(x
[i
], y
[i
]);
1290 *ptr1
= (GLchan
) colorIndex
;
1297 read_index_span( const GLcontext
*ctx
,
1298 GLuint n
, GLint x
, GLint y
, GLuint index
[] )
1300 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1302 const GLchan
*ptr1
= (const GLchan
*) PIXELADDR1(x
, y
);
1303 for (i
=0;i
<n
;i
++,ptr1
++) {
1304 index
[i
] = (GLuint
) *ptr1
;
1310 read_index_pixels( const GLcontext
*ctx
,
1311 GLuint n
, const GLint x
[], const GLint y
[],
1312 GLuint index
[], const GLubyte mask
[] )
1314 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1318 const GLchan
*ptr1
= PIXELADDR1(x
[i
], y
[i
]);
1319 index
[i
] = (GLuint
) *ptr1
;
1326 /**********************************************************************/
1327 /***** Optimized line rendering *****/
1328 /**********************************************************************/
1332 * Draw a flat-shaded, RGB line into an osmesa buffer.
1335 flat_rgba_line( GLcontext
*ctx
, const SWvertex
*vert0
, const SWvertex
*vert1
)
1337 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1338 const GLchan
*color
= vert0
->color
;
1342 #define PLOT(X, Y) \
1344 GLchan *p = PIXELADDR4(X, Y); \
1345 PACK_RGBA(p, color[0], color[1], color[2], color[3]); \
1349 #include "..\swrast\s_linetemp.h"
1351 #include "swrast/s_linetemp.h"
1357 * Draw a flat-shaded, Z-less, RGB line into an osmesa buffer.
1360 flat_rgba_z_line(GLcontext
*ctx
, const SWvertex
*vert0
, const SWvertex
*vert1
)
1362 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1363 const GLchan
*color
= vert0
->color
;
1367 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
1369 #define PLOT(X, Y) \
1372 GLchan *p = PIXELADDR4(X, Y); \
1373 PACK_RGBA(p, color[RCOMP], color[GCOMP], \
1374 color[BCOMP], color[ACOMP]); \
1381 #include "..\swrast\s_linetemp.h"
1383 #include "swrast/s_linetemp.h"
1389 * Draw a flat-shaded, alpha-blended, RGB line into an osmesa buffer.
1390 * XXX update for GLchan
1393 flat_blend_rgba_line( GLcontext
*ctx
,
1394 const SWvertex
*vert0
, const SWvertex
*vert1
)
1396 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1397 const GLint rshift
= osmesa
->rshift
;
1398 const GLint gshift
= osmesa
->gshift
;
1399 const GLint bshift
= osmesa
->bshift
;
1400 const GLint avalue
= vert0
->color
[3];
1401 const GLint msavalue
= 255 - avalue
;
1402 const GLint rvalue
= vert0
->color
[0]*avalue
;
1403 const GLint gvalue
= vert0
->color
[1]*avalue
;
1404 const GLint bvalue
= vert0
->color
[2]*avalue
;
1409 { GLuint *ptr4 = (GLuint *) PIXELADDR4(X, Y); \
1411 pixel |=((((((*ptr4) >> rshift) & 0xff)*msavalue+rvalue)>>8) << rshift);\
1412 pixel |=((((((*ptr4) >> gshift) & 0xff)*msavalue+gvalue)>>8) << gshift);\
1413 pixel |=((((((*ptr4) >> bshift) & 0xff)*msavalue+bvalue)>>8) << bshift);\
1418 #include "..\swrast\s_linetemp.h"
1420 #include "swrast/s_linetemp.h"
1426 * Draw a flat-shaded, Z-less, alpha-blended, RGB line into an osmesa buffer.
1427 * XXX update for GLchan
1430 flat_blend_rgba_z_line( GLcontext
*ctx
,
1431 const SWvertex
*vert0
, const SWvertex
*vert1
)
1433 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1434 const GLint rshift
= osmesa
->rshift
;
1435 const GLint gshift
= osmesa
->gshift
;
1436 const GLint bshift
= osmesa
->bshift
;
1437 const GLint avalue
= vert0
->color
[3];
1438 const GLint msavalue
= 256 - avalue
;
1439 const GLint rvalue
= vert0
->color
[0]*avalue
;
1440 const GLint gvalue
= vert0
->color
[1]*avalue
;
1441 const GLint bvalue
= vert0
->color
[2]*avalue
;
1445 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
1449 GLuint *ptr4 = (GLuint *) PIXELADDR4(X, Y); \
1451 pixel |=((((((*ptr4) >> rshift) & 0xff)*msavalue+rvalue)>>8) << rshift); \
1452 pixel |=((((((*ptr4) >> gshift) & 0xff)*msavalue+gvalue)>>8) << gshift); \
1453 pixel |=((((((*ptr4) >> bshift) & 0xff)*msavalue+bvalue)>>8) << bshift); \
1458 #include "..\swrast\s_linetemp.h"
1460 #include "swrast/s_linetemp.h"
1466 * Draw a flat-shaded, Z-less, alpha-blended, RGB line into an osmesa buffer.
1467 * XXX update for GLchan
1470 flat_blend_rgba_z_line_write( GLcontext
*ctx
,
1471 const SWvertex
*vert0
, const SWvertex
*vert1
)
1473 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1474 const GLint rshift
= osmesa
->rshift
;
1475 const GLint gshift
= osmesa
->gshift
;
1476 const GLint bshift
= osmesa
->bshift
;
1477 const GLint avalue
= vert0
->color
[3];
1478 const GLint msavalue
= 256 - avalue
;
1479 const GLint rvalue
= vert0
->color
[0]*avalue
;
1480 const GLint gvalue
= vert0
->color
[1]*avalue
;
1481 const GLint bvalue
= vert0
->color
[2]*avalue
;
1485 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
1489 GLuint *ptr4 = (GLuint *) PIXELADDR4(X, Y); \
1491 pixel |=((((((*ptr4) >> rshift) & 0xff)*msavalue+rvalue)>>8) << rshift); \
1492 pixel |=((((((*ptr4) >> gshift) & 0xff)*msavalue+gvalue)>>8) << gshift); \
1493 pixel |=((((((*ptr4) >> bshift) & 0xff)*msavalue+bvalue)>>8) << bshift); \
1499 #include "..\swrast\s_linetemp.h"
1501 #include "swrast/s_linetemp.h"
1507 * Analyze context state to see if we can provide a fast line drawing
1508 * function, like those in lines.c. Otherwise, return NULL.
1510 static swrast_line_func
1511 osmesa_choose_line_function( GLcontext
*ctx
)
1513 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1514 const SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
1516 if (CHAN_BITS
!= 8) return NULL
;
1517 if (ctx
->RenderMode
!= GL_RENDER
) return NULL
;
1518 if (ctx
->Line
.SmoothFlag
) return NULL
;
1519 if (ctx
->Texture
._ReallyEnabled
) return NULL
;
1520 if (ctx
->Light
.ShadeModel
!= GL_FLAT
) return NULL
;
1521 if (ctx
->Line
.Width
!= 1.0F
) return NULL
;
1522 if (ctx
->Line
.StippleFlag
) return NULL
;
1523 if (ctx
->Line
.SmoothFlag
) return NULL
;
1524 if (osmesa
->format
!= OSMESA_RGBA
&&
1525 osmesa
->format
!= OSMESA_BGRA
&&
1526 osmesa
->format
!= OSMESA_ARGB
) return NULL
;
1528 if (swrast
->_RasterMask
==DEPTH_BIT
1529 && ctx
->Depth
.Func
==GL_LESS
1530 && ctx
->Depth
.Mask
==GL_TRUE
1531 && ctx
->Visual
.depthBits
== DEFAULT_SOFTWARE_DEPTH_BITS
) {
1532 return flat_rgba_z_line
;
1535 if (swrast
->_RasterMask
== 0) {
1536 return flat_rgba_line
;
1539 if (swrast
->_RasterMask
==(DEPTH_BIT
|BLEND_BIT
)
1540 && ctx
->Depth
.Func
==GL_LESS
1541 && ctx
->Depth
.Mask
==GL_TRUE
1542 && ctx
->Visual
.depthBits
== DEFAULT_SOFTWARE_DEPTH_BITS
1543 && ctx
->Color
.BlendSrcRGB
==GL_SRC_ALPHA
1544 && ctx
->Color
.BlendDstRGB
==GL_ONE_MINUS_SRC_ALPHA
1545 && ctx
->Color
.BlendSrcA
==GL_SRC_ALPHA
1546 && ctx
->Color
.BlendDstA
==GL_ONE_MINUS_SRC_ALPHA
1547 && ctx
->Color
.BlendEquation
==GL_FUNC_ADD_EXT
) {
1548 return flat_blend_rgba_z_line_write
;
1551 if (swrast
->_RasterMask
==(DEPTH_BIT
|BLEND_BIT
)
1552 && ctx
->Depth
.Func
==GL_LESS
1553 && ctx
->Depth
.Mask
==GL_FALSE
1554 && ctx
->Visual
.depthBits
== DEFAULT_SOFTWARE_DEPTH_BITS
1555 && ctx
->Color
.BlendSrcRGB
==GL_SRC_ALPHA
1556 && ctx
->Color
.BlendDstRGB
==GL_ONE_MINUS_SRC_ALPHA
1557 && ctx
->Color
.BlendSrcA
==GL_SRC_ALPHA
1558 && ctx
->Color
.BlendDstA
==GL_ONE_MINUS_SRC_ALPHA
1559 && ctx
->Color
.BlendEquation
==GL_FUNC_ADD_EXT
) {
1560 return flat_blend_rgba_z_line
;
1563 if (swrast
->_RasterMask
==BLEND_BIT
1564 && ctx
->Color
.BlendSrcRGB
==GL_SRC_ALPHA
1565 && ctx
->Color
.BlendDstRGB
==GL_ONE_MINUS_SRC_ALPHA
1566 && ctx
->Color
.BlendSrcA
==GL_SRC_ALPHA
1567 && ctx
->Color
.BlendDstA
==GL_ONE_MINUS_SRC_ALPHA
1568 && ctx
->Color
.BlendEquation
==GL_FUNC_ADD_EXT
) {
1569 return flat_blend_rgba_line
;
1576 /**********************************************************************/
1577 /***** Optimized triangle rendering *****/
1578 /**********************************************************************/
1582 * Smooth-shaded, z-less triangle, RGBA color.
1584 static void smooth_rgba_z_triangle( GLcontext
*ctx
,
1587 const SWvertex
*v2
)
1589 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1592 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
1593 #define INTERP_RGB 1
1594 #define INTERP_ALPHA 1
1595 #define INNER_LOOP( LEFT, RIGHT, Y ) \
1597 GLint i, len = RIGHT-LEFT; \
1598 GLchan *img = PIXELADDR4(LEFT, Y); \
1600 for (i = 0; i < len; i++, img += 4) { \
1601 GLdepth z = FixedToDepth(ffz); \
1602 if (z < zRow[i]) { \
1603 PACK_RGBA(img, FixedToInt(ffr), FixedToInt(ffg), \
1604 FixedToInt(ffb), FixedToInt(ffa)); \
1607 ffr += fdrdx; ffg += fdgdx; ffb += fdbdx; ffa += fdadx;\
1612 #include "..\swrast\s_tritemp.h"
1614 #include "swrast/s_tritemp.h"
1622 * Flat-shaded, z-less triangle, RGBA color.
1624 static void flat_rgba_z_triangle( GLcontext
*ctx
,
1627 const SWvertex
*v2
)
1629 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1631 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
1632 #define SETUP_CODE \
1634 PACK_RGBA((GLchan *) &pixel, v0->color[0], v0->color[1], \
1635 v0->color[2], v0->color[3]);
1637 #define INNER_LOOP( LEFT, RIGHT, Y ) \
1639 GLint i, len = RIGHT-LEFT; \
1640 GLuint *img = (GLuint *) PIXELADDR4(LEFT, Y); \
1642 for (i=0;i<len;i++) { \
1643 GLdepth z = FixedToDepth(ffz); \
1644 if (z < zRow[i]) { \
1652 #include "..\swrast\s_tritemp.h"
1654 #include "swrast/s_tritemp.h"
1661 * Return pointer to an accelerated triangle function if possible.
1663 static swrast_tri_func
1664 osmesa_choose_triangle_function( GLcontext
*ctx
)
1666 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1667 const SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
1669 if (CHAN_BITS
!= 8) return (swrast_tri_func
) NULL
;
1670 if (ctx
->RenderMode
!= GL_RENDER
) return (swrast_tri_func
) NULL
;
1671 if (ctx
->Polygon
.SmoothFlag
) return (swrast_tri_func
) NULL
;
1672 if (ctx
->Polygon
.StippleFlag
) return (swrast_tri_func
) NULL
;
1673 if (ctx
->Texture
._ReallyEnabled
) return (swrast_tri_func
) NULL
;
1674 if (osmesa
->format
!= OSMESA_RGBA
&&
1675 osmesa
->format
!= OSMESA_BGRA
&&
1676 osmesa
->format
!= OSMESA_ARGB
) return (swrast_tri_func
) NULL
;
1678 if (swrast
->_RasterMask
== DEPTH_BIT
&&
1679 ctx
->Depth
.Func
== GL_LESS
&&
1680 ctx
->Depth
.Mask
== GL_TRUE
&&
1681 ctx
->Visual
.depthBits
== DEFAULT_SOFTWARE_DEPTH_BITS
) {
1682 if (ctx
->Light
.ShadeModel
== GL_SMOOTH
) {
1683 return smooth_rgba_z_triangle
;
1686 return flat_rgba_z_triangle
;
1689 return (swrast_tri_func
) NULL
;
1694 /* Override for the swrast triangle-selection function. Try to use one
1695 * of our internal triangle functions, otherwise fall back to the
1696 * standard swrast functions.
1698 static void osmesa_choose_triangle( GLcontext
*ctx
)
1700 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
1702 swrast
->Triangle
= osmesa_choose_triangle_function( ctx
);
1703 if (!swrast
->Triangle
)
1704 _swrast_choose_triangle( ctx
);
1707 static void osmesa_choose_line( GLcontext
*ctx
)
1709 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
1711 swrast
->Line
= osmesa_choose_line_function( ctx
);
1713 _swrast_choose_line( ctx
);
1717 #define OSMESA_NEW_LINE (_NEW_LINE | \
1722 _SWRAST_NEW_RASTERMASK)
1724 #define OSMESA_NEW_TRIANGLE (_NEW_POLYGON | \
1729 _SWRAST_NEW_RASTERMASK)
1732 /* Extend the software rasterizer with our line and triangle
1735 static void osmesa_register_swrast_functions( GLcontext
*ctx
)
1737 SWcontext
*swrast
= SWRAST_CONTEXT( ctx
);
1739 swrast
->choose_line
= osmesa_choose_line
;
1740 swrast
->choose_triangle
= osmesa_choose_triangle
;
1742 swrast
->invalidate_line
|= OSMESA_NEW_LINE
;
1743 swrast
->invalidate_triangle
|= OSMESA_NEW_TRIANGLE
;
1747 static const GLubyte
*get_string( GLcontext
*ctx
, GLenum name
)
1752 return (const GLubyte
*) "Mesa OffScreen";
1759 static void osmesa_update_state( GLcontext
*ctx
, GLuint new_state
)
1761 OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1763 ASSERT((void *) osmesa
== (void *) ctx
->DriverCtx
);
1766 * XXX these function pointers could be initialized just once during
1767 * context creation since they don't depend on any state changes.
1770 ctx
->Driver
.GetString
= get_string
;
1771 ctx
->Driver
.UpdateState
= osmesa_update_state
;
1773 ctx
->Driver
.SetDrawBuffer
= set_draw_buffer
;
1774 ctx
->Driver
.SetReadBuffer
= set_read_buffer
;
1776 ctx
->Driver
.Accum
= _swrast_Accum
;
1777 ctx
->Driver
.Bitmap
= _swrast_Bitmap
;
1778 ctx
->Driver
.Clear
= clear
;
1779 ctx
->Driver
.CopyPixels
= _swrast_CopyPixels
;
1780 ctx
->Driver
.DrawPixels
= _swrast_DrawPixels
;
1781 ctx
->Driver
.ReadPixels
= _swrast_ReadPixels
;
1782 ctx
->Driver
.ResizeBuffersMESA
= _swrast_alloc_buffers
;
1784 ctx
->Driver
.GetBufferSize
= buffer_size
;
1786 ctx
->Driver
.TexImage1D
= _mesa_store_teximage1d
;
1787 ctx
->Driver
.TexImage2D
= _mesa_store_teximage2d
;
1788 ctx
->Driver
.TexImage3D
= _mesa_store_teximage3d
;
1789 ctx
->Driver
.TexSubImage1D
= _mesa_store_texsubimage1d
;
1790 ctx
->Driver
.TexSubImage2D
= _mesa_store_texsubimage2d
;
1791 ctx
->Driver
.TexSubImage3D
= _mesa_store_texsubimage3d
;
1792 ctx
->Driver
.TestProxyTexImage
= _mesa_test_proxy_teximage
;
1794 ctx
->Driver
.PointsFunc
= _swsetup_Points
;
1795 ctx
->Driver
.LineFunc
= _swsetup_Line
;
1796 ctx
->Driver
.TriangleFunc
= _swsetup_Triangle
;
1797 ctx
->Driver
.QuadFunc
= _swsetup_Quad
;
1798 ctx
->Driver
.BuildProjectedVertices
= _swsetup_BuildProjectedVertices
;
1799 ctx
->Driver
.RenderPrimitive
= _swsetup_RenderPrimitive
;
1800 ctx
->Driver
.RenderStart
= _swsetup_RenderStart
;
1801 ctx
->Driver
.RenderFinish
= _swsetup_RenderFinish
;
1802 ctx
->Driver
.RenderInterp
= _swsetup_RenderInterp
;
1803 ctx
->Driver
.RenderCopyPV
= _swsetup_RenderCopyPV
;
1804 ctx
->Driver
.RenderClippedLine
= _swsetup_RenderClippedLine
;
1805 ctx
->Driver
.RenderClippedPolygon
= _swsetup_RenderClippedPolygon
;
1807 /* RGB(A) span/pixel functions */
1808 if (osmesa
->format
== OSMESA_RGB
) {
1809 ctx
->Driver
.WriteRGBASpan
= write_rgba_span_RGB
;
1810 ctx
->Driver
.WriteRGBSpan
= write_rgb_span_RGB
;
1811 ctx
->Driver
.WriteMonoRGBASpan
= write_monocolor_span_RGB
;
1812 ctx
->Driver
.WriteRGBAPixels
= write_rgba_pixels_RGB
;
1813 ctx
->Driver
.WriteMonoRGBAPixels
= write_monocolor_pixels_RGB
;
1814 ctx
->Driver
.ReadRGBASpan
= read_rgba_span3
;
1815 ctx
->Driver
.ReadRGBAPixels
= read_rgba_pixels3
;
1817 else if (osmesa
->format
== OSMESA_BGR
) {
1818 ctx
->Driver
.WriteRGBASpan
= write_rgba_span_BGR
;
1819 ctx
->Driver
.WriteRGBSpan
= write_rgb_span_BGR
;
1820 ctx
->Driver
.WriteMonoRGBASpan
= write_monocolor_span_BGR
;
1821 ctx
->Driver
.WriteRGBAPixels
= write_rgba_pixels_BGR
;
1822 ctx
->Driver
.WriteMonoRGBAPixels
= write_monocolor_pixels_BGR
;
1823 ctx
->Driver
.ReadRGBASpan
= read_rgba_span3
;
1824 ctx
->Driver
.ReadRGBAPixels
= read_rgba_pixels3
;
1827 /* 4 bytes / pixel in frame buffer */
1828 ctx
->Driver
.WriteRGBSpan
= write_rgb_span
;
1829 ctx
->Driver
.WriteRGBAPixels
= write_rgba_pixels
;
1830 ctx
->Driver
.WriteMonoRGBASpan
= write_monocolor_span
;
1831 ctx
->Driver
.WriteMonoRGBAPixels
= write_monocolor_pixels
;
1832 if (osmesa
->format
== OSMESA_RGBA
&&
1833 CHAN_TYPE
== GL_UNSIGNED_BYTE
&&
1834 RCOMP
==0 && GCOMP
==1 && BCOMP
==2 && ACOMP
==3) {
1835 /* special, fast case */
1836 ctx
->Driver
.WriteRGBASpan
= write_rgba_span_rgba
;
1837 ctx
->Driver
.ReadRGBASpan
= read_rgba_span_rgba
;
1840 ctx
->Driver
.WriteRGBASpan
= write_rgba_span
;
1841 ctx
->Driver
.ReadRGBASpan
= read_rgba_span
;
1843 ctx
->Driver
.ReadRGBAPixels
= read_rgba_pixels
;
1846 /* CI span/pixel functions */
1847 ctx
->Driver
.WriteCI32Span
= write_index32_span
;
1848 ctx
->Driver
.WriteCI8Span
= write_index8_span
;
1849 ctx
->Driver
.WriteMonoCISpan
= write_monoindex_span
;
1850 ctx
->Driver
.WriteCI32Pixels
= write_index_pixels
;
1851 ctx
->Driver
.WriteMonoCIPixels
= write_monoindex_pixels
;
1852 ctx
->Driver
.ReadCI32Span
= read_index_span
;
1853 ctx
->Driver
.ReadCI32Pixels
= read_index_pixels
;
1855 _swrast_InvalidateState( ctx
, new_state
);
1856 _swsetup_InvalidateState( ctx
, new_state
);
1857 _ac_InvalidateState( ctx
, new_state
);
1858 _tnl_InvalidateState( ctx
, new_state
);