wined3d: Apply shaders in their state handlers.

This commit is contained in:
Stefan Dösinger 2007-01-06 18:14:12 +01:00 committed by Alexandre Julliard
parent 7e314011fb
commit 799770b992
3 changed files with 37 additions and 22 deletions

View File

@ -946,6 +946,9 @@ static void shader_arb_select(IWineD3DDevice *iface, BOOL usePS, BOOL useVS) {
checkGLcall("glEnable(GL_VERTEX_PROGRAM_ARB);");
TRACE("(%p) : Bound vertex program %u and enabled GL_VERTEX_PROGRAM_ARB\n",
This, ((IWineD3DVertexShaderImpl *)This->stateBlock->vertexShader)->baseShader.prgId);
} else if(GL_SUPPORT(GL_VERTEX_PROGRAM_ARB)) {
glDisable(GL_VERTEX_PROGRAM_ARB);
checkGLcall("glDisable(GL_VERTEX_PROGRAM_ARB)");
}
if (usePS) {
@ -961,6 +964,9 @@ static void shader_arb_select(IWineD3DDevice *iface, BOOL usePS, BOOL useVS) {
checkGLcall("glEnable(GL_FRAGMENT_PROGRAM_ARB);");
TRACE("(%p) : Bound fragment program %u and enabled GL_FRAGMENT_PROGRAM_ARB\n",
This, ((IWineD3DPixelShaderImpl *)This->stateBlock->pixelShader)->baseShader.prgId);
} else if(GL_SUPPORT(ARB_FRAGMENT_PROGRAM)) {
glDisable(GL_FRAGMENT_PROGRAM_ARB);
checkGLcall("glDisable(GL_FRAGMENT_PROGRAM_ARB)");
}
}

View File

@ -1108,9 +1108,6 @@ inline static void drawPrimitiveDrawStrided(
IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
/* Make any shaders active */
This->shader_backend->shader_select(iface, usePixelShaderFunction, useVertexShaderFunction);
/* Load any global constants/uniforms that may have been set by the application */
This->shader_backend->shader_load_constants(iface, usePixelShaderFunction, useVertexShaderFunction);
@ -1119,9 +1116,6 @@ inline static void drawPrimitiveDrawStrided(
drawStridedSlow(iface, dataLocations, numberOfIndicies, glPrimType, idxData, idxSize, minIndex, StartIdx, baseVIndex);
else
drawStridedFast(iface, numberOfIndicies, glPrimType, idxData, idxSize, minIndex, StartIdx, baseVIndex);
/* Cleanup any shaders */
This->shader_backend->shader_cleanup(usePixelShaderFunction, useVertexShaderFunction);
}
static void check_fbo_status(IWineD3DDevice *iface) {
@ -1164,6 +1158,14 @@ static void depth_blt(IWineD3DDevice *iface, GLuint texture) {
glBindTexture(GL_TEXTURE_2D, old_binding);
glPopAttrib();
/* Reselect the old shaders. There doesn't seem to be any glPushAttrib bit for arb shaders,
* and this seems easier and more efficient than providing the shader backend with a private
* storage to read and restore the old shader settings
*/
This->shader_backend->shader_select(iface,
This->stateBlock->pixelShader && ((IWineD3DPixelShaderImpl *)This->stateBlock->pixelShader)->baseShader.function,
This->stateBlock->vertexShader && ((IWineD3DVertexShaderImpl *)This->stateBlock->vertexShader)->baseShader.function);
}
static void depth_copy(IWineD3DDevice *iface) {

View File

@ -1833,16 +1833,12 @@ static void pixelshader(DWORD state, IWineD3DStateBlockImpl *stateblock) {
/* Compile and bind the shader */
IWineD3DPixelShader_CompileShader(stateblock->pixelShader);
#if 0
/* Can't do that here right now, because glsl shaders depend on having both pixel and vertex shader
* setup at the same time. The shader_select call will be done by drawprim until vertex shaders are
* moved to the state table too
*/
stateblock->wineD3DDevice->shader_backend->shader_select(
(IWineD3DDevice *) stateblock->wineD3DDevice,
TRUE,
!stateblock->vertexShader ? FALSE : ((IWineD3DVertexShaderImpl *) stateblock->vertexShader)->baseShader.function != NULL);
#endif
if(!isStateDirty(stateblock->wineD3DDevice, StateTable[STATE_VSHADER].representative)) {
stateblock->wineD3DDevice->shader_backend->shader_select(
(IWineD3DDevice *) stateblock->wineD3DDevice,
TRUE,
!stateblock->vertexShader ? FALSE : ((IWineD3DVertexShaderImpl *) stateblock->vertexShader)->baseShader.function != NULL);
}
stateblock->wineD3DDevice->last_was_pshader = TRUE;
} else {
/* Disabled the pixel shader - color ops weren't applied
@ -1855,12 +1851,12 @@ static void pixelshader(DWORD state, IWineD3DStateBlockImpl *stateblock) {
}
stateblock->wineD3DDevice->last_was_pshader = FALSE;
#if 0
stateblock->wineD3DDevice->shader_backend->shader_select(
(IWineD3DDevice *) stateblock->wineD3DDevice,
FALSE,
!stateblock->vertexShader ? FALSE : ((IWineD3DVertexShaderImpl *) stateblock->vertexShader)->baseShader.function != NULL);
#endif
if(!isStateDirty(stateblock->wineD3DDevice, StateTable[STATE_VSHADER].representative)) {
stateblock->wineD3DDevice->shader_backend->shader_select(
(IWineD3DDevice *) stateblock->wineD3DDevice,
FALSE,
!stateblock->vertexShader ? FALSE : ((IWineD3DVertexShaderImpl *) stateblock->vertexShader)->baseShader.function != NULL);
}
}
}
@ -2653,6 +2649,17 @@ static void vertexdeclaration(DWORD state, IWineD3DStateBlockImpl *stateblock) {
* in order to determine if we need to do any swizzling for D3DCOLOR
* registers. If the shader is already compiled this call will do nothing. */
IWineD3DVertexShader_CompileShader(stateblock->vertexShader);
/* Vertex and pixel shaders are applied together for now, so let the last dirty state do the
* application
*/
if(!isStateDirty(device, STATE_PIXELSHADER)) {
BOOL usePixelShaderFunction = device->ps_selected_mode != SHADER_NONE &&
stateblock->pixelShader &&
((IWineD3DPixelShaderImpl *)stateblock->pixelShader)->baseShader.function;
device->shader_backend->shader_select((IWineD3DDevice *) device, usePixelShaderFunction, useVertexShaderFunction);
}
}
if(updateFog) {