Mercurial > sdl-ios-xcode
comparison src/video/SDL_renderer_sw.c @ 1681:80a5e6a4e1e2 SDL-1.3
Working on paletted display and texture support (two different issues)
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Thu, 15 Jun 2006 07:07:07 +0000 |
parents | 9488fca10677 |
children | 396a35389351 |
comparison
equal
deleted
inserted
replaced
1680:9488fca10677 | 1681:80a5e6a4e1e2 |
---|---|
32 SDL_Texture * texture); | 32 SDL_Texture * texture); |
33 static int SDL_SW_QueryTexturePixels(SDL_Renderer * renderer, | 33 static int SDL_SW_QueryTexturePixels(SDL_Renderer * renderer, |
34 SDL_Texture * texture, void **pixels, | 34 SDL_Texture * texture, void **pixels, |
35 int *pitch); | 35 int *pitch); |
36 static int SDL_SW_SetTexturePalette(SDL_Renderer * renderer, | 36 static int SDL_SW_SetTexturePalette(SDL_Renderer * renderer, |
37 SDL_Texture * texture, | |
38 const SDL_Color * colors, int firstcolor, | |
39 int ncolors); | |
40 static int SDL_SW_GetTexturePalette(SDL_Renderer * renderer, | |
37 SDL_Texture * texture, SDL_Color * colors, | 41 SDL_Texture * texture, SDL_Color * colors, |
38 int firstcolor, int ncolors); | 42 int firstcolor, int ncolors); |
39 static int SDL_SW_UpdateTexture(SDL_Renderer * renderer, | 43 static int SDL_SW_UpdateTexture(SDL_Renderer * renderer, |
40 SDL_Texture * texture, SDL_Rect * rect, | 44 SDL_Texture * texture, const SDL_Rect * rect, |
41 const void *pixels, int pitch); | 45 const void *pixels, int pitch); |
42 static int SDL_SW_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, | 46 static int SDL_SW_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, |
43 SDL_Rect * rect, int markDirty, void **pixels, | 47 const SDL_Rect * rect, int markDirty, |
44 int *pitch); | 48 void **pixels, int *pitch); |
45 static void SDL_SW_UnlockTexture(SDL_Renderer * renderer, | 49 static void SDL_SW_UnlockTexture(SDL_Renderer * renderer, |
46 SDL_Texture * texture); | 50 SDL_Texture * texture); |
47 static void SDL_SW_DirtyTexture(SDL_Renderer * renderer, | 51 static void SDL_SW_DirtyTexture(SDL_Renderer * renderer, |
48 SDL_Texture * texture, int numrects, | 52 SDL_Texture * texture, int numrects, |
49 SDL_Rect * rects); | 53 const SDL_Rect * rects); |
50 static void SDL_SW_SelectRenderTexture(SDL_Renderer * renderer, | 54 static void SDL_SW_SelectRenderTexture(SDL_Renderer * renderer, |
51 SDL_Texture * texture); | 55 SDL_Texture * texture); |
52 static void SDL_SW_RenderFill(SDL_Renderer * renderer, SDL_Rect * rect, | 56 static void SDL_SW_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect, |
53 Uint32 color); | 57 Uint32 color); |
54 static int SDL_SW_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, | 58 static int SDL_SW_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, |
55 SDL_Rect * srcrect, SDL_Rect * dstrect, | 59 const SDL_Rect * srcrect, |
56 int blendMode, int scaleMode); | 60 const SDL_Rect * dstrect, int blendMode, |
57 static int SDL_SW_RenderReadPixels(SDL_Renderer * renderer, SDL_Rect * rect, | 61 int scaleMode); |
58 void *pixels, int pitch); | 62 static int SDL_SW_RenderReadPixels(SDL_Renderer * renderer, |
59 static int SDL_SW_RenderWritePixels(SDL_Renderer * renderer, SDL_Rect * rect, | 63 const SDL_Rect * rect, void *pixels, |
60 const void *pixels, int pitch); | 64 int pitch); |
65 static int SDL_SW_RenderWritePixels(SDL_Renderer * renderer, | |
66 const SDL_Rect * rect, const void *pixels, | |
67 int pitch); | |
61 static void SDL_SW_RenderPresent(SDL_Renderer * renderer); | 68 static void SDL_SW_RenderPresent(SDL_Renderer * renderer); |
62 static void SDL_SW_DestroyTexture(SDL_Renderer * renderer, | 69 static void SDL_SW_DestroyTexture(SDL_Renderer * renderer, |
63 SDL_Texture * texture); | 70 SDL_Texture * texture); |
64 static void SDL_SW_DestroyRenderer(SDL_Renderer * renderer); | 71 static void SDL_SW_DestroyRenderer(SDL_Renderer * renderer); |
65 | 72 |
132 SDL_zerop(data); | 139 SDL_zerop(data); |
133 | 140 |
134 renderer->CreateTexture = SDL_SW_CreateTexture; | 141 renderer->CreateTexture = SDL_SW_CreateTexture; |
135 renderer->QueryTexturePixels = SDL_SW_QueryTexturePixels; | 142 renderer->QueryTexturePixels = SDL_SW_QueryTexturePixels; |
136 renderer->SetTexturePalette = SDL_SW_SetTexturePalette; | 143 renderer->SetTexturePalette = SDL_SW_SetTexturePalette; |
144 renderer->GetTexturePalette = SDL_SW_GetTexturePalette; | |
137 renderer->UpdateTexture = SDL_SW_UpdateTexture; | 145 renderer->UpdateTexture = SDL_SW_UpdateTexture; |
138 renderer->LockTexture = SDL_SW_LockTexture; | 146 renderer->LockTexture = SDL_SW_LockTexture; |
139 renderer->UnlockTexture = SDL_SW_UnlockTexture; | 147 renderer->UnlockTexture = SDL_SW_UnlockTexture; |
140 renderer->DirtyTexture = SDL_SW_DirtyTexture; | 148 renderer->DirtyTexture = SDL_SW_DirtyTexture; |
141 renderer->SelectRenderTexture = SDL_SW_SelectRenderTexture; | 149 renderer->SelectRenderTexture = SDL_SW_SelectRenderTexture; |
233 return 0; | 241 return 0; |
234 } | 242 } |
235 | 243 |
236 static int | 244 static int |
237 SDL_SW_SetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture, | 245 SDL_SW_SetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture, |
246 const SDL_Color * colors, int firstcolor, | |
247 int ncolors) | |
248 { | |
249 SDL_Surface *surface = (SDL_Surface *) texture->driverdata; | |
250 | |
251 SDL_SetColors(surface, colors, firstcolor, ncolors); | |
252 return 0; | |
253 } | |
254 | |
255 static int | |
256 SDL_SW_GetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture, | |
238 SDL_Color * colors, int firstcolor, int ncolors) | 257 SDL_Color * colors, int firstcolor, int ncolors) |
239 { | 258 { |
240 SDL_Surface *surface = (SDL_Surface *) texture->driverdata; | 259 SDL_Surface *surface = (SDL_Surface *) texture->driverdata; |
241 | 260 |
242 SDL_SetColors(surface, colors, firstcolor, ncolors); | 261 SDL_memcpy(colors, &surface->format->palette->colors[firstcolor], |
262 ncolors * sizeof(*colors)); | |
243 return 0; | 263 return 0; |
244 } | 264 } |
245 | 265 |
246 static int | 266 static int |
247 SDL_SW_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, | 267 SDL_SW_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, |
248 SDL_Rect * rect, const void *pixels, int pitch) | 268 const SDL_Rect * rect, const void *pixels, int pitch) |
249 { | 269 { |
250 SDL_Surface *surface = (SDL_Surface *) texture->driverdata; | 270 SDL_Surface *surface = (SDL_Surface *) texture->driverdata; |
251 Uint8 *src, *dst; | 271 Uint8 *src, *dst; |
252 int row; | 272 int row; |
253 size_t length; | 273 size_t length; |
265 return 0; | 285 return 0; |
266 } | 286 } |
267 | 287 |
268 static int | 288 static int |
269 SDL_SW_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, | 289 SDL_SW_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, |
270 SDL_Rect * rect, int markDirty, void **pixels, int *pitch) | 290 const SDL_Rect * rect, int markDirty, void **pixels, |
291 int *pitch) | |
271 { | 292 { |
272 SDL_Surface *surface = (SDL_Surface *) texture->driverdata; | 293 SDL_Surface *surface = (SDL_Surface *) texture->driverdata; |
273 | 294 |
274 *pixels = | 295 *pixels = |
275 (void *) ((Uint8 *) surface->pixels + rect->y * surface->pitch + | 296 (void *) ((Uint8 *) surface->pixels + rect->y * surface->pitch + |
283 { | 304 { |
284 } | 305 } |
285 | 306 |
286 static void | 307 static void |
287 SDL_SW_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture, | 308 SDL_SW_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture, |
288 int numrects, SDL_Rect * rects) | 309 int numrects, const SDL_Rect * rects) |
289 { | 310 { |
290 } | 311 } |
291 | 312 |
292 static void | 313 static void |
293 SDL_SW_SelectRenderTexture(SDL_Renderer * renderer, SDL_Texture * texture) | 314 SDL_SW_SelectRenderTexture(SDL_Renderer * renderer, SDL_Texture * texture) |
295 SDL_SW_RenderData *data = (SDL_SW_RenderData *) renderer->driverdata; | 316 SDL_SW_RenderData *data = (SDL_SW_RenderData *) renderer->driverdata; |
296 data->target = (SDL_Surface *) texture->driverdata; | 317 data->target = (SDL_Surface *) texture->driverdata; |
297 } | 318 } |
298 | 319 |
299 static void | 320 static void |
300 SDL_SW_RenderFill(SDL_Renderer * renderer, SDL_Rect * rect, Uint32 color) | 321 SDL_SW_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect, |
301 { | 322 Uint32 color) |
302 SDL_SW_RenderData *data = (SDL_SW_RenderData *) renderer->driverdata; | 323 { |
324 SDL_SW_RenderData *data = (SDL_SW_RenderData *) renderer->driverdata; | |
325 SDL_Rect real_rect = *rect; | |
303 Uint8 r, g, b, a; | 326 Uint8 r, g, b, a; |
304 | 327 |
305 a = (Uint8) ((color >> 24) & 0xFF); | 328 a = (Uint8) ((color >> 24) & 0xFF); |
306 r = (Uint8) ((color >> 16) & 0xFF); | 329 r = (Uint8) ((color >> 16) & 0xFF); |
307 g = (Uint8) ((color >> 8) & 0xFF); | 330 g = (Uint8) ((color >> 8) & 0xFF); |
308 b = (Uint8) (color & 0xFF); | 331 b = (Uint8) (color & 0xFF); |
309 color = SDL_MapRGBA(data->target->format, r, g, b, a); | 332 color = SDL_MapRGBA(data->target->format, r, g, b, a); |
310 | 333 |
311 SDL_FillRect(data->target, rect, color); | 334 SDL_FillRect(data->target, &real_rect, color); |
312 } | 335 } |
313 | 336 |
314 static int | 337 static int |
315 SDL_SW_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, | 338 SDL_SW_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, |
316 SDL_Rect * srcrect, SDL_Rect * dstrect, int blendMode, | 339 const SDL_Rect * srcrect, const SDL_Rect * dstrect, |
317 int scaleMode) | 340 int blendMode, int scaleMode) |
318 { | 341 { |
319 SDL_SW_RenderData *data = (SDL_SW_RenderData *) renderer->driverdata; | 342 SDL_SW_RenderData *data = (SDL_SW_RenderData *) renderer->driverdata; |
320 SDL_Surface *surface = (SDL_Surface *) texture->driverdata; | 343 SDL_Surface *surface = (SDL_Surface *) texture->driverdata; |
344 SDL_Rect real_srcrect = *srcrect; | |
345 SDL_Rect real_dstrect = *dstrect; | |
321 | 346 |
322 if (blendMode & (SDL_TextureBlendMode_Mask | SDL_TextureBlendMode_Blend)) { | 347 if (blendMode & (SDL_TextureBlendMode_Mask | SDL_TextureBlendMode_Blend)) { |
323 SDL_SetAlpha(surface, SDL_SRCALPHA, 0); | 348 SDL_SetAlpha(surface, SDL_SRCALPHA, 0); |
324 } else { | 349 } else { |
325 SDL_SetAlpha(surface, 0, 0); | 350 SDL_SetAlpha(surface, 0, 0); |
326 } | 351 } |
327 if (scaleMode != SDL_TextureScaleMode_None && | 352 if (scaleMode != SDL_TextureScaleMode_None && |
328 (srcrect->w != dstrect->w || srcrect->h != dstrect->h)) { | 353 (srcrect->w != dstrect->w || srcrect->h != dstrect->h)) { |
329 return SDL_SoftStretch(surface, srcrect, data->target, dstrect); | 354 return SDL_SoftStretch(surface, &real_srcrect, data->target, |
355 &real_dstrect); | |
330 } else { | 356 } else { |
331 return SDL_LowerBlit(surface, srcrect, data->target, dstrect); | 357 return SDL_LowerBlit(surface, &real_srcrect, data->target, |
332 } | 358 &real_dstrect); |
333 } | 359 } |
334 | 360 } |
335 static int | 361 |
336 SDL_SW_RenderReadPixels(SDL_Renderer * renderer, SDL_Rect * rect, | 362 static int |
363 SDL_SW_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, | |
337 void *pixels, int pitch) | 364 void *pixels, int pitch) |
338 { | 365 { |
339 SDL_SW_RenderData *data = (SDL_SW_RenderData *) renderer->driverdata; | 366 SDL_SW_RenderData *data = (SDL_SW_RenderData *) renderer->driverdata; |
340 SDL_Surface *surface = data->target; | 367 SDL_Surface *surface = data->target; |
341 Uint8 *src, *dst; | 368 Uint8 *src, *dst; |
354 } | 381 } |
355 return 0; | 382 return 0; |
356 } | 383 } |
357 | 384 |
358 static int | 385 static int |
359 SDL_SW_RenderWritePixels(SDL_Renderer * renderer, SDL_Rect * rect, | 386 SDL_SW_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect, |
360 const void *pixels, int pitch) | 387 const void *pixels, int pitch) |
361 { | 388 { |
362 SDL_SW_RenderData *data = (SDL_SW_RenderData *) renderer->driverdata; | 389 SDL_SW_RenderData *data = (SDL_SW_RenderData *) renderer->driverdata; |
363 SDL_Surface *surface = data->target; | 390 SDL_Surface *surface = data->target; |
364 Uint8 *src, *dst; | 391 Uint8 *src, *dst; |