1414#include " tss.h"
1515#include " blenders/blender.h"
1616#include " blenders/blender_recorder.h"
17+ #include " ShaderResourceTraits.h"
1718
1819void fix_texture_name (LPSTR fn);
1920
@@ -156,7 +157,6 @@ void CResourceManager::_DeleteDecl(const SDeclaration* dcl)
156157}
157158
158159// --------------------------------------------------------------------------------------------------------------
159- #ifndef _EDITOR
160160SVS* CResourceManager::_CreateVS (LPCSTR _name)
161161{
162162 string_path name;
@@ -171,179 +171,14 @@ SVS* CResourceManager::_CreateVS(LPCSTR _name)
171171 xr_strcat (name, " _3" );
172172 if (4 == GEnv.Render ->m_skinning )
173173 xr_strcat (name, " _4" );
174- LPSTR N = LPSTR (name);
175- map_VS::iterator I = m_vs.find (N);
176- if (I != m_vs.end ())
177- return I->second ;
178- else
179- {
180- SVS* _vs = new SVS ();
181- _vs->dwFlags |= xr_resource_flagged::RF_REGISTERED;
182- m_vs.insert (std::make_pair (_vs->set_name (name), _vs));
183- if (0 == xr_stricmp (_name, " null" ))
184- {
185- _vs->vs = nullptr ;
186- return _vs;
187- }
188-
189- string_path cname;
190- strconcat (sizeof (cname), cname, GEnv.Render ->getShaderPath (), _name, " .vs" );
191- FS.update_path (cname, " $game_shaders$" , cname);
192- // LPCSTR target = NULL;
193-
194- IReader* fs = FS.r_open (cname);
195- R_ASSERT3 (fs, " shader file doesnt exist" , cname);
196-
197- // Select target
198- LPCSTR c_target = " vs_2_0" ;
199- LPCSTR c_entry = " main" ;
200- if (HW.Caps .geometry_major >= 2 )
201- c_target = " vs_2_0" ;
202- else
203- c_target = " vs_1_1" ;
204-
205- // duplicate and zero-terminate
206- IReader* file = FS.r_open (cname);
207- R_ASSERT2 (file, cname);
208- u32 const size = file->length ();
209- char * const data = (LPSTR)_alloca (size + 1 );
210- CopyMemory (data, file->pointer (), size);
211- data[size] = 0 ;
212- FS.r_close (file);
213-
214- if (strstr (data, " main_vs_1_1" ))
215- {
216- c_target = " vs_1_1" ;
217- c_entry = " main_vs_1_1" ;
218- }
219- if (strstr (data, " main_vs_2_0" ))
220- {
221- c_target = " vs_2_0" ;
222- c_entry = " main_vs_2_0" ;
223- }
224-
225- Msg (" compiling shader %s" , name);
226- HRESULT const _hr = GEnv.Render ->shader_compile (name, (DWORD const *)data, size, c_entry, c_target,
227- D3DXSHADER_DEBUG | D3DXSHADER_PACKMATRIX_ROWMAJOR, (void *&)_vs);
228-
229- if (FAILED (_hr))
230- {
231- FlushLog ();
232- }
233-
234- CHECK_OR_EXIT (!FAILED (_hr), " Your video card doesn't meet game requirements.\n\n Try to lower game settings." );
235-
236- return _vs;
237- }
174+
175+ return CreateShader<SVS>(name, true );
238176}
239- #endif
240-
241- void CResourceManager::_DeleteVS (const SVS* vs)
242- {
243- if (0 == (vs->dwFlags & xr_resource_flagged::RF_REGISTERED))
244- return ;
245- LPSTR N = LPSTR (*vs->cName );
246- map_VS::iterator I = m_vs.find (N);
247- if (I != m_vs.end ())
248- {
249- m_vs.erase (I);
250- return ;
251- }
252- Msg (" ! ERROR: Failed to find compiled vertex-shader '%s'" , *vs->cName );
253- }
254-
255- #ifndef _EDITOR
256- // --------------------------------------------------------------------------------------------------------------
257- SPS* CResourceManager::_CreatePS (LPCSTR name)
258- {
259- LPSTR N = LPSTR (name);
260- map_PS::iterator I = m_ps.find (N);
261- if (I != m_ps.end ())
262- return I->second ;
263- else
264- {
265- SPS* _ps = new SPS ();
266- _ps->dwFlags |= xr_resource_flagged::RF_REGISTERED;
267- m_ps.insert (std::make_pair (_ps->set_name (name), _ps));
268- if (0 == xr_stricmp (name, " null" ))
269- {
270- _ps->ps = nullptr ;
271- return _ps;
272- }
273-
274- // Open file
275- string_path cname;
276- LPCSTR shader_path = GEnv.Render ->getShaderPath ();
277- strconcat (sizeof (cname), cname, shader_path, name, " .ps" );
278- FS.update_path (cname, " $game_shaders$" , cname);
279177
280- // duplicate and zero-terminate
281- IReader* file = FS.r_open (cname);
282- R_ASSERT2 (file, cname);
283- u32 const size = file->length ();
284- char * const data = (LPSTR)_alloca (size + 1 );
285- CopyMemory (data, file->pointer (), size);
286- data[size] = 0 ;
287- FS.r_close (file);
178+ void CResourceManager::_DeleteVS (const SVS* vs) { DestroyShader (vs); }
288179
289- // Select target
290- LPCSTR c_target = " ps_2_0" ;
291- LPCSTR c_entry = " main" ;
292- if (strstr (data, " main_ps_1_1" ))
293- {
294- c_target = " ps_1_1" ;
295- c_entry = " main_ps_1_1" ;
296- }
297- if (strstr (data, " main_ps_1_2" ))
298- {
299- c_target = " ps_1_2" ;
300- c_entry = " main_ps_1_2" ;
301- }
302- if (strstr (data, " main_ps_1_3" ))
303- {
304- c_target = " ps_1_3" ;
305- c_entry = " main_ps_1_3" ;
306- }
307- if (strstr (data, " main_ps_1_4" ))
308- {
309- c_target = " ps_1_4" ;
310- c_entry = " main_ps_1_4" ;
311- }
312- if (strstr (data, " main_ps_2_0" ))
313- {
314- c_target = " ps_2_0" ;
315- c_entry = " main_ps_2_0" ;
316- }
317-
318- Msg (" compiling shader %s" , name);
319- HRESULT const _hr = GEnv.Render ->shader_compile (name, (DWORD const *)data, size, c_entry, c_target,
320- D3DXSHADER_DEBUG | D3DXSHADER_PACKMATRIX_ROWMAJOR, (void *&)_ps);
321-
322- if (FAILED (_hr))
323- {
324- FlushLog ();
325- }
326-
327- CHECK_OR_EXIT (!FAILED (_hr), " Your video card doesn't meet game requirements.\n\n Try to lower game settings." );
328-
329- return _ps;
330- }
331- }
332- #endif
333-
334- void CResourceManager::_DeletePS (const SPS* ps)
335- {
336- if (0 == (ps->dwFlags & xr_resource_flagged::RF_REGISTERED))
337- return ;
338- LPSTR N = LPSTR (*ps->cName );
339- map_PS::iterator I = m_ps.find (N);
340- if (I != m_ps.end ())
341- {
342- m_ps.erase (I);
343- return ;
344- }
345- Msg (" ! ERROR: Failed to find compiled pixel-shader '%s'" , *ps->cName );
346- }
180+ SPS* CResourceManager::_CreatePS (LPCSTR name) { return CreateShader<SPS>(name, true ); }
181+ void CResourceManager::_DeletePS (const SPS* ps) { DestroyShader (ps); }
347182
348183R_constant_table* CResourceManager::_CreateConstantTable (R_constant_table& C)
349184{
0 commit comments