<commit_before>#ifndef __SHADER_EFFECT_H_GUARD
#define __SHADER_EFFECT_H_GUARD

#include <api/math.h>
#include <api/gpu/graphics.h>
#include <util/rect.h>

namespace rendering {

namespace shader_type {
    enum shader_type_set { VERTEX = 1, TESS_CONTROL = 2, TESS_EVAL = 4, GEOMETRY = 8, FRAGMENT = 16 };

    constexpr shader_type_set operator|(shader_type_set a, shader_type_set b)
    {
        return static_cast<shader_type_set>(static_cast<int>(a) | static_cast<int>(b));
    }

    constexpr shader_type_set TESSELLATION = TESS_CONTROL | TESS_EVAL;
} // namespace shader_type

typedef shader_type::shader_type_set shader_type_set;


class shader_effect {
public:
    shader_effect() : program_id(0), z_test_enabled(true), z_write_enabled(true) {}
    ~shader_effect();
    shader_effect(const shader_effect&) = delete;
    shader_effect& operator=(const shader_effect&) = delete;

    template <typename T>
    void set_parameter(const char *param_name, const T& value) const;
    void load_shaders(const char *filename, shader_type_set pipeline_stages);
    bool get_z_test_state() const { return z_test_enabled; }
    void set_z_test_state(bool enabled) { z_test_enabled = enabled; }
    bool get_z_write_state() const { return z_write_enabled; }
    void set_z_write_state(bool enabled) { z_write_enabled = enabled; }
    void use() const;

private:
    GLint get_param_location(const char *param_name) const;
    GLuint compile_gl_shader(GLenum shader_type, const char *filename, const char *defines="");

    GLuint program_id;
    bool z_test_enabled, z_write_enabled;
};

template<typename T>
inline void shader_effect::set_parameter(const char *param_name, const T& value) const
{ static_assert(false, "not implemented"); }

template<> inline void shader_effect::set_parameter<GLint>(const char *param_name, const GLint& value) const
{
    glUniform1i(get_param_location(param_name), value);
    GL_CHECK();
}

template<> inline void shader_effect::set_parameter<GLuint>(const char *param_name, const GLuint& value) const
{
    glUniform1i(get_param_location(param_name), value);<commit_msg>make static_assert depend on template type<commit_after>#ifndef __SHADER_EFFECT_H_GUARD
#define __SHADER_EFFECT_H_GUARD

#include <api/math.h>
#include <api/gpu/graphics.h>
#include <util/rect.h>

namespace rendering {

namespace shader_type {
    enum shader_type_set { VERTEX = 1, TESS_CONTROL = 2, TESS_EVAL = 4, GEOMETRY = 8, FRAGMENT = 16 };

    constexpr shader_type_set operator|(shader_type_set a, shader_type_set b)
    {
        return static_cast<shader_type_set>(static_cast<int>(a) | static_cast<int>(b));
    }

    constexpr shader_type_set TESSELLATION = TESS_CONTROL | TESS_EVAL;
} // namespace shader_type

typedef shader_type::shader_type_set shader_type_set;


class shader_effect {
public:
    shader_effect() : program_id(0), z_test_enabled(true), z_write_enabled(true) {}
    ~shader_effect();
    shader_effect(const shader_effect&) = delete;
    shader_effect& operator=(const shader_effect&) = delete;

    template <typename T>
    void set_parameter(const char *param_name, const T& value) const;
    void load_shaders(const char *filename, shader_type_set pipeline_stages);
    bool get_z_test_state() const { return z_test_enabled; }
    void set_z_test_state(bool enabled) { z_test_enabled = enabled; }
    bool get_z_write_state() const { return z_write_enabled; }
    void set_z_write_state(bool enabled) { z_write_enabled = enabled; }
    void use() const;

private:
    GLint get_param_location(const char *param_name) const;
    GLuint compile_gl_shader(GLenum shader_type, const char *filename, const char *defines="");

    GLuint program_id;
    bool z_test_enabled, z_write_enabled;
};

template<typename T>
inline void shader_effect::set_parameter(const char *param_name, const T& value) const
{ static_assert(sizeof(T)==-1, "not implemented"); }

template<> inline void shader_effect::set_parameter<GLint>(const char *param_name, const GLint& value) const
{
    glUniform1i(get_param_location(param_name), value);
    GL_CHECK();
}

template<> inline void shader_effect::set_parameter<GLuint>(const char *param_name, const GLuint& value) const
{
    glUniform1i(get_param_location(param_name), value);
{'fraction_non_alphanumeric': 0.09997647612326512, 'fraction_numerical': 0.004469536579628322, 'mean_word_length': 5.531490015360983, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7370435', 'n_tokens_mistral': 1468, 'n_tokens_neox': 1427, 'n_words': 322}