代码拉取完成,页面将自动刷新
同步操作将从 2144/Gut 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#pragma once
#include "Core.h"
struct ShaderCode
{
unsigned int id = 0;
bool CreateFrom(const char* code, int type);
void Release();
};
struct ShaderFile :public ShaderCode
{
bool CreateFromFile(std::string path, int type);
};
struct Shader
{
public:
bool CreateFromCode(const char* vcode, const char* fCode);
bool CreateFromFile(ShaderFile vFile, ShaderFile fFile);
bool CreateFromFilePath(std::string vPath, std::string fPath);
#ifdef WIN32
bool CreateFromFilePath(std::string vPath, std::string gPath, std::string fPath);
bool CreateFormFile(ShaderFile vFile, ShaderFile gFile, ShaderFile fFile);
#endif // DEBUG
public:
unsigned int ID = 0;
void Use();
void Create();
void Release();
void Link();
void UnUse();
~Shader()
{
glDeleteShader(ID);
}
void Bind(const std::string& name, unsigned int binding)
{
glUniformBlockBinding(ID , GetUniformBlockIndex(name), binding);
}
unsigned int GetUniformBlockIndex(const std::string& name)
{
return glGetUniformBlockIndex(ID, name.c_str());
}
unsigned int GetLocation(const std::string& name) const
{
unsigned int res= glGetUniformLocation(ID, name.c_str());
#ifdef SHADER_DEBUG
if (res == -1)
{
LOGE("index of location %s is -1", name.c_str());
}
#endif // SHADER_DEBUG
return res;
}
void setBool(const std::string& name, bool value) const
{
glUniform1i(GetLocation(name), (int)value);
}
// ------------------------------------------------------------------------
void setInt(const std::string& name, int value) const
{
glUniform1i(GetLocation(name), value);
}
// ------------------------------------------------------------------------
void setFloat(const std::string& name, float value) const
{
glUniform1f(GetLocation(name), value);
}
void SetFloatArray(const std::string& name, float* val, int num)
{
for (int i = 0; i < num; i++)
{
std::string label = name + std::string("[") + std::to_string(i) + "]";
setFloat(label, val[i]);
}
}
// ------------------------------------------------------------------------
void setVec2(const std::string& name, const float* value) const
{
glUniform2fv(GetLocation(name), 1, &value[0]);
}
void setVec2(const std::string& name, float x, float y) const
{
glUniform2f(GetLocation(name), x, y);
}
// ------------------------------------------------------------------------
void setVec3(const std::string& name, const float* value) const
{
glUniform3fv(GetLocation(name), 1, &value[0]);
}
void setVec3(const std::string& name, float x, float y, float z) const
{
glUniform3f(GetLocation(name), x, y, z);
}
// ------------------------------------------------------------------------
void setVec4(const std::string& name, const float* value, const int num = 1) const
{
glUniform4fv(GetLocation(name), num, &value[0]);
}
void setVec4(const std::string& name, float x, float y, float z, float w)
{
glUniform4f(GetLocation(name), x, y, z, w);
}
// ------------------------------------------------------------------------
void setMat2(const std::string& name, const float* mat) const
{
glUniformMatrix2fv(GetLocation(name), 1, GL_FALSE, &mat[0]);
}
// ------------------------------------------------------------------------
void setMat3(const std::string& name, const float* mat) const
{
glUniformMatrix3fv(GetLocation(name), 1, GL_FALSE, &mat[0]);
}
// ------------------------------------------------------------------------
void setMat4(const std::string& name, const float* mat) const
{
glUniformMatrix4fv(GetLocation(name), 1, GL_FALSE, &mat[0]);
}
};
struct ShaderVertexFramentDesc
{
const char* vcode;
const char* fcode;
};
struct ShaderVertexFragment : public Shader
{
};
struct ShaderVertexGeometryFragment :public Shader
{
};
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。