| 107 | } |
| 108 | |
| 109 | std::shared_ptr<VisualProgram> HLSLProgramFactory::CreateFromNamedSources( |
| 110 | std::string const& vsName, std::string const& vsSource, |
| 111 | std::string const& psName, std::string const& psSource, |
| 112 | std::string const& gsName, std::string const& gsSource) |
| 113 | { |
| 114 | LogAssert(vsSource != "" && psSource != "", |
| 115 | "A program must have a vertex shader and a pixel shader."); |
| 116 | |
| 117 | std::shared_ptr<HLSLShader> vshader; |
| 118 | std::shared_ptr<HLSLShader> pshader; |
| 119 | std::shared_ptr<HLSLShader> gshader; |
| 120 | |
| 121 | HLSLReflection hlslVShader = HLSLShaderFactory::CreateFromString(vsName, |
| 122 | vsSource, vsEntry, std::string("vs_") + version, defines, flags); |
| 123 | if (hlslVShader.IsValid()) |
| 124 | { |
| 125 | vshader = std::make_shared<HLSLShader>(hlslVShader, GT_VERTEX_SHADER); |
| 126 | } |
| 127 | else |
| 128 | { |
| 129 | return nullptr; |
| 130 | } |
| 131 | |
| 132 | HLSLReflection hlslPShader = HLSLShaderFactory::CreateFromString(psName, |
| 133 | psSource, psEntry, std::string("ps_") + version, defines, flags); |
| 134 | if (hlslPShader.IsValid()) |
| 135 | { |
| 136 | pshader = std::make_shared<HLSLShader>(hlslPShader, GT_PIXEL_SHADER); |
| 137 | } |
| 138 | else |
| 139 | { |
| 140 | return nullptr; |
| 141 | } |
| 142 | |
| 143 | HLSLReflection hlslGShader; |
| 144 | if (gsSource != "") |
| 145 | { |
| 146 | hlslGShader = HLSLShaderFactory::CreateFromString(gsName, |
| 147 | gsSource, gsEntry, std::string("gs_") + version, defines, flags); |
| 148 | if (hlslGShader.IsValid()) |
| 149 | { |
| 150 | gshader = std::make_shared<HLSLShader>(hlslGShader, GT_GEOMETRY_SHADER); |
| 151 | } |
| 152 | else |
| 153 | { |
| 154 | return nullptr; |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | auto program = std::make_shared<HLSLVisualProgram>(); |
| 159 | program->SetVertexShader(vshader); |
| 160 | program->SetPixelShader(pshader); |
| 161 | program->SetGeometryShader(gshader); |
| 162 | return program; |
| 163 | } |
| 164 | |
| 165 | std::shared_ptr<ComputeProgram> HLSLProgramFactory::CreateFromBytecode( |
| 166 | std::vector<uint8_t> const& csBytecode) |
nothing calls this directly
no test coverage detected