Commit e0d2fb67 authored by Jason Edmeades's avatar Jason Edmeades Committed by Alexandre Julliard

Only reapply the world, view or projection transform changes if we

really have to.
parent 9fdc759b
......@@ -258,6 +258,12 @@ struct IDirect3DDevice8Impl
float lightPosn[MAX_ACTIVE_LIGHTS][4];
float lightDirn[MAX_ACTIVE_LIGHTS][4];
/* Optimization */
D3DMATRIX lastProj;
D3DMATRIX lastView;
D3DMATRIX lastWorld0;
/* OpenGL related */
GLXContext glCtx;
XVisualInfo *visInfo;
......
......@@ -1700,6 +1700,7 @@ HRESULT WINAPI IDirect3DDevice8Impl_SetTransform(LPDIRECT3DDEVICE8 iface, D3DT
D3DMATRIX m;
int k;
float f;
BOOL viewChanged = TRUE;
/* Most of this routine, comments included copied from ddraw tree initially: */
TRACE("(%p) : State=%d\n", This, d3dts);
......@@ -1784,18 +1785,27 @@ HRESULT WINAPI IDirect3DDevice8Impl_SetTransform(LPDIRECT3DDEVICE8 iface, D3DT
/*
* Move the GL operation to outside of switch to make it work
* regardless of transform set order. Optimize later.
* regardless of transform set order.
*/
ENTER_GL();
if (memcmp(&This->lastProj, &This->StateBlock->transforms[D3DTS_PROJECTION].u.m[0][0], sizeof(D3DMATRIX))) {
glMatrixMode(GL_PROJECTION);
checkGLcall("glMatrixMode");
glLoadMatrixf((float *) &This->StateBlock->transforms[D3DTS_PROJECTION].u.m[0][0]);
checkGLcall("glLoadMatrixf");
memcpy(&This->lastProj, &This->StateBlock->transforms[D3DTS_PROJECTION].u.m[0][0], sizeof(D3DMATRIX));
} else {
TRACE("Skipping as projection already correct\n");
}
glMatrixMode(GL_MODELVIEW);
checkGLcall("glMatrixMode");
viewChanged = FALSE;
if (memcmp(&This->lastView, &This->StateBlock->transforms[D3DTS_VIEW].u.m[0][0], sizeof(D3DMATRIX))) {
glLoadMatrixf((float *) &This->StateBlock->transforms[D3DTS_VIEW].u.m[0][0]);
checkGLcall("glLoadMatrixf");
memcpy(&This->lastView, &This->StateBlock->transforms[D3DTS_VIEW].u.m[0][0], sizeof(D3DMATRIX));
viewChanged = TRUE;
/* If we are changing the View matrix, reset the light and clipping planes to the new view */
if (d3dts == D3DTS_VIEW) {
......@@ -1818,6 +1828,9 @@ HRESULT WINAPI IDirect3DDevice8Impl_SetTransform(LPDIRECT3DDEVICE8 iface, D3DT
}
}
} else {
TRACE("Skipping view setup as view already correct\n");
}
/**
* Vertex Blending as described
......@@ -1826,8 +1839,18 @@ HRESULT WINAPI IDirect3DDevice8Impl_SetTransform(LPDIRECT3DDEVICE8 iface, D3DT
switch (This->UpdateStateBlock->vertex_blend) {
case D3DVBF_DISABLE:
{
if (viewChanged == TRUE ||
(memcmp(&This->lastWorld0, &This->StateBlock->transforms[D3DTS_WORLDMATRIX(0)].u.m[0][0], sizeof(D3DMATRIX)))) {
memcpy(&This->lastWorld0, &This->StateBlock->transforms[D3DTS_WORLDMATRIX(0)].u.m[0][0], sizeof(D3DMATRIX));
if (viewChanged==FALSE) {
glLoadMatrixf((float *) &This->StateBlock->transforms[D3DTS_VIEW].u.m[0][0]);
checkGLcall("glLoadMatrixf");
}
glMultMatrixf((float *) &This->StateBlock->transforms[D3DTS_WORLDMATRIX(0)].u.m[0][0]);
checkGLcall("glMultMatrixf");
} else {
TRACE("Skipping as world already correct\n");
}
}
break;
case D3DVBF_1WEIGHTS:
......@@ -1853,6 +1876,10 @@ HRESULT WINAPI IDirect3DDevice8Impl_SetTransform(LPDIRECT3DDEVICE8 iface, D3DT
m.u.s._21 = f; m.u.s._22 = f; m.u.s._23 = f; m.u.s._24 = f;
m.u.s._31 = f; m.u.s._32 = f; m.u.s._33 = f; m.u.s._34 = f;
m.u.s._41 = f; m.u.s._42 = f; m.u.s._43 = f; m.u.s._44 = f;
if (viewChanged==FALSE) {
glLoadMatrixf((float *) &This->StateBlock->transforms[D3DTS_VIEW].u.m[0][0]);
checkGLcall("glLoadMatrixf");
}
glMultMatrixf((float *) &m.u.m[0][0]);
checkGLcall("glMultMatrixf");
}
......@@ -1865,6 +1892,10 @@ HRESULT WINAPI IDirect3DDevice8Impl_SetTransform(LPDIRECT3DDEVICE8 iface, D3DT
m.u.s._21 = 1.0f; m.u.s._22 = 1.0f; m.u.s._23 = 1.0f; m.u.s._24 = 1.0f;
m.u.s._31 = 1.0f; m.u.s._32 = 1.0f; m.u.s._33 = 1.0f; m.u.s._34 = 1.0f;
m.u.s._41 = 1.0f; m.u.s._42 = 1.0f; m.u.s._43 = 1.0f; m.u.s._44 = 1.0f;
if (viewChanged==FALSE) {
glLoadMatrixf((float *) &This->StateBlock->transforms[D3DTS_VIEW].u.m[0][0]);
checkGLcall("glLoadMatrixf");
}
glMultMatrixf((float *) &m.u.m[0][0]);
checkGLcall("glMultMatrixf");
}
......
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