Mercurial > sdl-ios-xcode
comparison src/video/nds/SDL_ndsrender.c @ 2678:3895761db26a gsoc2008_nds
Removed old touchscreen system, starting to implement mouse-based touchscreen. Also, more work on a non-software-rendering video driver
author | Darren Alton <dalton@stevens.edu> |
---|---|
date | Thu, 10 Jul 2008 23:35:01 +0000 |
parents | 6386764eb222 |
children | bc3e3e889f6d |
comparison
equal
deleted
inserted
replaced
2677:6386764eb222 | 2678:3895761db26a |
---|---|
77 static void NDS_DestroyRenderer(SDL_Renderer * renderer); | 77 static void NDS_DestroyRenderer(SDL_Renderer * renderer); |
78 | 78 |
79 | 79 |
80 SDL_RenderDriver NDS_RenderDriver = { | 80 SDL_RenderDriver NDS_RenderDriver = { |
81 NDS_CreateRenderer, | 81 NDS_CreateRenderer, |
82 {"nds", SDL_RENDERER_PRESENTCOPY} | 82 {"nds", SDL_RENDERER_SINGLEBUFFER} |
83 /* (SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTCOPY | | 83 /*SDL_RENDERER_ values |
84 SDL_RENDERER_PRESENTFLIP2 | SDL_RENDERER_PRESENTFLIP3 | | 84 SINGLEBUFFER Render directly to the window, if possible |
85 SDL_RENDERER_PRESENTDISCARD),*/ | 85 PRESENTCOPY Present uses a copy from back buffer to the front buffer |
86 PRESENTFLIP2 Present uses a flip, swapping back buffer and front buffer | |
87 PRESENTFLIP3 Present uses a flip, rotating two back buf.s and a front buf. | |
88 PRESENTDISCARD Present leaves the contents of the backbuffer undefined | |
89 PRESENTVSYNC Present is synchronized with the refresh rate | |
90 ACCELERATED The renderer uses hardware acceleration | |
91 */ | |
86 }; | 92 }; |
87 | 93 |
88 typedef struct | 94 typedef struct |
89 { | 95 { |
90 int current_screen; | 96 int current_screen; |
91 u16* fb; | 97 u16* fb; |
92 } NDS_RenderData; | 98 } NDS_RenderData; |
93 | 99 |
100 typedef struct | |
101 { | |
102 enum { NDSTX_BG, NDSTX_SPR } type; | |
103 struct { int w, h, pitch, bpp; } dim; | |
104 u16 *vram; | |
105 } NDS_TextureData; | |
94 | 106 |
95 | 107 |
96 /* this is mainly hackish testing/debugging stuff to get cleaned up soon | 108 /* this is mainly hackish testing/debugging stuff to get cleaned up soon |
97 anything named sdlds_blah shouldn't make it into the stable version | 109 anything named sdlds_blah shouldn't make it into the stable version |
98 */ | 110 */ |
141 printf("flags: %x\nsize: %dx%d, pitch: %d\nlocked: %d, refcount: %d\n", | 153 printf("flags: %x\nsize: %dx%d, pitch: %d\nlocked: %d, refcount: %d\n", |
142 s->flags, s->w, s->h, s->pitch, s->locked, s->refcount); | 154 s->flags, s->w, s->h, s->pitch, s->locked, s->refcount); |
143 sdlds_print_pixfmt_info(s->format); | 155 sdlds_print_pixfmt_info(s->format); |
144 } | 156 } |
145 | 157 |
146 | 158 /* again the above shouldn't make it into the stable version */ |
147 | 159 |
148 SDL_Renderer * | 160 SDL_Renderer * |
149 NDS_CreateRenderer(SDL_Window * window, Uint32 flags) | 161 NDS_CreateRenderer(SDL_Window * window, Uint32 flags) |
150 { | 162 { |
151 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window); | 163 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window); |
197 renderer->info.flags |= SDL_RENDERER_PRESENTFLIP3; | 209 renderer->info.flags |= SDL_RENDERER_PRESENTFLIP3; |
198 n = 3; | 210 n = 3; |
199 } else { | 211 } else { |
200 renderer->info.flags |= SDL_RENDERER_PRESENTCOPY; | 212 renderer->info.flags |= SDL_RENDERER_PRESENTCOPY; |
201 n = 1; | 213 n = 1; |
202 }/* | 214 } |
215 /* | |
203 for (i = 0; i < n; ++i) { | 216 for (i = 0; i < n; ++i) { |
204 data->screens[i] = | 217 data->screens[i] = |
205 SDL_CreateRGBSurface(0, 256, 192, bpp, Rmask, Gmask, Bmask, | 218 SDL_CreateRGBSurface(0, 256, 192, bpp, Rmask, Gmask, Bmask, |
206 Amask); | 219 Amask); |
207 if (!data->screens[i]) { | 220 if (!data->screens[i]) { |
216 | 229 |
217 return renderer; | 230 return renderer; |
218 } | 231 } |
219 | 232 |
220 static int | 233 static int |
234 NDS_ActivateRenderer(SDL_Renderer * renderer) | |
235 { | |
236 NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata; | |
237 /* stub. TODO: figure out what needs to be done, if anything. */ | |
238 return 0; | |
239 } | |
240 | |
241 static int | |
242 NDS_DisplayModeChanged(SDL_Renderer * renderer) | |
243 { | |
244 NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata; | |
245 /* stub. TODO: figure out what needs to be done */ | |
246 return 0; | |
247 } | |
248 | |
249 static int | |
250 NDS_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) | |
251 { | |
252 NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata; | |
253 | |
254 if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) { | |
255 SDL_SetError("Unsupported texture format"); | |
256 return -1; | |
257 } else { | |
258 int bpp; | |
259 Uint32 Rmask, Gmask, Bmask, Amask; | |
260 | |
261 if (!SDL_PixelFormatEnumToMasks | |
262 (texture->format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) { | |
263 SDL_SetError("Unknown texture format"); | |
264 return -1; | |
265 } | |
266 /* TODO: appropriate checks for ABGR1555 */ | |
267 texture->driverdata = SDL_calloc(1, sizeof(NDS_TextureData)); | |
268 /* TODO: conditional statements on w/h to place it as bg/sprite */ | |
269 } | |
270 | |
271 if (!texture->driverdata) { | |
272 return -1; | |
273 } | |
274 return 0; | |
275 } | |
276 | |
277 static int | |
278 NDS_QueryTexturePixels(SDL_Renderer * renderer, SDL_Texture * texture, | |
279 void **pixels, int *pitch) | |
280 { | |
281 if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) { | |
282 SDL_SetError("Unsupported texture format"); | |
283 return -1; | |
284 } else { | |
285 NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata; | |
286 | |
287 *pixels = txdat->vram; | |
288 *pitch = txdat->dim.pitch; | |
289 return 0; | |
290 } | |
291 } | |
292 | |
293 static int | |
294 NDS_SetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture, | |
295 const SDL_Color * colors, int firstcolor, int ncolors) | |
296 { | |
297 if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) { | |
298 SDL_SetError("YUV textures don't have a palette"); | |
299 return -1; | |
300 } else { | |
301 NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata; | |
302 /* TODO: mess with 8-bit modes and/or 16-color palette modes */ | |
303 return 0; | |
304 } | |
305 } | |
306 | |
307 static int | |
308 NDS_GetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture, | |
309 SDL_Color * colors, int firstcolor, int ncolors) | |
310 { | |
311 if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) { | |
312 SDL_SetError("YUV textures don't have a palette"); | |
313 return -1; | |
314 } else { | |
315 NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata; | |
316 /* TODO: mess with 8-bit modes and/or 16-color palette modes */ | |
317 return 0; | |
318 } | |
319 } | |
320 | |
321 static int | |
322 NDS_SetTextureColorMod(SDL_Renderer * renderer, SDL_Texture * texture) | |
323 { | |
324 /* stub. TODO: figure out what needs to be done, if anything */ | |
325 return 0; | |
326 } | |
327 | |
328 static int | |
329 NDS_SetTextureAlphaMod(SDL_Renderer * renderer, SDL_Texture * texture) | |
330 { | |
331 /* stub. TODO: figure out what needs to be done, if anything */ | |
332 return 0; | |
333 } | |
334 | |
335 static int | |
336 NDS_SetTextureBlendMode(SDL_Renderer * renderer, SDL_Texture * texture) | |
337 { | |
338 /* stub. TODO: figure out what needs to be done, if anything */ | |
339 return 0; | |
340 } | |
341 | |
342 static int | |
343 NDS_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture) | |
344 { | |
345 /* stub. TODO: figure out what needs to be done. | |
346 (NDS hardware scaling is nearest neighbor.) */ | |
347 return 0; | |
348 } | |
349 | |
350 static int | |
351 NDS_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, | |
352 const SDL_Rect * rect, const void *pixels, int pitch) | |
353 { | |
354 if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) { | |
355 SDL_SetError("Unsupported texture format"); | |
356 return -1; | |
357 } else { | |
358 NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata; | |
359 Uint8 *src, *dst; | |
360 int row; | |
361 size_t length; | |
362 /* IMPORTANT! copy the new pixels into the sprite or bg. */ | |
363 src = (Uint8 *) pixels; | |
364 dst = | |
365 (Uint8 *) txdat->vram + rect->y * txdat->dim.pitch + | |
366 rect->x * (txdat->dim.bpp/8); | |
367 length = rect->w * (txdat->dim.bpp/8); | |
368 for (row = 0; row < rect->h; ++row) { | |
369 SDL_memcpy(dst, src, length); | |
370 src += pitch; | |
371 dst += surface->pitch; | |
372 } | |
373 return 0; | |
374 } | |
375 } | |
376 | |
377 static int | |
378 NDS_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, | |
379 const SDL_Rect * rect, int markDirty, void **pixels, | |
380 int *pitch) | |
381 { | |
382 if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) { | |
383 SDL_SetError("Unsupported texture format"); | |
384 return -1; | |
385 } else { | |
386 NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata; | |
387 | |
388 *pixels = (void *) ((u8 *)txdat->vram + rect->y * txdat->dim.pitch | |
389 + rect->x * (txdat->dim.bpp/8)); | |
390 *pitch = txdat->dim.pitch; | |
391 return 0; | |
392 } | |
393 } | |
394 | |
395 static void | |
396 NDS_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture) | |
397 { | |
398 if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) { | |
399 SDL_SetError("Unsupported texture format"); | |
400 } | |
401 } | |
402 | |
403 static void | |
404 NDS_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture, | |
405 int numrects, const SDL_Rect * rects) | |
406 { /* stub */ | |
407 } | |
408 | |
409 static int | |
221 NDS_RenderFill(SDL_Renderer * renderer, Uint8 r, Uint8 g, Uint8 b, | 410 NDS_RenderFill(SDL_Renderer * renderer, Uint8 r, Uint8 g, Uint8 b, |
222 Uint8 a, const SDL_Rect * rect) | 411 Uint8 a, const SDL_Rect * rect) |
223 { | 412 { |
224 NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata; | 413 NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata; |
225 SDL_Rect real_rect = *rect; | 414 SDL_Rect real_rect = *rect; |
233 0x8000 | color; | 422 0x8000 | color; |
234 } | 423 } |
235 } | 424 } |
236 return 0; | 425 return 0; |
237 } | 426 } |
427 | |
238 static int | 428 static int |
239 NDS_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, | 429 NDS_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, |
240 const SDL_Rect * srcrect, const SDL_Rect * dstrect) | 430 const SDL_Rect * srcrect, const SDL_Rect * dstrect) |
241 { | 431 { |
242 NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata; | 432 NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata; |
295 data->current_screen = (data->current_screen + 1) % 3; | 485 data->current_screen = (data->current_screen + 1) % 3; |
296 } | 486 } |
297 } | 487 } |
298 | 488 |
299 static void | 489 static void |
490 NDS_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture) | |
491 { | |
492 if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) { | |
493 SDL_SetError("Unsupported texture format"); | |
494 } else { | |
495 /* TODO: free anything allocated for texture */ | |
496 /*SDL_Surface *surface = (SDL_Surface *) texture->driverdata; | |
497 SDL_FreeSurface(surface);*/ | |
498 } | |
499 } | |
500 | |
501 static void | |
300 NDS_DestroyRenderer(SDL_Renderer * renderer) | 502 NDS_DestroyRenderer(SDL_Renderer * renderer) |
301 { | 503 { |
302 NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata; | 504 NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata; |
505 /*SDL_Window *window = SDL_GetWindowFromID(renderer->window); | |
506 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);*/ | |
303 int i; | 507 int i; |
304 | 508 |
305 printf("NDS_DestroyRenderer(renderer)\n"); | |
306 printf(" renderer: %s\n", renderer->info.name); | |
307 if (data) { | 509 if (data) { |
308 /*for (i = 0; i < SDL_arraysize(data->screens); ++i) { | 510 for (i = 0; i < SDL_arraysize(data->texture); ++i) { |
309 if (data->screens[i]) { | 511 if (data->texture[i]) { |
310 SDL_FreeSurface(data->screens[i]); | 512 DestroyTexture(data->renderer, data->texture[i]); |
311 } | 513 } |
312 }*/ | 514 } |
515 if (data->surface.format) { | |
516 SDL_SetSurfacePalette(&data->surface, NULL); | |
517 SDL_FreeFormat(data->surface.format); | |
518 } | |
519 if (display->palette) { | |
520 SDL_DelPaletteWatch(display->palette, DisplayPaletteChanged, | |
521 data); | |
522 } | |
523 SDL_FreeDirtyRects(&data->dirty); | |
313 SDL_free(data); | 524 SDL_free(data); |
314 } | 525 } |
315 SDL_free(renderer); | 526 SDL_free(renderer); |
316 } | 527 } |
317 | 528 |