OpenCores
URL https://opencores.org/ocsvn/orsoc_graphics_accelerator/orsoc_graphics_accelerator/trunk

Subversion Repositories orsoc_graphics_accelerator

[/] [orsoc_graphics_accelerator/] [trunk/] [sw/] [drivers/] [gfx/] [bare/] [orgfx_plus.c] - Blame information for rev 5

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 5 maiden
/*
2
Enhanced Bare metal OpenCores GFX IP driver for Wishbone bus.
3
 
4
This driver provides more functionality than orgfx.h
5
 
6
Anton Fosselius, Per Lenander 2012
7
  */
8
 
9
#include "orgfx_plus.h"
10
#include "orgfx.h"
11
 
12
#define NUM_SURFACES 10
13
 
14
struct orgfx_surface textures[NUM_SURFACES];
15
int surfaceCounter = 0;
16
 
17
int activeSurface = -1;
18
 
19
// For double buffering
20
unsigned char doubleBufferingEnabled = 0;
21
struct orgfx_surface screen0, screen1, depthBuffer;
22
unsigned char activeScreen = 1;
23
 
24
int orgfxplus_init(unsigned int width, unsigned int height, unsigned char bpp,
25
                    unsigned char doubleBuffering, unsigned char zbuffer)
26
{
27
    doubleBufferingEnabled = doubleBuffering;
28
 
29
    orgfx_init(GFX_VMEM);
30
    orgfx_vga_set_videomode(width, height, bpp);
31
 
32
    screen0 = orgfx_init_surface(width, height);
33
    if(doubleBuffering)
34
    {
35
        screen1 = orgfx_init_surface(width, height);
36
        screen1.addr += 0x00800000;
37
        orgfx_vga_set_vbarb(screen1.addr);
38
        orgfx_bind_rendertarget(&screen1);
39
    }
40
    else
41
        orgfx_bind_rendertarget(&screen0);
42
 
43
    if(zbuffer)
44
    {
45
        depthBuffer = orgfx_init_surface(width, height);
46
        orgfx_bind_zbuffer(&depthBuffer);
47
    }
48
 
49
    return -1; // This index is used for binding the screen surface(s)
50
}
51
 
52
int orgfxplus_init_surface(unsigned int width, unsigned int height, unsigned int mem[])
53
{
54
    if(surfaceCounter >= NUM_SURFACES)
55
        return -1;
56
    textures[surfaceCounter] = orgfx_init_surface(width, height);
57
 
58
    int tmp = activeSurface;
59
 
60
    orgfxplus_bind_rendertarget(surfaceCounter);
61
    orgfx_memcpy(mem, width*height/2); // TODO: Only works for 16 bits!
62
 
63
    orgfxplus_bind_rendertarget(tmp);
64
 
65
    return surfaceCounter++;
66
}
67
 
68
void orgfxplus_bind_rendertarget(int surface)
69
{
70
    if(surface == -1)
71
    {
72
        if(doubleBufferingEnabled && activeScreen == 1)
73
            orgfx_bind_rendertarget(&screen1);
74
        else
75
            orgfx_bind_rendertarget(&screen0);
76
    }
77
    else
78
        orgfx_bind_rendertarget(&textures[surface]);
79
}
80
 
81
void orgfxplus_bind_tex0(int surface)
82
{
83
    if(surface == -1)
84
    {
85
 
86
    }
87
    else
88
        orgfx_bind_tex0(&textures[surface]);
89
}
90
 
91
void orgfxplus_bind_zbuffer(int surface)
92
{
93
    if(surface == -1)
94
    {
95
 
96
    }
97
    else
98
        orgfx_bind_zbuffer(&textures[surface]);
99
}
100
 
101
void orgfxplus_clip(unsigned int x0, unsigned int y0, unsigned int x1, unsigned int y1, unsigned int enable)
102
{
103
    orgfx_enable_cliprect(enable);
104
    orgfx_cliprect(x0, y0, x1, y1);
105
}
106
 
107
void orgfxplus_fill(int x0, int y0, int x1, int y1, unsigned int color)
108
{
109
    orgfx_enable_tex0(0);
110
    orgfx_set_color(color);
111
    orgfx_rect(x0, y0, x1, y1);
112
}
113
 
114
void orgfxplus_line(int x0, int y0, int x1, int y1, unsigned int color)
115
{
116
    orgfx_enable_tex0(0);
117
    orgfx_set_color(color);
118
    orgfx_line(x0, y0, x1, y1);
119
}
120
 
121
void orgfxplus_triangle(int x0, int y0, int x1, int y1, int x2, int y2, unsigned int color)
122
{
123
    orgfx_enable_tex0(0);
124
    orgfx_set_color(color);
125
    orgfx_triangle(x0, y0, x1, y1, x2, y2, 0);
126
}
127
 
128
void orgfxplus_curve(int x0, int y0, int x1, int y1, int x2, int y2, unsigned int inside, unsigned int color)
129
{
130
    orgfx_enable_tex0(0);
131
    orgfx_set_color(color);
132
    orgfx_curve(x0, y0, x1, y1, x2, y2, inside);
133
}
134
 
135
void orgfxplus_draw_surface(int x0, int y0, unsigned int surface)
136
{
137
    orgfx_enable_tex0(1);
138
    orgfx_bind_tex0(&textures[surface]);
139
    orgfx_rect(x0, y0, x0+textures[surface].w*FIXEDW, y0+textures[surface].h*FIXEDW);
140
}
141
 
142
void orgfxplus_draw_surface_section(int x0, int y0, unsigned int srcx0, unsigned int srcy0, unsigned int srcx1, unsigned int srcy1, unsigned int surface)
143
{
144
    orgfx_enable_tex0(1);
145
    orgfx_bind_tex0(&textures[surface]);
146
    orgfx_srcrect(srcx0, srcy0, srcx1, srcy1);
147
    orgfx_rect(x0, y0, x0+(srcx1-srcx0)*FIXEDW, y0+(srcy1-srcy0)*FIXEDW);
148
}
149
 
150
// Swap active frame buffers
151
void orgfxplus_flip()
152
{
153
    if(!doubleBufferingEnabled)
154
        return;
155
 
156
    orgfx_vga_bank_switch();
157
 
158
    // Wait until VGA has switched
159
    while(orgfx_vga_AVMP() != activeScreen);
160
 
161
    activeScreen = !activeScreen;
162
    if(activeSurface == -1)
163
    {
164
        if(activeScreen) orgfx_bind_rendertarget(&screen1);
165
        else orgfx_bind_rendertarget(&screen0);
166
    }
167
}
168
 
169
void orgfxplus_colorkey(unsigned int colorkey, unsigned int enable)
170
{
171
    orgfx_enable_colorkey(enable);
172
    orgfx_set_colorkey(colorkey);
173
}
174
 
175
void orgfxplus_alpha(unsigned int alpha, unsigned int enable)
176
{
177
    orgfx_enable_alpha(enable);
178
    orgfx_set_alpha(alpha);
179
}
180
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.