Commit e26e3ee5 authored by Stefan Dösinger's avatar Stefan Dösinger Committed by Alexandre Julliard

wined3d: Remove d3ddevice_set_ortho.

parent 82bd0790
...@@ -1936,7 +1936,6 @@ static HRESULT WINAPI IWineD3DDeviceImpl_Init3D(IWineD3DDevice *iface, WINED3DPR ...@@ -1936,7 +1936,6 @@ static HRESULT WINAPI IWineD3DDeviceImpl_Init3D(IWineD3DDevice *iface, WINED3DPR
} }
/* Initialize the current view state */ /* Initialize the current view state */
This->proj_valid = 0;
This->view_ident = 1; This->view_ident = 1;
This->last_was_rhw = 0; This->last_was_rhw = 0;
glGetIntegerv(GL_MAX_LIGHTS, &This->maxConcurrentLights); glGetIntegerv(GL_MAX_LIGHTS, &This->maxConcurrentLights);
...@@ -5877,7 +5876,7 @@ static void device_render_to_texture(IWineD3DDeviceImpl* This, BOOL isTexture) { ...@@ -5877,7 +5876,7 @@ static void device_render_to_texture(IWineD3DDeviceImpl* This, BOOL isTexture) {
This->depth_copy_state = WINED3D_DCS_COPY; This->depth_copy_state = WINED3D_DCS_COPY;
} }
This->last_was_rhw = FALSE; This->last_was_rhw = FALSE;
This->proj_valid = FALSE; /* Viewport state will reapply the projection matrix for now */
IWineD3DDeviceImpl_MarkStateDirty(This, WINED3DRS_CULLMODE); IWineD3DDeviceImpl_MarkStateDirty(This, WINED3DRS_CULLMODE);
/* Restore recording */ /* Restore recording */
......
...@@ -155,22 +155,6 @@ static const GLfloat invymat[16] = { ...@@ -155,22 +155,6 @@ static const GLfloat invymat[16] = {
0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f}; 0.0f, 0.0f, 0.0f, 1.0f};
void d3ddevice_set_ortho(IWineD3DDeviceImpl *This) {
/* If the last draw was transformed as well, no need to reapply all the matrixes */
if ( (!This->last_was_rhw) || (This->viewport_changed) ) {
This->last_was_rhw = TRUE;
This->viewport_changed = FALSE;
/* Transformed already into viewport coordinates, so we do not need transform
matrices. Reset all matrices to identity and leave the default matrix in world
mode. */
glMatrixMode(GL_MODELVIEW);
checkGLcall("glMatrixMode(GL_MODELVIEW)");
glLoadIdentity();
checkGLcall("glLoadIdentity");
}
}
static BOOL fixed_get_input( static BOOL fixed_get_input(
BYTE usage, BYTE usage_idx, BYTE usage, BYTE usage_idx,
unsigned int* regnum) { unsigned int* regnum) {
......
...@@ -1821,25 +1821,30 @@ static void pixelshader(DWORD state, IWineD3DStateBlockImpl *stateblock) { ...@@ -1821,25 +1821,30 @@ static void pixelshader(DWORD state, IWineD3DStateBlockImpl *stateblock) {
} }
static void transform_world(DWORD state, IWineD3DStateBlockImpl *stateblock) { static void transform_world(DWORD state, IWineD3DStateBlockImpl *stateblock) {
/* Do not bother applying when we're in rhw mode. vertexdeclaration() will call /* This function is called by transform_view below if the view matrix was changed too
* transform_world if it switches out of rhw mode. This function is also called *
* by transform_view below if the view matrix was changed * Deliberately no check if the vertex declaration is dirty because the vdecl state
* does not always update the world matrix, only on a switch between transformed
* and untrannsformed draws. It *may* happen that the world matrix is set 2 times during one
* draw, but that should be rather rare and cheaper in total.
*/ */
if(stateblock->wineD3DDevice->last_was_rhw) {
return;
}
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
checkGLcall("glMatrixMode"); checkGLcall("glMatrixMode");
/* In the general case, the view matrix is the identity matrix */ if(stateblock->wineD3DDevice->last_was_rhw) {
if (stateblock->wineD3DDevice->view_ident) { glLoadIdentity();
glLoadMatrixf((float *) &stateblock->transforms[WINED3DTS_WORLDMATRIX(0)].u.m[0][0]); checkGLcall("glLoadIdentity()");
checkGLcall("glLoadMatrixf");
} else { } else {
glLoadMatrixf((float *) &stateblock->transforms[WINED3DTS_VIEW].u.m[0][0]); /* In the general case, the view matrix is the identity matrix */
checkGLcall("glLoadMatrixf"); if (stateblock->wineD3DDevice->view_ident) {
glMultMatrixf((float *) &stateblock->transforms[WINED3DTS_WORLDMATRIX(0)].u.m[0][0]); glLoadMatrixf((float *) &stateblock->transforms[WINED3DTS_WORLDMATRIX(0)].u.m[0][0]);
checkGLcall("glMultMatrixf"); checkGLcall("glLoadMatrixf");
} else {
glLoadMatrixf((float *) &stateblock->transforms[WINED3DTS_VIEW].u.m[0][0]);
checkGLcall("glLoadMatrixf");
glMultMatrixf((float *) &stateblock->transforms[WINED3DTS_WORLDMATRIX(0)].u.m[0][0]);
checkGLcall("glMultMatrixf");
}
} }
} }
...@@ -2037,8 +2042,7 @@ static void vertexdeclaration(DWORD state, IWineD3DStateBlockImpl *stateblock) { ...@@ -2037,8 +2042,7 @@ static void vertexdeclaration(DWORD state, IWineD3DStateBlockImpl *stateblock) {
} }
if (!useVertexShaderFunction && transformed) { if (!useVertexShaderFunction && transformed) {
d3ddevice_set_ortho(device); stateblock->wineD3DDevice->last_was_rhw = TRUE;
} else { } else {
/* Untransformed, so relies on the view and projection matrices */ /* Untransformed, so relies on the view and projection matrices */
...@@ -2046,42 +2050,50 @@ static void vertexdeclaration(DWORD state, IWineD3DStateBlockImpl *stateblock) { ...@@ -2046,42 +2050,50 @@ static void vertexdeclaration(DWORD state, IWineD3DStateBlockImpl *stateblock) {
/* This turns off the Z scale trick to 'disable' viewport frustum clipping in rhw mode*/ /* This turns off the Z scale trick to 'disable' viewport frustum clipping in rhw mode*/
device->untransformed = TRUE; device->untransformed = TRUE;
/* Don't bother checking for !useVertexShaderFunction here. If shaders are always on wasrhw will never /* Todo for sw shaders: Vertex Shader output is already transformed, so set up identity matrices
* be true. If they are switched on and off then knowing that the fixed function matrices are ok makes * Not needed as long as only hw shaders are supported
* those switches cheaper
*/ */
if (wasrhw) {
/* switching out of orthogonal mode? have to reapply the modelview matrix.
* Only do that when it is not dirty though
*/
if(!isStateDirty(device, STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(0)))) {
transform_world(STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(0)), stateblock);
}
}
if (!useVertexShaderFunction) { /* This sets the shader output position correction constants.
device->proj_valid = TRUE; * TODO: Move to the viewport state
} */
/* Vertex Shader output is already transformed, so set up identity matrices */
if (useVertexShaderFunction) { if (useVertexShaderFunction) {
device->posFixup[1] = device->render_offscreen ? -1.0 : 1.0; device->posFixup[1] = device->render_offscreen ? -1.0 : 1.0;
device->posFixup[2] = 0.9 / stateblock->viewport.Width; device->posFixup[2] = 0.9 / stateblock->viewport.Width;
device->posFixup[3] = -0.9 / stateblock->viewport.Height; device->posFixup[3] = -0.9 / stateblock->viewport.Height;
} }
device->last_was_rhw = FALSE;
} }
/* TODO: Move this mainly to the viewport state and only apply when the vp has changed /* Don't have to apply the matrices when vertex shaders are used. When vshaders are turned
* or transformed / untransformed was switched * off this function will be called again anyway to make sure they're properly set
*/ */
if(!isStateDirty(stateblock->wineD3DDevice, STATE_TRANSFORM(WINED3DTS_PROJECTION))) { if(!useVertexShaderFunction) {
transform_projection(STATE_TRANSFORM(WINED3DTS_PROJECTION), stateblock); /* TODO: Move this mainly to the viewport state and only apply when the vp has changed
} * or transformed / untransformed was switched
*/
if(!isStateDirty(stateblock->wineD3DDevice, STATE_TRANSFORM(WINED3DTS_PROJECTION))) {
transform_projection(STATE_TRANSFORM(WINED3DTS_PROJECTION), stateblock);
}
/* World matrix needs reapplication here only if we're switching between rhw and non-rhw
* mode.
*
* If a vertex shader is used, the world matrix changed and then vertex shader unbound
* this check will fail and the matrix not applied again. This is OK because a simple
* world matrix change reapplies the matrix - These checks here are only to satisfy the
* needs of the vertex declaration.
*
* World and view matrix go into the same gl matrix, so only apply them when neither is
* dirty
*/
if(transformed != wasrhw &&
!isStateDirty(stateblock->wineD3DDevice, STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(0))) &&
!isStateDirty(stateblock->wineD3DDevice, STATE_TRANSFORM(WINED3DTS_VIEW))) {
transform_world(STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(0)), stateblock);
}
}
/* Setup fogging */
if(updateFog) { if(updateFog) {
state_fog(STATE_RENDER(WINED3DRS_FOGENABLE), stateblock); state_fog(STATE_RENDER(WINED3DRS_FOGENABLE), stateblock);
} }
} }
......
...@@ -1149,9 +1149,10 @@ static HRESULT WINAPI IWineD3DSurfaceImpl_UnlockRect(IWineD3DSurface *iface) { ...@@ -1149,9 +1149,10 @@ static HRESULT WINAPI IWineD3DSurfaceImpl_UnlockRect(IWineD3DSurface *iface) {
/* glDrawPixels transforms the raster position as though it was a vertex - /* glDrawPixels transforms the raster position as though it was a vertex -
we want to draw at screen position 0,0 - Set up ortho (rhw) mode as we want to draw at screen position 0,0 - Set up ortho (rhw) mode as
per drawprim (and leave set - it will sort itself out due to last_was_rhw */ per drawprim (and leave set - it will sort itself out due to last_was_rhw */
d3ddevice_set_ortho(This->resource.wineD3DDevice); myDevice->last_was_rhw = TRUE;
/* Apply the projection matrix, it sets up orthogonal projection due to last_was_rhw */ /* Apply the projection and world matrices, it sets up orthogonal projection due to last_was_rhw */
StateTable[STATE_TRANSFORM(WINED3DTS_PROJECTION)].apply(STATE_TRANSFORM(WINED3DTS_PROJECTION), myDevice->stateBlock); StateTable[STATE_TRANSFORM(WINED3DTS_PROJECTION)].apply(STATE_TRANSFORM(WINED3DTS_PROJECTION), myDevice->stateBlock);
StateTable[STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(0))].apply(STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(0)), myDevice->stateBlock);
/* Will reapply the projection matrix too */ /* Will reapply the projection matrix too */
IWineD3DDeviceImpl_MarkStateDirty(myDevice, STATE_VDECL); IWineD3DDeviceImpl_MarkStateDirty(myDevice, STATE_VDECL);
...@@ -2476,9 +2477,10 @@ static HRESULT IWineD3DSurfaceImpl_BltOverride(IWineD3DSurfaceImpl *This, RECT * ...@@ -2476,9 +2477,10 @@ static HRESULT IWineD3DSurfaceImpl_BltOverride(IWineD3DSurfaceImpl *This, RECT *
/* Draw a textured quad /* Draw a textured quad
*/ */
d3ddevice_set_ortho(This->resource.wineD3DDevice); myDevice->last_was_rhw = TRUE;
/* Apply the projection matrix, it sets up orthogonal projection due to last_was_rhw */ /* Apply the projection matrix, it sets up orthogonal projection due to last_was_rhw */
StateTable[STATE_TRANSFORM(WINED3DTS_PROJECTION)].apply(STATE_TRANSFORM(WINED3DTS_PROJECTION), myDevice->stateBlock); StateTable[STATE_TRANSFORM(WINED3DTS_PROJECTION)].apply(STATE_TRANSFORM(WINED3DTS_PROJECTION), myDevice->stateBlock);
StateTable[STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(0))].apply(STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(0)), myDevice->stateBlock);
/* That will reapply the projection matrix too */ /* That will reapply the projection matrix too */
IWineD3DDeviceImpl_MarkStateDirty(myDevice, STATE_VDECL); IWineD3DDeviceImpl_MarkStateDirty(myDevice, STATE_VDECL);
......
...@@ -563,7 +563,6 @@ typedef struct IWineD3DDeviceImpl ...@@ -563,7 +563,6 @@ typedef struct IWineD3DDeviceImpl
const shader_backend_t *shader_backend; const shader_backend_t *shader_backend;
/* Optimization */ /* Optimization */
BOOL proj_valid;
BOOL view_ident; /* true iff view matrix is identity */ BOOL view_ident; /* true iff view matrix is identity */
BOOL last_was_rhw; /* true iff last draw_primitive was in xyzrhw mode */ BOOL last_was_rhw; /* true iff last draw_primitive was in xyzrhw mode */
BOOL viewport_changed; /* Was the viewport changed since the last draw? */ BOOL viewport_changed; /* Was the viewport changed since the last draw? */
...@@ -704,8 +703,6 @@ typedef struct PrivateData ...@@ -704,8 +703,6 @@ typedef struct PrivateData
DWORD size; DWORD size;
} PrivateData; } PrivateData;
void d3ddevice_set_ortho(IWineD3DDeviceImpl *This);
/***************************************************************************** /*****************************************************************************
* IWineD3DResource implementation structure * IWineD3DResource implementation structure
*/ */
......
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