summaryrefslogtreecommitdiff
path: root/gfx/gl/uiShader.h
blob: 6d001666b7381e64574d0fb9ce552bdf930f7347 (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
47
#pragma once

#include "config/types.h"
#include "gl_traits.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);
			glUniform(uiProjectionLoc, 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 {*this, "colour"};
	};

public:
	IconProgram icon;
	TextProgram text;
};