aboutsummaryrefslogtreecommitdiff
path: root/mesalib/src
diff options
context:
space:
mode:
authormarha <marha@users.sourceforge.net>2011-12-12 14:26:41 +0100
committermarha <marha@users.sourceforge.net>2011-12-12 14:26:41 +0100
commit2b5652fc7742c5ac57aca701214b046626a729e9 (patch)
treea994b9e63a32a7c061bcfb563aa22369c217e49c /mesalib/src
parent2331d6e4ac699e775ccee07a8a461cae0a98033a (diff)
parent5efb0a5e19b75137b7294b27f4e7878aeb8f0927 (diff)
downloadvcxsrv-2b5652fc7742c5ac57aca701214b046626a729e9.tar.gz
vcxsrv-2b5652fc7742c5ac57aca701214b046626a729e9.tar.bz2
vcxsrv-2b5652fc7742c5ac57aca701214b046626a729e9.zip
Merge remote-tracking branch 'origin/released'
Diffstat (limited to 'mesalib/src')
-rw-r--r--mesalib/src/gallium/auxiliary/util/u_math.h4
-rw-r--r--mesalib/src/mesa/SConscript4
-rw-r--r--mesalib/src/mesa/drivers/common/driverfuncs.c12
-rw-r--r--mesalib/src/mesa/drivers/dri/swrast/swrast.c15
-rw-r--r--mesalib/src/mesa/drivers/windows/gdi/wmesa.c15
-rw-r--r--mesalib/src/mesa/main/accum.c386
-rw-r--r--mesalib/src/mesa/main/accum.h18
-rw-r--r--mesalib/src/mesa/main/dd.h18
-rw-r--r--mesalib/src/mesa/main/depthstencil.c155
-rw-r--r--mesalib/src/mesa/main/depthstencil.h16
-rw-r--r--mesalib/src/mesa/main/format_pack.c2496
-rw-r--r--mesalib/src/mesa/main/format_pack.h98
-rw-r--r--mesalib/src/mesa/main/format_unpack.c8
-rw-r--r--mesalib/src/mesa/main/formats.c2
-rw-r--r--mesalib/src/mesa/main/formats.h8
-rw-r--r--mesalib/src/mesa/main/framebuffer.c1
-rw-r--r--mesalib/src/mesa/main/image.c104
-rw-r--r--mesalib/src/mesa/main/image.h7
-rw-r--r--mesalib/src/mesa/main/pack.c4
-rw-r--r--mesalib/src/mesa/main/pbo.c29
-rw-r--r--mesalib/src/mesa/main/readpix.c23
-rw-r--r--mesalib/src/mesa/main/renderbuffer.c2022
-rw-r--r--mesalib/src/mesa/main/renderbuffer.h57
-rw-r--r--mesalib/src/mesa/main/texobj.c23
-rw-r--r--mesalib/src/mesa/main/texparam.c6
-rw-r--r--mesalib/src/mesa/main/texstore.c17
-rw-r--r--mesalib/src/mesa/sources.mak4
-rw-r--r--mesalib/src/mesa/state_tracker/st_cb_accum.c347
-rw-r--r--mesalib/src/mesa/state_tracker/st_cb_accum.h63
-rw-r--r--mesalib/src/mesa/state_tracker/st_cb_clear.c5
-rw-r--r--mesalib/src/mesa/state_tracker/st_cb_fbo.c21
-rw-r--r--mesalib/src/mesa/state_tracker/st_cb_texture.c222
-rw-r--r--mesalib/src/mesa/state_tracker/st_context.c5
-rw-r--r--mesalib/src/mesa/state_tracker/st_extensions.c10
-rw-r--r--mesalib/src/mesa/state_tracker/st_glsl_to_tgsi.cpp18
-rw-r--r--mesalib/src/mesa/state_tracker/st_manager.c64
-rw-r--r--mesalib/src/mesa/state_tracker/st_program.c19
-rw-r--r--mesalib/src/mesa/swrast/s_accum.c598
-rw-r--r--mesalib/src/mesa/swrast/s_clear.c5
-rw-r--r--mesalib/src/mesa/swrast/s_context.c6
-rw-r--r--mesalib/src/mesa/swrast/s_context.h5
-rw-r--r--mesalib/src/mesa/swrast/s_copypix.c10
-rw-r--r--mesalib/src/mesa/swrast/s_renderbuffer.c2034
-rw-r--r--mesalib/src/mesa/swrast/s_renderbuffer.h (renamed from mesalib/src/mesa/swrast/s_accum.h)104
-rw-r--r--mesalib/src/mesa/swrast/s_texfetch_tmp.h4
-rw-r--r--mesalib/src/mesa/swrast/s_zoom.c10
-rw-r--r--mesalib/src/mesa/swrast/swrast.h3
47 files changed, 5442 insertions, 3663 deletions
diff --git a/mesalib/src/gallium/auxiliary/util/u_math.h b/mesalib/src/gallium/auxiliary/util/u_math.h
index f908341f6..404bd21e1 100644
--- a/mesalib/src/gallium/auxiliary/util/u_math.h
+++ b/mesalib/src/gallium/auxiliary/util/u_math.h
@@ -51,6 +51,10 @@ extern "C" {
#include <math.h>
#include <stdarg.h>
+#ifdef PIPE_OS_UNIX
+#include <strings.h> /* for ffs */
+#endif
+
#ifndef M_SQRT2
#define M_SQRT2 1.41421356237309504880
diff --git a/mesalib/src/mesa/SConscript b/mesalib/src/mesa/SConscript
index bcb6a2491..da4d9b185 100644
--- a/mesalib/src/mesa/SConscript
+++ b/mesalib/src/mesa/SConscript
@@ -74,6 +74,7 @@ main_sources = [
'main/ffvertex_prog.c',
'main/fog.c',
'main/formats.c',
+ 'main/format_pack.c',
'main/format_unpack.c',
'main/framebuffer.c',
'main/get.c',
@@ -152,7 +153,6 @@ math_sources = [
swrast_sources = [
'swrast/s_aaline.c',
'swrast/s_aatriangle.c',
- 'swrast/s_accum.c',
'swrast/s_alpha.c',
'swrast/s_atifragshader.c',
'swrast/s_bitmap.c',
@@ -170,6 +170,7 @@ swrast_sources = [
'swrast/s_logic.c',
'swrast/s_masking.c',
'swrast/s_points.c',
+ 'swrast/s_renderbuffer.c',
'swrast/s_span.c',
'swrast/s_stencil.c',
'swrast/s_texcombine.c',
@@ -240,7 +241,6 @@ statetracker_sources = [
'state_tracker/st_atom_stipple.c',
'state_tracker/st_atom_texture.c',
'state_tracker/st_atom_viewport.c',
- 'state_tracker/st_cb_accum.c',
'state_tracker/st_cb_bitmap.c',
'state_tracker/st_cb_blit.c',
'state_tracker/st_cb_bufferobjects.c',
diff --git a/mesalib/src/mesa/drivers/common/driverfuncs.c b/mesalib/src/mesa/drivers/common/driverfuncs.c
index 5e25d7fda..c6b42a21d 100644
--- a/mesalib/src/mesa/drivers/common/driverfuncs.c
+++ b/mesalib/src/mesa/drivers/common/driverfuncs.c
@@ -25,6 +25,7 @@
#include "main/glheader.h"
#include "main/imports.h"
+#include "main/accum.h"
#include "main/arrayobj.h"
#include "main/context.h"
#include "main/framebuffer.h"
@@ -49,6 +50,7 @@
#include "program/program.h"
#include "tnl/tnl.h"
#include "swrast/swrast.h"
+#include "swrast/s_renderbuffer.h"
#include "driverfuncs.h"
#include "meta.h"
@@ -80,7 +82,7 @@ _mesa_init_driver_functions(struct dd_function_table *driver)
/* framebuffer/image functions */
driver->Clear = _swrast_Clear;
- driver->Accum = _swrast_Accum;
+ driver->Accum = _mesa_accum;
driver->RasterPos = _tnl_RasterPos;
driver->DrawPixels = _swrast_DrawPixels;
driver->ReadPixels = _mesa_readpixels;
@@ -119,8 +121,6 @@ _mesa_init_driver_functions(struct dd_function_table *driver)
driver->UnmapTextureImage = _swrast_unmap_teximage;
driver->MapTexture = NULL;
driver->UnmapTexture = NULL;
- driver->TextureMemCpy = memcpy;
- driver->IsTextureResident = NULL;
driver->DrawTex = _mesa_meta_DrawTex;
/* Vertex/fragment programs */
@@ -180,9 +180,9 @@ _mesa_init_driver_functions(struct dd_function_table *driver)
_mesa_init_sync_object_functions(driver);
driver->NewFramebuffer = _mesa_new_framebuffer;
- driver->NewRenderbuffer = _mesa_new_soft_renderbuffer;
- driver->MapRenderbuffer = _mesa_map_soft_renderbuffer;
- driver->UnmapRenderbuffer = _mesa_unmap_soft_renderbuffer;
+ driver->NewRenderbuffer = _swrast_new_soft_renderbuffer;
+ driver->MapRenderbuffer = _swrast_map_soft_renderbuffer;
+ driver->UnmapRenderbuffer = _swrast_unmap_soft_renderbuffer;
driver->RenderTexture = _swrast_render_texture;
driver->FinishRenderTexture = _swrast_finish_render_texture;
driver->FramebufferRenderbuffer = _mesa_framebuffer_renderbuffer;
diff --git a/mesalib/src/mesa/drivers/dri/swrast/swrast.c b/mesalib/src/mesa/drivers/dri/swrast/swrast.c
index f4c656d01..b31700d10 100644
--- a/mesalib/src/mesa/drivers/dri/swrast/swrast.c
+++ b/mesalib/src/mesa/drivers/dri/swrast/swrast.c
@@ -43,6 +43,7 @@
#include "main/imports.h"
#include "main/renderbuffer.h"
#include "swrast/swrast.h"
+#include "swrast/s_renderbuffer.h"
#include "swrast_setup/swrast_setup.h"
#include "tnl/tnl.h"
#include "tnl/t_context.h"
@@ -495,13 +496,13 @@ dri_create_buffer(__DRIscreen * sPriv,
}
/* add software renderbuffers */
- _mesa_add_soft_renderbuffers(fb,
- GL_FALSE, /* color */
- visual->haveDepthBuffer,
- visual->haveStencilBuffer,
- visual->haveAccumBuffer,
- GL_FALSE, /* alpha */
- GL_FALSE /* aux bufs */);
+ _swrast_add_soft_renderbuffers(fb,
+ GL_FALSE, /* color */
+ visual->haveDepthBuffer,
+ visual->haveStencilBuffer,
+ visual->haveAccumBuffer,
+ GL_FALSE, /* alpha */
+ GL_FALSE /* aux bufs */);
return GL_TRUE;
diff --git a/mesalib/src/mesa/drivers/windows/gdi/wmesa.c b/mesalib/src/mesa/drivers/windows/gdi/wmesa.c
index 14d15ed6c..675ffdaaa 100644
--- a/mesalib/src/mesa/drivers/windows/gdi/wmesa.c
+++ b/mesalib/src/mesa/drivers/windows/gdi/wmesa.c
@@ -16,6 +16,7 @@
#include "drivers/common/meta.h"
#include "vbo/vbo.h"
#include "swrast/swrast.h"
+#include "swrast/s_renderbuffer.h"
#include "swrast_setup/swrast_setup.h"
#include "tnl/tnl.h"
#include "tnl/t_context.h"
@@ -1610,13 +1611,13 @@ void WMesaMakeCurrent(WMesaContext c, HDC hdc)
wmesa_set_renderbuffer_funcs(rb, pwfb->pixelformat, pwfb->cColorBits, 0);
/* Let Mesa own the Depth, Stencil, and Accum buffers */
- _mesa_add_soft_renderbuffers(&pwfb->Base,
- GL_FALSE, /* color */
- visual->depthBits > 0,
- visual->stencilBits > 0,
- visual->accumRedBits > 0,
- visual->alphaBits >0,
- GL_FALSE);
+ _swrast_add_soft_renderbuffers(&pwfb->Base,
+ GL_FALSE, /* color */
+ visual->depthBits > 0,
+ visual->stencilBits > 0,
+ visual->accumRedBits > 0,
+ visual->alphaBits >0,
+ GL_FALSE);
}
if (c && pwfb)
diff --git a/mesalib/src/mesa/main/accum.c b/mesalib/src/mesa/main/accum.c
index d7ed3a849..eb06bbb6e 100644
--- a/mesalib/src/mesa/main/accum.c
+++ b/mesalib/src/mesa/main/accum.c
@@ -24,7 +24,10 @@
#include "glheader.h"
#include "accum.h"
+#include "condrender.h"
#include "context.h"
+#include "format_unpack.h"
+#include "format_pack.h"
#include "imports.h"
#include "macros.h"
#include "mfeatures.h"
@@ -101,7 +104,7 @@ _mesa_Accum( GLenum op, GLfloat value )
return;
if (ctx->RenderMode == GL_RENDER) {
- ctx->Driver.Accum(ctx, op, value);
+ _mesa_accum(ctx, op, value);
}
}
@@ -123,3 +126,384 @@ _mesa_init_accum( struct gl_context *ctx )
/* Accumulate buffer group */
ASSIGN_4V( ctx->Accum.ClearColor, 0.0, 0.0, 0.0, 0.0 );
}
+
+
+
+
+/**
+ * Clear the accumulation buffer by mapping the renderbuffer and
+ * writing the clear color to it. Called by the driver's implementation
+ * of the glClear function.
+ */
+void
+_mesa_clear_accum_buffer(struct gl_context *ctx)
+{
+ GLuint x, y, width, height;
+ GLubyte *accMap;
+ GLint accRowStride;
+ struct gl_renderbuffer *accRb;
+
+ if (!ctx->DrawBuffer)
+ return;
+
+ accRb = ctx->DrawBuffer->Attachment[BUFFER_ACCUM].Renderbuffer;
+ if (!accRb)
+ return; /* missing accum buffer, not an error */
+
+ /* bounds, with scissor */
+ x = ctx->DrawBuffer->_Xmin;
+ y = ctx->DrawBuffer->_Ymin;
+ width = ctx->DrawBuffer->_Xmax - ctx->DrawBuffer->_Xmin;
+ height = ctx->DrawBuffer->_Ymax - ctx->DrawBuffer->_Ymin;
+
+ ctx->Driver.MapRenderbuffer(ctx, accRb, x, y, width, height,
+ GL_MAP_WRITE_BIT, &accMap, &accRowStride);
+
+ if (!accMap) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glAccum");
+ return;
+ }
+
+ if (accRb->Format == MESA_FORMAT_SIGNED_RGBA_16) {
+ const GLshort clearR = FLOAT_TO_SHORT(ctx->Accum.ClearColor[0]);
+ const GLshort clearG = FLOAT_TO_SHORT(ctx->Accum.ClearColor[1]);
+ const GLshort clearB = FLOAT_TO_SHORT(ctx->Accum.ClearColor[2]);
+ const GLshort clearA = FLOAT_TO_SHORT(ctx->Accum.ClearColor[3]);
+ GLuint i, j;
+
+ for (j = 0; j < height; j++) {
+ GLshort *row = (GLshort *) accMap;
+
+ for (i = 0; i < width; i++) {
+ row[i * 4 + 0] = clearR;
+ row[i * 4 + 1] = clearG;
+ row[i * 4 + 2] = clearB;
+ row[i * 4 + 3] = clearA;
+ }
+ accMap += accRowStride;
+ }
+ }
+ else {
+ /* other types someday? */
+ _mesa_warning(ctx, "unexpected accum buffer type");
+ }
+
+ ctx->Driver.UnmapRenderbuffer(ctx, accRb);
+}
+
+
+/**
+ * if (bias)
+ * Accum += value
+ * else
+ * Accum *= value
+ */
+static void
+accum_scale_or_bias(struct gl_context *ctx, GLfloat value,
+ GLint xpos, GLint ypos, GLint width, GLint height,
+ GLboolean bias)
+{
+ struct gl_renderbuffer *accRb =
+ ctx->DrawBuffer->Attachment[BUFFER_ACCUM].Renderbuffer;
+ GLubyte *accMap;
+ GLint accRowStride;
+
+ assert(accRb);
+
+ ctx->Driver.MapRenderbuffer(ctx, accRb, xpos, ypos, width, height,
+ GL_MAP_READ_BIT | GL_MAP_WRITE_BIT,
+ &accMap, &accRowStride);
+
+ if (!accMap) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glAccum");
+ return;
+ }
+
+ if (accRb->Format == MESA_FORMAT_SIGNED_RGBA_16) {
+ const GLshort incr = (GLshort) (value * 32767.0f);
+ GLuint i, j;
+ if (bias) {
+ for (j = 0; j < height; j++) {
+ GLshort *acc = (GLshort *) accMap;
+ for (i = 0; i < 4 * width; i++) {
+ acc[i] += incr;
+ }
+ accMap += accRowStride;
+ }
+ }
+ else {
+ /* scale */
+ for (j = 0; j < height; j++) {
+ GLshort *acc = (GLshort *) accMap;
+ for (i = 0; i < 4 * width; i++) {
+ acc[i] = (GLshort) (acc[i] * value);
+ }
+ accMap += accRowStride;
+ }
+ }
+ }
+ else {
+ /* other types someday? */
+ }
+
+ ctx->Driver.UnmapRenderbuffer(ctx, accRb);
+}
+
+
+/**
+ * if (load)
+ * Accum = ColorBuf * value
+ * else
+ * Accum += ColorBuf * value
+ */
+static void
+accum_or_load(struct gl_context *ctx, GLfloat value,
+ GLint xpos, GLint ypos, GLint width, GLint height,
+ GLboolean load)
+{
+ struct gl_renderbuffer *accRb =
+ ctx->DrawBuffer->Attachment[BUFFER_ACCUM].Renderbuffer;
+ struct gl_renderbuffer *colorRb = ctx->ReadBuffer->_ColorReadBuffer;
+ GLubyte *accMap, *colorMap;
+ GLint accRowStride, colorRowStride;
+ GLbitfield mappingFlags;
+
+ if (!colorRb) {
+ /* no read buffer - OK */
+ return;
+ }
+
+ assert(accRb);
+
+ mappingFlags = GL_MAP_WRITE_BIT;
+ if (!load) /* if we're accumulating */
+ mappingFlags |= GL_MAP_READ_BIT;
+
+ /* Map accum buffer */
+ ctx->Driver.MapRenderbuffer(ctx, accRb, xpos, ypos, width, height,
+ mappingFlags, &accMap, &accRowStride);
+ if (!accMap) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glAccum");
+ return;
+ }
+
+ /* Map color buffer */
+ ctx->Driver.MapRenderbuffer(ctx, colorRb, xpos, ypos, width, height,
+ GL_MAP_READ_BIT,
+ &colorMap, &colorRowStride);
+ if (!colorMap) {
+ ctx->Driver.UnmapRenderbuffer(ctx, accRb);
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glAccum");
+ return;
+ }
+
+ if (accRb->Format == MESA_FORMAT_SIGNED_RGBA_16) {
+ const GLfloat scale = value * 32767.0f;
+ GLuint i, j;
+ GLfloat (*rgba)[4];
+
+ rgba = (GLfloat (*)[4]) malloc(width * 4 * sizeof(GLfloat));
+ if (rgba) {
+ for (j = 0; j < height; j++) {
+ GLshort *acc = (GLshort *) accMap;
+
+ /* read colors from source color buffer */
+ _mesa_unpack_rgba_row(colorRb->Format, width, colorMap, rgba);
+
+ if (load) {
+ for (i = 0; i < width; i++) {
+ acc[i * 4 + 0] = (GLshort) (rgba[i][RCOMP] * scale);
+ acc[i * 4 + 1] = (GLshort) (rgba[i][GCOMP] * scale);
+ acc[i * 4 + 2] = (GLshort) (rgba[i][BCOMP] * scale);
+ acc[i * 4 + 3] = (GLshort) (rgba[i][ACOMP] * scale);
+ }
+ }
+ else {
+ /* accumulate */
+ for (i = 0; i < width; i++) {
+ acc[i * 4 + 0] += (GLshort) (rgba[i][RCOMP] * scale);
+ acc[i * 4 + 1] += (GLshort) (rgba[i][GCOMP] * scale);
+ acc[i * 4 + 2] += (GLshort) (rgba[i][BCOMP] * scale);
+ acc[i * 4 + 3] += (GLshort) (rgba[i][ACOMP] * scale);
+ }
+ }
+
+ colorMap += colorRowStride;
+ accMap += accRowStride;
+ }
+
+ free(rgba);
+ }
+ else {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glAccum");
+ }
+ }
+ else {
+ /* other types someday? */
+ }
+
+ ctx->Driver.UnmapRenderbuffer(ctx, accRb);
+ ctx->Driver.UnmapRenderbuffer(ctx, colorRb);
+}
+
+
+/**
+ * ColorBuffer = Accum * value
+ */
+static void
+accum_return(struct gl_context *ctx, GLfloat value,
+ GLint xpos, GLint ypos, GLint width, GLint height)
+{
+ struct gl_framebuffer *fb = ctx->DrawBuffer;
+ struct gl_renderbuffer *accRb = fb->Attachment[BUFFER_ACCUM].Renderbuffer;
+ GLubyte *accMap, *colorMap;
+ GLint accRowStride, colorRowStride;
+ GLuint buffer;
+
+ /* Map accum buffer */
+ ctx->Driver.MapRenderbuffer(ctx, accRb, xpos, ypos, width, height,
+ GL_MAP_READ_BIT,
+ &accMap, &accRowStride);
+ if (!accMap) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glAccum");
+ return;
+ }
+
+ /* Loop over destination buffers */
+ for (buffer = 0; buffer < fb->_NumColorDrawBuffers; buffer++) {
+ struct gl_renderbuffer *colorRb = fb->_ColorDrawBuffers[buffer];
+ const GLboolean masking = (!ctx->Color.ColorMask[buffer][RCOMP] ||
+ !ctx->Color.ColorMask[buffer][GCOMP] ||
+ !ctx->Color.ColorMask[buffer][BCOMP] ||
+ !ctx->Color.ColorMask[buffer][ACOMP]);
+ GLbitfield mappingFlags = GL_MAP_WRITE_BIT;
+
+ if (masking)
+ mappingFlags |= GL_MAP_READ_BIT;
+
+ /* Map color buffer */
+ ctx->Driver.MapRenderbuffer(ctx, colorRb, xpos, ypos, width, height,
+ mappingFlags, &colorMap, &colorRowStride);
+ if (!colorMap) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glAccum");
+ continue;
+ }
+
+ if (accRb->Format == MESA_FORMAT_SIGNED_RGBA_16) {
+ const GLfloat scale = value / 32767.0f;
+ GLint i, j;
+ GLfloat (*rgba)[4], (*dest)[4];
+
+ rgba = (GLfloat (*)[4]) malloc(width * 4 * sizeof(GLfloat));
+ dest = (GLfloat (*)[4]) malloc(width * 4 * sizeof(GLfloat));
+
+ if (rgba && dest) {
+ for (j = 0; j < height; j++) {
+ GLshort *acc = (GLshort *) accMap;
+
+ for (i = 0; i < width; i++) {
+ rgba[i][0] = acc[i * 4 + 0] * scale;
+ rgba[i][1] = acc[i * 4 + 1] * scale;
+ rgba[i][2] = acc[i * 4 + 2] * scale;
+ rgba[i][3] = acc[i * 4 + 3] * scale;
+ }
+
+ if (masking) {
+
+ /* get existing colors from dest buffer */
+ _mesa_unpack_rgba_row(colorRb->Format, width, colorMap, dest);
+
+ /* use the dest colors where mask[channel] = 0 */
+ if (ctx->Color.ColorMask[buffer][RCOMP] == 0) {
+ for (i = 0; i < width; i++)
+ rgba[i][RCOMP] = dest[i][RCOMP];
+ }
+ if (ctx->Color.ColorMask[buffer][GCOMP] == 0) {
+ for (i = 0; i < width; i++)
+ rgba[i][GCOMP] = dest[i][GCOMP];
+ }
+ if (ctx->Color.ColorMask[buffer][BCOMP] == 0) {
+ for (i = 0; i < width; i++)
+ rgba[i][BCOMP] = dest[i][BCOMP];
+ }
+ if (ctx->Color.ColorMask[buffer][ACOMP] == 0) {
+ for (i = 0; i < width; i++)
+ rgba[i][ACOMP] = dest[i][ACOMP];
+ }
+ }
+
+ _mesa_pack_float_rgba_row(colorRb->Format, width,
+ (const GLfloat (*)[4]) rgba, colorMap);
+
+ accMap += accRowStride;
+ colorMap += colorRowStride;
+ }
+ }
+ else {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glAccum");
+ }
+ free(rgba);
+ free(dest);
+ }
+ else {
+ /* other types someday? */
+ }
+
+ ctx->Driver.UnmapRenderbuffer(ctx, colorRb);
+ }
+
+ ctx->Driver.UnmapRenderbuffer(ctx, accRb);
+}
+
+
+
+/**
+ * Software fallback for glAccum. A hardware driver that supports
+ * signed 16-bit color channels could implement hardware accumulation
+ * operations, but no driver does so at this time.
+ */
+void
+_mesa_accum(struct gl_context *ctx, GLenum op, GLfloat value)
+{
+ GLint xpos, ypos, width, height;
+
+ if (!ctx->DrawBuffer->Attachment[BUFFER_ACCUM].Renderbuffer) {
+ _mesa_warning(ctx, "Calling glAccum() without an accumulation buffer");
+ return;
+ }
+
+ if (!_mesa_check_conditional_render(ctx))
+ return;
+
+ xpos = ctx->DrawBuffer->_Xmin;
+ ypos = ctx->DrawBuffer->_Ymin;
+ width = ctx->DrawBuffer->_Xmax - ctx->DrawBuffer->_Xmin;
+ height = ctx->DrawBuffer->_Ymax - ctx->DrawBuffer->_Ymin;
+
+ switch (op) {
+ case GL_ADD:
+ if (value != 0.0F) {
+ accum_scale_or_bias(ctx, value, xpos, ypos, width, height, GL_TRUE);
+ }
+ break;
+ case GL_MULT:
+ if (value != 1.0F) {
+ accum_scale_or_bias(ctx, value, xpos, ypos, width, height, GL_FALSE);
+ }
+ break;
+ case GL_ACCUM:
+ if (value != 0.0F) {
+ accum_or_load(ctx, value, xpos, ypos, width, height, GL_FALSE);
+ }
+ break;
+ case GL_LOAD:
+ accum_or_load(ctx, value, xpos, ypos, width, height, GL_TRUE);
+ break;
+ case GL_RETURN:
+ accum_return(ctx, value, xpos, ypos, width, height);
+ break;
+ default:
+ _mesa_problem(ctx, "invalid mode in _mesa_accum()");
+ break;
+ }
+}
diff --git a/mesalib/src/mesa/main/accum.h b/mesalib/src/mesa/main/accum.h
index f16378cc1..5b3f06aa9 100644
--- a/mesalib/src/mesa/main/accum.h
+++ b/mesalib/src/mesa/main/accum.h
@@ -42,6 +42,7 @@
struct _glapi_table;
struct gl_context;
+struct gl_renderbuffer;
#if FEATURE_accum
@@ -51,6 +52,12 @@ _mesa_ClearAccum( GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha );
extern void
_mesa_init_accum_dispatch(struct _glapi_table *disp);
+extern void
+_mesa_accum(struct gl_context *ctx, GLenum op, GLfloat value);
+
+extern void
+_mesa_clear_accum_buffer(struct gl_context *ctx);
+
#else /* FEATURE_accum */
#include "main/compiler.h"
@@ -67,6 +74,17 @@ _mesa_init_accum_dispatch(struct _glapi_table *disp)
{
}
+static inline void
+_mesa_accum(struct gl_context *ctx, GLenum op, GLfloat value)
+{
+}
+
+static inline void
+_mesa_clear_accum_buffer(struct gl_context *ctx)
+{
+}
+
+
#endif /* FEATURE_accum */
extern void
diff --git a/mesalib/src/mesa/main/dd.h b/mesalib/src/mesa/main/dd.h
index 9842540da..d6f70d1c4 100644
--- a/mesalib/src/mesa/main/dd.h
+++ b/mesalib/src/mesa/main/dd.h
@@ -532,24 +532,6 @@ struct dd_function_table {
void (*UnmapRenderbuffer)(struct gl_context *ctx,
struct gl_renderbuffer *rb);
- /**
- * Note: no context argument. This function doesn't initially look
- * like it belongs here, except that the driver is the only entity
- * that knows for sure how the texture memory is allocated - via
- * the above callbacks. There is then an argument that the driver
- * knows what memcpy paths might be fast. Typically this is invoked with
- *
- * to -- a pointer into texture memory allocated by NewTextureImage() above.
- * from -- a pointer into client memory or a mesa temporary.
- * sz -- nr bytes to copy.
- */
- void* (*TextureMemCpy)( void *to, const void *from, size_t sz );
-
- /**
- * Called by glAreTextureResident().
- */
- GLboolean (*IsTextureResident)( struct gl_context *ctx,
- struct gl_texture_object *t );
/*@}*/
diff --git a/mesalib/src/mesa/main/depthstencil.c b/mesalib/src/mesa/main/depthstencil.c
index 40d6c9612..af5c12f67 100644
--- a/mesalib/src/mesa/main/depthstencil.c
+++ b/mesalib/src/mesa/main/depthstencil.c
@@ -957,158 +957,3 @@ _mesa_new_s8_renderbuffer_wrapper(struct gl_context *ctx, struct gl_renderbuffer
return s8rb;
}
-
-
-
-/**
- ** The following functions are useful for hardware drivers that only
- ** implement combined depth/stencil buffers.
- ** The GL_EXT_framebuffer_object extension allows indepedent depth and
- ** stencil buffers to be used in any combination.
- ** Therefore, we sometimes have to merge separate depth and stencil
- ** renderbuffers into a single depth+stencil renderbuffer. And sometimes
- ** we have to split combined depth+stencil renderbuffers into separate
- ** renderbuffers.
- **/
-
-
-/**
- * Extract stencil values from the combined depth/stencil renderbuffer, storing
- * the values into a separate stencil renderbuffer.
- * \param dsRb the source depth/stencil renderbuffer
- * \param stencilRb the destination stencil renderbuffer
- * (either 8-bit or 32-bit)
- */
-void
-_mesa_extract_stencil(struct gl_context *ctx,
- struct gl_renderbuffer *dsRb,
- struct gl_renderbuffer *stencilRb)
-{
- GLuint row, width, height;
-
- ASSERT(dsRb);
- ASSERT(stencilRb);
-
- ASSERT(dsRb->Format == MESA_FORMAT_Z24_S8);
- ASSERT(dsRb->DataType == GL_UNSIGNED_INT_24_8_EXT);
- ASSERT(stencilRb->Format == MESA_FORMAT_Z24_S8 ||
- stencilRb->Format == MESA_FORMAT_S8);
- ASSERT(dsRb->Width == stencilRb->Width);
- ASSERT(dsRb->Height == stencilRb->Height);
-
- width = dsRb->Width;
- height = dsRb->Height;
-
- for (row = 0; row < height; row++) {
- GLuint depthStencil[MAX_WIDTH];
- dsRb->GetRow(ctx, dsRb, width, 0, row, depthStencil);
- if (stencilRb->Format == MESA_FORMAT_S8) {
- /* 8bpp stencil */
- GLubyte stencil[MAX_WIDTH];
- GLuint i;
- for (i = 0; i < width; i++) {
- stencil[i] = depthStencil[i] & 0xff;
- }
- stencilRb->PutRow(ctx, stencilRb, width, 0, row, stencil, NULL);
- }
- else {
- /* 32bpp stencil */
- /* the 24 depth bits will be ignored */
- ASSERT(stencilRb->Format == MESA_FORMAT_Z24_S8);
- ASSERT(stencilRb->DataType == GL_UNSIGNED_INT_24_8_EXT);
- stencilRb->PutRow(ctx, stencilRb, width, 0, row, depthStencil, NULL);
- }
- }
-}
-
-
-/**
- * Copy stencil values from a stencil renderbuffer into a combined
- * depth/stencil renderbuffer.
- * \param dsRb the destination depth/stencil renderbuffer
- * \param stencilRb the source stencil buffer (either 8-bit or 32-bit)
- */
-void
-_mesa_insert_stencil(struct gl_context *ctx,
- struct gl_renderbuffer *dsRb,
- struct gl_renderbuffer *stencilRb)
-{
- GLuint row, width, height;
-
- ASSERT(dsRb);
- ASSERT(stencilRb);
-
- ASSERT(dsRb->Format == MESA_FORMAT_Z24_S8);
- ASSERT(dsRb->DataType == GL_UNSIGNED_INT_24_8_EXT);
- ASSERT(stencilRb->Format == MESA_FORMAT_Z24_S8 ||
- stencilRb->Format == MESA_FORMAT_S8);
-
- ASSERT(dsRb->Width == stencilRb->Width);
- ASSERT(dsRb->Height == stencilRb->Height);
-
- width = dsRb->Width;
- height = dsRb->Height;
-
- for (row = 0; row < height; row++) {
- GLuint depthStencil[MAX_WIDTH];
-
- dsRb->GetRow(ctx, dsRb, width, 0, row, depthStencil);
-
- if (stencilRb->Format == MESA_FORMAT_S8) {
- /* 8bpp stencil */
- GLubyte stencil[MAX_WIDTH];
- GLuint i;
- stencilRb->GetRow(ctx, stencilRb, width, 0, row, stencil);
- for (i = 0; i < width; i++) {
- depthStencil[i] = (depthStencil[i] & 0xffffff00) | stencil[i];
- }
- }
- else {
- /* 32bpp stencil buffer */
- GLuint stencil[MAX_WIDTH], i;
- ASSERT(stencilRb->Format == MESA_FORMAT_Z24_S8);
- ASSERT(stencilRb->DataType == GL_UNSIGNED_INT_24_8_EXT);
- stencilRb->GetRow(ctx, stencilRb, width, 0, row, stencil);
- for (i = 0; i < width; i++) {
- depthStencil[i]
- = (depthStencil[i] & 0xffffff00) | (stencil[i] & 0xff);
- }
- }
-
- dsRb->PutRow(ctx, dsRb, width, 0, row, depthStencil, NULL);
- }
-}
-
-
-/**
- * Convert the stencil buffer from 8bpp to 32bpp depth/stencil.
- * \param stencilRb the stencil renderbuffer to promote
- */
-void
-_mesa_promote_stencil(struct gl_context *ctx, struct gl_renderbuffer *stencilRb)
-{
- const GLsizei width = stencilRb->Width;
- const GLsizei height = stencilRb->Height;
- GLubyte *data;
- GLint i, j, k;
-
- ASSERT(stencilRb->Format == MESA_FORMAT_S8);
- ASSERT(stencilRb->Data);
-
- data = (GLubyte *) stencilRb->Data;
- stencilRb->Data = NULL;
- stencilRb->AllocStorage(ctx, stencilRb, GL_DEPTH24_STENCIL8_EXT,
- width, height);
-
- ASSERT(stencilRb->DataType == GL_UNSIGNED_INT_24_8_EXT);
-
- k = 0;
- for (i = 0; i < height; i++) {
- GLuint depthStencil[MAX_WIDTH];
- for (j = 0; j < width; j++) {
- depthStencil[j] = data[k++];
- }
- stencilRb->PutRow(ctx, stencilRb, width, 0, i, depthStencil, NULL);
- }
- free(data);
-}
diff --git a/mesalib/src/mesa/main/depthstencil.h b/mesalib/src/mesa/main/depthstencil.h
index b47a2e482..c3871d805 100644
--- a/mesalib/src/mesa/main/depthstencil.h
+++ b/mesalib/src/mesa/main/depthstencil.h
@@ -43,20 +43,4 @@ _mesa_new_s8_renderbuffer_wrapper(struct gl_context *ctx,
struct gl_renderbuffer *dsrb);
-extern void
-_mesa_extract_stencil(struct gl_context *ctx,
- struct gl_renderbuffer *dsRb,
- struct gl_renderbuffer *stencilRb);
-
-
-extern void
-_mesa_insert_stencil(struct gl_context *ctx,
- struct gl_renderbuffer *dsRb,
- struct gl_renderbuffer *stencilRb);
-
-
-extern void
-_mesa_promote_stencil(struct gl_context *ctx, struct gl_renderbuffer *stencilRb);
-
-
#endif /* DEPTHSTENCIL_H */
diff --git a/mesalib/src/mesa/main/format_pack.c b/mesalib/src/mesa/main/format_pack.c
new file mode 100644
index 000000000..390b494c0
--- /dev/null
+++ b/mesalib/src/mesa/main/format_pack.c
@@ -0,0 +1,2496 @@
+/*
+ * Mesa 3-D graphics library
+ *
+ * Copyright (c) 2011 VMware, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+
+/**
+ * Color, depth, stencil packing functions.
+ * Used to pack basic color, depth and stencil formats to specific
+ * hardware formats.
+ *
+ * There are both per-pixel and per-row packing functions:
+ * - The former will be used by swrast to write values to the color, depth,
+ * stencil buffers when drawing points, lines and masked spans.
+ * - The later will be used for image-oriented functions like glDrawPixels,
+ * glAccum, and glTexImage.
+ */
+
+
+#include "colormac.h"
+#include "format_pack.h"
+#include "macros.h"
+#include "../../gallium/auxiliary/util/u_format_rgb9e5.h"
+#include "../../gallium/auxiliary/util/u_format_r11g11b10f.h"
+
+
+typedef void (*pack_ubyte_rgba_row_func)(GLuint n,
+ const GLubyte src[][4], void *dst);
+
+typedef void (*pack_float_rgba_row_func)(GLuint n,
+ const GLfloat src[][4], void *dst);
+
+
+
+static inline GLfloat
+linear_to_srgb(GLfloat cl)
+{
+ if (cl < 0.0f)
+ return 0.0f;
+ else if (cl < 0.0031308f)
+ return 12.92f * cl;
+ else if (cl < 1.0f)
+ return 1.055f * powf(cl, 0.41666f) - 0.055f;
+ else
+ return 1.0f;
+}
+
+
+static inline GLubyte
+linear_float_to_srgb_ubyte(GLfloat cl)
+{
+ GLubyte res = FLOAT_TO_UBYTE(linear_to_srgb(cl));
+ return res;
+}
+
+
+static inline GLubyte
+linear_ubyte_to_srgb_ubyte(GLubyte cl)
+{
+ GLubyte res = FLOAT_TO_UBYTE(linear_to_srgb(cl / 255.0f));
+ return res;
+}
+
+
+
+
+/*
+ * MESA_FORMAT_RGBA8888
+ */
+
+static void
+pack_ubyte_RGBA8888(const GLubyte src[4], void *dst)
+{
+ GLuint *d = ((GLuint *) dst);
+ *d = PACK_COLOR_8888(src[RCOMP], src[GCOMP], src[BCOMP], src[ACOMP]);
+}
+
+static void
+pack_float_RGBA8888(const GLfloat src[4], void *dst)
+{
+ GLubyte v[4];
+ _mesa_unclamped_float_rgba_to_ubyte(v, src);
+ pack_ubyte_RGBA8888(v, dst);
+}
+
+static void
+pack_row_ubyte_RGBA8888(GLuint n, const GLubyte src[][4], void *dst)
+{
+ GLuint *d = ((GLuint *) dst);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ d[i] = PACK_COLOR_8888(src[i][RCOMP], src[i][GCOMP],
+ src[i][BCOMP], src[i][ACOMP]);
+ }
+}
+
+static void
+pack_row_float_RGBA8888(GLuint n, const GLfloat src[][4], void *dst)
+{
+ GLuint *d = ((GLuint *) dst);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ GLubyte v[4];
+ _mesa_unclamped_float_rgba_to_ubyte(v, src[i]);
+ pack_ubyte_RGBA8888(v, d + i);
+ }
+}
+
+
+
+/*
+ * MESA_FORMAT_RGBA8888_REV
+ */
+
+static void
+pack_ubyte_RGBA8888_REV(const GLubyte src[4], void *dst)
+{
+ GLuint *d = ((GLuint *) dst);
+ *d = PACK_COLOR_8888(src[ACOMP], src[BCOMP], src[GCOMP], src[RCOMP]);
+}
+
+static void
+pack_float_RGBA8888_REV(const GLfloat src[4], void *dst)
+{
+ GLubyte v[4];
+ _mesa_unclamped_float_rgba_to_ubyte(v, src);
+ pack_ubyte_RGBA8888_REV(v, dst);
+}
+
+static void
+pack_row_ubyte_RGBA8888_REV(GLuint n, const GLubyte src[][4], void *dst)
+{
+ GLuint *d = ((GLuint *) dst);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ d[i] = PACK_COLOR_8888(src[i][ACOMP], src[i][BCOMP],
+ src[i][GCOMP], src[i][RCOMP]);
+ }
+}
+
+static void
+pack_row_float_RGBA8888_REV(GLuint n, const GLfloat src[][4], void *dst)
+{
+ GLuint *d = ((GLuint *) dst);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ GLubyte v[4];
+ _mesa_unclamped_float_rgba_to_ubyte(v, src[i]);
+ pack_ubyte_RGBA8888_REV(v, d + i);
+ }
+}
+
+
+/*
+ * MESA_FORMAT_ARGB8888
+ */
+
+static void
+pack_ubyte_ARGB8888(const GLubyte src[4], void *dst)
+{
+ GLuint *d = ((GLuint *) dst);
+ *d = PACK_COLOR_8888(src[ACOMP], src[RCOMP], src[GCOMP], src[BCOMP]);
+}
+
+static void
+pack_float_ARGB8888(const GLfloat src[4], void *dst)
+{
+ GLubyte v[4];
+ _mesa_unclamped_float_rgba_to_ubyte(v, src);
+ pack_ubyte_ARGB8888(v, dst);
+}
+
+static void
+pack_row_ubyte_ARGB8888(GLuint n, const GLubyte src[][4], void *dst)
+{
+ GLuint *d = ((GLuint *) dst);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ d[i] = PACK_COLOR_8888(src[i][ACOMP], src[i][RCOMP],
+ src[i][GCOMP], src[i][BCOMP]);
+ }
+}
+
+static void
+pack_row_float_ARGB8888(GLuint n, const GLfloat src[][4], void *dst)
+{
+ GLuint *d = ((GLuint *) dst);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ GLubyte v[4];
+ _mesa_unclamped_float_rgba_to_ubyte(v, src[i]);
+ pack_ubyte_ARGB8888(v, d + i);
+ }
+}
+
+
+/*
+ * MESA_FORMAT_ARGB8888_REV
+ */
+
+static void
+pack_ubyte_ARGB8888_REV(const GLubyte src[4], void *dst)
+{
+ GLuint *d = ((GLuint *) dst);
+ *d = PACK_COLOR_8888(src[BCOMP], src[GCOMP], src[RCOMP], src[ACOMP]);
+}
+
+static void
+pack_float_ARGB8888_REV(const GLfloat src[4], void *dst)
+{
+ GLubyte v[4];
+ _mesa_unclamped_float_rgba_to_ubyte(v, src);
+ pack_ubyte_ARGB8888_REV(v, dst);
+}
+
+static void
+pack_row_ubyte_ARGB8888_REV(GLuint n, const GLubyte src[][4], void *dst)
+{
+ GLuint *d = ((GLuint *) dst);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ d[i] = PACK_COLOR_8888(src[i][BCOMP], src[i][GCOMP],
+ src[i][RCOMP], src[i][ACOMP]);
+ }
+}
+
+static void
+pack_row_float_ARGB8888_REV(GLuint n, const GLfloat src[][4], void *dst)
+{
+ GLuint *d = ((GLuint *) dst);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ GLubyte v[4];
+ _mesa_unclamped_float_rgba_to_ubyte(v, src[i]);
+ pack_ubyte_ARGB8888_REV(v, d + i);
+ }
+}
+
+
+/*
+ * MESA_FORMAT_XRGB8888
+ */
+
+static void
+pack_ubyte_XRGB8888(const GLubyte src[4], void *dst)
+{
+ GLuint *d = ((GLuint *) dst);
+ *d = PACK_COLOR_8888(0x0, src[RCOMP], src[GCOMP], src[BCOMP]);
+}
+
+static void
+pack_float_XRGB8888(const GLfloat src[4], void *dst)
+{
+ GLubyte v[4];
+ _mesa_unclamped_float_rgba_to_ubyte(v, src);
+ pack_ubyte_XRGB8888(v, dst);
+}
+
+static void
+pack_row_ubyte_XRGB8888(GLuint n, const GLubyte src[][4], void *dst)
+{
+ GLuint *d = ((GLuint *) dst);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ d[i] = PACK_COLOR_8888(0, src[i][RCOMP], src[i][GCOMP], src[i][BCOMP]);
+ }
+}
+
+static void
+pack_row_float_XRGB8888(GLuint n, const GLfloat src[][4], void *dst)
+{
+ GLuint *d = ((GLuint *) dst);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ GLubyte v[4];
+ _mesa_unclamped_float_rgba_to_ubyte(v, src[i]);
+ pack_ubyte_XRGB8888(v, d + i);
+ }
+}
+
+
+/*
+ * MESA_FORMAT_XRGB8888_REV
+ */
+
+static void
+pack_ubyte_XRGB8888_REV(const GLubyte src[4], void *dst)
+{
+ GLuint *d = ((GLuint *) dst);
+ *d = PACK_COLOR_8888(src[BCOMP], src[GCOMP], src[RCOMP], 0);
+}
+
+static void
+pack_float_XRGB8888_REV(const GLfloat src[4], void *dst)
+{
+ GLubyte v[4];
+ _mesa_unclamped_float_rgba_to_ubyte(v, src);
+ pack_ubyte_XRGB8888_REV(v, dst);
+}
+
+static void
+pack_row_ubyte_XRGB8888_REV(GLuint n, const GLubyte src[][4], void *dst)
+{
+ GLuint *d = ((GLuint *) dst);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ d[i] = PACK_COLOR_8888(src[i][BCOMP], src[i][GCOMP], src[i][RCOMP], 0);
+ }
+}
+
+static void
+pack_row_float_XRGB8888_REV(GLuint n, const GLfloat src[][4], void *dst)
+{
+ GLuint *d = ((GLuint *) dst);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ GLubyte v[4];
+ _mesa_unclamped_float_rgba_to_ubyte(v, src[i]);
+ pack_ubyte_XRGB8888_REV(v, d + i);
+ }
+}
+
+
+/*
+ * MESA_FORMAT_RGB888
+ */
+
+static void
+pack_ubyte_RGB888(const GLubyte src[4], void *dst)
+{
+ GLubyte *d = ((GLubyte *) dst);
+ d[2] = src[RCOMP];
+ d[1] = src[GCOMP];
+ d[0] = src[BCOMP];
+}
+
+static void
+pack_float_RGB888(const GLfloat src[4], void *dst)
+{
+ GLubyte *d = ((GLubyte *) dst);
+ UNCLAMPED_FLOAT_TO_UBYTE(d[2], src[RCOMP]);
+ UNCLAMPED_FLOAT_TO_UBYTE(d[1], src[GCOMP]);
+ UNCLAMPED_FLOAT_TO_UBYTE(d[0], src[BCOMP]);
+}
+
+static void
+pack_row_ubyte_RGB888(GLuint n, const GLubyte src[][4], void *dst)
+{
+ GLubyte *d = ((GLubyte *) dst);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ d[i*3+2] = src[i][RCOMP];
+ d[i*3+1] = src[i][GCOMP];
+ d[i*3+0] = src[i][BCOMP];
+ }
+}
+
+static void
+pack_row_float_RGB888(GLuint n, const GLfloat src[][4], void *dst)
+{
+ GLubyte *d = ((GLubyte *) dst);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ GLubyte v[4];
+ _mesa_unclamped_float_rgba_to_ubyte(v, src[i]);
+ d[i*3+2] = v[RCOMP];
+ d[i*3+1] = v[GCOMP];
+ d[i*3+0] = v[BCOMP];
+ }
+}
+
+
+/*
+ * MESA_FORMAT_BGR888
+ */
+
+static void
+pack_ubyte_BGR888(const GLubyte src[4], void *dst)
+{
+ GLubyte *d = ((GLubyte *) dst);
+ d[2] = src[BCOMP];
+ d[1] = src[GCOMP];
+ d[0] = src[RCOMP];
+}
+
+static void
+pack_float_BGR888(const GLfloat src[4], void *dst)
+{
+ GLubyte *d = ((GLubyte *) dst);
+ UNCLAMPED_FLOAT_TO_UBYTE(d[2], src[BCOMP]);
+ UNCLAMPED_FLOAT_TO_UBYTE(d[1], src[GCOMP]);
+ UNCLAMPED_FLOAT_TO_UBYTE(d[0], src[RCOMP]);
+}
+
+static void
+pack_row_ubyte_BGR888(GLuint n, const GLubyte src[][4], void *dst)
+{
+ GLubyte *d = ((GLubyte *) dst);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ d[i*3+2] = src[i][BCOMP];
+ d[i*3+1] = src[i][GCOMP];
+ d[i*3+0] = src[i][RCOMP];
+ }
+}
+
+static void
+pack_row_float_BGR888(GLuint n, const GLfloat src[][4], void *dst)
+{
+ GLubyte *d = ((GLubyte *) dst);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ GLubyte v[4];
+ _mesa_unclamped_float_rgba_to_ubyte(v, src[i]);
+ d[i*3+2] = v[BCOMP];
+ d[i*3+1] = v[GCOMP];
+ d[i*3+0] = v[RCOMP];
+ }
+}
+
+
+/*
+ * MESA_FORMAT_RGB565
+ */
+
+static void
+pack_ubyte_RGB565(const GLubyte src[4], void *dst)
+{
+ GLushort *d = ((GLushort *) dst);
+ *d = PACK_COLOR_565(src[RCOMP], src[GCOMP], src[BCOMP]);
+}
+
+static void
+pack_float_RGB565(const GLfloat src[4], void *dst)
+{
+ GLubyte v[3];
+ UNCLAMPED_FLOAT_TO_UBYTE(v[0], src[RCOMP]);
+ UNCLAMPED_FLOAT_TO_UBYTE(v[1], src[GCOMP]);
+ UNCLAMPED_FLOAT_TO_UBYTE(v[2], src[BCOMP]);
+ pack_ubyte_RGB565(v, dst);
+}
+
+static void
+pack_row_ubyte_RGB565(GLuint n, const GLubyte src[][4], void *dst)
+{
+ GLushort *d = ((GLushort *) dst);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ pack_ubyte_RGB565(src[i], d + i);
+ }
+}
+
+static void
+pack_row_float_RGB565(GLuint n, const GLfloat src[][4], void *dst)
+{
+ GLushort *d = ((GLushort *) dst);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ GLubyte v[4];
+ _mesa_unclamped_float_rgba_to_ubyte(v, src[i]);
+ pack_ubyte_RGB565(v, d + i);
+ }
+}
+
+
+/*
+ * MESA_FORMAT_RGB565_REV
+ */
+
+static void
+pack_ubyte_RGB565_REV(const GLubyte src[4], void *dst)
+{
+ GLushort *d = ((GLushort *) dst);
+ *d = PACK_COLOR_565_REV(src[RCOMP], src[GCOMP], src[BCOMP]);
+}
+
+static void
+pack_float_RGB565_REV(const GLfloat src[4], void *dst)
+{
+ GLushort *d = ((GLushort *) dst);
+ GLubyte r, g, b;
+ UNCLAMPED_FLOAT_TO_UBYTE(r, src[RCOMP]);
+ UNCLAMPED_FLOAT_TO_UBYTE(g, src[GCOMP]);
+ UNCLAMPED_FLOAT_TO_UBYTE(b, src[BCOMP]);
+ *d = PACK_COLOR_565_REV(r, g, b);
+}
+
+static void
+pack_row_ubyte_RGB565_REV(GLuint n, const GLubyte src[][4], void *dst)
+{
+ GLushort *d = ((GLushort *) dst);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ pack_ubyte_RGB565_REV(src[i], d + i);
+ }
+}
+
+static void
+pack_row_float_RGB565_REV(GLuint n, const GLfloat src[][4], void *dst)
+{
+ GLushort *d = ((GLushort *) dst);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ GLubyte v[4];
+ _mesa_unclamped_float_rgba_to_ubyte(v, src[i]);
+ pack_ubyte_RGB565_REV(v, d + i);
+ }
+}
+
+
+/*
+ * MESA_FORMAT_ARGB4444
+ */
+
+static void
+pack_ubyte_ARGB4444(const GLubyte src[4], void *dst)
+{
+ GLushort *d = ((GLushort *) dst);
+ *d = PACK_COLOR_4444(src[ACOMP], src[RCOMP], src[GCOMP], src[BCOMP]);
+}
+
+static void
+pack_float_ARGB4444(const GLfloat src[4], void *dst)
+{
+ GLubyte v[4];
+ _mesa_unclamped_float_rgba_to_ubyte(v, src);
+ pack_ubyte_ARGB4444(v, dst);
+}
+
+/* use fallback row packing functions */
+
+
+/*
+ * MESA_FORMAT_ARGB4444_REV
+ */
+
+static void
+pack_ubyte_ARGB4444_REV(const GLubyte src[4], void *dst)
+{
+ GLushort *d = ((GLushort *) dst);
+ *d = PACK_COLOR_4444(src[GCOMP], src[BCOMP], src[ACOMP], src[RCOMP]);
+}
+
+static void
+pack_float_ARGB4444_REV(const GLfloat src[4], void *dst)
+{
+ GLubyte v[4];
+ _mesa_unclamped_float_rgba_to_ubyte(v, src);
+ pack_ubyte_ARGB4444_REV(v, dst);
+}
+
+/* use fallback row packing functions */
+
+
+/*
+ * MESA_FORMAT_RGBA5551
+ */
+
+static void
+pack_ubyte_RGBA5551(const GLubyte src[4], void *dst)
+{
+ GLushort *d = ((GLushort *) dst);
+ *d = PACK_COLOR_5551(src[RCOMP], src[GCOMP], src[BCOMP], src[ACOMP]);
+}
+
+static void
+pack_float_RGBA5551(const GLfloat src[4], void *dst)
+{
+ GLubyte v[4];
+ _mesa_unclamped_float_rgba_to_ubyte(v, src);
+ pack_ubyte_RGBA5551(v, dst);
+}
+
+/* use fallback row packing functions */
+
+
+/*
+ * MESA_FORMAT_ARGB1555
+ */
+
+static void
+pack_ubyte_ARGB1555(const GLubyte src[4], void *dst)
+{
+ GLushort *d = ((GLushort *) dst);
+ *d = PACK_COLOR_1555(src[ACOMP], src[RCOMP], src[GCOMP], src[BCOMP]);
+}
+
+static void
+pack_float_ARGB1555(const GLfloat src[4], void *dst)
+{
+ GLubyte v[4];
+ _mesa_unclamped_float_rgba_to_ubyte(v, src);
+ pack_ubyte_ARGB1555(v, dst);
+}
+
+
+/* MESA_FORMAT_ARGB1555_REV */
+
+static void
+pack_ubyte_ARGB1555_REV(const GLubyte src[4], void *dst)
+{
+ GLushort *d = ((GLushort *) dst), tmp;
+ tmp = PACK_COLOR_1555(src[ACOMP], src[RCOMP], src[GCOMP], src[BCOMP]);
+ *d = (tmp >> 8) | (tmp << 8);
+}
+
+static void
+pack_float_ARGB1555_REV(const GLfloat src[4], void *dst)
+{
+ GLubyte v[4];
+ _mesa_unclamped_float_rgba_to_ubyte(v, src);
+ pack_ubyte_ARGB1555_REV(v, dst);
+}
+
+
+/* MESA_FORMAT_AL44 */
+
+static void
+pack_ubyte_AL44(const GLubyte src[4], void *dst)
+{
+ GLushort *d = ((GLushort *) dst);
+ *d = PACK_COLOR_44(src[ACOMP], src[RCOMP]);
+}
+
+static void
+pack_float_AL44(const GLfloat src[4], void *dst)
+{
+ GLubyte v[4];
+ UNCLAMPED_FLOAT_TO_UBYTE(v[0], src[RCOMP]);
+ UNCLAMPED_FLOAT_TO_UBYTE(v[3], src[ACOMP]);
+ pack_ubyte_AL44(v, dst);
+}
+
+
+/* MESA_FORMAT_AL88 */
+
+static void
+pack_ubyte_AL88(const GLubyte src[4], void *dst)
+{
+ GLushort *d = ((GLushort *) dst);
+ *d = PACK_COLOR_88(src[ACOMP], src[RCOMP]);
+}
+
+static void
+pack_float_AL88(const GLfloat src[4], void *dst)
+{
+ GLubyte v[4];
+ UNCLAMPED_FLOAT_TO_UBYTE(v[0], src[RCOMP]);
+ UNCLAMPED_FLOAT_TO_UBYTE(v[3], src[ACOMP]);
+ pack_ubyte_AL88(v, dst);
+}
+
+
+/* MESA_FORMAT_AL88_REV */
+
+static void
+pack_ubyte_AL88_REV(const GLubyte src[4], void *dst)
+{
+ GLushort *d = ((GLushort *) dst);
+ *d = PACK_COLOR_88(src[RCOMP], src[ACOMP]);
+}
+
+static void
+pack_float_AL88_REV(const GLfloat src[4], void *dst)
+{
+ GLubyte v[4];
+ UNCLAMPED_FLOAT_TO_UBYTE(v[0], src[RCOMP]);
+ UNCLAMPED_FLOAT_TO_UBYTE(v[3], src[ACOMP]);
+ pack_ubyte_AL88_REV(v, dst);
+}
+
+
+/* MESA_FORMAT_AL1616 */
+
+static void
+pack_ubyte_AL1616(const GLubyte src[4], void *dst)
+{
+ GLuint *d = ((GLuint *) dst);
+ GLushort l = UBYTE_TO_USHORT(src[RCOMP]);
+ GLushort a = UBYTE_TO_USHORT(src[ACOMP]);
+ *d = PACK_COLOR_1616(a, l);
+}
+
+static void
+pack_float_AL1616(const GLfloat src[4], void *dst)
+{
+ GLuint *d = ((GLuint *) dst);
+ GLushort l, a;
+ UNCLAMPED_FLOAT_TO_USHORT(l, src[RCOMP]);
+ UNCLAMPED_FLOAT_TO_USHORT(a, src[ACOMP]);
+ *d = PACK_COLOR_1616(a, l);
+}
+
+
+/* MESA_FORMAT_AL1616_REV */
+
+static void
+pack_ubyte_AL1616_REV(const GLubyte src[4], void *dst)
+{
+ GLuint *d = ((GLuint *) dst);
+ GLushort l = UBYTE_TO_USHORT(src[RCOMP]);
+ GLushort a = UBYTE_TO_USHORT(src[ACOMP]);
+ *d = PACK_COLOR_1616(l, a);
+}
+
+static void
+pack_float_AL1616_REV(const GLfloat src[4], void *dst)
+{
+ GLuint *d = ((GLuint *) dst);
+ GLushort l, a;
+ UNCLAMPED_FLOAT_TO_USHORT(l, src[RCOMP]);
+ UNCLAMPED_FLOAT_TO_USHORT(a, src[ACOMP]);
+ *d = PACK_COLOR_1616(l, a);
+}
+
+
+/* MESA_FORMAT_RGB332 */
+
+static void
+pack_ubyte_RGB332(const GLubyte src[4], void *dst)
+{
+ GLubyte *d = ((GLubyte *) dst);
+ *d = PACK_COLOR_332(src[RCOMP], src[GCOMP], src[BCOMP]);
+}
+
+static void
+pack_float_RGB332(const GLfloat src[4], void *dst)
+{
+ GLubyte v[4];
+ UNCLAMPED_FLOAT_TO_UBYTE(v[0], src[RCOMP]);
+ UNCLAMPED_FLOAT_TO_UBYTE(v[1], src[GCOMP]);
+ UNCLAMPED_FLOAT_TO_UBYTE(v[2], src[BCOMP]);
+ pack_ubyte_RGB332(v, dst);
+}
+
+
+/* MESA_FORMAT_A8 */
+
+static void
+pack_ubyte_A8(const GLubyte src[4], void *dst)
+{
+ GLubyte *d = ((GLubyte *) dst);
+ *d = src[ACOMP];
+}
+
+static void
+pack_float_A8(const GLfloat src[4], void *dst)
+{
+ GLubyte *d = ((GLubyte *) dst);
+ UNCLAMPED_FLOAT_TO_UBYTE(d[0], src[ACOMP]);
+}
+
+
+/* MESA_FORMAT_A16 */
+
+static void
+pack_ubyte_A16(const GLubyte src[4], void *dst)
+{
+ GLushort *d = ((GLushort *) dst);
+ *d = UBYTE_TO_USHORT(src[ACOMP]);
+}
+
+static void
+pack_float_A16(const GLfloat src[4], void *dst)
+{
+ GLushort *d = ((GLushort *) dst);
+ UNCLAMPED_FLOAT_TO_USHORT(d[0], src[ACOMP]);
+}
+
+
+/* MESA_FORMAT_L8 */
+
+static void
+pack_ubyte_L8(const GLubyte src[4], void *dst)
+{
+ GLubyte *d = ((GLubyte *) dst);
+ *d = src[RCOMP];
+}
+
+static void
+pack_float_L8(const GLfloat src[4], void *dst)
+{
+ GLubyte *d = ((GLubyte *) dst);
+ UNCLAMPED_FLOAT_TO_UBYTE(d[0], src[RCOMP]);
+}
+
+
+/* MESA_FORMAT_L16 */
+
+static void
+pack_ubyte_L16(const GLubyte src[4], void *dst)
+{
+ GLushort *d = ((GLushort *) dst);
+ *d = UBYTE_TO_USHORT(src[RCOMP]);
+}
+
+static void
+pack_float_L16(const GLfloat src[4], void *dst)
+{
+ GLushort *d = ((GLushort *) dst);
+ UNCLAMPED_FLOAT_TO_USHORT(d[0], src[RCOMP]);
+}
+
+
+/* MESA_FORMAT_YCBCR */
+
+static void
+pack_ubyte_YCBCR(const GLubyte src[4], void *dst)
+{
+ /* todo */
+}
+
+static void
+pack_float_YCBCR(const GLfloat src[4], void *dst)
+{
+ /* todo */
+}
+
+
+/* MESA_FORMAT_YCBCR_REV */
+
+static void
+pack_ubyte_YCBCR_REV(const GLubyte src[4], void *dst)
+{
+ /* todo */
+}
+
+static void
+pack_float_YCBCR_REV(const GLfloat src[4], void *dst)
+{
+ /* todo */
+}
+
+
+/* MESA_FORMAT_R8 */
+
+static void
+pack_ubyte_R8(const GLubyte src[4], void *dst)
+{
+ GLubyte *d = ((GLubyte *) dst);
+ *d = src[RCOMP];
+}
+
+static void
+pack_float_R8(const GLfloat src[4], void *dst)
+{
+ GLubyte *d = ((GLubyte *) dst);
+ GLubyte r;
+ UNCLAMPED_FLOAT_TO_UBYTE(r, src[RCOMP]);
+ d[0] = r;
+}
+
+
+/* MESA_FORMAT_GR88 */
+
+static void
+pack_ubyte_GR88(const GLubyte src[4], void *dst)
+{
+ GLubyte *d = ((GLubyte *) dst);
+ *d = PACK_COLOR_88(src[GCOMP], src[RCOMP]);
+}
+
+static void
+pack_float_GR88(const GLfloat src[4], void *dst)
+{
+ GLushort *d = ((GLushort *) dst);
+ GLubyte r, g;
+ UNCLAMPED_FLOAT_TO_UBYTE(r, src[RCOMP]);
+ UNCLAMPED_FLOAT_TO_UBYTE(g, src[GCOMP]);
+ *d = PACK_COLOR_88(g, r);
+}
+
+
+/* MESA_FORMAT_RG88 */
+
+static void
+pack_ubyte_RG88(const GLubyte src[4], void *dst)
+{
+ GLubyte *d = ((GLubyte *) dst);
+ *d = PACK_COLOR_88(src[RCOMP], src[GCOMP]);
+}
+
+static void
+pack_float_RG88(const GLfloat src[4], void *dst)
+{
+ GLushort *d = ((GLushort *) dst);
+ GLubyte r, g;
+ UNCLAMPED_FLOAT_TO_UBYTE(r, src[RCOMP]);
+ UNCLAMPED_FLOAT_TO_UBYTE(g, src[GCOMP]);
+ *d = PACK_COLOR_88(r, g);
+}
+
+
+/* MESA_FORMAT_R16 */
+
+static void
+pack_ubyte_R16(const GLubyte src[4], void *dst)
+{
+ GLushort *d = ((GLushort *) dst);
+ *d = UBYTE_TO_USHORT(src[RCOMP]);
+}
+
+static void
+pack_float_R16(const GLfloat src[4], void *dst)
+{
+ GLushort *d = ((GLushort *) dst);
+ UNCLAMPED_FLOAT_TO_USHORT(d[0], src[RCOMP]);
+}
+
+
+/* MESA_FORMAT_RG1616 */
+
+static void
+pack_ubyte_RG1616(const GLubyte src[4], void *dst)
+{
+ GLuint *d = ((GLuint *) dst);
+ GLushort r = UBYTE_TO_USHORT(src[RCOMP]);
+ GLushort g = UBYTE_TO_USHORT(src[GCOMP]);
+ *d = PACK_COLOR_1616(g, r);
+}
+
+static void
+pack_float_RG1616(const GLfloat src[4], void *dst)
+{
+ GLuint *d = ((GLuint *) dst);
+ GLushort r, g;
+ UNCLAMPED_FLOAT_TO_USHORT(r, src[RCOMP]);
+ UNCLAMPED_FLOAT_TO_USHORT(g, src[GCOMP]);
+ *d = PACK_COLOR_1616(g, r);
+}
+
+
+/* MESA_FORMAT_RG1616_REV */
+
+static void
+pack_ubyte_RG1616_REV(const GLubyte src[4], void *dst)
+{
+ GLuint *d = ((GLuint *) dst);
+ GLushort r = UBYTE_TO_USHORT(src[RCOMP]);
+ GLushort g = UBYTE_TO_USHORT(src[GCOMP]);
+ *d = PACK_COLOR_1616(r, g);
+}
+
+
+static void
+pack_float_RG1616_REV(const GLfloat src[4], void *dst)
+{
+ GLuint *d = ((GLuint *) dst);
+ GLushort r, g;
+ UNCLAMPED_FLOAT_TO_USHORT(r, src[RCOMP]);
+ UNCLAMPED_FLOAT_TO_USHORT(g, src[GCOMP]);
+ *d = PACK_COLOR_1616(r, g);
+}
+
+
+/* MESA_FORMAT_ARGB2101010 */
+
+static void
+pack_ubyte_ARGB2101010(const GLubyte src[4], void *dst)
+{
+ GLuint *d = ((GLuint *) dst);
+ GLushort r = UBYTE_TO_USHORT(src[RCOMP]);
+ GLushort g = UBYTE_TO_USHORT(src[GCOMP]);
+ GLushort b = UBYTE_TO_USHORT(src[BCOMP]);
+ GLushort a = UBYTE_TO_USHORT(src[ACOMP]);
+ *d = PACK_COLOR_2101010_US(a, r, g, b);
+}
+
+static void
+pack_float_ARGB2101010(const GLfloat src[4], void *dst)
+{
+ GLuint *d = ((GLuint *) dst);
+ GLushort r, g, b, a;
+ UNCLAMPED_FLOAT_TO_USHORT(r, src[RCOMP]);
+ UNCLAMPED_FLOAT_TO_USHORT(g, src[GCOMP]);
+ UNCLAMPED_FLOAT_TO_USHORT(b, src[BCOMP]);
+ UNCLAMPED_FLOAT_TO_USHORT(a, src[ACOMP]);
+ *d = PACK_COLOR_2101010_US(a, r, g, b);
+}
+
+
+/* MESA_FORMAT_SRGB8 */
+
+static void
+pack_ubyte_SRGB8(const GLubyte src[4], void *dst)
+{
+ GLubyte *d = ((GLubyte *) dst);
+ d[2] = linear_ubyte_to_srgb_ubyte(src[RCOMP]);
+ d[1] = linear_ubyte_to_srgb_ubyte(src[RCOMP]);
+ d[0] = linear_ubyte_to_srgb_ubyte(src[RCOMP]);
+}
+
+static void
+pack_float_SRGB8(const GLfloat src[4], void *dst)
+{
+ GLubyte *d = ((GLubyte *) dst);
+ d[2] = linear_float_to_srgb_ubyte(src[RCOMP]);
+ d[1] = linear_float_to_srgb_ubyte(src[GCOMP]);
+ d[0] = linear_float_to_srgb_ubyte(src[BCOMP]);
+}
+
+
+/* MESA_FORMAT_SRGBA8 */
+
+static void
+pack_ubyte_SRGBA8(const GLubyte src[4], void *dst)
+{
+ GLuint *d = ((GLuint *) dst);
+ GLubyte r = linear_ubyte_to_srgb_ubyte(src[RCOMP]);
+ GLubyte g = linear_ubyte_to_srgb_ubyte(src[GCOMP]);
+ GLubyte b = linear_ubyte_to_srgb_ubyte(src[BCOMP]);
+ *d = PACK_COLOR_8888(r, g, b, src[ACOMP]);
+}
+
+static void
+pack_float_SRGBA8(const GLfloat src[4], void *dst)
+{
+ GLuint *d = ((GLuint *) dst);
+ GLubyte r, g, b, a;
+ r = linear_float_to_srgb_ubyte(src[RCOMP]);
+ g = linear_float_to_srgb_ubyte(src[GCOMP]);
+ b = linear_float_to_srgb_ubyte(src[BCOMP]);
+ UNCLAMPED_FLOAT_TO_UBYTE(a, src[ACOMP]);
+ *d = PACK_COLOR_8888(r, g, b, a);
+}
+
+
+/* MESA_FORMAT_SARGB8 */
+
+static void
+pack_ubyte_SARGB8(const GLubyte src[4], void *dst)
+{
+ GLuint *d = ((GLuint *) dst);
+ GLubyte r = linear_ubyte_to_srgb_ubyte(src[RCOMP]);
+ GLubyte g = linear_ubyte_to_srgb_ubyte(src[RCOMP]);
+ GLubyte b = linear_ubyte_to_srgb_ubyte(src[RCOMP]);
+ *d = PACK_COLOR_8888(src[ACOMP], r, g, b);
+}
+
+static void
+pack_float_SARGB8(const GLfloat src[4], void *dst)
+{
+ GLuint *d = ((GLuint *) dst);
+ GLubyte r, g, b, a;
+ r = linear_float_to_srgb_ubyte(src[RCOMP]);
+ g = linear_float_to_srgb_ubyte(src[GCOMP]);
+ b = linear_float_to_srgb_ubyte(src[BCOMP]);
+ UNCLAMPED_FLOAT_TO_UBYTE(a, src[ACOMP]);
+ *d = PACK_COLOR_8888(a, r, g, b);
+}
+
+
+/* MESA_FORMAT_SL8 */
+
+static void
+pack_ubyte_SL8(const GLubyte src[4], void *dst)
+{
+ GLubyte *d = ((GLubyte *) dst);
+ *d = linear_ubyte_to_srgb_ubyte(src[RCOMP]);
+}
+
+static void
+pack_float_SL8(const GLfloat src[4], void *dst)
+{
+ GLubyte *d = ((GLubyte *) dst);
+ GLubyte l = linear_float_to_srgb_ubyte(src[RCOMP]);
+ *d = l;
+}
+
+
+/* MESA_FORMAT_SLA8 */
+
+static void
+pack_ubyte_SLA8(const GLubyte src[4], void *dst)
+{
+ GLushort *d = ((GLushort *) dst);
+ GLubyte l = linear_ubyte_to_srgb_ubyte(src[RCOMP]);
+ *d = PACK_COLOR_88(src[ACOMP], l);
+}
+
+static void
+pack_float_SLA8(const GLfloat src[4], void *dst)
+{
+ GLushort *d = ((GLushort *) dst);
+ GLubyte a, l = linear_float_to_srgb_ubyte(src[RCOMP]);
+ CLAMPED_FLOAT_TO_UBYTE(a, src[ACOMP]);
+ *d = PACK_COLOR_88(a, l);
+}
+
+
+/* MESA_FORMAT_RGBA_FLOAT32 */
+
+static void
+pack_ubyte_RGBA_FLOAT32(const GLubyte src[4], void *dst)
+{
+ GLfloat *d = ((GLfloat *) dst);
+ d[0] = UBYTE_TO_FLOAT(src[0]);
+ d[1] = UBYTE_TO_FLOAT(src[1]);
+ d[2] = UBYTE_TO_FLOAT(src[2]);
+ d[3] = UBYTE_TO_FLOAT(src[3]);
+}
+
+static void
+pack_float_RGBA_FLOAT32(const GLfloat src[4], void *dst)
+{
+ GLfloat *d = ((GLfloat *) dst);
+ d[0] = src[0];
+ d[1] = src[1];
+ d[2] = src[2];
+ d[3] = src[3];
+}
+
+
+/* MESA_FORMAT_RGBA_FLOAT16 */
+
+static void
+pack_ubyte_RGBA_FLOAT16(const GLubyte src[4], void *dst)
+{
+ GLhalfARB *d = ((GLhalfARB *) dst);
+ d[0] = _mesa_float_to_half(UBYTE_TO_FLOAT(src[0]));
+ d[1] = _mesa_float_to_half(UBYTE_TO_FLOAT(src[1]));
+ d[2] = _mesa_float_to_half(UBYTE_TO_FLOAT(src[2]));
+ d[3] = _mesa_float_to_half(UBYTE_TO_FLOAT(src[3]));
+}
+
+static void
+pack_float_RGBA_FLOAT16(const GLfloat src[4], void *dst)
+{
+ GLhalfARB *d = ((GLhalfARB *) dst);
+ d[0] = _mesa_float_to_half(src[0]);
+ d[1] = _mesa_float_to_half(src[1]);
+ d[2] = _mesa_float_to_half(src[2]);
+ d[3] = _mesa_float_to_half(src[3]);
+}
+
+
+/* MESA_FORMAT_RGB_FLOAT32 */
+
+static void
+pack_ubyte_RGB_FLOAT32(const GLubyte src[4], void *dst)
+{
+ GLfloat *d = ((GLfloat *) dst);
+ d[0] = UBYTE_TO_FLOAT(src[0]);
+ d[1] = UBYTE_TO_FLOAT(src[1]);
+ d[2] = UBYTE_TO_FLOAT(src[2]);
+}
+
+static void
+pack_float_RGB_FLOAT32(const GLfloat src[4], void *dst)
+{
+ GLfloat *d = ((GLfloat *) dst);
+ d[0] = src[0];
+ d[1] = src[1];
+ d[2] = src[2];
+}
+
+
+/* MESA_FORMAT_RGB_FLOAT16 */
+
+static void
+pack_ubyte_RGB_FLOAT16(const GLubyte src[4], void *dst)
+{
+ GLhalfARB *d = ((GLhalfARB *) dst);
+ d[0] = _mesa_float_to_half(UBYTE_TO_FLOAT(src[0]));
+ d[1] = _mesa_float_to_half(UBYTE_TO_FLOAT(src[1]));
+ d[2] = _mesa_float_to_half(UBYTE_TO_FLOAT(src[2]));
+}
+
+static void
+pack_float_RGB_FLOAT16(const GLfloat src[4], void *dst)
+{
+ GLhalfARB *d = ((GLhalfARB *) dst);
+ d[0] = _mesa_float_to_half(src[0]);
+ d[1] = _mesa_float_to_half(src[1]);
+ d[2] = _mesa_float_to_half(src[2]);
+}
+
+
+/* MESA_FORMAT_ALPHA_FLOAT32 */
+
+static void
+pack_ubyte_ALPHA_FLOAT32(const GLubyte src[4], void *dst)
+{
+ GLfloat *d = ((GLfloat *) dst);
+ d[0] = UBYTE_TO_FLOAT(src[ACOMP]);
+}
+
+static void
+pack_float_ALPHA_FLOAT32(const GLfloat src[4], void *dst)
+{
+ GLfloat *d = ((GLfloat *) dst);
+ d[0] = src[ACOMP];
+}
+
+
+/* MESA_FORMAT_ALPHA_FLOAT16 */
+
+static void
+pack_ubyte_ALPHA_FLOAT16(const GLubyte src[4], void *dst)
+{
+ GLhalfARB *d = ((GLhalfARB *) dst);
+ d[0] = _mesa_float_to_half(UBYTE_TO_FLOAT(src[ACOMP]));
+}
+
+static void
+pack_float_ALPHA_FLOAT16(const GLfloat src[4], void *dst)
+{
+ GLhalfARB *d = ((GLhalfARB *) dst);
+ d[0] = _mesa_float_to_half(src[ACOMP]);
+}
+
+
+/* MESA_FORMAT_LUMINANCE_FLOAT32 (and INTENSITY_FLOAT32, R_FLOAT32) */
+
+static void
+pack_ubyte_LUMINANCE_FLOAT32(const GLubyte src[4], void *dst)
+{
+ GLfloat *d = ((GLfloat *) dst);
+ d[0] = UBYTE_TO_FLOAT(src[RCOMP]);
+}
+
+static void
+pack_float_LUMINANCE_FLOAT32(const GLfloat src[4], void *dst)
+{
+ GLfloat *d = ((GLfloat *) dst);
+ d[0] = src[RCOMP];
+}
+
+
+/* MESA_FORMAT_LUMINANCE_FLOAT16 (and INTENSITY_FLOAT16, R_FLOAT32) */
+
+static void
+pack_ubyte_LUMINANCE_FLOAT16(const GLubyte src[4], void *dst)
+{
+ GLhalfARB *d = ((GLhalfARB *) dst);
+ d[0] = _mesa_float_to_half(UBYTE_TO_FLOAT(src[RCOMP]));
+}
+
+static void
+pack_float_LUMINANCE_FLOAT16(const GLfloat src[4], void *dst)
+{
+ GLhalfARB *d = ((GLhalfARB *) dst);
+ d[0] = _mesa_float_to_half(src[RCOMP]);
+}
+
+
+/* MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32 */
+
+static void
+pack_ubyte_LUMINANCE_ALPHA_FLOAT32(const GLubyte src[4], void *dst)
+{
+ GLfloat *d = ((GLfloat *) dst);
+ d[0] = UBYTE_TO_FLOAT(src[RCOMP]);
+ d[1] = UBYTE_TO_FLOAT(src[ACOMP]);
+}
+
+static void
+pack_float_LUMINANCE_ALPHA_FLOAT32(const GLfloat src[4], void *dst)
+{
+ GLfloat *d = ((GLfloat *) dst);
+ d[0] = src[RCOMP];
+ d[1] = src[ACOMP];
+}
+
+
+/* MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16 */
+
+static void
+pack_ubyte_LUMINANCE_ALPHA_FLOAT16(const GLubyte src[4], void *dst)
+{
+ GLhalfARB *d = ((GLhalfARB *) dst);
+ d[0] = _mesa_float_to_half(UBYTE_TO_FLOAT(src[RCOMP]));
+ d[1] = _mesa_float_to_half(UBYTE_TO_FLOAT(src[ACOMP]));
+}
+
+static void
+pack_float_LUMINANCE_ALPHA_FLOAT16(const GLfloat src[4], void *dst)
+{
+ GLhalfARB *d = ((GLhalfARB *) dst);
+ d[0] = _mesa_float_to_half(src[RCOMP]);
+ d[1] = _mesa_float_to_half(src[ACOMP]);
+}
+
+
+/* MESA_FORMAT_RG_FLOAT32 */
+
+static void
+pack_ubyte_RG_FLOAT32(const GLubyte src[4], void *dst)
+{
+ GLfloat *d = ((GLfloat *) dst);
+ d[0] = UBYTE_TO_FLOAT(src[RCOMP]);
+ d[1] = UBYTE_TO_FLOAT(src[GCOMP]);
+}
+
+static void
+pack_float_RG_FLOAT32(const GLfloat src[4], void *dst)
+{
+ GLfloat *d = ((GLfloat *) dst);
+ d[0] = src[RCOMP];
+ d[1] = src[GCOMP];
+}
+
+
+/* MESA_FORMAT_RG_FLOAT16 */
+
+static void
+pack_ubyte_RG_FLOAT16(const GLubyte src[4], void *dst)
+{
+ GLhalfARB *d = ((GLhalfARB *) dst);
+ d[0] = _mesa_float_to_half(UBYTE_TO_FLOAT(src[RCOMP]));
+ d[1] = _mesa_float_to_half(UBYTE_TO_FLOAT(src[GCOMP]));
+}
+
+static void
+pack_float_RG_FLOAT16(const GLfloat src[4], void *dst)
+{
+ GLhalfARB *d = ((GLhalfARB *) dst);
+ d[0] = _mesa_float_to_half(src[RCOMP]);
+ d[1] = _mesa_float_to_half(src[GCOMP]);
+}
+
+
+/* MESA_FORMAT_DUDV8 */
+
+static void
+pack_ubyte_DUDV8(const GLubyte src[4], void *dst)
+{
+ /* XXX is this ever used? */
+ GLushort *d = ((GLushort *) dst);
+ *d = PACK_COLOR_88(src[0], src[1]);
+}
+
+static void
+pack_float_DUDV8(const GLfloat src[4], void *dst)
+{
+ GLushort *d = ((GLushort *) dst);
+ GLbyte du, dv;
+ du = FLOAT_TO_BYTE(CLAMP(src[0], 0.0F, 1.0F));
+ dv = FLOAT_TO_BYTE(CLAMP(src[1], 0.0F, 1.0F));
+ *d = PACK_COLOR_88(du, dv);
+}
+
+
+/* MESA_FORMAT_RGBA_16 */
+
+static void
+pack_ubyte_RGBA_16(const GLubyte src[4], void *dst)
+{
+ GLushort *d = ((GLushort *) dst);
+ d[0] = UBYTE_TO_USHORT(src[RCOMP]);
+ d[1] = UBYTE_TO_USHORT(src[GCOMP]);
+ d[2] = UBYTE_TO_USHORT(src[BCOMP]);
+ d[3] = UBYTE_TO_USHORT(src[ACOMP]);
+}
+
+static void
+pack_float_RGBA_16(const GLfloat src[4], void *dst)
+{
+ GLushort *d = ((GLushort *) dst);
+ UNCLAMPED_FLOAT_TO_USHORT(d[0], src[RCOMP]);
+ UNCLAMPED_FLOAT_TO_USHORT(d[1], src[GCOMP]);
+ UNCLAMPED_FLOAT_TO_USHORT(d[2], src[BCOMP]);
+ UNCLAMPED_FLOAT_TO_USHORT(d[3], src[ACOMP]);
+}
+
+
+
+/*
+ * MESA_FORMAT_SIGNED_R8
+ */
+
+static void
+pack_float_SIGNED_R8(const GLfloat src[4], void *dst)
+{
+ GLbyte *d = (GLbyte *) dst;
+ *d = FLOAT_TO_BYTE(CLAMP(src[RCOMP], -1.0f, 1.0f));
+}
+
+
+/*
+ * MESA_FORMAT_SIGNED_RG88_REV
+ */
+
+static void
+pack_float_SIGNED_RG88_REV(const GLfloat src[4], void *dst)
+{
+ GLushort *d = (GLushort *) dst;
+ GLbyte r = FLOAT_TO_BYTE(CLAMP(src[RCOMP], -1.0f, 1.0f));
+ GLbyte g = FLOAT_TO_BYTE(CLAMP(src[GCOMP], -1.0f, 1.0f));
+ *d = (g << 8) | r;
+}
+
+
+/*
+ * MESA_FORMAT_SIGNED_RGBX8888
+ */
+
+static void
+pack_float_SIGNED_RGBX8888(const GLfloat src[4], void *dst)
+{
+ GLuint *d = (GLuint *) dst;
+ GLbyte r = FLOAT_TO_BYTE(CLAMP(src[RCOMP], -1.0f, 1.0f));
+ GLbyte g = FLOAT_TO_BYTE(CLAMP(src[GCOMP], -1.0f, 1.0f));
+ GLbyte b = FLOAT_TO_BYTE(CLAMP(src[BCOMP], -1.0f, 1.0f));
+ GLbyte a = 127;
+ *d = PACK_COLOR_8888(r, g, b, a);
+}
+
+
+/*
+ * MESA_FORMAT_SIGNED_RGBA8888
+ */
+
+static void
+pack_float_SIGNED_RGBA8888(const GLfloat src[4], void *dst)
+{
+ GLuint *d = (GLuint *) dst;
+ GLbyte r = FLOAT_TO_BYTE(CLAMP(src[RCOMP], -1.0f, 1.0f));
+ GLbyte g = FLOAT_TO_BYTE(CLAMP(src[GCOMP], -1.0f, 1.0f));
+ GLbyte b = FLOAT_TO_BYTE(CLAMP(src[BCOMP], -1.0f, 1.0f));
+ GLbyte a = FLOAT_TO_BYTE(CLAMP(src[ACOMP], -1.0f, 1.0f));
+ *d = PACK_COLOR_8888(r, g, b, a);
+}
+
+
+/*
+ * MESA_FORMAT_SIGNED_RGBA8888_REV
+ */
+
+static void
+pack_float_SIGNED_RGBA8888_REV(const GLfloat src[4], void *dst)
+{
+ GLuint *d = (GLuint *) dst;
+ GLbyte r = FLOAT_TO_BYTE(CLAMP(src[RCOMP], -1.0f, 1.0f));
+ GLbyte g = FLOAT_TO_BYTE(CLAMP(src[GCOMP], -1.0f, 1.0f));
+ GLbyte b = FLOAT_TO_BYTE(CLAMP(src[BCOMP], -1.0f, 1.0f));
+ GLbyte a = FLOAT_TO_BYTE(CLAMP(src[ACOMP], -1.0f, 1.0f));
+ *d = PACK_COLOR_8888(a, b, g, r);
+}
+
+
+/*
+ * MESA_FORMAT_SIGNED_R16
+ */
+
+static void
+pack_float_SIGNED_R16(const GLfloat src[4], void *dst)
+{
+ GLshort *d = (GLshort *) dst;
+ *d = FLOAT_TO_SHORT(CLAMP(src[RCOMP], -1.0f, 1.0f));
+}
+
+
+/*
+ * MESA_FORMAT_SIGNED_GR1616
+ */
+
+static void
+pack_float_SIGNED_GR1616(const GLfloat src[4], void *dst)
+{
+ GLuint *d = (GLuint *) dst;
+ GLshort r = FLOAT_TO_SHORT(CLAMP(src[RCOMP], -1.0f, 1.0f));
+ GLshort g = FLOAT_TO_SHORT(CLAMP(src[GCOMP], -1.0f, 1.0f));
+ *d = (g << 16) | (r & 0xffff);
+}
+
+
+/*
+ * MESA_FORMAT_SIGNED_RGB_16
+ */
+
+static void
+pack_float_SIGNED_RGB_16(const GLfloat src[4], void *dst)
+{
+ GLshort *d = (GLshort *) dst;
+ d[0] = FLOAT_TO_SHORT(CLAMP(src[RCOMP], -1.0f, 1.0f));
+ d[1] = FLOAT_TO_SHORT(CLAMP(src[GCOMP], -1.0f, 1.0f));
+ d[2] = FLOAT_TO_SHORT(CLAMP(src[BCOMP], -1.0f, 1.0f));
+}
+
+
+/*
+ * MESA_FORMAT_SIGNED_RGBA_16
+ */
+
+static void
+pack_float_SIGNED_RGBA_16(const GLfloat src[4], void *dst)
+{
+ GLshort *d = (GLshort *) dst;
+ d[0] = FLOAT_TO_SHORT(CLAMP(src[RCOMP], -1.0f, 1.0f));
+ d[1] = FLOAT_TO_SHORT(CLAMP(src[GCOMP], -1.0f, 1.0f));
+ d[2] = FLOAT_TO_SHORT(CLAMP(src[BCOMP], -1.0f, 1.0f));
+ d[3] = FLOAT_TO_SHORT(CLAMP(src[ACOMP], -1.0f, 1.0f));
+}
+
+
+/*
+ * MESA_FORMAT_SIGNED_A8
+ */
+
+static void
+pack_float_SIGNED_A8(const GLfloat src[4], void *dst)
+{
+ GLbyte *d = (GLbyte *) dst;
+ *d = FLOAT_TO_BYTE(CLAMP(src[ACOMP], -1.0f, 1.0f));
+}
+
+
+/*
+ * MESA_FORMAT_SIGNED_L8
+ */
+
+static void
+pack_float_SIGNED_L8(const GLfloat src[4], void *dst)
+{
+ GLbyte *d = (GLbyte *) dst;
+ *d = FLOAT_TO_BYTE(CLAMP(src[RCOMP], -1.0f, 1.0f));
+}
+
+
+/*
+ * MESA_FORMAT_SIGNED_AL88
+ */
+
+static void
+pack_float_SIGNED_AL88(const GLfloat src[4], void *dst)
+{
+ GLushort *d = (GLushort *) dst;
+ GLbyte l = FLOAT_TO_BYTE(CLAMP(src[RCOMP], -1.0f, 1.0f));
+ GLbyte a = FLOAT_TO_BYTE(CLAMP(src[ACOMP], -1.0f, 1.0f));
+ *d = (a << 8) | l;
+}
+
+
+/*
+ * MESA_FORMAT_SIGNED_A16
+ */
+
+static void
+pack_float_SIGNED_A16(const GLfloat src[4], void *dst)
+{
+ GLshort *d = (GLshort *) dst;
+ *d = FLOAT_TO_SHORT(CLAMP(src[ACOMP], -1.0f, 1.0f));
+}
+
+
+/*
+ * MESA_FORMAT_SIGNED_L16
+ */
+
+static void
+pack_float_SIGNED_L16(const GLfloat src[4], void *dst)
+{
+ GLshort *d = (GLshort *) dst;
+ *d = FLOAT_TO_SHORT(CLAMP(src[RCOMP], -1.0f, 1.0f));
+}
+
+
+/*
+ * MESA_FORMAT_SIGNED_AL1616
+ */
+
+static void
+pack_float_SIGNED_AL1616(const GLfloat src[4], void *dst)
+{
+ GLuint *d = (GLuint *) dst;
+ GLshort l = FLOAT_TO_SHORT(CLAMP(src[RCOMP], -1.0f, 1.0f));
+ GLshort a = FLOAT_TO_SHORT(CLAMP(src[ACOMP], -1.0f, 1.0f));
+ *d = PACK_COLOR_1616(a, l);
+}
+
+
+/*
+ * MESA_FORMAT_RGB9_E5_FLOAT;
+ */
+
+static void
+pack_float_RGB9_E5_FLOAT(const GLfloat src[4], void *dst)
+{
+ GLuint *d = (GLuint *) dst;
+ *d = float3_to_rgb9e5(src);
+}
+
+static void
+pack_ubyte_RGB9_E5_FLOAT(const GLubyte src[4], void *dst)
+{
+ GLuint *d = (GLuint *) dst;
+ GLfloat rgb[3];
+ rgb[0] = UBYTE_TO_FLOAT(src[RCOMP]);
+ rgb[1] = UBYTE_TO_FLOAT(src[GCOMP]);
+ rgb[2] = UBYTE_TO_FLOAT(src[BCOMP]);
+ *d = float3_to_rgb9e5(rgb);
+}
+
+
+
+/*
+ * MESA_FORMAT_R11_G11_B10_FLOAT;
+ */
+
+static void
+pack_ubyte_R11_G11_B10_FLOAT(const GLubyte src[4], void *dst)
+{
+ GLuint *d = (GLuint *) dst;
+ GLfloat rgb[3];
+ rgb[0] = UBYTE_TO_FLOAT(src[RCOMP]);
+ rgb[1] = UBYTE_TO_FLOAT(src[GCOMP]);
+ rgb[2] = UBYTE_TO_FLOAT(src[BCOMP]);
+ *d = float3_to_r11g11b10f(rgb);
+}
+
+static void
+pack_float_R11_G11_B10_FLOAT(const GLfloat src[4], void *dst)
+{
+ GLuint *d = (GLuint *) dst;
+ *d = float3_to_r11g11b10f(src);
+}
+
+
+
+/**
+ * Return a function that can pack a GLubyte rgba[4] color.
+ */
+gl_pack_ubyte_rgba_func
+_mesa_get_pack_ubyte_rgba_function(gl_format format)
+{
+ static gl_pack_ubyte_rgba_func table[MESA_FORMAT_COUNT];
+ static GLboolean initialized = GL_FALSE;
+
+ if (!initialized) {
+ memset(table, 0, sizeof(table));
+
+ table[MESA_FORMAT_NONE] = NULL;
+
+ table[MESA_FORMAT_RGBA8888] = pack_ubyte_RGBA8888;
+ table[MESA_FORMAT_RGBA8888_REV] = pack_ubyte_RGBA8888_REV;
+ table[MESA_FORMAT_ARGB8888] = pack_ubyte_ARGB8888;
+ table[MESA_FORMAT_ARGB8888_REV] = pack_ubyte_ARGB8888_REV;
+ table[MESA_FORMAT_RGBX8888] = pack_ubyte_RGBA8888; /* reused */
+ table[MESA_FORMAT_RGBX8888_REV] = pack_ubyte_RGBA8888_REV; /* reused */
+ table[MESA_FORMAT_XRGB8888] = pack_ubyte_XRGB8888;
+ table[MESA_FORMAT_XRGB8888_REV] = pack_ubyte_XRGB8888_REV;
+ table[MESA_FORMAT_RGB888] = pack_ubyte_RGB888;
+ table[MESA_FORMAT_BGR888] = pack_ubyte_BGR888;
+ table[MESA_FORMAT_RGB565] = pack_ubyte_RGB565;
+ table[MESA_FORMAT_RGB565_REV] = pack_ubyte_RGB565_REV;
+ table[MESA_FORMAT_ARGB4444] = pack_ubyte_ARGB4444;
+ table[MESA_FORMAT_ARGB4444_REV] = pack_ubyte_ARGB4444_REV;
+ table[MESA_FORMAT_RGBA5551] = pack_ubyte_RGBA5551;
+ table[MESA_FORMAT_ARGB1555] = pack_ubyte_ARGB1555;
+ table[MESA_FORMAT_ARGB1555_REV] = pack_ubyte_ARGB1555_REV;
+ table[MESA_FORMAT_AL44] = pack_ubyte_AL44;
+ table[MESA_FORMAT_AL88] = pack_ubyte_AL88;
+ table[MESA_FORMAT_AL88_REV] = pack_ubyte_AL88_REV;
+ table[MESA_FORMAT_AL1616] = pack_ubyte_AL1616;
+ table[MESA_FORMAT_AL1616_REV] = pack_ubyte_AL1616_REV;
+ table[MESA_FORMAT_RGB332] = pack_ubyte_RGB332;
+ table[MESA_FORMAT_A8] = pack_ubyte_A8;
+ table[MESA_FORMAT_A16] = pack_ubyte_A16;
+ table[MESA_FORMAT_L8] = pack_ubyte_L8;
+ table[MESA_FORMAT_L16] = pack_ubyte_L16;
+ table[MESA_FORMAT_I8] = pack_ubyte_L8; /* reuse pack_ubyte_L8 */
+ table[MESA_FORMAT_I16] = pack_ubyte_L16; /* reuse pack_ubyte_L16 */
+ table[MESA_FORMAT_YCBCR] = pack_ubyte_YCBCR;
+ table[MESA_FORMAT_YCBCR_REV] = pack_ubyte_YCBCR_REV;
+ table[MESA_FORMAT_R8] = pack_ubyte_R8;
+ table[MESA_FORMAT_GR88] = pack_ubyte_GR88;
+ table[MESA_FORMAT_RG88] = pack_ubyte_RG88;
+ table[MESA_FORMAT_R16] = pack_ubyte_R16;
+ table[MESA_FORMAT_RG1616] = pack_ubyte_RG1616;
+ table[MESA_FORMAT_RG1616_REV] = pack_ubyte_RG1616_REV;
+ table[MESA_FORMAT_ARGB2101010] = pack_ubyte_ARGB2101010;
+
+ /* should never convert RGBA to these formats */
+ table[MESA_FORMAT_Z24_S8] = NULL;
+ table[MESA_FORMAT_S8_Z24] = NULL;
+ table[MESA_FORMAT_Z16] = NULL;
+ table[MESA_FORMAT_X8_Z24] = NULL;
+ table[MESA_FORMAT_Z24_X8] = NULL;
+ table[MESA_FORMAT_Z32] = NULL;
+ table[MESA_FORMAT_S8] = NULL;
+
+ /* sRGB */
+ table[MESA_FORMAT_SRGB8] = pack_ubyte_SRGB8;
+ table[MESA_FORMAT_SRGBA8] = pack_ubyte_SRGBA8;
+ table[MESA_FORMAT_SARGB8] = pack_ubyte_SARGB8;
+ table[MESA_FORMAT_SL8] = pack_ubyte_SL8;
+ table[MESA_FORMAT_SLA8] = pack_ubyte_SLA8;
+
+ /* n/a */
+ table[MESA_FORMAT_SRGB_DXT1] = NULL; /* pack_ubyte_SRGB_DXT1; */
+ table[MESA_FORMAT_SRGBA_DXT1] = NULL; /* pack_ubyte_SRGBA_DXT1; */
+ table[MESA_FORMAT_SRGBA_DXT3] = NULL; /* pack_ubyte_SRGBA_DXT3; */
+ table[MESA_FORMAT_SRGBA_DXT5] = NULL; /* pack_ubyte_SRGBA_DXT5; */
+
+ table[MESA_FORMAT_RGB_FXT1] = NULL; /* pack_ubyte_RGB_FXT1; */
+ table[MESA_FORMAT_RGBA_FXT1] = NULL; /* pack_ubyte_RGBA_FXT1; */
+ table[MESA_FORMAT_RGB_DXT1] = NULL; /* pack_ubyte_RGB_DXT1; */
+ table[MESA_FORMAT_RGBA_DXT1] = NULL; /* pack_ubyte_RGBA_DXT1; */
+ table[MESA_FORMAT_RGBA_DXT3] = NULL; /* pack_ubyte_RGBA_DXT3; */
+ table[MESA_FORMAT_RGBA_DXT5] = NULL; /* pack_ubyte_RGBA_DXT5; */
+
+ table[MESA_FORMAT_RGBA_FLOAT32] = pack_ubyte_RGBA_FLOAT32;
+ table[MESA_FORMAT_RGBA_FLOAT16] = pack_ubyte_RGBA_FLOAT16;
+ table[MESA_FORMAT_RGB_FLOAT32] = pack_ubyte_RGB_FLOAT32;
+ table[MESA_FORMAT_RGB_FLOAT16] = pack_ubyte_RGB_FLOAT16;
+ table[MESA_FORMAT_ALPHA_FLOAT32] = pack_ubyte_ALPHA_FLOAT32;
+ table[MESA_FORMAT_ALPHA_FLOAT16] = pack_ubyte_ALPHA_FLOAT16;
+ table[MESA_FORMAT_LUMINANCE_FLOAT32] = pack_ubyte_LUMINANCE_FLOAT32;
+ table[MESA_FORMAT_LUMINANCE_FLOAT16] = pack_ubyte_LUMINANCE_FLOAT16;
+ table[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32] = pack_ubyte_LUMINANCE_ALPHA_FLOAT32;
+ table[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16] = pack_ubyte_LUMINANCE_ALPHA_FLOAT16;
+ table[MESA_FORMAT_INTENSITY_FLOAT32] = pack_ubyte_LUMINANCE_FLOAT32;
+ table[MESA_FORMAT_INTENSITY_FLOAT16] = pack_ubyte_LUMINANCE_FLOAT16;
+ table[MESA_FORMAT_R_FLOAT32] = pack_ubyte_LUMINANCE_FLOAT32;
+ table[MESA_FORMAT_R_FLOAT16] = pack_ubyte_LUMINANCE_FLOAT16;
+ table[MESA_FORMAT_RG_FLOAT32] = pack_ubyte_RG_FLOAT32;
+ table[MESA_FORMAT_RG_FLOAT16] = pack_ubyte_RG_FLOAT16;
+
+ /* n/a */
+ table[MESA_FORMAT_RGBA_INT8] = NULL; /* pack_ubyte_RGBA_INT8 */
+ table[MESA_FORMAT_RGBA_INT16] = NULL; /* pack_ubyte_RGBA_INT16 */
+ table[MESA_FORMAT_RGBA_INT32] = NULL; /* pack_ubyte_RGBA_INT32 */
+ table[MESA_FORMAT_RGBA_UINT8] = NULL; /* pack_ubyte_RGBA_UINT8 */
+ table[MESA_FORMAT_RGBA_UINT16] = NULL; /* pack_ubyte_RGBA_UINT16 */
+ table[MESA_FORMAT_RGBA_UINT32] = NULL; /* pack_ubyte_RGBA_UINT32 */
+
+ table[MESA_FORMAT_DUDV8] = pack_ubyte_DUDV8;
+
+ table[MESA_FORMAT_RGBA_16] = pack_ubyte_RGBA_16;
+
+ /* n/a */
+ table[MESA_FORMAT_SIGNED_R8] = NULL;
+ table[MESA_FORMAT_SIGNED_RG88_REV] = NULL;
+ table[MESA_FORMAT_SIGNED_RGBX8888] = NULL;
+ table[MESA_FORMAT_SIGNED_RGBA8888] = NULL;
+ table[MESA_FORMAT_SIGNED_RGBA8888_REV] = NULL;
+ table[MESA_FORMAT_SIGNED_R16] = NULL;
+ table[MESA_FORMAT_SIGNED_GR1616] = NULL;
+ table[MESA_FORMAT_SIGNED_RGB_16] = NULL;
+ table[MESA_FORMAT_SIGNED_RGBA_16] = NULL;
+ table[MESA_FORMAT_SIGNED_A8] = NULL;
+ table[MESA_FORMAT_SIGNED_L8] = NULL;
+ table[MESA_FORMAT_SIGNED_AL88] = NULL;
+ table[MESA_FORMAT_SIGNED_I8] = NULL;
+ table[MESA_FORMAT_SIGNED_A16] = NULL;
+ table[MESA_FORMAT_SIGNED_L16] = NULL;
+ table[MESA_FORMAT_SIGNED_AL1616] = NULL;
+ table[MESA_FORMAT_SIGNED_I16] = NULL;
+
+
+ table[MESA_FORMAT_RGBA_16] = pack_ubyte_RGBA_16;
+
+ table[MESA_FORMAT_RGB9_E5_FLOAT] = pack_ubyte_RGB9_E5_FLOAT;
+ table[MESA_FORMAT_R11_G11_B10_FLOAT] = pack_ubyte_R11_G11_B10_FLOAT;
+
+ initialized = GL_TRUE;
+ }
+
+ return table[format];
+}
+
+
+
+/**
+ * Return a function that can pack a GLfloat rgba[4] color.
+ */
+gl_pack_float_rgba_func
+_mesa_get_pack_float_rgba_function(gl_format format)
+{
+ static gl_pack_float_rgba_func table[MESA_FORMAT_COUNT];
+ static GLboolean initialized = GL_FALSE;
+
+ if (!initialized) {
+ memset(table, 0, sizeof(table));
+
+ table[MESA_FORMAT_NONE] = NULL;
+
+ table[MESA_FORMAT_RGBA8888] = pack_float_RGBA8888;
+ table[MESA_FORMAT_RGBA8888_REV] = pack_float_RGBA8888_REV;
+ table[MESA_FORMAT_ARGB8888] = pack_float_ARGB8888;
+ table[MESA_FORMAT_ARGB8888_REV] = pack_float_ARGB8888_REV;
+ table[MESA_FORMAT_RGBX8888] = pack_float_RGBA8888; /* reused */
+ table[MESA_FORMAT_RGBX8888_REV] = pack_float_RGBA8888_REV; /* reused */
+ table[MESA_FORMAT_XRGB8888] = pack_float_XRGB8888;
+ table[MESA_FORMAT_XRGB8888_REV] = pack_float_XRGB8888_REV;
+ table[MESA_FORMAT_RGB888] = pack_float_RGB888;
+ table[MESA_FORMAT_BGR888] = pack_float_BGR888;
+ table[MESA_FORMAT_RGB565] = pack_float_RGB565;
+ table[MESA_FORMAT_RGB565_REV] = pack_float_RGB565_REV;
+ table[MESA_FORMAT_ARGB4444] = pack_float_ARGB4444;
+ table[MESA_FORMAT_ARGB4444_REV] = pack_float_ARGB4444_REV;
+ table[MESA_FORMAT_RGBA5551] = pack_float_RGBA5551;
+ table[MESA_FORMAT_ARGB1555] = pack_float_ARGB1555;
+ table[MESA_FORMAT_ARGB1555_REV] = pack_float_ARGB1555_REV;
+
+ table[MESA_FORMAT_AL44] = pack_float_AL44;
+ table[MESA_FORMAT_AL88] = pack_float_AL88;
+ table[MESA_FORMAT_AL88_REV] = pack_float_AL88_REV;
+ table[MESA_FORMAT_AL1616] = pack_float_AL1616;
+ table[MESA_FORMAT_AL1616_REV] = pack_float_AL1616_REV;
+ table[MESA_FORMAT_RGB332] = pack_float_RGB332;
+ table[MESA_FORMAT_A8] = pack_float_A8;
+ table[MESA_FORMAT_A16] = pack_float_A16;
+ table[MESA_FORMAT_L8] = pack_float_L8;
+ table[MESA_FORMAT_L16] = pack_float_L16;
+ table[MESA_FORMAT_I8] = pack_float_L8; /* reuse pack_float_L8 */
+ table[MESA_FORMAT_I16] = pack_float_L16; /* reuse pack_float_L16 */
+ table[MESA_FORMAT_YCBCR] = pack_float_YCBCR;
+ table[MESA_FORMAT_YCBCR_REV] = pack_float_YCBCR_REV;
+ table[MESA_FORMAT_R8] = pack_float_R8;
+ table[MESA_FORMAT_GR88] = pack_float_GR88;
+ table[MESA_FORMAT_RG88] = pack_float_RG88;
+ table[MESA_FORMAT_R16] = pack_float_R16;
+ table[MESA_FORMAT_RG1616] = pack_float_RG1616;
+ table[MESA_FORMAT_RG1616_REV] = pack_float_RG1616_REV;
+ table[MESA_FORMAT_ARGB2101010] = pack_float_ARGB2101010;
+
+ /* should never convert RGBA to these formats */
+ table[MESA_FORMAT_Z24_S8] = NULL;
+ table[MESA_FORMAT_S8_Z24] = NULL;
+ table[MESA_FORMAT_Z16] = NULL;
+ table[MESA_FORMAT_X8_Z24] = NULL;
+ table[MESA_FORMAT_Z24_X8] = NULL;
+ table[MESA_FORMAT_Z32] = NULL;
+ table[MESA_FORMAT_S8] = NULL;
+
+ table[MESA_FORMAT_SRGB8] = pack_float_SRGB8;
+ table[MESA_FORMAT_SRGBA8] = pack_float_SRGBA8;
+ table[MESA_FORMAT_SARGB8] = pack_float_SARGB8;
+ table[MESA_FORMAT_SL8] = pack_float_SL8;
+ table[MESA_FORMAT_SLA8] = pack_float_SLA8;
+
+ /* n/a */
+ table[MESA_FORMAT_SRGB_DXT1] = NULL;
+ table[MESA_FORMAT_SRGBA_DXT1] = NULL;
+ table[MESA_FORMAT_SRGBA_DXT3] = NULL;
+ table[MESA_FORMAT_SRGBA_DXT5] = NULL;
+
+ table[MESA_FORMAT_RGB_FXT1] = NULL;
+ table[MESA_FORMAT_RGBA_FXT1] = NULL;
+ table[MESA_FORMAT_RGB_DXT1] = NULL;
+ table[MESA_FORMAT_RGBA_DXT1] = NULL;
+ table[MESA_FORMAT_RGBA_DXT3] = NULL;
+ table[MESA_FORMAT_RGBA_DXT5] = NULL;
+
+ table[MESA_FORMAT_RGBA_FLOAT32] = pack_float_RGBA_FLOAT32;
+ table[MESA_FORMAT_RGBA_FLOAT16] = pack_float_RGBA_FLOAT16;
+ table[MESA_FORMAT_RGB_FLOAT32] = pack_float_RGB_FLOAT32;
+ table[MESA_FORMAT_RGB_FLOAT16] = pack_float_RGB_FLOAT16;
+ table[MESA_FORMAT_ALPHA_FLOAT32] = pack_float_ALPHA_FLOAT32;
+ table[MESA_FORMAT_ALPHA_FLOAT16] = pack_float_ALPHA_FLOAT16;
+ table[MESA_FORMAT_LUMINANCE_FLOAT32] = pack_float_LUMINANCE_FLOAT32;
+ table[MESA_FORMAT_LUMINANCE_FLOAT16] = pack_float_LUMINANCE_FLOAT16;
+ table[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32] = pack_float_LUMINANCE_ALPHA_FLOAT32;
+ table[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16] = pack_float_LUMINANCE_ALPHA_FLOAT16;
+
+ table[MESA_FORMAT_INTENSITY_FLOAT32] = pack_float_LUMINANCE_FLOAT32;
+ table[MESA_FORMAT_INTENSITY_FLOAT16] = pack_float_LUMINANCE_FLOAT16;
+ table[MESA_FORMAT_R_FLOAT32] = pack_float_LUMINANCE_FLOAT32;
+ table[MESA_FORMAT_R_FLOAT16] = pack_float_LUMINANCE_FLOAT16;
+ table[MESA_FORMAT_RG_FLOAT32] = pack_float_RG_FLOAT32;
+ table[MESA_FORMAT_RG_FLOAT16] = pack_float_RG_FLOAT16;
+
+ /* n/a */
+ table[MESA_FORMAT_RGBA_INT8] = NULL;
+ table[MESA_FORMAT_RGBA_INT16] = NULL;
+ table[MESA_FORMAT_RGBA_INT32] = NULL;
+ table[MESA_FORMAT_RGBA_UINT8] = NULL;
+ table[MESA_FORMAT_RGBA_UINT16] = NULL;
+ table[MESA_FORMAT_RGBA_UINT32] = NULL;
+
+ table[MESA_FORMAT_DUDV8] = pack_float_DUDV8;
+
+ table[MESA_FORMAT_RGBA_16] = pack_float_RGBA_16;
+
+ table[MESA_FORMAT_SIGNED_R8] = pack_float_SIGNED_R8;
+ table[MESA_FORMAT_SIGNED_RG88_REV] = pack_float_SIGNED_RG88_REV;
+ table[MESA_FORMAT_SIGNED_RGBX8888] = pack_float_SIGNED_RGBX8888;
+ table[MESA_FORMAT_SIGNED_RGBA8888] = pack_float_SIGNED_RGBA8888;
+ table[MESA_FORMAT_SIGNED_RGBA8888_REV] = pack_float_SIGNED_RGBA8888_REV;
+ table[MESA_FORMAT_SIGNED_R16] = pack_float_SIGNED_R16;
+ table[MESA_FORMAT_SIGNED_GR1616] = pack_float_SIGNED_GR1616;
+ table[MESA_FORMAT_SIGNED_RGB_16] = pack_float_SIGNED_RGB_16;
+ table[MESA_FORMAT_SIGNED_RGBA_16] = pack_float_SIGNED_RGBA_16;
+ table[MESA_FORMAT_SIGNED_A8] = pack_float_SIGNED_A8;
+ table[MESA_FORMAT_SIGNED_L8] = pack_float_SIGNED_L8;
+ table[MESA_FORMAT_SIGNED_AL88] = pack_float_SIGNED_AL88;
+ table[MESA_FORMAT_SIGNED_I8] = pack_float_SIGNED_L8; /* reused */
+ table[MESA_FORMAT_SIGNED_A16] = pack_float_SIGNED_A16;
+ table[MESA_FORMAT_SIGNED_L16] = pack_float_SIGNED_L16;
+ table[MESA_FORMAT_SIGNED_AL1616] = pack_float_SIGNED_AL1616;
+ table[MESA_FORMAT_SIGNED_I16] = pack_float_SIGNED_L16; /* reused */
+
+ table[MESA_FORMAT_RGB9_E5_FLOAT] = pack_float_RGB9_E5_FLOAT;
+ table[MESA_FORMAT_R11_G11_B10_FLOAT] = pack_float_R11_G11_B10_FLOAT;
+
+ initialized = GL_TRUE;
+ }
+
+ return table[format];
+}
+
+
+
+static pack_float_rgba_row_func
+get_pack_float_rgba_row_function(gl_format format)
+{
+ static pack_float_rgba_row_func table[MESA_FORMAT_COUNT];
+ static GLboolean initialized = GL_FALSE;
+
+ if (!initialized) {
+ /* We don't need a special row packing function for each format.
+ * There's a generic fallback which uses a per-pixel packing function.
+ */
+ memset(table, 0, sizeof(table));
+
+ table[MESA_FORMAT_RGBA8888] = pack_row_float_RGBA8888;
+ table[MESA_FORMAT_RGBA8888_REV] = pack_row_float_RGBA8888_REV;
+ table[MESA_FORMAT_ARGB8888] = pack_row_float_ARGB8888;
+ table[MESA_FORMAT_ARGB8888_REV] = pack_row_float_ARGB8888_REV;
+ table[MESA_FORMAT_RGBX8888] = pack_row_float_RGBA8888; /* reused */
+ table[MESA_FORMAT_RGBX8888_REV] = pack_row_float_RGBA8888_REV; /* reused */
+ table[MESA_FORMAT_XRGB8888] = pack_row_float_XRGB8888;
+ table[MESA_FORMAT_XRGB8888_REV] = pack_row_float_XRGB8888_REV;
+ table[MESA_FORMAT_RGB888] = pack_row_float_RGB888;
+ table[MESA_FORMAT_BGR888] = pack_row_float_BGR888;
+ table[MESA_FORMAT_RGB565] = pack_row_float_RGB565;
+ table[MESA_FORMAT_RGB565_REV] = pack_row_float_RGB565_REV;
+
+ initialized = GL_TRUE;
+ }
+
+ return table[format];
+}
+
+
+
+static pack_ubyte_rgba_row_func
+get_pack_ubyte_rgba_row_function(gl_format format)
+{
+ static pack_ubyte_rgba_row_func table[MESA_FORMAT_COUNT];
+ static GLboolean initialized = GL_FALSE;
+
+ if (!initialized) {
+ /* We don't need a special row packing function for each format.
+ * There's a generic fallback which uses a per-pixel packing function.
+ */
+ memset(table, 0, sizeof(table));
+
+ table[MESA_FORMAT_RGBA8888] = pack_row_ubyte_RGBA8888;
+ table[MESA_FORMAT_RGBA8888_REV] = pack_row_ubyte_RGBA8888_REV;
+ table[MESA_FORMAT_ARGB8888] = pack_row_ubyte_ARGB8888;
+ table[MESA_FORMAT_ARGB8888_REV] = pack_row_ubyte_ARGB8888_REV;
+ table[MESA_FORMAT_RGBX8888] = pack_row_ubyte_RGBA8888; /* reused */
+ table[MESA_FORMAT_RGBX8888_REV] = pack_row_ubyte_RGBA8888_REV; /* reused */
+ table[MESA_FORMAT_XRGB8888] = pack_row_ubyte_XRGB8888;
+ table[MESA_FORMAT_XRGB8888_REV] = pack_row_ubyte_XRGB8888_REV;
+ table[MESA_FORMAT_RGB888] = pack_row_ubyte_RGB888;
+ table[MESA_FORMAT_BGR888] = pack_row_ubyte_BGR888;
+ table[MESA_FORMAT_RGB565] = pack_row_ubyte_RGB565;
+ table[MESA_FORMAT_RGB565_REV] = pack_row_ubyte_RGB565_REV;
+
+ initialized = GL_TRUE;
+ }
+
+ return table[format];
+}
+
+
+
+/**
+ * Pack a row of GLfloat rgba[4] values to the destination.
+ */
+void
+_mesa_pack_float_rgba_row(gl_format format, GLuint n,
+ const GLfloat src[][4], void *dst)
+{
+ pack_float_rgba_row_func packrow = get_pack_float_rgba_row_function(format);
+ if (packrow) {
+ /* use "fast" function */
+ packrow(n, src, dst);
+ }
+ else {
+ /* slower fallback */
+ gl_pack_float_rgba_func pack = _mesa_get_pack_float_rgba_function(format);
+ GLuint dstStride = _mesa_get_format_bytes(format);
+ GLubyte *dstPtr = (GLubyte *) dst;
+ GLuint i;
+
+ assert(pack);
+ if (!pack)
+ return;
+
+ for (i = 0; i < n; i++) {
+ pack(src[i], dstPtr);
+ dstPtr += dstStride;
+ }
+ }
+}
+
+
+/**
+ * Pack a row of GLubyte rgba[4] values to the destination.
+ */
+void
+_mesa_pack_ubyte_rgba_row(gl_format format, GLuint n,
+ const GLubyte src[][4], void *dst)
+{
+ pack_ubyte_rgba_row_func packrow = get_pack_ubyte_rgba_row_function(format);
+ if (packrow) {
+ /* use "fast" function */
+ packrow(n, src, dst);
+ }
+ else {
+ /* slower fallback */
+ gl_pack_ubyte_rgba_func pack = _mesa_get_pack_ubyte_rgba_function(format);
+ const GLuint stride = _mesa_get_format_bytes(format);
+ GLubyte *d = ((GLubyte *) dst);
+ GLuint i;
+
+ assert(pack);
+ if (!pack)
+ return;
+
+ for (i = 0; i < n; i++) {
+ pack(src[i], d);
+ d += stride;
+ }
+ }
+}
+
+
+/**
+ ** Pack float Z pixels
+ **/
+
+static void
+pack_float_z_Z24_S8(const GLfloat *src, void *dst)
+{
+ /* don't disturb the stencil values */
+ GLuint *d = ((GLuint *) dst);
+ const GLdouble scale = (GLdouble) 0xffffff;
+ GLuint s = *d & 0xff;
+ GLuint z = (GLuint) (*src * scale);
+ assert(z <= 0xffffff);
+ *d = (z << 8) | s;
+}
+
+static void
+pack_float_z_S8_Z24(const GLfloat *src, void *dst)
+{
+ /* don't disturb the stencil values */
+ GLuint *d = ((GLuint *) dst);
+ const GLdouble scale = (GLdouble) 0xffffff;
+ GLuint s = *d & 0xff000000;
+ GLuint z = (GLuint) (*src * scale);
+ assert(z <= 0xffffff);
+ *d = s | z;
+}
+
+static void
+pack_float_z_Z16(const GLfloat *src, void *dst)
+{
+ GLushort *d = ((GLushort *) dst);
+ const GLfloat scale = (GLfloat) 0xffff;
+ *d = (GLushort) (*src * scale);
+}
+
+static void
+pack_float_z_Z32(const GLfloat *src, void *dst)
+{
+ GLuint *d = ((GLuint *) dst);
+ const GLdouble scale = (GLdouble) 0xffffffff;
+ *d = (GLuint) (*src * scale);
+}
+
+static void
+pack_float_z_Z32_FLOAT(const GLfloat *src, void *dst)
+{
+ GLfloat *d = (GLfloat *) dst;
+ *d = *src;
+}
+
+gl_pack_float_z_func
+_mesa_get_pack_float_z_func(gl_format format)
+{
+ switch (format) {
+ case MESA_FORMAT_Z24_S8:
+ case MESA_FORMAT_Z24_X8:
+ return pack_float_z_Z24_S8;
+ case MESA_FORMAT_S8_Z24:
+ case MESA_FORMAT_X8_Z24:
+ return pack_float_z_S8_Z24;
+ case MESA_FORMAT_Z16:
+ return pack_float_z_Z16;
+ case MESA_FORMAT_Z32:
+ return pack_float_z_Z32;
+ case MESA_FORMAT_Z32_FLOAT:
+ case MESA_FORMAT_Z32_FLOAT_X24S8:
+ return pack_float_z_Z32_FLOAT;
+ default:
+ _mesa_problem(NULL,
+ "unexpected format in _mesa_get_pack_float_z_func()");
+ return NULL;
+ }
+}
+
+
+
+/**
+ ** Pack uint Z pixels. The incoming src value is always in
+ ** the range [0, 2^32-1].
+ **/
+
+static void
+pack_uint_z_Z24_S8(const GLuint *src, void *dst)
+{
+ /* don't disturb the stencil values */
+ GLuint *d = ((GLuint *) dst);
+ GLuint s = *d & 0xff;
+ GLuint z = *src & 0xffffff00;
+ *d = z | s;
+}
+
+static void
+pack_uint_z_S8_Z24(const GLuint *src, void *dst)
+{
+ /* don't disturb the stencil values */
+ GLuint *d = ((GLuint *) dst);
+ GLuint s = *d & 0xff000000;
+ GLuint z = *src >> 8;
+ *d = s | z;
+}
+
+static void
+pack_uint_z_Z16(const GLuint *src, void *dst)
+{
+ GLushort *d = ((GLushort *) dst);
+ *d = *src >> 16;
+}
+
+static void
+pack_uint_z_Z32(const GLuint *src, void *dst)
+{
+ GLuint *d = ((GLuint *) dst);
+ *d = *src;
+}
+
+static void
+pack_uint_z_Z32_FLOAT(const GLuint *src, void *dst)
+{
+ GLuint *d = ((GLuint *) dst);
+ const GLdouble scale = 1.0 / (GLdouble) 0xffffffff;
+ *d = *src * scale;
+ assert(*d >= 0.0f);
+ assert(*d <= 1.0f);
+}
+
+static void
+pack_uint_z_Z32_FLOAT_X24S8(const GLuint *src, void *dst)
+{
+ GLfloat *d = ((GLfloat *) dst);
+ const GLdouble scale = 1.0 / (GLdouble) 0xffffffff;
+ *d = *src * scale;
+ assert(*d >= 0.0f);
+ assert(*d <= 1.0f);
+}
+
+gl_pack_uint_z_func
+_mesa_get_pack_uint_z_func(gl_format format)
+{
+ switch (format) {
+ case MESA_FORMAT_Z24_S8:
+ case MESA_FORMAT_Z24_X8:
+ return pack_uint_z_Z24_S8;
+ case MESA_FORMAT_S8_Z24:
+ case MESA_FORMAT_X8_Z24:
+ return pack_uint_z_S8_Z24;
+ case MESA_FORMAT_Z16:
+ return pack_uint_z_Z16;
+ case MESA_FORMAT_Z32:
+ return pack_uint_z_Z32;
+ case MESA_FORMAT_Z32_FLOAT:
+ return pack_uint_z_Z32_FLOAT;
+ case MESA_FORMAT_Z32_FLOAT_X24S8:
+ return pack_uint_z_Z32_FLOAT_X24S8;
+ default:
+ _mesa_problem(NULL, "unexpected format in _mesa_get_pack_uint_z_func()");
+ return NULL;
+ }
+}
+
+
+/**
+ ** Pack ubyte stencil pixels
+ **/
+
+static void
+pack_ubyte_stencil_Z24_S8(const GLubyte *src, void *dst)
+{
+ /* don't disturb the Z values */
+ GLuint *d = ((GLuint *) dst);
+ GLuint s = *src;
+ GLuint z = *d & 0xffffff00;
+ *d = z | s;
+}
+
+static void
+pack_ubyte_stencil_S8_Z24(const GLubyte *src, void *dst)
+{
+ /* don't disturb the Z values */
+ GLuint *d = ((GLuint *) dst);
+ GLuint s = *src << 24;
+ GLuint z = *d & 0xffffff;
+ *d = s | z;
+}
+
+static void
+pack_ubyte_stencil_S8(const GLubyte *src, void *dst)
+{
+ GLubyte *d = (GLubyte *) dst;
+ *d = *src;
+}
+
+static void
+pack_ubyte_stencil_Z32_FLOAT_X24S8(const GLubyte *src, void *dst)
+{
+ GLfloat *d = ((GLfloat *) dst);
+ d[1] = *src;
+}
+
+
+gl_pack_ubyte_stencil_func
+_mesa_get_pack_ubyte_stencil_func(gl_format format)
+{
+ switch (format) {
+ case MESA_FORMAT_Z24_S8:
+ return pack_ubyte_stencil_Z24_S8;
+ case MESA_FORMAT_S8_Z24:
+ return pack_ubyte_stencil_S8_Z24;
+ case MESA_FORMAT_S8:
+ return pack_ubyte_stencil_S8;
+ case MESA_FORMAT_Z32_FLOAT_X24S8:
+ return pack_ubyte_stencil_Z32_FLOAT_X24S8;
+ default:
+ _mesa_problem(NULL,
+ "unexpected format in _mesa_pack_ubyte_stencil_func()");
+ return NULL;
+ }
+}
+
+
+
+void
+_mesa_pack_float_z_row(gl_format format, GLuint n,
+ const GLfloat *src, void *dst)
+{
+ switch (format) {
+ case MESA_FORMAT_Z24_S8:
+ case MESA_FORMAT_Z24_X8:
+ {
+ /* don't disturb the stencil values */
+ GLuint *d = ((GLuint *) dst);
+ const GLdouble scale = (GLdouble) 0xffffff;
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ GLuint s = d[i] & 0xff;
+ GLuint z = (GLuint) (src[i] * scale);
+ assert(z <= 0xffffff);
+ d[i] = (z << 8) | s;
+ }
+ }
+ break;
+ case MESA_FORMAT_S8_Z24:
+ case MESA_FORMAT_X8_Z24:
+ {
+ /* don't disturb the stencil values */
+ GLuint *d = ((GLuint *) dst);
+ const GLdouble scale = (GLdouble) 0xffffff;
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ GLuint s = d[i] & 0xff000000;
+ GLuint z = (GLuint) (src[i] * scale);
+ assert(z <= 0xffffff);
+ d[i] = s | z;
+ }
+ }
+ break;
+ case MESA_FORMAT_Z16:
+ {
+ GLushort *d = ((GLushort *) dst);
+ const GLfloat scale = (GLfloat) 0xffff;
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ d[i] = (GLushort) (src[i] * scale);
+ }
+ }
+ break;
+ case MESA_FORMAT_Z32:
+ {
+ GLuint *d = ((GLuint *) dst);
+ const GLdouble scale = (GLdouble) 0xffffffff;
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ d[i] = (GLuint) (src[i] * scale);
+ }
+ }
+ break;
+ case MESA_FORMAT_Z32_FLOAT:
+ memcpy(dst, src, n * sizeof(GLfloat));
+ break;
+ case MESA_FORMAT_Z32_FLOAT_X24S8:
+ {
+ GLfloat *d = ((GLfloat *) dst);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ d[i * 2] = src[i];
+ }
+ }
+ break;
+ default:
+ _mesa_problem(NULL, "unexpected format in _mesa_pack_float_z_row()");
+ }
+}
+
+
+/**
+ * The incoming Z values are always in the range [0, 0xffffffff].
+ */
+void
+_mesa_pack_uint_z_row(gl_format format, GLuint n,
+ const GLuint *src, void *dst)
+{
+ switch (format) {
+ case MESA_FORMAT_Z24_S8:
+ case MESA_FORMAT_Z24_X8:
+ {
+ /* don't disturb the stencil values */
+ GLuint *d = ((GLuint *) dst);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ GLuint s = d[i] & 0xff;
+ GLuint z = src[i] & 0xffffff00;
+ d[i] = z | s;
+ }
+ }
+ break;
+ case MESA_FORMAT_S8_Z24:
+ case MESA_FORMAT_X8_Z24:
+ {
+ /* don't disturb the stencil values */
+ GLuint *d = ((GLuint *) dst);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ GLuint s = d[i] & 0xff000000;
+ GLuint z = src[i] >> 8;
+ d[i] = s | z;
+ }
+ }
+ break;
+ case MESA_FORMAT_Z16:
+ {
+ GLushort *d = ((GLushort *) dst);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ d[i] = src[i] >> 16;
+ }
+ }
+ break;
+ case MESA_FORMAT_Z32:
+ memcpy(dst, src, n * sizeof(GLfloat));
+ break;
+ case MESA_FORMAT_Z32_FLOAT:
+ {
+ GLuint *d = ((GLuint *) dst);
+ const GLdouble scale = 1.0 / (GLdouble) 0xffffffff;
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ d[i] = src[i] * scale;
+ assert(d[i] >= 0.0f);
+ assert(d[i] <= 1.0f);
+ }
+ }
+ break;
+ case MESA_FORMAT_Z32_FLOAT_X24S8:
+ {
+ GLfloat *d = ((GLfloat *) dst);
+ const GLdouble scale = 1.0 / (GLdouble) 0xffffffff;
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ d[i * 2] = src[i] * scale;
+ assert(d[i * 2] >= 0.0f);
+ assert(d[i * 2] <= 1.0f);
+ }
+ }
+ break;
+ default:
+ _mesa_problem(NULL, "unexpected format in _mesa_pack_uint_z_row()");
+ }
+}
+
+
+void
+_mesa_pack_ubyte_stencil_row(gl_format format, GLuint n,
+ const GLubyte *src, void *dst)
+{
+ switch (format) {
+ case MESA_FORMAT_Z24_S8:
+ {
+ /* don't disturb the Z values */
+ GLuint *d = ((GLuint *) dst);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ GLuint s = src[i];
+ GLuint z = d[i] & 0xffffff00;
+ d[i] = z | s;
+ }
+ }
+ break;
+ case MESA_FORMAT_S8_Z24:
+ {
+ /* don't disturb the Z values */
+ GLuint *d = ((GLuint *) dst);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ GLuint s = src[i] << 24;
+ GLuint z = d[i] & 0xffffff;
+ d[i] = s | z;
+ }
+ }
+ break;
+ case MESA_FORMAT_S8:
+ memcpy(dst, src, n * sizeof(GLubyte));
+ break;
+ case MESA_FORMAT_Z32_FLOAT_X24S8:
+ {
+ GLfloat *d = ((GLfloat *) dst);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ d[i * 2 + 1] = src[i];
+ }
+ }
+ break;
+ default:
+ _mesa_problem(NULL, "unexpected format in _mesa_pack_ubyte_stencil_row()");
+ }
+}
+
+
+/**
+ * Incoming Z/stencil values are always in uint_24_8 format.
+ */
+void
+_mesa_pack_uint_24_8_depth_stencil_row(gl_format format, GLuint n,
+ const GLuint *src, void *dst)
+{
+ switch (format) {
+ case MESA_FORMAT_Z24_S8:
+ memcpy(dst, src, n * sizeof(GLuint));
+ break;
+ case MESA_FORMAT_S8_Z24:
+ {
+ GLuint *d = ((GLuint *) dst);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ GLuint s = src[i] << 24;
+ GLuint z = src[i] >> 8;
+ d[i] = s | z;
+ }
+ }
+ break;
+ default:
+ _mesa_problem(NULL, "bad format %s in _mesa_pack_ubyte_s_row",
+ _mesa_get_format_name(format));
+ return;
+ }
+}
diff --git a/mesalib/src/mesa/main/format_pack.h b/mesalib/src/mesa/main/format_pack.h
new file mode 100644
index 000000000..7df135632
--- /dev/null
+++ b/mesalib/src/mesa/main/format_pack.h
@@ -0,0 +1,98 @@
+/*
+ * Mesa 3-D graphics library
+ *
+ * Copyright (c) 2011 VMware, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+
+#ifndef FORMAT_PACK_H
+#define FORMAT_PACK_H
+
+
+#include "formats.h"
+
+
+/** Pack a GLubyte rgba[4] color to dest address */
+typedef void (*gl_pack_ubyte_rgba_func)(const GLubyte src[4], void *dst);
+
+/** Pack a GLfloat rgba[4] color to dest address */
+typedef void (*gl_pack_float_rgba_func)(const GLfloat src[4], void *dst);
+
+/** Pack a GLfloat Z value to dest address */
+typedef void (*gl_pack_float_z_func)(const GLfloat *src, void *dst);
+
+/** Pack a GLuint Z value to dest address */
+typedef void (*gl_pack_uint_z_func)(const GLuint *src, void *dst);
+
+/** Pack a GLubyte stencil value to dest address */
+typedef void (*gl_pack_ubyte_stencil_func)(const GLubyte *src, void *dst);
+
+
+
+
+extern gl_pack_ubyte_rgba_func
+_mesa_get_pack_ubyte_rgba_function(gl_format format);
+
+
+extern gl_pack_float_rgba_func
+_mesa_get_pack_float_rgba_function(gl_format format);
+
+
+extern gl_pack_float_z_func
+_mesa_get_pack_float_z_func(gl_format format);
+
+
+extern gl_pack_uint_z_func
+_mesa_get_pack_uint_z_func(gl_format format);
+
+
+extern gl_pack_ubyte_stencil_func
+_mesa_get_pack_ubyte_stencil_func(gl_format format);
+
+
+
+extern void
+_mesa_pack_float_rgba_row(gl_format format, GLuint n,
+ const GLfloat src[][4], void *dst);
+
+extern void
+_mesa_pack_ubyte_rgba_row(gl_format format, GLuint n,
+ const GLubyte src[][4], void *dst);
+
+
+
+extern void
+_mesa_pack_float_z_row(gl_format format, GLuint n,
+ const GLfloat *src, void *dst);
+
+extern void
+_mesa_pack_uint_z_row(gl_format format, GLuint n,
+ const GLuint *src, void *dst);
+
+extern void
+_mesa_pack_ubyte_stencil_row(gl_format format, GLuint n,
+ const GLubyte *src, void *dst);
+
+extern void
+_mesa_pack_uint_24_8_depth_stencil_row(gl_format format, GLuint n,
+ const GLuint *src, void *dst);
+
+
+#endif
diff --git a/mesalib/src/mesa/main/format_unpack.c b/mesalib/src/mesa/main/format_unpack.c
index f821c2be4..4f23f3dec 100644
--- a/mesalib/src/mesa/main/format_unpack.c
+++ b/mesalib/src/mesa/main/format_unpack.c
@@ -587,7 +587,7 @@ unpack_Z24_S8(const void *src, GLfloat dst[][4], GLuint n)
{
/* only return Z, not stencil data */
const GLuint *s = ((const GLuint *) src);
- const GLfloat scale = 1.0F / (GLfloat) 0xffffff;
+ const GLdouble scale = 1.0 / (GLdouble) 0xffffff;
GLuint i;
for (i = 0; i < n; i++) {
dst[i][0] =
@@ -604,7 +604,7 @@ unpack_S8_Z24(const void *src, GLfloat dst[][4], GLuint n)
{
/* only return Z, not stencil data */
const GLuint *s = ((const GLuint *) src);
- const GLfloat scale = 1.0F / (GLfloat) 0xffffff;
+ const GLdouble scale = 1.0 / (GLdouble) 0xffffff;
GLuint i;
for (i = 0; i < n; i++) {
dst[i][0] =
@@ -1761,7 +1761,7 @@ unpack_float_z_Z24_X8(GLuint n, const void *src, GLfloat *dst)
{
/* only return Z, not stencil data */
const GLuint *s = ((const GLuint *) src);
- const GLfloat scale = 1.0F / (GLfloat) 0xffffff;
+ const GLdouble scale = 1.0 / (GLdouble) 0xffffff;
GLuint i;
for (i = 0; i < n; i++) {
dst[i] = (s[i] >> 8) * scale;
@@ -1775,7 +1775,7 @@ unpack_float_z_X8_Z24(GLuint n, const void *src, GLfloat *dst)
{
/* only return Z, not stencil data */
const GLuint *s = ((const GLuint *) src);
- const GLfloat scale = 1.0F / (GLfloat) 0xffffff;
+ const GLdouble scale = 1.0 / (GLdouble) 0xffffff;
GLuint i;
for (i = 0; i < n; i++) {
dst[i] = (s[i] & 0x00ffffff) * scale;
diff --git a/mesalib/src/mesa/main/formats.c b/mesalib/src/mesa/main/formats.c
index 595da773b..1f83a5368 100644
--- a/mesalib/src/mesa/main/formats.c
+++ b/mesalib/src/mesa/main/formats.c
@@ -1553,6 +1553,8 @@ _mesa_get_format_bytes(gl_format format)
{
const struct gl_format_info *info = _mesa_get_format_info(format);
ASSERT(info->BytesPerBlock);
+ ASSERT(info->BytesPerBlock <= MAX_PIXEL_BYTES ||
+ _mesa_is_format_compressed(format));
return info->BytesPerBlock;
}
diff --git a/mesalib/src/mesa/main/formats.h b/mesalib/src/mesa/main/formats.h
index 3960f028e..e6b429d5f 100644
--- a/mesalib/src/mesa/main/formats.h
+++ b/mesalib/src/mesa/main/formats.h
@@ -47,6 +47,14 @@ extern "C" {
/**
+ * Max number of bytes for any non-compressed pixel format below, or for
+ * intermediate pixel storage in Mesa. This should never be less than
+ * 16. Maybe 32 someday?
+ */
+#define MAX_PIXEL_BYTES 16
+
+
+/**
* Mesa texture/renderbuffer image formats.
*/
typedef enum
diff --git a/mesalib/src/mesa/main/framebuffer.c b/mesalib/src/mesa/main/framebuffer.c
index 8d0763db3..e30f31a39 100644
--- a/mesalib/src/mesa/main/framebuffer.c
+++ b/mesalib/src/mesa/main/framebuffer.c
@@ -879,6 +879,7 @@ renderbuffer_exists(struct gl_context *ctx,
case GL_BGRA:
case GL_ABGR_EXT:
case GL_RED_INTEGER_EXT:
+ case GL_RG_INTEGER:
case GL_GREEN_INTEGER_EXT:
case GL_BLUE_INTEGER_EXT:
case GL_ALPHA_INTEGER_EXT:
diff --git a/mesalib/src/mesa/main/image.c b/mesalib/src/mesa/main/image.c
index b266e26c6..b37cd7e7d 100644
--- a/mesalib/src/mesa/main/image.c
+++ b/mesalib/src/mesa/main/image.c
@@ -238,6 +238,7 @@ _mesa_components_in_format( GLenum format )
case GL_DEPTH_STENCIL_EXT:
case GL_DUDV_ATI:
case GL_DU8DV8_ATI:
+ case GL_RG_INTEGER:
return 2;
case GL_RGB:
@@ -527,6 +528,7 @@ _mesa_is_legal_format_and_type(const struct gl_context *ctx,
case GL_GREEN_INTEGER_EXT:
case GL_BLUE_INTEGER_EXT:
case GL_ALPHA_INTEGER_EXT:
+ case GL_RG_INTEGER:
switch (type) {
case GL_BYTE:
case GL_UNSIGNED_BYTE:
@@ -751,6 +753,7 @@ _mesa_is_color_format(GLenum format)
case GL_RGBA_INTEGER_EXT:
case GL_BGR_INTEGER_EXT:
case GL_BGRA_INTEGER_EXT:
+ case GL_RG_INTEGER:
case GL_LUMINANCE_INTEGER_EXT:
case GL_LUMINANCE_ALPHA_INTEGER_EXT:
/* sized integer formats */
@@ -954,6 +957,7 @@ _mesa_is_integer_format(GLenum format)
case GL_BGRA_INTEGER_EXT:
case GL_LUMINANCE_INTEGER_EXT:
case GL_LUMINANCE_ALPHA_INTEGER_EXT:
+ case GL_RG_INTEGER:
/* specific integer formats */
case GL_RGBA32UI_EXT:
case GL_RGB32UI_EXT:
@@ -1160,32 +1164,30 @@ _mesa_base_format_has_channel(GLenum base_format, GLenum pname)
/**
- * Return the address of a specific pixel in an image (1D, 2D or 3D).
+ * Return the byte offset of a specific pixel in an image (1D, 2D or 3D).
*
* Pixel unpacking/packing parameters are observed according to \p packing.
*
* \param dimensions either 1, 2 or 3 to indicate dimensionality of image
- * \param image starting address of image data
- * \param width the image width
- * \param height theimage height
- * \param format the pixel format
- * \param type the pixel data type
* \param packing the pixelstore attributes
+ * \param width the image width
+ * \param height the image height
+ * \param format the pixel format (must be validated beforehand)
+ * \param type the pixel data type (must be validated beforehand)
* \param img which image in the volume (0 for 1D or 2D images)
* \param row row of pixel in the image (0 for 1D images)
* \param column column of pixel in the image
- *
- * \return address of pixel on success, or NULL on error.
+ *
+ * \return offset of pixel.
*
* \sa gl_pixelstore_attrib.
*/
-GLvoid *
-_mesa_image_address( GLuint dimensions,
- const struct gl_pixelstore_attrib *packing,
- const GLvoid *image,
- GLsizei width, GLsizei height,
- GLenum format, GLenum type,
- GLint img, GLint row, GLint column )
+GLintptr
+_mesa_image_offset( GLuint dimensions,
+ const struct gl_pixelstore_attrib *packing,
+ GLsizei width, GLsizei height,
+ GLenum format, GLenum type,
+ GLint img, GLint row, GLint column )
{
GLint alignment; /* 1, 2 or 4 */
GLint pixels_per_row;
@@ -1193,7 +1195,7 @@ _mesa_image_address( GLuint dimensions,
GLint skiprows;
GLint skippixels;
GLint skipimages; /* for 3-D volume images */
- GLubyte *pixel_addr;
+ GLintptr offset;
ASSERT(dimensions >= 1 && dimensions <= 3);
@@ -1219,30 +1221,20 @@ _mesa_image_address( GLuint dimensions,
if (type == GL_BITMAP) {
/* BITMAP data */
- GLint comp_per_pixel; /* components per pixel */
- GLint bytes_per_comp; /* bytes per component */
GLint bytes_per_row;
GLint bytes_per_image;
+ /* components per pixel for color or stencil index: */
+ const GLint comp_per_pixel = 1;
- /* Compute bytes per component */
- bytes_per_comp = _mesa_sizeof_packed_type( type );
- if (bytes_per_comp < 0) {
- return NULL;
- }
-
- /* Compute number of components per pixel */
- comp_per_pixel = _mesa_components_in_format( format );
- if (comp_per_pixel < 0) {
- return NULL;
- }
+ /* The pixel type and format should have been error checked earlier */
+ assert(format == GL_COLOR_INDEX || format == GL_STENCIL_INDEX);
bytes_per_row = alignment
* CEILING( comp_per_pixel*pixels_per_row, 8*alignment );
bytes_per_image = bytes_per_row * rows_per_image;
- pixel_addr = (GLubyte *) image
- + (skipimages + img) * bytes_per_image
+ offset = (skipimages + img) * bytes_per_image
+ (skiprows + row) * bytes_per_row
+ (skippixels + column) / 8;
}
@@ -1275,14 +1267,50 @@ _mesa_image_address( GLuint dimensions,
}
/* compute final pixel address */
- pixel_addr = (GLubyte *) image
- + (skipimages + img) * bytes_per_image
+ offset = (skipimages + img) * bytes_per_image
+ topOfImage
+ (skiprows + row) * bytes_per_row
+ (skippixels + column) * bytes_per_pixel;
}
- return (GLvoid *) pixel_addr;
+ return offset;
+}
+
+
+/**
+ * Return the address of a specific pixel in an image (1D, 2D or 3D).
+ *
+ * Pixel unpacking/packing parameters are observed according to \p packing.
+ *
+ * \param dimensions either 1, 2 or 3 to indicate dimensionality of image
+ * \param packing the pixelstore attributes
+ * \param image starting address of image data
+ * \param width the image width
+ * \param height the image height
+ * \param format the pixel format (must be validated beforehand)
+ * \param type the pixel data type (must be validated beforehand)
+ * \param img which image in the volume (0 for 1D or 2D images)
+ * \param row row of pixel in the image (0 for 1D images)
+ * \param column column of pixel in the image
+ *
+ * \return address of pixel.
+ *
+ * \sa gl_pixelstore_attrib.
+ */
+GLvoid *
+_mesa_image_address( GLuint dimensions,
+ const struct gl_pixelstore_attrib *packing,
+ const GLvoid *image,
+ GLsizei width, GLsizei height,
+ GLenum format, GLenum type,
+ GLint img, GLint row, GLint column )
+{
+ const GLubyte *addr = (const GLubyte *) image;
+
+ addr += _mesa_image_offset(dimensions, packing, width, height,
+ format, type, img, row, column);
+
+ return (GLvoid *) addr;
}
@@ -1520,9 +1548,13 @@ _mesa_convert_colors(GLenum srcType, const GLvoid *src,
GLenum dstType, GLvoid *dst,
GLuint count, const GLubyte mask[])
{
- GLuint tempBuffer[MAX_WIDTH][4];
+ GLuint *tempBuffer;
const GLboolean useTemp = (src == dst);
+ tempBuffer = malloc(count * MAX_PIXEL_BYTES);
+ if (!tempBuffer)
+ return;
+
ASSERT(srcType != dstType);
switch (srcType) {
@@ -1624,6 +1656,8 @@ _mesa_convert_colors(GLenum srcType, const GLvoid *src,
default:
_mesa_problem(NULL, "Invalid datatype in _mesa_convert_colors");
}
+
+ free(tempBuffer);
}
diff --git a/mesalib/src/mesa/main/image.h b/mesalib/src/mesa/main/image.h
index b606545b7..e4961ed3d 100644
--- a/mesalib/src/mesa/main/image.h
+++ b/mesalib/src/mesa/main/image.h
@@ -87,6 +87,13 @@ _mesa_is_compressed_format(struct gl_context *ctx, GLenum format);
extern GLboolean
_mesa_base_format_has_channel(GLenum base_format, GLenum pname);
+extern GLintptr
+_mesa_image_offset( GLuint dimensions,
+ const struct gl_pixelstore_attrib *packing,
+ GLsizei width, GLsizei height,
+ GLenum format, GLenum type,
+ GLint img, GLint row, GLint column );
+
extern GLvoid *
_mesa_image_address( GLuint dimensions,
const struct gl_pixelstore_attrib *packing,
diff --git a/mesalib/src/mesa/main/pack.c b/mesalib/src/mesa/main/pack.c
index 0bd4ff199..2933ff638 100644
--- a/mesalib/src/mesa/main/pack.c
+++ b/mesalib/src/mesa/main/pack.c
@@ -467,6 +467,7 @@ _mesa_pack_rgba_span_int(struct gl_context *ctx, GLuint n, GLuint rgba[][4],
case GL_GREEN_INTEGER_EXT:
case GL_BLUE_INTEGER_EXT:
case GL_ALPHA_INTEGER_EXT:
+ case GL_RG_INTEGER:
case GL_RGB_INTEGER_EXT:
case GL_RGBA_INTEGER_EXT:
case GL_BGR_INTEGER_EXT:
@@ -490,6 +491,7 @@ _mesa_pack_rgba_span_int(struct gl_context *ctx, GLuint n, GLuint rgba[][4],
case GL_GREEN_INTEGER_EXT:
case GL_BLUE_INTEGER_EXT:
case GL_ALPHA_INTEGER_EXT:
+ case GL_RG_INTEGER:
case GL_RGB_INTEGER_EXT:
case GL_RGBA_INTEGER_EXT:
case GL_BGR_INTEGER_EXT:
@@ -3021,6 +3023,7 @@ extract_uint_rgba(GLuint n, GLuint rgba[][4],
srcFormat == GL_DU8DV8_ATI ||
srcFormat == GL_DUDV_ATI ||
srcFormat == GL_RED_INTEGER_EXT ||
+ srcFormat == GL_RG_INTEGER ||
srcFormat == GL_GREEN_INTEGER_EXT ||
srcFormat == GL_BLUE_INTEGER_EXT ||
srcFormat == GL_ALPHA_INTEGER_EXT ||
@@ -3980,6 +3983,7 @@ _mesa_unpack_color_span_uint(struct gl_context *ctx,
srcFormat == GL_GREEN_INTEGER_EXT ||
srcFormat == GL_BLUE_INTEGER_EXT ||
srcFormat == GL_ALPHA_INTEGER_EXT ||
+ srcFormat == GL_RG_INTEGER ||
srcFormat == GL_RGB_INTEGER_EXT ||
srcFormat == GL_RGBA_INTEGER_EXT ||
srcFormat == GL_BGR_INTEGER_EXT ||
diff --git a/mesalib/src/mesa/main/pbo.c b/mesalib/src/mesa/main/pbo.c
index 41ff2ff44..d8fa9191d 100644
--- a/mesalib/src/mesa/main/pbo.c
+++ b/mesalib/src/mesa/main/pbo.c
@@ -68,8 +68,8 @@ _mesa_validate_pbo_access(GLuint dimensions,
GLenum format, GLenum type, GLsizei clientMemSize,
const GLvoid *ptr)
{
- const GLvoid *start, *end, *offset;
- const GLubyte *sizeAddr; /* buffer size, cast to a pointer */
+ /* unsigned, to detect overflow/wrap-around */
+ uintptr_t start, end, offset, size;
/* If no PBO is bound, 'ptr' is a pointer to client memory containing
'clientMemSize' bytes.
@@ -78,10 +78,10 @@ _mesa_validate_pbo_access(GLuint dimensions,
*/
if (!_mesa_is_bufferobj(pack->BufferObj)) {
offset = 0;
- sizeAddr = ((const GLubyte *) 0) + clientMemSize;
+ size = clientMemSize;
} else {
- offset = ptr;
- sizeAddr = ((const GLubyte *) 0) + pack->BufferObj->Size;
+ offset = (uintptr_t)ptr;
+ size = pack->BufferObj->Size;
/* The ARB_pixel_buffer_object spec says:
* "INVALID_OPERATION is generated by ColorTable, ColorSubTable,
* ConvolutionFilter2D, ConvolutionFilter1D, SeparableFilter2D,
@@ -93,27 +93,30 @@ _mesa_validate_pbo_access(GLuint dimensions,
* parameter."
*/
if (type != GL_BITMAP &&
- ((GLintptr)offset % _mesa_sizeof_packed_type(type)))
+ (offset % _mesa_sizeof_packed_type(type)))
return GL_FALSE;
}
- if (sizeAddr == 0)
+ if (size == 0)
/* no buffer! */
return GL_FALSE;
/* get the offset to the first pixel we'll read/write */
- start = _mesa_image_address(dimensions, pack, offset, width, height,
- format, type, 0, 0, 0);
+ start = _mesa_image_offset(dimensions, pack, width, height,
+ format, type, 0, 0, 0);
/* get the offset to just past the last pixel we'll read/write */
- end = _mesa_image_address(dimensions, pack, offset, width, height,
- format, type, depth-1, height-1, width);
+ end = _mesa_image_offset(dimensions, pack, width, height,
+ format, type, depth-1, height-1, width);
- if ((const GLubyte *) start > sizeAddr) {
+ start += offset;
+ end += offset;
+
+ if (start > size) {
/* This will catch negative values / wrap-around */
return GL_FALSE;
}
- if ((const GLubyte *) end > sizeAddr) {
+ if (end > size) {
/* Image read/write goes beyond end of buffer */
return GL_FALSE;
}
diff --git a/mesalib/src/mesa/main/readpix.c b/mesalib/src/mesa/main/readpix.c
index a7b7ed7f2..38b9c64ed 100644
--- a/mesalib/src/mesa/main/readpix.c
+++ b/mesalib/src/mesa/main/readpix.c
@@ -252,10 +252,7 @@ slow_read_rgba_pixels( struct gl_context *ctx,
{
struct gl_renderbuffer *rb = ctx->ReadBuffer->_ColorReadBuffer;
const gl_format rbFormat = _mesa_get_srgb_format_linear(rb->Format);
- union {
- float f[MAX_WIDTH][4];
- unsigned int i[MAX_WIDTH][4];
- } rgba;
+ void *rgba;
GLubyte *dst, *map;
int dstStride, stride, j;
@@ -270,19 +267,27 @@ slow_read_rgba_pixels( struct gl_context *ctx,
return;
}
+ rgba = malloc(width * MAX_PIXEL_BYTES);
+ if (!rgba)
+ goto done;
+
for (j = 0; j < height; j++) {
if (_mesa_is_integer_format(format)) {
- _mesa_unpack_int_rgba_row(rbFormat, width, map, rgba.i);
- _mesa_pack_rgba_span_int(ctx, width, rgba.i, format, type, dst);
+ _mesa_unpack_int_rgba_row(rbFormat, width, map, (GLuint (*)[4]) rgba);
+ _mesa_pack_rgba_span_int(ctx, width, (GLuint (*)[4]) rgba, format,
+ type, dst);
} else {
- _mesa_unpack_rgba_row(rbFormat, width, map, rgba.f);
- _mesa_pack_rgba_span_float(ctx, width, rgba.f, format, type, dst,
- packing, transferOps);
+ _mesa_unpack_rgba_row(rbFormat, width, map, (GLfloat (*)[4]) rgba);
+ _mesa_pack_rgba_span_float(ctx, width, (GLfloat (*)[4]) rgba, format,
+ type, dst, packing, transferOps);
}
dst += dstStride;
map += stride;
}
+ free(rgba);
+
+done:
ctx->Driver.UnmapRenderbuffer(ctx, rb);
}
diff --git a/mesalib/src/mesa/main/renderbuffer.c b/mesalib/src/mesa/main/renderbuffer.c
index 24060e695..d82b19ad5 100644
--- a/mesalib/src/mesa/main/renderbuffer.c
+++ b/mesalib/src/mesa/main/renderbuffer.c
@@ -23,18 +23,6 @@
*/
-/**
- * Functions for allocating/managing renderbuffers.
- * Also, routines for reading/writing software-based renderbuffer data as
- * ubytes, ushorts, uints, etc.
- *
- * Down the road we'll use this for run-time support of 8, 16 and 32-bit
- * color channels. For example, Mesa may use 32-bit/float color channels
- * internally (swrast) and use wrapper renderbuffers to convert 32-bit
- * values down to 16 or 8-bit values for whatever kind of framebuffer we have.
- */
-
-
#include "glheader.h"
#include "imports.h"
#include "context.h"
@@ -44,1700 +32,6 @@
#include "renderbuffer.h"
-/*
- * Routines for get/put values in common buffer formats follow.
- */
-
-/* Returns a bytes per pixel of the DataType in the get/put span
- * functions for at least a subset of the available combinations a
- * renderbuffer can have.
- *
- * It would be nice to see gl_renderbuffer start talking about a
- * gl_format instead of a GLenum DataType.
- */
-static int
-get_datatype_bytes(struct gl_renderbuffer *rb)
-{
- int component_size;
-
- switch (rb->DataType) {
- case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:
- component_size = 8;
- break;
- case GL_FLOAT:
- case GL_UNSIGNED_INT:
- case GL_UNSIGNED_INT_24_8_EXT:
- component_size = 4;
- break;
- case GL_UNSIGNED_SHORT:
- component_size = 2;
- break;
- case GL_UNSIGNED_BYTE:
- component_size = 1;
- break;
- default:
- component_size = 1;
- assert(0);
- }
-
- switch (rb->_BaseFormat) {
- case GL_DEPTH_COMPONENT:
- case GL_DEPTH_STENCIL:
- return component_size;
- default:
- return 4 * component_size;
- }
-}
-
-/* This is commonly used by most of the accessors. */
-static void *
-get_pointer_generic(struct gl_context *ctx, struct gl_renderbuffer *rb,
- GLint x, GLint y)
-{
- if (!rb->Data)
- return NULL;
-
- return ((char *) rb->Data +
- (y * rb->RowStride + x) * _mesa_get_format_bytes(rb->Format));
-}
-
-/* GetRow() implementation for formats where DataType matches the rb->Format.
- */
-static void
-get_row_generic(struct gl_context *ctx, struct gl_renderbuffer *rb,
- GLuint count, GLint x, GLint y, void *values)
-{
- void *src = rb->GetPointer(ctx, rb, x, y);
- memcpy(values, src, count * _mesa_get_format_bytes(rb->Format));
-}
-
-/* Only used for float textures currently, but might also be used for
- * RGBA8888, RGBA16, etc.
- */
-static void
-get_values_generic(struct gl_context *ctx, struct gl_renderbuffer *rb,
- GLuint count, const GLint x[], const GLint y[], void *values)
-{
- int format_bytes = _mesa_get_format_bytes(rb->Format) / sizeof(GLfloat);
- GLuint i;
-
- for (i = 0; i < count; i++) {
- const void *src = rb->GetPointer(ctx, rb, x[i], y[i]);
- char *dst = (char *) values + i * format_bytes;
- memcpy(dst, src, format_bytes);
- }
-}
-
-/* For the GL_RED/GL_RG/GL_RGB format/DataType combinations (and
- * GL_LUMINANCE/GL_INTENSITY?), the Put functions are a matter of
- * storing those initial components of the value per pixel into the
- * destination.
- */
-static void
-put_row_generic(struct gl_context *ctx, struct gl_renderbuffer *rb,
- GLuint count, GLint x, GLint y,
- const void *values, const GLubyte *mask)
-{
- void *row = rb->GetPointer(ctx, rb, x, y);
- int format_bytes = _mesa_get_format_bytes(rb->Format) / sizeof(GLfloat);
- int datatype_bytes = get_datatype_bytes(rb);
- unsigned int i;
-
- if (mask) {
- for (i = 0; i < count; i++) {
- char *dst = (char *) row + i * format_bytes;
- const char *src = (const char *) values + i * datatype_bytes;
-
- if (mask[i]) {
- memcpy(dst, src, format_bytes);
- }
- }
- }
- else {
- for (i = 0; i < count; i++) {
- char *dst = (char *) row + i * format_bytes;
- const char *src = (const char *) values + i * datatype_bytes;
- memcpy(dst, src, format_bytes);
- }
- }
-}
-
-static void
-put_mono_row_generic(struct gl_context *ctx, struct gl_renderbuffer *rb,
- GLuint count, GLint x, GLint y,
- const void *value, const GLubyte *mask)
-{
- void *row = rb->GetPointer(ctx, rb, x, y);
- int format_bytes = _mesa_get_format_bytes(rb->Format) / sizeof(GLfloat);
- unsigned int i;
-
- if (mask) {
- for (i = 0; i < count; i++) {
- char *dst = (char *) row + i * format_bytes;
- if (mask[i]) {
- memcpy(dst, value, format_bytes);
- }
- }
- }
- else {
- for (i = 0; i < count; i++) {
- char *dst = (char *) row + i * format_bytes;
- memcpy(dst, value, format_bytes);
- }
- }
-}
-
-
-static void
-put_values_generic(struct gl_context *ctx, struct gl_renderbuffer *rb,
- GLuint count, const GLint x[], const GLint y[],
- const void *values, const GLubyte *mask)
-{
- int format_bytes = _mesa_get_format_bytes(rb->Format) / sizeof(GLfloat);
- int datatype_bytes = get_datatype_bytes(rb);
- unsigned int i;
-
- for (i = 0; i < count; i++) {
- if (!mask || mask[i]) {
- void *dst = rb->GetPointer(ctx, rb, x[i], y[i]);
- const char *src = (const char *) values + i * datatype_bytes;
- memcpy(dst, src, format_bytes);
- }
- }
-}
-
-
-static void
-put_mono_values_generic(struct gl_context *ctx,
- struct gl_renderbuffer *rb,
- GLuint count, const GLint x[], const GLint y[],
- const void *value, const GLubyte *mask)
-{
- int format_bytes = _mesa_get_format_bytes(rb->Format) / sizeof(GLfloat);
- unsigned int i;
-
- for (i = 0; i < count; i++) {
- if (!mask || mask[i]) {
- void *dst = rb->GetPointer(ctx, rb, x[i], y[i]);
- memcpy(dst, value, format_bytes);
- }
- }
-}
-
-/**********************************************************************
- * Functions for buffers of 1 X GLubyte values.
- * Typically stencil.
- */
-
-static void
-get_values_ubyte(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
- const GLint x[], const GLint y[], void *values)
-{
- GLubyte *dst = (GLubyte *) values;
- GLuint i;
- ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
- for (i = 0; i < count; i++) {
- const GLubyte *src = (GLubyte *) rb->Data + y[i] * rb->RowStride + x[i];
- dst[i] = *src;
- }
-}
-
-
-static void
-put_row_ubyte(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
- GLint x, GLint y, const void *values, const GLubyte *mask)
-{
- const GLubyte *src = (const GLubyte *) values;
- GLubyte *dst = (GLubyte *) rb->Data + y * rb->RowStride + x;
- ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
- if (mask) {
- GLuint i;
- for (i = 0; i < count; i++) {
- if (mask[i]) {
- dst[i] = src[i];
- }
- }
- }
- else {
- memcpy(dst, values, count * sizeof(GLubyte));
- }
-}
-
-
-static void
-put_mono_row_ubyte(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
- GLint x, GLint y, const void *value, const GLubyte *mask)
-{
- const GLubyte val = *((const GLubyte *) value);
- GLubyte *dst = (GLubyte *) rb->Data + y * rb->RowStride + x;
- ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
- if (mask) {
- GLuint i;
- for (i = 0; i < count; i++) {
- if (mask[i]) {
- dst[i] = val;
- }
- }
- }
- else {
- GLuint i;
- for (i = 0; i < count; i++) {
- dst[i] = val;
- }
- }
-}
-
-
-static void
-put_values_ubyte(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
- const GLint x[], const GLint y[],
- const void *values, const GLubyte *mask)
-{
- const GLubyte *src = (const GLubyte *) values;
- GLuint i;
- ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
- for (i = 0; i < count; i++) {
- if (!mask || mask[i]) {
- GLubyte *dst = (GLubyte *) rb->Data + y[i] * rb->RowStride + x[i];
- *dst = src[i];
- }
- }
-}
-
-
-static void
-put_mono_values_ubyte(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
- const GLint x[], const GLint y[],
- const void *value, const GLubyte *mask)
-{
- const GLubyte val = *((const GLubyte *) value);
- GLuint i;
- ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
- for (i = 0; i < count; i++) {
- if (!mask || mask[i]) {
- GLubyte *dst = (GLubyte *) rb->Data + y[i] * rb->RowStride + x[i];
- *dst = val;
- }
- }
-}
-
-
-/**********************************************************************
- * Functions for buffers of 1 X GLushort values.
- * Typically depth/Z.
- */
-
-static void
-get_values_ushort(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
- const GLint x[], const GLint y[], void *values)
-{
- GLushort *dst = (GLushort *) values;
- GLuint i;
- ASSERT(rb->DataType == GL_UNSIGNED_SHORT);
- for (i = 0; i < count; i++) {
- const GLushort *src = (GLushort *) rb->Data + y[i] * rb->RowStride + x[i];
- dst[i] = *src;
- }
-}
-
-
-static void
-put_row_ushort(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
- GLint x, GLint y, const void *values, const GLubyte *mask)
-{
- const GLushort *src = (const GLushort *) values;
- GLushort *dst = (GLushort *) rb->Data + y * rb->RowStride + x;
- ASSERT(rb->DataType == GL_UNSIGNED_SHORT);
- if (mask) {
- GLuint i;
- for (i = 0; i < count; i++) {
- if (mask[i]) {
- dst[i] = src[i];
- }
- }
- }
- else {
- memcpy(dst, src, count * sizeof(GLushort));
- }
-}
-
-
-static void
-put_mono_row_ushort(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
- GLint x, GLint y, const void *value, const GLubyte *mask)
-{
- const GLushort val = *((const GLushort *) value);
- GLushort *dst = (GLushort *) rb->Data + y * rb->RowStride + x;
- ASSERT(rb->DataType == GL_UNSIGNED_SHORT);
- if (mask) {
- GLuint i;
- for (i = 0; i < count; i++) {
- if (mask[i]) {
- dst[i] = val;
- }
- }
- }
- else {
- GLuint i;
- for (i = 0; i < count; i++) {
- dst[i] = val;
- }
- }
-}
-
-
-static void
-put_values_ushort(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
- const GLint x[], const GLint y[], const void *values,
- const GLubyte *mask)
-{
- const GLushort *src = (const GLushort *) values;
- GLuint i;
- ASSERT(rb->DataType == GL_UNSIGNED_SHORT);
- for (i = 0; i < count; i++) {
- if (!mask || mask[i]) {
- GLushort *dst = (GLushort *) rb->Data + y[i] * rb->RowStride + x[i];
- *dst = src[i];
- }
- }
-}
-
-
-static void
-put_mono_values_ushort(struct gl_context *ctx, struct gl_renderbuffer *rb,
- GLuint count, const GLint x[], const GLint y[],
- const void *value, const GLubyte *mask)
-{
- const GLushort val = *((const GLushort *) value);
- ASSERT(rb->DataType == GL_UNSIGNED_SHORT);
- if (mask) {
- GLuint i;
- for (i = 0; i < count; i++) {
- if (mask[i]) {
- GLushort *dst = (GLushort *) rb->Data + y[i] * rb->RowStride + x[i];
- *dst = val;
- }
- }
- }
- else {
- GLuint i;
- for (i = 0; i < count; i++) {
- GLushort *dst = (GLushort *) rb->Data + y[i] * rb->RowStride + x[i];
- *dst = val;
- }
- }
-}
-
-
-/**********************************************************************
- * Functions for buffers of 1 X GLuint values.
- * Typically depth/Z or color index.
- */
-
-static void
-get_values_uint(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
- const GLint x[], const GLint y[], void *values)
-{
- GLuint *dst = (GLuint *) values;
- GLuint i;
- ASSERT(rb->DataType == GL_UNSIGNED_INT ||
- rb->DataType == GL_UNSIGNED_INT_24_8_EXT);
- for (i = 0; i < count; i++) {
- const GLuint *src = (GLuint *) rb->Data + y[i] * rb->RowStride + x[i];
- dst[i] = *src;
- }
-}
-
-
-static void
-put_row_uint(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
- GLint x, GLint y, const void *values, const GLubyte *mask)
-{
- const GLuint *src = (const GLuint *) values;
- GLuint *dst = (GLuint *) rb->Data + y * rb->RowStride + x;
- ASSERT(rb->DataType == GL_UNSIGNED_INT ||
- rb->DataType == GL_UNSIGNED_INT_24_8_EXT);
- if (mask) {
- GLuint i;
- for (i = 0; i < count; i++) {
- if (mask[i]) {
- dst[i] = src[i];
- }
- }
- }
- else {
- memcpy(dst, src, count * sizeof(GLuint));
- }
-}
-
-
-static void
-put_mono_row_uint(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
- GLint x, GLint y, const void *value, const GLubyte *mask)
-{
- const GLuint val = *((const GLuint *) value);
- GLuint *dst = (GLuint *) rb->Data + y * rb->RowStride + x;
- ASSERT(rb->DataType == GL_UNSIGNED_INT ||
- rb->DataType == GL_UNSIGNED_INT_24_8_EXT);
- if (mask) {
- GLuint i;
- for (i = 0; i < count; i++) {
- if (mask[i]) {
- dst[i] = val;
- }
- }
- }
- else {
- GLuint i;
- for (i = 0; i < count; i++) {
- dst[i] = val;
- }
- }
-}
-
-
-static void
-put_values_uint(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
- const GLint x[], const GLint y[], const void *values,
- const GLubyte *mask)
-{
- const GLuint *src = (const GLuint *) values;
- GLuint i;
- ASSERT(rb->DataType == GL_UNSIGNED_INT ||
- rb->DataType == GL_UNSIGNED_INT_24_8_EXT);
- for (i = 0; i < count; i++) {
- if (!mask || mask[i]) {
- GLuint *dst = (GLuint *) rb->Data + y[i] * rb->RowStride + x[i];
- *dst = src[i];
- }
- }
-}
-
-
-static void
-put_mono_values_uint(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
- const GLint x[], const GLint y[], const void *value,
- const GLubyte *mask)
-{
- const GLuint val = *((const GLuint *) value);
- GLuint i;
- ASSERT(rb->DataType == GL_UNSIGNED_INT ||
- rb->DataType == GL_UNSIGNED_INT_24_8_EXT);
- for (i = 0; i < count; i++) {
- if (!mask || mask[i]) {
- GLuint *dst = (GLuint *) rb->Data + y[i] * rb->RowStride + x[i];
- *dst = val;
- }
- }
-}
-
-
-/**********************************************************************
- * Functions for buffers of 3 X GLubyte (or GLbyte) values.
- * Typically color buffers.
- * NOTE: the incoming and outgoing colors are RGBA! We ignore incoming
- * alpha values and return 255 for outgoing alpha values.
- */
-
-static void *
-get_pointer_ubyte3(struct gl_context *ctx, struct gl_renderbuffer *rb,
- GLint x, GLint y)
-{
- ASSERT(rb->Format == MESA_FORMAT_RGB888);
- /* No direct access since this buffer is RGB but caller will be
- * treating it as if it were RGBA.
- */
- return NULL;
-}
-
-
-static void
-get_row_ubyte3(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
- GLint x, GLint y, void *values)
-{
- const GLubyte *src = ((const GLubyte *) rb->Data) +
- 3 * (y * rb->RowStride + x);
- GLubyte *dst = (GLubyte *) values;
- GLuint i;
- ASSERT(rb->Format == MESA_FORMAT_RGB888);
- ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
- for (i = 0; i < count; i++) {
- dst[i * 4 + 0] = src[i * 3 + 0];
- dst[i * 4 + 1] = src[i * 3 + 1];
- dst[i * 4 + 2] = src[i * 3 + 2];
- dst[i * 4 + 3] = 255;
- }
-}
-
-
-static void
-get_values_ubyte3(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
- const GLint x[], const GLint y[], void *values)
-{
- GLubyte *dst = (GLubyte *) values;
- GLuint i;
- ASSERT(rb->Format == MESA_FORMAT_RGB888);
- ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
- for (i = 0; i < count; i++) {
- const GLubyte *src
- = (GLubyte *) rb->Data + 3 * (y[i] * rb->RowStride + x[i]);
- dst[i * 4 + 0] = src[0];
- dst[i * 4 + 1] = src[1];
- dst[i * 4 + 2] = src[2];
- dst[i * 4 + 3] = 255;
- }
-}
-
-
-static void
-put_row_ubyte3(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
- GLint x, GLint y, const void *values, const GLubyte *mask)
-{
- /* note: incoming values are RGB+A! */
- const GLubyte *src = (const GLubyte *) values;
- GLubyte *dst = (GLubyte *) rb->Data + 3 * (y * rb->RowStride + x);
- GLuint i;
- ASSERT(rb->Format == MESA_FORMAT_RGB888);
- ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
- for (i = 0; i < count; i++) {
- if (!mask || mask[i]) {
- dst[i * 3 + 0] = src[i * 4 + 0];
- dst[i * 3 + 1] = src[i * 4 + 1];
- dst[i * 3 + 2] = src[i * 4 + 2];
- }
- }
-}
-
-
-static void
-put_row_rgb_ubyte3(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
- GLint x, GLint y, const void *values, const GLubyte *mask)
-{
- /* note: incoming values are RGB+A! */
- const GLubyte *src = (const GLubyte *) values;
- GLubyte *dst = (GLubyte *) rb->Data + 3 * (y * rb->RowStride + x);
- GLuint i;
- ASSERT(rb->Format == MESA_FORMAT_RGB888);
- ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
- for (i = 0; i < count; i++) {
- if (!mask || mask[i]) {
- dst[i * 3 + 0] = src[i * 3 + 0];
- dst[i * 3 + 1] = src[i * 3 + 1];
- dst[i * 3 + 2] = src[i * 3 + 2];
- }
- }
-}
-
-
-static void
-put_mono_row_ubyte3(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
- GLint x, GLint y, const void *value, const GLubyte *mask)
-{
- /* note: incoming value is RGB+A! */
- const GLubyte val0 = ((const GLubyte *) value)[0];
- const GLubyte val1 = ((const GLubyte *) value)[1];
- const GLubyte val2 = ((const GLubyte *) value)[2];
- GLubyte *dst = (GLubyte *) rb->Data + 3 * (y * rb->RowStride + x);
- ASSERT(rb->Format == MESA_FORMAT_RGB888);
- ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
- if (!mask && val0 == val1 && val1 == val2) {
- /* optimized case */
- memset(dst, val0, 3 * count);
- }
- else {
- GLuint i;
- for (i = 0; i < count; i++) {
- if (!mask || mask[i]) {
- dst[i * 3 + 0] = val0;
- dst[i * 3 + 1] = val1;
- dst[i * 3 + 2] = val2;
- }
- }
- }
-}
-
-
-static void
-put_values_ubyte3(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
- const GLint x[], const GLint y[], const void *values,
- const GLubyte *mask)
-{
- /* note: incoming values are RGB+A! */
- const GLubyte *src = (const GLubyte *) values;
- GLuint i;
- ASSERT(rb->Format == MESA_FORMAT_RGB888);
- ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
- for (i = 0; i < count; i++) {
- if (!mask || mask[i]) {
- GLubyte *dst = (GLubyte *) rb->Data + 3 * (y[i] * rb->RowStride + x[i]);
- dst[0] = src[i * 4 + 0];
- dst[1] = src[i * 4 + 1];
- dst[2] = src[i * 4 + 2];
- }
- }
-}
-
-
-static void
-put_mono_values_ubyte3(struct gl_context *ctx, struct gl_renderbuffer *rb,
- GLuint count, const GLint x[], const GLint y[],
- const void *value, const GLubyte *mask)
-{
- /* note: incoming value is RGB+A! */
- const GLubyte val0 = ((const GLubyte *) value)[0];
- const GLubyte val1 = ((const GLubyte *) value)[1];
- const GLubyte val2 = ((const GLubyte *) value)[2];
- GLuint i;
- ASSERT(rb->Format == MESA_FORMAT_RGB888);
- ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
- for (i = 0; i < count; i++) {
- if (!mask || mask[i]) {
- GLubyte *dst = ((GLubyte *) rb->Data) +
- 3 * (y[i] * rb->RowStride + x[i]);
- dst[0] = val0;
- dst[1] = val1;
- dst[2] = val2;
- }
- }
-}
-
-
-/**********************************************************************
- * Functions for buffers of 4 X GLubyte (or GLbyte) values.
- * Typically color buffers.
- */
-
-static void
-get_values_ubyte4(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
- const GLint x[], const GLint y[], void *values)
-{
- /* treat 4*GLubyte as 1*GLuint */
- GLuint *dst = (GLuint *) values;
- GLuint i;
- ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
- ASSERT(rb->Format == MESA_FORMAT_RGBA8888 ||
- rb->Format == MESA_FORMAT_RGBA8888_REV);
- for (i = 0; i < count; i++) {
- const GLuint *src = (GLuint *) rb->Data + (y[i] * rb->RowStride + x[i]);
- dst[i] = *src;
- }
-}
-
-
-static void
-put_row_ubyte4(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
- GLint x, GLint y, const void *values, const GLubyte *mask)
-{
- /* treat 4*GLubyte as 1*GLuint */
- const GLuint *src = (const GLuint *) values;
- GLuint *dst = (GLuint *) rb->Data + (y * rb->RowStride + x);
- ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
- ASSERT(rb->Format == MESA_FORMAT_RGBA8888 ||
- rb->Format == MESA_FORMAT_RGBA8888_REV);
- if (mask) {
- GLuint i;
- for (i = 0; i < count; i++) {
- if (mask[i]) {
- dst[i] = src[i];
- }
- }
- }
- else {
- memcpy(dst, src, 4 * count * sizeof(GLubyte));
- }
-}
-
-
-static void
-put_row_rgb_ubyte4(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
- GLint x, GLint y, const void *values, const GLubyte *mask)
-{
- /* Store RGB values in RGBA buffer */
- const GLubyte *src = (const GLubyte *) values;
- GLubyte *dst = (GLubyte *) rb->Data + 4 * (y * rb->RowStride + x);
- GLuint i;
- ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
- ASSERT(rb->Format == MESA_FORMAT_RGBA8888 ||
- rb->Format == MESA_FORMAT_RGBA8888_REV);
- for (i = 0; i < count; i++) {
- if (!mask || mask[i]) {
- dst[i * 4 + 0] = src[i * 3 + 0];
- dst[i * 4 + 1] = src[i * 3 + 1];
- dst[i * 4 + 2] = src[i * 3 + 2];
- dst[i * 4 + 3] = 0xff;
- }
- }
-}
-
-
-static void
-put_mono_row_ubyte4(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
- GLint x, GLint y, const void *value, const GLubyte *mask)
-{
- /* treat 4*GLubyte as 1*GLuint */
- const GLuint val = *((const GLuint *) value);
- GLuint *dst = (GLuint *) rb->Data + (y * rb->RowStride + x);
- ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
- ASSERT(rb->Format == MESA_FORMAT_RGBA8888 ||
- rb->Format == MESA_FORMAT_RGBA8888_REV);
- if (!mask && val == 0) {
- /* common case */
- memset(dst, 0, count * 4 * sizeof(GLubyte));
- }
- else {
- /* general case */
- if (mask) {
- GLuint i;
- for (i = 0; i < count; i++) {
- if (mask[i]) {
- dst[i] = val;
- }
- }
- }
- else {
- GLuint i;
- for (i = 0; i < count; i++) {
- dst[i] = val;
- }
- }
- }
-}
-
-
-static void
-put_values_ubyte4(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
- const GLint x[], const GLint y[], const void *values,
- const GLubyte *mask)
-{
- /* treat 4*GLubyte as 1*GLuint */
- const GLuint *src = (const GLuint *) values;
- GLuint i;
- ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
- ASSERT(rb->Format == MESA_FORMAT_RGBA8888 ||
- rb->Format == MESA_FORMAT_RGBA8888_REV);
- for (i = 0; i < count; i++) {
- if (!mask || mask[i]) {
- GLuint *dst = (GLuint *) rb->Data + (y[i] * rb->RowStride + x[i]);
- *dst = src[i];
- }
- }
-}
-
-
-static void
-put_mono_values_ubyte4(struct gl_context *ctx, struct gl_renderbuffer *rb,
- GLuint count, const GLint x[], const GLint y[],
- const void *value, const GLubyte *mask)
-{
- /* treat 4*GLubyte as 1*GLuint */
- const GLuint val = *((const GLuint *) value);
- GLuint i;
- ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
- ASSERT(rb->Format == MESA_FORMAT_RGBA8888 ||
- rb->Format == MESA_FORMAT_RGBA8888_REV);
- for (i = 0; i < count; i++) {
- if (!mask || mask[i]) {
- GLuint *dst = (GLuint *) rb->Data + (y[i] * rb->RowStride + x[i]);
- *dst = val;
- }
- }
-}
-
-
-/**********************************************************************
- * Functions for buffers of 4 X GLushort (or GLshort) values.
- * Typically accum buffer.
- */
-
-static void
-get_values_ushort4(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
- const GLint x[], const GLint y[], void *values)
-{
- GLushort *dst = (GLushort *) values;
- GLuint i;
- ASSERT(rb->DataType == GL_UNSIGNED_SHORT || rb->DataType == GL_SHORT);
- for (i = 0; i < count; i++) {
- const GLushort *src
- = (GLushort *) rb->Data + 4 * (y[i] * rb->RowStride + x[i]);
- dst[i] = *src;
- }
-}
-
-
-static void
-put_row_ushort4(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
- GLint x, GLint y, const void *values, const GLubyte *mask)
-{
- const GLushort *src = (const GLushort *) values;
- GLushort *dst = (GLushort *) rb->Data + 4 * (y * rb->RowStride + x);
- ASSERT(rb->DataType == GL_UNSIGNED_SHORT || rb->DataType == GL_SHORT);
- if (mask) {
- GLuint i;
- for (i = 0; i < count; i++) {
- if (mask[i]) {
- dst[i * 4 + 0] = src[i * 4 + 0];
- dst[i * 4 + 1] = src[i * 4 + 1];
- dst[i * 4 + 2] = src[i * 4 + 2];
- dst[i * 4 + 3] = src[i * 4 + 3];
- }
- }
- }
- else {
- memcpy(dst, src, 4 * count * sizeof(GLushort));
- }
-}
-
-
-static void
-put_row_rgb_ushort4(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
- GLint x, GLint y, const void *values, const GLubyte *mask)
-{
- /* Put RGB values in RGBA buffer */
- const GLushort *src = (const GLushort *) values;
- GLushort *dst = (GLushort *) rb->Data + 4 * (y * rb->RowStride + x);
- ASSERT(rb->DataType == GL_UNSIGNED_SHORT || rb->DataType == GL_SHORT);
- if (mask) {
- GLuint i;
- for (i = 0; i < count; i++) {
- if (mask[i]) {
- dst[i * 4 + 0] = src[i * 3 + 0];
- dst[i * 4 + 1] = src[i * 3 + 1];
- dst[i * 4 + 2] = src[i * 3 + 2];
- dst[i * 4 + 3] = 0xffff;
- }
- }
- }
- else {
- memcpy(dst, src, 4 * count * sizeof(GLushort));
- }
-}
-
-
-static void
-put_mono_row_ushort4(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
- GLint x, GLint y, const void *value, const GLubyte *mask)
-{
- const GLushort val0 = ((const GLushort *) value)[0];
- const GLushort val1 = ((const GLushort *) value)[1];
- const GLushort val2 = ((const GLushort *) value)[2];
- const GLushort val3 = ((const GLushort *) value)[3];
- GLushort *dst = (GLushort *) rb->Data + 4 * (y * rb->RowStride + x);
- ASSERT(rb->DataType == GL_UNSIGNED_SHORT || rb->DataType == GL_SHORT);
- if (!mask && val0 == 0 && val1 == 0 && val2 == 0 && val3 == 0) {
- /* common case for clearing accum buffer */
- memset(dst, 0, count * 4 * sizeof(GLushort));
- }
- else {
- GLuint i;
- for (i = 0; i < count; i++) {
- if (!mask || mask[i]) {
- dst[i * 4 + 0] = val0;
- dst[i * 4 + 1] = val1;
- dst[i * 4 + 2] = val2;
- dst[i * 4 + 3] = val3;
- }
- }
- }
-}
-
-
-static void
-put_values_ushort4(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
- const GLint x[], const GLint y[], const void *values,
- const GLubyte *mask)
-{
- const GLushort *src = (const GLushort *) values;
- GLuint i;
- ASSERT(rb->DataType == GL_UNSIGNED_SHORT || rb->DataType == GL_SHORT);
- for (i = 0; i < count; i++) {
- if (!mask || mask[i]) {
- GLushort *dst =
- ((GLushort *) rb->Data) + 4 * (y[i] * rb->RowStride + x[i]);
- dst[0] = src[i * 4 + 0];
- dst[1] = src[i * 4 + 1];
- dst[2] = src[i * 4 + 2];
- dst[3] = src[i * 4 + 3];
- }
- }
-}
-
-
-static void
-put_mono_values_ushort4(struct gl_context *ctx, struct gl_renderbuffer *rb,
- GLuint count, const GLint x[], const GLint y[],
- const void *value, const GLubyte *mask)
-{
- const GLushort val0 = ((const GLushort *) value)[0];
- const GLushort val1 = ((const GLushort *) value)[1];
- const GLushort val2 = ((const GLushort *) value)[2];
- const GLushort val3 = ((const GLushort *) value)[3];
- GLuint i;
- ASSERT(rb->DataType == GL_UNSIGNED_SHORT || rb->DataType == GL_SHORT);
- for (i = 0; i < count; i++) {
- if (!mask || mask[i]) {
- GLushort *dst = ((GLushort *) rb->Data) +
- 4 * (y[i] * rb->RowStride + x[i]);
- dst[0] = val0;
- dst[1] = val1;
- dst[2] = val2;
- dst[3] = val3;
- }
- }
-}
-
-/**********************************************************************
- * Functions for MESA_FORMAT_R8.
- */
-static void
-get_row_r8(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
- GLint x, GLint y, void *values)
-{
- const GLubyte *src = rb->GetPointer(ctx, rb, x, y);
- GLuint *dst = values;
- GLuint i;
-
- for (i = 0; i < count; i++) {
- dst[i] = 0xff000000 | src[i];
- }
-}
-
-static void
-get_values_r8(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
- const GLint x[], const GLint y[], void *values)
-{
- GLuint *dst = (GLuint *) values;
- GLuint i;
-
- for (i = 0; i < count; i++) {
- const GLubyte *src = rb->GetPointer(ctx, rb, x[i], y[i]);
- dst[i] = 0xff000000 | *src;
- }
-}
-
-/**********************************************************************
- * Functions for MESA_FORMAT_GR88.
- */
-static void
-get_row_rg88(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
- GLint x, GLint y, void *values)
-{
- const GLushort *src = rb->GetPointer(ctx, rb, x, y);
- GLuint *dst = values;
- GLuint i;
-
- for (i = 0; i < count; i++) {
- dst[i] = 0xff000000 | src[i];
- }
-}
-
-static void
-get_values_rg88(struct gl_context *ctx, struct gl_renderbuffer *rb,
- GLuint count, const GLint x[], const GLint y[], void *values)
-{
- GLuint *dst = (GLuint *) values;
- GLuint i;
-
- for (i = 0; i < count; i++) {
- const GLshort *src = rb->GetPointer(ctx, rb, x[i], y[i]);
- dst[i] = 0xff000000 | *src;
- }
-}
-
-/**********************************************************************
- * Functions for MESA_FORMAT_R16.
- */
-static void
-get_row_r16(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
- GLint x, GLint y, void *values)
-{
- const GLushort *src = rb->GetPointer(ctx, rb, x, y);
- GLushort *dst = values;
- GLuint i;
-
- for (i = 0; i < count; i++) {
- dst[i * 4 + RCOMP] = src[i];
- dst[i * 4 + GCOMP] = 0;
- dst[i * 4 + BCOMP] = 0;
- dst[i * 4 + ACOMP] = 0xffff;
- }
-}
-
-static void
-get_values_r16(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
- const GLint x[], const GLint y[], void *values)
-{
- GLushort *dst = values;
- GLuint i;
-
- for (i = 0; i < count; i++) {
- const GLushort *src = rb->GetPointer(ctx, rb, x[i], y[i]);
- dst[i * 4 + RCOMP] = *src;
- dst[i * 4 + GCOMP] = 0;
- dst[i * 4 + BCOMP] = 0;
- dst[i * 4 + ACOMP] = 0xffff;
- }
-}
-
-/**********************************************************************
- * Functions for MESA_FORMAT_RG1616.
- */
-static void
-get_row_rg1616(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
- GLint x, GLint y, void *values)
-{
- const GLushort *src = rb->GetPointer(ctx, rb, x, y);
- GLushort *dst = values;
- GLuint i;
-
- for (i = 0; i < count; i++) {
- dst[i * 4 + RCOMP] = src[i * 2];
- dst[i * 4 + GCOMP] = src[i * 2 + 1];
- dst[i * 4 + BCOMP] = 0;
- dst[i * 4 + ACOMP] = 0xffff;
- }
-}
-
-static void
-get_values_rg1616(struct gl_context *ctx, struct gl_renderbuffer *rb,
- GLuint count, const GLint x[], const GLint y[], void *values)
-{
- GLushort *dst = values;
- GLuint i;
-
- for (i = 0; i < count; i++) {
- const GLshort *src = rb->GetPointer(ctx, rb, x[i], y[i]);
- dst[i * 4 + RCOMP] = src[0];
- dst[i * 4 + GCOMP] = src[1];
- dst[i * 4 + BCOMP] = 0;
- dst[i * 4 + ACOMP] = 0xffff;
- }
-}
-
-/**********************************************************************
- * Functions for MESA_FORMAT_INTENSITY_FLOAT32.
- */
-static void
-get_row_i_float32(struct gl_context *ctx, struct gl_renderbuffer *rb,
- GLuint count, GLint x, GLint y, void *values)
-{
- const GLfloat *src = rb->GetPointer(ctx, rb, x, y);
- GLfloat *dst = values;
- GLuint i;
-
- for (i = 0; i < count; i++) {
- dst[i * 4 + RCOMP] =
- dst[i * 4 + GCOMP] =
- dst[i * 4 + BCOMP] =
- dst[i * 4 + ACOMP] = src[i];
- }
-}
-
-static void
-get_values_i_float32(struct gl_context *ctx, struct gl_renderbuffer *rb,
- GLuint count, const GLint x[], const GLint y[],
- void *values)
-{
- GLfloat *dst = values;
- GLuint i;
-
- for (i = 0; i < count; i++) {
- const GLfloat *src = rb->GetPointer(ctx, rb, x[i], y[i]);
- dst[i * 4 + RCOMP] =
- dst[i * 4 + GCOMP] =
- dst[i * 4 + BCOMP] =
- dst[i * 4 + ACOMP] = src[0];
- }
-}
-
-/**********************************************************************
- * Functions for MESA_FORMAT_LUMINANCE_FLOAT32.
- */
-static void
-get_row_l_float32(struct gl_context *ctx, struct gl_renderbuffer *rb,
- GLuint count, GLint x, GLint y, void *values)
-{
- const GLfloat *src = rb->GetPointer(ctx, rb, x, y);
- GLfloat *dst = values;
- GLuint i;
-
- for (i = 0; i < count; i++) {
- dst[i * 4 + RCOMP] =
- dst[i * 4 + GCOMP] =
- dst[i * 4 + BCOMP] = src[i];
- dst[i * 4 + ACOMP] = 1.0;
- }
-}
-
-static void
-get_values_l_float32(struct gl_context *ctx, struct gl_renderbuffer *rb,
- GLuint count, const GLint x[], const GLint y[],
- void *values)
-{
- GLfloat *dst = values;
- GLuint i;
-
- for (i = 0; i < count; i++) {
- const GLfloat *src = rb->GetPointer(ctx, rb, x[i], y[i]);
- dst[i * 4 + RCOMP] =
- dst[i * 4 + GCOMP] =
- dst[i * 4 + BCOMP] = src[0];
- dst[i * 4 + ACOMP] = 1.0;
- }
-}
-
-/**********************************************************************
- * Functions for MESA_FORMAT_ALPHA_FLOAT32.
- */
-static void
-get_row_a_float32(struct gl_context *ctx, struct gl_renderbuffer *rb,
- GLuint count, GLint x, GLint y, void *values)
-{
- const GLfloat *src = rb->GetPointer(ctx, rb, x, y);
- GLfloat *dst = values;
- GLuint i;
-
- for (i = 0; i < count; i++) {
- dst[i * 4 + RCOMP] = 0.0;
- dst[i * 4 + GCOMP] = 0.0;
- dst[i * 4 + BCOMP] = 0.0;
- dst[i * 4 + ACOMP] = src[i];
- }
-}
-
-static void
-get_values_a_float32(struct gl_context *ctx, struct gl_renderbuffer *rb,
- GLuint count, const GLint x[], const GLint y[],
- void *values)
-{
- GLfloat *dst = values;
- GLuint i;
-
- for (i = 0; i < count; i++) {
- const GLfloat *src = rb->GetPointer(ctx, rb, x[i], y[i]);
- dst[i * 4 + RCOMP] = 0.0;
- dst[i * 4 + GCOMP] = 0.0;
- dst[i * 4 + BCOMP] = 0.0;
- dst[i * 4 + ACOMP] = src[0];
- }
-}
-
-static void
-put_row_a_float32(struct gl_context *ctx, struct gl_renderbuffer *rb,
- GLuint count, GLint x, GLint y,
- const void *values, const GLubyte *mask)
-{
- float *dst = rb->GetPointer(ctx, rb, x, y);
- const float *src = values;
- unsigned int i;
-
- if (mask) {
- for (i = 0; i < count; i++) {
- if (mask[i]) {
- dst[i] = src[i * 4 + ACOMP];
- }
- }
- }
- else {
- for (i = 0; i < count; i++) {
- dst[i] = src[i * 4 + ACOMP];
- }
- }
-}
-
-static void
-put_mono_row_a_float32(struct gl_context *ctx, struct gl_renderbuffer *rb,
- GLuint count, GLint x, GLint y,
- const void *value, const GLubyte *mask)
-{
- float *dst = rb->GetPointer(ctx, rb, x, y);
- const float *src = value;
- unsigned int i;
-
- if (mask) {
- for (i = 0; i < count; i++) {
- if (mask[i]) {
- dst[i] = src[ACOMP];
- }
- }
- }
- else {
- for (i = 0; i < count; i++) {
- dst[i] = src[ACOMP];
- }
- }
-}
-
-static void
-put_values_a_float32(struct gl_context *ctx, struct gl_renderbuffer *rb,
- GLuint count, const GLint x[], const GLint y[],
- const void *values, const GLubyte *mask)
-{
- const float *src = values;
- unsigned int i;
-
- for (i = 0; i < count; i++) {
- if (!mask || mask[i]) {
- float *dst = rb->GetPointer(ctx, rb, x[i], y[i]);
-
- *dst = src[i * 4 + ACOMP];
- }
- }
-}
-
-static void
-put_mono_values_a_float32(struct gl_context *ctx,
- struct gl_renderbuffer *rb,
- GLuint count, const GLint x[], const GLint y[],
- const void *value, const GLubyte *mask)
-{
- const float *src = value;
- unsigned int i;
-
- for (i = 0; i < count; i++) {
- if (!mask || mask[i]) {
- float *dst = rb->GetPointer(ctx, rb, x[i], y[i]);
- *dst = src[ACOMP];
- }
- }
-}
-
-/**********************************************************************
- * Functions for MESA_FORMAT_R_FLOAT32.
- */
-static void
-get_row_r_float32(struct gl_context *ctx, struct gl_renderbuffer *rb,
- GLuint count, GLint x, GLint y, void *values)
-{
- const GLfloat *src = rb->GetPointer(ctx, rb, x, y);
- GLfloat *dst = values;
- GLuint i;
-
- for (i = 0; i < count; i++) {
- dst[i * 4 + RCOMP] = src[i];
- dst[i * 4 + GCOMP] = 0.0;
- dst[i * 4 + BCOMP] = 0.0;
- dst[i * 4 + ACOMP] = 1.0;
- }
-}
-
-static void
-get_values_r_float32(struct gl_context *ctx, struct gl_renderbuffer *rb,
- GLuint count, const GLint x[], const GLint y[],
- void *values)
-{
- GLfloat *dst = values;
- GLuint i;
-
- for (i = 0; i < count; i++) {
- const GLfloat *src = rb->GetPointer(ctx, rb, x[i], y[i]);
- dst[i * 4 + RCOMP] = src[0];
- dst[i * 4 + GCOMP] = 0.0;
- dst[i * 4 + BCOMP] = 0.0;
- dst[i * 4 + ACOMP] = 1.0;
- }
-}
-
-/**********************************************************************
- * Functions for MESA_FORMAT_RG_FLOAT32.
- */
-static void
-get_row_rg_float32(struct gl_context *ctx, struct gl_renderbuffer *rb,
- GLuint count, GLint x, GLint y, void *values)
-{
- const GLfloat *src = rb->GetPointer(ctx, rb, x, y);
- GLfloat *dst = values;
- GLuint i;
-
- for (i = 0; i < count; i++) {
- dst[i * 4 + RCOMP] = src[i * 2 + 0];
- dst[i * 4 + GCOMP] = src[i * 2 + 1];
- dst[i * 4 + BCOMP] = 0.0;
- dst[i * 4 + ACOMP] = 1.0;
- }
-}
-
-static void
-get_values_rg_float32(struct gl_context *ctx, struct gl_renderbuffer *rb,
- GLuint count, const GLint x[], const GLint y[],
- void *values)
-{
- GLfloat *dst = values;
- GLuint i;
-
- for (i = 0; i < count; i++) {
- const GLfloat *src = rb->GetPointer(ctx, rb, x[i], y[i]);
- dst[i * 4 + RCOMP] = src[0];
- dst[i * 4 + GCOMP] = src[1];
- dst[i * 4 + BCOMP] = 0.0;
- dst[i * 4 + ACOMP] = 1.0;
- }
-}
-
-/**
- * This is the default software fallback for gl_renderbuffer's span
- * access functions.
- *
- * The assumptions are that rb->Data will be a pointer to (0,0), that pixels
- * are packed in the type of rb->Format, and that subsequent rows appear
- * rb->RowStride pixels later.
- */
-void
-_mesa_set_renderbuffer_accessors(struct gl_renderbuffer *rb)
-{
- rb->GetPointer = get_pointer_generic;
- rb->GetRow = get_row_generic;
-
- switch (rb->Format) {
- case MESA_FORMAT_RGB888:
- rb->DataType = GL_UNSIGNED_BYTE;
- rb->GetPointer = get_pointer_ubyte3;
- rb->GetRow = get_row_ubyte3;
- rb->GetValues = get_values_ubyte3;
- rb->PutRow = put_row_ubyte3;
- rb->PutRowRGB = put_row_rgb_ubyte3;
- rb->PutMonoRow = put_mono_row_ubyte3;
- rb->PutValues = put_values_ubyte3;
- rb->PutMonoValues = put_mono_values_ubyte3;
- break;
-
- case MESA_FORMAT_RGBA8888:
- case MESA_FORMAT_RGBA8888_REV:
- rb->DataType = GL_UNSIGNED_BYTE;
- rb->GetValues = get_values_ubyte4;
- rb->PutRow = put_row_ubyte4;
- rb->PutRowRGB = put_row_rgb_ubyte4;
- rb->PutMonoRow = put_mono_row_ubyte4;
- rb->PutValues = put_values_ubyte4;
- rb->PutMonoValues = put_mono_values_ubyte4;
- break;
-
- case MESA_FORMAT_R8:
- rb->DataType = GL_UNSIGNED_BYTE;
- rb->GetValues = get_values_r8;
- rb->GetRow = get_row_r8;
- rb->PutRow = put_row_generic;
- rb->PutRowRGB = put_row_generic;
- rb->PutMonoRow = put_mono_row_generic;
- rb->PutValues = put_values_generic;
- rb->PutMonoValues = put_mono_values_generic;
- break;
-
- case MESA_FORMAT_GR88:
- rb->DataType = GL_UNSIGNED_BYTE;
- rb->GetValues = get_values_rg88;
- rb->GetRow = get_row_rg88;
- rb->PutRow = put_row_generic;
- rb->PutRowRGB = put_row_generic;
- rb->PutMonoRow = put_mono_row_generic;
- rb->PutValues = put_values_generic;
- rb->PutMonoValues = put_mono_values_generic;
- break;
-
- case MESA_FORMAT_R16:
- rb->DataType = GL_UNSIGNED_SHORT;
- rb->GetValues = get_values_r16;
- rb->GetRow = get_row_r16;
- rb->PutRow = put_row_generic;
- rb->PutRowRGB = put_row_generic;
- rb->PutMonoRow = put_mono_row_generic;
- rb->PutValues = put_values_generic;
- rb->PutMonoValues = put_mono_values_generic;
- break;
-
- case MESA_FORMAT_RG1616:
- rb->DataType = GL_UNSIGNED_SHORT;
- rb->GetValues = get_values_rg1616;
- rb->GetRow = get_row_rg1616;
- rb->PutRow = put_row_generic;
- rb->PutRowRGB = put_row_generic;
- rb->PutMonoRow = put_mono_row_generic;
- rb->PutValues = put_values_generic;
- rb->PutMonoValues = put_mono_values_generic;
- break;
-
- case MESA_FORMAT_SIGNED_RGBA_16:
- rb->DataType = GL_SHORT;
- rb->GetValues = get_values_ushort4;
- rb->PutRow = put_row_ushort4;
- rb->PutRowRGB = put_row_rgb_ushort4;
- rb->PutMonoRow = put_mono_row_ushort4;
- rb->PutValues = put_values_ushort4;
- rb->PutMonoValues = put_mono_values_ushort4;
- break;
-
- case MESA_FORMAT_S8:
- rb->DataType = GL_UNSIGNED_BYTE;
- rb->GetValues = get_values_ubyte;
- rb->PutRow = put_row_ubyte;
- rb->PutRowRGB = NULL;
- rb->PutMonoRow = put_mono_row_ubyte;
- rb->PutValues = put_values_ubyte;
- rb->PutMonoValues = put_mono_values_ubyte;
- break;
-
- case MESA_FORMAT_Z16:
- rb->DataType = GL_UNSIGNED_SHORT;
- rb->GetValues = get_values_ushort;
- rb->PutRow = put_row_ushort;
- rb->PutRowRGB = NULL;
- rb->PutMonoRow = put_mono_row_ushort;
- rb->PutValues = put_values_ushort;
- rb->PutMonoValues = put_mono_values_ushort;
- break;
-
- case MESA_FORMAT_Z32:
- case MESA_FORMAT_X8_Z24:
- case MESA_FORMAT_Z24_X8:
- rb->DataType = GL_UNSIGNED_INT;
- rb->GetValues = get_values_uint;
- rb->PutRow = put_row_uint;
- rb->PutRowRGB = NULL;
- rb->PutMonoRow = put_mono_row_uint;
- rb->PutValues = put_values_uint;
- rb->PutMonoValues = put_mono_values_uint;
- break;
-
- case MESA_FORMAT_Z24_S8:
- case MESA_FORMAT_S8_Z24:
- rb->DataType = GL_UNSIGNED_INT_24_8_EXT;
- rb->GetValues = get_values_uint;
- rb->PutRow = put_row_uint;
- rb->PutRowRGB = NULL;
- rb->PutMonoRow = put_mono_row_uint;
- rb->PutValues = put_values_uint;
- rb->PutMonoValues = put_mono_values_uint;
- break;
-
- case MESA_FORMAT_RGBA_FLOAT32:
- rb->GetRow = get_row_generic;
- rb->GetValues = get_values_generic;
- rb->PutRow = put_row_generic;
- rb->PutRowRGB = NULL;
- rb->PutMonoRow = put_mono_row_generic;
- rb->PutValues = put_values_generic;
- rb->PutMonoValues = put_mono_values_generic;
- break;
-
- case MESA_FORMAT_INTENSITY_FLOAT32:
- rb->GetRow = get_row_i_float32;
- rb->GetValues = get_values_i_float32;
- rb->PutRow = put_row_generic;
- rb->PutRowRGB = NULL;
- rb->PutMonoRow = put_mono_row_generic;
- rb->PutValues = put_values_generic;
- rb->PutMonoValues = put_mono_values_generic;
- break;
-
- case MESA_FORMAT_LUMINANCE_FLOAT32:
- rb->GetRow = get_row_l_float32;
- rb->GetValues = get_values_l_float32;
- rb->PutRow = put_row_generic;
- rb->PutRowRGB = NULL;
- rb->PutMonoRow = put_mono_row_generic;
- rb->PutValues = put_values_generic;
- rb->PutMonoValues = put_mono_values_generic;
- break;
-
- case MESA_FORMAT_ALPHA_FLOAT32:
- rb->GetRow = get_row_a_float32;
- rb->GetValues = get_values_a_float32;
- rb->PutRow = put_row_a_float32;
- rb->PutRowRGB = NULL;
- rb->PutMonoRow = put_mono_row_a_float32;
- rb->PutValues = put_values_a_float32;
- rb->PutMonoValues = put_mono_values_a_float32;
- break;
-
- case MESA_FORMAT_RG_FLOAT32:
- rb->GetRow = get_row_rg_float32;
- rb->GetValues = get_values_rg_float32;
- rb->PutRow = put_row_generic;
- rb->PutRowRGB = NULL;
- rb->PutMonoRow = put_mono_row_generic;
- rb->PutValues = put_values_generic;
- rb->PutMonoValues = put_mono_values_generic;
- break;
-
- case MESA_FORMAT_R_FLOAT32:
- rb->GetRow = get_row_r_float32;
- rb->GetValues = get_values_r_float32;
- rb->PutRow = put_row_generic;
- rb->PutRowRGB = NULL;
- rb->PutMonoRow = put_mono_row_generic;
- rb->PutValues = put_values_generic;
- rb->PutMonoValues = put_mono_values_generic;
- break;
-
- default:
- break;
- }
-}
-
-/**
- * This is a software fallback for the gl_renderbuffer->AllocStorage
- * function.
- * Device drivers will typically override this function for the buffers
- * which it manages (typically color buffers, Z and stencil).
- * Other buffers (like software accumulation and aux buffers) which the driver
- * doesn't manage can be handled with this function.
- *
- * This one multi-purpose function can allocate stencil, depth, accum, color
- * or color-index buffers!
- *
- * This function also plugs in the appropriate GetPointer, Get/PutRow and
- * Get/PutValues functions.
- */
-GLboolean
-_mesa_soft_renderbuffer_storage(struct gl_context *ctx, struct gl_renderbuffer *rb,
- GLenum internalFormat,
- GLuint width, GLuint height)
-{
- switch (internalFormat) {
- case GL_RGB:
- case GL_R3_G3_B2:
- case GL_RGB4:
- case GL_RGB5:
- case GL_RGB8:
- case GL_RGB10:
- case GL_RGB12:
- case GL_RGB16:
- rb->Format = MESA_FORMAT_RGB888;
- break;
- case GL_RGBA:
- case GL_RGBA2:
- case GL_RGBA4:
- case GL_RGB5_A1:
- case GL_RGBA8:
-#if 1
- case GL_RGB10_A2:
- case GL_RGBA12:
-#endif
- if (_mesa_little_endian())
- rb->Format = MESA_FORMAT_RGBA8888_REV;
- else
- rb->Format = MESA_FORMAT_RGBA8888;
- break;
- case GL_RGBA16:
- case GL_RGBA16_SNORM:
- /* for accum buffer */
- rb->Format = MESA_FORMAT_SIGNED_RGBA_16;
- break;
- case GL_STENCIL_INDEX:
- case GL_STENCIL_INDEX1_EXT:
- case GL_STENCIL_INDEX4_EXT:
- case GL_STENCIL_INDEX8_EXT:
- case GL_STENCIL_INDEX16_EXT:
- rb->Format = MESA_FORMAT_S8;
- break;
- case GL_DEPTH_COMPONENT:
- case GL_DEPTH_COMPONENT16:
- rb->Format = MESA_FORMAT_Z16;
- break;
- case GL_DEPTH_COMPONENT24:
- rb->Format = MESA_FORMAT_X8_Z24;
- break;
- case GL_DEPTH_COMPONENT32:
- rb->Format = MESA_FORMAT_Z32;
- break;
- case GL_DEPTH_STENCIL_EXT:
- case GL_DEPTH24_STENCIL8_EXT:
- rb->Format = MESA_FORMAT_Z24_S8;
- break;
- default:
- /* unsupported format */
- return GL_FALSE;
- }
-
- _mesa_set_renderbuffer_accessors(rb);
-
- ASSERT(rb->DataType);
- ASSERT(rb->GetPointer);
- ASSERT(rb->GetRow);
- ASSERT(rb->GetValues);
- ASSERT(rb->PutRow);
- ASSERT(rb->PutMonoRow);
- ASSERT(rb->PutValues);
- ASSERT(rb->PutMonoValues);
-
- /* free old buffer storage */
- if (rb->Data) {
- free(rb->Data);
- rb->Data = NULL;
- }
-
- rb->RowStride = width;
-
- if (width > 0 && height > 0) {
- /* allocate new buffer storage */
- rb->Data = malloc(width * height * _mesa_get_format_bytes(rb->Format));
-
- if (rb->Data == NULL) {
- rb->Width = 0;
- rb->Height = 0;
- rb->RowStride = 0;
- _mesa_error(ctx, GL_OUT_OF_MEMORY,
- "software renderbuffer allocation (%d x %d x %d)",
- width, height, _mesa_get_format_bytes(rb->Format));
- return GL_FALSE;
- }
- }
-
- rb->Width = width;
- rb->Height = height;
- rb->_BaseFormat = _mesa_base_fbo_format(ctx, internalFormat);
-
- if (rb->Name == 0 &&
- internalFormat == GL_RGBA16_SNORM &&
- rb->_BaseFormat == 0) {
- /* NOTE: This is a special case just for accumulation buffers.
- * This is a very limited use case- there's no snorm texturing or
- * rendering going on.
- */
- rb->_BaseFormat = GL_RGBA;
- }
- else {
- /* the internalFormat should have been error checked long ago */
- ASSERT(rb->_BaseFormat);
- }
-
- return GL_TRUE;
-}
-
-
-void
-_mesa_map_soft_renderbuffer(struct gl_context *ctx,
- struct gl_renderbuffer *rb,
- GLuint x, GLuint y, GLuint w, GLuint h,
- GLbitfield mode,
- GLubyte **out_map,
- GLint *out_stride)
-{
- GLubyte *map = rb->Data;
- int cpp = _mesa_get_format_bytes(rb->Format);
- int stride = rb->RowStride * cpp;
-
- ASSERT(rb->Data);
-
- map += y * stride;
- map += x * cpp;
-
- *out_map = map;
- *out_stride = stride;
-}
-
-void
-_mesa_unmap_soft_renderbuffer(struct gl_context *ctx,
- struct gl_renderbuffer *rb)
-{
-}
-
-
-
-/**********************************************************************/
-/**********************************************************************/
-/**********************************************************************/
-
-
/**
* Default GetPointer routine. Always return NULL to indicate that
* direct buffer access is not supported.
@@ -1821,310 +115,6 @@ _mesa_delete_renderbuffer(struct gl_renderbuffer *rb)
/**
- * Allocate a software-based renderbuffer. This is called via the
- * ctx->Driver.NewRenderbuffer() function when the user creates a new
- * renderbuffer.
- * This would not be used for hardware-based renderbuffers.
- */
-struct gl_renderbuffer *
-_mesa_new_soft_renderbuffer(struct gl_context *ctx, GLuint name)
-{
- struct gl_renderbuffer *rb = _mesa_new_renderbuffer(ctx, name);
- if (rb) {
- rb->AllocStorage = _mesa_soft_renderbuffer_storage;
- /* Normally, one would setup the PutRow, GetRow, etc functions here.
- * But we're doing that in the _mesa_soft_renderbuffer_storage() function
- * instead.
- */
- }
- return rb;
-}
-
-
-/**
- * Add software-based color renderbuffers to the given framebuffer.
- * This is a helper routine for device drivers when creating a
- * window system framebuffer (not a user-created render/framebuffer).
- * Once this function is called, you can basically forget about this
- * renderbuffer; core Mesa will handle all the buffer management and
- * rendering!
- */
-GLboolean
-_mesa_add_color_renderbuffers(struct gl_context *ctx, struct gl_framebuffer *fb,
- GLuint rgbBits, GLuint alphaBits,
- GLboolean frontLeft, GLboolean backLeft,
- GLboolean frontRight, GLboolean backRight)
-{
- gl_buffer_index b;
-
- if (rgbBits > 16 || alphaBits > 16) {
- _mesa_problem(ctx,
- "Unsupported bit depth in _mesa_add_color_renderbuffers");
- return GL_FALSE;
- }
-
- assert(MAX_COLOR_ATTACHMENTS >= 4);
-
- for (b = BUFFER_FRONT_LEFT; b <= BUFFER_BACK_RIGHT; b++) {
- struct gl_renderbuffer *rb;
-
- if (b == BUFFER_FRONT_LEFT && !frontLeft)
- continue;
- else if (b == BUFFER_BACK_LEFT && !backLeft)
- continue;
- else if (b == BUFFER_FRONT_RIGHT && !frontRight)
- continue;
- else if (b == BUFFER_BACK_RIGHT && !backRight)
- continue;
-
- assert(fb->Attachment[b].Renderbuffer == NULL);
-
- rb = _mesa_new_renderbuffer(ctx, 0);
- if (!rb) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "Allocating color buffer");
- return GL_FALSE;
- }
-
- rb->InternalFormat = GL_RGBA;
-
- rb->AllocStorage = _mesa_soft_renderbuffer_storage;
- _mesa_add_renderbuffer(fb, b, rb);
- }
-
- return GL_TRUE;
-}
-
-
-/**
- * Add a software-based depth renderbuffer to the given framebuffer.
- * This is a helper routine for device drivers when creating a
- * window system framebuffer (not a user-created render/framebuffer).
- * Once this function is called, you can basically forget about this
- * renderbuffer; core Mesa will handle all the buffer management and
- * rendering!
- */
-GLboolean
-_mesa_add_depth_renderbuffer(struct gl_context *ctx, struct gl_framebuffer *fb,
- GLuint depthBits)
-{
- struct gl_renderbuffer *rb;
-
- if (depthBits > 32) {
- _mesa_problem(ctx,
- "Unsupported depthBits in _mesa_add_depth_renderbuffer");
- return GL_FALSE;
- }
-
- assert(fb->Attachment[BUFFER_DEPTH].Renderbuffer == NULL);
-
- rb = _mesa_new_renderbuffer(ctx, 0);
- if (!rb) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "Allocating depth buffer");
- return GL_FALSE;
- }
-
- if (depthBits <= 16) {
- rb->InternalFormat = GL_DEPTH_COMPONENT16;
- }
- else if (depthBits <= 24) {
- rb->InternalFormat = GL_DEPTH_COMPONENT24;
- }
- else {
- rb->InternalFormat = GL_DEPTH_COMPONENT32;
- }
-
- rb->AllocStorage = _mesa_soft_renderbuffer_storage;
- _mesa_add_renderbuffer(fb, BUFFER_DEPTH, rb);
-
- return GL_TRUE;
-}
-
-
-/**
- * Add a software-based stencil renderbuffer to the given framebuffer.
- * This is a helper routine for device drivers when creating a
- * window system framebuffer (not a user-created render/framebuffer).
- * Once this function is called, you can basically forget about this
- * renderbuffer; core Mesa will handle all the buffer management and
- * rendering!
- */
-GLboolean
-_mesa_add_stencil_renderbuffer(struct gl_context *ctx, struct gl_framebuffer *fb,
- GLuint stencilBits)
-{
- struct gl_renderbuffer *rb;
-
- if (stencilBits > 16) {
- _mesa_problem(ctx,
- "Unsupported stencilBits in _mesa_add_stencil_renderbuffer");
- return GL_FALSE;
- }
-
- assert(fb->Attachment[BUFFER_STENCIL].Renderbuffer == NULL);
-
- rb = _mesa_new_renderbuffer(ctx, 0);
- if (!rb) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "Allocating stencil buffer");
- return GL_FALSE;
- }
-
- assert(stencilBits <= 8);
- rb->InternalFormat = GL_STENCIL_INDEX8;
-
- rb->AllocStorage = _mesa_soft_renderbuffer_storage;
- _mesa_add_renderbuffer(fb, BUFFER_STENCIL, rb);
-
- return GL_TRUE;
-}
-
-
-/**
- * Add a software-based accumulation renderbuffer to the given framebuffer.
- * This is a helper routine for device drivers when creating a
- * window system framebuffer (not a user-created render/framebuffer).
- * Once this function is called, you can basically forget about this
- * renderbuffer; core Mesa will handle all the buffer management and
- * rendering!
- */
-GLboolean
-_mesa_add_accum_renderbuffer(struct gl_context *ctx, struct gl_framebuffer *fb,
- GLuint redBits, GLuint greenBits,
- GLuint blueBits, GLuint alphaBits)
-{
- struct gl_renderbuffer *rb;
-
- if (redBits > 16 || greenBits > 16 || blueBits > 16 || alphaBits > 16) {
- _mesa_problem(ctx,
- "Unsupported accumBits in _mesa_add_accum_renderbuffer");
- return GL_FALSE;
- }
-
- assert(fb->Attachment[BUFFER_ACCUM].Renderbuffer == NULL);
-
- rb = _mesa_new_renderbuffer(ctx, 0);
- if (!rb) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "Allocating accum buffer");
- return GL_FALSE;
- }
-
- rb->InternalFormat = GL_RGBA16_SNORM;
- rb->AllocStorage = _mesa_soft_renderbuffer_storage;
- _mesa_add_renderbuffer(fb, BUFFER_ACCUM, rb);
-
- return GL_TRUE;
-}
-
-
-
-/**
- * Add a software-based aux renderbuffer to the given framebuffer.
- * This is a helper routine for device drivers when creating a
- * window system framebuffer (not a user-created render/framebuffer).
- * Once this function is called, you can basically forget about this
- * renderbuffer; core Mesa will handle all the buffer management and
- * rendering!
- *
- * NOTE: color-index aux buffers not supported.
- */
-GLboolean
-_mesa_add_aux_renderbuffers(struct gl_context *ctx, struct gl_framebuffer *fb,
- GLuint colorBits, GLuint numBuffers)
-{
- GLuint i;
-
- if (colorBits > 16) {
- _mesa_problem(ctx,
- "Unsupported accumBits in _mesa_add_aux_renderbuffers");
- return GL_FALSE;
- }
-
- assert(numBuffers <= MAX_AUX_BUFFERS);
-
- for (i = 0; i < numBuffers; i++) {
- struct gl_renderbuffer *rb = _mesa_new_renderbuffer(ctx, 0);
-
- assert(fb->Attachment[BUFFER_AUX0 + i].Renderbuffer == NULL);
-
- if (!rb) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "Allocating aux buffer");
- return GL_FALSE;
- }
-
- assert (colorBits <= 8);
- rb->InternalFormat = GL_RGBA;
-
- rb->AllocStorage = _mesa_soft_renderbuffer_storage;
- _mesa_add_renderbuffer(fb, BUFFER_AUX0 + i, rb);
- }
- return GL_TRUE;
-}
-
-
-/**
- * Create/attach software-based renderbuffers to the given framebuffer.
- * This is a helper routine for device drivers. Drivers can just as well
- * call the individual _mesa_add_*_renderbuffer() routines directly.
- */
-void
-_mesa_add_soft_renderbuffers(struct gl_framebuffer *fb,
- GLboolean color,
- GLboolean depth,
- GLboolean stencil,
- GLboolean accum,
- GLboolean alpha,
- GLboolean aux)
-{
- GLboolean frontLeft = GL_TRUE;
- GLboolean backLeft = fb->Visual.doubleBufferMode;
- GLboolean frontRight = fb->Visual.stereoMode;
- GLboolean backRight = fb->Visual.stereoMode && fb->Visual.doubleBufferMode;
-
- if (color) {
- assert(fb->Visual.redBits == fb->Visual.greenBits);
- assert(fb->Visual.redBits == fb->Visual.blueBits);
- _mesa_add_color_renderbuffers(NULL, fb,
- fb->Visual.redBits,
- fb->Visual.alphaBits,
- frontLeft, backLeft,
- frontRight, backRight);
- }
-
- if (depth) {
- assert(fb->Visual.depthBits > 0);
- _mesa_add_depth_renderbuffer(NULL, fb, fb->Visual.depthBits);
- }
-
- if (stencil) {
- assert(fb->Visual.stencilBits > 0);
- _mesa_add_stencil_renderbuffer(NULL, fb, fb->Visual.stencilBits);
- }
-
- if (accum) {
- assert(fb->Visual.accumRedBits > 0);
- assert(fb->Visual.accumGreenBits > 0);
- assert(fb->Visual.accumBlueBits > 0);
- _mesa_add_accum_renderbuffer(NULL, fb,
- fb->Visual.accumRedBits,
- fb->Visual.accumGreenBits,
- fb->Visual.accumBlueBits,
- fb->Visual.accumAlphaBits);
- }
-
- if (aux) {
- assert(fb->Visual.numAuxBuffers > 0);
- _mesa_add_aux_renderbuffers(NULL, fb, fb->Visual.redBits,
- fb->Visual.numAuxBuffers);
- }
-
-#if 0
- if (multisample) {
- /* maybe someday */
- }
-#endif
-}
-
-
-/**
* Attach a renderbuffer to a framebuffer.
* \param bufferName one of the BUFFER_x tokens
*/
@@ -2166,17 +156,9 @@ void
_mesa_remove_renderbuffer(struct gl_framebuffer *fb,
gl_buffer_index bufferName)
{
- struct gl_renderbuffer *rb;
-
assert(bufferName < BUFFER_COUNT);
-
- rb = fb->Attachment[bufferName].Renderbuffer;
- if (!rb)
- return;
-
- _mesa_reference_renderbuffer(&rb, NULL);
-
- fb->Attachment[bufferName].Renderbuffer = NULL;
+ _mesa_reference_renderbuffer(&fb->Attachment[bufferName].Renderbuffer,
+ NULL);
}
diff --git a/mesalib/src/mesa/main/renderbuffer.h b/mesalib/src/mesa/main/renderbuffer.h
index 3194fc3fe..0934d85df 100644
--- a/mesalib/src/mesa/main/renderbuffer.h
+++ b/mesalib/src/mesa/main/renderbuffer.h
@@ -42,63 +42,6 @@ _mesa_new_renderbuffer(struct gl_context *ctx, GLuint name);
extern void
_mesa_delete_renderbuffer(struct gl_renderbuffer *rb);
-
-extern struct gl_renderbuffer *
-_mesa_new_soft_renderbuffer(struct gl_context *ctx, GLuint name);
-
-void
-_mesa_map_soft_renderbuffer(struct gl_context *ctx,
- struct gl_renderbuffer *rb,
- GLuint x, GLuint y, GLuint w, GLuint h,
- GLbitfield mode,
- GLubyte **out_map,
- GLint *out_stride);
-
-void
-_mesa_unmap_soft_renderbuffer(struct gl_context *ctx,
- struct gl_renderbuffer *rb);
-
-extern void
-_mesa_set_renderbuffer_accessors(struct gl_renderbuffer *rb);
-
-extern GLboolean
-_mesa_soft_renderbuffer_storage(struct gl_context *ctx, struct gl_renderbuffer *rb,
- GLenum internalFormat,
- GLuint width, GLuint height);
-
-extern GLboolean
-_mesa_add_color_renderbuffers(struct gl_context *ctx, struct gl_framebuffer *fb,
- GLuint rgbBits, GLuint alphaBits,
- GLboolean frontLeft, GLboolean backLeft,
- GLboolean frontRight, GLboolean backRight);
-
-extern GLboolean
-_mesa_add_depth_renderbuffer(struct gl_context *ctx, struct gl_framebuffer *fb,
- GLuint depthBits);
-
-extern GLboolean
-_mesa_add_stencil_renderbuffer(struct gl_context *ctx, struct gl_framebuffer *fb,
- GLuint stencilBits);
-
-
-extern GLboolean
-_mesa_add_accum_renderbuffer(struct gl_context *ctx, struct gl_framebuffer *fb,
- GLuint redBits, GLuint greenBits,
- GLuint blueBits, GLuint alphaBits);
-
-extern GLboolean
-_mesa_add_aux_renderbuffers(struct gl_context *ctx, struct gl_framebuffer *fb,
- GLuint bits, GLuint numBuffers);
-
-extern void
-_mesa_add_soft_renderbuffers(struct gl_framebuffer *fb,
- GLboolean color,
- GLboolean depth,
- GLboolean stencil,
- GLboolean accum,
- GLboolean alpha,
- GLboolean aux);
-
extern void
_mesa_add_renderbuffer(struct gl_framebuffer *fb,
gl_buffer_index bufferName, struct gl_renderbuffer *rb);
diff --git a/mesalib/src/mesa/main/texobj.c b/mesalib/src/mesa/main/texobj.c
index 17c78ce3e..8e447cabd 100644
--- a/mesalib/src/mesa/main/texobj.c
+++ b/mesalib/src/mesa/main/texobj.c
@@ -1184,10 +1184,7 @@ _mesa_PrioritizeTextures( GLsizei n, const GLuint *texName,
*
* \return GL_TRUE if all textures are resident and \p residences is left unchanged,
*
- * \sa glAreTexturesResident().
- *
- * Looks up each texture in the hash and calls
- * dd_function_table::IsTextureResident.
+ * Note: we assume all textures are always resident
*/
GLboolean GLAPIENTRY
_mesa_AreTexturesResident(GLsizei n, const GLuint *texName,
@@ -1195,7 +1192,7 @@ _mesa_AreTexturesResident(GLsizei n, const GLuint *texName,
{
GET_CURRENT_CONTEXT(ctx);
GLboolean allResident = GL_TRUE;
- GLint i, j;
+ GLint i;
ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE);
if (n < 0) {
@@ -1206,6 +1203,7 @@ _mesa_AreTexturesResident(GLsizei n, const GLuint *texName,
if (!texName || !residences)
return GL_FALSE;
+ /* We only do error checking on the texture names */
for (i = 0; i < n; i++) {
struct gl_texture_object *t;
if (texName[i] == 0) {
@@ -1217,21 +1215,6 @@ _mesa_AreTexturesResident(GLsizei n, const GLuint *texName,
_mesa_error(ctx, GL_INVALID_VALUE, "glAreTexturesResident");
return GL_FALSE;
}
- if (!ctx->Driver.IsTextureResident ||
- ctx->Driver.IsTextureResident(ctx, t)) {
- /* The texture is resident */
- if (!allResident)
- residences[i] = GL_TRUE;
- }
- else {
- /* The texture is not resident */
- if (allResident) {
- allResident = GL_FALSE;
- for (j = 0; j < i; j++)
- residences[j] = GL_TRUE;
- }
- residences[i] = GL_FALSE;
- }
}
return allResident;
diff --git a/mesalib/src/mesa/main/texparam.c b/mesalib/src/mesa/main/texparam.c
index f4ec63388..0f92a5b98 100644
--- a/mesalib/src/mesa/main/texparam.c
+++ b/mesalib/src/mesa/main/texparam.c
@@ -1114,8 +1114,7 @@ _mesa_GetTexParameterfv( GLenum target, GLenum pname, GLfloat *params )
}
break;
case GL_TEXTURE_RESIDENT:
- *params = ctx->Driver.IsTextureResident ?
- ctx->Driver.IsTextureResident(ctx, obj) : 1.0F;
+ *params = 1.0F;
break;
case GL_TEXTURE_PRIORITY:
*params = obj->Priority;
@@ -1261,8 +1260,7 @@ _mesa_GetTexParameteriv( GLenum target, GLenum pname, GLint *params )
}
break;;
case GL_TEXTURE_RESIDENT:
- *params = ctx->Driver.IsTextureResident ?
- ctx->Driver.IsTextureResident(ctx, obj) : 1;
+ *params = 1;
break;;
case GL_TEXTURE_PRIORITY:
*params = FLOAT_TO_INT(obj->Priority);
diff --git a/mesalib/src/mesa/main/texstore.c b/mesalib/src/mesa/main/texstore.c
index 37fea2156..a57a38e12 100644
--- a/mesalib/src/mesa/main/texstore.c
+++ b/mesalib/src/mesa/main/texstore.c
@@ -954,8 +954,7 @@ memcpy_texture(struct gl_context *ctx,
GLubyte *dstImage = dstSlices[dstZoffset + img]
+ dstYoffset * dstRowStride
+ dstXoffset * texelBytes;
- ctx->Driver.TextureMemCpy(dstImage, srcImage,
- bytesPerRow * srcHeight);
+ memcpy(dstImage, srcImage, bytesPerRow * srcHeight);
srcImage += srcImageStride;
}
}
@@ -968,7 +967,7 @@ memcpy_texture(struct gl_context *ctx,
+ dstYoffset * dstRowStride
+ dstXoffset * texelBytes;
for (row = 0; row < srcHeight; row++) {
- ctx->Driver.TextureMemCpy(dstRow, srcRow, bytesPerRow);
+ memcpy(dstRow, srcRow, bytesPerRow);
dstRow += dstRowStride;
srcRow += srcRowStride;
}
@@ -3569,6 +3568,8 @@ _mesa_texstore_rgba_int8(TEXSTORE_PARAMS)
dstFormat == MESA_FORMAT_LUMINANCE_ALPHA_INT8);
ASSERT(baseInternalFormat == GL_RGBA ||
baseInternalFormat == GL_RGB ||
+ baseInternalFormat == GL_RG ||
+ baseInternalFormat == GL_RED ||
baseInternalFormat == GL_ALPHA ||
baseInternalFormat == GL_LUMINANCE ||
baseInternalFormat == GL_LUMINANCE_ALPHA ||
@@ -3639,6 +3640,8 @@ _mesa_texstore_rgba_int16(TEXSTORE_PARAMS)
dstFormat == MESA_FORMAT_LUMINANCE_ALPHA_INT16);
ASSERT(baseInternalFormat == GL_RGBA ||
baseInternalFormat == GL_RGB ||
+ baseInternalFormat == GL_RG ||
+ baseInternalFormat == GL_RED ||
baseInternalFormat == GL_ALPHA ||
baseInternalFormat == GL_LUMINANCE ||
baseInternalFormat == GL_LUMINANCE_ALPHA ||
@@ -3709,6 +3712,8 @@ _mesa_texstore_rgba_int32(TEXSTORE_PARAMS)
dstFormat == MESA_FORMAT_LUMINANCE_ALPHA_INT32);
ASSERT(baseInternalFormat == GL_RGBA ||
baseInternalFormat == GL_RGB ||
+ baseInternalFormat == GL_RG ||
+ baseInternalFormat == GL_RED ||
baseInternalFormat == GL_ALPHA ||
baseInternalFormat == GL_LUMINANCE ||
baseInternalFormat == GL_LUMINANCE_ALPHA ||
@@ -3779,6 +3784,8 @@ _mesa_texstore_rgba_uint8(TEXSTORE_PARAMS)
dstFormat == MESA_FORMAT_LUMINANCE_ALPHA_UINT8);
ASSERT(baseInternalFormat == GL_RGBA ||
baseInternalFormat == GL_RGB ||
+ baseInternalFormat == GL_RG ||
+ baseInternalFormat == GL_RED ||
baseInternalFormat == GL_ALPHA ||
baseInternalFormat == GL_LUMINANCE ||
baseInternalFormat == GL_LUMINANCE_ALPHA ||
@@ -3847,6 +3854,8 @@ _mesa_texstore_rgba_uint16(TEXSTORE_PARAMS)
dstFormat == MESA_FORMAT_LUMINANCE_ALPHA_UINT16);
ASSERT(baseInternalFormat == GL_RGBA ||
baseInternalFormat == GL_RGB ||
+ baseInternalFormat == GL_RG ||
+ baseInternalFormat == GL_RED ||
baseInternalFormat == GL_ALPHA ||
baseInternalFormat == GL_LUMINANCE ||
baseInternalFormat == GL_LUMINANCE_ALPHA ||
@@ -3915,6 +3924,8 @@ _mesa_texstore_rgba_uint32(TEXSTORE_PARAMS)
dstFormat == MESA_FORMAT_LUMINANCE_ALPHA_UINT32);
ASSERT(baseInternalFormat == GL_RGBA ||
baseInternalFormat == GL_RGB ||
+ baseInternalFormat == GL_RG ||
+ baseInternalFormat == GL_RED ||
baseInternalFormat == GL_ALPHA ||
baseInternalFormat == GL_LUMINANCE ||
baseInternalFormat == GL_LUMINANCE_ALPHA ||
diff --git a/mesalib/src/mesa/sources.mak b/mesalib/src/mesa/sources.mak
index 1f109fb36..a3ce85535 100644
--- a/mesalib/src/mesa/sources.mak
+++ b/mesalib/src/mesa/sources.mak
@@ -42,6 +42,7 @@ MAIN_SOURCES = \
main/ffvertex_prog.c \
main/fog.c \
main/formats.c \
+ main/format_pack.c \
main/format_unpack.c \
main/framebuffer.c \
main/get.c \
@@ -124,7 +125,6 @@ MATH_XFORM_SOURCES = \
SWRAST_SOURCES = \
swrast/s_aaline.c \
swrast/s_aatriangle.c \
- swrast/s_accum.c \
swrast/s_alpha.c \
swrast/s_atifragshader.c \
swrast/s_bitmap.c \
@@ -142,6 +142,7 @@ SWRAST_SOURCES = \
swrast/s_logic.c \
swrast/s_masking.c \
swrast/s_points.c \
+ swrast/s_renderbuffer.c \
swrast/s_span.c \
swrast/s_stencil.c \
swrast/s_texcombine.c \
@@ -208,7 +209,6 @@ STATETRACKER_SOURCES = \
state_tracker/st_atom_stipple.c \
state_tracker/st_atom_texture.c \
state_tracker/st_atom_viewport.c \
- state_tracker/st_cb_accum.c \
state_tracker/st_cb_bitmap.c \
state_tracker/st_cb_blit.c \
state_tracker/st_cb_bufferobjects.c \
diff --git a/mesalib/src/mesa/state_tracker/st_cb_accum.c b/mesalib/src/mesa/state_tracker/st_cb_accum.c
deleted file mode 100644
index 3e3659d15..000000000
--- a/mesalib/src/mesa/state_tracker/st_cb_accum.c
+++ /dev/null
@@ -1,347 +0,0 @@
-/**************************************************************************
- *
- * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sub license, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
- * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
- * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
- * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
- * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- **************************************************************************/
-
- /*
- * Authors:
- * Brian Paul
- */
-
-#include "main/imports.h"
-#include "main/image.h"
-#include "main/macros.h"
-#include "main/mfeatures.h"
-
-#include "st_debug.h"
-#include "st_context.h"
-#include "st_cb_accum.h"
-#include "st_cb_fbo.h"
-#include "st_texture.h"
-#include "pipe/p_context.h"
-#include "pipe/p_defines.h"
-#include "util/u_format.h"
-#include "util/u_inlines.h"
-#include "util/u_tile.h"
-
-
-#if FEATURE_accum
-
-/**
- * For hardware that supports deep color buffers, we could accelerate
- * most/all the accum operations with blending/texturing.
- * For now, just use the get/put_tile() functions and do things in software.
- */
-
-
-void
-st_clear_accum_buffer(struct gl_context *ctx, struct gl_renderbuffer *rb)
-{
- struct st_renderbuffer *acc_strb = st_renderbuffer(rb);
- const GLint xpos = ctx->DrawBuffer->_Xmin;
- const GLint ypos = ctx->DrawBuffer->_Ymin;
- const GLint width = ctx->DrawBuffer->_Xmax - xpos;
- const GLint height = ctx->DrawBuffer->_Ymax - ypos;
- size_t stride = acc_strb->stride;
- GLubyte *data = acc_strb->data;
-
- if(!data)
- return;
-
- switch (acc_strb->format) {
- case PIPE_FORMAT_R16G16B16A16_SNORM:
- {
- GLshort r = FLOAT_TO_SHORT(ctx->Accum.ClearColor[0]);
- GLshort g = FLOAT_TO_SHORT(ctx->Accum.ClearColor[1]);
- GLshort b = FLOAT_TO_SHORT(ctx->Accum.ClearColor[2]);
- GLshort a = FLOAT_TO_SHORT(ctx->Accum.ClearColor[3]);
- int i, j;
- for (i = 0; i < height; i++) {
- GLshort *dst = (GLshort *) (data + (ypos + i) * stride + xpos * 8);
- for (j = 0; j < width; j++) {
- dst[0] = r;
- dst[1] = g;
- dst[2] = b;
- dst[3] = a;
- dst += 4;
- }
- }
- }
- break;
- default:
- _mesa_problem(ctx, "unexpected format in st_clear_accum_buffer()");
- }
-}
-
-
-/** For ADD/MULT */
-static void
-accum_mad(struct gl_context *ctx, GLfloat scale, GLfloat bias,
- GLint xpos, GLint ypos, GLint width, GLint height,
- struct st_renderbuffer *acc_strb)
-{
- size_t stride = acc_strb->stride;
- GLubyte *data = acc_strb->data;
-
- switch (acc_strb->format) {
- case PIPE_FORMAT_R16G16B16A16_SNORM:
- {
- int i, j;
- for (i = 0; i < height; i++) {
- GLshort *acc = (GLshort *) (data + (ypos + i) * stride + xpos * 8);
- for (j = 0; j < width * 4; j++) {
- float val = SHORT_TO_FLOAT(*acc) * scale + bias;
- *acc++ = FLOAT_TO_SHORT(val);
- }
- }
- }
- break;
- default:
- _mesa_problem(NULL, "unexpected format in st_clear_accum_buffer()");
- }
-}
-
-
-static void
-accum_accum(struct st_context *st, GLfloat value,
- GLint xpos, GLint ypos, GLint width, GLint height,
- struct st_renderbuffer *acc_strb,
- struct st_renderbuffer *color_strb)
-{
- struct pipe_context *pipe = st->pipe;
- struct pipe_transfer *color_trans;
- size_t stride = acc_strb->stride;
- GLubyte *data = acc_strb->data;
- GLfloat *buf;
-
- if (ST_DEBUG & DEBUG_FALLBACK)
- debug_printf("%s: fallback processing\n", __FUNCTION__);
-
- color_trans = pipe_get_transfer(st->pipe,
- color_strb->texture,
- 0, 0,
- PIPE_TRANSFER_READ, xpos, ypos,
- width, height);
-
- buf = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat));
-
- pipe_get_tile_rgba_format(pipe, color_trans, 0, 0, width, height,
- util_format_linear(color_strb->texture->format),
- buf);
-
- switch (acc_strb->format) {
- case PIPE_FORMAT_R16G16B16A16_SNORM:
- {
- const GLfloat *color = buf;
- int i, j;
- for (i = 0; i < height; i++) {
- GLshort *acc = (GLshort *) (data + (ypos + i) * stride + xpos * 8);
- for (j = 0; j < width * 4; j++) {
- float val = *color++ * value;
- *acc++ += FLOAT_TO_SHORT(val);
- }
- }
- }
- break;
- default:
- _mesa_problem(NULL, "unexpected format in st_clear_accum_buffer()");
- }
-
- free(buf);
- pipe->transfer_destroy(pipe, color_trans);
-}
-
-
-static void
-accum_load(struct st_context *st, GLfloat value,
- GLint xpos, GLint ypos, GLint width, GLint height,
- struct st_renderbuffer *acc_strb,
- struct st_renderbuffer *color_strb)
-{
- struct pipe_context *pipe = st->pipe;
- struct pipe_transfer *color_trans;
- size_t stride = acc_strb->stride;
- GLubyte *data = acc_strb->data;
- GLfloat *buf;
-
- if (ST_DEBUG & DEBUG_FALLBACK)
- debug_printf("%s: fallback processing\n", __FUNCTION__);
-
- color_trans = pipe_get_transfer(st->pipe, color_strb->texture,
- 0, 0,
- PIPE_TRANSFER_READ, xpos, ypos,
- width, height);
-
- buf = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat));
-
- pipe_get_tile_rgba_format(pipe, color_trans, 0, 0, width, height,
- util_format_linear(color_strb->texture->format),
- buf);
-
- switch (acc_strb->format) {
- case PIPE_FORMAT_R16G16B16A16_SNORM:
- {
- const GLfloat *color = buf;
- int i, j;
- for (i = 0; i < height; i++) {
- GLshort *acc = (GLshort *) (data + (ypos + i) * stride + xpos * 8);
- for (j = 0; j < width * 4; j++) {
- float val = *color++ * value;
- *acc++ = FLOAT_TO_SHORT(val);
- }
- }
- }
- break;
- default:
- _mesa_problem(NULL, "unexpected format in st_clear_accum_buffer()");
- }
-
- free(buf);
- pipe->transfer_destroy(pipe, color_trans);
-}
-
-
-static void
-accum_return(struct gl_context *ctx, GLfloat value,
- GLint xpos, GLint ypos, GLint width, GLint height,
- struct st_renderbuffer *acc_strb,
- struct st_renderbuffer *color_strb)
-{
- struct pipe_context *pipe = st_context(ctx)->pipe;
- const GLubyte *colormask = ctx->Color.ColorMask[0];
- enum pipe_transfer_usage usage;
- struct pipe_transfer *color_trans;
- size_t stride = acc_strb->stride;
- const GLubyte *data = acc_strb->data;
- GLfloat *buf;
- enum pipe_format format = util_format_linear(color_strb->texture->format);
-
- if (ST_DEBUG & DEBUG_FALLBACK)
- debug_printf("%s: fallback processing\n", __FUNCTION__);
-
- buf = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat));
-
- if (!colormask[0] || !colormask[1] || !colormask[2] || !colormask[3])
- usage = PIPE_TRANSFER_READ_WRITE;
- else
- usage = PIPE_TRANSFER_WRITE;
-
- color_trans = pipe_get_transfer(pipe,
- color_strb->texture, 0, 0,
- usage,
- xpos, ypos,
- width, height);
-
- if (usage & PIPE_TRANSFER_READ)
- pipe_get_tile_rgba_format(pipe, color_trans, 0, 0, width, height,
- format, buf);
-
- switch (acc_strb->format) {
- case PIPE_FORMAT_R16G16B16A16_SNORM:
- {
- GLfloat *color = buf;
- int i, j, ch;
- for (i = 0; i < height; i++) {
- const GLshort *acc = (const GLshort *) (data + (ypos + i) * stride + xpos * 8);
- for (j = 0; j < width; j++) {
- for (ch = 0; ch < 4; ch++) {
- if (colormask[ch]) {
- GLfloat val = SHORT_TO_FLOAT(*acc * value);
- *color = CLAMP(val, 0.0f, 1.0f);
- }
- else {
- /* No change */
- }
- ++acc;
- ++color;
- }
- }
- }
- }
- break;
- default:
- _mesa_problem(NULL, "unexpected format in st_clear_accum_buffer()");
- }
-
- pipe_put_tile_rgba_format(pipe, color_trans, 0, 0, width, height,
- format, buf);
-
- free(buf);
- pipe->transfer_destroy(pipe, color_trans);
-}
-
-
-static void
-st_Accum(struct gl_context *ctx, GLenum op, GLfloat value)
-{
- struct st_context *st = st_context(ctx);
- struct st_renderbuffer *acc_strb
- = st_renderbuffer(ctx->DrawBuffer->Attachment[BUFFER_ACCUM].Renderbuffer);
- struct st_renderbuffer *color_strb
- = st_renderbuffer(ctx->ReadBuffer->_ColorReadBuffer);
-
- const GLint xpos = ctx->DrawBuffer->_Xmin;
- const GLint ypos = ctx->DrawBuffer->_Ymin;
- const GLint width = ctx->DrawBuffer->_Xmax - xpos;
- const GLint height = ctx->DrawBuffer->_Ymax - ypos;
-
- if(!acc_strb->data)
- return;
-
- switch (op) {
- case GL_ADD:
- if (value != 0.0F) {
- accum_mad(ctx, 1.0, value, xpos, ypos, width, height, acc_strb);
- }
- break;
- case GL_MULT:
- if (value != 1.0F) {
- accum_mad(ctx, value, 0.0, xpos, ypos, width, height, acc_strb);
- }
- break;
- case GL_ACCUM:
- if (value != 0.0F) {
- accum_accum(st, value, xpos, ypos, width, height, acc_strb, color_strb);
- }
- break;
- case GL_LOAD:
- accum_load(st, value, xpos, ypos, width, height, acc_strb, color_strb);
- break;
- case GL_RETURN:
- accum_return(ctx, value, xpos, ypos, width, height, acc_strb, color_strb);
- break;
- default:
- assert(0);
- }
-}
-
-
-
-void st_init_accum_functions(struct dd_function_table *functions)
-{
- functions->Accum = st_Accum;
-}
-
-#endif /* FEATURE_accum */
diff --git a/mesalib/src/mesa/state_tracker/st_cb_accum.h b/mesalib/src/mesa/state_tracker/st_cb_accum.h
deleted file mode 100644
index 90feddd6f..000000000
--- a/mesalib/src/mesa/state_tracker/st_cb_accum.h
+++ /dev/null
@@ -1,63 +0,0 @@
-/**************************************************************************
- *
- * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sub license, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
- * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
- * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
- * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
- * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- **************************************************************************/
-
-
-#ifndef ST_CB_ACCUM_H
-#define ST_CB_ACCUM_H
-
-
-#include "main/mfeatures.h"
-
-struct dd_function_table;
-struct gl_context;
-struct gl_renderbuffer;
-
-#if FEATURE_accum
-
-extern void
-st_clear_accum_buffer(struct gl_context *ctx, struct gl_renderbuffer *rb);
-
-extern void st_init_accum_functions(struct dd_function_table *functions);
-
-#else
-
-#include "main/compiler.h"
-
-static INLINE void
-st_clear_accum_buffer(struct gl_context *ctx, struct gl_renderbuffer *rb)
-{
- ASSERT_NO_FEATURE();
-}
-
-static INLINE void
-st_init_accum_functions(struct dd_function_table *functions)
-{
-}
-
-#endif /* FEATURE_accum */
-
-#endif /* ST_CB_ACCUM_H */
diff --git a/mesalib/src/mesa/state_tracker/st_cb_clear.c b/mesalib/src/mesa/state_tracker/st_cb_clear.c
index 89273e28e..61d98aeb9 100644
--- a/mesalib/src/mesa/state_tracker/st_cb_clear.c
+++ b/mesalib/src/mesa/state_tracker/st_cb_clear.c
@@ -34,12 +34,12 @@
*/
#include "main/glheader.h"
+#include "main/accum.h"
#include "main/formats.h"
#include "main/macros.h"
#include "program/prog_instruction.h"
#include "st_context.h"
#include "st_atom.h"
-#include "st_cb_accum.h"
#include "st_cb_clear.h"
#include "st_cb_fbo.h"
#include "st_format.h"
@@ -599,8 +599,7 @@ st_Clear(struct gl_context *ctx, GLbitfield mask)
ctx->Depth.Clear, ctx->Stencil.Clear);
}
if (mask & BUFFER_BIT_ACCUM)
- st_clear_accum_buffer(ctx,
- ctx->DrawBuffer->Attachment[BUFFER_ACCUM].Renderbuffer);
+ _mesa_clear_accum_buffer(ctx);
}
diff --git a/mesalib/src/mesa/state_tracker/st_cb_fbo.c b/mesalib/src/mesa/state_tracker/st_cb_fbo.c
index 2a60ed4df..ec40a2b70 100644
--- a/mesalib/src/mesa/state_tracker/st_cb_fbo.c
+++ b/mesalib/src/mesa/state_tracker/st_cb_fbo.c
@@ -667,6 +667,22 @@ st_MapRenderbuffer(struct gl_context *ctx,
unsigned usage;
GLuint y2;
+ if (strb->software) {
+ /* software-allocated renderbuffer (probably an accum buffer) */
+ GLubyte *map = (GLubyte *) strb->data;
+ if (strb->data) {
+ map += strb->stride * y;
+ map += util_format_get_blocksize(strb->format) * x;
+ *mapOut = map;
+ *rowStrideOut = strb->stride;
+ }
+ else {
+ *mapOut = NULL;
+ *rowStrideOut = 0;
+ }
+ return;
+ }
+
usage = 0x0;
if (mode & GL_MAP_READ_BIT)
usage |= PIPE_TRANSFER_READ;
@@ -716,6 +732,11 @@ st_UnmapRenderbuffer(struct gl_context *ctx,
struct st_renderbuffer *strb = st_renderbuffer(rb);
struct pipe_context *pipe = st->pipe;
+ if (strb->software) {
+ /* software-allocated renderbuffer (probably an accum buffer) */
+ return;
+ }
+
pipe_transfer_unmap(pipe, strb->transfer);
pipe->transfer_destroy(pipe, strb->transfer);
strb->transfer = NULL;
diff --git a/mesalib/src/mesa/state_tracker/st_cb_texture.c b/mesalib/src/mesa/state_tracker/st_cb_texture.c
index c58a9df56..52f654d7d 100644
--- a/mesalib/src/mesa/state_tracker/st_cb_texture.c
+++ b/mesalib/src/mesa/state_tracker/st_cb_texture.c
@@ -214,56 +214,6 @@ st_UnmapTextureImage(struct gl_context *ctx,
/**
- * From linux kernel i386 header files, copes with odd sizes better
- * than COPY_DWORDS would:
- * XXX Put this in src/mesa/main/imports.h ???
- */
-#if defined(PIPE_CC_GCC) && defined(PIPE_ARCH_X86)
-static INLINE void *
-__memcpy(void *to, const void *from, size_t n)
-{
- int d0, d1, d2;
- __asm__ __volatile__("rep ; movsl\n\t"
- "testb $2,%b4\n\t"
- "je 1f\n\t"
- "movsw\n"
- "1:\ttestb $1,%b4\n\t"
- "je 2f\n\t"
- "movsb\n" "2:":"=&c"(d0), "=&D"(d1), "=&S"(d2)
- :"0"(n / 4), "q"(n), "1"((long) to), "2"((long) from)
- :"memory");
- return (to);
-}
-#else
-#define __memcpy(a,b,c) memcpy(a,b,c)
-#endif
-
-
-/**
- * The system memcpy (at least on ubuntu 5.10) has problems copying
- * to agp (writecombined) memory from a source which isn't 64-byte
- * aligned - there is a 4x performance falloff.
- *
- * The x86 __memcpy is immune to this but is slightly slower
- * (10%-ish) than the system memcpy.
- *
- * The sse_memcpy seems to have a slight cliff at 64/32 bytes, but
- * isn't much faster than x86_memcpy for agp copies.
- *
- * TODO: switch dynamically.
- */
-static void *
-do_memcpy(void *dest, const void *src, size_t n)
-{
- if ((((unsigned long) src) & 63) || (((unsigned long) dest) & 63)) {
- return __memcpy(dest, src, n);
- }
- else
- return memcpy(dest, src, n);
-}
-
-
-/**
* Return default texture resource binding bitmask for the given format.
*/
static GLuint
@@ -1420,11 +1370,13 @@ st_copy_texsubimage(struct gl_context *ctx,
struct pipe_context *pipe = st->pipe;
struct pipe_screen *screen = pipe->screen;
enum pipe_format dest_format, src_format;
- GLboolean use_fallback = GL_TRUE;
GLboolean matching_base_formats;
GLuint format_writemask, sample_count;
struct pipe_surface *dest_surface = NULL;
GLboolean do_flip = (st_fb_orientation(ctx->ReadBuffer) == Y_0_TOP);
+ struct pipe_surface surf_tmpl;
+ unsigned int dst_usage;
+ GLint srcY0, srcY1;
/* make sure finalize_textures has been called?
*/
@@ -1472,99 +1424,105 @@ st_copy_texsubimage(struct gl_context *ctx,
matching_base_formats =
(_mesa_get_format_base_format(strb->Base.Format) ==
_mesa_get_format_base_format(texImage->TexFormat));
- format_writemask = compatible_src_dst_formats(ctx, &strb->Base, texImage);
- if (ctx->_ImageTransferState == 0x0) {
+ if (ctx->_ImageTransferState) {
+ goto fallback;
+ }
+
+ if (matching_base_formats &&
+ src_format == dest_format &&
+ !do_flip) {
+ /* use surface_copy() / blit */
+ struct pipe_box src_box;
+ u_box_2d_zslice(srcX, srcY, strb->surface->u.tex.first_layer,
+ width, height, &src_box);
+
+ /* for resource_copy_region(), y=0=top, always */
+ pipe->resource_copy_region(pipe,
+ /* dest */
+ stImage->pt,
+ stImage->base.Level,
+ destX, destY, destZ + stImage->base.Face,
+ /* src */
+ strb->texture,
+ strb->surface->u.tex.level,
+ &src_box);
+ return;
+ }
- if (matching_base_formats &&
- src_format == dest_format &&
- !do_flip)
- {
- /* use surface_copy() / blit */
- struct pipe_box src_box;
- u_box_2d_zslice(srcX, srcY, strb->surface->u.tex.first_layer,
- width, height, &src_box);
-
- /* for resource_copy_region(), y=0=top, always */
- pipe->resource_copy_region(pipe,
- /* dest */
- stImage->pt,
- stImage->base.Level,
- destX, destY, destZ + stImage->base.Face,
- /* src */
- strb->texture,
- strb->surface->u.tex.level,
- &src_box);
- use_fallback = GL_FALSE;
- }
- else if (format_writemask &&
- texBaseFormat != GL_DEPTH_COMPONENT &&
- texBaseFormat != GL_DEPTH_STENCIL &&
- screen->is_format_supported(screen, src_format,
- PIPE_TEXTURE_2D, sample_count,
- PIPE_BIND_SAMPLER_VIEW) &&
- screen->is_format_supported(screen, dest_format,
- PIPE_TEXTURE_2D, 0,
- PIPE_BIND_RENDER_TARGET)) {
- /* draw textured quad to do the copy */
- GLint srcY0, srcY1;
- struct pipe_surface surf_tmpl;
- memset(&surf_tmpl, 0, sizeof(surf_tmpl));
- surf_tmpl.format = util_format_linear(stImage->pt->format);
- surf_tmpl.usage = PIPE_BIND_RENDER_TARGET;
- surf_tmpl.u.tex.level = stImage->base.Level;
- surf_tmpl.u.tex.first_layer = stImage->base.Face + destZ;
- surf_tmpl.u.tex.last_layer = stImage->base.Face + destZ;
-
- dest_surface = pipe->create_surface(pipe, stImage->pt,
- &surf_tmpl);
-
- if (do_flip) {
- srcY1 = strb->Base.Height - srcY - height;
- srcY0 = srcY1 + height;
- }
- else {
- srcY0 = srcY;
- srcY1 = srcY0 + height;
- }
+ if (texBaseFormat == GL_DEPTH_STENCIL) {
+ goto fallback;
+ }
- /* Disable conditional rendering. */
- if (st->render_condition) {
- pipe->render_condition(pipe, NULL, 0);
- }
+ if (texBaseFormat == GL_DEPTH_COMPONENT) {
+ format_writemask = TGSI_WRITEMASK_XYZW;
+ dst_usage = PIPE_BIND_DEPTH_STENCIL;
+ }
+ else {
+ format_writemask = compatible_src_dst_formats(ctx, &strb->Base, texImage);
+ dst_usage = PIPE_BIND_RENDER_TARGET;
+ }
- util_blit_pixels_writemask(st->blit,
- strb->texture,
- strb->surface->u.tex.level,
- srcX, srcY0,
- srcX + width, srcY1,
- strb->surface->u.tex.first_layer,
- dest_surface,
- destX, destY,
- destX + width, destY + height,
- 0.0, PIPE_TEX_MIPFILTER_NEAREST,
- format_writemask);
-
- /* Restore conditional rendering state. */
- if (st->render_condition) {
- pipe->render_condition(pipe, st->render_condition,
- st->condition_mode);
- }
+ if (!format_writemask ||
+ !screen->is_format_supported(screen, src_format,
+ PIPE_TEXTURE_2D, sample_count,
+ PIPE_BIND_SAMPLER_VIEW) ||
+ !screen->is_format_supported(screen, dest_format,
+ PIPE_TEXTURE_2D, 0,
+ dst_usage)) {
+ goto fallback;
+ }
- use_fallback = GL_FALSE;
- }
+ if (do_flip) {
+ srcY1 = strb->Base.Height - srcY - height;
+ srcY0 = srcY1 + height;
+ }
+ else {
+ srcY0 = srcY;
+ srcY1 = srcY0 + height;
+ }
+
+ /* Disable conditional rendering. */
+ if (st->render_condition) {
+ pipe->render_condition(pipe, NULL, 0);
+ }
+
+ memset(&surf_tmpl, 0, sizeof(surf_tmpl));
+ surf_tmpl.format = util_format_linear(stImage->pt->format);
+ surf_tmpl.usage = dst_usage;
+ surf_tmpl.u.tex.level = stImage->base.Level;
+ surf_tmpl.u.tex.first_layer = stImage->base.Face + destZ;
+ surf_tmpl.u.tex.last_layer = stImage->base.Face + destZ;
+
+ dest_surface = pipe->create_surface(pipe, stImage->pt,
+ &surf_tmpl);
+ util_blit_pixels_writemask(st->blit,
+ strb->texture,
+ strb->surface->u.tex.level,
+ srcX, srcY0,
+ srcX + width, srcY1,
+ strb->surface->u.tex.first_layer,
+ dest_surface,
+ destX, destY,
+ destX + width, destY + height,
+ 0.0, PIPE_TEX_MIPFILTER_NEAREST,
+ format_writemask);
+ pipe_surface_reference(&dest_surface, NULL);
- if (dest_surface)
- pipe_surface_reference(&dest_surface, NULL);
+ /* Restore conditional rendering state. */
+ if (st->render_condition) {
+ pipe->render_condition(pipe, st->render_condition,
+ st->condition_mode);
}
- if (use_fallback) {
+ return;
+
+fallback:
/* software fallback */
fallback_copy_texsubimage(ctx, target, level,
strb, stImage, texBaseFormat,
destX, destY, destZ,
srcX, srcY, width, height);
- }
}
@@ -1937,8 +1895,6 @@ st_init_texture_functions(struct dd_function_table *functions)
functions->MapTextureImage = st_MapTextureImage;
functions->UnmapTextureImage = st_UnmapTextureImage;
- functions->TextureMemCpy = do_memcpy;
-
/* XXX Temporary until we can query pipe's texture sizes */
functions->TestProxyTexImage = _mesa_test_proxy_teximage;
diff --git a/mesalib/src/mesa/state_tracker/st_context.c b/mesalib/src/mesa/state_tracker/st_context.c
index a1817720d..dc1d33f1d 100644
--- a/mesalib/src/mesa/state_tracker/st_context.c
+++ b/mesalib/src/mesa/state_tracker/st_context.c
@@ -26,6 +26,7 @@
**************************************************************************/
#include "main/imports.h"
+#include "main/accum.h"
#include "main/context.h"
#include "main/samplerobj.h"
#include "main/shaderobj.h"
@@ -34,7 +35,6 @@
#include "glapi/glapi.h"
#include "st_context.h"
#include "st_debug.h"
-#include "st_cb_accum.h"
#include "st_cb_bitmap.h"
#include "st_cb_blit.h"
#include "st_cb_bufferobjects.h"
@@ -276,7 +276,8 @@ void st_init_driver_functions(struct dd_function_table *functions)
_mesa_init_shader_object_functions(functions);
_mesa_init_sampler_object_functions(functions);
- st_init_accum_functions(functions);
+ functions->Accum = _mesa_accum;
+
st_init_blit_functions(functions);
st_init_bufferobject_functions(functions);
st_init_clear_functions(functions);
diff --git a/mesalib/src/mesa/state_tracker/st_extensions.c b/mesalib/src/mesa/state_tracker/st_extensions.c
index 37fb3e7fd..9e39729e9 100644
--- a/mesalib/src/mesa/state_tracker/st_extensions.c
+++ b/mesalib/src/mesa/state_tracker/st_extensions.c
@@ -210,12 +210,10 @@ void st_init_limits(struct st_context *st)
options->MaxUnrollIterations = MIN2(screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_INSTRUCTIONS), 65536);
}
- /* PIPE_CAP_MAX_FS_INPUTS specifies the number of COLORn + GENERICn inputs
- * and is set in MaxNativeAttribs. It's always 2 colors + N generic
- * attributes. The GLSL compiler never uses COLORn for varyings, so we
- * subtract the 2 colors to get the maximum number of varyings (generic
- * attributes) supported by a driver. */
- c->MaxVarying = screen->get_shader_param(screen, PIPE_SHADER_FRAGMENT, PIPE_SHADER_CAP_MAX_INPUTS) - 2;
+ /* PIPE_SHADER_CAP_MAX_INPUTS for the FS specifies the maximum number
+ * of inputs. It's always 2 colors + N generic inputs. */
+ c->MaxVarying = screen->get_shader_param(screen, PIPE_SHADER_FRAGMENT,
+ PIPE_SHADER_CAP_MAX_INPUTS);
c->MaxVarying = MIN2(c->MaxVarying, MAX_VARYING);
c->MinProgramTexelOffset = screen->get_param(screen, PIPE_CAP_MIN_TEXEL_OFFSET);
diff --git a/mesalib/src/mesa/state_tracker/st_glsl_to_tgsi.cpp b/mesalib/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
index 59b5ffd4c..6cc655d70 100644
--- a/mesalib/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/mesalib/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -3514,25 +3514,23 @@ glsl_to_tgsi_visitor::eliminate_dead_code_advanced(void)
break;
case TGSI_OPCODE_ENDIF:
- --level;
- break;
-
case TGSI_OPCODE_ELSE:
- /* Clear all channels written inside the preceding if block from the
- * write array, but leave those that were not touched.
- *
- * FIXME: This destroys opportunities to remove dead code inside of
- * IF blocks that are followed by an ELSE block.
+ /* Promote the recorded level all channels written inside the preceding
+ * if or else block to the level above the if/else block.
*/
for (int r = 0; r < this->next_temp; r++) {
for (int c = 0; c < 4; c++) {
if (!writes[4 * r + c])
continue;
- if (write_level[4 * r + c] >= level)
- writes[4 * r + c] = NULL;
+ if (write_level[4 * r + c] == level)
+ write_level[4 * r + c] = level-1;
}
}
+
+ if(inst->op == TGSI_OPCODE_ENDIF)
+ --level;
+
break;
case TGSI_OPCODE_IF:
diff --git a/mesalib/src/mesa/state_tracker/st_manager.c b/mesalib/src/mesa/state_tracker/st_manager.c
index d5228d387..55699e721 100644
--- a/mesalib/src/mesa/state_tracker/st_manager.c
+++ b/mesalib/src/mesa/state_tracker/st_manager.c
@@ -404,54 +404,6 @@ st_visual_to_context_mode(const struct st_visual *visual,
}
/**
- * Determine the default draw or read buffer from a visual.
- */
-static void
-st_visual_to_default_buffer(const struct st_visual *visual,
- GLenum *buffer, GLint *index)
-{
- enum st_attachment_type statt;
- GLenum buf;
- gl_buffer_index idx;
-
- statt = visual->render_buffer;
- /* do nothing if an invalid render buffer is specified */
- if (statt == ST_ATTACHMENT_INVALID ||
- !st_visual_have_buffers(visual, 1 << statt))
- return;
-
- switch (statt) {
- case ST_ATTACHMENT_FRONT_LEFT:
- buf = GL_FRONT_LEFT;
- idx = BUFFER_FRONT_LEFT;
- break;
- case ST_ATTACHMENT_BACK_LEFT:
- buf = GL_BACK_LEFT;
- idx = BUFFER_BACK_LEFT;
- break;
- case ST_ATTACHMENT_FRONT_RIGHT:
- buf = GL_FRONT_RIGHT;
- idx = BUFFER_FRONT_RIGHT;
- break;
- case ST_ATTACHMENT_BACK_RIGHT:
- buf = GL_BACK_RIGHT;
- idx = BUFFER_BACK_RIGHT;
- break;
- default:
- buf = GL_NONE;
- idx = BUFFER_COUNT;
- break;
- }
-
- if (buf != GL_NONE) {
- if (buffer)
- *buffer = buf;
- if (index)
- *index = idx;
- }
-}
-
-/**
* Create a framebuffer from a manager interface.
*/
static struct st_framebuffer *
@@ -471,12 +423,6 @@ st_framebuffer_create(struct st_framebuffer_iface *stfbi)
st_visual_to_context_mode(stfbi->visual, &mode);
_mesa_initialize_window_framebuffer(&stfb->Base, &mode);
- /* modify the draw/read buffers of the fb */
- st_visual_to_default_buffer(stfbi->visual, &stfb->Base.ColorDrawBuffer[0],
- &stfb->Base._ColorDrawBufferIndexes[0]);
- st_visual_to_default_buffer(stfbi->visual, &stfb->Base.ColorReadBuffer,
- &stfb->Base._ColorReadBufferIndex);
-
stfb->iface = stfbi;
stfb->iface_stamp = p_atomic_read(&stfbi->stamp) - 1;
@@ -776,16 +722,6 @@ st_api_make_current(struct st_api *stapi, struct st_context_iface *stctxi,
if (stread != stdraw)
st_framebuffer_validate(stread, st);
- /* modify the draw/read buffers of the context */
- if (stdraw->iface) {
- st_visual_to_default_buffer(stdraw->iface->visual,
- &st->ctx->Color.DrawBuffer[0], NULL);
- }
- if (stread->iface) {
- st_visual_to_default_buffer(stread->iface->visual,
- &st->ctx->Pixel.ReadBuffer, NULL);
- }
-
ret = _mesa_make_current(st->ctx, &stdraw->Base, &stread->Base);
st->draw_stamp = stdraw->stamp - 1;
diff --git a/mesalib/src/mesa/state_tracker/st_program.c b/mesalib/src/mesa/state_tracker/st_program.c
index 768da5114..04d3ef60f 100644
--- a/mesalib/src/mesa/state_tracker/st_program.c
+++ b/mesalib/src/mesa/state_tracker/st_program.c
@@ -649,6 +649,25 @@ st_translate_fragment_program(struct st_context *st,
if (write_all == GL_TRUE)
ureg_property_fs_color0_writes_all_cbufs(ureg, 1);
+ if (stfp->Base.FragDepthLayout != FRAG_DEPTH_LAYOUT_NONE) {
+ switch (stfp->Base.FragDepthLayout) {
+ case FRAG_DEPTH_LAYOUT_ANY:
+ ureg_property_fs_depth_layout(ureg, TGSI_FS_DEPTH_LAYOUT_ANY);
+ break;
+ case FRAG_DEPTH_LAYOUT_GREATER:
+ ureg_property_fs_depth_layout(ureg, TGSI_FS_DEPTH_LAYOUT_GREATER);
+ break;
+ case FRAG_DEPTH_LAYOUT_LESS:
+ ureg_property_fs_depth_layout(ureg, TGSI_FS_DEPTH_LAYOUT_LESS);
+ break;
+ case FRAG_DEPTH_LAYOUT_UNCHANGED:
+ ureg_property_fs_depth_layout(ureg, TGSI_FS_DEPTH_LAYOUT_UNCHANGED);
+ break;
+ default:
+ assert(0);
+ }
+ }
+
if (stfp->glsl_to_tgsi)
st_translate_program(st->ctx,
TGSI_PROCESSOR_FRAGMENT,
diff --git a/mesalib/src/mesa/swrast/s_accum.c b/mesalib/src/mesa/swrast/s_accum.c
deleted file mode 100644
index 0ec907d79..000000000
--- a/mesalib/src/mesa/swrast/s_accum.c
+++ /dev/null
@@ -1,598 +0,0 @@
-/*
- * Mesa 3-D graphics library
- * Version: 6.5.2
- *
- * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-
-#include "main/glheader.h"
-#include "main/condrender.h"
-#include "main/context.h"
-#include "main/macros.h"
-#include "main/imports.h"
-
-#include "s_accum.h"
-#include "s_context.h"
-#include "s_masking.h"
-#include "s_span.h"
-
-
-/* XXX this would have to change for accum buffers with more or less
- * than 16 bits per color channel.
- */
-#define ACCUM_SCALE16 32767.0F
-
-
-/*
- * Accumulation buffer notes
- *
- * Normally, accumulation buffer values are GLshorts with values in
- * [-32767, 32767] which represent floating point colors in [-1, 1],
- * as defined by the OpenGL specification.
- *
- * We optimize for the common case used for full-scene antialiasing:
- * // start with accum buffer cleared to zero
- * glAccum(GL_LOAD, w); // or GL_ACCUM the first image
- * glAccum(GL_ACCUM, w);
- * ...
- * glAccum(GL_ACCUM, w);
- * glAccum(GL_RETURN, 1.0);
- * That is, we start with an empty accumulation buffer and accumulate
- * n images, each with weight w = 1/n.
- * In this scenario, we can simply store unscaled integer values in
- * the accum buffer instead of scaled integers. We'll also keep track
- * of the w value so when we do GL_RETURN we simply divide the accumulated
- * values by n (n=1/w).
- * This lets us avoid _many_ int->float->int conversions.
- */
-
-
-#if CHAN_BITS == 8
-/* enable the optimization */
-#define USE_OPTIMIZED_ACCUM 1
-#else
-#define USE_OPTIMIZED_ACCUM 0
-#endif
-
-
-/**
- * This is called when we fall out of optimized/unscaled accum buffer mode.
- * That is, we convert each unscaled accum buffer value into a scaled value
- * representing the range[-1, 1].
- */
-static void
-rescale_accum( struct gl_context *ctx )
-{
- SWcontext *swrast = SWRAST_CONTEXT(ctx);
- struct gl_renderbuffer *rb
- = ctx->DrawBuffer->Attachment[BUFFER_ACCUM].Renderbuffer;
- const GLfloat s = swrast->_IntegerAccumScaler * (32767.0F / CHAN_MAXF);
-
- assert(rb);
- assert(rb->_BaseFormat == GL_RGBA);
- /* add other types in future? */
- assert(rb->DataType == GL_SHORT || rb->DataType == GL_UNSIGNED_SHORT);
- assert(swrast->_IntegerAccumMode);
-
- if (rb->GetPointer(ctx, rb, 0, 0)) {
- /* directly-addressable memory */
- GLuint y;
- for (y = 0; y < rb->Height; y++) {
- GLuint i;
- GLshort *acc = (GLshort *) rb->GetPointer(ctx, rb, 0, y);
- for (i = 0; i < 4 * rb->Width; i++) {
- acc[i] = (GLshort) (acc[i] * s);
- }
- }
- }
- else {
- /* use get/put row funcs */
- GLuint y;
- for (y = 0; y < rb->Height; y++) {
- GLshort accRow[MAX_WIDTH * 4];
- GLuint i;
- rb->GetRow(ctx, rb, rb->Width, 0, y, accRow);
- for (i = 0; i < 4 * rb->Width; i++) {
- accRow[i] = (GLshort) (accRow[i] * s);
- }
- rb->PutRow(ctx, rb, rb->Width, 0, y, accRow, NULL);
- }
- }
-
- swrast->_IntegerAccumMode = GL_FALSE;
-}
-
-
-
-/**
- * Clear the accumulation Buffer.
- */
-void
-_swrast_clear_accum_buffer( struct gl_context *ctx, struct gl_renderbuffer *rb )
-{
- SWcontext *swrast = SWRAST_CONTEXT(ctx);
- GLuint x, y, width, height;
-
- /* No accumulation buffer! Not an error. */
- if (!rb || !rb->Data)
- return;
-
- assert(rb->_BaseFormat == GL_RGBA);
- /* add other types in future? */
- assert(rb->DataType == GL_SHORT || rb->DataType == GL_UNSIGNED_SHORT);
-
- /* bounds, with scissor */
- x = ctx->DrawBuffer->_Xmin;
- y = ctx->DrawBuffer->_Ymin;
- width = ctx->DrawBuffer->_Xmax - ctx->DrawBuffer->_Xmin;
- height = ctx->DrawBuffer->_Ymax - ctx->DrawBuffer->_Ymin;
-
- if (rb->DataType == GL_SHORT || rb->DataType == GL_UNSIGNED_SHORT) {
- const GLfloat accScale = 32767.0;
- GLshort clearVal[4];
- GLuint i;
-
- clearVal[0] = (GLshort) (ctx->Accum.ClearColor[0] * accScale);
- clearVal[1] = (GLshort) (ctx->Accum.ClearColor[1] * accScale);
- clearVal[2] = (GLshort) (ctx->Accum.ClearColor[2] * accScale);
- clearVal[3] = (GLshort) (ctx->Accum.ClearColor[3] * accScale);
-
- for (i = 0; i < height; i++) {
- rb->PutMonoRow(ctx, rb, width, x, y + i, clearVal, NULL);
- }
- }
- else {
- /* someday support other sizes */
- }
-
- /* update optimized accum state vars */
- if (ctx->Accum.ClearColor[0] == 0.0 && ctx->Accum.ClearColor[1] == 0.0 &&
- ctx->Accum.ClearColor[2] == 0.0 && ctx->Accum.ClearColor[3] == 0.0) {
-#if USE_OPTIMIZED_ACCUM
- swrast->_IntegerAccumMode = GL_TRUE;
-#else
- swrast->_IntegerAccumMode = GL_FALSE;
-#endif
- swrast->_IntegerAccumScaler = 0.0; /* denotes empty accum buffer */
- }
- else {
- swrast->_IntegerAccumMode = GL_FALSE;
- }
-}
-
-
-static void
-accum_add(struct gl_context *ctx, GLfloat value,
- GLint xpos, GLint ypos, GLint width, GLint height )
-{
- SWcontext *swrast = SWRAST_CONTEXT(ctx);
- struct gl_renderbuffer *rb
- = ctx->DrawBuffer->Attachment[BUFFER_ACCUM].Renderbuffer;
-
- assert(rb);
-
- /* Leave optimized accum buffer mode */
- if (swrast->_IntegerAccumMode)
- rescale_accum(ctx);
-
- if (rb->DataType == GL_SHORT || rb->DataType == GL_UNSIGNED_SHORT) {
- const GLshort incr = (GLshort) (value * ACCUM_SCALE16);
- if (rb->GetPointer(ctx, rb, 0, 0)) {
- GLint i, j;
- for (i = 0; i < height; i++) {
- GLshort *acc = (GLshort *) rb->GetPointer(ctx, rb, xpos, ypos + i);
- for (j = 0; j < 4 * width; j++) {
- acc[j] += incr;
- }
- }
- }
- else {
- GLint i, j;
- for (i = 0; i < height; i++) {
- GLshort accRow[4 * MAX_WIDTH];
- rb->GetRow(ctx, rb, width, xpos, ypos + i, accRow);
- for (j = 0; j < 4 * width; j++) {
- accRow[j] += incr;
- }
- rb->PutRow(ctx, rb, width, xpos, ypos + i, accRow, NULL);
- }
- }
- }
- else {
- /* other types someday */
- }
-}
-
-
-static void
-accum_mult(struct gl_context *ctx, GLfloat mult,
- GLint xpos, GLint ypos, GLint width, GLint height )
-{
- SWcontext *swrast = SWRAST_CONTEXT(ctx);
- struct gl_renderbuffer *rb
- = ctx->DrawBuffer->Attachment[BUFFER_ACCUM].Renderbuffer;
-
- assert(rb);
-
- /* Leave optimized accum buffer mode */
- if (swrast->_IntegerAccumMode)
- rescale_accum(ctx);
-
- if (rb->DataType == GL_SHORT || rb->DataType == GL_UNSIGNED_SHORT) {
- if (rb->GetPointer(ctx, rb, 0, 0)) {
- GLint i, j;
- for (i = 0; i < height; i++) {
- GLshort *acc = (GLshort *) rb->GetPointer(ctx, rb, xpos, ypos + i);
- for (j = 0; j < 4 * width; j++) {
- acc[j] = (GLshort) (acc[j] * mult);
- }
- }
- }
- else {
- GLint i, j;
- for (i = 0; i < height; i++) {
- GLshort accRow[4 * MAX_WIDTH];
- rb->GetRow(ctx, rb, width, xpos, ypos + i, accRow);
- for (j = 0; j < 4 * width; j++) {
- accRow[j] = (GLshort) (accRow[j] * mult);
- }
- rb->PutRow(ctx, rb, width, xpos, ypos + i, accRow, NULL);
- }
- }
- }
- else {
- /* other types someday */
- }
-}
-
-
-
-static void
-accum_accum(struct gl_context *ctx, GLfloat value,
- GLint xpos, GLint ypos, GLint width, GLint height )
-{
- SWcontext *swrast = SWRAST_CONTEXT(ctx);
- struct gl_renderbuffer *rb
- = ctx->DrawBuffer->Attachment[BUFFER_ACCUM].Renderbuffer;
- const GLboolean directAccess = (rb->GetPointer(ctx, rb, 0, 0) != NULL);
-
- assert(rb);
-
- if (!ctx->ReadBuffer->_ColorReadBuffer) {
- /* no read buffer - OK */
- return;
- }
-
- /* May have to leave optimized accum buffer mode */
- if (swrast->_IntegerAccumScaler == 0.0 && value > 0.0 && value <= 1.0)
- swrast->_IntegerAccumScaler = value;
- if (swrast->_IntegerAccumMode && value != swrast->_IntegerAccumScaler)
- rescale_accum(ctx);
-
- if (rb->DataType == GL_SHORT || rb->DataType == GL_UNSIGNED_SHORT) {
- const GLfloat scale = value * ACCUM_SCALE16 / CHAN_MAXF;
- GLshort accumRow[4 * MAX_WIDTH];
- GLchan rgba[MAX_WIDTH][4];
- GLint i;
-
- for (i = 0; i < height; i++) {
- GLshort *acc;
- if (directAccess) {
- acc = (GLshort *) rb->GetPointer(ctx, rb, xpos, ypos + i);
- }
- else {
- rb->GetRow(ctx, rb, width, xpos, ypos + i, accumRow);
- acc = accumRow;
- }
-
- /* read colors from color buffer */
- _swrast_read_rgba_span(ctx, ctx->ReadBuffer->_ColorReadBuffer, width,
- xpos, ypos + i, CHAN_TYPE, rgba);
-
- /* do accumulation */
- if (swrast->_IntegerAccumMode) {
- /* simply add integer color values into accum buffer */
- GLint j;
- for (j = 0; j < width; j++) {
- acc[j * 4 + 0] += rgba[j][RCOMP];
- acc[j * 4 + 1] += rgba[j][GCOMP];
- acc[j * 4 + 2] += rgba[j][BCOMP];
- acc[j * 4 + 3] += rgba[j][ACOMP];
- }
- }
- else {
- /* scaled integer (or float) accum buffer */
- GLint j;
- for (j = 0; j < width; j++) {
- acc[j * 4 + 0] += (GLshort) ((GLfloat) rgba[j][RCOMP] * scale);
- acc[j * 4 + 1] += (GLshort) ((GLfloat) rgba[j][GCOMP] * scale);
- acc[j * 4 + 2] += (GLshort) ((GLfloat) rgba[j][BCOMP] * scale);
- acc[j * 4 + 3] += (GLshort) ((GLfloat) rgba[j][ACOMP] * scale);
- }
- }
-
- if (!directAccess) {
- rb->PutRow(ctx, rb, width, xpos, ypos + i, accumRow, NULL);
- }
- }
- }
- else {
- /* other types someday */
- }
-}
-
-
-
-static void
-accum_load(struct gl_context *ctx, GLfloat value,
- GLint xpos, GLint ypos, GLint width, GLint height )
-{
- SWcontext *swrast = SWRAST_CONTEXT(ctx);
- struct gl_renderbuffer *rb
- = ctx->DrawBuffer->Attachment[BUFFER_ACCUM].Renderbuffer;
- const GLboolean directAccess = (rb->GetPointer(ctx, rb, 0, 0) != NULL);
-
- assert(rb);
-
- if (!ctx->ReadBuffer->_ColorReadBuffer) {
- /* no read buffer - OK */
- return;
- }
-
- /* This is a change to go into optimized accum buffer mode */
- if (value > 0.0 && value <= 1.0) {
-#if USE_OPTIMIZED_ACCUM
- swrast->_IntegerAccumMode = GL_TRUE;
-#else
- swrast->_IntegerAccumMode = GL_FALSE;
-#endif
- swrast->_IntegerAccumScaler = value;
- }
- else {
- swrast->_IntegerAccumMode = GL_FALSE;
- swrast->_IntegerAccumScaler = 0.0;
- }
-
- if (rb->DataType == GL_SHORT || rb->DataType == GL_UNSIGNED_SHORT) {
- const GLfloat scale = value * ACCUM_SCALE16 / CHAN_MAXF;
- GLshort accumRow[4 * MAX_WIDTH];
- GLchan rgba[MAX_WIDTH][4];
- GLint i;
-
- for (i = 0; i < height; i++) {
- GLshort *acc;
- if (directAccess) {
- acc = (GLshort *) rb->GetPointer(ctx, rb, xpos, ypos + i);
- }
- else {
- rb->GetRow(ctx, rb, width, xpos, ypos + i, accumRow);
- acc = accumRow;
- }
-
- /* read colors from color buffer */
- _swrast_read_rgba_span(ctx, ctx->ReadBuffer->_ColorReadBuffer, width,
- xpos, ypos + i, CHAN_TYPE, rgba);
-
- /* do load */
- if (swrast->_IntegerAccumMode) {
- /* just copy values in */
- GLint j;
- assert(swrast->_IntegerAccumScaler > 0.0);
- assert(swrast->_IntegerAccumScaler <= 1.0);
- for (j = 0; j < width; j++) {
- acc[j * 4 + 0] = rgba[j][RCOMP];
- acc[j * 4 + 1] = rgba[j][GCOMP];
- acc[j * 4 + 2] = rgba[j][BCOMP];
- acc[j * 4 + 3] = rgba[j][ACOMP];
- }
- }
- else {
- /* scaled integer (or float) accum buffer */
- GLint j;
- for (j = 0; j < width; j++) {
- acc[j * 4 + 0] = (GLshort) ((GLfloat) rgba[j][RCOMP] * scale);
- acc[j * 4 + 1] = (GLshort) ((GLfloat) rgba[j][GCOMP] * scale);
- acc[j * 4 + 2] = (GLshort) ((GLfloat) rgba[j][BCOMP] * scale);
- acc[j * 4 + 3] = (GLshort) ((GLfloat) rgba[j][ACOMP] * scale);
- }
- }
-
- if (!directAccess) {
- rb->PutRow(ctx, rb, width, xpos, ypos + i, accumRow, NULL);
- }
- }
- }
-}
-
-
-static void
-accum_return(struct gl_context *ctx, GLfloat value,
- GLint xpos, GLint ypos, GLint width, GLint height )
-{
- SWcontext *swrast = SWRAST_CONTEXT(ctx);
- struct gl_framebuffer *fb = ctx->DrawBuffer;
- struct gl_renderbuffer *accumRb = fb->Attachment[BUFFER_ACCUM].Renderbuffer;
- const GLboolean directAccess
- = (accumRb->GetPointer(ctx, accumRb, 0, 0) != NULL);
-
- static GLchan multTable[32768];
- static GLfloat prevMult = 0.0;
- const GLfloat mult = swrast->_IntegerAccumScaler;
- const GLint max = MIN2((GLint) (256 / mult), 32767);
-
- /* May have to leave optimized accum buffer mode */
- if (swrast->_IntegerAccumMode && value != 1.0)
- rescale_accum(ctx);
-
- if (swrast->_IntegerAccumMode && swrast->_IntegerAccumScaler > 0) {
- /* build lookup table to avoid many floating point multiplies */
- GLint j;
- assert(swrast->_IntegerAccumScaler <= 1.0);
- if (mult != prevMult) {
- for (j = 0; j < max; j++)
- multTable[j] = IROUND((GLfloat) j * mult);
- prevMult = mult;
- }
- }
-
- if (accumRb->DataType == GL_SHORT ||
- accumRb->DataType == GL_UNSIGNED_SHORT) {
- const GLfloat scale = value * CHAN_MAXF / ACCUM_SCALE16;
- GLuint buffer;
- GLint i;
-
- /* XXX maybe transpose the 'i' and 'buffer' loops??? */
- for (i = 0; i < height; i++) {
- GLshort accumRow[4 * MAX_WIDTH];
- GLshort *acc;
- SWspan span;
-
- /* init color span */
- INIT_SPAN(span, GL_BITMAP);
- span.end = width;
- span.arrayMask = SPAN_RGBA;
- span.x = xpos;
- span.y = ypos + i;
-
- if (directAccess) {
- acc = (GLshort *) accumRb->GetPointer(ctx, accumRb, xpos, ypos +i);
- }
- else {
- accumRb->GetRow(ctx, accumRb, width, xpos, ypos + i, accumRow);
- acc = accumRow;
- }
-
- /* get the colors to return */
- if (swrast->_IntegerAccumMode) {
- GLint j;
- for (j = 0; j < width; j++) {
- ASSERT(acc[j * 4 + 0] < max);
- ASSERT(acc[j * 4 + 1] < max);
- ASSERT(acc[j * 4 + 2] < max);
- ASSERT(acc[j * 4 + 3] < max);
- span.array->rgba[j][RCOMP] = multTable[acc[j * 4 + 0]];
- span.array->rgba[j][GCOMP] = multTable[acc[j * 4 + 1]];
- span.array->rgba[j][BCOMP] = multTable[acc[j * 4 + 2]];
- span.array->rgba[j][ACOMP] = multTable[acc[j * 4 + 3]];
- }
- }
- else {
- /* scaled integer (or float) accum buffer */
- GLint j;
- for (j = 0; j < width; j++) {
-#if CHAN_BITS==32
- GLchan r = acc[j * 4 + 0] * scale;
- GLchan g = acc[j * 4 + 1] * scale;
- GLchan b = acc[j * 4 + 2] * scale;
- GLchan a = acc[j * 4 + 3] * scale;
-#else
- GLint r = IROUND( (GLfloat) (acc[j * 4 + 0]) * scale );
- GLint g = IROUND( (GLfloat) (acc[j * 4 + 1]) * scale );
- GLint b = IROUND( (GLfloat) (acc[j * 4 + 2]) * scale );
- GLint a = IROUND( (GLfloat) (acc[j * 4 + 3]) * scale );
-#endif
- span.array->rgba[j][RCOMP] = CLAMP( r, 0, CHAN_MAX );
- span.array->rgba[j][GCOMP] = CLAMP( g, 0, CHAN_MAX );
- span.array->rgba[j][BCOMP] = CLAMP( b, 0, CHAN_MAX );
- span.array->rgba[j][ACOMP] = CLAMP( a, 0, CHAN_MAX );
- }
- }
-
- /* store colors */
- for (buffer = 0; buffer < fb->_NumColorDrawBuffers; buffer++) {
- struct gl_renderbuffer *rb = fb->_ColorDrawBuffers[buffer];
- const GLboolean masking = (!ctx->Color.ColorMask[buffer][RCOMP] ||
- !ctx->Color.ColorMask[buffer][GCOMP] ||
- !ctx->Color.ColorMask[buffer][BCOMP] ||
- !ctx->Color.ColorMask[buffer][ACOMP]);
- if (masking) {
- _swrast_mask_rgba_span(ctx, rb, &span, buffer);
- }
- rb->PutRow(ctx, rb, width, xpos, ypos + i, span.array->rgba, NULL);
- }
- }
- }
- else {
- /* other types someday */
- }
-}
-
-
-
-/**
- * Software fallback for glAccum.
- */
-void
-_swrast_Accum(struct gl_context *ctx, GLenum op, GLfloat value)
-{
- SWcontext *swrast = SWRAST_CONTEXT(ctx);
- GLint xpos, ypos, width, height;
-
- if (swrast->NewState)
- _swrast_validate_derived( ctx );
-
- if (!ctx->DrawBuffer->Attachment[BUFFER_ACCUM].Renderbuffer) {
- _mesa_warning(ctx, "Calling glAccum() without an accumulation buffer");
- return;
- }
-
- if (!_mesa_check_conditional_render(ctx))
- return;
-
- swrast_render_start(ctx);
-
- /* Compute region after calling swrast_render_start() so that we know the
- * drawbuffer's size/bounds are up to date.
- */
- xpos = ctx->DrawBuffer->_Xmin;
- ypos = ctx->DrawBuffer->_Ymin;
- width = ctx->DrawBuffer->_Xmax - ctx->DrawBuffer->_Xmin;
- height = ctx->DrawBuffer->_Ymax - ctx->DrawBuffer->_Ymin;
-
- switch (op) {
- case GL_ADD:
- if (value != 0.0F) {
- accum_add(ctx, value, xpos, ypos, width, height);
- }
- break;
- case GL_MULT:
- if (value != 1.0F) {
- accum_mult(ctx, value, xpos, ypos, width, height);
- }
- break;
- case GL_ACCUM:
- if (value != 0.0F) {
- accum_accum(ctx, value, xpos, ypos, width, height);
- }
- break;
- case GL_LOAD:
- accum_load(ctx, value, xpos, ypos, width, height);
- break;
- case GL_RETURN:
- accum_return(ctx, value, xpos, ypos, width, height);
- break;
- default:
- _mesa_problem(ctx, "invalid mode in _swrast_Accum()");
- break;
- }
-
- swrast_render_finish(ctx);
-}
diff --git a/mesalib/src/mesa/swrast/s_clear.c b/mesalib/src/mesa/swrast/s_clear.c
index 980d29bba..615747d69 100644
--- a/mesalib/src/mesa/swrast/s_clear.c
+++ b/mesalib/src/mesa/swrast/s_clear.c
@@ -23,13 +23,13 @@
*/
#include "main/glheader.h"
+#include "main/accum.h"
#include "main/colormac.h"
#include "main/condrender.h"
#include "main/macros.h"
#include "main/imports.h"
#include "main/mtypes.h"
-#include "s_accum.h"
#include "s_context.h"
#include "s_depth.h"
#include "s_masking.h"
@@ -225,8 +225,7 @@ _swrast_Clear(struct gl_context *ctx, GLbitfield buffers)
_swrast_clear_depth_buffer(ctx, ctx->DrawBuffer->_DepthBuffer);
}
if (buffers & BUFFER_BIT_ACCUM) {
- _swrast_clear_accum_buffer(ctx,
- ctx->DrawBuffer->Attachment[BUFFER_ACCUM].Renderbuffer);
+ _mesa_clear_accum_buffer(ctx);
}
if (buffers & BUFFER_BIT_STENCIL) {
_swrast_clear_stencil_buffer(ctx, ctx->DrawBuffer->_StencilBuffer);
diff --git a/mesalib/src/mesa/swrast/s_context.c b/mesalib/src/mesa/swrast/s_context.c
index 98702f068..924612578 100644
--- a/mesalib/src/mesa/swrast/s_context.c
+++ b/mesalib/src/mesa/swrast/s_context.c
@@ -597,7 +597,7 @@ _swrast_validate_derived( struct gl_context *ctx )
#define SWRAST_DEBUG 0
-/* Public entrypoints: See also s_accum.c, s_bitmap.c, etc.
+/* Public entrypoints: See also s_bitmap.c, etc.
*/
void
_swrast_Quad( struct gl_context *ctx,
@@ -755,10 +755,6 @@ _swrast_CreateContext( struct gl_context *ctx )
ctx->Driver.MapTexture = _swrast_map_texture;
ctx->Driver.UnmapTexture = _swrast_unmap_texture;
- /* Optimized Accum buffer */
- swrast->_IntegerAccumMode = GL_FALSE;
- swrast->_IntegerAccumScaler = 0.0;
-
for (i = 0; i < MAX_TEXTURE_IMAGE_UNITS; i++)
swrast->TextureSample[i] = NULL;
diff --git a/mesalib/src/mesa/swrast/s_context.h b/mesalib/src/mesa/swrast/s_context.h
index d3ba37819..446b990d9 100644
--- a/mesalib/src/mesa/swrast/s_context.h
+++ b/mesalib/src/mesa/swrast/s_context.h
@@ -203,11 +203,6 @@ typedef struct
/** Indicates how each attrib is to be interpolated (lines/tris) */
GLenum _InterpMode[FRAG_ATTRIB_MAX]; /* GL_FLAT or GL_SMOOTH (for now) */
- /* Accum buffer temporaries.
- */
- GLboolean _IntegerAccumMode; /**< Storing unscaled integers? */
- GLfloat _IntegerAccumScaler; /**< Implicit scale factor */
-
/* Working values:
*/
GLuint StippleCounter; /**< Line stipple counter */
diff --git a/mesalib/src/mesa/swrast/s_copypix.c b/mesalib/src/mesa/swrast/s_copypix.c
index 3ba31f22c..3bdf48b25 100644
--- a/mesalib/src/mesa/swrast/s_copypix.c
+++ b/mesalib/src/mesa/swrast/s_copypix.c
@@ -610,6 +610,7 @@ fast_copy_pixels(struct gl_context *ctx,
struct gl_framebuffer *dstFb = ctx->DrawBuffer;
struct gl_renderbuffer *srcRb, *dstRb;
GLint row, yStep;
+ void *temp;
if (SWRAST_CONTEXT(ctx)->_RasterMask != 0x0 ||
ctx->Pixel.ZoomX != 1.0F ||
@@ -667,14 +668,21 @@ fast_copy_pixels(struct gl_context *ctx,
yStep = 1;
}
+ temp = malloc(width * MAX_PIXEL_BYTES);
+ if (!temp) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCopyPixels");
+ return GL_FALSE;
+ }
+
for (row = 0; row < height; row++) {
- GLuint temp[MAX_WIDTH][4];
srcRb->GetRow(ctx, srcRb, width, srcX, srcY, temp);
dstRb->PutRow(ctx, dstRb, width, dstX, dstY, temp, NULL);
srcY += yStep;
dstY += yStep;
}
+ free(temp);
+
return GL_TRUE;
}
diff --git a/mesalib/src/mesa/swrast/s_renderbuffer.c b/mesalib/src/mesa/swrast/s_renderbuffer.c
new file mode 100644
index 000000000..7622e38fd
--- /dev/null
+++ b/mesalib/src/mesa/swrast/s_renderbuffer.c
@@ -0,0 +1,2034 @@
+/*
+ * Mesa 3-D graphics library
+ * Version: 6.5
+ *
+ * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+
+/**
+ * Functions for allocating/managing software-based renderbuffers.
+ * Also, routines for reading/writing software-based renderbuffer data as
+ * ubytes, ushorts, uints, etc.
+ */
+
+
+#include "main/glheader.h"
+#include "main/imports.h"
+#include "main/context.h"
+#include "main/fbobject.h"
+#include "main/formats.h"
+#include "main/mtypes.h"
+#include "main/renderbuffer.h"
+#include "swrast/s_renderbuffer.h"
+
+
+/*
+ * Routines for get/put values in common buffer formats follow.
+ */
+
+/* Returns a bytes per pixel of the DataType in the get/put span
+ * functions for at least a subset of the available combinations a
+ * renderbuffer can have.
+ *
+ * It would be nice to see gl_renderbuffer start talking about a
+ * gl_format instead of a GLenum DataType.
+ */
+static int
+get_datatype_bytes(struct gl_renderbuffer *rb)
+{
+ int component_size;
+
+ switch (rb->DataType) {
+ case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:
+ component_size = 8;
+ break;
+ case GL_FLOAT:
+ case GL_UNSIGNED_INT:
+ case GL_UNSIGNED_INT_24_8_EXT:
+ component_size = 4;
+ break;
+ case GL_UNSIGNED_SHORT:
+ component_size = 2;
+ break;
+ case GL_UNSIGNED_BYTE:
+ component_size = 1;
+ break;
+ default:
+ component_size = 1;
+ assert(0);
+ }
+
+ switch (rb->_BaseFormat) {
+ case GL_DEPTH_COMPONENT:
+ case GL_DEPTH_STENCIL:
+ return component_size;
+ default:
+ return 4 * component_size;
+ }
+}
+
+/* This is commonly used by most of the accessors. */
+static void *
+get_pointer_generic(struct gl_context *ctx, struct gl_renderbuffer *rb,
+ GLint x, GLint y)
+{
+ if (!rb->Data)
+ return NULL;
+
+ return ((char *) rb->Data +
+ (y * rb->RowStride + x) * _mesa_get_format_bytes(rb->Format));
+}
+
+/* GetRow() implementation for formats where DataType matches the rb->Format.
+ */
+static void
+get_row_generic(struct gl_context *ctx, struct gl_renderbuffer *rb,
+ GLuint count, GLint x, GLint y, void *values)
+{
+ void *src = rb->GetPointer(ctx, rb, x, y);
+ memcpy(values, src, count * _mesa_get_format_bytes(rb->Format));
+}
+
+/* Only used for float textures currently, but might also be used for
+ * RGBA8888, RGBA16, etc.
+ */
+static void
+get_values_generic(struct gl_context *ctx, struct gl_renderbuffer *rb,
+ GLuint count, const GLint x[], const GLint y[], void *values)
+{
+ int format_bytes = _mesa_get_format_bytes(rb->Format) / sizeof(GLfloat);
+ GLuint i;
+
+ for (i = 0; i < count; i++) {
+ const void *src = rb->GetPointer(ctx, rb, x[i], y[i]);
+ char *dst = (char *) values + i * format_bytes;
+ memcpy(dst, src, format_bytes);
+ }
+}
+
+/* For the GL_RED/GL_RG/GL_RGB format/DataType combinations (and
+ * GL_LUMINANCE/GL_INTENSITY?), the Put functions are a matter of
+ * storing those initial components of the value per pixel into the
+ * destination.
+ */
+static void
+put_row_generic(struct gl_context *ctx, struct gl_renderbuffer *rb,
+ GLuint count, GLint x, GLint y,
+ const void *values, const GLubyte *mask)
+{
+ void *row = rb->GetPointer(ctx, rb, x, y);
+ int format_bytes = _mesa_get_format_bytes(rb->Format) / sizeof(GLfloat);
+ int datatype_bytes = get_datatype_bytes(rb);
+ unsigned int i;
+
+ if (mask) {
+ for (i = 0; i < count; i++) {
+ char *dst = (char *) row + i * format_bytes;
+ const char *src = (const char *) values + i * datatype_bytes;
+
+ if (mask[i]) {
+ memcpy(dst, src, format_bytes);
+ }
+ }
+ }
+ else {
+ for (i = 0; i < count; i++) {
+ char *dst = (char *) row + i * format_bytes;
+ const char *src = (const char *) values + i * datatype_bytes;
+ memcpy(dst, src, format_bytes);
+ }
+ }
+}
+
+static void
+put_mono_row_generic(struct gl_context *ctx, struct gl_renderbuffer *rb,
+ GLuint count, GLint x, GLint y,
+ const void *value, const GLubyte *mask)
+{
+ void *row = rb->GetPointer(ctx, rb, x, y);
+ int format_bytes = _mesa_get_format_bytes(rb->Format) / sizeof(GLfloat);
+ unsigned int i;
+
+ if (mask) {
+ for (i = 0; i < count; i++) {
+ char *dst = (char *) row + i * format_bytes;
+ if (mask[i]) {
+ memcpy(dst, value, format_bytes);
+ }
+ }
+ }
+ else {
+ for (i = 0; i < count; i++) {
+ char *dst = (char *) row + i * format_bytes;
+ memcpy(dst, value, format_bytes);
+ }
+ }
+}
+
+
+static void
+put_values_generic(struct gl_context *ctx, struct gl_renderbuffer *rb,
+ GLuint count, const GLint x[], const GLint y[],
+ const void *values, const GLubyte *mask)
+{
+ int format_bytes = _mesa_get_format_bytes(rb->Format) / sizeof(GLfloat);
+ int datatype_bytes = get_datatype_bytes(rb);
+ unsigned int i;
+
+ for (i = 0; i < count; i++) {
+ if (!mask || mask[i]) {
+ void *dst = rb->GetPointer(ctx, rb, x[i], y[i]);
+ const char *src = (const char *) values + i * datatype_bytes;
+ memcpy(dst, src, format_bytes);
+ }
+ }
+}
+
+
+static void
+put_mono_values_generic(struct gl_context *ctx,
+ struct gl_renderbuffer *rb,
+ GLuint count, const GLint x[], const GLint y[],
+ const void *value, const GLubyte *mask)
+{
+ int format_bytes = _mesa_get_format_bytes(rb->Format) / sizeof(GLfloat);
+ unsigned int i;
+
+ for (i = 0; i < count; i++) {
+ if (!mask || mask[i]) {
+ void *dst = rb->GetPointer(ctx, rb, x[i], y[i]);
+ memcpy(dst, value, format_bytes);
+ }
+ }
+}
+
+/**********************************************************************
+ * Functions for buffers of 1 X GLubyte values.
+ * Typically stencil.
+ */
+
+static void
+get_values_ubyte(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
+ const GLint x[], const GLint y[], void *values)
+{
+ GLubyte *dst = (GLubyte *) values;
+ GLuint i;
+ ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
+ for (i = 0; i < count; i++) {
+ const GLubyte *src = (GLubyte *) rb->Data + y[i] * rb->RowStride + x[i];
+ dst[i] = *src;
+ }
+}
+
+
+static void
+put_row_ubyte(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
+ GLint x, GLint y, const void *values, const GLubyte *mask)
+{
+ const GLubyte *src = (const GLubyte *) values;
+ GLubyte *dst = (GLubyte *) rb->Data + y * rb->RowStride + x;
+ ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
+ if (mask) {
+ GLuint i;
+ for (i = 0; i < count; i++) {
+ if (mask[i]) {
+ dst[i] = src[i];
+ }
+ }
+ }
+ else {
+ memcpy(dst, values, count * sizeof(GLubyte));
+ }
+}
+
+
+static void
+put_mono_row_ubyte(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
+ GLint x, GLint y, const void *value, const GLubyte *mask)
+{
+ const GLubyte val = *((const GLubyte *) value);
+ GLubyte *dst = (GLubyte *) rb->Data + y * rb->RowStride + x;
+ ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
+ if (mask) {
+ GLuint i;
+ for (i = 0; i < count; i++) {
+ if (mask[i]) {
+ dst[i] = val;
+ }
+ }
+ }
+ else {
+ GLuint i;
+ for (i = 0; i < count; i++) {
+ dst[i] = val;
+ }
+ }
+}
+
+
+static void
+put_values_ubyte(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
+ const GLint x[], const GLint y[],
+ const void *values, const GLubyte *mask)
+{
+ const GLubyte *src = (const GLubyte *) values;
+ GLuint i;
+ ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
+ for (i = 0; i < count; i++) {
+ if (!mask || mask[i]) {
+ GLubyte *dst = (GLubyte *) rb->Data + y[i] * rb->RowStride + x[i];
+ *dst = src[i];
+ }
+ }
+}
+
+
+static void
+put_mono_values_ubyte(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
+ const GLint x[], const GLint y[],
+ const void *value, const GLubyte *mask)
+{
+ const GLubyte val = *((const GLubyte *) value);
+ GLuint i;
+ ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
+ for (i = 0; i < count; i++) {
+ if (!mask || mask[i]) {
+ GLubyte *dst = (GLubyte *) rb->Data + y[i] * rb->RowStride + x[i];
+ *dst = val;
+ }
+ }
+}
+
+
+/**********************************************************************
+ * Functions for buffers of 1 X GLushort values.
+ * Typically depth/Z.
+ */
+
+static void
+get_values_ushort(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
+ const GLint x[], const GLint y[], void *values)
+{
+ GLushort *dst = (GLushort *) values;
+ GLuint i;
+ ASSERT(rb->DataType == GL_UNSIGNED_SHORT);
+ for (i = 0; i < count; i++) {
+ const GLushort *src = (GLushort *) rb->Data + y[i] * rb->RowStride + x[i];
+ dst[i] = *src;
+ }
+}
+
+
+static void
+put_row_ushort(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
+ GLint x, GLint y, const void *values, const GLubyte *mask)
+{
+ const GLushort *src = (const GLushort *) values;
+ GLushort *dst = (GLushort *) rb->Data + y * rb->RowStride + x;
+ ASSERT(rb->DataType == GL_UNSIGNED_SHORT);
+ if (mask) {
+ GLuint i;
+ for (i = 0; i < count; i++) {
+ if (mask[i]) {
+ dst[i] = src[i];
+ }
+ }
+ }
+ else {
+ memcpy(dst, src, count * sizeof(GLushort));
+ }
+}
+
+
+static void
+put_mono_row_ushort(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
+ GLint x, GLint y, const void *value, const GLubyte *mask)
+{
+ const GLushort val = *((const GLushort *) value);
+ GLushort *dst = (GLushort *) rb->Data + y * rb->RowStride + x;
+ ASSERT(rb->DataType == GL_UNSIGNED_SHORT);
+ if (mask) {
+ GLuint i;
+ for (i = 0; i < count; i++) {
+ if (mask[i]) {
+ dst[i] = val;
+ }
+ }
+ }
+ else {
+ GLuint i;
+ for (i = 0; i < count; i++) {
+ dst[i] = val;
+ }
+ }
+}
+
+
+static void
+put_values_ushort(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
+ const GLint x[], const GLint y[], const void *values,
+ const GLubyte *mask)
+{
+ const GLushort *src = (const GLushort *) values;
+ GLuint i;
+ ASSERT(rb->DataType == GL_UNSIGNED_SHORT);
+ for (i = 0; i < count; i++) {
+ if (!mask || mask[i]) {
+ GLushort *dst = (GLushort *) rb->Data + y[i] * rb->RowStride + x[i];
+ *dst = src[i];
+ }
+ }
+}
+
+
+static void
+put_mono_values_ushort(struct gl_context *ctx, struct gl_renderbuffer *rb,
+ GLuint count, const GLint x[], const GLint y[],
+ const void *value, const GLubyte *mask)
+{
+ const GLushort val = *((const GLushort *) value);
+ ASSERT(rb->DataType == GL_UNSIGNED_SHORT);
+ if (mask) {
+ GLuint i;
+ for (i = 0; i < count; i++) {
+ if (mask[i]) {
+ GLushort *dst = (GLushort *) rb->Data + y[i] * rb->RowStride + x[i];
+ *dst = val;
+ }
+ }
+ }
+ else {
+ GLuint i;
+ for (i = 0; i < count; i++) {
+ GLushort *dst = (GLushort *) rb->Data + y[i] * rb->RowStride + x[i];
+ *dst = val;
+ }
+ }
+}
+
+
+/**********************************************************************
+ * Functions for buffers of 1 X GLuint values.
+ * Typically depth/Z or color index.
+ */
+
+static void
+get_values_uint(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
+ const GLint x[], const GLint y[], void *values)
+{
+ GLuint *dst = (GLuint *) values;
+ GLuint i;
+ ASSERT(rb->DataType == GL_UNSIGNED_INT ||
+ rb->DataType == GL_UNSIGNED_INT_24_8_EXT);
+ for (i = 0; i < count; i++) {
+ const GLuint *src = (GLuint *) rb->Data + y[i] * rb->RowStride + x[i];
+ dst[i] = *src;
+ }
+}
+
+
+static void
+put_row_uint(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
+ GLint x, GLint y, const void *values, const GLubyte *mask)
+{
+ const GLuint *src = (const GLuint *) values;
+ GLuint *dst = (GLuint *) rb->Data + y * rb->RowStride + x;
+ ASSERT(rb->DataType == GL_UNSIGNED_INT ||
+ rb->DataType == GL_UNSIGNED_INT_24_8_EXT);
+ if (mask) {
+ GLuint i;
+ for (i = 0; i < count; i++) {
+ if (mask[i]) {
+ dst[i] = src[i];
+ }
+ }
+ }
+ else {
+ memcpy(dst, src, count * sizeof(GLuint));
+ }
+}
+
+
+static void
+put_mono_row_uint(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
+ GLint x, GLint y, const void *value, const GLubyte *mask)
+{
+ const GLuint val = *((const GLuint *) value);
+ GLuint *dst = (GLuint *) rb->Data + y * rb->RowStride + x;
+ ASSERT(rb->DataType == GL_UNSIGNED_INT ||
+ rb->DataType == GL_UNSIGNED_INT_24_8_EXT);
+ if (mask) {
+ GLuint i;
+ for (i = 0; i < count; i++) {
+ if (mask[i]) {
+ dst[i] = val;
+ }
+ }
+ }
+ else {
+ GLuint i;
+ for (i = 0; i < count; i++) {
+ dst[i] = val;
+ }
+ }
+}
+
+
+static void
+put_values_uint(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
+ const GLint x[], const GLint y[], const void *values,
+ const GLubyte *mask)
+{
+ const GLuint *src = (const GLuint *) values;
+ GLuint i;
+ ASSERT(rb->DataType == GL_UNSIGNED_INT ||
+ rb->DataType == GL_UNSIGNED_INT_24_8_EXT);
+ for (i = 0; i < count; i++) {
+ if (!mask || mask[i]) {
+ GLuint *dst = (GLuint *) rb->Data + y[i] * rb->RowStride + x[i];
+ *dst = src[i];
+ }
+ }
+}
+
+
+static void
+put_mono_values_uint(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
+ const GLint x[], const GLint y[], const void *value,
+ const GLubyte *mask)
+{
+ const GLuint val = *((const GLuint *) value);
+ GLuint i;
+ ASSERT(rb->DataType == GL_UNSIGNED_INT ||
+ rb->DataType == GL_UNSIGNED_INT_24_8_EXT);
+ for (i = 0; i < count; i++) {
+ if (!mask || mask[i]) {
+ GLuint *dst = (GLuint *) rb->Data + y[i] * rb->RowStride + x[i];
+ *dst = val;
+ }
+ }
+}
+
+
+/**********************************************************************
+ * Functions for buffers of 3 X GLubyte (or GLbyte) values.
+ * Typically color buffers.
+ * NOTE: the incoming and outgoing colors are RGBA! We ignore incoming
+ * alpha values and return 255 for outgoing alpha values.
+ */
+
+static void *
+get_pointer_ubyte3(struct gl_context *ctx, struct gl_renderbuffer *rb,
+ GLint x, GLint y)
+{
+ ASSERT(rb->Format == MESA_FORMAT_RGB888);
+ /* No direct access since this buffer is RGB but caller will be
+ * treating it as if it were RGBA.
+ */
+ return NULL;
+}
+
+
+static void
+get_row_ubyte3(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
+ GLint x, GLint y, void *values)
+{
+ const GLubyte *src = ((const GLubyte *) rb->Data) +
+ 3 * (y * rb->RowStride + x);
+ GLubyte *dst = (GLubyte *) values;
+ GLuint i;
+ ASSERT(rb->Format == MESA_FORMAT_RGB888);
+ ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
+ for (i = 0; i < count; i++) {
+ dst[i * 4 + 0] = src[i * 3 + 0];
+ dst[i * 4 + 1] = src[i * 3 + 1];
+ dst[i * 4 + 2] = src[i * 3 + 2];
+ dst[i * 4 + 3] = 255;
+ }
+}
+
+
+static void
+get_values_ubyte3(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
+ const GLint x[], const GLint y[], void *values)
+{
+ GLubyte *dst = (GLubyte *) values;
+ GLuint i;
+ ASSERT(rb->Format == MESA_FORMAT_RGB888);
+ ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
+ for (i = 0; i < count; i++) {
+ const GLubyte *src
+ = (GLubyte *) rb->Data + 3 * (y[i] * rb->RowStride + x[i]);
+ dst[i * 4 + 0] = src[0];
+ dst[i * 4 + 1] = src[1];
+ dst[i * 4 + 2] = src[2];
+ dst[i * 4 + 3] = 255;
+ }
+}
+
+
+static void
+put_row_ubyte3(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
+ GLint x, GLint y, const void *values, const GLubyte *mask)
+{
+ /* note: incoming values are RGB+A! */
+ const GLubyte *src = (const GLubyte *) values;
+ GLubyte *dst = (GLubyte *) rb->Data + 3 * (y * rb->RowStride + x);
+ GLuint i;
+ ASSERT(rb->Format == MESA_FORMAT_RGB888);
+ ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
+ for (i = 0; i < count; i++) {
+ if (!mask || mask[i]) {
+ dst[i * 3 + 0] = src[i * 4 + 0];
+ dst[i * 3 + 1] = src[i * 4 + 1];
+ dst[i * 3 + 2] = src[i * 4 + 2];
+ }
+ }
+}
+
+
+static void
+put_row_rgb_ubyte3(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
+ GLint x, GLint y, const void *values, const GLubyte *mask)
+{
+ /* note: incoming values are RGB+A! */
+ const GLubyte *src = (const GLubyte *) values;
+ GLubyte *dst = (GLubyte *) rb->Data + 3 * (y * rb->RowStride + x);
+ GLuint i;
+ ASSERT(rb->Format == MESA_FORMAT_RGB888);
+ ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
+ for (i = 0; i < count; i++) {
+ if (!mask || mask[i]) {
+ dst[i * 3 + 0] = src[i * 3 + 0];
+ dst[i * 3 + 1] = src[i * 3 + 1];
+ dst[i * 3 + 2] = src[i * 3 + 2];
+ }
+ }
+}
+
+
+static void
+put_mono_row_ubyte3(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
+ GLint x, GLint y, const void *value, const GLubyte *mask)
+{
+ /* note: incoming value is RGB+A! */
+ const GLubyte val0 = ((const GLubyte *) value)[0];
+ const GLubyte val1 = ((const GLubyte *) value)[1];
+ const GLubyte val2 = ((const GLubyte *) value)[2];
+ GLubyte *dst = (GLubyte *) rb->Data + 3 * (y * rb->RowStride + x);
+ ASSERT(rb->Format == MESA_FORMAT_RGB888);
+ ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
+ if (!mask && val0 == val1 && val1 == val2) {
+ /* optimized case */
+ memset(dst, val0, 3 * count);
+ }
+ else {
+ GLuint i;
+ for (i = 0; i < count; i++) {
+ if (!mask || mask[i]) {
+ dst[i * 3 + 0] = val0;
+ dst[i * 3 + 1] = val1;
+ dst[i * 3 + 2] = val2;
+ }
+ }
+ }
+}
+
+
+static void
+put_values_ubyte3(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
+ const GLint x[], const GLint y[], const void *values,
+ const GLubyte *mask)
+{
+ /* note: incoming values are RGB+A! */
+ const GLubyte *src = (const GLubyte *) values;
+ GLuint i;
+ ASSERT(rb->Format == MESA_FORMAT_RGB888);
+ ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
+ for (i = 0; i < count; i++) {
+ if (!mask || mask[i]) {
+ GLubyte *dst = (GLubyte *) rb->Data + 3 * (y[i] * rb->RowStride + x[i]);
+ dst[0] = src[i * 4 + 0];
+ dst[1] = src[i * 4 + 1];
+ dst[2] = src[i * 4 + 2];
+ }
+ }
+}
+
+
+static void
+put_mono_values_ubyte3(struct gl_context *ctx, struct gl_renderbuffer *rb,
+ GLuint count, const GLint x[], const GLint y[],
+ const void *value, const GLubyte *mask)
+{
+ /* note: incoming value is RGB+A! */
+ const GLubyte val0 = ((const GLubyte *) value)[0];
+ const GLubyte val1 = ((const GLubyte *) value)[1];
+ const GLubyte val2 = ((const GLubyte *) value)[2];
+ GLuint i;
+ ASSERT(rb->Format == MESA_FORMAT_RGB888);
+ ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
+ for (i = 0; i < count; i++) {
+ if (!mask || mask[i]) {
+ GLubyte *dst = ((GLubyte *) rb->Data) +
+ 3 * (y[i] * rb->RowStride + x[i]);
+ dst[0] = val0;
+ dst[1] = val1;
+ dst[2] = val2;
+ }
+ }
+}
+
+
+/**********************************************************************
+ * Functions for buffers of 4 X GLubyte (or GLbyte) values.
+ * Typically color buffers.
+ */
+
+static void
+get_values_ubyte4(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
+ const GLint x[], const GLint y[], void *values)
+{
+ /* treat 4*GLubyte as 1*GLuint */
+ GLuint *dst = (GLuint *) values;
+ GLuint i;
+ ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
+ ASSERT(rb->Format == MESA_FORMAT_RGBA8888 ||
+ rb->Format == MESA_FORMAT_RGBA8888_REV);
+ for (i = 0; i < count; i++) {
+ const GLuint *src = (GLuint *) rb->Data + (y[i] * rb->RowStride + x[i]);
+ dst[i] = *src;
+ }
+}
+
+
+static void
+put_row_ubyte4(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
+ GLint x, GLint y, const void *values, const GLubyte *mask)
+{
+ /* treat 4*GLubyte as 1*GLuint */
+ const GLuint *src = (const GLuint *) values;
+ GLuint *dst = (GLuint *) rb->Data + (y * rb->RowStride + x);
+ ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
+ ASSERT(rb->Format == MESA_FORMAT_RGBA8888 ||
+ rb->Format == MESA_FORMAT_RGBA8888_REV);
+ if (mask) {
+ GLuint i;
+ for (i = 0; i < count; i++) {
+ if (mask[i]) {
+ dst[i] = src[i];
+ }
+ }
+ }
+ else {
+ memcpy(dst, src, 4 * count * sizeof(GLubyte));
+ }
+}
+
+
+static void
+put_row_rgb_ubyte4(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
+ GLint x, GLint y, const void *values, const GLubyte *mask)
+{
+ /* Store RGB values in RGBA buffer */
+ const GLubyte *src = (const GLubyte *) values;
+ GLubyte *dst = (GLubyte *) rb->Data + 4 * (y * rb->RowStride + x);
+ GLuint i;
+ ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
+ ASSERT(rb->Format == MESA_FORMAT_RGBA8888 ||
+ rb->Format == MESA_FORMAT_RGBA8888_REV);
+ for (i = 0; i < count; i++) {
+ if (!mask || mask[i]) {
+ dst[i * 4 + 0] = src[i * 3 + 0];
+ dst[i * 4 + 1] = src[i * 3 + 1];
+ dst[i * 4 + 2] = src[i * 3 + 2];
+ dst[i * 4 + 3] = 0xff;
+ }
+ }
+}
+
+
+static void
+put_mono_row_ubyte4(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
+ GLint x, GLint y, const void *value, const GLubyte *mask)
+{
+ /* treat 4*GLubyte as 1*GLuint */
+ const GLuint val = *((const GLuint *) value);
+ GLuint *dst = (GLuint *) rb->Data + (y * rb->RowStride + x);
+ ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
+ ASSERT(rb->Format == MESA_FORMAT_RGBA8888 ||
+ rb->Format == MESA_FORMAT_RGBA8888_REV);
+ if (!mask && val == 0) {
+ /* common case */
+ memset(dst, 0, count * 4 * sizeof(GLubyte));
+ }
+ else {
+ /* general case */
+ if (mask) {
+ GLuint i;
+ for (i = 0; i < count; i++) {
+ if (mask[i]) {
+ dst[i] = val;
+ }
+ }
+ }
+ else {
+ GLuint i;
+ for (i = 0; i < count; i++) {
+ dst[i] = val;
+ }
+ }
+ }
+}
+
+
+static void
+put_values_ubyte4(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
+ const GLint x[], const GLint y[], const void *values,
+ const GLubyte *mask)
+{
+ /* treat 4*GLubyte as 1*GLuint */
+ const GLuint *src = (const GLuint *) values;
+ GLuint i;
+ ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
+ ASSERT(rb->Format == MESA_FORMAT_RGBA8888 ||
+ rb->Format == MESA_FORMAT_RGBA8888_REV);
+ for (i = 0; i < count; i++) {
+ if (!mask || mask[i]) {
+ GLuint *dst = (GLuint *) rb->Data + (y[i] * rb->RowStride + x[i]);
+ *dst = src[i];
+ }
+ }
+}
+
+
+static void
+put_mono_values_ubyte4(struct gl_context *ctx, struct gl_renderbuffer *rb,
+ GLuint count, const GLint x[], const GLint y[],
+ const void *value, const GLubyte *mask)
+{
+ /* treat 4*GLubyte as 1*GLuint */
+ const GLuint val = *((const GLuint *) value);
+ GLuint i;
+ ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
+ ASSERT(rb->Format == MESA_FORMAT_RGBA8888 ||
+ rb->Format == MESA_FORMAT_RGBA8888_REV);
+ for (i = 0; i < count; i++) {
+ if (!mask || mask[i]) {
+ GLuint *dst = (GLuint *) rb->Data + (y[i] * rb->RowStride + x[i]);
+ *dst = val;
+ }
+ }
+}
+
+
+/**********************************************************************
+ * Functions for buffers of 4 X GLushort (or GLshort) values.
+ * Typically accum buffer.
+ */
+
+static void
+get_values_ushort4(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
+ const GLint x[], const GLint y[], void *values)
+{
+ GLushort *dst = (GLushort *) values;
+ GLuint i;
+ ASSERT(rb->DataType == GL_UNSIGNED_SHORT || rb->DataType == GL_SHORT);
+ for (i = 0; i < count; i++) {
+ const GLushort *src
+ = (GLushort *) rb->Data + 4 * (y[i] * rb->RowStride + x[i]);
+ dst[i] = *src;
+ }
+}
+
+
+static void
+put_row_ushort4(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
+ GLint x, GLint y, const void *values, const GLubyte *mask)
+{
+ const GLushort *src = (const GLushort *) values;
+ GLushort *dst = (GLushort *) rb->Data + 4 * (y * rb->RowStride + x);
+ ASSERT(rb->DataType == GL_UNSIGNED_SHORT || rb->DataType == GL_SHORT);
+ if (mask) {
+ GLuint i;
+ for (i = 0; i < count; i++) {
+ if (mask[i]) {
+ dst[i * 4 + 0] = src[i * 4 + 0];
+ dst[i * 4 + 1] = src[i * 4 + 1];
+ dst[i * 4 + 2] = src[i * 4 + 2];
+ dst[i * 4 + 3] = src[i * 4 + 3];
+ }
+ }
+ }
+ else {
+ memcpy(dst, src, 4 * count * sizeof(GLushort));
+ }
+}
+
+
+static void
+put_row_rgb_ushort4(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
+ GLint x, GLint y, const void *values, const GLubyte *mask)
+{
+ /* Put RGB values in RGBA buffer */
+ const GLushort *src = (const GLushort *) values;
+ GLushort *dst = (GLushort *) rb->Data + 4 * (y * rb->RowStride + x);
+ ASSERT(rb->DataType == GL_UNSIGNED_SHORT || rb->DataType == GL_SHORT);
+ if (mask) {
+ GLuint i;
+ for (i = 0; i < count; i++) {
+ if (mask[i]) {
+ dst[i * 4 + 0] = src[i * 3 + 0];
+ dst[i * 4 + 1] = src[i * 3 + 1];
+ dst[i * 4 + 2] = src[i * 3 + 2];
+ dst[i * 4 + 3] = 0xffff;
+ }
+ }
+ }
+ else {
+ memcpy(dst, src, 4 * count * sizeof(GLushort));
+ }
+}
+
+
+static void
+put_mono_row_ushort4(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
+ GLint x, GLint y, const void *value, const GLubyte *mask)
+{
+ const GLushort val0 = ((const GLushort *) value)[0];
+ const GLushort val1 = ((const GLushort *) value)[1];
+ const GLushort val2 = ((const GLushort *) value)[2];
+ const GLushort val3 = ((const GLushort *) value)[3];
+ GLushort *dst = (GLushort *) rb->Data + 4 * (y * rb->RowStride + x);
+ ASSERT(rb->DataType == GL_UNSIGNED_SHORT || rb->DataType == GL_SHORT);
+ if (!mask && val0 == 0 && val1 == 0 && val2 == 0 && val3 == 0) {
+ /* common case for clearing accum buffer */
+ memset(dst, 0, count * 4 * sizeof(GLushort));
+ }
+ else {
+ GLuint i;
+ for (i = 0; i < count; i++) {
+ if (!mask || mask[i]) {
+ dst[i * 4 + 0] = val0;
+ dst[i * 4 + 1] = val1;
+ dst[i * 4 + 2] = val2;
+ dst[i * 4 + 3] = val3;
+ }
+ }
+ }
+}
+
+
+static void
+put_values_ushort4(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
+ const GLint x[], const GLint y[], const void *values,
+ const GLubyte *mask)
+{
+ const GLushort *src = (const GLushort *) values;
+ GLuint i;
+ ASSERT(rb->DataType == GL_UNSIGNED_SHORT || rb->DataType == GL_SHORT);
+ for (i = 0; i < count; i++) {
+ if (!mask || mask[i]) {
+ GLushort *dst =
+ ((GLushort *) rb->Data) + 4 * (y[i] * rb->RowStride + x[i]);
+ dst[0] = src[i * 4 + 0];
+ dst[1] = src[i * 4 + 1];
+ dst[2] = src[i * 4 + 2];
+ dst[3] = src[i * 4 + 3];
+ }
+ }
+}
+
+
+static void
+put_mono_values_ushort4(struct gl_context *ctx, struct gl_renderbuffer *rb,
+ GLuint count, const GLint x[], const GLint y[],
+ const void *value, const GLubyte *mask)
+{
+ const GLushort val0 = ((const GLushort *) value)[0];
+ const GLushort val1 = ((const GLushort *) value)[1];
+ const GLushort val2 = ((const GLushort *) value)[2];
+ const GLushort val3 = ((const GLushort *) value)[3];
+ GLuint i;
+ ASSERT(rb->DataType == GL_UNSIGNED_SHORT || rb->DataType == GL_SHORT);
+ for (i = 0; i < count; i++) {
+ if (!mask || mask[i]) {
+ GLushort *dst = ((GLushort *) rb->Data) +
+ 4 * (y[i] * rb->RowStride + x[i]);
+ dst[0] = val0;
+ dst[1] = val1;
+ dst[2] = val2;
+ dst[3] = val3;
+ }
+ }
+}
+
+/**********************************************************************
+ * Functions for MESA_FORMAT_R8.
+ */
+static void
+get_row_r8(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
+ GLint x, GLint y, void *values)
+{
+ const GLubyte *src = rb->GetPointer(ctx, rb, x, y);
+ GLuint *dst = values;
+ GLuint i;
+
+ for (i = 0; i < count; i++) {
+ dst[i] = 0xff000000 | src[i];
+ }
+}
+
+static void
+get_values_r8(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
+ const GLint x[], const GLint y[], void *values)
+{
+ GLuint *dst = (GLuint *) values;
+ GLuint i;
+
+ for (i = 0; i < count; i++) {
+ const GLubyte *src = rb->GetPointer(ctx, rb, x[i], y[i]);
+ dst[i] = 0xff000000 | *src;
+ }
+}
+
+/**********************************************************************
+ * Functions for MESA_FORMAT_GR88.
+ */
+static void
+get_row_rg88(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
+ GLint x, GLint y, void *values)
+{
+ const GLushort *src = rb->GetPointer(ctx, rb, x, y);
+ GLuint *dst = values;
+ GLuint i;
+
+ for (i = 0; i < count; i++) {
+ dst[i] = 0xff000000 | src[i];
+ }
+}
+
+static void
+get_values_rg88(struct gl_context *ctx, struct gl_renderbuffer *rb,
+ GLuint count, const GLint x[], const GLint y[], void *values)
+{
+ GLuint *dst = (GLuint *) values;
+ GLuint i;
+
+ for (i = 0; i < count; i++) {
+ const GLshort *src = rb->GetPointer(ctx, rb, x[i], y[i]);
+ dst[i] = 0xff000000 | *src;
+ }
+}
+
+/**********************************************************************
+ * Functions for MESA_FORMAT_R16.
+ */
+static void
+get_row_r16(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
+ GLint x, GLint y, void *values)
+{
+ const GLushort *src = rb->GetPointer(ctx, rb, x, y);
+ GLushort *dst = values;
+ GLuint i;
+
+ for (i = 0; i < count; i++) {
+ dst[i * 4 + RCOMP] = src[i];
+ dst[i * 4 + GCOMP] = 0;
+ dst[i * 4 + BCOMP] = 0;
+ dst[i * 4 + ACOMP] = 0xffff;
+ }
+}
+
+static void
+get_values_r16(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
+ const GLint x[], const GLint y[], void *values)
+{
+ GLushort *dst = values;
+ GLuint i;
+
+ for (i = 0; i < count; i++) {
+ const GLushort *src = rb->GetPointer(ctx, rb, x[i], y[i]);
+ dst[i * 4 + RCOMP] = *src;
+ dst[i * 4 + GCOMP] = 0;
+ dst[i * 4 + BCOMP] = 0;
+ dst[i * 4 + ACOMP] = 0xffff;
+ }
+}
+
+/**********************************************************************
+ * Functions for MESA_FORMAT_RG1616.
+ */
+static void
+get_row_rg1616(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
+ GLint x, GLint y, void *values)
+{
+ const GLushort *src = rb->GetPointer(ctx, rb, x, y);
+ GLushort *dst = values;
+ GLuint i;
+
+ for (i = 0; i < count; i++) {
+ dst[i * 4 + RCOMP] = src[i * 2];
+ dst[i * 4 + GCOMP] = src[i * 2 + 1];
+ dst[i * 4 + BCOMP] = 0;
+ dst[i * 4 + ACOMP] = 0xffff;
+ }
+}
+
+static void
+get_values_rg1616(struct gl_context *ctx, struct gl_renderbuffer *rb,
+ GLuint count, const GLint x[], const GLint y[], void *values)
+{
+ GLushort *dst = values;
+ GLuint i;
+
+ for (i = 0; i < count; i++) {
+ const GLshort *src = rb->GetPointer(ctx, rb, x[i], y[i]);
+ dst[i * 4 + RCOMP] = src[0];
+ dst[i * 4 + GCOMP] = src[1];
+ dst[i * 4 + BCOMP] = 0;
+ dst[i * 4 + ACOMP] = 0xffff;
+ }
+}
+
+/**********************************************************************
+ * Functions for MESA_FORMAT_INTENSITY_FLOAT32.
+ */
+static void
+get_row_i_float32(struct gl_context *ctx, struct gl_renderbuffer *rb,
+ GLuint count, GLint x, GLint y, void *values)
+{
+ const GLfloat *src = rb->GetPointer(ctx, rb, x, y);
+ GLfloat *dst = values;
+ GLuint i;
+
+ for (i = 0; i < count; i++) {
+ dst[i * 4 + RCOMP] =
+ dst[i * 4 + GCOMP] =
+ dst[i * 4 + BCOMP] =
+ dst[i * 4 + ACOMP] = src[i];
+ }
+}
+
+static void
+get_values_i_float32(struct gl_context *ctx, struct gl_renderbuffer *rb,
+ GLuint count, const GLint x[], const GLint y[],
+ void *values)
+{
+ GLfloat *dst = values;
+ GLuint i;
+
+ for (i = 0; i < count; i++) {
+ const GLfloat *src = rb->GetPointer(ctx, rb, x[i], y[i]);
+ dst[i * 4 + RCOMP] =
+ dst[i * 4 + GCOMP] =
+ dst[i * 4 + BCOMP] =
+ dst[i * 4 + ACOMP] = src[0];
+ }
+}
+
+/**********************************************************************
+ * Functions for MESA_FORMAT_LUMINANCE_FLOAT32.
+ */
+static void
+get_row_l_float32(struct gl_context *ctx, struct gl_renderbuffer *rb,
+ GLuint count, GLint x, GLint y, void *values)
+{
+ const GLfloat *src = rb->GetPointer(ctx, rb, x, y);
+ GLfloat *dst = values;
+ GLuint i;
+
+ for (i = 0; i < count; i++) {
+ dst[i * 4 + RCOMP] =
+ dst[i * 4 + GCOMP] =
+ dst[i * 4 + BCOMP] = src[i];
+ dst[i * 4 + ACOMP] = 1.0;
+ }
+}
+
+static void
+get_values_l_float32(struct gl_context *ctx, struct gl_renderbuffer *rb,
+ GLuint count, const GLint x[], const GLint y[],
+ void *values)
+{
+ GLfloat *dst = values;
+ GLuint i;
+
+ for (i = 0; i < count; i++) {
+ const GLfloat *src = rb->GetPointer(ctx, rb, x[i], y[i]);
+ dst[i * 4 + RCOMP] =
+ dst[i * 4 + GCOMP] =
+ dst[i * 4 + BCOMP] = src[0];
+ dst[i * 4 + ACOMP] = 1.0;
+ }
+}
+
+/**********************************************************************
+ * Functions for MESA_FORMAT_ALPHA_FLOAT32.
+ */
+static void
+get_row_a_float32(struct gl_context *ctx, struct gl_renderbuffer *rb,
+ GLuint count, GLint x, GLint y, void *values)
+{
+ const GLfloat *src = rb->GetPointer(ctx, rb, x, y);
+ GLfloat *dst = values;
+ GLuint i;
+
+ for (i = 0; i < count; i++) {
+ dst[i * 4 + RCOMP] = 0.0;
+ dst[i * 4 + GCOMP] = 0.0;
+ dst[i * 4 + BCOMP] = 0.0;
+ dst[i * 4 + ACOMP] = src[i];
+ }
+}
+
+static void
+get_values_a_float32(struct gl_context *ctx, struct gl_renderbuffer *rb,
+ GLuint count, const GLint x[], const GLint y[],
+ void *values)
+{
+ GLfloat *dst = values;
+ GLuint i;
+
+ for (i = 0; i < count; i++) {
+ const GLfloat *src = rb->GetPointer(ctx, rb, x[i], y[i]);
+ dst[i * 4 + RCOMP] = 0.0;
+ dst[i * 4 + GCOMP] = 0.0;
+ dst[i * 4 + BCOMP] = 0.0;
+ dst[i * 4 + ACOMP] = src[0];
+ }
+}
+
+static void
+put_row_a_float32(struct gl_context *ctx, struct gl_renderbuffer *rb,
+ GLuint count, GLint x, GLint y,
+ const void *values, const GLubyte *mask)
+{
+ float *dst = rb->GetPointer(ctx, rb, x, y);
+ const float *src = values;
+ unsigned int i;
+
+ if (mask) {
+ for (i = 0; i < count; i++) {
+ if (mask[i]) {
+ dst[i] = src[i * 4 + ACOMP];
+ }
+ }
+ }
+ else {
+ for (i = 0; i < count; i++) {
+ dst[i] = src[i * 4 + ACOMP];
+ }
+ }
+}
+
+static void
+put_mono_row_a_float32(struct gl_context *ctx, struct gl_renderbuffer *rb,
+ GLuint count, GLint x, GLint y,
+ const void *value, const GLubyte *mask)
+{
+ float *dst = rb->GetPointer(ctx, rb, x, y);
+ const float *src = value;
+ unsigned int i;
+
+ if (mask) {
+ for (i = 0; i < count; i++) {
+ if (mask[i]) {
+ dst[i] = src[ACOMP];
+ }
+ }
+ }
+ else {
+ for (i = 0; i < count; i++) {
+ dst[i] = src[ACOMP];
+ }
+ }
+}
+
+static void
+put_values_a_float32(struct gl_context *ctx, struct gl_renderbuffer *rb,
+ GLuint count, const GLint x[], const GLint y[],
+ const void *values, const GLubyte *mask)
+{
+ const float *src = values;
+ unsigned int i;
+
+ for (i = 0; i < count; i++) {
+ if (!mask || mask[i]) {
+ float *dst = rb->GetPointer(ctx, rb, x[i], y[i]);
+
+ *dst = src[i * 4 + ACOMP];
+ }
+ }
+}
+
+static void
+put_mono_values_a_float32(struct gl_context *ctx,
+ struct gl_renderbuffer *rb,
+ GLuint count, const GLint x[], const GLint y[],
+ const void *value, const GLubyte *mask)
+{
+ const float *src = value;
+ unsigned int i;
+
+ for (i = 0; i < count; i++) {
+ if (!mask || mask[i]) {
+ float *dst = rb->GetPointer(ctx, rb, x[i], y[i]);
+ *dst = src[ACOMP];
+ }
+ }
+}
+
+/**********************************************************************
+ * Functions for MESA_FORMAT_R_FLOAT32.
+ */
+static void
+get_row_r_float32(struct gl_context *ctx, struct gl_renderbuffer *rb,
+ GLuint count, GLint x, GLint y, void *values)
+{
+ const GLfloat *src = rb->GetPointer(ctx, rb, x, y);
+ GLfloat *dst = values;
+ GLuint i;
+
+ for (i = 0; i < count; i++) {
+ dst[i * 4 + RCOMP] = src[i];
+ dst[i * 4 + GCOMP] = 0.0;
+ dst[i * 4 + BCOMP] = 0.0;
+ dst[i * 4 + ACOMP] = 1.0;
+ }
+}
+
+static void
+get_values_r_float32(struct gl_context *ctx, struct gl_renderbuffer *rb,
+ GLuint count, const GLint x[], const GLint y[],
+ void *values)
+{
+ GLfloat *dst = values;
+ GLuint i;
+
+ for (i = 0; i < count; i++) {
+ const GLfloat *src = rb->GetPointer(ctx, rb, x[i], y[i]);
+ dst[i * 4 + RCOMP] = src[0];
+ dst[i * 4 + GCOMP] = 0.0;
+ dst[i * 4 + BCOMP] = 0.0;
+ dst[i * 4 + ACOMP] = 1.0;
+ }
+}
+
+/**********************************************************************
+ * Functions for MESA_FORMAT_RG_FLOAT32.
+ */
+static void
+get_row_rg_float32(struct gl_context *ctx, struct gl_renderbuffer *rb,
+ GLuint count, GLint x, GLint y, void *values)
+{
+ const GLfloat *src = rb->GetPointer(ctx, rb, x, y);
+ GLfloat *dst = values;
+ GLuint i;
+
+ for (i = 0; i < count; i++) {
+ dst[i * 4 + RCOMP] = src[i * 2 + 0];
+ dst[i * 4 + GCOMP] = src[i * 2 + 1];
+ dst[i * 4 + BCOMP] = 0.0;
+ dst[i * 4 + ACOMP] = 1.0;
+ }
+}
+
+static void
+get_values_rg_float32(struct gl_context *ctx, struct gl_renderbuffer *rb,
+ GLuint count, const GLint x[], const GLint y[],
+ void *values)
+{
+ GLfloat *dst = values;
+ GLuint i;
+
+ for (i = 0; i < count; i++) {
+ const GLfloat *src = rb->GetPointer(ctx, rb, x[i], y[i]);
+ dst[i * 4 + RCOMP] = src[0];
+ dst[i * 4 + GCOMP] = src[1];
+ dst[i * 4 + BCOMP] = 0.0;
+ dst[i * 4 + ACOMP] = 1.0;
+ }
+}
+
+/**
+ * This is the default software fallback for gl_renderbuffer's span
+ * access functions.
+ *
+ * The assumptions are that rb->Data will be a pointer to (0,0), that pixels
+ * are packed in the type of rb->Format, and that subsequent rows appear
+ * rb->RowStride pixels later.
+ */
+void
+_swrast_set_renderbuffer_accessors(struct gl_renderbuffer *rb)
+{
+ rb->GetPointer = get_pointer_generic;
+ rb->GetRow = get_row_generic;
+
+ switch (rb->Format) {
+ case MESA_FORMAT_RGB888:
+ rb->DataType = GL_UNSIGNED_BYTE;
+ rb->GetPointer = get_pointer_ubyte3;
+ rb->GetRow = get_row_ubyte3;
+ rb->GetValues = get_values_ubyte3;
+ rb->PutRow = put_row_ubyte3;
+ rb->PutRowRGB = put_row_rgb_ubyte3;
+ rb->PutMonoRow = put_mono_row_ubyte3;
+ rb->PutValues = put_values_ubyte3;
+ rb->PutMonoValues = put_mono_values_ubyte3;
+ break;
+
+ case MESA_FORMAT_RGBA8888:
+ case MESA_FORMAT_RGBA8888_REV:
+ rb->DataType = GL_UNSIGNED_BYTE;
+ rb->GetValues = get_values_ubyte4;
+ rb->PutRow = put_row_ubyte4;
+ rb->PutRowRGB = put_row_rgb_ubyte4;
+ rb->PutMonoRow = put_mono_row_ubyte4;
+ rb->PutValues = put_values_ubyte4;
+ rb->PutMonoValues = put_mono_values_ubyte4;
+ break;
+
+ case MESA_FORMAT_R8:
+ rb->DataType = GL_UNSIGNED_BYTE;
+ rb->GetValues = get_values_r8;
+ rb->GetRow = get_row_r8;
+ rb->PutRow = put_row_generic;
+ rb->PutRowRGB = put_row_generic;
+ rb->PutMonoRow = put_mono_row_generic;
+ rb->PutValues = put_values_generic;
+ rb->PutMonoValues = put_mono_values_generic;
+ break;
+
+ case MESA_FORMAT_GR88:
+ rb->DataType = GL_UNSIGNED_BYTE;
+ rb->GetValues = get_values_rg88;
+ rb->GetRow = get_row_rg88;
+ rb->PutRow = put_row_generic;
+ rb->PutRowRGB = put_row_generic;
+ rb->PutMonoRow = put_mono_row_generic;
+ rb->PutValues = put_values_generic;
+ rb->PutMonoValues = put_mono_values_generic;
+ break;
+
+ case MESA_FORMAT_R16:
+ rb->DataType = GL_UNSIGNED_SHORT;
+ rb->GetValues = get_values_r16;
+ rb->GetRow = get_row_r16;
+ rb->PutRow = put_row_generic;
+ rb->PutRowRGB = put_row_generic;
+ rb->PutMonoRow = put_mono_row_generic;
+ rb->PutValues = put_values_generic;
+ rb->PutMonoValues = put_mono_values_generic;
+ break;
+
+ case MESA_FORMAT_RG1616:
+ rb->DataType = GL_UNSIGNED_SHORT;
+ rb->GetValues = get_values_rg1616;
+ rb->GetRow = get_row_rg1616;
+ rb->PutRow = put_row_generic;
+ rb->PutRowRGB = put_row_generic;
+ rb->PutMonoRow = put_mono_row_generic;
+ rb->PutValues = put_values_generic;
+ rb->PutMonoValues = put_mono_values_generic;
+ break;
+
+ case MESA_FORMAT_SIGNED_RGBA_16:
+ rb->DataType = GL_SHORT;
+ rb->GetValues = get_values_ushort4;
+ rb->PutRow = put_row_ushort4;
+ rb->PutRowRGB = put_row_rgb_ushort4;
+ rb->PutMonoRow = put_mono_row_ushort4;
+ rb->PutValues = put_values_ushort4;
+ rb->PutMonoValues = put_mono_values_ushort4;
+ break;
+
+ case MESA_FORMAT_S8:
+ rb->DataType = GL_UNSIGNED_BYTE;
+ rb->GetValues = get_values_ubyte;
+ rb->PutRow = put_row_ubyte;
+ rb->PutRowRGB = NULL;
+ rb->PutMonoRow = put_mono_row_ubyte;
+ rb->PutValues = put_values_ubyte;
+ rb->PutMonoValues = put_mono_values_ubyte;
+ break;
+
+ case MESA_FORMAT_Z16:
+ rb->DataType = GL_UNSIGNED_SHORT;
+ rb->GetValues = get_values_ushort;
+ rb->PutRow = put_row_ushort;
+ rb->PutRowRGB = NULL;
+ rb->PutMonoRow = put_mono_row_ushort;
+ rb->PutValues = put_values_ushort;
+ rb->PutMonoValues = put_mono_values_ushort;
+ break;
+
+ case MESA_FORMAT_Z32:
+ case MESA_FORMAT_X8_Z24:
+ case MESA_FORMAT_Z24_X8:
+ rb->DataType = GL_UNSIGNED_INT;
+ rb->GetValues = get_values_uint;
+ rb->PutRow = put_row_uint;
+ rb->PutRowRGB = NULL;
+ rb->PutMonoRow = put_mono_row_uint;
+ rb->PutValues = put_values_uint;
+ rb->PutMonoValues = put_mono_values_uint;
+ break;
+
+ case MESA_FORMAT_Z24_S8:
+ case MESA_FORMAT_S8_Z24:
+ rb->DataType = GL_UNSIGNED_INT_24_8_EXT;
+ rb->GetValues = get_values_uint;
+ rb->PutRow = put_row_uint;
+ rb->PutRowRGB = NULL;
+ rb->PutMonoRow = put_mono_row_uint;
+ rb->PutValues = put_values_uint;
+ rb->PutMonoValues = put_mono_values_uint;
+ break;
+
+ case MESA_FORMAT_RGBA_FLOAT32:
+ rb->GetRow = get_row_generic;
+ rb->GetValues = get_values_generic;
+ rb->PutRow = put_row_generic;
+ rb->PutRowRGB = NULL;
+ rb->PutMonoRow = put_mono_row_generic;
+ rb->PutValues = put_values_generic;
+ rb->PutMonoValues = put_mono_values_generic;
+ break;
+
+ case MESA_FORMAT_INTENSITY_FLOAT32:
+ rb->GetRow = get_row_i_float32;
+ rb->GetValues = get_values_i_float32;
+ rb->PutRow = put_row_generic;
+ rb->PutRowRGB = NULL;
+ rb->PutMonoRow = put_mono_row_generic;
+ rb->PutValues = put_values_generic;
+ rb->PutMonoValues = put_mono_values_generic;
+ break;
+
+ case MESA_FORMAT_LUMINANCE_FLOAT32:
+ rb->GetRow = get_row_l_float32;
+ rb->GetValues = get_values_l_float32;
+ rb->PutRow = put_row_generic;
+ rb->PutRowRGB = NULL;
+ rb->PutMonoRow = put_mono_row_generic;
+ rb->PutValues = put_values_generic;
+ rb->PutMonoValues = put_mono_values_generic;
+ break;
+
+ case MESA_FORMAT_ALPHA_FLOAT32:
+ rb->GetRow = get_row_a_float32;
+ rb->GetValues = get_values_a_float32;
+ rb->PutRow = put_row_a_float32;
+ rb->PutRowRGB = NULL;
+ rb->PutMonoRow = put_mono_row_a_float32;
+ rb->PutValues = put_values_a_float32;
+ rb->PutMonoValues = put_mono_values_a_float32;
+ break;
+
+ case MESA_FORMAT_RG_FLOAT32:
+ rb->GetRow = get_row_rg_float32;
+ rb->GetValues = get_values_rg_float32;
+ rb->PutRow = put_row_generic;
+ rb->PutRowRGB = NULL;
+ rb->PutMonoRow = put_mono_row_generic;
+ rb->PutValues = put_values_generic;
+ rb->PutMonoValues = put_mono_values_generic;
+ break;
+
+ case MESA_FORMAT_R_FLOAT32:
+ rb->GetRow = get_row_r_float32;
+ rb->GetValues = get_values_r_float32;
+ rb->PutRow = put_row_generic;
+ rb->PutRowRGB = NULL;
+ rb->PutMonoRow = put_mono_row_generic;
+ rb->PutValues = put_values_generic;
+ rb->PutMonoValues = put_mono_values_generic;
+ break;
+
+ default:
+ break;
+ }
+}
+
+/**
+ * This is a software fallback for the gl_renderbuffer->AllocStorage
+ * function.
+ * Device drivers will typically override this function for the buffers
+ * which it manages (typically color buffers, Z and stencil).
+ * Other buffers (like software accumulation and aux buffers) which the driver
+ * doesn't manage can be handled with this function.
+ *
+ * This one multi-purpose function can allocate stencil, depth, accum, color
+ * or color-index buffers!
+ *
+ * This function also plugs in the appropriate GetPointer, Get/PutRow and
+ * Get/PutValues functions.
+ */
+static GLboolean
+soft_renderbuffer_storage(struct gl_context *ctx, struct gl_renderbuffer *rb,
+ GLenum internalFormat,
+ GLuint width, GLuint height)
+{
+ switch (internalFormat) {
+ case GL_RGB:
+ case GL_R3_G3_B2:
+ case GL_RGB4:
+ case GL_RGB5:
+ case GL_RGB8:
+ case GL_RGB10:
+ case GL_RGB12:
+ case GL_RGB16:
+ rb->Format = MESA_FORMAT_RGB888;
+ break;
+ case GL_RGBA:
+ case GL_RGBA2:
+ case GL_RGBA4:
+ case GL_RGB5_A1:
+ case GL_RGBA8:
+#if 1
+ case GL_RGB10_A2:
+ case GL_RGBA12:
+#endif
+ if (_mesa_little_endian())
+ rb->Format = MESA_FORMAT_RGBA8888_REV;
+ else
+ rb->Format = MESA_FORMAT_RGBA8888;
+ break;
+ case GL_RGBA16:
+ case GL_RGBA16_SNORM:
+ /* for accum buffer */
+ rb->Format = MESA_FORMAT_SIGNED_RGBA_16;
+ break;
+ case GL_STENCIL_INDEX:
+ case GL_STENCIL_INDEX1_EXT:
+ case GL_STENCIL_INDEX4_EXT:
+ case GL_STENCIL_INDEX8_EXT:
+ case GL_STENCIL_INDEX16_EXT:
+ rb->Format = MESA_FORMAT_S8;
+ break;
+ case GL_DEPTH_COMPONENT:
+ case GL_DEPTH_COMPONENT16:
+ rb->Format = MESA_FORMAT_Z16;
+ break;
+ case GL_DEPTH_COMPONENT24:
+ rb->Format = MESA_FORMAT_X8_Z24;
+ break;
+ case GL_DEPTH_COMPONENT32:
+ rb->Format = MESA_FORMAT_Z32;
+ break;
+ case GL_DEPTH_STENCIL_EXT:
+ case GL_DEPTH24_STENCIL8_EXT:
+ rb->Format = MESA_FORMAT_Z24_S8;
+ break;
+ default:
+ /* unsupported format */
+ return GL_FALSE;
+ }
+
+ _swrast_set_renderbuffer_accessors(rb);
+
+ ASSERT(rb->DataType);
+ ASSERT(rb->GetPointer);
+ ASSERT(rb->GetRow);
+ ASSERT(rb->GetValues);
+ ASSERT(rb->PutRow);
+ ASSERT(rb->PutMonoRow);
+ ASSERT(rb->PutValues);
+ ASSERT(rb->PutMonoValues);
+
+ /* free old buffer storage */
+ if (rb->Data) {
+ free(rb->Data);
+ rb->Data = NULL;
+ }
+
+ rb->RowStride = width;
+
+ if (width > 0 && height > 0) {
+ /* allocate new buffer storage */
+ rb->Data = malloc(width * height * _mesa_get_format_bytes(rb->Format));
+
+ if (rb->Data == NULL) {
+ rb->Width = 0;
+ rb->Height = 0;
+ rb->RowStride = 0;
+ _mesa_error(ctx, GL_OUT_OF_MEMORY,
+ "software renderbuffer allocation (%d x %d x %d)",
+ width, height, _mesa_get_format_bytes(rb->Format));
+ return GL_FALSE;
+ }
+ }
+
+ rb->Width = width;
+ rb->Height = height;
+ rb->_BaseFormat = _mesa_base_fbo_format(ctx, internalFormat);
+
+ if (rb->Name == 0 &&
+ internalFormat == GL_RGBA16_SNORM &&
+ rb->_BaseFormat == 0) {
+ /* NOTE: This is a special case just for accumulation buffers.
+ * This is a very limited use case- there's no snorm texturing or
+ * rendering going on.
+ */
+ rb->_BaseFormat = GL_RGBA;
+ }
+ else {
+ /* the internalFormat should have been error checked long ago */
+ ASSERT(rb->_BaseFormat);
+ }
+
+ return GL_TRUE;
+}
+
+
+void
+_swrast_map_soft_renderbuffer(struct gl_context *ctx,
+ struct gl_renderbuffer *rb,
+ GLuint x, GLuint y, GLuint w, GLuint h,
+ GLbitfield mode,
+ GLubyte **out_map,
+ GLint *out_stride)
+{
+ GLubyte *map = rb->Data;
+ int cpp = _mesa_get_format_bytes(rb->Format);
+ int stride = rb->RowStride * cpp;
+
+ ASSERT(rb->Data);
+
+ map += y * stride;
+ map += x * cpp;
+
+ *out_map = map;
+ *out_stride = stride;
+}
+
+
+void
+_swrast_unmap_soft_renderbuffer(struct gl_context *ctx,
+ struct gl_renderbuffer *rb)
+{
+}
+
+
+
+/**
+ * Allocate a software-based renderbuffer. This is called via the
+ * ctx->Driver.NewRenderbuffer() function when the user creates a new
+ * renderbuffer.
+ * This would not be used for hardware-based renderbuffers.
+ */
+struct gl_renderbuffer *
+_swrast_new_soft_renderbuffer(struct gl_context *ctx, GLuint name)
+{
+ struct gl_renderbuffer *rb = _mesa_new_renderbuffer(ctx, name);
+ if (rb) {
+ rb->AllocStorage = soft_renderbuffer_storage;
+ /* Normally, one would setup the PutRow, GetRow, etc functions here.
+ * But we're doing that in the soft_renderbuffer_storage() function
+ * instead.
+ */
+ }
+ return rb;
+}
+
+
+/**
+ * Add software-based color renderbuffers to the given framebuffer.
+ * This is a helper routine for device drivers when creating a
+ * window system framebuffer (not a user-created render/framebuffer).
+ * Once this function is called, you can basically forget about this
+ * renderbuffer; core Mesa will handle all the buffer management and
+ * rendering!
+ */
+static GLboolean
+add_color_renderbuffers(struct gl_context *ctx, struct gl_framebuffer *fb,
+ GLuint rgbBits, GLuint alphaBits,
+ GLboolean frontLeft, GLboolean backLeft,
+ GLboolean frontRight, GLboolean backRight)
+{
+ gl_buffer_index b;
+
+ if (rgbBits > 16 || alphaBits > 16) {
+ _mesa_problem(ctx,
+ "Unsupported bit depth in add_color_renderbuffers");
+ return GL_FALSE;
+ }
+
+ assert(MAX_COLOR_ATTACHMENTS >= 4);
+
+ for (b = BUFFER_FRONT_LEFT; b <= BUFFER_BACK_RIGHT; b++) {
+ struct gl_renderbuffer *rb;
+
+ if (b == BUFFER_FRONT_LEFT && !frontLeft)
+ continue;
+ else if (b == BUFFER_BACK_LEFT && !backLeft)
+ continue;
+ else if (b == BUFFER_FRONT_RIGHT && !frontRight)
+ continue;
+ else if (b == BUFFER_BACK_RIGHT && !backRight)
+ continue;
+
+ assert(fb->Attachment[b].Renderbuffer == NULL);
+
+ rb = _mesa_new_renderbuffer(ctx, 0);
+ if (!rb) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "Allocating color buffer");
+ return GL_FALSE;
+ }
+
+ rb->InternalFormat = GL_RGBA;
+
+ rb->AllocStorage = soft_renderbuffer_storage;
+ _mesa_add_renderbuffer(fb, b, rb);
+ }
+
+ return GL_TRUE;
+}
+
+
+/**
+ * Add a software-based depth renderbuffer to the given framebuffer.
+ * This is a helper routine for device drivers when creating a
+ * window system framebuffer (not a user-created render/framebuffer).
+ * Once this function is called, you can basically forget about this
+ * renderbuffer; core Mesa will handle all the buffer management and
+ * rendering!
+ */
+static GLboolean
+add_depth_renderbuffer(struct gl_context *ctx, struct gl_framebuffer *fb,
+ GLuint depthBits)
+{
+ struct gl_renderbuffer *rb;
+
+ if (depthBits > 32) {
+ _mesa_problem(ctx,
+ "Unsupported depthBits in add_depth_renderbuffer");
+ return GL_FALSE;
+ }
+
+ assert(fb->Attachment[BUFFER_DEPTH].Renderbuffer == NULL);
+
+ rb = _mesa_new_renderbuffer(ctx, 0);
+ if (!rb) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "Allocating depth buffer");
+ return GL_FALSE;
+ }
+
+ if (depthBits <= 16) {
+ rb->InternalFormat = GL_DEPTH_COMPONENT16;
+ }
+ else if (depthBits <= 24) {
+ rb->InternalFormat = GL_DEPTH_COMPONENT24;
+ }
+ else {
+ rb->InternalFormat = GL_DEPTH_COMPONENT32;
+ }
+
+ rb->AllocStorage = soft_renderbuffer_storage;
+ _mesa_add_renderbuffer(fb, BUFFER_DEPTH, rb);
+
+ return GL_TRUE;
+}
+
+
+/**
+ * Add a software-based stencil renderbuffer to the given framebuffer.
+ * This is a helper routine for device drivers when creating a
+ * window system framebuffer (not a user-created render/framebuffer).
+ * Once this function is called, you can basically forget about this
+ * renderbuffer; core Mesa will handle all the buffer management and
+ * rendering!
+ */
+static GLboolean
+add_stencil_renderbuffer(struct gl_context *ctx, struct gl_framebuffer *fb,
+ GLuint stencilBits)
+{
+ struct gl_renderbuffer *rb;
+
+ if (stencilBits > 16) {
+ _mesa_problem(ctx,
+ "Unsupported stencilBits in add_stencil_renderbuffer");
+ return GL_FALSE;
+ }
+
+ assert(fb->Attachment[BUFFER_STENCIL].Renderbuffer == NULL);
+
+ rb = _mesa_new_renderbuffer(ctx, 0);
+ if (!rb) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "Allocating stencil buffer");
+ return GL_FALSE;
+ }
+
+ assert(stencilBits <= 8);
+ rb->InternalFormat = GL_STENCIL_INDEX8;
+
+ rb->AllocStorage = soft_renderbuffer_storage;
+ _mesa_add_renderbuffer(fb, BUFFER_STENCIL, rb);
+
+ return GL_TRUE;
+}
+
+
+/**
+ * Add a software-based accumulation renderbuffer to the given framebuffer.
+ * This is a helper routine for device drivers when creating a
+ * window system framebuffer (not a user-created render/framebuffer).
+ * Once this function is called, you can basically forget about this
+ * renderbuffer; core Mesa will handle all the buffer management and
+ * rendering!
+ */
+static GLboolean
+add_accum_renderbuffer(struct gl_context *ctx, struct gl_framebuffer *fb,
+ GLuint redBits, GLuint greenBits,
+ GLuint blueBits, GLuint alphaBits)
+{
+ struct gl_renderbuffer *rb;
+
+ if (redBits > 16 || greenBits > 16 || blueBits > 16 || alphaBits > 16) {
+ _mesa_problem(ctx,
+ "Unsupported accumBits in add_accum_renderbuffer");
+ return GL_FALSE;
+ }
+
+ assert(fb->Attachment[BUFFER_ACCUM].Renderbuffer == NULL);
+
+ rb = _mesa_new_renderbuffer(ctx, 0);
+ if (!rb) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "Allocating accum buffer");
+ return GL_FALSE;
+ }
+
+ rb->InternalFormat = GL_RGBA16_SNORM;
+ rb->AllocStorage = soft_renderbuffer_storage;
+ _mesa_add_renderbuffer(fb, BUFFER_ACCUM, rb);
+
+ return GL_TRUE;
+}
+
+
+
+/**
+ * Add a software-based aux renderbuffer to the given framebuffer.
+ * This is a helper routine for device drivers when creating a
+ * window system framebuffer (not a user-created render/framebuffer).
+ * Once this function is called, you can basically forget about this
+ * renderbuffer; core Mesa will handle all the buffer management and
+ * rendering!
+ *
+ * NOTE: color-index aux buffers not supported.
+ */
+static GLboolean
+add_aux_renderbuffers(struct gl_context *ctx, struct gl_framebuffer *fb,
+ GLuint colorBits, GLuint numBuffers)
+{
+ GLuint i;
+
+ if (colorBits > 16) {
+ _mesa_problem(ctx,
+ "Unsupported colorBits in add_aux_renderbuffers");
+ return GL_FALSE;
+ }
+
+ assert(numBuffers <= MAX_AUX_BUFFERS);
+
+ for (i = 0; i < numBuffers; i++) {
+ struct gl_renderbuffer *rb = _mesa_new_renderbuffer(ctx, 0);
+
+ assert(fb->Attachment[BUFFER_AUX0 + i].Renderbuffer == NULL);
+
+ if (!rb) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "Allocating aux buffer");
+ return GL_FALSE;
+ }
+
+ assert (colorBits <= 8);
+ rb->InternalFormat = GL_RGBA;
+
+ rb->AllocStorage = soft_renderbuffer_storage;
+ _mesa_add_renderbuffer(fb, BUFFER_AUX0 + i, rb);
+ }
+ return GL_TRUE;
+}
+
+
+/**
+ * Create/attach software-based renderbuffers to the given framebuffer.
+ * This is a helper routine for device drivers. Drivers can just as well
+ * call the individual _mesa_add_*_renderbuffer() routines directly.
+ */
+void
+_swrast_add_soft_renderbuffers(struct gl_framebuffer *fb,
+ GLboolean color,
+ GLboolean depth,
+ GLboolean stencil,
+ GLboolean accum,
+ GLboolean alpha,
+ GLboolean aux)
+{
+ GLboolean frontLeft = GL_TRUE;
+ GLboolean backLeft = fb->Visual.doubleBufferMode;
+ GLboolean frontRight = fb->Visual.stereoMode;
+ GLboolean backRight = fb->Visual.stereoMode && fb->Visual.doubleBufferMode;
+
+ if (color) {
+ assert(fb->Visual.redBits == fb->Visual.greenBits);
+ assert(fb->Visual.redBits == fb->Visual.blueBits);
+ add_color_renderbuffers(NULL, fb,
+ fb->Visual.redBits,
+ fb->Visual.alphaBits,
+ frontLeft, backLeft,
+ frontRight, backRight);
+ }
+
+ if (depth) {
+ assert(fb->Visual.depthBits > 0);
+ add_depth_renderbuffer(NULL, fb, fb->Visual.depthBits);
+ }
+
+ if (stencil) {
+ assert(fb->Visual.stencilBits > 0);
+ add_stencil_renderbuffer(NULL, fb, fb->Visual.stencilBits);
+ }
+
+ if (accum) {
+ assert(fb->Visual.accumRedBits > 0);
+ assert(fb->Visual.accumGreenBits > 0);
+ assert(fb->Visual.accumBlueBits > 0);
+ add_accum_renderbuffer(NULL, fb,
+ fb->Visual.accumRedBits,
+ fb->Visual.accumGreenBits,
+ fb->Visual.accumBlueBits,
+ fb->Visual.accumAlphaBits);
+ }
+
+ if (aux) {
+ assert(fb->Visual.numAuxBuffers > 0);
+ add_aux_renderbuffers(NULL, fb, fb->Visual.redBits,
+ fb->Visual.numAuxBuffers);
+ }
+
+#if 0
+ if (multisample) {
+ /* maybe someday */
+ }
+#endif
+}
diff --git a/mesalib/src/mesa/swrast/s_accum.h b/mesalib/src/mesa/swrast/s_renderbuffer.h
index bdd6ac326..266ebd934 100644
--- a/mesalib/src/mesa/swrast/s_accum.h
+++ b/mesalib/src/mesa/swrast/s_renderbuffer.h
@@ -1,38 +1,66 @@
-/*
- * Mesa 3-D graphics library
- * Version: 6.3
- *
- * Copyright (C) 1999-2005 Brian Paul All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-
-#ifndef S_ACCUM_H
-#define S_ACCUM_H
-
-
-struct gl_context;
-struct gl_renderbuffer;
-
-
-extern void
-_swrast_clear_accum_buffer(struct gl_context *ctx, struct gl_renderbuffer *rb);
-
-
-#endif
+/*
+ * Mesa 3-D graphics library
+ * Version: 6.5
+ *
+ * Copyright (C) 1999-2005 Brian Paul All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+
+#ifndef S_RENDERBUFFER_H
+#define S_RENDERBUFFER_H
+
+#include "main/glheader.h"
+
+
+struct gl_context;
+struct gl_framebuffer;
+struct gl_renderbuffer;
+
+
+extern struct gl_renderbuffer *
+_swrast_new_soft_renderbuffer(struct gl_context *ctx, GLuint name);
+
+extern void
+_swrast_map_soft_renderbuffer(struct gl_context *ctx,
+ struct gl_renderbuffer *rb,
+ GLuint x, GLuint y, GLuint w, GLuint h,
+ GLbitfield mode,
+ GLubyte **out_map,
+ GLint *out_stride);
+
+extern void
+_swrast_unmap_soft_renderbuffer(struct gl_context *ctx,
+ struct gl_renderbuffer *rb);
+
+extern void
+_swrast_set_renderbuffer_accessors(struct gl_renderbuffer *rb);
+
+
+extern void
+_swrast_add_soft_renderbuffers(struct gl_framebuffer *fb,
+ GLboolean color,
+ GLboolean depth,
+ GLboolean stencil,
+ GLboolean accum,
+ GLboolean alpha,
+ GLboolean aux);
+
+
+#endif /* S_RENDERBUFFER_H */
diff --git a/mesalib/src/mesa/swrast/s_texfetch_tmp.h b/mesalib/src/mesa/swrast/s_texfetch_tmp.h
index e9512b561..877c29c9b 100644
--- a/mesalib/src/mesa/swrast/s_texfetch_tmp.h
+++ b/mesalib/src/mesa/swrast/s_texfetch_tmp.h
@@ -2270,7 +2270,7 @@ static void FETCH(f_z24_s8)( const struct swrast_texture_image *texImage,
{
/* only return Z, not stencil data */
const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
- const GLfloat scale = 1.0F / (GLfloat) 0xffffff;
+ const GLdouble scale = 1.0 / (GLdouble) 0xffffff;
texel[0] = ((*src) >> 8) * scale;
ASSERT(texImage->Base.TexFormat == MESA_FORMAT_Z24_S8 ||
texImage->Base.TexFormat == MESA_FORMAT_Z24_X8);
@@ -2298,7 +2298,7 @@ static void FETCH(f_s8_z24)( const struct swrast_texture_image *texImage,
{
/* only return Z, not stencil data */
const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
- const GLfloat scale = 1.0F / (GLfloat) 0xffffff;
+ const GLdouble scale = 1.0 / (GLdouble) 0xffffff;
texel[0] = ((*src) & 0x00ffffff) * scale;
ASSERT(texImage->Base.TexFormat == MESA_FORMAT_S8_Z24 ||
texImage->Base.TexFormat == MESA_FORMAT_X8_Z24);
diff --git a/mesalib/src/mesa/swrast/s_zoom.c b/mesalib/src/mesa/swrast/s_zoom.c
index 16bb997f3..f407fdcf4 100644
--- a/mesalib/src/mesa/swrast/s_zoom.c
+++ b/mesalib/src/mesa/swrast/s_zoom.c
@@ -299,11 +299,17 @@ zoom_span( struct gl_context *ctx, GLint imgX, GLint imgY, const SWspan *span,
* Also, clipping may change the span end value, so store it as well.
*/
const GLint end = zoomed.end; /* save */
- GLuint rgbaSave[MAX_WIDTH][4];
+ void *rgbaSave;
const GLint pixelSize =
(zoomed.array->ChanType == GL_UNSIGNED_BYTE) ? 4 * sizeof(GLubyte) :
((zoomed.array->ChanType == GL_UNSIGNED_SHORT) ? 4 * sizeof(GLushort)
: 4 * sizeof(GLfloat));
+
+ rgbaSave = malloc(zoomed.end * pixelSize);
+ if (!rgbaSave) {
+ return;
+ }
+
if (y1 - y0 > 1) {
memcpy(rgbaSave, zoomed.array->rgba, zoomed.end * pixelSize);
}
@@ -315,6 +321,8 @@ zoom_span( struct gl_context *ctx, GLint imgX, GLint imgY, const SWspan *span,
memcpy(zoomed.array->rgba, rgbaSave, zoomed.end * pixelSize);
}
}
+
+ free(rgbaSave);
}
}
diff --git a/mesalib/src/mesa/swrast/swrast.h b/mesalib/src/mesa/swrast/swrast.h
index 17b66c664..dd4055159 100644
--- a/mesalib/src/mesa/swrast/swrast.h
+++ b/mesalib/src/mesa/swrast/swrast.h
@@ -127,9 +127,6 @@ _swrast_BlitFramebuffer(struct gl_context *ctx,
extern void
_swrast_Clear(struct gl_context *ctx, GLbitfield buffers);
-extern void
-_swrast_Accum(struct gl_context *ctx, GLenum op, GLfloat value);
-
/* Reset the stipple counter