📄 swrast.c
字号:
xrb->Base.DataType = GL_UNSIGNED_BYTE; xrb->Base.RedBits = 8 * sizeof(GLubyte); xrb->Base.GreenBits = 8 * sizeof(GLubyte); xrb->Base.BlueBits = 8 * sizeof(GLubyte); xrb->Base.AlphaBits = 8 * sizeof(GLubyte); break; case PF_R5G6B5: xrb->Base.InternalFormat = GL_RGB; xrb->Base._BaseFormat = GL_RGB; xrb->Base.DataType = GL_UNSIGNED_BYTE; xrb->Base.RedBits = 5 * sizeof(GLubyte); xrb->Base.GreenBits = 6 * sizeof(GLubyte); xrb->Base.BlueBits = 5 * sizeof(GLubyte); xrb->Base.AlphaBits = 0; break; case PF_R3G3B2: xrb->Base.InternalFormat = GL_RGB; xrb->Base._BaseFormat = GL_RGB; xrb->Base.DataType = GL_UNSIGNED_BYTE; xrb->Base.RedBits = 3 * sizeof(GLubyte); xrb->Base.GreenBits = 3 * sizeof(GLubyte); xrb->Base.BlueBits = 2 * sizeof(GLubyte); xrb->Base.AlphaBits = 0; break; case PF_CI8: xrb->Base.InternalFormat = GL_COLOR_INDEX8_EXT; xrb->Base._BaseFormat = GL_COLOR_INDEX; xrb->Base.DataType = GL_UNSIGNED_BYTE; xrb->Base.IndexBits = 8 * sizeof(GLubyte); break; default: return NULL; } return xrb;}static __DRIdrawable *driCreateNewDrawable(__DRIscreen *screen, const __DRIconfig *config, void *data){ __DRIdrawable *buf; struct swrast_renderbuffer *frontrb, *backrb; TRACE; buf = _mesa_calloc(sizeof *buf); if (!buf) return NULL; buf->loaderPrivate = data; buf->driScreenPriv = screen; buf->row = _mesa_malloc(MAX_WIDTH * 4); /* basic framebuffer setup */ _mesa_initialize_framebuffer(&buf->Base, &config->modes); /* add front renderbuffer */ frontrb = swrast_new_renderbuffer(&config->modes, GL_TRUE); _mesa_add_renderbuffer(&buf->Base, BUFFER_FRONT_LEFT, &frontrb->Base); /* add back renderbuffer */ if (config->modes.doubleBufferMode) { backrb = swrast_new_renderbuffer(&config->modes, GL_FALSE); _mesa_add_renderbuffer(&buf->Base, BUFFER_BACK_LEFT, &backrb->Base); } /* add software renderbuffers */ _mesa_add_soft_renderbuffers(&buf->Base, GL_FALSE, /* color */ config->modes.haveDepthBuffer, config->modes.haveStencilBuffer, config->modes.haveAccumBuffer, GL_FALSE, /* alpha */ GL_FALSE /* aux bufs */); return buf;}static voiddriDestroyDrawable(__DRIdrawable *buf){ TRACE; if (buf) { struct gl_framebuffer *fb = &buf->Base; _mesa_free(buf->row); fb->DeletePending = GL_TRUE; _mesa_unreference_framebuffer(&fb); }}static void driSwapBuffers(__DRIdrawable *buf){ GET_CURRENT_CONTEXT(ctx); struct swrast_renderbuffer *frontrb = swrast_renderbuffer(buf->Base.Attachment[BUFFER_FRONT_LEFT].Renderbuffer); struct swrast_renderbuffer *backrb = swrast_renderbuffer(buf->Base.Attachment[BUFFER_BACK_LEFT].Renderbuffer); __DRIscreen *screen = buf->driScreenPriv; TRACE; /* check for signle-buffered */ if (backrb == NULL) return; /* check if swapping currently bound buffer */ if (ctx && ctx->DrawBuffer == &(buf->Base)) { /* flush pending rendering */ _mesa_notifySwapBuffers(ctx); } screen->swrast_loader->putImage(buf, __DRI_SWRAST_IMAGE_OP_SWAP, 0, 0, frontrb->Base.Width, frontrb->Base.Height, backrb->Base.Data, buf->loaderPrivate);}/** * General device driver functions. */static voidget_window_size( GLframebuffer *fb, GLsizei *w, GLsizei *h ){ __DRIdrawable *buf = swrast_drawable(fb); __DRIscreen *screen = buf->driScreenPriv; int x, y; screen->swrast_loader->getDrawableInfo(buf, &x, &y, w, h, buf->loaderPrivate);}static voidswrast_check_and_update_window_size( GLcontext *ctx, GLframebuffer *fb ){ GLsizei width, height; get_window_size(fb, &width, &height); if (fb->Width != width || fb->Height != height) { _mesa_resize_framebuffer(ctx, fb, width, height); }}static const GLubyte *get_string(GLcontext *ctx, GLenum pname){ (void) ctx; switch (pname) { case GL_VENDOR: return (const GLubyte *) "Mesa Project"; case GL_RENDERER: return (const GLubyte *) "Software Rasterizer"; default: return NULL; }}static voidupdate_state( GLcontext *ctx, GLuint new_state ){ /* not much to do here - pass it on */ _swrast_InvalidateState( ctx, new_state ); _swsetup_InvalidateState( ctx, new_state ); _vbo_InvalidateState( ctx, new_state ); _tnl_InvalidateState( ctx, new_state );}static voidviewport(GLcontext *ctx, GLint x, GLint y, GLsizei w, GLsizei h){ GLframebuffer *draw = ctx->WinSysDrawBuffer; GLframebuffer *read = ctx->WinSysReadBuffer; swrast_check_and_update_window_size(ctx, draw); swrast_check_and_update_window_size(ctx, read);}static voidswrast_init_driver_functions(struct dd_function_table *driver){ driver->GetString = get_string; driver->UpdateState = update_state; driver->GetBufferSize = NULL; driver->Viewport = viewport;}/** * Context-related functions. */static __DRIcontext *driCreateNewContext(__DRIscreen *screen, const __DRIconfig *config, __DRIcontext *shared, void *data){ __DRIcontext *ctx; GLcontext *mesaCtx; struct dd_function_table functions; TRACE; ctx = _mesa_calloc(sizeof *ctx); if (!ctx) return NULL; ctx->loaderPrivate = data; ctx->driScreenPriv = screen; /* build table of device driver functions */ _mesa_init_driver_functions(&functions); swrast_init_driver_functions(&functions); if (!_mesa_initialize_context(&ctx->Base, &config->modes, shared ? &shared->Base : NULL, &functions, (void *) ctx)) { _mesa_free(ctx); return NULL; } mesaCtx = &ctx->Base; /* do bounds checking to prevent segfaults and server crashes! */ mesaCtx->Const.CheckArrayBounds = GL_TRUE; /* create module contexts */ _swrast_CreateContext( mesaCtx ); _vbo_CreateContext( mesaCtx ); _tnl_CreateContext( mesaCtx ); _swsetup_CreateContext( mesaCtx ); _swsetup_Wakeup( mesaCtx ); /* use default TCL pipeline */ { TNLcontext *tnl = TNL_CONTEXT(mesaCtx); tnl->Driver.RunPipeline = _tnl_run_pipeline; } _mesa_enable_sw_extensions(mesaCtx); _mesa_enable_1_3_extensions(mesaCtx); _mesa_enable_1_4_extensions(mesaCtx); _mesa_enable_1_5_extensions(mesaCtx); _mesa_enable_2_0_extensions(mesaCtx); _mesa_enable_2_1_extensions(mesaCtx); return ctx;}static voiddriDestroyContext(__DRIcontext *ctx){ GLcontext *mesaCtx; TRACE; if (ctx) { mesaCtx = &ctx->Base; _swsetup_DestroyContext( mesaCtx ); _swrast_DestroyContext( mesaCtx ); _tnl_DestroyContext( mesaCtx ); _vbo_DestroyContext( mesaCtx ); _mesa_destroy_context( mesaCtx ); }}static intdriCopyContext(__DRIcontext *dst, __DRIcontext *src, unsigned long mask){ TRACE; _mesa_copy_context(&src->Base, &dst->Base, mask); return GL_TRUE;}static int driBindContext(__DRIcontext *ctx, __DRIdrawable *draw, __DRIdrawable *read){ GLcontext *mesaCtx; GLframebuffer *mesaDraw; GLframebuffer *mesaRead; TRACE; if (ctx) { if (!draw || !read) return GL_FALSE; mesaCtx = &ctx->Base; mesaDraw = &draw->Base; mesaRead = &read->Base; /* check for same context and buffer */ if (mesaCtx == _mesa_get_current_context() && mesaCtx->DrawBuffer == mesaDraw && mesaCtx->ReadBuffer == mesaRead) { return GL_TRUE; } _glapi_check_multithread(); swrast_check_and_update_window_size(mesaCtx, mesaDraw); if (read != draw) swrast_check_and_update_window_size(mesaCtx, mesaRead); _mesa_make_current( mesaCtx, mesaDraw, mesaRead ); } else { /* unbind */ _mesa_make_current( NULL, NULL, NULL ); } return GL_TRUE;}static int driUnbindContext(__DRIcontext *ctx){ TRACE; (void) ctx; return GL_TRUE;}static const __DRIcoreExtension driCoreExtension = { { __DRI_CORE, __DRI_CORE_VERSION }, NULL, /* driCreateNewScreen */ driDestroyScreen, driGetExtensions, driGetConfigAttrib, driIndexConfigAttrib, NULL, /* driCreateNewDrawable */ driDestroyDrawable, driSwapBuffers, driCreateNewContext, driCopyContext, driDestroyContext, driBindContext, driUnbindContext};static const __DRIswrastExtension driSWRastExtension = { { __DRI_SWRAST, __DRI_SWRAST_VERSION }, driCreateNewScreen, driCreateNewDrawable};/* This is the table of extensions that the loader will dlsym() for. */PUBLIC const __DRIextension *__driDriverExtensions[] = { &driCoreExtension.base, &driSWRastExtension.base, NULL};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -