annotate src/video/nds/SDL_ndsrender.c @ 5284:96a22141cf86 tip

Changed output directory of Universal libSDL.a for iOS to respect build configurations. Template generator was updated to reflect these changes as well.
author Eric Wing <ewing . public |-at-| gmail . com>
date Sat, 12 Feb 2011 21:52:30 -0800
parents 7aba0406c273
children
rev   line source
2735
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1 /*
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2 SDL - Simple DirectMedia Layer
5267
b530ef003506 Happy 2011! :)
Sam Lantinga <slouken@libsdl.org>
parents: 5251
diff changeset
3 Copyright (C) 1997-2011 Sam Lantinga
2735
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5 This library is free software; you can redistribute it and/or
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
6 modify it under the terms of the GNU Lesser General Public
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
7 License as published by the Free Software Foundation; either
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
8 version 2.1 of the License, or (at your option) any later version.
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
9
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
10 This library is distributed in the hope that it will be useful,
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
13 Lesser General Public License for more details.
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
14
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
15 You should have received a copy of the GNU Lesser General Public
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
16 License along with this library; if not, write to the Free Software
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
18
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
19 Sam Lantinga
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
20 slouken@libsdl.org
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
21 */
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
22
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
23 #include <stdio.h>
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
24 #include <stdlib.h>
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
25 #include <nds.h>
3073
c5280d33c32a NDS compiles again, but may not yet work. Sprite support has been removed for the time being while it is re-worked.
Darren Alton <dalton@stevens.edu>
parents: 2884
diff changeset
26 //#include <nds/arm9/video.h>
c5280d33c32a NDS compiles again, but may not yet work. Sprite support has been removed for the time being while it is re-worked.
Darren Alton <dalton@stevens.edu>
parents: 2884
diff changeset
27 //#include <nds/arm9/sprite.h>
c5280d33c32a NDS compiles again, but may not yet work. Sprite support has been removed for the time being while it is re-worked.
Darren Alton <dalton@stevens.edu>
parents: 2884
diff changeset
28 //#include <nds/arm9/trig_lut.h>
2735
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
29
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
30 #include "SDL_config.h"
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
31
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
32 #include "SDL_video.h"
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
33 #include "../SDL_sysvideo.h"
5275
7aba0406c273 Frank Zago to sdl
Sam Lantinga <slouken@libsdl.org>
parents: 5267
diff changeset
34 #include "SDL_render.h"
7aba0406c273 Frank Zago to sdl
Sam Lantinga <slouken@libsdl.org>
parents: 5267
diff changeset
35 #include "../../render/SDL_sysrender.h"
2735
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
36
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
37 /* SDL NDS renderer implementation */
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
38
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
39 static SDL_Renderer *NDS_CreateRenderer(SDL_Window * window, Uint32 flags);
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
40 static int NDS_ActivateRenderer(SDL_Renderer * renderer);
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
41 static int NDS_DisplayModeChanged(SDL_Renderer * renderer);
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
42 static int NDS_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture);
5275
7aba0406c273 Frank Zago to sdl
Sam Lantinga <slouken@libsdl.org>
parents: 5267
diff changeset
43 #if 0
2735
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
44 static int NDS_QueryTexturePixels(SDL_Renderer * renderer,
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
45 SDL_Texture * texture, void **pixels,
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
46 int *pitch);
5275
7aba0406c273 Frank Zago to sdl
Sam Lantinga <slouken@libsdl.org>
parents: 5267
diff changeset
47 #endif
2735
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
48 static int NDS_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
49 const SDL_Rect * rect, const void *pixels,
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
50 int pitch);
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
51 static int NDS_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
52 const SDL_Rect * rect, int markDirty,
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
53 void **pixels, int *pitch);
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
54 static void NDS_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture);
5275
7aba0406c273 Frank Zago to sdl
Sam Lantinga <slouken@libsdl.org>
parents: 5267
diff changeset
55 static int NDS_RenderFillRects(SDL_Renderer * renderer, const SDL_Rect ** rects,
7aba0406c273 Frank Zago to sdl
Sam Lantinga <slouken@libsdl.org>
parents: 5267
diff changeset
56 int count);
2735
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
57 static int NDS_RenderCopy(SDL_Renderer * renderer,
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
58 SDL_Texture * texture,
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
59 const SDL_Rect * srcrect, const SDL_Rect * dstrect);
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
60 static void NDS_RenderPresent(SDL_Renderer * renderer);
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
61 static void NDS_DestroyTexture(SDL_Renderer * renderer,
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
62 SDL_Texture * texture);
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
63 static void NDS_DestroyRenderer(SDL_Renderer * renderer);
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
64
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
65
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
66 SDL_RenderDriver NDS_RenderDriver = {
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
67 NDS_CreateRenderer,
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
68 {"nds", /* char* name */
5145
c8e049de174c Making the API simpler, the renderer present semantics are always having a backbuffer and then discarding it. This is best for hardware accelerated rendering.
Sam Lantinga <slouken@libsdl.org>
parents: 5144
diff changeset
69 (SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC), /* u32 flags */
5152
be02be2ea897 Making the API simpler, removed support for palettized video modes and textures.
Sam Lantinga <slouken@libsdl.org>
parents: 5145
diff changeset
70 2, /* u32 num_texture_formats */
2735
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
71 {
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
72 SDL_PIXELFORMAT_ABGR1555,
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
73 SDL_PIXELFORMAT_BGR555,
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3073
diff changeset
74 }, /* u32 texture_formats[20] */
2735
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
75 (256), /* int max_texture_width */
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
76 (256), /* int max_texture_height */
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
77 }
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
78 };
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
79
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
80 typedef struct
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
81 {
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
82 u8 bg_taken[4];
3073
c5280d33c32a NDS compiles again, but may not yet work. Sprite support has been removed for the time being while it is re-worked.
Darren Alton <dalton@stevens.edu>
parents: 2884
diff changeset
83 OamState *oam;
2735
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
84 int sub;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
85 } NDS_RenderData;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
86
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
87 typedef struct
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
88 {
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
89 enum
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
90 { NDSTX_BG, NDSTX_SPR } type; /* represented in a bg or sprite. */
3073
c5280d33c32a NDS compiles again, but may not yet work. Sprite support has been removed for the time being while it is re-worked.
Darren Alton <dalton@stevens.edu>
parents: 2884
diff changeset
91 int hw_index; /* index of sprite in OAM or bg from libnds */
c5280d33c32a NDS compiles again, but may not yet work. Sprite support has been removed for the time being while it is re-worked.
Darren Alton <dalton@stevens.edu>
parents: 2884
diff changeset
92 int pitch, bpp; /* useful information about the texture */
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3073
diff changeset
93 struct
Sam Lantinga <slouken@libsdl.org>
parents: 3073
diff changeset
94 {
Sam Lantinga <slouken@libsdl.org>
parents: 3073
diff changeset
95 int x, y;
Sam Lantinga <slouken@libsdl.org>
parents: 3073
diff changeset
96 } scale; /* x/y stretch (24.8 fixed point) */
Sam Lantinga <slouken@libsdl.org>
parents: 3073
diff changeset
97 struct
Sam Lantinga <slouken@libsdl.org>
parents: 3073
diff changeset
98 {
Sam Lantinga <slouken@libsdl.org>
parents: 3073
diff changeset
99 int x, y;
Sam Lantinga <slouken@libsdl.org>
parents: 3073
diff changeset
100 } scroll; /* x/y offset */
3073
c5280d33c32a NDS compiles again, but may not yet work. Sprite support has been removed for the time being while it is re-worked.
Darren Alton <dalton@stevens.edu>
parents: 2884
diff changeset
101 int rotate; /* -32768 to 32767, texture rotation */
2735
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
102 u16 *vram_pixels; /* where the pixel data is stored (a pointer into VRAM) */
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
103 u16 *vram_palette; /* where the palette data is stored if it's indexed. */
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
104 /*int size; */
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
105 } NDS_TextureData;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
106
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
107
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
108
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
109 SDL_Renderer *
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
110 NDS_CreateRenderer(SDL_Window * window, Uint32 flags)
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
111 {
5251
58265e606e4e Window coordinates are in the global space and windows are not tied to a particular display.
Sam Lantinga <slouken@libsdl.org>
parents: 5152
diff changeset
112 SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
2735
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
113 SDL_DisplayMode *displayMode = &display->current_mode;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
114 SDL_Renderer *renderer;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
115 NDS_RenderData *data;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
116 int i, n;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
117 int bpp;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
118 Uint32 Rmask, Gmask, Bmask, Amask;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
119
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
120 if (!SDL_PixelFormatEnumToMasks(displayMode->format, &bpp,
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
121 &Rmask, &Gmask, &Bmask, &Amask)) {
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
122 SDL_SetError("Unknown display format");
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
123 return NULL;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
124 }
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
125 switch (displayMode->format) {
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
126 case SDL_PIXELFORMAT_ABGR1555:
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
127 case SDL_PIXELFORMAT_BGR555:
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
128 /* okay */
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
129 break;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
130 case SDL_PIXELFORMAT_RGB555:
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
131 case SDL_PIXELFORMAT_RGB565:
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
132 case SDL_PIXELFORMAT_ARGB1555:
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
133 /* we'll take these too for now */
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
134 break;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
135 default:
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
136 SDL_SetError("Warning: wrong display format for NDS!\n");
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
137 break;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
138 }
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
139
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
140 renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer));
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
141 if (!renderer) {
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
142 SDL_OutOfMemory();
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
143 return NULL;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
144 }
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
145
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
146 data = (NDS_RenderData *) SDL_malloc(sizeof(*data));
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
147 if (!data) {
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
148 NDS_DestroyRenderer(renderer);
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
149 SDL_OutOfMemory();
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
150 return NULL;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
151 }
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
152 SDL_zerop(data);
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
153
5275
7aba0406c273 Frank Zago to sdl
Sam Lantinga <slouken@libsdl.org>
parents: 5267
diff changeset
154 renderer->RenderFillRects = NDS_RenderFillRects;
2735
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
155 renderer->RenderCopy = NDS_RenderCopy;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
156 renderer->RenderPresent = NDS_RenderPresent;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
157 renderer->DestroyRenderer = NDS_DestroyRenderer;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
158 renderer->info.name = NDS_RenderDriver.info.name;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
159 renderer->info.flags = 0;
3685
64ce267332c6 Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents: 3139
diff changeset
160 renderer->window = window;
2735
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
161 renderer->driverdata = data;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
162 renderer->CreateTexture = NDS_CreateTexture;
5275
7aba0406c273 Frank Zago to sdl
Sam Lantinga <slouken@libsdl.org>
parents: 5267
diff changeset
163 // renderer->QueryTexturePixels = NDS_QueryTexturePixels;
2735
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
164 renderer->UpdateTexture = NDS_UpdateTexture;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
165 renderer->LockTexture = NDS_LockTexture;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
166 renderer->UnlockTexture = NDS_UnlockTexture;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
167 renderer->DestroyTexture = NDS_DestroyTexture;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
168
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
169 renderer->info.num_texture_formats =
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
170 NDS_RenderDriver.info.num_texture_formats;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
171 SDL_memcpy(renderer->info.texture_formats,
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
172 NDS_RenderDriver.info.texture_formats,
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
173 sizeof(renderer->info.texture_formats));
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
174 renderer->info.max_texture_width =
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
175 NDS_RenderDriver.info.max_texture_width;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
176 renderer->info.max_texture_height =
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
177 NDS_RenderDriver.info.max_texture_height;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
178
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3073
diff changeset
179 data->sub = 0; /* TODO: this is hard-coded to the "main" screen.
Sam Lantinga <slouken@libsdl.org>
parents: 3073
diff changeset
180 figure out how to detect whether to set it to
Sam Lantinga <slouken@libsdl.org>
parents: 3073
diff changeset
181 "sub" screen. window->id, perhaps? */
2735
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
182 data->bg_taken[2] = data->bg_taken[3] = 0;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
183
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
184 return renderer;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
185 }
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
186
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
187 static int
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
188 NDS_ActivateRenderer(SDL_Renderer * renderer)
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
189 {
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
190 NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
191
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
192 return 0;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
193 }
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
194
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
195 static int
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
196 NDS_DisplayModeChanged(SDL_Renderer * renderer)
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
197 {
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
198 NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
199
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
200 return 0;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
201 }
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
202
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
203 static int
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
204 NDS_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
205 {
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
206 NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
207 NDS_TextureData *txdat = NULL;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
208 int i;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
209 int bpp;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
210 Uint32 Rmask, Gmask, Bmask, Amask;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
211
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
212 if (!SDL_PixelFormatEnumToMasks
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
213 (texture->format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) {
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
214 SDL_SetError("Unknown texture format");
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
215 return -1;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
216 }
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
217
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
218 /* conditional statements on w/h to place it as bg/sprite
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
219 depending on which one it fits. */
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
220 if (texture->w <= 64 && texture->h <= 64) {
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
221 int whichspr = -1;
3073
c5280d33c32a NDS compiles again, but may not yet work. Sprite support has been removed for the time being while it is re-worked.
Darren Alton <dalton@stevens.edu>
parents: 2884
diff changeset
222 printf("NDS_CreateTexture: Tried to make a sprite.\n");
2735
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
223 txdat->type = NDSTX_SPR;
3073
c5280d33c32a NDS compiles again, but may not yet work. Sprite support has been removed for the time being while it is re-worked.
Darren Alton <dalton@stevens.edu>
parents: 2884
diff changeset
224 #if 0
2735
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
225 for (i = 0; i < SPRITE_COUNT; ++i) {
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
226 if (data->oam_copy.spriteBuffer[i].attribute[0] & ATTR0_DISABLED) {
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
227 whichspr = i;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
228 break;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
229 }
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
230 }
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
231 if (whichspr >= 0) {
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
232 SpriteEntry *sprent = &(data->oam_copy.spriteBuffer[whichspr]);
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
233 int maxside = texture->w > texture->h ? texture->w : texture->h;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
234 int pitch;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
235
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
236 texture->driverdata = SDL_calloc(1, sizeof(NDS_TextureData));
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
237 txdat = (NDS_TextureData *) texture->driverdata;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
238 if (!txdat) {
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
239 SDL_OutOfMemory();
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
240 return -1;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
241 }
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
242
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
243 sprent->objMode = OBJMODE_BITMAP;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
244 sprent->posX = 0;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
245 sprent->posY = 0;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
246 sprent->colMode = OBJCOLOR_16; /* OBJCOLOR_256 for INDEX8 */
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
247
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
248 /* the first 32 sprites get transformation matrices.
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
249 first come, first served */
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
250 if (whichspr < MATRIX_COUNT) {
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
251 sprent->isRotoscale = 1;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
252 sprent->rsMatrixIdx = whichspr;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
253 }
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
254
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
255 /* containing shape (square or 2:1 rectangles) */
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
256 sprent->objShape = OBJSHAPE_SQUARE;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
257 if (texture->w / 2 >= texture->h) {
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
258 sprent->objShape = OBJSHAPE_WIDE;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
259 } else if (texture->h / 2 >= texture->w) {
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
260 sprent->objShape = OBJSHAPE_TALL;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
261 }
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
262
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
263 /* size in pixels */
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
264 /* FIXME: "pitch" is hardcoded for 2bytes per pixel. */
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
265 sprent->objSize = OBJSIZE_64;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
266 pitch = 128;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
267 if (maxside <= 8) {
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
268 sprent->objSize = OBJSIZE_8;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
269 pitch = 16;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
270 } else if (maxside <= 16) {
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
271 sprent->objSize = OBJSIZE_16;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
272 pitch = 32;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
273 } else if (maxside <= 32) {
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
274 sprent->objSize = OBJSIZE_32;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
275 pitch = 64;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
276 }
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
277
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
278 /* FIXME: this is hard-coded and will obviously only work for one
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
279 sprite-texture. tells it to look at the beginning of SPRITE_GFX
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
280 for its pixels. */
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
281 sprent->tileIdx = 0;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
282
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
283 /* now for the texture data */
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
284 txdat->type = NDSTX_SPR;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
285 txdat->hw_index = whichspr;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
286 txdat->dim.hdx = 0x100;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
287 txdat->dim.hdy = 0;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
288 txdat->dim.vdx = 0;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
289 txdat->dim.vdy = 0x100;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
290 txdat->dim.pitch = pitch;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
291 txdat->dim.bpp = bpp;
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3073
diff changeset
292 txdat->vram_pixels =
Sam Lantinga <slouken@libsdl.org>
parents: 3073
diff changeset
293 (u16 *) (data->sub ? SPRITE_GFX_SUB : SPRITE_GFX);
3073
c5280d33c32a NDS compiles again, but may not yet work. Sprite support has been removed for the time being while it is re-worked.
Darren Alton <dalton@stevens.edu>
parents: 2884
diff changeset
294 /* FIXME: use tileIdx*boundary
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3073
diff changeset
295 to point to proper location */
2735
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
296 } else {
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
297 SDL_SetError("Out of NDS sprites.");
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
298 }
3073
c5280d33c32a NDS compiles again, but may not yet work. Sprite support has been removed for the time being while it is re-worked.
Darren Alton <dalton@stevens.edu>
parents: 2884
diff changeset
299 #endif
2735
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
300 } else if (texture->w <= 256 && texture->h <= 256) {
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
301 int whichbg = -1, base = 0;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
302 if (!data->bg_taken[2]) {
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
303 whichbg = 2;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
304 } else if (!data->bg_taken[3]) {
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
305 whichbg = 3;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
306 base = 4;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
307 }
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
308 if (whichbg >= 0) {
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
309 texture->driverdata = SDL_calloc(1, sizeof(NDS_TextureData));
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
310 txdat = (NDS_TextureData *) texture->driverdata;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
311 if (!txdat) {
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
312 SDL_OutOfMemory();
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
313 return -1;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
314 }
3073
c5280d33c32a NDS compiles again, but may not yet work. Sprite support has been removed for the time being while it is re-worked.
Darren Alton <dalton@stevens.edu>
parents: 2884
diff changeset
315 // hard-coded for 256x256 for now...
c5280d33c32a NDS compiles again, but may not yet work. Sprite support has been removed for the time being while it is re-worked.
Darren Alton <dalton@stevens.edu>
parents: 2884
diff changeset
316 // TODO: a series of if-elseif-else's to find the closest but larger size.
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3073
diff changeset
317 if (!data->sub) {
Sam Lantinga <slouken@libsdl.org>
parents: 3073
diff changeset
318 if (bpp == 8) {
Sam Lantinga <slouken@libsdl.org>
parents: 3073
diff changeset
319 txdat->hw_index =
Sam Lantinga <slouken@libsdl.org>
parents: 3073
diff changeset
320 bgInit(whichbg, BgType_Bmp8, BgSize_B8_256x256, 0, 0);
3073
c5280d33c32a NDS compiles again, but may not yet work. Sprite support has been removed for the time being while it is re-worked.
Darren Alton <dalton@stevens.edu>
parents: 2884
diff changeset
321 } else {
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3073
diff changeset
322 txdat->hw_index =
Sam Lantinga <slouken@libsdl.org>
parents: 3073
diff changeset
323 bgInit(whichbg, BgType_Bmp16, BgSize_B16_256x256, 0,
Sam Lantinga <slouken@libsdl.org>
parents: 3073
diff changeset
324 0);
3073
c5280d33c32a NDS compiles again, but may not yet work. Sprite support has been removed for the time being while it is re-worked.
Darren Alton <dalton@stevens.edu>
parents: 2884
diff changeset
325 }
c5280d33c32a NDS compiles again, but may not yet work. Sprite support has been removed for the time being while it is re-worked.
Darren Alton <dalton@stevens.edu>
parents: 2884
diff changeset
326 } else {
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3073
diff changeset
327 if (bpp == 8) {
Sam Lantinga <slouken@libsdl.org>
parents: 3073
diff changeset
328 txdat->hw_index =
Sam Lantinga <slouken@libsdl.org>
parents: 3073
diff changeset
329 bgInitSub(whichbg, BgType_Bmp8, BgSize_B8_256x256, 0,
Sam Lantinga <slouken@libsdl.org>
parents: 3073
diff changeset
330 0);
3073
c5280d33c32a NDS compiles again, but may not yet work. Sprite support has been removed for the time being while it is re-worked.
Darren Alton <dalton@stevens.edu>
parents: 2884
diff changeset
331 } else {
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3073
diff changeset
332 txdat->hw_index =
Sam Lantinga <slouken@libsdl.org>
parents: 3073
diff changeset
333 bgInitSub(whichbg, BgType_Bmp16, BgSize_B16_256x256,
Sam Lantinga <slouken@libsdl.org>
parents: 3073
diff changeset
334 0, 0);
3073
c5280d33c32a NDS compiles again, but may not yet work. Sprite support has been removed for the time being while it is re-worked.
Darren Alton <dalton@stevens.edu>
parents: 2884
diff changeset
335 }
c5280d33c32a NDS compiles again, but may not yet work. Sprite support has been removed for the time being while it is re-worked.
Darren Alton <dalton@stevens.edu>
parents: 2884
diff changeset
336 }
2735
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
337
3073
c5280d33c32a NDS compiles again, but may not yet work. Sprite support has been removed for the time being while it is re-worked.
Darren Alton <dalton@stevens.edu>
parents: 2884
diff changeset
338 /* useful functions
c5280d33c32a NDS compiles again, but may not yet work. Sprite support has been removed for the time being while it is re-worked.
Darren Alton <dalton@stevens.edu>
parents: 2884
diff changeset
339 bgGetGfxPtr(bg3);
c5280d33c32a NDS compiles again, but may not yet work. Sprite support has been removed for the time being while it is re-worked.
Darren Alton <dalton@stevens.edu>
parents: 2884
diff changeset
340 bgSetCenter(bg3, rcX, rcY);
c5280d33c32a NDS compiles again, but may not yet work. Sprite support has been removed for the time being while it is re-worked.
Darren Alton <dalton@stevens.edu>
parents: 2884
diff changeset
341 bgSetRotateScale(bg3, angle, scaleX, scaleY);
c5280d33c32a NDS compiles again, but may not yet work. Sprite support has been removed for the time being while it is re-worked.
Darren Alton <dalton@stevens.edu>
parents: 2884
diff changeset
342 bgSetScroll(bg3, scrollX, scrollY);
c5280d33c32a NDS compiles again, but may not yet work. Sprite support has been removed for the time being while it is re-worked.
Darren Alton <dalton@stevens.edu>
parents: 2884
diff changeset
343 bgUpdate(bg3);
c5280d33c32a NDS compiles again, but may not yet work. Sprite support has been removed for the time being while it is re-worked.
Darren Alton <dalton@stevens.edu>
parents: 2884
diff changeset
344 */
2735
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
345 txdat->type = NDSTX_BG;
5275
7aba0406c273 Frank Zago to sdl
Sam Lantinga <slouken@libsdl.org>
parents: 5267
diff changeset
346 txdat->pitch = (texture->w) * ((bpp+1) / 8);
3073
c5280d33c32a NDS compiles again, but may not yet work. Sprite support has been removed for the time being while it is re-worked.
Darren Alton <dalton@stevens.edu>
parents: 2884
diff changeset
347 txdat->bpp = bpp;
c5280d33c32a NDS compiles again, but may not yet work. Sprite support has been removed for the time being while it is re-worked.
Darren Alton <dalton@stevens.edu>
parents: 2884
diff changeset
348 txdat->rotate = 0;
c5280d33c32a NDS compiles again, but may not yet work. Sprite support has been removed for the time being while it is re-worked.
Darren Alton <dalton@stevens.edu>
parents: 2884
diff changeset
349 txdat->scale.x = 0x100;
c5280d33c32a NDS compiles again, but may not yet work. Sprite support has been removed for the time being while it is re-worked.
Darren Alton <dalton@stevens.edu>
parents: 2884
diff changeset
350 txdat->scale.y = 0x100;
c5280d33c32a NDS compiles again, but may not yet work. Sprite support has been removed for the time being while it is re-worked.
Darren Alton <dalton@stevens.edu>
parents: 2884
diff changeset
351 txdat->scroll.x = 0;
c5280d33c32a NDS compiles again, but may not yet work. Sprite support has been removed for the time being while it is re-worked.
Darren Alton <dalton@stevens.edu>
parents: 2884
diff changeset
352 txdat->scroll.y = 0;
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3073
diff changeset
353 txdat->vram_pixels = (u16 *) bgGetGfxPtr(txdat->hw_index);
2735
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
354
3073
c5280d33c32a NDS compiles again, but may not yet work. Sprite support has been removed for the time being while it is re-worked.
Darren Alton <dalton@stevens.edu>
parents: 2884
diff changeset
355 bgSetCenter(txdat->hw_index, 0, 0);
c5280d33c32a NDS compiles again, but may not yet work. Sprite support has been removed for the time being while it is re-worked.
Darren Alton <dalton@stevens.edu>
parents: 2884
diff changeset
356 bgSetRotateScale(txdat->hw_index, txdat->rotate, txdat->scale.x,
c5280d33c32a NDS compiles again, but may not yet work. Sprite support has been removed for the time being while it is re-worked.
Darren Alton <dalton@stevens.edu>
parents: 2884
diff changeset
357 txdat->scale.y);
c5280d33c32a NDS compiles again, but may not yet work. Sprite support has been removed for the time being while it is re-worked.
Darren Alton <dalton@stevens.edu>
parents: 2884
diff changeset
358 bgSetScroll(txdat->hw_index, txdat->scroll.x, txdat->scroll.y);
5275
7aba0406c273 Frank Zago to sdl
Sam Lantinga <slouken@libsdl.org>
parents: 5267
diff changeset
359 bgUpdate();
3073
c5280d33c32a NDS compiles again, but may not yet work. Sprite support has been removed for the time being while it is re-worked.
Darren Alton <dalton@stevens.edu>
parents: 2884
diff changeset
360
c5280d33c32a NDS compiles again, but may not yet work. Sprite support has been removed for the time being while it is re-worked.
Darren Alton <dalton@stevens.edu>
parents: 2884
diff changeset
361 data->bg_taken[whichbg] = 1;
2735
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
362 /*txdat->size = txdat->dim.pitch * texture->h; */
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
363 } else {
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
364 SDL_SetError("Out of NDS backgrounds.");
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
365 }
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
366 } else {
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
367 SDL_SetError("Texture too big for NDS hardware.");
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
368 }
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
369
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
370 if (!texture->driverdata) {
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
371 return -1;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
372 }
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
373
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
374 return 0;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
375 }
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
376
5275
7aba0406c273 Frank Zago to sdl
Sam Lantinga <slouken@libsdl.org>
parents: 5267
diff changeset
377 #if 0
2735
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
378 static int
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
379 NDS_QueryTexturePixels(SDL_Renderer * renderer, SDL_Texture * texture,
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
380 void **pixels, int *pitch)
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
381 {
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
382 NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
383 *pixels = txdat->vram_pixels;
3073
c5280d33c32a NDS compiles again, but may not yet work. Sprite support has been removed for the time being while it is re-worked.
Darren Alton <dalton@stevens.edu>
parents: 2884
diff changeset
384 *pitch = txdat->pitch;
2735
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
385 return 0;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
386 }
5275
7aba0406c273 Frank Zago to sdl
Sam Lantinga <slouken@libsdl.org>
parents: 5267
diff changeset
387 #endif
2735
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
388
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
389 static int
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
390 NDS_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
391 const SDL_Rect * rect, const void *pixels, int pitch)
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
392 {
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
393 NDS_TextureData *txdat;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
394 Uint8 *src, *dst;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
395 int row;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
396 size_t length;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
397
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
398 txdat = (NDS_TextureData *) texture->driverdata;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
399
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
400 src = (Uint8 *) pixels;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
401 dst =
3073
c5280d33c32a NDS compiles again, but may not yet work. Sprite support has been removed for the time being while it is re-worked.
Darren Alton <dalton@stevens.edu>
parents: 2884
diff changeset
402 (Uint8 *) txdat->vram_pixels + rect->y * txdat->pitch + rect->x *
c5280d33c32a NDS compiles again, but may not yet work. Sprite support has been removed for the time being while it is re-worked.
Darren Alton <dalton@stevens.edu>
parents: 2884
diff changeset
403 ((txdat->bpp + 1) / 8);
c5280d33c32a NDS compiles again, but may not yet work. Sprite support has been removed for the time being while it is re-worked.
Darren Alton <dalton@stevens.edu>
parents: 2884
diff changeset
404 length = rect->w * ((txdat->bpp + 1) / 8);
2735
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
405
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
406 if (rect->w == texture->w) {
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
407 dmaCopy(src, dst, length * rect->h);
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
408 } else {
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
409 for (row = 0; row < rect->h; ++row) {
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
410 dmaCopy(src, dst, length);
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
411 src += pitch;
3073
c5280d33c32a NDS compiles again, but may not yet work. Sprite support has been removed for the time being while it is re-worked.
Darren Alton <dalton@stevens.edu>
parents: 2884
diff changeset
412 dst += txdat->pitch;
2735
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
413 }
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
414 }
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
415
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
416 return 0;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
417 }
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
418
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
419 static int
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
420 NDS_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
421 const SDL_Rect * rect, int markDirty, void **pixels,
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
422 int *pitch)
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
423 {
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
424 NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
425
3073
c5280d33c32a NDS compiles again, but may not yet work. Sprite support has been removed for the time being while it is re-worked.
Darren Alton <dalton@stevens.edu>
parents: 2884
diff changeset
426 *pixels = (void *) ((u8 *) txdat->vram_pixels + rect->y * txdat->pitch +
c5280d33c32a NDS compiles again, but may not yet work. Sprite support has been removed for the time being while it is re-worked.
Darren Alton <dalton@stevens.edu>
parents: 2884
diff changeset
427 rect->x * ((txdat->bpp + 1) / 8));
c5280d33c32a NDS compiles again, but may not yet work. Sprite support has been removed for the time being while it is re-worked.
Darren Alton <dalton@stevens.edu>
parents: 2884
diff changeset
428 *pitch = txdat->pitch;
2735
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
429
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
430 return 0;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
431 }
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
432
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
433 static void
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
434 NDS_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
435 {
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
436 /* stub! */
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
437 }
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
438
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
439 static int
5275
7aba0406c273 Frank Zago to sdl
Sam Lantinga <slouken@libsdl.org>
parents: 5267
diff changeset
440 NDS_RenderFillRects(SDL_Renderer * renderer, const SDL_Rect ** rects,
7aba0406c273 Frank Zago to sdl
Sam Lantinga <slouken@libsdl.org>
parents: 5267
diff changeset
441 int count)
2735
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
442 {
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
443 NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
444
3073
c5280d33c32a NDS compiles again, but may not yet work. Sprite support has been removed for the time being while it is re-worked.
Darren Alton <dalton@stevens.edu>
parents: 2884
diff changeset
445 printf("NDS_RenderFill: stub\n");
5275
7aba0406c273 Frank Zago to sdl
Sam Lantinga <slouken@libsdl.org>
parents: 5267
diff changeset
446
2735
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
447 /* TODO: make a single-color sprite and stretch it.
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
448 calculate the "HDX" width modifier of the sprite by:
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
449 let S be the actual sprite's width (like, 32 pixels for example)
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
450 let R be the rectangle's width (maybe 50 pixels)
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
451 HDX = (R<<8) / S;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
452 (it's fixed point, hence the bit shift. same goes for vertical.
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
453 be sure to use 32-bit int's for the bit shift before the division!)
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
454 */
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
455
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
456 return 0;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
457 }
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
458
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
459 static int
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
460 NDS_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
461 const SDL_Rect * srcrect, const SDL_Rect * dstrect)
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
462 {
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
463 NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
464 NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata;
3685
64ce267332c6 Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents: 3139
diff changeset
465 SDL_Window *window = renderer->window;
5251
58265e606e4e Window coordinates are in the global space and windows are not tied to a particular display.
Sam Lantinga <slouken@libsdl.org>
parents: 5152
diff changeset
466 SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
3073
c5280d33c32a NDS compiles again, but may not yet work. Sprite support has been removed for the time being while it is re-worked.
Darren Alton <dalton@stevens.edu>
parents: 2884
diff changeset
467 int Bpp = SDL_BYTESPERPIXEL(texture->format);
2735
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
468
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
469 if (txdat->type == NDSTX_BG) {
3073
c5280d33c32a NDS compiles again, but may not yet work. Sprite support has been removed for the time being while it is re-worked.
Darren Alton <dalton@stevens.edu>
parents: 2884
diff changeset
470 txdat->scroll.x = dstrect->x;
c5280d33c32a NDS compiles again, but may not yet work. Sprite support has been removed for the time being while it is re-worked.
Darren Alton <dalton@stevens.edu>
parents: 2884
diff changeset
471 txdat->scroll.y = dstrect->y;
2735
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
472 } else {
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
473 /* sprites not fully implemented yet */
3073
c5280d33c32a NDS compiles again, but may not yet work. Sprite support has been removed for the time being while it is re-worked.
Darren Alton <dalton@stevens.edu>
parents: 2884
diff changeset
474 printf("NDS_RenderCopy: used sprite!\n");
c5280d33c32a NDS compiles again, but may not yet work. Sprite support has been removed for the time being while it is re-worked.
Darren Alton <dalton@stevens.edu>
parents: 2884
diff changeset
475 // SpriteEntry *spr = &(data->oam_copy.spriteBuffer[txdat->hw_index]);
c5280d33c32a NDS compiles again, but may not yet work. Sprite support has been removed for the time being while it is re-worked.
Darren Alton <dalton@stevens.edu>
parents: 2884
diff changeset
476 // spr->posX = dstrect->x;
c5280d33c32a NDS compiles again, but may not yet work. Sprite support has been removed for the time being while it is re-worked.
Darren Alton <dalton@stevens.edu>
parents: 2884
diff changeset
477 // spr->posY = dstrect->y;
c5280d33c32a NDS compiles again, but may not yet work. Sprite support has been removed for the time being while it is re-worked.
Darren Alton <dalton@stevens.edu>
parents: 2884
diff changeset
478 // if (txdat->hw_index < MATRIX_COUNT && spr->isRotoscale) {
c5280d33c32a NDS compiles again, but may not yet work. Sprite support has been removed for the time being while it is re-worked.
Darren Alton <dalton@stevens.edu>
parents: 2884
diff changeset
479 // }
2735
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
480 }
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
481
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
482 return 0;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
483 }
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
484
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
485
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
486 static void
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
487 NDS_RenderPresent(SDL_Renderer * renderer)
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
488 {
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
489 NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata;
3685
64ce267332c6 Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents: 3139
diff changeset
490 SDL_Window *window = renderer->window;
5251
58265e606e4e Window coordinates are in the global space and windows are not tied to a particular display.
Sam Lantinga <slouken@libsdl.org>
parents: 5152
diff changeset
491 SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
2735
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
492
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
493 /* update sprites */
3073
c5280d33c32a NDS compiles again, but may not yet work. Sprite support has been removed for the time being while it is re-worked.
Darren Alton <dalton@stevens.edu>
parents: 2884
diff changeset
494 // NDS_OAM_Update(&(data->oam_copy), data->sub);
2735
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
495 /* vsync for NDS */
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
496 if (renderer->info.flags & SDL_RENDERER_PRESENTVSYNC) {
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
497 swiWaitForVBlank();
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
498 }
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
499 }
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
500
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
501 static void
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
502 NDS_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture)
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
503 {
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
504 NDS_TextureData *txdat = texture->driverdata;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
505 /* free anything else allocated for texture */
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
506 SDL_free(txdat);
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
507 }
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
508
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
509 static void
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
510 NDS_DestroyRenderer(SDL_Renderer * renderer)
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
511 {
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
512 NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
513 int i;
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
514
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
515 if (data) {
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
516 /* free anything else relevant if anything else is allocated. */
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
517 SDL_free(data);
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
518 }
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
519 SDL_free(renderer);
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
520 }
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
521
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
522 /* vi: set ts=4 sw=4 expandtab: */