186 lines
5.6 KiB
C++
186 lines
5.6 KiB
C++
#pragma once
|
|
#include <vector>
|
|
#include <map>
|
|
#include "scene/Scene.h"
|
|
#include "core/CameraPath.h"
|
|
#include "core/LightPath.h"
|
|
#include "core/Defines.h"
|
|
#include "core/Util/Stopwatch.h"
|
|
|
|
class Camera;
|
|
class Controls;
|
|
class ObjLoader;
|
|
class ShaderLoader;
|
|
class PropertyLoader;
|
|
struct GLFWwindow;
|
|
|
|
class Renderer {
|
|
private:
|
|
// X and Y size of textures
|
|
const static unsigned TEXTURE_SIZE = 1024;
|
|
// The size (in the Z direction) of a single texture block
|
|
const static unsigned TEXTURE_BLOCK_SIZE = 1024;
|
|
|
|
public:
|
|
static void Create();
|
|
static void Destroy();
|
|
static Renderer* Instance();
|
|
void Render();
|
|
bool Initialize(bool fullscreen = false);
|
|
|
|
static size_t Load2DTexture(std::string filename);
|
|
void ToggleFullscreen(bool fullscreen);
|
|
void ReloadShaders();
|
|
void UpdateLightDirection();
|
|
void ToggleLight();
|
|
void ToggleAOMode();
|
|
void ToggleReflections();
|
|
void TakeScreenshot();
|
|
void SetPresetLocation(unsigned8 presetID);
|
|
// Starts and stops recording a camera path. Use StoreRecording() after calling this method to store screenshots along the path
|
|
void ToggleRecording();
|
|
void ClearLightPath();
|
|
void AddLightPathNode();
|
|
void ClearCameraPath();
|
|
void AddCameraPathNode();
|
|
void RemoveCameraPathNode();
|
|
/// Clears the camera path and replaces it with a rotation.
|
|
void SetRotationRecording();
|
|
|
|
|
|
// Stores screenshot along every path position of the last recording
|
|
void StoreRecording();
|
|
|
|
|
|
// Goes through the current camera path and stores the frame time for each frame.
|
|
void RunBenchmark();
|
|
void SaveLastViewpoint();
|
|
void LoadLastViewpoint();
|
|
void Resize(int width, int height);
|
|
|
|
void IncreaseOctreeRenderLevel();
|
|
void DecreaseOctreeRenderLevel();
|
|
|
|
private:
|
|
Renderer();
|
|
~Renderer();
|
|
bool Reinitialize(bool fullscreen);
|
|
bool InitializeGLFW(bool fullscreen);
|
|
void Transform();
|
|
void SetCameraState(CameraState state);
|
|
|
|
void InitFramebuffer();
|
|
void DeleteFramebuffer();
|
|
void SetStaticUniforms(unsigned program);
|
|
void SetDynamicUniforms(unsigned program);
|
|
void LoadOctree();
|
|
void GenerateRandomTexture();
|
|
void LoadFragmentShaderUniforms();
|
|
void LoadShaders();
|
|
|
|
void SaveViewpoint(std::string filename);
|
|
void LoadViewpoint(std::string filename);
|
|
void SaveRecording(std::string filename);
|
|
void LoadRecording(std::string filename);
|
|
void SaveLightPathRecording(std::string filename);
|
|
void LoadLightPathRecording(std::string filename);
|
|
void StartFlythrough();
|
|
void StopFlythrough();
|
|
void StartStoringRecording();
|
|
void StopStoringRecording();
|
|
void StartBenchmark();
|
|
void StopBenchmark();
|
|
void InitRecordingDirectory();
|
|
|
|
static void Resize(GLFWwindow* window, int width, int height);
|
|
|
|
bool textureLoaded(std::string filename);
|
|
|
|
void TakeScreenshot(std::string filename);
|
|
|
|
static Renderer* mInstance;
|
|
|
|
int mWidth;
|
|
int mHeight;
|
|
int mWidthOld;
|
|
int mHeightOld;
|
|
bool mUseCache;
|
|
unsigned8 mMaxLevel;
|
|
unsigned8 mRenderDepth;
|
|
std::string mTreeType;
|
|
|
|
GLFWwindow* mWindow;
|
|
|
|
Camera* mCamera;
|
|
Controls* mController;
|
|
ObjLoader* mObjLoader;
|
|
ShaderLoader* mShaderLoader;
|
|
PropertyLoader* mPropertyLoader;
|
|
enum AOMode{ NONE, REAL, SSAO, NUM_VALUES };
|
|
AOMode mAOMode;
|
|
bool mReflections;
|
|
|
|
unsigned mVertexArrayID, mVertexBuffer, mTextureBuffer, mNormalBuffer, mElementBuffer, mDefaultProgramID, mPostProcessProgramID, mGiPostProcessProgramID, mRenderDepthUniform;
|
|
unsigned mFramebuffer, mFramebufferTexture, mDirectLightTexture, mIndirectLightTexture, mVoxelPositionsTexture, mDepthTexture, mQuadVertexBuffer, mPostprocessRenderTextureUniform, mPostprocessVoxelPositionsTextureUniform, mPostprocessDepthTextureUniform, mGiPostProcessRenderTextureUniform, mGiPostProcessDirectLightTextureUniform, mGiPostProcessIndirectLightTextureUniform;
|
|
|
|
CameraState mCurrentCameraState;
|
|
|
|
LightState mLightState;
|
|
DirectionalLight mDirectionalLight;
|
|
PointLight mPointLight;
|
|
|
|
glm::mat4 mModelMatrix;
|
|
glm::mat4 mViewMatrix;
|
|
glm::mat4 mProjectionMatrix;
|
|
glm::mat4 mMVP;
|
|
glm::mat4 mInvMVP;
|
|
|
|
Scene* mScene;
|
|
std::map<std::string, unsigned> mTextures; // list of all textures
|
|
|
|
std::vector<unsigned32> mOctreeTextures;
|
|
std::vector<unsigned32> mBlockTextures;
|
|
|
|
// for binding the texture sampler
|
|
unsigned mTextureSampler, mMaterialOctreeSampler, mOctreeSamplers, mMaterialTextureSampler, mBlockPointerSampler, mBlockSamplers, mRandomTextureSampler;
|
|
unsigned mMaterialTexture, mMaterialOctreeTexture, mBlockPointerTexture, mRandomTexture;
|
|
std::map<std::string, std::string> mAdditionalProperties;
|
|
|
|
std::map<unsigned, bool> mStaticUniformsSet; // flag that static uniforms have been set
|
|
|
|
double mLastTime;
|
|
double mCurrentTime;
|
|
unsigned mFrames;
|
|
char mText[100];
|
|
|
|
std::string mDagFilename;
|
|
std::string mScreenshotDirectory;
|
|
|
|
// The actual recording (camera states and times)
|
|
CameraPath mCameraPath;
|
|
LightPath mLightPath;
|
|
|
|
// Properties used for camera path recording
|
|
Stopwatch mRecordingTimer;
|
|
bool mIsRecording;
|
|
|
|
// Properties used for video storing
|
|
bool mIsStoringRecording;
|
|
bool mIsTrackballReconding;
|
|
bool mIsPlayingFlythrough;
|
|
// Index of the current frame
|
|
unsigned mCameraPathFrame;
|
|
// Time per frame (1.0 / FPS)
|
|
float mRecordingFPS;
|
|
float mCameraPathFrameTime;
|
|
float mCameraPathNodeTime;
|
|
float mLightPathNodeTime;
|
|
|
|
// Stats for benchmarking:
|
|
std::vector<double> mFrameTimes;
|
|
|
|
// Directory of the images for the current recording
|
|
std::string mRecordingDirectory;
|
|
|
|
static const float QUAD_VERTEX_BUFFER_DATA[];
|
|
}; |