Rune Engine  Version 0.2.7-alpha
Documentation for how to make games using the Rune Engine.
shader.h
1 
10 #ifndef SHADER_H_DEFINED
11 #define SHADER_H_DEFINED
12 
13 #include "core.h"
14 #include <fstream>
15 #include <string>
16 #include <sstream>
17 #include "renderWindow.h"
18 #include <unordered_map>
19 
20 namespace rune{
21 
23 struct RUNE_ENGINE ShaderProgramSource
24 {
26  std::string VertexSource;
27 
29  std::string FragmentSource;
34  ShaderProgramSource(std::string const& vertex, std::string const& frag) : VertexSource(vertex), FragmentSource(frag)
35  {
36  }
37 
38 };
39 
40 class RUNE_ENGINE Shader
41 {
42 
43 private:
44  //Shader id to be used for binding the shader during rendering.
45  unsigned int m_shaderID;
46  //Compile and set the shader up given string literals.
47  unsigned int CreateShader(std::string const& vertexShader, std::string const& fragmentShader);
48  //Create the shader into a compiled shader id for opengl.
49  unsigned int CompileShader(unsigned int type, const std::string& source);
50  //Parse a raw string containing glsl source code and turn it into a ShaderProgramSource.
51  ShaderProgramSource ParseShader(std::string const& sourceCode);
52 
53  std::unordered_map<std::string, int> m_UniformLocationCache;
54 
56  int getUniformLocation(std::string const& name);
57 
58 public:
60  Shader();
62  Shader(const std::string& filePath);
64  Shader(const char* sourceCode);
68  void makeNewShader(std::string const& filePath);
70  void bind(void);
72  int getShaderID();
74  void setShader(int shaderID);
76  void setUniform1f(std::string const& name, float value);
78  void setUniform2f(std::string const& name, float v0, float v1);
80  void setUniform3f(std::string const& name, float v0, float v1, float v2);
82  void setUniform4f(std::string const& name, float v0, float v1, float v2, float v3);
84  void setUniform1i(std::string const& name, int value);
85 
86 };
87 }
88 
89 #endif
90 
rune::ShaderProgramSource::FragmentSource
std::string FragmentSource
The fragment shader code to be compiled.
Definition: shader.h:29
rune::ShaderProgramSource::VertexSource
std::string VertexSource
The vertex shader code to be compiled.
Definition: shader.h:26
rune::ShaderProgramSource
Compilable GLSL code generated by the shader file.
Definition: shader.h:24
rune::ShaderProgramSource::ShaderProgramSource
ShaderProgramSource(std::string const &vertex, std::string const &frag)
Definition: shader.h:34
rune::Shader
A shader that can be used to render objects to the screen.
Definition: shader.h:41
rune
The main namespace to be used for interfacing with the engine.
Definition: animator.h:21