comparison src/render/opengles2/SDL_render_gles2.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 7a963be087ef
comparison
equal deleted inserted replaced
5231:710d00cb3a6a 5232:9c0c4d767ef6
341 341
342 static void 342 static void
343 GLES2_UnlockTexture(SDL_Renderer *renderer, SDL_Texture *texture) 343 GLES2_UnlockTexture(SDL_Renderer *renderer, SDL_Texture *texture)
344 { 344 {
345 GLES2_TextureData *tdata = (GLES2_TextureData *)texture->driverdata; 345 GLES2_TextureData *tdata = (GLES2_TextureData *)texture->driverdata;
346 346 SDL_Rect rect;
347 GLES2_ActivateRenderer(renderer); 347
348 348 /* We do whole texture updates, at least for now */
349 glPixelStorei(GL_UNPACK_ALIGNMENT, 1); 349 rect.x = 0;
350 glActiveTexture(GL_TEXTURE0); 350 rect.y = 0;
351 glBindTexture(tdata->texture_type, tdata->texture); 351 rect.w = texture->w;
352 glTexSubImage2D(tdata->texture_type, 0, 0, 0, texture->w, texture->h, 352 rect.h = texture->h;
353 tdata->pixel_format, tdata->pixel_type, tdata->pixel_data); 353 GLES2_UpdateTexture(renderer, texture, &rect, tdata->pixel_data, tdata->pitch);
354 } 354 }
355 355
356 static int 356 static int
357 GLES2_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect, 357 GLES2_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect,
358 const void *pixels, int pitch) 358 const void *pixels, int pitch)
359 { 359 {
360 GLES2_TextureData *tdata = (GLES2_TextureData *)texture->driverdata; 360 GLES2_TextureData *tdata = (GLES2_TextureData *)texture->driverdata;
361 Uint8 *blob = NULL; 361 Uint8 *blob = NULL;
362 Uint8 *src; 362 Uint8 *src;
363 int srcPitch; 363 int srcPitch;
364 Uint8 *dest;
365 int y; 364 int y;
366 365
367 GLES2_ActivateRenderer(renderer); 366 GLES2_ActivateRenderer(renderer);
368 367
369 /* Bail out if we're supposed to update an empty rectangle */ 368 /* Bail out if we're supposed to update an empty rectangle */
403 rect->w, 402 rect->w,
404 rect->h, 403 rect->h,
405 tdata->pixel_format, 404 tdata->pixel_format,
406 tdata->pixel_type, 405 tdata->pixel_type,
407 src); 406 src);
408 SDL_free(blob); 407 if (blob) {
408 SDL_free(blob);
409 }
409 410
410 if (glGetError() != GL_NO_ERROR) 411 if (glGetError() != GL_NO_ERROR)
411 { 412 {
412 SDL_SetError("Failed to update texture"); 413 SDL_SetError("Failed to update texture");
413 return -1; 414 return -1;