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

📄 fxddspan.c

📁 Mesa is an open-source implementation of the OpenGL specification - a system for rendering interacti
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * Mesa 3-D graphics library * Version:  4.0 * * Copyright (C) 1999-2001  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. *//* Authors: *    David Bucciarelli *    Brian Paul *    Daryll Strauss *    Keith Whitwell *    Daniel Borca *    Hiroshi Morii *//* fxdd.c - 3Dfx VooDoo Mesa span and pixel functions */#ifdef HAVE_CONFIG_H#include "conf.h"#endif#if defined(FX)#include "fxdrv.h"#include "fxglidew.h"#include "swrast/swrast.h"/************************************************************************//*****                    Span functions                            *****//************************************************************************/#define DBG 0#define LOCAL_VARS							\    GrBuffer_t currentFB = GR_BUFFER_BACKBUFFER;			\    GLuint pitch = info.strideInBytes;					\    GLuint height = fxMesa->height;					\    char *buf = (char *)((char *)info.lfbPtr + 0 /* x, y offset */);	\    GLuint p;								\    (void) buf; (void) p;#define CLIPPIXEL( _x, _y )	( _x >= minx && _x < maxx &&		\				  _y >= miny && _y < maxy )#define CLIPSPAN( _x, _y, _n, _x1, _n1, _i )				\    if ( _y < miny || _y >= maxy ) {					\	_n1 = 0, _x1 = x;						\    } else {								\	_n1 = _n;							\	_x1 = _x;							\	if ( _x1 < minx ) _i += (minx-_x1), n1 -= (minx-_x1), _x1 = minx;\	if ( _x1 + _n1 >= maxx ) n1 -= (_x1 + n1 - maxx);		\    }#define Y_FLIP(_y)		(height - _y - 1)#define HW_WRITE_LOCK()							\    fxMesaContext fxMesa = FX_CONTEXT(ctx);				\    GrLfbInfo_t info;							\    info.size = sizeof(GrLfbInfo_t);					\    if ( grLfbLock( GR_LFB_WRITE_ONLY,					\                   currentFB, LFB_MODE,					\		   GR_ORIGIN_UPPER_LEFT, FXFALSE, &info ) ) {#define HW_WRITE_UNLOCK()						\	grLfbUnlock( GR_LFB_WRITE_ONLY, currentFB );			\    }#define HW_READ_LOCK()							\    fxMesaContext fxMesa = FX_CONTEXT(ctx);				\    GrLfbInfo_t info;							\    info.size = sizeof(GrLfbInfo_t);					\    if ( grLfbLock( GR_LFB_READ_ONLY, currentFB,			\                    LFB_MODE, GR_ORIGIN_UPPER_LEFT, FXFALSE, &info ) ) {#define HW_READ_UNLOCK()						\	grLfbUnlock( GR_LFB_READ_ONLY, currentFB );			\    }#define HW_WRITE_CLIPLOOP()						\    do {								\	/* remember, we need to flip the scissor, too */		\	/* is it better to do it inside fxDDScissor? */			\	const int minx = fxMesa->clipMinX;				\	const int maxy = Y_FLIP(fxMesa->clipMinY);			\	const int maxx = fxMesa->clipMaxX;				\	const int miny = Y_FLIP(fxMesa->clipMaxY);#define HW_READ_CLIPLOOP()						\    do {								\	/* remember, we need to flip the scissor, too */		\	/* is it better to do it inside fxDDScissor? */			\	const int minx = fxMesa->clipMinX;				\	const int maxy = Y_FLIP(fxMesa->clipMinY);			\	const int maxx = fxMesa->clipMaxX;				\	const int miny = Y_FLIP(fxMesa->clipMaxY);#define HW_ENDCLIPLOOP()						\    } while (0)/* 16 bit, ARGB1555 color spanline and pixel functions */#undef LFB_MODE#define LFB_MODE	GR_LFBWRITEMODE_1555#undef BYTESPERPIXEL#define BYTESPERPIXEL 2#undef INIT_MONO_PIXEL#define INIT_MONO_PIXEL(p, color) \    p = TDFXPACKCOLOR1555( color[RCOMP], color[GCOMP], color[BCOMP], color[ACOMP] )#define WRITE_RGBA( _x, _y, r, g, b, a )				\    *(GLushort *)(buf + _x*BYTESPERPIXEL + _y*pitch) =			\					TDFXPACKCOLOR1555( r, g, b, a )#define WRITE_PIXEL( _x, _y, p )					\    *(GLushort *)(buf + _x*BYTESPERPIXEL + _y*pitch) = p#define READ_RGBA( rgba, _x, _y )					\    do {								\	GLushort p = *(GLushort *)(buf + _x*BYTESPERPIXEL + _y*pitch);	\	rgba[0] = FX_rgb_scale_5[(p >> 10) & 0x1F];			\	rgba[1] = FX_rgb_scale_5[(p >> 5)  & 0x1F];			\	rgba[2] = FX_rgb_scale_5[ p        & 0x1F];			\	rgba[3] = (p & 0x8000) ? 255 : 0;				\    } while (0)#define TAG(x) tdfx##x##_ARGB1555#include "../dri/common/spantmp.h"/* 16 bit, RGB565 color spanline and pixel functions *//* [dBorca] Hack alert: * This is wrong. The alpha value is lost, even when we provide * HW alpha (565 w/o depth buffering). To really update alpha buffer, * we would need to do the 565 writings via 8888 colorformat and rely * on the Voodoo to perform color scaling. In which case our 565 span * would look nicer! But this violates FSAA rules... */#undef LFB_MODE#define LFB_MODE	GR_LFBWRITEMODE_565#undef BYTESPERPIXEL#define BYTESPERPIXEL 2#undef INIT_MONO_PIXEL#define INIT_MONO_PIXEL(p, color) \    p = TDFXPACKCOLOR565( color[RCOMP], color[GCOMP], color[BCOMP] )#define WRITE_RGBA( _x, _y, r, g, b, a )				\    *(GLushort *)(buf + _x*BYTESPERPIXEL + _y*pitch) =			\					TDFXPACKCOLOR565( r, g, b )#define WRITE_PIXEL( _x, _y, p )					\    *(GLushort *)(buf + _x*BYTESPERPIXEL + _y*pitch) = p#define READ_RGBA( rgba, _x, _y )					\    do {								\	GLushort p = *(GLushort *)(buf + _x*BYTESPERPIXEL + _y*pitch);	\	rgba[0] = FX_rgb_scale_5[(p >> 11) & 0x1F];			\	rgba[1] = FX_rgb_scale_6[(p >> 5)  & 0x3F];			\	rgba[2] = FX_rgb_scale_5[ p        & 0x1F];			\	rgba[3] = 0xff;							\    } while (0)#define TAG(x) tdfx##x##_RGB565#include "../dri/common/spantmp.h"/* 32 bit, ARGB8888 color spanline and pixel functions */#undef LFB_MODE#define LFB_MODE	GR_LFBWRITEMODE_8888#undef BYTESPERPIXEL#define BYTESPERPIXEL 4#undef INIT_MONO_PIXEL#define INIT_MONO_PIXEL(p, color) \    p = TDFXPACKCOLOR8888( color[RCOMP], color[GCOMP], color[BCOMP], color[ACOMP] )#define WRITE_RGBA( _x, _y, r, g, b, a )				\    *(GLuint *)(buf + _x*BYTESPERPIXEL + _y*pitch) =			\					TDFXPACKCOLOR8888( r, g, b, a )#define WRITE_PIXEL( _x, _y, p )					\    *(GLuint *)(buf + _x*BYTESPERPIXEL + _y*pitch) = p#define READ_RGBA( rgba, _x, _y )					\    do {								\	GLuint p = *(GLuint *)(buf + _x*BYTESPERPIXEL + _y*pitch);	\        rgba[0] = (p >> 16) & 0xff;					\        rgba[1] = (p >>  8) & 0xff;					\        rgba[2] = (p >>  0) & 0xff;					\        rgba[3] = (p >> 24) & 0xff;					\    } while (0)#define TAG(x) tdfx##x##_ARGB8888#include "../dri/common/spantmp.h"/************************************************************************//*****                    Depth functions                           *****//************************************************************************/#define DBG 0#undef HW_WRITE_LOCK#undef HW_WRITE_UNLOCK#undef HW_READ_LOCK#undef HW_READ_UNLOCK#define HW_CLIPLOOP HW_WRITE_CLIPLOOP#define LOCAL_DEPTH_VARS						\    GLuint pitch = info.strideInBytes;					\    GLuint height = fxMesa->height;					\    char *buf = (char *)((char *)info.lfbPtr + 0 /* x, y offset */);	\    (void) buf;#define HW_WRITE_LOCK()							\    fxMesaContext fxMesa = FX_CONTEXT(ctx);				\    GrLfbInfo_t info;							\    info.size = sizeof(GrLfbInfo_t);					\    if ( grLfbLock( GR_LFB_WRITE_ONLY,					\                   GR_BUFFER_AUXBUFFER, LFB_MODE,			\		   GR_ORIGIN_UPPER_LEFT, FXFALSE, &info ) ) {#define HW_WRITE_UNLOCK()						\	grLfbUnlock( GR_LFB_WRITE_ONLY, GR_BUFFER_AUXBUFFER);		\    }#define HW_READ_LOCK()							\    fxMesaContext fxMesa = FX_CONTEXT(ctx);				\    GrLfbInfo_t info;							\    info.size = sizeof(GrLfbInfo_t);					\    if ( grLfbLock( GR_LFB_READ_ONLY, GR_BUFFER_AUXBUFFER,		\                    LFB_MODE, GR_ORIGIN_UPPER_LEFT, FXFALSE, &info ) ) {#define HW_READ_UNLOCK()						\	grLfbUnlock( GR_LFB_READ_ONLY, GR_BUFFER_AUXBUFFER);		\    }/* 16 bit, depth spanline and pixel functions */#undef LFB_MODE#define LFB_MODE	GR_LFBWRITEMODE_ZA16#undef BYTESPERPIXEL#define BYTESPERPIXEL 2#define VALUE_TYPE GLushort#define WRITE_DEPTH( _x, _y, d )					\    *(GLushort *)(buf + _x*BYTESPERPIXEL + _y*pitch) = d#define READ_DEPTH( d, _x, _y )						\    d = *(GLushort *)(buf + _x*BYTESPERPIXEL + _y*pitch)#define TAG(x) tdfx##x##_Z16#include "../dri/common/depthtmp.h"/* 24 bit, depth spanline and pixel functions (for use w/ stencil) *//* [dBorca] Hack alert: * This is evil. The incoming Mesa's 24bit depth value * is shifted left 8 bits, to obtain a full 32bit value, * which will be thrown into the framebuffer. We rely on * the fact that Voodoo hardware transforms a 32bit value * into 24bit value automatically and, MOST IMPORTANT, won't * alter the upper 8bits of the value already existing in the * framebuffer (where stencil resides). */#undef LFB_MODE#define LFB_MODE	GR_LFBWRITEMODE_Z32#undef BYTESPERPIXEL#define BYTESPERPIXEL 4#define VALUE_TYPE GLuint#define WRITE_DEPTH( _x, _y, d )					\    *(GLuint *)(buf + _x*BYTESPERPIXEL + _y*pitch) = d << 8#define READ_DEPTH( d, _x, _y )						\    d = (*(GLuint *)(buf + _x*BYTESPERPIXEL + _y*pitch)) & 0xffffff#define TAG(x) tdfx##x##_Z24#include "../dri/common/depthtmp.h"/* 32 bit, depth spanline and pixel functions (for use w/o stencil) *//* [dBorca] Hack alert:

⌨️ 快捷键说明

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