comparison src/video/SDL_video.c @ 3596:f638ded38b8a

Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color. Renamed SDL_RenderPoint() and SDL_RenderLine() to SDL_RenderDrawPoint() and SDL_RenderDrawLine(). Added API for rectangle drawing (as opposed to filling) Added placeholder API functions for circles and ellipses ... I'm not sure whether these will stay. Optimized software line drawing quite a bit. Added support for Wu's anti-aliased line drawing, currently disabled by default.
author Sam Lantinga <slouken@libsdl.org>
date Wed, 23 Dec 2009 01:55:00 +0000
parents 19691cebb866
children 0f958e527e5e
comparison
equal deleted inserted replaced
3595:b7c6828d4039 3596:f638ded38b8a
2481 *blendMode = renderer->blendMode; 2481 *blendMode = renderer->blendMode;
2482 return 0; 2482 return 0;
2483 } 2483 }
2484 2484
2485 int 2485 int
2486 SDL_RenderPoint(int x, int y) 2486 SDL_RenderClear()
2487 {
2488 SDL_Renderer *renderer;
2489
2490 renderer = SDL_GetCurrentRenderer(SDL_TRUE);
2491 if (!renderer) {
2492 return -1;
2493 }
2494 if (!renderer->RenderClear) {
2495 int blendMode = renderer->blendMode;
2496 int status;
2497
2498 if (blendMode >= SDL_BLENDMODE_BLEND) {
2499 SDL_SetRenderDrawBlendMode(SDL_BLENDMODE_NONE);
2500 }
2501
2502 status = SDL_RenderFillRect(NULL);
2503
2504 if (blendMode >= SDL_BLENDMODE_BLEND) {
2505 SDL_SetRenderDrawBlendMode(blendMode);
2506 }
2507 return status;
2508 }
2509 return renderer->RenderClear(renderer);
2510 }
2511
2512 int
2513 SDL_RenderDrawPoint(int x, int y)
2487 { 2514 {
2488 SDL_Point point; 2515 SDL_Point point;
2489 2516
2490 point.x = x; 2517 point.x = x;
2491 point.y = y; 2518 point.y = y;
2492 return SDL_RenderPoints(&point, 1); 2519 return SDL_RenderDrawPoints(&point, 1);
2493 } 2520 }
2494 2521
2495 int 2522 int
2496 SDL_RenderPoints(const SDL_Point * points, int count) 2523 SDL_RenderDrawPoints(const SDL_Point * points, int count)
2497 { 2524 {
2498 SDL_Renderer *renderer; 2525 SDL_Renderer *renderer;
2499 2526
2500 if (!points) { 2527 if (!points) {
2501 SDL_SetError("SDL_RenderPoints(): Passed NULL points"); 2528 SDL_SetError("SDL_RenderDrawPoints(): Passed NULL points");
2502 return -1; 2529 return -1;
2503 } 2530 }
2504 2531
2505 renderer = SDL_GetCurrentRenderer(SDL_TRUE); 2532 renderer = SDL_GetCurrentRenderer(SDL_TRUE);
2506 if (!renderer) { 2533 if (!renderer) {
2507 return -1; 2534 return -1;
2508 } 2535 }
2509 if (!renderer->RenderPoints) { 2536 if (!renderer->RenderDrawPoints) {
2510 SDL_Unsupported(); 2537 SDL_Unsupported();
2511 return -1; 2538 return -1;
2512 } 2539 }
2513 if (count < 1) { 2540 if (count < 1) {
2514 return 0; 2541 return 0;
2515 } 2542 }
2516 return renderer->RenderPoints(renderer, points, count); 2543 return renderer->RenderDrawPoints(renderer, points, count);
2517 } 2544 }
2518 2545
2519 int 2546 int
2520 SDL_RenderLine(int x1, int y1, int x2, int y2) 2547 SDL_RenderDrawLine(int x1, int y1, int x2, int y2)
2521 { 2548 {
2522 SDL_Point points[2]; 2549 SDL_Point points[2];
2523 2550
2524 points[0].x = x1; 2551 points[0].x = x1;
2525 points[0].y = y1; 2552 points[0].y = y1;
2526 points[1].x = x2; 2553 points[1].x = x2;
2527 points[1].y = y2; 2554 points[1].y = y2;
2528 return SDL_RenderLines(points, 2); 2555 return SDL_RenderDrawLines(points, 2);
2529 } 2556 }
2530 2557
2531 int 2558 int
2532 SDL_RenderLines(const SDL_Point * points, int count) 2559 SDL_RenderDrawLines(const SDL_Point * points, int count)
2533 { 2560 {
2534 SDL_Renderer *renderer; 2561 SDL_Renderer *renderer;
2535 2562
2536 if (!points) { 2563 if (!points) {
2537 SDL_SetError("SDL_RenderLines(): Passed NULL points"); 2564 SDL_SetError("SDL_RenderDrawLines(): Passed NULL points");
2538 return -1; 2565 return -1;
2539 } 2566 }
2540 2567
2541 renderer = SDL_GetCurrentRenderer(SDL_TRUE); 2568 renderer = SDL_GetCurrentRenderer(SDL_TRUE);
2542 if (!renderer) { 2569 if (!renderer) {
2543 return -1; 2570 return -1;
2544 } 2571 }
2545 if (!renderer->RenderLines) { 2572 if (!renderer->RenderDrawLines) {
2546 SDL_Unsupported(); 2573 SDL_Unsupported();
2547 return -1; 2574 return -1;
2548 } 2575 }
2549 if (count < 2) { 2576 if (count < 2) {
2550 return 0; 2577 return 0;
2551 } 2578 }
2552 return renderer->RenderLines(renderer, points, count); 2579 return renderer->RenderDrawLines(renderer, points, count);
2553 } 2580 }
2554 2581
2555 int 2582 int
2556 SDL_RenderRect(const SDL_Rect * rect) 2583 SDL_RenderDrawRect(const SDL_Rect * rect)
2557 { 2584 {
2558 return SDL_RenderRects(&rect, 1); 2585 return SDL_RenderDrawRects(&rect, 1);
2559 } 2586 }
2560 2587
2561 int 2588 int
2562 SDL_RenderRects(const SDL_Rect ** rects, int count) 2589 SDL_RenderDrawRects(const SDL_Rect ** rects, int count)
2563 { 2590 {
2564 SDL_Renderer *renderer; 2591 SDL_Renderer *renderer;
2565 int i; 2592 int i;
2566 2593
2567 if (!rects) { 2594 if (!rects) {
2568 SDL_SetError("SDL_RenderRects(): Passed NULL rects"); 2595 SDL_SetError("SDL_RenderDrawRects(): Passed NULL rects");
2569 return -1; 2596 return -1;
2570 } 2597 }
2571 2598
2572 renderer = SDL_GetCurrentRenderer(SDL_TRUE); 2599 renderer = SDL_GetCurrentRenderer(SDL_TRUE);
2573 if (!renderer) { 2600 if (!renderer) {
2574 return -1; 2601 return -1;
2575 } 2602 }
2576 if (!renderer->RenderRects) { 2603 if (!renderer->RenderDrawRects) {
2577 SDL_Unsupported(); 2604 SDL_Unsupported();
2578 return -1; 2605 return -1;
2579 } 2606 }
2580 if (count < 1) { 2607 if (count < 1) {
2581 return 0; 2608 return 0;
2591 full_rect.x = 0; 2618 full_rect.x = 0;
2592 full_rect.y = 0; 2619 full_rect.y = 0;
2593 full_rect.w = window->w; 2620 full_rect.w = window->w;
2594 full_rect.h = window->h; 2621 full_rect.h = window->h;
2595 rect = &full_rect; 2622 rect = &full_rect;
2596 return renderer->RenderRects(renderer, &rect, 1); 2623 return renderer->RenderDrawRects(renderer, &rect, 1);
2597 } 2624 }
2598 } 2625 }
2599 return renderer->RenderRects(renderer, rects, count); 2626 return renderer->RenderDrawRects(renderer, rects, count);
2627 }
2628
2629 int
2630 SDL_RenderFillRect(const SDL_Rect * rect)
2631 {
2632 return SDL_RenderFillRects(&rect, 1);
2633 }
2634
2635 int
2636 SDL_RenderFillRects(const SDL_Rect ** rects, int count)
2637 {
2638 SDL_Renderer *renderer;
2639 int i;
2640
2641 if (!rects) {
2642 SDL_SetError("SDL_RenderFillRects(): Passed NULL rects");
2643 return -1;
2644 }
2645
2646 renderer = SDL_GetCurrentRenderer(SDL_TRUE);
2647 if (!renderer) {
2648 return -1;
2649 }
2650 if (!renderer->RenderFillRects) {
2651 SDL_Unsupported();
2652 return -1;
2653 }
2654 if (count < 1) {
2655 return 0;
2656 }
2657 /* Check for NULL rect, which means fill entire window */
2658 for (i = 0; i < count; ++i) {
2659 if (rects[i] == NULL) {
2660 SDL_Window *window;
2661 SDL_Rect full_rect;
2662 const SDL_Rect *rect;
2663
2664 window = SDL_GetWindowFromID(renderer->window);
2665 full_rect.x = 0;
2666 full_rect.y = 0;
2667 full_rect.w = window->w;
2668 full_rect.h = window->h;
2669 rect = &full_rect;
2670 return renderer->RenderFillRects(renderer, &rect, 1);
2671 }
2672 }
2673 return renderer->RenderFillRects(renderer, rects, count);
2674 }
2675
2676 int
2677 SDL_RenderDrawCircle(int x, int y, int radius)
2678 {
2679 return SDL_RenderDrawEllipse(x, y, 2*radius, 2*radius);
2680 }
2681
2682 int
2683 SDL_RenderFillCircle(int x, int y, int radius)
2684 {
2685 return SDL_RenderFillEllipse(x, y, 2*radius, 2*radius);
2686 }
2687
2688 int SDL_RenderDrawEllipse(int x, int y, int w, int h)
2689 {
2690 SDL_Renderer *renderer;
2691
2692 renderer = SDL_GetCurrentRenderer(SDL_TRUE);
2693 if (!renderer) {
2694 return -1;
2695 }
2696 if (!renderer->RenderDrawEllipse) {
2697 SDL_Unsupported();
2698 return -1;
2699 }
2700 return renderer->RenderDrawEllipse(renderer, x, y, w, h);
2701 }
2702
2703 int SDL_RenderFillEllipse(int x, int y, int w, int h)
2704 {
2705 SDL_Renderer *renderer;
2706
2707 renderer = SDL_GetCurrentRenderer(SDL_TRUE);
2708 if (!renderer) {
2709 return -1;
2710 }
2711 if (!renderer->RenderFillEllipse) {
2712 SDL_Unsupported();
2713 return -1;
2714 }
2715 return renderer->RenderFillEllipse(renderer, x, y, w, h);
2600 } 2716 }
2601 2717
2602 int 2718 int
2603 SDL_RenderCopy(SDL_TextureID textureID, const SDL_Rect * srcrect, 2719 SDL_RenderCopy(SDL_TextureID textureID, const SDL_Rect * srcrect,
2604 const SDL_Rect * dstrect) 2720 const SDL_Rect * dstrect)