summaryrefslogtreecommitdiff
path: root/src/render/opengl
diff options
context:
space:
mode:
authorSam Lantinga <slouken@libsdl.org>2011-03-10 01:03:43 -0800
committerSam Lantinga <slouken@libsdl.org>2011-03-10 01:03:43 -0800
commit32a9a2d69b62f2470caa30e1203c16516037f8fd (patch)
tree4f1ee8bcc1df4618accefd9afbf0e983516a467c /src/render/opengl
parente862f6dff9604dfb5cf69027fb131fb3797016cf (diff)
downloadsdl-32a9a2d69b62f2470caa30e1203c16516037f8fd.tar.gz
Fixed bug 1162 (Error calling SDL_RenderReadPixels() with format=0)
Diffstat (limited to 'src/render/opengl')
-rwxr-xr-xsrc/render/opengl/SDL_render_gl.c34
1 files changed, 23 insertions, 11 deletions
diff --git a/src/render/opengl/SDL_render_gl.c b/src/render/opengl/SDL_render_gl.c
index 7311e4fe4..3f1ed9e83 100755
--- a/src/render/opengl/SDL_render_gl.c
+++ b/src/render/opengl/SDL_render_gl.c
@@ -921,44 +921,56 @@ GL_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
{
GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
SDL_Window *window = renderer->window;
+ Uint32 temp_format = SDL_PIXELFORMAT_ARGB8888;
+ void *temp_pixels;
+ int temp_pitch;
GLint internalFormat;
GLenum format, type;
Uint8 *src, *dst, *tmp;
int w, h, length, rows;
+ int status;
GL_ActivateRenderer(renderer);
- if (!convert_format(data, pixel_format, &internalFormat, &format, &type)) {
- /* FIXME: Do a temp copy to a format that is supported */
- SDL_SetError("Unsupported pixel format");
+ temp_pitch = rect->w * SDL_BYTESPERPIXEL(temp_format);
+ temp_pixels = SDL_malloc(rect->h * temp_pitch);
+ if (!temp_pixels) {
+ SDL_OutOfMemory();
return -1;
}
+ convert_format(data, temp_format, &internalFormat, &format, &type);
+
SDL_GetWindowSize(window, &w, &h);
data->glPixelStorei(GL_PACK_ALIGNMENT, 1);
data->glPixelStorei(GL_PACK_ROW_LENGTH,
- (pitch / SDL_BYTESPERPIXEL(pixel_format)));
+ (temp_pitch / SDL_BYTESPERPIXEL(temp_format)));
data->glReadPixels(rect->x, (h-rect->y)-rect->h, rect->w, rect->h,
- format, type, pixels);
+ format, type, temp_pixels);
/* Flip the rows to be top-down */
- length = rect->w * SDL_BYTESPERPIXEL(pixel_format);
- src = (Uint8*)pixels + (rect->h-1)*pitch;
- dst = (Uint8*)pixels;
+ length = rect->w * SDL_BYTESPERPIXEL(temp_format);
+ src = (Uint8*)temp_pixels + (rect->h-1)*temp_pitch;
+ dst = (Uint8*)temp_pixels;
tmp = SDL_stack_alloc(Uint8, length);
rows = rect->h / 2;
while (rows--) {
SDL_memcpy(tmp, dst, length);
SDL_memcpy(dst, src, length);
SDL_memcpy(src, tmp, length);
- dst += pitch;
- src -= pitch;
+ dst += temp_pitch;
+ src -= temp_pitch;
}
SDL_stack_free(tmp);
- return 0;
+ status = SDL_ConvertPixels(rect->w, rect->h,
+ temp_format, temp_pixels, temp_pitch,
+ pixel_format, pixels, pitch);
+ SDL_free(temp_pixels);
+
+ return status;
}
static void