Instead of _mesa_map_readpix_pbo() use _mesa_map_pbo_source().
Instead of _mesa_map_drawpix_pbo() and _mesa_map_bitmap_pbo() use
_mesa_map_pbo_dest().
* currently mapped. Whoever calls this function should check for that.
* Remember, we can't use a PBO when it's mapped!
*
+ * If we're not using a PBO, this is a no-op.
+ *
* \param width width of image to read/write
* \param height height of image to read/write
* \param depth depth of image to read/write
GLvoid *start, *end;
const GLubyte *sizeAddr; /* buffer size, cast to a pointer */
- ASSERT(_mesa_is_bufferobj(pack->BufferObj));
+ if (!_mesa_is_bufferobj(pack->BufferObj))
+ return GL_TRUE; /* no PBO, OK */
if (pack->BufferObj->Size == 0)
/* no buffer! */
/**
- * If the source of glBitmap data is a PBO, check that we won't read out
- * of buffer bounds, then map the buffer.
- * If not sourcing from a PBO, just return the bitmap pointer.
- * This is a helper function for (some) drivers.
- * Return NULL if error.
- * If non-null return, must call _mesa_unmap_bitmap_pbo() when done.
+ * For commands that read from a PBO (glDrawPixels, glTexImage,
+ * glPolygonStipple, etc), if we're reading from a PBO, map it read-only
+ * and return the pointer into the PBO. If we're not reading from a
+ * PBO, return \p src as-is.
+ * If non-null return, must call _mesa_unmap_pbo_source() when done.
+ *
+ * \return NULL if error, else pointer to start of data
*/
-const GLubyte *
-_mesa_map_bitmap_pbo(GLcontext *ctx,
+const GLvoid *
+_mesa_map_pbo_source(GLcontext *ctx,
const struct gl_pixelstore_attrib *unpack,
- const GLubyte *bitmap)
+ const GLvoid *src)
{
const GLubyte *buf;
if (!buf)
return NULL;
- buf = ADD_POINTERS(buf, bitmap);
+ buf = ADD_POINTERS(buf, src);
}
else {
/* unpack from normal memory */
- buf = bitmap;
+ buf = src;
}
return buf;
/**
- * Counterpart to _mesa_map_bitmap_pbo()
- * This is a helper function for (some) drivers.
+ * Counterpart to _mesa_map_pbo_source()
*/
void
-_mesa_unmap_bitmap_pbo(GLcontext *ctx,
+_mesa_unmap_pbo_source(GLcontext *ctx,
const struct gl_pixelstore_attrib *unpack)
{
+ ASSERT(unpack != &ctx->Pack); /* catch pack/unpack mismatch */
if (_mesa_is_bufferobj(unpack->BufferObj)) {
ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT,
unpack->BufferObj);
/**
- * \sa _mesa_map_bitmap_pbo
- */
-const GLvoid *
-_mesa_map_drawpix_pbo(GLcontext *ctx,
- const struct gl_pixelstore_attrib *unpack,
- const GLvoid *pixels)
-{
- const GLvoid *buf;
-
- if (_mesa_is_bufferobj(unpack->BufferObj)) {
- /* unpack from PBO */
- buf = (GLubyte *) ctx->Driver.MapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT,
- GL_READ_ONLY_ARB,
- unpack->BufferObj);
- if (!buf)
- return NULL;
-
- buf = ADD_POINTERS(buf, pixels);
- }
- else {
- /* unpack from normal memory */
- buf = pixels;
- }
-
- return buf;
-}
-
-
-/**
- * \sa _mesa_unmap_bitmap_pbo
- */
-void
-_mesa_unmap_drawpix_pbo(GLcontext *ctx,
- const struct gl_pixelstore_attrib *unpack)
-{
- if (_mesa_is_bufferobj(unpack->BufferObj)) {
- ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT,
- unpack->BufferObj);
- }
-}
-
-
-/**
- * If PBO is bound, map the buffer, return dest pointer in mapped buffer.
- * Call _mesa_unmap_readpix_pbo() when finished
- * \return NULL if error
+ * For commands that write to a PBO (glReadPixels, glGetColorTable, etc),
+ * if we're writing to a PBO, map it write-only and return the pointer
+ * into the PBO. If we're not writing to a PBO, return \p dst as-is.
+ * If non-null return, must call _mesa_unmap_pbo_dest() when done.
+ *
+ * \return NULL if error, else pointer to start of data
*/
void *
-_mesa_map_readpix_pbo(GLcontext *ctx,
- const struct gl_pixelstore_attrib *pack,
- GLvoid *dest)
+_mesa_map_pbo_dest(GLcontext *ctx,
+ const struct gl_pixelstore_attrib *pack,
+ GLvoid *dest)
{
void *buf;
/**
- * Counterpart to _mesa_map_readpix_pbo()
+ * Counterpart to _mesa_map_pbo_dest()
*/
void
-_mesa_unmap_readpix_pbo(GLcontext *ctx,
- const struct gl_pixelstore_attrib *pack)
+_mesa_unmap_pbo_dest(GLcontext *ctx,
+ const struct gl_pixelstore_attrib *pack)
{
+ ASSERT(pack != &ctx->Unpack); /* catch pack/unpack mismatch */
if (_mesa_is_bufferobj(pack->BufferObj)) {
ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_PACK_BUFFER_EXT, pack->BufferObj);
}
GLsizei width, GLsizei height, GLsizei depth,
GLenum format, GLenum type, const GLvoid *ptr);
-extern const GLubyte *
-_mesa_map_bitmap_pbo(GLcontext *ctx,
+extern const GLvoid *
+_mesa_map_pbo_source(GLcontext *ctx,
const struct gl_pixelstore_attrib *unpack,
- const GLubyte *bitmap);
+ const GLvoid *src);
extern void
-_mesa_unmap_bitmap_pbo(GLcontext *ctx,
+_mesa_unmap_pbo_source(GLcontext *ctx,
const struct gl_pixelstore_attrib *unpack);
-extern const GLvoid *
-_mesa_map_drawpix_pbo(GLcontext *ctx,
- const struct gl_pixelstore_attrib *unpack,
- const GLvoid *pixels);
-
-extern void
-_mesa_unmap_drawpix_pbo(GLcontext *ctx,
- const struct gl_pixelstore_attrib *unpack);
-
extern void *
-_mesa_map_readpix_pbo(GLcontext *ctx,
- const struct gl_pixelstore_attrib *pack,
- GLvoid *dest);
+_mesa_map_pbo_dest(GLcontext *ctx,
+ const struct gl_pixelstore_attrib *pack,
+ GLvoid *dest);
extern void
-_mesa_unmap_readpix_pbo(GLcontext *ctx,
- const struct gl_pixelstore_attrib *pack);
+_mesa_unmap_pbo_dest(GLcontext *ctx,
+ const struct gl_pixelstore_attrib *pack);
extern void
struct pipe_texture *pt;
/* PBO source... */
- bitmap = _mesa_map_bitmap_pbo(ctx, unpack, bitmap);
+ bitmap = _mesa_map_pbo_source(ctx, unpack, bitmap);
if (!bitmap) {
return NULL;
}
0, width, height, 1,
PIPE_TEXTURE_USAGE_SAMPLER);
if (!pt) {
- _mesa_unmap_bitmap_pbo(ctx, unpack);
+ _mesa_unmap_pbo_source(ctx, unpack);
return NULL;
}
unpack_bitmap(ctx->st, 0, 0, width, height, unpack, bitmap,
dest, transfer->stride);
- _mesa_unmap_bitmap_pbo(ctx, unpack);
+ _mesa_unmap_pbo_source(ctx, unpack);
/* Release transfer */
screen->transfer_unmap(screen, transfer);
assert(pipeFormat);
cpp = st_sizeof_format(pipeFormat);
- pixels = _mesa_map_drawpix_pbo(ctx, unpack, pixels);
+ pixels = _mesa_map_pbo_source(ctx, unpack, pixels);
if (!pixels)
return NULL;
pt = st_texture_create(st, PIPE_TEXTURE_2D, pipeFormat, 0, ptw, pth, 1,
PIPE_TEXTURE_USAGE_SAMPLER);
if (!pt) {
- _mesa_unmap_drawpix_pbo(ctx, unpack);
+ _mesa_unmap_pbo_source(ctx, unpack);
return NULL;
}
ctx->_ImageTransferState = imageTransferStateSave;
}
- _mesa_unmap_drawpix_pbo(ctx, unpack);
+ _mesa_unmap_pbo_source(ctx, unpack);
return pt;
}
stmap = screen->transfer_map(screen, pt);
- pixels = _mesa_map_drawpix_pbo(ctx, unpack, pixels);
+ pixels = _mesa_map_pbo_source(ctx, unpack, pixels);
assert(pixels);
/* if width > MAX_WIDTH, have to process image in chunks */
skipPixels += spanWidth;
}
- _mesa_unmap_drawpix_pbo(ctx, unpack);
+ _mesa_unmap_pbo_source(ctx, unpack);
/* unmap the stencil buffer */
screen->transfer_unmap(screen, pt);
return;
}
- dest = _mesa_map_readpix_pbo(ctx, &clippedPacking, dest);
+ dest = _mesa_map_pbo_dest(ctx, &clippedPacking, dest);
if (!dest)
return;
if (st_fast_readpixels(ctx, strb, x, y, width, height,
format, type, pack, dest)) {
/* success! */
- _mesa_unmap_readpix_pbo(ctx, &clippedPacking);
+ _mesa_unmap_pbo_dest(ctx, &clippedPacking);
return;
}
screen->tex_transfer_destroy(trans);
- _mesa_unmap_readpix_pbo(ctx, &clippedPacking);
+ _mesa_unmap_pbo_dest(ctx, &clippedPacking);
}
PIPE_TRANSFER_READ,
0, 0, width, height);
- pixels = _mesa_map_readpix_pbo(ctx, &ctx->Pack, pixels);
+ pixels = _mesa_map_pbo_dest(ctx, &ctx->Pack, pixels);
/* copy/pack data into user buffer */
if (st_equal_formats(stImage->pt->format, format, type)) {
}
}
- _mesa_unmap_readpix_pbo(ctx, &ctx->Pack);
+ _mesa_unmap_pbo_dest(ctx, &ctx->Pack);
/* destroy the temp / dest surface */
util_destroy_rgba_surface(dst_texture, dst_surface);
ASSERT(ctx->RenderMode == GL_RENDER);
- bitmap = _mesa_map_bitmap_pbo(ctx, unpack, bitmap);
+ bitmap = (const GLubyte *) _mesa_map_pbo_source(ctx, unpack, bitmap);
if (!bitmap)
return;
swrast_render_finish(ctx);
- _mesa_unmap_bitmap_pbo(ctx, unpack);
+ _mesa_unmap_pbo_source(ctx, unpack);
}
if (swrast->NewState)
_swrast_validate_derived( ctx );
- pixels = _mesa_map_drawpix_pbo(ctx, unpack, pixels);
+ pixels = _mesa_map_pbo_source(ctx, unpack, pixels);
if (!pixels) {
swrast_render_finish(ctx);
_mesa_set_vp_override(ctx, save_vp_override);
swrast_render_finish(ctx);
_mesa_set_vp_override(ctx, save_vp_override);
- _mesa_unmap_drawpix_pbo(ctx, unpack);
+ _mesa_unmap_pbo_source(ctx, unpack);
}
return;
}
- pixels = _mesa_map_readpix_pbo(ctx, &clippedPacking, pixels);
+ pixels = _mesa_map_pbo_dest(ctx, &clippedPacking, pixels);
if (!pixels)
return;
swrast_render_finish(ctx);
- _mesa_unmap_readpix_pbo(ctx, &clippedPacking);
+ _mesa_unmap_pbo_dest(ctx, &clippedPacking);
}