static void sw_MapRenderbuffer(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint x, GLuint y, GLuint w, GLuint h, GLbitfield mode, GLubyte **mapOut, GLint *rowStrideOut) { if(rb->ClassID == SW_FRONT_RENDERBUFFER_CLASS) { /* This is our front buffer */ struct sw_front_renderbuffer* srb = (struct sw_front_renderbuffer*)rb; struct sw_framebuffer* fb = CONTAINING_RECORD(srb, struct sw_framebuffer, frontbuffer); /* Set the stride */ *rowStrideOut = WIDTH_BYTES_ALIGN32(rb->Width, pixel_formats[fb->format_index].color_bits); /* Remember where we "mapped" */ srb->x = x; srb->y = y; srb->w = w; srb->h = h; /* Remember if we should write it later */ srb->write = !!(mode & GL_MAP_WRITE_BIT); /* Get the bits, if needed */ if(mode & GL_MAP_READ_BIT) { BitBlt(srb->hdcmem, srb->x, srb->y, srb->w, srb->h, IntGetCurrentDC(), srb->x, srb->y, SRCCOPY); } /* And return it */ *mapOut = (BYTE*)srb->swrast.Buffer + *rowStrideOut*y + x*pixel_formats[fb->format_index].color_bits/8; return; } if(rb->ClassID == SW_BACK_RENDERBUFFER_CLASS) { /* This is our front buffer */ struct swrast_renderbuffer* srb = (struct swrast_renderbuffer*)rb; const GLuint bpp = _mesa_get_format_bytes(rb->Format); /* Set the stride */ *rowStrideOut = srb->RowStride; *mapOut = (BYTE*)srb->Buffer + srb->RowStride*y + x*bpp; return; } /* Let mesa rasterizer take care of this */ _swrast_map_soft_renderbuffer(ctx, rb, x, y, w, h, mode, mapOut, rowStrideOut); }
static GLboolean sw_fb_renderbuffer_storage(struct gl_context *ctx, struct gl_renderbuffer *rb, GLenum internalFormat, GLuint width, GLuint height) { struct sw_front_renderbuffer* srb = (struct sw_front_renderbuffer*)rb; struct sw_framebuffer* fb = CONTAINING_RECORD(srb, struct sw_framebuffer, frontbuffer); HDC hdc = IntGetCurrentDC(); /* Don't bother if the size doesn't change */ if(rb->Width == width && rb->Height == height) return GL_TRUE; /* Delete every objects which could have been used before */ sw_fb_renderbuffer_delete(&srb->swrast.Base); /* So the app wants to use the frontbuffer, allocate a DIB for it */ srb->hbmp = CreateDIBSection( hdc, &fb->bmi, DIB_RGB_COLORS, (void**)&srb->swrast.Buffer, NULL, 0); if(!srb->hbmp) { ERR("Failed to create the DIB section for the front buffer, %lu.\n", GetLastError()); return GL_FALSE; } /* Create the DC and attach the DIB section to it */ srb->hdcmem = CreateCompatibleDC(hdc); assert(srb->hdcmem != NULL); srb->hbmp = SelectObject(srb->hdcmem, srb->hbmp); assert(srb->hbmp != NULL); /* Set formats, width and height */ srb->swrast.Base.Format = pixel_formats[fb->format_index].mesa; srb->swrast.Base.Width = width; srb->swrast.Base.Height = height; return GL_TRUE; }
static void sw_UnmapRenderbuffer(struct gl_context *ctx, struct gl_renderbuffer *rb) { if (rb->ClassID== SW_FRONT_RENDERBUFFER_CLASS) { /* This is our front buffer */ struct sw_front_renderbuffer* srb = (struct sw_front_renderbuffer*)rb; if(srb->write) { /* Copy the bits to our display */ BitBlt(IntGetCurrentDC(), srb->x, srb->y, srb->w, srb->h, srb->hdcmem, srb->x, srb->y, SRCCOPY); srb->write = FALSE; } return; } if(rb->ClassID == SW_BACK_RENDERBUFFER_CLASS) return; /* nothing to do */ /* Let mesa rasterizer take care of this */ _swrast_unmap_soft_renderbuffer(ctx, rb); }
HDC WINAPI wglGetCurrentDC(void) { return IntGetCurrentDC(); }