diff options
Diffstat (limited to 'src/mesa/state_tracker')
-rw-r--r-- | src/mesa/state_tracker/st_atom_sampler.c | 49 | ||||
-rw-r--r-- | src/mesa/state_tracker/st_cb_clear.c | 210 | ||||
-rw-r--r-- | src/mesa/state_tracker/st_cb_drawpixels.c | 100 | ||||
-rw-r--r-- | src/mesa/state_tracker/st_cb_readpixels.c | 83 | ||||
-rw-r--r-- | src/mesa/state_tracker/st_cb_readpixels.h | 3 | ||||
-rw-r--r-- | src/mesa/state_tracker/st_cb_strings.c | 15 | ||||
-rw-r--r-- | src/mesa/state_tracker/st_cb_texture.c | 21 | ||||
-rw-r--r-- | src/mesa/state_tracker/st_framebuffer.c | 26 | ||||
-rw-r--r-- | src/mesa/state_tracker/st_program.c | 8 | ||||
-rw-r--r-- | src/mesa/state_tracker/st_public.h | 1 | ||||
-rw-r--r-- | src/mesa/state_tracker/st_texture.c | 2 | ||||
-rw-r--r-- | src/mesa/state_tracker/st_texture.h | 6 |
12 files changed, 276 insertions, 248 deletions
diff --git a/src/mesa/state_tracker/st_atom_sampler.c b/src/mesa/state_tracker/st_atom_sampler.c index d7b904354f..50ce82811c 100644 --- a/src/mesa/state_tracker/st_atom_sampler.c +++ b/src/mesa/state_tracker/st_atom_sampler.c @@ -48,7 +48,7 @@ * Convert GLenum texcoord wrap tokens to pipe tokens. */ static GLuint -gl_wrap_to_sp(GLenum wrap) +gl_wrap_xlate(GLenum wrap) { switch (wrap) { case GL_REPEAT: @@ -118,6 +118,37 @@ gl_filter_to_img_filter(GLenum filter) } +static void +xlate_border_color(const GLfloat *colorIn, GLenum baseFormat, GLfloat *colorOut) +{ + switch (baseFormat) { + case GL_RGB: + colorOut[0] = colorIn[0]; + colorOut[1] = colorIn[1]; + colorOut[2] = colorIn[2]; + colorOut[3] = 1.0F; + break; + case GL_ALPHA: + colorOut[0] = colorOut[1] = colorOut[2] = 0.0; + colorOut[3] = colorIn[3]; + break; + case GL_LUMINANCE: + colorOut[0] = colorOut[1] = colorOut[2] = colorIn[0]; + colorOut[3] = 1.0; + break; + case GL_LUMINANCE_ALPHA: + colorOut[0] = colorOut[1] = colorOut[2] = colorIn[0]; + colorOut[3] = colorIn[3]; + break; + case GL_INTENSITY: + colorOut[0] = colorOut[1] = colorOut[2] = colorOut[3] = colorIn[0]; + break; + default: + COPY_4V(colorOut, colorIn); + } +} + + static void update_samplers(struct st_context *st) { @@ -137,6 +168,7 @@ update_samplers(struct st_context *st) if (samplersUsed & (1 << su)) { struct gl_texture_object *texobj; + struct gl_texture_image *teximg; GLuint texUnit; if (fprog->Base.SamplersUsed & (1 << su)) @@ -149,9 +181,11 @@ update_samplers(struct st_context *st) texobj = st_get_default_texture(st); } - sampler->wrap_s = gl_wrap_to_sp(texobj->WrapS); - sampler->wrap_t = gl_wrap_to_sp(texobj->WrapT); - sampler->wrap_r = gl_wrap_to_sp(texobj->WrapR); + teximg = texobj->Image[0][texobj->BaseLevel]; + + sampler->wrap_s = gl_wrap_xlate(texobj->WrapS); + sampler->wrap_t = gl_wrap_xlate(texobj->WrapT); + sampler->wrap_r = gl_wrap_xlate(texobj->WrapR); sampler->min_img_filter = gl_filter_to_img_filter(texobj->MinFilter); sampler->min_mip_filter = gl_filter_to_mip_filter(texobj->MinFilter); @@ -174,10 +208,9 @@ update_samplers(struct st_context *st) assert(sampler->min_lod <= sampler->max_lod); } - sampler->border_color[0] = texobj->BorderColor[RCOMP]; - sampler->border_color[1] = texobj->BorderColor[GCOMP]; - sampler->border_color[2] = texobj->BorderColor[BCOMP]; - sampler->border_color[3] = texobj->BorderColor[ACOMP]; + xlate_border_color(texobj->BorderColor, + teximg ? teximg->TexFormat->BaseFormat : GL_RGBA, + sampler->border_color); sampler->max_anisotropy = texobj->MaxAnisotropy; if (sampler->max_anisotropy > 1.0) { diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index dd9ba2881f..5bdc6a1330 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -2,6 +2,7 @@ * * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. * All Rights Reserved. + * Copyright 2009 VMware, Inc. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the @@ -29,6 +30,7 @@ * Authors: * Keith Whitwell <keith@tungstengraphics.com> * Brian Paul + * Michel Dänzer */ #include "main/glheader.h" @@ -291,11 +293,6 @@ clear_with_quad(GLcontext *ctx, static INLINE GLboolean check_clear_color_with_quad(GLcontext *ctx, struct gl_renderbuffer *rb) { - const struct st_renderbuffer *strb = st_renderbuffer(rb); - - if (strb->surface->status == PIPE_SURFACE_STATUS_UNDEFINED) - return FALSE; - if (ctx->Scissor.Enabled) return TRUE; @@ -312,14 +309,10 @@ check_clear_color_with_quad(GLcontext *ctx, struct gl_renderbuffer *rb) static INLINE GLboolean check_clear_depth_stencil_with_quad(GLcontext *ctx, struct gl_renderbuffer *rb) { - const struct st_renderbuffer *strb = st_renderbuffer(rb); const GLuint stencilMax = (1 << rb->StencilBits) - 1; GLboolean maskStencil = (ctx->Stencil.WriteMask[0] & stencilMax) != stencilMax; - if (strb->surface->status == PIPE_SURFACE_STATUS_UNDEFINED) - return FALSE; - if (ctx->Scissor.Enabled) return TRUE; @@ -339,14 +332,10 @@ check_clear_depth_with_quad(GLcontext *ctx, struct gl_renderbuffer *rb) const struct st_renderbuffer *strb = st_renderbuffer(rb); const GLboolean isDS = is_depth_stencil_format(strb->surface->format); - if (strb->surface->status == PIPE_SURFACE_STATUS_UNDEFINED) - return FALSE; - if (ctx->Scissor.Enabled) return TRUE; if (isDS && - strb->surface->status == PIPE_SURFACE_STATUS_DEFINED && ctx->DrawBuffer->Visual.stencilBits > 0) return TRUE; @@ -366,9 +355,6 @@ check_clear_stencil_with_quad(GLcontext *ctx, struct gl_renderbuffer *rb) const GLboolean maskStencil = (ctx->Stencil.WriteMask[0] & stencilMax) != stencilMax; - if (strb->surface->status == PIPE_SURFACE_STATUS_UNDEFINED) - return FALSE; - if (maskStencil) return TRUE; @@ -381,7 +367,6 @@ check_clear_stencil_with_quad(GLcontext *ctx, struct gl_renderbuffer *rb) * current state. */ if (isDS && - strb->surface->status == PIPE_SURFACE_STATUS_DEFINED && ctx->DrawBuffer->Visual.depthBits > 0) return TRUE; @@ -390,111 +375,6 @@ check_clear_stencil_with_quad(GLcontext *ctx, struct gl_renderbuffer *rb) -static void -clear_color_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) -{ - struct st_renderbuffer *strb = st_renderbuffer(rb); - - if (!strb->surface) - return; - - if (check_clear_color_with_quad( ctx, rb )) { - /* masking or scissoring */ - clear_with_quad(ctx, GL_TRUE, GL_FALSE, GL_FALSE); - } - else { - /* clear whole buffer w/out masking */ - uint clearValue; - /* NOTE: we always pass the clear color as PIPE_FORMAT_A8R8G8B8_UNORM - * at this time! - */ - util_pack_color(ctx->Color.ClearColor, PIPE_FORMAT_A8R8G8B8_UNORM, &clearValue); - ctx->st->pipe->clear(ctx->st->pipe, strb->surface, clearValue); - } -} - - -static void -clear_depth_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) -{ - struct st_renderbuffer *strb = st_renderbuffer(rb); - - if (!strb->surface) - return; - - if (check_clear_depth_with_quad(ctx, rb)) { - /* scissoring or we have a combined depth/stencil buffer */ - clear_with_quad(ctx, GL_FALSE, GL_TRUE, GL_FALSE); - } - else { - /* simple clear of whole buffer */ - uint clearValue = util_pack_z(strb->surface->format, ctx->Depth.Clear); - ctx->st->pipe->clear(ctx->st->pipe, strb->surface, clearValue); - } -} - - -static void -clear_stencil_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) -{ - struct st_renderbuffer *strb = st_renderbuffer(rb); - - if (!strb->surface) - return; - - if (check_clear_stencil_with_quad(ctx, rb)) { - /* masking or scissoring or combined depth/stencil buffer */ - clear_with_quad(ctx, GL_FALSE, GL_FALSE, GL_TRUE); - } - else { - /* simple clear of whole buffer */ - GLuint clearValue = ctx->Stencil.Clear; - - switch (strb->surface->format) { - case PIPE_FORMAT_S8Z24_UNORM: - clearValue <<= 24; - break; - default: - ; /* no-op, stencil value is in least significant bits */ - } - - ctx->st->pipe->clear(ctx->st->pipe, strb->surface, clearValue); - } -} - - -static void -clear_depth_stencil_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) -{ - struct st_renderbuffer *strb = st_renderbuffer(rb); - - if (!strb->surface) - return; - - if (check_clear_depth_stencil_with_quad(ctx, rb)) { - /* masking or scissoring */ - clear_with_quad(ctx, GL_FALSE, GL_TRUE, GL_TRUE); - } - else { - /* clear whole buffer w/out masking */ - GLuint clearValue = util_pack_z(strb->surface->format, ctx->Depth.Clear); - - switch (strb->surface->format) { - case PIPE_FORMAT_S8Z24_UNORM: - clearValue |= ctx->Stencil.Clear << 24; - break; - case PIPE_FORMAT_Z24S8_UNORM: - clearValue |= ctx->Stencil.Clear; - break; - default: - assert(0); - } - - ctx->st->pipe->clear(ctx->st->pipe, strb->surface, clearValue); - } -} - - void st_flush_clear( struct st_context *st ) { /* Release vertex buffer to avoid synchronous rendering if we were @@ -520,51 +400,89 @@ static void st_clear(GLcontext *ctx, GLbitfield mask) = ctx->DrawBuffer->Attachment[BUFFER_DEPTH].Renderbuffer; struct gl_renderbuffer *stencilRb = ctx->DrawBuffer->Attachment[BUFFER_STENCIL].Renderbuffer; - GLbitfield cmask = mask & BUFFER_BITS_COLOR; + GLbitfield quad_buffers = 0; + GLbitfield clear_buffers = 0; + GLuint i; - /* This makes sure the softpipe has the latest scissor, etc values */ + /* This makes sure the pipe has the latest scissor, etc values */ st_validate_state( st ); - /* - * XXX TO-DO: - * If we're going to use clear_with_quad() for any reason, use it to - * clear as many other buffers as possible. - * As it is now, we sometimes call clear_with_quad() three times to clear - * color/depth/stencil individually... - */ + if (mask & BUFFER_BITS_COLOR) { + for (i = 0; i < ctx->DrawBuffer->_NumColorDrawBuffers; i++) { + GLuint b = ctx->DrawBuffer->_ColorDrawBufferIndexes[i]; - if (cmask) { - GLuint b; - for (b = 0; cmask; b++) { - if (cmask & (1 << b)) { + if (mask & (1 << b)) { struct gl_renderbuffer *rb = ctx->DrawBuffer->Attachment[b].Renderbuffer; + struct st_renderbuffer *strb; + assert(rb); - clear_color_buffer(ctx, rb); - cmask &= ~(1 << b); /* turn off bit */ + + strb = st_renderbuffer(rb); + + if (!strb->surface) + continue; + + if (check_clear_color_with_quad( ctx, rb )) + quad_buffers |= PIPE_CLEAR_COLOR; + else + clear_buffers |= PIPE_CLEAR_COLOR; } - assert(b < BUFFER_COUNT); } } - if (mask & BUFFER_BIT_ACCUM) { - st_clear_accum_buffer(ctx, - ctx->DrawBuffer->Attachment[BUFFER_ACCUM].Renderbuffer); - } - if ((mask & BUFFER_BITS_DS) == BUFFER_BITS_DS && depthRb == stencilRb) { /* clearing combined depth + stencil */ - clear_depth_stencil_buffer(ctx, depthRb); + struct st_renderbuffer *strb = st_renderbuffer(depthRb); + + if (strb->surface) { + if (check_clear_depth_stencil_with_quad(ctx, depthRb)) + quad_buffers |= PIPE_CLEAR_DEPTHSTENCIL; + else + clear_buffers |= PIPE_CLEAR_DEPTHSTENCIL; + } } else { /* separate depth/stencil clears */ if (mask & BUFFER_BIT_DEPTH) { - clear_depth_buffer(ctx, depthRb); + struct st_renderbuffer *strb = st_renderbuffer(depthRb); + + if (strb->surface) { + if (check_clear_depth_with_quad(ctx, depthRb)) + quad_buffers |= PIPE_CLEAR_DEPTHSTENCIL; + else + clear_buffers |= PIPE_CLEAR_DEPTHSTENCIL; + } } if (mask & BUFFER_BIT_STENCIL) { - clear_stencil_buffer(ctx, stencilRb); + struct st_renderbuffer *strb = st_renderbuffer(stencilRb); + + if (strb->surface) { + if (check_clear_stencil_with_quad(ctx, stencilRb)) + quad_buffers |= PIPE_CLEAR_DEPTHSTENCIL; + else + clear_buffers |= PIPE_CLEAR_DEPTHSTENCIL; + } } } + + /* + * If we're going to use clear_with_quad() for any reason, use it for + * everything possible. + */ + if (quad_buffers) { + quad_buffers |= clear_buffers; + clear_with_quad(ctx, + quad_buffers & PIPE_CLEAR_COLOR, + mask & BUFFER_BIT_DEPTH, + mask & BUFFER_BIT_STENCIL); + } else if (clear_buffers) + ctx->st->pipe->clear(ctx->st->pipe, clear_buffers, ctx->Color.ClearColor, + ctx->Depth.Clear, ctx->Stencil.Clear); + + if (mask & BUFFER_BIT_ACCUM) + st_clear_accum_buffer(ctx, + ctx->DrawBuffer->Attachment[BUFFER_ACCUM].Renderbuffer); } diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index 821ea67ce4..ebb1d1142a 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -309,6 +309,8 @@ _mesa_base_format(GLenum format) 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: @@ -617,7 +619,7 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, static void draw_stencil_pixels(GLcontext *ctx, GLint x, GLint y, - GLsizei width, GLsizei height, GLenum type, + GLsizei width, GLsizei height, GLenum format, GLenum type, const struct gl_pixelstore_attrib *unpack, const GLvoid *pixels) { @@ -634,12 +636,20 @@ draw_stencil_pixels(GLcontext *ctx, GLint x, GLint y, strb = st_renderbuffer(ctx->DrawBuffer-> Attachment[BUFFER_STENCIL].Renderbuffer); + + if (st_fb_orientation(ctx->DrawBuffer) == Y_0_TOP) { + y = ctx->DrawBuffer->Height - y - height; + } + pt = screen->get_tex_transfer(screen, strb->texture, 0, 0, 0, PIPE_TRANSFER_WRITE, x, y, width, height); stmap = screen->transfer_map(screen, pt); + pixels = _mesa_map_drawpix_pbo(ctx, unpack, pixels); + assert(pixels); + /* if width > MAX_WIDTH, have to process image in chunks */ skipPixels = 0; while (skipPixels < width) { @@ -647,42 +657,74 @@ draw_stencil_pixels(GLcontext *ctx, GLint x, GLint y, const GLint spanWidth = MIN2(width - skipPixels, MAX_WIDTH); GLint row; for (row = 0; row < height; row++) { - GLint spanY = row; - GLubyte values[MAX_WIDTH]; + GLubyte sValues[MAX_WIDTH]; + GLuint zValues[MAX_WIDTH]; GLenum destType = GL_UNSIGNED_BYTE; const GLvoid *source = _mesa_image_address2d(unpack, pixels, width, height, - GL_COLOR_INDEX, type, + format, type, row, skipPixels); - _mesa_unpack_stencil_span(ctx, spanWidth, destType, values, + _mesa_unpack_stencil_span(ctx, spanWidth, destType, sValues, type, source, unpack, ctx->_ImageTransferState); + + if (format == GL_DEPTH_STENCIL) { + _mesa_unpack_depth_span(ctx, spanWidth, GL_UNSIGNED_INT, zValues, + (1 << 24) - 1, type, source, unpack); + } + if (zoom) { - /* - _swrast_write_zoomed_stencil_span(ctx, 0, 0, spanWidth, - spanX, spanY, values); - */ + _mesa_problem(ctx, "Gallium glDrawPixels(GL_STENCIL) with " + "zoom not complete"); } - else { + + { + GLint spanY; + if (st_fb_orientation(ctx->DrawBuffer) == Y_0_TOP) { - spanY = height - spanY - 1; + spanY = height - row - 1; + } + else { + spanY = row; } + /* now pack the stencil (and Z) values in the dest format */ switch (pt->format) { case PIPE_FORMAT_S8_UNORM: { ubyte *dest = stmap + spanY * pt->stride + spanX; - memcpy(dest, values, spanWidth); + memcpy(dest, sValues, spanWidth); } break; case PIPE_FORMAT_S8Z24_UNORM: - { + if (format == GL_DEPTH_STENCIL) { uint *dest = (uint *) (stmap + spanY * pt->stride + spanX*4); GLint k; for (k = 0; k < spanWidth; k++) { - uint p = dest[k]; - p = (p & 0xffffff) | (values[k] << 24); - dest[k] = p; + dest[k] = zValues[k] | (sValues[k] << 24); + } + } + else { + uint *dest = (uint *) (stmap + spanY * pt->stride + spanX*4); + GLint k; + for (k = 0; k < spanWidth; k++) { + dest[k] = (dest[k] & 0xffffff) | (sValues[k] << 24); + } + } + break; + case PIPE_FORMAT_Z24S8_UNORM: + if (format == GL_DEPTH_STENCIL) { + uint *dest = (uint *) (stmap + spanY * pt->stride + spanX*4); + GLint k; + for (k = 0; k < spanWidth; k++) { + dest[k] = zValues[k] | (sValues[k] << 24); + } + } + else { + uint *dest = (uint *) (stmap + spanY * pt->stride + spanX*4); + GLint k; + for (k = 0; k < spanWidth; k++) { + dest[k] = (dest[k] & 0xffffff00) | (sValues[k] & 0xff); } } break; @@ -694,6 +736,8 @@ draw_stencil_pixels(GLcontext *ctx, GLint x, GLint y, skipPixels += spanWidth; } + _mesa_unmap_drawpix_pbo(ctx, unpack); + /* unmap the stencil buffer */ screen->transfer_unmap(screen, pt); screen->tex_transfer_destroy(pt); @@ -715,8 +759,10 @@ st_DrawPixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, GLuint bufferFormat; const GLfloat *color; - if (format == GL_STENCIL_INDEX) { - draw_stencil_pixels(ctx, x, y, width, height, type, unpack, pixels); + if (format == GL_STENCIL_INDEX || + format == GL_DEPTH_STENCIL) { + draw_stencil_pixels(ctx, x, y, width, height, format, type, + unpack, pixels); return; } @@ -731,11 +777,6 @@ st_DrawPixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, stvp = st_make_passthrough_vertex_shader(ctx->st, GL_TRUE); color = ctx->Current.RasterColor; } - else if (format == GL_STENCIL_INDEX) { - ps = st->state.framebuffer.zsbuf; - /* XXX special case - can't use texture map */ - color = NULL; - } else { ps = st->state.framebuffer.cbufs[0]; stfp = combined_drawpix_fragment_program(ctx); @@ -781,7 +822,8 @@ copy_stencil_pixels(GLcontext *ctx, GLint srcx, GLint srcy, } /* this will do stencil pixel transfer ops */ - st_read_stencil_pixels(ctx, srcx, srcy, width, height, GL_UNSIGNED_BYTE, + st_read_stencil_pixels(ctx, srcx, srcy, width, height, + GL_STENCIL_INDEX, GL_UNSIGNED_BYTE, &ctx->DefaultPacking, buffer); ptDraw = screen->get_tex_transfer(screen, rbDraw->texture, 0, 0, 0, @@ -821,6 +863,16 @@ copy_stencil_pixels(GLcontext *ctx, GLint srcx, GLint srcy, } } break; + case PIPE_FORMAT_Z24S8_UNORM: + { + uint *dst4 = (uint *) dst; + int j; + for (j = 0; j < width; j++) { + *dst4 = (*dst4 & 0xffffff00) | (src[j] & 0xff); + dst4++; + } + } + break; case PIPE_FORMAT_S8_UNORM: memcpy(dst, src, width); break; diff --git a/src/mesa/state_tracker/st_cb_readpixels.c b/src/mesa/state_tracker/st_cb_readpixels.c index 2a4beccd90..9ce5f3fe84 100644 --- a/src/mesa/state_tracker/st_cb_readpixels.c +++ b/src/mesa/state_tracker/st_cb_readpixels.c @@ -56,7 +56,8 @@ */ void st_read_stencil_pixels(GLcontext *ctx, GLint x, GLint y, - GLsizei width, GLsizei height, GLenum type, + GLsizei width, GLsizei height, + GLenum format, GLenum type, const struct gl_pixelstore_attrib *packing, GLvoid *pixels) { @@ -68,7 +69,7 @@ st_read_stencil_pixels(GLcontext *ctx, GLint x, GLint y, GLint j; if (st_fb_orientation(ctx->DrawBuffer) == Y_0_TOP) { - y = ctx->DrawBuffer->Height - y - 1; + y = ctx->DrawBuffer->Height - y - height; } /* Create a read transfer from the renderbuffer's texture */ @@ -84,7 +85,8 @@ st_read_stencil_pixels(GLcontext *ctx, GLint x, GLint y, /* process image row by row */ for (j = 0; j < height; j++) { GLvoid *dest; - GLstencil values[MAX_WIDTH]; + GLstencil sValues[MAX_WIDTH]; + GLfloat zValues[MAX_WIDTH]; GLint srcY; if (st_fb_orientation(ctx->DrawBuffer) == Y_0_TOP) { @@ -94,29 +96,47 @@ st_read_stencil_pixels(GLcontext *ctx, GLint x, GLint y, srcY = j; } - /* get stencil values */ + /* get stencil (and Z) values */ switch (pt->format) { case PIPE_FORMAT_S8_UNORM: { const ubyte *src = stmap + srcY * pt->stride; - memcpy(values, src, width); + memcpy(sValues, src, width); } break; case PIPE_FORMAT_S8Z24_UNORM: - { + if (format == GL_DEPTH_STENCIL) { const uint *src = (uint *) (stmap + srcY * pt->stride); + const GLfloat scale = 1.0 / (0xffffff); GLint k; for (k = 0; k < width; k++) { - values[k] = src[k] >> 24; + sValues[k] = src[k] >> 24; + zValues[k] = (src[k] & 0xffffff) * scale; + } + } + else { + const uint *src = (uint *) (stmap + srcY * pt->stride); + GLint k; + for (k = 0; k < width; k++) { + sValues[k] = src[k] >> 24; } } break; case PIPE_FORMAT_Z24S8_UNORM: - { + if (format == GL_DEPTH_STENCIL) { + const uint *src = (uint *) (stmap + srcY * pt->stride); + const GLfloat scale = 1.0 / (0xffffff); + GLint k; + for (k = 0; k < width; k++) { + sValues[k] = src[k] & 0xff; + zValues[k] = (src[k] >> 8) * scale; + } + } + else { const uint *src = (uint *) (stmap + srcY * pt->stride); GLint k; for (k = 0; k < width; k++) { - values[k] = src[k] & 0xff; + sValues[k] = src[k] & 0xff; } } break; @@ -126,12 +146,16 @@ st_read_stencil_pixels(GLcontext *ctx, GLint x, GLint y, /* store */ dest = _mesa_image_address2d(packing, pixels, width, height, - GL_STENCIL_INDEX, type, j, 0); - - _mesa_pack_stencil_span(ctx, width, type, dest, values, packing); + format, type, j, 0); + if (format == GL_DEPTH_STENCIL) { + _mesa_pack_depth_stencil_span(ctx, width, dest, + zValues, sValues, packing); + } + else { + _mesa_pack_stencil_span(ctx, width, type, dest, sValues, packing); + } } - /* unmap the stencil buffer */ screen->transfer_unmap(screen, pt); screen->tex_transfer_destroy(pt); @@ -329,8 +353,10 @@ st_readpixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, /* make sure rendering has completed */ st_flush(ctx->st, PIPE_FLUSH_RENDER_CACHE, NULL); - if (format == GL_STENCIL_INDEX) { - st_read_stencil_pixels(ctx, x, y, width, height, type, pack, dest); + if (format == GL_STENCIL_INDEX || + format == GL_DEPTH_STENCIL) { + st_read_stencil_pixels(ctx, x, y, width, height, + format, type, pack, dest); return; } else if (format == GL_DEPTH_COMPONENT) { @@ -420,6 +446,33 @@ st_readpixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, } } } + else if (trans->format == PIPE_FORMAT_Z24S8_UNORM || + trans->format == PIPE_FORMAT_Z24X8_UNORM) { + if (format == GL_DEPTH_COMPONENT) { + for (i = 0; i < height; i++) { + GLuint ztemp[MAX_WIDTH]; + GLfloat zfloat[MAX_WIDTH]; + const double scale = 1.0 / ((1 << 24) - 1); + pipe_get_tile_raw(trans, 0, y, width, 1, ztemp, 0); + y += yStep; + for (j = 0; j < width; j++) { + zfloat[j] = (float) (scale * ((ztemp[j] >> 8) & 0xffffff)); + } + _mesa_pack_depth_span(ctx, width, dst, type, + zfloat, &clippedPacking); + dst += dstStride; + } + } + else { + /* untested, but simple: */ + assert(format == GL_DEPTH_STENCIL_EXT); + for (i = 0; i < height; i++) { + pipe_get_tile_raw(trans, 0, y, width, 1, dst, 0); + y += yStep; + dst += dstStride; + } + } + } else if (trans->format == PIPE_FORMAT_Z16_UNORM) { for (i = 0; i < height; i++) { GLushort ztemp[MAX_WIDTH]; diff --git a/src/mesa/state_tracker/st_cb_readpixels.h b/src/mesa/state_tracker/st_cb_readpixels.h index 9e151be51f..c90ef02906 100644 --- a/src/mesa/state_tracker/st_cb_readpixels.h +++ b/src/mesa/state_tracker/st_cb_readpixels.h @@ -34,7 +34,8 @@ st_get_color_read_renderbuffer(GLcontext *ctx); extern void st_read_stencil_pixels(GLcontext *ctx, GLint x, GLint y, - GLsizei width, GLsizei height, GLenum type, + GLsizei width, GLsizei height, + GLenum format, GLenum type, const struct gl_pixelstore_attrib *packing, GLvoid *pixels); diff --git a/src/mesa/state_tracker/st_cb_strings.c b/src/mesa/state_tracker/st_cb_strings.c index 2036ccafbf..bb931f17c4 100644 --- a/src/mesa/state_tracker/st_cb_strings.c +++ b/src/mesa/state_tracker/st_cb_strings.c @@ -39,7 +39,7 @@ #include "st_context.h" #include "st_cb_strings.h" -#define ST_VERSION_STRING "0.2" +#define ST_VERSION_STRING "0.3" static const GLubyte * st_get_string(GLcontext * ctx, GLenum name) @@ -50,18 +50,7 @@ st_get_string(GLcontext * ctx, GLenum name) switch (name) { case GL_VENDOR: { const char *vendor = screen->get_vendor( screen ); - const char *tungsten = "Tungsten Graphics, Inc."; - - /* Tungsten Graphics, Inc. developed the state_tracker module - * (and much of Mesa), but the driver itself may come from elsewhere. - * The additional string allows "and XyzCorp" to reflect this. - */ - if (vendor && strcmp(vendor, tungsten) != 0) - util_snprintf(st->vendor, sizeof(st->vendor), - "%s and %s", tungsten, vendor); - else - util_snprintf(st->vendor, sizeof(st->vendor), "%s", tungsten); - + util_snprintf(st->vendor, sizeof(st->vendor), "%s", vendor); return (GLubyte *) st->vendor; } diff --git a/src/mesa/state_tracker/st_cb_texture.c b/src/mesa/state_tracker/st_cb_texture.c index 311d812ccf..8013e69e8e 100644 --- a/src/mesa/state_tracker/st_cb_texture.c +++ b/src/mesa/state_tracker/st_cb_texture.c @@ -37,6 +37,7 @@ #include "main/pixel.h" #include "main/texcompress.h" #include "main/texformat.h" +#include "main/texgetimage.h" #include "main/teximage.h" #include "main/texobj.h" #include "main/texstore.h" @@ -946,7 +947,8 @@ fallback_copy_texsubimage(GLcontext *ctx, texDest = st_texture_image_map(ctx->st, stImage, 0, PIPE_TRANSFER_WRITE, destX, destY, width, height); - if (baseFormat == GL_DEPTH_COMPONENT) { + if (baseFormat == GL_DEPTH_COMPONENT || + baseFormat == GL_DEPTH24_STENCIL8) { const GLboolean scaleOrBias = (ctx->Pixel.DepthScale != 1.0F || ctx->Pixel.DepthBias != 0.0F); GLint row, yStep; @@ -1056,7 +1058,8 @@ st_copy_texsubimage(GLcontext *ctx, st_finish(ctx->st); /* determine if copying depth or color data */ - if (texBaseFormat == GL_DEPTH_COMPONENT) { + if (texBaseFormat == GL_DEPTH_COMPONENT || + texBaseFormat == GL_DEPTH24_STENCIL8) { strb = st_renderbuffer(fb->_DepthBuffer); } else if (texBaseFormat == GL_DEPTH_STENCIL_EXT) { @@ -1471,9 +1474,19 @@ st_get_default_texture(struct st_context *st) GLubyte pixels[16][16][4]; struct gl_texture_object *texObj; struct gl_texture_image *texImg; + GLuint i, j; - /* init image to gray */ - memset(pixels, 127, sizeof(pixels)); + /* The ARB_fragment_program spec says (0,0,0,1) should be returned + * when attempting to sample incomplete textures. + */ + for (i = 0; i < 16; i++) { + for (j = 0; j < 16; j++) { + pixels[i][j][0] = 0; + pixels[i][j][1] = 0; + pixels[i][j][2] = 0; + pixels[i][j][3] = 255; + } + } texObj = st->ctx->Driver.NewTextureObject(st->ctx, 0, target); diff --git a/src/mesa/state_tracker/st_framebuffer.c b/src/mesa/state_tracker/st_framebuffer.c index 06fec20eee..daaad65cca 100644 --- a/src/mesa/state_tracker/st_framebuffer.c +++ b/src/mesa/state_tracker/st_framebuffer.c @@ -293,32 +293,6 @@ st_notify_swapbuffers(struct st_framebuffer *stfb) } -/** - * Quick hack - allows the winsys to inform the driver that surface - * states are now undefined after a glXSwapBuffers or similar. - */ -void -st_notify_swapbuffers_complete(struct st_framebuffer *stfb) -{ - GET_CURRENT_CONTEXT(ctx); - - if (ctx && ctx->DrawBuffer == &stfb->Base) { - struct st_renderbuffer *strb; - - /* Mark back color buffers as undefined */ - strb = st_renderbuffer(stfb->Base.Attachment[BUFFER_BACK_LEFT]. - Renderbuffer); - if (strb && strb->surface) - strb->surface->status = PIPE_SURFACE_STATUS_UNDEFINED; - - strb = st_renderbuffer(stfb->Base.Attachment[BUFFER_BACK_RIGHT]. - Renderbuffer); - if (strb && strb->surface) - strb->surface->status = PIPE_SURFACE_STATUS_UNDEFINED; - } -} - - void *st_framebuffer_private( struct st_framebuffer *stfb ) { return stfb->Private; diff --git a/src/mesa/state_tracker/st_program.c b/src/mesa/state_tracker/st_program.c index f825204915..6348e83d8a 100644 --- a/src/mesa/state_tracker/st_program.c +++ b/src/mesa/state_tracker/st_program.c @@ -427,11 +427,13 @@ st_translate_fragment_program(struct st_context *st, interpMode[slot] = TGSI_INTERPOLATE_LINEAR; break; case FRAG_ATTRIB_FOGC: - if (stfp->Base.UsesPointCoord) + if (stfp->Base.UsesPointCoord) { stfp->input_semantic_name[slot] = TGSI_SEMANTIC_GENERIC; - else + stfp->input_semantic_index[slot] = num_generic++; + } else { stfp->input_semantic_name[slot] = TGSI_SEMANTIC_FOG; - stfp->input_semantic_index[slot] = 0; + stfp->input_semantic_index[slot] = 0; + } interpMode[slot] = TGSI_INTERPOLATE_PERSPECTIVE; break; case FRAG_ATTRIB_TEX0: diff --git a/src/mesa/state_tracker/st_public.h b/src/mesa/state_tracker/st_public.h index 414218bb58..030314372f 100644 --- a/src/mesa/state_tracker/st_public.h +++ b/src/mesa/state_tracker/st_public.h @@ -100,7 +100,6 @@ void st_flush( struct st_context *st, uint pipeFlushFlags, void st_finish( struct st_context *st ); void st_notify_swapbuffers(struct st_framebuffer *stfb); -void st_notify_swapbuffers_complete(struct st_framebuffer *stfb); int st_set_teximage(struct pipe_texture *pt, int target); diff --git a/src/mesa/state_tracker/st_texture.c b/src/mesa/state_tracker/st_texture.c index 6f274d6d69..3f90ad502c 100644 --- a/src/mesa/state_tracker/st_texture.c +++ b/src/mesa/state_tracker/st_texture.c @@ -107,7 +107,7 @@ st_texture_create(struct st_context *st, newtex = screen->texture_create(screen, &pt); - assert(!newtex || p_atomic_read(&newtex->reference.count) == 1); + assert(!newtex || pipe_is_referenced(&newtex->reference)); return newtex; } diff --git a/src/mesa/state_tracker/st_texture.h b/src/mesa/state_tracker/st_texture.h index 840b7e27cc..28c2f580f6 100644 --- a/src/mesa/state_tracker/st_texture.h +++ b/src/mesa/state_tracker/st_texture.h @@ -99,12 +99,6 @@ st_get_stobj_texture(struct st_texture_object *stObj) return stObj ? stObj->pt : NULL; } -static INLINE GLboolean pf_is_depth_stencil( enum pipe_format format ) -{ - return (pf_get_component_bits( format, PIPE_FORMAT_COMP_Z ) + - pf_get_component_bits( format, PIPE_FORMAT_COMP_S )) != 0; -} - extern struct pipe_texture * st_texture_create(struct st_context *st, |