74 lines
2.2 KiB
C++
74 lines
2.2 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"),
|
|
TexMask = const_hash("tex_mask"),
|
|
TexStroke = const_hash("tex_stroke"),
|
|
Lock = const_hash("lock"),
|
|
Col = const_hash("col"),
|
|
Tof = const_hash("tof"),
|
|
Tsz = const_hash("tsz"),
|
|
Alpha = const_hash("alpha"),
|
|
Mask = const_hash("mask"),
|
|
Resolution = const_hash("resolution"),
|
|
Highlight = const_hash("highlight"),
|
|
};
|
|
|
|
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"),
|
|
CompErase = const_hash("comp-erase"),
|
|
CompDraw = const_hash("comp-draw"),
|
|
UVs = const_hash("uvs"),
|
|
Font = const_hash("font"),
|
|
Atlas = const_hash("atlas"),
|
|
Stroke = const_hash("stroke"),
|
|
Checkerboard= const_hash("checkerboard"),
|
|
Equirect = const_hash("equirect"),
|
|
};
|
|
|
|
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();
|
|
};
|
|
|
|
}
|