SDL2 - Why does SDL_CreateTextureFromSurface () need a renderer *?

This is the syntax of the SDL_CreateTextureFromSurface function:

SDL_Texture* SDL_CreateTextureFromSurface(SDL_Renderer* renderer, SDL_Surface*  surface)

However, I am confused, why do we need to pass the renderer *? I thought we only needed a visualizer * when drawing a texture?

+4
source share
2 answers

You will need SDL_Rendererto get information on the applicable restrictions:

  • maximum supported size
  • pixel format

And maybe something else ..

+5
source

In addition to plaes answer ..

Under the hood, it SDL_CreateTextureFromSurfacecalls SDL_CreateTexture, which also needs Renderer to create a new texture of the same size as the one transferred on the surface.

SDL_UpdateTexture () , , SDL_CreateTextureFromSurface. , , .

SDL_CreateTexture, GPU, ( ), Renderer .

Renderer .

, , SDL_render.c SDL2.

SDL_CreateTextureFromSurface:

texture = SDL_CreateTexture(renderer, format, SDL_TEXTUREACCESS_STATIC,
                            surface->w, surface->h);
if (!texture) {
    return NULL;
}

if (format == surface->format->format) {
    if (SDL_MUSTLOCK(surface)) {
        SDL_LockSurface(surface);
        SDL_UpdateTexture(texture, NULL, surface->pixels, surface->pitch);
        SDL_UnlockSurface(surface);
    } else {
        SDL_UpdateTexture(texture, NULL, surface->pixels, surface->pitch);
    }
}
+2

Source: https://habr.com/ru/post/1621383/


All Articles