/*
* Routines for get/put values in common buffer formats follow.
- * Someday add support for arbitrary row stride to make them more
- * flexible.
*/
/**********************************************************************
/* Can't assert rb->Format since these funcs may be used for serveral
* different formats (GL_ALPHA8, GL_STENCIL_INDEX8, etc).
*/
- return (GLubyte *) rb->Data + y * rb->Width + x;
+ return (GLubyte *) rb->Data + y * rb->RowStride + x;
}
get_row_ubyte(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
GLint x, GLint y, void *values)
{
- const GLubyte *src = (const GLubyte *) rb->Data + y * rb->Width + x;
+ const GLubyte *src = (const GLubyte *) rb->Data + y * rb->RowStride + x;
ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
memcpy(values, src, count * sizeof(GLubyte));
}
GLuint i;
ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
for (i = 0; i < count; i++) {
- const GLubyte *src = (GLubyte *) rb->Data + y[i] * rb->Width + x[i];
+ const GLubyte *src = (GLubyte *) rb->Data + y[i] * rb->RowStride + x[i];
dst[i] = *src;
}
}
GLint x, GLint y, const void *values, const GLubyte *mask)
{
const GLubyte *src = (const GLubyte *) values;
- GLubyte *dst = (GLubyte *) rb->Data + y * rb->Width + x;
+ GLubyte *dst = (GLubyte *) rb->Data + y * rb->RowStride + x;
ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
if (mask) {
GLuint i;
GLint x, GLint y, const void *value, const GLubyte *mask)
{
const GLubyte val = *((const GLubyte *) value);
- GLubyte *dst = (GLubyte *) rb->Data + y * rb->Width + x;
+ GLubyte *dst = (GLubyte *) rb->Data + y * rb->RowStride + x;
ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
if (mask) {
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->Width + x[i];
+ GLubyte *dst = (GLubyte *) rb->Data + y[i] * rb->RowStride + x[i];
*dst = src[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->Width + x[i];
+ GLubyte *dst = (GLubyte *) rb->Data + y[i] * rb->RowStride + x[i];
*dst = val;
}
}
return NULL;
ASSERT(rb->DataType == GL_UNSIGNED_SHORT);
ASSERT(rb->Width > 0);
- return (GLushort *) rb->Data + y * rb->Width + x;
+ return (GLushort *) rb->Data + y * rb->RowStride + x;
}
GLuint i;
ASSERT(rb->DataType == GL_UNSIGNED_SHORT);
for (i = 0; i < count; i++) {
- const GLushort *src = (GLushort *) rb->Data + y[i] * rb->Width + x[i];
+ const GLushort *src = (GLushort *) rb->Data + y[i] * rb->RowStride + x[i];
dst[i] = *src;
}
}
GLint x, GLint y, const void *values, const GLubyte *mask)
{
const GLushort *src = (const GLushort *) values;
- GLushort *dst = (GLushort *) rb->Data + y * rb->Width + x;
+ GLushort *dst = (GLushort *) rb->Data + y * rb->RowStride + x;
ASSERT(rb->DataType == GL_UNSIGNED_SHORT);
if (mask) {
GLuint i;
GLint x, GLint y, const void *value, const GLubyte *mask)
{
const GLushort val = *((const GLushort *) value);
- GLushort *dst = (GLushort *) rb->Data + y * rb->Width + x;
+ GLushort *dst = (GLushort *) rb->Data + y * rb->RowStride + x;
ASSERT(rb->DataType == GL_UNSIGNED_SHORT);
if (mask) {
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->Width + x[i];
+ GLushort *dst = (GLushort *) rb->Data + y[i] * rb->RowStride + x[i];
*dst = src[i];
}
}
GLuint i;
for (i = 0; i < count; i++) {
if (mask[i]) {
- GLushort *dst = (GLushort *) rb->Data + y[i] * rb->Width + x[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->Width + x[i];
+ GLushort *dst = (GLushort *) rb->Data + y[i] * rb->RowStride + x[i];
*dst = val;
}
}
return NULL;
ASSERT(rb->DataType == GL_UNSIGNED_INT ||
rb->DataType == GL_UNSIGNED_INT_24_8_EXT);
- return (GLuint *) rb->Data + y * rb->Width + x;
+ return (GLuint *) rb->Data + y * rb->RowStride + x;
}
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->Width + x[i];
+ const GLuint *src = (GLuint *) rb->Data + y[i] * rb->RowStride + x[i];
dst[i] = *src;
}
}
GLint x, GLint y, const void *values, const GLubyte *mask)
{
const GLuint *src = (const GLuint *) values;
- GLuint *dst = (GLuint *) rb->Data + y * rb->Width + x;
+ 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) {
GLint x, GLint y, const void *value, const GLubyte *mask)
{
const GLuint val = *((const GLuint *) value);
- GLuint *dst = (GLuint *) rb->Data + y * rb->Width + x;
+ 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) {
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->Width + x[i];
+ GLuint *dst = (GLuint *) rb->Data + y[i] * rb->RowStride + x[i];
*dst = src[i];
}
}
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->Width + x[i];
+ GLuint *dst = (GLuint *) rb->Data + y[i] * rb->RowStride + x[i];
*dst = val;
}
}
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->Width + x);
+ 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++) {
const GLubyte *src
- = (GLubyte *) rb->Data + 3 * (y[i] * rb->Width + x[i]);
+ = (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];
{
/* note: incoming values are RGB+A! */
const GLubyte *src = (const GLubyte *) values;
- GLubyte *dst = (GLubyte *) rb->Data + 3 * (y * rb->Width + x);
+ GLubyte *dst = (GLubyte *) rb->Data + 3 * (y * rb->RowStride + x);
GLuint i;
ASSERT(rb->Format == MESA_FORMAT_RGB888);
ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
{
/* note: incoming values are RGB+A! */
const GLubyte *src = (const GLubyte *) values;
- GLubyte *dst = (GLubyte *) rb->Data + 3 * (y * rb->Width + x);
+ GLubyte *dst = (GLubyte *) rb->Data + 3 * (y * rb->RowStride + x);
GLuint i;
ASSERT(rb->Format == MESA_FORMAT_RGB888);
ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
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->Width + x);
+ 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) {
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->Width + x[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];
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->Width + x[i]);
+ GLubyte *dst = (GLubyte *) (rb->Data +
+ 3 * (y[i] * rb->RowStride + x[i]));
dst[0] = val0;
dst[1] = val1;
dst[2] = val2;
return NULL;
ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
ASSERT(rb->Format == MESA_FORMAT_RGBA8888);
- return (GLubyte *) rb->Data + 4 * (y * rb->Width + x);
+ return (GLubyte *) rb->Data + 4 * (y * rb->RowStride + x);
}
get_row_ubyte4(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
GLint x, GLint y, void *values)
{
- const GLubyte *src = (const GLubyte *) rb->Data + 4 * (y * rb->Width + x);
+ const GLubyte *src = (const GLubyte *) (rb->Data +
+ 4 * (y * rb->RowStride + x));
ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
ASSERT(rb->Format == MESA_FORMAT_RGBA8888);
memcpy(values, src, 4 * count * sizeof(GLubyte));
ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
ASSERT(rb->Format == MESA_FORMAT_RGBA8888);
for (i = 0; i < count; i++) {
- const GLuint *src = (GLuint *) rb->Data + (y[i] * rb->Width + x[i]);
+ const GLuint *src = (GLuint *) rb->Data + (y[i] * rb->RowStride + x[i]);
dst[i] = *src;
}
}
{
/* treat 4*GLubyte as 1*GLuint */
const GLuint *src = (const GLuint *) values;
- GLuint *dst = (GLuint *) rb->Data + (y * rb->Width + x);
+ GLuint *dst = (GLuint *) rb->Data + (y * rb->RowStride + x);
ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
ASSERT(rb->Format == MESA_FORMAT_RGBA8888);
if (mask) {
{
/* Store RGB values in RGBA buffer */
const GLubyte *src = (const GLubyte *) values;
- GLubyte *dst = (GLubyte *) rb->Data + 4 * (y * rb->Width + x);
+ GLubyte *dst = (GLubyte *) rb->Data + 4 * (y * rb->RowStride + x);
GLuint i;
ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
ASSERT(rb->Format == MESA_FORMAT_RGBA8888);
{
/* treat 4*GLubyte as 1*GLuint */
const GLuint val = *((const GLuint *) value);
- GLuint *dst = (GLuint *) rb->Data + (y * rb->Width + x);
+ GLuint *dst = (GLuint *) rb->Data + (y * rb->RowStride + x);
ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
ASSERT(rb->Format == MESA_FORMAT_RGBA8888);
if (!mask && val == 0) {
ASSERT(rb->Format == MESA_FORMAT_RGBA8888);
for (i = 0; i < count; i++) {
if (!mask || mask[i]) {
- GLuint *dst = (GLuint *) rb->Data + (y[i] * rb->Width + x[i]);
+ GLuint *dst = (GLuint *) rb->Data + (y[i] * rb->RowStride + x[i]);
*dst = src[i];
}
}
ASSERT(rb->Format == MESA_FORMAT_RGBA8888);
for (i = 0; i < count; i++) {
if (!mask || mask[i]) {
- GLuint *dst = (GLuint *) rb->Data + (y[i] * rb->Width + x[i]);
+ GLuint *dst = (GLuint *) rb->Data + (y[i] * rb->RowStride + x[i]);
*dst = val;
}
}
if (!rb->Data)
return NULL;
ASSERT(rb->DataType == GL_UNSIGNED_SHORT || rb->DataType == GL_SHORT);
- return (GLushort *) rb->Data + 4 * (y * rb->Width + x);
+ return (GLushort *) rb->Data + 4 * (y * rb->RowStride + x);
}
get_row_ushort4(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
GLint x, GLint y, void *values)
{
- const GLshort *src = (const GLshort *) rb->Data + 4 * (y * rb->Width + x);
+ const GLshort *src = (const GLshort *) (rb->Data +
+ 4 * (y * rb->RowStride + x));
ASSERT(rb->DataType == GL_UNSIGNED_SHORT || rb->DataType == GL_SHORT);
memcpy(values, src, 4 * count * sizeof(GLshort));
}
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->Width + x[i]);
+ = (GLushort *) rb->Data + 4 * (y[i] * rb->RowStride + x[i]);
dst[i] = *src;
}
}
GLint x, GLint y, const void *values, const GLubyte *mask)
{
const GLushort *src = (const GLushort *) values;
- GLushort *dst = (GLushort *) rb->Data + 4 * (y * rb->Width + x);
+ GLushort *dst = (GLushort *) rb->Data + 4 * (y * rb->RowStride + x);
ASSERT(rb->DataType == GL_UNSIGNED_SHORT || rb->DataType == GL_SHORT);
if (mask) {
GLuint i;
{
/* Put RGB values in RGBA buffer */
const GLushort *src = (const GLushort *) values;
- GLushort *dst = (GLushort *) rb->Data + 4 * (y * rb->Width + x);
+ GLushort *dst = (GLushort *) rb->Data + 4 * (y * rb->RowStride + x);
ASSERT(rb->DataType == GL_UNSIGNED_SHORT || rb->DataType == GL_SHORT);
if (mask) {
GLuint i;
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->Width + x);
+ 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 */
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->Width + x[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];
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->Width + x[i]);
+ GLushort *dst = (GLushort *) (rb->Data +
+ 4 * (y[i] * rb->RowStride + x[i]));
dst[0] = val0;
dst[1] = val1;
dst[2] = val2;
rb->Data = NULL;
}
+ rb->RowStride = width;
+
if (width > 0 && height > 0) {
/* allocate new buffer storage */
rb->Data = malloc(width * height * pixelSize);
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, pixelSize);
arb->Width = width;
arb->Height = height;
+ arb->RowStride = width;
return GL_TRUE;
}
GLint x, GLint y, void *values)
{
/* NOTE: 'values' is RGBA format! */
- const GLubyte *src = (const GLubyte *) arb->Data + y * arb->Width + x;
+ const GLubyte *src = (const GLubyte *) arb->Data + y * arb->RowStride + x;
GLubyte *dst = (GLubyte *) values;
GLuint i;
ASSERT(arb != arb->Wrapped);
arb->Wrapped->GetValues(ctx, arb->Wrapped, count, x, y, values);
/* second, fill in alpha values from this buffer! */
for (i = 0; i < count; i++) {
- const GLubyte *src = (GLubyte *) arb->Data + y[i] * arb->Width + x[i];
+ const GLubyte *src = (GLubyte *) arb->Data + y[i] * arb->RowStride + x[i];
dst[i * 4 + 3] = *src;
}
}
GLint x, GLint y, const void *values, const GLubyte *mask)
{
const GLubyte *src = (const GLubyte *) values;
- GLubyte *dst = (GLubyte *) arb->Data + y * arb->Width + x;
+ GLubyte *dst = (GLubyte *) arb->Data + y * arb->RowStride + x;
GLuint i;
ASSERT(arb != arb->Wrapped);
ASSERT(arb->DataType == GL_UNSIGNED_BYTE);
GLint x, GLint y, const void *values, const GLubyte *mask)
{
const GLubyte *src = (const GLubyte *) values;
- GLubyte *dst = (GLubyte *) arb->Data + y * arb->Width + x;
+ GLubyte *dst = (GLubyte *) arb->Data + y * arb->RowStride + x;
GLuint i;
ASSERT(arb != arb->Wrapped);
ASSERT(arb->DataType == GL_UNSIGNED_BYTE);
GLint x, GLint y, const void *value, const GLubyte *mask)
{
const GLubyte val = ((const GLubyte *) value)[3];
- GLubyte *dst = (GLubyte *) arb->Data + y * arb->Width + x;
+ GLubyte *dst = (GLubyte *) arb->Data + y * arb->RowStride + x;
ASSERT(arb != arb->Wrapped);
ASSERT(arb->DataType == GL_UNSIGNED_BYTE);
/* first, pass the call to the wrapped RGB buffer */
/* second, store alpha in our buffer */
for (i = 0; i < count; i++) {
if (!mask || mask[i]) {
- GLubyte *dst = (GLubyte *) arb->Data + y[i] * arb->Width + x[i];
+ GLubyte *dst = (GLubyte *) arb->Data + y[i] * arb->RowStride + x[i];
*dst = src[i * 4 + 3];
}
}
/* second, store alpha in our buffer */
for (i = 0; i < count; i++) {
if (!mask || mask[i]) {
- GLubyte *dst = (GLubyte *) arb->Data + y[i] * arb->Width + x[i];
+ GLubyte *dst = (GLubyte *) arb->Data + y[i] * arb->RowStride + x[i];
*dst = val;
}
}
ASSERT(src->Format == MESA_FORMAT_A8);
ASSERT(dst->Width == src->Width);
ASSERT(dst->Height == src->Height);
+ ASSERT(dst->RowStride == src->RowStride);
- memcpy(dst->Data, src->Data, dst->Width * dst->Height * sizeof(GLubyte));
+ memcpy(dst->Data, src->Data, dst->RowStride * dst->Height * sizeof(GLubyte));
}