Commit 74cda79a authored by Matteo Bruni's avatar Matteo Bruni Committed by Alexandre Julliard

wined3d: Introduce a get_texture_matrix() function.

parent 2d270f31
...@@ -3278,12 +3278,10 @@ void tex_alphaop(struct wined3d_context *context, const struct wined3d_state *st ...@@ -3278,12 +3278,10 @@ void tex_alphaop(struct wined3d_context *context, const struct wined3d_state *st
void transform_texture(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) void transform_texture(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
{ {
DWORD texUnit = (state_id - STATE_TEXTURESTAGE(0, 0)) / (WINED3D_HIGHEST_TEXTURE_STATE + 1);
const struct wined3d_device *device = context->swapchain->device;
const struct wined3d_gl_info *gl_info = context->gl_info; const struct wined3d_gl_info *gl_info = context->gl_info;
DWORD mapped_stage = context->tex_unit_map[texUnit]; unsigned int tex = (state_id - STATE_TEXTURESTAGE(0, 0)) / (WINED3D_HIGHEST_TEXTURE_STATE + 1);
BOOL generated; unsigned int mapped_stage = context->tex_unit_map[tex];
int coordIdx; struct wined3d_matrix mat;
/* Ignore this when a vertex shader is used, or if the streams aren't sorted out yet */ /* Ignore this when a vertex shader is used, or if the streams aren't sorted out yet */
if (use_vs(state) || isStateDirty(context, STATE_VDECL)) if (use_vs(state) || isStateDirty(context, STATE_VDECL))
...@@ -3296,31 +3294,13 @@ void transform_texture(struct wined3d_context *context, const struct wined3d_sta ...@@ -3296,31 +3294,13 @@ void transform_texture(struct wined3d_context *context, const struct wined3d_sta
if (mapped_stage >= gl_info->limits.textures) return; if (mapped_stage >= gl_info->limits.textures) return;
context_active_texture(context, gl_info, mapped_stage); context_active_texture(context, gl_info, mapped_stage);
generated = (state->texture_states[texUnit][WINED3D_TSS_TEXCOORD_INDEX] & 0xffff0000) != WINED3DTSS_TCI_PASSTHRU; gl_info->gl_ops.gl.p_glMatrixMode(GL_TEXTURE);
coordIdx = min(state->texture_states[texUnit][WINED3D_TSS_TEXCOORD_INDEX & 0x0000ffff], MAX_TEXTURES - 1); checkGLcall("glMatrixMode(GL_TEXTURE)");
set_texture_matrix(gl_info, &state->transforms[WINED3D_TS_TEXTURE0 + texUnit], get_texture_matrix(context, state, mapped_stage, &mat);
state->texture_states[texUnit][WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS],
generated, context->last_was_rhw, gl_info->gl_ops.gl.p_glLoadMatrixf(&mat._11);
context->stream_info.use_map & (1 << (WINED3D_FFP_TEXCOORD0 + coordIdx)) checkGLcall("glLoadMatrixf");
? context->stream_info.elements[WINED3D_FFP_TEXCOORD0 + coordIdx].format->id
: WINED3DFMT_UNKNOWN,
device->shader_backend->shader_has_ffp_proj_control(device->shader_priv));
/* The sampler applying function calls us if this changes */
if ((context->lastWasPow2Texture & (1 << texUnit)) && state->textures[texUnit])
{
if(generated) {
FIXME("Non-power2 texture being used with generated texture coords\n");
}
/* NP2 texcoord fixup is implemented for pixelshaders so only enable the
fixed-function-pipeline fixup via pow2Matrix when no PS is used. */
if (!use_ps(state))
{
TRACE("Non power two matrix multiply fixup\n");
gl_info->gl_ops.gl.p_glMultMatrixf(state->textures[texUnit]->pow2_matrix);
}
}
} }
static void unload_tex_coords(const struct wined3d_gl_info *gl_info) static void unload_tex_coords(const struct wined3d_gl_info *gl_info)
......
...@@ -3203,19 +3203,15 @@ void get_projection_matrix(const struct wined3d_context *context, const struct w ...@@ -3203,19 +3203,15 @@ void get_projection_matrix(const struct wined3d_context *context, const struct w
} }
/* Setup this textures matrix according to the texture flags. */ /* Setup this textures matrix according to the texture flags. */
/* Context activation is done by the caller (state handler). */ static void compute_texture_matrix(const struct wined3d_gl_info *gl_info, const struct wined3d_matrix *matrix,
void set_texture_matrix(const struct wined3d_gl_info *gl_info, const struct wined3d_matrix *matrix, DWORD flags, DWORD flags, BOOL calculated_coords, BOOL transformed, enum wined3d_format_id format_id,
BOOL calculated_coords, BOOL transformed, enum wined3d_format_id format_id, BOOL ffp_proj_control) BOOL ffp_proj_control, struct wined3d_matrix *out_matrix)
{ {
struct wined3d_matrix mat; struct wined3d_matrix mat;
gl_info->gl_ops.gl.p_glMatrixMode(GL_TEXTURE);
checkGLcall("glMatrixMode(GL_TEXTURE)");
if (flags == WINED3D_TTFF_DISABLE || flags == WINED3D_TTFF_COUNT1 || transformed) if (flags == WINED3D_TTFF_DISABLE || flags == WINED3D_TTFF_COUNT1 || transformed)
{ {
gl_info->gl_ops.gl.p_glLoadIdentity(); get_identity_matrix(out_matrix);
checkGLcall("glLoadIdentity()");
return; return;
} }
...@@ -3314,8 +3310,39 @@ void set_texture_matrix(const struct wined3d_gl_info *gl_info, const struct wine ...@@ -3314,8 +3310,39 @@ void set_texture_matrix(const struct wined3d_gl_info *gl_info, const struct wine
} }
} }
gl_info->gl_ops.gl.p_glLoadMatrixf(&mat._11); *out_matrix = mat;
checkGLcall("glLoadMatrixf(mat)"); }
void get_texture_matrix(const struct wined3d_context *context, const struct wined3d_state *state,
unsigned int tex, struct wined3d_matrix *mat)
{
const struct wined3d_device *device = context->swapchain->device;
const struct wined3d_gl_info *gl_info = context->gl_info;
BOOL generated = (state->texture_states[tex][WINED3D_TSS_TEXCOORD_INDEX] & 0xffff0000)
!= WINED3DTSS_TCI_PASSTHRU;
unsigned int coord_idx = min(state->texture_states[tex][WINED3D_TSS_TEXCOORD_INDEX & 0x0000ffff],
MAX_TEXTURES - 1);
compute_texture_matrix(gl_info, &state->transforms[WINED3D_TS_TEXTURE0 + tex],
state->texture_states[tex][WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS],
generated, context->last_was_rhw,
context->stream_info.use_map & (1 << (WINED3D_FFP_TEXCOORD0 + coord_idx))
? context->stream_info.elements[WINED3D_FFP_TEXCOORD0 + coord_idx].format->id
: WINED3DFMT_UNKNOWN,
device->shader_backend->shader_has_ffp_proj_control(device->shader_priv), mat);
if ((context->lastWasPow2Texture & (1 << tex)) && state->textures[tex])
{
if (generated)
FIXME("Non-power-of-two texture being used with generated texture coords.\n");
/* NP2 texcoord fixup is implemented for pixelshaders so only enable the
* fixed-function-pipeline fixup via pow2Matrix when no PS is used. */
if (!use_ps(state))
{
TRACE("Non-power-of-two texture matrix multiply fixup.\n");
multiply_matrix(mat, mat, (struct wined3d_matrix *)state->textures[tex]->pow2_matrix);
}
}
} }
/* This small helper function is used to convert a bitmask into the number of masked bits */ /* This small helper function is used to convert a bitmask into the number of masked bits */
......
...@@ -2782,9 +2782,6 @@ BOOL is_invalid_op(const struct wined3d_state *state, int stage, ...@@ -2782,9 +2782,6 @@ BOOL is_invalid_op(const struct wined3d_state *state, int stage,
void set_tex_op_nvrc(const struct wined3d_gl_info *gl_info, const struct wined3d_state *state, void set_tex_op_nvrc(const struct wined3d_gl_info *gl_info, const struct wined3d_state *state,
BOOL is_alpha, int stage, enum wined3d_texture_op op, DWORD arg1, DWORD arg2, DWORD arg3, BOOL is_alpha, int stage, enum wined3d_texture_op op, DWORD arg1, DWORD arg2, DWORD arg3,
INT texture_idx, DWORD dst) DECLSPEC_HIDDEN; INT texture_idx, DWORD dst) DECLSPEC_HIDDEN;
void set_texture_matrix(const struct wined3d_gl_info *gl_info, const struct wined3d_matrix *matrix,
DWORD flags, BOOL calculated_coords, BOOL transformed, enum wined3d_format_id format_id,
BOOL ffp_can_disable_proj) DECLSPEC_HIDDEN;
void texture_activate_dimensions(const struct wined3d_texture *texture, void texture_activate_dimensions(const struct wined3d_texture *texture,
const struct wined3d_gl_info *gl_info) DECLSPEC_HIDDEN; const struct wined3d_gl_info *gl_info) DECLSPEC_HIDDEN;
void sampler_texdim(struct wined3d_context *context, void sampler_texdim(struct wined3d_context *context,
...@@ -3039,6 +3036,8 @@ void get_modelview_matrix(const struct wined3d_context *context, const struct wi ...@@ -3039,6 +3036,8 @@ void get_modelview_matrix(const struct wined3d_context *context, const struct wi
struct wined3d_matrix *mat) DECLSPEC_HIDDEN; struct wined3d_matrix *mat) DECLSPEC_HIDDEN;
void get_projection_matrix(const struct wined3d_context *context, const struct wined3d_state *state, void get_projection_matrix(const struct wined3d_context *context, const struct wined3d_state *state,
struct wined3d_matrix *mat) DECLSPEC_HIDDEN; struct wined3d_matrix *mat) DECLSPEC_HIDDEN;
void get_texture_matrix(const struct wined3d_context *context, const struct wined3d_state *state,
unsigned int tex, struct wined3d_matrix *mat) DECLSPEC_HIDDEN;
/* Using additional shader constants (uniforms in GLSL / program environment /* Using additional shader constants (uniforms in GLSL / program environment
* or local parameters in ARB) is costly: * or local parameters in ARB) is costly:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment