Sign in to follow this  
DOrmisher

Passing DX Shader Types as Parameters

Recommended Posts

Im currently creating a renderer for my engine and I am trying to get a shader manager class working. I have also created 2 seperate VertexShader and PixelShader classes. When a load shader function in the shader manager is called it creates a new object of the vertex or pixel shader class. These classes have these as properties:
//Shader and Shader consts table
LPDIRECT3DVERTEXSHADER9 m_Shader;
LPD3DXCONSTANTTABLE     m_ShaderConsts;
The constructor of both these classes then actually does the loading and compiling of the shaders like so:

	// Temporary variable to hold compiled pixel shader code
    LPD3DXBUFFER pShaderCode;

	// Compile external HLSL pixel shader into shader code to submit to the hardware
		D3DXCompileShaderFromFile( fileName.c_str(), // File containing pixel shader (HLSL)
			                       NULL, NULL,       // Advanced compilation options - not needed here
								   "main",           // Name of main function in the shader
								   "vs_3_0",         // Target vertex shader hardware - vs_1_1 is lowest level
												     // and will work on all video cards with a pixel shader
								   0,				 // Additional compilation flags (such as debug flags)
								   &pShaderCode,     // Ptr to variable to hold compiled shader code
								   NULL,             // Ptr to variable to hold error messages (not needed)
								   m_ShaderConsts );      // Ptr to variable to hold constants for the shader


	//***************************************************
	// Step 2: Convert compiled program to usable shader

	// Create the pixel shader using the compiled shader code
    d3dDevice->CreateVertexShader( (DWORD*)pShaderCode->GetBufferPointer(), m_Shader );
    
	// Discard the shader code now the shader has been created 
	pShaderCode->Release();
However I am hitting errors when I am trying to use the properties of the class in the DX functions, for example in the CreateVertexShader function, the last parametre wont be accepted because it is not the correct type, this is the exact output for that error:
error C2664: 'IDirect3DDevice9::CreateVertexShader' : cannot convert parameter 2 from 'LPDIRECT3DPIXELSHADER9' to 'IDirect3DVertexShader9 **'
I dont understand this as I thought the type LPDIRECT3DPIXELSHADER9 was actually a pointer to type IDirect3DVertexShader9 anyway. I assume it must be the ** at the end of the IDirect3DVertexShader9** but I dont actually know what that means. Any help anyone??? Thanks

Share this post


Link to post
Share on other sites
When you have "**" after a type, it means the variable or parameter is a pointer to a pointer of that type. So "IDirect3DVertexShader9**" is equivalent to "LPDIRECT3DVERTEXSHADER9*". You need to use the "&" operator to pass the address of your m_Shader variable.

The reason you do this is so that the CreateVertexShader method can set the value of your pointer. It's similar to using pass-by-reference in C++, however Direct3D doesn't use that since it's built upon COM.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this