📄 wmesa.c
字号:
#undef FLIP} /**********************************************************************//***** PIXEL Functions *****//**********************************************************************/#define FLIP(Y) (rb->Height - (Y) - 1)/** ** Front Buffer reading/writing ** These are slow, but work with all non-indexed visual types. **//* Write a horizontal span of RGBA color pixels with a boolean mask. */static void write_rgba_span_front(const GLcontext *ctx, struct gl_renderbuffer *rb, GLuint n, GLint x, GLint y, const GLubyte rgba[][4], const GLubyte mask[] ){ WMesaContext pwc = wmesa_context(ctx); WMesaFramebuffer pwfb = wmesa_lookup_framebuffer(pwc->hDC); CONST BITMAPINFO bmi= { { sizeof(BITMAPINFOHEADER), n, 1, 1, 32, BI_RGB, 0, 1, 1, 0, 0 } }; HBITMAP bmp=0; HDC mdc=0; typedef union { unsigned i; struct { unsigned b:8, g:8, r:8, a:8; }; } BGRA; BGRA *bgra, c; int i; if (n < 16) { // the value 16 is just guessed y=FLIP(y); if (mask) { for (i=0; i<n; i++) if (mask[i]) SetPixel(pwc->hDC, x+i, y, RGB(rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP])); } else { for (i=0; i<n; i++) SetPixel(pwc->hDC, x+i, y, RGB(rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP])); } } else { if (!pwfb) { _mesa_problem(NULL, "wmesa: write_rgba_span_front on unknown hdc"); return; } bgra=malloc(n*sizeof(BGRA)); if (!bgra) { _mesa_problem(NULL, "wmesa: write_rgba_span_front: out of memory"); return; } c.a=0; if (mask) { for (i=0; i<n; i++) { if (mask[i]) { c.r=rgba[i][RCOMP]; c.g=rgba[i][GCOMP]; c.b=rgba[i][BCOMP]; c.a=rgba[i][ACOMP]; bgra[i]=c; } else bgra[i].i=0; } } else { for (i=0; i<n; i++) { c.r=rgba[i][RCOMP]; c.g=rgba[i][GCOMP]; c.b=rgba[i][BCOMP]; c.a=rgba[i][ACOMP]; bgra[i]=c; } } bmp=CreateBitmap(n, 1, 1, 32, bgra); mdc=CreateCompatibleDC(pwfb->hDC); SelectObject(mdc, bmp); y=FLIP(y); BitBlt(pwfb->hDC, x, y, n, 1, mdc, 0, 0, SRCCOPY); SelectObject(mdc, 0); DeleteObject(bmp); DeleteDC(mdc); free(bgra); }}/* Write a horizontal span of RGB color pixels with a boolean mask. */static void write_rgb_span_front(const GLcontext *ctx, struct gl_renderbuffer *rb, GLuint n, GLint x, GLint y, const GLubyte rgb[][3], const GLubyte mask[] ){ WMesaContext pwc = wmesa_context(ctx); GLuint i; (void) ctx; y=FLIP(y); if (mask) { for (i=0; i<n; i++) if (mask[i]) SetPixel(pwc->hDC, x+i, y, RGB(rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP])); } else { for (i=0; i<n; i++) SetPixel(pwc->hDC, x+i, y, RGB(rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP])); } }/* * Write a horizontal span of pixels with a boolean mask. The current color * is used for all pixels. */static void write_mono_rgba_span_front(const GLcontext *ctx, struct gl_renderbuffer *rb, GLuint n, GLint x, GLint y, const GLchan color[4], const GLubyte mask[]){ GLuint i; WMesaContext pwc = wmesa_context(ctx); COLORREF colorref; (void) ctx; colorref = RGB(color[RCOMP], color[GCOMP], color[BCOMP]); y=FLIP(y); if (mask) { for (i=0; i<n; i++) if (mask[i]) SetPixel(pwc->hDC, x+i, y, colorref); } else for (i=0; i<n; i++) SetPixel(pwc->hDC, x+i, y, colorref);}/* Write an array of RGBA pixels with a boolean mask. */static void write_rgba_pixels_front(const GLcontext *ctx, struct gl_renderbuffer *rb, GLuint n, const GLint x[], const GLint y[], const GLubyte rgba[][4], const GLubyte mask[] ){ GLuint i; WMesaContext pwc = wmesa_context(ctx); (void) ctx; for (i=0; i<n; i++) if (mask[i]) SetPixel(pwc->hDC, x[i], FLIP(y[i]), RGB(rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]));}/* * Write an array of pixels with a boolean mask. The current color * is used for all pixels. */static void write_mono_rgba_pixels_front(const GLcontext *ctx, struct gl_renderbuffer *rb, GLuint n, const GLint x[], const GLint y[], const GLchan color[4], const GLubyte mask[] ){ GLuint i; WMesaContext pwc = wmesa_context(ctx); COLORREF colorref; (void) ctx; colorref = RGB(color[RCOMP], color[GCOMP], color[BCOMP]); for (i=0; i<n; i++) if (mask[i]) SetPixel(pwc->hDC, x[i], FLIP(y[i]), colorref);}/* Read a horizontal span of color pixels. */static void read_rgba_span_front(const GLcontext *ctx, struct gl_renderbuffer *rb, GLuint n, GLint x, GLint y, GLubyte rgba[][4] ){ WMesaContext pwc = wmesa_context(ctx); GLuint i; COLORREF Color; y = FLIP(y); for (i=0; i<n; i++) { Color = GetPixel(pwc->hDC, x+i, y); rgba[i][RCOMP] = GetRValue(Color); rgba[i][GCOMP] = GetGValue(Color); rgba[i][BCOMP] = GetBValue(Color); rgba[i][ACOMP] = 255; }}/* Read an array of color pixels. */static void read_rgba_pixels_front(const GLcontext *ctx, struct gl_renderbuffer *rb, GLuint n, const GLint x[], const GLint y[], GLubyte rgba[][4]){ WMesaContext pwc = wmesa_context(ctx); GLuint i; COLORREF Color; for (i=0; i<n; i++) { GLint y2 = FLIP(y[i]); Color = GetPixel(pwc->hDC, x[i], y2); rgba[i][RCOMP] = GetRValue(Color); rgba[i][GCOMP] = GetGValue(Color); rgba[i][BCOMP] = GetBValue(Color); rgba[i][ACOMP] = 255; }}/*********************************************************************//* DOUBLE BUFFER 32-bit */#define WMSETPIXEL32(pwc, y, x, r, g, b) { \LPDWORD lpdw = ((LPDWORD)((pwc)->pbPixels + (pwc)->ScanWidth * (y)) + (x)); \*lpdw = BGR32((r),(g),(b)); }/* Write a horizontal span of RGBA color pixels with a boolean mask. */static void write_rgba_span_32(const GLcontext *ctx, struct gl_renderbuffer *rb, GLuint n, GLint x, GLint y, const GLubyte rgba[][4], const GLubyte mask[] ){ WMesaContext pwc = wmesa_context(ctx); WMesaFramebuffer pwfb = wmesa_framebuffer(ctx->DrawBuffer); GLuint i; LPDWORD lpdw; (void) ctx; y=FLIP(y); lpdw = ((LPDWORD)(pwfb->pbPixels + pwfb->ScanWidth * y)) + x; if (mask) { for (i=0; i<n; i++) if (mask[i]) lpdw[i] = BGR32(rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]); } else { for (i=0; i<n; i++) *lpdw++ = BGR32(rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]); }}/* Write a horizontal span of RGB color pixels with a boolean mask. */static void write_rgb_span_32(const GLcontext *ctx, struct gl_renderbuffer *rb, GLuint n, GLint x, GLint y, const GLubyte rgb[][3], const GLubyte mask[] ){ WMesaContext pwc = wmesa_context(ctx); WMesaFramebuffer pwfb = wmesa_framebuffer(ctx->DrawBuffer); GLuint i; LPDWORD lpdw; (void) ctx; y=FLIP(y); lpdw = ((LPDWORD)(pwfb->pbPixels + pwfb->ScanWidth * y)) + x; if (mask) { for (i=0; i<n; i++) if (mask[i]) lpdw[i] = BGR32(rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP]); } else { for (i=0; i<n; i++) *lpdw++ = BGR32(rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP]); }}/* * Write a horizontal span of pixels with a boolean mask. The current color * is used for all pixels. */static void write_mono_rgba_span_32(const GLcontext *ctx, struct gl_renderbuffer *rb, GLuint n, GLint x, GLint y, const GLchan color[4], const GLubyte mask[]){ LPDWORD lpdw; DWORD pixel; GLuint i; WMesaContext pwc = wmesa_context(ctx); WMesaFramebuffer pwfb = wmesa_framebuffer(ctx->DrawBuffer); lpdw = ((LPDWORD)(pwfb->pbPixels + pwfb->ScanWidth * y)) + x; y=FLIP(y); pixel = BGR32(color[RCOMP], color[GCOMP], color[BCOMP]); if (mask) { for (i=0; i<n; i++) if (mask[i]) lpdw[i] = pixel; } else for (i=0; i<n; i++) *lpdw++ = pixel;}/* Write an array of RGBA pixels with a boolean mask. */static void write_rgba_pixels_32(const GLcontext *ctx, struct gl_renderbuffer *rb, GLuint n, const GLint x[], const GLint y[], const GLubyte rgba[][4], const GLubyte mask[]){ GLuint i; WMesaContext pwc = wmesa_context(ctx); WMesaFramebuffer pwfb = wmesa_framebuffer(ctx->DrawBuffer); for (i=0; i<n; i++) if (mask[i]) WMSETPIXEL32(pwfb, FLIP(y[i]), x[i], rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]);}/* * Write an array of pixels with a boolean mask. The current color * is used for all pixels. */static void write_mono_rgba_pixels_32(const GLcontext *ctx, struct gl_renderbuffer *rb, GLuint n, const GLint x[], const GLint y[], const GLchan color[4], const GLubyte mask[]){ GLuint i; WMesaContext pwc = wmesa_context(ctx); WMesaFramebuffer pwfb = wmesa_framebuffer(ctx->DrawBuffer); for (i=0; i<n; i++) if (mask[i]) WMSETPIXEL32(pwfb, FLIP(y[i]),x[i],color[RCOMP], color[GCOMP], color[BCOMP]);}/* Read a horizontal span of color pixels. */static void read_rgba_span_32(const GLcontext *ctx, struct gl_renderbuffer *rb, GLuint n, GLint x, GLint y, GLubyte rgba[][4] ){ GLuint i; DWORD pixel; LPDWORD lpdw; WMesaContext pwc = wmesa_context(ctx); WMesaFramebuffer pwfb = wmesa_framebuffer(ctx->DrawBuffer); y = FLIP(y); lpdw = ((LPDWORD)(pwfb->pbPixels + pwfb->ScanWidth * y)) + x; for (i=0; i<n; i++) { pixel = lpdw[i]; rgba[i][RCOMP] = (pixel & 0x00ff0000) >> 16; rgba[i][GCOMP] = (pixel & 0x0000ff00) >> 8; rgba[i][BCOMP] = (pixel & 0x000000ff); rgba[i][ACOMP] = 255; }}/* Read an array of color pixels. */static void read_rgba_pixels_32(const GLcontext *ctx, struct gl_renderbuffer *rb, GLuint n, const GLint x[], const GLint y[], GLubyte rgba[][4]){ GLuint i; DWORD pixel; LPDWORD lpdw; WMesaContext pwc = wmesa_context(ctx); WMesaFramebuffer pwfb = wmesa_framebuffer(ctx->DrawBuffer); for (i=0; i<n; i++) { GLint y2 = FLIP(y[i]); lpdw = ((LPDWORD)(pwfb->pbPixels + pwfb->ScanWidth * y2)) + x[i]; pixel = *lpdw; rgba[i][RCOMP] = (pixel & 0x00ff0000) >> 16; rgba[i][GCOMP] = (pixel & 0x0000ff00) >> 8; rgba[i][BCOMP] = (pixel & 0x000000ff); rgba[i][ACOMP] = 255; }}/*********************************************************************//* DOUBLE BUFFER 24-bit */#define WMSETPIXEL24(pwc, y, x, r, g, b) { \LPBYTE lpb = ((LPBYTE)((pwc)->pbPixels + (pwc)->ScanWidth * (y)) + (3 * x)); \lpb[0] = (b); \lpb[1] = (g); \lpb[2] = (r); }/* Write a horizontal span of RGBA color pixels with a boolean mask. */static void write_rgba_span_24(const GLcontext *ctx, struct gl_renderbuffer *rb, GLuint n, GLint x, GLint y, const GLubyte rgba[][4], const GLubyte mask[] ){ WMesaContext pwc = wmesa_context(ctx); WMesaFramebuffer pwfb = wmesa_framebuffer(ctx->DrawBuffer); GLuint i;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -