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_sw.c] - Blame information for rev 5

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 5 maiden
/*
2
Bare metal OpenCores GFX IP driver for Wishbone bus.
3
 
4
THIS IS A SOFTWARE IMPLEMENTATION USING SDL, FOR TESTING PROGRAMS AGAINST THE API
5
 
6
Anton Fosselius, Per Lenander 2012
7
  */
8
 
9
#include "orgfx.h"
10
#include "orgfx_plus.h"
11
#include "orgfx_3d.h"
12
 
13
#include <SDL/SDL.h>
14
#include <SDL/SDL_image.h>
15
 
16
#include <math.h>
17
 
18
typedef struct Point
19
{
20
    float x, y, z;
21
} Point;
22
 
23
 
24
SDL_Surface* screen = NULL;
25
 
26
#define NUM_SURFACES 10
27
SDL_Surface* surfaces[NUM_SURFACES];
28
int sCounter = 0;
29
 
30
SDL_Surface* target_surface = NULL;
31
SDL_Surface* tex0_surface = NULL;
32
SDL_Surface* zbuffer_surface = NULL;
33
 
34
SDL_Rect cliprect;
35
SDL_Rect srcrect;
36
 
37
unsigned int color_depth_reg = 16;
38
 
39
unsigned int texture_enable = 0;
40
unsigned int blend_enable = 0;
41
unsigned int colorkey_enable = 0;
42
unsigned int clipping_enable = 0;
43
unsigned int transform_enable = 0;
44
unsigned int zbuffer_enable = 0;
45
 
46
int z_reg = 0;
47
 
48
unsigned int colorkey_reg = 0;
49
float alpha_global_reg = 1;
50
float alpha0_reg = 1;
51
float alpha1_reg = 1;
52
float alpha2_reg = 1;
53
float pixel_alpha = 1;
54
 
55
unsigned int u0_reg = 0, v0_reg = 0;
56
unsigned int u1_reg = 0, v1_reg = 0;
57
unsigned int u2_reg = 0, v2_reg = 0;
58
 
59
float aa_reg = 1;
60
float ab_reg = 0;
61
float ac_reg = 0;
62
float tx_reg = 0;
63
float ba_reg = 0;
64
float bb_reg = 1;
65
float bc_reg = 0;
66
float ty_reg = 0;
67
float ca_reg = 0;
68
float cb_reg = 0;
69
float cc_reg = 1;
70
float tz_reg = 0;
71
 
72
// Pixel manipulation
73
void put_pixel16( SDL_Surface *surface, int x, int y, Uint16 pixel )
74
{
75
    if(x<0 || x > surface->w)
76
        return;
77
    if(y<0 || y > surface->h)
78
        return;
79
    //Convert the pixels to 16 bit
80
    Uint16 *pixels = (Uint16 *)surface->pixels;
81
 
82
    //Set the pixel
83
    pixels[ ( y * surface->w ) + x ] = pixel;
84
}
85
 
86
Uint16 get_pixel16( SDL_Surface *surface, int x, int y )
87
{
88
    if(x<0 || x > surface->w)
89
        return;
90
    if(y<0 || y > surface->h)
91
        return;
92
    //Convert the pixels to 16 bit
93
    Uint16 *pixels = (Uint16 *)surface->pixels;
94
 
95
    //Get the requested pixel
96
    return pixels[ ( y * surface->w ) + x ];
97
}
98
 
99
 
100
unsigned int color0_reg = 0, color1_reg = 0, color2_reg = 0;
101
 
102
unsigned int gfx_control_reg_memory = 0;
103
 
104
Point toPoint(int x, int y, int z)
105
{
106
    Point p;
107
    p.x = (float)x / FIXEDW;
108
    p.y = (float)y / FIXEDW;
109
    p.z = (float)z / FIXEDW;
110
 
111
    //printf("x: %d y: %d z: %d  --->  ", x, y, z);
112
    //printf("p: %f,%f,%f\n", p.x, p.y, p.z);
113
 
114
    if(!transform_enable)
115
        return p;
116
 
117
    Point ret;
118
 
119
    ret.x = aa_reg*p.x + ab_reg*p.y + ac_reg*p.z + tx_reg;
120
    ret.y = ba_reg*p.x + bb_reg*p.y + bc_reg*p.z + ty_reg;
121
    ret.z = ca_reg*p.x + cb_reg*p.y + cc_reg*p.z + tz_reg;
122
 
123
    return ret;
124
}
125
 
