X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fmesa%2Fswrast%2Fs_renderbuffer.c;h=d8c4ed3863881dec1cd7cb84d5755fd6b2f0d1b5;hb=03c4171b577b06b1d8dde50b6eb9507d8ef4c1ce;hp=637a7b6dc1e3e8461e97f05940ccf0db249e01e8;hpb=1caf698191fb871850311353862eb7fc927f9f9c;p=mesa.git diff --git a/src/mesa/swrast/s_renderbuffer.c b/src/mesa/swrast/s_renderbuffer.c index 637a7b6dc1e..d8c4ed38638 100644 --- a/src/mesa/swrast/s_renderbuffer.c +++ b/src/mesa/swrast/s_renderbuffer.c @@ -1,6 +1,5 @@ /* * Mesa 3-D graphics library - * Version: 6.5 * * Copyright (C) 1999-2006 Brian Paul All Rights Reserved. * @@ -17,9 +16,10 @@ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. */ @@ -69,7 +69,7 @@ soft_renderbuffer_storage(struct gl_context *ctx, struct gl_renderbuffer *rb, case GL_RGB10: case GL_RGB12: case GL_RGB16: - rb->Format = MESA_FORMAT_RGB888; + rb->Format = MESA_FORMAT_BGR_UNORM8; break; case GL_RGBA: case GL_RGBA2: @@ -81,35 +81,35 @@ soft_renderbuffer_storage(struct gl_context *ctx, struct gl_renderbuffer *rb, case GL_RGBA12: #endif if (_mesa_little_endian()) - rb->Format = MESA_FORMAT_RGBA8888_REV; + rb->Format = MESA_FORMAT_R8G8B8A8_UNORM; else - rb->Format = MESA_FORMAT_RGBA8888; + rb->Format = MESA_FORMAT_A8B8G8R8_UNORM; break; case GL_RGBA16: case GL_RGBA16_SNORM: /* for accum buffer */ - rb->Format = MESA_FORMAT_SIGNED_RGBA_16; + rb->Format = MESA_FORMAT_RGBA_SNORM16; break; case GL_STENCIL_INDEX: case GL_STENCIL_INDEX1_EXT: case GL_STENCIL_INDEX4_EXT: case GL_STENCIL_INDEX8_EXT: case GL_STENCIL_INDEX16_EXT: - rb->Format = MESA_FORMAT_S8; + rb->Format = MESA_FORMAT_S_UINT8; break; case GL_DEPTH_COMPONENT: case GL_DEPTH_COMPONENT16: - rb->Format = MESA_FORMAT_Z16; + rb->Format = MESA_FORMAT_Z_UNORM16; break; case GL_DEPTH_COMPONENT24: - rb->Format = MESA_FORMAT_X8_Z24; + rb->Format = MESA_FORMAT_Z24_UNORM_X8_UINT; break; case GL_DEPTH_COMPONENT32: - rb->Format = MESA_FORMAT_Z32; + rb->Format = MESA_FORMAT_Z_UNORM32; break; case GL_DEPTH_STENCIL_EXT: case GL_DEPTH24_STENCIL8_EXT: - rb->Format = MESA_FORMAT_Z24_S8; + rb->Format = MESA_FORMAT_S8_UINT_Z24_UNORM; break; default: /* unsupported format */ @@ -119,10 +119,8 @@ soft_renderbuffer_storage(struct gl_context *ctx, struct gl_renderbuffer *rb, bpp = _mesa_get_format_bytes(rb->Format); /* free old buffer storage */ - if (srb->Buffer) { - free(srb->Buffer); - srb->Buffer = NULL; - } + free(srb->Buffer); + srb->Buffer = NULL; srb->RowStride = width * bpp; @@ -155,7 +153,7 @@ soft_renderbuffer_storage(struct gl_context *ctx, struct gl_renderbuffer *rb, } else { /* the internalFormat should have been error checked long ago */ - ASSERT(rb->_BaseFormat); + assert(rb->_BaseFormat); } return GL_TRUE; @@ -166,15 +164,13 @@ soft_renderbuffer_storage(struct gl_context *ctx, struct gl_renderbuffer *rb, * Called via gl_renderbuffer::Delete() */ static void -soft_renderbuffer_delete(struct gl_renderbuffer *rb) +soft_renderbuffer_delete(struct gl_context *ctx, struct gl_renderbuffer *rb) { struct swrast_renderbuffer *srb = swrast_renderbuffer(rb); - if (srb->Buffer) { - free(srb->Buffer); - srb->Buffer = NULL; - } - free(srb); + free(srb->Buffer); + srb->Buffer = NULL; + _mesa_delete_renderbuffer(ctx, rb); } @@ -615,8 +611,31 @@ unmap_attachment(struct gl_context *ctx, srb->Map = NULL; } - - + + +/** + * Determine what type to use (ubyte vs. float) for span colors for the + * given renderbuffer. + * See also _swrast_write_rgba_span(). + */ +static void +find_renderbuffer_colortype(struct gl_renderbuffer *rb) +{ + struct swrast_renderbuffer *srb = swrast_renderbuffer(rb); + GLuint rbMaxBits = _mesa_get_format_max_bits(rb->Format); + GLenum rbDatatype = _mesa_get_format_datatype(rb->Format); + + if (rbDatatype == GL_UNSIGNED_NORMALIZED && rbMaxBits <= 8) { + /* the buffer's values fit in GLubyte values */ + srb->ColorType = GL_UNSIGNED_BYTE; + } + else { + /* use floats otherwise */ + srb->ColorType = GL_FLOAT; + } +} + + /** * Map the renderbuffers we'll use for tri/line/point rendering. */ @@ -640,7 +659,10 @@ _swrast_map_renderbuffers(struct gl_context *ctx) } for (buf = 0; buf < fb->_NumColorDrawBuffers; buf++) { - map_attachment(ctx, fb, fb->_ColorDrawBufferIndexes[buf]); + if (fb->_ColorDrawBufferIndexes[buf] >= 0) { + map_attachment(ctx, fb, fb->_ColorDrawBufferIndexes[buf]); + find_renderbuffer_colortype(fb->_ColorDrawBuffers[buf]); + } } } @@ -668,6 +690,8 @@ _swrast_unmap_renderbuffers(struct gl_context *ctx) } for (buf = 0; buf < fb->_NumColorDrawBuffers; buf++) { - unmap_attachment(ctx, fb, fb->_ColorDrawBufferIndexes[buf]); + if (fb->_ColorDrawBufferIndexes[buf] >= 0) { + unmap_attachment(ctx, fb, fb->_ColorDrawBufferIndexes[buf]); + } } }