1 |
5 |
maiden |
/*
|
2 |
|
|
Bare metal OpenCores GFX IP driver for Wishbone bus.
|
3 |
|
|
|
4 |
|
|
Anton Fosselius, Per Lenander 2012
|
5 |
|
|
*/
|
6 |
|
|
|
7 |
|
|
#ifndef ORGFX_H
|
8 |
|
|
#define ORGFX_H
|
9 |
|
|
|
10 |
|
|
// Pixel definitions, use these when setting colors
|
11 |
|
|
//
|
12 |
|
|
// Pixels are defined by R,G,B where R,G,B are the most significant Red, Green and Blue bits
|
13 |
|
|
// All color channels are in the range 0-255
|
14 |
|
|
// (Greyscale is kind of subobtimal)
|
15 |
|
|
#define GFX_PIXEL_8(R,G,B) (R*0.3 + G*0.59 + B*0.11)
|
16 |
|
|
#define GFX_PIXEL_16(R,G,B) (((R >> 3) << 11) | ((G >> 2) << 5) | (B>>3))
|
17 |
|
|
#define GFX_PIXEL_24(R,G,B) ((R << 16) | (G << 8) | B)
|
18 |
|
|
#define GFX_PIXEL_32(A,R,G,B) ((A << 24) | (R << 16) | (G << 8) | B)
|
19 |
|
|
|
20 |
|
|
#define SUBPIXEL_WIDTH 16
|
21 |
|
|
#define FIXEDW (1<<SUBPIXEL_WIDTH)
|
22 |
|
|
|
23 |
|
|
// Can be used as "memoryArea" in init
|
24 |
|
|
#define GFX_VMEM 0x00800000
|
25 |
|
|
// 800000
|
26 |
|
|
|
27 |
|
|
struct orgfx_surface
|
28 |
|
|
{
|
29 |
|
|
unsigned int addr;
|
30 |
|
|
unsigned int w;
|
31 |
|
|
unsigned int h;
|
32 |
|
|
};
|
33 |
|
|
|
34 |
|
|
typedef struct orgfx_point2
|
35 |
|
|
{
|
36 |
|
|
float x, y;
|
37 |
|
|
} orgfx_point2;
|
38 |
|
|
|
39 |
|
|
typedef struct orgfx_point3
|
40 |
|
|
{
|
41 |
|
|
float x, y, z;
|
42 |
|
|
} orgfx_point3;
|
43 |
|
|
|
44 |
|
|
|
45 |
|
|
// Must be called before any other orgfx functions.
|
46 |
|
|
void orgfx_init(unsigned int memoryArea);
|
47 |
|
|
|
48 |
|
|
// Set video mode
|
49 |
|
|
void orgfx_vga_set_videomode(unsigned int width, unsigned int height, unsigned char bpp);
|
50 |
|
|
|
51 |
|
|
// Vga stuff for double buffering (bank switching)
|
52 |
|
|
inline void orgfx_vga_set_vbara(unsigned int addr);
|
53 |
|
|
inline void orgfx_vga_set_vbarb(unsigned int addr);
|
54 |
|
|
inline void orgfx_vga_bank_switch();
|
55 |
|
|
inline unsigned int orgfx_vga_AVMP(); // Get the active memory page
|
56 |
|
|
|
57 |
|
|
struct orgfx_surface orgfx_init_surface(unsigned int width, unsigned int height);
|
58 |
|
|
void orgfx_bind_rendertarget(struct orgfx_surface *surface);
|
59 |
|
|
|
60 |
|
|
// Set the clip rect. Nothing outside this area will be rendered. This is reset every time you change render target
|
61 |
|
|
void orgfx_enable_cliprect(unsigned int enable);
|
62 |
|
|
void orgfx_cliprect(unsigned int x0, unsigned int y0, unsigned int x1, unsigned int y1);
|
63 |
|
|
|
64 |
|
|
// Set source rect (applied to texturing). This is reset every time you bind a new texture or enable/disable texturing
|
65 |
|
|
inline void orgfx_srcrect(unsigned int x0, unsigned int y0, unsigned int x1, unsigned int y1);
|
66 |
|
|
|
67 |
|
|
// Set pixels (slooooow)
|
68 |
|
|
inline void orgfx_set_pixel(int x, int y, unsigned int color);
|
69 |
|
|
|
70 |
|
|
// Copies a buffer into the current render target
|
71 |
|
|
void orgfx_memcpy(unsigned int mem[], unsigned int size);
|
72 |
|
|
|
73 |
|
|
// Primitives
|
74 |
|
|
inline void orgfx_set_color(unsigned int color);
|
75 |
|
|
inline void orgfx_set_colors(unsigned int color0, unsigned int color1, unsigned int color2);
|
76 |
|
|
inline void orgfx_rect(int x0, int y0, int x1, int y1);
|
77 |
|
|
inline void orgfx_line(int x0, int y0, int x1, int y1);
|
78 |
|
|
inline void orgfx_triangle(int x0, int y0,
|
79 |
|
|
int x1, int y1,
|
80 |
|
|
int x2, int y2,
|
81 |
|
|
unsigned int interpolate);
|
82 |
|
|
inline void orgfx_curve(int x0, int y0,
|
83 |
|
|
int x1, int y1,
|
84 |
|
|
int x2, int y2,
|
85 |
|
|
unsigned int inside);
|
86 |
|
|
|
87 |
|
|
inline void orgfx_line3d(int x0, int y0, int z0, int x1, int y1, int z1);
|
88 |
|
|
inline void orgfx_triangle3d(int x0, int y0, int z0,
|
89 |
|
|
int x1, int y1, int z1,
|
90 |
|
|
int x2, int y2, int z2,
|
91 |
|
|
unsigned int interpolate);
|
92 |
|
|
|
93 |
|
|
inline void orgfx_uv(unsigned int u0, unsigned int v0,
|
94 |
|
|
unsigned int u1, unsigned int v1,
|
95 |
|
|
unsigned int u2, unsigned int v2);
|
96 |
|
|
|
97 |
|
|
void orgfx_enable_tex0(unsigned int enable);
|
98 |
|
|
void orgfx_bind_tex0(struct orgfx_surface* surface);
|
99 |
|
|
void orgfx_enable_zbuffer(unsigned int enable);
|
100 |
|
|
void orgfx_bind_zbuffer(struct orgfx_surface *surface);
|
101 |
|
|
void orgfx_clear_zbuffer();
|
102 |
|
|
|
103 |
|
|
#define GFX_OPAQUE 0xffffffff
|
104 |
|
|
|
105 |
|
|
void orgfx_enable_alpha(unsigned int enable);
|
106 |
|
|
void orgfx_set_alpha(unsigned int alpha);
|
107 |
|
|
|
108 |
|
|
void orgfx_enable_colorkey(unsigned int enable);
|
109 |
|
|
void orgfx_set_colorkey(unsigned int colorkey);
|
110 |
|
|
|
111 |
|
|
void orgfx_enable_transform(unsigned int enable);
|
112 |
|
|
void orgfx_set_transformation_matrix(int aa, int ab, int ac, int tx,
|
113 |
|
|
int ba, int bb, int bc, int ty,
|
114 |
|
|
int ca, int cb, int cc, int tz);
|
115 |
|
|
|
116 |
|
|
#endif
|