File: ShaderProgram.h

package info (click to toggle)
freespace2 25.0.0~rc11%2Brepack-1
  • links: PTS, VCS
  • area: non-free
  • in suites: forky, sid
  • size: 47,232 kB
  • sloc: cpp: 657,500; ansic: 22,305; sh: 293; python: 200; makefile: 198; xml: 181
file content (75 lines) | stat: -rw-r--r-- 1,525 bytes parent folder | download
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75

#ifndef OPENGL_SHADER_PROGRAM_H
#define OPENGL_SHADER_PROGRAM_H
#pragma once

#include "globalincs/pstypes.h"
#include "gropenglshader.h"

#include <glad/glad.h>

namespace opengl {

class ShaderProgram;
class ShaderUniforms {
	struct uniform_bind
	{
		SCP_string name;

		int value;
	};

	ShaderProgram* _program;

	SCP_vector<uniform_bind> _uniforms;

	SCP_unordered_map<SCP_string, size_t> _uniform_lookup;

	SCP_unordered_map<SCP_string, GLint> _uniform_locations;

	size_t findUniform(const SCP_string &name);
	GLint findUniformLocation(const SCP_string& name);
 public:
	explicit ShaderUniforms(ShaderProgram* shaderProgram);

	void setTextureUniform(const SCP_string &name, const int texture_unit);
};

enum ShaderStage {
	STAGE_VERTEX,
	STAGE_GEOMETRY,
	STAGE_FRAGMENT
};

class ShaderProgram {
	GLuint _program_id;

	SCP_vector<GLuint> _compiled_shaders;

	void freeCompiledShaders();
 public:
	explicit ShaderProgram(const SCP_string& program_name);
	~ShaderProgram();

	ShaderUniforms Uniforms;

	ShaderProgram(const ShaderProgram&) = delete;
	ShaderProgram& operator=(const ShaderProgram&) = delete;

	ShaderProgram(ShaderProgram&& other) noexcept = default;
	ShaderProgram& operator=(ShaderProgram&& other) noexcept = default;

	void use();

	void addShaderCode(ShaderStage stage, const SCP_string& name, const SCP_vector<SCP_string>& codeParts);

	void linkProgram();

	void initAttribute(const SCP_string& name, const vec4& default_value);

	GLuint getShaderHandle();
};

}

#endif // OPENGL_SHADER_PROGRAM_H