Files
vb01/root.h
T
devZoGok cc59f9160c Box/Quad clone methods
Phong lighting shaders
using multi draw indirect rendering
2026-06-26 09:40:46 +03:00

128 lines
4.1 KiB
C++
Executable File

#ifndef ROOT_H
#define ROOT_H
#include "util.h"
#include "meshData.h"
#include <glm.hpp>
#include <glad.h>
#include <glfw3.h>
#include <unordered_map>
#include <string>
#include <vector>
class GLFWwindow;
namespace vb01{
void foo();
class Camera;
class Mesh;
class Box;
class Quad;
class Node;
class Texture;
class Shader;
class ParticleEmitter;
class Root{
public:
static Root* getSingleton();
void update();
void start(int, int, std::string, std::string);
void toggleHDR(bool);
void toggleBloom(bool);
void addMeshes(Node*);
void createSkybox(std::string[6]);
void createSkybox(vb01::Texture*);
void removeSkybox();
void initVertexDataOnGpu(MeshData&, u32&, u32&, u32&, bool);
inline u32& getMeshVAO(){return meshVAO;}
inline u32& getMeshVBO(){return meshVBO;}
inline u32& getMeshEBO(){return meshEBO;}
inline const int getMaxNumShapeKeys(){return MAX_NUM_SHAPE_KEYS;}
inline Camera* getCamera(){return camera;}
inline Node* getRootNode(){return rootNode;}
inline Node* getGuiNode(){return guiNode;}
inline int getWidth(){return width;}
inline int getHeight(){return height;}
inline u32* getFBO(){return &FBO;}
inline u32* getRBO(){return &RBO;}
inline GLFWwindow* getWindow(){return window;}
inline void setExposure(float exposure){this->exposure = exposure;}
inline void setGamma(float gamma){this->gamma = gamma;}
inline void setBlurLevel(bool level){this->blurLevel = level;}
inline Box* getSkybox(){return skybox;}
inline Box* getIblBox(){return iblBox;}
inline Quad* getBrdfLutPlane(){return brdfLutPlane;}
inline void shiftNumLights(bool increase){numLights += (increase ? 1 : -1);}
inline int getNumLights(){return numLights;}
inline std::string getLibPath(){return libPath;}
private:
struct DrawElementsIndirectCommand {
u32 count = 0;
u32 instanceCount = 0;
u32 firstIndex = 0;
int baseVertex = 0;
u32 baseInstance = 0;
};
struct ObjectVertexData {
float shapeKeyFactors[24];
glm::mat4 viewProj, model, bones[256];
//bool animated;
};
struct ObjectFragmentData {
Vector4 diffuseColor, specularColor;
float shinyness, specularStrength;
bool lightingEnabled, constLightingEnabled, texturingEnabled, normalMapEnabled, specularMapEnabled, castShadow, environmentMapEnabled;
};
const int MAX_NUM_SHAPE_KEYS = 5;
int NUM_MAX_TEXTURE_UNITS = 0, NUM_MAX_TEXTURE_ARRAY_SIZE = 0, numLights = 0, width, height, blurLevel = 10, currNumVerts = 0, currNumIndexes = 0;
u32 meshVAO, meshVBO, meshEBO, particleVAO, particleVBO, guiPlaneVAO, guiPlaneVBO, guiPlaneEBO, FBO, RBO, pingpongBuffers[2], drawCmdBuffer = -1, objVertBuffer = -1, objFragBuffer = -1;
bool bloom = false, hdr = false;
float exposure = 1, gamma = 1;
Box *skybox = nullptr, *iblBox = nullptr;
Quad *guiPlane = nullptr, *brdfLutPlane = nullptr;
GLFWwindow *window;
Node *rootNode, *guiNode;
Camera *camera;
Shader *blurShader;
Texture *pingPongTextures[2];
std::vector<MeshData*> drawCmdMeshes;
std::vector<MeshData::GpuVertex> currentGpuVertices;
std::vector<u32> currentIndices;
std::vector<Mesh*> meshes;
std::vector<DrawElementsIndirectCommand> drawCmds;
std::vector<ObjectVertexData> objVertData;
std::vector<ObjectFragmentData> objFragData;
std::string libPath;
Root();
void framebuffer_size_callback(GLFWwindow*, int, int);
void renderMeshes();
void renderParticles(std::vector<ParticleEmitter*>&);
void renderGui(std::vector<Mesh*>&);
void initWindow(std::string);
void initMainFramebuffer(Texture*, Texture*);
void initBloomFramebuffer();
void initGuiPlane();
void updateBloomFramebuffer();
void updateGuiPlane();
void updateNodeTree(vb01::Node*, glm::mat4&, bool);
void updateNode(vb01::Node*, glm::mat4&, glm::mat4&, bool);
void renderMesh(Mesh*, u32&);
protected:
virtual void initMeshRendering(u32 &vao, u32 &vbo, u32 &ebo);
virtual void initParticleRendering();
virtual void initGuiRendering();
virtual void initPostProcessing();
virtual void postProcess(){}
};
}
#endif