[Python] pygame._sdl2 and SDL2 - Efficient Texture Storage on GPU with Multple Renderers

Discussão em 'Python' iniciado por Stack, Setembro 15, 2024.

  1. Stack

    Stack Membro Participativo

    I'm working in pygame._sdl2 so that I can create multiple (2) windows simultaneously. I think this is an SDL2 question, not specific to pygame:

    I want to be able to blit() the same textures into both windows (at different times). From what I've been able to tell, an SDL2 Texture is associated with a particular Renderer. So it seems like I have to create 2 Textures for each source image - one for each Renderer.

    Since Textures live on the GPU, am I doubling my GPU storage requirements?

    Is there a way to have a single memory resource that can draw to both Renderers? Or is there another way to improve GPU memory usage?

    I'm working in Windows and Raspberry Pi, so I imagine my GPU storage availability on the RPi will be pretty limited.

    I have tried working with Surfaces, but those won't blit() into the Renderer:

    import pygame as pg
    from pygame._sdl2 import Window, Texture, Image, Renderer, get_drivers, messagebox

    pg.display.init()
    win = Window("My Window", resizable=True)
    ren = Renderer(win)
    srf = pg.image.load("image.png")
    ren.blit(srf, pg.Rect(300,100,100,100))


    This gives:

    TypeError: source must be drawable

    which is odd, since blit() does not do any drawing on the source, only reading from it. I assume that "drawable" is referring to data being in GPU memory, but I might be wrong about that.

    One thing I was thinking about is to create a single Texture and then update() it with multple Surfaces (many of my textures are the same size). But as I understand it update() requires copying from CPU memory to GPU memory and is slow.

    Continue reading...

Compartilhe esta Página