I learn C ++ and DirectX, and I notice a lot of duplication, trying to keep the structure in my HLSL shaders and C ++ code in sync. I would like to separate the structures, since both languages have the same #includesemantics and structure of the header file. I met success with
#pragma once
#ifdef __cplusplus
#include <DirectXMath.h>
using namespace DirectX;
using float4 = XMFLOAT4;
namespace ColorShader
{
#endif
struct VertexInput
{
float4 Position;
float4 Color;
};
struct PixelInput
{
float4 Position;
float4 Color;
};
#ifdef __cplusplus
}
#endif
The problem is that when compiling these shaders, FXC tells me input parameter 'input' missing sematicsabout the main function of my pixel shader:
#include "ColorStructs.h"
void main(PixelInput input)
{
}
I know that I need to have semantics like float4 Position : POSITION, but I cannot think of a way to do this so as not to violate the C ++ syntax.
Is there a way to maintain common structures between HLSL and C ++? Or is this impracticable and requires duplication of structures between two source trees?