126
void orgfx_init(unsigned int memoryArea)
127
{
128
    SDL_Init(SDL_INIT_VIDEO);
129
}
130
 
131
void orgfx_vga_set_vbara(unsigned int addr)
132
{
133
 
134
}
135
 
136
void orgfx_vga_set_vbarb(unsigned int addr)
137
{
138
 
139
}
140
 
141
inline void orgfx_vga_bank_switch()
142
{
143
 
144
}
145
 
146
void orgfx_vga_set_videomode(unsigned int width, unsigned int height, unsigned char bpp)
147
{
148
    color_depth_reg = bpp;
149
    screen = SDL_SetVideoMode(width, height, bpp, SDL_DOUBLEBUF);
150
    target_surface = screen;
151
}
152
 
153
struct orgfx_surface orgfx_init_surface(unsigned int width, unsigned int height)
154
{
155
    static int screenInitialized = 0;
156
    struct orgfx_surface surface;
157
 
158
    surface.addr = sCounter;
159
 
160
    if(screenInitialized)
161
    {
162
        SDL_Surface* s = SDL_CreateRGBSurface(0,width, height, color_depth_reg, 0, 0, 0, 0);
163
        surfaces[sCounter] = s;
164
        surface.w = s->w;
165
        surface.h = s->h;
166
    }
167
    else
168
    {
169
        surfaces[sCounter] = screen;
170
        surface.w = screen->w;
171
        surface.h = screen->h;
172
        screenInitialized = 1;
173
    }
174
 
175
    sCounter++;
176
 
177
    return surface;
178
}
179
 
180
void orgfx_bind_rendertarget(struct orgfx_surface *surface)
181
{
182
    unsigned int sIndex = surface->addr;
183
    target_surface = surfaces[sIndex];
184
    // Clear clip rect
185
    orgfx_cliprect(0,0,surface->w,surface->h);
186
}
187
 
188
void orgfx_enable_cliprect(unsigned int enable)
189
{
190
    clipping_enable = enable;
191
}
192
 
193
void orgfx_cliprect(unsigned int x0, unsigned int y0,
194
                     unsigned int x1, unsigned int y1)
195
{
196
    cliprect.x = x0;
197
    cliprect.y = y0;
198
    cliprect.w = x1-x0;
199
    cliprect.h = y1-y0;
200
}
201
 
202
void orgfx_srcrect(unsigned int x0, unsigned int y0,
203
                    unsigned int x1, unsigned int y1)
204
{
205
    srcrect.x = x0;
206
    srcrect.y = y0;
207
    srcrect.w = x1-x0;
208
    srcrect.h = y1-y0;
209
}
210
 
211
void orgfx_init_src()
212
{
213
    if(texture_enable && tex0_surface)
214
        orgfx_srcrect(0, 0, tex0_surface->w, tex0_surface->h);
215
    else if(target_surface)
216
        orgfx_srcrect(0, 0, target_surface->w, target_surface->h);
217
}
218
 
