bug fixes and minor features added
This commit is contained in:
parent
fb8ff13751
commit
080f3f6c53
@ -55,6 +55,8 @@ void ForwardModule::lightPass(Camera* myCamera, Scene* scene, Light* light)
|
|||||||
for(j=0; j<lightFlagList.size(); ++j)
|
for(j=0; j<lightFlagList.size(); ++j)
|
||||||
if(lightFlagList[j] == Light::getFlags(light))
|
if(lightFlagList[j] == Light::getFlags(light))
|
||||||
break;
|
break;
|
||||||
|
if(j == lightFlagList.size())
|
||||||
|
continue; // WARNING : missing shader for the light
|
||||||
Shader* shader = shaders[i*lightFlagList.size() + j];
|
Shader* shader = shaders[i*lightFlagList.size() + j];
|
||||||
shader->bind();
|
shader->bind();
|
||||||
|
|
||||||
|
@ -82,6 +82,7 @@ void Light::initShadowMap(int resWidth, int resHeight, glm::vec3 dim)
|
|||||||
// Depth buffer
|
// Depth buffer
|
||||||
Texture* tex = new Texture(GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT, resWidth, resHeight, GL_FLOAT);
|
Texture* tex = new Texture(GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT, resWidth, resHeight, GL_FLOAT);
|
||||||
tex->setFiltering(GL_LINEAR);
|
tex->setFiltering(GL_LINEAR);
|
||||||
|
tex->setWrap(GL_CLAMP_TO_EDGE);
|
||||||
shadowMap->addTexture(tex, GL_DEPTH_ATTACHMENT);
|
shadowMap->addTexture(tex, GL_DEPTH_ATTACHMENT);
|
||||||
shadowMap->initColorAttachments();
|
shadowMap->initColorAttachments();
|
||||||
|
|
||||||
@ -107,25 +108,27 @@ void Light::generateShadowMap(Scene* scene)
|
|||||||
for(SceneIterator<GeometryNode*>* geometryIt = scene->getGeometry();
|
for(SceneIterator<GeometryNode*>* geometryIt = scene->getGeometry();
|
||||||
geometryIt->isValid(); geometryIt->next())
|
geometryIt->isValid(); geometryIt->next())
|
||||||
{
|
{
|
||||||
// compute matrix attributes
|
|
||||||
GeometryNode* node = geometryIt->getItem();
|
GeometryNode* node = geometryIt->getItem();
|
||||||
glm::mat4 lightMVP = getProjectionMatrix() * (getViewMatrix() * node->modelMatrix);
|
|
||||||
// loop over material groups
|
|
||||||
Material* mat = node->mesh->material;
|
Material* mat = node->mesh->material;
|
||||||
if(mat->getFlags() & ALPHA_MASK_FLAG)
|
if(((PhongMaterial*)mat)->castShadow)
|
||||||
{
|
{
|
||||||
PhongMaterial* pmat = (PhongMaterial*)mat;
|
// compute matrix attributes
|
||||||
shaders[1]->bind();
|
glm::mat4 lightMVP = getProjectionMatrix() * (getViewMatrix() * node->modelMatrix);
|
||||||
pmat->alpha_mask->bind(ALPHA_MASK);
|
if(mat->getFlags() & ALPHA_MASK_FLAG)
|
||||||
shaders[1]->bindMat4(shaders[1]->getLocation("MVP"), lightMVP);
|
{
|
||||||
shaders[1]->bindInteger(shaders[1]->getLocation("alphaMask"), ALPHA_MASK);
|
PhongMaterial* pmat = (PhongMaterial*)mat;
|
||||||
node->mesh->draw(shaders[1], false, true, false);
|
shaders[1]->bind();
|
||||||
}
|
pmat->alpha_mask->bind(ALPHA_MASK);
|
||||||
else
|
shaders[1]->bindMat4(shaders[1]->getLocation("MVP"), lightMVP);
|
||||||
{
|
shaders[1]->bindInteger(shaders[1]->getLocation("alphaMask"), ALPHA_MASK);
|
||||||
shaders[0]->bind();
|
node->mesh->draw(shaders[1], false, true, false);
|
||||||
shaders[0]->bindMat4(shaders[1]->getLocation("MVP"), lightMVP);
|
}
|
||||||
node->mesh->draw(shaders[0], false, false, false);
|
else
|
||||||
|
{
|
||||||
|
shaders[0]->bind();
|
||||||
|
shaders[0]->bindMat4(shaders[1]->getLocation("MVP"), lightMVP);
|
||||||
|
node->mesh->draw(shaders[0], false, false, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
glAssert(glCullFace(GL_BACK));
|
glAssert(glCullFace(GL_BACK));
|
||||||
@ -136,6 +139,12 @@ Texture* Light::getShadowMap()
|
|||||||
return shadowMap->getTexture(0);
|
return shadowMap->getTexture(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Light::setPosition(glm::vec3 new_pos)
|
||||||
|
{
|
||||||
|
position = new_pos;
|
||||||
|
viewMatrix = glm::lookAt(position, position+direction, glm::vec3(0, 1, 0));
|
||||||
|
}
|
||||||
|
|
||||||
unsigned int Light::getFlags(Light* l)
|
unsigned int Light::getFlags(Light* l)
|
||||||
{
|
{
|
||||||
if(l == NULL)
|
if(l == NULL)
|
||||||
|
@ -32,7 +32,7 @@ public:
|
|||||||
static const glm::mat4 biasMatrix;
|
static const glm::mat4 biasMatrix;
|
||||||
|
|
||||||
Light();
|
Light();
|
||||||
void initDirectionnalLight(glm::vec3 dir = glm::vec3(1, 0, 0), glm::vec3 lightColor = glm::vec3(1));
|
void initDirectionnalLight(glm::vec3 dir = glm::vec3(0, -1, 0), glm::vec3 lightColor = glm::vec3(1));
|
||||||
void initPointLight(glm::vec3 pos = glm::vec3(0), glm::vec3 lightColor = glm::vec3(1), float att = 1);
|
void initPointLight(glm::vec3 pos = glm::vec3(0), glm::vec3 lightColor = glm::vec3(1), float att = 1);
|
||||||
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));
|
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));
|
||||||
|
|
||||||
@ -49,6 +49,8 @@ public:
|
|||||||
Texture* getShadowMap();
|
Texture* getShadowMap();
|
||||||
|
|
||||||
void setAttenuation(float a) {attenuation = a;}
|
void setAttenuation(float a) {attenuation = a;}
|
||||||
|
void setPosition(glm::vec3 new_pos);
|
||||||
|
void setColor(glm::vec3 new_color) {color = new_color;}
|
||||||
|
|
||||||
// camera inheritance
|
// camera inheritance
|
||||||
virtual glm::mat4 getProjectionMatrix() {return projectionMatrix;}
|
virtual glm::mat4 getProjectionMatrix() {return projectionMatrix;}
|
||||||
|
23
src/mesh.cpp
23
src/mesh.cpp
@ -10,8 +10,7 @@
|
|||||||
Mesh::Mesh() :
|
Mesh::Mesh() :
|
||||||
material(NULL),
|
material(NULL),
|
||||||
vao(0),
|
vao(0),
|
||||||
nb_buffers(0),
|
nb_buffers(0)
|
||||||
vbo(NULL)
|
|
||||||
{}
|
{}
|
||||||
|
|
||||||
Mesh::~Mesh()
|
Mesh::~Mesh()
|
||||||
@ -21,7 +20,7 @@ Mesh::~Mesh()
|
|||||||
|
|
||||||
void Mesh::initGL(bool isDynamic)
|
void Mesh::initGL(bool isDynamic)
|
||||||
{
|
{
|
||||||
if(vbo != NULL)
|
if(vao != 0)
|
||||||
destroyGL();
|
destroyGL();
|
||||||
|
|
||||||
GLenum buffer_type = isDynamic ? GL_DYNAMIC_DRAW : GL_STATIC_DRAW;
|
GLenum buffer_type = isDynamic ? GL_DYNAMIC_DRAW : GL_STATIC_DRAW;
|
||||||
@ -30,17 +29,8 @@ void Mesh::initGL(bool isDynamic)
|
|||||||
glAssert(glGenVertexArrays(1, &vao));
|
glAssert(glGenVertexArrays(1, &vao));
|
||||||
glAssert(glBindVertexArray(vao));
|
glAssert(glBindVertexArray(vao));
|
||||||
|
|
||||||
nb_buffers = 2; // positions and indices buffers
|
|
||||||
if(hasNormals())
|
|
||||||
++nb_buffers;
|
|
||||||
if(hasTexCoords())
|
|
||||||
++nb_buffers;
|
|
||||||
if(hasTangents())
|
|
||||||
++nb_buffers;
|
|
||||||
|
|
||||||
// create VBOs
|
// create VBOs
|
||||||
vbo = new GLuint[nb_buffers]();
|
glAssert(glGenBuffers(NB_BUFFERS, vbo));
|
||||||
glAssert(glGenBuffers(nb_buffers, vbo));
|
|
||||||
|
|
||||||
// init indices vbos
|
// init indices vbos
|
||||||
glAssert(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo[INDICES_BUFFER]));
|
glAssert(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo[INDICES_BUFFER]));
|
||||||
@ -57,7 +47,7 @@ void Mesh::initGL(bool isDynamic)
|
|||||||
glAssert(glBufferData(GL_ARRAY_BUFFER, normals.size() * sizeof(glm::vec3), normals.data(), buffer_type));
|
glAssert(glBufferData(GL_ARRAY_BUFFER, normals.size() * sizeof(glm::vec3), normals.data(), buffer_type));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(hasNormals())
|
if(hasTexCoords())
|
||||||
{
|
{
|
||||||
// init texCoords vbo
|
// init texCoords vbo
|
||||||
glAssert(glBindBuffer(GL_ARRAY_BUFFER, vbo[TEXCOORD_BUFFER]));
|
glAssert(glBindBuffer(GL_ARRAY_BUFFER, vbo[TEXCOORD_BUFFER]));
|
||||||
@ -145,11 +135,8 @@ void Mesh::destroyGL()
|
|||||||
if(vbo != NULL)
|
if(vbo != NULL)
|
||||||
{
|
{
|
||||||
glAssert(glDeleteVertexArrays(1, &vao));
|
glAssert(glDeleteVertexArrays(1, &vao));
|
||||||
glAssert(glDeleteBuffers(nb_buffers, vbo));
|
glAssert(glDeleteBuffers(NB_BUFFERS, vbo));
|
||||||
delete[] vbo;
|
|
||||||
vao = 0;
|
vao = 0;
|
||||||
nb_buffers = 0;
|
|
||||||
vbo = NULL;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,15 +38,17 @@ protected:
|
|||||||
enum {
|
enum {
|
||||||
// required buffers
|
// required buffers
|
||||||
POSITION_BUFFER,
|
POSITION_BUFFER,
|
||||||
|
// indices buffers
|
||||||
|
INDICES_BUFFER,
|
||||||
// optionnal buffers :
|
// optionnal buffers :
|
||||||
NORMAL_BUFFER, TEXCOORD_BUFFER, TANGENT_BUFFER,
|
NORMAL_BUFFER, TEXCOORD_BUFFER, TANGENT_BUFFER,
|
||||||
// indices buffers
|
|
||||||
INDICES_BUFFER
|
NB_BUFFERS
|
||||||
};
|
};
|
||||||
|
|
||||||
GLuint vao;
|
GLuint vao;
|
||||||
int nb_buffers;
|
int nb_buffers;
|
||||||
GLuint* vbo;
|
GLuint vbo[NB_BUFFERS];
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Mesh();
|
Mesh();
|
||||||
|
@ -13,6 +13,7 @@ public:
|
|||||||
glm::vec3 diffuse;
|
glm::vec3 diffuse;
|
||||||
glm::vec3 specular;
|
glm::vec3 specular;
|
||||||
float shininess;
|
float shininess;
|
||||||
|
bool castShadow;
|
||||||
Texture* ambient_texture;
|
Texture* ambient_texture;
|
||||||
Texture* diffuse_texture;
|
Texture* diffuse_texture;
|
||||||
Texture* specular_texture;
|
Texture* specular_texture;
|
||||||
@ -24,6 +25,7 @@ public:
|
|||||||
diffuse(0.5f),
|
diffuse(0.5f),
|
||||||
specular(0.5f),
|
specular(0.5f),
|
||||||
shininess(10),
|
shininess(10),
|
||||||
|
castShadow(true),
|
||||||
ambient_texture(NULL),
|
ambient_texture(NULL),
|
||||||
diffuse_texture(NULL),
|
diffuse_texture(NULL),
|
||||||
specular_texture(NULL),
|
specular_texture(NULL),
|
||||||
|
@ -19,7 +19,8 @@ PostEffectModule::PostEffectModule(int width, int height) :
|
|||||||
frameBuffers(NULL),
|
frameBuffers(NULL),
|
||||||
blur(NULL),
|
blur(NULL),
|
||||||
redux(NULL),
|
redux(NULL),
|
||||||
blurSource(NULL)
|
blurSource(NULL),
|
||||||
|
bloom_threshold(0.7f)
|
||||||
{
|
{
|
||||||
for(int i=0; i<NB_SHADERS; ++i)
|
for(int i=0; i<NB_SHADERS; ++i)
|
||||||
shaders[i] = NULL;
|
shaders[i] = NULL;
|
||||||
@ -59,6 +60,7 @@ void PostEffectModule::resize(int w, int h)
|
|||||||
delete[](frameBuffers);
|
delete[](frameBuffers);
|
||||||
}
|
}
|
||||||
frameBuffers = new FrameBuffer[NB_FBO];
|
frameBuffers = new FrameBuffer[NB_FBO];
|
||||||
|
// TODO : don't delete, forward module reference is lost
|
||||||
|
|
||||||
// creating input FBO
|
// creating input FBO
|
||||||
|
|
||||||
@ -144,7 +146,7 @@ void PostEffectModule::luminanceStep()
|
|||||||
shaders[LUMINANCE_SHADER]->bindInteger(shaders[LUMINANCE_SHADER]->getLocation("colorSampler"), 0);
|
shaders[LUMINANCE_SHADER]->bindInteger(shaders[LUMINANCE_SHADER]->getLocation("colorSampler"), 0);
|
||||||
frameBuffers[INPUT_FBO].getTexture(0)->bind(0);
|
frameBuffers[INPUT_FBO].getTexture(0)->bind(0);
|
||||||
|
|
||||||
shaders[LUMINANCE_SHADER]->bindFloat(shaders[LUMINANCE_SHADER]->getLocation("threshold"), BLOOM_LUMINANCE_THRESHOLD);
|
shaders[LUMINANCE_SHADER]->bindFloat(shaders[LUMINANCE_SHADER]->getLocation("threshold"), bloom_threshold);
|
||||||
|
|
||||||
glAssert(glDrawArrays(GL_TRIANGLES, 0, 3));
|
glAssert(glDrawArrays(GL_TRIANGLES, 0, 3));
|
||||||
}
|
}
|
||||||
|
@ -7,8 +7,6 @@
|
|||||||
#include "module.h"
|
#include "module.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#define BLOOM_LUMINANCE_THRESHOLD 0.5f
|
|
||||||
|
|
||||||
class Shader;
|
class Shader;
|
||||||
class FrameBuffer;
|
class FrameBuffer;
|
||||||
class Texture;
|
class Texture;
|
||||||
@ -59,6 +57,9 @@ class PostEffectModule : public Module
|
|||||||
ShaderSource* blurSource;
|
ShaderSource* blurSource;
|
||||||
TextureRedux* redux;
|
TextureRedux* redux;
|
||||||
|
|
||||||
|
// arguments
|
||||||
|
float bloom_threshold;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PostEffectModule(int width, int height);
|
PostEffectModule(int width, int height);
|
||||||
~PostEffectModule();
|
~PostEffectModule();
|
||||||
@ -78,6 +79,8 @@ public:
|
|||||||
FrameBuffer* getInputFBO() {return frameBuffers;}
|
FrameBuffer* getInputFBO() {return frameBuffers;}
|
||||||
|
|
||||||
void setRenderTarget(FrameBuffer* renderTarget) {outputFBO = renderTarget;}
|
void setRenderTarget(FrameBuffer* renderTarget) {outputFBO = renderTarget;}
|
||||||
|
|
||||||
|
void setBloomThreshold(float threshold) {bloom_threshold = threshold;}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // POSTEFFECTMODULE_H
|
#endif // POSTEFFECTMODULE_H
|
||||||
|
@ -15,10 +15,10 @@ class SceneIterator
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual SceneIterator& operator++() = 0;
|
virtual SceneIterator& operator++() = 0;
|
||||||
virtual T& operator*() = 0;
|
virtual T operator*() = 0;
|
||||||
virtual bool isValid() = 0;
|
virtual bool isValid() = 0;
|
||||||
void next() {if(isValid()) operator++();}
|
void next() {if(isValid()) operator++();}
|
||||||
T& getItem() {return operator*();}
|
T getItem() {return operator*();}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct GeometryNode
|
struct GeometryNode
|
||||||
@ -44,7 +44,7 @@ class ArraySceneIterator : public SceneIterator<T>
|
|||||||
public:
|
public:
|
||||||
ArraySceneIterator(std::vector<T> &myVec, int myId=0) : vec(myVec), id(myId) {}
|
ArraySceneIterator(std::vector<T> &myVec, int myId=0) : vec(myVec), id(myId) {}
|
||||||
virtual SceneIterator<T>& operator++() {++id; return *this;}
|
virtual SceneIterator<T>& operator++() {++id; return *this;}
|
||||||
virtual T& operator*() {return vec[id];}
|
virtual T operator*() {return vec[id];}
|
||||||
virtual bool isValid() {return id < vec.size();}
|
virtual bool isValid() {return id < vec.size();}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -5,39 +5,32 @@
|
|||||||
#include "shader.h"
|
#include "shader.h"
|
||||||
#include "texture.h"
|
#include "texture.h"
|
||||||
#include "camera.h"
|
#include "camera.h"
|
||||||
|
#include "framebuffer.h"
|
||||||
#include "glassert.h"
|
#include "glassert.h"
|
||||||
#include "sparrowrenderer.h"
|
#include "sparrowrenderer.h"
|
||||||
|
|
||||||
|
#define BUFFER_OFFSET(i) ((char *)NULL + (i))
|
||||||
|
|
||||||
SkyboxModule::SkyboxModule(Texture* myCubeMap)
|
SkyboxModule::SkyboxModule(Texture* myCubeMap)
|
||||||
{
|
{
|
||||||
|
cubeMap = myCubeMap;
|
||||||
|
|
||||||
|
glAssert(glGenVertexArrays(1, &vao));
|
||||||
|
glAssert(glBindVertexArray(vao));
|
||||||
|
glAssert(glGenBuffers(2, vbos));
|
||||||
|
glAssert(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbos[0]));
|
||||||
|
glAssert(glBufferData(GL_ELEMENT_ARRAY_BUFFER, 36 * sizeof(GLubyte), skyboxIndices, GL_STATIC_DRAW));
|
||||||
|
glAssert(glBindBuffer(GL_ARRAY_BUFFER, vbos[1]));
|
||||||
|
glAssert(glBufferData(GL_ARRAY_BUFFER, 24 * sizeof(GLfloat), skyboxVertices, GL_STATIC_DRAW));
|
||||||
|
|
||||||
if(SparrowRenderer::isModernOpenGLAvailable())
|
if(SparrowRenderer::isModernOpenGLAvailable())
|
||||||
{
|
{
|
||||||
|
renderTarget = FrameBuffer::screen;
|
||||||
shader = new Shader(vertSource, fragSource);
|
shader = new Shader(vertSource, fragSource);
|
||||||
mvpLocation = shader->getLocation("MVP");
|
mvpLocation = shader->getLocation("MVP");
|
||||||
cubeMap = myCubeMap;
|
}
|
||||||
|
|
||||||
// set up vao
|
glAssert(glBindVertexArray(0));
|
||||||
glAssert(glGenVertexArrays(1, &vao));
|
|
||||||
glAssert(glBindVertexArray(vao));
|
|
||||||
glAssert(glGenBuffers(1, &vbo));
|
|
||||||
glAssert(glBindBuffer(GL_ARRAY_BUFFER, vbo));
|
|
||||||
glAssert(glBufferData(GL_ARRAY_BUFFER, 108 * sizeof(GLfloat), skyboxVertices, GL_STATIC_DRAW));
|
|
||||||
glAssert(glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(float)*3, NULL));
|
|
||||||
glAssert(glEnableVertexAttribArray(0));
|
|
||||||
glAssert(glBindVertexArray(0));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
displayList = glAssert(glGenLists(1));
|
|
||||||
glAssert(glNewList(displayList, GL_COMPILE));
|
|
||||||
glAssert(glDisable(GL_LIGHTING));
|
|
||||||
glAssert(glEnable(GL_TEXTURE_CUBE_MAP));
|
|
||||||
myCubeMap->bind(0);
|
|
||||||
drawCube();
|
|
||||||
glAssert(glDisable(GL_TEXTURE_CUBE_MAP));
|
|
||||||
glAssert(glEnable(GL_LIGHTING));
|
|
||||||
glAssert(glEndList());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SkyboxModule::~SkyboxModule()
|
SkyboxModule::~SkyboxModule()
|
||||||
@ -45,7 +38,7 @@ SkyboxModule::~SkyboxModule()
|
|||||||
if(SparrowRenderer::isModernOpenGLAvailable())
|
if(SparrowRenderer::isModernOpenGLAvailable())
|
||||||
{
|
{
|
||||||
glAssert(glDeleteVertexArrays(1, &vao));
|
glAssert(glDeleteVertexArrays(1, &vao));
|
||||||
glAssert(glDeleteBuffers(1, &vbo));
|
glAssert(glDeleteBuffers(2, vbos));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,6 +46,7 @@ void SkyboxModule::renderGL(Camera* myCamera, Scene* scene)
|
|||||||
{
|
{
|
||||||
glm::mat4 viewMatrix = glm::mat4(glm::mat3(myCamera->getViewMatrix()));
|
glm::mat4 viewMatrix = glm::mat4(glm::mat3(myCamera->getViewMatrix()));
|
||||||
glm::mat4 projectionMatrix = myCamera->getProjectionMatrix();
|
glm::mat4 projectionMatrix = myCamera->getProjectionMatrix();
|
||||||
|
glAssert(glDisable(GL_CULL_FACE));
|
||||||
glAssert(glDepthMask(GL_FALSE));
|
glAssert(glDepthMask(GL_FALSE));
|
||||||
if(!SparrowRenderer::isModernOpenGLAvailable())
|
if(!SparrowRenderer::isModernOpenGLAvailable())
|
||||||
{
|
{
|
||||||
@ -60,97 +54,78 @@ void SkyboxModule::renderGL(Camera* myCamera, Scene* scene)
|
|||||||
glAssert(glLoadMatrixf(glm::value_ptr(viewMatrix)));
|
glAssert(glLoadMatrixf(glm::value_ptr(viewMatrix)));
|
||||||
glAssert(glMatrixMode(GL_PROJECTION));
|
glAssert(glMatrixMode(GL_PROJECTION));
|
||||||
glAssert(glLoadMatrixf(glm::value_ptr(projectionMatrix)));
|
glAssert(glLoadMatrixf(glm::value_ptr(projectionMatrix)));
|
||||||
glAssert(glCallList(displayList));
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
renderTarget->bindFBO();
|
||||||
shader->bind();
|
shader->bind();
|
||||||
shader->bindMat4(mvpLocation, projectionMatrix * viewMatrix);
|
shader->bindMat4(mvpLocation, projectionMatrix * viewMatrix);
|
||||||
}
|
}
|
||||||
cubeMap->bind(0);
|
cubeMap->bind(0);
|
||||||
glAssert(glBindVertexArray(vao));
|
glAssert(glBindVertexArray(vao));
|
||||||
glAssert(glDrawArrays(GL_TRIANGLES, 0, 36));
|
|
||||||
|
glAssert(glBindBuffer(GL_ARRAY_BUFFER, vbos[1]));
|
||||||
|
if(SparrowRenderer::isModernOpenGLAvailable())
|
||||||
|
{
|
||||||
|
glAssert(glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3*sizeof(GLfloat), BUFFER_OFFSET(0)));
|
||||||
|
glAssert(glEnableVertexAttribArray(0));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
glAssert(glDisable(GL_LIGHTING));
|
||||||
|
glAssert(glEnable(GL_TEXTURE_CUBE_MAP));
|
||||||
|
|
||||||
|
glAssert(glEnableClientState(GL_VERTEX_ARRAY));
|
||||||
|
glAssert(glVertexPointer(3, GL_FLOAT, 0, BUFFER_OFFSET(0)));
|
||||||
|
glAssert(glEnableClientState(GL_TEXTURE_COORD_ARRAY));
|
||||||
|
glAssert(glTexCoordPointer(3, GL_FLOAT, 0, BUFFER_OFFSET(0)));
|
||||||
|
}
|
||||||
|
|
||||||
|
glAssert(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbos[0]));
|
||||||
|
glAssert(glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_BYTE, NULL));
|
||||||
|
glAssert(glBindVertexArray(0));
|
||||||
|
|
||||||
|
if(!SparrowRenderer::isModernOpenGLAvailable())
|
||||||
|
{
|
||||||
|
glAssert(glEnable(GL_LIGHTING));
|
||||||
|
glAssert(glDisable(GL_TEXTURE_CUBE_MAP));
|
||||||
|
glAssert(glDisableClientState(GL_VERTEX_ARRAY));
|
||||||
|
glAssert(glDisableClientState(GL_TEXTURE_COORD_ARRAY));
|
||||||
|
}
|
||||||
|
glAssert(glEnable(GL_CULL_FACE));
|
||||||
glAssert(glDepthMask(GL_TRUE));
|
glAssert(glDepthMask(GL_TRUE));
|
||||||
}
|
}
|
||||||
|
|
||||||
void SkyboxModule::drawCube()
|
void SkyboxModule::setRenderTarget(const FrameBuffer* target)
|
||||||
{
|
{
|
||||||
const float t = 1;
|
if(target != NULL)
|
||||||
glAssert(glBegin(GL_QUADS));
|
renderTarget = target;
|
||||||
glTexCoord3f(-t,-t,-t); glVertex3f(-t,-t,-t);
|
|
||||||
glTexCoord3f(-t,t,-t); glVertex3f(-t,t,-t);
|
|
||||||
glTexCoord3f(-t,t,t); glVertex3f(-t,t,t);
|
|
||||||
glTexCoord3f(-t,-t,t); glVertex3f(-t,-t,t);
|
|
||||||
|
|
||||||
glTexCoord3f(t, -t,-t); glVertex3f(t,-t,-t);
|
|
||||||
glTexCoord3f(t,-t,t); glVertex3f(t,-t,t);
|
|
||||||
glTexCoord3f(t,t,t); glVertex3f(t,t,t);
|
|
||||||
glTexCoord3f(t,t,-t); glVertex3f(t,t,-t);
|
|
||||||
|
|
||||||
glTexCoord3f(-t,-t,-t); glVertex3f(-t,-t,-t);
|
|
||||||
glTexCoord3f(-t,-t,t); glVertex3f(-t,-t,t);
|
|
||||||
glTexCoord3f(t,-t,t); glVertex3f(t,-t,t);
|
|
||||||
glTexCoord3f(t, -t,-t); glVertex3f(t,-t,-t);
|
|
||||||
|
|
||||||
glTexCoord3f(-t,t,-t); glVertex3f(-t,t,-t);
|
|
||||||
glTexCoord3f(t,t,-t); glVertex3f(t,t,-t);
|
|
||||||
glTexCoord3f(t,t,t); glVertex3f(t,t,t);
|
|
||||||
glTexCoord3f(-t,t,t); glVertex3f(-t,t,t);
|
|
||||||
|
|
||||||
glTexCoord3f(-t,-t,-t); glVertex3f(-t,-t,-t);
|
|
||||||
glTexCoord3f(t, -t,-t); glVertex3f(t,-t,-t);
|
|
||||||
glTexCoord3f(t,t,-t); glVertex3f(t,t,-t);
|
|
||||||
glTexCoord3f(-t,t,-t); glVertex3f(-t,t,-t);
|
|
||||||
|
|
||||||
glTexCoord3f(-t,-t,t); glVertex3f(-t,-t,t);
|
|
||||||
glTexCoord3f(-t,t,t); glVertex3f(-t,t,t);
|
|
||||||
glTexCoord3f(t,t,t); glVertex3f(t,t,t);
|
|
||||||
glTexCoord3f(t,-t,t); glVertex3f(t,-t,t);
|
|
||||||
glAssert(glEnd());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const GLfloat SkyboxModule::skyboxVertices[] = {
|
const GLfloat SkyboxModule::skyboxVertices[] = {
|
||||||
-1.0f, 1.0f, -1.0f,
|
|
||||||
-1.0f, -1.0f, -1.0f,
|
|
||||||
1.0f, -1.0f, -1.0f,
|
|
||||||
1.0f, -1.0f, -1.0f,
|
|
||||||
1.0f, 1.0f, -1.0f,
|
|
||||||
-1.0f, 1.0f, -1.0f,
|
|
||||||
|
|
||||||
-1.0f, -1.0f, 1.0f,
|
|
||||||
-1.0f, -1.0f, -1.0f,
|
|
||||||
-1.0f, 1.0f, -1.0f,
|
|
||||||
-1.0f, 1.0f, -1.0f,
|
|
||||||
-1.0f, 1.0f, 1.0f,
|
-1.0f, 1.0f, 1.0f,
|
||||||
|
-1.0f, 1.0f, -1.0f,
|
||||||
-1.0f, -1.0f, 1.0f,
|
-1.0f, -1.0f, 1.0f,
|
||||||
|
-1.0f, -1.0f, -1.0f,
|
||||||
1.0f, -1.0f, -1.0f,
|
1.0f, 1.0f, 1.0f,
|
||||||
|
1.0f, 1.0f, -1.0f,
|
||||||
1.0f, -1.0f, 1.0f,
|
1.0f, -1.0f, 1.0f,
|
||||||
1.0f, 1.0f, 1.0f,
|
1.0f, -1.0f, -1.0f
|
||||||
1.0f, 1.0f, 1.0f,
|
};
|
||||||
1.0f, 1.0f, -1.0f,
|
|
||||||
1.0f, -1.0f, -1.0f,
|
|
||||||
|
|
||||||
-1.0f, -1.0f, 1.0f,
|
const GLubyte SkyboxModule::skyboxIndices[] = {
|
||||||
-1.0f, 1.0f, 1.0f,
|
0, 6, 2,
|
||||||
1.0f, 1.0f, 1.0f,
|
0, 4, 6,
|
||||||
1.0f, 1.0f, 1.0f,
|
1, 3, 5,
|
||||||
1.0f, -1.0f, 1.0f,
|
3, 7, 5,
|
||||||
-1.0f, -1.0f, 1.0f,
|
0, 3, 1,
|
||||||
|
0, 2, 3,
|
||||||
-1.0f, 1.0f, -1.0f,
|
4, 5, 6,
|
||||||
1.0f, 1.0f, -1.0f,
|
5, 7, 6,
|
||||||
1.0f, 1.0f, 1.0f,
|
0, 5, 4,
|
||||||
1.0f, 1.0f, 1.0f,
|
0, 1, 5,
|
||||||
-1.0f, 1.0f, 1.0f,
|
2, 6, 3,
|
||||||
-1.0f, 1.0f, -1.0f,
|
6, 7, 3
|
||||||
|
|
||||||
-1.0f, -1.0f, -1.0f,
|
|
||||||
-1.0f, -1.0f, 1.0f,
|
|
||||||
1.0f, -1.0f, -1.0f,
|
|
||||||
1.0f, -1.0f, -1.0f,
|
|
||||||
-1.0f, -1.0f, 1.0f,
|
|
||||||
1.0f, -1.0f, 1.0f
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const std::string SkyboxModule::vertSource =
|
const std::string SkyboxModule::vertSource =
|
||||||
|
@ -7,29 +7,30 @@
|
|||||||
|
|
||||||
class Shader;
|
class Shader;
|
||||||
class Texture;
|
class Texture;
|
||||||
|
class FrameBuffer;
|
||||||
|
|
||||||
class SkyboxModule : public Module
|
class SkyboxModule : public Module
|
||||||
{
|
{
|
||||||
static const GLfloat skyboxVertices[];
|
static const GLfloat skyboxVertices[];
|
||||||
|
static const GLubyte skyboxIndices[];
|
||||||
static const std::string vertSource;
|
static const std::string vertSource;
|
||||||
static const std::string fragSource;
|
static const std::string fragSource;
|
||||||
|
|
||||||
// modern opengl variables
|
// modern opengl variables
|
||||||
GLuint vao;
|
GLuint vao;
|
||||||
GLuint vbo;
|
GLuint vbos[2];
|
||||||
GLuint mvpLocation;
|
GLuint mvpLocation;
|
||||||
Shader* shader;
|
Shader* shader;
|
||||||
Texture* cubeMap;
|
Texture* cubeMap;
|
||||||
//crappy opengl variables
|
|
||||||
GLuint displayList;
|
|
||||||
|
|
||||||
void drawCube();
|
const FrameBuffer* renderTarget;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SkyboxModule(Texture* myCubeMap);
|
SkyboxModule(Texture* myCubeMap);
|
||||||
~SkyboxModule();
|
~SkyboxModule();
|
||||||
virtual void renderGL(Camera* myCamera, Scene* scene = NULL);
|
virtual void renderGL(Camera* myCamera, Scene* scene = NULL);
|
||||||
virtual bool requiresModernOpenGL() {return false;}
|
virtual bool requiresModernOpenGL() {return false;}
|
||||||
|
void setRenderTarget(const FrameBuffer* target);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SKYBOXMODULE_H
|
#endif // SKYBOXMODULE_H
|
||||||
|
@ -60,7 +60,8 @@ void SparrowRenderer::resizeGL(int w, int h)
|
|||||||
width = w;
|
width = w;
|
||||||
height = h;
|
height = h;
|
||||||
glAssert(glViewport(0, 0, width, height));
|
glAssert(glViewport(0, 0, width, height));
|
||||||
camera->resize(width, height);
|
if(camera != NULL)
|
||||||
|
camera->resize(width, height);
|
||||||
for(ModuleNode &mn : modules)
|
for(ModuleNode &mn : modules)
|
||||||
mn.module->resize(w, h);
|
mn.module->resize(w, h);
|
||||||
}
|
}
|
||||||
@ -133,6 +134,7 @@ void SparrowRenderer::setModuleEnabled(std::string module, bool isEnabled)
|
|||||||
void SparrowRenderer::setCamera(Camera* myCamera)
|
void SparrowRenderer::setCamera(Camera* myCamera)
|
||||||
{
|
{
|
||||||
camera = myCamera;
|
camera = myCamera;
|
||||||
|
camera->resize(width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
Camera* SparrowRenderer::getCamera()
|
Camera* SparrowRenderer::getCamera()
|
||||||
|
@ -53,6 +53,8 @@ Texture::Texture(Image* myImage) :
|
|||||||
|
|
||||||
Texture::Texture(Image* myCubemapImages[6]) :
|
Texture::Texture(Image* myCubemapImages[6]) :
|
||||||
m_target(GL_TEXTURE_CUBE_MAP),
|
m_target(GL_TEXTURE_CUBE_MAP),
|
||||||
|
m_width(myCubemapImages[0]->width),
|
||||||
|
m_height(myCubemapImages[0]->height),
|
||||||
m_dataType(GL_UNSIGNED_BYTE)
|
m_dataType(GL_UNSIGNED_BYTE)
|
||||||
{
|
{
|
||||||
glAssert(glGenTextures(1, &texId));
|
glAssert(glGenTextures(1, &texId));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user