I want to combine SDL’s hardware rendering with some special software rendering. For this I use a streaming texture for the software rendering part.
Rendering only with hardware or software is easy, but how to best combine both approaches?
The problem is, that the software renderer needs to see the current pixels but the pixels of the streaming texture are not preset. And the streaming texture is stated to be read-only, so I don’t have any idea how to preset the pixels.
Further, I didn’t see anything where I could specify a blit operation like OVER or something like that, which would be used when the texture gets unlocked.
It looks like a streaming texture always gets blitted to the screen by completely replacing the prior content.
Keep the pixel data in SDL_surface or just in a custom buffer that you allocate yourself. During software rendering, update the state of this surface/buffer, and when you want to send the data to the GPU, copy the data from the surface/buffer to this texture.
It’s currently not implemented/wrapped as a SDL_Renderer but rather using the pixelbuffers directly. Works so far as long as either SDL or B2D draw the picture.
Next step is to use both to let SDL draw a blue rectangle and B2D a red frame on top of it. So that I can see the blue SDL pixels below and in the middle of the frame. Like this:
It doesn’t read single pixels, it’s SDL_RenderReadPixels()plural not SDL_RenderReadPixel()! Although it’s best avoided, because it can be relatively slow, sometimes there’s no alternative - and you did ask how to get the existing pixels from a texture.