219
void orgfx_set_pixel(int x, int y, unsigned int color)
220
{
221
    if(!colorkey_enable || colorkey_reg != color)
222
    {
223
        // Check for depth
224
        if(zbuffer_enable)
225
        {
226
            short depthAtTarget = get_pixel16(zbuffer_surface, x, y);
227
 
228
            if(depthAtTarget > z_reg)
229
            {
230
                //printf("Z: %d ZBUF: %d\n", z_reg, depthAtTarget);
231
                return;
232
            }
233
            else
234
                put_pixel16(zbuffer_surface, x, y, z_reg);
235
        }
236
 
237
        if(blend_enable)
238
        {
239
            unsigned int targetCol = get_pixel16(target_surface, x, y);
240
 
241
            float alpha = alpha_global_reg * pixel_alpha;
242
 
243
            Uint8 rt = targetCol >> 11, rc = color >> 11;
244
            Uint8 gt = (targetCol >> 5) & 0x3f, gc = (color >> 5) & 0x3f;
245
            Uint8 bt = targetCol & 0x1f, bc = color & 0x1f;
246
 
247
            Uint8 r = alpha*rc+(1.0 - alpha)*rt;
248
            Uint8 g = alpha*gc+(1.0 - alpha)*gt;
249
            Uint8 b = alpha*bc+(1.0 - alpha)*bt;
250
 
251
            color = (r << 11) + (g << 5) + b;
252
        }
253
        put_pixel16(target_surface, x, y, color);
254
    }
255
}
256
 
257
// Copies a buffer into the current render target
258
void orgfx_memcpy(unsigned int mem[], unsigned int size)
259
{
260
    unsigned int i;
261
    for(i=0; i < size; ++i)
262
    {
263
        put_pixel16(target_surface,
264
                    (2*i)%target_surface->w,    // x
265
                    (2*i)/target_surface->w,    // y
266
                    mem[i]>>SUBPIXEL_WIDTH);    // high word
267
        put_pixel16(target_surface,
268
                    (2*i)%target_surface->w+1,  // x+1
269
                    (2*i)/target_surface->w,    // y
270
                    mem[i]&0xffff);             // low word
271
    }
272
}
273
 
274
void orgfx_clear_zbuffer()
275
{
276
    if(zbuffer_surface)
277
        SDL_FillRect(zbuffer_surface, NULL, -32768); // -maxdepth
278
}
279
 
280
void orgfx_set_color(unsigned int color)
281
{
282
    color0_reg = color;
283
}
284
 
285
 
286
void orgfx_set_colors(unsigned int color0, unsigned int color1, unsigned int color2)
287
{
288
    color0_reg = color0;
289
    color1_reg = color1;
290
    color2_reg = color2;
291
}
292
 
293
void orgfx_rect(int x0, int y0,
294
                 int x1, int y1)
295
{
296
    Point p0 = toPoint(x0, y0, 0);
297
    Point p1 = toPoint(x1, y1, 0);
298
    pixel_alpha = 1;
299
 
300
    SDL_Rect dest;
301
    dest.x = p0.x;
302
    dest.y = p0.y;
303
    dest.w = p1.x-p0.x;
304
    dest.h = p1.y-p0.y;
305
 
306
    if(texture_enable)
307
    {
308
        int y, x, u, v;
309
        for(y = p0.y, v = srcrect.y; y < p1.y; ++y, ++v)
310
            for(x = p0.x, u = srcrect.x; x < p1.x; ++x, ++u)
311
                orgfx_set_pixel(x, y, get_pixel16(tex0_surface, u, v));
312
    }
313
    //   SDL_BlitSurface(tex0_surface, &srcrect, target_surface, &dest);
314
    else
315
    {
316
        int y, x;
317
        for(y = p0.y; y < p1.y; ++y)
318
            for(x = p0.x; x < p1.x; ++x)
319
                orgfx_set_pixel(x, y, color0_reg);
320
    }
321
    //   SDL_FillRect(target_surface, &dest, color0_reg);
322
}
323
 
324
void orgfx_line(int x0, int y0,
325
                 int x1, int y1)
326
{
327
    orgfx_line3d(x0, y0, 0, x1, y1, 0);
328
}
329
 
330
 
331
void orgfx_line3d(int x0, int y0, int z0,
332
                   int x1, int y1, int z1)
