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

📄 r300_state.c

📁 Mesa is an open-source implementation of the OpenGL specification - a system for rendering interacti
💻 C
📖 第 1 页 / 共 5 页
字号:
/*Copyright (C) The Weather Channel, Inc.  2002.Copyright (C) 2004 Nicolai Haehnle.All Rights Reserved.The Weather Channel (TM) funded Tungsten Graphics to develop theinitial release of the Radeon 8500 driver under the XFree86 license.This notice must be preserved.Permission is hereby granted, free of charge, to any person obtaininga copy of this software and associated documentation files (the"Software"), to deal in the Software without restriction, includingwithout limitation the rights to use, copy, modify, merge, publish,distribute, sublicense, and/or sell copies of the Software, and topermit persons to whom the Software is furnished to do so, subject tothe following conditions:The above copyright notice and this permission notice (including thenext paragraph) shall be included in all copies or substantialportions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OFMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BELIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTIONOF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTIONWITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.**************************************************************************//** * \file * * \author Nicolai Haehnle <prefect_@gmx.net> */#include "glheader.h"#include "state.h"#include "imports.h"#include "enums.h"#include "macros.h"#include "context.h"#include "dd.h"#include "simple_list.h"#include "api_arrayelt.h"#include "swrast/swrast.h"#include "swrast_setup/swrast_setup.h"#include "shader/prog_parameter.h"#include "shader/prog_statevars.h"#include "vbo/vbo.h"#include "tnl/tnl.h"#include "texformat.h"#include "radeon_ioctl.h"#include "radeon_state.h"#include "r300_context.h"#include "r300_ioctl.h"#include "r300_state.h"#include "r300_reg.h"#include "r300_emit.h"#include "r300_fragprog.h"#include "r300_tex.h"#include "drirenderbuffer.h"extern int future_hw_tcl_on;extern void _tnl_UpdateFixedFunctionProgram(GLcontext * ctx);static void r300BlendColor(GLcontext * ctx, const GLfloat cf[4]){	r300ContextPtr rmesa = R300_CONTEXT(ctx);	R300_STATECHANGE(rmesa, blend_color);	if (rmesa->radeon.radeonScreen->chip_family >= CHIP_FAMILY_RV515) {		GLuint r = IROUND(cf[0]*1023.0f);		GLuint g = IROUND(cf[1]*1023.0f);		GLuint b = IROUND(cf[2]*1023.0f);		GLuint a = IROUND(cf[3]*1023.0f);		rmesa->hw.blend_color.cmd[1] = r | (a << 16);		rmesa->hw.blend_color.cmd[2] = b | (g << 16);	} else {		GLubyte color[4];		CLAMPED_FLOAT_TO_UBYTE(color[0], cf[0]);		CLAMPED_FLOAT_TO_UBYTE(color[1], cf[1]);		CLAMPED_FLOAT_TO_UBYTE(color[2], cf[2]);		CLAMPED_FLOAT_TO_UBYTE(color[3], cf[3]);		rmesa->hw.blend_color.cmd[1] = PACK_COLOR_8888(color[3], color[0],							color[1], color[2]);	}}/** * Calculate the hardware blend factor setting.  This same function is used * for source and destination of both alpha and RGB. * * \returns * The hardware register value for the specified blend factor.  This value * will need to be shifted into the correct position for either source or * destination factor. * * \todo * Since the two cases where source and destination are handled differently * are essentially error cases, they should never happen.  Determine if these * cases can be removed. */static int blend_factor(GLenum factor, GLboolean is_src){	switch (factor) {	case GL_ZERO:		return R300_BLEND_GL_ZERO;		break;	case GL_ONE:		return R300_BLEND_GL_ONE;		break;	case GL_DST_COLOR:		return R300_BLEND_GL_DST_COLOR;		break;	case GL_ONE_MINUS_DST_COLOR:		return R300_BLEND_GL_ONE_MINUS_DST_COLOR;		break;	case GL_SRC_COLOR:		return R300_BLEND_GL_SRC_COLOR;		break;	case GL_ONE_MINUS_SRC_COLOR:		return R300_BLEND_GL_ONE_MINUS_SRC_COLOR;		break;	case GL_SRC_ALPHA:		return R300_BLEND_GL_SRC_ALPHA;		break;	case GL_ONE_MINUS_SRC_ALPHA:		return R300_BLEND_GL_ONE_MINUS_SRC_ALPHA;		break;	case GL_DST_ALPHA:		return R300_BLEND_GL_DST_ALPHA;		break;	case GL_ONE_MINUS_DST_ALPHA:		return R300_BLEND_GL_ONE_MINUS_DST_ALPHA;		break;	case GL_SRC_ALPHA_SATURATE:		return (is_src) ? R300_BLEND_GL_SRC_ALPHA_SATURATE :		    R300_BLEND_GL_ZERO;		break;	case GL_CONSTANT_COLOR:		return R300_BLEND_GL_CONST_COLOR;		break;	case GL_ONE_MINUS_CONSTANT_COLOR:		return R300_BLEND_GL_ONE_MINUS_CONST_COLOR;		break;	case GL_CONSTANT_ALPHA:		return R300_BLEND_GL_CONST_ALPHA;		break;	case GL_ONE_MINUS_CONSTANT_ALPHA:		return R300_BLEND_GL_ONE_MINUS_CONST_ALPHA;		break;	default:		fprintf(stderr, "unknown blend factor %x\n", factor);		return (is_src) ? R300_BLEND_GL_ONE : R300_BLEND_GL_ZERO;		break;	}}/** * Sets both the blend equation and the blend function. * This is done in a single * function because some blend equations (i.e., \c GL_MIN and \c GL_MAX) * change the interpretation of the blend function. * Also, make sure that blend function and blend equation are set to their * default value if color blending is not enabled, since at least blend * equations GL_MIN and GL_FUNC_REVERSE_SUBTRACT will cause wrong results * otherwise for unknown reasons. *//* helper function */static void r300SetBlendCntl(r300ContextPtr r300, int func, int eqn,			     int cbits, int funcA, int eqnA){	GLuint new_ablend, new_cblend;#if 0	fprintf(stderr,		"eqnA=%08x funcA=%08x eqn=%08x func=%08x cbits=%08x\n",		eqnA, funcA, eqn, func, cbits);#endif	new_ablend = eqnA | funcA;	new_cblend = eqn | func;	/* Some blend factor combinations don't seem to work when the	 * BLEND_NO_SEPARATE bit is set.	 *	 * Especially problematic candidates are the ONE_MINUS_* flags,	 * but I can't see a real pattern.	 */#if 0	if (new_ablend == new_cblend) {		new_cblend |= R300_DISCARD_SRC_PIXELS_SRC_ALPHA_0;	}#endif	new_cblend |= cbits;	if ((new_ablend != r300->hw.bld.cmd[R300_BLD_ABLEND]) ||	    (new_cblend != r300->hw.bld.cmd[R300_BLD_CBLEND])) {		R300_STATECHANGE(r300, bld);		r300->hw.bld.cmd[R300_BLD_ABLEND] = new_ablend;		r300->hw.bld.cmd[R300_BLD_CBLEND] = new_cblend;	}}static void r300SetBlendState(GLcontext * ctx){	r300ContextPtr r300 = R300_CONTEXT(ctx);	int func = (R300_BLEND_GL_ONE << R300_SRC_BLEND_SHIFT) |	    (R300_BLEND_GL_ZERO << R300_DST_BLEND_SHIFT);	int eqn = R300_COMB_FCN_ADD_CLAMP;	int funcA = (R300_BLEND_GL_ONE << R300_SRC_BLEND_SHIFT) |	    (R300_BLEND_GL_ZERO << R300_DST_BLEND_SHIFT);	int eqnA = R300_COMB_FCN_ADD_CLAMP;	if (RGBA_LOGICOP_ENABLED(ctx) || !ctx->Color.BlendEnabled) {		r300SetBlendCntl(r300, func, eqn, 0, func, eqn);		return;	}	func =	    (blend_factor(ctx->Color.BlendSrcRGB, GL_TRUE) <<	     R300_SRC_BLEND_SHIFT) | (blend_factor(ctx->Color.BlendDstRGB,						   GL_FALSE) <<				      R300_DST_BLEND_SHIFT);	switch (ctx->Color.BlendEquationRGB) {	case GL_FUNC_ADD:		eqn = R300_COMB_FCN_ADD_CLAMP;		break;	case GL_FUNC_SUBTRACT:		eqn = R300_COMB_FCN_SUB_CLAMP;		break;	case GL_FUNC_REVERSE_SUBTRACT:		eqn = R300_COMB_FCN_RSUB_CLAMP;		break;	case GL_MIN:		eqn = R300_COMB_FCN_MIN;		func = (R300_BLEND_GL_ONE << R300_SRC_BLEND_SHIFT) |		    (R300_BLEND_GL_ONE << R300_DST_BLEND_SHIFT);		break;	case GL_MAX:		eqn = R300_COMB_FCN_MAX;		func = (R300_BLEND_GL_ONE << R300_SRC_BLEND_SHIFT) |		    (R300_BLEND_GL_ONE << R300_DST_BLEND_SHIFT);		break;	default:		fprintf(stderr,			"[%s:%u] Invalid RGB blend equation (0x%04x).\n",			__FUNCTION__, __LINE__, ctx->Color.BlendEquationRGB);		return;	}	funcA =	    (blend_factor(ctx->Color.BlendSrcA, GL_TRUE) <<	     R300_SRC_BLEND_SHIFT) | (blend_factor(ctx->Color.BlendDstA,						   GL_FALSE) <<				      R300_DST_BLEND_SHIFT);	switch (ctx->Color.BlendEquationA) {	case GL_FUNC_ADD:		eqnA = R300_COMB_FCN_ADD_CLAMP;		break;	case GL_FUNC_SUBTRACT:		eqnA = R300_COMB_FCN_SUB_CLAMP;		break;	case GL_FUNC_REVERSE_SUBTRACT:		eqnA = R300_COMB_FCN_RSUB_CLAMP;		break;	case GL_MIN:		eqnA = R300_COMB_FCN_MIN;		funcA = (R300_BLEND_GL_ONE << R300_SRC_BLEND_SHIFT) |		    (R300_BLEND_GL_ONE << R300_DST_BLEND_SHIFT);		break;	case GL_MAX:		eqnA = R300_COMB_FCN_MAX;		funcA = (R300_BLEND_GL_ONE << R300_SRC_BLEND_SHIFT) |		    (R300_BLEND_GL_ONE << R300_DST_BLEND_SHIFT);		break;	default:		fprintf(stderr,			"[%s:%u] Invalid A blend equation (0x%04x).\n",			__FUNCTION__, __LINE__, ctx->Color.BlendEquationA);		return;	}	r300SetBlendCntl(r300,			 func, eqn,			 (R300_SEPARATE_ALPHA_ENABLE |			  R300_READ_ENABLE |			  R300_ALPHA_BLEND_ENABLE), funcA, eqnA);}static void r300BlendEquationSeparate(GLcontext * ctx,				      GLenum modeRGB, GLenum modeA){	r300SetBlendState(ctx);}static void r300BlendFuncSeparate(GLcontext * ctx,				  GLenum sfactorRGB, GLenum dfactorRGB,				  GLenum sfactorA, GLenum dfactorA){	r300SetBlendState(ctx);}/** * Translate LogicOp enums into hardware representation. * Both use a very logical bit-wise layout, but unfortunately the order * of bits is reversed. */static GLuint translate_logicop(GLenum logicop){	GLuint bits = logicop - GL_CLEAR;	bits = ((bits & 1) << 3) | ((bits & 2) << 1) | ((bits & 4) >> 1) | ((bits & 8) >> 3);	return bits << R300_RB3D_ROPCNTL_ROP_SHIFT;}/** * Used internally to update the r300->hw hardware state to match the * current OpenGL state. */static void r300SetLogicOpState(GLcontext *ctx){	r300ContextPtr r300 = R300_CONTEXT(ctx);	R300_STATECHANGE(r300, rop);	if (RGBA_LOGICOP_ENABLED(ctx)) {		r300->hw.rop.cmd[1] = R300_RB3D_ROPCNTL_ROP_ENABLE |			translate_logicop(ctx->Color.LogicOp);	} else {		r300->hw.rop.cmd[1] = 0;	}}/** * Called by Mesa when an application program changes the LogicOp state * via glLogicOp. */static void r300LogicOpcode(GLcontext *ctx, GLenum logicop){	if (RGBA_LOGICOP_ENABLED(ctx))		r300SetLogicOpState(ctx);}static void r300ClipPlane( GLcontext *ctx, GLenum plane, const GLfloat *eq ){	r300ContextPtr rmesa = R300_CONTEXT(ctx);	GLint p;	GLint *ip;	/* no VAP UCP on non-TCL chipsets */	if (!(rmesa->radeon.radeonScreen->chip_flags & RADEON_CHIPSET_TCL))			return;	p = (GLint) plane - (GLint) GL_CLIP_PLANE0;	ip = (GLint *)ctx->Transform._ClipUserPlane[p];	R300_STATECHANGE( rmesa, vpucp[p] );	rmesa->hw.vpucp[p].cmd[R300_VPUCP_X] = ip[0];	rmesa->hw.vpucp[p].cmd[R300_VPUCP_Y] = ip[1];	rmesa->hw.vpucp[p].cmd[R300_VPUCP_Z] = ip[2];	rmesa->hw.vpucp[p].cmd[R300_VPUCP_W] = ip[3];}static void r300SetClipPlaneState(GLcontext * ctx, GLenum cap, GLboolean state){	r300ContextPtr r300 = R300_CONTEXT(ctx);	GLuint p;	/* no VAP UCP on non-TCL chipsets */	if (!(r300->radeon.radeonScreen->chip_flags & RADEON_CHIPSET_TCL))		return;	p = cap - GL_CLIP_PLANE0;	R300_STATECHANGE(r300, vap_clip_cntl);	if (state) {		r300->hw.vap_clip_cntl.cmd[1] |= (R300_VAP_UCP_ENABLE_0 << p);		r300ClipPlane(ctx, cap, NULL);	} else {		r300->hw.vap_clip_cntl.cmd[1] &= ~(R300_VAP_UCP_ENABLE_0 << p);	}}/** * Update our tracked culling state based on Mesa's state. */static void r300UpdateCulling(GLcontext * ctx){	r300ContextPtr r300 = R300_CONTEXT(ctx);	uint32_t val = 0;	if (ctx->Polygon.CullFlag) {		switch (ctx->Polygon.CullFaceMode) {		case GL_FRONT:			val = R300_CULL_FRONT;			break;		case GL_BACK:			val = R300_CULL_BACK;			break;		case GL_FRONT_AND_BACK:			val = R300_CULL_FRONT | R300_CULL_BACK;			break;		default:			break;		}	}	switch (ctx->Polygon.FrontFace) {	case GL_CW:		val |= R300_FRONT_FACE_CW;		break;	case GL_CCW:		val |= R300_FRONT_FACE_CCW;		break;	default:		break;	}	R300_STATECHANGE(r300, cul);	r300->hw.cul.cmd[R300_CUL_CULL] = val;}static void r300SetPolygonOffsetState(GLcontext * ctx, GLboolean state){	r300ContextPtr r300 = R300_CONTEXT(ctx);	R300_STATECHANGE(r300, occlusion_cntl);	if (state) {		r300->hw.occlusion_cntl.cmd[1] |= (3 << 0);	} else {		r300->hw.occlusion_cntl.cmd[1] &= ~(3 << 0);	}}static GLboolean current_fragment_program_writes_depth(GLcontext* ctx){	r300ContextPtr r300 = R300_CONTEXT(ctx);	if (r300->radeon.radeonScreen->chip_family < CHIP_FAMILY_RV515) {		struct r300_fragment_program *fp = (struct r300_fragment_program *)

⌨️ 快捷键说明

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