| 107 | } |
| 108 | |
| 109 | std::shared_ptr<ComputeProgram> GLSLProgramFactory::CreateFromNamedSource( |
| 110 | std::string const&, std::string const& csSource) |
| 111 | { |
| 112 | if (csSource == "") |
| 113 | { |
| 114 | LogError("A program must have a compute shader."); |
| 115 | } |
| 116 | |
| 117 | GLuint csHandle = Compile(GL_COMPUTE_SHADER, csSource); |
| 118 | if (csHandle == 0) |
| 119 | { |
| 120 | return nullptr; |
| 121 | } |
| 122 | |
| 123 | GLuint programHandle = glCreateProgram(); |
| 124 | if (programHandle == 0) |
| 125 | { |
| 126 | LogError("Program creation failed."); |
| 127 | } |
| 128 | |
| 129 | glAttachShader(programHandle, csHandle); |
| 130 | |
| 131 | if (!Link(programHandle)) |
| 132 | { |
| 133 | glDetachShader(programHandle, csHandle); |
| 134 | glDeleteShader(csHandle); |
| 135 | glDeleteProgram(programHandle); |
| 136 | return nullptr; |
| 137 | } |
| 138 | |
| 139 | auto program = std::make_shared<GLSLComputeProgram>(programHandle, csHandle); |
| 140 | GLSLReflection const& reflector = program->GetReflector(); |
| 141 | auto cshader = std::make_shared<GLSLShader>(reflector, GT_COMPUTE_SHADER, GLSLReflection::ReferenceType::COMPUTE); |
| 142 | program->SetComputeShader(cshader); |
| 143 | return program; |
| 144 | } |
| 145 | |
| 146 | GLuint GLSLProgramFactory::Compile(GLenum shaderType, std::string const& source) |
| 147 | { |
nothing calls this directly
no test coverage detected