Set up Renderer base and shader compilation

This commit is contained in:
viktorljung
2015-12-01 10:35:59 +01:00
parent 798e42999d
commit 1fdf312af4
8 changed files with 391 additions and 2 deletions
+23
View File
@@ -0,0 +1,23 @@
#ifndef Renderer_h__
#define Renderer_h__
#include <sstream>
#include "IRenderer.h"
#include "ShaderProgram.h"
class Renderer : public IRenderer
{
public:
virtual void Initialize() override;
virtual void Draw(RenderQueueCollection& rq) override;
private:
void InitializeWindow();
void InitializeShaders();
ShaderProgram m_BasicForwardProgram;
};
#endif
+91
View File
@@ -0,0 +1,91 @@
#include <string>
#include "../Core/Util/Logging.h"
// OpenGL
#include <GL/glew.h>
#define GLFW_INCLUDE_GLU
#include <GLFW/glfw3.h>
#include <glext.h>
#include "Util/GLError.h"
#include <fstream>
#include <vector>
class Shader
{
public:
static GLuint CompileShader(GLenum shaderType, std::string fileName);
Shader(GLenum shaderType, std::string fileName);
virtual ~Shader();
GLuint Compile();
GLenum GetType() const;
std::string GetFileName() const;
GLuint GetHandle() const;
bool IsCompiled() const;
protected:
GLenum m_ShaderType;
std::string m_FileName;
GLint m_ShaderHandle;
};
template <int SHADERTYPE>
class ShaderType : public Shader
{
public:
ShaderType(std::string fileName)
: Shader(SHADERTYPE, fileName) { }
};
class VertexShader : public ShaderType<GL_VERTEX_SHADER>
{
public:
VertexShader(std::string fileName)
: ShaderType(fileName) { }
};
class FragmentShader : public ShaderType<GL_FRAGMENT_SHADER>
{
public:
FragmentShader(std::string fileName)
: ShaderType(fileName) { }
};
class GeometryShader : public ShaderType<GL_GEOMETRY_SHADER>
{
public:
GeometryShader(std::string fileName)
: ShaderType(fileName) { }
};
class ComputeShader : public ShaderType<GL_COMPUTE_SHADER>
{
public:
ComputeShader(std::string fileName)
: ShaderType(fileName) { }
};
class ShaderProgram
{
public:
ShaderProgram()
: m_ShaderProgramHandle(0) { }
~ShaderProgram();
void AddShader(std::shared_ptr<Shader> shader);
void Compile();
GLuint Link();
GLuint GetHandle();
void Bind();
void Unbind();
private:
GLuint m_ShaderProgramHandle;
std::vector<std::shared_ptr<Shader>> m_Shaders;
};