1 /* $Id: osmesa.c,v 1.64 2001/08/28 22:46:22 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"
49 #include "texformat.h"
51 #include "array_cache/acache.h"
52 #include "swrast/swrast.h"
53 #include "swrast_setup/swrast_setup.h"
54 #include "swrast/s_context.h"
55 #include "swrast/s_depth.h"
56 #include "swrast/s_lines.h"
57 #include "swrast/s_triangle.h"
58 #include "swrast/s_trispan.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 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 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;
140 const GLubyte
*i1
= (GLubyte
*) &i4
;
141 const GLint little_endian
= *i1
;
144 rind
= gind
= bind
= aind
= 0;
145 if (format
==OSMESA_COLOR_INDEX
) {
147 rshift
= gshift
= bshift
= ashift
= 0;
150 else if (format
==OSMESA_RGBA
) {
153 greenBits
= CHAN_BITS
;
154 blueBits
= CHAN_BITS
;
155 alphaBits
= CHAN_BITS
;
174 else if (format
==OSMESA_BGRA
) {
177 greenBits
= CHAN_BITS
;
178 blueBits
= CHAN_BITS
;
179 alphaBits
= CHAN_BITS
;
198 else if (format
==OSMESA_ARGB
) {
201 greenBits
= CHAN_BITS
;
202 blueBits
= CHAN_BITS
;
203 alphaBits
= CHAN_BITS
;
222 else if (format
==OSMESA_RGB
) {
225 greenBits
= CHAN_BITS
;
226 blueBits
= CHAN_BITS
;
238 else if (format
==OSMESA_BGR
) {
241 greenBits
= CHAN_BITS
;
242 blueBits
= CHAN_BITS
;
254 else if (format
==OSMESA_RGB_565
) {
264 rind
= 0; /* not used */
275 osmesa
= (OSMesaContext
) CALLOC_STRUCT(osmesa_context
);
277 osmesa
->gl_visual
= _mesa_create_visual( rgbmode
,
278 GL_FALSE
, /* double buffer */
279 GL_FALSE
, /* stereo */
290 alphaBits
? accumBits
: 0,
293 if (!osmesa
->gl_visual
) {
298 if (!_mesa_initialize_context(&osmesa
->gl_ctx
,
300 sharelist
? &sharelist
->gl_ctx
301 : (GLcontext
*) NULL
,
302 (void *) osmesa
, GL_TRUE
)) {
303 _mesa_destroy_visual( osmesa
->gl_visual
);
308 _mesa_enable_sw_extensions(&(osmesa
->gl_ctx
));
309 _mesa_enable_1_3_extensions(&(osmesa
->gl_ctx
));
311 osmesa
->gl_buffer
= _mesa_create_framebuffer( osmesa
->gl_visual
,
312 osmesa
->gl_visual
->depthBits
> 0,
313 osmesa
->gl_visual
->stencilBits
> 0,
314 osmesa
->gl_visual
->accumRedBits
> 0,
317 if (!osmesa
->gl_buffer
) {
318 _mesa_destroy_visual( osmesa
->gl_visual
);
319 _mesa_free_context_data( &osmesa
->gl_ctx
);
323 osmesa
->format
= format
;
324 osmesa
->buffer
= NULL
;
327 osmesa
->userRowLength
= 0;
328 osmesa
->rowlength
= 0;
329 osmesa
->yup
= GL_TRUE
;
330 osmesa
->rshift
= rshift
;
331 osmesa
->gshift
= gshift
;
332 osmesa
->bshift
= bshift
;
333 osmesa
->ashift
= ashift
;
340 /* Initialize the software rasterizer and helper modules.
343 GLcontext
*ctx
= &osmesa
->gl_ctx
;
345 _swrast_CreateContext( ctx
);
346 _ac_CreateContext( ctx
);
347 _tnl_CreateContext( ctx
);
348 _swsetup_CreateContext( ctx
);
350 _swsetup_Wakeup( ctx
);
351 osmesa_register_swrast_functions( ctx
);
361 * Destroy an Off-Screen Mesa rendering context.
363 * Input: ctx - the context to destroy
365 void GLAPIENTRY
OSMesaDestroyContext( OSMesaContext ctx
)
368 _swsetup_DestroyContext( &ctx
->gl_ctx
);
369 _tnl_DestroyContext( &ctx
->gl_ctx
);
370 _ac_DestroyContext( &ctx
->gl_ctx
);
371 _swrast_DestroyContext( &ctx
->gl_ctx
);
373 _mesa_destroy_visual( ctx
->gl_visual
);
374 _mesa_destroy_framebuffer( ctx
->gl_buffer
);
375 _mesa_free_context_data( &ctx
->gl_ctx
);
383 * Recompute the values of the context's rowaddr array.
385 static void compute_row_addresses( OSMesaContext ctx
)
387 GLint bytesPerPixel
, bytesPerRow
, i
;
388 GLubyte
*origin
= (GLubyte
*) ctx
->buffer
;
390 if (ctx
->format
== OSMESA_COLOR_INDEX
) {
392 bytesPerPixel
= 1 * sizeof(GLchan
);
394 else if ((ctx
->format
== OSMESA_RGB
) || (ctx
->format
== OSMESA_BGR
)) {
396 bytesPerPixel
= 3 * sizeof(GLchan
);
398 else if (ctx
->format
== OSMESA_RGB_565
) {
399 /* 5/6/5 RGB pixel in 16 bits */
404 bytesPerPixel
= 4 * sizeof(GLchan
);
407 bytesPerRow
= ctx
->rowlength
* bytesPerPixel
;
410 /* Y=0 is bottom line of window */
411 for (i
= 0; i
< MAX_HEIGHT
; i
++) {
412 ctx
->rowaddr
[i
] = (GLchan
*) ((GLubyte
*) origin
+ i
* bytesPerRow
);
416 /* Y=0 is top line of window */
417 for (i
= 0; i
< MAX_HEIGHT
; i
++) {
418 GLint j
= ctx
->height
- i
- 1;
419 ctx
->rowaddr
[i
] = (GLchan
*) ((GLubyte
*) origin
+ j
* bytesPerRow
);
426 * Bind an OSMesaContext to an image buffer. The image buffer is just a
427 * block of memory which the client provides. Its size must be at least
428 * as large as width*height*sizeof(type). Its address should be a multiple
429 * of 4 if using RGBA mode.
431 * Image data is stored in the order of glDrawPixels: row-major order
432 * with the lower-left image pixel stored in the first array position
433 * (ie. bottom-to-top).
435 * Since the only type initially supported is GL_UNSIGNED_BYTE, if the
436 * context is in RGBA mode, each pixel will be stored as a 4-byte RGBA
437 * value. If the context is in color indexed mode, each pixel will be
438 * stored as a 1-byte value.
440 * If the context's viewport hasn't been initialized yet, it will now be
441 * initialized to (0,0,width,height).
443 * Input: ctx - the rendering context
444 * buffer - the image buffer memory
445 * type - data type for pixel components, only GL_UNSIGNED_BYTE
446 * and GL_UNSIGNED_SHORT_5_6_5 supported now.
447 * width, height - size of image buffer in pixels, at least 1
448 * Return: GL_TRUE if success, GL_FALSE if error because of invalid ctx,
449 * invalid buffer address, type!=GL_UNSIGNED_BYTE, width<1, height<1,
450 * width>internal limit or height>internal limit.
453 OSMesaMakeCurrent( OSMesaContext ctx
, void *buffer
, GLenum type
,
454 GLsizei width
, GLsizei height
)
456 if (!ctx
|| !buffer
||
457 width
< 1 || height
< 1 ||
458 width
> MAX_WIDTH
|| height
> MAX_HEIGHT
) {
462 if (ctx
->format
== OSMESA_RGB_565
) {
463 if (type
!= GL_UNSIGNED_SHORT_5_6_5
)
466 else if (type
!= CHAN_TYPE
) {
470 osmesa_update_state( &ctx
->gl_ctx
, 0 );
471 _mesa_make_current( &ctx
->gl_ctx
, ctx
->gl_buffer
);
473 ctx
->buffer
= buffer
;
475 ctx
->height
= height
;
476 if (ctx
->userRowLength
)
477 ctx
->rowlength
= ctx
->userRowLength
;
479 ctx
->rowlength
= width
;
481 compute_row_addresses( ctx
);
484 if (ctx
->gl_ctx
.Viewport
.Width
==0) {
485 /* initialize viewport and scissor box to buffer size */
486 _mesa_Viewport( 0, 0, width
, height
);
487 ctx
->gl_ctx
.Scissor
.Width
= width
;
488 ctx
->gl_ctx
.Scissor
.Height
= height
;
496 OSMesaContext GLAPIENTRY
OSMesaGetCurrentContext( void )
498 GLcontext
*ctx
= _mesa_get_current_context();
500 return (OSMesaContext
) ctx
;
507 void GLAPIENTRY
OSMesaPixelStore( GLint pname
, GLint value
)
509 OSMesaContext ctx
= OSMesaGetCurrentContext();
512 case OSMESA_ROW_LENGTH
:
514 _mesa_error( &ctx
->gl_ctx
, GL_INVALID_VALUE
,
515 "OSMesaPixelStore(value)" );
518 ctx
->userRowLength
= value
;
519 ctx
->rowlength
= value
;
522 ctx
->yup
= value
? GL_TRUE
: GL_FALSE
;
525 _mesa_error( &ctx
->gl_ctx
, GL_INVALID_ENUM
, "OSMesaPixelStore(pname)" );
529 compute_row_addresses( ctx
);
533 void GLAPIENTRY
OSMesaGetIntegerv( GLint pname
, GLint
*value
)
535 OSMesaContext ctx
= OSMesaGetCurrentContext();
542 *value
= ctx
->height
;
545 *value
= ctx
->format
;
550 case OSMESA_ROW_LENGTH
:
551 *value
= ctx
->rowlength
;
557 _mesa_error(&ctx
->gl_ctx
, GL_INVALID_ENUM
, "OSMesaGetIntergerv(pname)");
563 * Return the depth buffer associated with an OSMesa context.
564 * Input: c - the OSMesa context
565 * Output: width, height - size of buffer in pixels
566 * bytesPerValue - bytes per depth value (2 or 4)
567 * buffer - pointer to depth buffer values
568 * Return: GL_TRUE or GL_FALSE to indicate success or failure.
571 OSMesaGetDepthBuffer( OSMesaContext c
, GLint
*width
, GLint
*height
,
572 GLint
*bytesPerValue
, void **buffer
)
574 if ((!c
->gl_buffer
) || (!c
->gl_buffer
->DepthBuffer
)) {
582 *width
= c
->gl_buffer
->Width
;
583 *height
= c
->gl_buffer
->Height
;
584 if (c
->gl_visual
->depthBits
<= 16)
585 *bytesPerValue
= sizeof(GLushort
);
587 *bytesPerValue
= sizeof(GLuint
);
588 *buffer
= c
->gl_buffer
->DepthBuffer
;
594 * Return the color buffer associated with an OSMesa context.
595 * Input: c - the OSMesa context
596 * Output: width, height - size of buffer in pixels
597 * format - the pixel format (OSMESA_FORMAT)
598 * buffer - pointer to color buffer values
599 * Return: GL_TRUE or GL_FALSE to indicate success or failure.
602 OSMesaGetColorBuffer( OSMesaContext c
, GLint
*width
,
603 GLint
*height
, GLint
*format
, void **buffer
)
621 /**********************************************************************/
622 /*** Device Driver Functions ***/
623 /**********************************************************************/
630 #define PACK_RGBA(DST, R, G, B, A) \
632 (DST)[osmesa->rInd] = R; \
633 (DST)[osmesa->gInd] = G; \
634 (DST)[osmesa->bInd] = B; \
635 (DST)[osmesa->aInd] = A; \
638 #define PACK_RGB(DST, R, G, B) \
645 #define PACK_BGR(DST, R, G, B) \
652 #define PACK_RGB_565(DST, R, G, B) \
654 (DST) = (((int) (R) << 8) & 0xf800) | (((int) (G) << 3) & 0x7e0) | ((int) (B) >> 3);\
658 #define UNPACK_RED(P) ( (P)[osmesa->rInd] )
659 #define UNPACK_GREEN(P) ( (P)[osmesa->gInd] )
660 #define UNPACK_BLUE(P) ( (P)[osmesa->bInd] )
661 #define UNPACK_ALPHA(P) ( (P)[osmesa->aInd] )
664 #define PIXELADDR1(X,Y) (osmesa->rowaddr[Y] + (X))
665 #define PIXELADDR2(X,Y) (osmesa->rowaddr[Y] + 2 * (X))
666 #define PIXELADDR3(X,Y) (osmesa->rowaddr[Y] + 3 * (X))
667 #define PIXELADDR4(X,Y) (osmesa->rowaddr[Y] + 4 * (X))
671 static GLboolean
set_draw_buffer( GLcontext
*ctx
, GLenum mode
)
674 if (mode
==GL_FRONT_LEFT
) {
683 static void set_read_buffer( GLcontext
*ctx
, GLframebuffer
*buffer
, GLenum mode
)
685 /* separate read buffer not supported */
686 ASSERT(buffer
== ctx
->DrawBuffer
);
687 ASSERT(mode
== GL_FRONT_LEFT
);
691 static void clear( GLcontext
*ctx
, GLbitfield mask
, GLboolean all
,
692 GLint x
, GLint y
, GLint width
, GLint height
)
694 OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
695 const GLuint
*colorMask
= (GLuint
*) &ctx
->Color
.ColorMask
;
697 /* sanity check - we only have a front-left buffer */
698 ASSERT((mask
& (DD_FRONT_RIGHT_BIT
| DD_BACK_LEFT_BIT
| DD_BACK_RIGHT_BIT
)) == 0);
699 if (*colorMask
== 0xffffffff && ctx
->Color
.IndexMask
== 0xffffffff) {
700 if (mask
& DD_FRONT_LEFT_BIT
) {
701 if (osmesa
->format
== OSMESA_COLOR_INDEX
) {
703 /* Clear whole CI buffer */
704 #if CHAN_TYPE == GL_UNSIGNED_BYTE
705 MEMSET(osmesa
->buffer
, ctx
->Color
.ClearIndex
,
706 osmesa
->rowlength
* osmesa
->height
);
708 const GLint n
= osmesa
->rowlength
* osmesa
->height
;
709 GLchan
*buffer
= (GLchan
*) osmesa
->buffer
;
711 for (i
= 0; i
< n
; i
++) {
712 buffer
[i
] = ctx
->Color
.ClearIndex
;
717 /* Clear part of CI buffer */
718 const GLchan clearIndex
= (GLchan
) ctx
->Color
.ClearIndex
;
720 for (i
= 0; i
< height
; i
++) {
721 GLchan
*ptr1
= PIXELADDR1(x
, (y
+ i
));
722 for (j
= 0; j
< width
; j
++) {
723 *ptr1
++ = clearIndex
;
728 else if (osmesa
->format
== OSMESA_RGB
) {
729 const GLchan r
= ctx
->Color
.ClearColor
[0];
730 const GLchan g
= ctx
->Color
.ClearColor
[1];
731 const GLchan b
= ctx
->Color
.ClearColor
[2];
733 /* Clear whole RGB buffer */
734 GLuint n
= osmesa
->rowlength
* osmesa
->height
;
735 GLchan
*ptr3
= (GLchan
*) osmesa
->buffer
;
737 for (i
= 0; i
< n
; i
++) {
738 PACK_RGB(ptr3
, r
, g
, b
);
743 /* Clear part of RGB buffer */
745 for (i
= 0; i
< height
; i
++) {
746 GLchan
*ptr3
= PIXELADDR3(x
, (y
+ i
));
747 for (j
= 0; j
< width
; j
++) {
748 PACK_RGB(ptr3
, r
, g
, b
);
754 else if (osmesa
->format
== OSMESA_BGR
) {
755 const GLchan r
= ctx
->Color
.ClearColor
[0];
756 const GLchan g
= ctx
->Color
.ClearColor
[1];
757 const GLchan b
= ctx
->Color
.ClearColor
[2];
759 /* Clear whole RGB buffer */
760 const GLint n
= osmesa
->rowlength
* osmesa
->height
;
761 GLchan
*ptr3
= (GLchan
*) osmesa
->buffer
;
763 for (i
= 0; i
< n
; i
++) {
764 PACK_BGR(ptr3
, r
, g
, b
);
769 /* Clear part of RGB buffer */
771 for (i
= 0; i
< height
; i
++) {
772 GLchan
*ptr3
= PIXELADDR3(x
, (y
+ i
));
773 for (j
= 0; j
< width
; j
++) {
774 PACK_BGR(ptr3
, r
, g
, b
);
780 else if (osmesa
->format
== OSMESA_RGB_565
) {
781 const GLchan r
= ctx
->Color
.ClearColor
[0];
782 const GLchan g
= ctx
->Color
.ClearColor
[1];
783 const GLchan b
= ctx
->Color
.ClearColor
[2];
785 PACK_RGB_565(clearPixel
, r
, g
, b
);
787 /* Clear whole RGB buffer */
788 const GLint n
= osmesa
->rowlength
* osmesa
->height
;
789 GLushort
*ptr2
= (GLushort
*) osmesa
->buffer
;
791 for (i
= 0; i
< n
; i
++) {
797 /* clear scissored region */
799 for (i
= 0; i
< height
; i
++) {
800 GLushort
*ptr2
= (GLushort
*) PIXELADDR2(x
, (y
+ i
));
801 for (j
= 0; j
< width
; j
++) {
809 #if CHAN_TYPE == GL_UNSIGNED_BYTE
810 /* 4-byte pixel value */
812 GLchan
*clr
= (GLchan
*) &clearPixel
;
813 clr
[osmesa
->rInd
] = ctx
->Color
.ClearColor
[0];
814 clr
[osmesa
->gInd
] = ctx
->Color
.ClearColor
[1];
815 clr
[osmesa
->bInd
] = ctx
->Color
.ClearColor
[2];
816 clr
[osmesa
->aInd
] = ctx
->Color
.ClearColor
[3];
818 /* Clear whole RGBA buffer */
819 const GLuint n
= osmesa
->rowlength
* osmesa
->height
;
820 GLuint
*ptr4
= (GLuint
*) osmesa
->buffer
;
823 for (i
= 0; i
< n
; i
++) {
824 *ptr4
++ = clearPixel
;
828 BZERO(ptr4
, n
* sizeof(GLuint
));
832 /* Clear part of RGBA buffer */
834 for (i
= 0; i
< height
; i
++) {
835 GLuint
*ptr4
= (GLuint
*) PIXELADDR4(x
, (y
+ i
));
836 for (j
= 0; j
< width
; j
++) {
837 *ptr4
++ = clearPixel
;
842 const GLchan r
= ctx
->Color
.ClearColor
[0];
843 const GLchan g
= ctx
->Color
.ClearColor
[1];
844 const GLchan b
= ctx
->Color
.ClearColor
[2];
845 const GLchan a
= ctx
->Color
.ClearColor
[3];
847 /* Clear whole RGBA buffer */
848 const GLuint n
= osmesa
->rowlength
* osmesa
->height
;
849 GLchan
*p
= (GLchan
*) osmesa
->buffer
;
851 for (i
= 0; i
< n
; i
++) {
852 PACK_RGBA(p
, r
, g
, b
, a
);
857 /* Clear part of RGBA buffer */
859 for (i
= 0; i
< height
; i
++) {
860 GLchan
*p
= PIXELADDR4(x
, (y
+ i
));
861 for (j
= 0; j
< width
; j
++) {
862 PACK_RGBA(p
, r
, g
, b
, a
);
870 mask
&= ~DD_FRONT_LEFT_BIT
;
875 _swrast_Clear( ctx
, mask
, all
, x
, y
, width
, height
);
880 static void buffer_size( GLcontext
*ctx
, GLuint
*width
, GLuint
*height
)
882 OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
883 *width
= osmesa
->width
;
884 *height
= osmesa
->height
;
888 /**********************************************************************/
889 /***** Read/write spans/arrays of RGBA pixels *****/
890 /**********************************************************************/
892 /* Write RGBA pixels to an RGBA (or permuted) buffer. */
894 write_rgba_span( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
895 CONST GLchan rgba
[][4], const GLubyte mask
[] )
897 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
898 GLchan
*p
= PIXELADDR4(x
, y
);
901 for (i
= 0; i
< n
; i
++, p
+= 4) {
903 PACK_RGBA(p
, rgba
[i
][RCOMP
], rgba
[i
][GCOMP
],
904 rgba
[i
][BCOMP
], rgba
[i
][ACOMP
]);
909 for (i
= 0; i
< n
; i
++, p
+= 4) {
910 PACK_RGBA(p
, rgba
[i
][RCOMP
], rgba
[i
][GCOMP
],
911 rgba
[i
][BCOMP
], rgba
[i
][ACOMP
]);
917 /* Write RGBA pixels to an RGBA buffer. This is the fastest span-writer. */
919 write_rgba_span_rgba( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
920 CONST GLchan rgba
[][4], const GLubyte mask
[] )
922 OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
923 GLuint
*ptr4
= (GLuint
*) PIXELADDR4(x
, y
);
924 const GLuint
*rgba4
= (const GLuint
*) rgba
;
926 ASSERT(CHAN_TYPE
== GL_UNSIGNED_BYTE
);
928 for (i
= 0; i
< n
; i
++) {
935 MEMCPY( ptr4
, rgba4
, n
* 4 );
940 /* Write RGB pixels to an RGBA (or permuted) buffer. */
942 write_rgb_span( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
943 CONST GLchan rgb
[][3], const GLubyte mask
[] )
945 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
946 GLchan
*p
= PIXELADDR4(x
, y
);
949 for (i
= 0; i
< n
; i
++, p
+=4) {
951 PACK_RGBA(p
, rgb
[i
][RCOMP
], rgb
[i
][GCOMP
], rgb
[i
][BCOMP
], CHAN_MAX
);
956 for (i
= 0; i
< n
; i
++, p
+=4) {
957 PACK_RGBA(p
, rgb
[i
][RCOMP
], rgb
[i
][GCOMP
], rgb
[i
][BCOMP
], CHAN_MAX
);
965 write_monocolor_span( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
966 const GLchan color
[4], const GLubyte mask
[] )
968 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
969 GLchan
*p
= PIXELADDR4(x
, y
);
971 for (i
= 0; i
< n
; i
++, p
+= 4) {
973 PACK_RGBA(p
, color
[RCOMP
], color
[GCOMP
], color
[BCOMP
], color
[ACOMP
]);
981 write_rgba_pixels( const GLcontext
*ctx
, GLuint n
,
982 const GLint x
[], const GLint y
[],
983 CONST GLchan rgba
[][4], const GLubyte mask
[] )
985 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
987 for (i
= 0; i
< n
; i
++) {
989 GLchan
*p
= PIXELADDR4(x
[i
], y
[i
]);
990 PACK_RGBA(p
, rgba
[i
][RCOMP
], rgba
[i
][GCOMP
],
991 rgba
[i
][BCOMP
], rgba
[i
][ACOMP
]);
999 write_monocolor_pixels( const GLcontext
*ctx
, GLuint n
,
1000 const GLint x
[], const GLint y
[],
1001 const GLchan color
[4], const GLubyte mask
[] )
1003 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1005 for (i
= 0; i
< n
; i
++) {
1007 GLchan
*p
= PIXELADDR4(x
[i
], y
[i
]);
1008 PACK_RGBA(p
, color
[RCOMP
], color
[GCOMP
], color
[BCOMP
], color
[ACOMP
]);
1015 read_rgba_span( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
1018 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1020 GLchan
*p
= PIXELADDR4(x
, y
);
1021 for (i
= 0; i
< n
; i
++, p
+= 4) {
1022 rgba
[i
][RCOMP
] = UNPACK_RED(p
);
1023 rgba
[i
][GCOMP
] = UNPACK_GREEN(p
);
1024 rgba
[i
][BCOMP
] = UNPACK_BLUE(p
);
1025 rgba
[i
][ACOMP
] = UNPACK_ALPHA(p
);
1030 /* Read RGBA pixels from an RGBA buffer */
1032 read_rgba_span_rgba( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
1035 OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1036 GLuint
*ptr4
= (GLuint
*) PIXELADDR4(x
, y
);
1037 MEMCPY( rgba
, ptr4
, n
* 4 * sizeof(GLchan
) );
1042 read_rgba_pixels( const GLcontext
*ctx
,
1043 GLuint n
, const GLint x
[], const GLint y
[],
1044 GLchan rgba
[][4], const GLubyte mask
[] )
1046 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1048 for (i
= 0; i
< n
; i
++) {
1050 const GLchan
*p
= PIXELADDR4(x
[i
], y
[i
]);
1051 rgba
[i
][RCOMP
] = UNPACK_RED(p
);
1052 rgba
[i
][GCOMP
] = UNPACK_GREEN(p
);
1053 rgba
[i
][BCOMP
] = UNPACK_BLUE(p
);
1054 rgba
[i
][ACOMP
] = UNPACK_ALPHA(p
);
1059 /**********************************************************************/
1060 /***** 3 byte RGB pixel support funcs *****/
1061 /**********************************************************************/
1063 /* Write RGBA pixels to an RGB buffer. */
1065 write_rgba_span_RGB( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
1066 CONST GLchan rgba
[][4], const GLubyte mask
[] )
1068 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1069 GLchan
*p
= PIXELADDR3(x
, y
);
1072 for (i
= 0; i
< n
; i
++, p
+= 3) {
1074 PACK_RGB(p
, rgba
[i
][RCOMP
], rgba
[i
][GCOMP
], rgba
[i
][BCOMP
]);
1079 for (i
= 0; i
< n
; i
++, p
+= 3) {
1080 PACK_RGB(p
, rgba
[i
][RCOMP
], rgba
[i
][GCOMP
], rgba
[i
][BCOMP
]);
1085 /* Write RGBA pixels to an BGR buffer. */
1087 write_rgba_span_BGR( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
1088 CONST GLchan rgba
[][4], const GLubyte mask
[] )
1090 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1091 GLchan
*p
= PIXELADDR3(x
, y
);
1094 for (i
= 0; i
< n
; i
++, p
+= 3) {
1096 PACK_BGR(p
, rgba
[i
][RCOMP
], rgba
[i
][GCOMP
], rgba
[i
][BCOMP
]);
1101 for (i
= 0; i
< n
; i
++, p
+= 3) {
1102 PACK_BGR(p
, rgba
[i
][RCOMP
], rgba
[i
][GCOMP
], rgba
[i
][BCOMP
]);
1107 /* Write RGB pixels to an RGB buffer. */
1109 write_rgb_span_RGB( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
1110 CONST GLchan rgb
[][3], const GLubyte mask
[] )
1112 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1113 GLchan
*p
= PIXELADDR3(x
, y
);
1116 for (i
= 0; i
< n
; i
++, p
+= 3) {
1118 PACK_RGB(p
, rgb
[i
][RCOMP
], rgb
[i
][GCOMP
], rgb
[i
][BCOMP
]);
1123 for (i
= 0; i
< n
; i
++, p
+= 3) {
1124 PACK_RGB(p
, rgb
[i
][RCOMP
], rgb
[i
][GCOMP
], rgb
[i
][BCOMP
]);
1129 /* Write RGB pixels to an BGR buffer. */
1131 write_rgb_span_BGR( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
1132 CONST GLchan rgb
[][3], const GLubyte mask
[] )
1134 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1135 GLchan
*p
= PIXELADDR3(x
, y
);
1138 for (i
= 0; i
< n
; i
++, p
+= 3) {
1140 PACK_BGR(p
, rgb
[i
][RCOMP
], rgb
[i
][GCOMP
], rgb
[i
][BCOMP
]);
1145 for (i
= 0; i
< n
; i
++, p
+= 3) {
1146 PACK_BGR(p
, rgb
[i
][RCOMP
], rgb
[i
][GCOMP
], rgb
[i
][BCOMP
]);
1153 write_monocolor_span_RGB( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
1154 const GLchan color
[4], const GLubyte mask
[] )
1156 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1157 GLchan
*p
= PIXELADDR3(x
, y
);
1159 for (i
= 0; i
< n
; i
++, p
+= 3) {
1161 PACK_RGB(p
, color
[RCOMP
], color
[GCOMP
], color
[BCOMP
]);
1167 write_monocolor_span_BGR( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
1168 const GLchan color
[4], const GLubyte mask
[] )
1170 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1171 GLchan
*p
= PIXELADDR3(x
, y
);
1173 for (i
= 0; i
< n
; i
++, p
+= 3) {
1175 PACK_BGR(p
, color
[RCOMP
], color
[GCOMP
], color
[BCOMP
]);
1181 write_rgba_pixels_RGB( const GLcontext
*ctx
, GLuint n
,
1182 const GLint x
[], const GLint y
[],
1183 CONST GLchan rgba
[][4], const GLubyte mask
[] )
1185 const OSMesaContext osmesa
= (const OSMesaContext
) ctx
;
1187 for (i
= 0; i
< n
; i
++) {
1189 GLchan
*p
= PIXELADDR3(x
[i
], y
[i
]);
1190 PACK_RGB(p
, rgba
[i
][RCOMP
], rgba
[i
][GCOMP
], rgba
[i
][BCOMP
]);
1196 write_rgba_pixels_BGR( const GLcontext
*ctx
, GLuint n
,
1197 const GLint x
[], const GLint y
[],
1198 CONST GLchan rgba
[][4], const GLubyte mask
[] )
1200 const OSMesaContext osmesa
= (const OSMesaContext
) ctx
;
1202 for (i
= 0; i
< n
; i
++) {
1204 GLchan
*p
= PIXELADDR3(x
[i
], y
[i
]);
1205 PACK_BGR(p
, rgba
[i
][RCOMP
], rgba
[i
][GCOMP
], rgba
[i
][BCOMP
]);
1211 write_monocolor_pixels_RGB( const GLcontext
*ctx
,
1212 GLuint n
, const GLint x
[], const GLint y
[],
1213 const GLchan color
[4], const GLubyte mask
[] )
1215 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1217 for (i
= 0; i
< n
; i
++) {
1219 GLchan
*p
= PIXELADDR3(x
[i
], y
[i
]);
1220 PACK_RGB(p
, color
[RCOMP
], color
[GCOMP
], color
[BCOMP
]);
1226 write_monocolor_pixels_BGR( const GLcontext
*ctx
,
1227 GLuint n
, const GLint x
[], const GLint y
[],
1228 const GLchan color
[4], const GLubyte mask
[] )
1230 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1232 for (i
= 0; i
< n
; i
++) {
1234 GLchan
*p
= PIXELADDR3(x
[i
], y
[i
]);
1235 PACK_BGR(p
, color
[RCOMP
], color
[GCOMP
], color
[BCOMP
]);
1241 read_rgba_span3( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
1244 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1246 const GLchan
*p
= PIXELADDR3(x
, y
);
1247 for (i
= 0; i
< n
; i
++, p
+= 3) {
1248 rgba
[i
][RCOMP
] = UNPACK_RED(p
);
1249 rgba
[i
][GCOMP
] = UNPACK_GREEN(p
);
1250 rgba
[i
][BCOMP
] = UNPACK_BLUE(p
);
1251 rgba
[i
][ACOMP
] = CHAN_MAX
;
1256 read_rgba_pixels3( const GLcontext
*ctx
,
1257 GLuint n
, const GLint x
[], const GLint y
[],
1258 GLchan rgba
[][4], const GLubyte mask
[] )
1260 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1262 for (i
= 0; i
< n
; i
++) {
1264 const GLchan
*p
= PIXELADDR3(x
[i
], y
[i
]);
1265 rgba
[i
][RCOMP
] = UNPACK_RED(p
);
1266 rgba
[i
][GCOMP
] = UNPACK_GREEN(p
);
1267 rgba
[i
][BCOMP
] = UNPACK_BLUE(p
);
1268 rgba
[i
][ACOMP
] = CHAN_MAX
;
1274 /**********************************************************************/
1275 /***** 2 byte RGB pixel support funcs *****/
1276 /**********************************************************************/
1278 /* Write RGBA pixels to an RGB_565 buffer. */
1280 write_rgba_span2( const GLcontext
*ctx
,
1281 GLuint n
, GLint x
, GLint y
,
1282 CONST GLchan rgba
[][4], const GLubyte mask
[] )
1284 OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1285 GLushort
*ptr2
= (GLushort
*) PIXELADDR2(x
, y
);
1288 for (i
= 0; i
< n
; i
++, ptr2
++) {
1290 PACK_RGB_565(*ptr2
, rgba
[i
][RCOMP
], rgba
[i
][GCOMP
], rgba
[i
][BCOMP
]);
1295 for (i
= 0; i
< n
; i
++, ptr2
++) {
1296 PACK_RGB_565(*ptr2
, rgba
[i
][RCOMP
], rgba
[i
][GCOMP
], rgba
[i
][BCOMP
]);
1302 /* Write RGB pixels to an RGB_565 buffer. */
1304 write_rgb_span2( const GLcontext
*ctx
,
1305 GLuint n
, GLint x
, GLint y
,
1306 CONST GLchan rgb
[][3], const GLubyte mask
[] )
1308 OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1309 GLushort
*ptr2
= (GLushort
*) PIXELADDR2(x
, y
);
1312 for (i
= 0; i
< n
; i
++, ptr2
++) {
1314 PACK_RGB_565(*ptr2
, rgb
[i
][RCOMP
], rgb
[i
][GCOMP
], rgb
[i
][BCOMP
]);
1319 for (i
= 0; i
< n
; i
++, ptr2
++) {
1320 PACK_RGB_565(*ptr2
, rgb
[i
][RCOMP
], rgb
[i
][GCOMP
], rgb
[i
][BCOMP
]);
1327 write_monocolor_span2( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
1328 const GLchan color
[4], const GLubyte mask
[] )
1330 OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1332 GLushort
*ptr2
= (GLushort
*) PIXELADDR2(x
, y
);
1334 PACK_RGB_565(pixel
, color
[RCOMP
], color
[GCOMP
], color
[BCOMP
]);
1335 for (i
= 0; i
< n
; i
++, ptr2
++) {
1344 write_rgba_pixels2( const GLcontext
*ctx
,
1345 GLuint n
, const GLint x
[], const GLint y
[],
1346 CONST GLchan rgba
[][4], const GLubyte mask
[] )
1348 OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1350 for (i
= 0; i
< n
; i
++) {
1352 GLushort
*ptr2
= (GLushort
*) PIXELADDR2(x
[i
],y
[i
]);
1353 PACK_RGB_565(*ptr2
, rgba
[i
][RCOMP
], rgba
[i
][GCOMP
], rgba
[i
][BCOMP
]);
1359 write_monocolor_pixels2( const GLcontext
*ctx
,
1360 GLuint n
, const GLint x
[], const GLint y
[],
1361 const GLchan color
[4], const GLubyte mask
[] )
1363 OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1366 PACK_RGB_565(pixel
, color
[RCOMP
], color
[GCOMP
], color
[BCOMP
]);
1367 for (i
= 0; i
< n
; i
++) {
1369 GLushort
*ptr2
= (GLushort
*) PIXELADDR2(x
[i
],y
[i
]);
1376 read_rgba_span2( const GLcontext
*ctx
,
1377 GLuint n
, GLint x
, GLint y
,
1380 OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1382 const GLushort
*ptr2
= (const GLushort
*) PIXELADDR2(x
, y
);
1383 for (i
= 0; i
< n
; i
++, ptr2
++) {
1384 /* This should be fixed to get the low bits right */
1385 rgba
[i
][RCOMP
] = (*ptr2
>> 8) & 0xFe;
1386 rgba
[i
][GCOMP
] = (*ptr2
>> 3) & 0xFc;
1387 rgba
[i
][BCOMP
] = (*ptr2
<< 3) & 0xFe;
1393 read_rgba_pixels2( const GLcontext
*ctx
,
1394 GLuint n
, const GLint x
[], const GLint y
[],
1395 GLchan rgba
[][4], const GLubyte mask
[] )
1397 OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1399 for (i
= 0; i
< n
; i
++) {
1401 /* This should be fixed to get the low bits right */
1402 const GLushort
*ptr2
= (const GLushort
*) PIXELADDR2(x
[i
],y
[i
]);
1403 rgba
[i
][RCOMP
] = (*ptr2
>> 8) & 0xFE;
1404 rgba
[i
][GCOMP
] = (*ptr2
>> 3) & 0xFC;
1405 rgba
[i
][BCOMP
] = (*ptr2
<< 3) & 0xFE;
1413 /**********************************************************************/
1414 /***** Read/write spans/arrays of CI pixels *****/
1415 /**********************************************************************/
1417 /* Write 32-bit color index to buffer */
1419 write_index32_span( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
1420 const GLuint index
[], const GLubyte mask
[] )
1422 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1423 GLchan
*ptr1
= PIXELADDR1(x
, y
);
1426 for (i
=0;i
<n
;i
++,ptr1
++) {
1428 *ptr1
= (GLchan
) index
[i
];
1433 for (i
=0;i
<n
;i
++,ptr1
++) {
1434 *ptr1
= (GLchan
) index
[i
];
1440 /* Write 8-bit color index to buffer */
1442 write_index8_span( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
1443 const GLubyte index
[], const GLubyte mask
[] )
1445 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1446 GLchan
*ptr1
= PIXELADDR1(x
, y
);
1449 for (i
=0;i
<n
;i
++,ptr1
++) {
1451 *ptr1
= (GLchan
) index
[i
];
1456 MEMCPY(ptr1
, index
, n
* sizeof(GLchan
));
1462 write_monoindex_span( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
1463 GLuint colorIndex
, const GLubyte mask
[] )
1465 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1466 GLchan
*ptr1
= PIXELADDR1(x
, y
);
1468 for (i
=0;i
<n
;i
++,ptr1
++) {
1470 *ptr1
= (GLchan
) colorIndex
;
1477 write_index_pixels( const GLcontext
*ctx
,
1478 GLuint n
, const GLint x
[], const GLint y
[],
1479 const GLuint index
[], const GLubyte mask
[] )
1481 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1485 GLchan
*ptr1
= PIXELADDR1(x
[i
], y
[i
]);
1486 *ptr1
= (GLchan
) index
[i
];
1493 write_monoindex_pixels( const GLcontext
*ctx
,
1494 GLuint n
, const GLint x
[], const GLint y
[],
1495 GLuint colorIndex
, const GLubyte mask
[] )
1497 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1501 GLchan
*ptr1
= PIXELADDR1(x
[i
], y
[i
]);
1502 *ptr1
= (GLchan
) colorIndex
;
1509 read_index_span( const GLcontext
*ctx
,
1510 GLuint n
, GLint x
, GLint y
, GLuint index
[] )
1512 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1514 const GLchan
*ptr1
= (const GLchan
*) PIXELADDR1(x
, y
);
1515 for (i
=0;i
<n
;i
++,ptr1
++) {
1516 index
[i
] = (GLuint
) *ptr1
;
1522 read_index_pixels( const GLcontext
*ctx
,
1523 GLuint n
, const GLint x
[], const GLint y
[],
1524 GLuint index
[], const GLubyte mask
[] )
1526 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1530 const GLchan
*ptr1
= PIXELADDR1(x
[i
], y
[i
]);
1531 index
[i
] = (GLuint
) *ptr1
;
1538 /**********************************************************************/
1539 /***** Optimized line rendering *****/
1540 /**********************************************************************/
1544 * Draw a flat-shaded, RGB line into an osmesa buffer.
1547 flat_rgba_line( GLcontext
*ctx
, const SWvertex
*vert0
, const SWvertex
*vert1
)
1549 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1550 const GLchan
*color
= vert0
->color
;
1554 #define PLOT(X, Y) \
1556 GLchan *p = PIXELADDR4(X, Y); \
1557 PACK_RGBA(p, color[0], color[1], color[2], color[3]); \
1561 #include "..\swrast\s_linetemp.h"
1563 #include "swrast/s_linetemp.h"
1569 * Draw a flat-shaded, Z-less, RGB line into an osmesa buffer.
1572 flat_rgba_z_line(GLcontext
*ctx
, const SWvertex
*vert0
, const SWvertex
*vert1
)
1574 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1575 const GLchan
*color
= vert0
->color
;
1579 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
1581 #define PLOT(X, Y) \
1584 GLchan *p = PIXELADDR4(X, Y); \
1585 PACK_RGBA(p, color[RCOMP], color[GCOMP], \
1586 color[BCOMP], color[ACOMP]); \
1593 #include "..\swrast\s_linetemp.h"
1595 #include "swrast/s_linetemp.h"
1601 * Draw a flat-shaded, alpha-blended, RGB line into an osmesa buffer.
1602 * XXX update for GLchan
1605 flat_blend_rgba_line( GLcontext
*ctx
,
1606 const SWvertex
*vert0
, const SWvertex
*vert1
)
1608 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1609 const GLint rshift
= osmesa
->rshift
;
1610 const GLint gshift
= osmesa
->gshift
;
1611 const GLint bshift
= osmesa
->bshift
;
1612 const GLint avalue
= vert0
->color
[3];
1613 const GLint msavalue
= CHAN_MAX
- avalue
;
1614 const GLint rvalue
= vert0
->color
[0]*avalue
;
1615 const GLint gvalue
= vert0
->color
[1]*avalue
;
1616 const GLint bvalue
= vert0
->color
[2]*avalue
;
1621 { GLuint *ptr4 = (GLuint *) PIXELADDR4(X, Y); \
1623 pixel |=((((((*ptr4) >> rshift) & 0xff)*msavalue+rvalue)>>8) << rshift);\
1624 pixel |=((((((*ptr4) >> gshift) & 0xff)*msavalue+gvalue)>>8) << gshift);\
1625 pixel |=((((((*ptr4) >> bshift) & 0xff)*msavalue+bvalue)>>8) << bshift);\
1630 #include "..\swrast\s_linetemp.h"
1632 #include "swrast/s_linetemp.h"
1638 * Draw a flat-shaded, Z-less, alpha-blended, RGB line into an osmesa buffer.
1639 * XXX update for GLchan
1642 flat_blend_rgba_z_line( GLcontext
*ctx
,
1643 const SWvertex
*vert0
, const SWvertex
*vert1
)
1645 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1646 const GLint rshift
= osmesa
->rshift
;
1647 const GLint gshift
= osmesa
->gshift
;
1648 const GLint bshift
= osmesa
->bshift
;
1649 const GLint avalue
= vert0
->color
[3];
1650 const GLint msavalue
= 256 - avalue
;
1651 const GLint rvalue
= vert0
->color
[0]*avalue
;
1652 const GLint gvalue
= vert0
->color
[1]*avalue
;
1653 const GLint bvalue
= vert0
->color
[2]*avalue
;
1657 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
1661 GLuint *ptr4 = (GLuint *) PIXELADDR4(X, Y); \
1663 pixel |=((((((*ptr4) >> rshift) & 0xff)*msavalue+rvalue)>>8) << rshift); \
1664 pixel |=((((((*ptr4) >> gshift) & 0xff)*msavalue+gvalue)>>8) << gshift); \
1665 pixel |=((((((*ptr4) >> bshift) & 0xff)*msavalue+bvalue)>>8) << bshift); \
1670 #include "..\swrast\s_linetemp.h"
1672 #include "swrast/s_linetemp.h"
1678 * Draw a flat-shaded, Z-less, alpha-blended, RGB line into an osmesa buffer.
1679 * XXX update for GLchan
1682 flat_blend_rgba_z_line_write( GLcontext
*ctx
,
1683 const SWvertex
*vert0
, const SWvertex
*vert1
)
1685 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1686 const GLint rshift
= osmesa
->rshift
;
1687 const GLint gshift
= osmesa
->gshift
;
1688 const GLint bshift
= osmesa
->bshift
;
1689 const GLint avalue
= vert0
->color
[3];
1690 const GLint msavalue
= 256 - avalue
;
1691 const GLint rvalue
= vert0
->color
[0]*avalue
;
1692 const GLint gvalue
= vert0
->color
[1]*avalue
;
1693 const GLint bvalue
= vert0
->color
[2]*avalue
;
1697 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
1701 GLuint *ptr4 = (GLuint *) PIXELADDR4(X, Y); \
1703 pixel |=((((((*ptr4) >> rshift) & 0xff)*msavalue+rvalue)>>8) << rshift); \
1704 pixel |=((((((*ptr4) >> gshift) & 0xff)*msavalue+gvalue)>>8) << gshift); \
1705 pixel |=((((((*ptr4) >> bshift) & 0xff)*msavalue+bvalue)>>8) << bshift); \
1711 #include "..\swrast\s_linetemp.h"
1713 #include "swrast/s_linetemp.h"
1719 * Analyze context state to see if we can provide a fast line drawing
1720 * function, like those in lines.c. Otherwise, return NULL.
1722 static swrast_line_func
1723 osmesa_choose_line_function( GLcontext
*ctx
)
1725 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1726 const SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
1728 if (CHAN_BITS
!= 8) return NULL
;
1729 if (ctx
->RenderMode
!= GL_RENDER
) return NULL
;
1730 if (ctx
->Line
.SmoothFlag
) return NULL
;
1731 if (ctx
->Texture
._ReallyEnabled
) return NULL
;
1732 if (ctx
->Light
.ShadeModel
!= GL_FLAT
) return NULL
;
1733 if (ctx
->Line
.Width
!= 1.0F
) return NULL
;
1734 if (ctx
->Line
.StippleFlag
) return NULL
;
1735 if (ctx
->Line
.SmoothFlag
) return NULL
;
1736 if (osmesa
->format
!= OSMESA_RGBA
&&
1737 osmesa
->format
!= OSMESA_BGRA
&&
1738 osmesa
->format
!= OSMESA_ARGB
) return NULL
;
1740 if (swrast
->_RasterMask
==DEPTH_BIT
1741 && ctx
->Depth
.Func
==GL_LESS
1742 && ctx
->Depth
.Mask
==GL_TRUE
1743 && ctx
->Visual
.depthBits
== DEFAULT_SOFTWARE_DEPTH_BITS
) {
1744 return flat_rgba_z_line
;
1747 if (swrast
->_RasterMask
== 0) {
1748 return flat_rgba_line
;
1751 if (swrast
->_RasterMask
==(DEPTH_BIT
|BLEND_BIT
)
1752 && ctx
->Depth
.Func
==GL_LESS
1753 && ctx
->Depth
.Mask
==GL_TRUE
1754 && ctx
->Visual
.depthBits
== DEFAULT_SOFTWARE_DEPTH_BITS
1755 && ctx
->Color
.BlendSrcRGB
==GL_SRC_ALPHA
1756 && ctx
->Color
.BlendDstRGB
==GL_ONE_MINUS_SRC_ALPHA
1757 && ctx
->Color
.BlendSrcA
==GL_SRC_ALPHA
1758 && ctx
->Color
.BlendDstA
==GL_ONE_MINUS_SRC_ALPHA
1759 && ctx
->Color
.BlendEquation
==GL_FUNC_ADD_EXT
) {
1760 return flat_blend_rgba_z_line_write
;
1763 if (swrast
->_RasterMask
==(DEPTH_BIT
|BLEND_BIT
)
1764 && ctx
->Depth
.Func
==GL_LESS
1765 && ctx
->Depth
.Mask
==GL_FALSE
1766 && ctx
->Visual
.depthBits
== DEFAULT_SOFTWARE_DEPTH_BITS
1767 && ctx
->Color
.BlendSrcRGB
==GL_SRC_ALPHA
1768 && ctx
->Color
.BlendDstRGB
==GL_ONE_MINUS_SRC_ALPHA
1769 && ctx
->Color
.BlendSrcA
==GL_SRC_ALPHA
1770 && ctx
->Color
.BlendDstA
==GL_ONE_MINUS_SRC_ALPHA
1771 && ctx
->Color
.BlendEquation
==GL_FUNC_ADD_EXT
) {
1772 return flat_blend_rgba_z_line
;
1775 if (swrast
->_RasterMask
==BLEND_BIT
1776 && ctx
->Color
.BlendSrcRGB
==GL_SRC_ALPHA
1777 && ctx
->Color
.BlendDstRGB
==GL_ONE_MINUS_SRC_ALPHA
1778 && ctx
->Color
.BlendSrcA
==GL_SRC_ALPHA
1779 && ctx
->Color
.BlendDstA
==GL_ONE_MINUS_SRC_ALPHA
1780 && ctx
->Color
.BlendEquation
==GL_FUNC_ADD_EXT
) {
1781 return flat_blend_rgba_line
;
1788 /**********************************************************************/
1789 /***** Optimized triangle rendering *****/
1790 /**********************************************************************/
1794 * Smooth-shaded, z-less triangle, RGBA color.
1796 static void smooth_rgba_z_triangle( GLcontext
*ctx
,
1799 const SWvertex
*v2
)
1801 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1804 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
1805 #define INTERP_RGB 1
1806 #define INTERP_ALPHA 1
1807 #define RENDER_SPAN( span ) \
1809 GLchan *img = PIXELADDR4(span.x, span.y); \
1810 for (i = 0; i < span.count; i++, img += 4) { \
1811 const GLdepth z = FixedToDepth(span.z); \
1812 if (z < zRow[i]) { \
1813 PACK_RGBA(img, FixedToChan(span.red), \
1814 FixedToChan(span.green), FixedToChan(span.blue), \
1815 FixedToChan(span.alpha)); \
1818 span.red += span.redStep; \
1819 span.green += span.greenStep; \
1820 span.blue += span.blueStep; \
1821 span.alpha += span.alphaStep; \
1822 span.z += span.zStep; \
1826 #include "..\swrast\s_tritemp.h"
1828 #include "swrast/s_tritemp.h"
1836 * Flat-shaded, z-less triangle, RGBA color.
1838 static void flat_rgba_z_triangle( GLcontext
*ctx
,
1841 const SWvertex
*v2
)
1843 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1845 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
1846 #define SETUP_CODE \
1848 PACK_RGBA((GLchan *) &pixel, v0->color[0], v0->color[1], \
1849 v0->color[2], v0->color[3]);
1851 #define RENDER_SPAN( span ) \
1853 GLuint *img = (GLuint *) PIXELADDR4(span.x, span.y); \
1854 for (i = 0; i < span.count; i++) { \
1855 const GLdepth z = FixedToDepth(span.z); \
1856 if (z < zRow[i]) { \
1860 span.z += span.zStep; \
1864 #include "..\swrast\s_tritemp.h"
1866 #include "swrast/s_tritemp.h"
1873 * Return pointer to an accelerated triangle function if possible.
1875 static swrast_tri_func
1876 osmesa_choose_triangle_function( GLcontext
*ctx
)
1878 const OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1879 const SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
1881 if (CHAN_BITS
!= 8) return (swrast_tri_func
) NULL
;
1882 if (ctx
->RenderMode
!= GL_RENDER
) return (swrast_tri_func
) NULL
;
1883 if (ctx
->Polygon
.SmoothFlag
) return (swrast_tri_func
) NULL
;
1884 if (ctx
->Polygon
.StippleFlag
) return (swrast_tri_func
) NULL
;
1885 if (ctx
->Texture
._ReallyEnabled
) return (swrast_tri_func
) NULL
;
1886 if (osmesa
->format
!= OSMESA_RGBA
&&
1887 osmesa
->format
!= OSMESA_BGRA
&&
1888 osmesa
->format
!= OSMESA_ARGB
) return (swrast_tri_func
) NULL
;
1890 if (swrast
->_RasterMask
== DEPTH_BIT
&&
1891 ctx
->Depth
.Func
== GL_LESS
&&
1892 ctx
->Depth
.Mask
== GL_TRUE
&&
1893 ctx
->Visual
.depthBits
== DEFAULT_SOFTWARE_DEPTH_BITS
) {
1894 if (ctx
->Light
.ShadeModel
== GL_SMOOTH
) {
1895 return smooth_rgba_z_triangle
;
1898 return flat_rgba_z_triangle
;
1901 return (swrast_tri_func
) NULL
;
1906 /* Override for the swrast triangle-selection function. Try to use one
1907 * of our internal triangle functions, otherwise fall back to the
1908 * standard swrast functions.
1910 static void osmesa_choose_triangle( GLcontext
*ctx
)
1912 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
1914 swrast
->Triangle
= osmesa_choose_triangle_function( ctx
);
1915 if (!swrast
->Triangle
)
1916 _swrast_choose_triangle( ctx
);
1919 static void osmesa_choose_line( GLcontext
*ctx
)
1921 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
1923 swrast
->Line
= osmesa_choose_line_function( ctx
);
1925 _swrast_choose_line( ctx
);
1929 #define OSMESA_NEW_LINE (_NEW_LINE | \
1934 _SWRAST_NEW_RASTERMASK)
1936 #define OSMESA_NEW_TRIANGLE (_NEW_POLYGON | \
1941 _SWRAST_NEW_RASTERMASK)
1944 /* Extend the software rasterizer with our line and triangle
1947 static void osmesa_register_swrast_functions( GLcontext
*ctx
)
1949 SWcontext
*swrast
= SWRAST_CONTEXT( ctx
);
1951 swrast
->choose_line
= osmesa_choose_line
;
1952 swrast
->choose_triangle
= osmesa_choose_triangle
;
1954 swrast
->invalidate_line
|= OSMESA_NEW_LINE
;
1955 swrast
->invalidate_triangle
|= OSMESA_NEW_TRIANGLE
;
1959 static const GLubyte
*get_string( GLcontext
*ctx
, GLenum name
)
1964 return (const GLubyte
*) "Mesa OffScreen";
1971 static void osmesa_update_state( GLcontext
*ctx
, GLuint new_state
)
1973 OSMesaContext osmesa
= OSMESA_CONTEXT(ctx
);
1974 struct swrast_device_driver
*swdd
= _swrast_GetDeviceDriverReference( ctx
);
1975 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
1977 ASSERT((void *) osmesa
== (void *) ctx
->DriverCtx
);
1980 * XXX these function pointers could be initialized just once during
1981 * context creation since they don't depend on any state changes.
1984 ctx
->Driver
.GetString
= get_string
;
1985 ctx
->Driver
.UpdateState
= osmesa_update_state
;
1986 ctx
->Driver
.SetDrawBuffer
= set_draw_buffer
;
1987 ctx
->Driver
.ResizeBuffersMESA
= _swrast_alloc_buffers
;
1988 ctx
->Driver
.GetBufferSize
= buffer_size
;
1990 ctx
->Driver
.Accum
= _swrast_Accum
;
1991 ctx
->Driver
.Bitmap
= _swrast_Bitmap
;
1992 ctx
->Driver
.Clear
= clear
;
1993 ctx
->Driver
.CopyPixels
= _swrast_CopyPixels
;
1994 ctx
->Driver
.DrawPixels
= _swrast_DrawPixels
;
1995 ctx
->Driver
.ReadPixels
= _swrast_ReadPixels
;
1997 ctx
->Driver
.ChooseTextureFormat
= _mesa_choose_tex_format
;
1998 ctx
->Driver
.TexImage1D
= _mesa_store_teximage1d
;
1999 ctx
->Driver
.TexImage2D
= _mesa_store_teximage2d
;
2000 ctx
->Driver
.TexImage3D
= _mesa_store_teximage3d
;
2001 ctx
->Driver
.TexSubImage1D
= _mesa_store_texsubimage1d
;
2002 ctx
->Driver
.TexSubImage2D
= _mesa_store_texsubimage2d
;
2003 ctx
->Driver
.TexSubImage3D
= _mesa_store_texsubimage3d
;
2004 ctx
->Driver
.TestProxyTexImage
= _mesa_test_proxy_teximage
;
2006 ctx
->Driver
.CopyTexImage1D
= _swrast_copy_teximage1d
;
2007 ctx
->Driver
.CopyTexImage2D
= _swrast_copy_teximage2d
;
2008 ctx
->Driver
.CopyTexSubImage1D
= _swrast_copy_texsubimage1d
;
2009 ctx
->Driver
.CopyTexSubImage2D
= _swrast_copy_texsubimage2d
;
2010 ctx
->Driver
.CopyTexSubImage3D
= _swrast_copy_texsubimage3d
;
2011 ctx
->Driver
.CopyColorTable
= _swrast_CopyColorTable
;
2012 ctx
->Driver
.CopyColorSubTable
= _swrast_CopyColorSubTable
;
2013 ctx
->Driver
.CopyConvolutionFilter1D
= _swrast_CopyConvolutionFilter1D
;
2014 ctx
->Driver
.CopyConvolutionFilter2D
= _swrast_CopyConvolutionFilter2D
;
2017 /* RGB(A) span/pixel functions */
2018 if (osmesa
->format
== OSMESA_RGB
) {
2019 swdd
->WriteRGBASpan
= write_rgba_span_RGB
;
2020 swdd
->WriteRGBSpan
= write_rgb_span_RGB
;
2021 swdd
->WriteMonoRGBASpan
= write_monocolor_span_RGB
;
2022 swdd
->WriteRGBAPixels
= write_rgba_pixels_RGB
;
2023 swdd
->WriteMonoRGBAPixels
= write_monocolor_pixels_RGB
;
2024 swdd
->ReadRGBASpan
= read_rgba_span3
;
2025 swdd
->ReadRGBAPixels
= read_rgba_pixels3
;
2027 else if (osmesa
->format
== OSMESA_BGR
) {
2028 swdd
->WriteRGBASpan
= write_rgba_span_BGR
;
2029 swdd
->WriteRGBSpan
= write_rgb_span_BGR
;
2030 swdd
->WriteMonoRGBASpan
= write_monocolor_span_BGR
;
2031 swdd
->WriteRGBAPixels
= write_rgba_pixels_BGR
;
2032 swdd
->WriteMonoRGBAPixels
= write_monocolor_pixels_BGR
;
2033 swdd
->ReadRGBASpan
= read_rgba_span3
;
2034 swdd
->ReadRGBAPixels
= read_rgba_pixels3
;
2036 else if (osmesa
->format
== OSMESA_RGB_565
) {
2037 swdd
->WriteRGBASpan
= write_rgba_span2
;
2038 swdd
->WriteRGBSpan
= write_rgb_span2
;
2039 swdd
->WriteMonoRGBASpan
= write_monocolor_span2
;
2040 swdd
->WriteRGBAPixels
= write_rgba_pixels2
;
2041 swdd
->WriteMonoRGBAPixels
= write_monocolor_pixels2
;
2042 swdd
->ReadRGBASpan
= read_rgba_span2
;
2043 swdd
->ReadRGBAPixels
= read_rgba_pixels2
;
2046 /* 4 GLchan / pixel in frame buffer */
2047 swdd
->WriteRGBSpan
= write_rgb_span
;
2048 swdd
->WriteRGBAPixels
= write_rgba_pixels
;
2049 swdd
->WriteMonoRGBASpan
= write_monocolor_span
;
2050 swdd
->WriteMonoRGBAPixels
= write_monocolor_pixels
;
2051 if (osmesa
->format
== OSMESA_RGBA
&&
2052 CHAN_TYPE
== GL_UNSIGNED_BYTE
&&
2053 RCOMP
==0 && GCOMP
==1 && BCOMP
==2 && ACOMP
==3) {
2054 /* special, fast case */
2055 swdd
->WriteRGBASpan
= write_rgba_span_rgba
;
2056 swdd
->ReadRGBASpan
= read_rgba_span_rgba
;
2059 swdd
->WriteRGBASpan
= write_rgba_span
;
2060 swdd
->ReadRGBASpan
= read_rgba_span
;
2062 swdd
->ReadRGBAPixels
= read_rgba_pixels
;
2065 /* CI span/pixel functions */
2066 swdd
->WriteCI32Span
= write_index32_span
;
2067 swdd
->WriteCI8Span
= write_index8_span
;
2068 swdd
->WriteMonoCISpan
= write_monoindex_span
;
2069 swdd
->WriteCI32Pixels
= write_index_pixels
;
2070 swdd
->WriteMonoCIPixels
= write_monoindex_pixels
;
2071 swdd
->ReadCI32Span
= read_index_span
;
2072 swdd
->ReadCI32Pixels
= read_index_pixels
;
2074 swdd
->SetReadBuffer
= set_read_buffer
;
2076 tnl
->Driver
.RunPipeline
= _tnl_run_pipeline
;
2078 _swrast_InvalidateState( ctx
, new_state
);
2079 _swsetup_InvalidateState( ctx
, new_state
);
2080 _ac_InvalidateState( ctx
, new_state
);
2081 _tnl_InvalidateState( ctx
, new_state
);