2

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?

Joseph Pla
  • 1,600
  • 1
  • 10
  • 21

1 Answers1

3

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

Aaron Hagan
  • 586
  • 2
  • 4
  • Wow, I feel really stupid. Thanks so much, this is perfect :) – Joseph Pla Jul 23 '13 at 21:00
  • I'll accept it as soon as I can, problem is you answered too fast ;) – Joseph Pla Jul 23 '13 at 21:01
  • @JosephPla: Note that this does *not* prevent a user from being able to access the shader. They can always yank it from your executable, though obviously it requires more effort. But it requires *less* effort than figuring out what compression your pack files use and decoding it from that. – Nicol Bolas Jul 23 '13 at 22:18
  • @NicolBolas alright, thanks alot. I'll definitely keep that in mind. – Joseph Pla Jul 23 '13 at 22:35