summaryrefslogtreecommitdiff
path: root/gfx/gl/uiShader.h
blob: 362e90ccbf805d9baac893b801dcb4ed54529daf (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
46
#pragma once

#include "config/types.h"
#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 RGB & colour) const;

	private:
		RequiredUniformLocation colorLoc;
	};

public:
	IconProgram icon;
	TextProgram text;
};