mesa: use new _mesa_map_pbo_source/dest() functions in more places

This trims down the code a bit.  The next step would be to combine
the validate and map operations into one helper...
This commit is contained in:
Brian Paul 2009-09-03 10:41:14 -06:00
parent 1b448c7a5c
commit 203f395aaf
5 changed files with 195 additions and 357 deletions

View File

@ -179,26 +179,21 @@ store_colortable_entries(GLcontext *ctx, struct gl_color_table *table,
GLfloat bScale, GLfloat bBias, GLfloat bScale, GLfloat bBias,
GLfloat aScale, GLfloat aBias) GLfloat aScale, GLfloat aBias)
{ {
if (_mesa_is_bufferobj(ctx->Unpack.BufferObj)) { if (!_mesa_validate_pbo_access(1, &ctx->Unpack, count, 1, 1,
/* Get/unpack the color table data from a PBO */ format, type, data)) {
GLubyte *buf; _mesa_error(ctx, GL_INVALID_OPERATION,
if (!_mesa_validate_pbo_access(1, &ctx->Unpack, count, 1, 1, "glColor[Sub]Table(bad PBO access)");
format, type, data)) { return;
_mesa_error(ctx, GL_INVALID_OPERATION,
"glColor[Sub]Table(bad PBO access)");
return;
}
buf = (GLubyte *) ctx->Driver.MapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT,
GL_READ_ONLY_ARB,
ctx->Unpack.BufferObj);
if (!buf) {
_mesa_error(ctx, GL_INVALID_OPERATION,
"glColor[Sub]Table(PBO mapped)");
return;
}
data = ADD_POINTERS(buf, data);
} }
data = _mesa_map_pbo_source(ctx, &ctx->Unpack, data);
if (!data) {
if (_mesa_is_bufferobj(ctx->Unpack.BufferObj)) {
_mesa_error(ctx, GL_INVALID_OPERATION,
"glColor[Sub]Table(PBO mapped)");
}
return;
}
{ {
/* convert user-provided data to GLfloat values */ /* convert user-provided data to GLfloat values */
@ -279,10 +274,7 @@ store_colortable_entries(GLcontext *ctx, struct gl_color_table *table,
} }
} }
if (_mesa_is_bufferobj(ctx->Unpack.BufferObj)) { _mesa_unmap_pbo_source(ctx, &ctx->Unpack);
ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT,
ctx->Unpack.BufferObj);
}
} }
@ -696,34 +688,27 @@ _mesa_GetColorTable( GLenum target, GLenum format,
return; return;
} }
if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) { if (!_mesa_validate_pbo_access(1, &ctx->Pack, table->Size, 1, 1,
/* pack color table into PBO */ format, type, data)) {
GLubyte *buf; _mesa_error(ctx, GL_INVALID_OPERATION,
if (!_mesa_validate_pbo_access(1, &ctx->Pack, table->Size, 1, 1, "glGetColorTable(invalid PBO access)");
format, type, data)) { return;
_mesa_error(ctx, GL_INVALID_OPERATION, }
"glGetColorTable(invalid PBO access)");
return; data = _mesa_map_pbo_dest(ctx, &ctx->Pack, data);
} if (!data) {
buf = (GLubyte *) ctx->Driver.MapBuffer(ctx, GL_PIXEL_PACK_BUFFER_EXT, if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) {
GL_WRITE_ONLY_ARB,
ctx->Pack.BufferObj);
if (!buf) {
/* buffer is already mapped - that's an error */ /* buffer is already mapped - that's an error */
_mesa_error(ctx, GL_INVALID_OPERATION, _mesa_error(ctx, GL_INVALID_OPERATION,
"glGetColorTable(PBO is mapped)"); "glGetColorTable(PBO is mapped)");
return;
} }
data = ADD_POINTERS(buf, data); return;
} }
_mesa_pack_rgba_span_float(ctx, table->Size, rgba, _mesa_pack_rgba_span_float(ctx, table->Size, rgba,
format, type, data, &ctx->Pack, 0x0); format, type, data, &ctx->Pack, 0x0);
if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) { _mesa_unmap_pbo_dest(ctx, &ctx->Pack);
ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_PACK_BUFFER_EXT,
ctx->Pack.BufferObj);
}
} }

View File