333
{
334
    Point p0 = toPoint(x0, y0, z0);
335
    Point p1 = toPoint(x1, y1, z1);
336
    pixel_alpha = 1;
337
 
338
    orgfx_set_pixel(p0.x,p0.y,color0_reg);
339
    orgfx_set_pixel(p1.x,p1.y,color0_reg);
340
 
341
    int X0 = p0.x, Y0 = p0.y;
342
    int X1 = p1.x, Y1 = p1.y;
343
    int dx = abs(X1-X0), sx = X0<X1 ? 1 : -1;
344
    int dy = abs(Y1-Y0), sy = Y0<Y1 ? 1 : -1;
345
    int err = (dx>dy ? dx : -dy)/2, e2;
346
 
347
    for(;;){
348
        orgfx_set_pixel(X0, Y0, color0_reg);
349
        if (X0==X1 && Y0==Y1) break;
350
        e2 = err;
351
        if (e2 >-dx) { err -= dy; X0 += sx; }
352
        if (e2 < dy) { err += dx; Y0 += sy; }
353
    }
354
}
355
 
356
void orgfx_triangle(int x0, int y0,
357
                     int x1, int y1,
358
                     int x2, int y2,
359
                     unsigned int interpolate)
360
{
361
    orgfx_triangle3d(x0, y0, 0, x1, y1, 0, x2, y2, 0, interpolate);
362
}
363
 
364
void orgfx_curve(int x0, int y0,
365
                  int x1, int y1,
366
                  int x2, int y2,
367
                  unsigned int inside)
368
{
369
    Point p0 = toPoint(x0, y0, 0);
370
    Point p1 = toPoint(x1, y1, 0);
371
    Point p2 = toPoint(x2, y2, 0);
372
 
373
    float xmin = p0.x; float xmax = p0.x;
374
    if(p1.x < xmin) xmin = p1.x; if(p1.x > xmax) xmax = p1.x;
375
    if(p2.x < xmin) xmin = p2.x; if(p2.x > xmax) xmax = p2.x;
376
    float ymin = p0.y; float ymax = p0.y;
377
    if(p1.y < ymin) ymin = p1.y; if(p1.y > ymax) ymax = p1.y;
378
    if(p2.y < ymin) ymin = p2.y; if(p2.y > ymax) ymax = p2.y;
379
 
380
    float area = (p1.x - p0.x)*(p2.y-p0.y) - (p2.x-p0.x)*(p1.y-p0.y);
381
 
382
    float x, y;
383
 
384
    for(y = ymin; y < ymax; y++)
385
    {
386
        for(x = xmin; x < xmax; x++)
387
        {
388
            float e0 = -(p2.y-p1.y)*(x-p1.x)+(p2.x-p1.x)*(y-p1.y);
389
            float e1 = -(p0.y-p2.y)*(x-p2.x)+(p0.x-p2.x)*(y-p2.y);
390
            float e2 = -(p1.y-p0.y)*(x-p0.x)+(p1.x-p0.x)*(y-p0.y);
391
 
392
            if(e0 >= 0 && e1 >= 0 && e2 >= 0)
393
            {
394
                float factor1 = e1/area;
395
                float factor2 = e2/area;
396
                float factor0 = 1 - factor1 - factor2;
397
 
398
                if(blend_enable)
399
                    pixel_alpha = factor0*alpha0_reg + factor1*alpha1_reg + factor2*alpha2_reg;
400
                else
401
                    pixel_alpha = 1;
402
 
403
                float bezierFactor0 = factor1/2.0 + factor2;
404
                float bezierFactor1 = factor2;
405
 
406
                if(inside)
407
                {
408
                    if(bezierFactor0*bezierFactor0 < bezierFactor1)
409
                        orgfx_set_pixel( x, y, color0_reg);
410
                }
411
                else if(bezierFactor0*bezierFactor0 > bezierFactor1)
412
                    orgfx_set_pixel( x, y, color0_reg);
413
            }
414
        }
415
    }
416
}
417
 
418
#include <stdio.h>
419
 
420
void orgfx_triangle3d(int x0, int y0, int z0,
421
                       int x1, int y1, int z1,
422
                       int x2, int y2, int z2,
423
                       unsigned int interpolate)
