Previous 199869 Revisions Next

r40571 Tuesday 1st September, 2015 at 15:11:31 UTC by Andrew Gardner
Converts namcos23 to "polynew" (nw)
[src/mame/drivers]namcos23.c

trunk/src/mame/drivers/namcos23.c
r249082r249083
12341234
12351235#include "emu.h"
12361236#include <float.h>
1237#include "video/polylgcy.h"
1237#include "video/poly.h"
12381238#include "cpu/mips/mips3.h"
12391239#include "cpu/h8/h83002.h"
12401240#include "cpu/h8/h83337.h"
r249082r249083
12641264
12651265enum { MODEL, FLUSH };
12661266
1267enum { RENDER_MAX_ENTRIES = 1000, POLY_MAX_ENTRIES = 10000 };
1268
1269class namcos23_state;
1270struct namcos23_render_data;
1271
1272class namcos23_renderer : public poly_manager<float, namcos23_render_data, 4, POLY_MAX_ENTRIES>
1273{
1274public:
1275    namcos23_renderer(namcos23_state &state);
1276   
1277    void render_flush(bitmap_rgb32& bitmap);
1278    void render_scanline(INT32 scanline, const extent_t& extent, const namcos23_render_data& object, int threadid);
1279   
1280private:
1281    namcos23_state& m_state;
1282    bitmap_rgb32 m_bitmap;
1283};
1284
1285typedef namcos23_renderer::vertex_t poly_vertex;
1286
1287
12671288struct namcos23_render_entry
12681289{
12691290   int type;
r249082r249083
12961317   poly_vertex pv[16];
12971318};
12981319
1299enum { RENDER_MAX_ENTRIES = 1000, POLY_MAX_ENTRIES = 10000 };
1300
1301
13021320struct c417_t
13031321{
13041322   UINT16 ram[0x10000];
r249082r249083
13441362
13451363struct render_t
13461364{
1347   legacy_poly_manager *polymgr;
1365    namcos23_renderer *polymgr;
13481366   int cur;
13491367   int poly_count;
13501368   int count[2];
r249082r249083
15401558   void render_apply_matrot(INT32 xi, INT32 yi, INT32 zi, const namcos23_render_entry *re, INT32 &x, INT32 &y, INT32 &z);
15411559   void render_project(poly_vertex &pv);
15421560   void render_one_model(const namcos23_render_entry *re);
1543   void render_flush(bitmap_rgb32 &bitmap);
15441561   void render_run(bitmap_rgb32 &bitmap);
15451562};
15461563
r249082r249083
15671584
15681585***************************************************************************/
15691586
1587namcos23_renderer::namcos23_renderer(namcos23_state &state)
1588    : poly_manager<float, namcos23_render_data, 4, POLY_MAX_ENTRIES>(state.machine()),
1589      m_state(state),
1590      m_bitmap(state.m_screen->width(), state.m_screen->height())
1591{}
1592
15701593// 3D hardware, to throw at least in part in video/namcos23.c
15711594
15721595inline INT32 namcos23_state::u32_to_s24(UINT32 v)
r249082r249083
18571880
18581881
18591882
1860static void render_scanline(void *dest, INT32 scanline, const poly_extent *extent, const void *extradata, int threadid)
1883void namcos23_renderer::render_scanline(INT32 scanline, const extent_t& extent, const namcos23_render_data& object, int threadid)
18611884{
1862   const namcos23_render_data *rd = (const namcos23_render_data *)extradata;
1885   const namcos23_render_data& rd = object;
18631886
1864   float w = extent->param[0].start;
1865   float u = extent->param[1].start;
1866   float v = extent->param[2].start;
1867   float l = extent->param[3].start;
1868   float dw = extent->param[0].dpdx;
1869   float du = extent->param[1].dpdx;
1870   float dv = extent->param[2].dpdx;
1871   float dl = extent->param[3].dpdx;
1872   bitmap_rgb32 *bitmap = (bitmap_rgb32 *)dest;
1873   UINT32 *img = &bitmap->pix32(scanline, extent->startx);
1887   float w = extent.param[0].start;
1888   float u = extent.param[1].start;
1889   float v = extent.param[2].start;
1890   float l = extent.param[3].start;
1891   float dw = extent.param[0].dpdx;
1892   float du = extent.param[1].dpdx;
1893   float dv = extent.param[2].dpdx;
1894   float dl = extent.param[3].dpdx;
1895   UINT32 *img = &m_bitmap.pix32(scanline, extent.startx);
18741896
1875   for(int x = extent->startx; x < extent->stopx; x++) {
1897   for(int x = extent.startx; x < extent.stopx; x++) {
18761898      float z = w ? 1/w : 0;
1877      UINT32 pcol = rd->texture_lookup(*rd->machine, rd->pens, u*z, v*z);
1899      UINT32 pcol = rd.texture_lookup(*rd.machine, rd.pens, u*z, v*z);
18781900      float ll = l*z;
18791901      *img = (light(pcol >> 16, ll) << 16) | (light(pcol >> 8, ll) << 8) | light(pcol, ll);
18801902
r249082r249083
20132035
20142036      namcos23_poly_entry *p = render.polys + render.poly_count;
20152037
2016      p->vertex_count = poly_zclip_if_less(ne, pv, p->pv, 4, 0.001f);
2038      p->vertex_count = render.polymgr->zclip_if_less(ne, pv, p->pv, 4, 0.001f);
20172039
20182040      if(p->vertex_count >= 3) {
20192041         for(int i=0; i<p->vertex_count; i++) {
r249082r249083
20472069   return p1->zkey < p2->zkey ? 1 : p1->zkey > p2->zkey ? -1 : 0;
20482070}
20492071
2050void namcos23_state::render_flush(bitmap_rgb32 &bitmap)
2072void namcos23_renderer::render_flush(bitmap_rgb32& bitmap)
20512073{
2052   render_t &render = m_render;
2074   render_t &render = m_state.m_render;
20532075
20542076   if(!render.poly_count)
20552077      return;
r249082r249083
20632085
20642086   for(int i=0; i<render.poly_count; i++) {
20652087      const namcos23_poly_entry *p = render.poly_order[i];
2066      namcos23_render_data *rd = (namcos23_render_data *)poly_get_extra_data(render.polymgr);
2067      *rd = p->rd;
2068      poly_render_triangle_fan(render.polymgr, &bitmap, scissor, render_scanline, 4, p->vertex_count, p->pv);
2088        namcos23_render_data& extra = render.polymgr->object_data_alloc();
2089        extra = p->rd;
2090       
2091        if (p->vertex_count == 3)
2092            render_triangle(scissor, render_delegate(FUNC(namcos23_renderer::render_scanline), this), 4, p->pv[0], p->pv[1], p->pv[2]);
2093        else if (p->vertex_count == 4)
2094            render_polygon<4>(scissor, render_delegate(FUNC(namcos23_renderer::render_scanline), this), 4, p->pv);
2095        else if (p->vertex_count == 5)
2096            render_polygon<5>(scissor, render_delegate(FUNC(namcos23_renderer::render_scanline), this), 4, p->pv);
20692097   }
20702098   render.poly_count = 0;
2099   
2100    copybitmap(bitmap, m_bitmap, 0, 0, 0, 0, scissor);
20712101}
20722102
20732103void namcos23_state::render_run(bitmap_rgb32 &bitmap)
r249082r249083
20822112         render_one_model(re);
20832113         break;
20842114      case FLUSH:
2085         render_flush(bitmap);
2115         render.polymgr->render_flush(bitmap);
20862116         break;
20872117      }
20882118      re++;
20892119   }
2090   render_flush(bitmap);
2091
2092   poly_wait(render.polymgr, "render_run");
2120   render.polymgr->render_flush(bitmap);
2121    render.polymgr->wait();
20932122}
20942123
20952124
r249082r249083
21612190   m_bgtilemap = &machine().tilemap().create(m_gfxdecode, tilemap_get_info_delegate(FUNC(namcos23_state::TextTilemapGetInfo),this), TILEMAP_SCAN_ROWS, 16, 16, 64, 64);
21622191   m_bgtilemap->set_transparent_pen(0xf);
21632192   m_bgtilemap->set_scrolldx(860, 860);
2164   m_render.polymgr = poly_alloc(machine(), 10000, sizeof(namcos23_render_data), 0);
2193    m_render.polymgr = auto_alloc(machine(), namcos23_renderer(*this));
21652194}
21662195
21672196


Previous 199869 Revisions Next


© 1997-2024 The MAME Team