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 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213
| DWORD WINAPI D3D11Rendering::texturesLoading(LPVOID lpParam)
{
LoadingThreadsParameters* parameters = (LoadingThreadsParameters*)lpParam;
for (unsigned short i = parameters->beginning; i <= parameters->end; i++)
{
string textureName(objectsData[i].textureName);
//_ASSERT(i != 236);
if (textureName.length() > 1)
{
string textureDirectory("./Assets/Textures/");
textureName.replace(textureName.length() - 4, 4, ".jpg");
string textureFilePath = textureDirectory + textureName;
// Load the texture and initialize an ID3D11Texture2D object.
HRESULT result = D3DX11CreateTextureFromFile(deviceDX11, textureFilePath.c_str(), NULL, NULL, (ID3D11Resource **)&textureData[i], NULL);
D3D11_SHADER_RESOURCE_VIEW_DESC shaderResourceViewDesc;
// Fill in the D3D11_SHADER_RESOURCE_VIEW_DESC structure.
shaderResourceViewDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;// textureDesc.Format;
shaderResourceViewDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
shaderResourceViewDesc.Texture2D.MostDetailedMip = 0;
shaderResourceViewDesc.Texture2D.MipLevels = 1;
textureSRV.resize(Loader3ds::nbObj+1);
normalMapSRV.resize(Loader3ds::nbObj + 1);
// Create the shader resource view.
HRESULT hResult = deviceDX11->CreateShaderResourceView((ID3D11Resource*)textureData[i], &shaderResourceViewDesc, &textureSRV[i]);
textureData[i]->Release();
textureData[i] = NULL;
if (strstr(objectsData[i].textureName, "SKY")!=0)
backgroundIndex = i;
//Loading of the normal maps
if ( ( strstr(textureFilePath.c_str(), "backgroun") == 0 ) /*|| (strstr(textureFilePath.c_str(), "badTree") == 0 )*/)
{
string textureDirectory("./Assets/Textures/");
textureName.replace(textureName.length() - 4, 4, "");
string textureFilePath = textureDirectory + textureName;
textureFilePath += string("_NormalMap.png");
// Load the texture and initialize an ID3D11Texture2D object.
HRESULT result = D3DX11CreateTextureFromFile(deviceDX11, textureFilePath.c_str(), NULL, NULL, (ID3D11Resource**)&normalMapTexture[i], NULL);
D3D11_SHADER_RESOURCE_VIEW_DESC shaderResourceViewDesc;
// Fill in the D3D11_SHADER_RESOURCE_VIEW_DESC structure.
shaderResourceViewDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;// textureDesc.Format;
shaderResourceViewDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
shaderResourceViewDesc.Texture2D.MostDetailedMip = 0;
shaderResourceViewDesc.Texture2D.MipLevels = 1;
//textureSRV.resize(Loader3ds::nbObj + 1);
//normalMapSRV.resize(Loader3ds::nbObj + 1);
// Create the shader resource view.
HRESULT hResult = deviceDX11->CreateShaderResourceView((ID3D11Resource*)normalMapTexture[i], &shaderResourceViewDesc, &normalMapSRV[i]);
// normalMapTexture[i]->Release();
// normalMapTexture[i] = NULL;
MemoryUtilities::SafeDeleteD3Dobject(normalMapTexture[i]);
}
}
}
_CrtDumpMemoryLeaks();
/*MemoryUtilities::SafeDelete(lpParam);
MemoryUtilities::SafeDelete(parameters);*/
return 0;
}
void D3D11Rendering::parallelizeTextureLoading()
{
LoadingThreadsParameters loadingThreadsParameters0;
LoadingThreadsParameters loadingThreadsParameters1;
LoadingThreadsParameters loadingThreadsParameters2;
LoadingThreadsParameters loadingThreadsParameters3;
LoadingThreadsParameters loadingThreadsParameters4;
LoadingThreadsParameters loadingThreadsParameters5;
LoadingThreadsParameters loadingThreadsParameters6;
LoadingThreadsParameters loadingThreadsParameters7;
SetThreadPriority(handleLoadingTexturesThread[0], THREAD_PRIORITY_TIME_CRITICAL);
SetThreadPriority(handleLoadingTexturesThread[1], THREAD_PRIORITY_TIME_CRITICAL);
SetThreadPriority(handleLoadingTexturesThread[2], THREAD_PRIORITY_TIME_CRITICAL);
SetThreadPriority(handleLoadingTexturesThread[3], THREAD_PRIORITY_TIME_CRITICAL);
SetThreadPriority(handleLoadingTexturesThread[4], THREAD_PRIORITY_TIME_CRITICAL);
SetThreadPriority(handleLoadingTexturesThread[5], THREAD_PRIORITY_TIME_CRITICAL);
SetThreadPriority(handleLoadingTexturesThread[6], THREAD_PRIORITY_TIME_CRITICAL);
SetThreadPriority(handleLoadingTexturesThread[7], THREAD_PRIORITY_TIME_CRITICAL);
loadingThreadsParameters0.beginning = 0;
loadingThreadsParameters0.end = nbObj / 8;
handleLoadingTexturesThread[0] = CreateThread(
NULL, // default security attributes
0, // use default stack size
&D3D11Rendering::texturesLoading, // thread function name
&loadingThreadsParameters0, // argument to thread function
0, // use default creation flags
0);
loadingThreadsParameters1.beginning = (nbObj / 8)+1;
loadingThreadsParameters1.end = (nbObj/8)*2;
handleLoadingTexturesThread[1] = CreateThread(
NULL, // default security attributes
0, // use default stack size
&D3D11Rendering::texturesLoading, // thread function name
&loadingThreadsParameters1, // argument to thread function
0, // use default creation flags
0);
loadingThreadsParameters2.beginning = ((nbObj / 8) * 2)+1;
loadingThreadsParameters2.end = (nbObj / 8) * 3;
handleLoadingTexturesThread[2] = CreateThread(
NULL, // default security attributes
0, // use default stack size
&D3D11Rendering::texturesLoading, // thread function name
&loadingThreadsParameters2, // argument to thread function
0, // use default creation flags
0);
loadingThreadsParameters3.beginning = ((nbObj / 8) * 3) +1 ;
loadingThreadsParameters3.end = (nbObj / 8) * 4;
handleLoadingTexturesThread[3] = CreateThread(
NULL, // default security attributes
0, // use default stack size
&D3D11Rendering::texturesLoading, // thread function name
&loadingThreadsParameters3, // argument to thread function
0, // use default creation flags
0);
loadingThreadsParameters4.beginning = ((nbObj / 8) * 4)+1;
loadingThreadsParameters4.end = (nbObj / 8) * 5;
handleLoadingTexturesThread[4] = CreateThread(
NULL, // default security attributes
0, // use default stack size
&D3D11Rendering::texturesLoading, // thread function name
&loadingThreadsParameters4, // argument to thread function
0, // use default creation flags
0);
loadingThreadsParameters5.beginning = ((nbObj / 8) * 5)+1;
loadingThreadsParameters5.end = (nbObj / 8) * 6;
handleLoadingTexturesThread[5] = CreateThread(
NULL, // default security attributes
0, // use default stack size
&D3D11Rendering::texturesLoading, // thread function name
&loadingThreadsParameters5, // argument to thread function
0, // use default creation flags
0);
loadingThreadsParameters6.beginning = ((nbObj / 8) * 6)+1;
loadingThreadsParameters6.end = (nbObj / 8) * 7;
handleLoadingTexturesThread[6] = CreateThread(
NULL, // default security attributes
0, // use default stack size
&D3D11Rendering::texturesLoading, // thread function name
&loadingThreadsParameters6, // argument to thread function
0, // use default creation flags
0);
loadingThreadsParameters7.beginning = ((nbObj / 8) * 7)+1;
loadingThreadsParameters7.end = (nbObj);
handleLoadingTexturesThread[7] = CreateThread(
NULL, // default security attributes
0, // use default stack size
&D3D11Rendering::texturesLoading, // thread function name
&loadingThreadsParameters7, // argument to thread function
0, // use default creation flags
0);
WaitForMultipleObjects(8, handleLoadingTexturesThread, TRUE, INFINITE);
CloseHandle(handleLoadingTexturesThread[0]);
CloseHandle(handleLoadingTexturesThread[1]);
CloseHandle(handleLoadingTexturesThread[2]);
CloseHandle(handleLoadingTexturesThread[3]);
CloseHandle(handleLoadingTexturesThread[4]);
CloseHandle(handleLoadingTexturesThread[5]);
CloseHandle(handleLoadingTexturesThread[6]);
CloseHandle(handleLoadingTexturesThread[7]);
} |
Partager