diff options
author | Iago Toral Quiroga <[email protected]> | 2014-11-10 11:25:20 +0100 |
---|---|---|
committer | Iago Toral Quiroga <[email protected]> | 2015-01-12 11:20:29 +0100 |
commit | 84eb402c01962e3ff4b70c9948c85a61ed81678f (patch) | |
tree | 5f256152fa87110ed34ab81a6adfda4de0d47f63 /src/mesa/swrast/s_drawpix.c | |
parent | a629f0612d59f5a304df2e809f4b8bd6c8757adf (diff) |
swrast: Use _mesa_format_convert to implement draw_rgba_pixels.
This is the only place that uses _mesa_unpack_color_span_float so after
this we should be able to remove that function.
Reviewed-by: Jason Ekstrand <[email protected]>
Diffstat (limited to 'src/mesa/swrast/s_drawpix.c')
-rw-r--r-- | src/mesa/swrast/s_drawpix.c | 38 |
1 files changed, 34 insertions, 4 deletions
diff --git a/src/mesa/swrast/s_drawpix.c b/src/mesa/swrast/s_drawpix.c index 227faa229aa..b30e3895ae3 100644 --- a/src/mesa/swrast/s_drawpix.c +++ b/src/mesa/swrast/s_drawpix.c @@ -29,6 +29,8 @@ #include "main/condrender.h" #include "main/context.h" #include "main/format_pack.h" +#include "main/format_utils.h" +#include "main/glformats.h" #include "main/image.h" #include "main/imports.h" #include "main/macros.h" @@ -451,6 +453,28 @@ draw_rgba_pixels( struct gl_context *ctx, GLint x, GLint y, GLint skipPixels = 0; /* use span array for temp color storage */ GLfloat *rgba = (GLfloat *) span.array->attribs[VARYING_SLOT_COL0]; + void *tempImage = NULL; + + if (unpack->SwapBytes) { + /* We have to handle byte-swapping scenarios before calling + * _mesa_format_convert + */ + GLint swapSize = _mesa_sizeof_packed_type(type); + if (swapSize == 2 || swapSize == 4) { + int components = _mesa_components_in_format(format); + int elementCount = width * height * components; + tempImage = malloc(elementCount * swapSize); + if (!tempImage) { + _mesa_error(ctx, GL_OUT_OF_MEMORY, "glDrawPixels"); + return; + } + if (swapSize == 2) + _mesa_swap2_copy(tempImage, (GLushort *) pixels, elementCount); + else + _mesa_swap4_copy(tempImage, (GLuint *) pixels, elementCount); + pixels = tempImage; + } + } /* if the span is wider than SWRAST_MAX_WIDTH we have to do it in chunks */ while (skipPixels < width) { @@ -461,11 +485,15 @@ draw_rgba_pixels( struct gl_context *ctx, GLint x, GLint y, type, 0, skipPixels); GLint row; + /* get image row as float/RGBA */ + uint32_t srcMesaFormat = _mesa_format_from_format_and_type(format, type); for (row = 0; row < height; row++) { - /* get image row as float/RGBA */ - _mesa_unpack_color_span_float(ctx, spanWidth, GL_RGBA, rgba, - format, type, source, unpack, - transferOps); + int dstRowStride = 4 * width * sizeof(float); + _mesa_format_convert(rgba, RGBA8888_FLOAT, dstRowStride, + (void*)source, srcMesaFormat, srcStride, + spanWidth, 1, NULL); + if (transferOps) + _mesa_apply_rgba_transfer_ops(ctx, transferOps, spanWidth, (GLfloat (*)[4])rgba); /* Set these for each row since the _swrast_write_* functions * may change them while clipping/rendering. */ @@ -490,6 +518,8 @@ draw_rgba_pixels( struct gl_context *ctx, GLint x, GLint y, /* XXX this is ugly/temporary, to undo above change */ span.array->ChanType = CHAN_TYPE; + + free(tempImage); } swrast_render_finish(ctx); |