//current_world->addObject(new SceneObject(shader1, glm::mat4(1.0f), "Player.dae", "model_player.png"));
//current_world->addObject(new SceneObject(shader1, translate(vec3(-3.f, .4f, 0.f))*scale(vec3(3.f)), "cow/cow.dae", "model_cow_2D.jpg"));
current_world->addObject(new SceneObject(shader1, translate(vec3(-3.f, .4f, 0.f))*scale(vec3(.32f)), vec4(3.0f, 0.5f, 0.4f, 1.5f), "duck.dae", "model_duck_2D.png"));
- current_world->addObject(new SceneObject(shader1, translate(vec3(-5.f, .4f, 0.f))*scale(vec3(.32f)), vec4(3.0f, 3.f, 0.4f, 1.5f), "duck.dae", "model_cow_2D.jpg"));
+ current_world->addObject(new SceneObject(shader1, translate(vec3(-5.f, .4f, 0.f))*scale(vec3(.32f)), vec4(3.0f, 3.f, 0.4f, 1.5f), "duck.dae", "model_duck_2D.png"));
current_world->addObject(new EventBox(translate(vec3(3.f, .4f, 0.f)),EB_LOSTZONE));
current_world->addObject(new EventBox(translate(vec3(3.f, .4f, -15.f)), EB_WINZONE));
getBBoxModel()->drawModel(Graphix::shader_BBox, NULL, _modelMat*translate(BBpos)*glm::scale(BBsiz*2.f));
}
+
void Model::updateBB(const vec3& _min, const vec3& _max)
{
BBmin = _min;
}
-
void Model::genBuffer(uint &buffer, uint size, void* value)
{
glGenBuffers(1, &buffer);
glBindBuffer(GL_ARRAY_BUFFER, 0);
}
+
void Model::useModel(Shader* _shader) const
{
_shader->useShader();
glUniformMatrix4fv(tmp, 1, GL_FALSE, value_ptr(_model));
}
+
Overlap Model::isColliding(const Model* _modelThis, const Model* _modelOther, const mat4& _modelMatThis, const mat4& _modelMatOther)
{
return _modelThis->checkColS2O(_modelMatThis, _modelOther, _modelMatOther);
_inside = -1;
}
+
vec3 Model::rotateSize(const vec3& _size, const mat4& _modelMat)
{
vec3 Size = vec3(0.f);
_vec[i] *= _scale[i];
}
+
Model* Model::getBBoxModel()
{
if (BoundingBox == nullptr)
SkyBoxModel = nullptr;
}
-
void Model::deleteIMetaModel(const string& _modelpath)
{
if (_modelpath == "SkyBox" || _modelpath == "BBox" || _modelpath == "IMesh")
}
+
float Model::getPDistHit(const vec3& _P, const vec3& _direction) const
{
class Model
{
public:
- Model();
- virtual ~Model();
/* Binds Model to the Model*/
virtual void bindShader(Shader* shader);
virtual operator std::string() const = 0;
protected:
+ Model();
+ virtual ~Model();
+
uint numvertices, numfaces;
uint vertexBuffer, indexBuffer, normalBuffer, uvBuffer;
#include "Graphix.h"
using std::string;
+using std::unordered_map;
+
+
Texture::Texture(const string& _path, const vec4& _material) : path(_path), handle(-1), TEXTURE_TYPE(-1), material(_material)
{
//Graphix::getGlError();
//Message::info("Do some Stuff");
- auto i = texture_map.find(_path);
- if (i != texture_map.end())
+
+ texHandle& t_ptr = texture_Map[_path];
+
+ if (t_ptr.handle >= 0)
{
- handle = i->second;
+ handle = t_ptr.handle;
return;
}
glTexParameteri(TEXTURE_TYPE, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
}
- texture_map[_path] = handle;
+ t_ptr.handle = handle;
//Graphix::getGlError();
//Message::info("Done");
Texture::~Texture()
{
- texture_map.erase(path);
glDeleteTextures(1, &handle);
}
+Texture* Texture::newTexture(const string& _path, const vec4& _material)
+{
+ texHandle& t_ptr = texture_Map[_path];
+
+ if (t_ptr.ptr == nullptr)
+ {
+ t_ptr.ptr = new Texture(_path, _material);
+ }
+
+ ++t_ptr.count;
+
+ return t_ptr.ptr;
+}
+
+void Texture::deleteTexture(const string& _path)
+{
+ texHandle& t_ptr = texture_Map[_path];
+
+ if (t_ptr.ptr == nullptr)
+ {
+ Message::warning("deleteTexture: " + _path + " doesn't exist.");
+ return;
+ }
+
+ --t_ptr.count;
+
+ if (!t_ptr.count)
+ {
+ delete t_ptr.ptr;
+ texture_Map.erase(_path);
+ }
+}
+
void Texture::bind(int unit)
{
glActiveTexture(GL_TEXTURE0 + unit);
return path;
}
-void Texture::clean()
-{
- //RALLLY BAD HACK!!!! No Texture will be freed!!!!
- texture_map.clear();
-}
-
-str2int_map Texture::texture_map;
\ No newline at end of file
+unordered_map<string, Texture::texHandle> Texture::texture_Map;
\ No newline at end of file
#pragma once
-#include <string>
#include "GLM.h"
-
+#include <string>
#include <unordered_map>
-using std::unordered_map;
-
-using std::string;
-
-typedef unordered_map<string, unsigned int> str2int_map;
-
class Texture
{
public:
- Texture(const string& path, const vec4& material);
- ~Texture();
+ static Texture* newTexture(const std::string& path, const vec4& material);
+ static void deleteTexture(const std::string& path);
void bind(int unit);
- operator string() const;
+ operator std::string() const;
vec4 material;
- //RALLLY BAD HACK!!!! No Texture will be freed!!!!
- static void clean();
-
private:
+ Texture(const std::string& path, const vec4& material);
+ ~Texture();
+
unsigned int handle;
- string path;
+ std::string path;
unsigned int TEXTURE_TYPE;
- static str2int_map texture_map;
+ typedef struct texStruct
+ {
+ int handle=-1;
+ unsigned int count=0;
+ Texture* ptr=nullptr;
+ } texHandle;
+
+ static std::unordered_map<std::string, texHandle> texture_Map;
};
\ No newline at end of file
}
if (texturepath != "")
- texture = new Texture(texturepath, _material);
+ texture = Texture::newTexture(texturepath, _material);
//Message::info("Creating SkyBox Shader");
//Graphix::getGlError();
//Graphix::getGlError();
//modelID = _shader->getUniformLocation("modelMat");
if (texturepath != "")
- texture = new Texture(texturepath, _material);
+ texture = Texture::newTexture(texturepath, _material);
//Message::info("Creating SkyBox Shader");
//Graphix::getGlError();
SceneObject::~SceneObject()
{
- delete texture;
- if (newModel)
- Model::deleteIMetaModel(*model);
+ if (texture!=nullptr)
+ Texture::deleteTexture(*texture);
+ if (newModel)
+ Model::deleteIMetaModel(*model);
}
float SceneObject::getFloor() const