2014-06-06 18:04:00 +02:00
|
|
|
#ifndef _GAMERENDERER_HPP_
|
|
|
|
#define _GAMERENDERER_HPP_
|
2013-07-03 10:46:07 +02:00
|
|
|
|
|
|
|
#define GLEW_STATIC
|
|
|
|
#include <GL/glew.h>
|
2013-07-04 03:40:47 +02:00
|
|
|
#include <memory>
|
2013-12-20 14:43:12 +01:00
|
|
|
#include <vector>
|
2013-07-03 10:46:07 +02:00
|
|
|
|
2013-12-20 15:03:32 +01:00
|
|
|
#include <render/ViewCamera.hpp>
|
2013-07-02 09:53:23 +02:00
|
|
|
|
2013-07-04 03:40:47 +02:00
|
|
|
class Model;
|
2014-02-09 04:14:43 +01:00
|
|
|
class ModelFrame;
|
2013-12-20 17:02:46 +01:00
|
|
|
class GameWorld;
|
2014-02-28 12:23:51 +01:00
|
|
|
class GameObject;
|
2013-09-11 01:26:13 +02:00
|
|
|
class Animator;
|
2014-06-29 23:14:46 +02:00
|
|
|
class InventoryItem;
|
2013-07-22 05:39:58 +02:00
|
|
|
|
2014-02-13 11:55:11 +01:00
|
|
|
/**
|
|
|
|
* Renderer
|
|
|
|
*
|
|
|
|
* Handles low level rendering of Models, as well as high level rendering of
|
|
|
|
* objects in the world.
|
|
|
|
*/
|
2014-06-06 18:04:00 +02:00
|
|
|
class GameRenderer
|
2013-07-02 09:53:23 +02:00
|
|
|
{
|
2013-12-20 17:02:46 +01:00
|
|
|
GameWorld* engine;
|
2013-12-20 14:43:12 +01:00
|
|
|
|
|
|
|
struct RQueueEntry {
|
|
|
|
Model* model;
|
|
|
|
size_t g;
|
|
|
|
size_t sg;
|
|
|
|
glm::mat4 matrix;
|
2014-02-28 12:23:51 +01:00
|
|
|
GameObject* object;
|
2013-12-20 14:43:12 +01:00
|
|
|
};
|
|
|
|
|
2014-02-28 12:23:51 +01:00
|
|
|
bool renderFrame(Model* m, ModelFrame* f, const glm::mat4& matrix, GameObject* object, bool queueTransparent = true);
|
2014-02-09 04:14:43 +01:00
|
|
|
|
2013-12-20 14:43:12 +01:00
|
|
|
// Internal method for processing sub-geometry
|
2014-02-28 12:23:51 +01:00
|
|
|
bool renderSubgeometry(Model* model, size_t g, size_t sg, const glm::mat4& matrix, GameObject* object, bool queueTransparent = true);
|
2013-12-20 14:43:12 +01:00
|
|
|
|
|
|
|
/// Queue of sub-geometry to post-render
|
|
|
|
/// With a faster occulusion culling stage
|
|
|
|
/// This could be replaced with a 2nd draw pass.
|
|
|
|
std::vector<RQueueEntry> transparentDrawQueue;
|
2013-07-24 01:42:50 +02:00
|
|
|
|
2014-06-02 05:58:41 +02:00
|
|
|
float _renderAlpha;
|
|
|
|
|
2014-06-30 02:56:45 +02:00
|
|
|
std::vector<std::pair<glm::vec3, glm::vec3>> _tracers;
|
|
|
|
|
2013-07-02 09:53:23 +02:00
|
|
|
public:
|
|
|
|
|
2014-06-06 18:04:00 +02:00
|
|
|
GameRenderer(GameWorld*);
|
2013-07-02 09:53:23 +02:00
|
|
|
|
|
|
|
ViewCamera camera;
|
|
|
|
|
2013-07-02 10:58:01 +02:00
|
|
|
/// The numer of things rendered by the last renderWorld
|
|
|
|
size_t rendered;
|
|
|
|
size_t culled;
|
2013-07-03 10:46:07 +02:00
|
|
|
|
2014-02-13 11:55:11 +01:00
|
|
|
/* TODO clean up all these variables */
|
2013-07-03 10:46:07 +02:00
|
|
|
GLuint worldProgram;
|
2014-06-17 22:46:54 +02:00
|
|
|
GLint uniTexture;
|
|
|
|
GLuint ubiScene, ubiObject;
|
|
|
|
GLuint uboScene, uboObject;
|
|
|
|
|
2013-07-05 03:15:29 +02:00
|
|
|
GLuint skyProgram;
|
2014-06-14 19:48:14 +02:00
|
|
|
GLuint waterProgram, waterMVP, waterHeight, waterTexture, waterSize, waterTime, waterPosition, waterWave;
|
2013-07-05 03:15:29 +02:00
|
|
|
GLint skyUniView, skyUniProj, skyUniTop, skyUniBottom;
|
2013-07-02 10:58:01 +02:00
|
|
|
|
2013-07-06 02:39:54 +02:00
|
|
|
/// Internal VAO to avoid clobbering global state.
|
2013-07-30 17:59:44 +02:00
|
|
|
GLuint vao, debugVAO;
|
2013-07-06 02:39:54 +02:00
|
|
|
|
2014-06-08 20:04:47 +02:00
|
|
|
GLuint skydomeVBO, skydomeIBO, debugVBO;
|
2013-07-30 17:59:44 +02:00
|
|
|
GLuint debugTex;
|
2013-07-04 12:43:28 +02:00
|
|
|
|
2013-07-30 17:59:44 +02:00
|
|
|
/**
|
2014-02-13 11:55:11 +01:00
|
|
|
* Renders the current World.
|
2013-07-30 17:59:44 +02:00
|
|
|
*/
|
2014-06-02 05:58:41 +02:00
|
|
|
void renderWorld(float alpha);
|
2013-07-30 17:59:44 +02:00
|
|
|
|
2014-06-01 18:41:09 +02:00
|
|
|
void renderWheel(Model*, const glm::mat4& matrix, const std::string& name);
|
2013-07-24 01:42:50 +02:00
|
|
|
|
2014-06-29 23:14:46 +02:00
|
|
|
void renderItem(InventoryItem* item, const glm::mat4& modelMatrix);
|
|
|
|
|
2014-02-28 12:23:51 +01:00
|
|
|
void renderGeometry(Model*, size_t geom, const glm::mat4& modelMatrix, GameObject* = nullptr);
|
2013-07-22 05:39:58 +02:00
|
|
|
|
2014-02-13 11:55:11 +01:00
|
|
|
/**
|
|
|
|
* Renders a model (who'd have thought)
|
|
|
|
*/
|
2014-02-28 12:23:51 +01:00
|
|
|
void renderModel(Model*, const glm::mat4& modelMatrix, GameObject* = nullptr, Animator* animator = nullptr);
|
2013-07-30 17:59:44 +02:00
|
|
|
|
|
|
|
/**
|
2014-02-13 11:55:11 +01:00
|
|
|
* Debug method renders all AI paths
|
2013-07-30 17:59:44 +02:00
|
|
|
*/
|
|
|
|
void renderPaths();
|
2014-06-17 22:46:54 +02:00
|
|
|
|
2014-06-30 02:56:45 +02:00
|
|
|
void addTracer(const glm::vec3& from, const glm::vec3& to) {
|
|
|
|
_tracers.push_back({from, to});
|
|
|
|
}
|
|
|
|
|
2014-06-17 22:46:54 +02:00
|
|
|
static GLuint currentUBO;
|
|
|
|
template<class T> void uploadUBO(GLuint buffer, const T& data)
|
|
|
|
{
|
|
|
|
if( currentUBO != buffer ) {
|
|
|
|
glBindBuffer(GL_UNIFORM_BUFFER, buffer);
|
|
|
|
currentUBO = buffer;
|
|
|
|
}
|
|
|
|
glBufferData(GL_UNIFORM_BUFFER, sizeof(T), &data, GL_DYNAMIC_DRAW);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct SceneUniformData {
|
|
|
|
glm::mat4 projection;
|
|
|
|
glm::mat4 view;
|
|
|
|
glm::vec4 ambient;
|
|
|
|
glm::vec4 dynamic;
|
|
|
|
float fogStart;
|
|
|
|
float fogEnd;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ObjectUniformData {
|
|
|
|
glm::mat4 model;
|
|
|
|
glm::vec4 colour;
|
|
|
|
float diffuse;
|
|
|
|
float ambient;
|
2013-07-02 09:53:23 +02:00
|
|
|
};
|
|
|
|
|
2013-07-22 05:39:58 +02:00
|
|
|
#endif
|