MCPcopy Create free account
hub / github.com/davideberly/GeometricTools / CreateFromNamedSources

Method CreateFromNamedSources

GTE/Graphics/GL46/GLSLProgramFactory.cpp:32–107  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

30}
31
32std::shared_ptr<VisualProgram> GLSLProgramFactory::CreateFromNamedSources(
33 std::string const&, std::string const& vsSource,
34 std::string const&, std::string const& psSource,
35 std::string const&, std::string const& gsSource)
36{
37 if (vsSource == "" || psSource == "")
38 {
39 LogError("A program must have a vertex shader and a pixel shader.");
40 }
41
42 GLuint vsHandle = Compile(GL_VERTEX_SHADER, vsSource);
43 if (vsHandle == 0)
44 {
45 return nullptr;
46 }
47
48 GLuint psHandle = Compile(GL_FRAGMENT_SHADER, psSource);
49 if (psHandle == 0)
50 {
51 return nullptr;
52 }
53
54 GLuint gsHandle = 0;
55 if (gsSource != "")
56 {
57 gsHandle = Compile(GL_GEOMETRY_SHADER, gsSource);
58 if (gsHandle == 0)
59 {
60 return nullptr;
61 }
62 }
63
64 GLuint programHandle = glCreateProgram();
65 if (programHandle == 0)
66 {
67 LogError("Program creation failed.");
68 }
69
70 glAttachShader(programHandle, vsHandle);
71 glAttachShader(programHandle, psHandle);
72 if (gsHandle > 0)
73 {
74 glAttachShader(programHandle, gsHandle);
75 }
76
77 if (!Link(programHandle))
78 {
79 glDetachShader(programHandle, vsHandle);
80 glDeleteShader(vsHandle);
81 glDetachShader(programHandle, psHandle);
82 glDeleteShader(psHandle);
83 if (gsHandle)
84 {
85 glDetachShader(programHandle, gsHandle);
86 glDeleteShader(gsHandle);
87 }
88 glDeleteProgram(programHandle);
89 return nullptr;

Callers

nothing calls this directly

Calls 8

glCreateProgramFunction · 0.85
glAttachShaderFunction · 0.85
glDetachShaderFunction · 0.85
glDeleteShaderFunction · 0.85
glDeleteProgramFunction · 0.85
SetVertexShaderMethod · 0.80
SetPixelShaderMethod · 0.80
SetGeometryShaderMethod · 0.80

Tested by

no test coverage detected