Skip to content

Commit

Permalink
CStdGLShaderProgram: Use concepts instead of std::enable_if
Browse files Browse the repository at this point in the history
  • Loading branch information
maxmitti authored and Fulgen301 committed Aug 7, 2023
1 parent 1d7bb55 commit 8919c62
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/StdGL.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
#endif
#include <StdDDraw2.h>

#include <concepts>
#include <type_traits>

class CStdWindow;

class CStdGLShader : public CStdShader
Expand All @@ -51,9 +54,6 @@ class CStdGLShader : public CStdShader

class CStdGLShaderProgram : public CStdShaderProgram
{
private:
template<typename T> static constexpr bool isFunctionPointer{std::is_function_v<std::remove_pointer_t<T>>};

public:
using CStdShaderProgram::CStdShaderProgram;

Expand All @@ -64,12 +64,14 @@ class CStdGLShaderProgram : public CStdShaderProgram

void EnsureProgram() override;

template<typename Func, typename... Args> typename std::enable_if_t<isFunctionPointer<Func>, bool> SetAttribute(std::string_view key, Func function, Args... args)
template<typename Func, typename... Args> requires std::invocable<Func, GLint, Args...>
bool SetAttribute(std::string_view key, Func function, Args... args)
{
return SetAttribute(key, &CStdGLShaderProgram::attributeLocations, glGetAttribLocation, function, args...);
}

template<typename Func, typename... Args> typename std::enable_if_t<isFunctionPointer<Func>, bool> SetUniform(std::string_view key, Func function, Args... args)
template<typename Func, typename... Args> requires std::invocable<Func, GLint, Args...>
bool SetUniform(std::string_view key, Func function, Args... args)
{
return SetAttribute(key, &CStdGLShaderProgram::uniformLocations, glGetUniformLocation, function, args...);
}
Expand All @@ -87,7 +89,10 @@ class CStdGLShaderProgram : public CStdShaderProgram
void OnDeselect() override;

using Locations = std::unordered_map<std::string, GLint>;
template<typename MapFunc, typename SetFunc, typename... Args> bool SetAttribute(std::string_view key, Locations CStdGLShaderProgram::*locationPointer, MapFunc mapFunction, SetFunc setFunction, Args... args)

template<typename MapFunc, typename SetFunc, typename... Args>
requires (std::is_invocable_r_v<GLint, MapFunc, GLuint, const char *> && std::invocable<SetFunc, GLint, Args...>)
bool SetAttribute(std::string_view key, Locations CStdGLShaderProgram::*locationPointer, MapFunc mapFunction, SetFunc setFunction, Args... args)
{
assert(shaderProgram);

Expand Down

0 comments on commit 8919c62

Please sign in to comment.