Jump to content

  • Log In with Google      Sign In   
  • Create Account


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


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 3D BYTE   Members   -  Reputation: 126

Like
0Likes
Like

Posted 08 February 2010 - 02:59 AM

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

Sponsor:

#2 DieterVW   Members   -  Reputation: 700

Like
1Likes
Like

Posted 08 February 2010 - 05:04 AM

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.

#3 3D BYTE   Members   -  Reputation: 126

Like
0Likes
Like

Posted 08 February 2010 - 05:58 AM

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!




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS