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

📄 xm_tri.c

📁 Mesa is an open-source implementation of the OpenGL specification - a system for rendering interacti
💻 C
📖 第 1 页 / 共 4 页
字号:
/* * Mesa 3-D graphics library * Version:  6.5 * * Copyright (C) 1999-2006  Brian Paul   All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *//* * This file contains "accelerated" triangle functions.  It should be * fairly easy to write new special-purpose triangle functions and hook * them into this module. */#include "glxheader.h"#include "depth.h"#include "macros.h"#include "imports.h"#include "mtypes.h"#include "xmesaP.h"/* Internal swrast includes: */#include "swrast/s_context.h"#include "swrast/s_depth.h"#include "swrast/s_triangle.h"#define GET_XRB(XRB)  struct xmesa_renderbuffer *XRB = \   xmesa_renderbuffer(ctx->DrawBuffer->_ColorDrawBuffers[0]->Wrapped)/**********************************************************************//***                   Triangle rendering                           ***//**********************************************************************/#if CHAN_BITS == 8/* * XImage, smooth, depth-buffered, PF_TRUECOLOR triangle. */#define NAME smooth_TRUECOLOR_z_triangle#define INTERP_Z 1#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE#define INTERP_RGB 1#define SETUP_CODE						\   XMesaContext xmesa = XMESA_CONTEXT(ctx);			\   GET_XRB(xrb);#define RENDER_SPAN( span ) {					\   GLint x = span.x, y = YFLIP(xrb, span.y);			\   GLuint i;							\   for (i = 0; i < span.end; i++, x++) {			\      const DEPTH_TYPE z = FixedToDepth(span.z);		\      if (z < zRow[i]) {					\         unsigned long p;					\         PACK_TRUECOLOR(p, FixedToInt(span.red),		\            FixedToInt(span.green), FixedToInt(span.blue));	\         XMesaPutPixel(xrb->ximage, x, y, p);			\         zRow[i] = z;						\      }								\      span.red += span.redStep;					\      span.green += span.greenStep;				\      span.blue += span.blueStep;				\      span.z += span.zStep;					\   } }#include "swrast/s_tritemp.h"/* * XImage, smooth, depth-buffered, PF_8A8B8G8R triangle. */#define NAME smooth_8A8B8G8R_z_triangle#define INTERP_Z 1#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE#define INTERP_RGB 1#define INTERP_ALPHA 1#define PIXEL_ADDRESS(X,Y) PIXEL_ADDR4(xrb, X, Y)#define PIXEL_TYPE GLuint#define BYTES_PER_ROW (xrb->ximage->bytes_per_line)#define SETUP_CODE						\   GET_XRB(xrb);#define RENDER_SPAN( span ) {					\   GLuint i;							\   for (i = 0; i < span.end; i++) {				\      const DEPTH_TYPE z = FixedToDepth(span.z);		\      if (z < zRow[i]) {					\         pRow[i] = PACK_8A8B8G8R(FixedToInt(span.red),		\            FixedToInt(span.green), FixedToInt(span.blue),	\            FixedToInt(span.alpha));				\         zRow[i] = z;						\      }								\      span.red += span.redStep;					\      span.green += span.greenStep;				\      span.blue += span.blueStep;				\      span.alpha += span.alphaStep;				\      span.z += span.zStep;					\   } }#include "swrast/s_tritemp.h"/* * XImage, smooth, depth-buffered, PF_8A8R8G8B triangle. */#define NAME smooth_8A8R8G8B_z_triangle#define INTERP_Z 1#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE#define INTERP_RGB 1#define INTERP_ALPHA 1#define PIXEL_ADDRESS(X,Y) PIXEL_ADDR4(xrb, X, Y)#define PIXEL_TYPE GLuint#define BYTES_PER_ROW (xrb->ximage->bytes_per_line)#define SETUP_CODE						\   GET_XRB(xrb);#define RENDER_SPAN( span ) {					\   GLuint i;							\   for (i = 0; i < span.end; i++) {				\      const DEPTH_TYPE z = FixedToDepth(span.z);		\      if (z < zRow[i]) {					\         pRow[i] = PACK_8A8R8G8B(FixedToInt(span.red),		\            FixedToInt(span.green), FixedToInt(span.blue),	\            FixedToInt(span.alpha));				\         zRow[i] = z;						\      }								\      span.red += span.redStep;					\      span.green += span.greenStep;				\      span.blue += span.blueStep;				\      span.alpha += span.alphaStep;				\      span.z += span.zStep;					\   } }#include "swrast/s_tritemp.h"/* * XImage, smooth, depth-buffered, PF_8R8G8B triangle. */#define NAME smooth_8R8G8B_z_triangle#define INTERP_Z 1#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE#define INTERP_RGB 1#define PIXEL_ADDRESS(X,Y) PIXEL_ADDR4(xrb, X, Y)#define PIXEL_TYPE GLuint#define BYTES_PER_ROW (xrb->ximage->bytes_per_line)#define SETUP_CODE						\   GET_XRB(xrb);#define RENDER_SPAN( span ) {					\   GLuint i;							\   for (i = 0; i < span.end; i++) {				\      const DEPTH_TYPE z = FixedToDepth(span.z);		\      if (z < zRow[i]) {					\         pRow[i] = PACK_8R8G8B(FixedToInt(span.red),		\            FixedToInt(span.green), FixedToInt(span.blue));	\         zRow[i] = z;						\      }								\      span.red += span.redStep;					\      span.green += span.greenStep;				\      span.blue += span.blueStep;				\      span.z += span.zStep;					\   } }#include "swrast/s_tritemp.h"/* * XImage, smooth, depth-buffered, PF_8R8G8B24 triangle. */#define NAME smooth_8R8G8B24_z_triangle#define INTERP_Z 1#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE#define INTERP_RGB 1#define PIXEL_ADDRESS(X,Y) PIXEL_ADDR3(xrb, X, Y)#define PIXEL_TYPE bgr_t#define BYTES_PER_ROW (xrb->ximage->bytes_per_line)#define SETUP_CODE						\   GET_XRB(xrb);#define RENDER_SPAN( span ) {					\   GLuint i;							\   for (i = 0; i < span.end; i++) {				\      const DEPTH_TYPE z = FixedToDepth(span.z);		\      if (z < zRow[i]) {					\	 PIXEL_TYPE *ptr = pRow + i;				\         ptr->r = FixedToInt(span.red);				\         ptr->g = FixedToInt(span.green);			\         ptr->b = FixedToInt(span.blue);			\         zRow[i] = z;						\      }								\      span.red += span.redStep;					\      span.green += span.greenStep;				\      span.blue += span.blueStep;				\      span.z += span.zStep;					\   } }#include "swrast/s_tritemp.h"/* * XImage, smooth, depth-buffered, PF_TRUEDITHER triangle. */#define NAME smooth_TRUEDITHER_z_triangle#define INTERP_Z 1#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE#define INTERP_RGB 1#define SETUP_CODE						\   XMesaContext xmesa = XMESA_CONTEXT(ctx);			\   GET_XRB(xrb);#define RENDER_SPAN( span ) {					\   GLuint i;							\   GLint x = span.x, y = YFLIP(xrb, span.y);			\   for (i = 0; i < span.end; i++, x++) {			\      const DEPTH_TYPE z = FixedToDepth(span.z);		\      if (z < zRow[i]) {					\         unsigned long p;					\         PACK_TRUEDITHER(p, x, y, FixedToInt(span.red),		\            FixedToInt(span.green), FixedToInt(span.blue));	\         XMesaPutPixel(xrb->ximage, x, y, p);			\         zRow[i] = z;						\      }								\      span.red += span.redStep;					\      span.green += span.greenStep;				\      span.blue += span.blueStep;				\      span.z += span.zStep;					\   } }#include "swrast/s_tritemp.h"/* * XImage, smooth, depth-buffered, PF_5R6G5B triangle. */#define NAME smooth_5R6G5B_z_triangle#define INTERP_Z 1#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE#define INTERP_RGB 1#define PIXEL_ADDRESS(X,Y) PIXEL_ADDR2(xrb, X, Y)#define PIXEL_TYPE GLushort#define BYTES_PER_ROW (xrb->ximage->bytes_per_line)#define SETUP_CODE						\   GET_XRB(xrb);#define RENDER_SPAN( span ) {					\   GLuint i;							\   for (i = 0; i < span.end; i++) {				\      const DEPTH_TYPE z = FixedToDepth(span.z);		\      if (z < zRow[i]) {					\         pRow[i] = PACK_5R6G5B(FixedToInt(span.red),		\            FixedToInt(span.green), FixedToInt(span.blue));	\         zRow[i] = z;						\      }								\      span.red += span.redStep;					\      span.green += span.greenStep;				\      span.blue += span.blueStep;				\      span.z += span.zStep;					\   } }#include "swrast/s_tritemp.h"/* * XImage, smooth, depth-buffered, PF_DITHER_5R6G5B triangle. */#define NAME smooth_DITHER_5R6G5B_z_triangle#define INTERP_Z 1#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE#define INTERP_RGB 1#define PIXEL_ADDRESS(X,Y) PIXEL_ADDR2(xrb, X, Y)#define PIXEL_TYPE GLushort#define BYTES_PER_ROW (xrb->ximage->bytes_per_line)#define SETUP_CODE						\   XMesaContext xmesa = XMESA_CONTEXT(ctx);			\   GET_XRB(xrb);#define RENDER_SPAN( span ) {					\   GLuint i;							\   GLint x = span.x, y = YFLIP(xrb, span.y);			\   for (i = 0; i < span.end; i++, x++) {			\      const DEPTH_TYPE z = FixedToDepth(span.z);		\      if (z < zRow[i]) {					\         PACK_TRUEDITHER(pRow[i], x, y, FixedToInt(span.red),	\            FixedToInt(span.green), FixedToInt(span.blue));	\         zRow[i] = z;						\      }								\      span.red += span.redStep;					\      span.green += span.greenStep;				\      span.blue += span.blueStep;				\      span.z += span.zStep;					\   } }#include "swrast/s_tritemp.h"/* * XImage, smooth, depth-buffered, 8-bit, PF_DITHER8 triangle. */#define NAME smooth_DITHER8_z_triangle#define INTERP_Z 1#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE#define INTERP_RGB 1#define PIXEL_ADDRESS(X,Y) PIXEL_ADDR1(xrb, X, Y)#define PIXEL_TYPE GLubyte#define BYTES_PER_ROW (xrb->ximage->bytes_per_line)#define SETUP_CODE						\   GET_XRB(xrb);#define RENDER_SPAN( span ) {					\   GLuint i;							\   GLint x = span.x, y = YFLIP(xrb, span.y);			\   XDITHER_SETUP(y);						\   for (i = 0; i < span.end; i++, x++) {			\      const DEPTH_TYPE z = FixedToDepth(span.z);		\      if (z < zRow[i]) {					\         pRow[i] = (PIXEL_TYPE) XDITHER(x, FixedToInt(span.red),\            FixedToInt(span.green), FixedToInt(span.blue) );	\         zRow[i] = z;						\      }								\      span.red += span.redStep;					\      span.green += span.greenStep;				\      span.blue += span.blueStep;				\      span.z += span.zStep;					\   } }#include "swrast/s_tritemp.h"/* * XImage, smooth, depth-buffered, PF_DITHER triangle. */#define NAME smooth_DITHER_z_triangle#define INTERP_Z 1#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE#define INTERP_RGB 1#define SETUP_CODE						\   GET_XRB(xrb);						\   XMesaImage *img = xrb->ximage;#define RENDER_SPAN( span ) {					\   GLuint i;							\   GLint x = span.x, y = YFLIP(xrb, span.y);			\   XDITHER_SETUP(y);						\   for (i = 0; i < span.end; i++, x++) {			\      const DEPTH_TYPE z = FixedToDepth(span.z);		\      if (z < zRow[i]) {					\         unsigned long p = XDITHER(x, FixedToInt(span.red),	\            FixedToInt(span.green), FixedToInt(span.blue));	\	 XMesaPutPixel(img, x, y, p);			       	\         zRow[i] = z;						\      }								\      span.red += span.redStep;					\      span.green += span.greenStep;				\      span.blue += span.blueStep;				\      span.z += span.zStep;					\   } }#include "swrast/s_tritemp.h"/* * XImage, smooth, depth-buffered, 8-bit PF_LOOKUP triangle. */#define NAME smooth_LOOKUP8_z_triangle#define INTERP_Z 1#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE#define INTERP_RGB 1#define PIXEL_ADDRESS(X,Y) PIXEL_ADDR1(xrb, X, Y)#define PIXEL_TYPE GLubyte#define BYTES_PER_ROW (xrb->ximage->bytes_per_line)#define SETUP_CODE						\   GET_XRB(xrb);#define RENDER_SPAN( span ) {					\   GLuint i;							\   LOOKUP_SETUP;						\   for (i = 0; i < span.end; i++) {				\      const DEPTH_TYPE z = FixedToDepth(span.z);		\      if (z < zRow[i]) {					\         pRow[i] = LOOKUP(FixedToInt(span.red),			\            FixedToInt(span.green), FixedToInt(span.blue));	\         zRow[i] = z;						\      }								\      span.red += span.redStep;					\      span.green += span.greenStep;				\      span.blue += span.blueStep;				\      span.z += span.zStep;					\   } }#include "swrast/s_tritemp.h"/* * XImage, smooth, depth-buffered, 8-bit PF_HPCR triangle. */

⌨️ 快捷键说明

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