this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Added GPU_IntersectRect() and GPU_IntersectClipRect().

+70
+8
include/SDL_gpu.h
··· 970 970 /*! Turns off clipping for the given target. */ 971 971 DECLSPEC void SDLCALL GPU_UnsetClip(GPU_Target* target); 972 972 973 + /*! Returns GPU_TRUE if the given rects A and B overlap, in which case it also fills the given result rect with the intersection. `result` can be NULL if you don't need the intersection. */ 974 + DECLSPEC GPU_bool SDLCALL GPU_IntersectRect(GPU_Rect A, GPU_Rect B, GPU_Rect* result); 975 + 976 + /*! Returns GPU_TRUE if the given target's clip rect and the given B rect overlap, in which case it also fills the given result rect with the intersection. `result` can be NULL if you don't need the intersection. 977 + * If the target doesn't have a clip rect enabled, this uses the whole target area. 978 + */ 979 + DECLSPEC GPU_bool SDLCALL GPU_IntersectClipRect(GPU_Target* target, GPU_Rect B, GPU_Rect* result); 980 + 973 981 /*! Sets the modulation color for subsequent drawing of images and shapes on the given target. 974 982 * This has a cumulative effect with the image coloring functions. 975 983 * e.g. GPU_SetRGB(image, 255, 128, 0); GPU_SetTargetRGB(target, 128, 128, 128);
+62
src/SDL_gpu.c
··· 1474 1474 _gpu_current_renderer->impl->UnsetClip(_gpu_current_renderer, target); 1475 1475 } 1476 1476 1477 + /* Adapted from SDL_IntersectRect() */ 1478 + GPU_bool GPU_IntersectRect(GPU_Rect A, GPU_Rect B, GPU_Rect* result) 1479 + { 1480 + GPU_bool has_horiz_intersection = GPU_FALSE; 1481 + float Amin, Amax, Bmin, Bmax; 1482 + GPU_Rect intersection; 1477 1483 1484 + // Special case for empty rects 1485 + if (A.w <= 0.0f || A.h <= 0.0f || B.w <= 0.0f || B.h <= 0.0f) 1486 + return GPU_FALSE; 1487 + 1488 + // Horizontal intersection 1489 + Amin = A.x; 1490 + Amax = Amin + A.w; 1491 + Bmin = B.x; 1492 + Bmax = Bmin + B.w; 1493 + if (Bmin > Amin) 1494 + Amin = Bmin; 1495 + if (Bmax < Amax) 1496 + Amax = Bmax; 1497 + 1498 + intersection.x = Amin; 1499 + intersection.w = Amax - Amin; 1500 + 1501 + has_horiz_intersection = (Amax > Amin); 1502 + 1503 + // Vertical intersection 1504 + Amin = A.y; 1505 + Amax = Amin + A.h; 1506 + Bmin = B.y; 1507 + Bmax = Bmin + B.h; 1508 + if (Bmin > Amin) 1509 + Amin = Bmin; 1510 + if (Bmax < Amax) 1511 + Amax = Bmax; 1512 + 1513 + intersection.y = Amin; 1514 + intersection.h = Amax - Amin; 1515 + 1516 + if(has_horiz_intersection && Amax > Amin) 1517 + { 1518 + if(result != NULL) 1519 + *result = intersection; 1520 + return GPU_TRUE; 1521 + } 1522 + else 1523 + return GPU_FALSE; 1524 + } 1525 + 1526 + 1527 + GPU_bool GPU_IntersectClipRect(GPU_Target* target, GPU_Rect B, GPU_Rect* result) 1528 + { 1529 + if(target == NULL) 1530 + return GPU_FALSE; 1531 + 1532 + if(!target->use_clip_rect) 1533 + { 1534 + GPU_Rect A = {0, 0, target->w, target->h}; 1535 + return GPU_IntersectRect(A, B, result); 1536 + } 1537 + 1538 + return GPU_IntersectRect(target->clip_rect, B, result); 1539 + } 1478 1540 1479 1541 1480 1542 void GPU_SetColor(GPU_Image* image, SDL_Color color)