wined3d: Introduce D3D7+ normal matrix computation.

This commit is contained in:
Matteo Bruni 2015-04-23 22:41:12 +02:00 committed by Alexandre Julliard
parent bc68b30d20
commit b963c73abb
8 changed files with 243 additions and 47 deletions

View File

@ -283,18 +283,13 @@ static void lighting_test(void)
unsigned int size;
DWORD expected;
const char *message;
BOOL todo;
}
tests[] =
{
{&mat, nquad, sizeof(nquad[0]), 0x000000ff,
"Lit quad with light", FALSE},
{&mat_singular, nquad, sizeof(nquad[0]), 0x000000ff,
"Lit quad with singular world matrix", FALSE},
{&mat_transf, rotatedquad, sizeof(rotatedquad[0]), 0x000000ff,
"Lit quad with transformation matrix", FALSE},
{&mat_nonaffine, translatedquad, sizeof(translatedquad[0]), 0x00000000,
"Lit quad with non-affine matrix", TRUE},
{&mat, nquad, sizeof(nquad[0]), 0x000000ff, "Lit quad with light"},
{&mat_singular, nquad, sizeof(nquad[0]), 0x000000ff, "Lit quad with singular world matrix"},
{&mat_transf, rotatedquad, sizeof(rotatedquad[0]), 0x000000ff, "Lit quad with transformation matrix"},
{&mat_nonaffine, translatedquad, sizeof(translatedquad[0]), 0x00000000, "Lit quad with non-affine matrix"},
};
window = CreateWindowA("static", "d3d8_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
@ -397,10 +392,7 @@ static void lighting_test(void)
ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
color = getPixelColor(device, 320, 240);
if (tests[i].todo)
todo_wine ok(color == tests[i].expected, "%s has color 0x%08x.\n", tests[i].message, color);
else
ok(color == tests[i].expected, "%s has color 0x%08x.\n", tests[i].message, color);
ok(color == tests[i].expected, "%s has color 0x%08x.\n", tests[i].message, color);
}
refcount = IDirect3DDevice8_Release(device);

View File

@ -367,18 +367,13 @@ static void lighting_test(void)
unsigned int size;
DWORD expected;
const char *message;
BOOL todo;
}
tests[] =
{
{&mat, nquad, sizeof(nquad[0]), 0x000000ff,
"Lit quad with light", FALSE},
{&mat_singular, nquad, sizeof(nquad[0]), 0x000000ff,
"Lit quad with singular world matrix", FALSE},
{&mat_transf, rotatedquad, sizeof(rotatedquad[0]), 0x000000ff,
"Lit quad with transformation matrix", FALSE},
{&mat_nonaffine, translatedquad, sizeof(translatedquad[0]), 0x00000000,
"Lit quad with non-affine matrix", TRUE},
{&mat, nquad, sizeof(nquad[0]), 0x000000ff, "Lit quad with light"},
{&mat_singular, nquad, sizeof(nquad[0]), 0x000000ff, "Lit quad with singular world matrix"},
{&mat_transf, rotatedquad, sizeof(rotatedquad[0]), 0x000000ff, "Lit quad with transformation matrix"},
{&mat_nonaffine, translatedquad, sizeof(translatedquad[0]), 0x00000000, "Lit quad with non-affine matrix"},
};
window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
@ -481,10 +476,7 @@ static void lighting_test(void)
ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
color = getPixelColor(device, 320, 240);
if (tests[i].todo)
todo_wine ok(color == tests[i].expected, "%s has color 0x%08x.\n", tests[i].message, color);
else
ok(color == tests[i].expected, "%s has color 0x%08x.\n", tests[i].message, color);
ok(color == tests[i].expected, "%s has color 0x%08x.\n", tests[i].message, color);
}
hr = IDirect3DDevice9_SetTransform(device, D3DTS_WORLD, &mat);

View File

