Commit 0119931f authored by Sadman Kazi's avatar Sadman Kazi 🎸

Added basic shader singleton class

Also added stubs for mesh loading
parent 7b67a641
Pipeline #150 passed with stage
in 4 minutes and 18 seconds
#include "basic_shader.h"
const std::string BasicShader::BASIC_SHADER_FILE = "../res/basicShader";
BasicShader* BasicShader::getInstance() {
static BasicShader instance;
return &instance;
}
BasicShader::BasicShader() :
Shader(BASIC_SHADER_FILE) {
addUniform("u_transform");
}
void BasicShader::updateUniforms(const glm::mat4& proj_matrix) {
setUniformMat4("u_transform", proj_matrix);
}
#ifndef BASIC_SHADER_H_
#define BASIC_SHADER_H_
#include "shader.h"
class BasicShader : public Shader {
public:
static BasicShader* getInstance();
virtual void updateUniforms(const glm::mat4& proj_matrix);
private:
BasicShader();
static const std::string BASIC_SHADER_FILE;
};
#endif // BASIC_SHADER_H_
......@@ -110,3 +110,8 @@ void CoreEngine::run() {
void CoreEngine::stop() {
m_isRunning = false;
}
void CoreEngine::loadMesh(const std::string& model_path) {
m_game->loadMesh(model_path);
}
......@@ -28,6 +28,7 @@ public:
void start();
void stop();
void loadMesh(const std::string& model_path);
~CoreEngine();
......
......@@ -17,6 +17,7 @@
#include "input.h"
#include <iostream>
#include "time.h"
#include "basic_shader.h"
Game::Game()
{
......@@ -30,7 +31,7 @@ Game::Game()
2, 1, 0,
0, 2, 3};
m_shader = new Shader("../res/basicShader");
m_shader = BasicShader::getInstance();
//m_mesh = new Mesh(data, sizeof(data)/sizeof(data[0]), indices, sizeof(indices)/sizeof(indices[0]));
......@@ -41,8 +42,6 @@ Game::Game()
m_camera = new Camera(glm::vec3(0.0f, 0.0f, -2.0f), 70.0f, (float)WIDTH/HEIGHT, 1.0f, 100.0f);
m_transform->setScale(glm::vec3(0.5f, 0.5f, 0.5f));
m_shader->addUniform("u_transform");
//m_shader->addUniform("u_ambientLight");
//m_shader->setUniformVec3("u_ambientLight", glm::vec3(1,1,1));
m_counter = 0;
......@@ -52,7 +51,6 @@ Game::Game()
Game::~Game()
{
delete m_mesh;
delete m_shader;
delete m_transform;
delete m_camera;
}
......@@ -91,9 +89,9 @@ void Game::update() {
//m_transform->getRot().y = sinCounter;
//transform->GetRot().z = sinCounter;
m_shader->setUniformMat4("u_transform", m_transform->getProjectedModel(m_camera));
m_shader->updateUniforms(m_transform->getProjectedModel(m_camera));
}
void Game::loadMesh(const std::string& model_path) {
}
......@@ -20,7 +20,13 @@
int main(int argc, char* argv[]) {
CoreEngine game (TITLE, WIDTH, HEIGHT);
if (argc == 1) {
std::cerr << "Usage: ./GameEngine path_to_model_files file_name1 file_name2 ...)" << std::endl;
for (int i = 1; i < argc; i++) {
game.loadMesh (std::string(argv[0], argv[i]));
}
}
//main loop
game.start();
......
......@@ -6,7 +6,7 @@ static void checkError(GLuint shader, GLuint flag, bool isProgram, const std::st
static std::string load(const std::string& fileName);
static GLuint create(const std::string& text, GLenum shaderType);
Shader::Shader(const std::string fileName)
Shader::Shader(const std::string& fileName)
{
m_program = glCreateProgram();
m_shaders[0] = create(load(fileName + ".vs"), GL_VERTEX_SHADER);
......
......@@ -10,7 +10,7 @@
class Shader
{
public:
Shader(const std::string fileName);
Shader(const std::string& fileName);
void bind();
void printActiveUniforms();
......@@ -20,7 +20,8 @@ public:
void setUniformF(const std::string& name, float value);
void setUniformVec3(const std::string& name, const glm::vec3& value);
void setUniformMat4(const std::string& name, const glm::mat4& value);
~Shader();
virtual void updateUniforms(const glm::mat4&) = 0;
virtual ~Shader();
private:
static const unsigned int NUM_SHADERS = 2; //since we will only be using vertex and fragment shaders(for now)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment