From 068e2741085d2fcb45f22ff4650a788aeda32f10 Mon Sep 17 00:00:00 2001 From: LockedLunatic Date: Sun, 3 May 2015 01:31:31 +0200 Subject: [PATCH] material moved to texture --- Weave/Graphix/Model/IMesh.cpp | 6 ------ Weave/Graphix/Model/IMesh.h | 1 - Weave/Graphix/Model/IMetaMesh.cpp | 4 ++-- Weave/Graphix/Model/IMetaMesh.h | 2 +- Weave/Graphix/Model/Model.cpp | 19 ++++++------------- Weave/Graphix/Model/Model.h | 3 +-- Weave/Graphix/Model/SkyBox.cpp | 8 ++------ Weave/Graphix/Model/SkyBox.h | 3 +-- Weave/Graphix/Texture.cpp | 4 ++-- Weave/Graphix/Texture.h | 5 ++++- Weave/Scene/SceneObject.cpp | 12 +++--------- Weave/Scene/SceneObject.h | 2 -- 12 files changed, 22 insertions(+), 47 deletions(-) diff --git a/Weave/Graphix/Model/IMesh.cpp b/Weave/Graphix/Model/IMesh.cpp index d06493d..8ef5ca1 100644 --- a/Weave/Graphix/Model/IMesh.cpp +++ b/Weave/Graphix/Model/IMesh.cpp @@ -70,12 +70,6 @@ void IMesh::useModelMat(const mat4& _model, Shader* _shader) const glUniformMatrix4fv(tmp, 1, GL_FALSE, value_ptr(_model*glm::scale(modelScale)* modelMat)); } -//void IMesh::useMaterial(const vec4& _material, Shader* _shader) const -//{ -// // Model::useMaterial(_material, _shader); -// Model::useMaterial(_material, _shader); -//} - //void IMesh::drawModel(Shader* _shader, Texture* _texture, const mat4& _modelMat) const //{ // diff --git a/Weave/Graphix/Model/IMesh.h b/Weave/Graphix/Model/IMesh.h index 43ee0ac..16626ca 100644 --- a/Weave/Graphix/Model/IMesh.h +++ b/Weave/Graphix/Model/IMesh.h @@ -20,7 +20,6 @@ public: virtual ~IMesh(); void useModelMat(const mat4& model, Shader* shader) const; -// void useMaterial(const vec4& material, Shader* shader) const; //void drawModel(Shader* shader, Texture* texture, const mat4& modelMat) const; diff --git a/Weave/Graphix/Model/IMetaMesh.cpp b/Weave/Graphix/Model/IMetaMesh.cpp index 8515171..13da142 100644 --- a/Weave/Graphix/Model/IMetaMesh.cpp +++ b/Weave/Graphix/Model/IMetaMesh.cpp @@ -76,11 +76,11 @@ void IMetaMesh::bindShader(Shader* _shader) } } -void IMetaMesh::drawModel(Shader* _shader, Texture* _texture, const mat4& _modelMat, const vec4& _material) const +void IMetaMesh::drawModel(Shader* _shader, Texture* _texture, const mat4& _modelMat) const { for (auto i = models.begin(); i != models.end(); ++i) { - (*i)->drawModel(_shader, _texture, _modelMat, _material); + (*i)->drawModel(_shader, _texture, _modelMat); } } diff --git a/Weave/Graphix/Model/IMetaMesh.h b/Weave/Graphix/Model/IMetaMesh.h index 0632152..988877c 100644 --- a/Weave/Graphix/Model/IMetaMesh.h +++ b/Weave/Graphix/Model/IMetaMesh.h @@ -20,7 +20,7 @@ public: void bindShader(Shader* shader); - void drawModel(Shader* shader, Texture* texture, const mat4& modelMat, const vec4& material) const; + void drawModel(Shader* shader, Texture* texture, const mat4& modelMat) const; void drawBBox(Shader* shader, const mat4& modelMat) const; diff --git a/Weave/Graphix/Model/Model.cpp b/Weave/Graphix/Model/Model.cpp index d13f0dd..5973b83 100644 --- a/Weave/Graphix/Model/Model.cpp +++ b/Weave/Graphix/Model/Model.cpp @@ -82,7 +82,7 @@ void Model::drawModel() const glBindVertexArray(0); } -void Model::drawModel(Shader* _shader, Texture* _texture, const mat4& _modelMat, const vec4& _material) const +void Model::drawModel(Shader* _shader, Texture* _texture, const mat4& _modelMat) const { //Message::info("Error from before?"); //Graphix::getGlError(); @@ -95,9 +95,6 @@ void Model::drawModel(Shader* _shader, Texture* _texture, const mat4& _modelMat, useModelMat(_modelMat, _shader); //Message::info("IMesh loading MMatrix"); //Graphix::getGlError(); - useMaterial(_material, _shader); - //Message::info("IMesh loading MMatrix"); - //Graphix::getGlError(); drawModel(); //Message::info("IMesh drawing Elements"); //Graphix::getGlError(); @@ -119,7 +116,7 @@ void Model::drawBBox(Shader* _shader, const mat4& _modelMat) const // BoundingBox->bindShader(_shader); vec3 BBsiz, BBpos; getBBsp(BBsiz, BBpos); - BoundingBox->drawModel(Graphix::shader_BBox, (Texture*)nullptr, _modelMat*translate(BBpos)*glm::scale(BBsiz), vec4(1.0f, 1.0f, 1.0f, 3.0f)); + BoundingBox->drawModel(Graphix::shader_BBox, (Texture*)nullptr, _modelMat*translate(BBpos)*glm::scale(BBsiz)); } void Model::updateBB(const vec3& _min, const vec3& _max) @@ -235,6 +232,10 @@ void Model::useTexture(Texture* _texture, Shader* _shader) const int unit = 0; _texture->bind(unit); glUniform1i(tmp, unit); + + int tmp2 = _shader->getUniformLocation("material"); + if (tmp2 >= 0) + glUniform4fv(tmp2, 1, value_ptr(_texture->material)); } } @@ -245,14 +246,6 @@ void Model::useModelMat(const mat4& _model, Shader* _shader) const glUniformMatrix4fv(tmp, 1, GL_FALSE, value_ptr(_model*glm::scale(modelScale))); } -void Model::useMaterial(const vec4& _material, Shader* _shader) const -{ - int tmp = _shader->getUniformLocation("material"); - if (tmp >= 0) - glUniform4fv(tmp, 1, value_ptr(_material)); -} - - void Model::isColliding(float& _overlap, float& _inside, const Model* _model, const mat4& _modelMatThis, const mat4& _modelMatOther) const { vec3 posA, sizeA, posB, sizeB; diff --git a/Weave/Graphix/Model/Model.h b/Weave/Graphix/Model/Model.h index 034d22c..fec1a11 100644 --- a/Weave/Graphix/Model/Model.h +++ b/Weave/Graphix/Model/Model.h @@ -18,7 +18,7 @@ public: virtual void bindShader(Shader* shader); /* Draws Model */ - virtual void drawModel(Shader* shader, Texture* texture, const mat4& modelMat, const vec4& material) const; + virtual void drawModel(Shader* shader, Texture* texture, const mat4& modelMat) const; /* Draws a BoundingBox around the Model */ virtual void drawBBox(Shader* shader, const mat4& modelMat) const; @@ -50,7 +50,6 @@ protected: virtual void useModel(Shader* shader) const; virtual void useTexture(Texture* texture, Shader* shader) const; virtual void useModelMat(const mat4& model, Shader* shader) const; - virtual void useMaterial(const vec4& material, Shader* shader) const; virtual void drawModel() const; static Model* BoundingBox; diff --git a/Weave/Graphix/Model/SkyBox.cpp b/Weave/Graphix/Model/SkyBox.cpp index ff7cfd5..9c37e0c 100644 --- a/Weave/Graphix/Model/SkyBox.cpp +++ b/Weave/Graphix/Model/SkyBox.cpp @@ -25,10 +25,10 @@ SkyBox::~SkyBox() { } -void SkyBox::drawModel(Shader* _shader, Texture* _texture, const mat4& _modelMat, const vec4& _material) const +void SkyBox::drawModel(Shader* _shader, Texture* _texture, const mat4& _modelMat) const { glDisable(GL_DEPTH_TEST); - Model::drawModel(_shader, _texture, _modelMat, _material); + Model::drawModel(_shader, _texture, _modelMat); glEnable(GL_DEPTH_TEST); } @@ -36,10 +36,6 @@ void SkyBox::useModelMat(const mat4& _model, Shader* _shader) const { } -void SkyBox::useMaterial(const vec4& _material, Shader* _shader) const -{ -} - void SkyBox::useTexture(Texture* _texture, Shader* _shader) const { } diff --git a/Weave/Graphix/Model/SkyBox.h b/Weave/Graphix/Model/SkyBox.h index 14da4b9..5bf1552 100644 --- a/Weave/Graphix/Model/SkyBox.h +++ b/Weave/Graphix/Model/SkyBox.h @@ -9,11 +9,10 @@ public: SkyBox(); ~SkyBox(); - void drawModel(Shader* shader, Texture* texture, const mat4& modelMat, const vec4& material) const; + void drawModel(Shader* shader, Texture* texture, const mat4& modelMat) const; //uncommend following lines to use default Loaders void useModelMat(const mat4& model, Shader* shader) const; - void useMaterial(const vec4& material, Shader* shader) const; void useTexture(Texture* texture, Shader* shader) const; void drawBBox(Shader* shader, const mat4& modelMat) const; diff --git a/Weave/Graphix/Texture.cpp b/Weave/Graphix/Texture.cpp index 788de1f..6c19a45 100644 --- a/Weave/Graphix/Texture.cpp +++ b/Weave/Graphix/Texture.cpp @@ -2,15 +2,15 @@ #include #include "FreeImage.h" #include +#include "GLM.h" #include "../Message.h" #include "Graphix.h" using std::string; -Texture::Texture(const string& _path) : path(_path), handle(-1), TEXTURE_TYPE(-1) +Texture::Texture(const string& _path, const vec4& _material) : path(_path), handle(-1), TEXTURE_TYPE(-1), material(_material) { - //Message::info("Error from before?"); //Graphix::getGlError(); //Message::info("Do some Stuff"); diff --git a/Weave/Graphix/Texture.h b/Weave/Graphix/Texture.h index 36ec0a0..7137d6c 100644 --- a/Weave/Graphix/Texture.h +++ b/Weave/Graphix/Texture.h @@ -1,6 +1,7 @@ #pragma once #include +#include "GLM.h" #include @@ -14,13 +15,15 @@ typedef unordered_map str2int_map; class Texture { public: - Texture(const string& path); + Texture(const string& path, const vec4& material); ~Texture(); void bind(int unit); operator string() const; + vec4 material; + private: unsigned int handle; string path; diff --git a/Weave/Scene/SceneObject.cpp b/Weave/Scene/SceneObject.cpp index 81cebec..3cfd3f8 100644 --- a/Weave/Scene/SceneObject.cpp +++ b/Weave/Scene/SceneObject.cpp @@ -23,7 +23,6 @@ using std::string; SceneObject::SceneObject(Shader* _shader, const mat4& _modelMat, const vec4& _material, string _modelpath, string texturepath, const vec3& _scale) : model(nullptr), modelMat(_modelMat), -material(_material), shader(_shader), mainScene(NULL), collision_ignore(false), @@ -45,7 +44,7 @@ ignore(false) } if (texturepath != "") - texture = new Texture(texturepath); + texture = new Texture(texturepath, _material); //Message::info("Creating SkyBox Shader"); //Graphix::getGlError(); @@ -59,7 +58,6 @@ ignore(false) SceneObject::SceneObject(Shader* _shader, const mat4& _modelMat, const vec4& _material, Model* _model, string texturepath) : model(_model), modelMat(_modelMat), -material(_material), shader(_shader), mainScene(NULL), collision_ignore(false), @@ -75,7 +73,7 @@ ignore(false) //Graphix::getGlError(); //modelID = _shader->getUniformLocation("modelMat"); if (texturepath != "") - texture = new Texture(texturepath); + texture = new Texture(texturepath, _material); //Message::info("Creating SkyBox Shader"); //Graphix::getGlError(); @@ -150,7 +148,7 @@ void SceneObject::draw() const // drawModel(); - model->drawModel(shader, texture, modelMat, material); + model->drawModel(shader, texture, modelMat); if (Events::isKToggleActive(SDLK_F6)) model->drawBBox(shader, modelMat); } @@ -187,10 +185,6 @@ void SceneObject::setModel(mat4& _modelMat){ modelMat = _modelMat; } -void SceneObject::setMaterial(vec4& _material){ - material = _material; -} - void SceneObject::turn(float angle, vec3& axis){ //vec3 pos = getPosition(); //modelMat = rotate(degree, axis)*modelMat; diff --git a/Weave/Scene/SceneObject.h b/Weave/Scene/SceneObject.h index 7ad1338..4fb127c 100644 --- a/Weave/Scene/SceneObject.h +++ b/Weave/Scene/SceneObject.h @@ -32,7 +32,6 @@ public: __declspec(deprecated) virtual void setModel(mat4&); - virtual void setMaterial(vec4&); __declspec(deprecated) virtual void turn(float angle, vec3& axis); virtual void turnTo(vec3& direction, float speed = 1); @@ -67,7 +66,6 @@ protected: mat4 modelMat; - vec4 material; Shader* shader; Texture* texture; Model* model; -- 2.47.3