add a number of PBO validate/map/unmap functions
Helper functions for (some) drivers, including swrast. cherry-picked from Mesa/master
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
* Mesa 3-D graphics library
|
* Mesa 3-D graphics library
|
||||||
* Version: 6.5.1
|
* Version: 7.1
|
||||||
*
|
*
|
||||||
* Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
|
* Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
* copy of this software and associated documentation files (the "Software"),
|
* copy of this software and associated documentation files (the "Software"),
|
||||||
@@ -469,6 +469,189 @@ _mesa_validate_pbo_access(GLuint dimensions,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 validate_and_map_bitmap_pbo() when done.
|
||||||
|
*/
|
||||||
|
const GLubyte *
|
||||||
|
_mesa_validate_and_map_bitmap_pbo(GLcontext *ctx,
|
||||||
|
GLsizei width, GLsizei height,
|
||||||
|
const struct gl_pixelstore_attrib *unpack,
|
||||||
|
const GLubyte *bitmap)
|
||||||
|
{
|
||||||
|
const GLubyte *buf;
|
||||||
|
|
||||||
|
if (unpack->BufferObj->Name) {
|
||||||
|
/* unpack from PBO */
|
||||||
|
if (!_mesa_validate_pbo_access(2, unpack, width, height, 1,
|
||||||
|
GL_COLOR_INDEX, GL_BITMAP,
|
||||||
|
(GLvoid *) bitmap)) {
|
||||||
|
_mesa_error(ctx, GL_INVALID_OPERATION,"glBitmap(invalid PBO access)");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (unpack->BufferObj->Pointer) {
|
||||||
|
/* buffer is already mapped - that's an error */
|
||||||
|
_mesa_error(ctx, GL_INVALID_OPERATION, "glBitmap(PBO is mapped)");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
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, bitmap);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
/* unpack from normal memory */
|
||||||
|
buf = bitmap;
|
||||||
|
}
|
||||||
|
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Counterpart to validate_and_map_bitmap_pbo()
|
||||||
|
* This is a helper function for (some) drivers.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
_mesa_unmap_bitmap_pbo(GLcontext *ctx,
|
||||||
|
const struct gl_pixelstore_attrib *unpack)
|
||||||
|
{
|
||||||
|
if (unpack->BufferObj->Name) {
|
||||||
|
ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT,
|
||||||
|
unpack->BufferObj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \sa _mesa_validate_and_map_bitmap_pbo
|
||||||
|
*/
|
||||||
|
const GLvoid *
|
||||||
|
_mesa_validate_and_map_drawpix_pbo(GLcontext *ctx,
|
||||||
|
GLsizei width, GLsizei height,
|
||||||
|
GLenum format, GLenum type,
|
||||||
|
const struct gl_pixelstore_attrib *unpack,
|
||||||
|
const GLvoid *pixels)
|
||||||
|
{
|
||||||
|
const GLvoid *buf;
|
||||||
|
|
||||||
|
if (unpack->BufferObj->Name) {
|
||||||
|
/* unpack from PBO */
|
||||||
|
|
||||||
|
if (!_mesa_validate_pbo_access(2, unpack, width, height, 1,
|
||||||
|
format, type, pixels)) {
|
||||||
|
_mesa_error(ctx, GL_INVALID_OPERATION,
|
||||||
|
"glDrawPixels(invalid PBO access)");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (unpack->BufferObj->Pointer) {
|
||||||
|
/* buffer is already mapped - that's an error */
|
||||||
|
_mesa_error(ctx, GL_INVALID_OPERATION, "glDrawPixels(PBO is mapped)");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
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_drapix_pbo(GLcontext *ctx,
|
||||||
|
const struct gl_pixelstore_attrib *unpack)
|
||||||
|
{
|
||||||
|
if (unpack->BufferObj->Name) {
|
||||||
|
ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT,
|
||||||
|
unpack->BufferObj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* When doing glReadPixels into a PBO, this function will check for errors
|
||||||
|
* and map the buffer.
|
||||||
|
* Call _mesa_unmap_readpix_pbo() when finished
|
||||||
|
* \return NULL if error
|
||||||
|
*/
|
||||||
|
void *
|
||||||
|
_mesa_validate_and_map_readpix_pbo(GLcontext *ctx,
|
||||||
|
GLint x, GLint y,
|
||||||
|
GLsizei width, GLsizei height,
|
||||||
|
GLenum format, GLenum type,
|
||||||
|
const struct gl_pixelstore_attrib *pack,
|
||||||
|
GLvoid *dest)
|
||||||
|
{
|
||||||
|
void *buf;
|
||||||
|
|
||||||
|
if (pack->BufferObj->Name) {
|
||||||
|
/* pack into PBO */
|
||||||
|
if (!_mesa_validate_pbo_access(2, pack, width, height, 1,
|
||||||
|
format, type, dest)) {
|
||||||
|
_mesa_error(ctx, GL_INVALID_OPERATION,
|
||||||
|
"glReadPixels(invalid PBO access)");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pack->BufferObj->Pointer) {
|
||||||
|
/* buffer is already mapped - that's an error */
|
||||||
|
_mesa_error(ctx, GL_INVALID_OPERATION, "glReadPixels(PBO is mapped)");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
buf = (GLubyte *) ctx->Driver.MapBuffer(ctx, GL_PIXEL_PACK_BUFFER_EXT,
|
||||||
|
GL_WRITE_ONLY_ARB,
|
||||||
|
pack->BufferObj);
|
||||||
|
if (!buf)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
buf = ADD_POINTERS(buf, dest);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
/* pack to normal memory */
|
||||||
|
buf = dest;
|
||||||
|
}
|
||||||
|
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Counterpart to validate_and_map_readpix_pbo()
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
_mesa_unmap_readpix_pbo(GLcontext *ctx,
|
||||||
|
const struct gl_pixelstore_attrib *pack)
|
||||||
|
{
|
||||||
|
if (pack->BufferObj->Name) {
|
||||||
|
ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_PACK_BUFFER_EXT, pack->BufferObj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the gl_buffer_object for the given ID.
|
* Return the gl_buffer_object for the given ID.
|
||||||
* Always return NULL for ID 0.
|
* Always return NULL for ID 0.
|
||||||
|
@@ -1,8 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
* Mesa 3-D graphics library
|
* Mesa 3-D graphics library
|
||||||
* Version: 6.3
|
* Version: 7.1
|
||||||
*
|
*
|
||||||
* Copyright (C) 1999-2004 Brian Paul All Rights Reserved.
|
* Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
* copy of this software and associated documentation files (the "Software"),
|
* copy of this software and associated documentation files (the "Software"),
|
||||||
@@ -86,6 +86,41 @@ _mesa_validate_pbo_access(GLuint dimensions,
|
|||||||
GLsizei width, GLsizei height, GLsizei depth,
|
GLsizei width, GLsizei height, GLsizei depth,
|
||||||
GLenum format, GLenum type, const GLvoid *ptr);
|
GLenum format, GLenum type, const GLvoid *ptr);
|
||||||
|
|
||||||
|
extern const GLubyte *
|
||||||
|
_mesa_validate_and_map_bitmap_pbo(GLcontext *ctx,
|
||||||
|
GLsizei width, GLsizei height,
|
||||||
|
const struct gl_pixelstore_attrib *unpack,
|
||||||
|
const GLubyte *bitmap);
|
||||||
|
|
||||||
|
extern void
|
||||||
|
_mesa_unmap_bitmap_pbo(GLcontext *ctx,
|
||||||
|
const struct gl_pixelstore_attrib *unpack);
|
||||||
|
|
||||||
|
extern const GLvoid *
|
||||||
|
_mesa_validate_and_map_drawpix_pbo(GLcontext *ctx,
|
||||||
|
GLsizei width, GLsizei height,
|
||||||
|
GLenum format, GLenum type,
|
||||||
|
const struct gl_pixelstore_attrib *unpack,
|
||||||
|
const GLvoid *pixels);
|
||||||
|
|
||||||
|
extern void
|
||||||
|
_mesa_unmap_drapix_pbo(GLcontext *ctx,
|
||||||
|
const struct gl_pixelstore_attrib *unpack);
|
||||||
|
|
||||||
|
|
||||||
|
extern void *
|
||||||
|
_mesa_validate_and_map_readpix_pbo(GLcontext *ctx,
|
||||||
|
GLint x, GLint y,
|
||||||
|
GLsizei width, GLsizei height,
|
||||||
|
GLenum format, GLenum type,
|
||||||
|
const struct gl_pixelstore_attrib *pack,
|
||||||
|
GLvoid *dest);
|
||||||
|
|
||||||
|
extern void
|
||||||
|
_mesa_unmap_readpix_pbo(GLcontext *ctx,
|
||||||
|
const struct gl_pixelstore_attrib *pack);
|
||||||
|
|
||||||
|
|
||||||
extern void
|
extern void
|
||||||
_mesa_unbind_buffer_object( GLcontext *ctx, struct gl_buffer_object *bufObj );
|
_mesa_unbind_buffer_object( GLcontext *ctx, struct gl_buffer_object *bufObj );
|
||||||
|
|
||||||
|
@@ -1,8 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
* Mesa 3-D graphics library
|
* Mesa 3-D graphics library
|
||||||
* Version: 6.5.2
|
* Version: 7.1
|
||||||
*
|
*
|
||||||
* Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
|
* Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
* copy of this software and associated documentation files (the "Software"),
|
* copy of this software and associated documentation files (the "Software"),
|
||||||
@@ -57,24 +57,10 @@ _swrast_Bitmap( GLcontext *ctx, GLint px, GLint py,
|
|||||||
|
|
||||||
ASSERT(ctx->RenderMode == GL_RENDER);
|
ASSERT(ctx->RenderMode == GL_RENDER);
|
||||||
|
|
||||||
if (unpack->BufferObj->Name) {
|
bitmap = _mesa_validate_and_map_bitmap_pbo(ctx, width, height,
|
||||||
/* unpack from PBO */
|
unpack, bitmap);
|
||||||
GLubyte *buf;
|
if (!bitmap) {
|
||||||
if (!_mesa_validate_pbo_access(2, unpack, width, height, 1,
|
return NULL;
|
||||||
GL_COLOR_INDEX, GL_BITMAP,
|
|
||||||
(GLvoid *) bitmap)) {
|
|
||||||
_mesa_error(ctx, GL_INVALID_OPERATION,"glBitmap(invalid PBO access)");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
buf = (GLubyte *) ctx->Driver.MapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT,
|
|
||||||
GL_READ_ONLY_ARB,
|
|
||||||
unpack->BufferObj);
|
|
||||||
if (!buf) {
|
|
||||||
/* buffer is already mapped - that's an error */
|
|
||||||
_mesa_error(ctx, GL_INVALID_OPERATION, "glBitmap(PBO is mapped)");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
bitmap = ADD_POINTERS(buf, bitmap);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RENDER_START(swrast,ctx);
|
RENDER_START(swrast,ctx);
|
||||||
@@ -150,11 +136,7 @@ _swrast_Bitmap( GLcontext *ctx, GLint px, GLint py,
|
|||||||
|
|
||||||
RENDER_FINISH(swrast,ctx);
|
RENDER_FINISH(swrast,ctx);
|
||||||
|
|
||||||
if (unpack->BufferObj->Name) {
|
_mesa_unmap_bitmap_pbo(ctx, unpack);
|
||||||
/* done with PBO so unmap it now */
|
|
||||||
ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT,
|
|
||||||
unpack->BufferObj);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -812,7 +812,6 @@ draw_depth_stencil_pixels(GLcontext *ctx, GLint x, GLint y,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute software-based glDrawPixels.
|
* Execute software-based glDrawPixels.
|
||||||
* By time we get here, all error checking will have been done.
|
* By time we get here, all error checking will have been done.
|
||||||
@@ -835,25 +834,10 @@ _swrast_DrawPixels( GLcontext *ctx,
|
|||||||
if (swrast->NewState)
|
if (swrast->NewState)
|
||||||
_swrast_validate_derived( ctx );
|
_swrast_validate_derived( ctx );
|
||||||
|
|
||||||
if (unpack->BufferObj->Name) {
|
pixels = _mesa_validate_and_map_drawpix_pbo(ctx, x, y, width, height,
|
||||||
/* unpack from PBO */
|
format, type, unpack, pixels);
|
||||||
GLubyte *buf;
|
if (!pixels)
|
||||||
if (!_mesa_validate_pbo_access(2, unpack, width, height, 1,
|
return;
|
||||||
format, type, pixels)) {
|
|
||||||
_mesa_error(ctx, GL_INVALID_OPERATION,
|
|
||||||
"glDrawPixels(invalid PBO access)");
|
|
||||||
goto end;
|
|
||||||
}
|
|
||||||
buf = (GLubyte *) ctx->Driver.MapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT,
|
|
||||||
GL_READ_ONLY_ARB,
|
|
||||||
unpack->BufferObj);
|
|
||||||
if (!buf) {
|
|
||||||
/* buffer is already mapped - that's an error */
|
|
||||||
_mesa_error(ctx, GL_INVALID_OPERATION, "glDrawPixels(PBO is mapped)");
|
|
||||||
goto end;
|
|
||||||
}
|
|
||||||
pixels = ADD_POINTERS(buf, pixels);
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (format) {
|
switch (format) {
|
||||||
case GL_STENCIL_INDEX:
|
case GL_STENCIL_INDEX:
|
||||||
@@ -894,11 +878,7 @@ end:
|
|||||||
|
|
||||||
RENDER_FINISH(swrast,ctx);
|
RENDER_FINISH(swrast,ctx);
|
||||||
|
|
||||||
if (unpack->BufferObj->Name) {
|
_mesa_unmap_drapix_pbo(ctx, unpack);
|
||||||
/* done with PBO so unmap it now */
|
|
||||||
ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT,
|
|
||||||
unpack->BufferObj);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -572,25 +572,11 @@ _swrast_ReadPixels( GLcontext *ctx,
|
|||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (clippedPacking.BufferObj->Name) {
|
pixels = _mesa_validate_and_map_readpix_pbo(ctx, x, y, width, height,
|
||||||
/* pack into PBO */
|
format, type,
|
||||||
GLubyte *buf;
|
&clippedPacking, pixels);
|
||||||
if (!_mesa_validate_pbo_access(2, &clippedPacking, width, height, 1,
|
if (!pixels)
|
||||||
format, type, pixels)) {
|
return;
|
||||||
_mesa_error(ctx, GL_INVALID_OPERATION,
|
|
||||||
"glReadPixels(invalid PBO access)");
|
|
||||||
goto end;
|
|
||||||
}
|
|
||||||
buf = (GLubyte *) ctx->Driver.MapBuffer(ctx, GL_PIXEL_PACK_BUFFER_EXT,
|
|
||||||
GL_WRITE_ONLY_ARB,
|
|
||||||
clippedPacking.BufferObj);
|
|
||||||
if (!buf) {
|
|
||||||
/* buffer is already mapped - that's an error */
|
|
||||||
_mesa_error(ctx, GL_INVALID_OPERATION, "glReadPixels(PBO is mapped)");
|
|
||||||
goto end;
|
|
||||||
}
|
|
||||||
pixels = ADD_POINTERS(buf, pixels);
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (format) {
|
switch (format) {
|
||||||
case GL_COLOR_INDEX:
|
case GL_COLOR_INDEX:
|
||||||
@@ -632,9 +618,5 @@ _swrast_ReadPixels( GLcontext *ctx,
|
|||||||
end:
|
end:
|
||||||
RENDER_FINISH(swrast, ctx);
|
RENDER_FINISH(swrast, ctx);
|
||||||
|
|
||||||
if (clippedPacking.BufferObj->Name) {
|
_mesa_unmap_readpix_pbo(ctx, &clippedPacking);
|
||||||
/* done with PBO so unmap it now */
|
|
||||||
ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_PACK_BUFFER_EXT,
|
|
||||||
clippedPacking.BufferObj);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user