📄 renderbuffer.c
字号:
} else { rb->_ActualFormat = COLOR_INDEX32; } rb->InternalFormat = rb->_ActualFormat; rb->AllocStorage = _mesa_soft_renderbuffer_storage; _mesa_add_renderbuffer(fb, b, rb); } return GL_TRUE;}/** * Add software-based alpha renderbuffers to the given framebuffer. * This is a helper routine for device drivers when creating a * window system framebuffer (not a user-created render/framebuffer). * Once this function is called, you can basically forget about this * renderbuffer; core Mesa will handle all the buffer management and * rendering! */GLboolean_mesa_add_alpha_renderbuffers(GLcontext *ctx, struct gl_framebuffer *fb, GLuint alphaBits, GLboolean frontLeft, GLboolean backLeft, GLboolean frontRight, GLboolean backRight){ GLuint b; /* for window system framebuffers only! */ assert(fb->Name == 0); if (alphaBits > 8) { _mesa_problem(ctx, "Unsupported bit depth in _mesa_add_alpha_renderbuffers"); return GL_FALSE; } assert(MAX_COLOR_ATTACHMENTS >= 4); /* Wrap each of the RGB color buffers with an alpha renderbuffer. */ for (b = BUFFER_FRONT_LEFT; b <= BUFFER_BACK_RIGHT; b++) { struct gl_renderbuffer *arb; if (b == BUFFER_FRONT_LEFT && !frontLeft) continue; else if (b == BUFFER_BACK_LEFT && !backLeft) continue; else if (b == BUFFER_FRONT_RIGHT && !frontRight) continue; else if (b == BUFFER_BACK_RIGHT && !backRight) continue; /* the RGB buffer to wrap must already exist!! */ assert(fb->Attachment[b].Renderbuffer); /* only GLubyte supported for now */ assert(fb->Attachment[b].Renderbuffer->DataType == GL_UNSIGNED_BYTE); /* allocate alpha renderbuffer */ arb = _mesa_new_renderbuffer(ctx, 0); if (!arb) { _mesa_error(ctx, GL_OUT_OF_MEMORY, "Allocating alpha buffer"); return GL_FALSE; } /* wrap the alpha renderbuffer around the RGB renderbuffer */ arb->Wrapped = fb->Attachment[b].Renderbuffer; /* Set up my alphabuffer fields and plug in my functions. * The functions will put/get the alpha values from/to RGBA arrays * and then call the wrapped buffer's functions to handle the RGB * values. */ arb->InternalFormat = arb->Wrapped->InternalFormat; arb->_ActualFormat = GL_ALPHA8; arb->_BaseFormat = arb->Wrapped->_BaseFormat; arb->DataType = arb->Wrapped->DataType; arb->AllocStorage = alloc_storage_alpha8; arb->Delete = delete_renderbuffer_alpha8; arb->GetPointer = get_pointer_alpha8; arb->GetRow = get_row_alpha8; arb->GetValues = get_values_alpha8; arb->PutRow = put_row_alpha8; arb->PutRowRGB = put_row_rgb_alpha8; arb->PutMonoRow = put_mono_row_alpha8; arb->PutValues = put_values_alpha8; arb->PutMonoValues = put_mono_values_alpha8; /* clear the pointer to avoid assertion/sanity check failure later */ fb->Attachment[b].Renderbuffer = NULL; /* plug the alpha renderbuffer into the colorbuffer attachment */ _mesa_add_renderbuffer(fb, b, arb); } return GL_TRUE;}/** * Add a software-based depth renderbuffer to the given framebuffer. * This is a helper routine for device drivers when creating a * window system framebuffer (not a user-created render/framebuffer). * Once this function is called, you can basically forget about this * renderbuffer; core Mesa will handle all the buffer management and * rendering! */GLboolean_mesa_add_depth_renderbuffer(GLcontext *ctx, struct gl_framebuffer *fb, GLuint depthBits){ struct gl_renderbuffer *rb; if (depthBits > 32) { _mesa_problem(ctx, "Unsupported depthBits in _mesa_add_depth_renderbuffer"); return GL_FALSE; } assert(fb->Attachment[BUFFER_DEPTH].Renderbuffer == NULL); rb = _mesa_new_renderbuffer(ctx, 0); if (!rb) { _mesa_error(ctx, GL_OUT_OF_MEMORY, "Allocating depth buffer"); return GL_FALSE; } if (depthBits <= 16) { rb->_ActualFormat = GL_DEPTH_COMPONENT16; } else if (depthBits <= 24) { rb->_ActualFormat = GL_DEPTH_COMPONENT24; } else { rb->_ActualFormat = GL_DEPTH_COMPONENT32; } rb->InternalFormat = rb->_ActualFormat; rb->AllocStorage = _mesa_soft_renderbuffer_storage; _mesa_add_renderbuffer(fb, BUFFER_DEPTH, rb); return GL_TRUE;}/** * Add a software-based stencil renderbuffer to the given framebuffer. * This is a helper routine for device drivers when creating a * window system framebuffer (not a user-created render/framebuffer). * Once this function is called, you can basically forget about this * renderbuffer; core Mesa will handle all the buffer management and * rendering! */GLboolean_mesa_add_stencil_renderbuffer(GLcontext *ctx, struct gl_framebuffer *fb, GLuint stencilBits){ struct gl_renderbuffer *rb; if (stencilBits > 16) { _mesa_problem(ctx, "Unsupported stencilBits in _mesa_add_stencil_renderbuffer"); return GL_FALSE; } assert(fb->Attachment[BUFFER_STENCIL].Renderbuffer == NULL); rb = _mesa_new_renderbuffer(ctx, 0); if (!rb) { _mesa_error(ctx, GL_OUT_OF_MEMORY, "Allocating stencil buffer"); return GL_FALSE; } if (stencilBits <= 8) { rb->_ActualFormat = GL_STENCIL_INDEX8_EXT; } else { /* not really supported (see s_stencil.c code) */ rb->_ActualFormat = GL_STENCIL_INDEX16_EXT; } rb->InternalFormat = rb->_ActualFormat; rb->AllocStorage = _mesa_soft_renderbuffer_storage; _mesa_add_renderbuffer(fb, BUFFER_STENCIL, rb); return GL_TRUE;}/** * Add a software-based accumulation renderbuffer to the given framebuffer. * This is a helper routine for device drivers when creating a * window system framebuffer (not a user-created render/framebuffer). * Once this function is called, you can basically forget about this * renderbuffer; core Mesa will handle all the buffer management and * rendering! */GLboolean_mesa_add_accum_renderbuffer(GLcontext *ctx, struct gl_framebuffer *fb, GLuint redBits, GLuint greenBits, GLuint blueBits, GLuint alphaBits){ struct gl_renderbuffer *rb; if (redBits > 16 || greenBits > 16 || blueBits > 16 || alphaBits > 16) { _mesa_problem(ctx, "Unsupported accumBits in _mesa_add_accum_renderbuffer"); return GL_FALSE; } assert(fb->Attachment[BUFFER_ACCUM].Renderbuffer == NULL); rb = _mesa_new_renderbuffer(ctx, 0); if (!rb) { _mesa_error(ctx, GL_OUT_OF_MEMORY, "Allocating accum buffer"); return GL_FALSE; } rb->_ActualFormat = GL_RGBA16; rb->InternalFormat = GL_RGBA16; rb->AllocStorage = _mesa_soft_renderbuffer_storage; _mesa_add_renderbuffer(fb, BUFFER_ACCUM, rb); return GL_TRUE;}/** * Add a software-based accumulation renderbuffer to the given framebuffer. * This is a helper routine for device drivers when creating a * window system framebuffer (not a user-created render/framebuffer). * Once this function is called, you can basically forget about this * renderbuffer; core Mesa will handle all the buffer management and * rendering! * * NOTE: color-index aux buffers not supported. */GLboolean_mesa_add_aux_renderbuffers(GLcontext *ctx, struct gl_framebuffer *fb, GLuint colorBits, GLuint numBuffers){ GLuint i; if (colorBits > 16) { _mesa_problem(ctx, "Unsupported accumBits in _mesa_add_aux_renderbuffers"); return GL_FALSE; } assert(numBuffers < MAX_AUX_BUFFERS); for (i = 0; i < numBuffers; i++) { struct gl_renderbuffer *rb = _mesa_new_renderbuffer(ctx, 0); assert(fb->Attachment[BUFFER_AUX0 + i].Renderbuffer == NULL); if (!rb) { _mesa_error(ctx, GL_OUT_OF_MEMORY, "Allocating accum buffer"); return GL_FALSE; } if (colorBits <= 8) { rb->_ActualFormat = GL_RGBA8; } else { rb->_ActualFormat = GL_RGBA16; } rb->InternalFormat = rb->_ActualFormat; rb->AllocStorage = _mesa_soft_renderbuffer_storage; _mesa_add_renderbuffer(fb, BUFFER_AUX0 + i, rb); } return GL_TRUE;}/** * Create/attach software-based renderbuffers to the given framebuffer. * This is a helper routine for device drivers. Drivers can just as well * call the individual _mesa_add_*_renderbuffer() routines directly. */void_mesa_add_soft_renderbuffers(struct gl_framebuffer *fb, GLboolean color, GLboolean depth, GLboolean stencil, GLboolean accum, GLboolean alpha, GLboolean aux){ GLboolean frontLeft = GL_TRUE; GLboolean backLeft = fb->Visual.doubleBufferMode; GLboolean frontRight = fb->Visual.stereoMode; GLboolean backRight = fb->Visual.stereoMode && fb->Visual.doubleBufferMode; if (color) { if (fb->Visual.rgbMode) { assert(fb->Visual.redBits == fb->Visual.greenBits); assert(fb->Visual.redBits == fb->Visual.blueBits); _mesa_add_color_renderbuffers(NULL, fb, fb->Visual.redBits, fb->Visual.alphaBits, frontLeft, backLeft, frontRight, backRight); } else { _mesa_add_color_index_renderbuffers(NULL, fb, fb->Visual.indexBits, frontLeft, backLeft, frontRight, backRight); } } if (depth) { assert(fb->Visual.depthBits > 0); _mesa_add_depth_renderbuffer(NULL, fb, fb->Visual.depthBits); } if (stencil) { assert(fb->Visual.stencilBits > 0); _mesa_add_stencil_renderbuffer(NULL, fb, fb->Visual.stencilBits); } if (accum) { assert(fb->Visual.rgbMode); assert(fb->Visual.accumRedBits > 0); assert(fb->Visual.accumGreenBits > 0); assert(fb->Visual.accumBlueBits > 0); _mesa_add_accum_renderbuffer(NULL, fb, fb->Visual.accumRedBits, fb->Visual.accumGreenBits, fb->Visual.accumBlueBits, fb->Visual.accumAlphaBits); } if (aux) { assert(fb->Visual.rgbMode); assert(fb->Visual.numAuxBuffers > 0); _mesa_add_aux_renderbuffers(NULL, fb, fb->Visual.redBits, fb->Visual.numAuxBuffers); } if (alpha) { assert(fb->Visual.rgbMode); assert(fb->Visual.alphaBits > 0); _mesa_add_alpha_renderbuffers(NULL, fb, fb->Visual.alphaBits, frontLeft, backLeft, frontRight, backRight); }#if 0 if (multisample) { /* maybe someday */ }#endif}/** * Attach a renderbuffer to a framebuffer. */void_mesa_add_renderbuffer(struct gl_framebuffer *fb, GLuint bufferName, struct gl_renderbuffer *rb){ assert(fb); assert(rb);#if 00 /* there should be no previous renderbuffer on this attachment point! */ assert(fb->Attachment[bufferName].Renderbuffer == NULL);#endif assert(bufferName < BUFFER_COUNT); /* winsys vs. user-created buffer cross check */ if (fb->Name) { assert(rb->Name); } else { assert(!rb->Name); } fb->Attachment[bufferName].Type = GL_RENDERBUFFER_EXT; fb->Attachment[bufferName].Complete = GL_TRUE; fb->Attachment[bufferName].Renderbuffer = rb;}/** * Create a new combined depth/stencil renderbuffer for implementing * the GL_EXT_packed_depth_stencil extension. * \return new depth/stencil renderbuffer */struct gl_renderbuffer *_mesa_new_depthstencil_renderbuffer(GLcontext *ctx, GLuint name){ struct gl_renderbuffer *dsrb; dsrb = _mesa_new_renderbuffer(ctx, name); if (!dsrb) return NULL; /* init fields not covered by _mesa_new_renderbuffer() */ dsrb->InternalFormat = GL_DEPTH24_STENCIL8_EXT; dsrb->_ActualFormat = GL_DEPTH24_STENCIL8_EXT; dsrb->AllocStorage = _mesa_soft_renderbuffer_storage; return dsrb;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -