ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

s_buffers.c
Go to the documentation of this file.
00001 /*
00002  * Mesa 3-D graphics library
00003  * Version:  7.1
00004  *
00005  * Copyright (C) 1999-2008  Brian Paul   All Rights Reserved.
00006  *
00007  * Permission is hereby granted, free of charge, to any person obtaining a
00008  * copy of this software and associated documentation files (the "Software"),
00009  * to deal in the Software without restriction, including without limitation
00010  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
00011  * and/or sell copies of the Software, and to permit persons to whom the
00012  * Software is furnished to do so, subject to the following conditions:
00013  *
00014  * The above copyright notice and this permission notice shall be included
00015  * in all copies or substantial portions of the Software.
00016  *
00017  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00018  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00019  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
00020  * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
00021  * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
00022  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00023  */
00024 
00027 #include "main/glheader.h"
00028 #include "main/colormac.h"
00029 #include "main/macros.h"
00030 #include "main/imports.h"
00031 #include "main/mtypes.h"
00032 
00033 #include "s_accum.h"
00034 #include "s_context.h"
00035 #include "s_depth.h"
00036 #include "s_masking.h"
00037 #include "s_stencil.h"
00038 
00039 
00043 static void
00044 clear_rgba_buffer_with_masking(GLcontext *ctx, struct gl_renderbuffer *rb)
00045 {
00046    const GLint x = ctx->DrawBuffer->_Xmin;
00047    const GLint y = ctx->DrawBuffer->_Ymin;
00048    const GLint height = ctx->DrawBuffer->_Ymax - ctx->DrawBuffer->_Ymin;
00049    const GLint width  = ctx->DrawBuffer->_Xmax - ctx->DrawBuffer->_Xmin;
00050    SWspan span;
00051    GLint i;
00052 
00053    ASSERT(ctx->Visual.rgbMode);
00054    ASSERT(rb->PutRow);
00055 
00056    /* Initialize color span with clear color */
00057    /* XXX optimize for clearcolor == black/zero (bzero) */
00058    INIT_SPAN(span, GL_BITMAP);
00059    span.end = width;
00060    span.arrayMask = SPAN_RGBA;
00061    span.array->ChanType = rb->DataType;
00062    if (span.array->ChanType == GL_UNSIGNED_BYTE) {
00063       GLubyte clearColor[4];
00064       UNCLAMPED_FLOAT_TO_UBYTE(clearColor[RCOMP], ctx->Color.ClearColor[0]);
00065       UNCLAMPED_FLOAT_TO_UBYTE(clearColor[GCOMP], ctx->Color.ClearColor[1]);
00066       UNCLAMPED_FLOAT_TO_UBYTE(clearColor[BCOMP], ctx->Color.ClearColor[2]);
00067       UNCLAMPED_FLOAT_TO_UBYTE(clearColor[ACOMP], ctx->Color.ClearColor[3]);
00068       for (i = 0; i < width; i++) {
00069          COPY_4UBV(span.array->rgba[i], clearColor);
00070       }
00071    }
00072    else if (span.array->ChanType == GL_UNSIGNED_SHORT) {
00073       GLushort clearColor[4];
00074       UNCLAMPED_FLOAT_TO_USHORT(clearColor[RCOMP], ctx->Color.ClearColor[0]);
00075       UNCLAMPED_FLOAT_TO_USHORT(clearColor[GCOMP], ctx->Color.ClearColor[1]);
00076       UNCLAMPED_FLOAT_TO_USHORT(clearColor[BCOMP], ctx->Color.ClearColor[2]);
00077       UNCLAMPED_FLOAT_TO_USHORT(clearColor[ACOMP], ctx->Color.ClearColor[3]);
00078       for (i = 0; i < width; i++) {
00079          COPY_4V(span.array->rgba[i], clearColor);
00080       }
00081    }
00082    else {
00083       ASSERT(span.array->ChanType == GL_FLOAT);
00084       for (i = 0; i < width; i++) {
00085          CLAMPED_FLOAT_TO_CHAN(span.array->rgba[i][0], ctx->Color.ClearColor[0]);
00086          CLAMPED_FLOAT_TO_CHAN(span.array->rgba[i][1], ctx->Color.ClearColor[1]);
00087          CLAMPED_FLOAT_TO_CHAN(span.array->rgba[i][2], ctx->Color.ClearColor[2]);
00088          CLAMPED_FLOAT_TO_CHAN(span.array->rgba[i][3], ctx->Color.ClearColor[3]);
00089       }
00090    }
00091 
00092    /* Note that masking will change the color values, but only the
00093     * channels for which the write mask is GL_FALSE.  The channels
00094     * which which are write-enabled won't get modified.
00095     */
00096    for (i = 0; i < height; i++) {
00097       span.x = x;
00098       span.y = y + i;
00099       _swrast_mask_rgba_span(ctx, rb, &span);
00100       /* write masked row */
00101       rb->PutRow(ctx, rb, width, x, y + i, span.array->rgba, NULL);
00102    }
00103 }
00104 
00105 
00109 static void
00110 clear_ci_buffer_with_masking(GLcontext *ctx, struct gl_renderbuffer *rb)
00111 {
00112    const GLint x = ctx->DrawBuffer->_Xmin;
00113    const GLint y = ctx->DrawBuffer->_Ymin;
00114    const GLint height = ctx->DrawBuffer->_Ymax - ctx->DrawBuffer->_Ymin;
00115    const GLint width  = ctx->DrawBuffer->_Xmax - ctx->DrawBuffer->_Xmin;
00116    SWspan span;
00117    GLint i;
00118 
00119    ASSERT(!ctx->Visual.rgbMode);
00120    ASSERT(rb->PutRow);
00121    ASSERT(rb->DataType == GL_UNSIGNED_INT);
00122 
00123    /* Initialize index span with clear index */
00124    INIT_SPAN(span, GL_BITMAP);
00125    span.end = width;
00126    span.arrayMask = SPAN_INDEX;
00127    for (i = 0; i < width;i++) {
00128       span.array->index[i] = ctx->Color.ClearIndex;
00129    }
00130 
00131    /* Note that masking will change the color indexes, but only the
00132     * bits for which the write mask is GL_FALSE.  The bits
00133     * which are write-enabled won't get modified.
00134     */
00135    for (i = 0; i < height;i++) {
00136       span.x = x;
00137       span.y = y + i;
00138       _swrast_mask_ci_span(ctx, rb, &span);
00139       /* write masked row */
00140       rb->PutRow(ctx, rb, width, x, y + i, span.array->index, NULL);
00141    }
00142 }
00143 
00144 
00148 static void
00149 clear_rgba_buffer(GLcontext *ctx, struct gl_renderbuffer *rb)
00150 {
00151    const GLint x = ctx->DrawBuffer->_Xmin;
00152    const GLint y = ctx->DrawBuffer->_Ymin;
00153    const GLint height = ctx->DrawBuffer->_Ymax - ctx->DrawBuffer->_Ymin;
00154    const GLint width  = ctx->DrawBuffer->_Xmax - ctx->DrawBuffer->_Xmin;
00155    GLubyte clear8[4];
00156    GLushort clear16[4];
00157    GLvoid *clearVal;
00158    GLint i;
00159 
00160    ASSERT(ctx->Visual.rgbMode);
00161 
00162    ASSERT(ctx->Color.ColorMask[0] &&
00163           ctx->Color.ColorMask[1] &&
00164           ctx->Color.ColorMask[2] &&
00165           ctx->Color.ColorMask[3]);             
00166 
00167    ASSERT(rb->PutMonoRow);
00168 
00169    switch (rb->DataType) {
00170       case GL_UNSIGNED_BYTE:
00171          UNCLAMPED_FLOAT_TO_UBYTE(clear8[0], ctx->Color.ClearColor[0]);
00172          UNCLAMPED_FLOAT_TO_UBYTE(clear8[1], ctx->Color.ClearColor[1]);
00173          UNCLAMPED_FLOAT_TO_UBYTE(clear8[2], ctx->Color.ClearColor[2]);
00174          UNCLAMPED_FLOAT_TO_UBYTE(clear8[3], ctx->Color.ClearColor[3]);
00175          clearVal = clear8;
00176          break;
00177       case GL_UNSIGNED_SHORT:
00178          UNCLAMPED_FLOAT_TO_USHORT(clear16[0], ctx->Color.ClearColor[0]);
00179          UNCLAMPED_FLOAT_TO_USHORT(clear16[1], ctx->Color.ClearColor[1]);
00180          UNCLAMPED_FLOAT_TO_USHORT(clear16[2], ctx->Color.ClearColor[2]);
00181          UNCLAMPED_FLOAT_TO_USHORT(clear16[3], ctx->Color.ClearColor[3]);
00182          clearVal = clear16;
00183          break;
00184       case GL_FLOAT:
00185          clearVal = ctx->Color.ClearColor;
00186          break;
00187       default:
00188          _mesa_problem(ctx, "Bad rb DataType in clear_color_buffer");
00189          return;
00190    }
00191 
00192    for (i = 0; i < height; i++) {
00193       rb->PutMonoRow(ctx, rb, width, x, y + i, clearVal, NULL);
00194    }
00195 }
00196 
00197 
00201 static void
00202 clear_ci_buffer(GLcontext *ctx, struct gl_renderbuffer *rb)
00203 {
00204    const GLint x = ctx->DrawBuffer->_Xmin;
00205    const GLint y = ctx->DrawBuffer->_Ymin;
00206    const GLint height = ctx->DrawBuffer->_Ymax - ctx->DrawBuffer->_Ymin;
00207    const GLint width  = ctx->DrawBuffer->_Xmax - ctx->DrawBuffer->_Xmin;
00208    GLubyte clear8;
00209    GLushort clear16;
00210    GLuint clear32;
00211    GLvoid *clearVal;
00212    GLint i;
00213 
00214    ASSERT(!ctx->Visual.rgbMode);
00215 
00216    ASSERT((ctx->Color.IndexMask & ((1 << rb->IndexBits) - 1))
00217           == (GLuint) ((1 << rb->IndexBits) - 1));
00218 
00219    ASSERT(rb->PutMonoRow);
00220 
00221    /* setup clear value */
00222    switch (rb->DataType) {
00223       case GL_UNSIGNED_BYTE:
00224          clear8 = (GLubyte) ctx->Color.ClearIndex;
00225          clearVal = &clear8;
00226          break;
00227       case GL_UNSIGNED_SHORT:
00228          clear16 = (GLushort) ctx->Color.ClearIndex;
00229          clearVal = &clear16;
00230          break;
00231       case GL_UNSIGNED_INT:
00232          clear32 = ctx->Color.ClearIndex;
00233          clearVal = &clear32;
00234          break;
00235       default:
00236          _mesa_problem(ctx, "Bad rb DataType in clear_color_buffer");
00237          return;
00238    }
00239 
00240    for (i = 0; i < height; i++)
00241       rb->PutMonoRow(ctx, rb, width, x, y + i, clearVal, NULL);
00242 }
00243 
00244 
00250 static void
00251 clear_color_buffers(GLcontext *ctx)
00252 {
00253    GLboolean masking;
00254    GLuint buf;
00255 
00256    if (ctx->Visual.rgbMode) {
00257       if (ctx->Color.ColorMask[0] && 
00258           ctx->Color.ColorMask[1] && 
00259           ctx->Color.ColorMask[2] && 
00260           ctx->Color.ColorMask[3]) {
00261          masking = GL_FALSE;
00262       }
00263       else {
00264          masking = GL_TRUE;
00265       }
00266    }
00267    else {
00268       struct gl_renderbuffer *rb = ctx->DrawBuffer->_ColorDrawBuffers[0];
00269       const GLuint indexBits = (1 << rb->IndexBits) - 1;
00270       if ((ctx->Color.IndexMask & indexBits) == indexBits) {
00271          masking = GL_FALSE;
00272       }
00273       else {
00274          masking = GL_TRUE;
00275       }
00276    }
00277 
00278    for (buf = 0; buf < ctx->DrawBuffer->_NumColorDrawBuffers; buf++) {
00279       struct gl_renderbuffer *rb = ctx->DrawBuffer->_ColorDrawBuffers[buf];
00280       if (ctx->Visual.rgbMode) {
00281          if (masking) {
00282             clear_rgba_buffer_with_masking(ctx, rb);
00283          }
00284          else {
00285             clear_rgba_buffer(ctx, rb);
00286          }
00287       }
00288       else {
00289          if (masking) {
00290             clear_ci_buffer_with_masking(ctx, rb);
00291          }
00292          else {
00293             clear_ci_buffer(ctx, rb);
00294          }
00295       }
00296    }
00297 }
00298 
00299 
00307 void
00308 _swrast_Clear(GLcontext *ctx, GLbitfield buffers)
00309 {
00310    SWcontext *swrast = SWRAST_CONTEXT(ctx);
00311 
00312 #ifdef DEBUG_FOO
00313    {
00314       const GLbitfield legalBits =
00315          BUFFER_BIT_FRONT_LEFT |
00316      BUFFER_BIT_FRONT_RIGHT |
00317      BUFFER_BIT_BACK_LEFT |
00318      BUFFER_BIT_BACK_RIGHT |
00319      BUFFER_BIT_DEPTH |
00320      BUFFER_BIT_STENCIL |
00321      BUFFER_BIT_ACCUM |
00322          BUFFER_BIT_AUX0 |
00323          BUFFER_BIT_AUX1 |
00324          BUFFER_BIT_AUX2 |
00325          BUFFER_BIT_AUX3;
00326       assert((buffers & (~legalBits)) == 0);
00327    }
00328 #endif
00329 
00330    RENDER_START(swrast,ctx);
00331 
00332    /* do software clearing here */
00333    if (buffers) {
00334       if ((buffers & BUFFER_BITS_COLOR)
00335           && (ctx->DrawBuffer->_NumColorDrawBuffers > 0)) {
00336          clear_color_buffers(ctx);
00337       }
00338       if (buffers & BUFFER_BIT_DEPTH) {
00339          _swrast_clear_depth_buffer(ctx, ctx->DrawBuffer->_DepthBuffer);
00340       }
00341       if (buffers & BUFFER_BIT_ACCUM) {
00342          _swrast_clear_accum_buffer(ctx,
00343                        ctx->DrawBuffer->Attachment[BUFFER_ACCUM].Renderbuffer);
00344       }
00345       if (buffers & BUFFER_BIT_STENCIL) {
00346          _swrast_clear_stencil_buffer(ctx, ctx->DrawBuffer->_StencilBuffer);
00347       }
00348    }
00349 
00350    RENDER_FINISH(swrast,ctx);
00351 }

Generated on Sun May 27 2012 04:20:42 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.