📄 renderbuffer.c
字号:
const GLushort val2 = ((const GLushort *) value)[2]; const GLushort val3 = ((const GLushort *) value)[3]; GLushort *dst = (GLushort *) rb->Data + 4 * (y * rb->Width + 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 */ _mesa_bzero(dst, count * 4 * sizeof(GLushort)); } else { GLuint i; for (i = 0; i < count; i++) { if (!mask || mask[i]) { dst[i * 4 + 0] = val0; dst[i * 4 + 1] = val1; dst[i * 4 + 2] = val2; dst[i * 4 + 3] = val3; } } }}static voidput_values_ushort4(GLcontext *ctx, struct gl_renderbuffer *rb, GLuint count, const GLint x[], const GLint y[], const void *values, const GLubyte *mask){ const GLushort *src = (const GLushort *) values; GLuint i; 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]); dst[0] = src[i * 4 + 0]; dst[1] = src[i * 4 + 1]; dst[2] = src[i * 4 + 2]; dst[3] = src[i * 4 + 3]; } }}static voidput_mono_values_ushort4(GLcontext *ctx, struct gl_renderbuffer *rb, GLuint count, const GLint x[], const GLint y[], const void *value, const GLubyte *mask){ const GLushort val0 = ((const GLushort *) value)[0]; const GLushort val1 = ((const GLushort *) value)[1]; const GLushort val2 = ((const GLushort *) value)[2]; const GLushort val3 = ((const GLushort *) value)[3]; GLuint i; 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]); dst[0] = val0; dst[1] = val1; dst[2] = val2; dst[3] = val3; } }}/** * This is a software fallback for the gl_renderbuffer->AllocStorage * function. * Device drivers will typically override this function for the buffers * which it manages (typically color buffers, Z and stencil). * Other buffers (like software accumulation and aux buffers) which the driver * doesn't manage can be handled with this function. * * This one multi-purpose function can allocate stencil, depth, accum, color * or color-index buffers! * * This function also plugs in the appropriate GetPointer, Get/PutRow and * Get/PutValues functions. */GLboolean_mesa_soft_renderbuffer_storage(GLcontext *ctx, struct gl_renderbuffer *rb, GLenum internalFormat, GLuint width, GLuint height){ GLuint pixelSize; /* first clear these fields */ rb->RedBits = rb->GreenBits = rb->BlueBits = rb->AlphaBits = rb->IndexBits = rb->DepthBits = rb->StencilBits = 0; switch (internalFormat) { case GL_RGB: case GL_R3_G3_B2: case GL_RGB4: case GL_RGB5: case GL_RGB8: case GL_RGB10: case GL_RGB12: case GL_RGB16: rb->_ActualFormat = GL_RGB8; rb->_BaseFormat = GL_RGB; rb->DataType = GL_UNSIGNED_BYTE; rb->GetPointer = get_pointer_ubyte3; rb->GetRow = get_row_ubyte3; rb->GetValues = get_values_ubyte3; rb->PutRow = put_row_ubyte3; rb->PutRowRGB = put_row_rgb_ubyte3; rb->PutMonoRow = put_mono_row_ubyte3; rb->PutValues = put_values_ubyte3; rb->PutMonoValues = put_mono_values_ubyte3; rb->RedBits = 8 * sizeof(GLubyte); rb->GreenBits = 8 * sizeof(GLubyte); rb->BlueBits = 8 * sizeof(GLubyte); rb->AlphaBits = 0; pixelSize = 3 * sizeof(GLubyte); break; case GL_RGBA: case GL_RGBA2: case GL_RGBA4: case GL_RGB5_A1: case GL_RGBA8: rb->_ActualFormat = 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->RedBits = 8 * sizeof(GLubyte); rb->GreenBits = 8 * sizeof(GLubyte); rb->BlueBits = 8 * sizeof(GLubyte); rb->AlphaBits = 8 * sizeof(GLubyte); pixelSize = 4 * sizeof(GLubyte); break; case GL_RGB10_A2: case GL_RGBA12: case GL_RGBA16: rb->_ActualFormat = 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->RedBits = 8 * sizeof(GLushort); rb->GreenBits = 8 * sizeof(GLushort); rb->BlueBits = 8 * sizeof(GLushort); rb->AlphaBits = 8 * sizeof(GLushort); pixelSize = 4 * sizeof(GLushort); break;#if 00 case GL_ALPHA8: rb->_ActualFormat = GL_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->RedBits = 0; /*red*/ rb->GreenBits = 0; /*green*/ rb->BlueBits = 0; /*blue*/ rb->AlphaBits = 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->_ActualFormat = 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->StencilBits = 8 * sizeof(GLubyte); pixelSize = sizeof(GLubyte); break; case GL_STENCIL_INDEX16_EXT: rb->_ActualFormat = 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->StencilBits = 8 * sizeof(GLushort); pixelSize = sizeof(GLushort); break; case GL_DEPTH_COMPONENT: case GL_DEPTH_COMPONENT16: rb->_ActualFormat = 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->DepthBits = 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; if (internalFormat == GL_DEPTH_COMPONENT24) { rb->_ActualFormat = GL_DEPTH_COMPONENT24; rb->DepthBits = 24; } else { rb->_ActualFormat = GL_DEPTH_COMPONENT32; rb->DepthBits = 32; } pixelSize = sizeof(GLuint); break; case GL_DEPTH_STENCIL_EXT: case GL_DEPTH24_STENCIL8_EXT: rb->_ActualFormat = GL_DEPTH24_STENCIL8_EXT; rb->_BaseFormat = GL_DEPTH_STENCIL_EXT; rb->DataType = GL_UNSIGNED_INT_24_8_EXT; 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->DepthBits = 24; rb->StencilBits = 8; pixelSize = sizeof(GLuint); break; case GL_COLOR_INDEX8_EXT: rb->_ActualFormat = 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->IndexBits = 8 * sizeof(GLubyte); pixelSize = sizeof(GLubyte); break; case GL_COLOR_INDEX16_EXT: rb->_ActualFormat = 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->IndexBits = 8 * sizeof(GLushort); pixelSize = sizeof(GLushort); break; case COLOR_INDEX32: rb->_ActualFormat = 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->IndexBits = 8 * sizeof(GLuint); pixelSize = sizeof(GLuint); break; default: _mesa_problem(ctx, "Bad internalFormat in _mesa_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); /* free old buffer storage */ if (rb->Data) { _mesa_free(rb->Data); rb->Data = NULL; } if (width > 0 && height > 0) { /* 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 (%d x %d x %d)", width, height, pixelSize); return GL_FALSE; } } rb->Width = width; rb->Height = height; 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 GLbooleanalloc_storage_alpha8(GLcontext *ctx, struct gl_renderbuffer *arb, GLenum internalFormat, GLuint width, GLuint height){ ASSERT(arb != arb->Wrapped); ASSERT(arb->_ActualFormat == GL_ALPHA8); /* 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; return GL_TRUE;}/** * Delete an alpha_renderbuffer object, as well as the wrapped RGB buffer. */static voiddelete_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! */}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -