Currently, the way I render my frames is as follows. I have two arrays of pixels (in SDL_PIXELFORMAT_ABGR8888
) called frame_pixels
(which represents the pixel data for the current frame) and clear_frame_pixels
(which is a constant array of black pixels). First I clear the renderer and reset frame_pixels
by copying clear_frame_pixels
to it. During my draw calls, I write to frame_pixels
and then copy the data into a texture called frame_texture
(with access SDL_TEXTUREACCESS_STREAMING
), which is then copied onto the renderer and presented.
SDL_RenderClear(renderer)
memcpy(frame_pixels, clear_frame, size_of_frame_pixels);
// Draw functions go here.
// Lock frame texture and copy the pixel array onto it.
unsigned char *locked_pixels;
int pitch;
SDL_LockTexture(frame_texture, NULL, locked, &pitch);
memcpy(locked, frame_pixels, size_of_frame_pixels);
SDL_UnlockTexture(frame_texture);
SDL_RenderCopy(renderer, frame_texture, NULL, NULL);
SDL_Present(renderer);
I have a few questions, the first of which concerns the top 2 lines:
- Do I need
SDL_RenderClear
anymore? Without it, my program runs with no difference, but I'm worried that there are underlying side effects that have not hit me yet. - Is there a faster way to do this? The reason I'm rendering using textures and pixel arrays is because it is much faster than the standard
SDL_RenderDrawX
functions. So any further optimization is appreciated. - In terms of terminology, would
frame_pixels
be called a "frame buffer"? What wouldframe_texture
be called, then?