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

depthstencil.c
Go to the documentation of this file.
00001 /*
00002  * Mesa 3-D graphics library
00003  * Version:  6.5
00004  *
00005  * Copyright (C) 1999-2006  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 
00025 #include "glheader.h"
00026 #include "imports.h"
00027 #include "context.h"
00028 #include "fbobject.h"
00029 #include "mtypes.h"
00030 #include "depthstencil.h"
00031 #include "renderbuffer.h"
00032 
00033 
00048 static void *
00049 nop_get_pointer(GLcontext *ctx, struct gl_renderbuffer *rb, GLint x, GLint y)
00050 {
00051    (void) ctx;
00052    (void) rb;
00053    (void) x;
00054    (void) y;
00055    return NULL;
00056 }
00057 
00058 
00062 static void
00063 delete_wrapper(struct gl_renderbuffer *rb)
00064 {
00065    struct gl_renderbuffer *dsrb = rb->Wrapped;
00066    ASSERT(dsrb);
00067    ASSERT(rb->_ActualFormat == GL_DEPTH_COMPONENT24 ||
00068           rb->_ActualFormat == GL_STENCIL_INDEX8_EXT);
00069    /* decrement refcount on the wrapped buffer and delete it if necessary */
00070    dsrb->RefCount--;
00071    if (dsrb->RefCount <= 0) {
00072       dsrb->Delete(dsrb);
00073    }
00074    _mesa_free(rb);
00075 }
00076 
00077 
00081 static GLboolean
00082 alloc_wrapper_storage(GLcontext *ctx, struct gl_renderbuffer *rb,
00083                       GLenum internalFormat, GLuint width, GLuint height)
00084 {
00085    /* just pass this on to the wrapped renderbuffer */
00086    struct gl_renderbuffer *dsrb = rb->Wrapped;
00087    GLboolean retVal;
00088 
00089    (void) internalFormat;
00090 
00091    ASSERT(dsrb->_ActualFormat == GL_DEPTH24_STENCIL8_EXT);
00092 
00093    retVal = dsrb->AllocStorage(ctx, dsrb, dsrb->InternalFormat, width, height);
00094    if (retVal) {
00095       rb->Width = width;
00096       rb->Height = height;
00097    }
00098    return retVal;
00099 }
00100 
00101 
00102 
00103 
00104 /*======================================================================
00105  * Depth wrapper around depth/stencil renderbuffer
00106  */
00107 
00108 static void
00109 get_row_z24(GLcontext *ctx, struct gl_renderbuffer *z24rb, GLuint count,
00110             GLint x, GLint y, void *values)
00111 {
00112    struct gl_renderbuffer *dsrb = z24rb->Wrapped;
00113    GLuint temp[MAX_WIDTH], i;
00114    GLuint *dst = (GLuint *) values;
00115    const GLuint *src = (const GLuint *) dsrb->GetPointer(ctx, dsrb, x, y);
00116    ASSERT(z24rb->DataType == GL_UNSIGNED_INT);
00117    ASSERT(dsrb->_ActualFormat == GL_DEPTH24_STENCIL8_EXT);
00118    ASSERT(dsrb->DataType == GL_UNSIGNED_INT_24_8_EXT);
00119    if (!src) {
00120       dsrb->GetRow(ctx, dsrb, count, x, y, temp);
00121       src = temp;
00122    }
00123    for (i = 0; i < count; i++) {
00124       dst[i] = src[i] >> 8;
00125    }
00126 }
00127 
00128 static void
00129 get_values_z24(GLcontext *ctx, struct gl_renderbuffer *z24rb, GLuint count,
00130                const GLint x[], const GLint y[], void *values)
00131 {
00132    struct gl_renderbuffer *dsrb = z24rb->Wrapped;
00133    GLuint temp[MAX_WIDTH], i;
00134    GLuint *dst = (GLuint *) values;
00135    ASSERT(z24rb->DataType == GL_UNSIGNED_INT);
00136    ASSERT(dsrb->_ActualFormat == GL_DEPTH24_STENCIL8_EXT);
00137    ASSERT(dsrb->DataType == GL_UNSIGNED_INT_24_8_EXT);
00138    ASSERT(count <= MAX_WIDTH);
00139    /* don't bother trying direct access */
00140    dsrb->GetValues(ctx, dsrb, count, x, y, temp);
00141    for (i = 0; i < count; i++) {
00142       dst[i] = temp[i] >> 8;
00143    }
00144 }
00145 
00146 static void
00147 put_row_z24(GLcontext *ctx, struct gl_renderbuffer *z24rb, GLuint count,
00148             GLint x, GLint y, const void *values, const GLubyte *mask)
00149 {
00150    struct gl_renderbuffer *dsrb = z24rb->Wrapped;
00151    const GLuint *src = (const GLuint *) values;
00152    GLuint *dst = (GLuint *) dsrb->GetPointer(ctx, dsrb, x, y);
00153    ASSERT(z24rb->DataType == GL_UNSIGNED_INT);
00154    ASSERT(dsrb->_ActualFormat == GL_DEPTH24_STENCIL8_EXT);
00155    ASSERT(dsrb->DataType == GL_UNSIGNED_INT_24_8_EXT);
00156    if (dst) {
00157       /* direct access */
00158       GLuint i;
00159       for (i = 0; i < count; i++) {
00160          if (!mask || mask[i]) {
00161             dst[i] = (src[i] << 8) | (dst[i] & 0xff);
00162          }
00163       }
00164    }
00165    else {
00166       /* get, modify, put */
00167       GLuint temp[MAX_WIDTH], i;
00168       dsrb->GetRow(ctx, dsrb, count, x, y, temp);
00169       for (i = 0; i < count; i++) {
00170          if (!mask || mask[i]) {
00171             temp[i] = (src[i] << 8) | (temp[i] & 0xff);
00172          }
00173       }
00174       dsrb->PutRow(ctx, dsrb, count, x, y, temp, mask);
00175    }
00176 }
00177 
00178 static void
00179 put_mono_row_z24(GLcontext *ctx, struct gl_renderbuffer *z24rb, GLuint count,
00180                  GLint x, GLint y, const void *value, const GLubyte *mask)
00181 {
00182    struct gl_renderbuffer *dsrb = z24rb->Wrapped;
00183    const GLuint shiftedVal = *((GLuint *) value) << 8;
00184    GLuint *dst = (GLuint *) dsrb->GetPointer(ctx, dsrb, x, y);
00185    ASSERT(z24rb->DataType == GL_UNSIGNED_INT);
00186    ASSERT(dsrb->_ActualFormat == GL_DEPTH24_STENCIL8_EXT);
00187    ASSERT(dsrb->DataType == GL_UNSIGNED_INT_24_8_EXT);
00188    if (dst) {
00189       /* direct access */
00190       GLuint i;
00191       for (i = 0; i < count; i++) {
00192          if (!mask || mask[i]) {
00193             dst[i] = shiftedVal | (dst[i] & 0xff);
00194          }
00195       }
00196    }
00197    else {
00198       /* get, modify, put */
00199       GLuint temp[MAX_WIDTH], i;
00200       dsrb->GetRow(ctx, dsrb, count, x, y, temp);
00201       for (i = 0; i < count; i++) {
00202          if (!mask || mask[i]) {
00203             temp[i] = shiftedVal | (temp[i] & 0xff);
00204          }
00205       }
00206       dsrb->PutRow(ctx, dsrb, count, x, y, temp, mask);
00207    }
00208 }
00209 
00210 static void
00211 put_values_z24(GLcontext *ctx, struct gl_renderbuffer *z24rb, GLuint count,
00212                const GLint x[], const GLint y[],
00213                const void *values, const GLubyte *mask)
00214 {
00215    struct gl_renderbuffer *dsrb = z24rb->Wrapped;
00216    const GLuint *src = (const GLuint *) values;
00217    ASSERT(z24rb->DataType == GL_UNSIGNED_INT);
00218    ASSERT(dsrb->_ActualFormat == GL_DEPTH24_STENCIL8_EXT);
00219    ASSERT(dsrb->DataType == GL_UNSIGNED_INT_24_8_EXT);
00220    if (dsrb->GetPointer(ctx, dsrb, 0, 0)) {
00221       /* direct access */
00222       GLuint i;
00223       for (i = 0; i < count; i++) {
00224          if (!mask || mask[i]) {
00225             GLuint *dst = (GLuint *) dsrb->GetPointer(ctx, dsrb, x[i], y[i]);
00226             *dst = (src[i] << 8) | (*dst & 0xff);
00227          }
00228       }
00229    }
00230    else {
00231       /* get, modify, put */
00232       GLuint temp[MAX_WIDTH], i;
00233       dsrb->GetValues(ctx, dsrb, count, x, y, temp);
00234       for (i = 0; i < count; i++) {
00235          if (!mask || mask[i]) {
00236             temp[i] = (src[i] << 8) | (temp[i] & 0xff);
00237          }
00238       }
00239       dsrb->PutValues(ctx, dsrb, count, x, y, temp, mask);
00240    }
00241 }
00242 
00243 static void
00244 put_mono_values_z24(GLcontext *ctx, struct gl_renderbuffer *z24rb,
00245                     GLuint count, const GLint x[], const GLint y[],
00246                     const void *value, const GLubyte *mask)
00247 {
00248    struct gl_renderbuffer *dsrb = z24rb->Wrapped;
00249    GLuint temp[MAX_WIDTH], i;
00250    const GLuint shiftedVal = *((GLuint *) value) << 8;
00251    /* get, modify, put */
00252    dsrb->GetValues(ctx, dsrb, count, x, y, temp);
00253    for (i = 0; i < count; i++) {
00254       if (!mask || mask[i]) {
00255          temp[i] = shiftedVal | (temp[i] & 0xff);
00256       }
00257    }
00258    dsrb->PutValues(ctx, dsrb, count, x, y, temp, mask);
00259 }
00260 
00261 
00267 struct gl_renderbuffer *
00268 _mesa_new_z24_renderbuffer_wrapper(GLcontext *ctx,
00269                                    struct gl_renderbuffer *dsrb)
00270 {
00271    struct gl_renderbuffer *z24rb;
00272 
00273    ASSERT(dsrb->_ActualFormat == GL_DEPTH24_STENCIL8_EXT);
00274    ASSERT(dsrb->DataType == GL_UNSIGNED_INT_24_8_EXT);
00275 
00276    z24rb = _mesa_new_renderbuffer(ctx, 0);
00277    if (!z24rb)
00278       return NULL;
00279 
00280    z24rb->Wrapped = dsrb;
00281    z24rb->Name = dsrb->Name;
00282    z24rb->RefCount = 1;
00283    z24rb->Width = dsrb->Width;
00284    z24rb->Height = dsrb->Height;
00285    z24rb->InternalFormat = GL_DEPTH_COMPONENT24;
00286    z24rb->_ActualFormat = GL_DEPTH_COMPONENT24;
00287    z24rb->_BaseFormat = GL_DEPTH_COMPONENT;
00288    z24rb->DataType = GL_UNSIGNED_INT;
00289    z24rb->DepthBits = 24;
00290    z24rb->Data = NULL;
00291    z24rb->Delete = delete_wrapper;
00292    z24rb->AllocStorage = alloc_wrapper_storage;
00293    z24rb->GetPointer = nop_get_pointer;
00294    z24rb->GetRow = get_row_z24;
00295    z24rb->GetValues = get_values_z24;
00296    z24rb->PutRow = put_row_z24;
00297    z24rb->PutRowRGB = NULL;
00298    z24rb->PutMonoRow = put_mono_row_z24;
00299    z24rb->PutValues = put_values_z24;
00300    z24rb->PutMonoValues = put_mono_values_z24;
00301 
00302    return z24rb;
00303 }
00304 
00305 
00306 /*======================================================================
00307  * Stencil wrapper around depth/stencil renderbuffer
00308  */
00309 
00310 static void
00311 get_row_s8(GLcontext *ctx, struct gl_renderbuffer *s8rb, GLuint count,
00312            GLint x, GLint y, void *values)
00313 {
00314    struct gl_renderbuffer *dsrb = s8rb->Wrapped;
00315    GLuint temp[MAX_WIDTH], i;
00316    GLubyte *dst = (GLubyte *) values;
00317    const GLuint *src = (const GLuint *) dsrb->GetPointer(ctx, dsrb, x, y);
00318    ASSERT(s8rb->DataType == GL_UNSIGNED_BYTE);
00319    ASSERT(dsrb->_ActualFormat == GL_DEPTH24_STENCIL8_EXT);
00320    ASSERT(dsrb->DataType == GL_UNSIGNED_INT_24_8_EXT);
00321    if (!src) {
00322       dsrb->GetRow(ctx, dsrb, count, x, y, temp);
00323       src = temp;
00324    }
00325    for (i = 0; i < count; i++) {
00326       dst[i] = src[i] & 0xff;
00327    }
00328 }
00329 
00330 static void
00331 get_values_s8(GLcontext *ctx, struct gl_renderbuffer *s8rb, GLuint count,
00332               const GLint x[], const GLint y[], void *values)
00333 {
00334    struct gl_renderbuffer *dsrb = s8rb->Wrapped;
00335    GLuint temp[MAX_WIDTH], i;
00336    GLubyte *dst = (GLubyte *) values;
00337    ASSERT(s8rb->DataType == GL_UNSIGNED_BYTE);
00338    ASSERT(dsrb->_ActualFormat == GL_DEPTH24_STENCIL8_EXT);
00339    ASSERT(dsrb->DataType == GL_UNSIGNED_INT_24_8_EXT);
00340    ASSERT(count <= MAX_WIDTH);
00341    /* don't bother trying direct access */
00342    dsrb->GetValues(ctx, dsrb, count, x, y, temp);
00343    for (i = 0; i < count; i++) {
00344       dst[i] = temp[i] & 0xff;
00345    }
00346 }
00347 
00348 static void
00349 put_row_s8(GLcontext *ctx, struct gl_renderbuffer *s8rb, GLuint count,
00350            GLint x, GLint y, const void *values, const GLubyte *mask)
00351 {
00352    struct gl_renderbuffer *dsrb = s8rb->Wrapped;
00353    const GLubyte *src = (const GLubyte *) values;
00354    GLuint *dst = (GLuint *) dsrb->GetPointer(ctx, dsrb, x, y);
00355    ASSERT(s8rb->DataType == GL_UNSIGNED_BYTE);
00356    ASSERT(dsrb->_ActualFormat == GL_DEPTH24_STENCIL8_EXT);
00357    ASSERT(dsrb->DataType == GL_UNSIGNED_INT_24_8_EXT);
00358    if (dst) {
00359       /* direct access */
00360       GLuint i;
00361       for (i = 0; i < count; i++) {
00362          if (!mask || mask[i]) {
00363             dst[i] = (dst[i] & 0xffffff00) | src[i];
00364          }
00365       }
00366    }
00367    else {
00368       /* get, modify, put */
00369       GLuint temp[MAX_WIDTH], i;
00370       dsrb->GetRow(ctx, dsrb, count, x, y, temp);
00371       for (i = 0; i < count; i++) {
00372          if (!mask || mask[i]) {
00373             temp[i] = (temp[i] & 0xffffff00) | src[i];
00374          }
00375       }
00376       dsrb->PutRow(ctx, dsrb, count, x, y, temp, mask);
00377    }
00378 }
00379 
00380 static void
00381 put_mono_row_s8(GLcontext *ctx, struct gl_renderbuffer *s8rb, GLuint count,
00382                 GLint x, GLint y, const void *value, const GLubyte *mask)
00383 {
00384    struct gl_renderbuffer *dsrb = s8rb->Wrapped;
00385    const GLubyte val = *((GLubyte *) value);
00386    GLuint *dst = (GLuint *) dsrb->GetPointer(ctx, dsrb, x, y);
00387    ASSERT(s8rb->DataType == GL_UNSIGNED_BYTE);
00388    ASSERT(dsrb->_ActualFormat == GL_DEPTH24_STENCIL8_EXT);
00389    ASSERT(dsrb->DataType == GL_UNSIGNED_INT_24_8_EXT);
00390    if (dst) {
00391       /* direct access */
00392       GLuint i;
00393       for (i = 0; i < count; i++) {
00394          if (!mask || mask[i]) {
00395             dst[i] = (dst[i] & 0xffffff00) | val;
00396          }
00397       }
00398    }
00399    else {
00400       /* get, modify, put */
00401       GLuint temp[MAX_WIDTH], i;
00402       dsrb->GetRow(ctx, dsrb, count, x, y, temp);
00403       for (i = 0; i < count; i++) {
00404          if (!mask || mask[i]) {
00405             temp[i] = (temp[i] & 0xffffff00) | val;
00406          }
00407       }
00408       dsrb->PutRow(ctx, dsrb, count, x, y, temp, mask);
00409    }
00410 }
00411 
00412 static void
00413 put_values_s8(GLcontext *ctx, struct gl_renderbuffer *s8rb, GLuint count,
00414               const GLint x[], const GLint y[],
00415               const void *values, const GLubyte *mask)
00416 {
00417    struct gl_renderbuffer *dsrb = s8rb->Wrapped;
00418    const GLubyte *src = (const GLubyte *) values;
00419    ASSERT(s8rb->DataType == GL_UNSIGNED_BYTE);
00420    ASSERT(dsrb->_ActualFormat == GL_DEPTH24_STENCIL8_EXT);
00421    ASSERT(dsrb->DataType == GL_UNSIGNED_INT_24_8_EXT);
00422    if (dsrb->GetPointer(ctx, dsrb, 0, 0)) {
00423       /* direct access */
00424       GLuint i;
00425       for (i = 0; i < count; i++) {
00426          if (!mask || mask[i]) {
00427             GLuint *dst = (GLuint *) dsrb->GetPointer(ctx, dsrb, x[i], y[i]);
00428             *dst = (*dst & 0xffffff00) | src[i];
00429          }
00430       }
00431    }
00432    else {
00433       /* get, modify, put */
00434       GLuint temp[MAX_WIDTH], i;
00435       dsrb->GetValues(ctx, dsrb, count, x, y, temp);
00436       for (i = 0; i < count; i++) {
00437          if (!mask || mask[i]) {
00438             temp[i] = (temp[i] & 0xffffff00) | src[i];
00439          }
00440       }
00441       dsrb->PutValues(ctx, dsrb, count, x, y, temp, mask);
00442    }
00443 }
00444 
00445 static void
00446 put_mono_values_s8(GLcontext *ctx, struct gl_renderbuffer *s8rb, GLuint count,
00447                    const GLint x[], const GLint y[],
00448                    const void *value, const GLubyte *mask)
00449 {
00450    struct gl_renderbuffer *dsrb = s8rb->Wrapped;
00451    GLuint temp[MAX_WIDTH], i;
00452    const GLubyte val = *((GLubyte *) value);
00453    /* get, modify, put */
00454    dsrb->GetValues(ctx, dsrb, count, x, y, temp);
00455    for (i = 0; i < count; i++) {
00456       if (!mask || mask[i]) {
00457          temp[i] = (temp[i] & 0xffffff) | val;
00458       }
00459    }
00460    dsrb->PutValues(ctx, dsrb, count, x, y, temp, mask);
00461 }
00462 
00463 
00469 struct gl_renderbuffer *
00470 _mesa_new_s8_renderbuffer_wrapper(GLcontext *ctx, struct gl_renderbuffer *dsrb)
00471 {
00472    struct gl_renderbuffer *s8rb;
00473 
00474    ASSERT(dsrb->_ActualFormat == GL_DEPTH24_STENCIL8_EXT);
00475    ASSERT(dsrb->DataType == GL_UNSIGNED_INT_24_8_EXT);
00476 
00477    s8rb = _mesa_new_renderbuffer(ctx, 0);
00478    if (!s8rb)
00479       return NULL;
00480 
00481    s8rb->Wrapped = dsrb;
00482    s8rb->Name = dsrb->Name;
00483    s8rb->RefCount = 1;
00484    s8rb->Width = dsrb->Width;
00485    s8rb->Height = dsrb->Height;
00486    s8rb->InternalFormat = GL_STENCIL_INDEX8_EXT;
00487    s8rb->_ActualFormat = GL_STENCIL_INDEX8_EXT;
00488    s8rb->_BaseFormat = GL_STENCIL_INDEX;
00489    s8rb->DataType = GL_UNSIGNED_BYTE;
00490    s8rb->StencilBits = 8;
00491    s8rb->Data = NULL;
00492    s8rb->Delete = delete_wrapper;
00493    s8rb->AllocStorage = alloc_wrapper_storage;
00494    s8rb->GetPointer = nop_get_pointer;
00495    s8rb->GetRow = get_row_s8;
00496    s8rb->GetValues = get_values_s8;
00497    s8rb->PutRow = put_row_s8;
00498    s8rb->PutRowRGB = NULL;
00499    s8rb->PutMonoRow = put_mono_row_s8;
00500    s8rb->PutValues = put_values_s8;
00501    s8rb->PutMonoValues = put_mono_values_s8;
00502 
00503    return s8rb;
00504 }
00505 
00506 
00507 
00527 void
00528 _mesa_extract_stencil(GLcontext *ctx,
00529                       struct gl_renderbuffer *dsRb,
00530                       struct gl_renderbuffer *stencilRb)
00531 {
00532    GLuint row, width, height;
00533 
00534    ASSERT(dsRb);
00535    ASSERT(stencilRb);
00536 
00537    ASSERT(dsRb->_ActualFormat == GL_DEPTH24_STENCIL8_EXT);
00538    ASSERT(dsRb->DataType == GL_UNSIGNED_INT_24_8_EXT);
00539    ASSERT(stencilRb->_ActualFormat == GL_DEPTH24_STENCIL8_EXT ||
00540           stencilRb->_ActualFormat == GL_STENCIL_INDEX8_EXT);
00541    ASSERT(dsRb->Width == stencilRb->Width);
00542    ASSERT(dsRb->Height == stencilRb->Height);
00543 
00544    width = dsRb->Width;
00545    height = dsRb->Height;
00546 
00547    for (row = 0; row < height; row++) {
00548       GLuint depthStencil[MAX_WIDTH];
00549       dsRb->GetRow(ctx, dsRb, width, 0, row, depthStencil);
00550       if (stencilRb->_ActualFormat == GL_STENCIL_INDEX8_EXT) {
00551          /* 8bpp stencil */
00552          GLubyte stencil[MAX_WIDTH];
00553          GLuint i;
00554          for (i = 0; i < width; i++) {
00555             stencil[i] = depthStencil[i] & 0xff;
00556          }
00557          stencilRb->PutRow(ctx, stencilRb, width, 0, row, stencil, NULL);
00558       }
00559       else {
00560          /* 32bpp stencil */
00561          /* the 24 depth bits will be ignored */
00562          ASSERT(stencilRb->_ActualFormat == GL_DEPTH24_STENCIL8_EXT);
00563          ASSERT(stencilRb->DataType == GL_UNSIGNED_INT_24_8_EXT);
00564          stencilRb->PutRow(ctx, stencilRb, width, 0, row, depthStencil, NULL);
00565       }
00566    }
00567 }
00568 
00569 
00576 void
00577 _mesa_insert_stencil(GLcontext *ctx,
00578                      struct gl_renderbuffer *dsRb,
00579                      struct gl_renderbuffer *stencilRb)
00580 {
00581    GLuint row, width, height;
00582 
00583    ASSERT(dsRb);
00584    ASSERT(stencilRb);
00585 
00586    ASSERT(dsRb->_ActualFormat == GL_DEPTH24_STENCIL8_EXT);
00587    ASSERT(dsRb->DataType == GL_UNSIGNED_INT_24_8_EXT);
00588    ASSERT(stencilRb->_ActualFormat == GL_DEPTH24_STENCIL8_EXT ||
00589           stencilRb->_ActualFormat == GL_STENCIL_INDEX8_EXT);
00590 
00591    ASSERT(dsRb->Width == stencilRb->Width);
00592    ASSERT(dsRb->Height == stencilRb->Height);
00593 
00594    width = dsRb->Width;
00595    height = dsRb->Height;
00596 
00597    for (row = 0; row < height; row++) {
00598       GLuint depthStencil[MAX_WIDTH];
00599 
00600       dsRb->GetRow(ctx, dsRb, width, 0, row, depthStencil);
00601 
00602       if (stencilRb->_ActualFormat == GL_STENCIL_INDEX8_EXT) {
00603          /* 8bpp stencil */
00604          GLubyte stencil[MAX_WIDTH];
00605          GLuint i;
00606          stencilRb->GetRow(ctx, stencilRb, width, 0, row, stencil);
00607          for (i = 0; i < width; i++) {
00608             depthStencil[i] = (depthStencil[i] & 0xffffff00) | stencil[i];
00609          }
00610       }
00611       else {
00612          /* 32bpp stencil buffer */
00613          GLuint stencil[MAX_WIDTH], i;
00614          ASSERT(stencilRb->_ActualFormat == GL_DEPTH24_STENCIL8_EXT);
00615          ASSERT(stencilRb->DataType == GL_UNSIGNED_INT_24_8_EXT);
00616          stencilRb->GetRow(ctx, stencilRb, width, 0, row, stencil);
00617          for (i = 0; i < width; i++) {
00618             depthStencil[i]
00619                = (depthStencil[i] & 0xffffff00) | (stencil[i] & 0xff);
00620          }
00621       }
00622 
00623       dsRb->PutRow(ctx, dsRb, width, 0, row, depthStencil, NULL);
00624    }
00625 }
00626 
00627 
00632 void
00633 _mesa_promote_stencil(GLcontext *ctx, struct gl_renderbuffer *stencilRb)
00634 {
00635    const GLsizei width = stencilRb->Width;
00636    const GLsizei height = stencilRb->Height;
00637    GLubyte *data;
00638    GLint i, j, k;
00639 
00640    ASSERT(stencilRb->_ActualFormat == GL_STENCIL_INDEX8_EXT);
00641    ASSERT(stencilRb->Data);
00642 
00643    data = (GLubyte *) stencilRb->Data;
00644    stencilRb->Data = NULL;
00645    stencilRb->AllocStorage(ctx, stencilRb, GL_DEPTH24_STENCIL8_EXT,
00646                            width, height);
00647 
00648    ASSERT(stencilRb->DataType == GL_UNSIGNED_INT_24_8_EXT);
00649 
00650    k = 0;
00651    for (i = 0; i < height; i++) {
00652       GLuint depthStencil[MAX_WIDTH];
00653       for (j = 0; j < width; j++) {
00654          depthStencil[j] = data[k++];
00655       }
00656       stencilRb->PutRow(ctx, stencilRb, width, 0, i, depthStencil, NULL);
00657    }
00658    _mesa_free(data);
00659 
00660    stencilRb->_BaseFormat = GL_DEPTH_STENCIL_EXT;
00661 }

Generated on Sat May 26 2012 04:19:00 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.