Do full state initialization in D3D_Reset(), this fixes blend mode issues when resizing the window on Windows 8.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
diff --git a/src/render/direct3d/SDL_render_d3d.c b/src/render/direct3d/SDL_render_d3d.c
index e9fc0ce..4333bad 100644
--- a/src/render/direct3d/SDL_render_d3d.c
+++ b/src/render/direct3d/SDL_render_d3d.c
@@ -395,6 +395,71 @@ D3DFMTToPixelFormat(D3DFORMAT format)
}
}
+static void
+D3D_InitRenderState(D3D_RenderData *data)
+{
+ Direct3DDevice9 *device = data->device;
+
+ IDirect3DDevice9_SetVertexShader(device, NULL);
+ IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1);
+ IDirect3DDevice9_SetRenderState(device, D3DRS_ZENABLE, D3DZB_FALSE);
+ IDirect3DDevice9_SetRenderState(device, D3DRS_CULLMODE, D3DCULL_NONE);
+ IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
+
+ /* Enable color modulation by diffuse color */
+ IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLOROP,
+ D3DTOP_MODULATE);
+ IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG1,
+ D3DTA_TEXTURE);
+ IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG2,
+ D3DTA_DIFFUSE);
+
+ /* Enable alpha modulation by diffuse alpha */
+ IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_ALPHAOP,
+ D3DTOP_MODULATE);
+ IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_ALPHAARG1,
+ D3DTA_TEXTURE);
+ IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_ALPHAARG2,
+ D3DTA_DIFFUSE);
+
+ /* Enable separate alpha blend function, if possible */
+ if (data->enableSeparateAlphaBlend) {
+ IDirect3DDevice9_SetRenderState(device, D3DRS_SEPARATEALPHABLENDENABLE, TRUE);
+ }
+
+ /* Disable second texture stage, since we're done */
+ IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_COLOROP,
+ D3DTOP_DISABLE);
+ IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_ALPHAOP,
+ D3DTOP_DISABLE);
+
+ /* Set an identity world and view matrix */
+ matrix.m[0][0] = 1.0f;
+ matrix.m[0][1] = 0.0f;
+ matrix.m[0][2] = 0.0f;
+ matrix.m[0][3] = 0.0f;
+ matrix.m[1][0] = 0.0f;
+ matrix.m[1][1] = 1.0f;
+ matrix.m[1][2] = 0.0f;
+ matrix.m[1][3] = 0.0f;
+ matrix.m[2][0] = 0.0f;
+ matrix.m[2][1] = 0.0f;
+ matrix.m[2][2] = 1.0f;
+ matrix.m[2][3] = 0.0f;
+ matrix.m[3][0] = 0.0f;
+ matrix.m[3][1] = 0.0f;
+ matrix.m[3][2] = 0.0f;
+ matrix.m[3][3] = 1.0f;
+ IDirect3DDevice9_SetTransform(device, D3DTS_WORLD, &matrix);
+ IDirect3DDevice9_SetTransform(device, D3DTS_VIEW, &matrix);
+
+ /* Reset our current scale mode */
+ SDL_memset(data->scaleMode, 0xFF, sizeof(data->scaleMode));
+
+ /* Start the render with beginScene */
+ data->beginScene = SDL_TRUE;
+}
+
static int
D3D_Reset(SDL_Renderer * renderer)
{
@@ -416,14 +481,9 @@ D3D_Reset(SDL_Renderer * renderer)
return D3D_SetError("Reset()", result);
}
}
- IDirect3DDevice9_SetVertexShader(data->device, NULL);
- IDirect3DDevice9_SetFVF(data->device,
- D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1);
- IDirect3DDevice9_SetRenderState(data->device, D3DRS_CULLMODE,
- D3DCULL_NONE);
- IDirect3DDevice9_SetRenderState(data->device, D3DRS_LIGHTING, FALSE);
+
IDirect3DDevice9_GetRenderTarget(data->device, 0, &data->defaultRenderTarget);
- SDL_memset(data->scaleMode, 0xFF, sizeof(data->scaleMode));
+ D3D_InitRenderState(data);
D3D_UpdateViewport(renderer);
return 0;
}
@@ -624,8 +684,6 @@ D3D_CreateRenderer(SDL_Window * window, Uint32 flags)
D3D_SetError("CreateDevice()", result);
return NULL;
}
- data->beginScene = SDL_TRUE;
- SDL_memset(data->scaleMode, 0xFF, sizeof(data->scaleMode));
/* Get presentation parameters to fill info */
result = IDirect3DDevice9_GetSwapChain(data->device, 0, &chain);
@@ -658,61 +716,12 @@ D3D_CreateRenderer(SDL_Window * window, Uint32 flags)
data->enableSeparateAlphaBlend = SDL_TRUE;
}
- /* Set up parameters for rendering */
- IDirect3DDevice9_SetVertexShader(data->device, NULL);
- IDirect3DDevice9_SetFVF(data->device,
- D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1);
- IDirect3DDevice9_SetRenderState(data->device, D3DRS_ZENABLE, D3DZB_FALSE);
- IDirect3DDevice9_SetRenderState(data->device, D3DRS_CULLMODE,
- D3DCULL_NONE);
- IDirect3DDevice9_SetRenderState(data->device, D3DRS_LIGHTING, FALSE);
- /* Enable color modulation by diffuse color */
- IDirect3DDevice9_SetTextureStageState(data->device, 0, D3DTSS_COLOROP,
- D3DTOP_MODULATE);
- IDirect3DDevice9_SetTextureStageState(data->device, 0, D3DTSS_COLORARG1,
- D3DTA_TEXTURE);
- IDirect3DDevice9_SetTextureStageState(data->device, 0, D3DTSS_COLORARG2,
- D3DTA_DIFFUSE);
- /* Enable alpha modulation by diffuse alpha */
- IDirect3DDevice9_SetTextureStageState(data->device, 0, D3DTSS_ALPHAOP,
- D3DTOP_MODULATE);
- IDirect3DDevice9_SetTextureStageState(data->device, 0, D3DTSS_ALPHAARG1,
- D3DTA_TEXTURE);
- IDirect3DDevice9_SetTextureStageState(data->device, 0, D3DTSS_ALPHAARG2,
- D3DTA_DIFFUSE);
- /* Enable separate alpha blend function, if possible */
- if (data->enableSeparateAlphaBlend) {
- IDirect3DDevice9_SetRenderState(data->device, D3DRS_SEPARATEALPHABLENDENABLE, TRUE);
- }
- /* Disable second texture stage, since we're done */
- IDirect3DDevice9_SetTextureStageState(data->device, 1, D3DTSS_COLOROP,
- D3DTOP_DISABLE);
- IDirect3DDevice9_SetTextureStageState(data->device, 1, D3DTSS_ALPHAOP,
- D3DTOP_DISABLE);
-
/* Store the default render target */
IDirect3DDevice9_GetRenderTarget(data->device, 0, &data->defaultRenderTarget );
data->currentRenderTarget = NULL;
- /* Set an identity world and view matrix */
- matrix.m[0][0] = 1.0f;
- matrix.m[0][1] = 0.0f;
- matrix.m[0][2] = 0.0f;
- matrix.m[0][3] = 0.0f;
- matrix.m[1][0] = 0.0f;
- matrix.m[1][1] = 1.0f;
- matrix.m[1][2] = 0.0f;
- matrix.m[1][3] = 0.0f;
- matrix.m[2][0] = 0.0f;
- matrix.m[2][1] = 0.0f;
- matrix.m[2][2] = 1.0f;
- matrix.m[2][3] = 0.0f;
- matrix.m[3][0] = 0.0f;
- matrix.m[3][1] = 0.0f;
- matrix.m[3][2] = 0.0f;
- matrix.m[3][3] = 1.0f;
- IDirect3DDevice9_SetTransform(data->device, D3DTS_WORLD, &matrix);
- IDirect3DDevice9_SetTransform(data->device, D3DTS_VIEW, &matrix);
+ /* Set up parameters for rendering */
+ D3D_InitRenderState(data);
if (caps.MaxSimultaneousTextures >= 3)
{