Ignore:
Timestamp:
May 23, 2000, 10:41:28 PM (25 years ago)
Author:
jeroen
Message:

* empty log message *

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 sandervl Exp $ */
     1/* $Id: osmesa.c,v 1.3 2000-05-23 20:40:42 jeroen Exp $ */
    22
    33/*
    44 * Mesa 3-D graphics library
    5  * Version:  3.1
     5 * Version:  3.3
    66 *
    77 * Copyright (C) 1999  Brian Paul   All Rights Reserved.
     
    2828/*
    2929 * 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.
    3035 */
    31 
    32 #ifdef __WIN32OS2__
    33 #include <windows.h>
    34 #endif
    3536
    3637
     
    3839#include "all.h"
    3940#else
    40 #include <stdlib.h>
    41 #include <string.h>
     41#include "glheader.h"
    4242#include "types.h"
    4343#include "osmesa.h"
     
    4747#include "matrix.h"
    4848#include "vb.h"
     49#include "mem.h"
    4950#endif
    5051
    5152
     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 */
    5260struct osmesa_context {
    53    GLcontext *gl_ctx;           /* The core GL/Mesa context */
     61   GLcontext gl_ctx;            /* The core GL/Mesa context        */
    5462   GLvisual *gl_visual;         /* Describes the buffers */
    5563   GLframebuffer *gl_buffer;    /* Depth, stencil, accum, etc buffers */
     
    6775   GLboolean yup;               /* TRUE  -> Y increases upward */
    6876                                /* FALSE -> Y increases downward */
     77   GLboolean bVisible;          /* TRUE if geometry is visible */
    6978};
    7079
    71 
    72 
    73 #ifdef THREADS
    74 
    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 #else
    87   return (OSMesaContext) MesaGetTSD(&osmesa_ctx_tsd);
    88 #endif
    89 }
    90 
    91 static void osmesa_set_thread_context( OSMesaContext ctx ) {
    92   MesaSetTSD(&osmesa_ctx_tsd, ctx, osmesa_ctx_thread_init);
    93 }
    94 
    95 
    96 #else
    97    /* One current context for address space, all threads */
    98    static OSMesaContext Current = NULL;
    99 #endif
    10080
    10181
     
    120100 * Return:  an OSMesaContext or 0 if error
    121101 */
    122 OSMesaContext WIN32API OSMesaCreateContext( GLenum format, OSMesaContext sharelist )
     102OSMesaContext GLAPIENTRY
     103OSMesaCreateContext( GLenum format, OSMesaContext sharelist )
    123104{
    124105   OSMesaContext osmesa;
     
    227208                                            GL_FALSE,   /* double buffer */
    228209                                            GL_FALSE,   /* stereo */
    229                                             DEPTH_BITS,
     210                                            DEFAULT_SOFTWARE_DEPTH_BITS,
    230211                                            STENCIL_BITS,
    231                                             ACCUM_BITS,
     212                                            rgbmode ? ACCUM_BITS : 0,
    232213                                            indexBits,
    233214                                            8, 8, 8, alphaBits );
     
    236217      }
    237218
    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 )) {
    242224         gl_destroy_visual( osmesa->gl_visual );
    243225         FREE(osmesa);
    244226         return NULL;
    245227      }
    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
    247236      if (!osmesa->gl_buffer) {
    248237         gl_destroy_visual( osmesa->gl_visual );
    249          gl_destroy_context( osmesa->gl_ctx );
     238         gl_free_context_data( &osmesa->gl_ctx );
    250239         FREE(osmesa);
    251240         return NULL;
     
    267256      osmesa->gind = gind;
    268257      osmesa->bind = bind;
     258      osmesa->bVisible = GL_FALSE;
    269259   }
    270260   return osmesa;
     
    278268 * Input:  ctx - the context to destroy
    279269 */
    280 void WIN32API OSMesaDestroyContext( OSMesaContext ctx )
     270void GLAPIENTRY OSMesaDestroyContext( OSMesaContext ctx )
    281271{
    282272   if (ctx) {
    283273      gl_destroy_visual( ctx->gl_visual );
    284274      gl_destroy_framebuffer( ctx->gl_buffer );
    285       gl_destroy_context( ctx->gl_ctx );
     275      gl_free_context_data( &ctx->gl_ctx );
    286276      FREE( ctx );
    287277   }
     
    377367 *          width>internal limit or height>internal limit.
    378368 */
    379 GLboolean WIN32API OSMesaMakeCurrent( OSMesaContext ctx, void *buffer, GLenum type,
    380                              GLsizei width, GLsizei height )
     369GLboolean GLAPIENTRY
     370OSMesaMakeCurrent( OSMesaContext ctx, void *buffer, GLenum type,
     371                   GLsizei width, GLsizei height )
    381372{
    382373   if (!ctx || !buffer || type!=GL_UNSIGNED_BYTE
     
    385376   }
    386377
    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 );
    389380
    390381   ctx->buffer = buffer;
     
    396387      ctx->rowlength = width;
    397388
    398 #ifdef THREADS
    399    /* Set current context for the calling thread */
    400    osmesa_set_thread_context(ctx);
    401 #else
    402    /* Set current context for the address space, all threads */
    403    Current = ctx;
    404 #endif
    405 
    406389   compute_row_addresses( ctx );
    407390
    408391   /* init viewport */
    409    if (ctx->gl_ctx->Viewport.Width==0) {
     392   if (ctx->gl_ctx.Viewport.Width==0) {
    410393      /* 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;
    414397   }
    415398
     
    419402
    420403
    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 )
     404OSMesaContext 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
     415void GLAPIENTRY OSMesaPixelStore( GLint pname, GLint value )
    436416{
    437417   OSMesaContext ctx = OSMesaGetCurrentContext();
     
    440420      case OSMESA_ROW_LENGTH:
    441421         if (value<0) {
    442             gl_error( ctx->gl_ctx, GL_INVALID_VALUE,
     422            gl_error( &ctx->gl_ctx, GL_INVALID_VALUE,
    443423                      "OSMesaPixelStore(value)" );
    444424            return;
     
    451431         break;
    452432      default:
    453          gl_error( ctx->gl_ctx, GL_INVALID_ENUM, "OSMesaPixelStore(pname)" );
     433         gl_error( &ctx->gl_ctx, GL_INVALID_ENUM, "OSMesaPixelStore(pname)" );
    454434         return;
    455435   }
     
    459439
    460440
    461 void WIN32API OSMesaGetIntegerv( GLint pname, GLint *value )
     441void GLAPIENTRY OSMesaGetIntegerv( GLint pname, GLint *value )
    462442{
    463443   OSMesaContext ctx = OSMesaGetCurrentContext();
     
    483463         return;
    484464      default:
    485          gl_error( ctx->gl_ctx, GL_INVALID_ENUM, "OSMesaGetIntergerv(pname)" );
     465         gl_error(&ctx->gl_ctx, GL_INVALID_ENUM, "OSMesaGetIntergerv(pname)");
    486466         return;
    487467   }
    488468}
    489469
    490 
     470void 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}
    491484
    492485/*
     
    498491 * Return:  GL_TRUE or GL_FALSE to indicate success or failure.
    499492 */
    500 GLboolean WIN32API OSMesaGetDepthBuffer( OSMesaContext c, GLint *width, GLint *height,
     493GLboolean GLAPIENTRY OSMesaGetDepthBuffer( OSMesaContext c, GLint *width, GLint *height,
    501494                                GLint *bytesPerValue, void **buffer )
    502495{
    503    if ((!c->gl_buffer) || (!c->gl_buffer->Depth)) {
     496   if ((!c->gl_buffer) || (!c->gl_buffer->DepthBuffer)) {
    504497      *width = 0;
    505498      *height = 0;
     
    512505      *height = c->gl_buffer->Height;
    513506      *bytesPerValue = sizeof(GLdepth);
    514       *buffer = c->gl_buffer->Depth;
     507      *buffer = c->gl_buffer->DepthBuffer;
    515508      return GL_TRUE;
    516509   }
     
    550543
    551544
    552 static GLboolean set_buffer( GLcontext *ctx, GLenum mode )
     545static GLboolean set_draw_buffer( GLcontext *ctx, GLenum mode )
    553546{
    554547   (void) ctx;
     
    562555
    563556
     557static 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
    564565static void clear_index( GLcontext *ctx, GLuint index )
    565566{
    566    OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx;
     567   OSMesaContext osmesa = (OSMesaContext) ctx;
    567568   osmesa->clearpixel = index;
    568569}
     
    573574                         GLubyte r, GLubyte g, GLubyte b, GLubyte a )
    574575{
    575    OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx;
     576   OSMesaContext osmesa = (OSMesaContext) ctx;
    576577   osmesa->clearpixel = PACK_RGBA( r, g, b, a );
    577578}
     
    582583                         GLint x, GLint y, GLint width, GLint height )
    583584{
    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) {
    586596      if (osmesa->format==OSMESA_COLOR_INDEX) {
    587597         if (all) {
     
    656666      }
    657667   }
    658    return mask & (~GL_COLOR_BUFFER_BIT);
     668   /* have Mesa clear all other buffers */
     669   return mask & (~DD_FRONT_LEFT_BIT);
    659670}
    660671
     
    663674static void set_index( GLcontext *ctx, GLuint index )
    664675{
    665    OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx;
     676   OSMesaContext osmesa = (OSMesaContext) ctx;
    666677   osmesa->pixel = index;
    667678}
     
    672683                       GLubyte r, GLubyte g, GLubyte b, GLubyte a )
    673684{
    674    OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx;
     685   OSMesaContext osmesa = (OSMesaContext) ctx;
    675686   osmesa->pixel = PACK_RGBA( r, g, b, a );
    676687}
     
    680691static void buffer_size( GLcontext *ctx, GLuint *width, GLuint *height )
    681692{
    682    OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx;
     693   OSMesaContext osmesa = (OSMesaContext) ctx;
    683694   *width = osmesa->width;
    684695   *height = osmesa->height;
     
    695706                             CONST GLubyte rgba[][4], const GLubyte mask[] )
    696707{
    697    OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx;
     708   OSMesaContext osmesa = (OSMesaContext) ctx;
    698709   GLuint *ptr4 = PIXELADDR4( x, y );
    699710   GLuint i;
     
    702713   GLint bshift = osmesa->bshift;
    703714   GLint ashift = osmesa->ashift;
     715   osmesa->bVisible = GL_TRUE; /* if here, the occlusion test is misused  */
    704716   if (mask) {
    705717      for (i=0;i<n;i++,ptr4++) {
     
    723735                                  const GLubyte mask[] )
    724736{
    725    OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx;
     737   OSMesaContext osmesa = (OSMesaContext) ctx;
    726738   GLuint *ptr4 = PIXELADDR4( x, y );
    727739   const GLuint *rgba4 = (const GLuint *) rgba;
    728740   GLuint i;
     741   osmesa->bVisible = GL_TRUE; /* if here, the occlusion test is misused  */
    729742   if (mask) {
    730743      for (i=0;i<n;i++) {
     
    745758                            CONST GLubyte rgb[][3], const GLubyte mask[] )
    746759{
    747    OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx;
     760   OSMesaContext osmesa = (OSMesaContext) ctx;
    748761   GLuint *ptr4 = PIXELADDR4( x, y );
    749762   GLuint i;
     
    752765   GLint bshift = osmesa->bshift;
    753766   GLint ashift = osmesa->ashift;
     767   osmesa->bVisible = GL_TRUE; /* if here, the occlusion test is misused  */
    754768   if (mask) {
    755769      for (i=0;i<n;i++,ptr4++) {
     
    772786                                  const GLubyte mask[] )
    773787{
    774    OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx;
     788   OSMesaContext osmesa = (OSMesaContext) ctx;
    775789   GLuint *ptr4 = PIXELADDR4(x,y);
    776790   GLuint i;
     791   osmesa->bVisible = GL_TRUE; /* if here, the occlusion test is misused  */
    777792   for (i=0;i<n;i++,ptr4++) {
    778793      if (mask[i]) {
     
    788803                               CONST GLubyte rgba[][4], const GLubyte mask[] )
    789804{
    790    OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx;
     805   OSMesaContext osmesa = (OSMesaContext) ctx;
    791806   GLuint i;
    792807   GLint rshift = osmesa->rshift;
     
    794809   GLint bshift = osmesa->bshift;
    795810   GLint ashift = osmesa->ashift;
     811   osmesa->bVisible = GL_TRUE; /* if here, the occlusion test is misused  */
    796812   for (i=0;i<n;i++) {
    797813      if (mask[i]) {
     
    808824                                    const GLubyte mask[] )
    809825{
    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  */
    812829   for (i=0;i<n;i++) {
    813830      if (mask[i]) {
     
    822839                             GLubyte rgba[][4] )
    823840{
    824    OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx;
     841   OSMesaContext osmesa = (OSMesaContext) ctx;
    825842   GLuint i;
    826843   GLuint *ptr4 = PIXELADDR4(x,y);
     
    840857                                 GLubyte rgba[][4] )
    841858{
    842    OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx;
     859   OSMesaContext osmesa = (OSMesaContext) ctx;
    843860   GLuint *ptr4 = PIXELADDR4(x,y);
    844861   MEMCPY( rgba, ptr4, n * 4 * sizeof(GLubyte) );
     
    850867                               GLubyte rgba[][4], const GLubyte mask[] )
    851868{
    852    OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx;
     869   OSMesaContext osmesa = (OSMesaContext) ctx;
    853870   GLuint i;
    854871   for (i=0;i<n;i++) {
     
    873890                              CONST GLubyte rgba[][4], const GLubyte mask[] )
    874891{
    875    OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx;
     892   OSMesaContext osmesa = (OSMesaContext) ctx;
    876893   GLubyte *ptr3 = PIXELADDR3( x, y);
    877894   GLuint i;
     
    879896   GLint gind = osmesa->gind;
    880897   GLint bind = osmesa->bind;
     898   osmesa->bVisible = GL_TRUE; /* if here, the occlusion test is misused  */
    881899   if (mask) {
    882900      for (i=0;i<n;i++,ptr3+=3) {
     
    902920                             CONST GLubyte rgb[][3], const GLubyte mask[] )
    903921{
    904    OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx;
     922   OSMesaContext osmesa = (OSMesaContext) ctx;
    905923   GLubyte *ptr3 = PIXELADDR3( x, y);
    906924   GLuint i;
     
    908926   GLint gind = osmesa->gind;
    909927   GLint bind = osmesa->bind;
     928   osmesa->bVisible = GL_TRUE; /* if here, the occlusion test is misused  */
    910929   if (mask) {
    911930      for (i=0;i<n;i++,ptr3+=3) {
     
    931950                                  const GLubyte mask[] )
    932951{
    933    OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx;
     952   OSMesaContext osmesa = (OSMesaContext) ctx;
    934953
    935954   GLubyte rval = UNPACK_RED(osmesa->pixel);
     
    943962   GLubyte *ptr3 = PIXELADDR3( x, y);
    944963   GLuint i;
     964   osmesa->bVisible = GL_TRUE; /* if here, the occlusion test is misused  */
    945965   for (i=0;i<n;i++,ptr3+=3) {
    946966      if (mask[i]) {
     
    956976                                CONST GLubyte rgba[][4], const GLubyte mask[] )
    957977{
    958    OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx;
     978   OSMesaContext osmesa = (OSMesaContext) ctx;
    959979   GLuint i;
    960980   GLint rind = osmesa->rind;
    961981   GLint gind = osmesa->gind;
    962982   GLint bind = osmesa->bind;
    963 
     983   osmesa->bVisible = GL_TRUE; /* if here, the occlusion test is misused  */
    964984   for (i=0;i<n;i++) {
    965985      if (mask[i]) {
     
    976996                                    const GLubyte mask[] )
    977997{
    978    OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx;
     998   OSMesaContext osmesa = (OSMesaContext) ctx;
    979999   GLuint i;
    9801000   GLint rind = osmesa->rind;
     
    9841004   GLubyte gval = UNPACK_GREEN(osmesa->pixel);
    9851005   GLubyte bval = UNPACK_BLUE(osmesa->pixel);
     1006   osmesa->bVisible = GL_TRUE; /* if here, the occlusion test is misused  */
    9861007   for (i=0;i<n;i++) {
    9871008      if (mask[i]) {
     
    9981019                             GLubyte rgba[][4] )
    9991020{
    1000    OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx;
     1021   OSMesaContext osmesa = (OSMesaContext) ctx;
    10011022   GLuint i;
    10021023   GLint rind = osmesa->rind;
     
    10161037                               GLubyte rgba[][4], const GLubyte mask[] )
    10171038{
    1018    OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx;
     1039   OSMesaContext osmesa = (OSMesaContext) ctx;
    10191040   GLuint i;
    10201041   GLint rind = osmesa->rind;
     
    10421063                                const GLuint index[], const GLubyte mask[] )
    10431064{
    1044    OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx;
     1065   OSMesaContext osmesa = (OSMesaContext) ctx;
    10451066   GLubyte *ptr1 = PIXELADDR1(x,y);
    10461067   GLuint i;
     1068   osmesa->bVisible = GL_TRUE; /* if here, the occlusion test is misused  */
    10471069   if (mask) {
    10481070      for (i=0;i<n;i++,ptr1++) {
     
    10651087                               const GLubyte index[], const GLubyte mask[] )
    10661088{
    1067    OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx;
     1089   OSMesaContext osmesa = (OSMesaContext) ctx;
    10681090   GLubyte *ptr1 = PIXELADDR1(x,y);
    10691091   GLuint i;
     1092   osmesa->bVisible = GL_TRUE; /* if here, the occlusion test is misused  */
    10701093   if (mask) {
    10711094      for (i=0;i<n;i++,ptr1++) {
     
    10851108                                  const GLubyte mask[] )
    10861109{
    1087    OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx;
     1110   OSMesaContext osmesa = (OSMesaContext) ctx;
    10881111   GLubyte *ptr1 = PIXELADDR1(x,y);
    10891112   GLuint i;
     1113   osmesa->bVisible = GL_TRUE; /* if here, the occlusion test is misused  */
    10901114   for (i=0;i<n;i++,ptr1++) {
    10911115      if (mask[i]) {
     
    11001124                                const GLuint index[], const GLubyte mask[] )
    11011125{
    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  */
    11041129   for (i=0;i<n;i++) {
    11051130      if (mask[i]) {
     
    11151140                                    const GLubyte mask[] )
    11161141{
    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  */
    11191145   for (i=0;i<n;i++) {
    11201146      if (mask[i]) {
     
    11291155                             GLuint n, GLint x, GLint y, GLuint index[] )
    11301156{
    1131    OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx;
     1157   OSMesaContext osmesa = (OSMesaContext) ctx;
    11321158   GLuint i;
    11331159   GLubyte *ptr1 = PIXELADDR1(x,y);
     
    11421168                               GLuint index[], const GLubyte mask[] )
    11431169{
    1144    OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx;
     1170   OSMesaContext osmesa = (OSMesaContext) ctx;
    11451171   GLuint i;
    11461172   for (i=0;i<n;i++) {
     
    11651191                            GLuint vert0, GLuint vert1, GLuint pvert )
    11661192{
    1167    OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx;
     1193   OSMesaContext osmesa = (OSMesaContext) ctx;
    11681194   GLubyte *color = ctx->VB->ColorPtr->data[pvert];
    11691195   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  */
    11701197
    11711198#define INTERP_XY 1
     
    11871214                              GLuint vert0, GLuint vert1, GLuint pvert )
    11881215{
    1189    OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx;
     1216   OSMesaContext osmesa = (OSMesaContext) ctx;
    11901217   GLubyte *color = ctx->VB->ColorPtr->data[pvert];
    11911218   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  */
    11921220
    11931221#define INTERP_XY 1
    11941222#define INTERP_Z 1
     1223#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
    11951224#define CLIP_HACK 1
    11961225#define PLOT(X,Y)                               \
     
    12151244                                  GLuint vert0, GLuint vert1, GLuint pvert )
    12161245{
    1217    OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx;
     1246   OSMesaContext osmesa = (OSMesaContext) ctx;
    12181247   struct vertex_buffer *VB = ctx->VB;
    12191248   GLint rshift = osmesa->rshift;
     
    12251254   GLint gvalue = VB->ColorPtr->data[pvert][1]*avalue;
    12261255   GLint bvalue = VB->ColorPtr->data[pvert][2]*avalue;
     1256   osmesa->bVisible = GL_TRUE; /* if here, the occlusion test is misused  */
    12271257
    12281258#define INTERP_XY 1
     
    12441274}
    12451275
     1276
    12461277/*
    12471278 * Draw a flat-shaded, Z-less, alpha-blended, RGB line into an osmesa buffer.
     
    12501281                                   GLuint vert0, GLuint vert1, GLuint pvert )
    12511282{
    1252    OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx;
     1283   OSMesaContext osmesa = (OSMesaContext) ctx;
    12531284   struct vertex_buffer *VB = ctx->VB;
    12541285   GLint rshift = osmesa->rshift;
     
    12601291   GLint gvalue = VB->ColorPtr->data[pvert][1]*avalue;
    12611292   GLint bvalue = VB->ColorPtr->data[pvert][2]*avalue;
     1293   osmesa->bVisible = GL_TRUE; /* if here, the occlusion test is misused  */
    12621294
    12631295#define INTERP_XY 1
    12641296#define INTERP_Z 1
     1297#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
    12651298#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;                                                               \
    12751307        }
    12761308
     
    12821314}
    12831315
     1316
    12841317/*
    12851318 * Draw a flat-shaded, Z-less, alpha-blended, RGB line into an osmesa buffer.
     
    12881321                                   GLuint vert0, GLuint vert1, GLuint pvert )
    12891322{
    1290    OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx;
     1323   OSMesaContext osmesa = (OSMesaContext) ctx;
    12911324   struct vertex_buffer *VB = ctx->VB;
    12921325   GLint rshift = osmesa->rshift;
     
    12981331   GLint gvalue = VB->ColorPtr->data[pvert][1]*avalue;
    12991332   GLint bvalue = VB->ColorPtr->data[pvert][2]*avalue;
     1333   osmesa->bVisible = GL_TRUE; /* if here, the occlusion test is misused  */
    13001334
    13011335#define INTERP_XY 1
    13021336#define INTERP_Z 1
     1337#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
    13031338#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;                                                                   \
    13141348        }
    13151349
     
    13281362static line_func choose_line_function( GLcontext *ctx )
    13291363{
    1330    OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx;
     1364   OSMesaContext osmesa = (OSMesaContext) ctx;
    13311365
    13321366   if (ctx->Line.SmoothFlag)              return NULL;
     
    13391373       if (ctx->RasterMask==DEPTH_BIT
    13401374           && 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) {
    13421377           switch(osmesa->format) {
    13431378                case OSMESA_RGBA:
     
    13641399           && ctx->Depth.Func==GL_LESS
    13651400           && ctx->Depth.Mask==GL_TRUE
     1401           && ctx->Visual->DepthBits == DEFAULT_SOFTWARE_DEPTH_BITS
    13661402           && ctx->Color.BlendSrcRGB==GL_SRC_ALPHA
    13671403           && ctx->Color.BlendDstRGB==GL_ONE_MINUS_SRC_ALPHA
     
    13821418           && ctx->Depth.Func==GL_LESS
    13831419           && ctx->Depth.Mask==GL_FALSE
     1420           && ctx->Visual->DepthBits == DEFAULT_SOFTWARE_DEPTH_BITS
    13841421           && ctx->Color.BlendSrcRGB==GL_SRC_ALPHA
    13851422           && ctx->Color.BlendDstRGB==GL_ONE_MINUS_SRC_ALPHA
     
    14291466                                    GLuint v2, GLuint pv )
    14301467{
    1431    OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx;
     1468   OSMesaContext osmesa = (OSMesaContext) ctx;
    14321469   GLint rshift = osmesa->rshift;
    14331470   GLint gshift = osmesa->gshift;
     
    14351472   GLint ashift = osmesa->ashift;
    14361473   (void) pv;
     1474   osmesa->bVisible = GL_TRUE; /* if here, the occlusion test is misused  */
    14371475#define INTERP_Z 1
     1476#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
    14381477#define INTERP_RGB 1
    14391478#define INTERP_ALPHA 1
     
    14691508                                   GLuint v2, GLuint pv )
    14701509{
    1471    OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx;
     1510   OSMesaContext osmesa = (OSMesaContext) ctx;
    14721511#define INTERP_Z 1
     1512#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
    14731513#define SETUP_CODE                      \
    14741514   GLubyte r = VB->ColorPtr->data[pv][0];       \
     
    15051545static triangle_func choose_triangle_function( GLcontext *ctx )
    15061546{
    1507    OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx;
     1547   OSMesaContext osmesa = (OSMesaContext) ctx;
    15081548
    15091549   if ((osmesa->format==OSMESA_RGB)||(osmesa->format==OSMESA_BGR)) return NULL;
     
    15161556       && ctx->Depth.Func==GL_LESS
    15171557       && ctx->Depth.Mask==GL_TRUE
     1558       && ctx->Visual->DepthBits == DEFAULT_SOFTWARE_DEPTH_BITS
    15181559       && osmesa->format!=OSMESA_COLOR_INDEX) {
    15191560      if (ctx->Light.ShadeModel==GL_SMOOTH) {
     
    15271568}
    15281569
     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
     1594static 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
     1602static 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
     1610static 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
     1618static 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
     1626static 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**/
     1636static 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
     1644static 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
     1653static 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
     1661static 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
     1669static 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**/
     1680static 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
     1688static 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**/
     1715static 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
     1723static 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}
    15291748
    15301749
     
    15431762static void osmesa_update_state( GLcontext *ctx )
    15441763{
    1545    OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx;
     1764   OSMesaContext osmesa = (OSMesaContext) ctx;
     1765
     1766   ASSERT((void *) osmesa == (void *) ctx->DriverCtx);
    15461767
    15471768   ctx->Driver.GetString = get_string;
    15481769   ctx->Driver.UpdateState = osmesa_update_state;
    15491770
    1550    ctx->Driver.SetBuffer = set_buffer;
     1771   ctx->Driver.SetDrawBuffer = set_draw_buffer;
     1772   ctx->Driver.SetReadBuffer = set_read_buffer;
    15511773   ctx->Driver.Color = set_color;
    15521774   ctx->Driver.Index = set_index;
     
    16001822   ctx->Driver.ReadCI32Span = read_index_span;
    16011823   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.