Jump to content
  • Advertisement
Sign in to follow this  
Patrick Polzin

DX11 How do I work with ID3D10Include::Open()?

This topic is 3057 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi guys, since yesterday I want to try to include additional HLSL Shader Files with the D3DX11 Effect Framework but I have none success. As I looked to the documentation, I found out that I have to create a class which inherits from ID3D10Include and I have to write the functions Open() and Close(). I think Close() isn't a problem, but Open(). As I read from documentation, I'm reading "A user-implemented method for opening and reading the contents of a shader #include file.". So I'm understanding that I have to read the content from a file and save it into ppData. Am I right?
// The defined open Method for ID3D10Include
STDMETHOD(Open)(D3D10_INCLUDE_TYPE IncludeType, LPCSTR pFileName, LPCVOID pParentData, LPCVOID *ppData, UINT *pBytes)
{
	// Read the file content
	FILE *f = fopen(pFileName, "rb");
	if(f == nullptr)
	{
		char buffere[2048];
		sprintf_s(buffere, 2048, "Could not load the effect include file \"%s\".", pFileName);
		BSX_ERROR(buffere);
		return E_FAIL;
	}

	// Get the file size
	fseek(f, 0, SEEK_END);
	long sz = ftell(f);
	fseek(f, 0, SEEK_SET);

	// Get the file content
	char *buffer = new char[sz];
	fread(buffer, 1, sz, f);
	fclose(f);

	// Save the file data into ppData and the size into pBytes.
	*ppData = buffer;
	pBytes = new UINT; *pBytes = UINT(sz);
		
	// return E_FAIL; // Because it isn't successfull supported...
	return S_OK;
}
But it doesn't work and my shader is telling me, that the definitions from the include file are not known. Another possibility I checked out was to compile the shader file. But here the shader will completly fail. The ID3D10Include::Open() should be identical with it from D3D9 and D3D10 the documentation says. Has somebody an idea where the problem is or knows my ideologic error? [oh] Thank you

Share this post


Link to post
Share on other sites
Advertisement
First, your code has an error. pBytes is being passed in so that you can set the size, not create a new UINT. Your code should read *pByte = sz; It's not working right now because the size value after the call to open would still be zero and your memory would be leaked.


The other thing is that the compiler will search for include files automatically in the same directory as the file you are trying to compile (provided that the include object is NULL). If I recall correctly, I believe that it even recursively searches down the sub directories. This interface is more useful for doing things like opening resources that are in the exe, like a resource file, or unpacking shaders that are in zip files.

Share this post


Link to post
Share on other sites
Oh my god, and now it works fine.

Sometimes I watching hours to the monitor and a can't find the bug. What for an horror to waste time for this simple bug.

Really really thank you! [smile] And the day is saved!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!