summaryrefslogtreecommitdiff
path: root/gfx/gl/program.cpp
blob: 0b60eaaba50bbc80e59f6fb72d16e1026a47009f (plain)
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
35
#include "program.h"
#include "shader.h"
#include <glm/gtc/type_ptr.hpp>
#include <glm/gtx/transform.hpp>
#include <location.h>
#include <maths.h>

void
Program::linkAndValidate() const
{
	glLinkProgram(m_program);
	Shader::CheckShaderError(m_program, GL_LINK_STATUS, true, "Error linking shader program");

	glValidateProgram(m_program);
	Shader::CheckShaderError(m_program, GL_VALIDATE_STATUS, true, "Invalid shader program");
}

void
Program::use() const
{
	glUseProgram(m_program);
}

Program::UniformLocation::UniformLocation(GLuint program, const char * name) :
	location {glGetUniformLocation(program, name)}
{
}

Program::RequiredUniformLocation::RequiredUniformLocation(GLuint program, const char * name) :
	UniformLocation {program, name}
{
	if (location < 0) {
		throw std::logic_error(std::string {"Required uniform does not exist: "} + name);
	}
}