+/** Put colors at x/y locations into a renderbuffer */
+static void
+put_values(struct gl_context *ctx, struct gl_renderbuffer *rb,
+ GLenum datatype,
+ GLuint count, const GLint x[], const GLint y[],
+ const void *values, const GLubyte *mask)
+{
+ gl_pack_ubyte_rgba_func pack_ubyte = NULL;
+ gl_pack_float_rgba_func pack_float = NULL;
+ GLuint i;
+
+ if (datatype == GL_UNSIGNED_BYTE)
+ pack_ubyte = _mesa_get_pack_ubyte_rgba_function(rb->Format);
+ else
+ pack_float = _mesa_get_pack_float_rgba_function(rb->Format);
+
+ for (i = 0; i < count; i++) {
+ if (mask[i]) {
+ GLubyte *dst = _swrast_pixel_address(rb, x[i], y[i]);
+
+ if (datatype == GL_UNSIGNED_BYTE) {
+ pack_ubyte((const GLubyte *) values + 4 * i, dst);
+ }
+ else {
+ assert(datatype == GL_FLOAT);
+ pack_float((const GLfloat *) values + 4 * i, dst);
+ }
+ }
+ }
+}
+
+
+/** Put row of colors into renderbuffer */
+void
+_swrast_put_row(struct gl_context *ctx, struct gl_renderbuffer *rb,
+ GLenum datatype,
+ GLuint count, GLint x, GLint y,
+ const void *values, const GLubyte *mask)
+{
+ GLubyte *dst = _swrast_pixel_address(rb, x, y);
+
+ if (!mask) {
+ if (datatype == GL_UNSIGNED_BYTE) {
+ _mesa_pack_ubyte_rgba_row(rb->Format, count,
+ (const GLubyte (*)[4]) values, dst);
+ }
+ else {
+ assert(datatype == GL_FLOAT);
+ _mesa_pack_float_rgba_row(rb->Format, count,
+ (const GLfloat (*)[4]) values, dst);
+ }
+ }
+ else {
+ const GLuint bpp = _mesa_get_format_bytes(rb->Format);
+ GLuint i, runLen, runStart;
+ /* We can't pass a 'mask' array to the _mesa_pack_rgba_row() functions
+ * so look for runs where mask=1...
+ */
+ runLen = runStart = 0;
+ for (i = 0; i < count; i++) {
+ if (mask[i]) {
+ if (runLen == 0)
+ runStart = i;
+ runLen++;
+ }
+
+ if (!mask[i] || i == count - 1) {
+ /* might be the end of a run of pixels */
+ if (runLen > 0) {
+ if (datatype == GL_UNSIGNED_BYTE) {
+ _mesa_pack_ubyte_rgba_row(rb->Format, runLen,
+ (const GLubyte (*)[4]) values + runStart,
+ dst + runStart * bpp);
+ }
+ else {
+ assert(datatype == GL_FLOAT);
+ _mesa_pack_float_rgba_row(rb->Format, runLen,
+ (const GLfloat (*)[4]) values + runStart,
+ dst + runStart * bpp);
+ }
+ runLen = 0;
+ }
+ }
+ }
+ }
+}
+
+