📄 renderbuffer.c
字号:
case GL_RGBA:
case GL_RGBA2:
case GL_RGBA4:
case GL_RGB5_A1:
case GL_RGBA8:
rb->_BaseFormat = GL_RGBA;
rb->DataType = GL_UNSIGNED_BYTE;
rb->GetPointer = get_pointer_ubyte4;
rb->GetRow = get_row_ubyte4;
rb->GetValues = get_values_ubyte4;
rb->PutRow = put_row_ubyte4;
rb->PutRowRGB = put_row_rgb_ubyte4;
rb->PutMonoRow = put_mono_row_ubyte4;
rb->PutValues = put_values_ubyte4;
rb->PutMonoValues = put_mono_values_ubyte4;
rb->ComponentSizes[0] = 8 * sizeof(GLubyte);
rb->ComponentSizes[1] = 8 * sizeof(GLubyte);
rb->ComponentSizes[2] = 8 * sizeof(GLubyte);
rb->ComponentSizes[3] = 8 * sizeof(GLubyte);
pixelSize = 4 * sizeof(GLubyte);
break;
case GL_RGB10_A2:
case GL_RGBA12:
case GL_RGBA16:
rb->_BaseFormat = GL_RGBA;
rb->DataType = GL_UNSIGNED_SHORT;
rb->GetPointer = get_pointer_ushort4;
rb->GetRow = get_row_ushort4;
rb->GetValues = get_values_ushort4;
rb->PutRow = put_row_ushort4;
rb->PutRowRGB = put_row_rgb_ushort4;
rb->PutMonoRow = put_mono_row_ushort4;
rb->PutValues = put_values_ushort4;
rb->PutMonoValues = put_mono_values_ushort4;
rb->ComponentSizes[0] = 8 * sizeof(GLushort);
rb->ComponentSizes[1] = 8 * sizeof(GLushort);
rb->ComponentSizes[2] = 8 * sizeof(GLushort);
rb->ComponentSizes[3] = 8 * sizeof(GLushort);
pixelSize = 4 * sizeof(GLushort);
break;
#if 00
case ALPHA8:
rb->_BaseFormat = GL_RGBA; /* Yes, not GL_ALPHA! */
rb->DataType = GL_UNSIGNED_BYTE;
rb->GetPointer = get_pointer_alpha8;
rb->GetRow = get_row_alpha8;
rb->GetValues = get_values_alpha8;
rb->PutRow = put_row_alpha8;
rb->PutRowRGB = NULL;
rb->PutMonoRow = put_mono_row_alpha8;
rb->PutValues = put_values_alpha8;
rb->PutMonoValues = put_mono_values_alpha8;
rb->ComponentSizes[0] = 0; /*red*/
rb->ComponentSizes[1] = 0; /*green*/
rb->ComponentSizes[2] = 0; /*blue*/
rb->ComponentSizes[3] = 8 * sizeof(GLubyte);
pixelSize = sizeof(GLubyte);
break;
#endif
case GL_STENCIL_INDEX:
case GL_STENCIL_INDEX1_EXT:
case GL_STENCIL_INDEX4_EXT:
case GL_STENCIL_INDEX8_EXT:
rb->_BaseFormat = GL_STENCIL_INDEX;
rb->DataType = GL_UNSIGNED_BYTE;
rb->GetPointer = get_pointer_ubyte;
rb->GetRow = get_row_ubyte;
rb->GetValues = get_values_ubyte;
rb->PutRow = put_row_ubyte;
rb->PutRowRGB = NULL;
rb->PutMonoRow = put_mono_row_ubyte;
rb->PutValues = put_values_ubyte;
rb->PutMonoValues = put_mono_values_ubyte;
rb->ComponentSizes[0] = 8 * sizeof(GLubyte);
pixelSize = sizeof(GLubyte);
break;
case GL_STENCIL_INDEX16_EXT:
rb->_BaseFormat = GL_STENCIL_INDEX;
rb->DataType = GL_UNSIGNED_SHORT;
rb->GetPointer = get_pointer_ushort;
rb->GetRow = get_row_ushort;
rb->GetValues = get_values_ushort;
rb->PutRow = put_row_ushort;
rb->PutRowRGB = NULL;
rb->PutMonoRow = put_mono_row_ushort;
rb->PutValues = put_values_ushort;
rb->PutMonoValues = put_mono_values_ushort;
rb->ComponentSizes[0] = 8 * sizeof(GLushort);
pixelSize = sizeof(GLushort);
break;
case GL_DEPTH_COMPONENT:
case GL_DEPTH_COMPONENT16:
rb->_BaseFormat = GL_DEPTH_COMPONENT;
rb->DataType = GL_UNSIGNED_SHORT;
rb->GetPointer = get_pointer_ushort;
rb->GetRow = get_row_ushort;
rb->GetValues = get_values_ushort;
rb->PutRow = put_row_ushort;
rb->PutRowRGB = NULL;
rb->PutMonoRow = put_mono_row_ushort;
rb->PutValues = put_values_ushort;
rb->PutMonoValues = put_mono_values_ushort;
rb->ComponentSizes[0] = 8 * sizeof(GLushort);
pixelSize = sizeof(GLushort);
break;
case GL_DEPTH_COMPONENT24:
case GL_DEPTH_COMPONENT32:
rb->_BaseFormat = GL_DEPTH_COMPONENT;
rb->DataType = GL_UNSIGNED_INT;
rb->GetPointer = get_pointer_uint;
rb->GetRow = get_row_uint;
rb->GetValues = get_values_uint;
rb->PutRow = put_row_uint;
rb->PutRowRGB = NULL;
rb->PutMonoRow = put_mono_row_uint;
rb->PutValues = put_values_uint;
rb->PutMonoValues = put_mono_values_uint;
rb->ComponentSizes[0] = 8 * sizeof(GLuint);
pixelSize = sizeof(GLuint);
break;
case GL_COLOR_INDEX8_EXT:
rb->_BaseFormat = GL_COLOR_INDEX;
rb->DataType = GL_UNSIGNED_BYTE;
rb->GetPointer = get_pointer_ubyte;
rb->GetRow = get_row_ubyte;
rb->GetValues = get_values_ubyte;
rb->PutRow = put_row_ubyte;
rb->PutRowRGB = NULL;
rb->PutMonoRow = put_mono_row_ubyte;
rb->PutValues = put_values_ubyte;
rb->PutMonoValues = put_mono_values_ubyte;
rb->ComponentSizes[0] = 8 * sizeof(GLubyte);
pixelSize = sizeof(GLubyte);
break;
case GL_COLOR_INDEX16_EXT:
rb->_BaseFormat = GL_COLOR_INDEX;
rb->DataType = GL_UNSIGNED_SHORT;
rb->GetPointer = get_pointer_ushort;
rb->GetRow = get_row_ushort;
rb->GetValues = get_values_ushort;
rb->PutRow = put_row_ushort;
rb->PutRowRGB = NULL;
rb->PutMonoRow = put_mono_row_ushort;
rb->PutValues = put_values_ushort;
rb->PutMonoValues = put_mono_values_ushort;
rb->ComponentSizes[0] = 8 * sizeof(GLushort);
pixelSize = sizeof(GLushort);
break;
case COLOR_INDEX32:
rb->_BaseFormat = GL_COLOR_INDEX;
rb->DataType = GL_UNSIGNED_INT;
rb->GetPointer = get_pointer_uint;
rb->GetRow = get_row_uint;
rb->GetValues = get_values_uint;
rb->PutRow = put_row_uint;
rb->PutRowRGB = NULL;
rb->PutMonoRow = put_mono_row_uint;
rb->PutValues = put_values_uint;
rb->PutMonoValues = put_mono_values_uint;
rb->ComponentSizes[0] = 8 * sizeof(GLuint);
pixelSize = sizeof(GLuint);
break;
default:
_mesa_problem(ctx, "Bad internalFormat in soft_renderbuffer_storage");
return GL_FALSE;
}
ASSERT(rb->DataType);
ASSERT(rb->GetPointer);
ASSERT(rb->GetRow);
ASSERT(rb->GetValues);
ASSERT(rb->PutRow);
ASSERT(rb->PutMonoRow);
ASSERT(rb->PutValues);
ASSERT(rb->PutMonoValues);
ASSERT(rb->ComponentSizes[0] > 0);
/* free old buffer storage */
if (rb->Data)
_mesa_free(rb->Data);
/* allocate new buffer storage */
rb->Data = _mesa_malloc(width * height * pixelSize);
if (rb->Data == NULL) {
rb->Width = 0;
rb->Height = 0;
_mesa_error(ctx, GL_OUT_OF_MEMORY, "software renderbuffer allocation");
return GL_FALSE;
}
rb->Width = width;
rb->Height = height;
rb->InternalFormat = internalFormat;
return GL_TRUE;
}
/**********************************************************************/
/**********************************************************************/
/**********************************************************************/
/**
* Here we utilize the gl_renderbuffer->Wrapper field to put an alpha
* buffer wrapper around an existing RGB renderbuffer (hw or sw).
*
* When PutRow is called (for example), we store the alpha values in
* this buffer, then pass on the PutRow call to the wrapped RGB
* buffer.
*/
static GLboolean
alloc_storage_alpha8(GLcontext *ctx, struct gl_renderbuffer *arb,
GLenum internalFormat, GLuint width, GLuint height)
{
ASSERT(arb != arb->Wrapped);
/* first, pass the call to the wrapped RGB buffer */
if (!arb->Wrapped->AllocStorage(ctx, arb->Wrapped, internalFormat,
width, height)) {
return GL_FALSE;
}
/* next, resize my alpha buffer */
if (arb->Data) {
_mesa_free(arb->Data);
}
arb->Data = _mesa_malloc(width * height * sizeof(GLubyte));
if (arb->Data == NULL) {
arb->Width = 0;
arb->Height = 0;
_mesa_error(ctx, GL_OUT_OF_MEMORY, "software alpha buffer allocation");
return GL_FALSE;
}
arb->Width = width;
arb->Height = height;
arb->InternalFormat = internalFormat;
return GL_TRUE;
}
/**
* Delete an alpha_renderbuffer object, as well as the wrapped RGB buffer.
*/
static void
delete_renderbuffer_alpha8(struct gl_renderbuffer *arb)
{
if (arb->Data) {
_mesa_free(arb->Data);
}
ASSERT(arb->Wrapped);
ASSERT(arb != arb->Wrapped);
arb->Wrapped->Delete(arb->Wrapped);
arb->Wrapped = NULL;
_mesa_free(arb);
}
static void *
get_pointer_alpha8(GLcontext *ctx, struct gl_renderbuffer *arb,
GLint x, GLint y)
{
return NULL; /* don't allow direct access! */
}
static void
get_row_alpha8(GLcontext *ctx, struct gl_renderbuffer *arb, GLuint count,
GLint x, GLint y, void *values)
{
/* NOTE: 'values' is RGBA format! */
const GLubyte *src = (const GLubyte *) arb->Data + y * arb->Width + x;
GLubyte *dst = (GLubyte *) values;
GLuint i;
ASSERT(arb != arb->Wrapped);
ASSERT(arb->DataType == GL_UNSIGNED_BYTE);
/* first, pass the call to the wrapped RGB buffer */
arb->Wrapped->GetRow(ctx, arb->Wrapped, count, x, y, values);
/* second, fill in alpha values from this buffer! */
for (i = 0; i < count; i++) {
dst[i * 4 + 3] = src[i];
}
}
static void
get_values_alpha8(GLcontext *ctx, struct gl_renderbuffer *arb, GLuint count,
const GLint x[], const GLint y[], void *values)
{
GLubyte *dst = (GLubyte *) values;
GLuint i;
ASSERT(arb != arb->Wrapped);
ASSERT(arb->DataType == GL_UNSIGNED_BYTE);
/* first, pass the call to the wrapped RGB buffer */
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];
dst[i * 4 + 3] = *src;
}
}
static void
put_row_alpha8(GLcontext *ctx, struct gl_renderbuffer *arb, GLuint count,
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;
GLuint i;
ASSERT(arb != arb->Wrapped);
ASSERT(arb->DataType == GL_UNSIGNED_BYTE);
/* first, pass the call to the wrapped RGB buffer */
arb->Wrapped->PutRow(ctx, arb->Wrapped, count, x, y, values, mask);
/* second, store alpha in our buffer */
for (i = 0; i < count; i++) {
if (!mask || mask[i]) {
dst[i] = src[i * 4 + 3];
}
}
}
static void
put_row_rgb_alpha8(GLcontext *ctx, struct gl_renderbuffer *arb, GLuint count,
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;
GLuint i;
ASSERT(arb != arb->Wrapped);
ASSERT(arb->DataType == GL_UNSIGNED_BYTE);
/* first, pass the call to the wrapped RGB buffer */
arb->Wrapped->PutRowRGB(ctx, arb->Wrapped, count, x, y, values, mask);
/* second, store alpha in our buffer */
for (i = 0; i < count; i++) {
if (!mask || mask[i]) {
dst[i] = src[i * 4 + 3];
}
}
}
static void
put_mono_row_alpha8(GLcontext *ctx, struct gl_renderbuffer *arb, GLuint count,
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;
ASSERT(arb != arb->Wrapped);
ASSERT(arb->DataType == GL_UNSIGNED_BYTE);
/* first, pass the call to the wrapped RGB buffer */
arb->Wrapped->PutMonoRow(ctx, arb->Wrapped, count, x, y, value, mask);
/* second, store alpha in our buffer */
if (mask) {
GLuint i;
for (i = 0; i < count; i++) {
if (mask[i]) {
dst[i] = val;
}
}
}
else {
_mesa_memset(dst, val, count);
}
}
static void
put_values_alpha8(GLcontext *ctx, struct gl_renderbuffer *arb, GLuint count,
const GLint x[], const GLint y[],
const void *values, const GLubyte *mask)
{
const GLubyte *src = (const GLubyte *) values;
GLuint i;
ASSERT(arb != arb->Wrapped);
ASSERT(arb->DataType == GL_UNSIGNED_BYTE);
/* first, pass the call to the wrapped RGB buffer */
arb->Wrapped->PutValues(ctx, arb->Wrapped, count, x, y, values, mask);
/* 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];
*dst = src[i * 4 + 3];
}
}
}
static void
put_mono_values_alpha8(GLcontext *ctx, struct gl_renderbuffer *arb,
GLuint count, const GLint x[], const GLint y[],
const void *value, const GLubyte *mask)
{
const GLubyte val = ((const GLubyte *) value)[3];
GLuint i;
ASSERT(arb != arb->Wrapped);
ASSERT(arb->DataType == GL_UNSIGNED_BYTE);
/* first, pass the call to the wrapped RGB buffer */
arb->Wrapped->PutValues(ctx, arb->Wrapped, count, x, y, value, mask);
/* 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];
*dst = val;
}
}
}
/**********************************************************************/
/**********************************************************************/
/**********************************************************************/
/**
* Default GetPointer routine. Always return NULL to indicate that
* direct buffer access is not supported.
*/
static void *
nop_get_pointer(GLcontext *ctx, struct gl_renderbuffer *rb, GLint x, GLint y)
{
return NULL;
}
/**
* Initialize the fields of a gl_renderbuffer to default values.
*/
void
_mesa_init_renderbuffer(struct gl_renderbuffer *rb, GLuint name)
{
rb->Name = name;
rb->RefCount = 1;
rb->Delete = _mesa_delete_renderbuffer;
/* The rest of these should be set later by the caller of this function or
* the AllocStorage method:
*/
rb->AllocStorage = NULL;
rb->Width = 0;
rb->Height = 0;
rb->InternalFormat = GL_NONE;
rb->_BaseFormat = GL_NONE;
rb->DataType = GL_NONE;
rb->ComponentSizes[0] = 0;
rb->ComponentSizes[1] = 0;
rb->ComponentSizes[2] = 0;
rb->ComponentSizes[3] = 0;
rb->Data = NULL;
/* Point back to ourself so that we don't have to check for Wrapped==NULL
* all over the drivers.
*/
rb->Wrapped = rb;
rb->GetPointer = nop_get_pointer;
rb->GetRow = NULL;
rb->GetValues = NULL;
rb->PutRow = NULL;
rb->PutRowRGB = NULL;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -