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-2026 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;
15struct ShaderBytecode;
16
19public:
22 ShaderProgram(const Shader& vertex, const Shader& fragment);
23
26 explicit ShaderProgram(const ShaderBytecode&);
28 ShaderProgram(const ShaderProgram&) = delete;
29 ShaderProgram(ShaderProgram&&) noexcept;
30 ShaderProgram& operator=(const ShaderProgram&) = delete;
31 ShaderProgram& operator=(ShaderProgram&&) noexcept;
32
33 struct Impl;
35 struct Context {
36 explicit Context(const Impl&);
37 ~Context();
38 Context(const Context&) = delete;
39 Context& operator=(const Context&) = delete;
40 Context(Context&&) noexcept;
41 Context& operator=(Context&&) = delete;
42
45 static void setUniform(int location, int v0);
46 static void setUniform(int location, float v0);
47 static void setUniform(int location, float v0, float v1);
48 static void setUniform(int location, float v0, float v1, float v2, float v3);
49
51 static void setUniform(int location, Rgb);
52
53 private:
54 static int referenceCount;
55 static const Impl* activeImpl;
56 };
57
58#if __cplusplus >= 201703L
59 [[nodiscard]]
60#endif
62 use() const;
63
64 [[nodiscard]] int getAttribLocation(const std::string& name) const;
65
77 [[nodiscard]] int getUniformLocation(const std::string& name) const;
78
79private:
81};
82
83void setUniform(int location, float v0, float v1);
84
85} // 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:21
Linked vertex and fragment shaders.
int getUniformLocation(const std::string &name) const
Returns the location of a uniform variable for use with Context::setUniform.
ShaderProgram(const Shader &vertex, const Shader &fragment)
Not supported by the Direct3D 12 and Metal renderers and the Vulkan renderer on Android,...
ShaderProgram(const ShaderBytecode &)
Creates the program from what jngl-shaderc has compiled it to.
Fragment or vertex GLSL shader.
Definition Shader.hpp:14
JNGL's main namespace.
A ShaderProgram's GLSL compiled at build time by jngl-shaderc, for the Vulkan (SPIR-V),...
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.