Mercurial > sdl-ios-xcode
comparison src/render/opengl/SDL_render_gl.c @ 5232:9c0c4d767ef6
Reduce duplicated code in the texture update code paths
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Tue, 08 Feb 2011 10:38:12 -0800 |
parents | 710d00cb3a6a |
children | 811beeb698f9 |
comparison
equal
deleted
inserted
replaced
5231:710d00cb3a6a | 5232:9c0c4d767ef6 |
---|---|
104 GLfloat texh; | 104 GLfloat texh; |
105 GLenum format; | 105 GLenum format; |
106 GLenum formattype; | 106 GLenum formattype; |
107 void *pixels; | 107 void *pixels; |
108 int pitch; | 108 int pitch; |
109 SDL_Rect locked_rect; | |
109 } GL_TextureData; | 110 } GL_TextureData; |
110 | 111 |
111 | 112 |
112 static void | 113 static void |
113 GL_SetError(const char *prefix, GLenum result) | 114 GL_SetError(const char *prefix, GLenum result) |
446 return -1; | 447 return -1; |
447 } | 448 } |
448 return 0; | 449 return 0; |
449 } | 450 } |
450 | 451 |
451 static void | 452 static int |
452 SetupTextureUpdate(GL_RenderData * renderdata, SDL_Texture * texture, | 453 GL_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, |
453 int pitch) | 454 const SDL_Rect * rect, const void *pixels, int pitch) |
454 { | 455 { |
456 GL_RenderData *renderdata = (GL_RenderData *) renderer->driverdata; | |
457 GL_TextureData *data = (GL_TextureData *) texture->driverdata; | |
458 GLenum result; | |
459 | |
460 GL_ActivateRenderer(renderer); | |
461 | |
462 renderdata->glGetError(); | |
455 renderdata->glPixelStorei(GL_UNPACK_ALIGNMENT, 1); | 463 renderdata->glPixelStorei(GL_UNPACK_ALIGNMENT, 1); |
456 renderdata->glPixelStorei(GL_UNPACK_ROW_LENGTH, | 464 renderdata->glPixelStorei(GL_UNPACK_ROW_LENGTH, |
457 (pitch / SDL_BYTESPERPIXEL(texture->format))); | 465 (pitch / SDL_BYTESPERPIXEL(texture->format))); |
458 } | |
459 | |
460 static int | |
461 GL_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, | |
462 const SDL_Rect * rect, const void *pixels, int pitch) | |
463 { | |
464 GL_RenderData *renderdata = (GL_RenderData *) renderer->driverdata; | |
465 GL_TextureData *data = (GL_TextureData *) texture->driverdata; | |
466 GLenum result; | |
467 | |
468 GL_ActivateRenderer(renderer); | |
469 | |
470 renderdata->glGetError(); | |
471 SetupTextureUpdate(renderdata, texture, pitch); | |
472 renderdata->glEnable(data->type); | 466 renderdata->glEnable(data->type); |
473 renderdata->glBindTexture(data->type, data->texture); | 467 renderdata->glBindTexture(data->type, data->texture); |
474 renderdata->glTexSubImage2D(data->type, 0, rect->x, rect->y, rect->w, | 468 renderdata->glTexSubImage2D(data->type, 0, rect->x, rect->y, rect->w, |
475 rect->h, data->format, data->formattype, | 469 rect->h, data->format, data->formattype, |
476 pixels); | 470 pixels); |
487 GL_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, | 481 GL_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, |
488 const SDL_Rect * rect, void **pixels, int *pitch) | 482 const SDL_Rect * rect, void **pixels, int *pitch) |
489 { | 483 { |
490 GL_TextureData *data = (GL_TextureData *) texture->driverdata; | 484 GL_TextureData *data = (GL_TextureData *) texture->driverdata; |
491 | 485 |
492 *pixels = | 486 data->locked_rect = *rect; |
487 *pixels = | |
493 (void *) ((Uint8 *) data->pixels + rect->y * data->pitch + | 488 (void *) ((Uint8 *) data->pixels + rect->y * data->pitch + |
494 rect->x * SDL_BYTESPERPIXEL(texture->format)); | 489 rect->x * SDL_BYTESPERPIXEL(texture->format)); |
495 *pitch = data->pitch; | 490 *pitch = data->pitch; |
496 return 0; | 491 return 0; |
497 } | 492 } |
498 | 493 |
499 static void | 494 static void |
500 GL_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture) | 495 GL_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture) |
501 { | 496 { |
502 GL_RenderData *renderdata = (GL_RenderData *) renderer->driverdata; | |
503 GL_TextureData *data = (GL_TextureData *) texture->driverdata; | 497 GL_TextureData *data = (GL_TextureData *) texture->driverdata; |
504 | 498 const SDL_Rect *rect; |
505 GL_ActivateRenderer(renderer); | 499 void *pixels; |
506 | 500 |
507 SetupTextureUpdate(renderdata, texture, data->pitch); | 501 rect = &data->locked_rect; |
508 renderdata->glEnable(data->type); | 502 pixels = |
509 renderdata->glBindTexture(data->type, data->texture); | 503 (void *) ((Uint8 *) data->pixels + rect->y * data->pitch + |
510 renderdata->glTexSubImage2D(data->type, 0, 0, 0, texture->w, texture->h, | 504 rect->x * SDL_BYTESPERPIXEL(texture->format)); |
511 data->format, data->formattype, data->pixels); | 505 GL_UpdateTexture(renderer, texture, rect, pixels, data->pitch); |
512 renderdata->glDisable(data->type); | |
513 } | 506 } |
514 | 507 |
515 static void | 508 static void |
516 GL_SetClipRect(SDL_Renderer * renderer, const SDL_Rect * rect) | 509 GL_SetClipRect(SDL_Renderer * renderer, const SDL_Rect * rect) |
517 { | 510 { |