Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Latest commit

 

History

History
595 lines (537 loc) · 19.9 KB

SDL_ndsrender.c

File metadata and controls

595 lines (537 loc) · 19.9 KB
 
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
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997-2006 Sam Lantinga
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Sam Lantinga
slouken@libsdl.org
*/
#include <stdio.h>
#include <stdlib.h>
#include <nds.h>
#include "SDL_config.h"
#include "SDL_video.h"
#include "../SDL_sysvideo.h"
#include "../SDL_yuv_sw_c.h"
#include "../SDL_renderer_sw.h"
/* SDL surface based renderer implementation */
Jul 2, 2008
Jul 2, 2008
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
static SDL_Renderer *NDS_CreateRenderer(SDL_Window * window, Uint32 flags);
static int NDS_ActivateRenderer(SDL_Renderer * renderer);
static int NDS_DisplayModeChanged(SDL_Renderer * renderer);
static int NDS_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture);
static int NDS_QueryTexturePixels(SDL_Renderer * renderer,
SDL_Texture * texture, void **pixels,
int *pitch);
static int NDS_SetTexturePalette(SDL_Renderer * renderer,
SDL_Texture * texture,
const SDL_Color * colors, int firstcolor,
int ncolors);
static int NDS_GetTexturePalette(SDL_Renderer * renderer,
SDL_Texture * texture, SDL_Color * colors,
int firstcolor, int ncolors);
static int NDS_SetTextureColorMod(SDL_Renderer * renderer,
SDL_Texture * texture);
static int NDS_SetTextureAlphaMod(SDL_Renderer * renderer,
SDL_Texture * texture);
static int NDS_SetTextureBlendMode(SDL_Renderer * renderer,
SDL_Texture * texture);
static int NDS_SetTextureScaleMode(SDL_Renderer * renderer,
SDL_Texture * texture);
static int NDS_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * rect, const void *pixels,
int pitch);
static int NDS_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * rect, int markDirty, void **pixels,
int *pitch);
static void NDS_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture);
static void NDS_DirtyTexture(SDL_Renderer * renderer,
SDL_Texture * texture, int numrects,
const SDL_Rect * rects);
static int NDS_RenderFill(SDL_Renderer * renderer, Uint8 r, Uint8 g,
Jun 12, 2008
Jun 12, 2008
70
Uint8 b, Uint8 a, const SDL_Rect * rect);
Jul 2, 2008
Jul 2, 2008
71
static int NDS_RenderCopy(SDL_Renderer * renderer,
Jun 12, 2008
Jun 12, 2008
72
73
74
SDL_Texture * texture,
const SDL_Rect * srcrect,
const SDL_Rect * dstrect);
Jul 2, 2008
Jul 2, 2008
75
76
77
static void NDS_RenderPresent(SDL_Renderer * renderer);
static void NDS_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture);
static void NDS_DestroyRenderer(SDL_Renderer * renderer);
Jul 2, 2008
Jul 2, 2008
80
81
SDL_RenderDriver NDS_RenderDriver = {
NDS_CreateRenderer,
Jul 13, 2008
Jul 13, 2008
82
83
84
85
86
87
88
89
{ "nds", /* char* name */
(SDL_RENDERER_SINGLEBUFFER|SDL_RENDERER_ACCELERATED), /* u32 flags */
(SDL_TEXTUREMODULATE_NONE), /* u32 mod_modes */
(SDL_TEXTUREBLENDMODE_NONE), /* u32 blend_modes */
(SDL_TEXTURESCALEMODE_NONE), /* u32 scale_modes */
3, /* u32 num_texture_formats */
{
SDL_PIXELFORMAT_INDEX8,
Jul 25, 2008
Jul 25, 2008
90
91
SDL_PIXELFORMAT_ABGR1555,
SDL_PIXELFORMAT_BGR555,
Jul 13, 2008
Jul 13, 2008
92
93
94
95
}, /* u32 texture_formats[20] */
(256), /* int max_texture_width */
(256), /* int max_texture_height */
}
96
97
98
99
};
typedef struct
{
Jul 13, 2008
Jul 13, 2008
100
101
102
bg_attribute *bg;
u8 bg_taken[4];
int sub;
Jul 2, 2008
Jul 2, 2008
103
} NDS_RenderData;
Jul 10, 2008
Jul 10, 2008
105
106
107
typedef struct
{
enum { NDSTX_BG, NDSTX_SPR } type;
Jul 13, 2008
Jul 13, 2008
108
int hw_index;
Jul 10, 2008
Jul 10, 2008
109
110
111
struct { int w, h, pitch, bpp; } dim;
u16 *vram;
} NDS_TextureData;
Jun 17, 2008
Jun 17, 2008
112
113
114
115
116
117
118
/* this is mainly hackish testing/debugging stuff to get cleaned up soon
anything named sdlds_blah shouldn't make it into the stable version
*/
u16
Jun 19, 2008
Jun 19, 2008
119
120
121
sdlds_rgb2bgr(u16 c)
{
/* hack to get the proper colors until I actually get BGR555 to work right */
Jun 17, 2008
Jun 17, 2008
122
123
124
125
126
127
128
u16 Rmask = 0x7C00, Bmask = 0x001F, GAmask = 0x83E0, r, b;
r = (c & Rmask) >> 10;
b = (c & Bmask) << 10;
return (c & GAmask) | r | b;
}
void
Jun 19, 2008
Jun 19, 2008
129
130
131
132
133
134
sdlds_print_pixfmt_info(SDL_PixelFormat * f)
{
if (!f)
return;
printf("bpp: %d\nRGBA: %x %x %x %x\n",
f->BitsPerPixel, f->Rmask, f->Gmask, f->Bmask, f->Amask);
Jun 17, 2008
Jun 17, 2008
135
136
137
}
void
Jun 19, 2008
Jun 19, 2008
138
139
140
141
142
143
144
sdlds_print_surface_info(SDL_Surface * s)
{
if (!s)
return;
printf("flags: %x\nsize: %dx%d, pitch: %d\nlocked: %d, refcount: %d\n",
s->flags, s->w, s->h, s->pitch, s->locked, s->refcount);
sdlds_print_pixfmt_info(s->format);
Jun 17, 2008
Jun 17, 2008
145
146
}
Jul 10, 2008
Jul 10, 2008
147
/* again the above shouldn't make it into the stable version */
Jun 17, 2008
Jun 17, 2008
148
149
SDL_Renderer *
Jul 2, 2008
Jul 2, 2008
150
NDS_CreateRenderer(SDL_Window * window, Uint32 flags)
151
152
153
154
{
SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
SDL_DisplayMode *displayMode = &display->current_mode;
SDL_Renderer *renderer;
Jul 2, 2008
Jul 2, 2008
155
NDS_RenderData *data;
Jun 17, 2008
Jun 17, 2008
157
int bpp = 15;
Jun 19, 2008
Jun 19, 2008
158
159
Uint32 Rmask, Gmask, Bmask, Amask;
/* Uint32 Rmask = 0x7C00, Gmask = 0x03E0, Bmask = 0x001F, Amask = 0x8000;
Jun 17, 2008
Jun 17, 2008
160
Uint32 Rmask = 0x001F, Gmask = 0x03E0, Bmask = 0x7C00, Amask = 0x8000;
Jun 19, 2008
Jun 19, 2008
161
*/
Jul 19, 2008
Jul 19, 2008
162
printf("+NDS_CreateRenderer\n");
Jun 19, 2008
Jun 19, 2008
164
165
166
167
168
169
/* hard coded this to BGR555 for now */
if (!SDL_PixelFormatEnumToMasks(SDL_PIXELFORMAT_BGR555, &bpp,
&Rmask, &Gmask, &Bmask, &Amask)) {
SDL_SetError("Unknown display format");
return NULL;
}
170
171
172
173
174
175
176
renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer));
if (!renderer) {
SDL_OutOfMemory();
return NULL;
}
Jul 2, 2008
Jul 2, 2008
177
data = (NDS_RenderData *) SDL_malloc(sizeof(*data));
Jul 2, 2008
Jul 2, 2008
179
NDS_DestroyRenderer(renderer);
180
181
182
183
184
SDL_OutOfMemory();
return NULL;
}
SDL_zerop(data);
Jul 2, 2008
Jul 2, 2008
185
186
187
188
189
renderer->RenderFill = NDS_RenderFill;
renderer->RenderCopy = NDS_RenderCopy;
renderer->RenderPresent = NDS_RenderPresent;
renderer->DestroyRenderer = NDS_DestroyRenderer;
renderer->info.name = NDS_RenderDriver.info.name;
190
191
192
renderer->info.flags = 0;
renderer->window = window->id;
renderer->driverdata = data;
Jul 13, 2008
Jul 13, 2008
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
renderer->CreateTexture = NDS_CreateTexture;
renderer->QueryTexturePixels = NDS_QueryTexturePixels;
renderer->SetTexturePalette = NDS_SetTexturePalette;
renderer->GetTexturePalette = NDS_GetTexturePalette;
renderer->SetTextureColorMod = NDS_SetTextureColorMod;
renderer->SetTextureAlphaMod = NDS_SetTextureAlphaMod;
renderer->SetTextureBlendMode = NDS_SetTextureBlendMode;
renderer->SetTextureScaleMode = NDS_SetTextureScaleMode;
renderer->UpdateTexture = NDS_UpdateTexture;
renderer->LockTexture = NDS_LockTexture;
renderer->UnlockTexture = NDS_UnlockTexture;
renderer->DirtyTexture = NDS_DirtyTexture;
renderer->DestroyTexture = NDS_DestroyTexture;
renderer->info.mod_modes = NDS_RenderDriver.info.mod_modes;
renderer->info.blend_modes = NDS_RenderDriver.info.blend_modes;
renderer->info.scale_modes = NDS_RenderDriver.info.scale_modes;
renderer->info.num_texture_formats =
NDS_RenderDriver.info.num_texture_formats;
SDL_memcpy(renderer->info.texture_formats,
NDS_RenderDriver.info.texture_formats,
sizeof(renderer->info.texture_formats));;
renderer->info.max_texture_width = NDS_RenderDriver.info.max_texture_width;
renderer->info.max_texture_height =
NDS_RenderDriver.info.max_texture_height;
/*data->fb = (u16*)0x06020000;*/
data->bg = &BACKGROUND;
data->bg_taken[2] = data->bg_taken[3] = 0;
data->sub = 0;
Jun 17, 2008
Jun 17, 2008
223
Jul 19, 2008
Jul 19, 2008
224
printf("-NDS_CreateRenderer\n");
225
226
227
return renderer;
}
Jul 10, 2008
Jul 10, 2008
228
229
230
231
232
static int
NDS_ActivateRenderer(SDL_Renderer * renderer)
{
NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata;
/* stub. TODO: figure out what needs to be done, if anything. */
Jul 19, 2008
Jul 19, 2008
233
printf("!NDS_ActivateRenderer\n");
Jul 10, 2008
Jul 10, 2008
234
235
236
237
238
239
240
241
return 0;
}
static int
NDS_DisplayModeChanged(SDL_Renderer * renderer)
{
NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata;
/* stub. TODO: figure out what needs to be done */
Jul 19, 2008
Jul 19, 2008
242
printf("!NDS_DisplayModeChanged\n");
Jul 10, 2008
Jul 10, 2008
243
244
245
246
247
248
249
return 0;
}
static int
NDS_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
{
NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata;
Jul 13, 2008
Jul 13, 2008
250
NDS_TextureData *txdat = NULL;
Jul 26, 2008
Jul 26, 2008
251
int i;
Jul 19, 2008
Jul 19, 2008
252
printf("+NDS_CreateTexture\n");
Jul 10, 2008
Jul 10, 2008
253
254
255
256
257
258
259
260
261
262
263
264
if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
SDL_SetError("Unsupported texture format");
return -1;
} else {
int bpp;
Uint32 Rmask, Gmask, Bmask, Amask;
if (!SDL_PixelFormatEnumToMasks
(texture->format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) {
SDL_SetError("Unknown texture format");
return -1;
}
Jul 13, 2008
Jul 13, 2008
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
/* conditional statements on w/h to place it as bg/sprite */
/*if(texture->w <= 64 && texture->h <= 64) {
sprites not implemented yet. elegant, I know.
} else*/ if(texture->w <= 256 && texture->h <= 256) {
int whichbg = -1;
if(!data->bg_taken[2]) {
whichbg = 2;
data->bg->bg2_rotation.xdx = 0x100;
data->bg->bg2_rotation.xdy = 0;
data->bg->bg2_rotation.ydx = 0;
data->bg->bg2_rotation.ydy = 0x100;
data->bg->bg2_rotation.centerX = 0;
data->bg->bg2_rotation.centerY = 0;
} else if(!data->bg_taken[3]) {
whichbg = 3;
data->bg->bg3_rotation.xdx = 0x100;
data->bg->bg3_rotation.xdy = 0;
data->bg->bg3_rotation.ydx = 0;
data->bg->bg3_rotation.ydy = 0x100;
data->bg->bg3_rotation.centerX = 0;
data->bg->bg3_rotation.centerY = 0;
}
if(whichbg >= 0) {
data->bg->control[whichbg] = (bpp == 8) ?
BG_BMP8_256x256 : BG_BMP16_256x256;
data->bg->scroll[whichbg].x = 0;
data->bg->scroll[whichbg].y = 0;
texture->driverdata = SDL_calloc(1, sizeof(NDS_TextureData));
txdat = (NDS_TextureData*)texture->driverdata;
txdat->type = NDSTX_BG;
txdat->hw_index = whichbg;
txdat->dim.w = texture->w;
txdat->dim.h = texture->h;
txdat->dim.pitch = 256 * (bpp/8);
txdat->dim.bpp = bpp;
txdat->vram = (u16*)(data->sub ?
BG_BMP_RAM_SUB(whichbg) : BG_BMP_RAM(whichbg));
Jul 26, 2008
Jul 26, 2008
302
303
304
305
for(i = 0; i < 256*256; ++i) {
txdat->vram[i] = 0x8000|RGB15(0,31,31);
}
for(i = 0; i < 60; ++i) swiWaitForVBlank();
Jul 13, 2008
Jul 13, 2008
306
307
308
309
310
311
} else {
SDL_SetError("Out of NDS backgrounds.");
}
} else {
SDL_SetError("Texture too big for NDS hardware.");
}
Jul 10, 2008
Jul 10, 2008
312
313
}
Jul 19, 2008
Jul 19, 2008
314
printf("-NDS_CreateTexture\n");
Jul 10, 2008
Jul 10, 2008
315
316
317
318
319
320
321
322
323
324
if (!texture->driverdata) {
return -1;
}
return 0;
}
static int
NDS_QueryTexturePixels(SDL_Renderer * renderer, SDL_Texture * texture,
void **pixels, int *pitch)
{
Jul 19, 2008
Jul 19, 2008
325
printf("+NDS_QueryTexturePixels\n");
Jul 10, 2008
Jul 10, 2008
326
327
328
329
330
331
332
333
if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
SDL_SetError("Unsupported texture format");
return -1;
} else {
NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata;
*pixels = txdat->vram;
*pitch = txdat->dim.pitch;
Jul 19, 2008
Jul 19, 2008
334
printf("-NDS_QueryTexturePixels\n");
Jul 10, 2008
Jul 10, 2008
335
336
337
338
339
340
341
342
return 0;
}
}
static int
NDS_SetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Color * colors, int firstcolor, int ncolors)
{
Jul 19, 2008
Jul 19, 2008
343
printf("+NDS_SetTexturePalette\n");
Jul 10, 2008
Jul 10, 2008
344
345
346
347
348
349
if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
SDL_SetError("YUV textures don't have a palette");
return -1;
} else {
NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata;
/* TODO: mess with 8-bit modes and/or 16-color palette modes */
Jul 19, 2008
Jul 19, 2008
350
printf("-NDS_SetTexturePalette\n");
Jul 10, 2008
Jul 10, 2008
351
352
353
354
355
356
357
358
return 0;
}
}
static int
NDS_GetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture,
SDL_Color * colors, int firstcolor, int ncolors)
{
Jul 19, 2008
Jul 19, 2008
359
printf("+NDS_GetTexturePalette\n");
Jul 10, 2008
Jul 10, 2008
360
361
362
363
364
if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
SDL_SetError("YUV textures don't have a palette");
return -1;
} else {
NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata;
Jul 19, 2008
Jul 19, 2008
365
printf("-NDS_GetTexturePalette\n");
Jul 10, 2008
Jul 10, 2008
366
367
368
369
370
371
372
373
/* TODO: mess with 8-bit modes and/or 16-color palette modes */
return 0;
}
}
static int
NDS_SetTextureColorMod(SDL_Renderer * renderer, SDL_Texture * texture)
{
Jul 19, 2008
Jul 19, 2008
374
printf("!NDS_SetTextureColorMod\n");
Jul 10, 2008
Jul 10, 2008
375
376
377
378
379
380
381
/* stub. TODO: figure out what needs to be done, if anything */
return 0;
}
static int
NDS_SetTextureAlphaMod(SDL_Renderer * renderer, SDL_Texture * texture)
{
Jul 19, 2008
Jul 19, 2008
382
printf("!NDS_SetTextureAlphaMod\n");
Jul 10, 2008
Jul 10, 2008
383
384
385
386
387
388
389
/* stub. TODO: figure out what needs to be done, if anything */
return 0;
}
static int
NDS_SetTextureBlendMode(SDL_Renderer * renderer, SDL_Texture * texture)
{
Jul 19, 2008
Jul 19, 2008
390
printf("!NDS_SetTextureBlendMode\n");
Jul 10, 2008
Jul 10, 2008
391
392
393
394
395
396
397
/* stub. TODO: figure out what needs to be done, if anything */
return 0;
}
static int
NDS_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture)
{
Jul 19, 2008
Jul 19, 2008
398
printf("!NDS_SetTextureScaleMode\n");
Jul 10, 2008
Jul 10, 2008
399
400
401
402
403
404
405
406
407
/* stub. TODO: figure out what needs to be done.
(NDS hardware scaling is nearest neighbor.) */
return 0;
}
static int
NDS_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * rect, const void *pixels, int pitch)
{
Jul 19, 2008
Jul 19, 2008
408
printf("+NDS_UpdateTexture\n");
Jul 10, 2008
Jul 10, 2008
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
SDL_SetError("Unsupported texture format");
return -1;
} else {
NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata;
Uint8 *src, *dst;
int row;
size_t length;
/* IMPORTANT! copy the new pixels into the sprite or bg. */
src = (Uint8 *) pixels;
dst =
(Uint8 *) txdat->vram + rect->y * txdat->dim.pitch +
rect->x * (txdat->dim.bpp/8);
length = rect->w * (txdat->dim.bpp/8);
for (row = 0; row < rect->h; ++row) {
SDL_memcpy(dst, src, length);
src += pitch;
Jul 13, 2008
Jul 13, 2008
426
dst += txdat->dim.pitch;
Jul 10, 2008
Jul 10, 2008
427
}
Jul 19, 2008
Jul 19, 2008
428
printf("-NDS_UpdateTexture\n");
Jul 10, 2008
Jul 10, 2008
429
430
431
432
433
434
435
436
437
return 0;
}
}
static int
NDS_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * rect, int markDirty, void **pixels,
int *pitch)
{
Jul 19, 2008
Jul 19, 2008
438
printf("+NDS_LockTexture\n");
Jul 10, 2008
Jul 10, 2008
439
440
441
442
443
444
if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
SDL_SetError("Unsupported texture format");
return -1;
} else {
NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata;
Jul 25, 2008
Jul 25, 2008
445
if (markDirty) {
Jul 26, 2008
Jul 26, 2008
446
/*SDL_AddDirtyRect(&txdat->dirty, rect);*/
Jul 25, 2008
Jul 25, 2008
447
448
}
Jul 10, 2008
Jul 10, 2008
449
450
451
*pixels = (void *) ((u8 *)txdat->vram + rect->y * txdat->dim.pitch
+ rect->x * (txdat->dim.bpp/8));
*pitch = txdat->dim.pitch;
Jul 19, 2008
Jul 19, 2008
452
printf("-NDS_LockTexture\n");
Jul 10, 2008
Jul 10, 2008
453
454
455
456
457
458
459
460
461
462
return 0;
}
}
static void
NDS_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
{
if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
SDL_SetError("Unsupported texture format");
}
Aug 8, 2008
Aug 8, 2008
463
printf("+NDS_UnlockTexture\n-NDS_UnlockTexture\n");
Jul 10, 2008
Jul 10, 2008
464
465
466
467
468
469
}
static void
NDS_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture,
int numrects, const SDL_Rect * rects)
{ /* stub */
Jul 19, 2008
Jul 19, 2008
470
printf("!NDS_DirtyTexture\n");
Jul 10, 2008
Jul 10, 2008
471
472
}
Jul 2, 2008
Jul 2, 2008
474
NDS_RenderFill(SDL_Renderer * renderer, Uint8 r, Uint8 g, Uint8 b,
Jun 12, 2008
Jun 12, 2008
475
Uint8 a, const SDL_Rect * rect)
Jul 2, 2008
Jul 2, 2008
477
NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata;
478
SDL_Rect real_rect = *rect;
Jul 2, 2008
Jul 2, 2008
479
480
481
u16 color;
int i, j;
Jul 19, 2008
Jul 19, 2008
482
printf("+NDS_RenderFill\n");
Jul 13, 2008
Jul 13, 2008
483
/* TODO: make a single-color sprite and stretch it.
Jul 2, 2008
Jul 2, 2008
484
485
486
487
488
489
color = RGB15(r>>3,g>>3,b>>3);
for (i = real_rect.x; i < real_rect.x+real_rect.w; ++i) {
for (j = real_rect.y; j < real_rect.y+real_rect.h; ++j) {
data->fb[(j + real_rect.y) * 256 + i + real_rect.x] =
0x8000 | color;
}
Jul 13, 2008
Jul 13, 2008
490
}*/
Jul 19, 2008
Jul 19, 2008
491
printf("-NDS_RenderFill\n");
Jul 2, 2008
Jul 2, 2008
492
return 0;
Jul 10, 2008
Jul 10, 2008
494
Jul 2, 2008
Jul 2, 2008
496
NDS_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
Jun 12, 2008
Jun 12, 2008
497
const SDL_Rect * srcrect, const SDL_Rect * dstrect)
Jul 2, 2008
Jul 2, 2008
499
NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata;
Jul 25, 2008
Jul 25, 2008
500
501
502
NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata;
// SDL_Window *window = SDL_GetWindowFromID(renderer->window);
// SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
Jul 26, 2008
Jul 26, 2008
503
int i;
Jul 19, 2008
Jul 19, 2008
504
printf("+NDS_RenderCopy\n");
Aug 8, 2008
Aug 8, 2008
505
/*for(i = 0; i <= 0xFFFF; ++i) {
Jul 26, 2008
Jul 26, 2008
506
txdat->vram[i] = 0x8000|i;
Aug 8, 2008
Aug 8, 2008
507
}*/
Jul 26, 2008
Jul 26, 2008
508
509
printf("/txdat->hw_index = %d\n", txdat->hw_index);
#if 0
Jul 25, 2008
Jul 25, 2008
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
if (txdat->dirty.list) {
SDL_DirtyRect *dirty;
void *pixels;
int bpp = SDL_BYTESPERPIXEL(texture->format);
int pitch = txdat->pitch;
/* below was borrowed from SDL_renderer_gl.c. doesn't work, obv.
figure out how to get the graphics data into VRAM. */
for (dirty = txdat->dirty.list; dirty; dirty = dirty->next) {
SDL_Rect *rect = &dirty->rect;
/*pixels =
(void *) ((Uint8 *) txdat->vram + rect->y * pitch +
rect->x * bpp);
data->glTexSubImage2D(texturedata->type, 0, rect->x, rect->y,
rect->w, rect->h, texturedata->format,
texturedata->formattype, pixels);*/
}
SDL_ClearDirtyRects(&txdat->dirty);
Jul 26, 2008
Jul 26, 2008
529
#endif
Jul 19, 2008
Jul 19, 2008
530
printf("-NDS_RenderCopy\n");
Jul 26, 2008
Jul 26, 2008
531
return 0;
Jun 17, 2008
Jun 17, 2008
534
Jul 2, 2008
Jul 2, 2008
536
NDS_RenderPresent(SDL_Renderer * renderer)
Jul 2, 2008
Jul 2, 2008
538
539
NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata;
/* Send the data to the display TODO */
Jul 19, 2008
Jul 19, 2008
541
printf("+NDS_RenderPresent\n");
542
/* Update the flipping chain, if any */
Jul 13, 2008
Jul 13, 2008
543
544
if (renderer->info.flags & SDL_RENDERER_PRESENTVSYNC) {
swiWaitForVBlank();
Jul 19, 2008
Jul 19, 2008
546
printf("-NDS_RenderPresent\n");
Jul 10, 2008
Jul 10, 2008
549
550
551
static void
NDS_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture)
{
Jul 19, 2008
Jul 19, 2008
552
printf("+NDS_DestroyTexture\n");
Jul 10, 2008
Jul 10, 2008
553
554
555
if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
SDL_SetError("Unsupported texture format");
} else {
Jul 13, 2008
Jul 13, 2008
556
/* free anything else allocated for texture */
Jul 25, 2008
Jul 25, 2008
557
NDS_TextureData *txdat = texture->driverdata;
Jul 26, 2008
Jul 26, 2008
558
/*SDL_FreeDirtyRects(&txdat->dirty);*/
Jul 25, 2008
Jul 25, 2008
559
SDL_free(txdat);
Jul 10, 2008
Jul 10, 2008
560
}
Jul 19, 2008
Jul 19, 2008
561
printf("-NDS_DestroyTexture\n");
Jul 10, 2008
Jul 10, 2008
562
563
}
Jul 2, 2008
Jul 2, 2008
565
NDS_DestroyRenderer(SDL_Renderer * renderer)
Jul 2, 2008
Jul 2, 2008
567
NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata;
Jul 10, 2008
Jul 10, 2008
568
569
/*SDL_Window *window = SDL_GetWindowFromID(renderer->window);
SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);*/
Jul 19, 2008
Jul 19, 2008
572
printf("+NDS_DestroyRenderer\n");
Jul 13, 2008
Jul 13, 2008
574
575
/* TODO: free anything relevant. */
/*for (i = 0; i < SDL_arraysize(data->texture); ++i) {
Jul 10, 2008
Jul 10, 2008
576
577
if (data->texture[i]) {
DestroyTexture(data->renderer, data->texture[i]);
Jul 10, 2008
Jul 10, 2008
579
580
581
582
583
584
585
586
587
}
if (data->surface.format) {
SDL_SetSurfacePalette(&data->surface, NULL);
SDL_FreeFormat(data->surface.format);
}
if (display->palette) {
SDL_DelPaletteWatch(display->palette, DisplayPaletteChanged,
data);
}
Jul 13, 2008
Jul 13, 2008
588
SDL_FreeDirtyRects(&data->dirty);*/
589
590
591
SDL_free(data);
}
SDL_free(renderer);
Jul 19, 2008
Jul 19, 2008
592
printf("-NDS_DestroyRenderer\n");
593
594
595
}
/* vi: set ts=4 sw=4 expandtab: */