📄 ggimesa.c
字号:
width, height); } ggiSetGCForeground(ggi_ctx->ggi_visual, ggi_ctx->color); mask &= ~(DD_FRONT_LEFT_BIT | DD_BACK_LEFT_BIT); } _swrast_Clear(ctx, mask); }/* Set the buffer used for reading *//* XXX support for separate read/draw buffers hasn't been tested */static GLboolean gl_ggiSetBuffer(GLcontext *ctx, GLframebuffer *buffer, GLuint bufferBit){ ggi_mesa_context_t ggi_ctx = (ggi_mesa_context_t)ctx->DriverCtx; printf("set read %d\n", bufferBit); GGIMESADPRINT_CORE("gl_ggiSetBuffer() called\n"); if (bufferBit == DD_FRONT_LEFT_BIT) { ggiSetReadFrame(ggi_ctx->ggi_visual, ggiGetDisplayFrame(ggi_ctx->ggi_visual)); ggiSetWriteFrame(ggi_ctx->ggi_visual, ggiGetDisplayFrame(ggi_ctx->ggi_visual)); return GL_TRUE; } else if (bufferBit == DD_BACK_LEFT_BIT) { ggiSetReadFrame(ggi_ctx->ggi_visual, ggiGetDisplayFrame(ggi_ctx->ggi_visual)?0 : 1); ggiSetWriteFrame(ggi_ctx->ggi_visual, ggiGetDisplayFrame(ggi_ctx->ggi_visual)?0 : 1); return GL_TRUE; } else return GL_FALSE;}static const GLubyte * gl_ggiGetString(GLcontext *ctx, GLenum name){ GGIMESADPRINT_CORE("gl_ggiGetString() called\n"); if (name == GL_RENDERER) { return (GLubyte *) "Mesa GGI"; } else { return NULL; }}static void gl_ggiFlush(GLcontext *ctx){ ggi_mesa_context_t ggi_ctx = (ggi_mesa_context_t)ctx->DriverCtx; GGIMESADPRINT_CORE("gl_ggiFlush() called\n"); ggiFlush(ggi_ctx->ggi_visual);}static void gl_ggiIndexMask(GLcontext *ctx, GLuint mask){ GGIMESADPRINT_CORE("gl_ggiIndexMask() called\n");}static void gl_ggiColorMask(GLcontext *ctx, GLboolean rmask, GLboolean gmask, GLboolean bmask, GLboolean amask){ GGIMESADPRINT_CORE("gl_ggiColorMask() called\n");}static void gl_ggiEnable(GLcontext *ctx, GLenum pname, GLboolean state){ GGIMESADPRINT_CORE("gl_ggiEnable() called\n");}static void gl_ggiSetupPointers(GLcontext *ctx){ TNLcontext *tnl; GGIMESADPRINT_CORE("gl_ggiSetupPointers() called\n"); /* Plug in default driver functions */ _mesa_init_driver_functions(&ctx->Driver); /* Plug in ggi-specific functions */ ctx->Driver.GetString = gl_ggiGetString; ctx->Driver.GetBufferSize = gl_ggiGetSize; ctx->Driver.Viewport = gl_ggiViewport; ctx->Driver.Finish = gl_ggiFlush; ctx->Driver.Flush = gl_ggiFlush; ctx->Driver.Clear = gl_ggiClear; ctx->Driver.ClearIndex = gl_ggiSetClearIndex; ctx->Driver.ClearColor = gl_ggiSetClearColor; ctx->Driver.IndexMask = gl_ggiIndexMask; ctx->Driver.ColorMask = gl_ggiColorMask; ctx->Driver.Enable = gl_ggiEnable; ctx->Driver.UpdateState = gl_ggiUpdateState; /* Initialize TNL driver interface */ tnl = TNL_CONTEXT(ctx); tnl->Driver.RunPipeline = _tnl_run_pipeline; /* Install setup for tnl */ _swsetup_Wakeup(ctx);}static void get_mode_info(ggi_visual_t vis, int *r, int *g, int *b, GLboolean *rgb, GLboolean *db, int *ci){ unsigned int i; *r = 0; *g = 0; *b = 0; for(i = 0; i < sizeof(ggi_pixel)*8; ++i) { int mask = 1 << i; if (LIBGGI_PIXFMT(vis)->red_mask & mask) ++(*r); if (LIBGGI_PIXFMT(vis)->green_mask & mask) ++(*g); if (LIBGGI_PIXFMT(vis)->blue_mask & mask) ++(*b); } *rgb = GT_SCHEME(LIBGGI_MODE(vis)->graphtype) == GT_TRUECOLOR; *db = LIBGGI_MODE(vis)->frames > 1; *ci = GT_SIZE(LIBGGI_MODE(vis)->graphtype); printf("rgb (%d, %d, %d) db %d, rgb %d ci %d\n",*r,*g,*b,*db,*rgb,*ci);} int ggiMesaAttach(ggi_visual_t vis){ int rc; GGIMESADPRINT_CORE("ggiMesaAttach() called\n"); rc = ggiExtensionAttach(vis, _ggiMesaID); if (rc == 0) { int r, g, b, ci; GLboolean rgb, db; GLvisual *gl_visual; /* We are creating the primary instance */ memset(LIBGGI_MESAEXT(vis), 0, sizeof(struct ggi_mesa_ext)); LIBGGI_MESAEXT(vis)->update_state = (void *)_ggi_error; LIBGGI_MESAEXT(vis)->setup_driver = (void *)_ggi_error; /* Initialize default mesa visual */ get_mode_info(vis, &r, &g, &b, &rgb, &db, &ci); gl_visual = &(LIBGGI_MESAEXT(vis)->mesa_visual.gl_visual); _mesa_initialize_visual(gl_visual, rgb, db, 0 /* No stereo */, r, g, b, 0 /* No alpha */, ci, 0 /* No depth */, 0 /* No stencil */, 0, 0, 0, 0 /* No accum */, 0); /* Now fake an "API change" so the right libs get loaded */ changed(vis, GGI_CHG_APILIST); } return rc;}int ggiMesaDetach(ggi_visual_t vis){ GGIMESADPRINT_CORE("ggiMesaDetach() called\n"); return ggiExtensionDetach(vis, _ggiMesaID);} int ggiMesaExtendVisual(ggi_visual_t vis, GLboolean alpha_flag, GLboolean stereo_flag, GLint depth_size, GLint stencil_size, GLint accum_red_size, GLint accum_green_size, GLint accum_blue_size, GLint accum_alpha_size, GLint num_samples){ GLvisual *gl_vis = &(LIBGGI_MESAEXT(vis)->mesa_visual.gl_visual); int r, g, b, ci; GLboolean db, rgb; get_mode_info(vis, &r, &g, &b, &rgb, &db, &ci); /* Initialize the visual with the provided information */ _mesa_initialize_visual(gl_vis, rgb, db, stereo_flag, r, g, b, 0 /* FIXME */, ci, depth_size, stencil_size, accum_red_size, accum_green_size, accum_blue_size, accum_alpha_size, 0); /* Now fake an "API change" so the right libs get loaded. After all, extending the visual by all these new buffers could be considered a "mode change" which requires an "API change". */ changed(vis, GGI_CHG_APILIST); return 0;}ggi_mesa_context_t ggiMesaCreateContext(ggi_visual_t vis){ ggi_mesa_context_t ctx; int err; GGIMESADPRINT_CORE("ggiMesaCreateContext() called\n"); ctx = (ggi_mesa_context_t)malloc(sizeof(struct ggi_mesa_context)); if (!ctx) return NULL; ctx->ggi_visual = vis; ctx->color = 0; ctx->gl_ctx = _mesa_create_context(&(LIBGGI_MESAEXT(vis)->mesa_visual.gl_visual), NULL, (void *) ctx, GL_FALSE); if (!ctx->gl_ctx) goto free_context; _mesa_enable_sw_extensions(ctx->gl_ctx); _swrast_CreateContext(ctx->gl_ctx); _vbo_CreateContext(ctx->gl_ctx); _tnl_CreateContext(ctx->gl_ctx); _swsetup_CreateContext(ctx->gl_ctx); gl_ggiSetupPointers(ctx->gl_ctx); /* Make sure that an appropriate sublib has been loaded */ if (!LIBGGI_MESAEXT(ctx->ggi_visual)->setup_driver){ GGIMESADPRINT_CORE("setup_driver==NULL!\n"); GGIMESADPRINT_CORE("Please check your config files!\n"); goto free_context; } /* Set up the sublib driver */ err = LIBGGI_MESAEXT(ctx->ggi_visual)->setup_driver(ctx); if (err){ GGIMESADPRINT_CORE("setup_driver failed (err = %d)", err); goto free_gl_context; } return ctx; free_gl_context: _mesa_destroy_context(ctx->gl_ctx);free_context: free(ctx); return NULL;}void ggiMesaDestroyContext(ggi_mesa_context_t ctx){ GGIMESADPRINT_CORE("ggiMesaDestroyContext() called\n"); if(!ctx) return; _mesa_destroy_context(ctx->gl_ctx); free(ctx);}void ggiMesaMakeCurrent(ggi_mesa_context_t ctx, ggi_visual_t vis){ GGIMESADPRINT_CORE("ggiMesaMakeCurrent(ctx = %p) called\n", ctx); /* FIXME: clean up where are ggi_vis */ if (ctx->ggi_visual != vis) { GGIMESADPRINT_CORE("Cannot migrate GL contexts\n"); return; } _mesa_make_current(ctx->gl_ctx, &LIBGGI_MESAEXT(vis)->mesa_buffer);}/* * Swap front/back buffers for current context if double buffered. */void ggiMesaSwapBuffers(void){ GLcontext *ctx; ggi_mesa_context_t ggi_ctx; ctx = _mesa_get_current_context(); ggi_ctx = (ggi_mesa_context_t)ctx->DriverCtx; GGIMESADPRINT_CORE("ggiMesaSwapBuffers() called\n"); _mesa_notifySwapBuffers(ctx); gl_ggiFlush(ctx); ggiSetDisplayFrame(ggi_ctx->ggi_visual, !ggiGetDisplayFrame(ggi_ctx->ggi_visual)); ggiSetWriteFrame(ggi_ctx->ggi_visual, !ggiGetWriteFrame(ggi_ctx->ggi_visual)); ggiSetReadFrame(ggi_ctx->ggi_visual, !ggiGetReadFrame(ggi_ctx->ggi_visual)); GGIMESADPRINT_CORE("swap disp: %d, write %d\n", ggiGetDisplayFrame(ggi_ctx->ggi_visual), ggiGetWriteFrame(ggi_ctx->ggi_visual));}static void gl_ggiUpdateState(GLcontext *ctx, GLuint new_state){ ggi_mesa_context_t ggi_ctx = (ggi_mesa_context_t)ctx->DriverCtx; GGIMESADPRINT_CORE("gl_ggiUpdateState() called\n"); /* Propogate statechange information to swrast and swrast_setup * modules. The GGI driver has no internal GL-dependent state. */ _swrast_InvalidateState(ctx, new_state); _swsetup_InvalidateState(ctx, new_state); _tnl_InvalidateState(ctx, new_state); /* XXX: Better use an assertion that bails out here on failure */ if (!LIBGGI_MESAEXT(ggi_ctx->ggi_visual)->update_state) { GGIMESADPRINT_CORE("update_state == NULL!\n"); GGIMESADPRINT_CORE("Please check your config files!\n"); ggiPanic(""); } LIBGGI_MESAEXT(ggi_ctx->ggi_visual)->update_state(ggi_ctx);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -