📄 utils.c
字号:
else if (mapping == GL_SIGNED_IDENTITY_NV) return GL_UNSIGNED_INVERT_NV;
FIXME("Unhandled mapping %#x\n", mapping);
return mapping;
}
static void get_src_and_opr_nvrc(DWORD stage, DWORD arg, BOOL is_alpha, GLenum* input, GLenum* mapping, GLenum *component_usage, INT texture_idx) {
/* The WINED3DTA_COMPLEMENT flag specifies the complement of the input should
* be used. */
if (arg & WINED3DTA_COMPLEMENT) *mapping = GL_UNSIGNED_INVERT_NV;
else *mapping = GL_SIGNED_IDENTITY_NV;
/* The WINED3DTA_ALPHAREPLICATE flag specifies the alpha component of the input
* should be used for all input components. */
if (is_alpha || arg & WINED3DTA_ALPHAREPLICATE) *component_usage = GL_ALPHA;
else *component_usage = GL_RGB;
*input = d3dta_to_combiner_input(arg & WINED3DTA_SELECTMASK, stage, texture_idx);
}
typedef struct {
GLenum input[3];
GLenum mapping[3];
GLenum component_usage[3];
} tex_op_args;
static BOOL is_invalid_op(IWineD3DDeviceImpl *This, int stage, WINED3DTEXTUREOP op, DWORD arg1, DWORD arg2, DWORD arg3) {
if (op == WINED3DTOP_DISABLE) return FALSE;
if (This->stateBlock->textures[stage]) return FALSE;
if ((arg1 & WINED3DTA_SELECTMASK) == WINED3DTA_TEXTURE
&& op != WINED3DTOP_SELECTARG2) return TRUE;
if ((arg2 & WINED3DTA_SELECTMASK) == WINED3DTA_TEXTURE
&& op != WINED3DTOP_SELECTARG1) return TRUE;
if ((arg3 & WINED3DTA_SELECTMASK) == WINED3DTA_TEXTURE
&& (op == WINED3DTOP_MULTIPLYADD || op == WINED3DTOP_LERP)) return TRUE;
return FALSE;
}
void set_tex_op_nvrc(IWineD3DDevice *iface, BOOL is_alpha, int stage, WINED3DTEXTUREOP op, DWORD arg1, DWORD arg2, DWORD arg3, INT texture_idx) {
IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl*)iface;
tex_op_args tex_op_args = {{0}, {0}, {0}};
GLenum portion = is_alpha ? GL_ALPHA : GL_RGB;
GLenum target = GL_COMBINER0_NV + stage;
TRACE("stage %d, is_alpha %d, op %s, arg1 %#x, arg2 %#x, arg3 %#x, texture_idx %d\n",
stage, is_alpha, debug_d3dtop(op), arg1, arg2, arg3, texture_idx);
/* If a texture stage references an invalid texture unit the stage just
* passes through the result from the previous stage */
if (is_invalid_op(This, stage, op, arg1, arg2, arg3)) {
arg1 = WINED3DTA_CURRENT;
op = WINED3DTOP_SELECTARG1;
}
get_src_and_opr_nvrc(stage, arg1, is_alpha, &tex_op_args.input[0],
&tex_op_args.mapping[0], &tex_op_args.component_usage[0], texture_idx);
get_src_and_opr_nvrc(stage, arg2, is_alpha, &tex_op_args.input[1],
&tex_op_args.mapping[1], &tex_op_args.component_usage[1], texture_idx);
get_src_and_opr_nvrc(stage, arg3, is_alpha, &tex_op_args.input[2],
&tex_op_args.mapping[2], &tex_op_args.component_usage[2], texture_idx);
/* This is called by a state handler which has the gl lock held and a context for the thread */
switch(op)
{
case WINED3DTOP_DISABLE:
/* Only for alpha */
if (!is_alpha) ERR("Shouldn't be called for WINED3DTSS_COLOROP (WINED3DTOP_DISABLE)\n");
/* Input, prev_alpha*1 */
GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
GL_SPARE0_NV, GL_UNSIGNED_IDENTITY_NV, GL_ALPHA));
GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
GL_ZERO, GL_UNSIGNED_INVERT_NV, GL_ALPHA));
/* Output */
GL_EXTCALL(glCombinerOutputNV(target, portion, GL_SPARE0_NV, GL_DISCARD_NV,
GL_DISCARD_NV, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
break;
case WINED3DTOP_SELECTARG1:
case WINED3DTOP_SELECTARG2:
/* Input, arg*1 */
if (op == WINED3DTOP_SELECTARG1) {
GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
tex_op_args.input[0], tex_op_args.mapping[0], tex_op_args.component_usage[0]));
} else {
GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
tex_op_args.input[1], tex_op_args.mapping[1], tex_op_args.component_usage[1]));
}
GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
GL_ZERO, GL_UNSIGNED_INVERT_NV, portion));
/* Output */
GL_EXTCALL(glCombinerOutputNV(target, portion, GL_SPARE0_NV, GL_DISCARD_NV,
GL_DISCARD_NV, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
break;
case WINED3DTOP_MODULATE:
case WINED3DTOP_MODULATE2X:
case WINED3DTOP_MODULATE4X:
/* Input, arg1*arg2 */
GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
tex_op_args.input[0], tex_op_args.mapping[0], tex_op_args.component_usage[0]));
GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
tex_op_args.input[1], tex_op_args.mapping[1], tex_op_args.component_usage[1]));
/* Output */
if (op == WINED3DTOP_MODULATE) {
GL_EXTCALL(glCombinerOutputNV(target, portion, GL_SPARE0_NV, GL_DISCARD_NV,
GL_DISCARD_NV, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
} else if (op == WINED3DTOP_MODULATE2X) {
GL_EXTCALL(glCombinerOutputNV(target, portion, GL_SPARE0_NV, GL_DISCARD_NV,
GL_DISCARD_NV, GL_SCALE_BY_TWO_NV, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
} else if (op == WINED3DTOP_MODULATE4X) {
GL_EXTCALL(glCombinerOutputNV(target, portion, GL_SPARE0_NV, GL_DISCARD_NV,
GL_DISCARD_NV, GL_SCALE_BY_FOUR_NV, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
}
break;
case WINED3DTOP_ADD:
case WINED3DTOP_ADDSIGNED:
case WINED3DTOP_ADDSIGNED2X:
/* Input, arg1*1+arg2*1 */
GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
tex_op_args.input[0], tex_op_args.mapping[0], tex_op_args.component_usage[0]));
GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
GL_ZERO, GL_UNSIGNED_INVERT_NV, portion));
GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_C_NV,
tex_op_args.input[1], tex_op_args.mapping[1], tex_op_args.component_usage[1]));
GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_D_NV,
GL_ZERO, GL_UNSIGNED_INVERT_NV, portion));
/* Output */
if (op == WINED3DTOP_ADD) {
GL_EXTCALL(glCombinerOutputNV(target, portion, GL_DISCARD_NV, GL_DISCARD_NV,
GL_SPARE0_NV, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
} else if (op == WINED3DTOP_ADDSIGNED) {
GL_EXTCALL(glCombinerOutputNV(target, portion, GL_DISCARD_NV, GL_DISCARD_NV,
GL_SPARE0_NV, GL_NONE, GL_BIAS_BY_NEGATIVE_ONE_HALF_NV, GL_FALSE, GL_FALSE, GL_FALSE));
} else if (op == WINED3DTOP_ADDSIGNED2X) {
GL_EXTCALL(glCombinerOutputNV(target, portion, GL_DISCARD_NV, GL_DISCARD_NV,
GL_SPARE0_NV, GL_SCALE_BY_TWO_NV, GL_BIAS_BY_NEGATIVE_ONE_HALF_NV, GL_FALSE, GL_FALSE, GL_FALSE));
}
break;
case WINED3DTOP_SUBTRACT:
/* Input, arg1*1+-arg2*1 */
GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
tex_op_args.input[0], tex_op_args.mapping[0], tex_op_args.component_usage[0]));
GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
GL_ZERO, GL_UNSIGNED_INVERT_NV, portion));
GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_C_NV,
tex_op_args.input[1], GL_SIGNED_NEGATE_NV, tex_op_args.component_usage[1]));
GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_D_NV,
GL_ZERO, GL_UNSIGNED_INVERT_NV, portion));
/* Output */
GL_EXTCALL(glCombinerOutputNV(target, portion, GL_DISCARD_NV, GL_DISCARD_NV,
GL_SPARE0_NV, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
break;
case WINED3DTOP_ADDSMOOTH:
/* Input, arg1*1+(1-arg1)*arg2 */
GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
tex_op_args.input[0], tex_op_args.mapping[0], tex_op_args.component_usage[0]));
GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
GL_ZERO, GL_UNSIGNED_INVERT_NV, portion));
GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_C_NV,
tex_op_args.input[0], invert_mapping(tex_op_args.mapping[0]), tex_op_args.component_usage[0]));
GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_D_NV,
tex_op_args.input[1], tex_op_args.mapping[1], tex_op_args.component_usage[1]));
/* Output */
GL_EXTCALL(glCombinerOutputNV(target, portion, GL_DISCARD_NV, GL_DISCARD_NV,
GL_SPARE0_NV, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
break;
case WINED3DTOP_BLENDDIFFUSEALPHA:
case WINED3DTOP_BLENDTEXTUREALPHA:
case WINED3DTOP_BLENDFACTORALPHA:
case WINED3DTOP_BLENDTEXTUREALPHAPM:
case WINED3DTOP_BLENDCURRENTALPHA:
{
GLenum alpha_src = GL_PRIMARY_COLOR_NV;
if (op == WINED3DTOP_BLENDDIFFUSEALPHA) alpha_src = d3dta_to_combiner_input(WINED3DTA_DIFFUSE, stage, texture_idx);
else if (op == WINED3DTOP_BLENDTEXTUREALPHA) alpha_src = d3dta_to_combiner_input(WINED3DTA_TEXTURE, stage, texture_idx);
else if (op == WINED3DTOP_BLENDFACTORALPHA) alpha_src = d3dta_to_combiner_input(WINED3DTA_TFACTOR, stage, texture_idx);
else if (op == WINED3DTOP_BLENDTEXTUREALPHAPM) alpha_src = d3dta_to_combiner_input(WINED3DTA_TEXTURE, stage, texture_idx);
else if (op == WINED3DTOP_BLENDCURRENTALPHA) alpha_src = d3dta_to_combiner_input(WINED3DTA_CURRENT, stage, texture_idx);
else FIXME("Unhandled WINED3DTOP %s, shouldn't happen\n", debug_d3dtop(op));
/* Input, arg1*alpha_src+arg2*(1-alpha_src) */
GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
tex_op_args.input[0], tex_op_args.mapping[0], tex_op_args.component_usage[0]));
if (op == WINED3DTOP_BLENDTEXTUREALPHAPM)
{
GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
GL_ZERO, GL_UNSIGNED_INVERT_NV, portion));
} else {
GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
alpha_src, GL_UNSIGNED_IDENTITY_NV, GL_ALPHA));
}
GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_C_NV,
tex_op_args.input[1], tex_op_args.mapping[1], tex_op_args.component_usage[1]));
GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_D_NV,
alpha_src, GL_UNSIGNED_INVERT_NV, GL_ALPHA));
/* Output */
GL_EXTCALL(glCombinerOutputNV(target, portion, GL_DISCARD_NV, GL_DISCARD_NV,
GL_SPARE0_NV, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
break;
}
case WINED3DTOP_MODULATEALPHA_ADDCOLOR:
/* Input, arg1_alpha*arg2_rgb+arg1_rgb*1 */
if (is_alpha) ERR("Only supported for WINED3DTSS_COLOROP (WINED3DTOP_MODULATEALPHA_ADDCOLOR)\n");
GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
tex_op_args.input[0], tex_op_args.mapping[0], GL_ALPHA));
GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
tex_op_args.input[1], tex_op_args.mapping[1], tex_op_args.component_usage[1]));
GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_C_NV,
tex_op_args.input[0], tex_op_args.mapping[0], tex_op_args.component_usage[0]));
GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_D_NV,
GL_ZERO, GL_UNSIGNED_INVERT_NV, portion));
/* Output */
GL_EXTCALL(glCombinerOutputNV(target, portion, GL_DISCARD_NV, GL_DISCARD_NV,
GL_SPARE0_NV, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
break;
case WINED3DTOP_MODULAT
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -