finished refactoring, sparrowrenderer compiles

This commit is contained in:
Anselme 2016-04-26 23:07:25 +02:00
parent 209cec4c7c
commit 48e1c4afdc
8 changed files with 2559 additions and 2522 deletions

4974
src/glew.c

File diff suppressed because it is too large Load Diff

View File

@ -19700,6 +19700,11 @@ VERSION_MINOR 13
VERSION_MICRO 0 VERSION_MICRO 0
*/ */
#ifdef RENDER_DEBUG
#include <stdio.h>
#define GLEW_STR(x) #x
#endif /* RENDER_DEBUG */
/* API */ /* API */
#ifdef GLEW_MX #ifdef GLEW_MX
@ -19712,12 +19717,39 @@ GLEWAPI GLboolean GLEWAPIENTRY glewContextIsSupported (const GLEWContext *ctx, c
#define glewIsExtensionSupported(x) glewIsSupported(x) #define glewIsExtensionSupported(x) glewIsSupported(x)
#define GLEW_GET_VAR(x) (*(const GLboolean*)&(glewGetContext()->x)) #define GLEW_GET_VAR(x) (*(const GLboolean*)&(glewGetContext()->x))
#ifdef RENDER_DEBUG
#ifdef _WIN32
#define GLEW_GET_FUN(code) \
glewGetContext()->code; \
{\
GLuint err = glGetError(); \
if(err != GL_NO_ERROR){ \
fprintf(stderr, "OpenGL Error (%s : %d, %s) : %s (%d)\n", __FILE__, __LINE__, GLEW_STR(code), gluErrorString(err), err);\
} \
}
#else
#define GLEW_GET_FUN(code) \
code; \
{\
GLuint err = glGetError(); \
if(err != GL_NO_ERROR){ \
fprintf(stderr, "OpenGL Error (%s : %d, %s) : %s (%d)\n", __FILE__, __LINE__, GLEW_STR(code), gluErrorString(err), err);\
} \
}
#endif
#else /* RENDER_DEBUG */
#ifdef _WIN32 #ifdef _WIN32
# define GLEW_GET_FUN(x) glewGetContext()->x # define GLEW_GET_FUN(x) glewGetContext()->x
#else #else
# define GLEW_GET_FUN(x) x # define GLEW_GET_FUN(x) x
#endif #endif
#endif /* RENDER_DEBUG */
#else /* GLEW_MX */ #else /* GLEW_MX */
GLEWAPI GLenum GLEWAPIENTRY glewInit (void); GLEWAPI GLenum GLEWAPIENTRY glewInit (void);
@ -19726,21 +19758,19 @@ GLEWAPI GLboolean GLEWAPIENTRY glewIsSupported (const char *name);
#define GLEW_GET_VAR(x) (*(const GLboolean*)&x) #define GLEW_GET_VAR(x) (*(const GLboolean*)&x)
#include <stdio.h>
#ifdef RENDER_DEBUG #ifdef RENDER_DEBUG
#define STR(x) #x
#define GLEW_GET_FUN(code) \ #define GLEW_GET_FUN(code) \
code; \ code; \
{\ {\
GLuint err = glGetError(); \ GLuint err = glGetError(); \
if(err != GL_NO_ERROR){ \ if(err != GL_NO_ERROR){ \
fprintf(stderr, "OpenGL Error (%s : %d, %s) : %s (%d)\n", __FILE__, __LINE__, STR(code), gluErrorString(err), err);\ fprintf(stderr, "OpenGL Error (%s : %d, %s) : %s (%d)\n", __FILE__, __LINE__, GLEW_STR(code), gluErrorString(err), err);\
} \ } \
} }
#else #else /* RENDER_DEBUG */
#define GLEW_GET_FUN(code) code #define GLEW_GET_FUN(code) code
#endif #endif /* RENDER_DEBUG */
#endif /* GLEW_MX */ #endif /* GLEW_MX */

View File

@ -2,6 +2,7 @@
#define PARAMETRIC_MESH_H #define PARAMETRIC_MESH_H
#include "mesh.h" #include "mesh.h"
#include <cmath>
class MeshGenerator class MeshGenerator
{ {

View File

@ -3,32 +3,22 @@
#include <set> #include <set>
std::vector<unsigned int> Scene::getMeshTypes() void Scene::getMeshTypes(std::vector<unsigned int> &meshTypes)
{ {
std::set<unsigned int> typesSet; std::set<unsigned int> typesSet;
std::vector<unsigned int> types; for(SceneIterator<GeometryNode*>* geometryIt = getGeometry(); geometryIt->isValid(); geometryIt->next())
for(SceneIterator<GeometryNode*>* geometryIt = scene->getGeometry();
geometryIt->isValid(); geometryIt->next())
{
typesSet.emplace(geometryIt->getItem()->mesh->getFlags()); typesSet.emplace(geometryIt->getItem()->mesh->getFlags());
}
for(unsigned int type : typesSet) for(unsigned int type : typesSet)
types.push_back(type); meshTypes.push_back(type);
return types;
} }
std::vector<unsigned int> Scene::getLightTypes() void Scene::getLightTypes(std::vector<unsigned int> &lightTypes)
{ {
std::set<unsigned int> typesSet; std::set<unsigned int> typesSet;
std::vector<unsigned int> types; for(SceneIterator<Light*>* lightIt = getLights(); lightIt->isValid(); lightIt->next())
for(SceneIterator<Light*>* lightIt = scene->getLights(); typesSet.emplace(lightIt->getItem()->getFlags());
lightIt->isValid(); lightIt->next())
{
typesSet.emplace(getFlags(geometryIt->getItem()));
}
for(unsigned int type : typesSet) for(unsigned int type : typesSet)
types.push_back(type); lightTypes.push_back(type);
return types;
} }
BasicScene::~BasicScene() BasicScene::~BasicScene()
@ -38,7 +28,7 @@ BasicScene::~BasicScene()
void BasicScene::addMesh(GeometryNode* gn) void BasicScene::addMesh(GeometryNode* gn)
{ {
geometry->push_back(gn); geometry.push_back(gn);
} }
GeometryNode* BasicScene::addMesh(Mesh* m, glm::mat4 transform) GeometryNode* BasicScene::addMesh(Mesh* m, glm::mat4 transform)

View File

@ -43,8 +43,8 @@ public:
virtual SceneIterator<Light*>* getLights() = 0; virtual SceneIterator<Light*>* getLights() = 0;
virtual SceneIterator<GeometryNode*>* getGeometry() = 0; virtual SceneIterator<GeometryNode*>* getGeometry() = 0;
virtual void getMeshTypes(std::vector<unsigned int> &meshTypes); void getMeshTypes(std::vector<unsigned int> &meshTypes);
virtual void getLightTypes(std::vector<unsigned int> &lightTypes); void getLightTypes(std::vector<unsigned int> &lightTypes);
}; };
// A basic implementation : // A basic implementation :

View File

@ -31,20 +31,33 @@ void ShaderSource::setSource(const char *source, SourceType type)
Shader* ShaderSource::compile(unsigned int geomFlags, unsigned int lightFlags) Shader* ShaderSource::compile(unsigned int geomFlags, unsigned int lightFlags)
{ {
std::string header = "#version 330 core"; std::vector<const char*> defines;
for(int i=0; i<Mesh::NB_FLAGS; ++i) for(int i=0; i<Mesh::NB_FLAGS; ++i)
{ {
if((geomFlags >> i) & 0x00000001) if((geomFlags >> i) & 0x00000001)
header += "\n#define "+std::string(Mesh::flagStr[i]); defines.push_back(Mesh::flagStr[i]);
} }
for(int i=0; i<Light::NB_FLAGS; ++i) for(int i=0; i<Light::NB_FLAGS; ++i)
{ {
if((lightFlags >> i) & 0x00000001) if((lightFlags >> i) & 0x00000001)
header += "\n#define "+std::string(Light::flagStr[i]); defines.push_back(Light::flagStr[i]);
} }
return compile(defines);
}
Shader* ShaderSource::compile(const std::vector<const char*> &defines)
{
std::string header = "#version 330 core";
for(int i=0; i<Light::NB_FLAGS; ++i)
{
for(const char* def : defines)
header += "\n#define "+std::string(def);
}
header += "\n#line 1\n"; header += "\n#line 1\n";
if(sources[VERTEX] == NULL || sources[FRAGMENT] == NULL) if(sources[VERTEX] == NULL || sources[FRAGMENT] == NULL)
@ -60,4 +73,3 @@ Shader* ShaderSource::compile(unsigned int geomFlags, unsigned int lightFlags)
else else
return new Shader(compiledSources[VERTEX], compiledSources[FRAGMENT]); return new Shader(compiledSources[VERTEX], compiledSources[FRAGMENT]);
} }

View File

@ -2,6 +2,7 @@
#define SHADERSOURCE_H #define SHADERSOURCE_H
#include <string> #include <string>
#include <vector>
class Shader; class Shader;
@ -23,6 +24,8 @@ public:
Shader* compile(unsigned int geomFlags, unsigned int lightFlags); Shader* compile(unsigned int geomFlags, unsigned int lightFlags);
Shader* compile(const std::vector<const char*> &defines);
private: private:
std::string* sources[NB_TYPES]; std::string* sources[NB_TYPES];
}; };

View File

@ -46,10 +46,11 @@ TextureBlur::~TextureBlur()
void TextureBlur::setSource(ShaderSource* source) void TextureBlur::setSource(ShaderSource* source)
{ {
const char* horizontalDefine = "HORIZONTAL_BLUR"; std::vector<const char*> defines(1);
horizontal = source->compile(1, &horizontalDefine); defines[0] = "HORIZONTAL_BLUR";
const char* verticalDefine = "VERTICAL_BLUR"; horizontal = source->compile(defines);
vertical = source->compile(1, &verticalDefine); defines[0] = "VERTICAL_BLUR";
vertical = source->compile(defines);
uniformLocations[H_SAMPLER] = horizontal->getLocation("colorSampler"); uniformLocations[H_SAMPLER] = horizontal->getLocation("colorSampler");
uniformLocations[H_WIDTH] = horizontal->getLocation("width"); uniformLocations[H_WIDTH] = horizontal->getLocation("width");
uniformLocations[H_HEIGHT] = horizontal->getLocation("height"); uniformLocations[H_HEIGHT] = horizontal->getLocation("height");