+static inline size_t buffer_to_size(GLenum buffer)
+{
+ switch (buffer) {
+ case GL_COLOR:
+ return 4;
+ case GL_DEPTH_STENCIL:
+ return 2;
+ case GL_STENCIL:
+ case GL_DEPTH:
+ return 1;
+ default:
+ return 0;
+ }
+}
+
+static inline bool clear_buffer_add_command(struct gl_context *ctx, uint16_t id,
+ GLenum buffer, GLint drawbuffer,
+ const GLuint *value, size_t size)
+{
+ size_t cmd_size = sizeof(struct marshal_cmd_ClearBuffer) + 4 * size;
+ if (cmd_size <= MARSHAL_MAX_CMD_SIZE) {
+ struct marshal_cmd_ClearBuffer *cmd =
+ _mesa_glthread_allocate_command(ctx, id,
+ cmd_size);
+ cmd->buffer = buffer;
+ cmd->drawbuffer = drawbuffer;
+ GLuint *variable_data = (GLuint *) (cmd + 1);
+ if (size == 4)
+ COPY_4V(variable_data, value);
+ else if (size == 2)
+ COPY_2V(variable_data, value);
+ else
+ *variable_data = *value;
+
+ _mesa_post_marshal_hook(ctx);
+ return true;
+ }
+
+ return false;
+}
+