summaryrefslogtreecommitdiff
path: root/src/mesa/swrast
diff options
context:
space:
mode:
authorBrian Paul <brian.paul@tungstengraphics.com>2004-03-13 18:21:40 +0000
committerBrian Paul <brian.paul@tungstengraphics.com>2004-03-13 18:21:40 +0000
commit7a6b71ef2944bae1718e8167b2faaceb8422071c (patch)
tree3fb3435f3728f09486d455f6060f06dd42fe0e80 /src/mesa/swrast
parent5498e8b9f34718aba506421988116ccb1e5e3de7 (diff)
Implementation of GL_EXT_pixel_buffer_object extension.
Note: extension may not be finalized yet - subject to change! Note: implementation not fully suitable for h/w implementation yet.
Diffstat (limited to 'src/mesa/swrast')
-rw-r--r--src/mesa/swrast/s_bitmap.c13
-rw-r--r--src/mesa/swrast/s_context.c23
-rw-r--r--src/mesa/swrast/s_drawpix.c21
-rw-r--r--src/mesa/swrast/s_imaging.c22
-rw-r--r--src/mesa/swrast/s_readpix.c22
-rw-r--r--src/mesa/swrast/s_texstore.c49
-rw-r--r--src/mesa/swrast/swrast.h6
7 files changed, 103 insertions, 53 deletions
diff --git a/src/mesa/swrast/s_bitmap.c b/src/mesa/swrast/s_bitmap.c
index aeacba88ea..6c8f515b62 100644
--- a/src/mesa/swrast/s_bitmap.c
+++ b/src/mesa/swrast/s_bitmap.c
@@ -1,8 +1,8 @@
/*
* Mesa 3-D graphics library
- * Version: 5.1
+ * Version: 6.1
*
- * Copyright (C) 1999-2003 Brian Paul All Rights Reserved.
+ * Copyright (C) 1999-2004 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"),
@@ -53,7 +53,14 @@ _swrast_Bitmap( GLcontext *ctx, GLint px, GLint py,
struct sw_span span;
ASSERT(ctx->RenderMode == GL_RENDER);
- ASSERT(bitmap);
+
+ bitmap = _swrast_validate_pbo_access(unpack, width, height, 1,
+ GL_COLOR_INDEX, GL_BITMAP,
+ (GLvoid *) bitmap);
+ if (!bitmap) {
+ /* XXX GL_INVALID_OPERATION? */
+ return;
+ }
RENDER_START(swrast,ctx);
diff --git a/src/mesa/swrast/s_context.c b/src/mesa/swrast/s_context.c
index 0a81048e6f..be800d4d59 100644
--- a/src/mesa/swrast/s_context.c
+++ b/src/mesa/swrast/s_context.c
@@ -27,6 +27,7 @@
*/
#include "imports.h"
+#include "bufferobj.h"
#include "context.h"
#include "colormac.h"
#include "mtypes.h"
@@ -731,3 +732,25 @@ _swrast_print_vertex( GLcontext *ctx, const SWvertex *v )
_mesa_debug(ctx, "\n");
}
}
+
+
+/**
+ * Validate access to a PBO to be sure we're not going to read/write
+ * out of buffer bounds.
+ */
+GLvoid *
+_swrast_validate_pbo_access(const struct gl_pixelstore_attrib *pack,
+ GLsizei width, GLsizei height, GLsizei depth,
+ GLenum format, GLenum type, GLvoid *ptr)
+{
+ if (pack->BufferObj->Name == 0) {
+ /* no PBO */
+ return ptr;
+ }
+ else if (_mesa_validate_pbo_access(pack, width, height, depth, format,
+ type, ptr)) {
+ return ADD_POINTERS(pack->BufferObj->Data, ptr);
+ }
+ /* bad access! */
+ return NULL;
+}
diff --git a/src/mesa/swrast/s_drawpix.c b/src/mesa/swrast/s_drawpix.c
index 5b6f924405..337b5a5bfd 100644
--- a/src/mesa/swrast/s_drawpix.c
+++ b/src/mesa/swrast/s_drawpix.c
@@ -1,8 +1,8 @@
/*
* Mesa 3-D graphics library
- * Version: 5.1
+ * Version: 6.1
*
- * Copyright (C) 1999-2003 Brian Paul All Rights Reserved.
+ * Copyright (C) 1999-2004 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"),
@@ -785,14 +785,14 @@ draw_rgba_pixels( GLcontext *ctx, GLint x, GLint y,
GLint row;
GLfloat *dest, *tmpImage;
- tmpImage = (GLfloat *) MALLOC(width * height * 4 * sizeof(GLfloat));
+ tmpImage = (GLfloat *) _mesa_malloc(width * height * 4 * sizeof(GLfloat));
if (!tmpImage) {
_mesa_error(ctx, GL_OUT_OF_MEMORY, "glDrawPixels");
return;
}
- convImage = (GLfloat *) MALLOC(width * height * 4 * sizeof(GLfloat));
+ convImage = (GLfloat *) _mesa_malloc(width * height * 4 * sizeof(GLfloat));
if (!convImage) {
- FREE(tmpImage);
+ _mesa_free(tmpImage);
_mesa_error(ctx, GL_OUT_OF_MEMORY, "glDrawPixels");
return;
}
@@ -816,10 +816,10 @@ draw_rgba_pixels( GLcontext *ctx, GLint x, GLint y,
ASSERT(ctx->Pixel.Separable2DEnabled);
_mesa_convolve_sep_image(ctx, &width, &height, tmpImage, convImage);
}
- FREE(tmpImage);
+ _mesa_free(tmpImage);
/* continue transfer ops and draw the convolved image */
- unpack = &_mesa_native_packing;
+ unpack = &ctx->DefaultPacking;
pixels = convImage;
format = GL_RGBA;
type = GL_FLOAT;
@@ -887,7 +887,7 @@ draw_rgba_pixels( GLcontext *ctx, GLint x, GLint y,
}
if (convImage) {
- FREE(convImage);
+ _mesa_free(convImage);
}
}
@@ -910,6 +910,11 @@ _swrast_DrawPixels( GLcontext *ctx,
if (swrast->NewState)
_swrast_validate_derived( ctx );
+ pixels = _swrast_validate_pbo_access(unpack, width, height, 1,
+ format, type, (GLvoid *) pixels);
+ if (!pixels)
+ return;
+
RENDER_START(swrast,ctx);
switch (format) {
diff --git a/src/mesa/swrast/s_imaging.c b/src/mesa/swrast/s_imaging.c
index b9c413687b..52c809f7a9 100644
--- a/src/mesa/swrast/s_imaging.c
+++ b/src/mesa/swrast/s_imaging.c
@@ -1,9 +1,8 @@
-
/*
* Mesa 3-D graphics library
- * Version: 4.1
+ * Version: 6.1
*
- * Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
+ * Copyright (C) 1999-2004 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"),
@@ -30,6 +29,9 @@
#include "s_context.h"
#include "s_span.h"
+#include "colortab.h"
+#include "convolve.h"
+
void
_swrast_CopyColorTable( GLcontext *ctx,
@@ -50,9 +52,10 @@ _swrast_CopyColorTable( GLcontext *ctx,
/* Restore reading from draw buffer (the default) */
_swrast_use_draw_buffer(ctx);
- glColorTable(target, internalformat, width, GL_RGBA, CHAN_TYPE, data);
+ _mesa_ColorTable(target, internalformat, width, GL_RGBA, CHAN_TYPE, data);
}
+
void
_swrast_CopyColorSubTable( GLcontext *ctx,GLenum target, GLsizei start,
GLint x, GLint y, GLsizei width)
@@ -71,7 +74,7 @@ _swrast_CopyColorSubTable( GLcontext *ctx,GLenum target, GLsizei start,
/* Restore reading from draw buffer (the default) */
_swrast_use_draw_buffer(ctx);
- glColorSubTable(target, start, width, GL_RGBA, CHAN_TYPE, data);
+ _mesa_ColorSubTable(target, start, width, GL_RGBA, CHAN_TYPE, data);
}
@@ -98,8 +101,8 @@ _swrast_CopyConvolutionFilter1D(GLcontext *ctx, GLenum target,
_swrast_use_draw_buffer(ctx);
/* store as convolution filter */
- glConvolutionFilter1D(target, internalFormat, width,
- GL_RGBA, CHAN_TYPE, rgba);
+ _mesa_ConvolutionFilter1D(target, internalFormat, width,
+ GL_RGBA, CHAN_TYPE, rgba);
}
@@ -145,10 +148,11 @@ _swrast_CopyConvolutionFilter2D(GLcontext *ctx, GLenum target,
ctx->Unpack.SkipImages = 0;
ctx->Unpack.SwapBytes = GL_FALSE;
ctx->Unpack.LsbFirst = GL_FALSE;
+ ctx->Unpack.BufferObj = ctx->Array.NullBufferObj;
ctx->NewState |= _NEW_PACKUNPACK;
- glConvolutionFilter2D(target, internalFormat, width, height,
- GL_RGBA, CHAN_TYPE, rgba);
+ _mesa_ConvolutionFilter2D(target, internalFormat, width, height,
+ GL_RGBA, CHAN_TYPE, rgba);
ctx->Unpack = packSave; /* restore pixel packing params */
ctx->NewState |= _NEW_PACKUNPACK;
diff --git a/src/mesa/swrast/s_readpix.c b/src/mesa/swrast/s_readpix.c
index 7c2ce36491..b5ab06e4ba 100644
--- a/src/mesa/swrast/s_readpix.c
+++ b/src/mesa/swrast/s_readpix.c
@@ -1,8 +1,8 @@
/*
* Mesa 3-D graphics library
- * Version: 5.1
+ * Version: 6.1
*
- * Copyright (C) 1999-2003 Brian Paul All Rights Reserved.
+ * Copyright (C) 1999-2004 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"),
@@ -382,14 +382,14 @@ read_rgba_pixels( GLcontext *ctx,
GLfloat *dest, *src, *tmpImage, *convImage;
GLint row;
- tmpImage = (GLfloat *) MALLOC(width * height * 4 * sizeof(GLfloat));
+ tmpImage = (GLfloat *) _mesa_malloc(width * height * 4 * sizeof(GLfloat));
if (!tmpImage) {
_mesa_error(ctx, GL_OUT_OF_MEMORY, "glReadPixels");
return;
}
- convImage = (GLfloat *) MALLOC(width * height * 4 * sizeof(GLfloat));
+ convImage = (GLfloat *) _mesa_malloc(width * height * 4 * sizeof(GLfloat));
if (!convImage) {
- FREE(tmpImage);
+ _mesa_free(tmpImage);
_mesa_error(ctx, GL_OUT_OF_MEMORY, "glReadPixels");
return;
}
@@ -410,7 +410,7 @@ read_rgba_pixels( GLcontext *ctx,
_mesa_map_ci_to_rgba_chan(ctx, readWidth, index, rgba);
}
_mesa_pack_rgba_span_chan(ctx, readWidth, (const GLchan (*)[4]) rgba,
- GL_RGBA, GL_FLOAT, dest, &_mesa_native_packing,
+ GL_RGBA, GL_FLOAT, dest, &ctx->DefaultPacking,
transferOps & IMAGE_PRE_CONVOLUTION_BITS);
dest += width * 4;
}
@@ -423,7 +423,7 @@ read_rgba_pixels( GLcontext *ctx,
ASSERT(ctx->Pixel.Separable2DEnabled);
_mesa_convolve_sep_image(ctx, &readWidth, &height, tmpImage, convImage);
}
- FREE(tmpImage);
+ _mesa_free(tmpImage);
/* finish transfer ops and pack the resulting image */
src = convImage;
@@ -501,6 +501,14 @@ _swrast_ReadPixels( GLcontext *ctx,
if (swrast->NewState)
_swrast_validate_derived( ctx );
+ pixels = _swrast_validate_pbo_access(pack, width, height, 1,
+ format, type, (GLvoid *) pixels);
+
+ if (!pixels) {
+ _mesa_error( ctx, GL_INVALID_VALUE, "glReadPixels(pixels)" );
+ return;
+ }
+
RENDER_START(swrast,ctx);
switch (format) {
diff --git a/src/mesa/swrast/s_texstore.c b/src/mesa/swrast/s_texstore.c
index edf75f61f5..fa6b74b745 100644
--- a/src/mesa/swrast/s_texstore.c
+++ b/src/mesa/swrast/s_texstore.c
@@ -1,9 +1,8 @@
-
/*
* Mesa 3-D graphics library
- * Version: 5.1
+ * Version: 6.1
*
- * Copyright (C) 1999-2003 Brian Paul All Rights Reserved.
+ * Copyright (C) 1999-2004 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"),
@@ -68,7 +67,7 @@ read_color_image( GLcontext *ctx, GLint x, GLint y,
GLint stride, i;
GLchan *image, *dst;
- image = (GLchan *) MALLOC(width * height * 4 * sizeof(GLchan));
+ image = (GLchan *) _mesa_malloc(width * height * 4 * sizeof(GLchan));
if (!image)
return NULL;
@@ -105,7 +104,7 @@ read_depth_image( GLcontext *ctx, GLint x, GLint y,
GLfloat *image, *dst;
GLint i;
- image = (GLfloat *) MALLOC(width * height * sizeof(GLfloat));
+ image = (GLfloat *) _mesa_malloc(width * height * sizeof(GLfloat));
if (!image)
return NULL;
@@ -171,8 +170,8 @@ _swrast_copy_teximage1d( GLcontext *ctx, GLenum target, GLint level,
(*ctx->Driver.TexImage1D)(ctx, target, level, internalFormat,
width, border,
GL_DEPTH_COMPONENT, GL_FLOAT, image,
- &_mesa_native_packing, texObj, texImage);
- FREE(image);
+ &ctx->DefaultPacking, texObj, texImage);
+ _mesa_free(image);
}
else {
/* read RGBA image from framebuffer */
@@ -186,8 +185,8 @@ _swrast_copy_teximage1d( GLcontext *ctx, GLenum target, GLint level,
(*ctx->Driver.TexImage1D)(ctx, target, level, internalFormat,
width, border,
GL_RGBA, CHAN_TYPE, image,
- &_mesa_native_packing, texObj, texImage);
- FREE(image);
+ &ctx->DefaultPacking, texObj, texImage);
+ _mesa_free(image);
}
/* GL_SGIS_generate_mipmap */
@@ -230,8 +229,8 @@ _swrast_copy_teximage2d( GLcontext *ctx, GLenum target, GLint level,
(*ctx->Driver.TexImage2D)(ctx, target, level, internalFormat,
width, height, border,
GL_DEPTH_COMPONENT, GL_FLOAT, image,
- &_mesa_native_packing, texObj, texImage);
- FREE(image);
+ &ctx->DefaultPacking, texObj, texImage);
+ _mesa_free(image);
}
else {
/* read RGBA image from framebuffer */
@@ -245,8 +244,8 @@ _swrast_copy_teximage2d( GLcontext *ctx, GLenum target, GLint level,
(*ctx->Driver.TexImage2D)(ctx, target, level, internalFormat,
width, height, border,
GL_RGBA, CHAN_TYPE, image,
- &_mesa_native_packing, texObj, texImage);
- FREE(image);
+ &ctx->DefaultPacking, texObj, texImage);
+ _mesa_free(image);
}
/* GL_SGIS_generate_mipmap */
@@ -286,8 +285,8 @@ _swrast_copy_texsubimage1d( GLcontext *ctx, GLenum target, GLint level,
/* call glTexSubImage1D to redefine the texture */
(*ctx->Driver.TexSubImage1D)(ctx, target, level, xoffset, width,
GL_DEPTH_COMPONENT, GL_FLOAT, image,
- &_mesa_native_packing, texObj, texImage);
- FREE(image);
+ &ctx->DefaultPacking, texObj, texImage);
+ _mesa_free(image);
}
else {
/* read RGBA image from framebuffer */
@@ -300,8 +299,8 @@ _swrast_copy_texsubimage1d( GLcontext *ctx, GLenum target, GLint level,
/* now call glTexSubImage1D to do the real work */
(*ctx->Driver.TexSubImage1D)(ctx, target, level, xoffset, width,
GL_RGBA, CHAN_TYPE, image,
- &_mesa_native_packing, texObj, texImage);
- FREE(image);
+ &ctx->DefaultPacking, texObj, texImage);
+ _mesa_free(image);
}
/* GL_SGIS_generate_mipmap */
@@ -344,8 +343,8 @@ _swrast_copy_texsubimage2d( GLcontext *ctx,
(*ctx->Driver.TexSubImage2D)(ctx, target, level,
xoffset, yoffset, width, height,
GL_DEPTH_COMPONENT, GL_FLOAT, image,
- &_mesa_native_packing, texObj, texImage);
- FREE(image);
+ &ctx->DefaultPacking, texObj, texImage);
+ _mesa_free(image);
}
else {
/* read RGBA image from framebuffer */
@@ -359,8 +358,8 @@ _swrast_copy_texsubimage2d( GLcontext *ctx,
(*ctx->Driver.TexSubImage2D)(ctx, target, level,
xoffset, yoffset, width, height,
GL_RGBA, CHAN_TYPE, image,
- &_mesa_native_packing, texObj, texImage);
- FREE(image);
+ &ctx->DefaultPacking, texObj, texImage);
+ _mesa_free(image);
}
/* GL_SGIS_generate_mipmap */
@@ -403,8 +402,8 @@ _swrast_copy_texsubimage3d( GLcontext *ctx,
(*ctx->Driver.TexSubImage3D)(ctx, target, level,
xoffset, yoffset, zoffset, width, height, 1,
GL_DEPTH_COMPONENT, GL_FLOAT, image,
- &_mesa_native_packing, texObj, texImage);
- FREE(image);
+ &ctx->DefaultPacking, texObj, texImage);
+ _mesa_free(image);
}
else {
/* read RGBA image from framebuffer */
@@ -418,8 +417,8 @@ _swrast_copy_texsubimage3d( GLcontext *ctx,
(*ctx->Driver.TexSubImage3D)(ctx, target, level,
xoffset, yoffset, zoffset, width, height, 1,
GL_RGBA, CHAN_TYPE, image,
- &_mesa_native_packing, texObj, texImage);
- FREE(image);
+ &ctx->DefaultPacking, texObj, texImage);
+ _mesa_free(image);
}
/* GL_SGIS_generate_mipmap */
diff --git a/src/mesa/swrast/swrast.h b/src/mesa/swrast/swrast.h
index 61cc017b85..e1220cff4e 100644
--- a/src/mesa/swrast/swrast.h
+++ b/src/mesa/swrast/swrast.h
@@ -197,6 +197,11 @@ extern void
_swrast_print_vertex( GLcontext *ctx, const SWvertex *v );
+extern GLvoid *
+_swrast_validate_pbo_access(const struct gl_pixelstore_attrib *pack,
+ GLsizei width, GLsizei height, GLsizei depth,
+ GLenum format, GLenum type, GLvoid *ptr);
+
/*
* Imaging fallbacks (a better solution should be found, perhaps
* moving all the imaging fallback code to a new module)
@@ -252,7 +257,6 @@ _swrast_copy_texsubimage3d(GLcontext *ctx,
GLint x, GLint y, GLsizei width, GLsizei height);
-
/* The driver interface for the software rasterizer.
* Unless otherwise noted, all functions are mandatory.
*/