home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Amiga 5 / MA_Cover_5.iso / ppc / mesa / src / ddsample.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-01-31  |  20.3 KB  |  773 lines

  1. /* $Id: ddsample.c,v 1.5 1997/06/04 00:30:40 brianp Exp $ */
  2.  
  3. /*
  4.  * Mesa 3-D graphics library
  5.  * Version:  2.3
  6.  * Copyright (C) 1995-1997  Brian Paul
  7.  *
  8.  * This library is free software; you can redistribute it and/or
  9.  * modify it under the terms of the GNU Library General Public
  10.  * License as published by the Free Software Foundation; either
  11.  * version 2 of the License, or (at your option) any later version.
  12.  *
  13.  * This library is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16.  * Library General Public License for more details.
  17.  *
  18.  * You should have received a copy of the GNU Library General Public
  19.  * License along with this library; if not, write to the Free
  20.  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  */
  22.  
  23.  
  24. /*
  25.  * $Log: ddsample.c,v $
  26.  * Revision 1.5  1997/06/04 00:30:40  brianp
  27.  * replaced VB->Unclipped with VB->ClipMask
  28.  *
  29.  * Revision 1.4  1997/05/26 21:15:37  brianp
  30.  * now pass red/green/blue/alpha bits to gl_create_visual()
  31.  *
  32.  * Revision 1.3  1996/11/13 03:52:12  brianp
  33.  * updated comments
  34.  *
  35.  * Revision 1.2  1996/09/15 14:30:27  brianp
  36.  * updated for new GLframebuffer and GLvisual datatypes and functions
  37.  *
  38.  * Revision 1.1  1996/09/13 01:38:16  brianp
  39.  * Initial revision
  40.  *
  41.  */
  42.  
  43.  
  44.  
  45. /*
  46.  * This is a sample template for writing new Mesa device drivers.
  47.  * You'll have to rewrite all the pseudo code below.
  48.  *
  49.  * Let's say you're interfacing Mesa to a window/operating system
  50.  * called FOO.  Replace all occurances of FOOMesa with the real name
  51.  * you select for your interface  (i.e. XMesa, WMesa, AmigaMesa).
  52.  *
  53.  * You'll have to design an API for clients to use, defined in a
  54.  * header called Mesa/include/GL/FooMesa.h  Use the sample as an
  55.  * example.  The API should at least have functions for creating
  56.  * rendering contexts, binding rendering contexts to windows/frame
  57.  * buffers, etc.
  58.  * 
  59.  * Next, you'll have to write implementations for the device driver
  60.  * functions described in dd.h
  61.  *
  62.  * Note that you'll usually have to flip Y coordinates since Mesa's
  63.  * window coordinates start at the bottom and increase upward.  Most
  64.  * window system's Y-axis increases downward
  65.  *
  66.  * Functions marked OPTIONAL may be completely omitted by your driver.
  67.  *
  68.  * Your Makefile should compile this module along with the rest of
  69.  * the core Mesa library.
  70.  */
  71.  
  72.  
  73. #include <stdlib.h>
  74. #include "GL/FooMesa.h"
  75. #include "context.h"
  76. #include "types.h"
  77. #include "vb.h"
  78.  
  79.  
  80.  
  81. /*
  82.  * This struct describes the attributes (number of channels, video mode,
  83.  * bits per pixel, etc) for a drawable (window, screen, or frame buffer).
  84.  */
  85. struct foo_mesa_visual {
  86.    GLvisual *gl_visual;
  87.    GLboolean db_flag;        /* double buffered? */
  88.    GLboolean rgb_flag;        /* RGB mode? */
  89.    GLuint depth;        /* bits per pixel (1, 8, 24, etc) */
  90. };
  91.  
  92.  
  93. /*
  94.  * This struct is a wrapper for your system's notion of a window or
  95.  * frame buffer.  It's needed because most window systems don't have
  96.  * any notion of the Z buffers, stencil buffers, etc needed by Mesa.
  97.  */
  98. struct foo_mesa_buffer {
  99.    GLframebuffer *gl_buffer;    /* The depth, stencil, accum, etc buffers */
  100.    WindowType *the_window;    /* your window handle, etc */
  101. };
  102.  
  103.  
  104.  
  105. /*
  106.  * This struct contains all device-driver state information.  Think of it
  107.  * as an extension of the core GLcontext from types.h.
  108.  */
  109. struct foo_mesa_context {
  110.    GLcontext *gl_ctx;        /* the core library context */
  111.    FooMesaVisual visual;
  112.    FooMesaBuffer buffer;
  113.    unsigned long pixel;        /* current color index or RGBA pixel value */
  114.    unsigned long clearpixel;    /* pixel for clearing the color buffers */
  115.    /* etc... */
  116. };
  117.  
  118.  
  119.  
  120.  
  121. /**********************************************************************/
  122. /*****              Miscellaneous device driver funcs             *****/
  123. /**********************************************************************/
  124.  
  125.  
  126. static void finish( GLcontext *ctx )
  127. {
  128.    struct foo_mesa_context *foo = (struct foo_mesa_context *) ctx->DriverCtx;
  129.    /* OPTIONAL FUNCTION: implements glFinish if possible */
  130. }
  131.  
  132.  
  133.  
  134. static void flush( GLcontext *ctx )
  135. {
  136.    struct foo_mesa_context *foo = (struct foo_mesa_context *) ctx->DriverCtx;
  137.    /* OPTIONAL FUNCTION: implements glFlush if possible */
  138. }
  139.  
  140.  
  141.  
  142. static void clear_index( GLcontext *ctx, GLuint index )
  143. {
  144.    struct foo_mesa_context *foo = (struct foo_mesa_context *) ctx->DriverCtx;
  145.    /* implement glClearIndex */
  146.    /* usually just save the color index value in the foo struct */
  147. }
  148.  
  149.  
  150.  
  151. static void clear_color( GLcontext *ctx, GLubyte r, GLubyte g, GLubyte b, GLubyte a )
  152. {
  153.    struct foo_mesa_context *foo = (struct foo_mesa_context *) ctx->DriverCtx;
  154.    /* implement glClearColor */
  155.    /* color components are floats in [0,1] */
  156.    /* usually just save the value in the foo struct */
  157. }
  158.  
  159.  
  160.  
  161. static void clear( GLcontext *ctx,
  162.            GLboolean all, GLint x, GLint y, GLint width, GLint height )
  163. {
  164.    struct foo_mesa_context *foo = (struct foo_mesa_context *) ctx->DriverCtx;
  165. /*
  166.  * Clear the specified region of the current color buffer using the clear
  167.  * color or index as specified by one of the two functions above.
  168.  * If all==GL_TRUE, clear whole buffer, else just clear region defined
  169.  * by x,y,width,height
  170.  */
  171. }
  172.  
  173.  
  174.  
  175. static void set_index( GLcontext *ctx, GLuint index )
  176. {
  177.    struct foo_mesa_context *foo = (struct foo_mesa_context *) ctx->DriverCtx;
  178.    /* Set the current color index. */
  179. }
  180.  
  181.  
  182.  
  183. static void set_color( GLcontext *ctx, GLubyte r, GLubyte g, GLubyte b, GLubyte a )
  184. {
  185.    struct foo_mesa_context *foo = (struct foo_mesa_context *) ctx->DriverCtx;
  186.    /* Set the current RGBA color. */
  187.    /* r is in [0,ctx->Visual->RedScale]   */
  188.    /* g is in [0,ctx->Visual->GreenScale] */
  189.    /* b is in [0,ctx->Visual->BlueScale]  */
  190.    /* a is in [0,ctx->Visual->AlphaScale] */
  191. }
  192.  
  193.  
  194.  
  195. static GLboolean index_mask( GLcontext *ctx, GLuint mask )
  196. {
  197.    struct foo_mesa_context *foo = (struct foo_mesa_context *) ctx->DriverCtx;
  198.    /* OPTIONAL FUNCTION: implement glIndexMask if possible, else
  199.     * return GL_FALSE
  200.     */
  201. }
  202.  
  203.  
  204.  
  205. static GLboolean color_mask( GLcontext *ctx, 
  206.                              GLboolean rmask, GLboolean gmask,
  207.                              GLboolean bmask, GLboolean amask)
  208. {
  209.    struct foo_mesa_context *foo = (struct foo_mesa_context *) ctx->DriverCtx;
  210.    /* OPTIONAL FUNCTION: implement glColorMask if possible, else
  211.     * return GL_FALSE
  212.     */
  213. }
  214.  
  215.  
  216.  
  217. static GLboolean logicop( GLcontext *ctx, GLenum op )
  218. {
  219.    struct foo_mesa_context *foo = (struct foo_mesa_context *) ctx->DriverCtx;
  220.    /*
  221.     * OPTIONAL FUNCTION: 
  222.     * Implements glLogicOp if possible.  Return GL_TRUE if the device driver
  223.     * can perform the operation, otherwise return GL_FALSE.  If GL_FALSE
  224.     * is returned, the logic op will be done in software by Mesa.
  225.     */
  226. }
  227.  
  228.  
  229. static void dither( GLcontext *ctx, GLboolean enable )
  230. {
  231.    struct foo_mesa_context *foo = (struct foo_mesa_context *) ctx->DriverCtx;
  232.    /* OPTIONAL FUNCTION: enable/disable dithering if applicable */
  233. }
  234.  
  235.  
  236.  
  237. static GLboolean set_buffer( GLcontext *ctx, GLenum mode )
  238. {
  239.    struct foo_mesa_context *foo = (struct foo_mesa_context *) ctx->DriverCtx;
  240.    /* set the current drawing/reading buffer, return GL_TRUE or GL_FALSE */
  241.    /* for success/failure */
  242.    setup_DD_pointers( ctx );
  243. }
  244.  
  245.  
  246.  
  247. static void get_buffer_size( GLcontext *ctx, GLuint *width, GLuint *height )
  248. {
  249.    struct foo_mesa_context *foo = (struct foo_mesa_context *) ctx->DriverCtx;
  250.    /* return the width and height of the current buffer */
  251.    /* if anything special has to been done when the buffer/window is */
  252.    /* resized, do it now */
  253. }
  254.  
  255.  
  256.  
  257. /**********************************************************************/
  258. /*****           Accelerated point, line, triangle rendering      *****/
  259. /**********************************************************************/
  260.  
  261.  
  262. /* There may several functions like this, for different screen modes, etc */
  263. static void fast_points_function( GLcontext *ctx, GLuint first, GLuint last )
  264. {
  265.    struct vertex_buffer *VB = ctx->VB;
  266.  
  267.    /* Render a number of points by some hardware/OS accerated method */
  268.    if (VB->MonoColor) {
  269.       /* draw all points using the current color (set_color) */
  270.       for (i=first;i<=last;i++) {
  271.          if (VB->ClipMask[i]==0) {
  272.             /* compute window coordinate */
  273.             int x, y;
  274.             x =       (GLint) VB->Win[i][0];
  275.             y = FLIP( (GLint) VB->Win[i][1] );
  276.             PLOT_PIXEL( x, y, currentcolor );
  277.          }
  278.       }
  279.    }
  280.    else {
  281.       /* each point is a different color */
  282.       for (i=first;i<=last;i++) {
  283.          if (VB->ClipMask[i]==0) {
  284.             int x, y;
  285.             x =       (GLint) VB->Win[i][0];
  286.             y = FLIP( (GLint) VB->Win[i][1] );
  287.             PLOT_PIXEL( x, y, VB->Color[i] );
  288.          }
  289.       }
  290.    }
  291. }
  292.  
  293.  
  294.  
  295.  
  296. /* There may several functions like this, for different screen modes, etc */
  297. static void fast_line_function( GLcontext *ctx, GLuint v0, GLuint v1, GLuint pv )
  298. {
  299.    /* Render a line by some hardware/OS accerated method */
  300.    struct vertex_buffer *VB = ctx->VB;
  301.    int x0, y0, x1, y1;
  302.    unsigned long pixel;
  303.  
  304.    if (VB->MonoColor) {
  305.       pixel = current color;
  306.    }
  307.    else {
  308.       pixel = VB->Color[pv];
  309.    }
  310.  
  311.    x0 =       (int) VB->Win[v0][0];
  312.    y0 = FLIP( (int) VB->Win[v0][1] );
  313.    x1 =       (int) VB->Win[v1][0];
  314.    y1 = FLIP( (int) VB->Win[v1][1] );
  315.  
  316.    DRAW_LINE( x0,y0, x1,y1, pixel );
  317. }
  318.  
  319.  
  320.  
  321.  
  322. /* There may several functions like this, for different screen modes, etc */
  323. static void fast_triangle_function( GLcontext *ctx, GLuint v0,
  324.                                     GLuint v1, GLuint v2, GLuint pv )
  325. {
  326.    /* Render a triangle by some hardware/OS accerated method */
  327.    struct vertex_buffer *VB = ctx->VB;
  328.    int i;
  329.  
  330.    if (VB->MonoColor) {
  331.       pixel = current color or index;
  332.    }
  333.    else {
  334.       pixel = VB->Color[pv] or VB->Index[pv];
  335.    }
  336.  
  337.    DRAW_TRIANGLE( v0, v1, v2 );
  338. }
  339.  
  340.  
  341.  
  342.  
  343.  
  344.  
  345. /**********************************************************************/
  346. /*****            Write spans of pixels                           *****/
  347. /**********************************************************************/
  348.  
  349.  
  350. static void write_index_span( GLcontext *ctx,
  351.                               GLuint n, GLint x, GLint y,
  352.                               const GLuint index[],
  353.                               const GLubyte mask[] )
  354. {
  355.    int i;
  356.    for (i=0;i<n;i++) {
  357.       if (mask[i]) {
  358.          /* draw pixel (x[i],y[i]) using index[i] */
  359.       }
  360.    }
  361. }
  362.  
  363.  
  364.  
  365. static void write_monoindex_span( GLcontext *ctx,
  366.                                   GLuint n,GLint x,GLint y,const GLubyte mask[] )
  367. {
  368.    int i;
  369.    for (i=0;i<n;i++) {
  370.       if (mask[i]) {
  371.          /* draw pixel (x[i],y[i]) using current color index */
  372.       }
  373.    }
  374. }
  375.  
  376.  
  377.  
  378. static void write_color_span( GLcontext *ctx, 
  379.                               GLuint n, GLint x, GLint y,
  380.                               const GLubyte red[], const GLubyte green[],
  381.                               const GLubyte blue[], const GLubyte alpha[],
  382.                               const GLubyte mask[] )
  383. {
  384.    int i;
  385.    y=FLIP(y);
  386.    if (mask) {
  387.       /* draw some pixels */
  388.       for (i=0; i<n; i++, x++) {
  389.          if (mask[i]) {
  390.             /* draw pixel x,y using color red[i]/green[i]/blue[i]/alpha[i] */
  391.          }
  392.       }
  393.    }
  394.    else {
  395.       /* draw all pixels */
  396.       for (i=0; i<n; i++, x++) {
  397.          /* draw pixel x,y using color red[i]/green[i]/blue[i]/alpha[i] */
  398.       }
  399.    }
  400. }
  401.  
  402.  
  403.  
  404. static void write_monocolor_span( GLcontext *ctx,
  405.                                   GLuint n, GLint x, GLint y,
  406.                                   const GLubyte mask[])
  407. {
  408.    int i;
  409.    y=FLIP(y);
  410.    for (i=0; i<n; i++, x++) {
  411.       if (mask[i]) {
  412.          plot pixel (x,y) using current color
  413.       }
  414.    }
  415. }
  416.  
  417.  
  418.  
  419. /**********************************************************************/
  420. /*****                 Read spans of pixels                       *****/
  421. /**********************************************************************/
  422.  
  423.  
  424. static void read_index_span( GLcontext *ctx,
  425.                              GLuint n, GLint x, GLint y, GLuint index[])
  426. {
  427.    int i;
  428.    for (i=0; i<n; i++) {
  429.       index[i] = read_pixel(x[i],y[i]);
  430.    }
  431. }
  432.  
  433.  
  434.  
  435. static void read_color_span( GLcontext *ctx,
  436.                              GLuint n, GLint x, GLint y,
  437.                              GLubyte red[], GLubyte green[],
  438.                              GLubyte blue[], GLubyte alpha[] )
  439. {
  440.    int i;
  441.    for (i=0; i<n; i++, x++) {
  442.       red[i] = read_red( x, y );
  443.       green[i] = read_green( x, y );
  444.       /* etc */
  445.    }
  446. }
  447.  
  448.  
  449.  
  450. /**********************************************************************/
  451. /*****              Write arrays of pixels                        *****/
  452. /**********************************************************************/
  453.  
  454.  
  455. static void write_index_pixels( GLcontext *ctx,
  456.                                 GLuint n, const GLint x[], const GLint y[],
  457.                                 const GLuint index[], const GLubyte mask[] )
  458. {
  459.    int i;
  460.    for (i=0; i<n; i++) {
  461.       if (mask[i]) {
  462.          plot pixel x[i], y[i] using index[i]
  463.       }
  464.    }
  465. }
  466.  
  467.  
  468.  
  469. static void write_monoindex_pixels( GLcontext *ctx,
  470.                                     GLuint n,
  471.                                     const GLint x[], const GLint y[],
  472.                                     const GLubyte mask[] )
  473. {
  474.    int i;
  475.    for (i=0; i<n; i++) {
  476.       if (mask[i]) {
  477.          write pixel x[i], y[i] using current index
  478.       }
  479.    }
  480. }
  481.  
  482.  
  483.  
  484. static void write_color_pixels( GLcontext *ctx,
  485.                                 GLuint n, const GLint x[], const GLint y[],
  486.                                 const GLubyte r[], const GLubyte g[],
  487.                                 const GLubyte b[], const GLubyte a[],
  488.                                 const GLubyte mask[] )
  489. {
  490.    int i;
  491.    for (i=0; i<n; i++) {
  492.       if (mask[i]) {
  493.          write pixel x[i], y[i] using red[i],green[i],blue[i],alpha[i]
  494.       }
  495.    }
  496. }
  497.  
  498.  
  499.  
  500. static void write_monocolor_pixels( GLcontext *ctx,
  501.                                     GLuint n,
  502.                                     const GLint x[], const GLint y[],
  503.                                     const GLubyte mask[] )
  504. {
  505.    int i;
  506.    for (i=0; i<n; i++) {
  507.       if (mask[i]) {
  508.          write pixel x[i], y[i] using current color
  509.       }
  510.    }
  511. }
  512.  
  513.  
  514.  
  515.  
  516. /**********************************************************************/
  517. /*****                   Read arrays of pixels                    *****/
  518. /**********************************************************************/
  519.  
  520. /* Read an array of color index pixels. */
  521. static void read_index_pixels( GLcontext *ctx,
  522.                                GLuint n, const GLint x[], const GLint y[],
  523.                                GLuint indx[], const GLubyte mask[] )
  524. {
  525.   int i;
  526.   for (i=0; i<n; i++) {
  527.      if (mask[i]) {
  528.         index[i] = read_pixel( x[i], y[i] );
  529.      }
  530.   }
  531. }
  532.  
  533.  
  534.  
  535. static void read_color_pixels( GLcontext *ctx,
  536.                                GLuint n, const GLint x[], const GLint y[],
  537.                                GLubyte red[], GLubyte green[],
  538.                                GLubyte blue[], GLubyte alpha[],
  539.                                const GLubyte mask[] )
  540. {
  541.    int i;
  542.    for (i=0; i<n; i++) {
  543.       if (mask[i]) {
  544.          red[i] = read_red( x[i], y[i] );
  545.          green[i] = read_green( x[i], y[i] );
  546.          /* etc */
  547.       }
  548.    }
  549. }
  550.  
  551.  
  552.  
  553.  
  554. /**********************************************************************/
  555. /**********************************************************************/
  556.  
  557.  
  558. static void setup_DD_pointers( GLcontext *ctx )
  559. {
  560.    /* Initialize all the pointers in the DD struct.  Do this whenever */
  561.    /* a new context is made current or we change buffers via set_buffer! */
  562.  
  563.    ctx->Driver.UpdateState = setup_DD_pointers;
  564.  
  565.    ctx->Driver.ClearIndex = clear_index;
  566.    ctx->Driver.ClearColor = clear_color;
  567.    ctx->Driver.Clear = clear;
  568.  
  569.    ctx->Driver.Index = set_index;
  570.    ctx->Driver.Color = set_color;
  571.  
  572.    ctx->Driver.SetBuffer = set_buffer;
  573.    ctx->Driver.GetBufferSize = get_buffer_size;
  574.  
  575.    ctx->Driver.PointsFunc = fast_points_function;
  576.    ctx->Driver.LineFunc = fast_line_function;
  577.    ctx->Driver.TriangleFunc = fast_triangle_function;
  578.  
  579.    /* Pixel/span writing functions: */
  580.    ctx->Driver.WriteColorSpan       = write_color_span;
  581.    ctx->Driver.WriteMonocolorSpan   = write_monocolor_span;
  582.    ctx->Driver.WriteColorPixels     = write_color_pixels;
  583.    ctx->Driver.WriteMonocolorPixels = write_monocolor_pixels;
  584.    ctx->Driver.WriteIndexSpan       = write_index_span;
  585.    ctx->Driver.WriteMonoindexSpan   = write_monoindex_span;
  586.    ctx->Driver.WriteIndexPixels     = write_index_pixels;
  587.    ctx->Driver.WriteMonoindexPixels = write_monoindex_pixels;
  588.  
  589.    /* Pixel/span reading functions: */
  590.    ctx->Driver.ReadIndexSpan = read_index_span;
  591.    ctx->Driver.ReadColorSpan = read_color_span;
  592.    ctx->Driver.ReadIndexPixels = read_index_pixels;
  593.    ctx->Driver.ReadColorPixels = read_color_pixels;
  594.  
  595.  
  596.    /*
  597.     * OPTIONAL FUNCTIONS:  these may be left uninitialized if the device
  598.     * driver can't/needn't implement them.
  599.     */
  600. #if 0
  601.    ctx->Driver.Finish = finish;
  602.    ctx->Driver.Flush = flush;
  603.    ctx->Driver.IndexMask = index_mask;
  604.    ctx->Driver.ColorMask = color_mask;
  605.    ctx->Driver.LogicOp = logicop;
  606.    ctx->Driver.Dither = dither;
  607. #endif
  608. }
  609.  
  610.  
  611.  
  612. /**********************************************************************/
  613. /*****               FOO/Mesa API Functions                       *****/
  614. /**********************************************************************/
  615.  
  616.  
  617.  
  618. /*
  619.  * The exact arguments to this function will depend on your window system
  620.  */
  621. FooMesaVisual FooMesaCreateVisual( GLboolean rgb_mode, GLboolean db_flag,
  622.                                    /* etc... */ )
  623. {
  624.    FooMesaVisual v;
  625.    GLfloat redscale, greenscale, bluescale, alphascale;
  626.  
  627.    v = (FooMesaVisual) calloc( 1, sizeof(struct foo_mesa_visual) );
  628.    if (!v) {
  629.       return NULL;
  630.    }
  631.  
  632.    if (rgb_mode) {
  633.       /* RGB(A) mode */
  634.       redscale = ??;
  635.       greedscale = ??;
  636.       bluescale = ??;
  637.       alphascale = ??;
  638.       redbits = ??;
  639.       greenbits = ??;
  640.       bluebits = ??;
  641.       alphabits = ??;
  642.       index_bits = 0;
  643.    }
  644.    else {
  645.       /* color index mode */
  646.       redscale = 0.0;
  647.       greedscale = 0.0;
  648.       bluescale = 0.0;
  649.       alphascale = 0.0;
  650.       redbits = 0;
  651.       greenbits = 0;
  652.       bluebits = 0;
  653.       alphabits = 0;
  654.       index_bits = ??;
  655.    }
  656.  
  657.    /* Create core visual */
  658.    v->gl_visual = gl_create_visual( rgb_mode, 
  659.                                     alpha_flag,
  660.                                     db_flag,
  661.                                     depth_size,
  662.                                     stencil_size,
  663.                                     accum_size,
  664.                                     index_bits,
  665.                                     redscale, greenscale,
  666.                                     bluescale, alphascale,
  667.                                     redbits, greenbits, bluebits, alphabits;
  668.  
  669.    return v;
  670. }
  671.  
  672.  
  673.  
  674. void FooMesaDestroyVisual( FooMesaVisual v )
  675. {
  676.    gl_destroy_visual( v->gl_visual );
  677.    free( v );
  678. }
  679.  
  680.  
  681.  
  682.  
  683. FooMesaBuffer FooMesaCreateBuffer( FooMesaVisual visual,
  684.                                    int /* your window id */ )
  685. {
  686.    FooMesaBuffer b;
  687.  
  688.    b = (FooMesaBuffer) calloc( 1, sizeof(struct foo_mesa_buffer) );
  689.    if (!b) {
  690.       return NULL;
  691.    }
  692.  
  693.    b->gl_buffer = gl_create_buffer( visual->gl_visual, windowid, 0, 0 );
  694.  
  695.    /* other stuff */
  696.  
  697.    return b;
  698. }
  699.  
  700.  
  701.  
  702. void FooMesaDestroyBuffer( FooMesaBuffer b )
  703. {
  704.    gl_destroy_buffer( b->gl_buffer );
  705.    free( b );
  706. }
  707.  
  708.  
  709.  
  710.  
  711. FooMesaContext FooMesaCreateContext( FooMesaVisual visual,
  712.                                      FooMesaContext share )
  713. {
  714.    FooMesaContext c;
  715.  
  716.    c = (FooMesaContext) calloc( 1, sizeof(struct foo_mesa_context) );
  717.    if (!c) {
  718.       return NULL;
  719.    }
  720.  
  721.    c->gl_ctx = gl_create_context( visual->gl_visual,
  722.                                   share ? share->gl_ctx : NULL,
  723.                                   (void *) c );
  724.  
  725.  
  726.    /* you probably have to do a bunch of other initializations here. */
  727.  
  728.    return c;
  729. }
  730.  
  731.  
  732.  
  733. void FooMesaDestroyContext( FooMesaContext c )
  734. {
  735.    gl_destroy_context( c->gl_ctx );
  736.    free( c );
  737. }
  738.  
  739.  
  740.  
  741. /*
  742.  * Make the specified context the current one */
  743.  * Might also want to specify the window/drawable here, like for GLX.
  744.  */
  745. void FooMesaMakeCurrent( FooMesaContext c, FooMesaBuffer b )
  746. {
  747.    if (c && b) {
  748.       gl_make_current( c->gl_ctx, b->gl_buffer );
  749.       Current_context = c;
  750.       if (c->gl_ctx->Viewport.Width==0) {
  751.          /* initialize viewport to window size */
  752.          gl_Viewport( c->gl_ctx, 0, 0, c->width, c->height );
  753.       }
  754.    }
  755.    else {
  756.       /* Detach */
  757.       gl_make_current( NULL, NULL );
  758.       Current = NULL;
  759.    }
  760. }
  761.  
  762.  
  763.  
  764. void FooMesaSwapBuffers( FooMesaBuffer b )
  765. {
  766.    /* copy/swap back buffer to front if applicable */
  767. }
  768.  
  769.  
  770.  
  771. /* you may need to add other FOO/Mesa functions too... */
  772.  
  773.