From e6ac8d5353dda1b859dbc1219ca4e91c9183ae85 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Sat, 23 Oct 2010 10:23:05 -0600 Subject: st/mesa: be smarter choosing texture format for glDrawPixels() This lets us get an integer texture format for integer pixel formats. --- src/mesa/state_tracker/st_cb_drawpixels.c | 50 ++++++++++++++++++++++++++++--- 1 file changed, 46 insertions(+), 4 deletions(-) diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index 0de6697ca2..122d8f0765 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -299,8 +299,8 @@ make_passthrough_vertex_shader(struct st_context *st, /** - * Return a texture internalFormat for drawing/copying an image - * of the given type. + * Return a texture base format for drawing/copying an image + * of the given format. */ static GLenum base_format(GLenum format) @@ -318,6 +318,47 @@ base_format(GLenum format) } +/** + * Return a texture internalFormat for drawing/copying an image + * of the given format and type. + */ +static GLenum +internal_format(GLenum format, GLenum type) +{ + switch (format) { + case GL_DEPTH_COMPONENT: + return GL_DEPTH_COMPONENT; + case GL_DEPTH_STENCIL: + return GL_DEPTH_STENCIL; + case GL_STENCIL_INDEX: + return GL_STENCIL_INDEX; + default: + if (_mesa_is_integer_format(format)) { + switch (type) { + case GL_BYTE: + return GL_RGBA8I; + case GL_UNSIGNED_BYTE: + return GL_RGBA8UI; + case GL_SHORT: + return GL_RGBA16I; + case GL_UNSIGNED_SHORT: + return GL_RGBA16UI; + case GL_INT: + return GL_RGBA32I; + case GL_UNSIGNED_INT: + return GL_RGBA32UI; + default: + assert(0 && "Unexpected type in internal_format()"); + return GL_RGBA_INTEGER; + } + } + else { + return GL_RGBA; + } + } +} + + /** * Create a temporary texture to hold an image of the given size. * If width, height are not POT and the driver only handles POT textures, @@ -352,11 +393,12 @@ make_texture(struct st_context *st, struct pipe_resource *pt; enum pipe_format pipeFormat; GLuint cpp; - GLenum baseFormat; + GLenum baseFormat, intFormat; baseFormat = base_format(format); + intFormat = internal_format(format, type); - mformat = st_ChooseTextureFormat_renderable(ctx, baseFormat, + mformat = st_ChooseTextureFormat_renderable(ctx, intFormat, format, type, GL_FALSE); assert(mformat); -- cgit v1.2.3