added resourcebase
This commit is contained in:
parent
26bfe5566b
commit
eaa70e2cde
@ -45,6 +45,40 @@
|
|||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
|
<widget class="QDockWidget" name="dockWidget_4">
|
||||||
|
<property name="floating">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<attribute name="dockWidgetArea">
|
||||||
|
<number>1</number>
|
||||||
|
</attribute>
|
||||||
|
<widget class="QWidget" name="dockWidgetContents_4">
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||||
|
<property name="spacing">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="leftMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="topMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="rightMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="bottomMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<item>
|
||||||
|
<widget class="QGroupBox" name="groupBox">
|
||||||
|
<property name="title">
|
||||||
|
<string>renderer</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</widget>
|
||||||
</widget>
|
</widget>
|
||||||
<layoutdefault spacing="6" margin="11"/>
|
<layoutdefault spacing="6" margin="11"/>
|
||||||
<customwidgets>
|
<customwidgets>
|
||||||
|
@ -28,18 +28,12 @@ MyGLWidget::~MyGLWidget()
|
|||||||
Scene* MyGLWidget::buildScene()
|
Scene* MyGLWidget::buildScene()
|
||||||
{
|
{
|
||||||
Scene* scene = new Scene();
|
Scene* scene = new Scene();
|
||||||
|
|
||||||
Camera* cam = new Camera(width(), height());
|
Camera* cam = new Camera(width(), height());
|
||||||
cam->moveTo(glm::vec3(0, 0, 3));
|
cam->moveTo(glm::vec3(0, 0, 3));
|
||||||
cam->lookAt(glm::vec2(0, 0));
|
cam->lookAt(glm::vec2(0, 0));
|
||||||
scene->setCamera(cam);
|
scene->setCamera(cam);
|
||||||
Mesh* myGrid = new Sphere(2);
|
|
||||||
myGrid->initGL();
|
|
||||||
std::string vertSource = Utils::fileToString("../phong.vert");
|
|
||||||
std::string fragSource = Utils::fileToString("../phong.frag");
|
|
||||||
Shader* shader = new Shader(vertSource, fragSource);
|
|
||||||
PhongMaterial* mat = new PhongMaterial(shader);
|
|
||||||
Texture* tex = new Texture("../data/noise.png");
|
|
||||||
mat->setTexture(tex);
|
|
||||||
std::string filenames[6] = {
|
std::string filenames[6] = {
|
||||||
"../data/skybox_ft", "../data/skybox_bk",
|
"../data/skybox_ft", "../data/skybox_bk",
|
||||||
"../data/skybox_up", "../data/skybox_dn",
|
"../data/skybox_up", "../data/skybox_dn",
|
||||||
@ -47,7 +41,19 @@ Scene* MyGLWidget::buildScene()
|
|||||||
};
|
};
|
||||||
SkyBox* skybox = new SkyBox(filenames);
|
SkyBox* skybox = new SkyBox(filenames);
|
||||||
scene->addEntity(skybox);
|
scene->addEntity(skybox);
|
||||||
|
|
||||||
|
Mesh* myGrid = new Sphere(2);
|
||||||
|
myGrid->initGL();
|
||||||
|
|
||||||
|
std::string vertSource = Utils::fileToString("../phong.vert");
|
||||||
|
std::string fragSource = Utils::fileToString("../phong.frag");
|
||||||
|
Shader* shader = new Shader(vertSource, fragSource);
|
||||||
|
PhongMaterial* mat = new PhongMaterial(shader);
|
||||||
|
Texture* tex = new Texture("../data/noise.png");
|
||||||
|
mat->setTexture(tex);
|
||||||
|
|
||||||
scene->addEntity(myGrid, mat);
|
scene->addEntity(myGrid, mat);
|
||||||
|
|
||||||
return scene;
|
return scene;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
73
resourcebase.cpp
Normal file
73
resourcebase.cpp
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
#include "resourcebase.h"
|
||||||
|
|
||||||
|
ResourceBase::~ResourceBase()
|
||||||
|
{
|
||||||
|
for(std::string str : textureNames)
|
||||||
|
delete(textures[str]);
|
||||||
|
for(std::string str : meshNames)
|
||||||
|
delete(meshes[str]);
|
||||||
|
for(std::string str : materialNames)
|
||||||
|
delete(materials[str]);
|
||||||
|
for(std::string str : shaderNames)
|
||||||
|
delete(shaders[str]);
|
||||||
|
for(std::string str : entityNames)
|
||||||
|
delete(entities[str]);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ResourceBase::addTexture(std::string textureName, Texture* myTexture)
|
||||||
|
{
|
||||||
|
textureNames.push_back(textureName);
|
||||||
|
textures[textureName] = myTexture;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ResourceBase::addMesh(std::string meshName, Mesh* myMesh)
|
||||||
|
{
|
||||||
|
meshNames.push_back(meshName);
|
||||||
|
meshes[meshName] = myMesh;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ResourceBase::addMaterial(std::string materialName, Material* myMaterial)
|
||||||
|
{
|
||||||
|
materialNames.push_back(materialName);
|
||||||
|
materials[materialName] = myMaterial;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ResourceBase::addShader(std::string shaderName, Shader* myShader)
|
||||||
|
{
|
||||||
|
shaderNames.push_back(shaderName);
|
||||||
|
shaders[shaderName] = myShader;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ResourceBase::addEntity(std::string entityName, Entity* myEntity)
|
||||||
|
{
|
||||||
|
entityNames.push_back(entityName);
|
||||||
|
entities[entityName] = myEntity;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Texture* ResourceBase::getTexture(std::string textureName)
|
||||||
|
{
|
||||||
|
return textures[textureName];
|
||||||
|
}
|
||||||
|
|
||||||
|
Mesh* ResourceBase::getMesh(std::string meshName)
|
||||||
|
{
|
||||||
|
return meshes[meshName];
|
||||||
|
}
|
||||||
|
|
||||||
|
Material* ResourceBase::getMaterial(std::string materialName)
|
||||||
|
{
|
||||||
|
return materials[materialName];
|
||||||
|
}
|
||||||
|
|
||||||
|
Shader* ResourceBase::getShader(std::string shaderName)
|
||||||
|
{
|
||||||
|
return shaders[shaderName];
|
||||||
|
}
|
||||||
|
|
||||||
|
Entity* ResourceBase::getEntity(std::string entityName)
|
||||||
|
{
|
||||||
|
return entities[entityName];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
45
resourcebase.h
Normal file
45
resourcebase.h
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
#ifndef RESOURCEBASE_H
|
||||||
|
#define RESOURCEBASE_H
|
||||||
|
|
||||||
|
class Texture;
|
||||||
|
class Mesh;
|
||||||
|
class Material;
|
||||||
|
class Shader;
|
||||||
|
class Entity;
|
||||||
|
|
||||||
|
#include <unordered_map>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
class ResourceBase
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
std::vector<std::string> textureNames;
|
||||||
|
std::vector<std::string> meshNames;
|
||||||
|
std::vector<std::string> materialNames;
|
||||||
|
std::vector<std::string> shaderNames;
|
||||||
|
std::vector<std::string> entityNames;
|
||||||
|
|
||||||
|
std::unordered_map<std::string, Texture*> textures;
|
||||||
|
std::unordered_map<std::string, Mesh*> meshes;
|
||||||
|
std::unordered_map<std::string, Material*> materials;
|
||||||
|
std::unordered_map<std::string, Shader*> shaders;
|
||||||
|
std::unordered_map<std::string, Entity*> entities;
|
||||||
|
public:
|
||||||
|
ResourceBase();
|
||||||
|
~ResourceBase();
|
||||||
|
|
||||||
|
void addTexture(std::string textureName, Texture* myTexture);
|
||||||
|
void addMesh(std::string meshName, Mesh* myMesh);
|
||||||
|
void addMaterial(std::string materialName, Material* myMaterial);
|
||||||
|
void addShader(std::string shaderName, Shader* myShader);
|
||||||
|
void addEntity(std::string entityName, Entity* myEntity);
|
||||||
|
|
||||||
|
Texture* getTexture(std::string textureName);
|
||||||
|
Mesh* getMesh(std::string meshName);
|
||||||
|
Material* getMaterial(std::string materialName);
|
||||||
|
Shader* getShader(std::string shaderName);
|
||||||
|
Entity* getEntity(std::string entityName);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // RESOURCEBASE_H
|
@ -36,7 +36,8 @@ SOURCES += main.cpp\
|
|||||||
entity.cpp \
|
entity.cpp \
|
||||||
utils.cpp \
|
utils.cpp \
|
||||||
lights.cpp \
|
lights.cpp \
|
||||||
sparrowrenderer.cpp
|
sparrowrenderer.cpp \
|
||||||
|
resourcebase.cpp
|
||||||
|
|
||||||
HEADERS += mainwindow.h \
|
HEADERS += mainwindow.h \
|
||||||
myglwidget.h \
|
myglwidget.h \
|
||||||
@ -56,7 +57,8 @@ HEADERS += mainwindow.h \
|
|||||||
entity.h \
|
entity.h \
|
||||||
utils.h \
|
utils.h \
|
||||||
lights.h \
|
lights.h \
|
||||||
sparrowrenderer.h
|
sparrowrenderer.h \
|
||||||
|
resourcebase.h
|
||||||
|
|
||||||
FORMS += mainwindow.ui
|
FORMS += mainwindow.ui
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user