diff options
author | Gustaw Smolarczyk <[email protected]> | 2017-03-30 20:09:30 +0200 |
---|---|---|
committer | Marek Olšák <[email protected]> | 2017-04-08 20:29:58 +0200 |
commit | 837ad2dc384096d936fd65e30374129f36e09335 (patch) | |
tree | 2ea6f0e8abcb2144563e6505b456d23d1430c5dd /src/mesa/main | |
parent | 6fa34de8308fd4abc2fb23aa9071a35cb08552c9 (diff) |
mesa/main: Maintain compressed TexEnv Combine state.
Signed-off-by: Gustaw Smolarczyk <[email protected]>
Signed-off-by: Marek Olšák <[email protected]>
Diffstat (limited to 'src/mesa/main')
-rw-r--r-- | src/mesa/main/mtypes.h | 83 | ||||
-rw-r--r-- | src/mesa/main/texstate.c | 103 |
2 files changed, 186 insertions, 0 deletions
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h index 4986e42d1b3..e5f7cbaa5bc 100644 --- a/src/mesa/main/mtypes.h +++ b/src/mesa/main/mtypes.h @@ -1078,6 +1078,87 @@ struct gl_tex_env_combine_state }; +/** Compressed TexEnv effective Combine mode */ +enum gl_tex_env_mode +{ + TEXENV_MODE_REPLACE, /* r = a0 */ + TEXENV_MODE_MODULATE, /* r = a0 * a1 */ + TEXENV_MODE_ADD, /* r = a0 + a1 */ + TEXENV_MODE_ADD_SIGNED, /* r = a0 + a1 - 0.5 */ + TEXENV_MODE_INTERPOLATE, /* r = a0 * a2 + a1 * (1 - a2) */ + TEXENV_MODE_SUBTRACT, /* r = a0 - a1 */ + TEXENV_MODE_DOT3_RGB, /* r = a0 . a1 */ + TEXENV_MODE_DOT3_RGB_EXT, /* r = a0 . a1 */ + TEXENV_MODE_DOT3_RGBA, /* r = a0 . a1 */ + TEXENV_MODE_DOT3_RGBA_EXT, /* r = a0 . a1 */ + TEXENV_MODE_MODULATE_ADD_ATI, /* r = a0 * a2 + a1 */ + TEXENV_MODE_MODULATE_SIGNED_ADD_ATI, /* r = a0 * a2 + a1 - 0.5 */ + TEXENV_MODE_MODULATE_SUBTRACT_ATI, /* r = a0 * a2 - a1 */ + TEXENV_MODE_ADD_PRODUCTS_NV, /* r = a0 * a1 + a2 * a3 */ + TEXENV_MODE_ADD_PRODUCTS_SIGNED_NV, /* r = a0 * a1 + a2 * a3 - 0.5 */ +}; + + +/** Compressed TexEnv Combine source */ +enum gl_tex_env_source +{ + TEXENV_SRC_TEXTURE0, + TEXENV_SRC_TEXTURE1, + TEXENV_SRC_TEXTURE2, + TEXENV_SRC_TEXTURE3, + TEXENV_SRC_TEXTURE4, + TEXENV_SRC_TEXTURE5, + TEXENV_SRC_TEXTURE6, + TEXENV_SRC_TEXTURE7, + TEXENV_SRC_TEXTURE, + TEXENV_SRC_PREVIOUS, + TEXENV_SRC_PRIMARY_COLOR, + TEXENV_SRC_CONSTANT, + TEXENV_SRC_ZERO, + TEXENV_SRC_ONE, +}; + + +/** Compressed TexEnv Combine operand */ +enum gl_tex_env_operand +{ + TEXENV_OPR_COLOR, + TEXENV_OPR_ONE_MINUS_COLOR, + TEXENV_OPR_ALPHA, + TEXENV_OPR_ONE_MINUS_ALPHA, +}; + + +/** Compressed TexEnv Combine argument */ +struct gl_tex_env_argument +{ +#ifdef __GNUC__ + __extension__ uint8_t Source:4; /**< TEXENV_SRC_x */ + __extension__ uint8_t Operand:2; /**< TEXENV_OPR_x */ +#else + uint8_t Source; /**< SRC_x */ + uint8_t Operand; /**< OPR_x */ +#endif +}; + + +/*** + * Compressed TexEnv Combine state. + */ +struct gl_tex_env_combine_packed +{ + uint32_t ModeRGB:4; /**< Effective mode for RGB as 4 bits */ + uint32_t ModeA:4; /**< Effective mode for RGB as 4 bits */ + uint32_t ScaleShiftRGB:2; /**< 0, 1 or 2 */ + uint32_t ScaleShiftA:2; /**< 0, 1 or 2 */ + uint32_t NumArgsRGB:3; /**< Number of inputs used for the RGB combiner */ + uint32_t NumArgsA:3; /**< Number of inputs used for the A combiner */ + /** Source arguments in a packed manner */ + struct gl_tex_env_argument ArgsRGB[MAX_COMBINER_TERMS]; + struct gl_tex_env_argument ArgsA[MAX_COMBINER_TERMS]; +}; + + /** * TexGenEnabled flags. */ @@ -1180,6 +1261,8 @@ struct gl_texture_unit /** Points to highest priority, complete and enabled texture object */ struct gl_texture_object *_Current; + /** Current compressed TexEnv & Combine state */ + struct gl_tex_env_combine_packed _CurrentCombinePacked; }; 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 |