summaryrefslogtreecommitdiff
path: root/bowshock/source/init/bow/compShdProg.cxx
blob: 43bd7e516188947495d44405fef2a6bd9c66a217 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Copyright 2022-2023 Gabriel Jensen.

#include <bow/init.hxx>

#include <glad/glad.h>
#include <stdexcept>

void ::bow::bow::compShdProg(GLuint & shdProg,char const * const nm) noexcept {
	bow_log("compiling shader program \"%s\"",nm);

	GLuint vtxShd;
	GLuint fragShd;

	try {
		compShd(vtxShd, nm, GL_VERTEX_SHADER);
		compShd(fragShd,nm,GL_FRAGMENT_SHADER);
	}
	catch (::std::runtime_error const & e) {
		bow_logErr("%s",e.what());
		::bow::abrt();
	}
	catch (::std::bad_alloc const & e) {
		bow_logErr("unable to allocate memory for shader data");
		::bow::abrt();
	}

	shdProg = glCreateProgram();
	glAttachShader(shdProg,vtxShd);
	glAttachShader(shdProg,fragShd);
	glLinkProgram(shdProg);

	glDeleteShader(vtxShd);
	glDeleteShader(fragShd);
}