+ if (*colorMask == 0xffffffff && ctx->Color.IndexMask == 0xffffffff) {
+ if (mask & DD_FRONT_LEFT_BIT) {
+ if (osmesa->format == OSMESA_COLOR_INDEX) {
+ if (all) {
+ /* Clear whole CI buffer */
+#if CHAN_TYPE == GL_UNSIGNED_BYTE
+ MEMSET(osmesa->buffer, ctx->Color.ClearIndex,
+ osmesa->rowlength * osmesa->height);
+#else
+ const GLint n = osmesa->rowlength * osmesa->height;
+ GLchan *buffer = (GLchan *) osmesa->buffer;
+ GLint i;
+ for (i = 0; i < n; i ++) {
+ buffer[i] = ctx->Color.ClearIndex;
+ }
+#endif
+ }
+ else {
+ /* Clear part of CI buffer */
+ const GLchan clearIndex = (GLchan) ctx->Color.ClearIndex;
+ GLint i, j;
+ for (i = 0; i < height; i++) {
+ GLchan *ptr1 = PIXELADDR1(x, (y + i));
+ for (j = 0; j < width; j++) {
+ *ptr1++ = clearIndex;
+ }
+ }
+ }
+ }
+ else if (osmesa->format == OSMESA_RGB) {
+ const GLchan r = ctx->Color.ClearColor[0];
+ const GLchan g = ctx->Color.ClearColor[1];
+ const GLchan b = ctx->Color.ClearColor[2];
+ if (all) {
+ /* Clear whole RGB buffer */
+ GLuint n = osmesa->rowlength * osmesa->height;
+ GLchan *ptr3 = (GLchan *) osmesa->buffer;
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ PACK_RGB(ptr3, r, g, b);
+ ptr3 += 3;
+ }
+ }
+ else {
+ /* Clear part of RGB buffer */
+ GLint i, j;
+ for (i = 0; i < height; i++) {
+ GLchan *ptr3 = PIXELADDR3(x, (y + i));
+ for (j = 0; j < width; j++) {
+ PACK_RGB(ptr3, r, g, b);
+ ptr3 += 3;
+ }
+ }
+ }
+ }
+ else if (osmesa->format == OSMESA_BGR) {
+ const GLchan r = ctx->Color.ClearColor[0];
+ const GLchan g = ctx->Color.ClearColor[1];
+ const GLchan b = ctx->Color.ClearColor[2];
+ if (all) {
+ /* Clear whole RGB buffer */
+ const GLint n = osmesa->rowlength * osmesa->height;
+ GLchan *ptr3 = (GLchan *) osmesa->buffer;
+ GLint i;
+ for (i = 0; i < n; i++) {
+ PACK_BGR(ptr3, r, g, b);
+ ptr3 += 3;
+ }
+ }
+ else {
+ /* Clear part of RGB buffer */
+ GLint i, j;
+ for (i = 0; i < height; i++) {
+ GLchan *ptr3 = PIXELADDR3(x, (y + i));
+ for (j = 0; j < width; j++) {
+ PACK_BGR(ptr3, r, g, b);
+ ptr3 += 3;
+ }
+ }
+ }
+ }
+ else {
+#if CHAN_TYPE == GL_UNSIGNED_BYTE
+ /* 4-byte pixel value */
+ GLuint clearPixel;
+ GLchan *clr = (GLchan *) &clearPixel;
+ clr[osmesa->rInd] = ctx->Color.ClearColor[0];
+ clr[osmesa->gInd] = ctx->Color.ClearColor[1];
+ clr[osmesa->bInd] = ctx->Color.ClearColor[2];
+ clr[osmesa->aInd] = ctx->Color.ClearColor[3];
+ if (all) {
+ /* Clear whole RGBA buffer */
+ const GLuint n = osmesa->rowlength * osmesa->height;
+ GLuint *ptr4 = (GLuint *) osmesa->buffer;
+ GLuint i;
+ if (clearPixel) {
+ for (i = 0; i < n; i++) {
+ *ptr4++ = clearPixel;
+ }
+ }
+ else {
+ BZERO(ptr4, n * sizeof(GLuint));
+ }
+ }
+ else {
+ /* Clear part of RGBA buffer */
+ GLint i, j;
+ for (i = 0; i < height; i++) {
+ GLuint *ptr4 = (GLuint *) PIXELADDR4(x, (y + i));
+ for (j = 0; j < width; j++) {
+ *ptr4++ = clearPixel;
+ }
+ }
+ }
+#else
+ const GLchan r = ctx->Color.ClearColor[0];
+ const GLchan g = ctx->Color.ClearColor[1];
+ const GLchan b = ctx->Color.ClearColor[2];
+ const GLchan a = ctx->Color.ClearColor[3];
+ if (all) {
+ /* Clear whole RGBA buffer */
+ const GLuint n = osmesa->rowlength * osmesa->height;
+ GLchan *p = (GLchan *) osmesa->buffer;
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ PACK_RGBA(p, r, g, b, a);
+ p += 4;
+ }
+ }
+ else {
+ /* Clear part of RGBA buffer */
+ GLint i, j;
+ for (i = 0; i < height; i++) {
+ GLchan *p = PIXELADDR4(x, (y + i));
+ for (j = 0; j < width; j++) {
+ PACK_RGBA(p, r, g, b, a);
+ p += 4;
+ }
+ }
+ }