📄 tdfx_span.c
字号:
for (; i < n; i++) { const GLuint mask = (stencil_size > 0) ? 0x00FFFFFF : 0xFFFFFFFF; depth[i] = GET_WRAPPED_FB_DATA(&ReadParams, GLuint, x + i, y); depth[i] &= mask; } READ_FB_SPAN_UNLOCK(fxMesa, GR_BUFFER_AUXBUFFER); break; } }}static voidtdfxDDWriteDepthPixels(GLcontext * ctx, struct gl_renderbuffer *rb, GLuint n, const GLint x[], const GLint y[], const void *values, const GLubyte mask[]){ const GLuint *depth = (const GLuint *) values; tdfxContextPtr fxMesa = (tdfxContextPtr) ctx->DriverCtx; GLint bottom = fxMesa->height + fxMesa->y_offset - 1; GLuint i; GLushort d16; GLuint d32; GLuint depth_size = fxMesa->glCtx->Visual.depthBits; GLuint stencil_size = fxMesa->glCtx->Visual.stencilBits; GrLfbInfo_t info; int xpos; int ypos; GrLfbInfo_t backBufferInfo; if (MESA_VERBOSE & VERBOSE_DRIVER) { fprintf(stderr, "tdfxmesa: tdfxDDWriteDepthPixels(...)\n"); } switch (depth_size) { case 16: GetBackBufferInfo(fxMesa, &backBufferInfo); /* * Note that the _LOCK macro adds a curly brace, * and the UNLOCK macro removes it. */ WRITE_FB_SPAN_LOCK(fxMesa, info, GR_BUFFER_AUXBUFFER, GR_LFBWRITEMODE_ANY); { LFBParameters ReadParams; GetFbParams(fxMesa, &info, &backBufferInfo, &ReadParams, sizeof(GLushort)); for (i = 0; i < n; i++) { if ((!mask || mask[i]) && visible_pixel(fxMesa, x[i], y[i])) { xpos = x[i] + fxMesa->x_offset; ypos = bottom - y[i]; d16 = depth[i]; PUT_FB_DATA(&ReadParams, GLushort, xpos, ypos, d16); } } } WRITE_FB_SPAN_UNLOCK(fxMesa, GR_BUFFER_AUXBUFFER); break; case 24: case 32: GetBackBufferInfo(fxMesa, &backBufferInfo); /* * Note that the _LOCK macro adds a curly brace, * and the UNLOCK macro removes it. */ WRITE_FB_SPAN_LOCK(fxMesa, info, GR_BUFFER_AUXBUFFER, GR_LFBWRITEMODE_ANY); { LFBParameters ReadParams; GetFbParams(fxMesa, &info, &backBufferInfo, &ReadParams, sizeof(GLuint)); for (i = 0; i < n; i++) { if (!mask || mask[i]) { if (visible_pixel(fxMesa, x[i], y[i])) { xpos = x[i] + fxMesa->x_offset; ypos = bottom - y[i]; if (stencil_size > 0) { d32 = GET_FB_DATA(&ReadParams, GLuint, xpos, ypos); d32 = (d32 & 0xFF000000) | (depth[i] & 0xFFFFFF); } else { d32 = depth[i]; } PUT_FB_DATA(&ReadParams, GLuint, xpos, ypos, d32); } } } } WRITE_FB_SPAN_UNLOCK(fxMesa, GR_BUFFER_AUXBUFFER); break; }}static voidtdfxDDReadDepthPixels(GLcontext * ctx, struct gl_renderbuffer *rb, GLuint n, const GLint x[], const GLint y[], void *values){ GLuint *depth = (GLuint *) values; tdfxContextPtr fxMesa = (tdfxContextPtr) ctx->DriverCtx; GLint bottom = fxMesa->height + fxMesa->y_offset - 1; GLuint i; GLuint depth_size = fxMesa->glCtx->Visual.depthBits; GLushort d16; int xpos; int ypos; GrLfbInfo_t info; GLuint stencil_size; GrLfbInfo_t backBufferInfo; if (MESA_VERBOSE & VERBOSE_DRIVER) { fprintf(stderr, "tdfxmesa: tdfxDDReadDepthPixels(...)\n"); } assert((depth_size == 16) || (depth_size == 24) || (depth_size == 32)); switch (depth_size) { case 16: GetBackBufferInfo(fxMesa, &backBufferInfo); /* * Note that the _LOCK macro adds a curly brace, * and the UNLOCK macro removes it. */ READ_FB_SPAN_LOCK(fxMesa, info, GR_BUFFER_AUXBUFFER); { LFBParameters ReadParams; GetFbParams(fxMesa, &info, &backBufferInfo, &ReadParams, sizeof(GLushort)); for (i = 0; i < n; i++) { /* * Convert to screen coordinates. */ xpos = x[i] + fxMesa->x_offset; ypos = bottom - y[i]; d16 = GET_FB_DATA(&ReadParams, GLushort, xpos, ypos); depth[i] = d16; } } READ_FB_SPAN_UNLOCK(fxMesa, GR_BUFFER_AUXBUFFER); break; case 24: case 32: GetBackBufferInfo(fxMesa, &backBufferInfo); /* * Note that the _LOCK macro adds a curly brace, * and the UNLOCK macro removes it. */ READ_FB_SPAN_LOCK(fxMesa, info, GR_BUFFER_AUXBUFFER); stencil_size = fxMesa->glCtx->Visual.stencilBits; { LFBParameters ReadParams; GetFbParams(fxMesa, &info, &backBufferInfo, &ReadParams, sizeof(GLuint)); for (i = 0; i < n; i++) { GLuint d32; /* * Convert to screen coordinates. */ xpos = x[i] + fxMesa->x_offset; ypos = bottom - y[i]; d32 = GET_FB_DATA(&ReadParams, GLuint, xpos, ypos); if (stencil_size > 0) { d32 &= 0x00FFFFFF; } depth[i] = d32; } } READ_FB_SPAN_UNLOCK(fxMesa, GR_BUFFER_AUXBUFFER); break; default: assert(0); }}/* * Stencil buffer read/write functions. */#define EXTRACT_S_FROM_ZS(zs) (((zs) >> 24) & 0xFF)#define EXTRACT_Z_FROM_ZS(zs) ((zs) & 0xffffff)#define BUILD_ZS(z, s) (((s) << 24) | (z))static voidwrite_stencil_span(GLcontext * ctx, struct gl_renderbuffer *rb, GLuint n, GLint x, GLint y, const void *values, const GLubyte mask[]){ const GLubyte *stencil = (const GLubyte *) values; tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx); GrLfbInfo_t info; GrLfbInfo_t backBufferInfo; GetBackBufferInfo(fxMesa, &backBufferInfo); /* * Note that the _LOCK macro adds a curly brace, * and the UNLOCK macro removes it. */ WRITE_FB_SPAN_LOCK(fxMesa, info, GR_BUFFER_AUXBUFFER, GR_LFBWRITEMODE_ANY); { const GLint winY = fxMesa->y_offset + fxMesa->height - 1; const GLint winX = fxMesa->x_offset; const GLint scrX = winX + x; const GLint scrY = winY - y; LFBParameters ReadParams; GLubyte visMask[MAX_WIDTH]; GLuint i; int wrappedPartStart; GetFbParams(fxMesa, &info, &backBufferInfo, &ReadParams, sizeof(GLuint)); if (ReadParams.firstWrappedX <= x) { wrappedPartStart = 0; } else if (n <= (ReadParams.firstWrappedX - x)) { wrappedPartStart = n; } else { wrappedPartStart = (ReadParams.firstWrappedX - x); } generate_vismask(fxMesa, scrX, scrY, n, visMask); for (i = 0; i < wrappedPartStart; i++) { if (visMask[i] && (!mask || mask[i])) { GLuint z = GET_ORDINARY_FB_DATA(&ReadParams, GLuint, scrX + i, scrY) & 0x00FFFFFF; z |= (stencil[i] & 0xFF) << 24; PUT_ORDINARY_FB_DATA(&ReadParams, GLuint, scrX + i, scrY, z); } } for (; i < n; i++) { if (visMask[i] && (!mask || mask[i])) { GLuint z = GET_WRAPPED_FB_DATA(&ReadParams, GLuint, scrX + i, scrY) & 0x00FFFFFF; z |= (stencil[i] & 0xFF) << 24; PUT_WRAPPED_FB_DATA(&ReadParams, GLuint, scrX + i, scrY, z); } } } WRITE_FB_SPAN_UNLOCK(fxMesa, GR_BUFFER_AUXBUFFER);}static voidwrite_mono_stencil_span(GLcontext * ctx, struct gl_renderbuffer *rb, GLuint n, GLint x, GLint y, const void *value, const GLubyte mask[]){ GLbyte stencilVal = *((GLbyte *) value); GLbyte stencils[MAX_WIDTH]; GLuint i; for (i = 0; i < n; i++) stencils[i] = stencilVal; write_stencil_span(ctx, rb, n, x, y, stencils, mask);}static voidread_stencil_span(GLcontext * ctx, struct gl_renderbuffer *rb, GLuint n, GLint x, GLint y, void *values){ GLubyte *stencil = (GLubyte *) values; tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx); GrLfbInfo_t info; GrLfbInfo_t backBufferInfo; GetBackBufferInfo(fxMesa, &backBufferInfo); /* * Note that the _LOCK macro adds a curly brace, * and the UNLOCK macro removes it. */ READ_FB_SPAN_LOCK(fxMesa, info, GR_BUFFER_AUXBUFFER); { const GLint winY = fxMesa->y_offset + fxMesa->height - 1; const GLint winX = fxMesa->x_offset; GLuint i; LFBParameters ReadParams; int wrappedPartStart; /* * Convert to screen coordinates. */ x += winX; y = winY - y; GetFbParams(fxMesa, &info, &backBufferInfo, &ReadParams, sizeof(GLuint)); if (ReadParams.firstWrappedX <= x) { wrappedPartStart = 0; } else if (n <= (ReadParams.firstWrappedX - x)) { wrappedPartStart = n; } else { wrappedPartStart = (ReadParams.firstWrappedX - x); } for (i = 0; i < wrappedPartStart; i++) { stencil[i] = (GET_ORDINARY_FB_DATA(&ReadParams, GLuint, x + i, y) >> 24) & 0xFF; } for (; i < n; i++) { stencil[i] = (GET_WRAPPED_FB_DATA(&ReadParams, GLuint, x + i, y) >> 24) & 0xFF; } } READ_FB_SPAN_UNLOCK(fxMesa, GR_BUFFER_AUXBUFFER);}static voidwrite_stencil_pixels(GLcontext * ctx, struct gl_renderbuffer *rb, GLuint n, const GLint x[], const GLint y[], const void *values, const GLubyte mask[]){ const GLubyte *stencil = (const GLubyte *) values; tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx); GrLfbInfo_t info; GrLfbInfo_t backBufferInfo; GetBackBufferInfo(fxMesa, &backBufferInfo); /* * Note that the _LOCK macro adds a curly brace, * and the UNLOCK macro removes it. */ WRITE_FB_SPAN_LOCK(fxMesa, info, GR_BUFFER_AUXBUFFER, GR_LFBWRITEMODE_ANY); { const GLint winY = fxMesa->y_offset + fxMesa->height - 1; const GLint winX = fxMesa->x_offset; LFBParameters ReadParams; GLuint i; GetFbParams(fxMesa, &info, &backBufferInfo, &ReadParams, sizeof(GLuint)); for (i = 0; i < n; i++) { const GLint scrX = winX + x[i]; const GLint scrY = winY - y[i]; if ((!mask || mask[i]) && visible_pixel(fxMesa, scrX, scrY)) { GLuint z = GET_FB_DATA(&ReadParams, GLuint, scrX, scrY) & 0x00FFFFFF; z |= (stencil[i] & 0xFF) << 24; PUT_FB_DATA(&ReadParams, GLuint, scrX, scrY, z); } } } WRITE_FB_SPAN_UNLOCK(fxMesa, GR_BUFFER_AUXBUFFER);}static voidread_stencil_pixels(GLcontext * ctx, struct gl_renderbuffer *rb, GLuint n, const GLint x[], const GLint y[], void *values){ GLubyte *stencil = (GLubyte *) values; tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx); GrLfbInfo_t info; GrLfbInfo_t backBufferInfo; GetBackBufferInfo(fxMesa, &backBufferInfo); /* * Note that the _LOCK macro adds a curly brace, * and the UNLOCK macro removes it. */ READ_FB_SPAN_LOCK(fxMesa, info, GR_BUFFER_AUXBUFFER); { const GLint winY = fxMesa->y_offset + fxMesa->height - 1; const GLint winX = fxMesa->x_offset; GLuint i; LFBParameters ReadParams; GetFbParams(fxMesa, &info, &backBufferInfo, &ReadParams, sizeof(GLuint)); for (i = 0; i < n; i++) { const GLint scrX = winX + x[i]; const GLint scrY = winY - y[i]; stencil[i] = (GET_FB_DATA(&ReadParams, GLuint, scrX, scrY) >> 24) & 0xFF; } } READ_FB_SPAN_UNLOCK(fxMesa, GR_BUFFER_AUXBUFFER);}#define VISUAL_EQUALS_RGBA(vis, r, g, b, a) \ ((vis.redBits == r) && \ (vis.greenBits == g) && \ (vis.blueBits == b) && \ (vis.alphaBits == a))/**********************************************************************//* Locking for swrast *//**********************************************************************/static void tdfxSpanRenderStart( GLcontext *ctx ){ tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx); LOCK_HARDWARE(fxMesa);}static void tdfxSpanRenderFinish( GLcontext *ctx ){ tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx); _swrast_flush( ctx ); UNLOCK_HARDWARE(fxMesa);}/**********************************************************************//* Initialize swrast device driver *//**********************************************************************/void tdfxDDInitSpanFuncs( GLcontext *ctx ){ struct swrast_device_driver *swdd = _swrast_GetDeviceDriverReference( ctx ); swdd->SpanRenderStart = tdfxSpanRenderStart; swdd->SpanRenderFinish = tdfxSpanRenderFinish; }/** * Plug in the Get/Put routines for the given driRenderbuffer. */voidtdfxSetSpanFunctions(driRenderbuffer *drb, const GLvisual *vis){ if (drb->Base.InternalFormat == GL_RGBA) { if (vis->redBits == 5 && vis->greenBits == 6 && vis->blueBits == 5) { tdfxInitPointers_RGB565(&drb->Base); } else if (vis->redBits == 8 && vis->greenBits == 8 && vis->blueBits == 8 && vis->alphaBits == 0) { tdfxInitPointers_RGB888(&drb->Base); } else if (vis->redBits == 8 && vis->greenBits == 8 && vis->blueBits == 8 && vis->alphaBits == 8) { tdfxInitPointers_ARGB8888(&drb->Base); } else { _mesa_problem(NULL, "problem in tdfxSetSpanFunctions"); } } else if (drb->Base.InternalFormat == GL_DEPTH_COMPONENT16 || drb->Base.InternalFormat == GL_DEPTH_COMPONENT24) { drb->Base.GetRow = tdfxDDReadDepthSpan; drb->Base.GetValues = tdfxDDReadDepthPixels; drb->Base.PutRow = tdfxDDWriteDepthSpan; drb->Base.PutMonoRow = tdfxDDWriteMonoDepthSpan; drb->Base.PutValues = tdfxDDWriteDepthPixels; drb->Base.PutMonoValues = NULL; } else if (drb->Base.InternalFormat == GL_STENCIL_INDEX8_EXT) { drb->Base.GetRow = read_stencil_span; drb->Base.GetValues = read_stencil_pixels; drb->Base.PutRow = write_stencil_span; drb->Base.PutMonoRow = write_mono_stencil_span; drb->Base.PutValues = write_stencil_pixels; drb->Base.PutMonoValues = NULL; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -