可视化 如何在 C++/DirectX 和 HLSL 之间共享结构
visual How to share a struct between C++/DirectX and HLSL?
我正在学习C++和DirectX,我注意到在尝试保持HLSL着色器和C++代码中的结构同步时存在很多重复。我想分享结构,因为两种语言具有相同的#include
语义和头文件结构。我遇到了成功
// ColorStructs.h
#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
但是,问题在于在这些着色器的编译过程中,FXC告诉我input parameter 'input' missing sematics
了像素着色器的主要功能:
#include "ColorStructs.h"
void main(PixelInput input)
{
// Contents elided
}
我知道我需要像float4 Position : POSITION
这样的语义,但我无法想出一种不违反C++语法的方法。
有没有办法使 HLSL 和 C++ 之间的结构保持通用?还是不可行,需要在两个源树之间复制结构?
您可以使用函数宏在编译时删除语义说明符C++
#ifdef __cplusplus
#define SEMANTIC(sem)
#else
#define SEMANTIC(sem) : sem
#endif
struct VertexInput
{
float4 Position SEMANTIC(POSITION0);
float4 Color SEMANTIC(COLOR0);
};
相关文章:
- C++中std::resize(n)和std::shrink_to_fit之间的区别
- int(c) 和 c-'0' 之间的区别。C++
- 在cuda线程之间共享大量常量数据
- 在c代码之间共享数据的最佳方式
- Mix_Init和Mix_OpenAudio SDL之间的区别是什么
- C++ 使用 assign 函数的字符串与直接使用 '=' 更改值的字符串之间的区别
- VSOMEIP-2个设备之间的通信(TCP/UDP)不工作
- std::atomic和std::condition_variable wait,notify_*方法之间的区别
- 大小相等但成员数量不同的结构之间的性能差异
- 类与私有变量的其他类之间的线程安全性
- 如何在cpp文件之间切换窗口?在Qt中
- 线程之间的布尔停止信号
- 我是C++编程的新手,这些代码之间有什么区别,我应该使用哪一个
- 在 const 函数中通过引用和指针返回之间的区别
- 我想知道长双倍和双倍之间的区别
- 如何防止clang格式在流运算符调用之间添加换行符<<
- 在两台机器之间进行时间戳的最佳c++chrono函数是什么
- 使用.find函数在c++中查找字符和另一个字符之间的大小
- 构造函数和转换运算符之间的重载解析
- 可视化 如何在 C++/DirectX 和 HLSL 之间共享结构