summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/video/namcos21_3d.h
blob: 2973e0a6df21f9e40b4bd7053dbfe9df33386703 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// license:BSD-3-Clause
// copyright-holders:David Haywood
#ifndef MAME_VIDEO_NAMCOS21_3D_H
#define MAME_VIDEO_NAMCOS21_3D_H

#pragma once

class namcos21_3d_device : public device_t
{
public:
	namcos21_3d_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);

	// config
	void set_fixed_palbase(int base) { m_fixed_palbase = base; }
	void set_zz_shift_mult(int shift, int mult) { m_zz_shift = shift; m_zzmult = mult;  }
	void set_depth_reverse(bool reverse) { m_depth_reverse = reverse;  }

	void set_framebuffer_size(int width, int height)
	{
		m_poly_frame_width = width;
		m_poly_frame_height = height;
		m_framebuffer_size_in_bytes = (sizeof(uint16_t)*m_poly_frame_width*m_poly_frame_height);
	}

	int get_width() { return m_poly_frame_width; }
	int get_height() { return m_poly_frame_height; }

	void copy_visible_poly_framebuffer(bitmap_ind16 &bitmap, const rectangle &clip, int zlo, int zhi);
	void swap_and_clear_poly_framebuffer();

	void draw_quad(int sx[4], int sy[4], int zcode[4], int color);

protected:
	// device-level overrides
	virtual void device_start() override;
	virtual void device_reset() override;

private:
	struct n21_vertex
	{
		double x,y;
		double z;
	};

	struct edge
	{
		double x;
		double z;
	};

	void renderscanline_flat(const edge *e1, const edge *e2, int sy, unsigned color, int depthcueenable);
	void rendertri(const n21_vertex *v0, const n21_vertex *v1, const n21_vertex *v2, unsigned color, int depthcueenable);
	void allocate_poly_framebuffer();

	std::unique_ptr<uint16_t[]> m_mpPolyFrameBufferPens;
	std::unique_ptr<uint16_t[]> m_mpPolyFrameBufferZ;
	std::unique_ptr<uint16_t[]> m_mpPolyFrameBufferPens2;
	std::unique_ptr<uint16_t[]> m_mpPolyFrameBufferZ2;

	int m_fixed_palbase;
	int m_zz_shift, m_zzmult;
	bool m_depth_reverse;

	int m_poly_frame_width;
	int m_poly_frame_height;
	int m_framebuffer_size_in_bytes;
};

DECLARE_DEVICE_TYPE(NAMCOS21_3D, namcos21_3d_device)

#endif // MAME_VIDEO_NAMCOS21_3D_H