Commit eb6e8307 authored by Lionel Ulmer's avatar Lionel Ulmer Committed by Alexandre Julliard

Implement GetTransform and rework a bit the matrices storage.

parent 7a025001
......@@ -181,6 +181,11 @@ struct IDirect3DDeviceImpl
IDirectDrawSurfaceImpl *current_texture[MAX_TEXTURES];
/* Current transformation matrices */
D3DMATRIX *world_mat;
D3DMATRIX *view_mat;
D3DMATRIX *proj_mat;
void (*set_context)(IDirect3DDeviceImpl*);
HRESULT (*clear)(IDirect3DDeviceImpl *This,
DWORD dwCount,
......
......@@ -211,7 +211,32 @@ Main_IDirect3DDeviceImpl_7_3T_2T_GetTransform(LPDIRECT3DDEVICE7 iface,
LPD3DMATRIX lpD3DMatrix)
{
ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
FIXME("(%p/%p)->(%08x,%p): stub!\n", This, iface, dtstTransformStateType, lpD3DMatrix);
TRACE("(%p/%p)->(%08x,%p)\n", This, iface, dtstTransformStateType, lpD3DMatrix);
switch (dtstTransformStateType) {
case D3DTRANSFORMSTATE_WORLD: {
TRACE(" returning D3DTRANSFORMSTATE_WORLD :\n");
memcpy(lpD3DMatrix, This->world_mat, 16 * sizeof(D3DVALUE));
dump_mat(lpD3DMatrix);
} break;
case D3DTRANSFORMSTATE_VIEW: {
TRACE(" returning D3DTRANSFORMSTATE_VIEW :\n");
memcpy(lpD3DMatrix, This->world_mat, 16 * sizeof(D3DVALUE));
dump_mat(lpD3DMatrix);
} break;
case D3DTRANSFORMSTATE_PROJECTION: {
TRACE(" returning D3DTRANSFORMSTATE_PROJECTION :\n");
memcpy(lpD3DMatrix, This->world_mat, 16 * sizeof(D3DVALUE));
dump_mat(lpD3DMatrix);
} break;
default:
ERR("Unknown transform type %08x !!!\n", dtstTransformStateType);
return DDERR_INVALIDPARAMS;
}
return DD_OK;
}
......
......@@ -306,6 +306,10 @@ GL_IDirect3DDeviceImpl_7_3T_2T_1T_Release(LPDIRECT3DDEVICE7 iface)
/* And warn the D3D object that this device is no longer active... */
This->d3d->removed_device(This->d3d, This);
HeapFree(GetProcessHeap(), 0, This->world_mat);
HeapFree(GetProcessHeap(), 0, This->view_mat);
HeapFree(GetProcessHeap(), 0, This->proj_mat);
ENTER_GL();
glXDestroyContext(glThis->display, glThis->gl_context);
LEAVE_GL();
......@@ -624,25 +628,31 @@ GL_IDirect3DDeviceImpl_7_3T_2T_SetTransform(LPDIRECT3DDEVICE7 iface,
switch (dtstTransformStateType) {
case D3DTRANSFORMSTATE_WORLD: {
TRACE(" D3DTRANSFORMSTATE_WORLD :\n");
conv_mat(lpD3DMatrix, glThis->world_mat);
conv_mat(lpD3DMatrix, This->world_mat);
if (glThis->last_vertices_transformed == FALSE) {
glMatrixMode(GL_MODELVIEW);
glLoadMatrixf((float *) glThis->view_mat);
glMultMatrixf((float *) glThis->world_mat);
glLoadMatrixf((float *) This->view_mat);
glMultMatrixf((float *) This->world_mat);
}
} break;
case D3DTRANSFORMSTATE_VIEW: {
TRACE(" D3DTRANSFORMSTATE_VIEW :\n");
conv_mat(lpD3DMatrix, glThis->view_mat);
conv_mat(lpD3DMatrix, This->view_mat);
if (glThis->last_vertices_transformed == FALSE) {
glMatrixMode(GL_MODELVIEW);
glLoadMatrixf((float *) glThis->view_mat);
glMultMatrixf((float *) glThis->world_mat);
glLoadMatrixf((float *) This->view_mat);
glMultMatrixf((float *) This->world_mat);
}
} break;
case D3DTRANSFORMSTATE_PROJECTION: {
TRACE(" D3DTRANSFORMSTATE_PROJECTION :\n");
conv_mat(lpD3DMatrix, glThis->proj_mat);
conv_mat(lpD3DMatrix, This->proj_mat);
if (glThis->last_vertices_transformed == FALSE) {
glMatrixMode(GL_PROJECTION);
glLoadMatrixf((float *) glThis->proj_mat);
glLoadMatrixf((float *) This->proj_mat);
}
} break;
default:
......@@ -651,9 +661,6 @@ GL_IDirect3DDeviceImpl_7_3T_2T_SetTransform(LPDIRECT3DDEVICE7 iface,
}
LEAVE_GL();
/* And set the 'matrix changed' flag */
glThis->matrices_changed = TRUE;
return DD_OK;
}
......@@ -696,26 +703,26 @@ static void draw_primitive_start_GL(D3DPRIMITIVETYPE d3dpt)
}
}
static void draw_primitive_handle_GL_state(IDirect3DDeviceGLImpl *glThis,
static void draw_primitive_handle_GL_state(IDirect3DDeviceImpl *This,
BOOLEAN vertex_transformed,
BOOLEAN vertex_lit) {
IDirect3DDeviceGLImpl* glThis = (IDirect3DDeviceGLImpl*) This;
/* Puts GL in the correct lighting / transformation mode */
if ((vertex_transformed == FALSE) &&
((glThis->last_vertices_transformed == TRUE) ||
(glThis->matrices_changed == TRUE))) {
(glThis->last_vertices_transformed == TRUE)) {
/* Need to put the correct transformation again if we go from Transformed
vertices to non-transformed ones.
*/
glMatrixMode(GL_MODELVIEW);
glLoadMatrixf((float *) glThis->view_mat);
glMultMatrixf((float *) glThis->world_mat);
glLoadMatrixf((float *) This->view_mat);
glMultMatrixf((float *) This->world_mat);
glMatrixMode(GL_PROJECTION);
glLoadMatrixf((float *) glThis->proj_mat);
glLoadMatrixf((float *) This->proj_mat);
if (glThis->render_state.fog_on == TRUE) glEnable(GL_FOG);
} else if ((vertex_transformed == TRUE) &&
((glThis->last_vertices_transformed == FALSE) ||
(glThis->matrices_changed == TRUE))) {
(glThis->last_vertices_transformed == FALSE)) {
GLfloat height, width;
GLfloat trans_mat[16];
......@@ -739,7 +746,6 @@ static void draw_primitive_handle_GL_state(IDirect3DDeviceGLImpl *glThis,
/* Remove also fogging... */
glDisable(GL_FOG);
}
glThis->matrices_changed = FALSE;
if ((glThis->last_vertices_lit == TRUE) && (vertex_lit == FALSE)) {
glEnable(GL_LIGHTING);
......@@ -976,7 +982,7 @@ static void draw_primitive_strided_7(IDirect3DDeviceImpl *This,
}
ENTER_GL();
draw_primitive_handle_GL_state(glThis,
draw_primitive_handle_GL_state(This,
(d3dvtVertexType & D3DFVF_POSITION_MASK) != D3DFVF_XYZ,
(d3dvtVertexType & D3DFVF_NORMAL) == 0);
draw_primitive_start_GL(d3dptPrimitiveType);
......@@ -1958,14 +1964,12 @@ d3ddevice_create(IDirect3DDeviceImpl **obj, IDirect3DImpl *d3d, IDirectDrawSurfa
gl_object->render_state.fog_on = FALSE;
/* Allocate memory for the matrices */
gl_object->world_mat = (D3DMATRIX *) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, 16 * sizeof(float));
gl_object->view_mat = (D3DMATRIX *) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, 16 * sizeof(float));
gl_object->proj_mat = (D3DMATRIX *) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, 16 * sizeof(float));
gl_object->matrices_changed = TRUE;
memcpy(gl_object->world_mat, id_mat, 16 * sizeof(float));
memcpy(gl_object->view_mat , id_mat, 16 * sizeof(float));
memcpy(gl_object->proj_mat , id_mat, 16 * sizeof(float));
object->world_mat = (D3DMATRIX *) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, 16 * sizeof(float));
object->view_mat = (D3DMATRIX *) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, 16 * sizeof(float));
object->proj_mat = (D3DMATRIX *) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, 16 * sizeof(float));
memcpy(object->world_mat, id_mat, 16 * sizeof(float));
memcpy(object->view_mat , id_mat, 16 * sizeof(float));
memcpy(object->proj_mat , id_mat, 16 * sizeof(float));
/* Initialisation */
TRACE(" setting current context\n");
......
......@@ -243,16 +243,16 @@ static void execute(IDirect3DExecuteBufferImpl *This,
glLoadIdentity(); /* The model transformation was done during the
transformation phase */
glMatrixMode(GL_PROJECTION);
TRACE(" Projection Matrix : (%p)\n", lpDeviceGL->proj_mat);
dump_mat(lpDeviceGL->proj_mat);
TRACE(" View Matrix : (%p)\n", lpDeviceGL->view_mat);
dump_mat(lpDeviceGL->view_mat);
TRACE(" Projection Matrix : (%p)\n", lpDevice->proj_mat);
dump_mat(lpDevice->proj_mat);
TRACE(" View Matrix : (%p)\n", lpDevice->view_mat);
dump_mat(lpDevice->view_mat);
/* Although z axis is inverted between OpenGL and Direct3D, the z projected coordinates
are always 0.0 at the front viewing volume and 1.0 at the back with Direct 3D and with
the default behaviour of OpenGL. So, no additional transformation is required. */
glLoadMatrixf((float *) lpDeviceGL->proj_mat);
glMultMatrixf((float *) lpDeviceGL->view_mat);
glLoadMatrixf((float *) lpDevice->proj_mat);
glMultMatrixf((float *) lpDevice->view_mat);
break;
case D3DVT_LVERTEX:
......@@ -265,16 +265,16 @@ static void execute(IDirect3DExecuteBufferImpl *This,
transformation phase */
glMatrixMode(GL_PROJECTION);
TRACE(" Projection Matrix : (%p)\n", lpDeviceGL->proj_mat);
dump_mat(lpDeviceGL->proj_mat);
TRACE(" View Matrix : (%p)\n", lpDeviceGL->view_mat);
dump_mat(lpDeviceGL->view_mat);
TRACE(" Projection Matrix : (%p)\n", lpDevice->proj_mat);
dump_mat(lpDevice->proj_mat);
TRACE(" View Matrix : (%p)\n", lpDevice->view_mat);
dump_mat(lpDevice->view_mat);
/* Although z axis is inverted between OpenGL and Direct3D, the z projected coordinates
are always 0 at the front viewing volume and 1 at the back with Direct 3D and with
the default behaviour of OpenGL. So, no additional transformation is required. */
glLoadMatrixf((float *) lpDeviceGL->proj_mat);
glMultMatrixf((float *) lpDeviceGL->view_mat);
glLoadMatrixf((float *) lpDevice->proj_mat);
glMultMatrixf((float *) lpDevice->view_mat);
break;
case D3DVT_TLVERTEX: {
......@@ -379,17 +379,17 @@ static void execute(IDirect3DExecuteBufferImpl *This,
switch (ci->u1.dtstTransformStateType) {
case D3DTRANSFORMSTATE_WORLD: {
TRACE(" WORLD (%p)\n", (D3DMATRIX*) ci->u2.dwArg[0]);
lpDeviceGL->world_mat = (D3DMATRIX*) ci->u2.dwArg[0];
lpDevice->world_mat = (D3DMATRIX*) ci->u2.dwArg[0];
} break;
case D3DTRANSFORMSTATE_VIEW: {
TRACE(" VIEW (%p)\n", (D3DMATRIX*) ci->u2.dwArg[0]);
lpDeviceGL->view_mat = (D3DMATRIX*) ci->u2.dwArg[0];
lpDevice->view_mat = (D3DMATRIX*) ci->u2.dwArg[0];
} break;
case D3DTRANSFORMSTATE_PROJECTION: {
TRACE(" PROJECTION (%p)\n", (D3DMATRIX*) ci->u2.dwArg[0]);
lpDeviceGL->proj_mat = (D3DMATRIX*) ci->u2.dwArg[0];
lpDevice->proj_mat = (D3DMATRIX*) ci->u2.dwArg[0];
} break;
default:
......@@ -538,7 +538,7 @@ static void execute(IDirect3DExecuteBufferImpl *This,
int nb;
D3DVERTEX *src = ((LPD3DVERTEX) (This->desc.lpData + vs)) + ci->wStart;
OGL_Vertex *dst = ((OGL_Vertex *) (This->vertex_data)) + ci->wDest;
D3DMATRIX *mat = lpDeviceGL->world_mat;
D3DMATRIX *mat = lpDevice->world_mat;
TRACE(" World Matrix : (%p)\n", mat);
dump_mat(mat);
......@@ -567,7 +567,7 @@ static void execute(IDirect3DExecuteBufferImpl *This,
int nb;
D3DLVERTEX *src = ((LPD3DLVERTEX) (This->desc.lpData + vs)) + ci->wStart;
OGL_LVertex *dst = ((OGL_LVertex *) (This->vertex_data)) + ci->wDest;
D3DMATRIX *mat = lpDeviceGL->world_mat;
D3DMATRIX *mat = lpDevice->world_mat;
TRACE(" World Matrix : (%p)\n", mat);
dump_mat(mat);
......
......@@ -118,11 +118,6 @@ typedef struct IDirect3DDeviceGLImpl
BOOLEAN last_vertices_transformed;
BOOLEAN last_vertices_lit;
D3DMATRIX *world_mat;
D3DMATRIX *view_mat;
D3DMATRIX *proj_mat;
BOOLEAN matrices_changed;
Display *display;
Drawable drawable;
} IDirect3DDeviceGLImpl;
......
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