diff options
Diffstat (limited to 'src/mesa/main/texstate.c')
-rw-r--r-- | src/mesa/main/texstate.c | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/src/mesa/main/texstate.c b/src/mesa/main/texstate.c index aa99b0667cb..830b230b5d7 100644 --- a/src/mesa/main/texstate.c +++ b/src/mesa/main/texstate.c @@ -376,6 +376,107 @@ _mesa_update_texture_matrices(struct gl_context *ctx) /** + * Translate GL combiner state into a MODE_x value + */ +static uint32_t +tex_combine_translate_mode(GLenum envMode, GLenum mode) +{ + switch (mode) { + case GL_REPLACE: return TEXENV_MODE_REPLACE; + case GL_MODULATE: return TEXENV_MODE_MODULATE; + case GL_ADD: + if (envMode == GL_COMBINE4_NV) + return TEXENV_MODE_ADD_PRODUCTS_NV; + else + return TEXENV_MODE_ADD; + case GL_ADD_SIGNED: + if (envMode == GL_COMBINE4_NV) + return TEXENV_MODE_ADD_PRODUCTS_SIGNED_NV; + else + return TEXENV_MODE_ADD_SIGNED; + case GL_INTERPOLATE: return TEXENV_MODE_INTERPOLATE; + case GL_SUBTRACT: return TEXENV_MODE_SUBTRACT; + case GL_DOT3_RGB: return TEXENV_MODE_DOT3_RGB; + case GL_DOT3_RGB_EXT: return TEXENV_MODE_DOT3_RGB_EXT; + case GL_DOT3_RGBA: return TEXENV_MODE_DOT3_RGBA; + case GL_DOT3_RGBA_EXT: return TEXENV_MODE_DOT3_RGBA_EXT; + case GL_MODULATE_ADD_ATI: return TEXENV_MODE_MODULATE_ADD_ATI; + case GL_MODULATE_SIGNED_ADD_ATI: return TEXENV_MODE_MODULATE_SIGNED_ADD_ATI; + case GL_MODULATE_SUBTRACT_ATI: return TEXENV_MODE_MODULATE_SUBTRACT_ATI; + default: + unreachable("Invalid TexEnv Combine mode"); + } +} + + +static uint8_t +tex_combine_translate_source(GLenum src) +{ + switch (src) { + case GL_TEXTURE0: + case GL_TEXTURE1: + case GL_TEXTURE2: + case GL_TEXTURE3: + case GL_TEXTURE4: + case GL_TEXTURE5: + case GL_TEXTURE6: + case GL_TEXTURE7: return TEXENV_SRC_TEXTURE0 + (src - GL_TEXTURE0); + case GL_TEXTURE: return TEXENV_SRC_TEXTURE; + case GL_PREVIOUS: return TEXENV_SRC_PREVIOUS; + case GL_PRIMARY_COLOR: return TEXENV_SRC_PRIMARY_COLOR; + case GL_CONSTANT: return TEXENV_SRC_CONSTANT; + case GL_ZERO: return TEXENV_SRC_ZERO; + case GL_ONE: return TEXENV_SRC_ONE; + default: + unreachable("Invalid TexEnv Combine argument source"); + } +} + + +static uint8_t +tex_combine_translate_operand(GLenum operand) +{ + switch (operand) { + case GL_SRC_COLOR: return TEXENV_OPR_COLOR; + case GL_ONE_MINUS_SRC_COLOR: return TEXENV_OPR_ONE_MINUS_COLOR; + case GL_SRC_ALPHA: return TEXENV_OPR_ALPHA; + case GL_ONE_MINUS_SRC_ALPHA: return TEXENV_OPR_ONE_MINUS_ALPHA; + default: + unreachable("Invalid TexEnv Combine argument source"); + } +} + + +static void +pack_tex_combine(struct gl_texture_unit *texUnit) +{ + struct gl_tex_env_combine_state *state = texUnit->_CurrentCombine; + struct gl_tex_env_combine_packed *packed = &texUnit->_CurrentCombinePacked; + + memset(packed, 0, sizeof *packed); + + packed->ModeRGB = tex_combine_translate_mode(texUnit->EnvMode, state->ModeRGB); + packed->ModeA = tex_combine_translate_mode(texUnit->EnvMode, state->ModeA); + packed->ScaleShiftRGB = state->ScaleShiftRGB; + packed->ScaleShiftA = state->ScaleShiftA; + packed->NumArgsRGB = state->_NumArgsRGB; + packed->NumArgsA = state->_NumArgsA; + + for (int i = 0; i < state->_NumArgsRGB; ++i) + { + packed->ArgsRGB[i].Source = tex_combine_translate_source(state->SourceRGB[i]); + packed->ArgsRGB[i].Operand = tex_combine_translate_operand(state->OperandRGB[i]); + } + + for (int i = 0; i < state->_NumArgsA; ++i) + { + packed->ArgsA[i].Source = tex_combine_translate_source(state->SourceA[i]); + packed->ArgsA[i].Operand = tex_combine_translate_operand(state->OperandA[i]); + } +} + + +/** * Examine texture unit's combine/env state to update derived state. */ static void @@ -467,6 +568,8 @@ update_tex_combine(struct gl_context *ctx, struct gl_texture_unit *texUnit) _mesa_problem(ctx, "invalid Alpha combine mode in update_texture_state"); break; } + + pack_tex_combine(texUnit); } static void |