⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wmesa.c

📁 Mesa is an open-source implementation of the OpenGL specification - a system for rendering interacti
💻 C
📖 第 1 页 / 共 4 页
字号:
	default:	    break;	}    }    else {        /* front buffer (actual Windows window) */	rb->PutRow = write_rgba_span_front;	rb->PutRowRGB = write_rgb_span_front;	rb->PutMonoRow = write_mono_rgba_span_front;	rb->PutValues = write_rgba_pixels_front;	rb->PutMonoValues = write_mono_rgba_pixels_front;	rb->GetRow = read_rgba_span_front;	rb->GetValues = read_rgba_pixels_front;        rb->RedBits = 8; /* XXX fix these (565?) */        rb->GreenBits = 8;        rb->BlueBits = 8;    }}/** * Called by ctx->Driver.ResizeBuffers() * Resize the front/back colorbuffers to match the latest window size. */static voidwmesa_resize_buffers(GLcontext *ctx, GLframebuffer *buffer,                     GLuint width, GLuint height){    WMesaContext pwc = wmesa_context(ctx);    WMesaFramebuffer pwfb = wmesa_framebuffer(buffer);    if (pwfb->Base.Width != width || pwfb->Base.Height != height) {	/* Realloc back buffer */	if (ctx->Visual.doubleBufferMode == 1) {	    wmDeleteBackingStore(pwfb);	    wmCreateBackingStore(pwfb, width, height);	}    }    _mesa_resize_framebuffer(ctx, buffer, width, height);}/** * Called by glViewport. * This is a good time for us to poll the current window size and adjust * our renderbuffers to match the current window size. * Remember, we have no opportunity to respond to conventional * resize events since the driver has no event loop. * Thus, we poll. * MakeCurrent also ends up making a call here, so that ensures * we get the viewport set correctly, even if the app does not call * glViewport and relies on the defaults. */static void wmesa_viewport(GLcontext *ctx, 			   GLint x, GLint y, 			   GLsizei width, GLsizei height){    WMesaContext pwc = wmesa_context(ctx);    GLuint new_width, new_height;    wmesa_get_buffer_size(ctx->WinSysDrawBuffer, &new_width, &new_height);    /**     * Resize buffers if the window size changed.     */    wmesa_resize_buffers(ctx, ctx->WinSysDrawBuffer, new_width, new_height);    ctx->NewState |= _NEW_BUFFERS;  /* to update scissor / window bounds */}/** * Called when the driver should update it's state, based on the new_state * flags. */static void wmesa_update_state(GLcontext *ctx, GLuint new_state){    _swrast_InvalidateState(ctx, new_state);    _swsetup_InvalidateState(ctx, new_state);    _vbo_InvalidateState(ctx, new_state);    _tnl_InvalidateState(ctx, new_state);    /* TODO - This code is not complete yet because I      * don't know what to do for all state updates.     */    if (new_state & _NEW_BUFFERS) {    }}/**********************************************************************//*****                   WMESA Functions                          *****//**********************************************************************/WMesaContext WMesaCreateContext(HDC hDC, 				HPALETTE* Pal,				GLboolean rgb_flag,				GLboolean db_flag,				GLboolean alpha_flag){    WMesaContext c;    struct dd_function_table functions;    GLint red_bits, green_bits, blue_bits, alpha_bits;    GLcontext *ctx;    GLvisual *visual;    (void) Pal;        /* Indexed mode not supported */    if (!rgb_flag)	return NULL;    /* Allocate wmesa context */    c = CALLOC_STRUCT(wmesa_context);    if (!c)	return NULL;#if 0    /* I do not understand this contributed code */    /* Support memory and device contexts */    if(WindowFromDC(hDC) != NULL) {	c->hDC = GetDC(WindowFromDC(hDC)); /* huh ???? */    }    else {	c->hDC = hDC;    }#else    c->hDC = hDC;#endif    /* Get data for visual */    /* Dealing with this is actually a bit of overkill because Mesa will end     * up treating all color component size requests less than 8 by using      * a single byte per channel.  In addition, the interface to the span     * routines passes colors as an entire byte per channel anyway, so there     * is nothing to be saved by telling the visual to be 16 bits if the device     * is 16 bits.  That is, Mesa is going to compute colors down to 8 bits per     * channel anyway.     * But we go through the motions here anyway.     */    switch (GetDeviceCaps(c->hDC, BITSPIXEL)) {    case 16:	red_bits = green_bits = blue_bits = 5;	alpha_bits = 0;	break;    default:	red_bits = green_bits = blue_bits = 8;	alpha_bits = 8;	break;    }    /* Create visual based on flags */    visual = _mesa_create_visual(rgb_flag,                                 db_flag,    /* db_flag */                                 GL_FALSE,   /* stereo */                                 red_bits, green_bits, blue_bits, /* color RGB */                                 alpha_flag ? alpha_bits : 0, /* color A */                                 0,          /* index bits */                                 DEFAULT_SOFTWARE_DEPTH_BITS, /* depth_bits */                                 8,          /* stencil_bits */                                 16,16,16,   /* accum RGB */                                 alpha_flag ? 16 : 0, /* accum A */                                 1);         /* num samples */        if (!visual) {	_mesa_free(c);	return NULL;    }    /* Set up driver functions */    _mesa_init_driver_functions(&functions);    functions.GetString = wmesa_get_string;    functions.UpdateState = wmesa_update_state;    functions.GetBufferSize = wmesa_get_buffer_size;    functions.Flush = wmesa_flush;    functions.Clear = clear;    functions.ClearIndex = clear_index;    functions.ClearColor = clear_color;    functions.ResizeBuffers = wmesa_resize_buffers;    functions.Viewport = wmesa_viewport;    /* initialize the Mesa context data */    ctx = &c->gl_ctx;    _mesa_initialize_context(ctx, visual, NULL, &functions, (void *)c);    _mesa_enable_sw_extensions(ctx);    _mesa_enable_1_3_extensions(ctx);    _mesa_enable_1_4_extensions(ctx);    _mesa_enable_1_5_extensions(ctx);    _mesa_enable_2_0_extensions(ctx);    _mesa_enable_2_1_extensions(ctx);      /* Initialize the software rasterizer and helper modules. */    if (!_swrast_CreateContext(ctx) ||        !_vbo_CreateContext(ctx) ||        !_tnl_CreateContext(ctx) ||	!_swsetup_CreateContext(ctx)) {	_mesa_free_context_data(ctx);	_mesa_free(c);	return NULL;    }    _swsetup_Wakeup(ctx);    TNL_CONTEXT(ctx)->Driver.RunPipeline = _tnl_run_pipeline;    return c;}void WMesaDestroyContext( WMesaContext pwc ){    GLcontext *ctx = &pwc->gl_ctx;    WMesaFramebuffer pwfb;    GET_CURRENT_CONTEXT(cur_ctx);    if (cur_ctx == ctx) {        /* unbind current if deleting current context */        WMesaMakeCurrent(NULL, NULL);    }    /* clean up frame buffer resources */    pwfb = wmesa_lookup_framebuffer(pwc->hDC);    if (pwfb) {	if (ctx->Visual.doubleBufferMode == 1)	    wmDeleteBackingStore(pwfb);	wmesa_free_framebuffer(pwc->hDC);    }    /* Release for device, not memory contexts */    if (WindowFromDC(pwc->hDC) != NULL)    {      ReleaseDC(WindowFromDC(pwc->hDC), pwc->hDC);    }    DeleteObject(pwc->clearPen);     DeleteObject(pwc->clearBrush);         _swsetup_DestroyContext(ctx);    _tnl_DestroyContext(ctx);    _vbo_DestroyContext(ctx);    _swrast_DestroyContext(ctx);        _mesa_free_context_data(ctx);    _mesa_free(pwc);}/** * Create a new color renderbuffer. */struct gl_renderbuffer *wmesa_new_renderbuffer(void){    struct gl_renderbuffer *rb = CALLOC_STRUCT(gl_renderbuffer);    if (!rb)        return NULL;    _mesa_init_renderbuffer(rb, (GLuint)0);        rb->_BaseFormat = GL_RGBA;    rb->InternalFormat = GL_RGBA;    rb->DataType = CHAN_TYPE;    rb->Delete = wmesa_delete_renderbuffer;    rb->AllocStorage = wmesa_renderbuffer_storage;    return rb;}void WMesaMakeCurrent(WMesaContext c, HDC hdc){    WMesaFramebuffer pwfb;    {        /* return if already current */        GET_CURRENT_CONTEXT(ctx);        WMesaContext pwc = wmesa_context(ctx);        if (pwc && c == pwc && pwc->hDC == hdc)            return;    }    pwfb = wmesa_lookup_framebuffer(hdc);    /* Lazy creation of framebuffers */    if (c && !pwfb && hdc) {        struct gl_renderbuffer *rb;        GLvisual *visual = &c->gl_ctx.Visual;        GLuint width, height;        get_window_size(hdc, &width, &height);	c->clearPen = CreatePen(PS_SOLID, 1, 0); 	c->clearBrush = CreateSolidBrush(0);         pwfb = wmesa_new_framebuffer(hdc, visual);	/* Create back buffer if double buffered */	if (visual->doubleBufferMode == 1) {	    wmCreateBackingStore(pwfb, width, height);	}	        /* make render buffers */        if (visual->doubleBufferMode == 1) {            rb = wmesa_new_renderbuffer();            _mesa_add_renderbuffer(&pwfb->Base, BUFFER_BACK_LEFT, rb);            wmesa_set_renderbuffer_funcs(rb, pwfb->pixelformat, pwfb->cColorBits, 1);	}        rb = wmesa_new_renderbuffer();        _mesa_add_renderbuffer(&pwfb->Base, BUFFER_FRONT_LEFT, rb);        wmesa_set_renderbuffer_funcs(rb, pwfb->pixelformat, pwfb->cColorBits, 0);	/* Let Mesa own the Depth, Stencil, and Accum buffers */        _mesa_add_soft_renderbuffers(&pwfb->Base,                                     GL_FALSE, /* color */                                     visual->depthBits > 0,                                     visual->stencilBits > 0,                                     visual->accumRedBits > 0,                                     visual->alphaBits >0,                                      GL_FALSE);    }    if (c && pwfb)	_mesa_make_current(&c->gl_ctx, &pwfb->Base, &pwfb->Base);    else        _mesa_make_current(NULL, NULL, NULL);}void WMesaSwapBuffers( HDC hdc ){    GET_CURRENT_CONTEXT(ctx);    WMesaContext pwc = wmesa_context(ctx);    WMesaFramebuffer pwfb = wmesa_lookup_framebuffer(hdc);    if (!pwfb) {        _mesa_problem(NULL, "wmesa: swapbuffers on unknown hdc");        return;    }    /* If we're swapping the buffer associated with the current context     * we have to flush any pending rendering commands first.     */    if (pwc->hDC == hdc) {	_mesa_notifySwapBuffers(ctx);	BitBlt(pwfb->hDC, 0, 0, pwfb->Base.Width, pwfb->Base.Height,	       pwfb->dib_hDC, 0, 0, SRCCOPY);    }    else {        /* XXX for now only allow swapping current window */        _mesa_problem(NULL, "wmesa: can't swap non-current window");    }}void WMesaShareLists(WMesaContext ctx_to_share, WMesaContext ctx){	_mesa_share_state(&ctx->gl_ctx, &ctx_to_share->gl_ctx);	}/* This is hopefully a temporary hack to define some needed dispatch * table entries.  Hopefully, I'll find a better solution.  The * dispatch table generation scripts ought to be making these dummy * stubs as well. */#if !defined(__MINGW32__) || !defined(GL_NO_STDCALL)void gl_dispatch_stub_543(void){}void gl_dispatch_stub_544(void){}void gl_dispatch_stub_545(void){}void gl_dispatch_stub_546(void){}void gl_dispatch_stub_547(void){}void gl_dispatch_stub_548(void){}void gl_dispatch_stub_549(void){}void gl_dispatch_stub_550(void){}void gl_dispatch_stub_551(void){}void gl_dispatch_stub_552(void){}void gl_dispatch_stub_553(void){}void gl_dispatch_stub_554(void){}void gl_dispatch_stub_555(void){}void gl_dispatch_stub_556(void){}void gl_dispatch_stub_557(void){}void gl_dispatch_stub_558(void){}void gl_dispatch_stub_559(void){}void gl_dispatch_stub_560(void){}void gl_dispatch_stub_561(void){}void gl_dispatch_stub_565(void){}void gl_dispatch_stub_566(void){}void gl_dispatch_stub_577(void){}void gl_dispatch_stub_578(void){}void gl_dispatch_stub_603(void){}void gl_dispatch_stub_645(void){}void gl_dispatch_stub_646(void){}void gl_dispatch_stub_647(void){}void gl_dispatch_stub_648(void){}void gl_dispatch_stub_649(void){}void gl_dispatch_stub_650(void){}void gl_dispatch_stub_651(void){}void gl_dispatch_stub_652(void){}void gl_dispatch_stub_653(void){}void gl_dispatch_stub_733(void){}void gl_dispatch_stub_734(void){}void gl_dispatch_stub_735(void){}void gl_dispatch_stub_736(void){}void gl_dispatch_stub_737(void){}void gl_dispatch_stub_738(void){}void gl_dispatch_stub_744(void){}void gl_dispatch_stub_745(void){}void gl_dispatch_stub_746(void){}void gl_dispatch_stub_760(void){}void gl_dispatch_stub_761(void){}void gl_dispatch_stub_763(void){}void gl_dispatch_stub_765(void){}void gl_dispatch_stub_766(void){}void gl_dispatch_stub_767(void){}void gl_dispatch_stub_768(void){}void gl_dispatch_stub_562(void){}void gl_dispatch_stub_563(void){}void gl_dispatch_stub_564(void){}void gl_dispatch_stub_567(void){}void gl_dispatch_stub_568(void){}void gl_dispatch_stub_569(void){}void gl_dispatch_stub_580(void){}void gl_dispatch_stub_581(void){}void gl_dispatch_stub_606(void){}void gl_dispatch_stub_654(void){}void gl_dispatch_stub_655(void){}void gl_dispatch_stub_656(void){}void gl_dispatch_stub_739(void){}void gl_dispatch_stub_740(void){}void gl_dispatch_stub_741(void){}void gl_dispatch_stub_748(void){}void gl_dispatch_stub_749(void){}void gl_dispatch_stub_769(void){}void gl_dispatch_stub_770(void){}void gl_dispatch_stub_771(void){}#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -