additions in scene, shader, material, modules, towards the new module format
This commit is contained in:
parent
e95212468f
commit
09afb90dd4
@ -27,9 +27,10 @@ set(LIB_SRC_LIST
|
||||
parametricmesh.cpp
|
||||
texture.cpp
|
||||
scene.cpp
|
||||
entityloader.cpp
|
||||
deferredmodule.cpp
|
||||
forwardmodule.cpp
|
||||
shadersource.cpp
|
||||
light.cpp
|
||||
)
|
||||
|
||||
set(LIBRARY_NAME ${PROJECT_NAME})
|
||||
|
@ -13,13 +13,9 @@ class PhongEntity;
|
||||
class DeferredModule : public Module
|
||||
{
|
||||
public:
|
||||
DeferredModule(Lights::Light* myDirLight, Lights* myPointLights);
|
||||
DeferredModule();
|
||||
|
||||
//void addEntity(PhongEntity* myEntity);
|
||||
//void clearEntities();
|
||||
|
||||
virtual void renderGL(Camera* myCamera) = 0;
|
||||
virtual bool requiresModernOpenGL() {return true;}
|
||||
virtual void renderGL(Camera* myCamera, Scene* scene);
|
||||
private:
|
||||
/*Lights::Light* dirLight;
|
||||
Lights* pointLights;
|
||||
|
38
forwardmodule.cpp
Normal file
38
forwardmodule.cpp
Normal file
@ -0,0 +1,38 @@
|
||||
#include "forwardmodule.h"
|
||||
#include "scene.h"
|
||||
#include "phongentity.h"
|
||||
#include "mesh.h"
|
||||
#include "material.h"
|
||||
|
||||
const char* const ForwardModule::flagStr[ForwardModule::NB_FLAGS] =
|
||||
{
|
||||
"NORMAL_MAP",
|
||||
"DIFFUSE_TEXTURE",
|
||||
"SPECULAR_TEXTURE",
|
||||
"ALPHA_MASK"
|
||||
};
|
||||
|
||||
void ForwardModule::renderGL(Camera* myCamera, Scene* scene)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// modern opengl methods
|
||||
|
||||
void ForwardModule::setShaderSource(ShaderSource* source)
|
||||
{
|
||||
shaderSources = source;
|
||||
}
|
||||
|
||||
void ForwardModule::compileShaders(Scene* scene)
|
||||
{
|
||||
for(SceneIterator<PhongEntity*>* EntityIt = scene->getGeometry();
|
||||
EntityIt->isValid(); EntityIt->next())
|
||||
{
|
||||
Mesh* m = EntityIt->getItem()->getMesh();
|
||||
for(Mesh::Group &g : m->indiceGroups)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
41
forwardmodule.h
Normal file
41
forwardmodule.h
Normal file
@ -0,0 +1,41 @@
|
||||
#ifndef FORWARDMODULE_H
|
||||
#define FORWARDMODULE_H
|
||||
|
||||
#include "module.h"
|
||||
#include <vector>
|
||||
#include <cstddef>
|
||||
#include <glew/glew.h>
|
||||
#include "shadersource.h"
|
||||
|
||||
class Scene;
|
||||
class PhongEntity;
|
||||
|
||||
class ForwardModule : public Module
|
||||
{
|
||||
public:
|
||||
ForwardModule() : shaderSources(NULL) {}
|
||||
|
||||
virtual void renderGL(Camera* myCamera, Scene* scene);
|
||||
virtual bool requiresModernOpenGL() {return false;}
|
||||
|
||||
// modern opengl methods
|
||||
|
||||
void setShaderSource(ShaderSource* source);
|
||||
void compileShaders(Scene* scene);
|
||||
|
||||
private:
|
||||
enum {
|
||||
NORMAL_MAP,
|
||||
DIFFUSE_TEXTURE,
|
||||
SPECULAR_TEXTURE,
|
||||
ALPHA_MASK,
|
||||
NB_FLAGS
|
||||
};
|
||||
|
||||
static const char* const flagStr[NB_FLAGS];
|
||||
|
||||
ShaderSource* shaderSources;
|
||||
Shader* shaders[1 << NB_FLAGS];
|
||||
};
|
||||
|
||||
#endif // FORWARDMODULE_H
|
25
light.cpp
Normal file
25
light.cpp
Normal file
@ -0,0 +1,25 @@
|
||||
#include "light.h"
|
||||
|
||||
Light::Light()
|
||||
{
|
||||
initPointLight();
|
||||
}
|
||||
|
||||
void Light::initDirectionnalLight(glm::vec3 dir, glm::vec3 lightColor, bool isShadowCaster)
|
||||
{
|
||||
initSpotLight(glm::vec3(0), dir, -1, lightColor, isShadowCaster);
|
||||
}
|
||||
|
||||
void Light::initPointLight(glm::vec3 pos, glm::vec3 lightColor, bool isShadowCaster)
|
||||
{
|
||||
initSpotLight(pos, glm::vec3(0), 360, lightColor, isShadowCaster);
|
||||
}
|
||||
|
||||
void Light::initSpotLight(glm::vec3 pos, glm::vec3 dir, float spotAngle, glm::vec3 lightColor, bool isShadowCaster)
|
||||
{
|
||||
position = pos;
|
||||
direction = dir;
|
||||
angle = spotAngle;
|
||||
color = lightColor;
|
||||
shadowCaster = isShadowCaster;
|
||||
}
|
25
light.h
Normal file
25
light.h
Normal file
@ -0,0 +1,25 @@
|
||||
#ifndef LIGHT_H
|
||||
#define LIGHT_H
|
||||
|
||||
#include <glm/vec3.hpp>
|
||||
|
||||
class Light
|
||||
{
|
||||
private:
|
||||
// standard attributes
|
||||
glm::vec3 position;
|
||||
glm::vec3 direction;
|
||||
float angle;
|
||||
glm::vec3 color;
|
||||
|
||||
// shadowmap attributes
|
||||
bool shadowCaster;
|
||||
// Shadowmap fbo
|
||||
public:
|
||||
Light();
|
||||
void initDirectionnalLight(glm::vec3 dir = glm::vec3(1, 0, 0), glm::vec3 lightColor = glm::vec3(1), bool isShadowCaster = false);
|
||||
void initPointLight(glm::vec3 pos = glm::vec3(0), glm::vec3 lightColor = glm::vec3(1), bool isShadowCaster = false);
|
||||
void initSpotLight(glm::vec3 pos = glm::vec3(0), glm::vec3 dir = glm::vec3(1, 0, 0), float spotAngle = 360, glm::vec3 lightColor = glm::vec3(1), bool isShadowCaster = false);
|
||||
};
|
||||
|
||||
#endif // LIGHT_H
|
8
lights.h
8
lights.h
@ -1,5 +1,5 @@
|
||||
#ifndef LIGHT_H
|
||||
#define LIGHT_H
|
||||
#ifndef LIGHTS_H
|
||||
#define LIGHTS_H
|
||||
|
||||
#include <glew/glew.h>
|
||||
#include <glm/vec3.hpp>
|
||||
@ -19,10 +19,12 @@ public:
|
||||
{
|
||||
glm::vec3 position;
|
||||
glm::vec3 color;
|
||||
bool shadowCaster;
|
||||
// Shadowmap fbo
|
||||
} Light;
|
||||
|
||||
private:
|
||||
std::vector<Light> lights;
|
||||
};
|
||||
|
||||
#endif // LIGHT_H
|
||||
#endif // LIGHTS_H
|
||||
|
@ -4,6 +4,14 @@
|
||||
#include "shader.h"
|
||||
#include "glm/fwd.hpp"
|
||||
|
||||
enum {
|
||||
// Geometry Flags
|
||||
NORMAL_MAP = 1 << 0,
|
||||
DIFFUSE_TEXTURE = 1 << 1,
|
||||
SPECULAR_TEXTURE = 1 << 2,
|
||||
ALPHA_MASK = 1 << 3,
|
||||
};
|
||||
|
||||
class Material
|
||||
{
|
||||
public:
|
||||
@ -11,6 +19,7 @@ public:
|
||||
Shader* getShader() {return shader;}
|
||||
|
||||
virtual void bindAttributes() = 0;
|
||||
virtual unsigned int getFlags() = 0;
|
||||
|
||||
protected:
|
||||
Shader* shader;
|
||||
|
3
module.h
3
module.h
@ -2,11 +2,12 @@
|
||||
#define MODULE
|
||||
|
||||
class Camera;
|
||||
class Scene;
|
||||
|
||||
class Module
|
||||
{
|
||||
public:
|
||||
virtual void renderGL(Camera* myCamera) = 0;
|
||||
virtual void renderGL(Camera* myCamera, Scene* scene) = 0;
|
||||
virtual bool requiresModernOpenGL() {return true;}
|
||||
};
|
||||
|
||||
|
@ -12,7 +12,7 @@ Modules :
|
||||
- forward (compatible crappy)
|
||||
IN :
|
||||
for sources
|
||||
for geometry
|
||||
for geometrie phong
|
||||
OUT :
|
||||
image éclairée
|
||||
|
||||
@ -25,13 +25,13 @@ image éclairée
|
||||
|
||||
- gbuffer
|
||||
IN :
|
||||
for géométrie
|
||||
for geometrie phong
|
||||
OUT :
|
||||
gbuffer
|
||||
|
||||
- shadowmap
|
||||
IN :
|
||||
for géométrie
|
||||
for géométrie phong
|
||||
source
|
||||
OUT :
|
||||
shadowmap
|
||||
|
@ -44,12 +44,35 @@ void PhongMaterial::bindAttributes()
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int PhongMaterial::getFlags()
|
||||
{
|
||||
unsigned int flags = 0;
|
||||
if(normal_map != NULL)
|
||||
flags |= NORMAL_MAP;
|
||||
if(diffuse_texture != NULL)
|
||||
flags |= DIFFUSE_TEXTURE;
|
||||
if(specular_texture != NULL)
|
||||
flags |= SPECULAR_TEXTURE;
|
||||
return flags;
|
||||
}
|
||||
|
||||
void PhongMaterial::setTexture(Texture* myTexture)
|
||||
{
|
||||
setDiffuseTexture(myTexture);
|
||||
}
|
||||
|
||||
void PhongMaterial::setDiffuseTexture(Texture* myTexture)
|
||||
{
|
||||
diffuse_texture = myTexture;
|
||||
updateShader();
|
||||
}
|
||||
|
||||
void PhongMaterial::setSpecularTexture(Texture* myTexture)
|
||||
{
|
||||
specular_texture = myTexture;
|
||||
updateShader();
|
||||
}
|
||||
|
||||
void PhongMaterial::setNormalMap(Texture* myNormalMap)
|
||||
{
|
||||
normal_map = myNormalMap;
|
||||
|
@ -14,6 +14,7 @@ public:
|
||||
glm::vec3 specular;
|
||||
float shininess;
|
||||
Texture* diffuse_texture;
|
||||
Texture* specular_texture;
|
||||
Texture* normal_map;
|
||||
|
||||
PhongMaterial() :
|
||||
@ -21,7 +22,8 @@ public:
|
||||
diffuse(0.5f),
|
||||
specular(0.5f),
|
||||
shininess(10),
|
||||
diffuse_texture(NULL),
|
||||
diffuse_texture(NULL),
|
||||
specular_texture(NULL),
|
||||
normal_map(NULL)
|
||||
{
|
||||
updateShader();
|
||||
@ -32,14 +34,20 @@ public:
|
||||
specular(myKs),
|
||||
shininess(myNs),
|
||||
diffuse_texture(NULL),
|
||||
specular_texture(NULL),
|
||||
normal_map(NULL)
|
||||
{
|
||||
updateShader();
|
||||
}
|
||||
virtual void bindAttributes();
|
||||
virtual unsigned int getFlags();
|
||||
void crappyBindAttributes();
|
||||
|
||||
// deprecated, you should use setDiffuseTexture instead
|
||||
void setTexture(Texture* myTexture);
|
||||
|
||||
void setDiffuseTexture(Texture* myTexture);
|
||||
void setSpecularTexture(Texture* myTexture);
|
||||
void setNormalMap(Texture* myNormalMap);
|
||||
|
||||
void updateShader();
|
||||
|
@ -34,7 +34,7 @@ void PhongModule::clearEntities()
|
||||
entities.clear();
|
||||
}
|
||||
|
||||
void PhongModule::renderGL(Camera* myCamera)
|
||||
void PhongModule::renderGL(Camera* myCamera, Scene* scene)
|
||||
{
|
||||
if(!SparrowRenderer::isModernOpenGLAvailable())
|
||||
{
|
||||
|
@ -25,7 +25,7 @@ public:
|
||||
void addEntity(PhongEntity* myEntity);
|
||||
void clearEntities();
|
||||
|
||||
virtual void renderGL(Camera* myCamera);
|
||||
virtual void renderGL(Camera* myCamera, Scene* scene = NULL);
|
||||
virtual bool requiresModernOpenGL() {return false;}
|
||||
|
||||
// modern opengl methods
|
||||
|
83
scene.h
83
scene.h
@ -3,74 +3,55 @@
|
||||
|
||||
#include <glm/mat4x4.hpp>
|
||||
#include "camera.h"
|
||||
|
||||
// Scene Node flags :
|
||||
|
||||
#define CAMERA_NODE 1
|
||||
#define DIRECTIONNAL_LIGHT_NODE 2
|
||||
#define POINT_LIGHT_NODE 4
|
||||
#define PHONG_NODE 8
|
||||
#define PHONG_DIFFUSE_TEXTURED_NODE 16
|
||||
#define PHONG_SPECULAR_TEXTURED_NODE 32
|
||||
#define PHONG_NORMAL_TEXTURED_NODE 64
|
||||
#define PARTICLES_NODE 128
|
||||
// up to 24 more nodes can be added here...
|
||||
#include <vector>
|
||||
#include "light.h"
|
||||
#include "phongentity.h"
|
||||
|
||||
// Scene interface :
|
||||
|
||||
template <class T>
|
||||
class SceneIterator
|
||||
{
|
||||
public:
|
||||
virtual SceneIterator& operator++() = 0;
|
||||
virtual T& operator*() = 0;
|
||||
virtual bool isValid() = 0;
|
||||
void next() {if(isValid()) operator++();}
|
||||
T& getItem() {return operator*();}
|
||||
};
|
||||
|
||||
class Scene
|
||||
{
|
||||
// the scene is supposed to contain Scene Nodes
|
||||
public:
|
||||
// this should draw all nodes matching the specified flags.
|
||||
virtual draw(unsigned int flags) = 0;
|
||||
virtual SceneIterator<Light*>* getLights() = 0;
|
||||
virtual SceneIterator<PhongEntity*>* getGeometry() = 0;
|
||||
};
|
||||
|
||||
// Some basic implementations :
|
||||
|
||||
class Mesh;
|
||||
|
||||
class LeafNode : public SceneNode
|
||||
template <class T>
|
||||
class ArraySceneIterator : public SceneIterator<T>
|
||||
{
|
||||
glm::mat4 transform;
|
||||
std::vector<LeafNode*> children;
|
||||
std::vector<T> &vec;
|
||||
int id;
|
||||
public:
|
||||
virtual void drawChildren(glm::mat4 m, unsigned int flags)
|
||||
{
|
||||
for(LeafNode* node : children)
|
||||
node->drawChildren(m*transform, flags);
|
||||
}
|
||||
ArraySceneIterator(std::vector<T> &myVec, int myId=0) : vec(myVec), id(myId) {}
|
||||
virtual SceneIterator<T>& operator++() {++id; return *this;}
|
||||
virtual T& operator*() {return vec[id];}
|
||||
virtual bool isValid() {return id < vec.size();}
|
||||
};
|
||||
|
||||
class MeshNode : public LeafNode
|
||||
class ArrayScene : public Scene
|
||||
{
|
||||
Mesh* mesh;
|
||||
std::vector<Light*> lights;
|
||||
std::vector<PhongEntity*> entities;
|
||||
public:
|
||||
virtual void drawChildren(glm::mat4 m, unsigned int flags)
|
||||
{
|
||||
// TODO : draw VAOs matching the flags
|
||||
for(LeafNode* node : children)
|
||||
node->drawChildren(m*transform, flags);
|
||||
}
|
||||
};
|
||||
void clearScene() {lights.clear(); entities.clear();}
|
||||
void addEntity(PhongEntity* myEntity) {entities.push_back(myEntity);}
|
||||
void addLight(Light* myLight) {lights.push_back(myLight);}
|
||||
|
||||
class TreeScene
|
||||
{
|
||||
LeafNode* root;
|
||||
public:
|
||||
virtual draw(unsigned int flags)
|
||||
{
|
||||
root->drawChildren(glm::mat4(), flags);
|
||||
}
|
||||
};
|
||||
|
||||
class CameraNode : public LeafNode
|
||||
{
|
||||
public:
|
||||
virtual glm::mat4 getProjectionMatrix() = 0;
|
||||
virtual glm::mat4 getViewMatrix() = 0;
|
||||
|
||||
virtual void resize(int width, int height) = 0;
|
||||
virtual SceneIterator<Light*>* getLights() {return new ArraySceneIterator<Light*>(lights);}
|
||||
virtual SceneIterator<PhongEntity*>* getGeometry() {return new ArraySceneIterator<PhongEntity*>(entities);}
|
||||
};
|
||||
|
||||
#endif // SCENE_H
|
||||
|
@ -18,11 +18,14 @@ ShaderSource::~ShaderSource()
|
||||
delete(sources[i]);
|
||||
}
|
||||
|
||||
void ShaderSource::addSource(const char *source, SourceType type)
|
||||
void ShaderSource::setSource(const char *source, SourceType type)
|
||||
{
|
||||
if(sources[type] != NULL)
|
||||
delete(sources[type]);
|
||||
sources[type] = new std::string(source);
|
||||
if(source == NULL)
|
||||
sources[type] = NULL;
|
||||
else
|
||||
sources[type] = new std::string(source);
|
||||
}
|
||||
|
||||
Shader* ShaderSource::compile(int nbDefines, const char** defines)
|
||||
|
@ -19,7 +19,7 @@ public:
|
||||
ShaderSource();
|
||||
~ShaderSource();
|
||||
|
||||
void addSource(const char *source, SourceType type);
|
||||
void setSource(const char *source, SourceType type);
|
||||
|
||||
Shader* compile(int nbDefines = 0, const char** defines = NULL);
|
||||
|
||||
|
@ -50,7 +50,7 @@ SkyboxModule::~SkyboxModule()
|
||||
}
|
||||
}
|
||||
|
||||
void SkyboxModule::renderGL(Camera* myCamera)
|
||||
void SkyboxModule::renderGL(Camera* myCamera, Scene* scene)
|
||||
{
|
||||
glm::mat4 viewMatrix = glm::mat4(glm::mat3(myCamera->getViewMatrix()));
|
||||
glm::mat4 projectionMatrix = myCamera->getProjectionMatrix();
|
||||
|
@ -28,7 +28,7 @@ class SkyboxModule : public Module
|
||||
public:
|
||||
SkyboxModule(Texture* myCubeMap);
|
||||
~SkyboxModule();
|
||||
virtual void renderGL(Camera* myCamera);
|
||||
virtual void renderGL(Camera* myCamera, Scene* scene = NULL);
|
||||
virtual bool requiresModernOpenGL() {return false;}
|
||||
};
|
||||
|
||||
|
@ -62,7 +62,7 @@ void SparrowRenderer::renderGL()
|
||||
for(ModuleNode &m : modules)
|
||||
{
|
||||
if(m.isEnabled)
|
||||
m.module->renderGL(getCamera());
|
||||
m.module->renderGL(getCamera(), scene);
|
||||
}
|
||||
}
|
||||
|
||||
@ -96,4 +96,16 @@ Camera* SparrowRenderer::getCamera()
|
||||
return camera;
|
||||
}
|
||||
|
||||
// scene methods
|
||||
|
||||
void SparrowRenderer::setScene(Scene* myScene)
|
||||
{
|
||||
scene = myScene;
|
||||
}
|
||||
|
||||
Scene* SparrowRenderer::getScene()
|
||||
{
|
||||
return scene;
|
||||
}
|
||||
|
||||
|
||||
|
@ -6,6 +6,7 @@
|
||||
|
||||
class Camera;
|
||||
class Module;
|
||||
class Scene;
|
||||
|
||||
class SparrowRenderer
|
||||
{
|
||||
@ -25,6 +26,10 @@ public:
|
||||
void setCamera(Camera* myCamera);
|
||||
Camera* getCamera();
|
||||
|
||||
// scene methods
|
||||
void setScene(Scene* myScene);
|
||||
Scene* getScene();
|
||||
|
||||
protected:
|
||||
typedef struct s_moduleNode{
|
||||
Module* module;
|
||||
@ -35,6 +40,7 @@ protected:
|
||||
} ModuleNode;
|
||||
|
||||
Camera* camera;
|
||||
Scene* scene;
|
||||
std::list<ModuleNode> modules;
|
||||
static bool modernOpenglAvailable;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user