Mercurial > sdl-ios-xcode
comparison src/SDL_compat.c @ 5150:ad50b3db78bd
The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Tue, 01 Feb 2011 19:19:43 -0800 |
parents | c8e049de174c |
children | be02be2ea897 |
comparison
equal
deleted
inserted
replaced
5149:3052772b59db | 5150:ad50b3db78bd |
---|---|
29 #include "video/SDL_sysvideo.h" | 29 #include "video/SDL_sysvideo.h" |
30 #include "video/SDL_pixels_c.h" | 30 #include "video/SDL_pixels_c.h" |
31 #include "video/SDL_yuv_sw_c.h" | 31 #include "video/SDL_yuv_sw_c.h" |
32 | 32 |
33 static SDL_Window *SDL_VideoWindow = NULL; | 33 static SDL_Window *SDL_VideoWindow = NULL; |
34 static SDL_RendererInfo SDL_VideoRendererInfo; | 34 static SDL_Renderer *SDL_VideoRenderer = NULL; |
35 static SDL_Texture *SDL_VideoTexture = NULL; | 35 static SDL_Texture *SDL_VideoTexture = NULL; |
36 static SDL_Surface *SDL_VideoSurface = NULL; | 36 static SDL_Surface *SDL_VideoSurface = NULL; |
37 static SDL_Surface *SDL_ShadowSurface = NULL; | 37 static SDL_Surface *SDL_ShadowSurface = NULL; |
38 static SDL_Surface *SDL_PublicSurface = NULL; | 38 static SDL_Surface *SDL_PublicSurface = NULL; |
39 static SDL_GLContext *SDL_VideoContext = NULL; | 39 static SDL_GLContext *SDL_VideoContext = NULL; |
465 } | 465 } |
466 | 466 |
467 /* Destroy the screen texture and recreate it */ | 467 /* Destroy the screen texture and recreate it */ |
468 SDL_QueryTexture(SDL_VideoTexture, &format, &access, &w, &h); | 468 SDL_QueryTexture(SDL_VideoTexture, &format, &access, &w, &h); |
469 SDL_DestroyTexture(SDL_VideoTexture); | 469 SDL_DestroyTexture(SDL_VideoTexture); |
470 SDL_VideoTexture = SDL_CreateTexture(format, access, width, height); | 470 SDL_VideoTexture = SDL_CreateTexture(SDL_VideoRenderer, format, |
471 access, width, height); | |
471 if (!SDL_VideoTexture) { | 472 if (!SDL_VideoTexture) { |
472 return -1; | 473 return -1; |
473 } | 474 } |
474 | 475 |
475 SDL_VideoSurface->w = width; | 476 SDL_VideoSurface->w = width; |
665 SDL_PublicSurface = SDL_VideoSurface; | 666 SDL_PublicSurface = SDL_VideoSurface; |
666 return SDL_PublicSurface; | 667 return SDL_PublicSurface; |
667 } | 668 } |
668 | 669 |
669 /* Create a renderer for the window */ | 670 /* Create a renderer for the window */ |
670 if (SDL_CreateRenderer(SDL_VideoWindow, -1, 0) < 0) { | 671 SDL_VideoRenderer = SDL_CreateRenderer(SDL_VideoWindow, -1, 0); |
672 if (!SDL_VideoRenderer) { | |
671 return NULL; | 673 return NULL; |
672 } | 674 } |
673 SDL_GetRendererInfo(&SDL_VideoRendererInfo); | |
674 | 675 |
675 /* Create a texture for the screen surface */ | 676 /* Create a texture for the screen surface */ |
676 SDL_VideoTexture = | 677 SDL_VideoTexture = SDL_CreateTexture(SDL_VideoRenderer, desired_format, |
677 SDL_CreateTexture(desired_format, SDL_TEXTUREACCESS_STREAMING, width, | 678 SDL_TEXTUREACCESS_STREAMING, |
678 height); | 679 width, height); |
679 | 680 |
680 if (!SDL_VideoTexture) { | 681 if (!SDL_VideoTexture) { |
681 SDL_VideoTexture = | 682 SDL_VideoTexture = SDL_CreateTexture(SDL_VideoRenderer, desktop_format, |
682 SDL_CreateTexture(desktop_format, | 683 SDL_TEXTUREACCESS_STREAMING, |
683 SDL_TEXTUREACCESS_STREAMING, width, height); | 684 width, height); |
684 } | 685 } |
685 if (!SDL_VideoTexture) { | 686 if (!SDL_VideoTexture) { |
686 return NULL; | 687 return NULL; |
687 } | 688 } |
688 | 689 |
888 } | 889 } |
889 rect.x = 0; | 890 rect.x = 0; |
890 rect.y = 0; | 891 rect.y = 0; |
891 rect.w = screen->w; | 892 rect.w = screen->w; |
892 rect.h = screen->h; | 893 rect.h = screen->h; |
893 SDL_RenderCopy(SDL_VideoTexture, &rect, &rect); | 894 SDL_RenderCopy(SDL_VideoRenderer, SDL_VideoTexture, &rect, &rect); |
894 SDL_RenderPresent(); | 895 SDL_RenderPresent(SDL_VideoRenderer); |
895 } | 896 } |
896 } | 897 } |
897 | 898 |
898 void | 899 void |
899 SDL_WM_SetCaption(const char *title, const char *icon) | 900 SDL_WM_SetCaption(const char *title, const char *icon) |
1582 overlay->pitches[0] = overlay->w * 2; | 1583 overlay->pitches[0] = overlay->w * 2; |
1583 break; | 1584 break; |
1584 } | 1585 } |
1585 | 1586 |
1586 overlay->hwdata->texture = | 1587 overlay->hwdata->texture = |
1587 SDL_CreateTexture(texture_format, SDL_TEXTUREACCESS_STREAMING, w, h); | 1588 SDL_CreateTexture(SDL_VideoRenderer, texture_format, |
1589 SDL_TEXTUREACCESS_STREAMING, w, h); | |
1588 if (overlay->hwdata->texture) { | 1590 if (overlay->hwdata->texture) { |
1589 overlay->hwdata->sw = NULL; | 1591 overlay->hwdata->sw = NULL; |
1590 } else { | 1592 } else { |
1591 SDL_DisplayMode current_mode; | 1593 SDL_DisplayMode current_mode; |
1592 | 1594 |
1598 | 1600 |
1599 /* Create a supported RGB format texture for display */ | 1601 /* Create a supported RGB format texture for display */ |
1600 SDL_GetCurrentDisplayMode(¤t_mode); | 1602 SDL_GetCurrentDisplayMode(¤t_mode); |
1601 texture_format = current_mode.format; | 1603 texture_format = current_mode.format; |
1602 overlay->hwdata->texture = | 1604 overlay->hwdata->texture = |
1603 SDL_CreateTexture(texture_format, | 1605 SDL_CreateTexture(SDL_VideoRenderer, texture_format, |
1604 SDL_TEXTUREACCESS_STREAMING, w, h); | 1606 SDL_TEXTUREACCESS_STREAMING, w, h); |
1605 } | 1607 } |
1606 if (!overlay->hwdata->texture) { | 1608 if (!overlay->hwdata->texture) { |
1607 SDL_FreeYUVOverlay(overlay); | 1609 SDL_FreeYUVOverlay(overlay); |
1608 return NULL; | 1610 return NULL; |
1686 { | 1688 { |
1687 if (!overlay || !dstrect) { | 1689 if (!overlay || !dstrect) { |
1688 SDL_SetError("Passed a NULL overlay or dstrect"); | 1690 SDL_SetError("Passed a NULL overlay or dstrect"); |
1689 return -1; | 1691 return -1; |
1690 } | 1692 } |
1691 if (SDL_RenderCopy(overlay->hwdata->texture, NULL, dstrect) < 0) { | 1693 if (SDL_RenderCopy(SDL_VideoRenderer, overlay->hwdata->texture, NULL, dstrect) < 0) { |
1692 return -1; | 1694 return -1; |
1693 } | 1695 } |
1694 SDL_RenderPresent(); | 1696 SDL_RenderPresent(SDL_VideoRenderer); |
1695 return 0; | 1697 return 0; |
1696 } | 1698 } |
1697 | 1699 |
1698 void | 1700 void |
1699 SDL_FreeYUVOverlay(SDL_Overlay * overlay) | 1701 SDL_FreeYUVOverlay(SDL_Overlay * overlay) |