1 Star 0 Fork 1

波波/Gut

forked from 2144/Gut 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Shader.cpp 2.48 KB
一键复制 编辑 原始数据 按行查看 历史
2144 提交于 2023-08-31 15:46 . s
#include "Shader.h"
bool ShaderFile::CreateFromFile(std::string path, int type)
{
bool gr = true;
std::ifstream ifs(path, std::ios::in);
if (!ifs.is_open())
{
LOGI("cannot open file %s [path]", path.c_str());
ifs.close();
return false;
}
std::string text = std::string((std::istreambuf_iterator<char>(ifs)),
(std::istreambuf_iterator<char>()));
gr = CreateFrom(text.c_str(), type);
ifs.close();
return gr;
}
bool Shader::CreateFromCode(const char* vcode, const char* fcode)
{
ShaderFile vFile;
ShaderFile fFile;
ThrowIfFailed(vFile.CreateFrom(vcode, GL_VERTEX_SHADER));
ThrowIfFailed(fFile.CreateFrom(fcode, GL_FRAGMENT_SHADER));
this->ID = glCreateProgram();
glAttachShader(this->ID, vFile.id);
glAttachShader(this->ID, fFile.id);
glLinkProgram(ID);
return true;
}
bool Shader::CreateFromFile(ShaderFile vFile, ShaderFile fFile)
{
this->ID = glCreateProgram();
glAttachShader(this->ID, vFile.id);
glAttachShader(this->ID, fFile.id);
glLinkProgram(ID);
return true;
}
bool Shader::CreateFromFilePath(std::string vPath, std::string fPath)
{
bool gr;
ShaderFile vFile;
ShaderFile fFile;
ThrowIfFailed(vFile.CreateFromFile(vPath, GL_VERTEX_SHADER));
ThrowIfFailed(fFile.CreateFromFile(fPath, GL_FRAGMENT_SHADER));
return CreateFromFile(vFile, fFile);
}
bool ShaderCode::CreateFrom(const char* code, int type)
{
this->id = glCreateShader(type);
glShaderSource(id, 1, &code, NULL);
glCompileShader(id);
if (!checkCompileErrors(id, GetShaderType(type)))
{
return false;
}
return true;
}
void ShaderCode::Release()
{
glDeleteShader(this->id);
}
void Shader::Use()
{
glUseProgram(ID);
}
void Shader::Create()
{
ID=glCreateProgram();
}
void Shader::Release()
{
glDeleteProgram(this->ID);
}
void Shader::Link()
{
glLinkProgram(ID);
}
void Shader::UnUse()
{
glUseProgram(0);
}
#ifdef WIN32
bool Shader::CreateFormFile(ShaderFile vFile, ShaderFile gFile, ShaderFile fFile)
{
this->ID = glCreateProgram();
glAttachShader(this->ID, vFile.id);
glAttachShader(this->ID, gFile.id);
glAttachShader(this->ID, fFile.id);
glLinkProgram(ID);
return true;
}
bool Shader::CreateFromFilePath(std::string vPath, std::string gPath, std::string fPath)
{
ShaderFile vFile;
ShaderFile gFile;
ShaderFile fFile;
ThrowIfFailed(vFile.CreateFromFile(vPath, GL_VERTEX_SHADER));
ThrowIfFailed(gFile.CreateFromFile(gPath, GL_GEOMETRY_SHADER));
ThrowIfFailed(fFile.CreateFromFile(fPath, GL_FRAGMENT_SHADER));
return CreateFormFile(vFile, gFile, fFile);
}
#endif // DEBUG
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/bobo110/gut.git
git@gitee.com:bobo110/gut.git
bobo110
gut
Gut
master

搜索帮助