1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-11-08 03:42:35 +01:00
openrw/rwengine/include/render/GameRenderer.hpp

129 lines
2.9 KiB
C++
Raw Normal View History

2014-06-06 18:04:00 +02:00
#ifndef _GAMERENDERER_HPP_
#define _GAMERENDERER_HPP_
#define GLEW_STATIC
#include <GL/glew.h>
2013-07-04 03:40:47 +02:00
#include <memory>
#include <vector>
#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;
class GameObject;
2013-09-11 01:26:13 +02:00
class Animator;
class InventoryItem;
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;
struct RQueueEntry {
Model* model;
size_t g;
size_t sg;
glm::mat4 matrix;
GameObject* object;
};
bool renderFrame(Model* m, ModelFrame* f, const glm::mat4& matrix, GameObject* object, bool queueTransparent = true);
2014-02-09 04:14:43 +01:00
// Internal method for processing sub-geometry
bool renderSubgeometry(Model* model, size_t g, size_t sg, const glm::mat4& matrix, GameObject* object, bool queueTransparent = true);
/// 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;
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;
2014-02-13 11:55:11 +01:00
/* TODO clean up all these variables */
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
/// Internal VAO to avoid clobbering global state.
2013-07-30 17:59:44 +02:00
GLuint vao, debugVAO;
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
*/
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);
void renderItem(InventoryItem* item, const glm::mat4& modelMatrix);
void renderGeometry(Model*, size_t geom, const glm::mat4& modelMatrix, GameObject* = nullptr);
2014-02-13 11:55:11 +01:00
/**
* Renders a model (who'd have thought)
*/
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
};
#endif