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

📄 tdfx_pixels.c

📁 Mesa is an open-source implementation of the OpenGL specification - a system for rendering interacti
💻 C
📖 第 1 页 / 共 2 页
字号:
       * width, height, skipPixels and skipRows values we can do       * scissoring without special code in the rendering loop.       */      /* we'll construct a new pixelstore struct */      finalUnpack = &scissoredUnpack;      scissoredUnpack = *unpack;      if (scissoredUnpack.RowLength == 0)	 scissoredUnpack.RowLength = width;      /* clip left */      if (px < ctx->Scissor.X) {	 scissoredUnpack.SkipPixels += (ctx->Scissor.X - px);	 width -= (ctx->Scissor.X - px);	 px = ctx->Scissor.X;      }      /* clip right */      if (px + width >= ctx->Scissor.X + ctx->Scissor.Width) {	 width -= (px + width - (ctx->Scissor.X + ctx->Scissor.Width));      }      /* clip bottom */      if (py < ctx->Scissor.Y) {	 scissoredUnpack.SkipRows += (ctx->Scissor.Y - py);	 height -= (ctx->Scissor.Y - py);	 py = ctx->Scissor.Y;      }      /* clip top */      if (py + height >= ctx->Scissor.Y + ctx->Scissor.Height) {	 height -= (py + height - (ctx->Scissor.Y + ctx->Scissor.Height));      }      if (width <= 0 || height <= 0)	 return GL_TRUE;     /* totally scissored away */   }   else {      finalUnpack = unpack;   }   /* compute pixel value */   {      GLint r = (GLint) (ctx->Current.RasterColor[0] * 255.0f);      GLint g = (GLint) (ctx->Current.RasterColor[1] * 255.0f);      GLint b = (GLint) (ctx->Current.RasterColor[2] * 255.0f);      GLint a = (GLint) (ctx->Current.RasterColor[3] * 255.0f);      color = PACK_BGRA32(r, g, b, a);   }   info.size = sizeof(info);   if (!TDFX_grLfbLock(fxMesa, GR_LFB_WRITE_ONLY,		     fxMesa->currentFB, GR_LFBWRITEMODE_8888,		     GR_ORIGIN_UPPER_LEFT, FXFALSE, &info)) {#ifndef TDFX_SILENT      fprintf(stderr, "tdfx Driver: error locking the linear frame buffer\n");#endif      return GL_TRUE;   }   {      const GLint winX = fxMesa->x_offset;      const GLint winY = fxMesa->y_offset + fxMesa->height - 1;      GLint dstStride;      GLuint *dst;      GLint row;      if (fxMesa->glCtx->Color.DrawBuffer[0] == GL_FRONT) {	 dstStride = fxMesa->screen_width;	 dst =	    (GLuint *) info.lfbPtr + (winY - py) * dstStride + (winX +								px);      }      else {	 dstStride = info.strideInBytes / 4;	 dst =	    (GLuint *) info.lfbPtr + (winY - py) * dstStride + (winX +								px);      }      /* compute dest address of bottom-left pixel in bitmap */      for (row = 0; row < height; row++) {	 const GLubyte *src =	    (const GLubyte *) _mesa_image_address2d(finalUnpack,                                                    bitmap, width, height,                                                    GL_COLOR_INDEX,                                                    GL_BITMAP, row, 0);	 if (finalUnpack->LsbFirst) {	    /* least significan bit first */	    GLubyte mask = 1U << (finalUnpack->SkipPixels & 0x7);	    GLint col;	    for (col = 0; col < width; col++) {	       if (*src & mask) {		  if (inClipRects(fxMesa, winX + px + col, winY - py - row))		     dst[col] = color;	       }	       if (mask == 128U) {		  src++;		  mask = 1U;	       }	       else {		  mask = mask << 1;	       }	    }	    if (mask != 1)	       src++;	 }	 else {	    /* most significan bit first */	    GLubyte mask = 128U >> (finalUnpack->SkipPixels & 0x7);	    GLint col;	    for (col = 0; col < width; col++) {	       if (*src & mask) {		  if (inClipRects(fxMesa, winX + px + col, winY - py - row))		     dst[col] = color;	       }	       if (mask == 1U) {		  src++;		  mask = 128U;	       }	       else {		  mask = mask >> 1;	       }	    }	    if (mask != 128)	       src++;	 }	 dst -= dstStride;      }   }   TDFX_grLfbUnlock(fxMesa, GR_LFB_WRITE_ONLY, fxMesa->currentFB);   return GL_TRUE;}#endifvoidtdfx_readpixels_R5G6B5(GLcontext * ctx, GLint x, GLint y,		       GLsizei width, GLsizei height,		       GLenum format, GLenum type,		       const struct gl_pixelstore_attrib *packing,		       GLvoid * dstImage){   if (format != GL_RGB ||       type != GL_UNSIGNED_SHORT_5_6_5 ||       (ctx->_ImageTransferState & (IMAGE_SCALE_BIAS_BIT|				    IMAGE_MAP_COLOR_BIT)))   {      _swrast_ReadPixels( ctx, x, y, width, height, format, type, packing,			  dstImage );      return;   }   {      tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);      GrLfbInfo_t info;      __DRIdrawablePrivate *const readable = fxMesa->driReadable;      const GLint winX = readable->x;      const GLint winY = readable->y + readable->h - 1;      const GLint scrX = winX + x;      const GLint scrY = winY - y;      LOCK_HARDWARE( fxMesa );      info.size = sizeof(info);      if (fxMesa->Glide.grLfbLock(GR_LFB_READ_ONLY,		    fxMesa->ReadBuffer,		    GR_LFBWRITEMODE_ANY,		    GR_ORIGIN_UPPER_LEFT, FXFALSE, &info)) {	 const GLint srcStride = (fxMesa->glCtx->Color.DrawBuffer[0] ==	     GL_FRONT) ? (fxMesa->screen_width) : (info.strideInBytes / 2);	 const GLushort *src = (const GLushort *) info.lfbPtr	    + scrY * srcStride + scrX;	 GLubyte *dst = (GLubyte *) _mesa_image_address2d(packing,            dstImage, width, height, format, type, 0, 0);	 const GLint dstStride = _mesa_image_row_stride(packing,            width, format, type);	 /* directly memcpy 5R6G5B pixels into client's buffer */	 const GLint widthInBytes = width * 2;	 GLint row;	 for (row = 0; row < height; row++) {	    MEMCPY(dst, src, widthInBytes);	    dst += dstStride;	    src -= srcStride;	 }	 fxMesa->Glide.grLfbUnlock(GR_LFB_READ_ONLY, fxMesa->ReadBuffer);      }      UNLOCK_HARDWARE( fxMesa );      return;   }}voidtdfx_readpixels_R8G8B8A8(GLcontext * ctx, GLint x, GLint y,                         GLsizei width, GLsizei height,                         GLenum format, GLenum type,                         const struct gl_pixelstore_attrib *packing,                         GLvoid * dstImage){   if ((!(format == GL_BGRA && type == GL_UNSIGNED_INT_8_8_8_8) &&	!(format == GL_BGRA && type == GL_UNSIGNED_BYTE)) ||       (ctx->_ImageTransferState & (IMAGE_SCALE_BIAS_BIT|				    IMAGE_MAP_COLOR_BIT)))   {      _swrast_ReadPixels( ctx, x, y, width, height, format, type, packing,			  dstImage );      return;   }   {      tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);      GrLfbInfo_t info;      __DRIdrawablePrivate *const readable = fxMesa->driReadable;      const GLint winX = readable->x;      const GLint winY = readable->y + readable->h - 1;      const GLint scrX = winX + x;      const GLint scrY = winY - y;      LOCK_HARDWARE(fxMesa);      info.size = sizeof(info);      if (fxMesa->Glide.grLfbLock(GR_LFB_READ_ONLY,                    fxMesa->ReadBuffer,                    GR_LFBWRITEMODE_ANY,                    GR_ORIGIN_UPPER_LEFT, FXFALSE, &info))      {         const GLint srcStride = (fxMesa->glCtx->Color.DrawBuffer[0] == GL_FRONT)            ? (fxMesa->screen_width) : (info.strideInBytes / 4);         const GLuint *src = (const GLuint *) info.lfbPtr            + scrY * srcStride + scrX;         const GLint dstStride =            _mesa_image_row_stride(packing, width, format, type);         GLubyte *dst = (GLubyte *) _mesa_image_address2d(packing,            dstImage, width, height, format, type, 0, 0);         const GLint widthInBytes = width * 4;	 {            GLint row;            for (row = 0; row < height; row++) {               MEMCPY(dst, src, widthInBytes);               dst += dstStride;               src -= srcStride;            }         }         fxMesa->Glide.grLfbUnlock(GR_LFB_READ_ONLY, fxMesa->ReadBuffer);      }      UNLOCK_HARDWARE(fxMesa);   }}voidtdfx_drawpixels_R8G8B8A8(GLcontext * ctx, GLint x, GLint y,                         GLsizei width, GLsizei height,                         GLenum format, GLenum type,                         const struct gl_pixelstore_attrib *unpack,                         const GLvoid * pixels){   tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);   if ((!(format == GL_BGRA && type == GL_UNSIGNED_INT_8_8_8_8) &&	!(format == GL_BGRA && type == GL_UNSIGNED_BYTE)) ||       ctx->Pixel.ZoomX != 1.0F ||        ctx->Pixel.ZoomY != 1.0F ||       (ctx->_ImageTransferState & (IMAGE_SCALE_BIAS_BIT|				    IMAGE_MAP_COLOR_BIT)) ||       ctx->Color.AlphaEnabled ||       ctx->Depth.Test ||       ctx->Fog.Enabled ||       ctx->Scissor.Enabled ||       ctx->Stencil.Enabled ||       !ctx->Color.ColorMask[0] ||       !ctx->Color.ColorMask[1] ||       !ctx->Color.ColorMask[2] ||       !ctx->Color.ColorMask[3] ||       ctx->Color.ColorLogicOpEnabled ||       ctx->Texture._EnabledUnits ||       fxMesa->Fallback)          {      _swrast_DrawPixels( ctx, x, y, width, height, format, type, 			  unpack, pixels );      return;    }   {      tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);      GrLfbInfo_t info;      GLboolean result = GL_FALSE;      const GLint winX = fxMesa->x_offset;      const GLint winY = fxMesa->y_offset + fxMesa->height - 1;      const GLint scrX = winX + x;      const GLint scrY = winY - y;      /* lock early to make sure cliprects are right */      LOCK_HARDWARE(fxMesa);      /* make sure hardware has latest blend funcs */      if (ctx->Color.BlendEnabled) {         fxMesa->dirty |= TDFX_UPLOAD_BLEND_FUNC;         tdfxEmitHwStateLocked( fxMesa );      }      /* look for clipmasks, giveup if region obscured */      if (fxMesa->glCtx->Color.DrawBuffer[0] == GL_FRONT) {         if (!inClipRects_Region(fxMesa, scrX, scrY, width, height)) {            UNLOCK_HARDWARE(fxMesa);	    _swrast_DrawPixels( ctx, x, y, width, height, format, type, 				unpack, pixels );            return;         }      }      info.size = sizeof(info);      if (fxMesa->Glide.grLfbLock(GR_LFB_WRITE_ONLY,                    fxMesa->DrawBuffer,                    GR_LFBWRITEMODE_8888,                    GR_ORIGIN_UPPER_LEFT, FXTRUE, &info))      {         const GLint dstStride = (fxMesa->glCtx->Color.DrawBuffer[0] == GL_FRONT)            ? (fxMesa->screen_width * 4) : (info.strideInBytes);         GLubyte *dst = (GLubyte *) info.lfbPtr            + scrY * dstStride + scrX * 4;         const GLint srcStride =            _mesa_image_row_stride(unpack, width, format, type);         const GLubyte *src = (GLubyte *) _mesa_image_address2d(unpack,            pixels, width, height, format, type, 0, 0);         const GLint widthInBytes = width * 4;         if ((format == GL_BGRA && type == GL_UNSIGNED_INT_8_8_8_8) ||             (format == GL_BGRA && type == GL_UNSIGNED_BYTE)) {            GLint row;            for (row = 0; row < height; row++) {               MEMCPY(dst, src, widthInBytes);               dst -= dstStride;               src += srcStride;            }            result = GL_TRUE;         }         fxMesa->Glide.grLfbUnlock(GR_LFB_WRITE_ONLY, fxMesa->DrawBuffer);      }      UNLOCK_HARDWARE(fxMesa);   }}

⌨️ 快捷键说明

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