@ -144,27 +144,19 @@ _mesa_ConvolutionFilter1D(GLenum target, GLenum internalFormat, GLsizei width, G
ctx->Convolution1D.Width = width; ctx->Convolution1D.Width = width;
ctx->Convolution1D.Height = 1; ctx->Convolution1D.Height = 1;
if (_mesa_is_bufferobj(ctx->Unpack.BufferObj)) { if (!_mesa_validate_pbo_access(1, &ctx->Unpack, width, 1, 1,
/* unpack filter from PBO */ format, type, image)) {
GLubyte *buf; _mesa_error(ctx, GL_INVALID_OPERATION,
if (!_mesa_validate_pbo_access(1, &ctx->Unpack, width, 1, 1, "glConvolutionFilter1D(invalid PBO access)");
format, type, image)) { return;
_mesa_error(ctx, GL_INVALID_OPERATION, }
"glConvolutionFilter1D(invalid PBO access)");
return; image = _mesa_map_pbo_source(ctx, &ctx->Unpack, image);
} if (!image) {
buf = (GLubyte *) ctx->Driver.MapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT, if (_mesa_is_bufferobj(ctx->Unpack.BufferObj)) {
GL_READ_ONLY_ARB,
ctx->Unpack.BufferObj);
if (!buf) {
/* buffer is already mapped - that's an error */
_mesa_error(ctx, GL_INVALID_OPERATION, _mesa_error(ctx, GL_INVALID_OPERATION,
"glConvolutionFilter1D(PBO is mapped)"); "glConvolutionFilter1D(PBO is mapped)");
return;
} }
image = ADD_POINTERS(buf, image);
}
else if (!image) {
return; return;
} }
@ -173,10 +165,7 @@ _mesa_ConvolutionFilter1D(GLenum target, GLenum internalFormat, GLsizei width, G
format, type, image, &ctx->Unpack, format, type, image, &ctx->Unpack,
0); /* transferOps */ 0); /* transferOps */
if (_mesa_is_bufferobj(ctx->Unpack.BufferObj)) { _mesa_unmap_pbo_source(ctx, &ctx->Unpack);
ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT,
ctx->Unpack.BufferObj);
}
_mesa_scale_and_bias_rgba(width, _mesa_scale_and_bias_rgba(width,
(GLfloat (*)[4]) ctx->Convolution1D.Filter, (GLfloat (*)[4]) ctx->Convolution1D.Filter,
@ -242,27 +231,19 @@ _mesa_ConvolutionFilter2D(GLenum target, GLenum internalFormat, GLsizei width, G
ctx->Convolution2D.Width = width; ctx->Convolution2D.Width = width;
ctx->Convolution2D.Height = height; ctx->Convolution2D.Height = height;
if (_mesa_is_bufferobj(ctx->Unpack.BufferObj)) { if (!_mesa_validate_pbo_access(2, &ctx->Unpack, width, height, 1,
/* unpack filter from PBO */ format, type, image)) {
GLubyte *buf; _mesa_error(ctx, GL_INVALID_OPERATION,
if (!_mesa_validate_pbo_access(2, &ctx->Unpack, width, height, 1, "glConvolutionFilter2D(invalid PBO access)");
format, type, image)) { return;
_mesa_error(ctx, GL_INVALID_OPERATION, }
"glConvolutionFilter2D(invalid PBO access)");
return; image = _mesa_map_pbo_source(ctx, &ctx->Unpack, image);
} if (!image) {
buf = (GLubyte *) ctx->Driver.MapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT, if (_mesa_is_bufferobj(ctx->Unpack.BufferObj)) {
GL_READ_ONLY_ARB,
ctx->Unpack.BufferObj);
if (!buf) {
/* buffer is already mapped - that's an error */
_mesa_error(ctx, GL_INVALID_OPERATION, _mesa_error(ctx, GL_INVALID_OPERATION,
"glConvolutionFilter2D(PBO is mapped)"); "glConvolutionFilter2D(PBO is mapped)");
return;
} }
image = ADD_POINTERS(buf, image);
}
else if (!image) {
return; return;
} }
@ -276,10 +257,7 @@ _mesa_ConvolutionFilter2D(GLenum target, GLenum internalFormat, GLsizei width, G
0); /* transferOps */ 0); /* transferOps */
} }
if (_mesa_is_bufferobj(ctx->Unpack.BufferObj)) { _mesa_unmap_pbo_source(ctx, &ctx->Unpack);
ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT,
ctx->Unpack.BufferObj);
}
_mesa_scale_and_bias_rgba(width * height, _mesa_scale_and_bias_rgba(width * height,
(GLfloat (*)[4]) ctx->Convolution2D.Filter, (GLfloat (*)[4]) ctx->Convolution2D.Filter,
@ -598,26 +576,21 @@ _mesa_GetConvolutionFilter(GLenum target, GLenum format, GLenum type,
return; return;
} }
if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) { if (!_mesa_validate_pbo_access(2, &ctx->Pack,
/* Pack the filter into a PBO */ filter->Width, filter->Height,
GLubyte *buf; 1, format, type, image)) {
if (!_mesa_validate_pbo_access(2, &ctx->Pack, _mesa_error(ctx, GL_INVALID_OPERATION,
filter->Width, filter->Height, "glGetConvolutionFilter(invalid PBO access)");
1, format, type, image)) { return;
_mesa_error(ctx, GL_INVALID_OPERATION, }
"glGetConvolutionFilter(invalid PBO access)");
return; image = _mesa_map_pbo_dest(ctx, &ctx->Pack, image);
} if (!image) {
buf = (GLubyte *) ctx->Driver.MapBuffer(ctx, GL_PIXEL_PACK_BUFFER_EXT, if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) {
GL_WRITE_ONLY_ARB,
ctx->Pack.BufferObj);
if (!buf) {
/* buffer is already mapped - that's an error */
_mesa_error(ctx, GL_INVALID_OPERATION, _mesa_error(ctx, GL_INVALID_OPERATION,
"glGetConvolutionFilter(PBO is mapped)"); "glGetConvolutionFilter(PBO is mapped)");
return;
} }
image = ADD_POINTERS(image, buf); return;
} }
for (row = 0; row < filter->Height; row++) { for (row = 0; row < filter->Height; row++) {
@ -629,10 +602,7 @@ _mesa_GetConvolutionFilter(GLenum target, GLenum format, GLenum type,
format, type, dst, &ctx->Pack, 0x0); format, type, dst, &ctx->Pack, 0x0);
} }
if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) { _mesa_unmap_pbo_dest(ctx, &ctx->Pack);
ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_PACK_BUFFER_EXT,
ctx->Pack.BufferObj);
}
} }

View File

@ -649,27 +649,19 @@ _mesa_GetMinmax(GLenum target, GLboolean reset, GLenum format, GLenum type, GLvo
return; return;
} }
if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) { if (!_mesa_validate_pbo_access(1, &ctx->Pack, 2, 1, 1,
/* pack min/max values into a PBO */ format, type, values)) {
GLubyte *buf; _mesa_error(ctx, GL_INVALID_OPERATION,
if (!_mesa_validate_pbo_access(1, &ctx->Pack, 2, 1, 1, "glGetMinMax(invalid PBO access)");
format, type, values)) { return;
_mesa_error(ctx, GL_INVALID_OPERATION, }
"glGetMinMax(invalid PBO access)");
return; values = _mesa_map_pbo_dest(ctx, &ctx->Pack, values);
} if (!values) {
buf = (GLubyte *) ctx->Driver.MapBuffer(ctx, GL_PIXEL_PACK_BUFFER_EXT, if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) {
GL_WRITE_ONLY_ARB,
ctx->Pack.BufferObj);
if (!buf) {
/* buffer is already mapped - that's an error */ /* buffer is already mapped - that's an error */
_mesa_error(ctx, GL_INVALID_OPERATION,"glGetMinMax(PBO is mapped)"); _mesa_error(ctx, GL_INVALID_OPERATION,"glGetMinMax(PBO is mapped)");
return;
} }
values = ADD_POINTERS(buf, values);
}
else if (!values) {
/* not an error */
return; return;
} }
@ -687,10 +679,7 @@ _mesa_GetMinmax(GLenum target, GLboolean reset, GLenum format, GLenum type, GLvo
format, type, values, &ctx->Pack, 0x0); format, type, values, &ctx->Pack, 0x0);
} }
if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) { _mesa_unmap_pbo_dest(ctx, &ctx->Pack);
ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_PACK_BUFFER_EXT,
ctx->Pack.BufferObj);
}
if (reset) { if (reset) {
_mesa_ResetMinmax(GL_MINMAX); _mesa_ResetMinmax(GL_MINMAX);
@ -733,27 +722,18 @@ _mesa_GetHistogram(GLenum target, GLboolean reset, GLenum format, GLenum type, G
return; return;
} }
if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) { if (!_mesa_validate_pbo_access(1, &ctx->Pack, ctx->Histogram.Width, 1, 1,
/* pack min/max values into a PBO */ format, type, values)) {
GLubyte *buf; _mesa_error(ctx, GL_INVALID_OPERATION,
if (!_mesa_validate_pbo_access(1, &ctx->Pack, ctx->Histogram.Width, 1, 1, "glGetHistogram(invalid PBO access)");
format, type, values)) { return;
_mesa_error(ctx, GL_INVALID_OPERATION,
"glGetHistogram(invalid PBO access)");
return;
}
buf = (GLubyte *) ctx->Driver.MapBuffer(ctx, GL_PIXEL_PACK_BUFFER_EXT,
GL_WRITE_ONLY_ARB,
ctx->Pack.BufferObj);
if (!buf) {
/* buffer is already mapped - that's an error */
_mesa_error(ctx,GL_INVALID_OPERATION,"glGetHistogram(PBO is mapped)");
return;
}
values = ADD_POINTERS(buf, values);
} }
else if (!values) {
/* not an error */ values = _mesa_map_pbo_dest(ctx, &ctx->Pack, values);
if (!values) {
if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) {
_mesa_error(ctx,GL_INVALID_OPERATION,"glGetHistogram(PBO is mapped)");
}
return; return;
} }
@ -761,10 +741,7 @@ _mesa_GetHistogram(GLenum target, GLboolean reset, GLenum format, GLenum type, G
(CONST GLuint (*)[4]) ctx->Histogram.Count, (CONST GLuint (*)[4]) ctx->Histogram.Count,
format, type, values, &ctx->Pack); format, type, values, &ctx->Pack);
if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) { _mesa_unmap_pbo_dest(ctx, &ctx->Pack);
ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_PACK_BUFFER_EXT,
ctx->Pack.BufferObj);
}
if (reset) { if (reset) {
GLuint i; GLuint i;

View File

@ -136,6 +136,33 @@ store_pixelmap(GLcontext *ctx, GLenum map, GLsizei mapsize,
} }
/**
* Convenience wrapper for _mesa_validate_pbo_access() for gl[Get]PixelMap().
*/
static GLboolean
validate_pbo_access(GLcontext *ctx, struct gl_pixelstore_attrib *pack,
GLsizei mapsize, GLenum format, GLenum type,
const GLvoid *ptr)
{
GLboolean ok;
/* Note, need to use DefaultPacking and Unpack's buffer object */
ctx->DefaultPacking.BufferObj = pack->BufferObj;
ok = _mesa_validate_pbo_access(1, &ctx->DefaultPacking, mapsize, 1, 1,
format, type, ptr);
/* restore */
ctx->DefaultPacking.BufferObj = ctx->Shared->NullBufferObj;
if (!ok) {
_mesa_error(ctx, GL_INVALID_OPERATION,
"glPixelMap(invalid PBO access)");
}
return ok;
}
void GLAPIENTRY void GLAPIENTRY
_mesa_PixelMapfv( GLenum map, GLsizei mapsize, const GLfloat *values ) _mesa_PixelMapfv( GLenum map, GLsizei mapsize, const GLfloat *values )
{ {
@ -158,40 +185,23 @@ _mesa_PixelMapfv( GLenum map, GLsizei mapsize, const GLfloat *values )
FLUSH_VERTICES(ctx, _NEW_PIXEL); FLUSH_VERTICES(ctx, _NEW_PIXEL);
if (_mesa_is_bufferobj(ctx->Unpack.BufferObj)) { if (!validate_pbo_access(ctx, &ctx->Unpack, mapsize,
/* unpack pixelmap from PBO */ GL_INTENSITY, GL_FLOAT, values)) {
GLubyte *buf; return;
/* Note, need to use DefaultPacking and Unpack's buffer object */ }
ctx->DefaultPacking.BufferObj = ctx->Unpack.BufferObj;
if (!_mesa_validate_pbo_access(1, &ctx->DefaultPacking, mapsize, 1, 1, values = (const GLfloat *) _mesa_map_pbo_source(ctx, &ctx->Unpack, values);
GL_INTENSITY, GL_FLOAT, values)) { if (!values) {
_mesa_error(ctx, GL_INVALID_OPERATION, if (_mesa_is_bufferobj(ctx->Unpack.BufferObj)) {
"glPixelMapfv(invalid PBO access)");
return;
}
/* restore */
ctx->DefaultPacking.BufferObj = ctx->Shared->NullBufferObj;
buf = (GLubyte *) ctx->Driver.MapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT,
GL_READ_ONLY_ARB,
ctx->Unpack.BufferObj);
if (!buf) {
/* buffer is already mapped - that's an error */
_mesa_error(ctx, GL_INVALID_OPERATION, _mesa_error(ctx, GL_INVALID_OPERATION,
"glPixelMapfv(PBO is mapped)"); "glPixelMapfv(PBO is mapped)");
return;
} }
values = (const GLfloat *) ADD_POINTERS(buf, values);
}
else if (!values) {
return; return;
} }
store_pixelmap(ctx, map, mapsize, values); store_pixelmap(ctx, map, mapsize, values);
if (_mesa_is_bufferobj(ctx->Unpack.BufferObj)) { _mesa_unmap_pbo_source(ctx, &ctx->Unpack);
ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT,
ctx->Unpack.BufferObj);
}
} }
@ -217,31 +227,17 @@ _mesa_PixelMapuiv(GLenum map, GLsizei mapsize, const GLuint *values )
FLUSH_VERTICES(ctx, _NEW_PIXEL); FLUSH_VERTICES(ctx, _NEW_PIXEL);
if (_mesa_is_bufferobj(ctx->Unpack.BufferObj)) { if (!validate_pbo_access(ctx, &ctx->Unpack, mapsize,
/* unpack pixelmap from PBO */ GL_INTENSITY, GL_UNSIGNED_INT, values)) {
GLubyte *buf; return;
/* Note, need to use DefaultPacking and Unpack's buffer object */ }
ctx->DefaultPacking.BufferObj = ctx->Unpack.BufferObj;
if (!_mesa_validate_pbo_access(1, &ctx->DefaultPacking, mapsize, 1, 1, values = (const GLuint *) _mesa_map_pbo_source(ctx, &ctx->Unpack, values);
GL_INTENSITY, GL_UNSIGNED_INT, values)) { if (!values) {
_mesa_error(ctx, GL_INVALID_OPERATION, if (_mesa_is_bufferobj(ctx->Unpack.BufferObj)) {
"glPixelMapuiv(invalid PBO access)");
return;
}
/* restore */
ctx->DefaultPacking.BufferObj = ctx->Shared->NullBufferObj;
buf = (GLubyte *) ctx->Driver.MapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT,
GL_READ_ONLY_ARB,
ctx->Unpack.BufferObj);
if (!buf) {
/* buffer is already mapped - that's an error */
_mesa_error(ctx, GL_INVALID_OPERATION, _mesa_error(ctx, GL_INVALID_OPERATION,
"glPixelMapuiv(PBO is mapped)"); "glPixelMapuiv(PBO is mapped)");
return;
} }
values = (const GLuint *) ADD_POINTERS(buf, values);
}
else if (!values) {
return; return;
} }
@ -259,10 +255,7 @@ _mesa_PixelMapuiv(GLenum map, GLsizei mapsize, const GLuint *values )
} }
} }
if (_mesa_is_bufferobj(ctx->Unpack.BufferObj)) { _mesa_unmap_pbo_source(ctx, &ctx->Unpack);
ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT,
ctx->Unpack.BufferObj);
}
store_pixelmap(ctx, map, mapsize, fvalues); store_pixelmap(ctx, map, mapsize, fvalues);
} }
@ -290,32 +283,17 @@ _mesa_PixelMapusv(GLenum map, GLsizei mapsize, const GLushort *values )
FLUSH_VERTICES(ctx, _NEW_PIXEL); FLUSH_VERTICES(ctx, _NEW_PIXEL);
if (_mesa_is_bufferobj(ctx->Unpack.BufferObj)) { if (!validate_pbo_access(ctx, &ctx->Unpack, mapsize,
/* unpack pixelmap from PBO */ GL_INTENSITY, GL_UNSIGNED_SHORT, values)) {
GLubyte *buf; return;
/* Note, need to use DefaultPacking and Unpack's buffer object */ }
ctx->DefaultPacking.BufferObj = ctx->Unpack.BufferObj;
if (!_mesa_validate_pbo_access(1, &ctx->DefaultPacking, mapsize, 1, 1, values = (const GLushort *) _mesa_map_pbo_source(ctx, &ctx->Unpack, values);
GL_INTENSITY, GL_UNSIGNED_SHORT, if (!values) {
values)) { if (_mesa_is_bufferobj(ctx->Unpack.BufferObj)) {
_mesa_error(ctx, GL_INVALID_OPERATION,
"glPixelMapusv(invalid PBO access)");
return;
}
/* restore */
ctx->DefaultPacking.BufferObj = ctx->Shared->NullBufferObj;
buf = (GLubyte *) ctx->Driver.MapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT,
GL_READ_ONLY_ARB,
ctx->Unpack.BufferObj);
if (!buf) {
/* buffer is already mapped - that's an error */
_mesa_error(ctx, GL_INVALID_OPERATION, _mesa_error(ctx, GL_INVALID_OPERATION,
"glPixelMapusv(PBO is mapped)"); "glPixelMapusv(PBO is mapped)");
return;
} }
values = (const GLushort *) ADD_POINTERS(buf, values);
}
else if (!values) {
return; return;
} }
@ -333,10 +311,7 @@ _mesa_PixelMapusv(GLenum map, GLsizei mapsize, const GLushort *values )
} }
} }
if (_mesa_is_bufferobj(ctx->Unpack.BufferObj)) { _mesa_unmap_pbo_source(ctx, &ctx->Unpack);
ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT,
ctx->Unpack.BufferObj);
}
store_pixelmap(ctx, map, mapsize, fvalues); store_pixelmap(ctx, map, mapsize, fvalues);
} }
@ -359,31 +334,17 @@ _mesa_GetPixelMapfv( GLenum map, GLfloat *values )
mapsize = pm->Size; mapsize = pm->Size;
if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) { if (!validate_pbo_access(ctx, &ctx->Pack, mapsize,
/* pack pixelmap into PBO */ GL_INTENSITY, GL_FLOAT, values)) {
GLubyte *buf; return;
/* Note, need to use DefaultPacking and Pack's buffer object */ }
ctx->DefaultPacking.BufferObj = ctx->Pack.BufferObj;
if (!_mesa_validate_pbo_access(1, &ctx->DefaultPacking, mapsize, 1, 1, values = (GLfloat *) _mesa_map_pbo_dest(ctx, &ctx->Pack, values);
GL_INTENSITY, GL_FLOAT, values)) { if (!values) {
_mesa_error(ctx, GL_INVALID_OPERATION, if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) {
"glGetPixelMapfv(invalid PBO access)");
return;
}
/* restore */
ctx->DefaultPacking.BufferObj = ctx->Shared->NullBufferObj;
buf = (GLubyte *) ctx->Driver.MapBuffer(ctx, GL_PIXEL_PACK_BUFFER_EXT,
GL_WRITE_ONLY_ARB,
ctx->Pack.BufferObj);
if (!buf) {
/* buffer is already mapped - that's an error */
_mesa_error(ctx, GL_INVALID_OPERATION, _mesa_error(ctx, GL_INVALID_OPERATION,
"glGetPixelMapfv(PBO is mapped)"); "glGetPixelMapfv(PBO is mapped)");
return;
} }
values = (GLfloat *) ADD_POINTERS(buf, values);
}
else if (!values) {
return; return;
} }
@ -397,10 +358,7 @@ _mesa_GetPixelMapfv( GLenum map, GLfloat *values )
MEMCPY(values, pm->Map, mapsize * sizeof(GLfloat)); MEMCPY(values, pm->Map, mapsize * sizeof(GLfloat));
} }
if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) { _mesa_unmap_pbo_dest(ctx, &ctx->Pack);
ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_PACK_BUFFER_EXT,
ctx->Pack.BufferObj);
}
} }
@ -420,31 +378,17 @@ _mesa_GetPixelMapuiv( GLenum map, GLuint *values )
} }
mapsize = pm->Size; mapsize = pm->Size;
if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) { if (!validate_pbo_access(ctx, &ctx->Pack, mapsize,
/* pack pixelmap into PBO */ GL_INTENSITY, GL_UNSIGNED_INT, values)) {
GLubyte *buf; return;
/* Note, need to use DefaultPacking and Pack's buffer object */ }
ctx->DefaultPacking.BufferObj = ctx->Pack.BufferObj;
if (!_mesa_validate_pbo_access(1, &ctx->DefaultPacking, mapsize, 1, 1, values = (GLuint *) _mesa_map_pbo_dest(ctx, &ctx->Pack, values);
GL_INTENSITY, GL_UNSIGNED_INT, values)) { if (!values) {
_mesa_error(ctx, GL_INVALID_OPERATION, if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) {
"glGetPixelMapuiv(invalid PBO access)");
return;
}
/* restore */
ctx->DefaultPacking.BufferObj = ctx->Shared->NullBufferObj;
buf = (GLubyte *) ctx->Driver.MapBuffer(ctx, GL_PIXEL_PACK_BUFFER_EXT,
GL_WRITE_ONLY_ARB,
ctx->Pack.BufferObj);
if (!buf) {
/* buffer is already mapped - that's an error */
_mesa_error(ctx, GL_INVALID_OPERATION, _mesa_error(ctx, GL_INVALID_OPERATION,
"glGetPixelMapuiv(PBO is mapped)"); "glGetPixelMapuiv(PBO is mapped)");
return;
} }
values = (GLuint *) ADD_POINTERS(buf, values);
}
else if (!values) {
return; return;
} }
@ -458,10 +402,7 @@ _mesa_GetPixelMapuiv( GLenum map, GLuint *values )
} }
} }
if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) { _mesa_unmap_pbo_dest(ctx, &ctx->Pack);
ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_PACK_BUFFER_EXT,
ctx->Pack.BufferObj);
}
} }
@ -481,32 +422,17 @@ _mesa_GetPixelMapusv( GLenum map, GLushort *values )
} }
mapsize = pm ? pm->Size : 0; mapsize = pm ? pm->Size : 0;
if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) { if (!validate_pbo_access(ctx, &ctx->Pack, mapsize,
/* pack pixelmap into PBO */ GL_INTENSITY, GL_UNSIGNED_SHORT, values)) {
GLubyte *buf; return;
/* Note, need to use DefaultPacking and Pack's buffer object */ }
ctx->DefaultPacking.BufferObj = ctx->Pack.BufferObj;
if (!_mesa_validate_pbo_access(1, &ctx->DefaultPacking, mapsize, 1, 1, values = (GLushort *) _mesa_map_pbo_dest(ctx, &ctx->Pack, values);
GL_INTENSITY, GL_UNSIGNED_SHORT, if (!values) {
values)) { if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) {
_mesa_error(ctx, GL_INVALID_OPERATION,
"glGetPixelMapusv(invalid PBO access)");
return;
}
/* restore */
ctx->DefaultPacking.BufferObj = ctx->Shared->NullBufferObj;
buf = (GLubyte *) ctx->Driver.MapBuffer(ctx, GL_PIXEL_PACK_BUFFER_EXT,
GL_WRITE_ONLY_ARB,
ctx->Pack.BufferObj);
if (!buf) {
/* buffer is already mapped - that's an error */
_mesa_error(ctx, GL_INVALID_OPERATION, _mesa_error(ctx, GL_INVALID_OPERATION,
"glGetPixelMapusv(PBO is mapped)"); "glGetPixelMapusv(PBO is mapped)");
return;
} }
values = (GLushort *) ADD_POINTERS(buf, values);
}
else if (!values) {
return; return;
} }
@ -528,10 +454,7 @@ _mesa_GetPixelMapusv( GLenum map, GLushort *values )
} }
} }
if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) { _mesa_unmap_pbo_dest(ctx, &ctx->Pack);
ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_PACK_BUFFER_EXT,
ctx->Pack.BufferObj);
}
} }

