1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-10-05 08:37:20 +02:00
openrw/rwengine/include/render/GameRenderer.hpp

262 lines
6.0 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;
/// @todo migrate to some other way of rendering each object type.
class CharacterObject;
class VehicleObject;
class InstanceObject;
class PickupObject;
class ProjectileObject;
class CutsceneObject;
2013-09-11 01:26:13 +02:00
class Animator;
class InventoryItem;
2014-02-13 11:55:11 +01:00
/**
* @brief Implements high level drawing logic and low level draw commands
*
* Rendering of object types is handled by drawWorld, calling the respective
* render function for each object.
2014-02-13 11:55:11 +01:00
*/
2014-06-06 18:04:00 +02:00
class GameRenderer
2013-07-02 09:53:23 +02:00
{
/** Pointer to the world instance */
GameWorld* engine;
/** Data required to queue transparent objects for delayed rendering */
struct RQueueEntry {
Model* model;
size_t g;
size_t sg;
glm::mat4 matrix;
GameObject* object;
};
/**
* @brief renders a model's frame.
* @param m
* @param f
* @param matrix
* @param object
* @param queueTransparent abort the draw if the frame contains transparent materials
* @return True if the frame was drawn, false if it should be queued
*/
bool renderFrame(Model* m, ModelFrame* f, const glm::mat4& matrix, GameObject* object, bool queueTransparent = true);
2014-02-09 04:14:43 +01:00
/**
* @brief renders a model's subgeometry
* @param model
* @param g
* @param sg
* @param matrix
* @param object
* @param queueTransparent
* @return @see renderFrame(
*/
bool renderSubgeometry(Model* model, size_t g, size_t sg, const glm::mat4& matrix, GameObject* object, bool queueTransparent = true);
/** Transparent objects are queued into this list */
std::vector<RQueueEntry> transparentDrawQueue;
float _renderAlpha;
public:
/**
* @brief Stores particle effect instance data
*/
struct FXParticle {
/** Initial world position */
glm::vec3 position;
/** Direction of particle */
glm::vec3 direction;
/** Velocity of particle */
float velocity;
/** Particle orientation modes */
enum Orientation {
Free, /** faces direction using up */
Camera, /** Faces towards the camera @todo implement */
UpCamera /** Face closes point in camera's look direction */
};
Orientation orientation;
/** Game time at particle instantiation */
float starttime;
float lifetime;
/** Texture name */
GLuint texture;
/** Size of particle */
glm::vec2 size;
/** Up direction (only used in Free mode) */
glm::vec3 up;
2014-07-09 23:28:25 +02:00
/** Render tint colour */
glm::vec4 colour;
/** Internal cache value */
glm::vec3 _currentPosition;
/** Constructs a particle */
FXParticle(const glm::vec3& p, const glm::vec3& d, float v,
Orientation o, float st, float lt, GLuint texture,
2014-07-09 23:28:25 +02:00
const glm::vec2& size, const glm::vec3& up = {0.f, 0.f, 1.f},
const glm::vec4& colour = {1.f, 1.f, 1.f, 1.f})
: position(p), direction(d), velocity(v), orientation(o),
starttime(st), lifetime(lt), texture(texture), size(size),
2014-07-09 23:28:25 +02:00
up(up), colour(colour), _currentPosition(p) {}
};
private:
/** Particles in flight */
std::vector<FXParticle> _particles;
2014-06-30 02:56:45 +02:00
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;
/** Number of issued draw calls */
2013-07-02 10:58:01 +02:00
size_t rendered;
/** Number of culling events */
2013-07-02 10:58:01 +02:00
size_t culled;
/** @todo Clean up all these shader program and location 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;
GLuint particleProgram;
GLuint ssRectProgram;
GLint ssRectTexture, ssRectColour, ssRectSize, ssRectOffset;
2013-07-02 10:58:01 +02:00
/** Internal non-descript VAOs */
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
/**
* Draws the world:
*
* - draws all objects (instances, vehicles etc.)
* - draws particles
* - draws water surfaces
* - draws the skybox
2013-07-30 17:59:44 +02:00
*/
void renderWorld(float alpha);
2013-07-30 17:59:44 +02:00
/**
* @brief draws a CharacterObject and any item they are holding.
* @param pedestrian the character to render
*/
void renderPedestrian(CharacterObject* pedestrian);
/**
* @brief draws a VehicleObject and it's wheels.
* @param vehicle vehicle to render
*/
void renderVehicle(VehicleObject* vehicle);
/**
* @brief draw part of the world.
*/
void renderInstance(InstanceObject* instance);
/**
* @brief draws a pickup with it's model
* @param pickup
* @todo corona rendering, with tint.
*/
void renderPickup(PickupObject* pickup);
void renderProjectile(ProjectileObject* projectile);
void renderCutsceneObject(CutsceneObject *cutscene);
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);
/**
* @brief renders all visible particles and removes expired
*/
void renderParticles();
/**
* @brief Draws the current on screen text.
*/
void drawOnScreenText();
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
/** method for rendering AI debug information */
2013-07-30 17:59:44 +02:00
void renderPaths();
2014-06-17 22:46:54 +02:00
/** Adds a particle to the rendering */
void addParticle(const FXParticle& particle);
2014-06-30 02:56:45 +02:00
2014-06-17 22:46:54 +02:00
static GLuint currentUBO;
/**
* Uploads data from T into the specified UBO
*/
2014-06-17 22:46:54 +02:00
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;
glm::vec4 fogColour;
glm::vec4 campos;
2014-06-17 22:46:54 +02:00
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