mirror of https://github.com/encounter/SDL.git
SDL_UpdateTexture: intersect update rect with texture dimension
- fix crash with software renderer - fix non texture update with opengl/gles2
This commit is contained in:
parent
5e3cf0d1f4
commit
13626c3681
|
@ -1540,7 +1540,7 @@ int
|
||||||
SDL_UpdateTexture(SDL_Texture * texture, const SDL_Rect * rect,
|
SDL_UpdateTexture(SDL_Texture * texture, const SDL_Rect * rect,
|
||||||
const void *pixels, int pitch)
|
const void *pixels, int pitch)
|
||||||
{
|
{
|
||||||
SDL_Rect full_rect;
|
SDL_Rect real_rect;
|
||||||
|
|
||||||
CHECK_TEXTURE_MAGIC(texture, -1);
|
CHECK_TEXTURE_MAGIC(texture, -1);
|
||||||
|
|
||||||
|
@ -1551,28 +1551,30 @@ SDL_UpdateTexture(SDL_Texture * texture, const SDL_Rect * rect,
|
||||||
return SDL_InvalidParamError("pitch");
|
return SDL_InvalidParamError("pitch");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!rect) {
|
real_rect.x = 0;
|
||||||
full_rect.x = 0;
|
real_rect.y = 0;
|
||||||
full_rect.y = 0;
|
real_rect.w = texture->w;
|
||||||
full_rect.w = texture->w;
|
real_rect.h = texture->h;
|
||||||
full_rect.h = texture->h;
|
if (rect) {
|
||||||
rect = &full_rect;
|
if (!SDL_IntersectRect(rect, &real_rect, &real_rect)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((rect->w == 0) || (rect->h == 0)) {
|
if (real_rect.w == 0 || real_rect.h == 0) {
|
||||||
return 0; /* nothing to do. */
|
return 0; /* nothing to do. */
|
||||||
#if SDL_HAVE_YUV
|
#if SDL_HAVE_YUV
|
||||||
} else if (texture->yuv) {
|
} else if (texture->yuv) {
|
||||||
return SDL_UpdateTextureYUV(texture, rect, pixels, pitch);
|
return SDL_UpdateTextureYUV(texture, &real_rect, pixels, pitch);
|
||||||
#endif
|
#endif
|
||||||
} else if (texture->native) {
|
} else if (texture->native) {
|
||||||
return SDL_UpdateTextureNative(texture, rect, pixels, pitch);
|
return SDL_UpdateTextureNative(texture, &real_rect, pixels, pitch);
|
||||||
} else {
|
} else {
|
||||||
SDL_Renderer *renderer = texture->renderer;
|
SDL_Renderer *renderer = texture->renderer;
|
||||||
if (FlushRenderCommandsIfTextureNeeded(texture) < 0) {
|
if (FlushRenderCommandsIfTextureNeeded(texture) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return renderer->UpdateTexture(renderer, texture, rect, pixels, pitch);
|
return renderer->UpdateTexture(renderer, texture, &real_rect, pixels, pitch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1890,7 +1892,6 @@ SDL_LockTextureToSurface(SDL_Texture *texture, const SDL_Rect *rect,
|
||||||
real_rect.y = 0;
|
real_rect.y = 0;
|
||||||
real_rect.w = texture->w;
|
real_rect.w = texture->w;
|
||||||
real_rect.h = texture->h;
|
real_rect.h = texture->h;
|
||||||
|
|
||||||
if (rect) {
|
if (rect) {
|
||||||
SDL_IntersectRect(rect, &real_rect, &real_rect);
|
SDL_IntersectRect(rect, &real_rect, &real_rect);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue