summaryrefslogtreecommitdiff
path: root/gfx/gl/uiShader.h
blob: 2766af8d7cc391802bdb59d862920694424b894a (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
36
37
38
39
40
41
42
43
44
45
#pragma once

#include "program.h"
#include <cstddef>
#include <glad/gl.h>
#include <glm/glm.hpp>
#include <glm/gtc/type_ptr.hpp>

class UIShader {
public:
	UIShader(std::size_t width, std::size_t height);

private:
	explicit UIShader(const glm::mat4 & viewProjection);

	class UIProgram : public Program {
	public:
		template<typename... S>
		explicit UIProgram(const glm::mat4 & vp, S &&... srcs) : Program {std::forward<S>(srcs)...}
		{
			const RequiredUniformLocation uiProjectionLoc {*this, "uiProjection"};
			glUseProgram(*this);
			glUniformMatrix4fv(uiProjectionLoc, 1, GL_FALSE, glm::value_ptr(vp));
		}
	};

	class IconProgram : public UIProgram {
	public:
		explicit IconProgram(const glm::mat4 & vp);
		using Program::use;
	};

	class TextProgram : public UIProgram {
	public:
		explicit TextProgram(const glm::mat4 & vp);
		void use(const glm::vec3 & colour) const;

	private:
		RequiredUniformLocation colorLoc;
	};

public:
	IconProgram icon;
	TextProgram text;
};