mirror of
https://github.com/MichaelFisher1997/opengl-cpp.git
synced 2025-04-27 06:03:10 +00:00
37 lines
970 B
C++
37 lines
970 B
C++
#pragma once
|
|
|
|
#include <string>
|
|
#include <unordered_map>
|
|
|
|
struct ShaderProgramSource
|
|
{
|
|
std::string VertexSource;
|
|
std::string FragmentSource;
|
|
};
|
|
|
|
class Shader
|
|
{
|
|
private:
|
|
unsigned int m_RendererID;
|
|
std::string m_FilePath;
|
|
std::unordered_map<std::string, int> m_UniformLocationCache;
|
|
|
|
public:
|
|
Shader(const std::string& filepath);
|
|
~Shader();
|
|
|
|
void Bind() const;
|
|
void Unbind() const;
|
|
|
|
// Set uniforms
|
|
void SetUniform4f(const std::string& name, float f0, float f1, float f2, float f3);
|
|
void SetUniform1f(const std::string& name, float value);
|
|
|
|
private:
|
|
int GetUniformLocation(const std::string& name);
|
|
struct ShaderProgramSource ParseShader(const std::string& filepath);
|
|
unsigned int CompileShader(unsigned int type, const std::string& source);
|
|
unsigned int CreateShader(const std::string& vertexShader, const std::string& fragmentShader);
|
|
|
|
};
|