MCPcopy Create free account
hub / github.com/RavEngine/RavEngine / SDL_SetRenderTarget

Function SDL_SetRenderTarget

deps/SDL2/src/render/SDL_render.c:1853–1930  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1851}
1852
1853int
1854SDL_SetRenderTarget(SDL_Renderer *renderer, SDL_Texture *texture)
1855{
1856 if (!SDL_RenderTargetSupported(renderer)) {
1857 return SDL_Unsupported();
1858 }
1859 if (texture == renderer->target) {
1860 /* Nothing to do! */
1861 return 0;
1862 }
1863
1864 FlushRenderCommands(renderer); /* time to send everything to the GPU! */
1865
1866 /* texture == NULL is valid and means reset the target to the window */
1867 if (texture) {
1868 CHECK_TEXTURE_MAGIC(texture, -1);
1869 if (renderer != texture->renderer) {
1870 return SDL_SetError("Texture was not created with this renderer");
1871 }
1872 if (texture->access != SDL_TEXTUREACCESS_TARGET) {
1873 return SDL_SetError("Texture not created with SDL_TEXTUREACCESS_TARGET");
1874 }
1875 if (texture->native) {
1876 /* Always render to the native texture */
1877 texture = texture->native;
1878 }
1879 }
1880
1881 SDL_LockMutex(renderer->target_mutex);
1882
1883 if (texture && !renderer->target) {
1884 /* Make a backup of the viewport */
1885 renderer->viewport_backup = renderer->viewport;
1886 renderer->clip_rect_backup = renderer->clip_rect;
1887 renderer->clipping_enabled_backup = renderer->clipping_enabled;
1888 renderer->scale_backup = renderer->scale;
1889 renderer->logical_w_backup = renderer->logical_w;
1890 renderer->logical_h_backup = renderer->logical_h;
1891 }
1892 renderer->target = texture;
1893
1894 if (renderer->SetRenderTarget(renderer, texture) < 0) {
1895 SDL_UnlockMutex(renderer->target_mutex);
1896 return -1;
1897 }
1898
1899 if (texture) {
1900 renderer->viewport.x = 0;
1901 renderer->viewport.y = 0;
1902 renderer->viewport.w = texture->w;
1903 renderer->viewport.h = texture->h;
1904 SDL_zero(renderer->clip_rect);
1905 renderer->clipping_enabled = SDL_FALSE;
1906 renderer->scale.x = 1.0f;
1907 renderer->scale.y = 1.0f;
1908 renderer->logical_w = texture->w;
1909 renderer->logical_h = texture->h;
1910 } else {

Callers 7

DrawFunction · 0.85
loopFunction · 0.85
mainFunction · 0.85
DrawCompositeFunction · 0.85
DrawFunction · 0.85
SDL_RendererEventWatchFunction · 0.85
SDL_DestroyTextureFunction · 0.85

Calls 8

FlushRenderCommandsFunction · 0.85
SDL_SetErrorFunction · 0.85
QueueCmdSetViewportFunction · 0.85
QueueCmdSetClipRectFunction · 0.85
SDL_LockMutexFunction · 0.50
SDL_UnlockMutexFunction · 0.50

Tested by 5

DrawFunction · 0.68
loopFunction · 0.68
mainFunction · 0.68
DrawCompositeFunction · 0.68
DrawFunction · 0.68