Skip to content

Commit

Permalink
master: make Shader class use mem pool
Browse files Browse the repository at this point in the history
  • Loading branch information
paulgheorghecristian committed Sep 30, 2017
1 parent fa6be97 commit 8658721
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
3 changes: 2 additions & 1 deletion Core/ComponentFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ Component *ComponentFactory::createComponent(const rapidjson::Value::ConstMember
}

mesh = Mesh::loadObject (itr->value["Mesh"].GetString());
shader = new Shader (itr->value["Shader"].GetString());
shader = new Shader ();
shader->construct (itr->value["Shader"].GetString());
if (itr->value.HasMember("Texture")) {
texture = new Texture(itr->value["Texture"].GetString(), 0);
}
Expand Down
2 changes: 1 addition & 1 deletion Core/EngineCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ void EngineCore::input() {
glm::vec3 (0),
glm::vec3 (20));
entities.push_back ((new Entity(transform))->addComponent (new RenderComponent(Mesh::loadObject("res/models/cube4.obj"),
new Shader("res/shaders/example.json"),
(new Shader())->construct("res/shaders/example.json"),
NULL,
Material (glm::vec3(1, 0, 0),
glm::vec3(0),
Expand Down
6 changes: 5 additions & 1 deletion Rendering/Shader.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#include "Shader.h"

Shader::Shader(std::string &&jsonPath) {
Shader::Shader() {
}

Shader *Shader::construct (std::string &&jsonPath) {
GLint compileResult = 0, linkResult = 0;
char infoLogMessage[1024];
std::string jsonBody;
Expand Down Expand Up @@ -123,6 +125,8 @@ Shader::Shader(std::string &&jsonPath) {
for (auto it : uniforms) {
//std::cout << it.first << " " << it.second << std::endl;
}

return this;
}

void Shader::unbind() {
Expand Down
7 changes: 5 additions & 2 deletions Rendering/Shader.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@
#include "rapidjson/document.h"
#include "rapidjson/error/en.h"

#include "MemoryPoolInterface.h"

class ShaderUniform;

class Shader
class Shader : public MemoryPoolInterface<Shader>
{
public:
Shader(std::string &&jsonPath);
Shader();
Shader *construct (std::string &&jsonPath);
void reloadShader();
void bind();
void unbind();
Expand Down

0 comments on commit 8658721

Please sign in to comment.