- do you means that the current GL_RenderReadPixels does not work ?------------------
Yes, If you want to read pixels from SDL_TEXTUREACCESS_TARGET’s SDL_texture,
current GL_RenderReadPixels will work unsuccessfully. Of course,
GL_RenderReadPixels is corresponding to Open GL, for example Microsoft
Windows with SDL_WINDOW_OPENGL. If your app use OpenGL ES2, for example iOS
and Android, you require modify GLES2_RenderReadPixels. Their modification
are the same.
-
the doc says "WARNING: This is a very slow operation, and should not
be used frequently." Is this still the case with your version ?
This still the case with my version, modify don’t touch that. You should
absolutely not use SDL_RenderReadPixels(), ever, for anything other than
screenshots and the like.
I think that next official SDL2 will fix this BUG. Of course, I hope to
patch code to official SDL2, especial BLE.
If you want read pixels from tex(it’s type must be
SDL_TEXTUREACCESS_TARGET), you can write below code.
int RenderReadPixels (SDL_Renderer* renderer, const SDL_Rect* rect,
Uint32 format, void* pixels, int pitch,
SDL_Texture* tex)
{
// assume current target is NULL.
int result ;
SDL_Rect dst = {0, 0, rect->w, rect->h} ;
// Since want to read from tex, should set it to target.
SDL_SetRenderTarget(renderer, tex) ;
// pitch = dst.w * byte of one pixel. not tex’width * byte of pixel.
result = SDL_RenderReadPixels(renderer, &dst, format, pixels, pitch);
// recover target to NULL.
SDL_SetRenderTarget (renderer, NULL) ;
return result ;
}