The Wayback Machine - https://web.archive.org/web/20130104090240/http://mamedev.org/source/src/emu/video/poly.h.html

Viewing File: <root>/src/emu/video/poly.h

    1  /***************************************************************************
    2  
    3      poly.h
    4  
    5      New polygon helper routines.
    6  
    7  ****************************************************************************
    8  
    9      Pixel model:
   10  
   11      (0.0,0.0)       (1.0,0.0)       (2.0,0.0)       (3.0,0.0)
   12          +---------------+---------------+---------------+
   13          |               |               |               |
   14          |               |               |               |
   15          |   (0.5,0.5)   |   (1.5,0.5)   |   (2.5,0.5)   |
   16          |       *       |       *       |       *       |
   17          |               |               |               |
   18          |               |               |               |
   19      (0.0,1.0)       (1.0,1.0)       (2.0,1.0)       (3.0,1.0)
   20          +---------------+---------------+---------------+
   21          |               |               |               |
   22          |               |               |               |
   23          |   (0.5,1.5)   |   (1.5,1.5)   |   (2.5,1.5)   |
   24          |       *       |       *       |       *       |
   25          |               |               |               |
   26          |               |               |               |
   27          |               |               |               |
   28          +---------------+---------------+---------------+
   29      (0.0,2.0)       (1.0,2.0)       (2.0,2.0)       (3.0,2.0)
   30  
   31  ***************************************************************************/
   32  
   33  #pragma once
   34  
   35  #ifndef __POLYNEW_H__
   36  #define __POLYNEW_H__
   37  
   38  
   39  /***************************************************************************
   40      CONSTANTS
   41  ***************************************************************************/
   42  
   43  #define MAX_VERTEX_PARAMS                   6
   44  #define MAX_POLYGON_VERTS                   32
   45  
   46  #define POLYFLAG_INCLUDE_BOTTOM_EDGE        0x01
   47  #define POLYFLAG_INCLUDE_RIGHT_EDGE         0x02
   48  #define POLYFLAG_NO_WORK_QUEUE              0x04
   49  #define POLYFLAG_ALLOW_QUADS                0x08
   50  
   51  
   52  
   53  /***************************************************************************
   54      TYPE DEFINITIONS
   55  ***************************************************************************/
   56  
   57  /* opaque reference to the poly manager */
   58  struct poly_manager;
   59  
   60  
   61  /* input vertex data */
   62  struct poly_vertex
   63  {
   64      float       x;                          /* X coordinate */
   65      float       y;                          /* Y coordinate */
   66      float       p[MAX_VERTEX_PARAMS];       /* interpolated parameter values */
   67  };
   68  
   69  
   70  /* poly_param_extent describes information for a single parameter in an extent */
   71  struct poly_param_extent
   72  {
   73      float       start;                      /* parameter value at starting X,Y */
   74      float       dpdx;                       /* dp/dx relative to starting X */
   75  };
   76  
   77  
   78  /* poly_extent describes start/end points for a scanline, along with per-scanline parameters */
   79  struct poly_extent
   80  {
   81      INT16       startx;                     /* starting X coordinate (inclusive) */
   82      INT16       stopx;                      /* ending X coordinate (exclusive) */
   83      poly_param_extent param[MAX_VERTEX_PARAMS]; /* starting and dx values for each parameter */
   84  };
   85  
   86  
   87  /* callback routine to process a batch of scanlines in a triangle */
   88  typedef void (*poly_draw_scanline_func)(void *dest, INT32 scanline, const poly_extent *extent, const void *extradata, int threadid);
   89  
   90  
   91  
   92  /***************************************************************************
   93      TYPE DEFINITIONS
   94  ***************************************************************************/
   95  
   96  
   97  /* ----- initialization/teardown ----- */
   98  
   99  /* allocate a new poly manager that can render triangles */
  100  poly_manager *poly_alloc(running_machine &machine, int max_polys, size_t extra_data_size, UINT8 flags);
  101  
  102  /* free a poly manager */
  103  void poly_free(poly_manager *poly);
  104  
  105  
  106  
  107  /* ----- common functions ----- */
  108  
  109  /* wait until all polygons in the queue have been rendered */
  110  void poly_wait(poly_manager *poly, const char *debug_reason);
  111  
  112  /* get a pointer to the extra data for the next polygon */
  113  void *poly_get_extra_data(poly_manager *poly);
  114  
  115  
  116  
  117  /* ----- core triangle rendering ----- */
  118  
  119  /* render a single triangle given 3 vertexes */
  120  UINT32 poly_render_triangle(poly_manager *poly, void *dest, const rectangle &cliprect, poly_draw_scanline_func callback, int paramcount, const poly_vertex *v1, const poly_vertex *v2, const poly_vertex *v3);
  121  
  122  /* render a set of triangles in a fan */
  123  UINT32 poly_render_triangle_fan(poly_manager *poly, void *dest, const rectangle &cliprect, poly_draw_scanline_func callback, int paramcount, int numverts, const poly_vertex *v);
  124  
  125  /* perform a custom render of an object, given specific extents */
  126  UINT32 poly_render_triangle_custom(poly_manager *poly, void *dest, const rectangle &cliprect, poly_draw_scanline_func callback, int startscanline, int numscanlines, const poly_extent *extents);
  127  
  128  
  129  
  130  /* ----- core quad rendering ----- */
  131  
  132  /* render a single quad given 4 vertexes */
  133  UINT32 poly_render_quad(poly_manager *poly, void *dest, const rectangle &cliprect, poly_draw_scanline_func callback, int paramcount, const poly_vertex *v1, const poly_vertex *v2, const poly_vertex *v3, const poly_vertex *v4);
  134  
  135  /* render a set of quads in a fan */
  136  UINT32 poly_render_quad_fan(poly_manager *poly, void *dest, const rectangle &cliprect, poly_draw_scanline_func callback, int paramcount, int numverts, const poly_vertex *v);
  137  
  138  
  139  
  140  /* ----- core polygon rendering ----- */
  141  
  142  /* render a single polygon up to 32 vertices */
  143  UINT32 poly_render_polygon(poly_manager *poly, void *dest, const rectangle &cliprect, poly_draw_scanline_func callback, int paramcount, int numverts, const poly_vertex *v);
  144  
  145  
  146  
  147  /* ----- clipping ----- */
  148  
  149  /* zclip (assumes p[0] == z) a polygon */
  150  int poly_zclip_if_less(int numverts, const poly_vertex *v, poly_vertex *outv, int paramcount, float clipval);
  151  
  152  
  153  #endif  /* __POLY_H__ */