comparison src/video/nds/SDL_ndsrender.c @ 2671:c3e7c0698cbb gsoc2008_nds

some changes to the dummy driver for debug purposes that should be reverted. most importantly, commenting out a check for an env. var.
author Darren Alton <dalton@stevens.edu>
date Thu, 12 Jun 2008 02:38:49 +0000
parents 6e4669f4db49
children 74ac057679d5
comparison
equal deleted inserted replaced
2670:6e4669f4db49 2671:c3e7c0698cbb
33 33
34 34
35 /* SDL surface based renderer implementation */ 35 /* SDL surface based renderer implementation */
36 36
37 static SDL_Renderer *SDL_NDS_CreateRenderer(SDL_Window * window, 37 static SDL_Renderer *SDL_NDS_CreateRenderer(SDL_Window * window,
38 Uint32 flags); 38 Uint32 flags);
39 static int SDL_NDS_RenderFill(SDL_Renderer * renderer, Uint8 r, Uint8 g, 39 static int SDL_NDS_RenderFill(SDL_Renderer * renderer, Uint8 r, Uint8 g,
40 Uint8 b, Uint8 a, const SDL_Rect * rect); 40 Uint8 b, Uint8 a, const SDL_Rect * rect);
41 static int SDL_NDS_RenderCopy(SDL_Renderer * renderer, 41 static int SDL_NDS_RenderCopy(SDL_Renderer * renderer,
42 SDL_Texture * texture, 42 SDL_Texture * texture,
43 const SDL_Rect * srcrect, 43 const SDL_Rect * srcrect,
44 const SDL_Rect * dstrect); 44 const SDL_Rect * dstrect);
45 static void SDL_NDS_RenderPresent(SDL_Renderer * renderer); 45 static void SDL_NDS_RenderPresent(SDL_Renderer * renderer);
46 static void SDL_NDS_DestroyRenderer(SDL_Renderer * renderer); 46 static void SDL_NDS_DestroyRenderer(SDL_Renderer * renderer);
47 47
48 48
49 SDL_RenderDriver SDL_NDS_RenderDriver = { 49 SDL_RenderDriver SDL_NDS_RenderDriver = {
50 SDL_NDS_CreateRenderer, 50 SDL_NDS_CreateRenderer,
51 { "nds", SDL_RENDERER_PRESENTCOPY } 51 {"nds", SDL_RENDERER_PRESENTCOPY}
52 /* (SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTCOPY | 52 /* (SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTCOPY |
53 SDL_RENDERER_PRESENTFLIP2 | SDL_RENDERER_PRESENTFLIP3 | 53 SDL_RENDERER_PRESENTFLIP2 | SDL_RENDERER_PRESENTFLIP3 |
54 SDL_RENDERER_PRESENTDISCARD),*/ 54 SDL_RENDERER_PRESENTDISCARD),*/
55 }; 55 };
56 56
71 int i, n; 71 int i, n;
72 int bpp = 16; 72 int bpp = 16;
73 Uint32 Rmask = 0x7C00, Gmask = 0x03E0, Bmask = 0x001F, Amask = 0x8000; 73 Uint32 Rmask = 0x7C00, Gmask = 0x03E0, Bmask = 0x001F, Amask = 0x8000;
74 74
75 printf("SDL_NDS_CreateRenderer(window, 0x%x)\n", flags); 75 printf("SDL_NDS_CreateRenderer(window, 0x%x)\n", flags);
76 printf(" window: (%d,%d), %dx%d\n", window->x, window->y, window->w, window->h); 76 printf(" window: (%d,%d), %dx%d\n", window->x, window->y, window->w,
77 window->h);
77 78
78 /* hard coded this to ARGB1555 for now 79 /* hard coded this to ARGB1555 for now
79 if (!SDL_PixelFormatEnumToMasks 80 if (!SDL_PixelFormatEnumToMasks
80 (displayMode->format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) { 81 (displayMode->format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) {
81 SDL_SetError("Unknown display format"); 82 SDL_SetError("Unknown display format");
82 return NULL; 83 return NULL;
83 }*/ 84 } */
84 85
85 renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer)); 86 renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer));
86 if (!renderer) { 87 if (!renderer) {
87 SDL_OutOfMemory(); 88 SDL_OutOfMemory();
88 return NULL; 89 return NULL;
116 renderer->info.flags |= SDL_RENDERER_PRESENTCOPY; 117 renderer->info.flags |= SDL_RENDERER_PRESENTCOPY;
117 n = 1; 118 n = 1;
118 } 119 }
119 for (i = 0; i < n; ++i) { 120 for (i = 0; i < n; ++i) {
120 data->screens[i] = 121 data->screens[i] =
121 SDL_CreateRGBSurface(0, 256, 192, bpp, Rmask, Gmask, Bmask, Amask); 122 SDL_CreateRGBSurface(0, 256, 192, bpp, Rmask, Gmask, Bmask,
123 Amask);
122 if (!data->screens[i]) { 124 if (!data->screens[i]) {
123 SDL_NDS_DestroyRenderer(renderer); 125 SDL_NDS_DestroyRenderer(renderer);
124 return NULL; 126 return NULL;
125 } 127 }
126 SDL_SetSurfacePalette(data->screens[i], display->palette); 128 SDL_SetSurfacePalette(data->screens[i], display->palette);
129 data->current_screen = 0; 131 data->current_screen = 0;
130 data->ultimate_answer = 42; 132 data->ultimate_answer = 42;
131 #if 0 133 #if 0
132 #define blarg (data->screens[0]) 134 #define blarg (data->screens[0])
133 printf("hello?\n"); 135 printf("hello?\n");
134 if(!data || !(data->screens) || !blarg) { 136 if (!data || !(data->screens) || !blarg) {
135 printf("they're null.\n"); 137 printf("they're null.\n");
136 } else { 138 } else {
137 printf("not null.\n"); 139 printf("not null.\n");
138 printf("%d\n%d\n%d\n%d\n%x\n%x\n%x\n%x\n", 140 printf("%d\n%d\n%d\n%d\n%x\n%x\n%x\n%x\n", blarg->w, blarg->h, blarg->pitch, blarg->format->BitsPerPixel, blarg->format->Rmask, blarg->format->Gmask, blarg->format->Bmask, (u32) (blarg->pixels)); /* ARGH WHY DOESN'T THIS PRINT AT ALL? */
139 blarg->w, blarg->h, blarg->pitch,
140 blarg->format->BitsPerPixel,
141 blarg->format->Rmask,
142 blarg->format->Gmask,
143 blarg->format->Bmask,
144 (u32)(blarg->pixels)); /* ARGH WHY DOESN'T THIS PRINT AT ALL? */
145 printf("hurr\n"); 141 printf("hurr\n");
146 } 142 }
147 #undef blarg 143 #undef blarg
148 #endif 144 #endif
149 return renderer; 145 return renderer;
150 } 146 }
151 147
152 static int 148 static int
153 SDL_NDS_RenderFill(SDL_Renderer * renderer, Uint8 r, Uint8 g, Uint8 b, 149 SDL_NDS_RenderFill(SDL_Renderer * renderer, Uint8 r, Uint8 g, Uint8 b,
154 Uint8 a, const SDL_Rect * rect) 150 Uint8 a, const SDL_Rect * rect)
155 { 151 {
156 SDL_NDS_RenderData *data = (SDL_NDS_RenderData *) renderer->driverdata; 152 SDL_NDS_RenderData *data = (SDL_NDS_RenderData *) renderer->driverdata;
157 SDL_Surface *target = data->screens[data->current_screen]; 153 SDL_Surface *target = data->screens[data->current_screen];
158 Uint32 color; 154 Uint32 color;
159 SDL_Rect real_rect = *rect; 155 SDL_Rect real_rect = *rect;
162 158
163 return SDL_FillRect(target, &real_rect, color); 159 return SDL_FillRect(target, &real_rect, color);
164 } 160 }
165 161
166 /* this is mainly for testing stuff to put a surface where I can see it */ 162 /* this is mainly for testing stuff to put a surface where I can see it */
167 void sdlds_surf2vram(SDL_Surface *s) { 163 void
164 sdlds_surf2vram(SDL_Surface * s)
165 {
168 int i; 166 int i;
169 for(i = 0; i < 256*192; ++i) { 167 for (i = 0; i < 256 * 192; ++i) {
170 ((u16*)VRAM_A)[i] = ((u16*)(s->pixels))[i]; 168 ((u16 *) VRAM_A)[i] = ((u16 *) (s->pixels))[i];
171 } 169 }
172 } 170 }
173 171
174 static int 172 static int
175 SDL_NDS_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, 173 SDL_NDS_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
176 const SDL_Rect * srcrect, const SDL_Rect * dstrect) 174 const SDL_Rect * srcrect, const SDL_Rect * dstrect)
177 { 175 {
178 SDL_NDS_RenderData *data = 176 SDL_NDS_RenderData *data = (SDL_NDS_RenderData *) renderer->driverdata;
179 (SDL_NDS_RenderData *) renderer->driverdata;
180 SDL_Window *window = SDL_GetWindowFromID(renderer->window); 177 SDL_Window *window = SDL_GetWindowFromID(renderer->window);
181 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window); 178 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
182 printf("SDL_NDS_RenderCopy(renderer, texture, srcrect, dstrect)\n"); 179 printf("SDL_NDS_RenderCopy(renderer, texture, srcrect, dstrect)\n");
183 printf(" renderer: %s\n", renderer->info.name); 180 printf(" renderer: %s\n", renderer->info.name);
184 printf(" texture: %dx%d\n", texture->w, texture->h); 181 printf(" texture: %dx%d\n", texture->w, texture->h);
185 printf(" srcrect: (%d,%d), %dx%d\n", srcrect->x, srcrect->y, srcrect->w, srcrect->h); 182 printf(" srcrect: (%d,%d), %dx%d\n", srcrect->x, srcrect->y, srcrect->w,
186 printf(" dstrect: (%d,%d), %dx%d\n", dstrect->x, dstrect->y, dstrect->w, dstrect->h); 183 srcrect->h);
184 printf(" dstrect: (%d,%d), %dx%d\n", dstrect->x, dstrect->y, dstrect->w,
185 dstrect->h);
187 186
188 if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) { 187 if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
189 SDL_Surface *target = data->screens[data->current_screen]; 188 SDL_Surface *target = data->screens[data->current_screen];
190 void *pixels = 189 void *pixels =
191 (Uint8 *) target->pixels + dstrect->y * target->pitch + 190 (Uint8 *) target->pixels + dstrect->y * target->pitch +
199 SDL_Surface *target = data->screens[data->current_screen]; 198 SDL_Surface *target = data->screens[data->current_screen];
200 SDL_Rect real_srcrect = *srcrect; 199 SDL_Rect real_srcrect = *srcrect;
201 SDL_Rect real_dstrect = *dstrect; 200 SDL_Rect real_dstrect = *dstrect;
202 printf("Rmask %x Gmask %x Bmask %x Amask %x\n" 201 printf("Rmask %x Gmask %x Bmask %x Amask %x\n"
203 "width %d, height %d, pitch %d\nbpp %d, pixels %x\n", 202 "width %d, height %d, pitch %d\nbpp %d, pixels %x\n",
204 surface->format->Rmask, surface->format->Gmask, 203 surface->format->Rmask, surface->format->Gmask,
205 surface->format->Bmask, surface->format->Amask, 204 surface->format->Bmask, surface->format->Amask,
206 surface->w, surface->h, surface->pitch, 205 surface->w, surface->h, surface->pitch,
207 surface->format->BitsPerPixel, (u32)(surface->pixels)); 206 surface->format->BitsPerPixel, (u32) (surface->pixels));
208 sdlds_surf2vram(surface); 207 sdlds_surf2vram(surface);
209 return SDL_LowerBlit(surface, &real_srcrect, target, &real_dstrect); 208 return SDL_LowerBlit(surface, &real_srcrect, target, &real_dstrect);
210 } 209 }
211 #if 0 210 #if 0
212 /* previous attempt to copy it directly to vram */ 211 /* previous attempt to copy it directly to vram */
213 SDL_Surface *surface = (SDL_Surface *) texture->driverdata; 212 SDL_Surface *surface = (SDL_Surface *) texture->driverdata;
214 int sx = srcrect->x, sy = srcrect->y, sw = srcrect->w, sh = srcrect->h; 213 int sx = srcrect->x, sy = srcrect->y, sw = srcrect->w, sh = srcrect->h;
215 int dx = dstrect->x, dy = dstrect->y, dw = dstrect->w, dh = dstrect->h; 214 int dx = dstrect->x, dy = dstrect->y, dw = dstrect->w, dh = dstrect->h;
216 int si,sj, di,dj; 215 int si, sj, di, dj;
217 /*printf("DEBUG: still alive!\n");*/ 216 /*printf("DEBUG: still alive!\n"); */
218 for(sj=0, dj=0; sj<sh && dj<dh; ++sj, ++dj) { 217 for (sj = 0, dj = 0; sj < sh && dj < dh; ++sj, ++dj) {
219 for(si=0, di=0; si<sw && di<dw; ++si, ++di) { 218 for (si = 0, di = 0; si < sw && di < dw; ++si, ++di) {
220 ((uint16*)VRAM_A)[(dj+dy)*256 + di+dx] 219 ((uint16 *) VRAM_A)[(dj + dy) * 256 + di + dx]
221 = ((Uint16*)surface->pixels)[(sj+sy)*(surface->w) + si+sx]; 220 = ((Uint16 *) surface->pixels)[(sj + sy) * (surface->w) + si +
222 } 221 sx];
223 } 222 }
224 /*printf("DEBUG: still alive!\n");*/ 223 }
225 } 224 /*printf("DEBUG: still alive!\n"); */
226 return 0; 225 }
226
227 return 0;
227 #endif 228 #endif
228 } 229 }
229 230
230 static void 231 static void
231 SDL_NDS_RenderPresent(SDL_Renderer * renderer) 232 SDL_NDS_RenderPresent(SDL_Renderer * renderer)
232 { 233 {
233 SDL_NDS_RenderData *data = 234 SDL_NDS_RenderData *data = (SDL_NDS_RenderData *) renderer->driverdata;
234 (SDL_NDS_RenderData *) renderer->driverdata;
235 235
236 printf("SDL_NDS_RenderPresent(renderer)\n"); 236 printf("SDL_NDS_RenderPresent(renderer)\n");
237 printf(" renderer: %s\n", renderer->info.name); 237 printf(" renderer: %s\n", renderer->info.name);
238 /* Send the data to the display */ 238 /* Send the data to the display */
239 239
240 #if 0 240 #if 0
241 /*testing to see if rectangles drawn get copied right*/ 241 /*testing to see if rectangles drawn get copied right*/
242 { 242 {
243 SDL_Rect ra; 243 SDL_Rect ra;
244 ra.x=0; ra.y=0; ra.w=256; ra.h=192; 244 ra.x = 0;
245 SDL_FillRect(data->screens[data->current_screen], &ra, 0x250); 245 ra.y = 0;
246 ra.x=32; ra.y=32; ra.w=192; ra.h=128; 246 ra.w = 256;
247 SDL_FillRect(data->screens[data->current_screen], &ra, 247 ra.h = 192;
248 SDL_MapRGBA(data->screens[data->current_screen]->format, 248
249 255,255,255,255)); 249 SDL_FillRect(data->screens[data->current_screen], &ra, 0x250);
250 } 250 ra.x = 32;
251 ra.y = 32;
252 ra.w = 192;
253 ra.h = 128;
254
255 SDL_FillRect(data->screens[data->current_screen], &ra,
256 SDL_MapRGBA(data->screens[data->current_screen]->format,
257 255, 255, 255, 255));
258 }
251 /*okay so this works but why not when I do it in the main()? 259 /*okay so this works but why not when I do it in the main()?
252 for some reason the screen I get from screen=SDL_SetVideoMode(...) 260 for some reason the screen I get from screen=SDL_SetVideoMode(...)
253 doesn't get copied to renderer->driverdata? */ 261 doesn't get copied to renderer->driverdata? */
254 for(i = 0; i < 30; ++i) swiWaitForVBlank(); /* delay for debug purpose */ 262 for (i = 0; i < 30; ++i)
263 swiWaitForVBlank(); /* delay for debug purpose */
255 #endif 264 #endif
256 sdlds_surf2vram(data->screens[data->current_screen]); 265 sdlds_surf2vram(data->screens[data->current_screen]);
257 266
258 /* Update the flipping chain, if any */ 267 /* Update the flipping chain, if any */
259 if (renderer->info.flags & SDL_RENDERER_PRESENTFLIP2) { 268 if (renderer->info.flags & SDL_RENDERER_PRESENTFLIP2) {