Hello,
I am not new to SDL (2D software rendering part), but I am new to SDL2. I was wondering what is the proper way to update a streaming texture?
I have been experimenting with using SDL_UpdateTexture and with SDL_LockTexture(). From my highly non-scientific benchmarking, it seems that
SDL_UpdateTexture() is slightly faster than using SDL_LockTexture().
My experimentation consists of using a loop to get a frame from ffmpeg (ignoring timestamps) and rendering/blitting that frame
to the current window/texture. I have a single texture that uses SDL_TEXTUREACCESS_STREAMING. The pixel format for both the texture and the
frame that I get from ffmpeg is RGB24.
Using SDL_UpdateTexture() I do something along the lines of (in a loop):
const unsigned char *frame_data = function_that_gets_frame_using_ffmpeg();
SDL_UpdateTexture(texture, NULL, frame_data, pitch);
Where ‘texture’ is a single, streaming texture for the single renderer and window. Pitch is known as well.
My other experiment was to use SDL_LockTexture(), again in a loop (omitting error checking):
const unsigned char *frame_data = function_that_gets_frame_using_ffmpeg();
byte_t *texture_data = NULL;
int texture_pitch = 0;
SDL_LockTexture(texture, 0, (void**)&texture_data, &texture_pitch));
memcpy(texture_data, frame_data, whBpp);
SDL_UnlockTexture(texture);
Where, w, h and Bpp are known.
The reason I ask is that the docs for SDL_UpdateTexture() state the function is fairly slow. Could that be relative and not be noticeable
in my trivial experiments?
If it matters, I am planning on trying the same experiments on my Android (4.0) tablet. I have a working Android project thanks to the excellent
documentation in README.android.
Any advice, insights or comments would be greatly appreciated. Thanks.
Cheers,
Alvin