424
{
425
    Point p0 = toPoint(x0, y0, z0);
426
    Point p1 = toPoint(x1, y1, z1);
427
    Point p2 = toPoint(x2, y2, z2);
428
 
429
    float xmin = p0.x; float xmax = p0.x;
430
    if(p1.x < xmin) xmin = p1.x; if(p1.x > xmax) xmax = p1.x;
431
    if(p2.x < xmin) xmin = p2.x; if(p2.x > xmax) xmax = p2.x;
432
    float ymin = p0.y; float ymax = p0.y;
433
    if(p1.y < ymin) ymin = p1.y; if(p1.y > ymax) ymax = p1.y;
434
    if(p2.y < ymin) ymin = p2.y; if(p2.y > ymax) ymax = p2.y;
435
 
436
    float area = (p1.x - p0.x)*(p2.y-p0.y) - (p2.x-p0.x)*(p1.y-p0.y);
437
 
438
    if(area < 0)
439
        return;
440
 
441
    pixel_alpha = 1;
442
 
443
    float x, y;
444
 
445
    for(y = ymin; y < ymax; y++)
446
    {
447
        for(x = xmin; x < xmax; x++)
448
        {
449
            float e0 = -(p2.y-p1.y)*(x-p1.x)+(p2.x-p1.x)*(y-p1.y);
450
            float e1 = -(p0.y-p2.y)*(x-p2.x)+(p0.x-p2.x)*(y-p2.y);
451
            float e2 = -(p1.y-p0.y)*(x-p0.x)+(p1.x-p0.x)*(y-p0.y);
452
 
453
            if(e0 >= 0 && e1 >= 0 && e2 >= 0)
454
            {
455
                if(interpolate)
456
                {
457
                    float factor1 = e1/area;
458
                    float factor2 = e2/area;
459
                    float factor0 = 1.0 - factor1 - factor2;
460
 
461
                    // Calculate depth
462
                    z_reg = factor0*p0.z + factor1*p1.z + factor2*p2.z;
463
 
464
                    if(blend_enable)
465
                        pixel_alpha = factor0*alpha0_reg + factor1*alpha1_reg + factor2*alpha2_reg;
466
                    else
467
                        pixel_alpha = 1;
468
 
469
                    if(texture_enable)
470
                    {
471
                        unsigned int u = factor0*u0_reg + factor1*u1_reg + factor2*u2_reg;
472
                        unsigned int v = factor0*v0_reg + factor1*v1_reg + factor2*v2_reg;
473
                        if(u >= tex0_surface->w) u = tex0_surface->w-1;
474
                        if(v >= tex0_surface->h) v = tex0_surface->h-1;
475
 
476
                        Uint32 col = get_pixel16(tex0_surface, u, v);
477
 
478
                        orgfx_set_pixel(x, y, col);
479
                    }
480
                    else
481
                    {
482
                        Uint8 r0 = color0_reg >> 11, r1 = color1_reg >> 11, r2 = color2_reg >> 11;
483
                        Uint8 g0 = (color0_reg >> 5) & 0x3f, g1 = (color1_reg >> 5) & 0x3f, g2 = (color2_reg >> 5) & 0x3f;
484
                        Uint8 b0 = color0_reg & 0x1f, b1 = color1_reg & 0x1f, b2 = color2_reg & 0x1f;
485
 
486
                        Uint8 r = factor0*r0+factor1*r1+factor2*r2;
487
                        Uint8 g = factor0*g0+factor1*g1+factor2*g2;
488
                        Uint8 b = factor0*b0+factor1*b1+factor2*b2;
489
 
490
                        Uint32 col = (r << 11) + (g << 5) + b;
491
 
492
                        orgfx_set_pixel(x, y, col);
493
                    }
494
                }
495
                else
496
                    orgfx_set_pixel(x, y, color0_reg);
497
            }
498
        }
499
    }
500
}
501
 
502
void orgfx_uv(unsigned int u0, unsigned int v0,
503
               unsigned int u1, unsigned int v1,
504
               unsigned int u2, unsigned int v2)
