66 lines
1.9 KiB
C++
66 lines
1.9 KiB
C++
#pragma once
|
|
#include "util.h"
|
|
|
|
namespace ui {
|
|
|
|
enum class kShaderUniform : uint16_t
|
|
{
|
|
MVP = const_hash("mvp"),
|
|
Tex = const_hash("tex"),
|
|
TexFG = const_hash("tex_fg"),
|
|
TexBG = const_hash("tex_bg"),
|
|
Col = const_hash("col"),
|
|
Tof = const_hash("tof"),
|
|
Tsz = const_hash("tsz"),
|
|
Alpha = const_hash("alpha"),
|
|
Resolution = const_hash("resolution"),
|
|
};
|
|
|
|
enum class kShader : uint16_t
|
|
{
|
|
Color = const_hash("color"),
|
|
ColorQuad = const_hash("color-quad"),
|
|
ColorHue = const_hash("color-hue"),
|
|
Texture = const_hash("texture"),
|
|
TextureAlpha = const_hash("texture-alpha"),
|
|
UVs = const_hash("uvs"),
|
|
Font = const_hash("font"),
|
|
Atlas = const_hash("atlas"),
|
|
Stroke = const_hash("stroke"),
|
|
StrokeErase = const_hash("stroke-erase"),
|
|
StrokeLayer = const_hash("stroke-layer"),
|
|
};
|
|
|
|
class Shader
|
|
{
|
|
std::map<kShaderUniform, GLuint> m_umap;
|
|
GLuint prog;
|
|
public:
|
|
kShader name;
|
|
bool create(const char* vertex, const char* fragment);
|
|
void use();
|
|
void u_vec4(kShaderUniform id, const glm::vec4& v);
|
|
void u_vec2(kShaderUniform id, const glm::vec2& v);
|
|
void u_mat4(kShaderUniform id, const glm::mat4& m);
|
|
void u_int(kShaderUniform id, int i);
|
|
void u_float(kShaderUniform id, float f);
|
|
GLint GetAttribLocation(const char* name);
|
|
};
|
|
|
|
class ShaderManager
|
|
{
|
|
static std::map<kShader, Shader> m_shaders;
|
|
static Shader* m_current;
|
|
public:
|
|
static bool create(kShader id, const char* vertex, const char* fragment);
|
|
static void use(kShader id);
|
|
static void use(const char* name);
|
|
static void u_vec4(kShaderUniform id, const glm::vec4& v);
|
|
static void u_vec2(kShaderUniform id, const glm::vec2& v);
|
|
static void u_mat4(kShaderUniform id, const glm::mat4& m);
|
|
static void u_int(kShaderUniform id, int i);
|
|
static void u_float(kShaderUniform id, float f);
|
|
static void invalidate();
|
|
};
|
|
|
|
} |