2
votes

I have a shader written in HLSL that I do not want the user to be able to access. Is there a way I can go about compiling from a section of memory. The problem is that the following function accepts an LPCSTR in order to use a .fx file as input:

    HRESULT D3DXCreateEffectFromFile(
  _In_   LPDIRECT3DDEVICE9 pDevice,
  _In_   LPCTSTR pSrcFile,
  _In_   const D3DXMACRO *pDefines,
  _In_   LPD3DXINCLUDE pInclude,
  _In_   DWORD Flags,
  _In_   LPD3DXEFFECTPOOL pPool,
  _Out_  LPD3DXEFFECT *ppEffect,
  _Out_  LPD3DXBUFFER *ppCompilationErrors
);

I need something more along the lines of void* or at least some way to compile from a block of memory. Other than just saving the data to a file, compiling, and deleting the file, is there a way to do this?

wchar_t* shaderCode = L"//Poorly formatted shader code goes here";

I want to be able to literally compile from the above section of memory. How can this be done?

1
What is your development environment? (Microsoft Visual Studio provides resource files)Hesam Qodsi
Yes, microsoft visual studio indeed. I'm going to look into that, thanks!Joseph Pla

1 Answers

3
votes

Yes. the D3DXCreateEffect function. Creates an effect from an ASCII or binary effect description.

http://msdn.microsoft.com/en-us/library/windows/desktop/bb172763(v=vs.85).aspx

Might also check out D3DX10CompileFromMemory..

http://msdn.microsoft.com/en-us/library/windows/desktop/bb310587(v=vs.85).aspx