Jump to content
  • Advertisement
Sign in to follow this  

Passing DX Shader Types as Parameters

This topic is 3635 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

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
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 
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
Sign in to follow this  

  • Advertisement

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!