505
{
506
    u0_reg = u0;
507
    v0_reg = v0;
508
    u1_reg = u1;
509
    v1_reg = v1;
510
    u2_reg = u2;
511
    v2_reg = v2;
512
}
513
 
514
void orgfx_enable_tex0(unsigned int enable)
515
{
516
    texture_enable = enable;
517
 
518
    orgfx_init_src();
519
}
520
 
521
void orgfx_bind_tex0(struct orgfx_surface* surface)
522
{
523
    tex0_surface = surfaces[surface->addr];
524
 
525
    orgfx_init_src();
526
}
527
 
528
void orgfx_enable_zbuffer(unsigned int enable)
529
{
530
    zbuffer_enable = enable;
531
}
532
 
533
void orgfx_bind_zbuffer(struct orgfx_surface *surface)
534
{
535
    unsigned int sIndex = surface->addr;
536
    zbuffer_surface = surfaces[sIndex];
537
}
538
 
539
void orgfx_enable_alpha(unsigned int enable)
540
{
541
    blend_enable = enable;
542
}
543
 
544
void orgfx_set_alpha(unsigned int alpha)
545
{
546
    alpha_global_reg = (float)(alpha & 0xff) / 0xff;
547
    alpha0_reg = (float)((alpha >> 24) & 0xff) / 0xff;
548
    alpha1_reg = (float)((alpha >> 16) & 0xff) / 0xff;
549
    alpha2_reg = (float)((alpha >> 8) & 0xff) / 0xff;
550
}
551
 
552
void orgfx_enable_colorkey(unsigned int enable)
553
{
554
    colorkey_enable = enable;
555
}
556
 
557
void orgfx_set_colorkey(unsigned int colorkey)
558
{
559
    colorkey_reg = colorkey;
560
}
561
 
562
void orgfx_enable_transform(unsigned int enable)
563
{
564
    transform_enable = enable;
565
}
566
 
567
void orgfx_set_transformation_matrix(int aa, int ab, int ac, int tx,
568
                                      int ba, int bb, int bc, int ty,
569
                                      int ca, int cb, int cc, int tz)
570
{
571
    aa_reg = (float)aa / FIXEDW;
572
    ab_reg = (float)ab / FIXEDW;
573
    ac_reg = (float)ac / FIXEDW;
574
    tx_reg = (float)tx / FIXEDW;
575
    ba_reg = (float)ba / FIXEDW;
576
    bb_reg = (float)bb / FIXEDW;
577
    bc_reg = (float)bc / FIXEDW;
578
    ty_reg = (float)ty / FIXEDW;
579
    ca_reg = (float)ca / FIXEDW;
580
    cb_reg = (float)cb / FIXEDW;
581
    cc_reg = (float)cc / FIXEDW;
582
    tz_reg = (float)tz / FIXEDW;
583
}
584
 
585
// ******** //
586
// GFX PLUS //
587
// ******** //
588
 
589
struct orgfx_surface textures[NUM_SURFACES];
590
int surfaceCounter = 0;
591
 
592
int activeSurface = -1;
593
struct orgfx_surface screen0;
594
struct orgfx_surface depthBuffer;
595
 
596
int orgfxplus_init(unsigned int width, unsigned int height, unsigned char bpp, unsigned char doubleBuffering, unsigned char zbuffer)
597
{
598
    orgfx_init(GFX_VMEM);
599
    orgfx_vga_set_videomode(width, height, bpp);
600
 
601
    screen0 = orgfx_init_surface(width, height);
602
    orgfx_bind_rendertarget(&screen0);
603
 
604
    if(zbuffer)
605
    {
606
        depthBuffer = orgfx_init_surface(width, height);
607
        orgfx_bind_zbuffer(&depthBuffer);
608
    }
609
 
610
    return -1; // This index is used for binding the screen surface(s)
611
}
612
 
