JNGL
Easy to use cross-platform 2D game library
Loading...
Searching...
No Matches
ShaderProgram.hpp
Go to the documentation of this file.
1// Copyright 2018-2025 Jan Niklas Hasse <jhasse@bixense.com>
2// For conditions of distribution and use, see copyright notice in LICENSE.txt
5#pragma once
6
7#include "Rgb.hpp"
8
9#include <memory>
10#include <string>
11
12namespace jngl {
13
14class Shader;
15
18public:
19 ShaderProgram(const Shader& vertex, const Shader& fragment);
21 ShaderProgram(const ShaderProgram&) = delete;
22 ShaderProgram(ShaderProgram&&) = delete;
23 ShaderProgram& operator=(const ShaderProgram&) = delete;
24 ShaderProgram& operator=(ShaderProgram&&) = delete;
25
26 struct Impl;
28 struct Context {
29 explicit Context(const Impl&);
30 ~Context();
31 Context(const Context&) = delete;
32 Context& operator=(const Context&) = delete;
33 Context(Context&&) noexcept;
34 Context& operator=(Context&&) = delete;
35
38 static void setUniform(int location, int v0);
39 static void setUniform(int location, float v0, float v1);
40 static void setUniform(int location, float v0, float v1, float v2, float v3);
41
43 static void setUniform(int location, Rgb);
44
45 private:
46 static int referenceCount;
47 static const Impl* activeImpl;
48 };
49
50#if __cplusplus >= 201703L
51 [[nodiscard]]
52#endif
54 use() const;
55
56 [[nodiscard]] int getAttribLocation(const std::string& name) const;
58 [[nodiscard]] int getUniformLocation(const std::string& name) const;
59
60private:
62};
63
64void setUniform(int location, float v0, float v1);
65
66} // namespace jngl
Contains jngl::Rgb class.
Object representing a RGB color, new version of jngl::Color (which will be deprecated in the future)
Definition Rgb.hpp:15
Linked vertex and fragment shaders.
int getUniformLocation(const std::string &name) const
Fragment or vertex GLSL shader.
Definition Shader.hpp:12
JNGL's main namespace.
Lifetime object when the ShaderProgram is in use.
static void setUniform(int location, Rgb)
sets a vec3 to the color of the Rgb object
static void setUniform(int location, int v0)
Sets the Context's associated ShaderProgram's uniform.