View File

@ -193,32 +193,25 @@ _mesa_PolygonMode( GLenum face, GLenum mode )
void void
_mesa_polygon_stipple(GLcontext *ctx, const GLubyte *pattern) _mesa_polygon_stipple(GLcontext *ctx, const GLubyte *pattern)
{ {
if (_mesa_is_bufferobj(ctx->Unpack.BufferObj)) { if (!_mesa_validate_pbo_access(2, &ctx->Unpack, 32, 32, 1,
/* Get/unpack the stipple pattern from a PBO */ GL_COLOR_INDEX, GL_BITMAP, pattern)) {
GLubyte *buf; _mesa_error(ctx, GL_INVALID_OPERATION,
if (!_mesa_validate_pbo_access(2, &ctx->Unpack, 32, 32, 1, "glPolygonStipple(bad PBO access)");
GL_COLOR_INDEX, GL_BITMAP, pattern)) { return;
_mesa_error(ctx, GL_INVALID_OPERATION, }
"glPolygonStipple(bad PBO access)");
return; pattern = _mesa_map_pbo_source(ctx, &ctx->Unpack, pattern);
} if (!pattern) {
buf = (GLubyte *) ctx->Driver.MapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT, if (_mesa_is_bufferobj(ctx->Unpack.BufferObj)) {
GL_READ_ONLY_ARB,
ctx->Unpack.BufferObj);
if (!buf) {
_mesa_error(ctx, GL_INVALID_OPERATION, _mesa_error(ctx, GL_INVALID_OPERATION,
"glPolygonStipple(PBO mapped)"); "glPolygonStipple(PBO mapped)");
return;
} }
buf = ADD_POINTERS(buf, pattern); return;
_mesa_unpack_polygon_stipple(buf, ctx->PolygonStipple, &ctx->Unpack);
ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT,
ctx->Unpack.BufferObj);
}
else {
/* Get/unpack the stipple pattern from user memory */
_mesa_unpack_polygon_stipple(pattern, ctx->PolygonStipple, &ctx->Unpack);
} }
_mesa_unpack_polygon_stipple(pattern, ctx->PolygonStipple, &ctx->Unpack);
_mesa_unmap_pbo_source(ctx, &ctx->Unpack);
} }
@ -255,35 +248,25 @@ _mesa_GetPolygonStipple( GLubyte *dest )
if (MESA_VERBOSE&VERBOSE_API) if (MESA_VERBOSE&VERBOSE_API)
_mesa_debug(ctx, "glGetPolygonStipple\n"); _mesa_debug(ctx, "glGetPolygonStipple\n");
/* XXX someday we may put this code into a separate function and call if (!_mesa_validate_pbo_access(2, &ctx->Pack, 32, 32, 1,
* it with ctx->Driver.GetPolygonStipple(). GL_COLOR_INDEX, GL_BITMAP, dest)) {
*/ _mesa_error(ctx, GL_INVALID_OPERATION,
if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) { "glGetPolygonStipple(bad PBO access)");
/* Put/pack the stipple pattern into a PBO */ return;
GLubyte *buf; }
if (!_mesa_validate_pbo_access(2, &ctx->Pack, 32, 32, 1,
GL_COLOR_INDEX, GL_BITMAP, dest)) { dest = _mesa_map_pbo_dest(ctx, &ctx->Pack, dest);
_mesa_error(ctx, GL_INVALID_OPERATION, if (!dest) {
"glGetPolygonStipple(bad PBO access)"); if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) {
return;
}
buf = (GLubyte *) ctx->Driver.MapBuffer(ctx, GL_PIXEL_PACK_BUFFER_EXT,
GL_WRITE_ONLY_ARB,
ctx->Pack.BufferObj);
if (!buf) {
_mesa_error(ctx, GL_INVALID_OPERATION, _mesa_error(ctx, GL_INVALID_OPERATION,
"glGetPolygonStipple(PBO mapped)"); "glGetPolygonStipple(PBO mapped)");
return;
} }
buf = ADD_POINTERS(buf, dest); return;
_mesa_pack_polygon_stipple(ctx->PolygonStipple, buf, &ctx->Pack);
ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_PACK_BUFFER_EXT,
ctx->Pack.BufferObj);
}
else {
/* Put/pack the stipple pattern into user memory */
_mesa_pack_polygon_stipple(ctx->PolygonStipple, dest, &ctx->Pack);
} }
_mesa_pack_polygon_stipple(ctx->PolygonStipple, dest, &ctx->Pack);
_mesa_unmap_pbo_dest(ctx, &ctx->Pack);
} }