Changeset 3598 for trunk/src/opengl/mesa/osmesa.c
- Timestamp:
- May 23, 2000, 10:41:28 PM (25 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/opengl/mesa/osmesa.c
r2970 r3598 1 /* $Id: osmesa.c,v 1. 2 2000-03-02 13:27:30 sandervlExp $ */1 /* $Id: osmesa.c,v 1.3 2000-05-23 20:40:42 jeroen Exp $ */ 2 2 3 3 /* 4 4 * Mesa 3-D graphics library 5 * Version: 3. 15 * Version: 3.3 6 6 * 7 7 * Copyright (C) 1999 Brian Paul All Rights Reserved. … … 28 28 /* 29 29 * Off-Screen Mesa rendering / Rendering into client memory space 30 * 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 gl_make_current() and gl_get_current_context() 34 * functions. Those functions are thread-safe. 30 35 */ 31 32 #ifdef __WIN32OS2__33 #include <windows.h>34 #endif35 36 36 37 … … 38 39 #include "all.h" 39 40 #else 40 #include <stdlib.h> 41 #include <string.h> 41 #include "glheader.h" 42 42 #include "types.h" 43 43 #include "osmesa.h" … … 47 47 #include "matrix.h" 48 48 #include "vb.h" 49 #include "mem.h" 49 50 #endif 50 51 51 52 53 /* 54 * This is the OS/Mesa context struct. 55 * Notice how it includes a GLcontext. By doing this we're mimicking 56 * C++ inheritance/derivation. 57 * Later, we can cast a GLcontext pointer into an OSMesaContext pointer 58 * or vice versa. 59 */ 52 60 struct osmesa_context { 53 GLcontext *gl_ctx; /* The core GL/Mesa context*/61 GLcontext gl_ctx; /* The core GL/Mesa context */ 54 62 GLvisual *gl_visual; /* Describes the buffers */ 55 63 GLframebuffer *gl_buffer; /* Depth, stencil, accum, etc buffers */ … … 67 75 GLboolean yup; /* TRUE -> Y increases upward */ 68 76 /* FALSE -> Y increases downward */ 77 GLboolean bVisible; /* TRUE if geometry is visible */ 69 78 }; 70 79 71 72 73 #ifdef THREADS74 75 #include "mthreads.h" /* Mesa platform independent threads interface */76 77 static MesaTSD osmesa_ctx_tsd;78 79 static void osmesa_ctx_thread_init() {80 MesaInitTSD(&osmesa_ctx_tsd);81 }82 83 static OSMesaContext osmesa_get_thread_context( void ) {84 #ifdef __WIN32OS2__85 return (OSMesaContext) MesaGetTSD(&osmesa_ctx_tsd, osmesa_ctx_thread_init);86 #else87 return (OSMesaContext) MesaGetTSD(&osmesa_ctx_tsd);88 #endif89 }90 91 static void osmesa_set_thread_context( OSMesaContext ctx ) {92 MesaSetTSD(&osmesa_ctx_tsd, ctx, osmesa_ctx_thread_init);93 }94 95 96 #else97 /* One current context for address space, all threads */98 static OSMesaContext Current = NULL;99 #endif100 80 101 81 … … 120 100 * Return: an OSMesaContext or 0 if error 121 101 */ 122 OSMesaContext WIN32API OSMesaCreateContext( GLenum format, OSMesaContext sharelist ) 102 OSMesaContext GLAPIENTRY 103 OSMesaCreateContext( GLenum format, OSMesaContext sharelist ) 123 104 { 124 105 OSMesaContext osmesa; … … 227 208 GL_FALSE, /* double buffer */ 228 209 GL_FALSE, /* stereo */ 229 DE PTH_BITS,210 DEFAULT_SOFTWARE_DEPTH_BITS, 230 211 STENCIL_BITS, 231 ACCUM_BITS,212 rgbmode ? ACCUM_BITS : 0, 232 213 indexBits, 233 214 8, 8, 8, alphaBits ); … … 236 217 } 237 218 238 osmesa->gl_ctx = gl_create_context( osmesa->gl_visual, 239 sharelist ? sharelist->gl_ctx : (GLcontext *) NULL, 240 (void *) osmesa, GL_TRUE ); 241 if (!osmesa->gl_ctx) { 219 if (!gl_initialize_context_data(&osmesa->gl_ctx, 220 osmesa->gl_visual, 221 sharelist ? &sharelist->gl_ctx 222 : (GLcontext *) NULL, 223 (void *) osmesa, GL_TRUE )) { 242 224 gl_destroy_visual( osmesa->gl_visual ); 243 225 FREE(osmesa); 244 226 return NULL; 245 227 } 246 osmesa->gl_buffer = gl_create_framebuffer( osmesa->gl_visual ); 228 229 230 osmesa->gl_buffer = gl_create_framebuffer( osmesa->gl_visual, 231 osmesa->gl_visual->DepthBits > 0, 232 osmesa->gl_visual->StencilBits > 0, 233 osmesa->gl_visual->AccumBits > 0, 234 osmesa->gl_visual->AlphaBits > 0 ); 235 247 236 if (!osmesa->gl_buffer) { 248 237 gl_destroy_visual( osmesa->gl_visual ); 249 gl_ destroy_context(osmesa->gl_ctx );238 gl_free_context_data( &osmesa->gl_ctx ); 250 239 FREE(osmesa); 251 240 return NULL; … … 267 256 osmesa->gind = gind; 268 257 osmesa->bind = bind; 258 osmesa->bVisible = GL_FALSE; 269 259 } 270 260 return osmesa; … … 278 268 * Input: ctx - the context to destroy 279 269 */ 280 void WIN32APIOSMesaDestroyContext( OSMesaContext ctx )270 void GLAPIENTRY OSMesaDestroyContext( OSMesaContext ctx ) 281 271 { 282 272 if (ctx) { 283 273 gl_destroy_visual( ctx->gl_visual ); 284 274 gl_destroy_framebuffer( ctx->gl_buffer ); 285 gl_ destroy_context(ctx->gl_ctx );275 gl_free_context_data( &ctx->gl_ctx ); 286 276 FREE( ctx ); 287 277 } … … 377 367 * width>internal limit or height>internal limit. 378 368 */ 379 GLboolean WIN32API OSMesaMakeCurrent( OSMesaContext ctx, void *buffer, GLenum type, 380 GLsizei width, GLsizei height ) 369 GLboolean GLAPIENTRY 370 OSMesaMakeCurrent( OSMesaContext ctx, void *buffer, GLenum type, 371 GLsizei width, GLsizei height ) 381 372 { 382 373 if (!ctx || !buffer || type!=GL_UNSIGNED_BYTE … … 385 376 } 386 377 387 osmesa_update_state( ctx->gl_ctx );388 gl_make_current( ctx->gl_ctx, ctx->gl_buffer );378 osmesa_update_state( &ctx->gl_ctx ); 379 gl_make_current( &ctx->gl_ctx, ctx->gl_buffer ); 389 380 390 381 ctx->buffer = buffer; … … 396 387 ctx->rowlength = width; 397 388 398 #ifdef THREADS399 /* Set current context for the calling thread */400 osmesa_set_thread_context(ctx);401 #else402 /* Set current context for the address space, all threads */403 Current = ctx;404 #endif405 406 389 compute_row_addresses( ctx ); 407 390 408 391 /* init viewport */ 409 if (ctx->gl_ctx ->Viewport.Width==0) {392 if (ctx->gl_ctx.Viewport.Width==0) { 410 393 /* initialize viewport and scissor box to buffer size */ 411 gl_Viewport( ctx->gl_ctx,0, 0, width, height );412 ctx->gl_ctx ->Scissor.Width = width;413 ctx->gl_ctx ->Scissor.Height = height;394 _mesa_Viewport( 0, 0, width, height ); 395 ctx->gl_ctx.Scissor.Width = width; 396 ctx->gl_ctx.Scissor.Height = height; 414 397 } 415 398 … … 419 402 420 403 421 422 OSMesaContext WIN32API OSMesaGetCurrentContext( void ) 423 { 424 #ifdef THREADS 425 /* Return current handle for the calling thread */ 426 return osmesa_get_thread_context(); 427 #else 428 /* Return current handle for the address space, all threads */ 429 return Current; 430 #endif 431 } 432 433 434 435 void WIN32API OSMesaPixelStore( GLint pname, GLint value ) 404 OSMesaContext GLAPIENTRY OSMesaGetCurrentContext( void ) 405 { 406 GLcontext *ctx = gl_get_current_context(); 407 if (ctx) 408 return (OSMesaContext) ctx; 409 else 410 return NULL; 411 } 412 413 414 415 void GLAPIENTRY OSMesaPixelStore( GLint pname, GLint value ) 436 416 { 437 417 OSMesaContext ctx = OSMesaGetCurrentContext(); … … 440 420 case OSMESA_ROW_LENGTH: 441 421 if (value<0) { 442 gl_error( ctx->gl_ctx, GL_INVALID_VALUE,422 gl_error( &ctx->gl_ctx, GL_INVALID_VALUE, 443 423 "OSMesaPixelStore(value)" ); 444 424 return; … … 451 431 break; 452 432 default: 453 gl_error( ctx->gl_ctx, GL_INVALID_ENUM, "OSMesaPixelStore(pname)" );433 gl_error( &ctx->gl_ctx, GL_INVALID_ENUM, "OSMesaPixelStore(pname)" ); 454 434 return; 455 435 } … … 459 439 460 440 461 void WIN32APIOSMesaGetIntegerv( GLint pname, GLint *value )441 void GLAPIENTRY OSMesaGetIntegerv( GLint pname, GLint *value ) 462 442 { 463 443 OSMesaContext ctx = OSMesaGetCurrentContext(); … … 483 463 return; 484 464 default: 485 gl_error( ctx->gl_ctx, GL_INVALID_ENUM, "OSMesaGetIntergerv(pname)");465 gl_error(&ctx->gl_ctx, GL_INVALID_ENUM, "OSMesaGetIntergerv(pname)"); 486 466 return; 487 467 } 488 468 } 489 469 490 470 void GLAPIENTRY OSMesaGetBooleanv( GLint pname, GLboolean *value ) 471 { 472 OSMesaContext ctx = OSMesaGetCurrentContext(); 473 474 switch (pname) { 475 case OSMESA_OCCLUSION_TEST_RESULT_HP: 476 *value = ctx->bVisible; 477 ctx->bVisible = GL_FALSE; 478 return; 479 default: 480 gl_error(&ctx->gl_ctx, GL_INVALID_ENUM, "OSMesaGetBooleanv(pname)" ); 481 return; 482 } 483 } 491 484 492 485 /* … … 498 491 * Return: GL_TRUE or GL_FALSE to indicate success or failure. 499 492 */ 500 GLboolean WIN32APIOSMesaGetDepthBuffer( OSMesaContext c, GLint *width, GLint *height,493 GLboolean GLAPIENTRY OSMesaGetDepthBuffer( OSMesaContext c, GLint *width, GLint *height, 501 494 GLint *bytesPerValue, void **buffer ) 502 495 { 503 if ((!c->gl_buffer) || (!c->gl_buffer->Depth )) {496 if ((!c->gl_buffer) || (!c->gl_buffer->DepthBuffer)) { 504 497 *width = 0; 505 498 *height = 0; … … 512 505 *height = c->gl_buffer->Height; 513 506 *bytesPerValue = sizeof(GLdepth); 514 *buffer = c->gl_buffer->Depth ;507 *buffer = c->gl_buffer->DepthBuffer; 515 508 return GL_TRUE; 516 509 } … … 550 543 551 544 552 static GLboolean set_ buffer( GLcontext *ctx, GLenum mode )545 static GLboolean set_draw_buffer( GLcontext *ctx, GLenum mode ) 553 546 { 554 547 (void) ctx; … … 562 555 563 556 557 static void set_read_buffer( GLcontext *ctx, GLframebuffer *buffer, GLenum mode ) 558 { 559 /* separate read buffer not supported */ 560 ASSERT(buffer == ctx->DrawBuffer); 561 ASSERT(mode == GL_FRONT_LEFT); 562 } 563 564 564 565 static void clear_index( GLcontext *ctx, GLuint index ) 565 566 { 566 OSMesaContext osmesa = (OSMesaContext) ctx ->DriverCtx;567 OSMesaContext osmesa = (OSMesaContext) ctx; 567 568 osmesa->clearpixel = index; 568 569 } … … 573 574 GLubyte r, GLubyte g, GLubyte b, GLubyte a ) 574 575 { 575 OSMesaContext osmesa = (OSMesaContext) ctx ->DriverCtx;576 OSMesaContext osmesa = (OSMesaContext) ctx; 576 577 osmesa->clearpixel = PACK_RGBA( r, g, b, a ); 577 578 } … … 582 583 GLint x, GLint y, GLint width, GLint height ) 583 584 { 584 OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx; 585 if (mask & GL_COLOR_BUFFER_BIT) { 585 OSMesaContext osmesa = (OSMesaContext) ctx; 586 const GLuint *colorMask = (GLuint *) &ctx->Color.ColorMask; 587 588 /* we can't handle color or index masking */ 589 if (*colorMask != 0xffffffff || ctx->Color.IndexMask != 0xffffffff) 590 return mask; 591 592 /* sanity check - we only have a front-left buffer */ 593 ASSERT((mask & (DD_FRONT_RIGHT_BIT | DD_BACK_LEFT_BIT | DD_BACK_RIGHT_BIT)) == 0); 594 595 if (mask & DD_FRONT_LEFT_BIT) { 586 596 if (osmesa->format==OSMESA_COLOR_INDEX) { 587 597 if (all) { … … 656 666 } 657 667 } 658 return mask & (~GL_COLOR_BUFFER_BIT); 668 /* have Mesa clear all other buffers */ 669 return mask & (~DD_FRONT_LEFT_BIT); 659 670 } 660 671 … … 663 674 static void set_index( GLcontext *ctx, GLuint index ) 664 675 { 665 OSMesaContext osmesa = (OSMesaContext) ctx ->DriverCtx;676 OSMesaContext osmesa = (OSMesaContext) ctx; 666 677 osmesa->pixel = index; 667 678 } … … 672 683 GLubyte r, GLubyte g, GLubyte b, GLubyte a ) 673 684 { 674 OSMesaContext osmesa = (OSMesaContext) ctx ->DriverCtx;685 OSMesaContext osmesa = (OSMesaContext) ctx; 675 686 osmesa->pixel = PACK_RGBA( r, g, b, a ); 676 687 } … … 680 691 static void buffer_size( GLcontext *ctx, GLuint *width, GLuint *height ) 681 692 { 682 OSMesaContext osmesa = (OSMesaContext) ctx ->DriverCtx;693 OSMesaContext osmesa = (OSMesaContext) ctx; 683 694 *width = osmesa->width; 684 695 *height = osmesa->height; … … 695 706 CONST GLubyte rgba[][4], const GLubyte mask[] ) 696 707 { 697 OSMesaContext osmesa = (OSMesaContext) ctx ->DriverCtx;708 OSMesaContext osmesa = (OSMesaContext) ctx; 698 709 GLuint *ptr4 = PIXELADDR4( x, y ); 699 710 GLuint i; … … 702 713 GLint bshift = osmesa->bshift; 703 714 GLint ashift = osmesa->ashift; 715 osmesa->bVisible = GL_TRUE; /* if here, the occlusion test is misused */ 704 716 if (mask) { 705 717 for (i=0;i<n;i++,ptr4++) { … … 723 735 const GLubyte mask[] ) 724 736 { 725 OSMesaContext osmesa = (OSMesaContext) ctx ->DriverCtx;737 OSMesaContext osmesa = (OSMesaContext) ctx; 726 738 GLuint *ptr4 = PIXELADDR4( x, y ); 727 739 const GLuint *rgba4 = (const GLuint *) rgba; 728 740 GLuint i; 741 osmesa->bVisible = GL_TRUE; /* if here, the occlusion test is misused */ 729 742 if (mask) { 730 743 for (i=0;i<n;i++) { … … 745 758 CONST GLubyte rgb[][3], const GLubyte mask[] ) 746 759 { 747 OSMesaContext osmesa = (OSMesaContext) ctx ->DriverCtx;760 OSMesaContext osmesa = (OSMesaContext) ctx; 748 761 GLuint *ptr4 = PIXELADDR4( x, y ); 749 762 GLuint i; … … 752 765 GLint bshift = osmesa->bshift; 753 766 GLint ashift = osmesa->ashift; 767 osmesa->bVisible = GL_TRUE; /* if here, the occlusion test is misused */ 754 768 if (mask) { 755 769 for (i=0;i<n;i++,ptr4++) { … … 772 786 const GLubyte mask[] ) 773 787 { 774 OSMesaContext osmesa = (OSMesaContext) ctx ->DriverCtx;788 OSMesaContext osmesa = (OSMesaContext) ctx; 775 789 GLuint *ptr4 = PIXELADDR4(x,y); 776 790 GLuint i; 791 osmesa->bVisible = GL_TRUE; /* if here, the occlusion test is misused */ 777 792 for (i=0;i<n;i++,ptr4++) { 778 793 if (mask[i]) { … … 788 803 CONST GLubyte rgba[][4], const GLubyte mask[] ) 789 804 { 790 OSMesaContext osmesa = (OSMesaContext) ctx ->DriverCtx;805 OSMesaContext osmesa = (OSMesaContext) ctx; 791 806 GLuint i; 792 807 GLint rshift = osmesa->rshift; … … 794 809 GLint bshift = osmesa->bshift; 795 810 GLint ashift = osmesa->ashift; 811 osmesa->bVisible = GL_TRUE; /* if here, the occlusion test is misused */ 796 812 for (i=0;i<n;i++) { 797 813 if (mask[i]) { … … 808 824 const GLubyte mask[] ) 809 825 { 810 OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx; 811 GLuint i; 826 OSMesaContext osmesa = (OSMesaContext) ctx; 827 GLuint i; 828 osmesa->bVisible = GL_TRUE; /* if here, the occlusion test is misused */ 812 829 for (i=0;i<n;i++) { 813 830 if (mask[i]) { … … 822 839 GLubyte rgba[][4] ) 823 840 { 824 OSMesaContext osmesa = (OSMesaContext) ctx ->DriverCtx;841 OSMesaContext osmesa = (OSMesaContext) ctx; 825 842 GLuint i; 826 843 GLuint *ptr4 = PIXELADDR4(x,y); … … 840 857 GLubyte rgba[][4] ) 841 858 { 842 OSMesaContext osmesa = (OSMesaContext) ctx ->DriverCtx;859 OSMesaContext osmesa = (OSMesaContext) ctx; 843 860 GLuint *ptr4 = PIXELADDR4(x,y); 844 861 MEMCPY( rgba, ptr4, n * 4 * sizeof(GLubyte) ); … … 850 867 GLubyte rgba[][4], const GLubyte mask[] ) 851 868 { 852 OSMesaContext osmesa = (OSMesaContext) ctx ->DriverCtx;869 OSMesaContext osmesa = (OSMesaContext) ctx; 853 870 GLuint i; 854 871 for (i=0;i<n;i++) { … … 873 890 CONST GLubyte rgba[][4], const GLubyte mask[] ) 874 891 { 875 OSMesaContext osmesa = (OSMesaContext) ctx ->DriverCtx;892 OSMesaContext osmesa = (OSMesaContext) ctx; 876 893 GLubyte *ptr3 = PIXELADDR3( x, y); 877 894 GLuint i; … … 879 896 GLint gind = osmesa->gind; 880 897 GLint bind = osmesa->bind; 898 osmesa->bVisible = GL_TRUE; /* if here, the occlusion test is misused */ 881 899 if (mask) { 882 900 for (i=0;i<n;i++,ptr3+=3) { … … 902 920 CONST GLubyte rgb[][3], const GLubyte mask[] ) 903 921 { 904 OSMesaContext osmesa = (OSMesaContext) ctx ->DriverCtx;922 OSMesaContext osmesa = (OSMesaContext) ctx; 905 923 GLubyte *ptr3 = PIXELADDR3( x, y); 906 924 GLuint i; … … 908 926 GLint gind = osmesa->gind; 909 927 GLint bind = osmesa->bind; 928 osmesa->bVisible = GL_TRUE; /* if here, the occlusion test is misused */ 910 929 if (mask) { 911 930 for (i=0;i<n;i++,ptr3+=3) { … … 931 950 const GLubyte mask[] ) 932 951 { 933 OSMesaContext osmesa = (OSMesaContext) ctx ->DriverCtx;952 OSMesaContext osmesa = (OSMesaContext) ctx; 934 953 935 954 GLubyte rval = UNPACK_RED(osmesa->pixel); … … 943 962 GLubyte *ptr3 = PIXELADDR3( x, y); 944 963 GLuint i; 964 osmesa->bVisible = GL_TRUE; /* if here, the occlusion test is misused */ 945 965 for (i=0;i<n;i++,ptr3+=3) { 946 966 if (mask[i]) { … … 956 976 CONST GLubyte rgba[][4], const GLubyte mask[] ) 957 977 { 958 OSMesaContext osmesa = (OSMesaContext) ctx ->DriverCtx;978 OSMesaContext osmesa = (OSMesaContext) ctx; 959 979 GLuint i; 960 980 GLint rind = osmesa->rind; 961 981 GLint gind = osmesa->gind; 962 982 GLint bind = osmesa->bind; 963 983 osmesa->bVisible = GL_TRUE; /* if here, the occlusion test is misused */ 964 984 for (i=0;i<n;i++) { 965 985 if (mask[i]) { … … 976 996 const GLubyte mask[] ) 977 997 { 978 OSMesaContext osmesa = (OSMesaContext) ctx ->DriverCtx;998 OSMesaContext osmesa = (OSMesaContext) ctx; 979 999 GLuint i; 980 1000 GLint rind = osmesa->rind; … … 984 1004 GLubyte gval = UNPACK_GREEN(osmesa->pixel); 985 1005 GLubyte bval = UNPACK_BLUE(osmesa->pixel); 1006 osmesa->bVisible = GL_TRUE; /* if here, the occlusion test is misused */ 986 1007 for (i=0;i<n;i++) { 987 1008 if (mask[i]) { … … 998 1019 GLubyte rgba[][4] ) 999 1020 { 1000 OSMesaContext osmesa = (OSMesaContext) ctx ->DriverCtx;1021 OSMesaContext osmesa = (OSMesaContext) ctx; 1001 1022 GLuint i; 1002 1023 GLint rind = osmesa->rind; … … 1016 1037 GLubyte rgba[][4], const GLubyte mask[] ) 1017 1038 { 1018 OSMesaContext osmesa = (OSMesaContext) ctx ->DriverCtx;1039 OSMesaContext osmesa = (OSMesaContext) ctx; 1019 1040 GLuint i; 1020 1041 GLint rind = osmesa->rind; … … 1042 1063 const GLuint index[], const GLubyte mask[] ) 1043 1064 { 1044 OSMesaContext osmesa = (OSMesaContext) ctx ->DriverCtx;1065 OSMesaContext osmesa = (OSMesaContext) ctx; 1045 1066 GLubyte *ptr1 = PIXELADDR1(x,y); 1046 1067 GLuint i; 1068 osmesa->bVisible = GL_TRUE; /* if here, the occlusion test is misused */ 1047 1069 if (mask) { 1048 1070 for (i=0;i<n;i++,ptr1++) { … … 1065 1087 const GLubyte index[], const GLubyte mask[] ) 1066 1088 { 1067 OSMesaContext osmesa = (OSMesaContext) ctx ->DriverCtx;1089 OSMesaContext osmesa = (OSMesaContext) ctx; 1068 1090 GLubyte *ptr1 = PIXELADDR1(x,y); 1069 1091 GLuint i; 1092 osmesa->bVisible = GL_TRUE; /* if here, the occlusion test is misused */ 1070 1093 if (mask) { 1071 1094 for (i=0;i<n;i++,ptr1++) { … … 1085 1108 const GLubyte mask[] ) 1086 1109 { 1087 OSMesaContext osmesa = (OSMesaContext) ctx ->DriverCtx;1110 OSMesaContext osmesa = (OSMesaContext) ctx; 1088 1111 GLubyte *ptr1 = PIXELADDR1(x,y); 1089 1112 GLuint i; 1113 osmesa->bVisible = GL_TRUE; /* if here, the occlusion test is misused */ 1090 1114 for (i=0;i<n;i++,ptr1++) { 1091 1115 if (mask[i]) { … … 1100 1124 const GLuint index[], const GLubyte mask[] ) 1101 1125 { 1102 OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx; 1103 GLuint i; 1126 OSMesaContext osmesa = (OSMesaContext) ctx; 1127 GLuint i; 1128 osmesa->bVisible = GL_TRUE; /* if here, the occlusion test is misused */ 1104 1129 for (i=0;i<n;i++) { 1105 1130 if (mask[i]) { … … 1115 1140 const GLubyte mask[] ) 1116 1141 { 1117 OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx; 1118 GLuint i; 1142 OSMesaContext osmesa = (OSMesaContext) ctx; 1143 GLuint i; 1144 osmesa->bVisible = GL_TRUE; /* if here, the occlusion test is misused */ 1119 1145 for (i=0;i<n;i++) { 1120 1146 if (mask[i]) { … … 1129 1155 GLuint n, GLint x, GLint y, GLuint index[] ) 1130 1156 { 1131 OSMesaContext osmesa = (OSMesaContext) ctx ->DriverCtx;1157 OSMesaContext osmesa = (OSMesaContext) ctx; 1132 1158 GLuint i; 1133 1159 GLubyte *ptr1 = PIXELADDR1(x,y); … … 1142 1168 GLuint index[], const GLubyte mask[] ) 1143 1169 { 1144 OSMesaContext osmesa = (OSMesaContext) ctx ->DriverCtx;1170 OSMesaContext osmesa = (OSMesaContext) ctx; 1145 1171 GLuint i; 1146 1172 for (i=0;i<n;i++) { … … 1165 1191 GLuint vert0, GLuint vert1, GLuint pvert ) 1166 1192 { 1167 OSMesaContext osmesa = (OSMesaContext) ctx ->DriverCtx;1193 OSMesaContext osmesa = (OSMesaContext) ctx; 1168 1194 GLubyte *color = ctx->VB->ColorPtr->data[pvert]; 1169 1195 unsigned long pixel = PACK_RGBA( color[0], color[1], color[2], color[3] ); 1196 osmesa->bVisible = GL_TRUE; /* if here, the occlusion test is misused */ 1170 1197 1171 1198 #define INTERP_XY 1 … … 1187 1214 GLuint vert0, GLuint vert1, GLuint pvert ) 1188 1215 { 1189 OSMesaContext osmesa = (OSMesaContext) ctx ->DriverCtx;1216 OSMesaContext osmesa = (OSMesaContext) ctx; 1190 1217 GLubyte *color = ctx->VB->ColorPtr->data[pvert]; 1191 1218 unsigned long pixel = PACK_RGBA( color[0], color[1], color[2], color[3] ); 1219 osmesa->bVisible = GL_TRUE; /* if here, the occlusion test is misused */ 1192 1220 1193 1221 #define INTERP_XY 1 1194 1222 #define INTERP_Z 1 1223 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE 1195 1224 #define CLIP_HACK 1 1196 1225 #define PLOT(X,Y) \ … … 1215 1244 GLuint vert0, GLuint vert1, GLuint pvert ) 1216 1245 { 1217 OSMesaContext osmesa = (OSMesaContext) ctx ->DriverCtx;1246 OSMesaContext osmesa = (OSMesaContext) ctx; 1218 1247 struct vertex_buffer *VB = ctx->VB; 1219 1248 GLint rshift = osmesa->rshift; … … 1225 1254 GLint gvalue = VB->ColorPtr->data[pvert][1]*avalue; 1226 1255 GLint bvalue = VB->ColorPtr->data[pvert][2]*avalue; 1256 osmesa->bVisible = GL_TRUE; /* if here, the occlusion test is misused */ 1227 1257 1228 1258 #define INTERP_XY 1 … … 1244 1274 } 1245 1275 1276 1246 1277 /* 1247 1278 * Draw a flat-shaded, Z-less, alpha-blended, RGB line into an osmesa buffer. … … 1250 1281 GLuint vert0, GLuint vert1, GLuint pvert ) 1251 1282 { 1252 OSMesaContext osmesa = (OSMesaContext) ctx ->DriverCtx;1283 OSMesaContext osmesa = (OSMesaContext) ctx; 1253 1284 struct vertex_buffer *VB = ctx->VB; 1254 1285 GLint rshift = osmesa->rshift; … … 1260 1291 GLint gvalue = VB->ColorPtr->data[pvert][1]*avalue; 1261 1292 GLint bvalue = VB->ColorPtr->data[pvert][2]*avalue; 1293 osmesa->bVisible = GL_TRUE; /* if here, the occlusion test is misused */ 1262 1294 1263 1295 #define INTERP_XY 1 1264 1296 #define INTERP_Z 1 1297 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE 1265 1298 #define CLIP_HACK 1 1266 #define PLOT(X,Y) \ 1267 if (Z < *zPtr) { \ 1268 { GLuint *ptr4 = PIXELADDR4(X,Y); \ 1269 GLuint pixel = 0; \ 1270 pixel |=((((((*ptr4) >> rshift) & 0xff)*msavalue+rvalue)>>8) << rshift);\ 1271 pixel |=((((((*ptr4) >> gshift) & 0xff)*msavalue+gvalue)>>8) << gshift);\ 1272 pixel |=((((((*ptr4) >> bshift) & 0xff)*msavalue+bvalue)>>8) << bshift);\ 1273 *ptr4 = pixel; \ 1274 } \ 1299 #define PLOT(X,Y) \ 1300 if (Z < *zPtr) { \ 1301 GLuint *ptr4 = PIXELADDR4(X,Y); \ 1302 GLuint pixel = 0; \ 1303 pixel |=((((((*ptr4) >> rshift) & 0xff)*msavalue+rvalue)>>8) << rshift); \ 1304 pixel |=((((((*ptr4) >> gshift) & 0xff)*msavalue+gvalue)>>8) << gshift); \ 1305 pixel |=((((((*ptr4) >> bshift) & 0xff)*msavalue+bvalue)>>8) << bshift); \ 1306 *ptr4 = pixel; \ 1275 1307 } 1276 1308 … … 1282 1314 } 1283 1315 1316 1284 1317 /* 1285 1318 * Draw a flat-shaded, Z-less, alpha-blended, RGB line into an osmesa buffer. … … 1288 1321 GLuint vert0, GLuint vert1, GLuint pvert ) 1289 1322 { 1290 OSMesaContext osmesa = (OSMesaContext) ctx ->DriverCtx;1323 OSMesaContext osmesa = (OSMesaContext) ctx; 1291 1324 struct vertex_buffer *VB = ctx->VB; 1292 1325 GLint rshift = osmesa->rshift; … … 1298 1331 GLint gvalue = VB->ColorPtr->data[pvert][1]*avalue; 1299 1332 GLint bvalue = VB->ColorPtr->data[pvert][2]*avalue; 1333 osmesa->bVisible = GL_TRUE; /* if here, the occlusion test is misused */ 1300 1334 1301 1335 #define INTERP_XY 1 1302 1336 #define INTERP_Z 1 1337 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE 1303 1338 #define CLIP_HACK 1 1304 #define PLOT(X,Y) \ 1305 if (Z < *zPtr) { \ 1306 { GLuint *ptr4 = PIXELADDR4(X,Y); \ 1307 GLuint pixel = 0; \ 1308 pixel |=((((((*ptr4) >> rshift) & 0xff)*msavalue+rvalue)>>8) << rshift);\ 1309 pixel |=((((((*ptr4) >> gshift) & 0xff)*msavalue+gvalue)>>8) << gshift);\ 1310 pixel |=((((((*ptr4) >> bshift) & 0xff)*msavalue+bvalue)>>8) << bshift);\ 1311 *ptr4 = pixel; \ 1312 } \ 1313 *zPtr = Z; \ 1339 #define PLOT(X,Y) \ 1340 if (Z < *zPtr) { \ 1341 GLuint *ptr4 = PIXELADDR4(X,Y); \ 1342 GLuint pixel = 0; \ 1343 pixel |=((((((*ptr4) >> rshift) & 0xff)*msavalue+rvalue)>>8) << rshift); \ 1344 pixel |=((((((*ptr4) >> gshift) & 0xff)*msavalue+gvalue)>>8) << gshift); \ 1345 pixel |=((((((*ptr4) >> bshift) & 0xff)*msavalue+bvalue)>>8) << bshift); \ 1346 *ptr4 = pixel; \ 1347 *zPtr = Z; \ 1314 1348 } 1315 1349 … … 1328 1362 static line_func choose_line_function( GLcontext *ctx ) 1329 1363 { 1330 OSMesaContext osmesa = (OSMesaContext) ctx ->DriverCtx;1364 OSMesaContext osmesa = (OSMesaContext) ctx; 1331 1365 1332 1366 if (ctx->Line.SmoothFlag) return NULL; … … 1339 1373 if (ctx->RasterMask==DEPTH_BIT 1340 1374 && ctx->Depth.Func==GL_LESS 1341 && ctx->Depth.Mask==GL_TRUE) { 1375 && ctx->Depth.Mask==GL_TRUE 1376 && ctx->Visual->DepthBits == DEFAULT_SOFTWARE_DEPTH_BITS) { 1342 1377 switch(osmesa->format) { 1343 1378 case OSMESA_RGBA: … … 1364 1399 && ctx->Depth.Func==GL_LESS 1365 1400 && ctx->Depth.Mask==GL_TRUE 1401 && ctx->Visual->DepthBits == DEFAULT_SOFTWARE_DEPTH_BITS 1366 1402 && ctx->Color.BlendSrcRGB==GL_SRC_ALPHA 1367 1403 && ctx->Color.BlendDstRGB==GL_ONE_MINUS_SRC_ALPHA … … 1382 1418 && ctx->Depth.Func==GL_LESS 1383 1419 && ctx->Depth.Mask==GL_FALSE 1420 && ctx->Visual->DepthBits == DEFAULT_SOFTWARE_DEPTH_BITS 1384 1421 && ctx->Color.BlendSrcRGB==GL_SRC_ALPHA 1385 1422 && ctx->Color.BlendDstRGB==GL_ONE_MINUS_SRC_ALPHA … … 1429 1466 GLuint v2, GLuint pv ) 1430 1467 { 1431 OSMesaContext osmesa = (OSMesaContext) ctx ->DriverCtx;1468 OSMesaContext osmesa = (OSMesaContext) ctx; 1432 1469 GLint rshift = osmesa->rshift; 1433 1470 GLint gshift = osmesa->gshift; … … 1435 1472 GLint ashift = osmesa->ashift; 1436 1473 (void) pv; 1474 osmesa->bVisible = GL_TRUE; /* if here, the occlusion test is misused */ 1437 1475 #define INTERP_Z 1 1476 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE 1438 1477 #define INTERP_RGB 1 1439 1478 #define INTERP_ALPHA 1 … … 1469 1508 GLuint v2, GLuint pv ) 1470 1509 { 1471 OSMesaContext osmesa = (OSMesaContext) ctx ->DriverCtx;1510 OSMesaContext osmesa = (OSMesaContext) ctx; 1472 1511 #define INTERP_Z 1 1512 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE 1473 1513 #define SETUP_CODE \ 1474 1514 GLubyte r = VB->ColorPtr->data[pv][0]; \ … … 1505 1545 static triangle_func choose_triangle_function( GLcontext *ctx ) 1506 1546 { 1507 OSMesaContext osmesa = (OSMesaContext) ctx ->DriverCtx;1547 OSMesaContext osmesa = (OSMesaContext) ctx; 1508 1548 1509 1549 if ((osmesa->format==OSMESA_RGB)||(osmesa->format==OSMESA_BGR)) return NULL; … … 1516 1556 && ctx->Depth.Func==GL_LESS 1517 1557 && ctx->Depth.Mask==GL_TRUE 1558 && ctx->Visual->DepthBits == DEFAULT_SOFTWARE_DEPTH_BITS 1518 1559 && osmesa->format!=OSMESA_COLOR_INDEX) { 1519 1560 if (ctx->Light.ShadeModel==GL_SMOOTH) { … … 1527 1568 } 1528 1569 1570 1571 1572 /**********************************************************************/ 1573 /***** Occlusion rendering routines *****/ 1574 /**********************************************************************/ 1575 1576 #define OCC_STD_MASK_TEST \ 1577 OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx; \ 1578 if (osmesa->bVisible) return; \ 1579 if (mask) { \ 1580 GLuint i; \ 1581 for (i=0;i<n;i++) if (mask[i]) { \ 1582 osmesa->bVisible = GL_TRUE; \ 1583 return; \ 1584 } \ 1585 } else { \ 1586 osmesa->bVisible = GL_TRUE; \ 1587 } \ 1588 return; 1589 1590 /** 1591 *** Color Index 1592 **/ 1593 1594 static void write_index32_span_occ( const GLcontext *ctx, 1595 GLuint n, GLint x, GLint y, 1596 const GLuint index[], const GLubyte mask[] ) 1597 { 1598 OCC_STD_MASK_TEST 1599 } 1600 1601 1602 static void write_index8_span_occ( const GLcontext *ctx, 1603 GLuint n, GLint x, GLint y, 1604 const GLubyte index[], const GLubyte mask[] ) 1605 { 1606 OCC_STD_MASK_TEST 1607 } 1608 1609 1610 static void write_monoindex_span_occ( const GLcontext *ctx, 1611 GLuint n, GLint x, GLint y, 1612 const GLubyte mask[] ) 1613 { 1614 OCC_STD_MASK_TEST 1615 } 1616 1617 1618 static void write_index_pixels_occ( const GLcontext *ctx, 1619 GLuint n, const GLint x[], const GLint y[], 1620 const GLuint index[], const GLubyte mask[] ) 1621 { 1622 OCC_STD_MASK_TEST 1623 } 1624 1625 1626 static void write_monoindex_pixels_occ( const GLcontext *ctx, 1627 GLuint n, const GLint x[], const GLint y[], 1628 const GLubyte mask[] ) 1629 { 1630 OCC_STD_MASK_TEST 1631 } 1632 1633 /** 1634 *** RGB/RGBA 1635 **/ 1636 static void write_rgba_span_occ( const GLcontext *ctx, 1637 GLuint n, GLint x, GLint y, 1638 CONST GLubyte rgba[][4], const GLubyte mask[] ) 1639 { 1640 OCC_STD_MASK_TEST 1641 } 1642 1643 1644 static void write_rgb_span_occ( const GLcontext *ctx, 1645 GLuint n, GLint x, GLint y, 1646 CONST GLubyte rgb[][3], 1647 const GLubyte mask[] ) 1648 { 1649 OCC_STD_MASK_TEST 1650 } 1651 1652 1653 static void write_rgba_pixels_occ( const GLcontext *ctx, 1654 GLuint n, const GLint x[], const GLint y[], 1655 CONST GLubyte rgba[][4], const GLubyte mask[] ) 1656 { 1657 OCC_STD_MASK_TEST 1658 } 1659 1660 1661 static void write_monocolor_span_occ( const GLcontext *ctx, 1662 GLuint n, GLint x, GLint y, 1663 const GLubyte mask[] ) 1664 { 1665 OCC_STD_MASK_TEST 1666 } 1667 1668 1669 static void write_monocolor_pixels_occ( const GLcontext *ctx, 1670 GLuint n, const GLint x[], const GLint y[], 1671 const GLubyte mask[] ) 1672 { 1673 OCC_STD_MASK_TEST 1674 } 1675 1676 1677 /** 1678 *** Line Drawing 1679 **/ 1680 static void line_occ( GLcontext *ctx, 1681 GLuint vert0, GLuint vert1, GLuint pvert ) 1682 { 1683 OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx; 1684 osmesa->bVisible = GL_TRUE; 1685 } 1686 1687 1688 static void line_z_occ( GLcontext *ctx, 1689 GLuint vert0, GLuint vert1, GLuint pvert ) 1690 { 1691 OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx; 1692 if (osmesa->bVisible) return; 1693 1694 #define INTERP_XY 1 1695 #define INTERP_Z 1 1696 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE 1697 #define CLIP_HACK 1 1698 #define PLOT(X,Y) \ 1699 if (Z < *zPtr) { \ 1700 osmesa->bVisible = GL_TRUE; \ 1701 return; \ 1702 } 1703 1704 #ifdef WIN32 1705 #include "..\linetemp.h" 1706 #else 1707 #include "linetemp.h" 1708 #endif 1709 } 1710 1711 1712 /** 1713 *** Triangle Drawing 1714 **/ 1715 static void triangle_occ( GLcontext *ctx, GLuint v0, GLuint v1, 1716 GLuint v2, GLuint pv ) 1717 { 1718 OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx; 1719 osmesa->bVisible = GL_TRUE; 1720 } 1721 1722 1723 static void triangle_z_occ( GLcontext *ctx, GLuint v0, GLuint v1, 1724 GLuint v2, GLuint pv ) 1725 { 1726 OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx; 1727 if (osmesa->bVisible) return; 1728 #define INTERP_Z 1 1729 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE 1730 #define INNER_LOOP( LEFT, RIGHT, Y ) \ 1731 { \ 1732 GLint i, len = RIGHT-LEFT; \ 1733 for (i=0;i<len;i++) { \ 1734 GLdepth z = FixedToDepth(ffz); \ 1735 if (z < zRow[i]) { \ 1736 osmesa->bVisible = GL_TRUE; \ 1737 return; \ 1738 } \ 1739 ffz += fdzdx; \ 1740 } \ 1741 } 1742 #ifdef WIN32 1743 #include "..\tritemp.h" 1744 #else 1745 #include "tritemp.h" 1746 #endif 1747 } 1529 1748 1530 1749 … … 1543 1762 static void osmesa_update_state( GLcontext *ctx ) 1544 1763 { 1545 OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx; 1764 OSMesaContext osmesa = (OSMesaContext) ctx; 1765 1766 ASSERT((void *) osmesa == (void *) ctx->DriverCtx); 1546 1767 1547 1768 ctx->Driver.GetString = get_string; 1548 1769 ctx->Driver.UpdateState = osmesa_update_state; 1549 1770 1550 ctx->Driver.SetBuffer = set_buffer; 1771 ctx->Driver.SetDrawBuffer = set_draw_buffer; 1772 ctx->Driver.SetReadBuffer = set_read_buffer; 1551 1773 ctx->Driver.Color = set_color; 1552 1774 ctx->Driver.Index = set_index; … … 1600 1822 ctx->Driver.ReadCI32Span = read_index_span; 1601 1823 ctx->Driver.ReadCI32Pixels = read_index_pixels; 1602 } 1824 1825 /* Occlusion test cases: 1826 * If no buffers have been selected for writing, 1827 * we swap in occlusion routines that: 1828 * (1) check the current flag and return if set 1829 * (2) set the flag if any pixel would be updated 1830 * Note: all the other buffer writing routines will 1831 * always set the visible flag so in cases of "improper" 1832 * extension use will just cause unnecessary rasterization 1833 * to occur. The image will be correct in any case. 1834 */ 1835 if ((ctx->Color.IndexMask == 0) && 1836 (ctx->Color.ColorMask[0] == 0) && 1837 (ctx->Color.ColorMask[1] == 0) && 1838 (ctx->Color.ColorMask[2] == 0) && 1839 (ctx->Color.ColorMask[3] == 0) && 1840 (ctx->Stencil.Enabled == GL_FALSE)) { 1841 1842 /* XXX depth.func == GL_LESS ? */ 1843 1844 ctx->Driver.WriteCI32Span = write_index32_span_occ; 1845 ctx->Driver.WriteCI8Span = write_index8_span_occ; 1846 ctx->Driver.WriteMonoCISpan = write_monoindex_span_occ; 1847 ctx->Driver.WriteCI32Pixels = write_index_pixels_occ; 1848 ctx->Driver.WriteMonoCIPixels = write_monoindex_pixels_occ; 1849 1850 ctx->Driver.WriteRGBASpan = write_rgba_span_occ; 1851 ctx->Driver.WriteRGBSpan = write_rgb_span_occ; 1852 ctx->Driver.WriteRGBAPixels = write_rgba_pixels_occ; 1853 ctx->Driver.WriteMonoRGBASpan = write_monocolor_span_occ; 1854 ctx->Driver.WriteMonoRGBAPixels = write_monocolor_pixels_occ; 1855 1856 if (ctx->RasterMask & DEPTH_BIT) { 1857 ctx->Driver.LineFunc = line_z_occ; 1858 ctx->Driver.TriangleFunc = triangle_z_occ; 1859 } else { 1860 ctx->Driver.LineFunc = line_occ; 1861 ctx->Driver.TriangleFunc = triangle_occ; 1862 } 1863 } 1864 }
Note:
See TracChangeset
for help on using the changeset viewer.