613
int orgfxplus_init_surface(unsigned int width, unsigned int height, unsigned int mem[])
614
{
615
    if(surfaceCounter >= NUM_SURFACES)
616
        return -1;
617
    textures[surfaceCounter] = orgfx_init_surface(width, height);
618
 
619
    int tmp = activeSurface;
620
 
621
    orgfxplus_bind_rendertarget(surfaceCounter);
622
    orgfx_memcpy(mem, width*height/2); // TODO: Only works for 16 bits!
623
 
624
    orgfxplus_bind_rendertarget(tmp);
625
 
626
    return surfaceCounter++;
627
}
628
 
629
void orgfxplus_bind_rendertarget(int surface)
630
{
631
    if(surface == -1)
632
        orgfx_bind_rendertarget(&screen0);
633
    else
634
        orgfx_bind_rendertarget(&textures[surface]);
635
}
636
 
637
void orgfxplus_bind_tex0(int surface)
638
{
639
    if(surface == -1)
640
    {
641
 
642
    }
643
    else
644
        orgfx_bind_tex0(&textures[surface]);
645
}
646
 
647
void orgfxplus_clip(unsigned int x0, unsigned int y0,
648
                     unsigned int x1, unsigned int y1,
649
                     unsigned int enable)
650
{
651
    orgfx_enable_cliprect(enable);
652
    orgfx_cliprect(x0, y0, x1, y1);
653
}
654
 
655
void orgfxplus_fill(int x0, int y0,
656
                     int x1, int y1,
657
                     unsigned int color)
658
{
659
    orgfx_enable_tex0(0);
660
    orgfx_set_color(color);
661
    orgfx_rect(x0, y0, x1, y1);
662
}
663
 
664
void orgfxplus_line(int x0, int y0,
665
                     int x1, int y1,
666
                     unsigned int color)
667
{
668
    orgfx_enable_tex0(0);
669
    orgfx_set_color(color);
670
    orgfx_line(x0, y0, x1, y1);
671
}
672
 
673
void orgfxplus_triangle(int x0, int y0,
674
                         int x1, int y1,
675
                         int x2, int y2,
676
                         unsigned int color)
677
{
678
    orgfx_enable_tex0(0);
679
    orgfx_set_color(color);
680
    orgfx_triangle(x0, y0, x1, y1, x2, y2, 0);
681
}
682
 
683
void orgfxplus_curve(int x0, int y0,
684
                      int x1, int y1,
685
                      int x2, int y2,
686
                      unsigned int inside, unsigned int color)
687
{
688
    orgfx_enable_tex0(0);
689
    orgfx_set_color(color);
690
    orgfx_curve(x0, y0, x1, y1, x2, y2, inside);
691
}
692
 
693
void orgfxplus_draw_surface(int x0, int y0,
694
                             unsigned int surface)
695
{
696
    orgfx_enable_tex0(1);
697
    orgfx_bind_tex0(&textures[surface]);
698
    orgfx_rect(x0, y0, x0+textures[surface].w*FIXEDW, y0+textures[surface].h*FIXEDW);
699
}
700
 
701
void orgfxplus_draw_surface_section(int x0, int y0,
702
                                     unsigned int srcx0, unsigned int srcy0,
703
                                     unsigned int srcx1, unsigned int srcy1,
704
                                     unsigned int surface)
705
{
706
    orgfx_enable_tex0(1);
707
    orgfx_bind_tex0(&textures[surface]);
708
    orgfx_srcrect(srcx0, srcy0, srcx1, srcy1);
709
    orgfx_rect(x0, y0, x0+(srcx1-srcx0)*FIXEDW, y0+(srcy1-srcy0)*FIXEDW);
710
}
711
 
712
// Swap active frame buffers
713
void orgfxplus_flip()
714
{
715
    SDL_Flip(screen);
716
}
717
 
718
void orgfxplus_colorkey(unsigned int colorkey, unsigned int enable)
719
{
720
    orgfx_enable_colorkey(enable);
721
    orgfx_set_colorkey(colorkey);
722
}
723
 
724
void orgfxplus_alpha(unsigned int alpha, unsigned int enable)
725
{
726
    orgfx_enable_alpha(enable);
727
    orgfx_set_alpha(alpha);
728
}
729
 

powered by: WebSVN 2.1.0

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