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

📄 s_drawpix.c

📁 mesa-6.5-minigui源码
💻 C
📖 第 1 页 / 共 3 页
字号:
      dest = tmpImage;      for (row = 0; row < height; row++) {         const GLvoid *source = _mesa_image_address2d(unpack,                                  pixels, width, height, format, type, row, 0);         _mesa_unpack_color_span_float(ctx, width, GL_RGBA, (GLfloat *) dest,                                     format, type, source, unpack,                                     transferOps & IMAGE_PRE_CONVOLUTION_BITS);         dest += width * 4;      }      /* do convolution */      if (ctx->Pixel.Convolution2DEnabled) {         _mesa_convolve_2d_image(ctx, &width, &height, tmpImage, convImage);      }      else {         ASSERT(ctx->Pixel.Separable2DEnabled);         _mesa_convolve_sep_image(ctx, &width, &height, tmpImage, convImage);      }      _mesa_free(tmpImage);      /* continue transfer ops and draw the convolved image */      unpack = &ctx->DefaultPacking;      pixels = convImage;      format = GL_RGBA;      type = GL_FLOAT;      transferOps &= IMAGE_POST_CONVOLUTION_BITS;   }   /*    * General solution    */   {      const GLbitfield interpMask = span.interpMask;      const GLbitfield arrayMask = span.arrayMask;      GLint skipPixels = 0;      /* if the span is wider than MAX_WIDTH we have to do it in chunks */      while (skipPixels < width) {         const GLint spanWidth = MIN2(width - skipPixels, MAX_WIDTH);         GLint row;         ASSERT(span.end <= MAX_WIDTH);         for (row = 0; row < height; row++) {            const GLvoid *source = _mesa_image_address2d(unpack,                     pixels, width, height, format, type, row, skipPixels);            /* Set these for each row since the _swrast_write_* function may             * change them while clipping.             */            span.x = x + skipPixels;            span.y = y + row;            span.end = spanWidth;            span.arrayMask = arrayMask;            span.interpMask = interpMask;            _mesa_unpack_color_span_chan(ctx, spanWidth, GL_RGBA,                                         (GLchan *) span.array->rgba,                                         format, type, source, unpack,                                         transferOps);            if ((ctx->Pixel.MinMaxEnabled && ctx->MinMax.Sink) ||                (ctx->Pixel.HistogramEnabled && ctx->Histogram.Sink))               continue;            /* draw the span */            if (quickDraw) {               rb->PutRow(ctx, rb, span.end, span.x, span.y,                          span.array->rgba, NULL);            }            else if (zoom) {               _swrast_write_zoomed_rgba_span(ctx, imgX, imgY, &span,                                       (CONST GLchan (*)[4]) span.array->rgba);            }            else {               _swrast_write_rgba_span(ctx, &span);            }         }         skipPixels += spanWidth;      }   }   if (convImage) {      _mesa_free(convImage);   }}/** * This is a bit different from drawing GL_DEPTH_COMPONENT pixels. * The only per-pixel operations that apply are depth scale/bias, * stencil offset/shift, GL_DEPTH_WRITEMASK and GL_STENCIL_WRITEMASK, * and pixel zoom. * Also, only the depth buffer and stencil buffers are touched, not the * color buffer(s). */static voiddraw_depth_stencil_pixels(GLcontext *ctx, GLint x, GLint y,                          GLsizei width, GLsizei height, GLenum type,                          const struct gl_pixelstore_attrib *unpack,                          const GLvoid *pixels){   const GLint imgX = x, imgY = y;   const GLboolean scaleOrBias =       ctx->Pixel.DepthScale != 1.0 || ctx->Pixel.DepthBias != 0.0;   const GLfloat depthScale = ctx->DrawBuffer->_DepthMaxF;   const GLuint stencilMask = ctx->Stencil.WriteMask[0];   const GLuint stencilType = (STENCIL_BITS == 8) ?       GL_UNSIGNED_BYTE : GL_UNSIGNED_SHORT;   const GLboolean zoom = ctx->Pixel.ZoomX != 1.0 || ctx->Pixel.ZoomY != 1.0;   struct gl_renderbuffer *depthRb, *stencilRb;   struct gl_pixelstore_attrib clippedUnpack = *unpack;   if (!zoom) {      if (!_mesa_clip_drawpixels(ctx, &x, &y, &width, &height,                                 &clippedUnpack)) {         /* totally clipped */         return;      }   }      depthRb = ctx->ReadBuffer->Attachment[BUFFER_DEPTH].Renderbuffer;   stencilRb = ctx->ReadBuffer->Attachment[BUFFER_STENCIL].Renderbuffer;   ASSERT(depthRb);   ASSERT(stencilRb);   if (depthRb->_BaseFormat == GL_DEPTH_STENCIL_EXT &&       stencilRb->_BaseFormat == GL_DEPTH_STENCIL_EXT &&       depthRb == stencilRb &&       !scaleOrBias &&       !zoom &&       ctx->Depth.Mask &&       (stencilMask & 0xff) == 0xff) {      /* This is the ideal case.       * Drawing GL_DEPTH_STENCIL pixels into a combined depth/stencil buffer.       * Plus, no pixel transfer ops, zooming, or masking needed.       */      GLint i;      for (i = 0; i < height; i++) {         const GLuint *src = (const GLuint *)             _mesa_image_address2d(&clippedUnpack, pixels, width, height,                                  GL_DEPTH_STENCIL_EXT, type, i, 0);         depthRb->PutRow(ctx, depthRb, width, x, y + i, src, NULL);      }   }   else {      /* sub-optimal cases:       * Separate depth/stencil buffers, or pixel transfer ops required.       */      /* XXX need to handle very wide images (skippixels) */      GLint i;      depthRb = ctx->DrawBuffer->_DepthBuffer;      stencilRb = ctx->DrawBuffer->_StencilBuffer;      for (i = 0; i < height; i++) {         const GLuint *depthStencilSrc = (const GLuint *)            _mesa_image_address2d(&clippedUnpack, pixels, width, height,                                  GL_DEPTH_STENCIL_EXT, type, i, 0);         if (ctx->Depth.Mask) {            if (!scaleOrBias && ctx->DrawBuffer->Visual.depthBits == 24) {               /* fast path 24-bit zbuffer */               GLuint zValues[MAX_WIDTH];               GLint j;               ASSERT(depthRb->DataType == GL_UNSIGNED_INT);               for (j = 0; j < width; j++) {                  zValues[j] = depthStencilSrc[j] >> 8;               }               if (zoom)                  _swrast_write_zoomed_z_span(ctx, imgX, imgY, width,                                              x, y + i, zValues);               else                  depthRb->PutRow(ctx, depthRb, width, x, y + i, zValues,NULL);            }            else if (!scaleOrBias && ctx->DrawBuffer->Visual.depthBits == 16) {               /* fast path 16-bit zbuffer */               GLushort zValues[MAX_WIDTH];               GLint j;               ASSERT(depthRb->DataType == GL_UNSIGNED_SHORT);               for (j = 0; j < width; j++) {                  zValues[j] = depthStencilSrc[j] >> 16;               }               if (zoom)                  _swrast_write_zoomed_z_span(ctx, imgX, imgY, width,                                              x, y + i, zValues);               else                  depthRb->PutRow(ctx, depthRb, width, x, y + i, zValues,NULL);            }            else {               /* general case */               GLuint zValues[MAX_WIDTH];  /* 16 or 32-bit Z value storage */               _mesa_unpack_depth_span(ctx, width,                                       depthRb->DataType, zValues, depthScale,                                       type, depthStencilSrc, &clippedUnpack);               if (zoom) {                  _swrast_write_zoomed_z_span(ctx, imgX, imgY, width, x,                                              y + i, zValues);               }               else {                  depthRb->PutRow(ctx, depthRb, width, x, y + i, zValues,NULL);               }            }         }         if (stencilMask != 0x0) {            GLstencil stencilValues[MAX_WIDTH];            /* get stencil values, with shift/offset/mapping */            _mesa_unpack_stencil_span(ctx, width, stencilType, stencilValues,                                      type, depthStencilSrc, &clippedUnpack,                                      ctx->_ImageTransferState);            if (zoom)               _swrast_write_zoomed_stencil_span(ctx, imgX, imgY, width,                                                  x, y + i, stencilValues);            else               _swrast_write_stencil_span(ctx, width, x, y + i, stencilValues);         }      }   }}/** * Execute software-based glDrawPixels. * By time we get here, all error checking will have been done. */void_swrast_DrawPixels( GLcontext *ctx,		    GLint x, GLint y,		    GLsizei width, GLsizei height,		    GLenum format, GLenum type,		    const struct gl_pixelstore_attrib *unpack,		    const GLvoid *pixels ){   SWcontext *swrast = SWRAST_CONTEXT(ctx);   RENDER_START(swrast,ctx);   if (ctx->NewState)      _mesa_update_state(ctx);   if (swrast->NewState)      _swrast_validate_derived( ctx );   if (unpack->BufferObj->Name) {      /* unpack from PBO */      GLubyte *buf;      if (!_mesa_validate_pbo_access(2, unpack, width, height, 1,                                     format, type, pixels)) {         _mesa_error(ctx, GL_INVALID_OPERATION,                     "glDrawPixels(invalid PBO access)");         goto end;      }      buf = (GLubyte *) ctx->Driver.MapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT,                                              GL_READ_ONLY_ARB,                                              unpack->BufferObj);      if (!buf) {         /* buffer is already mapped - that's an error */         _mesa_error(ctx, GL_INVALID_OPERATION, "glDrawPixels(PBO is mapped)");         goto end;      }      pixels = ADD_POINTERS(buf, pixels);   }   switch (format) {   case GL_STENCIL_INDEX:      draw_stencil_pixels( ctx, x, y, width, height, type, unpack, pixels );      break;   case GL_DEPTH_COMPONENT:      draw_depth_pixels( ctx, x, y, width, height, type, unpack, pixels );      break;   case GL_COLOR_INDEX:      if (ctx->Visual.rgbMode)	 draw_rgba_pixels(ctx, x,y, width, height, format, type, unpack, pixels);      else	 draw_index_pixels(ctx, x, y, width, height, type, unpack, pixels);      break;   case GL_RED:   case GL_GREEN:   case GL_BLUE:   case GL_ALPHA:   case GL_LUMINANCE:   case GL_LUMINANCE_ALPHA:   case GL_RGB:   case GL_BGR:   case GL_RGBA:   case GL_BGRA:   case GL_ABGR_EXT:      draw_rgba_pixels(ctx, x, y, width, height, format, type, unpack, pixels);      break;   case GL_DEPTH_STENCIL_EXT:      draw_depth_stencil_pixels(ctx, x, y, width, height,                                type, unpack, pixels);      break;   default:      _mesa_problem(ctx, "unexpected format in _swrast_DrawPixels");      /* don't return yet, clean-up */   }end:   RENDER_FINISH(swrast,ctx);   if (unpack->BufferObj->Name) {      /* done with PBO so unmap it now */      ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT,                              unpack->BufferObj);   }}#if 0  /* experimental *//* * Execute glDrawDepthPixelsMESA(). */void_swrast_DrawDepthPixelsMESA( GLcontext *ctx,                             GLint x, GLint y,                             GLsizei width, GLsizei height,                             GLenum colorFormat, GLenum colorType,                             const GLvoid *colors,                             GLenum depthType, const GLvoid *depths,                             const struct gl_pixelstore_attrib *unpack ){   SWcontext *swrast = SWRAST_CONTEXT(ctx);   if (swrast->NewState)      _swrast_validate_derived( ctx );   RENDER_START(swrast,ctx);   switch (colorFormat) {   case GL_COLOR_INDEX:      if (ctx->Visual.rgbMode)	 draw_rgba_pixels(ctx, x,y, width, height, colorFormat, colorType,                          unpack, colors);      else	 draw_index_pixels(ctx, x, y, width, height, colorType,                           unpack, colors);      break;   case GL_RED:   case GL_GREEN:   case GL_BLUE:   case GL_ALPHA:   case GL_LUMINANCE:   case GL_LUMINANCE_ALPHA:   case GL_RGB:   case GL_BGR:   case GL_RGBA:   case GL_BGRA:   case GL_ABGR_EXT:      draw_rgba_pixels(ctx, x, y, width, height, colorFormat, colorType,                       unpack, colors);      break;   default:      _mesa_problem(ctx, "unexpected format in glDrawDepthPixelsMESA");   }   RENDER_FINISH(swrast,ctx);}#endif

⌨️ 快捷键说明

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