- switch (type) {
- case GL_UNSIGNED_BYTE:
- if (sizeof(GLstencil) == 8) {
- MEMCPY( dest, stencil, readWidth );
- }
- else {
- GLubyte *dst = (GLubyte *) dest;
- for (i=0;i<readWidth;i++) {
- dst[i] = (GLubyte) stencil[i];
- }
- }
- break;
- case GL_BYTE:
- if (sizeof(GLstencil) == 8) {
- MEMCPY( dest, stencil, readWidth );
- }
- else {
- GLbyte *dst = (GLbyte *) dest;
- for (i=0;i<readWidth;i++) {
- dst[i] = (GLbyte) stencil[i];
- }
- }
- break;
- case GL_UNSIGNED_SHORT:
- {
- GLushort *dst = (GLushort *) dest;
- for (i=0;i<readWidth;i++) {
- dst[i] = (GLushort) stencil[i];
- }
- if (packing->SwapBytes) {
- _mesa_swap2( (GLushort *) dst, readWidth );
- }
- }
- break;
- case GL_SHORT:
- {
- GLshort *dst = (GLshort *) dest;
- for (i=0;i<readWidth;i++) {
- dst[i] = (GLshort) stencil[i];
- }
- if (packing->SwapBytes) {
- _mesa_swap2( (GLushort *) dst, readWidth );
- }
- }
- break;
- case GL_UNSIGNED_INT:
- {
- GLuint *dst = (GLuint *) dest;
- for (i=0;i<readWidth;i++) {
- dst[i] = (GLuint) stencil[i];
- }
- if (packing->SwapBytes) {
- _mesa_swap4( (GLuint *) dst, readWidth );
- }
- }
- break;
- case GL_INT:
- {
- GLint *dst = (GLint *) dest;
- for (i=0;i<readWidth;i++) {
- *dst++ = (GLint) stencil[i];
- }
- if (packing->SwapBytes) {
- _mesa_swap4( (GLuint *) dst, readWidth );
- }
- }
- break;
- case GL_FLOAT:
- {
- GLfloat *dst = (GLfloat *) dest;
- for (i=0;i<readWidth;i++) {
- dst[i] = (GLfloat) stencil[i];
- }
- if (packing->SwapBytes) {
- _mesa_swap4( (GLuint *) dst, readWidth );
- }
- }
- break;
- case GL_BITMAP:
- if (packing->LsbFirst) {
- GLubyte *dst = (GLubyte*) dest;
- GLint shift = 0;
- for (i = 0; i < readWidth; i++) {
- if (shift == 0)
- *dst = 0;
- *dst |= ((stencil != 0) << shift);
- shift++;
- if (shift == 8) {
- shift = 0;
- dst++;
- }
- }
- }
- else {
- GLubyte *dst = (GLubyte*) dest;
- GLint shift = 7;
- for (i = 0; i < readWidth; i++) {
- if (shift == 7)
- *dst = 0;
- *dst |= ((stencil != 0) << shift);
- shift--;
- if (shift < 0) {
- shift = 7;
- dst++;
- }
- }
- }
- break;
- default:
- gl_error( ctx, GL_INVALID_ENUM, "glReadPixels(type)" );
- }