@ -4832,7 +4832,7 @@ static const struct wined3d_device_parent_ops ddraw_wined3d_device_parent_ops =
device_parent_create_swapchain,
};
HRESULT ddraw_init(struct ddraw *ddraw, enum wined3d_device_type device_type)
HRESULT ddraw_init(struct ddraw *ddraw, DWORD flags, enum wined3d_device_type device_type)
{
WINED3DCAPS caps;
HRESULT hr;
@ -4849,9 +4849,11 @@ HRESULT ddraw_init(struct ddraw *ddraw, enum wined3d_device_type device_type)
ddraw->numIfaces = 1;
ddraw->ref7 = 1;
if (!(ddraw->wined3d = wined3d_create(DDRAW_WINED3D_FLAGS)))
flags |= DDRAW_WINED3D_FLAGS;
if (!(ddraw->wined3d = wined3d_create(flags)))
{
if (!(ddraw->wined3d = wined3d_create(DDRAW_WINED3D_FLAGS | WINED3D_NO3D)))
flags |= WINED3D_NO3D;
if (!(ddraw->wined3d = wined3d_create(flags)))
{
WARN("Failed to create a wined3d object.\n");
return E_FAIL;

View File

@ -122,7 +122,7 @@ struct ddraw
#define DDRAW_WINDOW_CLASS_NAME "DirectDrawDeviceWnd"
HRESULT ddraw_init(struct ddraw *ddraw, enum wined3d_device_type device_type) DECLSPEC_HIDDEN;
HRESULT ddraw_init(struct ddraw *ddraw, DWORD flags, enum wined3d_device_type device_type) DECLSPEC_HIDDEN;
void ddraw_d3dcaps1_from_7(D3DDEVICEDESC *caps1, D3DDEVICEDESC7 *caps7) DECLSPEC_HIDDEN;
void ddraw_destroy_swapchain(struct ddraw *ddraw) DECLSPEC_HIDDEN;
HRESULT ddraw_get_d3dcaps(const struct ddraw *ddraw, D3DDEVICEDESC7 *caps) DECLSPEC_HIDDEN;

View File

@ -230,15 +230,13 @@ DDRAW_Create(const GUID *guid,
enum wined3d_device_type device_type;
struct ddraw *ddraw;
HRESULT hr;
DWORD flags = 0;
TRACE("driver_guid %s, ddraw %p, outer_unknown %p, interface_iid %s.\n",
debugstr_guid(guid), DD, UnkOuter, debugstr_guid(iid));
*DD = NULL;
/* We don't care about this guids. Well, there's no special guid anyway
* OK, we could
*/
if (guid == (GUID *) DDCREATE_EMULATIONONLY)
{
/* Use the reference device id. This doesn't actually change anything,
@ -260,6 +258,9 @@ DDRAW_Create(const GUID *guid,
if (UnkOuter != NULL)
return CLASS_E_NOAGGREGATION;
if (!IsEqualGUID(iid, &IID_IDirectDraw7))
flags = WINED3D_LEGACY_FFP_LIGHTING;
/* DirectDraw creation comes here */
ddraw = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*ddraw));
if (!ddraw)
@ -268,7 +269,7 @@ DDRAW_Create(const GUID *guid,
return E_OUTOFMEMORY;
}
hr = ddraw_init(ddraw, device_type);
hr = ddraw_init(ddraw, flags, device_type);
if (FAILED(hr))
{
WARN("Failed to initialize ddraw object, hr %#x.\n", hr);

View File

@ -3495,14 +3495,13 @@ static void test_lighting(void)
void *quad;
DWORD expected;
const char *message;
BOOL todo;
}
tests[] =
{
{&mat, nquad, 0x000000ff, "Lit quad with light", FALSE},
{&mat_singular, nquad, 0x000000ff, "Lit quad with singular world matrix", FALSE},
{&mat_transf, rotatedquad, 0x000000ff, "Lit quad with transformation matrix", FALSE},
{&mat_nonaffine, translatedquad, 0x00000000, "Lit quad with non-affine matrix", TRUE},
{&mat, nquad, 0x000000ff, "Lit quad with light"},
{&mat_singular, nquad, 0x000000ff, "Lit quad with singular world matrix"},
{&mat_transf, rotatedquad, 0x000000ff, "Lit quad with transformation matrix"},
{&mat_nonaffine, translatedquad, 0x00000000, "Lit quad with non-affine matrix"},
};
HWND window;
@ -3609,10 +3608,7 @@ static void test_lighting(void)
ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
color = get_surface_color(rt, 320, 240);
if (tests[i].todo)
todo_wine ok(color == tests[i].expected, "%s has color 0x%08x.\n", tests[i].message, color);
else
ok(color == tests[i].expected, "%s has color 0x%08x.\n", tests[i].message, color);
ok(color == tests[i].expected, "%s has color 0x%08x.\n", tests[i].message, color);
}
IDirectDrawSurface7_Release(rt);

View File

@ -816,6 +816,218 @@ static BOOL invert_matrix_3d(struct wined3d_matrix *out, const struct wined3d_ma
return TRUE;
}
static void swap_rows(float **a, float **b)
{
float *tmp = *a;
*a = *b;
*b = tmp;
}
static BOOL invert_matrix(struct wined3d_matrix *out, struct wined3d_matrix *m)
{
float wtmp[4][8];
float m0, m1, m2, m3, s;
float *r0, *r1, *r2, *r3;
r0 = wtmp[0];
r1 = wtmp[1];
r2 = wtmp[2];
r3 = wtmp[3];
r0[0] = m->_11;
r0[1] = m->_12;
r0[2] = m->_13;
r0[3] = m->_14;
r0[4] = 1.0f;
r0[5] = r0[6] = r0[7] = 0.0f;
r1[0] = m->_21;
r1[1] = m->_22;
r1[2] = m->_23;
r1[3] = m->_24;
r1[5] = 1.0f;
r1[4] = r1[6] = r1[7] = 0.0f;
r2[0] = m->_31;
r2[1] = m->_32;
r2[2] = m->_33;
r2[3] = m->_34;
r2[6] = 1.0f;
r2[4] = r2[5] = r2[7] = 0.0f;
r3[0] = m->_41;
r3[1] = m->_42;
r3[2] = m->_43;
r3[3] = m->_44;
r3[7] = 1.0f;
r3[4] = r3[5] = r3[6] = 0.0f;
/* Choose pivot - or die. */
if (fabsf(r3[0]) > fabsf(r2[0]))
swap_rows(&r3, &r2);
if (fabsf(r2[0]) > fabsf(r1[0]))
swap_rows(&r2, &r1);
if (fabsf(r1[0]) > fabsf(r0[0]))
swap_rows(&r1, &r0);
if (r0[0] == 0.0f)
return FALSE;
/* Eliminate first variable. */
m1 = r1[0] / r0[0]; m2 = r2[0] / r0[0]; m3 = r3[0] / r0[0];
s = r0[1]; r1[1] -= m1 * s; r2[1] -= m2 * s; r3[1] -= m3 * s;
s = r0[2]; r1[2] -= m1 * s; r2[2] -= m2 * s; r3[2] -= m3 * s;
s = r0[3]; r1[3] -= m1 * s; r2[3] -= m2 * s; r3[3] -= m3 * s;
s = r0[4];
if (s != 0.0f)
{
r1[4] -= m1 * s;
r2[4] -= m2 * s;
r3[4] -= m3 * s;
}
s = r0[5];
if (s != 0.0f)
{
r1[5] -= m1 * s;
r2[5] -= m2 * s;
r3[5] -= m3 * s;
}
s = r0[6];
if (s != 0.0f)
{
r1[6] -= m1 * s;
r2[6] -= m2 * s;
r3[6] -= m3 * s;
}
s = r0[7];
if (s != 0.0f)
{
r1[7] -= m1 * s;
r2[7] -= m2 * s;
r3[7] -= m3 * s;
}
/* Choose pivot - or die. */
if (fabsf(r3[1]) > fabsf(r2[1]))
swap_rows(&r3, &r2);
if (fabsf(r2[1]) > fabsf(r1[1]))
swap_rows(&r2, &r1);
if (r1[1] == 0.0f)
return FALSE;
/* Eliminate second variable. */
m2 = r2[1] / r1[1]; m3 = r3[1] / r1[1];
r2[2] -= m2 * r1[2]; r3[2] -= m3 * r1[2];
r2[3] -= m2 * r1[3]; r3[3] -= m3 * r1[3];
s = r1[4];
if (s != 0.0f)
{
r2[4] -= m2 * s;
r3[4] -= m3 * s;
}
s = r1[5];
if (s != 0.0f)
{
r2[5] -= m2 * s;
r3[5] -= m3 * s;
}
s = r1[6];
if (s != 0.0f)
{
r2[6] -= m2 * s;
r3[6] -= m3 * s;
}
s = r1[7];
if (s != 0.0f)
{
r2[7] -= m2 * s;
r3[7] -= m3 * s;
}
/* Choose pivot - or die. */
if (fabsf(r3[2]) > fabsf(r2[2]))
swap_rows(&r3, &r2);
if (r2[2] == 0.0f)
return FALSE;
/* Eliminate third variable. */
m3 = r3[2] / r2[2];
r3[3] -= m3 * r2[3];
r3[4] -= m3 * r2[4];
r3[5] -= m3 * r2[5];
r3[6] -= m3 * r2[6];
r3[7] -= m3 * r2[7];
/* Last check. */
if (r3[3] == 0.0f)
return FALSE;
/* Back substitute row 3. */
s = 1.0f / r3[3];
r3[4] *= s;
r3[5] *= s;
r3[6] *= s;
r3[7] *= s;
/* Back substitute row 2. */
m2 = r2[3];
s = 1.0f / r2[2];
r2[4] = s * (r2[4] - r3[4] * m2);
r2[5] = s * (r2[5] - r3[5] * m2);
r2[6] = s * (r2[6] - r3[6] * m2);
r2[7] = s * (r2[7] - r3[7] * m2);
m1 = r1[3];
r1[4] -= r3[4] * m1;
r1[5] -= r3[5] * m1;
r1[6] -= r3[6] * m1;
r1[7] -= r3[7] * m1;
m0 = r0[3];
r0[4] -= r3[4] * m0;
r0[5] -= r3[5] * m0;
r0[6] -= r3[6] * m0;
r0[7] -= r3[7] * m0;
/* Back substitute row 1. */
m1 = r1[2];
s = 1.0f / r1[1];
r1[4] = s * (r1[4] - r2[4] * m1);
r1[5] = s * (r1[5] - r2[5] * m1);
r1[6] = s * (r1[6] - r2[6] * m1);
r1[7] = s * (r1[7] - r2[7] * m1);
m0 = r0[2];
r0[4] -= r2[4] * m0;
r0[5] -= r2[5] * m0;
r0[6] -= r2[6] * m0;
r0[7] -= r2[7] * m0;
/* Back substitute row 0. */
m0 = r0[1];
s = 1.0f / r0[0];
r0[4] = s * (r0[4] - r1[4] * m0);
r0[5] = s * (r0[5] - r1[5] * m0);
r0[6] = s * (r0[6] - r1[6] * m0);
r0[7] = s * (r0[7] - r1[7] * m0);
out->_11 = r0[4];
out->_12 = r0[5];
out->_13 = r0[6];
out->_14 = r0[7];
out->_21 = r1[4];
out->_22 = r1[5];
out->_23 = r1[6];
out->_24 = r1[7];
out->_31 = r2[4];
out->_32 = r2[5];
out->_33 = r2[6];
out->_34 = r2[7];
out->_41 = r3[4];
out->_42 = r3[5];
out->_43 = r3[6];
out->_44 = r3[7];
return TRUE;
}
static void shader_glsl_ffp_vertex_normalmatrix_uniform(const struct wined3d_context *context,
const struct wined3d_state *state, struct glsl_shader_prog_link *prog)
{
@ -824,11 +1036,11 @@ static void shader_glsl_ffp_vertex_normalmatrix_uniform(const struct wined3d_con
struct wined3d_matrix mv;
unsigned int i, j;
/* gl_NormalMatrix is defined in the OpenGL spec as "transpose of the
* inverse of the upper leftmost 3x3 of gl_ModelViewMatrix" and that
* seems to be correct for D3D too. */
get_modelview_matrix(context, state, &mv);
invert_matrix_3d(&mv, &mv);
if (context->swapchain->device->wined3d->flags & WINED3D_LEGACY_FFP_LIGHTING)
invert_matrix_3d(&mv, &mv);
else
invert_matrix(&mv, &mv);
/* Tests show that singular modelview matrices are used unchanged as normal
* matrices on D3D3 and older. There seems to be no clearly consistent
* behavior on newer D3D versions so always follow older ddraw behavior. */

View File

@ -1248,6 +1248,7 @@ enum wined3d_display_rotation
#define WINED3D_FOCUS_MESSAGES 0x00000020
#define WINED3D_HANDLE_RESTORE 0x00000040
#define WINED3D_PIXEL_CENTER_INTEGER 0x00000080
#define WINED3D_LEGACY_FFP_LIGHTING 0x00000100
#define WINED3D_RESZ_CODE 0x7fa05000